Skip to main content

Module stack_kind_code

Module stack_kind_code 

Source
Expand description

JIT-side parallel-kind track encoding (ADR-006 §2.7.7 / Q9).

This module is the JIT-tier analog of the VM-side Vec<NativeKind> parallel track on crates/shape-vm/src/executor/vm_impl/ stack.rs::VmStack. The JIT stores its parallel kind track as a contiguous [u8; 512] array (JITContext.stack_kinds) so Cranelift codegen can write a kind in lockstep with each data push via a plain iconst(types::I8, code) + byte store, mirroring the existing 8-byte data store at JITContext.stack[i].

The encoding is the §2.7.5 cross-crate stable-FFI raw-pair shape: each NativeKind value (including all Ptr(HeapKind::*) arms) maps to a single byte. The producing site stamps the code from the call signature at JIT-compile time; the consuming FFI side decodes the byte back to NativeKind and dispatches per ADR-006 §2.7.6 / Q8. No tag-bit decode on the raw u64, no is_heap() probe — the kind IS the discriminator.

Forbidden under §2.7.7:

  • Option<NativeKind> in the track — every push has a known kind from the producing call signature; if the kind genuinely isn’t known the answer is surface-and-stop, not None. The SENTINEL value is the uninitialized-slot pattern set by JITContext::default(); reading it at a pop site is a kind-source gap (forbidden #9).
  • Vec<KindedSlot> for the stack — same §2.7.5 rule the VM-side rules out; storage stays raw u64 + parallel byte track.
  • 16-byte slot — would conflict with the §2.1 8-byte invariant.
  • Encoding Ptr(HeapKind) arms via a tag-bit probe on the slot’s u64 — the deleted ValueWord tag_bits dispatch (CLAUDE.md “Forbidden Patterns” #4). Kind comes from the producing call signature, period.

Constants§

C_BOOL
C_CHAR
C_DECIMAL_V2
C_FLOAT32
C_FLOAT64
C_INT8
C_INT16
C_INT32
C_INT64
C_INTSIZE
C_NULL
C_NULLABLE_FLOAT64
C_NULLABLE_INT8
C_NULLABLE_INT16
C_NULLABLE_INT32
C_NULLABLE_INT64
C_NULLABLE_INTSIZE
C_NULLABLE_UINT8
C_NULLABLE_UINT16
C_NULLABLE_UINT32
C_NULLABLE_UINT64
C_NULLABLE_UINTSIZE
C_STRING
C_STRING_V2
C_UINT8
C_UINT16
C_UINT32
C_UINT64
C_UINTSIZE
PTR_BASE
Base code for Ptr(HeapKind::*) arms. Each HeapKind ordinal is added to PTR_BASE to produce the byte. With HeapKind ordinals 0..=28 today the Ptr-range is 128..=156, well clear of the scalar codes 0..=23 and the SENTINEL = 255.
SENTINEL
Sentinel byte for uninitialized stack slots (matches JITContext::default() initialization). Reading this at a pop site is a kind-source gap per ADR-006 §2.7.7 #9 — surface, do not Bool-default.

Functions§

decode
Decode a single-byte parallel-track code back to its NativeKind.
encode
Encode a NativeKind as its single-byte parallel-track code.