Expand description
Result Type FFI Functions for JIT
Functions for creating and manipulating Result types (Ok/Err) in JIT-compiled code.
§Arc-shape producers & consumers (W12-jit-result-option-trinity, Phase 3 cluster-0 Round 7A, 2026-05-12)
ADR-006 §2.7.17 / Q18 (Wave 14 W14-variant-codegen) defines the strict-typed
Arc<ResultData> / Arc<OptionData> carriers as the canonical runtime shape
for Result<T,E> and OptionArc::into_raw(Arc<ResultData>) as u64 / Arc::into_raw(Arc<OptionData>) as u64
with kind labels NativeKind::Ptr(HeapKind::Result) /
NativeKind::Ptr(HeapKind::Option). The VM-side BuiltinFunction::OkCtor /
ErrCtor / SomeCtor / NoneCtor (crates/shape-vm/src/executor/vm_impl/ builtins.rs:551-586) produces this shape via KindedSlot::from_result /
from_option.
The JIT-side jit_v2_make_result_ok / _err / jit_v2_make_option_some /
_none producers below match that output shape — Arc::into_raw(Arc::new( ResultData::ok(payload))) as u64. Predicate + extraction helpers
jit_arc_result_is_ok / _is_err / jit_arc_result_payload /
jit_arc_option_is_some / _is_none / jit_arc_option_payload read from
the *const ResultData / *const OptionData borrow directly — no NaN-box
tag decode, no is_heap_kind probe (§2.7.7 #4 / #7 forbidden per CLAUDE.md
“Forbidden code” — runtime tag_bits dispatch deleted with the W-series).
The legacy jit_make_ok / _err / _some + jit_is_ok / etc. above are
retained for the bytecode-VM-trampoline conversion path (ffi/conversion.rs)
but are NOT called from the new MIR EnumStore consumer — the producers below
are the §2.7.5 stamp-at-compile-time path.
Functions§
- jit_
arc_ option_ is_ none - Read
is_nonefrom anArc<OptionData>pointer (negation ofis_some). Treats null bits as “not a valid Option pointer” → returns0(so a downstream caller doesn’t enter the None arm on garbage bits). - jit_
arc_ option_ is_ some - Read
is_somefrom anArc<OptionData>pointer. Mirror ofjit_arc_result_is_okfor the Option carrier. - jit_
arc_ option_ payload - Extract the inner payload bits from an
Arc<OptionData>. Same shape / contract asjit_arc_result_payload. Callers must have provenis_some == trueviajit_arc_option_is_somebefore calling (the EnumTest → EnumPayload control-flow pair guarantees this); calling on a None carrier returns the inner zero-bits Bool placeholder — harmless but not meaningful. - jit_
arc_ option_ release - Release an
Arc<OptionData>strong-count share. Mirror ofjit_arc_result_release. - jit_
arc_ option_ retain - Retain (clone) an
Arc<OptionData>strong-count share. Mirror ofjit_arc_result_retain. - jit_
arc_ result_ is_ err - Read
is_errfrom anArc<ResultData>pointer (negation ofis_ok). - jit_
arc_ result_ is_ ok - Read
is_okfrom anArc<ResultData>pointer. Returns1for Ok,0otherwise (including the null-bits guard). Borrows the inner — does NOT consume or retain a strong-count share. The caller’s slot continues to own the Arc share. - jit_
arc_ result_ payload - Extract the inner payload bits from an
Arc<ResultData>and bump its strong-count share so the returned bits are an OWNED slot the caller can install at its destination. The wrapper Arc continues to own its own inner share viar.payload.clone()— when the wrapper Drops later, the wrapper-owned inner share will be retired too. The returned share is independent (the §2.7.17 receiver-recovery soundness rule: clone the inner share, transfer it viamem::forget). - jit_
arc_ result_ release - Release an
Arc<ResultData>strong-count share. Mirrorsjit_arc_result_retain’s decrement — usesArc::decrement_strong_count::<ResultData>per Rust Arc contract. Reaching refcount zero runsResultData::Dropwhich retires the innerKindedSlot::Drop(kind-aware per §2.7.6 / Q8). - jit_
arc_ result_ retain - Retain (clone) an
Arc<ResultData>strong-count share. Bumps the standard Rust Arc refcount at offset -16 of theArc::into_rawpointer viaArc::increment_strong_count::<ResultData>— NOT the W-seriesUnifiedValue<T>refcount at offset 4 (jit_arc_retain’s shape). - jit_
is_ err - Check if a value is Err (returns TAG_BOOL_TRUE or TAG_BOOL_FALSE)
- jit_
is_ none - Check if a value is None (returns TAG_BOOL_TRUE or TAG_BOOL_FALSE)
- jit_
is_ ok - Check if a value is Ok (returns TAG_BOOL_TRUE or TAG_BOOL_FALSE)
- jit_
is_ result - Check if a value is any Result type (Ok or Err)
- jit_
is_ some - Check if a value is Some (returns TAG_BOOL_TRUE or TAG_BOOL_FALSE)
- jit_
make_ err - Create an Err result wrapping the inner value
- jit_
make_ ok - Create an Ok result wrapping the inner value
- jit_
make_ some - Create a Some value wrapping the inner value
- jit_
result_ inner - Map over Ok value - if Ok, applies function and returns new Ok This is a simplified version that just returns the inner value for now (full map support would require function call machinery)
- jit_
unwrap_ err - Unwrap an Err value, returning the inner value. Consumes the Err wrapper (frees the wrapper, caller owns inner). If not Err, returns TAG_NULL.
- jit_
unwrap_ ok - Unwrap an Ok value, returning the inner value. Consumes the Ok wrapper (decrements refcount, frees if last reference). If not Ok, returns TAG_NULL.
- jit_
unwrap_ or - Unwrap Ok or return default value If Ok, returns the inner value; otherwise returns the default
- jit_
unwrap_ some - Unwrap a Some value, returning the inner value. Consumes the Some wrapper (frees the wrapper, caller owns inner). If not Some, returns TAG_NULL.
- jit_
v2_ make_ option_ none - Allocate an
Arc<OptionData>carryingNone. No payload — the inner payload slot is a zero-bits Bool placeholder per §2.7.17OptionData:: none()so the innerKindedSlot::Dropis a no-op when the wrapper Arc reaches refcount zero. - jit_
v2_ make_ option_ some - Allocate an
Arc<OptionData>carryingSome(payload). Mirror of thejit_v2_make_result_*shape. - jit_
v2_ make_ result_ err - Allocate an
Arc<ResultData>carryingErr(payload). Same contract asjit_v2_make_result_ok; the discriminator differs. - jit_
v2_ make_ result_ ok - Allocate an
Arc<ResultData>carryingOk(payload)with the payload’s kind stamped at the call site. ReturnsArc::into_raw(arc) as u64— the slot bits the caller installs with kindNativeKind::Ptr(HeapKind::Result).