Skip to main content

Resource

Struct Resource 

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

Source

pub fn id_ghost(&self) -> Id

Get the id for this resource.

This is the same as [Self::id], but for ghost code.

Source

pub fn alloc(r: Snapshot<R>) -> Ghost<Self>

Create a new resource

§Corresponding reasoning

⊢ |=> ∃γ, Own(value, γ)

Source

pub fn new_unit(id: Id) -> Self
where R: UnitRA,

Create a unit resource for a given identifier

Source

pub fn core(&self) -> Self

Duplicate the duplicable core of a resource

Source

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, γ)

Source

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.

Source

pub fn split_off(&mut self, r: Snapshot<R>, s: Snapshot<R>) -> Self

Remove r from self and return it, leaving s in self.

Source

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, γ)

Source

pub fn join_in(&mut self, other: Self)

Same as Self::join, but put the result into self.

Source

pub fn join_shared<'a>(&'a self, other: &'a Self) -> &'a Self

Join two shared resources together.

§Corresponding reasoning

⌜a ≼ c⌝ ∧ ⌜b ≼ c⌝ ∧ Own(a, γ) ∧ Own(b, γ) ⊢ Own(c, γ)

Source

pub fn weaken(&mut self, target: Snapshot<R>)

Transforms self into target, given that target is included in self.

Source

pub fn valid_op_lemma(&mut self, other: &Self)

Validate the composition of self and other.

Source

pub fn update<U: Update<R>>(&mut self, upd: U) -> Snapshot<U::Choice>

Perform an update.

§Corresponding reasoning

⌜a ⇝ B⌝ ∧ Own(a, γ) ⊢ ∃b∈B, Own(b, γ)

Source§

impl<R: UnitRA> Resource<R>

Source

pub fn take(&mut self) -> Self

Trait Implementations§

Source§

impl<R: UnitRA> From<Resource<View<AuthViewRel<R>>>> for Fragment<R>

Source§

fn from(value: Resource<Auth<R>>) -> Self

Converts to this type from the input type.
Source§

impl<R: RA> View for Resource<R>

Source§

impl<R> Send for Resource<R>

Auto Trait Implementations§

§

impl<R> Freeze for Resource<R>

§

impl<R> RefUnwindSafe for Resource<R>
where R: RefUnwindSafe,

§

impl<R> Sync for Resource<R>
where R: Sync,

§

impl<R> Unpin for Resource<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Resource<R>

§

impl<R> UnwindSafe for Resource<R>
where R: 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, 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, 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.
Source§

impl<F> FnGhost for F