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

Clone ghost containers #1289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions creusot-contracts/src/logic/fmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,25 @@ impl<K, V: ?Sized> FMap<K, V> {
panic!()
}
}

impl<K: Clone + Copy, V: Clone + Copy> Clone for FMap<K, V> {
#[pure]
#[ensures(result == *self)]
#[trusted]
fn clone(&self) -> Self {
*self
}
}

// Having `Copy` guarantees that the operation is pure, even if we decide to change the definition of `Clone`.
impl<K: Clone + Copy, V: Clone + Copy> Copy for FMap<K, V> {}

impl<K, V: ?Sized> Invariant for FMap<K, V> {
#[predicate(prophetic)]
#[open]
#[creusot::trusted_ignore_structural_inv]
#[creusot::trusted_is_tyinv_trivial_if_param_trivial]
fn invariant(self) -> bool {
pearlite! { forall<k: K> self.contains(k) ==> inv(k) && inv(self.lookup_unsized(k)) }
}
}
22 changes: 22 additions & 0 deletions creusot-contracts/src/logic/fset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,25 @@ impl<T: ?Sized> FSet<T> {
panic!()
}
}

impl<T: Clone + Copy> Clone for FSet<T> {
#[pure]
#[ensures(result == *self)]
#[trusted]
fn clone(&self) -> Self {
*self
}
}

// Having `Copy` guarantees that the operation is pure, even if we decide to change the definition of `Clone`.
impl<T: Clone + Copy> Copy for FSet<T> {}

impl<T: ?Sized> Invariant for FSet<T> {
#[predicate(prophetic)]
#[open]
#[creusot::trusted_ignore_structural_inv]
#[creusot::trusted_is_tyinv_trivial_if_param_trivial]
fn invariant(self) -> bool {
pearlite! { forall<x: &T> self.contains(*x) ==> inv(*x) }
}
}
12 changes: 12 additions & 0 deletions creusot-contracts/src/logic/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,18 @@ impl<T> Seq<T> {
}
}

// Having `Copy` guarantees that the operation is pure, even if we decide to change the definition of `Clone`.
impl<T: Clone + Copy> Clone for Seq<T> {
#[pure]
#[ensures(result == *self)]
#[trusted]
fn clone(&self) -> Self {
*self
}
}

impl<T: Clone + Copy> Copy for Seq<T> {}

impl<T: ?Sized> Invariant for Seq<T> {
#[predicate(prophetic)]
#[open]
Expand Down
319 changes: 255 additions & 64 deletions creusot/tests/creusot-contracts/creusot-contracts.coma

Large diffs are not rendered by default.

263 changes: 139 additions & 124 deletions creusot/tests/creusot-contracts/creusot-contracts/why3session.xml

Large diffs are not rendered by default.

Binary file modified creusot/tests/creusot-contracts/creusot-contracts/why3shapes.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions creusot/tests/should_fail/bug/878.coma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions creusot/tests/should_fail/bug/specialize.coma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions creusot/tests/should_succeed/bug/final_borrows.coma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading