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

Avoid using a quantifier for wildcard constraints for quantified resources #817

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 */
marcoeilers marked this conversation as resolved.
Show resolved Hide resolved
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
Loading