Skip to content

Commit f8cc484

Browse files
manud99JonasAlaif
andauthored
Use a Map from Snap to Snap to represent a magic wand snapshot. (#836)
* Use a Map from Snap to Snap to represent a magic wand snapshot. * Fix failing test cases. * Fix broken links in comments. * First optimization: Create sort MagicWandSnapFunction (MWSF) with its own function definitions to replace wand maps. * Second optimization: When there is no applying expression use the original approach using MagicWandSnapSingleton. * Revert "Second optimization: When there is no applying expression use the original approach using MagicWandSnapSingleton." This reverts commit fd87482. * Apply suggested changes from code review. * Fix test cases with quasihavoc statements. * Update submodule to use branch with both testcase changes * Remove abstractLhs and rhsSnapshot from MagicWandSnapshot. * Reduce diff * Simplify havoc * Simplify production of a MWSF. * Rename variable in Producer. * Update silver branch magic-wand-fixes. --------- Co-authored-by: Jonáš Fiala <jonas.fiala@inf.ethz.ch>
1 parent 4a0c07e commit f8cc484

17 files changed

Lines changed: 442 additions & 242 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(declare-fun MWSF_apply ($MWSF $Snap) $Snap)

src/main/scala/Utils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ package object utils {
222222
case class ViperEmbedding(embeddedSort: Sort) extends silver.ast.ExtensionType {
223223
def substitute(typVarsMap: Predef.Map[silver.ast.TypeVar, silver.ast.Type]): silver.ast.Type = this
224224
def isConcrete: Boolean = true
225+
override def toString: String = s"ViperEmbedding(sorts.$embeddedSort)"
225226
}
226227
}
227228

src/main/scala/decider/TermToSMTLib2Converter.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class TermToSMTLib2Converter
6161

6262
case sorts.FieldPermFunction() => text("$FPM")
6363
case sorts.PredicatePermFunction() => text("$PPM")
64+
65+
case sorts.MagicWandSnapFunction => text("$MWSF")
6466
}
6567

6668
def convert(d: Decl): String = {
@@ -263,7 +265,7 @@ class TermToSMTLib2Converter
263265

264266
case Lookup(field, fvf, at) => //fvf.sort match {
265267
// case _: sorts.PartialFieldValueFunction =>
266-
parens(text("$FVF.lookup_") <> field <+> render(fvf) <+> render(at))
268+
parens(text("$FVF.lookup_") <> field <+> render(fvf) <+> render(at))
267269
// case _: sorts.TotalFieldValueFunction =>
268270
// render(Apply(fvf, Seq(at)))
269271
// parens("$FVF.lookup_" <> field <+> render(fvf) <+> render(at))
@@ -313,6 +315,9 @@ class TermToSMTLib2Converter
313315
val docBindings = ssep((bindings.toSeq map (p => parens(render(p._1) <+> render(p._2)))).to(collection.immutable.Seq), space)
314316
parens(text("let") <+> parens(docBindings) <+> render(body))
315317

318+
case MagicWandSnapshot(mwsf) => render(mwsf)
319+
case MWSFLookup(mwsf, snap) => renderApp("MWSF_apply", Seq(mwsf, snap), sorts.Snap)
320+
316321
case _: MagicWandChunkTerm
317322
| _: Quantification =>
318323
sys.error(s"Unexpected term $term cannot be translated to SMTLib code")

src/main/scala/decider/TermToZ3APIConverter.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ class TermToZ3APIConverter
445445
case Let(bindings, body) =>
446446
convert(body.replace(bindings))
447447

448+
case MWSFLookup(mwsf, snap) => createApp("MWSF_apply", Seq(mwsf, snap), sorts.Snap)
449+
448450
case _: MagicWandChunkTerm
449451
| _: Quantification =>
450452
sys.error(s"Unexpected term $term cannot be translated to SMTLib code")

src/main/scala/rules/HavocSupporter.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,17 @@ object havocSupporter extends SymbolicExecutionRules {
181181
val id = ChunkIdentifier(resource, s.program)
182182
val (relevantChunks, otherChunks) = chunkSupporter.splitHeap[NonQuantifiedChunk](s.h, id)
183183

184-
val newChunks = relevantChunks.map { ch =>
185-
val havockedSnap = freshSnap(ch.snap.sort, v)
186-
val cond = replacementCond(lhs, ch.args, condInfo)
187-
ch.withSnap(Ite(cond, havockedSnap, ch.snap))
184+
val newChunks = relevantChunks.map {
185+
case ch: MagicWandChunk =>
186+
val havockedSnap = v.decider.fresh("mwsf", sorts.MagicWandSnapFunction)
187+
val cond = replacementCond(lhs, ch.args, condInfo)
188+
val magicWandSnapshot = MagicWandSnapshot(Ite(cond, havockedSnap, ch.snap.mwsf))
189+
ch.withSnap(magicWandSnapshot)
190+
191+
case ch =>
192+
val havockedSnap = freshSnap(ch.snap.sort, v)
193+
val cond = replacementCond(lhs, ch.args, condInfo)
194+
ch.withSnap(Ite(cond, havockedSnap, ch.snap))
188195
}
189196
otherChunks ++ newChunks
190197
}

src/main/scala/rules/MagicWandSupporter.scala

Lines changed: 201 additions & 132 deletions
Large diffs are not rendered by default.

src/main/scala/rules/MoreCompleteExhaleSupporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
5555
resource match {
5656
case f: ast.Field => v.symbolConverter.toSort(f.typ)
5757
case _: ast.Predicate => sorts.Snap
58-
case _: ast.MagicWand => sorts.Snap
58+
case _: ast.MagicWand => sorts.MagicWandSnapFunction
5959
}
6060

6161
val `?s` = Var(Identifier("?s"), sort, false)

src/main/scala/rules/Producer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ object producer extends ProductionRules {
397397
Q(s2, v1)})
398398

399399
case wand: ast.MagicWand =>
400-
val snap = sf(sorts.Snap, v)
400+
val snap = sf(sorts.MagicWandSnapFunction, v)
401401
magicWandSupporter.createChunk(s, wand, MagicWandSnapshot(snap), pve, v)((s1, chWand, v1) =>
402402
chunkSupporter.produce(s1, s1.h, chWand, v1)((s2, h2, v2) =>
403403
Q(s2.copy(h = h2), v2)))

src/main/scala/rules/QuantifiedChunkSupport.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
637637

638638
/* Snapshots */
639639

640-
/** @inheritdoc */
641640
def singletonSnapshotMap(s: State,
642641
resource: ast.Resource,
643642
arguments: Seq[Term],

0 commit comments

Comments
 (0)