summaryrefslogtreecommitdiff
path: root/Test/vstte2012
diff options
context:
space:
mode:
authorGravatar Rustan Leino <unknown>2014-08-19 23:51:35 -0700
committerGravatar Rustan Leino <unknown>2014-08-19 23:51:35 -0700
commitfeedce5021404af3f08dfc23944196d2ad8ed7fc (patch)
tree7709e8987982c3c420163099c7615742c7105fc3 /Test/vstte2012
parent78e74bf9fa5ad7175cafd171427f58f556256e4a (diff)
Change behavior of 'decreases *', which can be applied to loops and methods. Now, loops that may possibly
do an infinite number of iterations (that is, loops marked with 'decreases *') and calls to methods marked with 'decreases *' are allowed only in methods that themselves are marked with 'decreases *'. As before, ghost loops and ghost methods are not allowed to be marked with 'decreases *'. Previously, 'decreases *' was allowed on a method only if the method was tail recursive; this is no longer so. Note, however, that if the method is not tail recursive and engages in infinite recursion, then it will eventually run out of stack space. Previously, a 'decreases *' was not inherited in a refining module; this is no longer so. That is, 'decreases *' is now inherited. To refine a possibly non-terminating method or loop, the refining version simply provides a decreases clause that does not mention '*'. Note that if the refined method is not recursive, it still needs to have _some_ decreases clause in order not to inherit the 'decreases *' from the refined method, but the expression stated in the decreases clause can be arbitrary (for example, one can write 'decreases true' or 'decreases 7' or 'decreases x' for some 'x' in scope). Note, in the new design, a method needs to be declared with 'decreases *' if it may recurse forever _or_ if it contains a possibly infinite loop. Note that the absence of 'decreases *' on a loop does not mean the loop will terminate, but it does mean that the loop will iterate a finite number of times (the subtle distinction here is that a loop without a 'decreases *' is allowed to contain a nested loop that has a 'decreases *' -- provided the enclosing method is also declared with 'decreases *', as previously mentioned).
Diffstat (limited to 'Test/vstte2012')
-rw-r--r--Test/vstte2012/Combinators.dfy19
1 files changed, 10 insertions, 9 deletions
diff --git a/Test/vstte2012/Combinators.dfy b/Test/vstte2012/Combinators.dfy
index 82bfc970..37f3bd68 100644
--- a/Test/vstte2012/Combinators.dfy
+++ b/Test/vstte2012/Combinators.dfy
@@ -202,25 +202,25 @@ ghost method Lemma_FindAndStep(t: Term) returns (r: Term, C: Context, u: Term)
r == EvalExpr(C, Step(u));
{
Lemma_ContextPossibilities(t);
- if (Step(t) != t) {
+ if Step(t) != t {
// t == Hole[t] and Step applies t. So, return Hole[Step(t)]
return Step(t), Hole, t;
- } else if (!t.Apply?) {
+ } else if !t.Apply? {
r := t;
} else {
r, C, u := Lemma_FindAndStep(t.car); // (*)
- if (r != t.car) {
+ if r != t.car {
// t has the form (a b) where a==t.car and b==t.cdr, and a==C[u] for some
// context C and some u to which the Step applies. t can therefore be
// denoted by (C[u] b) == (C b)[u] and the Step applies to u. So, return
// (C b)[Step(u)] == (C[Step(u)] b). Note that FindAndStep(a)
// gives C[Step(u)].
return Apply(r, t.cdr), C_term(C, t.cdr), u;
- } else if (IsValue(t.car)) {
+ } else if IsValue(t.car) {
r, C, u := Lemma_FindAndStep(t.cdr);
assert IsTerminal(t.car); // make sure this is still remembered from (*)
- if (r != t.cdr) {
+ if r != t.cdr {
// t has the form (a b) where a==t.car and b==t.cdr and "a" is a Value,
// and b==C[u] for some context C and some u to which the Step applies.
// t can therefore be denoted by (a C[u]) == (C a)[u] and the Step
@@ -305,15 +305,16 @@ method reduction(t: Term) returns (r: Term)
ensures exists trace :: IsTrace(trace, t, r);
// The result "r" cannot be reduced any further:
ensures IsTerminal(r);
+ decreases *; // allow this method to diverge
{
r := t;
ghost var trace := EmptyTrace;
- while (true)
+ while true
invariant IsTrace(trace, t, r);
decreases *; // allow this statement to loop forever
{
var u := FindAndStep(r);
- if (u == r) {
+ if u == r {
// we have found a fixpoint
Theorem_FindAndStep(r);
return;
@@ -365,13 +366,13 @@ method VerificationTask2(t: Term) returns (r: Term)
{
r := t;
ghost var trace := EmptyTrace;
- while (true)
+ while true
invariant IsTrace(trace, t, r) && !ContainsS(r);
invariant TerminatingReduction(t) == TerminatingReduction(r);
decreases TermSize(r);
{
var u := FindAndStep(r);
- if (u == r) {
+ if u == r {
// we have found a fixpoint
Theorem_FindAndStep(r);
return;