pub struct GhostSubmap<K, V> { /* private fields */ }Expand description
A resource that asserts client ownership of a submap.
The existence of a GhostSubmap implies that:
- Those keys will remain in the map (unless the onwer of the
GhostSubmapdeletes it usingGhostMapAuth::delete); - Those keys will remain pointing to the same values (unless the onwer of the
GhostSubmapupdates them usingGhostSubmap::update) - All other
GhostSubmap/GhostPointsTo/GhostPersistentSubmap/GhostPersistentPointsToare disjoint subsets of the domain
Implementations§
Source§impl<K, V> GhostSubmap<K, V>
impl<K, V> GhostSubmap<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 GhostSubmap refers to a single key (and thus can be converted to a
GhostPointsTo).
Sourcepub open spec fn dom(self) -> Set<K>
pub open spec fn dom(self) -> Set<K>
{ self@.dom() }Domain of the GhostSubmap
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 : GhostSubmap<K, V>
pub proof fn dummy() -> tracked result : GhostSubmap<K, V>
Instantiate a dummy GhostSubmap
Sourcepub proof fn empty(id: int) -> tracked result : GhostSubmap<K, V>
pub proof fn empty(id: int) -> tracked result : GhostSubmap<K, V>
result.id() == id,result@ == Map::<K, V>::empty(),Instantiate an empty GhostSubmap of a particular id
Sourcepub proof fn take(tracked &mut self) -> tracked result : GhostSubmap<K, V>
pub proof fn take(tracked &mut self) -> tracked result : GhostSubmap<K, V>
old(self).id() == self.id(),self@.is_empty(),result == *old(self),result.id() == self.id(),Extract the GhostSubmap from a mutable reference, leaving behind an empty map.
Sourcepub proof fn agree(tracked self: &GhostSubmap<K, V>, tracked auth: &GhostMapAuth<K, V>)
pub proof fn agree(tracked self: &GhostSubmap<K, V>, tracked auth: &GhostMapAuth<K, V>)
self.id() == auth.id(),ensuresself@ <= auth@,Agreement between a GhostSubmap and a corresponding GhostMapAuth
Verus might not have full context of the GhostMapAuth and a corresponding GhostSubmap.
However, whenever we know that they refer to the same resource (i.e., have matching ids) we
can assert that the GhostSubmap is a submap of the GhostMapAuth.
proof fn test(tracked &auth: GhostMapAuth<int, int>, tracked &sub: GhostSubmap<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: GhostSubmap<K, V>)
pub proof fn combine(tracked &mut self, tracked other: GhostSubmap<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@.union_prefer_right(other@),old(self)@.dom().disjoint(other@.dom()),Combining two GhostSubmaps is possible.
We consume the input GhostSubmap and merge it into the first.
We also learn that they were disjoint.
Sourcepub proof fn combine_points_to(tracked &mut self, tracked other: GhostPointsTo<K, V>)
pub proof fn combine_points_to(tracked &mut self, tracked other: GhostPointsTo<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()),Combining a GhostPointsTo into GhostSubmap is possible, in a similar way to the way to combine
GhostSubmaps.
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 two GhostSubmaps we can prove that they have disjoint domains.
Sourcepub proof fn disjoint_persistent(tracked &mut self, tracked other: &GhostPersistentSubmap<K, V>)
pub proof fn disjoint_persistent(tracked &mut self, tracked other: &GhostPersistentSubmap<K, V>)
old(self).id() == other.id(),ensuresself.id() == old(self).id(),self@ == old(self)@,self@.dom().disjoint(other@.dom()),When we have a GhostSubmap and a GhostPersistentSubmap we can prove that they are in disjoint
domains.
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 GhostSubmap and a GhostPointsTo we can prove that they are in disjoint
domains.
Sourcepub proof fn disjoint_persistent_points_to(tracked
&mut self,
tracked other: &GhostPersistentPointsTo<K, V>,
)
pub proof fn disjoint_persistent_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()),When we have a GhostSubmap and a GhostPersistentPointsTo we can prove that they are in disjoint
domains.
Sourcepub proof fn split(tracked &mut self, s: Set<K>) -> tracked result : GhostSubmap<K, V>
pub proof fn split(tracked &mut self, s: Set<K>) -> tracked result : GhostSubmap<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 GhostSubmap based on a set of keys in its domain.
Sourcepub proof fn split_points_to(tracked &mut self, k: K) -> tracked result : GhostPointsTo<K, V>
pub proof fn split_points_to(tracked &mut self, k: K) -> tracked result : GhostPointsTo<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 GhostSubmap
Sourcepub proof fn update(tracked &mut self, tracked auth: &mut GhostMapAuth<K, V>, m: Map<K, V>)
pub proof fn update(tracked &mut self, tracked auth: &mut GhostMapAuth<K, V>, m: Map<K, V>)
m.dom() <= old(self)@.dom(),old(self).id() == old(auth).id(),ensuresself.id() == old(self).id(),auth.id() == old(auth).id(),self@ == old(self)@.union_prefer_right(m),auth@ == old(auth)@.union_prefer_right(m),When we have both the GhostMapAuth and a GhostSubmap we can update the values for a
subset of keys in our submap.
proof fn test(tracked auth: &mut GhostMapAuth<int, int>, tracked sub: &mut GhostSubmap<int, int>)
requires
auth.id() == sub.id(),
sub.dom() == set![1int, 2int, 3int]
ensures
auth[1int] == 9int
auth[2int] == 10int
auth[3int] == 11int
{
// need to agree on the subset
sub.agree(auth);
assert(sub@ <= auth@);
sub.update(map![1int => 9int, 2int => 10int, 3int => 11int]);
}Sourcepub proof fn points_to(tracked self) -> tracked r : GhostPointsTo<K, V>
pub proof fn points_to(tracked self) -> tracked r : GhostPointsTo<K, V>
self.is_points_to(),ensuresself@ == map![r.key() => r.value()],self.id() == r.id(),Converting a GhostSubmap into a GhostPointsTo
Sourcepub proof fn persist(tracked self) -> tracked r : GhostPersistentSubmap<K, V>
pub proof fn persist(tracked self) -> tracked r : GhostPersistentSubmap<K, V>
self@ == r@,self.id() == r.id(),Convert a GhostSubmap into a GhostPersistentSubmap