Skip to content

Commit

Permalink
Merge pull request #817 from viperproject/meilers_avoid_qp_wildcard_c…
Browse files Browse the repository at this point in the history
…onstraint_quantifier

Avoid using a quantifier for wildcard constraints for quantified resources
  • Loading branch information
marcoeilers authored Mar 14, 2024
2 parents 3d619b8 + e87700a commit 7534570
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/scala/rules/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ object executor extends ExecutionRules {
relevantChunks,
Seq(`?r`),
`?r` === tRcvr,
Some(Seq(tRcvr)),
field,
FullPerm,
chunkOrderHeuristics,
Expand Down
20 changes: 17 additions & 3 deletions src/main/scala/rules/QuantifiedChunkSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
relevantChunks,
formalQVars,
And(condOfInvOfLoc, And(imagesOfFormalQVars)),
None,
resource,
rPerm,
chunkOrderHeuristics,
Expand Down Expand Up @@ -1192,6 +1193,7 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
relevantChunks,
formalQVars,
And(condOfInvOfLoc, And(imagesOfFormalQVars)),
None,
resource,
lossOfInvOfLoc,
chunkOrderHeuristics,
Expand Down Expand Up @@ -1259,6 +1261,7 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
relevantChunks,
codomainQVars,
And(codomainQVars.zip(arguments).map { case (r, e) => r === e }),
Some(arguments),
resource,
rPerm,
chunkOrderHeuristics,
Expand Down Expand Up @@ -1302,6 +1305,7 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
relevantChunks,
codomainQVars,
And(codomainQVars.zip(arguments).map { case (r, e) => r === e }),
Some(arguments),
resource,
permissions,
chunkOrderHeuristics,
Expand Down Expand Up @@ -1339,6 +1343,9 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
relevantChunks: Seq[QuantifiedBasicChunk],
codomainQVars: Seq[Var], /* rs := r_1, ..., r_m */
condition: Term, // c(rs)
optQVarValues: Option[Seq[Term]], /* optionally actual known values vs := v_1, ..., v_m for all codomainQVars
(if we're consuming a single location), i.e., if condition is
forall i :: r_i == v_i */
resource: ast.Resource, // field f: e_1(rs).f; or predicate P: P(es); or magic wand
perms: Term, // p(rs)
chunkOrderHeuristic: Seq[QuantifiedBasicChunk] => Seq[QuantifiedBasicChunk],
Expand Down Expand Up @@ -1409,7 +1416,7 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
else {
val (permissionConstraint, depletedCheck) =
createPermissionConstraintAndDepletedCheck(
codomainQVars, condition, perms,constrainPermissions, ithChunk, ithPTaken, v)
codomainQVars, condition, optQVarValues, perms, constrainPermissions, ithChunk, ithPTaken, v)

if (constrainPermissions) {
v.decider.prover.comment(s"Constrain original permissions $perms")
Expand Down Expand Up @@ -1459,6 +1466,7 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {

private def createPermissionConstraintAndDepletedCheck(codomainQVars: Seq[Var], /* rs := r_1, ..., r_m */
condition: Term, // c(rs)
optQVarValues: Option[Seq[Term]], /* vs := v_1, ..., v_m if c is r_1 == v_1 && ... */
perms: Term, // p(rs)
constrainPermissions: Boolean,
ithChunk: QuantifiedBasicChunk,
Expand Down Expand Up @@ -1499,8 +1507,14 @@ object quantifiedChunkSupporter extends QuantifiedChunkSupport {
(quantifiedPermissionConstraint.map(_.instantiate(args)),
quantifiedDepletedCheck.instantiate(args))
case None =>
(quantifiedPermissionConstraint,
quantifiedDepletedCheck)
optQVarValues match {
case Some(values) =>
(quantifiedPermissionConstraint.map(_.instantiate(values)),
quantifiedDepletedCheck)
case _ =>
(quantifiedPermissionConstraint,
quantifiedDepletedCheck)
}
}

(permissionConstraint.getOrElse(True), depletedCheck)
Expand Down

0 comments on commit 7534570

Please sign in to comment.