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

Slightly more complete more complete exhale #795

Merged
merged 3 commits into from
Jan 22, 2024
Merged
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
40 changes: 31 additions & 9 deletions src/main/scala/rules/MoreCompleteExhaleSupporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
relevantChunks: Seq[NonQuantifiedChunk],
resource: ast.Resource,
args: Seq[Term],
knownValue: Option[Option[Term]],
v: Verifier)
: (State, TaggedSummarisingSnapshot, Seq[Term], Term) = {

Expand Down Expand Up @@ -75,11 +76,30 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
val taggedSummarisingSnapshot =
summarisingSnapshotDefinitions
.collectFirst {
case Equals(`?s`, snap) => ReusedSummarisingSnapshot(snap)
case Equals(`?s`, snap) =>
ReusedSummarisingSnapshot(snap)
}.getOrElse({
// val ss = v.decider.appliedFresh("ss", sort, s.relevantQuantifiedVariables)
val ss = v.decider.appliedFresh("ss", sort, s.functionRecorderQuantifiedVariables())
FreshSummarisingSnapshot(ss)
knownValue match {
case Some(Some(v)) =>
ReusedSummarisingSnapshot(v)
case _ =>
val definiteAliasValue = knownValue match {
case None =>
// We have not yet checked for a definite alias
val id = ChunkIdentifier(resource, s.program)
chunkSupporter.findChunk[NonQuantifiedChunk](relevantChunks, id, args, v).map(_.snap)
case Some(v) =>
// We have checked for a definite alias and may or may not have found one.
v
}
definiteAliasValue match {
case Some(v) =>
ReusedSummarisingSnapshot(v)
case None =>
val ss = v.decider.appliedFresh("ss", sort, s.functionRecorderQuantifiedVariables())
FreshSummarisingSnapshot(ss)
}
}
})

val summarisingSnapshot = taggedSummarisingSnapshot.snapshot
Expand All @@ -97,6 +117,8 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
relevantChunks: Seq[NonQuantifiedChunk],
resource: ast.Resource,
args: Seq[Term],
knownValue: Option[Option[Term]], // None if we have not yet checked for a definite alias,
// Some(v) if we have checked and the result was v
v: Verifier)
(Q: (State, Term, Seq[Term], Term, Verifier) => VerificationResult)
: VerificationResult = {
Expand All @@ -112,7 +134,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
return Q(s, chunk.snap, Seq(), NoPerm, v)
}
}
val (s1, taggedSnap, snapDefs, permSum) = summariseOnly(s, relevantChunks, resource, args, v)
val (s1, taggedSnap, snapDefs, permSum) = summariseOnly(s, relevantChunks, resource, args, knownValue, v)

v.decider.assumeDefinition(And(snapDefs))
// v.decider.assume(PermAtMost(permSum, FullPerm())) /* Done in StateConsolidator instead */
Expand Down Expand Up @@ -150,7 +172,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
createFailure(ve, v, s)
}
} else {
summarise(s, relevantChunks, resource, args, v)((s1, snap, _, permSum, v1) =>
summarise(s, relevantChunks, resource, args, None, v)((s1, snap, _, permSum, v1) =>
v.decider.assert(IsPositive(permSum)) {
case true =>
Q(s1, snap, v1)
Expand Down Expand Up @@ -188,7 +210,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
val id = ChunkIdentifier(resource, s.program)
val relevantChunks = findChunksWithID[NonQuantifiedChunk](h.values, id).toSeq

summarise(s, relevantChunks, resource, args, v)((s1, snap, _, permSum, v1) =>
summarise(s, relevantChunks, resource, args, None, v)((s1, snap, _, permSum, v1) =>
v.decider.assert(IsPositive(permSum)) {
case true =>
Q(s1, h, Some(snap), v1)
Expand Down Expand Up @@ -291,7 +313,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {

val s0 = s.copy(functionRecorder = currentFunctionRecorder)

summarise(s0, relevantChunks.toSeq, resource, args, v)((s1, snap, _, _, v1) => {
summarise(s0, relevantChunks.toSeq, resource, args, Some(definiteAlias.map(_.snap)), v)((s1, snap, _, _, v1) => {
val condSnap = if (v1.decider.check(IsPositive(perms), Verifier.config.checkTimeout())) {
snap
} else {
Expand Down Expand Up @@ -356,7 +378,7 @@ object moreCompleteExhaleSupporter extends SymbolicExecutionRules {
v.decider.assert(totalPermTaken !== NoPerm) {
case true =>
v.decider.assume(perms === totalPermTaken)
summarise(s1, relevantChunks.toSeq, resource, args, v)((s2, snap, _, _, v1) =>
summarise(s1, relevantChunks.toSeq, resource, args, None, v)((s2, snap, _, _, v1) =>
Q(s2, updatedChunks, Some(snap), v1))
case false =>
createFailure(ve, v, s)
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/issue387/jonas_viktor.vpr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ method foo() {
!(q < i.val_int) ||
idx_into(to_domain(a.val_ref), q) <=
idx_into(to_domain(a.val_ref), i.val_int)))
//:: UnexpectedOutput(assert.failed:assertion.false, /silicon/issue/387/)

assert (unfolding acc(usize(i), write) in
(forall q: Int :: { idx_into(to_domain(a.val_ref), q) }
!(q < i.val_int) ||
Expand Down
Loading