Skip to main content

Module result

Module result 

Source
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 Option values. Slot bits at the §2.7.7 stack tier are Arc::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_none from an Arc<OptionData> pointer (negation of is_some). Treats null bits as “not a valid Option pointer” → returns 0 (so a downstream caller doesn’t enter the None arm on garbage bits).
jit_arc_option_is_some
Read is_some from an Arc<OptionData> pointer. Mirror of jit_arc_result_is_ok for the Option carrier.
jit_arc_option_payload
Extract the inner payload bits from an Arc<OptionData>. Same shape / contract as jit_arc_result_payload. Callers must have proven is_some == true via jit_arc_option_is_some before 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 of jit_arc_result_release.
jit_arc_option_retain
Retain (clone) an Arc<OptionData> strong-count share. Mirror of jit_arc_result_retain.
jit_arc_result_is_err
Read is_err from an Arc<ResultData> pointer (negation of is_ok).
jit_arc_result_is_ok
Read is_ok from an Arc<ResultData> pointer. Returns 1 for Ok, 0 otherwise (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 via r.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 via mem::forget).
jit_arc_result_release
Release an Arc<ResultData> strong-count share. Mirrors jit_arc_result_retain’s decrement — uses Arc::decrement_strong_count::<ResultData> per Rust Arc contract. Reaching refcount zero runs ResultData::Drop which retires the inner KindedSlot::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 the Arc::into_raw pointer via Arc::increment_strong_count::<ResultData> — NOT the W-series UnifiedValue<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> carrying None. No payload — the inner payload slot is a zero-bits Bool placeholder per §2.7.17 OptionData:: none() so the inner KindedSlot::Drop is a no-op when the wrapper Arc reaches refcount zero.
jit_v2_make_option_some
Allocate an Arc<OptionData> carrying Some(payload). Mirror of the jit_v2_make_result_* shape.
jit_v2_make_result_err
Allocate an Arc<ResultData> carrying Err(payload). Same contract as jit_v2_make_result_ok; the discriminator differs.
jit_v2_make_result_ok
Allocate an Arc<ResultData> carrying Ok(payload) with the payload’s kind stamped at the call site. Returns Arc::into_raw(arc) as u64 — the slot bits the caller installs with kind NativeKind::Ptr(HeapKind::Result).