Skip to main content

heap_value_mut

Function heap_value_mut 

Source
pub unsafe fn heap_value_mut<'a>(slot: *mut StackValue) -> Option<&'a mut Value>
Expand description

Get a mutable reference to a heap Value at the given stack position without popping (no Arc alloc/dealloc cycle).

Returns Some(&mut Value) if the slot is a sole-owned heap value. Returns None if the slot is inline (Int/Bool) or shared (refcount > 1).

Sole ownership is verified via Arc::get_mut, which atomically checks both strong and weak refcounts — the same guard used throughout the codebase for COW mutations.

The caller MUST NOT move or replace the Value behind the reference — it is still owned by the Arc on the stack. Mutating fields in place (e.g., Vec::push on VariantData.fields) is the intended use.

§Safety

  • slot must point to a valid StackValue within the stack.
  • The stack must not be concurrently accessed (true for strand-local stacks).
  • The returned reference is bounded by lifetime 'a; the caller must ensure it does not outlive the stack slot.

§Tagged-value encoding

The inline-value guard covers all non-heap encodings exhaustively: Int (odd bits), Bool false (0x0), Bool true (0x2). Every other value (even > 2) is a valid Arc<Value> heap pointer.