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 invariants on data structures #83

Open
romac opened this issue Feb 17, 2021 · 0 comments
Open

Support invariants on data structures #83

romac opened this issue Feb 17, 2021 · 0 comments
Labels
extraction Feature or bug with the extraction phase feature Something needs to be added

Comments

@romac
Copy link
Member

romac commented Feb 17, 2021

Implement support for invariants on data structures.

Example

#[invariant(amount >= 0)]
pub struct Account {
  pub amount: u64
}

impl Account {
  #[pre(amount >= 0)] // needed for VC yielded at (1) to pass
  fn new(amount: u64) -> Account {
    Account { amount } // (1)
  }
}

The invariant is extracted as a method annotated with the Invariant flag:

case class Account(amount: UInt64) {
  @invariant
  def inv: Boolean = amount >= 0
}

Caveats:

Alternative designs:

@romac romac added extraction Feature or bug with the extraction phase feature Something needs to be added labels Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extraction Feature or bug with the extraction phase feature Something needs to be added
Projects
None yet
Development

No branches or pull requests

1 participant