Disallow transparent statement bodies. Check for this in the resolution phase. Add a Laurel test that expects the new diagnostic.
/-
Copyright Strata Contributors
SPDX-License-Identifier: Apache-2.0 OR MIT
-/
/-
A modifies clause CAN be placed on any procedure to generate a modifies axiom.
The modifies clause determines which references the procedure may modify.
This modifies axiom states how the in and out heap of the procedure relate.
A modifies clause is crucial on opaque procedures,
since otherwise all heap state is lost after calling them.
-/
import StrataTest.Util.TestDiagnostics
import StrataTest.Languages.Laurel.TestExamples
open StrataTest.Util
namespace Strata
namespace Laurel
def program := r"
composite Container {
var value: int
}
procedure modifyContainerOpaque(c: Container) returns (b: bool)
opaque
modifies c
{
c#value := c#value + 1;
true
};
procedure caller()
opaque
{
var c: Container := new Container;
var d: Container := new Container;
var x: int := d#value;
var b: bool := modifyContainerOpaque(c);
assert x == d#value // pass
};
// Commented out because
// Transparent assignments are not supported yet
// procedure modifyContainerTransparant(c: Container) returns (i: int)
//{
// c#value := c#value + 1;
// 7
//};
//procedure modifyContainerWithPermission1(c: Container, d: Container)
// ensures true
// modifies c
//{
// var i: int := modifyContainerTransparant(c);
//}
// TODO add wildcard support
// procedure modifyContainerWildcard(c: Container) returns (i: int)
// opaque
// modifies *
//{
// c#value := c#value + 1;
// 7
//};
//procedure modifyContainerWithoutPermission1(c: Container, d: Container)
// error: postcondition does not hold
// opaque
//{
// var i: int := modifyContainerWildcard(c)
//};
procedure modifyContainerWithoutPermission2(c: Container, d: Container)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: postcondition could not be proved
opaque
modifies d
{
c#value := 2
};
procedure modifyContainerWithoutPermission3(c: Container, d: Container)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: postcondition does not hold
opaque
modifies d
{
var i: bool := modifyContainerOpaque(c)
};
procedure multipleModifiesClauses(c: Container, d: Container, e: Container)
opaque
modifies c
modifies d
;
procedure multipleModifiesClausesCaller()
opaque
{
var c: Container := new Container;
var d: Container := new Container;
var e: Container := new Container;
var x: int := e#value;
multipleModifiesClauses(c, d, e);
assert x == e#value // pass
};
procedure newObjectDoNotCountForModifies()
opaque
{
var c: Container := new Container;
c#value := 1
};
"
#guard_msgs (drop info, error) in
#eval testInputWithOffset "ModifiesClauses" program 24 processLaurelFile
Disallow transparent statement bodies. Check for this in the resolution phase. Add a Laurel test that expects the new diagnostic.
The test T2_modifiesClauses will need to be updated to something like: