Expand description
Shared NaN-boxing tag constants and helpers.
This module is the single source of truth for the NaN-boxing bit layout used by
ValueWord in the VM stack. The JIT, GC, and any other subsystem that needs to
inspect or construct NaN-boxed values should import constants from here.
§NaN-boxing scheme
All tagged values use sign bit = 1 with a quiet NaN exponent, giving us 51 bits for tag + payload. Normal f64 values (including NaN, which is canonicalized to a positive quiet NaN) are stored directly and never collide with our tagged range.
Tagged: 0xFFF[C-F]_XXXX_XXXX_XXXX
Bit 63 = 1 (sign, marks as tagged)
Bits 62-52 = 0x7FF (NaN exponent)
Bit 51 = 1 (quiet NaN bit)
Bits 50-48 = tag (3 bits)
Bits 47-0 = payload (48 bits)Constants§
- CANONICAL_
NAN - Canonical NaN value used when the original f64 is NaN. Positive quiet NaN: 0x7FF8_0000_0000_0000 (sign=0, exponent all 1s, quiet bit). This has sign=0 so it will NOT be detected as tagged (our tagged values have sign=1).
- HEAP_
KIND_ ARRAY - HEAP_
KIND_ ATOMIC - HEAP_
KIND_ BIG_ INT - HEAP_
KIND_ BOOL - HEAP_
KIND_ BOOL_ ARRAY - HEAP_
KIND_ CLOSURE - HEAP_
KIND_ COLUMN_ REF - HEAP_
KIND_ CONTENT - HEAP_
KIND_ DATATABLE - HEAP_
KIND_ DATA_ DATETIME_ REF - HEAP_
KIND_ DATA_ REFERENCE - HEAP_
KIND_ DATETIME_ EXPR - HEAP_
KIND_ DECIMAL - HEAP_
KIND_ DURATION - HEAP_
KIND_ ENUM - HEAP_
KIND_ ERR - HEAP_
KIND_ EXPR_ PROXY - HEAP_
KIND_ F32_ ARRAY - HEAP_
KIND_ FILTER_ EXPR - HEAP_
KIND_ FLOAT_ ARRAY - HEAP_
KIND_ FUNCTION - HEAP_
KIND_ FUNCTION_ REF - HEAP_
KIND_ FUTURE - HEAP_
KIND_ GENERATOR - HEAP_
KIND_ HASHMAP - HEAP_
KIND_ HOST_ CLOSURE - HEAP_
KIND_ I8_ ARRAY - HEAP_
KIND_ I16_ ARRAY - HEAP_
KIND_ I32_ ARRAY - HEAP_
KIND_ INDEXED_ TABLE - HEAP_
KIND_ INSTANT - HEAP_
KIND_ INT_ ARRAY - HEAP_
KIND_ IO_ HANDLE - HEAP_
KIND_ ITERATOR - HEAP_
KIND_ LAZY - HEAP_
KIND_ MATRIX - HEAP_
KIND_ MODULE_ FUNCTION - HEAP_
KIND_ MUTEX - HEAP_
KIND_ NATIVE_ SCALAR - HEAP_
KIND_ NATIVE_ VIEW - HEAP_
KIND_ NONE - HEAP_
KIND_ NUMBER - HEAP_
KIND_ OK - HEAP_
KIND_ PRINT_ RESULT - HEAP_
KIND_ RANGE - HEAP_
KIND_ ROW_ VIEW - HEAP_
KIND_ SHARED_ CELL - HEAP_
KIND_ SIMULATION_ CALL - HEAP_
KIND_ SOME - HEAP_
KIND_ STRING - HEAP_
KIND_ TASK_ GROUP - HEAP_
KIND_ TIME - HEAP_
KIND_ TIMEFRAME - HEAP_
KIND_ TIMESPAN - HEAP_
KIND_ TIME_ REFERENCE - HEAP_
KIND_ TRAIT_ OBJECT - HEAP_
KIND_ TYPED_ OBJECT - HEAP_
KIND_ TYPED_ TABLE - HEAP_
KIND_ TYPE_ ANNOTATED_ VALUE - HEAP_
KIND_ TYPE_ ANNOTATION - HEAP_
KIND_ U8_ ARRAY - HEAP_
KIND_ U16_ ARRAY - HEAP_
KIND_ U32_ ARRAY - HEAP_
KIND_ U64_ ARRAY - HEAP_
KIND_ UNIT - I48_MAX
- Maximum i48 value: 2^47 - 1
- I48_MIN
- Minimum i48 value: -2^47
- PAYLOAD_
MASK - Mask for extracting the 48-bit payload (bits 0-47).
- TAG_
BASE - Tagged value base: sign=1 + exponent all 1s + quiet NaN bit. Binary: 1_11111111111_1000…0 = 0xFFF8_0000_0000_0000 All tagged values have this prefix, with the 3-bit tag in bits 50-48.
- TAG_
BOOL - Inline bool (payload bit 0: 0=false, 1=true).
- TAG_
FUNCTION - Function reference (payload = u16 function_id).
- TAG_
HEAP - Heap pointer to
Arc<HeapValue>(48-bit pointer in payload). - TAG_INT
- Inline i48 (48-bit signed integer, sign-extended to i64).
- TAG_
MASK - Mask for extracting the 3-bit tag (bits 48-50).
- TAG_
MODULE_ FN - Module function reference (payload = u32 index).
- TAG_
NONE - None (Option::None / null).
- TAG_REF
- Reference to a stack slot (payload = absolute slot index).
- TAG_
SHIFT - Bit shift for the tag field.
- TAG_
UNIT - Unit (void return value).
Functions§
- get_
payload - Extract the 48-bit payload from a NaN-boxed u64.
- get_tag
- Extract the 3-bit tag from a tagged NaN-boxed u64.
- is_
number - Check whether a u64 is a plain f64 (not tagged).
- is_
tagged - Check whether a u64 is a tagged NaN-boxed value (as opposed to a plain f64).
- make_
tagged - Build a tagged NaN-boxed u64 from a tag and payload.
- sign_
extend_ i48 - Sign-extend a 48-bit value to i64.