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

Add support for transitive modifies clause #3372

Open
celinval opened this issue Jul 23, 2024 · 1 comment
Open

Add support for transitive modifies clause #3372

celinval opened this issue Jul 23, 2024 · 1 comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. Z-Contracts Issue related to code contracts

Comments

@celinval
Copy link
Contributor

Requested feature: Enable contracts for functions that modify memory via encapsulated pointer.
Use case: Kani contracts require that all writeable memory to be specified. However, they may not be visible in the current context
Link to relevant documentation (Rust reference, Nomicon, RFC):

Test case:

mod heap {
#[derive(Default)]
pub struct HeapArray<T, const N: usize> {
  inner: Box<[T; N]>,
}

impl<T, const N: usize> HeapArray<T, N> {
  pub fn set(&mut self, val: T, idx: usize) {
  }
}
}

mod other {
  struct Stack<T> {
     buf: HeapArray,
     next: usize,
  }

  impl<T> Stack<T> {
    #[modifies(buf)] // This is not enough today
    #[kani::ensures(|_| self.contains(val))]
    fn enqueue(&mut self, val: T) {
      assert!(!self.is_full());
      self.buf.set(val, next);
    }
  }
}
@celinval celinval added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Jul 23, 2024
@celinval celinval added this to the Function Contracts milestone Jul 25, 2024
@celinval
Copy link
Contributor Author

A good example here is Arc, which contains a pointer to an ArcInner which includes the object itself, but also an atomic counter which is changed in get_mut.

@tautschnig tautschnig added the Z-Contracts Issue related to code contracts label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. Z-Contracts Issue related to code contracts
Projects
None yet
Development

No branches or pull requests

2 participants