Skip to main content

VmClosureHandle

Struct VmClosureHandle 

Source
pub struct VmClosureHandle<'a> { /* private fields */ }
Expand description

Read-only handle to a closure’s function id, type id, and captures.

Construction is a cheap reborrow over the TypedClosureHeader block + its ClosureLayout — no allocation, no refcount traffic.

§Safety invariant

ptr must have been returned by crate::v2::closure_raw::alloc_typed_closure paired with the exact layout reference carried here, and must still be live for the borrow 'a.

Implementations§

Source§

impl<'a> VmClosureHandle<'a>

Source

pub unsafe fn raw( ptr: *const TypedClosureHeader, layout: &'a ClosureLayout, ) -> Self

Construct a handle over a raw TypedClosureHeader block.

§Safety
Source

pub fn function_id(&self) -> u32

Function table index for the closure body.

Source

pub fn type_id(&self) -> u32

ClosureTypeId for the closure’s capture layout.

Source

pub fn capture_count(&self) -> usize

Number of captures.

Source

pub fn capture_execution_bits(&self, i: usize) -> u64

Track A.1B: raw 8-byte bits for capture i as stored in the closure’s slot, without running SharedCell or OwnedMutable auto-deref.

For CaptureKind::Immutable captures this returns the ValueWord bit pattern (identical to [Self::capture_as_value]’s result).

For CaptureKind::OwnedMutable captures this returns the raw *mut ValueWord pointer bits (cast to u64).

For CaptureKind::Shared captures this returns the raw *const SharedCell pointer bits (cast to u64).

Used by the closure-call plumbing to populate frame.upvalues so the A.1B MIR opcodes (LoadOwnedMutableCapture / LoadSharedCapture etc.) can recover the underlying cell pointer via Upvalue::clone_inner_bits_for_raw_pointer_access.

§Panics

Panics if i >= self.capture_count().

Source

pub fn capture_owned_mutable_ptr(&self, i: usize) -> Option<*mut u64>

Track A.1B: raw pointer to the *mut ValueWord box cell for an OwnedMutable capture.

Returns None when capture i is not CaptureKind::OwnedMutable.

§Safety

Callers must dereference the returned pointer only for the lifetime of the borrowing handle 'a — the closure block’s refcount keeps the Box<ValueWord> allocation alive. Writing through the pointer replaces the cell’s value in place; no retain or release is needed.

Source

pub fn capture_shared_cell_ptr(&self, i: usize) -> Option<*const SharedCell>

Track A.1B: raw pointer to the *const SharedCell ( Arc<parking_lot::Mutex<ValueWord>>) for a Shared capture.

Returns None when capture i is not CaptureKind::Shared.

§Safety

The returned pointer is derived from Arc::into_raw in A.1B’s op_make_closure. Reborrowing it as &SharedCell for the lifetime of a lock() guard is sound while the handle’s 'a lives. Callers MUST acquire the mutex before reading or writing the inner ValueWord (the cell is shared across nested closures, possibly on different threads).

Source

pub fn refcount(&self) -> u32

Exact refcount on the TypedClosureHeader block — i.e. the number of live shares on the block.

Auto Trait Implementations§

§

impl<'a> Freeze for VmClosureHandle<'a>

§

impl<'a> RefUnwindSafe for VmClosureHandle<'a>

§

impl<'a> !Send for VmClosureHandle<'a>

§

impl<'a> !Sync for VmClosureHandle<'a>

§

impl<'a> Unpin for VmClosureHandle<'a>

§

impl<'a> UnsafeUnpin for VmClosureHandle<'a>

§

impl<'a> UnwindSafe for VmClosureHandle<'a>

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.