Skip to content

Commit d0dcab3

Browse files
committed
force unfolding during exhale also if it's not inside a forall quantifier
1 parent f310849 commit d0dcab3

1 file changed

Lines changed: 10 additions & 20 deletions

File tree

src/main/scala/viper/carbon/modules/impls/DefaultExhaleModule.scala

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ class DefaultExhaleModule(val verifier: Verifier) extends ExhaleModule {
2929

3030
def name = "Exhale module"
3131

32-
//unfoldings within forall assertions must be executed when being exhaled
33-
var exhaleInsidePureForAll = true
34-
3532
override def reset = {
3633
currentPhaseId = -1
37-
exhaleInsidePureForAll = false
3834
}
3935

4036
override def start() {
@@ -137,43 +133,38 @@ class DefaultExhaleModule(val verifier: Verifier) extends ExhaleModule {
137133
}
138134
}
139135
case fa@sil.Forall(vars, _, body) if isInPhase(e, phase) && fa.isPure =>
140-
//GP: the definedness check for foralls is in another branch, hence we must take unfoldings of e into account here (otherwise they would be ignored)
136+
//GP: the definedness check for foralls is in another branch, hence we must take unfoldings of e
137+
// into account here (otherwise they would be ignored)
141138
{
142-
val oldExhaleInsidePureForAll = exhaleInsidePureForAll
143-
exhaleInsidePureForAll = true
144139
val varsFresh = vars.map(v => env.makeUniquelyNamed(v))
145140
varsFresh.foreach(vFresh => env.define(vFresh.localVar))
146141

147142
val renamedBody = Expressions.instantiateVariables(body, vars.map(_.localVar), varsFresh.map(_.localVar))
148143

149-
val exhaleStmt : Stmt = exhaleConnective(renamedBody, error, phase, havocHeap, statesStackForPackageStmt, insidePackageStmt, isAssert, currentStateForPackage = currentStateForPackage)
144+
val exhaleStmt : Stmt = exhaleConnective(renamedBody, error, phase, havocHeap, statesStackForPackageStmt,
145+
insidePackageStmt, isAssert, currentStateForPackage = currentStateForPackage)
150146

151147
Seqn(Seq (
152148
NondetIf(Seqn(Seq(exhaleStmt, Assume(FalseLit())))),
153149
//GP: in the non-deterministic branch we checked the assertion, hence we assume the assertion in the main branch
154150
Assume(translateExp(e)),
155151
{
156152
varsFresh.foreach(vFresh => env.undefine(vFresh.localVar))
157-
exhaleInsidePureForAll = oldExhaleInsidePureForAll
158153
Nil
159154
}
160155
))
161156
}
162157
case sil.Unfolding(_, body) if !insidePackageStmt && isInPhase(e, phase) => {
163158
val checks = components map (_.exhaleExpBeforeAfter(e, error))
164-
val stmtBefore = checks map (_._1())
159+
val stmtBefore = (checks map (_._1())).toList
165160

166161
val stmtBody =
167-
if (exhaleInsidePureForAll) {
168-
//GP: components only deal with the top-level unfolding, force to use unfoldings that are deeper if the exhale is within pure forall assertion
169-
exhaleConnective(body, error, phase, havocHeap, statesStackForPackageStmt, insidePackageStmt, isAssert, currentStateForPackage = currentStateForPackage)
170-
} else {
171-
Statements.EmptyStmt
172-
}
162+
exhaleConnective(body, error, phase, havocHeap, statesStackForPackageStmt, insidePackageStmt, isAssert,
163+
currentStateForPackage = currentStateForPackage)
173164

174-
val stmtAfter = checks map (_._2())
165+
val stmtAfter = (checks map (_._2())).toList
175166

176-
stmtBefore ++ stmtBody ++ stmtAfter
167+
(stmtBefore ++ stmtBody ++ stmtAfter)
177168
}
178169
case _ if isInPhase(e, phase) => {
179170
if(insidePackageStmt){ // handling exhales during packaging a wand
@@ -236,8 +227,7 @@ class DefaultExhaleModule(val verifier: Verifier) extends ExhaleModule {
236227
{
237228
if (e.isPure) {
238229
e match {
239-
case sil.Unfolding(_, _) if exhaleInsidePureForAll =>
240-
Nil //taken care of by exhaleConnective, since unfolding is within a forall expression
230+
case sil.Unfolding(_, _) => Nil //taken care of by exhaleConnective
241231
case _ => Assert(translateExp(e), error.dueTo(AssertionFalse(e)))
242232
}
243233
} else {

0 commit comments

Comments
 (0)