pub struct GhostPersistentSubmap<K, V> { /* private fields */ }Expand description
A resource representing duplicable client knowledge of a persistent submap.
The existence of a GhostPersistentSubmap implies that:
- Those keys will remain in the map, pointing to the same values, forever;
- All other
GhostSubmap/GhostPointsTo/GhostPersistentSubmap/GhostPersistentPointsToare disjoint subsets of the domain
Implementations§
Source§impl<K, V> GhostPersistentSubmap<K, V>
impl<K, V> GhostPersistentSubmap<K, V>
Sourcepub open spec fn is_points_to(self) -> bool
pub open spec fn is_points_to(self) -> bool
{
&&& self@.len() == 1
&&& self.dom().finite()
&&& !self@.is_empty()
}Checks whether the GhostPersistentSubmap refers to a single key (and thus can be converted to a
GhostPersistentPointsTo).
Sourcepub open spec fn dom(self) -> Set<K>
pub open spec fn dom(self) -> Set<K>
{ self@.dom() }Domain of the GhostPersistentSubmap
Sourcepub open spec fn spec_index(self, key: K) -> V
pub open spec fn spec_index(self, key: K) -> V
self.dom().contains(key),{ self@[key] }Indexing operation submap[key]
Sourcepub proof fn dummy() -> tracked result : GhostPersistentSubmap<K, V>
pub proof fn dummy() -> tracked result : GhostPersistentSubmap<K, V>
Instantiate a dummy GhostPersistentSubmap
Sourcepub proof fn empty(id: int) -> tracked result : GhostPersistentSubmap<K, V>
pub proof fn empty(id: int) -> tracked result : GhostPersistentSubmap<K, V>
result.id() == id,result@ == Map::<K, V>::empty(),Instantiate an empty GhostPersistentSubmap of a particular id
Sourcepub proof fn duplicate(tracked &mut self) -> tracked result : GhostPersistentSubmap<K, V>
pub proof fn duplicate(tracked &mut self) -> tracked result : GhostPersistentSubmap<K, V>
self.id() == result.id(),old(self).id() == self.id(),old(self)@ == self@,result@ == self@,Duplicate the GhostPersistentSubmap
Sourcepub proof fn agree(tracked self: &GhostPersistentSubmap<K, V>, tracked auth: &GhostMapAuth<K, V>)
pub proof fn agree(tracked self: &GhostPersistentSubmap<K, V>, tracked auth: &GhostMapAuth<K, V>)
self.id() == auth.id(),ensuresself@ <= auth@,Agreement between a GhostPersistentSubmap and a corresponding GhostMapAuth
Verus might not have full context of the GhostMapAuth and a corresponding GhostPersistentSubmap.
However, whenever we know that they refer to the same resource (i.e., have matching ids) we
can assert that the GhostPersistentSubmap is a submap of the GhostMapAuth.
proof fn test(tracked &auth: GhostMapAuth<int, int>, tracked &sub: GhostPersistentSubmap<int, int>)
requires
auth.id() == sub.id(),
sub.dom().contains(1int),
sub[1int] == 1int,
ensures
auth[1int] == 1int
{
sub.agree(auth);
assert(sub@ <= auth@);
assert(auth[1int] == 1int);
}Sourcepub proof fn combine(tracked &mut self, tracked other: GhostPersistentSubmap<K, V>)
pub proof fn combine(tracked &mut self, tracked other: GhostPersistentSubmap<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@.union_prefer_right(other@),old(self)@.agrees(other@),Combining two GhostPersistentSubmaps is possible.
We consume the input GhostPersistentSubmap and merge it into the first.
We also learn that they agreed
Sourcepub proof fn combine_points_to(tracked &mut self, tracked other: GhostPersistentPointsTo<K, V>)
pub proof fn combine_points_to(tracked &mut self, tracked other: GhostPersistentPointsTo<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@.insert(other.key(), other.value()),old(self)@.contains_key(other.key()) ==> old(self)@[other.key()] == other.value(),Combining a GhostPersistentPointsTo into GhostPersistentSubmap is possible, in a similar way to the way to combine
GhostPersistentSubmaps.
Sourcepub proof fn disjoint(tracked &mut self, tracked other: &GhostSubmap<K, V>)
pub proof fn disjoint(tracked &mut self, tracked other: &GhostSubmap<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,self@.dom().disjoint(other@.dom()),When we have a GhostPersistentSubmap and a GhostSubmap we can prove that they have disjoint domains.
Sourcepub proof fn intersection_agrees(tracked &mut self, tracked other: &GhostPersistentSubmap<K, V>)
pub proof fn intersection_agrees(tracked &mut self, tracked other: &GhostPersistentSubmap<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,self@.agrees(other@),When we have two GhostPersistentSubmaps we can prove that they agree on their intersection.
Sourcepub proof fn disjoint_points_to(tracked &mut self, tracked other: &GhostPointsTo<K, V>)
pub proof fn disjoint_points_to(tracked &mut self, tracked other: &GhostPointsTo<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,!self@.contains_key(other.key()),When we have a GhostPersistentSubmap and a GhostPointsTo we can prove that they are in disjoint
domains.
Sourcepub proof fn intersection_agrees_points_to(tracked
&mut self,
tracked other: &GhostPersistentPointsTo<K, V>,
)
pub proof fn intersection_agrees_points_to(tracked &mut self, tracked other: &GhostPersistentPointsTo<K, V>, )
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,self@.contains_key(other.key()) ==> self@[other.key()] == other.value(),When we have a GhostPersistentSubmap and a GhostPersistentPointsTo,
we can prove that either they are disjoint domains or the key-value pair is in the
persistent submap.
Sourcepub proof fn split(tracked &mut self, s: Set<K>) -> tracked result : GhostPersistentSubmap<K, V>
pub proof fn split(tracked &mut self, s: Set<K>) -> tracked result : GhostPersistentSubmap<K, V>
s <= old(self)@.dom(),ensuresself.id() == old(self).id(),result.id() == self.id(),old(self)@ == self@.union_prefer_right(result@),result@.dom() =~= s,self@.dom() =~= old(self)@.dom() - s,We can split a GhostPersistentSubmap based on a set of keys in its domain.
Sourcepub proof fn split_points_to(tracked &mut self, k: K) -> tracked result : GhostPersistentPointsTo<K, V>
pub proof fn split_points_to(tracked &mut self, k: K) -> tracked result : GhostPersistentPointsTo<K, V>
old(self)@.contains_key(k),ensuresself.id() == old(self).id(),result.id() == self.id(),old(self)@ == self@.insert(result.key(), result.value()),result.key() == k,self@.dom() =~= old(self)@.dom().remove(k),We can separate a single key out of a GhostPersistentSubmap
Sourcepub proof fn points_to(tracked self) -> tracked r : GhostPersistentPointsTo<K, V>
pub proof fn points_to(tracked self) -> tracked r : GhostPersistentPointsTo<K, V>
self.is_points_to(),ensuresself@ == map![r.key() => r.value()],self.id() == r.id(),Convert a GhostPersistentSubmap into a GhostPersistentPointsTo