-
Notifications
You must be signed in to change notification settings - Fork 109
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
Automatically add loop guards without preconditions as invariants #887
Conversation
We can check the encoded Viper of the first encoding of `G` and `B1`, before the loop
004315f
to
1b9ed1a
Compare
The check for |
I think this approach is too hacky. We generate stuff (the invariant) then figure out if what we generated fits into a particular shape (a "pure" invariant). It might also be a bit unpredictable as far as the user is concerned. |
@Aurel300 maybe you saw the version from the first commit, but the second one 1b9ed1a fixes the issue with unnecessarily generating stuff. The way it now works is that we generate (line by line): g = G
if (g) {
B1
exhale I
// ... havoc local variables modified in G, B1, or B2
// Check if the above generated G and B1 have preconditions
// Only generate if yes:
g = G
assume g
B1
// Continue as normal
inhale I
... There is no looking back at what we generated anymore. |
What I'm referring to is that you walk the generated VIR at all, and figure out which functions were called based on matching |
I agree with this; it's the same issue that we have with the fold-unfold pass. A consequence is that the "it requires the viper preconditions: ..." messages in this PR are going to be as unreadable as the current fold-unfold errors are. The difference is that fold-unfold errors are always bugs of some kind, so the user is not supposed to see them in the long term, while these loop invariant warnings only exist to help the user, so they should be fully understandable.
Either that, or |
Compared to not unrolling if we run into an assert
It seems that with |
And report them in the warning
bors r+ |
901: NFM22 examples r=Aurel300 a=Aurel300 This is to allow linking the examples online from the paper. PRs to be done before the deadline: - [x] #686 - [x] #882 - [x] #887 - [x] #899 972: Fix slice with range encoding r=JonasAlaif a=JonasAlaif Fixes #960 Issue is described there. Not sure if this is the correct way to do the error reporting? It would be really nice to just have a contract for `index` and `index_mut` and report the error as a precondition violation of those. E.g. I really don't want to hardcode the pledge required for `index_mut` by hand. Co-authored-by: Aurel Bílý <aurel.bily@gmail.com> Co-authored-by: Jonas <jonas.fiala.cardiff@gmail.com>
Currently, when encoding loops:
Prusti will translate this into the Viper:
We can try to assume the loop guard by adding the following:
This works great, except for when
G
orB1
includeexhale
/assert
statements (including function calls with preconditions). In such a case, these statements would very likely fail (everything has been havoced, and we have-not/cannot yet assume the invariant) resulting in an unavoidable verification failure. The solution I take is to use encoding2
if we find no such preconditions, and otherwise fall back to encoding1
with a warning to the user.Fixes #448, fixes #995