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>
impl<'a> VmClosureHandle<'a>
Sourcepub unsafe fn raw(
ptr: *const TypedClosureHeader,
layout: &'a ClosureLayout,
) -> Self
pub unsafe fn raw( ptr: *const TypedClosureHeader, layout: &'a ClosureLayout, ) -> Self
Construct a handle over a raw TypedClosureHeader block.
§Safety
ptrmust have been allocated bycrate::v2::closure_raw::alloc_typed_closurewith the samelayoutthat is passed in here.ptrmust remain live for the duration of the borrow'a.- The block’s capture slots must be initialised — each typed
width from
layoutmust contain a value thatread_capture_as_value_bitscan safely decode.
Sourcepub fn function_id(&self) -> u32
pub fn function_id(&self) -> u32
Function table index for the closure body.
Sourcepub fn capture_count(&self) -> usize
pub fn capture_count(&self) -> usize
Number of captures.
Sourcepub fn capture_execution_bits(&self, i: usize) -> u64
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().
Sourcepub fn capture_owned_mutable_ptr(&self, i: usize) -> Option<*mut u64>
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.
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).