Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing if conditions to temp vars to fix issue #420 #544

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion silver
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DefaultStmtModule(val verifier: Verifier) extends StmtModule with SimpleSt

private val lblNamespace = verifier.freshNamespace("stmt.lbl")
var lblVarsNamespace = verifier.freshNamespace("var.lbl")
private val tmpVarsNamespace = verifier.freshNamespace("stmt.tmpvar")
override def labelNamespace = lblNamespace

def name = "Statement module"
Expand Down Expand Up @@ -209,8 +210,12 @@ class DefaultStmtModule(val verifier: Verifier) extends StmtModule with SimpleSt
Nil
case i@sil.If(cond, thn, els) =>
val condTr = if(allStateAssms == TrueLit()) { translateExpInWand(cond) } else { allStateAssms ==> translateExpInWand(cond) }
val condTempVar = LocalVar(Identifier("condition")(tmpVarsNamespace), Bool)
checkDefinedness(cond, errors.IfFailed(cond), insidePackageStmt = insidePackageStmt) ++
If(condTr,
// Assign the condition to a temp var s.t. it's safe to optimize away the following if it's empty without
// losing triggering expressions in the if-condition (see Carbon issue #420).
Assign(condTempVar, condTr) ++
If(condTempVar,
translateStmt(thn, statesStack, allStateAssms, insidePackageStmt),
translateStmt(els, statesStack, allStateAssms, insidePackageStmt))
case sil.Label(name, _) => {
Expand Down
Loading