Skip to main content

UpVal

Struct UpVal 

Source
pub struct UpVal { /* private fields */ }
Expand description

A closure upvalue. Open upvalues point at a slot on a thread’s stack (referred to by index, since the stack reallocates). Closed upvalues own the value.

State lives entirely in three Cell fields and is single-source-of-truth. open_thread_id doubles as the open/closed discriminant: a non-negative value is the owning thread id of an open upvalue; the [CLOSED_TAG] sentinel (-1) means the upvalue is closed and its payload is in closed_value. Valid thread ids are non-negative (the main thread is id 0), so the sentinel is unambiguous. open_idx is the stack slot of an open upvalue. Closing is terminal — there is no re-open path — so a CLOSED_TAG tag never reverts.

Read the open shape with try_open_payload (None once closed) and the closed payload with closed_value / try_closed_value. The all-Cell layout lets state.rs::upvalue_get / upvalue_set short-circuit the Open path with zero borrow-guard overhead, which is the dominant cost in fibonacci-class recursion benchmarks.

Implementations§

Source§

impl UpVal

Source

pub fn open(thread_id: usize, idx: StackIdx) -> Self

Source

pub fn closed(v: LuaValue) -> Self

Source

pub fn is_open(&self) -> bool

Source

pub fn is_closed(&self) -> bool

Source

pub fn try_open_payload(&self) -> Option<(usize, StackIdx)>

Zero-overhead read of the open shape used by upvalue_get / upvalue_set and every out-of-crate consumer that inspects an open upvalue’s (thread_id, idx). Returns Some((thread_id, idx)) when the upvalue is still open, None once it has been closed.

Source

pub fn closed_value(&self) -> LuaValue

Returns the closed-side value. Callers must have confirmed the upvalue is closed (try_open_payload returned None).

Source

pub fn close_with(&self, v: LuaValue)

Source

pub fn set_closed_value(&self, v: LuaValue)

Source

pub fn try_closed_value(&self) -> Option<LuaValue>

Trait Implementations§

Source§

impl Debug for UpVal

Source§

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

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

impl Trace for UpVal

UpVal — Open (refers to a thread stack slot by index) or Closed (owns a LuaValue). The Open variant carries no direct GC reference; the slot it points at is traced through the owning thread’s stack walk.

Source§

fn type_name(&self) -> &'static str

Concrete Rust type name for diagnostic/testC telemetry (Heap::type_name_count). Collector behavior must not branch on this. The default covers container blanket impls, which are never GC-boxed directly; concrete runtime types override it with std::any::type_name::<Self>().
Source§

fn trace(&self, m: &mut Marker)

Auto Trait Implementations§

§

impl !Freeze for UpVal

§

impl !RefUnwindSafe for UpVal

§

impl !Send for UpVal

§

impl !Sync for UpVal

§

impl !UnwindSafe for UpVal

§

impl Unpin for UpVal

§

impl UnsafeUnpin for UpVal

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.