Replies: 3 comments 4 replies
-
Re 5: that would still be ambiguous right? E.g.: while(true)
//@ loop_invariant true;
while(true) assert true; 2 also sounds nice from a perspective of simplification and preventing easy mistakes. Otherwise my preference would be 4 or 5. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Just for reference:
|
Beta Was this translation helpful? Give feedback.
3 replies
-
I think I slightly prefer only before the loop, i.e. (2). It also makes sense in the context of how side-effectful conditions are now encoded: they are executed after the invariant is established. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The following C code has a nested loop:
VerCors determines that the invariant
i<10
above the inner loop cannot be established, even though it is the condition of the outer loop.This is due to the fact that the outer loop only contains the inner loop, and thus omitted the curly braces around its body. Therefore, the invariant of the inner loop could also be interpreted as belonging to the outer loop, using the syntax
while(cond) /*@contract*/ {body}
. VerCors indeed uses this interpretation, and correctly determines that the invariant cannot be established for the outer loop.I think it's clear in this case that the invariant was meant for the inner loop: The indentation gives a clear hint, the outer loop already has a contract above, and the inner loop does not have a contract except for the ambiguous one.
There are different viewpoints on this issue:
while(cond) /*@contract*/ {body}
. In the vast majority of cases we place the contract above the loop header anyway, so let's just get rid of the other option and remove any ambiguity.while(cond) /*@contract*/ {body}
if there are curly braces around the body. If there are no curly braces, the invariant goes to the inner loop (if there is one, error if not).What do people think? Which viewpoint do you prefer?
Beta Was this translation helpful? Give feedback.
All reactions