Skip to content

Commit

Permalink
add spec_has to Set, Multiset
Browse files Browse the repository at this point in the history
  • Loading branch information
utaal committed Oct 13, 2024
1 parent 5841832 commit 8d76bab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
18 changes: 7 additions & 11 deletions source/rust_verify/example/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,19 +572,15 @@ proof fn uses_arrow_matches_2(t: ThisOrThat)
assert(t is That && t->v == 3);
}

#[verifier::external_body]
struct Collection {}

impl Collection {
pub spec fn spec_has(&self, v: nat) -> bool;
}

proof fn uses_spec_has(c: Collection)
proof fn uses_spec_has(s: Set<int>, ms: vstd::multiset::Multiset<int>)
requires
c has 3,
s has 3,
ms has 4,
{
assert(c has 3);
assert(c has 3 == c has 3);
assert(s has 3);
assert(s has 3 == s has 3);
assert(ms has 4);
assert(ms has 4 == ms has 4);
}

} // verus!
6 changes: 6 additions & 0 deletions source/vstd/multiset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ impl<V> Multiset<V> {
self.count(v) > 0
}

/// Predicate indicating if the set contains the given element: supports `self has a` syntax.
#[verifier::inline]
pub open spec fn spec_has(self, v: V) -> bool {
self.contains(v)
}

/// Returns a multiset containing the lower count of a given element
/// between the two sets. In other words, returns a multiset with only
/// the elements that "overlap".
Expand Down
6 changes: 6 additions & 0 deletions source/vstd/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ impl<A> Set<A> {
/// Predicate indicating if the set contains the given element.
pub spec fn contains(self, a: A) -> bool;

/// Predicate indicating if the set contains the given element: supports `self has a` syntax.
#[verifier::inline]
pub open spec fn spec_has(self, a: A) -> bool {
self.contains(a)
}

/// DEPRECATED: use =~= or =~~= instead.
/// Returns `true` if for every value `a: A`, it is either in both input sets or neither.
/// This is equivalent to the sets being actually equal
Expand Down

0 comments on commit 8d76bab

Please sign in to comment.