Skip to main content

ClosureCell

Struct ClosureCell 

Source
pub struct ClosureCell {
    pub bits: Vec<u64>,
    pub kinds: Vec<NativeKind>,
}
Expand description

Kind-aware closure capture cell store (§2.7.8 / Q10).

Carries two parallel arrays in lockstep:

  • bits: Vec<u64> — 8-byte raw payload per cell (the same shape as the existing closure block’s capture slots, but stored separately as a kind-tracked side-store for cells whose kind is not derivable from ClosureLayout::capture_inner_kind alone — i.e. heap captures whose NativeKind::Ptr(HeapKind) discriminator is finer than FieldKind::Ptr).
  • kinds: Vec<NativeKind> — 1-byte interpretation per cell.

Index invariant: bits.len() == kinds.len() at every observable boundary (method entry/exit). Mixed lengths are a bug.

Drop discipline: every cell is released through drop_with_kind — never bare vw_drop (forbidden #8 per §2.7.7) or “drop only if heap-shaped” probes (forbidden #7). Inline-scalar kinds are no-op drops; heap-bearing kinds retire one Arc<T> strong-count share per the dispatch in KindedSlot::drop.

Construction: every push/pop/read accepts/returns (bits, kind) lockstep. There is no kind-less constructor — cells are post-proof per §2.7.5.1, so each cell carries a known NativeKind by construction.

Forbidden shapes (mirror of §2.7.7’s stack-side list):

  • Vec<KindedSlot> for the cell store (§2.7.5 — KindedSlot is a runtime-tier carrier, not the storage-tier shape).
  • 16-byte cell slots / packed tag bits in the u64 (§2.1 — 8-byte slot invariant).
  • Vec<Option<NativeKind>> for the kind track (§2.7.5.1 — cells are post-proof; every cell has a concrete kind by construction).
  • NativeKind::Unknown / Pending / Dynamic placeholders (deleted from the enum).
  • Bool-default fallback for any cell write (§2.7.7 #9 — the W-series rationalization; surface to supervisor on a kind-source gap instead).

Wave-β consumer migration: the Load*Ptr / Store*Ptr handlers in executor/variables/mod.rs (the 130 mandatory + 33 sibling sites cluster B partial-closed leaving as NotImplemented(SURFACE)) will be migrated by Wave-β cluster B6-variables-loadptr to thread the kind through the cell-bound read paths via this struct.

Fields§

§bits: Vec<u64>

Raw payload — 8-byte per cell. Cell i holds bits[i] interpreted per kinds[i] (e.g. an Arc::into_raw::<TypedArrayData> raw pointer when kinds[i] == NativeKind::Ptr(HeapKind::TypedArray), or a native f64 bit pattern when kinds[i] == NativeKind::Float64).

§kinds: Vec<NativeKind>

Per-cell kind track. Lockstep with bits per the §2.7.8 index invariant.

Implementations§

Source§

impl ClosureCell

Source

pub fn new() -> Self

Create an empty cell store.

Source

pub fn with_capacity(cap: usize) -> Self

Create an empty cell store with the given capacity reserved on both parallel tracks.

Source

pub fn len(&self) -> usize

Number of live cells. The §2.7.8 index invariant guarantees this equals self.kinds.len().

Source

pub fn is_empty(&self) -> bool

Whether the cell store is empty.

Source

pub unsafe fn push(&mut self, bits: u64, kind: NativeKind)

Append a cell. The caller transfers ownership of bits’s strong-count share (for heap kinds) into the cell store; the matching drop_with_kind discharge happens at pop / truncate / Drop time.

§Safety

bits must be a valid representation of kind per the construction-side contract — for heap kinds, the result of Arc::into_raw::<T> for the matching T; for inline scalars, the native bit pattern.

Source

pub fn pop(&mut self) -> Option<(u64, NativeKind)>

Remove and return the last (bits, kind). The caller takes ownership of the share (for heap kinds) and is responsible for drop_with_kind (or transferring it elsewhere). Pop does NOT clone — vec.pop() is move-out semantics.

Source

pub fn read(&self, idx: usize) -> (u64, NativeKind)

Read cell idx as (bits, kind) without consuming it. The returned bits is a borrowed copy — for heap kinds the caller must clone_with_kind(bits, kind) to obtain an independently- owned share before storing it elsewhere (the cell retains its share).

§Panics

Panics if idx >= self.len().

Source

pub fn read_kinded(&self, idx: usize) -> KindedSlot

Read cell idx and return a runtime-tier KindedSlot carrier with a freshly-cloned share (for heap kinds; inline scalars are Copy-equivalent). This is the §2.7.7 retain-on-read pattern, extended to cells per §2.7.8.

§Panics

Panics if idx >= self.len().

Source

pub unsafe fn replace( &mut self, idx: usize, bits: u64, kind: NativeKind, ) -> (u64, NativeKind)

Overwrite cell idx with a new (bits, kind) pair, returning the old (bits, kind). The caller is responsible for drop_with_kind on the returned previous value (or transferring it elsewhere) and for ensuring the new bits carry one fresh strong-count share for the new kind.

§Safety

New bits must be a valid representation of new kind per the construction-side contract (for heap kinds: one strong-count share from Arc::into_raw::<T> for the matching T).

§Panics

Panics if idx >= self.len().

Source

pub fn truncate(&mut self, new_len: usize)

Truncate the cell store to new_len cells, releasing every cell at index >= new_len via drop_with_kind. No-op if new_len >= self.len().

Trait Implementations§

Source§

impl Debug for ClosureCell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClosureCell

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for ClosureCell

Source§

fn drop(&mut self)

Releases every live cell via drop_with_kind per §2.7.8. The drop order is tail-first to mirror the last-pushed-first-dropped convention used by KindedSlot-bearing collections.

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§

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.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,