Skip to main content

NativeScope

Struct NativeScope 

Source
pub struct NativeScope<'c> { /* private fields */ }
Expand description

A RAII claim on the tail of NativeRootStore: records the store’s length on construction and truncates back to it on Drop.

Create one in any runtime wrapper that holds a GcRef across something that may allocate, and root every such reference through it; abi.rs, the parser interpreter and the debugger’s p EXPR all do. The type is a pointer, a usize and a PhantomData, constructed by an unsafe fn new(ctx) returning by value; root takes &self so several Rooted values can be live at once, and Rooted<'s> borrows from the scope.

The watermark is a usize index and it must stay one. The store grows — see NATIVE_ROOT_RESERVATION for why it has to — so a *mut GcRef watermark saved by an outer scope would dangle the moment an inner scope’s root() reallocs, and Drop would then publish that dangling pointer as the store’s new end. Only a scope that roots past the reservation while another is live exercises this: a_scope_survives_the_growth_its_own_roots_force and its sibling.

Implementations§

Source§

impl<'c> NativeScope<'c>

Source

pub unsafe fn new(ctx: *mut RuntimeContext) -> NativeScope<'c>

Open a scope on ctx’s native root store.

A null or unwired context is accepted: the scope has no store to claim from, so root records nothing, but it still hands back a Rooted, so the proof keeps its meaning on the defensive null-context paths. The references are unreachable from a collection that cannot happen, because a context with no store has no heap either.

§Safety

ctx must be null, or point at a live RuntimeContext that outlives this scope.

Source

pub fn root(&self, r: GcRef) -> Rooted<'_>

Root r for the rest of this scope and return the proof.

One bounds-checked store and one increment past the null test.

Source

pub fn root_count(&self) -> usize

The number of references this scope and everything nested inside it currently root.

Trait Implementations§

Source§

impl Drop for NativeScope<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'c> !RefUnwindSafe for NativeScope<'c>

§

impl<'c> !Send for NativeScope<'c>

§

impl<'c> !Sync for NativeScope<'c>

§

impl<'c> !UnwindSafe for NativeScope<'c>

§

impl<'c> Freeze for NativeScope<'c>

§

impl<'c> Unpin for NativeScope<'c>

§

impl<'c> UnsafeUnpin for NativeScope<'c>

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.