Skip to content

Commit

Permalink
Implement UncheckedAbruptCompletionMismatch (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Jihyeok Park <jihyeok_park@korea.ac.kr>
  • Loading branch information
hyp3rflow and jhnaldo authored Jul 21, 2023
1 parent d8823f9 commit 105fd64
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/esmeta/analyzer/AbsTransfer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ trait AbsTransfer extends Optimized with PruneHelper {
sem.rpMap += retRp -> (oldRet ⊔ newRet)
sem.worklist += retRp

// return if abrupt completion
/** return-if-abrupt completion */
def returnIfAbrupt(
riaExpr: EReturnIfAbrupt,
value: AbsValue,
Expand Down
11 changes: 10 additions & 1 deletion src/main/scala/esmeta/analyzer/AnalysisPoint.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package esmeta.analyzer

import esmeta.ir.Return
import esmeta.ir.{Func => _, *}
import esmeta.cfg.*

/** analysis points */
Expand Down Expand Up @@ -39,6 +39,15 @@ case class InternalReturnPoint(
inline def func = calleeRp.func
}

/** return-if-abrupt points */
case class ReturnIfAbruptPoint(
cp: ControlPoint,
riaExpr: EReturnIfAbrupt,
) extends AnalysisPoint {
inline def view = cp.view
inline def func = cp.func
}

/** control points */
sealed trait ControlPoint extends AnalysisPoint

Expand Down
19 changes: 18 additions & 1 deletion src/main/scala/esmeta/analyzer/TypeAnalyzer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import esmeta.{ANALYZE_LOG_DIR, LINE_SEP}
import esmeta.analyzer.domain.*
import esmeta.cfg.*
import esmeta.error.*
import esmeta.ir.{Return, Func => IRFunc, Name, Param, Local}
import esmeta.ir.{Func => IRFunc, *}
import esmeta.ty.*
import esmeta.ty.util.{Stringifier => TyStringifier}
import esmeta.util.*
import esmeta.util.Appender.*
import esmeta.state.*
import esmeta.util.BaseUtils.*
import esmeta.util.SystemUtils.*

Expand Down Expand Up @@ -61,6 +62,21 @@ class TypeAnalyzer(
/** abstract transfer function for types */
trait Transfer extends AbsTransfer {

/** loading monads */
import AbsState.monad.*

/** return-if-abrupt completion */
override def returnIfAbrupt(
riaExpr: EReturnIfAbrupt,
value: AbsValue,
check: Boolean,
)(using cp: ControlPoint): Result[AbsValue] = {
if (config.uncheckedAbrupt && !check && !value.abruptCompletion.isBottom)
val riap = ReturnIfAbruptPoint(cp, riaExpr)
addMismatch(UncheckedAbruptCompletionMismatch(riap, value.ty))
super.returnIfAbrupt(riaExpr, value, check)
}

/** handle calls */
override def doCall(
callerNp: NodePoint[Call],
Expand Down Expand Up @@ -301,5 +317,6 @@ object TypeAnalyzer {
arity: Boolean = true,
paramType: Boolean = true,
returnType: Boolean = true,
uncheckedAbrupt: Boolean = false,
)
}
6 changes: 6 additions & 0 deletions src/main/scala/esmeta/analyzer/TypeMismatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ case class ArityMismatch(
cp: CallPoint[Node],
actual: Int,
) extends TypeMismatch(cp)

/** unchecked abrupt completion mismatches */
case class UncheckedAbruptCompletionMismatch(
riap: ReturnIfAbruptPoint,
actual: ValueTy,
) extends TypeMismatch(riap)
7 changes: 7 additions & 0 deletions src/main/scala/esmeta/analyzer/util/Stringifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class Stringifier(
app >> " when " >> cp
case InternalReturnPoint(irReturn, calleeRp) =>
app >> "return statement in " >> calleeRp.func.name >> irReturn
case ReturnIfAbruptPoint(riap, riaExpr) =>
app >> "returnIfAbrupt"
app >> "(" >> (if (riaExpr.check) "?" else "!") >> ") "
app >> "in " >> riap.func.name >> riaExpr

// control points
given cpRule: Rule[ControlPoint] = (app, cp) =>
Expand Down Expand Up @@ -131,6 +135,9 @@ class Stringifier(
app >> "[ArityMismatch] " >> cp
app :> "- expected: " >> cp.func.arity
app :> "- actual : " >> actual
case UncheckedAbruptCompletionMismatch(riap, actual) =>
app >> "[UncheckedAbruptCompletionMismatch] " >> riap
app :> "- actual : " >> actual

private val addLocRule: Rule[IRElem with LangEdge] = (app, elem) => {
for {
Expand Down

0 comments on commit 105fd64

Please sign in to comment.