Expand description
Raw TypedClosureHeader allocation + accessor helpers.
This module is the VM-side counterpart to the JIT’s
crate::v2::closure_layout layout definitions. It provides a stable
C-ABI-compatible way to allocate, retain, release, read, and write
TypedClosureHeader blocks without going through HeapValue::Closure.
§Closure-spec §13 H3.B.1
The H3.B migration replaces HeapValue::Closure { function_id, upvalues }
(an Arc<HeapValue> carrying a Vec<Upvalue>) with a raw
*const TypedClosureHeader block matching the JIT’s Phase H1 memory
layout. This module is the shared infrastructure both the VM’s
op_make_closure_heap and the JIT’s emit_heap_closure converge on.
H3.B.1 introduces this module and its helpers; H3.B.2 wires them into
the 20+ HeapValue::Closure consumer sites.
§Memory layout (same as closure_layout::TypedClosureHeader)
Offset Size Field
------ ---- -----
0 8 HeapHeader (refcount @ 0, kind @ 4, flags @ 6, _pad @ 7)
8 4 function_id (u32)
12 4 type_id (u32, ClosureTypeId.0)
16 N captures[] (C-laid-out per ClosureLayout)Every capture slot is 8-byte wide in practice (the layout rounds up to
8-byte alignment), but the typed width at the slot is dictated by
the FieldKind: F64/I64/U64 use 8 bytes; I32/U32 use 4;
I16/U16 use 2; I8/U8/Bool use 1; Ptr uses 8 and participates
in the heap_capture_mask retain/release cycle.
Structs§
- Closure
Cell - Kind-aware closure capture cell store (§2.7.8 / Q10).
- Owned
Closure Block - Owning handle for a raw
TypedClosureHeaderblock paired with its layout.
Functions§
- alloc_
owned_ mutable_ bool - Allocate a fresh
OwnedMutablecell holding aboolpayload. - alloc_
owned_ mutable_ f64 - Allocate a fresh
OwnedMutablecell holding anf64payload. - alloc_
owned_ mutable_ i8 - Allocate a fresh
OwnedMutablecell holding ani8payload. - alloc_
owned_ mutable_ i16 - Allocate a fresh
OwnedMutablecell holding ani16payload. - alloc_
owned_ mutable_ i32 - Allocate a fresh
OwnedMutablecell holding ani32payload. - alloc_
owned_ mutable_ i64 - Allocate a fresh
OwnedMutablecell holding ani64payload. - alloc_
owned_ mutable_ ptr - Allocate a fresh
OwnedMutablecell holding aPtrpayload. - alloc_
owned_ mutable_ u8 - Allocate a fresh
OwnedMutablecell holding au8payload. - alloc_
owned_ mutable_ u16 - Allocate a fresh
OwnedMutablecell holding au16payload. - alloc_
owned_ mutable_ u32 - Allocate a fresh
OwnedMutablecell holding au32payload. - alloc_
owned_ mutable_ u64 - Allocate a fresh
OwnedMutablecell holding au64payload. - alloc_
typed_ ⚠closure - Allocate a zero-initialised
TypedClosureHeaderblock matching the given layout. TheHeapHeaderis written withrefcount = 1,kind = HEAP_KIND_V2_CLOSURE,flags = 0. Thefunction_idandtype_idfields are written from the arguments. The captures area is zero-filled — callers are responsible for writing each capture at its typed offset viawrite_capture_raw_u64before handing the pointer out. - dealloc_
typed_ ⚠closure_ no_ drop - Deallocate a
TypedClosureHeaderblock without walking the heap-capture mask. The caller is responsible for having already consumed or released each heap-typed capture’s refcount share. - drop_
owned_ ⚠mutable_ capture - Drop the
OwnedMutablecapture at indexiof a closure block. - drop_
shared_ ⚠capture - Release a
Sharedcapture: read the cell pointer at the slot, decode the interiorFieldKind, drop any heap refcount share carried by aPtrpayload, and finallyArc::from_raw+ drop the cell to release its strong-count share. - read_
capture_ ⚠as_ value_ bits - Read a capture slot as a typed
u64bit pattern suitable forValueWord::from_raw_bits. - read_
owned_ ⚠mutable_ bool - Read the
boolpayload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ f64 - Read the
f64payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ i8 - Read the
i8payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ i16 - Read the
i16payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ i32 - Read the
i32payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ i64 - Read the
i64payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ ptr - Read the raw
u64(Ptr-shaped) payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ u8 - Read the
u8payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ u16 - Read the
u16payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ u32 - Read the
u32payload of anOwnedMutablecell. - read_
owned_ ⚠mutable_ u64 - Read the
u64payload of anOwnedMutablecell. - read_
shared_ ⚠bool - Read a
boolfrom aSharedCell’s payload —falseiff every byte of the 8-byte payload is zero,trueotherwise. (write_shared_boolstores0or1, so this is just the standard “any non-zero byte” test.) - read_
shared_ ⚠f64 - Read a
f64from aSharedCell’s payload while holding its lock. - read_
shared_ ⚠i8 - Read an
i8from aSharedCell’s payload, truncating the upper bytes. - read_
shared_ ⚠i16 - Read an
i16from aSharedCell’s payload, truncating the upper bytes. - read_
shared_ ⚠i32 - Read an
i32from aSharedCell’s payload, truncating the upper bytes. - read_
shared_ ⚠i64 - Read an
i64from aSharedCell’s payload. - read_
shared_ ⚠ptr - Read the raw 8-byte pointer payload of a
SharedCellwhose interiorFieldKindisPtr. The returnedu64is aValueWordbit pattern (NaN-boxed Arc/Box pointer) that can beclone_from_bits’d to obtain a retained share. - read_
shared_ ⚠u8 - Read a
u8from aSharedCell’s payload, truncating the upper bytes. - read_
shared_ ⚠u16 - Read a
u16from aSharedCell’s payload, truncating the upper bytes. - read_
shared_ ⚠u32 - Read a
u32from aSharedCell’s payload, truncating the upper bytes. - read_
shared_ ⚠u64 - Read a
u64from aSharedCell’s payload. - release_
typed_ ⚠closure - Release one refcount share of a
TypedClosureHeaderblock. If the refcount reaches zero, this function walks all three per-capture masks to release each mutable-cell and heap-typed capture, then frees the block itself. The three masks are: - retain_
typed_ ⚠closure - Retain (bump refcount) on a
TypedClosureHeaderblock. - typed_
closure_ ⚠function_ id - Read the
function_idfrom aTypedClosureHeaderblock. - typed_
closure_ ⚠kind - Read the
HeapHeaderkind tag for aTypedClosureHeaderblock. - typed_
closure_ ⚠refcount - Get the current refcount of a
TypedClosureHeaderblock (for debugging / tests). - typed_
closure_ ⚠type_ id - Read the
type_idfrom aTypedClosureHeaderblock. - write_
capture_ ⚠raw_ u64 - Write a raw 8-byte capture slot at the given index.
- write_
capture_ ⚠typed - Write a capture slot from a
ValueWordbit pattern, selecting the correct native width based on the capture’sFieldKind. - write_
owned_ ⚠mutable_ bool - Write the
boolpayload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ f64 - Write the
f64payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ i8 - Write the
i8payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ i16 - Write the
i16payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ i32 - Write the
i32payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ i64 - Write the
i64payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ ptr - Write a new
u64(Ptr-shaped) payload into anOwnedMutablecell. - write_
owned_ ⚠mutable_ u8 - Write the
u8payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ u16 - Write the
u16payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ u32 - Write the
u32payload of anOwnedMutablecell. - write_
owned_ ⚠mutable_ u64 - Write the
u64payload of anOwnedMutablecell. - write_
shared_ ⚠bool - Write a
boolto aSharedCell’s payload as a 0/1 byte, zero-extended to 8 bytes. - write_
shared_ ⚠f64 - Write a
f64to aSharedCell’s payload while holding its lock. - write_
shared_ ⚠i8 - Write an
i8to aSharedCell’s payload, sign-extending to 8 bytes. - write_
shared_ ⚠i16 - Write an
i16to aSharedCell’s payload, sign-extending to 8 bytes. - write_
shared_ ⚠i32 - Write an
i32to aSharedCell’s payload, sign-extending to 8 bytes. - write_
shared_ ⚠i64 - Write an
i64to aSharedCell’s payload. - write_
shared_ ⚠ptr - Write a raw 8-byte pointer payload to a
SharedCellwhose interiorFieldKindisPtr. The caller is responsible for refcount semantics — this writer does NOT release the previous payload nor retain the new one. ForPtrpayloads the standard pattern is to read the old bits, release them, then write the new (already-retained) bits. - write_
shared_ ⚠u8 - Write a
u8to aSharedCell’s payload, zero-extending to 8 bytes. - write_
shared_ ⚠u16 - Write a
u16to aSharedCell’s payload, zero-extending to 8 bytes. - write_
shared_ ⚠u32 - Write a
u32to aSharedCell’s payload, zero-extending to 8 bytes. - write_
shared_ ⚠u64 - Write a
u64to aSharedCell’s payload.