pub struct OwnedClosureBlock { /* private fields */ }Expand description
Owning handle for a raw TypedClosureHeader block paired with its layout.
§Closure spec §14.6 (H6.5)
Wraps a *const TypedClosureHeader returned by
alloc_typed_closure alongside the Arc<ClosureLayout> needed to
decode/release its captures. Clone bumps the block’s refcount via
retain_typed_closure; Drop decrements via
release_typed_closure so ownership mirrors the Arc<HeapValue>
convention used by every other heap-backed value.
The raw pointer is stashed as *const u8 internally (erased) because
TypedClosureHeader is !Send + !Sync; the owner’s manual
unsafe impl Send + Sync is justified by the fact that the block
itself is immutable (refcount aside) and the layout is already Send + Sync via Arc.
§Safety invariant
For every live OwnedClosureBlock, ptr was allocated by
alloc_typed_closure with the exact layout carried in this owner,
and the block is refcount-owned by this instance.
Implementations§
Source§impl OwnedClosureBlock
impl OwnedClosureBlock
Sourcepub unsafe fn from_raw(ptr: *const u8, layout: Arc<ClosureLayout>) -> Self
pub unsafe fn from_raw(ptr: *const u8, layout: Arc<ClosureLayout>) -> Self
Construct an OwnedClosureBlock from a freshly-allocated raw
pointer. The caller transfers exactly one refcount share.
§Safety
ptrmust have been returned byalloc_typed_closurewith the exactlayoutpassed in here.- The caller must not call
release_typed_closureonptrindependently —Droptakes over that responsibility.
Sourcepub fn as_ptr(&self) -> *const u8
pub fn as_ptr(&self) -> *const u8
Borrow the underlying raw pointer. The returned pointer is live for
at least as long as self.
Sourcepub fn as_header_ptr(&self) -> *const TypedClosureHeader
pub fn as_header_ptr(&self) -> *const TypedClosureHeader
Borrow the underlying raw pointer typed as TypedClosureHeader.
Sourcepub fn layout(&self) -> &Arc<ClosureLayout>
pub fn layout(&self) -> &Arc<ClosureLayout>
Borrow the layout that describes this block’s captures. Shared with
the program’s closure_function_layouts side-table; clones are
cheap Arc bumps.
Sourcepub unsafe fn read_capture_kinded(&self, idx: usize) -> (u64, NativeKind)
pub unsafe fn read_capture_kinded(&self, idx: usize) -> (u64, NativeKind)
Read capture idx’s raw 8-byte payload paired with its
NativeKind from the layout’s per-capture kind track (ADR-006
§2.7.8 / Q10).
This is the cell-bound mirror of the §2.7.7 stack-side
read_owned_kinded accessor: returns (bits, kind) lockstep so
the caller can route through clone_with_kind /
drop_with_kind (the canonical KindedSlot dispatch) without
reconstructing the kind from the slot bits or probing a tag.
For Immutable captures the returned bits are the raw payload
bit pattern (e.g. f64::to_bits(v), Arc::into_raw::<T> raw
pointer) and kind classifies it directly.
For OwnedMutable and Shared captures the returned bits are
the raw cell pointer (*mut T from Box::into_raw or *const SharedCell from Arc::into_raw); kind classifies the cell’s
interior payload — the same shape capture_inner_kind
resolves to at the FieldKind level, but lifted to NativeKind
so heap-bearing interior payloads dispatch through the same
table the stack-tier uses. Wave-β B6-variables-loadptr consumes
this accessor to migrate the Load*Ptr / Store*Ptr handlers off
NotImplemented(SURFACE).
§Safety
The block’s captures area for idx must have been initialised
(zero-initialised by alloc_typed_closure and then written by
the make-closure init stage). The 8-byte read is always
in-bounds because the layout rounds total size up to 8-byte
alignment and idx < layout.capture_count().
§Panics
Panics if idx >= self.layout.capture_count().