GhostSubmap

Struct GhostSubmap 

Source
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:

Implementations§

Source§

impl<K, V> GhostSubmap<K, V>

Source

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).

Source

pub closed spec fn id(self) -> Loc

Resource location

Source

pub closed spec fn view(self) -> Map<K, V>

Logically underlying Map

Source

pub open spec fn dom(self) -> Set<K>

{ self@.dom() }

Domain of the GhostSubmap

Source

pub open spec fn spec_index(self, key: K) -> V

recommends
self.dom().contains(key),
{ self@[key] }

Indexing operation submap[key]

Source

pub proof fn dummy() -> tracked result : GhostSubmap<K, V>

Instantiate a dummy GhostSubmap

Source

pub proof fn empty(id: int) -> tracked result : GhostSubmap<K, V>

ensures
result.id() == id,
result@ == Map::<K, V>::empty(),

Instantiate an empty GhostSubmap of a particular id

Source

pub proof fn take(tracked &mut self) -> tracked result : GhostSubmap<K, V>

ensures
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.

Source

pub proof fn agree(tracked self: &GhostSubmap<K, V>, tracked auth: &GhostMapAuth<K, V>)

requires
self.id() == auth.id(),
ensures
self@ <= 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);
}
Source

pub proof fn combine(tracked &mut self, tracked other: GhostSubmap<K, V>)

requires
old(self).id() == other.id(),
ensures
self.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.

Source

pub proof fn combine_points_to(tracked &mut self, tracked other: GhostPointsTo<K, V>)

requires
old(self).id() == other.id(),
ensures
self.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.

Source

pub proof fn disjoint(tracked &mut self, tracked other: &GhostSubmap<K, V>)

requires
old(self).id() == other.id(),
ensures
self.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.

Source

pub proof fn disjoint_persistent(tracked &mut self, tracked other: &GhostPersistentSubmap<K, V>)

requires
old(self).id() == other.id(),
ensures
self.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.

Source

pub proof fn disjoint_points_to(tracked &mut self, tracked other: &GhostPointsTo<K, V>)

requires
old(self).id() == other.id(),
ensures
self.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.

Source

pub proof fn disjoint_persistent_points_to(tracked &mut self, tracked other: &GhostPersistentPointsTo<K, V>, )

requires
old(self).id() == other.id(),
ensures
self.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.

Source

pub proof fn split(tracked &mut self, s: Set<K>) -> tracked result : GhostSubmap<K, V>

requires
s <= old(self)@.dom(),
ensures
self.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.

Source

pub proof fn split_points_to(tracked &mut self, k: K) -> tracked result : GhostPointsTo<K, V>

requires
old(self)@.contains_key(k),
ensures
self.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

Source

pub proof fn update(tracked &mut self, tracked auth: &mut GhostMapAuth<K, V>, m: Map<K, V>)

requires
m.dom() <= old(self)@.dom(),
old(self).id() == old(auth).id(),
ensures
self.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]);
}
Source

pub proof fn points_to(tracked self) -> tracked r : GhostPointsTo<K, V>

requires
self.is_points_to(),
ensures
self@ == map![r.key() => r.value()],
self.id() == r.id(),

Converting a GhostSubmap into a GhostPointsTo

Source

pub proof fn persist(tracked self) -> tracked r : GhostPersistentSubmap<K, V>

ensures
self@ == r@,
self.id() == r.id(),

Convert a GhostSubmap into a GhostPersistentSubmap

Auto Trait Implementations§

§

impl<K, V> Freeze for GhostSubmap<K, V>

§

impl<K, V> RefUnwindSafe for GhostSubmap<K, V>

§

impl<K, V> Send for GhostSubmap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for GhostSubmap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for GhostSubmap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for GhostSubmap<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: From<T>,

Source§

exec fn obeys_from_spec() -> bool

Source§

exec fn from_spec(v: T) -> VERUS_SPEC__A

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: Into<T>,

Source§

exec fn obeys_into_spec() -> bool

Source§

exec fn into_spec(self) -> T

Source§

impl<T, U> IntoSpecImpl<U> for T
where U: From<T>,

Source§

open spec fn obeys_into_spec() -> bool

{ <U as FromSpec<Self>>::obeys_from_spec() }
Source§

open spec fn into_spec(self) -> U

{ U::from_spec(self) }
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.