Skip to content

Commit b7b5950

Browse files
authored
Fixing invalid Boogie code for quantified predicates without parameters (#541)
1 parent f7e0a9a commit b7b5950

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

silver

src/main/scala/viper/carbon/modules/impls/QuantifiedPermModule.scala

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ class QuantifiedPermModule(val verifier: Verifier)
743743
//for each argument, define the second inverse function
744744
val eqExpr = (argsInv zip freshFormalBoogieVars).map(x => x._1 === x._2)
745745
val conjoinedInverseAssumptions = eqExpr.foldLeft(TrueLit():Exp)((soFar,exp) => BinExp(soFar,And,exp))
746-
val invAssm2 = Forall(freshFormalBoogieDecls, Trigger(invFunApps), ((condInv && permGt(permInv, noPerm)) && rangeFunApp) ==> conjoinedInverseAssumptions)
746+
val invAssm2 = MaybeForall(freshFormalBoogieDecls, Trigger(invFunApps), ((condInv && permGt(permInv, noPerm)) && rangeFunApp) ==> conjoinedInverseAssumptions)
747747

748748
//check that the permission expression is non-negative for all predicates/wands satisfying the condition
749-
val permPositive = Assert(Forall(freshFormalBoogieDecls, Trigger(invFunApps), (condInv && rangeFunApp) ==> permissionPositive(permInv, true)),
749+
val permPositive = Assert(MaybeForall(freshFormalBoogieDecls, Trigger(invFunApps), (condInv && rangeFunApp) ==> permissionPositive(permInv, true)),
750750
error.dueTo(reasons.NegativePermission(perms)))
751751

752752
//check that sufficient permission is held
@@ -788,7 +788,7 @@ class QuantifiedPermModule(val verifier: Verifier)
788788

789789
//trigger:
790790
val triggerForPermissionUpdateAxioms = Seq(Trigger(currentPermission(qpMask,translateNull, general_location)) /*,Trigger(currentPermission(mask, translateNull, general_location)),Trigger(invFunApp)*/ )
791-
val permissionsMap = Assume(Forall(freshFormalBoogieDecls,triggerForPermissionUpdateAxioms, ((condInv && (permGt(permInv, noPerm)) && rangeFunApp) ==> (conjoinedInverseAssumptions && (currentPermission(qpMask,translateNull, general_location) === currentPermission(translateNull, general_location) - permInv)))))
791+
val permissionsMap = Assume(MaybeForall(freshFormalBoogieDecls,triggerForPermissionUpdateAxioms, ((condInv && (permGt(permInv, noPerm)) && rangeFunApp) ==> (conjoinedInverseAssumptions && (currentPermission(qpMask,translateNull, general_location) === currentPermission(translateNull, general_location) - permInv)))))
792792

793793
//Assume no change for independent locations: different predicate/wand or different resource type
794794
val obj = LocalVarDecl(Identifier("o"), refType)
@@ -804,7 +804,7 @@ class QuantifiedPermModule(val verifier: Verifier)
804804
((obj.l !== translateNull) || isDifferentFieldType || hasWrongId) ==>
805805
(currentPermission(obj.l,field.l) === currentPermission(qpMask,obj.l,field.l))))
806806
//same resource, but not satisfying the condition
807-
val independentResource = Assume(Forall(freshFormalBoogieDecls, triggerForPermissionUpdateAxioms, ((condInv && (permGt(permInv, noPerm)) && rangeFunApp).not) ==> (currentPermission(qpMask,translateNull, general_location) === currentPermission(translateNull, general_location))))
807+
val independentResource = Assume(MaybeForall(freshFormalBoogieDecls, triggerForPermissionUpdateAxioms, ((condInv && (permGt(permInv, noPerm)) && rangeFunApp).not) ==> (currentPermission(qpMask,translateNull, general_location) === currentPermission(translateNull, general_location))))
808808

809809

810810
//AS: TODO: it would be better to use the Boogie representation of a predicate/wand instance as the canonical representation here (i.e. the function mapping to a field in the Boogie heap); this would avoid the disjunction of arguments used below. In addition, this could be used as a candidate trigger in tr1 code above. See issue 242
@@ -1295,7 +1295,7 @@ class QuantifiedPermModule(val verifier: Verifier)
12951295
//for each argument, define the second inverse function
12961296
val eqExpr = (argsInv zip freshFormalBoogieVars).map(x => x._1 === x._2)
12971297
val conjoinedInverseAssumptions = eqExpr.foldLeft(TrueLit():Exp)((soFar,exp) => BinExp(soFar,And,exp))
1298-
val invAssm2 = Forall(freshFormalBoogieDecls, Trigger(invFunApps), ((condInv && permGt(permInv, noPerm)) && rangeFunApp) ==> conjoinedInverseAssumptions)
1298+
val invAssm2 = MaybeForall(freshFormalBoogieDecls, Trigger(invFunApps), ((condInv && permGt(permInv, noPerm)) && rangeFunApp) ==> conjoinedInverseAssumptions)
12991299

13001300
//define arguments needed to describe map updates
13011301
val general_location = accPred match {
@@ -1323,19 +1323,13 @@ class QuantifiedPermModule(val verifier: Verifier)
13231323
val permissionsMap = Assume(
13241324
{
13251325
val exp = ((condInv && permGt(permInv, noPerm)) && rangeFunApp) ==> ((permGt(permInv, noPerm) ==> conjoinedInverseAssumptions) && (currentPermission(qpMask,translateNull, general_location) === currentPermission(translateNull, general_location) + permInv))
1326-
if (freshFormalBoogieDecls.isEmpty)
1327-
exp
1328-
else
1329-
Forall(freshFormalBoogieDecls,triggerForPermissionUpdateAxioms, exp)
1326+
MaybeForall(freshFormalBoogieDecls,triggerForPermissionUpdateAxioms, exp)
13301327
})
13311328
//assumptions for predicates/wands of the same type which do not gain permission
13321329
val independentResource = Assume(
13331330
{
13341331
val exp = (((condInv && permGt(permInv, noPerm)) && rangeFunApp).not) ==> (currentPermission(qpMask,translateNull, general_location) === currentPermission(translateNull, general_location))
1335-
if (freshFormalBoogieDecls.isEmpty)
1336-
exp
1337-
else
1338-
Forall(freshFormalBoogieDecls, triggerForPermissionUpdateAxioms, exp)
1332+
MaybeForall(freshFormalBoogieDecls, triggerForPermissionUpdateAxioms, exp)
13391333
})
13401334

13411335
/*

0 commit comments

Comments
 (0)