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

Fix multiple apply of magic wands with quantified expressions #849

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
222499c
Use a Map from Snap to Snap to represent a magic wand snapshot.
manud99 Apr 11, 2024
cdb526f
Fix failing test cases.
manud99 May 2, 2024
0fe3f0a
Merge branch 'master' into magic-wand-maps
manud99 May 2, 2024
90b792e
Fix broken links in comments.
manud99 May 2, 2024
3b4b76d
Merge remote-tracking branch 'refs/remotes/origin/magic-wand-maps' in…
manud99 May 2, 2024
77324f4
First optimization: Create sort MagicWandSnapFunction (MWSF) with its…
manud99 May 6, 2024
fd87482
Second optimization: When there is no applying expression use the ori…
manud99 May 6, 2024
45f215c
Revert "Second optimization: When there is no applying expression use…
manud99 May 8, 2024
d67aa27
Apply suggested changes from code review.
manud99 May 8, 2024
98c7714
Merge branch 'master' into magic-wand-maps
manud99 May 8, 2024
7cf0edd
Merge branch 'master' into magic-wand-maps
manud99 May 13, 2024
2a887c4
Fix test cases with quasihavoc statements.
manud99 May 13, 2024
2211b6c
Update submodule to use branch with both testcase changes
JonasAlaif May 16, 2024
531e108
Update silver
JonasAlaif May 16, 2024
6195039
Remove abstractLhs and rhsSnapshot from MagicWandSnapshot.
manud99 May 17, 2024
f306ed7
Reduce diff
JonasAlaif May 17, 2024
e669d26
Simplify havoc
JonasAlaif May 17, 2024
336eda3
Simplify production of a MWSF.
manud99 May 17, 2024
82239ac
Rename variable in Producer.
manud99 May 19, 2024
0761aa9
[WIP] Use MWSF for quantified magic wands.
manud99 May 19, 2024
5441d10
Recursively replace all quantification in the PCS with the freshSnapR…
manud99 Jun 2, 2024
a5c55c0
Try to use implications.
manud99 Jun 5, 2024
00f5f11
Record which snapshot maps were created during packaging.
manud99 Jun 9, 2024
142cf32
Work on QPFields test cases.
manud99 Jun 10, 2024
6131c0f
Optimize for test9 in QPFields.vpr
manud99 Jun 11, 2024
e00837e
Let PredicateSnapFunctions be of sort Snap and use SortWrappers to co…
manud99 Jun 11, 2024
6dc023f
Remove commented code.
manud99 Jun 11, 2024
57f21a5
Make use of smValueDef.
manud99 Jun 11, 2024
f339f59
Cleanup MagicWandSupporter.
manud99 Jun 12, 2024
42bf90b
Generalize substitution for PredicateSnapFunctions.
manud99 Jun 12, 2024
5b52c4a
Add the full MWSF definition to the verifier's path conditions.
manud99 Jun 12, 2024
82670f8
Merge branch 'refs/heads/master' into quantified-magic-wand-maps
manud99 Jun 12, 2024
c089ebd
Revert change from object to case class of MagicWandSnapFunction.
manud99 Jun 12, 2024
0a4f3b5
Restructure MagicWandSupporter.
manud99 Jun 12, 2024
fc7e824
Update silver submodule.
manud99 Jun 15, 2024
bb60e54
Rename state and verifier such that their numbers are incrementing in…
manud99 Jun 16, 2024
064b3c3
Simplify conversion of snapWand from Snap to MWSF.
manud99 Jun 17, 2024
5a5a6af
Rename MWSFLookup to MWSFApply.
manud99 Jun 18, 2024
10942e3
Write documentation about optimizations.
manud99 Jun 22, 2024
d5d7591
Quantify overall FVFs and PSFs.
manud99 Jun 23, 2024
957ed9d
Generalize heuristic for quantification for snapshot trees.
manud99 Jun 23, 2024
94cf819
Implement MWSF which uses an image function to define when the defini…
manud99 Jun 25, 2024
d396389
Replace image function with inverse function.
manud99 Jun 27, 2024
2c72204
Update silver.
manud99 Jun 27, 2024
34bcb7d
Merge branch 'master' into quantified-magic-wand-maps
manud99 Jun 27, 2024
208e50c
Reverse adding field imgFun to MagicWandSnapshot.
manud99 Jun 27, 2024
90a42f9
Remove inverse functions.
manud99 Jun 28, 2024
2865e94
Rename test files.
manud99 Jun 28, 2024
8ac2fb8
Fix quantified magic wands and update documentation of `summarizeDefi…
manud99 Jun 30, 2024
b5ae0ba
Update silver.
manud99 Jun 30, 2024
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 src/main/scala/decider/TermToSMTLib2Converter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class TermToSMTLib2Converter
parens(text("let") <+> parens(docBindings) <+> render(body))

case MagicWandSnapshot(mwsf) => render(mwsf)
case MWSFLookup(mwsf, snap) => renderApp("MWSF_apply", Seq(mwsf, snap), sorts.Snap)
case MWSFApply(mwsf, snap) => renderApp("MWSF_apply", Seq(mwsf, snap), sorts.Snap)

case _: MagicWandChunkTerm
| _: Quantification =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/decider/TermToZ3APIConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class TermToZ3APIConverter
case Let(bindings, body) =>
convert(body.replace(bindings))

case MWSFLookup(mwsf, snap) => createApp("MWSF_apply", Seq(mwsf, snap), sorts.Snap)
case MWSFApply(mwsf, snap) => createApp("MWSF_apply", Seq(mwsf, snap), sorts.Snap)

case _: MagicWandChunkTerm
| _: Quantification =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/rules/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ object evaluator extends EvaluationRules {
if (pos.end.isEmpty) {
fallbackName
} else {
val file = pos.file.toString()
val file = pos.file.getFileName.toString
val end = pos.end.get
s"$file@${pos.start.line}@${pos.start.column}@${end.line}@${end.column}"
}
Expand Down
347 changes: 231 additions & 116 deletions src/main/scala/rules/MagicWandSupporter.scala

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/scala/state/Chunks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ case class QuantifiedMagicWandChunk(id: MagicWandIdentifier,
hints: Seq[Term] = Nil)
extends QuantifiedBasicChunk {

require(wsf.sort.isInstanceOf[terms.sorts.PredicateSnapFunction] && wsf.sort.asInstanceOf[terms.sorts.PredicateSnapFunction].codomainSort == sorts.Snap, s"Quantified magic wand chunk values must be of sort MagicWandSnapFunction ($wsf), but found ${wsf.sort}")
require(wsf.sort.isInstanceOf[terms.sorts.PredicateSnapFunction] && wsf.sort.asInstanceOf[terms.sorts.PredicateSnapFunction].codomainSort == sorts.Snap, s"Quantified magic wand chunk values must be of sort Snap ($wsf), but found ${wsf.sort}")
require(perm.sort == sorts.Perm, s"Permissions $perm must be of sort Perm, but found ${perm.sort}")

override val resourceID = MagicWandID
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/state/Identifiers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ sealed trait Identifier {
withSuffix(Identifier.defaultSeparator, suffix)

def withSuffix(separator: String, suffix: String): SuffixedIdentifier

override def equals(obj: Any): Boolean =
obj match {
case that: Identifier => this.toString == that.toString
case _ => false
}
}

/* TODO: Remove object Identifier, make concrete identifiers' constructors private, and force all
Expand Down
21 changes: 6 additions & 15 deletions src/main/scala/state/Terms.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2315,15 +2315,6 @@ class MagicWandSnapshot(val mwsf: Term) extends Term with ConditionalFlyweight[T
override lazy val toString = s"wandSnap($mwsf)"

override val equalityDefiningMembers: Term = mwsf

/**
* Apply the given snapshot of the left-hand side to the magic wand map to get the snapshot of the right-hand side
* which includes the values of the left-hand side.
*
* @param snapLhs The snapshot of the left-hand side that should be applied to the magic wand map.
* @return The snapshot of the right-hand side that preserves the values of the left-hand side.
*/
def applyToMWSF(snapLhs: Term): Term = MWSFLookup(mwsf, snapLhs)
}

object MagicWandSnapshot extends PreciseCondFlyweightFactory[Term, MagicWandSnapshot] {
Expand All @@ -2339,24 +2330,24 @@ object MagicWandSnapshot extends PreciseCondFlyweightFactory[Term, MagicWandSnap
* @param mwsf Term of sort [[sorts.MagicWandSnapFunction]]. Function from `Snap` to `Snap`.
* @param snap Term of sort [[sorts.Snap]] to which the MWSF is applied to. It represents the values of the wand's LHS.
*/
class MWSFLookup(val mwsf: Term, val snap: Term) extends Term with ConditionalFlyweightBinaryOp[MWSFLookup] {
class MWSFApply(val mwsf: Term, val snap: Term) extends Term with ConditionalFlyweightBinaryOp[MWSFApply] {
val sort: Sort = sorts.Snap
override def p0: Term = mwsf
override def p1: Term = snap
override lazy val toString = s"$mwsf[$snap]"
}

object MWSFLookup extends PreciseCondFlyweightFactory[(Term, Term), MWSFLookup] {
override def apply(pair: (Term, Term)): MWSFLookup = {
object MWSFApply extends PreciseCondFlyweightFactory[(Term, Term), MWSFApply] {
override def apply(pair: (Term, Term)): MWSFApply = {
val (mwsf, snap) = pair
utils.assertSort(mwsf, "mwsf", sorts.MagicWandSnapFunction)
utils.assertSort(snap, "snap", sorts.Snap)
createIfNonExistent(pair)
}

/** Create an instance of [[viper.silicon.state.terms.MWSFLookup]]. */
override def actualCreate(args: (Term, Term)): MWSFLookup =
new MWSFLookup(args._1, args._2)
/** Create an instance of [[viper.silicon.state.terms.MWSFApply]]. */
override def actualCreate(args: (Term, Term)): MWSFApply =
new MWSFApply(args._1, args._2)
}

class MagicWandChunkTerm(val chunk: MagicWandChunk) extends Term with ConditionalFlyweight[MagicWandChunk, MagicWandChunkTerm] {
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/state/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ package object utils {
case PredicatePermLookup(_, pm, args) => Seq(pm) ++ args
case FieldTrigger(_, fvf, at) => fvf :: at :: Nil
case PredicateTrigger(_, psf, args) => psf +: args

case MagicWandSnapshot(mwsf) => mwsf :: Nil
}

/** @see [[viper.silver.ast.utility.Simplifier.simplify]] */
Expand Down Expand Up @@ -197,7 +197,7 @@ package object utils {
case MapDomain(t) => MapDomain(go(t))
case MapRange(t) => MapRange(go(t))
case MagicWandSnapshot(t) => MagicWandSnapshot(go(t))
case MWSFLookup(t0, t1) => MWSFLookup(go(t0), go(t1))
case MWSFApply(t0, t1) => MWSFApply(go(t0), go(t1))
case Combine(t0, t1) => Combine(go(t0), go(t1))
case First(t) => First(go(t))
case Second(t) => Second(go(t))
Expand Down
Loading