Skip to content

Commit

Permalink
Assert-read-only function preconditions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed Oct 13, 2024
1 parent 53ecf55 commit f49fee0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/main/scala/rules/QuantifiedChunkSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1526,27 +1526,21 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
v: Verifier)
: ConsumptionResult = {

var success = false
var permsAvailable: Term = NoPerm
var permsAvailableExp: Option[ast.Exp] = Option.when(withExp)(ast.NoPerm()())

var tookEnoughCheck: Term = False

for (ch <- candidates) {
if (!success) {
permsAvailable = PermPlus(permsAvailable, ch.perm)
permsAvailableExp = permsAvailableExp.map(pae => ast.PermAdd(pae, permsExp.get)())

tookEnoughCheck =
Forall(codomainQVars, Implies(condition, Implies(Greater(perms, NoPerm), Greater(permsAvailable, NoPerm))), Nil)

success = v.decider.check(tookEnoughCheck, Verifier.config.splitTimeout())
}
permsAvailable = PermPlus(permsAvailable, ch.perm)
permsAvailableExp = permsAvailableExp.map(pae => ast.PermAdd(pae, permsExp.get)())
}

val tookEnoughCheck =
Forall(codomainQVars, Implies(condition, Implies(Greater(perms, NoPerm), Greater(permsAvailable, NoPerm))), Nil)

// final check
val result =
if (success || v.decider.check(tookEnoughCheck, Verifier.config.assertTimeout.getOrElse(0)) /* This check is a must-check, i.e. an assert */ )
if (v.decider.check(tookEnoughCheck, Verifier.config.assertTimeout.getOrElse(0)) /* This check is a must-check, i.e. an assert */ )
Complete()
else
Incomplete(PermMinus(permsAvailable, perms), permsAvailableExp.map(pa => ast.PermSub(pa, permsExp.get)()))
Expand Down

0 comments on commit f49fee0

Please sign in to comment.