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

Recursive definitions and invariant #879

Open
jhjourdan opened this issue Oct 3, 2023 · 2 comments
Open

Recursive definitions and invariant #879

jhjourdan opened this issue Oct 3, 2023 · 2 comments
Labels
bug Something isn't working soundness Enhance soundness

Comments

@jhjourdan
Copy link
Collaborator

extern crate creusot_contracts;
use creusot_contracts::{*, invariant::{Invariant, inv}};

struct S { }

impl Invariant for S {
    #[predicate]
    #[open]
    fn invariant(self) -> bool {
        !inv(self)
    }
}

This leads to an absurd axiom.

Basically, we need to check that inv is not used (directly or not) in the definition of invariant.

Note that, for this reason, Why3 refuses recursive types with invariants:

use option.Option

type t = {
    x : option t
}
invariant { not (x = None) }

is refused by Why3.

Also, Why3 rejects the following:

use option.Option

type t 'a = {
    x : option 'a
}
invariant { not (x = None) }

type u = { y : t u }

By telling that u is not used in a strictly positive fashion in its definition (i.e., a type with an invariant has no strictly positive type parameters).

Depending on the solution we find for this bug, we may need to take into account those problems in Creusot too.

@jhjourdan jhjourdan added bug Something isn't working soundness Enhance soundness labels Oct 3, 2023
@voidc
Copy link
Collaborator

voidc commented Oct 5, 2023

Good catch! The problem also exists with an invariant like forall<x: S> false. I'm not sure what the best way to fix this is.

@xldenis
Copy link
Collaborator

xldenis commented Oct 5, 2023

The solution @jhjourdan has proposed is to remove the implicit invariant assumption in quantifiers.

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

No branches or pull requests

3 participants