pub struct Resource<R>(/* private fields */);Expand description
A ghost wrapper around a resource algebra.
This structure is meant to be manipulated in ghost code.
The usual usage is this:
- Create some ghost resource
- Split it into multiple parts.
This may be used to duplicate the resource if we have
self.op(self) == self. - Join these parts later. By exploiting validity of the combination, this allows one to learn information about one part from the other.
§Example
use creusot_std::{ghost::resource::Resource, logic::ra::agree::Ag, prelude::*};
let mut res: Ghost<Resource<Ag<Int>>> = Resource::alloc(snapshot!(Ag(1)));
ghost! {
let part = res.split_off(snapshot!(Ag(1)), snapshot!(Ag(1)));
// Pass `part` around, forget what it contained...
let _ = res.join_shared(&part);
// And now we remember: the only way the above worked is if `part` contained `1`!
proof_assert!(part@ == Ag(1));
};Implementations§
Source§impl<R: RA> Resource<R>
impl<R: RA> Resource<R>
Sourcepub fn id_ghost(&self) -> Id
pub fn id_ghost(&self) -> Id
Get the id for this resource.
This is the same as [Self::id], but for ghost code.
Sourcepub fn split(self, a: Snapshot<R>, b: Snapshot<R>) -> (Self, Self)
pub fn split(self, a: Snapshot<R>, b: Snapshot<R>) -> (Self, Self)
Split a resource into two parts, described by a and b.
See also Self::split_mut and Self::split_off.
§Corresponding reasoning
⌜a = b ⋅ c⌝ ∧ Own(a, γ) ⊢ Own(b, γ) ∗ Own(c, γ)
Sourcepub fn split_mut(
&mut self,
a: Snapshot<R>,
b: Snapshot<R>,
) -> (&mut Self, &mut Self)
pub fn split_mut( &mut self, a: Snapshot<R>, b: Snapshot<R>, ) -> (&mut Self, &mut Self)
Split a resource into two, and join it again once the mutable borrows are dropped.
Sourcepub fn split_off(&mut self, r: Snapshot<R>, s: Snapshot<R>) -> Self
pub fn split_off(&mut self, r: Snapshot<R>, s: Snapshot<R>) -> Self
Remove r from self and return it, leaving s in self.
Sourcepub fn join(self, other: Self) -> Self
pub fn join(self, other: Self) -> Self
Join two owned resources together.
See also Self::join_in and Self::join_shared.
§Corresponding reasoning
⌜c = a ⋅ b⌝ ∗ Own(a, γ) ∗ Own(b, γ) ⊢ Own(c, γ)
Sourcepub fn join_in(&mut self, other: Self)
pub fn join_in(&mut self, other: Self)
Same as Self::join, but put the result into self.
Join two shared resources together.
§Corresponding reasoning
⌜a ≼ c⌝ ∧ ⌜b ≼ c⌝ ∧ Own(a, γ) ∧ Own(b, γ) ⊢ Own(c, γ)
Sourcepub fn weaken(&mut self, target: Snapshot<R>)
pub fn weaken(&mut self, target: Snapshot<R>)
Transforms self into target, given that target is included in self.
Sourcepub fn valid_op_lemma(&mut self, other: &Self)
pub fn valid_op_lemma(&mut self, other: &Self)
Validate the composition of self and other.