Skip to content
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

Support Loop Invariants and Old() Syntax #127

Open
DavePearce opened this issue Oct 18, 2021 · 3 comments
Open

Support Loop Invariants and Old() Syntax #127

DavePearce opened this issue Oct 18, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@DavePearce
Copy link
Member

DavePearce commented Oct 18, 2021

(see also #60, #126)

Currently, support for loop invariants with old() syntax is broken. The minimal test case is something like this:

public export method test():
    &int p = new 1
    //
    for i in 0..1
    where *p == old(*p):
        *p = *p
    //
    assert *p == 1

Observe however, that this variation does pass:

method test(&int p):
    int n = *p
    //
    for i in 0..1
    where *p == old(*p):
        *p = *p
    //
    assert *p == n

The reason is that old(e) when used in loop invariants inside Boogie refers to the heap on entry to the method!

@DavePearce DavePearce added the bug Something isn't working label Oct 18, 2021
@DavePearce
Copy link
Member Author

Does this variation make sense?

method f(&int p):
    int n = *p
    //
    for i in 0..1
    where *p > old(*p):
        *p = *p + 1
    //
    assert *p > n

@utting
Copy link
Collaborator

utting commented Nov 12, 2021

Isn't that invariant false upon entry to the loop, before *p is updated?

@DavePearce
Copy link
Member Author

Hey Mark,

Yeah, that's what I'm pondering. What is the semantic and how do I say what I want about (i.e. that it increases on every iteration). But, I think you are right here ... the invariant probably doesn't make sense here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants