Skip to content

Commit

Permalink
Reset resource cache
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed Nov 13, 2023
1 parent 5bfe0dc commit ceca6c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/scala/rules/MaskHeapSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ import viper.silicon.supporters.functions.NoopFunctionRecorder
import viper.silicon.verifier.Verifier
import viper.silver.verifier.{ErrorReason, PartialVerificationError}
import viper.silver.ast
import viper.silver.components.StatefulComponent
import viper.silver.reporter.InternalWarningMessage
import viper.silver.verifier.reasons.{InsufficientPermission, MagicWandChunkNotFound}

import scala.collection.mutable.ListBuffer
import scala.collection.{immutable, mutable}

object maskHeapSupporter extends SymbolicExecutionRules {
object maskHeapSupporter extends SymbolicExecutionRules with StatefulComponent {

val assumeGoodMask = true
val simplifyOnConsume = !Verifier.config.prover.toOption.contains("Z3-API")
val simplifyOnConsume = false // !Verifier.config.prover.toOption.contains("Z3-API")

val resCache = mutable.HashMap[(Seq[ast.Exp], ast.Program), Seq[Any]]()

override def start(): Unit = { }
override def stop(): Unit = {}
override def reset(): Unit = {
resCache.clear()
}
def getResourceSeq(tlcs: Seq[ast.Exp], program: ast.Program): Seq[Any] = {
val key = (tlcs, program)
val current = resCache.get(key)
Expand Down Expand Up @@ -741,8 +748,6 @@ object maskHeapSupporter extends SymbolicExecutionRules {
val qpMaskGet = HeapLookup(qpMask, argTerm)
val qpMaskConstraint = Forall(formalQVars, qpMaskGet === conditionalizedPermissions, Seq(Trigger(qpMaskGet)), "qpMaskdef")

v.decider.assume(qpMaskConstraint)

val resourceToFind = resource match {
case mw: ast.MagicWand => MagicWandIdentifier(mw, s.program)
case _ => resource
Expand All @@ -753,8 +758,7 @@ object maskHeapSupporter extends SymbolicExecutionRules {
case r: ast.Resource => (s.h, findMaskHeapChunk(s.h, r))
}
val newMask = MaskSum(currentChunk.mask, qpMask)
if (assumeGoodMask)
v.decider.assume(if (resource.isInstanceOf[ast.Field]) GoodFieldMask(newMask) else GoodMask(newMask))


val newHeap = MergeHeaps(currentChunk.heap, currentChunk.mask, snapHeapMap(resource), qpMask)
val (newChunk, fr0) = currentChunk.copy(newMask = newMask, v.decider, s.functionRecorder, newHeap = newHeap)
Expand Down Expand Up @@ -830,6 +834,11 @@ object maskHeapSupporter extends SymbolicExecutionRules {
v.decider.assume(FunctionPreconditionTransformer.transform(receiverInjectivityCheck, s.program))
v.decider.assert(receiverInjectivityCheck) {
case true =>
v.decider.assume(qpMaskConstraint)

if (assumeGoodMask)
v.decider.assume(if (resource.isInstanceOf[ast.Field]) GoodFieldMask(newMask) else GoodMask(newMask))

val ax = inverseFunctions.axiomInversesOfInvertibles
val inv = inverseFunctions.copy(axiomInversesOfInvertibles = Forall(ax.vars, ax.body, effectiveTriggers))

Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/verifier/DefaultMainVerifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import viper.silicon.interfaces._
import viper.silicon.interfaces.decider.ProverLike
import viper.silicon.logger.{MemberSymbExLogger, SymbExLogger}
import viper.silicon.reporting.{MultiRunRecorders, condenseToViperResult}
import viper.silicon.rules.maskHeapSupporter
import viper.silicon.state._
import viper.silicon.state.terms.{Decl, Sort, Term, sorts}
import viper.silicon.supporters._
Expand Down Expand Up @@ -85,6 +86,7 @@ class DefaultMainVerifier(config: Config,
fieldValueFunctionsContributor,
heapFunctionsContributor,
predSnapGenerator, predicateAndWandSnapFunctionsContributor,
maskHeapSupporter,
functionsSupporter, predicateSupporter,
_verificationPoolManager,
MultiRunRecorders /* In lieu of a better place, include MultiRunRecorders singleton here */
Expand Down

0 comments on commit ceca6c4

Please sign in to comment.