pub struct GhostSubset<T> { /* private fields */ }Expand description
A resource that has client ownership of a subset
The existence of a GhostSubset implies that:
- Those values will remain in the set unless ;
- Those values will remain in the set (unless the onwer of the
GhostSubsetdeletes it usingGhostSetAuth::delete); - All other
GhostSubset/GhostSingletonare disjoint from it
Implementations§
Source§impl<T> GhostSubset<T>
impl<T> GhostSubset<T>
Sourcepub open spec fn is_singleton(self) -> bool
pub open spec fn is_singleton(self) -> bool
{
&&& self@.len() == 1
&&& self@.finite()
&&& !self@.is_empty()
}Checks whether the GhostSubset refers to a single value (and thus can be converted to a
GhostSingleton).
Sourcepub proof fn dummy() -> tracked result : GhostSubset<T>
pub proof fn dummy() -> tracked result : GhostSubset<T>
Instantiate a dummy GhostSubset
Sourcepub proof fn empty(id: int) -> tracked result : GhostSubset<T>
pub proof fn empty(id: int) -> tracked result : GhostSubset<T>
result.id() == id,result@ == Set::<T>::empty(),Instantiate an empty GhostSubset of a particular id
Sourcepub proof fn take(tracked &mut self) -> tracked result : GhostSubset<T>
pub proof fn take(tracked &mut self) -> tracked result : GhostSubset<T>
old(self).id() == self.id(),self@.is_empty(),result == *old(self),result.id() == self.id(),Extract the GhostSubset from a mutable reference, leaving behind an empty map.
Sourcepub proof fn agree(tracked self: &GhostSubset<T>, tracked auth: &GhostSetAuth<T>)
pub proof fn agree(tracked self: &GhostSubset<T>, tracked auth: &GhostSetAuth<T>)
self.id() == auth.id(),ensuresself@ <= auth@,Agreement between a GhostSubset and a corresponding GhostSetAuth
Verus might not have full context of the GhostSetAuth and a corresponding GhostSubset.
However, whenever we know that they refer to the same resource (i.e., have matching ids) we
can assert that the GhostSubset is a submap of the GhostSetAuth.
proof fn test(tracked &auth: GhostSetAuth<int>, tracked &sub: GhostSubset<int>)
requires
auth.id() == sub.id(),
sub@.contains(1int),
ensures
auth@.contains(1int),
{
sub.agree(auth);
assert(sub@ <= auth@);
assert(auth.contains(1int));
}Sourcepub proof fn combine(tracked &mut self, tracked other: GhostSubset<T>)
pub proof fn combine(tracked &mut self, tracked other: GhostSubset<T>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@.union(other@),old(self)@.disjoint(other@),Combining two GhostSubsets is possible.
We consume the input GhostSubset and merge it into the first.
We also learn that they were disjoint.
Sourcepub proof fn combine_singleton(tracked &mut self, tracked other: GhostSingleton<T>)
pub proof fn combine_singleton(tracked &mut self, tracked other: GhostSingleton<T>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@.insert(other@),!old(self)@.contains(other@),Combining a GhostSingleton into GhostSubset is possible, in a similar way to the way to combine
GhostSubsets.
Sourcepub proof fn disjoint(tracked &mut self, tracked other: &GhostSubset<T>)
pub proof fn disjoint(tracked &mut self, tracked other: &GhostSubset<T>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,self@.disjoint(other@),When we have two GhostSubsets we can prove that they have disjoint domains.
Sourcepub proof fn disjoint_persistent(tracked &mut self, tracked other: &GhostPersistentSubset<T>)
pub proof fn disjoint_persistent(tracked &mut self, tracked other: &GhostPersistentSubset<T>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,self@.disjoint(other@),When we have a GhostSubset and a GhostPersistentSubset we can prove that they are in disjoint
domains.
Sourcepub proof fn disjoint_singleton(tracked &mut self, tracked other: &GhostSingleton<T>)
pub proof fn disjoint_singleton(tracked &mut self, tracked other: &GhostSingleton<T>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,!self@.contains(other@),When we have a GhostSubset and a GhostSingleton we can prove that they are in disjoint
domains.
Sourcepub proof fn disjoint_persistent_singleton(tracked
&mut self,
tracked other: &GhostPersistentSingleton<T>,
)
pub proof fn disjoint_persistent_singleton(tracked &mut self, tracked other: &GhostPersistentSingleton<T>, )
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,!self@.contains(other@),When we have a GhostSubset and a GhostPersistentSingleton we can prove that they are in disjoint
domains.
Sourcepub proof fn split(tracked &mut self, s: Set<T>) -> tracked result : GhostSubset<T>
pub proof fn split(tracked &mut self, s: Set<T>) -> tracked result : GhostSubset<T>
s <= old(self)@,ensuresself.id() == old(self).id(),result.id() == self.id(),old(self)@ == self@.union(result@),result@ =~= s,self@ =~= old(self)@ - s,We can split a GhostSubset based on a set of values
Sourcepub proof fn split_singleton(tracked &mut self, v: T) -> tracked result : GhostSingleton<T>
pub proof fn split_singleton(tracked &mut self, v: T) -> tracked result : GhostSingleton<T>
old(self)@.contains(v),ensuresself.id() == old(self).id(),result.id() == self.id(),old(self)@ == self@.insert(result@),result@ == v,self@ =~= old(self)@.remove(v),We can separate a single value out of a GhostSubset
Sourcepub proof fn singleton(tracked self) -> tracked r : GhostSingleton<T>
pub proof fn singleton(tracked self) -> tracked r : GhostSingleton<T>
self.is_singleton(),ensuresself@ == set![r @],self.id() == r.id(),Converting a GhostSubset into a GhostSingleton
Sourcepub proof fn persist(tracked self) -> tracked r : GhostPersistentSubset<T>
pub proof fn persist(tracked self) -> tracked r : GhostPersistentSubset<T>
self@ == r@,self.id() == r.id(),Converting a GhostSubset into a GhostPersistentSubset