Sign in

    wasmoon_jit

    Wasmoon-specific JIT integration and native runtime glue

    wasm
    jit
    runtime
    native
    Download zip
    Author
    Version
    0.17.1
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    182

    #wasmoon_jit

    JIT integration and native runtime support for Wasmoon.

    wasmoon_jit connects the compiler pipeline to Wasmoon's runtime. It provides VMContext layouts, native runtime helpers, v11 artifacts, trampolines, WASI bridge glue, and integration planning for loading generated code.

    #Packages

    • Milky2018/wasmoon_jit: runtime layout, JIT integration planning, trampolines, runtime symbols, and helper APIs.
    • Milky2018/wasmoon_jit/artifact: target-portable Cwasm manifests, symbolic function identities, signatures, and unlinked code-object data.
    • Milky2018/wasmoon_jit/perf: optional JIT performance metrics.

    #When to use it

    Use wasmoon_jit when integrating generated code with the Wasmoon runtime, including VMContext layout, runtime helper symbols, trampolines, v11 artifacts, and installed-code lifecycle management.

    #API changes for the next minor release

    The unused CompilationMode, CompilationRequest, CompilationQueue, TieredConfig, CompilationDecision, and CompilationStrategy APIs have been removed on main. They were published in earlier 0.x releases, so this is a source-breaking change reserved for the next minor release, not a 0.16.x patch. Repository consumer inspection cannot rule out external callers.

    These APIs maintained standalone decisions and queues; the runtime never consumed them to implement lazy or tiered compilation. Use NativeCompiler for explicit compilation and the runtime's interpreter/JIT selection for execution. The CLI selects JIT by default and provides --no-jit for the interpreter. Profiler and its independent call-counting APIs remain available.

    load_artifact keeps loading separate from installation: it performs bounded decoding, exact manifest and CPU-feature compatibility checks, symbolic target validation, and code-object verification without resolving an address or allocating executable memory.

    #Example: plan MilkIR through the Wasmoon JIT pipeline

    This API runs a MilkIR function through target lowering, register allocation, and emission, then returns the generated bytes and runtime integration data. Dialect verification failures are returned as JitPipelineError before register allocation or emission.

    ///|
    test "plan a small MilkIR function for x64 JIT integration" {
    let signature = @milkir.Signature::Signature([I64, I64], [I64])
    let milk = @milkir.Function::with_signature("add64", signature)
    let lhs = milk.param(0).unwrap()
    let rhs = milk.param(1).unwrap()
    let sum = milk.new_value(I64)
    let entry = milk.new_block([])
    entry.append_inst(milk.new_inst(Scalar(IntBinary(Add)), [lhs, rhs], [sum]))
    entry.set_terminator(Return([sum]))
    let plan = @wasmoon_jit.plan_milkir_integration_for_target(milk, X64)
    inspect(plan.entry_symbol, content="add64")
    debug_inspect(plan.target, content="X64")
    inspect(plan.object.get_bytes().length() > 0, content="true")
    }

    #Persisted artifacts

    Milky2018/wasmoon_jit/artifact defines the v11 ordinary-data format. The live compiler produces symbolic, unlinked function code; load_artifact performs bounded decoding and exact compatibility verification; and JitCodeInstaller owns relocation, executable-memory mutation, and publication. There is no compatibility decoder for the removed v8 format.

    The root package's LoadedArtifact also retains immutable prepared native safepoints, shared by contexts bound from that artifact. Modules with no safepoints allocate no native descriptor table. loaded.verified() exposes the portable loader value for installer.install(loaded.verified()); the artifact/loader package itself remains independent of native ownership. Contexts retain safepoints after the loaded artifact is released. Compatibility setters detach a private table before replacing a shared entry; bind metadata only outside execution, including suspended execution of that context.

    #Compiler pipeline

    JIT planning composes milkir, milkir/native, wasm_milkir/native, vcode_regalloc, and the selected target package. Each target owns instruction selection, allocation policy, frame layout, and emission. The resulting code object is combined with VMContext metadata, runtime symbols, and trampolines before it is installed and invoked by Wasmoon. Native stubs are private implementation details of this package rather than a separate public package.

    #Native resource handles

    Memory descriptors (MemoryDescriptor), GC heaps (GCHeapHandle), and indirect tables (NativeTableHandle) are managed opaque type values. Each native descriptor is allocated directly with moonbit_make_external_object; its finalizer releases its backing allocations. Copying a handle retains the resource through MoonBit RC, without a separate native owner counter or pointer wrapper. FFI operations borrow their arguments.

    Memory::desc_ptr(), NativeJITContext::memory_descriptor(), CHeap::get_ptr(), and JITTable::raw_ptr() return retaining handles. The owning Store can close while independently retained handles remain valid. Closing a CHeap or JITTableOwner invalidates aliases of that logical view and releases its reference; it does not invalidate another context's binding. Memory close similarly releases its descriptor. Explicit descriptor retain/free functions are no longer part of the MoonBit API.

    JIT contexts retain every bound memory, table and heap. Exception and parked continuation root registrations retain their heap until unregistration; the heap's registration list is non-owning. Table descriptors stay at a stable address as their entry arrays grow, and publish the new layout to all registered contexts. These context backlinks are non-owning and are unlinked before releasing the descriptor. Atomic wait registrations retain memory until cancellation or finalization. Native test workers acquire/release their RC references on the calling/joining thread, never on the worker thread.

    null() creates a managed empty handle, not a C NULL pointer. is_null() identifies an empty handle; descriptor equality compares live pointer identity and treats empty descriptors as equal. Native entrypoints normalize empty memory/heap handles to NULL before invoking internal helpers. There is no public integer-to-handle cast. Machine-code addresses, relocation values, raw byte addresses used for address arithmetic, and encoded guest values remain integers; callers must keep the relevant owner alive while using raw addresses. Lexical scope alone does not retain an owner past its last use; prefer descriptor-based operations over extracting an integer address.

    DWARFBuilder is a managed opaque type: its complete native state is allocated by moonbit_make_external_object, without a separate pointer wrapper or manual reference count. MoonBit aliases and capturing closures retain the same object. The finalizer unregisters debug information, frees the object buffer and clears the borrowed active-builder pointer. destroy() performs the same cleanup early and is idempotent; the MoonBit allocation survives until its last reference is released. After close, mutations are ignored and lookup returns None. Repeated registration is idempotent; unregister releases the generated buffer and permits registration again while the builder remains open.

    #Checked linear-memory access

    Public descriptor read, write, copy, move and fill operations return 0 on success and -1 for invalid descriptors, negative offsets/lengths, or ranges outside the current committed memory. Reads and writes also reject lengths larger than their MoonBit buffer. Rejection leaves the destination unchanged. Copies support overlapping ranges.

    A zero-length operation succeeds at any in-bounds position, including the end of a live zero-byte allocation. It never dereferences a pointer. Empty handles and positions past the end are rejected even for zero-length operations. The descriptor argument retains the allocation throughout each operation.

    The unused raw-address memory_read and memory_init APIs have been removed. Use memory_descriptor_read and memory_descriptor_write_bytes instead. alloc_memory/free_memory remain low-level unmanaged allocation operations for native ABI fixtures; callers must track ownership, capacity and alias lifetime. They are not substitutes for checked linear-memory access.

    ArtifactCompatibility

    Host and module contract used to accept or reject a decoded artifact.

    CHeap

    Logical owner of a shared managed GC heap.

    CHeapError

    CHeap error types for runtime errors

    ContextLayout

    Immutable layout retained by a loaded module and shared by its instances.

    ContextShape

    Compatibility exports for the shared runtime implementation.

    GCHeapHandle

    Managed GC heap handle. Copies retain the heap independently of its owner.

    GcSlot

    One field or element as the C heap stores it.

    lo is the runtime word. Every value kind except v128 is encoded entirely into it, and it is the only word the collector scans for references, so a reference must never be written to hi.

    InstalledCode

    Opaque ownership of a fully linked and executable artifact.

    Construction is the publication boundary: no staged address is returned before every mapping, relocation, metadata record, permission transition, and instruction-cache flush has succeeded.

    InstalledFunction

    Address-dependent metadata and entry identity for one committed function.

    Returned metadata arrays are copies. The addresses remain valid only while the owning InstalledCode is retained.

    InstalledImport

    A resolved import retained by a committed installation.

    InstalledTrampoline

    Opaque ownership of process-local executable trampoline code.

    InvocationControl

    Invocation-local cooperative cancellation and elapsed-time deadline. Uses a monotonic clock; time spent suspended or in host code counts.

    JITTable

    Shared indirect table that can be used by multiple JIT modules.

    JITTableOwner

    Logical close capability for one shared JIT table view.

    JitCodeInstaller

    Installer policy plus the embedding-provided external/data symbol resolver.

    JitInstallError

    Structured failures from the Wasmoon-owned executable-code transaction.

    MemoryDescriptor

    Shared managed linear-memory allocation. Each handle keeps the descriptor and its backing memory alive independently of a Store or JIT context.

    MemoryInfo

    Memory information for JIT execution.

    NativeAtomicWait

    Owns one native wait registration, including its memory descriptor lease. Dropping the object cancels its registration; explicit cancellation is idempotent. Creation requires a checked, aligned shared-memory address.

    NativeCallableRegistry

    Compatibility exports for the shared runtime implementation.

    NativeContinuationArena

    Store-owned continuation identities. The bridge retains state, while state owns physical storage and never retains the bridge or a native context.

    NativeExceptionArena

    Store-owned immutable exception snapshots shared by native instances.

    NativeExecutionState

    Compatibility exports for the shared runtime implementation.

    NativeExecutionStateError

    Compatibility exports for the shared runtime implementation.

    NativeInvocationHandle

    Compatibility exports for the shared runtime implementation.

    NativeInvocationPhase

    Compatibility exports for the shared runtime implementation.

    NativeTableHandle

    Managed shared table identity. Native context bindings retain this object.

    GCSetupError

    pub(all) suberror GCSetupError {
    MissingJITContext
    InvalidMetadata
    InvalidFuncCount(num_funcs~ : Int)
    FuncTypeIndicesLengthMismatch(func_type_indices_len~ : Int, num_funcs~ : Int)
    MissingFunctionTableContext(num_funcs~ : Int)
    } derive(
    Debug
    )

    Error for invalid JIT GC setup context

    GCSetupError::output

    fn GCSetupError::output(self : GCSetupError, logger : &Logger) -> Unit

    GCSetupError::to_string

    fn GCSetupError::to_string(self : GCSetupError) -> String

    HostcallImportTrampolineError

    pub suberror HostcallImportTrampolineError {
    UnsupportedHostcallImportTrampoline(message~ : String)
    } derive(Eq,
    Debug
    )

    HostcallImportTrampolineError::not_equal

    HostcallImportTrampolineError::output

    HostcallImportTrampolineError::to_string

    JitPipelineError

    pub suberror JitPipelineError {
    NativeLoweringFailed(cause~ :
    NativeLowerError
    )
    AArch64AbiInvalid(cause~ :
    InternalAbiError
    )
    X64AbiInvalid(cause~ :
    InternalAbiError
    )
    AArch64LoweringFailed(cause~ :
    AArch64LowerError
    )
    X64LoweringFailed(cause~ :
    X64LowerError
    )
    AArch64CompilationFailed(cause~ :
    AArch64CompileError
    )
    X64CompilationFailed(cause~ :
    X64CompileError
    )
    AArch64LinkPreparationFailed(cause~ :
    AArch64LinkError
    )
    X64LinkPreparationFailed(cause~ :
    X64LinkError
    )
    InvalidJitRelocation(target~ : NativeTarget, index~ : Int, message~ : String)
    UnsupportedEntrySignature(message~ : String)
    UnsupportedHostArchitecture(tag~ : Int)
    UnsupportedHostOsAbi(tag~ : Int)
    InvalidFunctionIndex(index~ : Int)
    } derive(
    Debug
    )

    JitPipelineError::output

    fn JitPipelineError::output(self : JitPipelineError, logger : &Logger) -> Unit

    JitPipelineError::to_string

    fn JitPipelineError::to_string(self : JitPipelineError) -> String

    NativeFiberError

    pub suberror NativeFiberError {
    StackAllocationFailed(Int64)
    WrongThread
    InvalidTransition(NativeFiberPhase)
    InvalidState(Int)
    UnexpectedYield(Int64)
    NativeFailure(Int)
    } derive(Eq,
    Debug
    )

    NativeFiberError::equal

    NativeFiberError::not_equal

    fn NativeFiberError::not_equal(x : NativeFiberError, y : NativeFiberError) -> Bool

    NativeFiberError::output

    fn NativeFiberError::output(self : NativeFiberError, logger : &Logger) -> Unit

    NativeFiberError::to_string

    fn NativeFiberError::to_string(self : NativeFiberError) -> String

    NativeSetupError

    pub(all) suberror NativeSetupError {
    SegmentAllocationFailed
    RootFrameAllocationFailed
    ExceptionPayloadAllocationFailed
    DebugRegistrationFailed
    MemoryBindingAllocationFailed
    TableBindingAllocationFailed
    InvalidBinding(String)
    } derive(
    Debug
    )

    Recoverable failure while preparing per-instance native state.

    NativeSetupError::output

    fn NativeSetupError::output(self : NativeSetupError, logger : &Logger) -> Unit

    NativeSetupError::to_string

    fn NativeSetupError::to_string(self : NativeSetupError) -> String

    BacktraceFrame

    pub struct BacktraceFrame {
    pc : Int64
    name : String
    offset : Int64
    func_idx : Int
    }

    Backtrace frame

    CallCounter

    pub(all) struct CallCounter {
    counts : Map[Int, Int]
    total_calls : Int
    }

    Stores call counts for each function

    CallCounter::CallCounter

    fn CallCounter::CallCounter() -> CallCounter

    CallCounter::clear

    fn CallCounter::clear(self : CallCounter) -> Unit

    Clear all counters

    CallCounter::get_count

    fn CallCounter::get_count(self : CallCounter, func_idx : Int) -> Int

    Get the call count for a function

    CallCounter::increment

    fn CallCounter::increment(self : CallCounter, func_idx : Int) -> Int

    Increment the call count for a function

    CallCounter::reset

    fn CallCounter::reset(self : CallCounter, func_idx : Int) -> Unit

    Reset counter for a specific function

    CallCounter::total

    fn CallCounter::total(self : CallCounter) -> Int

    Get total number of calls tracked

    CallCounter::unique_functions

    fn CallCounter::unique_functions(self : CallCounter) -> Int

    Get the number of unique functions called

    DWARFBuilder

    pub type DWARFBuilder

    DWARF debug info builder Owns native metadata and debugger registration through MoonBit RC. All aliases share the same state; destroy closes them together.

    DWARFBuilder::DWARFBuilder

    fn DWARFBuilder::DWARFBuilder() -> DWARFBuilder

    Create a new DWARF builder

    DWARFBuilder::add_function

    fn DWARFBuilder::add_function(self : DWARFBuilder, name : String, addr : Int64, size : Int, func_idx : Int) -> Unit

    Add a function to the DWARF debug info Parameters: name: Function name (e.g., "func_42" or "my_function") addr: Function start address in memory size: Function size in bytes func_idx: WebAssembly function index

    DWARFBuilder::capture_backtrace

    fn DWARFBuilder::capture_backtrace(self : DWARFBuilder) -> Array[BacktraceFrame]

    Capture and format a backtrace from the current trap state Returns an array of backtrace frames

    DWARFBuilder::destroy

    fn DWARFBuilder::destroy(self : DWARFBuilder) -> Unit

    Destroy the DWARF builder and free all resources This also unregisters debug info. Repeated calls are harmless. Closed builders ignore mutations and return None from address lookup.

    DWARFBuilder::format_backtrace

    fn DWARFBuilder::format_backtrace(_self : DWARFBuilder, frames : Array[BacktraceFrame]) -> String

    Format a backtrace as a string

    DWARFBuilder::lookup_address

    fn DWARFBuilder::lookup_address(self : DWARFBuilder, addr : Int64) -> FunctionInfo?

    Lookup an address to find which function it belongs to Returns None if the address is not in any known function

    DWARFBuilder::register

    fn DWARFBuilder::register(self : DWARFBuilder, verbose? : Bool) -> Bool

    Register the DWARF debug info with the debugger This generates an in-memory Mach-O/ELF object file with DWARF sections and registers it with LLDB/GDB via the standard JIT interface. After calling this, function names will appear in stack traces. Also sets this builder as the active one for backtrace lookups. Returns false on an empty/closed builder, exceeded function capacity, or native allocation failure. verbose: if true, print debug info to stderr

    DWARFBuilder::unregister

    fn DWARFBuilder::unregister(self : DWARFBuilder) -> Unit

    Unregister DWARF debug info from the debugger Call this before destroying if you want to explicitly unregister

    FunctionInfo

    pub struct FunctionInfo {
    name : String
    func_idx : Int
    offset : Int64
    }

    Function lookup result

    FunctionTemperature

    pub(all) enum FunctionTemperature {
    Cold
    Warm
    Hot
    }

    Temperature of a function based on call frequency

    FunctionTemperature::output

    fn FunctionTemperature::output(self : FunctionTemperature, logger : &Logger) -> Unit

    FunctionTemperature::to_string

    fn FunctionTemperature::to_string(self : FunctionTemperature) -> String

    GcSafepoint

    pub struct GcSafepoint {
    code_offset : Int
    live_refs : Array[Int]
    metadata : Int64
    } derive(
    Debug
    )

    Information about a GC safepoint in generated code.

    GcSafepoint::GcSafepoint

    fn GcSafepoint::GcSafepoint(code_offset : Int, live_refs : Array[Int], metadata : Int64) -> GcSafepoint

    HostcallImportTrampolineCode

    pub(all) struct HostcallImportTrampolineCode {
    code : Array[Int]
    }

    Machine-code bytes for Wasm-ABI import trampolines that call the wasmoon_jit_hostcall C bridge.

    HostcallImportTrampolineLayout

    pub(all) struct HostcallImportTrampolineLayout {
    arg_slots : Int
    result_slots : Int
    values_vec_bytes : Int
    int_overflow_count : Int
    float_overflow_types : Array[
    ValueType
    ]
    }

    HotThreshold

    pub(all) struct HotThreshold {
    warm_threshold : Int
    hot_threshold : Int
    }

    Configuration for hot function detection

    HotThreshold::aggressive

    fn HotThreshold::aggressive() -> HotThreshold

    HotThreshold::conservative

    fn HotThreshold::conservative() -> HotThreshold

    HotThreshold::default

    fn HotThreshold::default() -> HotThreshold

    ImportFunctionResolution

    pub(all) enum ImportFunctionResolution {
    DirectImportFunction(Int64)
    HostImportFunctionAddr(Int)
    UnsupportedImportFunction
    } derive(Eq,
    Debug
    )

    ImportFunctionResolution::equal

    ImportFunctionResolution::not_equal

    JITDebugDB

    pub struct JITDebugDB {
    entries : Map[Int, JITFunctionDebug]
    }

    Optional in-memory database of per-function debug dumps.

    JITDebugDB::JITDebugDB

    fn JITDebugDB::JITDebugDB() -> JITDebugDB

    JITDebugDB::get

    fn JITDebugDB::get(self : JITDebugDB, func_idx : Int) -> JITFunctionDebug?

    JITDebugDB::set

    fn JITDebugDB::set(self : JITDebugDB, func_idx : Int, debug : JITFunctionDebug) -> Unit

    JITFunctionDebug

    pub struct JITFunctionDebug {
    ir : String
    target_vcode : String
    allocated_vcode : String
    machine_code : String
    }

    Per-function compilation dumps captured for dump-on-trap.

    JITFunctionDebug::JITFunctionDebug

    fn JITFunctionDebug::JITFunctionDebug(ir : String, target_vcode : String, allocated_vcode : String, machine_code : String) -> JITFunctionDebug

    JitCodeObject

    pub struct JitCodeObject {
    // private fields
    } derive(
    Debug
    )

    JitCodeObject::get_bytes

    fn JitCodeObject::get_bytes(self : JitCodeObject) -> Array[Int]

    JitIntegrationPlan

    pub(all) struct JitIntegrationPlan {
    entry_symbol : String
    target : NativeTarget
    object : JitCodeObject
    }

    JitPipelineDiagnostics

    pub struct JitPipelineDiagnostics {
    target_vcode : String
    allocated_vcode : String
    code_object : String
    machine_code : String
    } derive(
    Debug
    )

    Stable, read-only renderings of the final native compilation checkpoints. Concrete target instruction, allocation, and frame types remain owned by their target modules and do not cross this diagnostics facade.

    LoadedArtifact

    pub struct LoadedArtifact {
    // private fields
    }

    Native preparation of a verified portable artifact. Instances retain the immutable safepoint owner independently of this wrapper.

    LoadedArtifact::bind_safepoints

    fn LoadedArtifact::bind_safepoints(self : LoadedArtifact, context : NativeJITContext) -> Bool

    Bind only to a fresh context, before any invocation can reference its metadata.

    LoadedArtifact::verified

    Portable verified input for code installation and inspection.

    MemoryDescriptorLayout

    pub(all) struct MemoryDescriptorLayout {
    base_offset : Int
    current_length_offset : Int
    }

    Fixed prefix layout of wasmoon_memory_t accessed by generated JIT code.

    Offsets are derived from the native C declarations at initialization.

    NativeCallable

    A native entry bound to the instance environment that owns its code. The leaf trampoline preserves all guest arguments and tail-call stack usage.

    NativeCallable::entry_address

    fn NativeCallable::entry_address(self : NativeCallable) -> Int64

    NativeCallable::release

    fn NativeCallable::release(self : NativeCallable) -> Unit

    NativeCompiler

    pub struct NativeCompiler {
    // private fields
    }

    Compile one verified Wasm MilkIR body directly into the final unlinked artifact representation. Symbolic relocations are retained unchanged.

    NativeCompiler::compile_wasm_body_artifact_function

    fn NativeCompiler::compile_wasm_body_artifact_function(self : NativeCompiler, function :
    Function
    , validation_context :
    WasmValidationContext
    , function_index~ : Int, signature~ :
    Signature
    , use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int]) ->
    FunctionCode
    raise JitPipelineError

    Compile one function while retaining target allocator scratch capacity for the next serial call on this compiler.

    NativeCompiler::diagnose_wasm_body

    fn NativeCompiler::diagnose_wasm_body(self : NativeCompiler, function :
    Function
    , validation_context :
    WasmValidationContext
    , function_index~ : Int, use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int]) -> JitPipelineDiagnostics raise JitPipelineError

    Observe the production pipeline with this compiler's target and context layout.

    NativeFiber

    type NativeFiber

    Fixed-stack, single-threaded native fiber.

    The external object owns a guarded native stack and the entry closure. A fiber may only be continued or cancelled on the thread that created it.

    NativeFiber::cancel

    fn NativeFiber::cancel(self : NativeFiber) -> Unit raise NativeFiberError

    NativeFiber::continue_with

    fn NativeFiber::continue_with(self : NativeFiber, value? : Int64) -> NativeFiberEvent raise NativeFiberError

    NativeFiber::guard_size

    fn NativeFiber::guard_size(self : NativeFiber) -> Int64

    NativeFiber::new

    fn NativeFiber::new(entry : () -> Int64, stack_size? : Int64) -> NativeFiber raise NativeFiberError

    NativeFiber::phase

    NativeFiber::stack_size

    fn NativeFiber::stack_size(self : NativeFiber) -> Int64

    NativeFiber::suspend

    fn NativeFiber::suspend(value : Int64) -> Int64

    Suspend the currently running native fiber and return the next resume value.

    NativeFiber::to_repr

    NativeFiberEvent

    pub(all) enum NativeFiberEvent {
    Yielded(Int64)
    Finished(Int64)
    } derive(Eq,
    Debug
    )

    Result of entering or continuing a native fiber.

    NativeFiberEvent::equal

    NativeFiberEvent::not_equal

    fn NativeFiberEvent::not_equal(x : NativeFiberEvent, y : NativeFiberEvent) -> Bool

    NativeFiberPhase

    pub(all) enum NativeFiberPhase {
    Ready
    Running
    Suspended
    Returned
    Cancelled
    } derive(Eq,
    Debug
    )

    Observable lifecycle of a single-threaded native fiber.

    NativeFiberPhase::equal

    NativeFiberPhase::not_equal

    fn NativeFiberPhase::not_equal(x : NativeFiberPhase, y : NativeFiberPhase) -> Bool

    NativeHostcallOutcome

    pub(all) enum NativeHostcallOutcome {
    HostcallCompleted
    HostcallExit(Int)
    HostcallTrap(Int)
    HostcallSuspended
    } derive(Eq,
    Debug
    )

    Typed result returned by a JIT hostcall dispatcher.

    NativeHostcallOutcome::equal

    NativeHostcallOutcome::not_equal

    NativeJITContext

    type NativeJITContext

    NativeJITContext::alloc_guarded_memory

    fn NativeJITContext::alloc_guarded_memory(self : NativeJITContext, initial_pages : Int, max_pages : Int?) ->
    MemoryDescriptor

    NativeJITContext::alloc_indirect_table

    fn NativeJITContext::alloc_indirect_table(self : NativeJITContext, count : Int) -> Bool

    NativeJITContext::bind_callable

    NativeJITContext::bind_callable_registry

    fn NativeJITContext::bind_callable_registry(self : NativeJITContext, registry :
    NativeCallableRegistry
    , local_types : Array[Int], tags : Array[Int], functions? : Array[Int]) -> Unit

    Bind shared Store identities with this instance's local type and tag maps.

    NativeJITContext::bind_globals

    fn NativeJITContext::bind_globals(self : NativeJITContext, globals : FixedArray[Int64]) -> Int64

    Snapshot borrowed global-cell addresses and retain the table until replacement.

    NativeJITContext::bind_segment_drop_flags

    fn NativeJITContext::bind_segment_drop_flags(self : NativeJITContext, data : FixedArray[Bool], elements : FixedArray[Bool]) -> Unit

    Share instance-local dropped bits with the interpreter and Store GC.

    NativeJITContext::call_trampoline

    fn NativeJITContext::call_trampoline(self : NativeJITContext, trampoline_ptr : Int64, func_ptr : Int64, values_vec : FixedArray[Int64], values_len : Int, use_native_fiber : Bool) -> Int raise NativeFiberError

    NativeJITContext::clear_cancellation_callback

    fn NativeJITContext::clear_cancellation_callback(self : NativeJITContext) -> Unit

    Clear the default callback without changing active or parked invocations.

    NativeJITContext::clear_gc_heap

    fn NativeJITContext::clear_gc_heap(self : NativeJITContext) -> Unit

    NativeJITContext::clear_hostcall_callback

    fn NativeJITContext::clear_hostcall_callback(self : NativeJITContext) -> Unit

    NativeJITContext::clear_segments

    fn NativeJITContext::clear_segments(self : NativeJITContext) -> Unit

    NativeJITContext::configure_native_fiber_stack_size

    #alias(alloc_wasm_stack, deprecated="Use configure_native_fiber_stack_size instead")
    fn NativeJITContext::configure_native_fiber_stack_size(self : NativeJITContext, stack_size : Int64) -> Bool

    Configure the guarded stack size used by future native JIT continuations. The stack mapping is allocated only when a continuation starts.

    NativeJITContext::define_continuation_type

    fn NativeJITContext::define_continuation_type(self : NativeJITContext, index : Int, trampoline : Int64, params : ArrayView[
    ValueType
    ], results : ArrayView[
    ValueType
    ]) -> Bool

    NativeJITContext::func_count

    fn NativeJITContext::func_count(self : NativeJITContext) -> Int

    NativeJITContext::func_ptr

    fn NativeJITContext::func_ptr(self : NativeJITContext, func_idx : Int) -> Int64

    NativeJITContext::gc_begin_frame

    fn NativeJITContext::gc_begin_frame(self : NativeJITContext, frame_id : Int64) -> Unit raise NativeSetupError

    NativeJITContext::gc_collect_for_alloc

    fn NativeJITContext::gc_collect_for_alloc(self : NativeJITContext, roots : Array[Int64]) -> Int

    NativeJITContext::gc_end_frame

    fn NativeJITContext::gc_end_frame(self : NativeJITContext) -> Unit

    NativeJITContext::gc_environment_is_clear

    fn NativeJITContext::gc_environment_is_clear(self : NativeJITContext) -> Bool

    NativeJITContext::gc_set_root_scratch

    fn NativeJITContext::gc_set_root_scratch(self : NativeJITContext, roots : Array[Int64]) -> Bool

    NativeJITContext::gc_set_safepoint_table

    fn NativeJITContext::gc_set_safepoint_table(self : NativeJITContext, table_ptr : Int64) -> Unit

    NativeJITContext::gc_use_func_safepoints

    fn NativeJITContext::gc_use_func_safepoints(self : NativeJITContext, func_idx : Int) -> Unit

    NativeJITContext::has_callable_metadata

    fn NativeJITContext::has_callable_metadata(self : NativeJITContext) -> Bool

    NativeJITContext::has_configured_native_fiber_stack_size

    #alias(has_wasm_stack, deprecated="Use has_configured_native_fiber_stack_size instead")
    fn NativeJITContext::has_configured_native_fiber_stack_size(self : NativeJITContext) -> Bool

    Check whether a native-fiber stack size override has been configured.

    NativeJITContext::memory_descriptor

    Retain a bound memory independently of this context. Invalid indices return an empty handle. Passing this handle to descriptor operations keeps the allocation alive throughout the operation.

    NativeJITContext::memory_ptr

    fn NativeJITContext::memory_ptr(self : NativeJITContext, memidx : Int) -> Int64

    Borrow a raw byte address. Use memory_descriptor for accesses that must retain the allocation independently of this context.

    NativeJITContext::memory_size

    fn NativeJITContext::memory_size(self : NativeJITContext, memidx : Int) -> Int64

    NativeJITContext::refresh_table_layout

    fn NativeJITContext::refresh_table_layout(self : NativeJITContext, table_idx : Int) -> Bool

    Refresh one borrowed table from the context it was registered with. The context supplies both the table identity and its live C-side layout.

    NativeJITContext::register_safepoints

    fn NativeJITContext::register_safepoints(self : NativeJITContext, func_idx : Int, safepoints : Array[
    SafepointSite
    ]) -> Bool

    NativeJITContext::set_callable_types

    fn NativeJITContext::set_callable_types(self : NativeJITContext, local_types : Array[Int], parents : Array[Int], entries : Array[(Int64, Int)], tags : Array[Int]) -> Unit

    Install an independent callable view for a standalone context.

    NativeJITContext::set_cancellation_callback

    fn NativeJITContext::set_cancellation_callback(self : NativeJITContext, callback : () -> Bool) -> Unit

    Set the cancellation callback for subsequent invocations. Active and parked invocations retain their existing callback; mutate its captured signal to cancel.

    NativeJITContext::set_continuation_arena

    NativeJITContext::set_cooperative_scheduling

    fn NativeJITContext::set_cooperative_scheduling(self : NativeJITContext, enabled : Bool) -> Unit

    Configure native scheduling for subsequent invocations at instrumented guest safepoints. Active invocations keep their own budget. The embedding must enter this context through a resumable native invocation.

    NativeJITContext::set_exception_arena

    NativeJITContext::set_func

    fn NativeJITContext::set_func(self : NativeJITContext, idx : Int, func_ptr : Int64) -> Unit

    NativeJITContext::set_gc_heap

    NativeJITContext::set_gc_heap_ptr

    NativeJITContext::set_globals

    fn NativeJITContext::set_globals(self : NativeJITContext, globals_ptr : Int64) -> Unit

    Transfer a malloc-owned table of borrowed cell addresses to this context. Prefer bind_globals for MoonBit-owned input.

    NativeJITContext::set_hostcall_callback

    fn NativeJITContext::set_hostcall_callback(self : NativeJITContext, callback : () -> NativeHostcallOutcome) -> Unit

    NativeJITContext::set_indirect

    fn NativeJITContext::set_indirect(self : NativeJITContext, table_idx : Int, func_idx : Int, type_idx : Int) -> Unit

    NativeJITContext::set_memory

    NativeJITContext::set_memory_pointers

    NativeJITContext::set_table_pointers

    NativeJITContext::setup_gc

    fn NativeJITContext::setup_gc(self : NativeJITContext, heap :
    CHeap
    , types : Array[
    SubType
    ], canonical_indices : Array[Int], func_type_indices : Array[Int]) -> Unit raise GCSetupError

    NativeJITContext::setup_gc_with_func_table

    fn NativeJITContext::setup_gc_with_func_table(self : NativeJITContext, heap :
    CHeap
    , types : Array[
    SubType
    ], canonical_indices : Array[Int], func_type_indices : Array[Int], func_table_ptr : Int64, num_funcs : Int) -> Unit raise GCSetupError

    NativeJITContext::setup_segments

    fn NativeJITContext::setup_segments(self : NativeJITContext, datas : Array[
    Data
    ], elem_segments : Array[Array[Int64]], data_dropped? : Array[Bool], elem_dropped? : Array[Bool]) -> Unit raise NativeSetupError

    NativeJITContext::start_continuation

    fn NativeJITContext::start_continuation(self : NativeJITContext, trampoline_ptr : Int64, func_ptr : Int64, values : FixedArray[Int64], values_len : Int, stack_size? : Int64) -> NativeJITContinuation raise NativeFiberError

    NativeJITContext::take_wasi_exit_code

    fn NativeJITContext::take_wasi_exit_code(self : NativeJITContext) -> Int

    NativeJITContext::teardown_gc

    fn NativeJITContext::teardown_gc(self : NativeJITContext) -> Unit

    NativeJITContext::throw_exception_tag

    fn NativeJITContext::throw_exception_tag(self : NativeJITContext, tag_addr : Int) -> Unit raise NativeSetupError

    Stage a module-local exception. Guest delivery occurs after the callback returns.

    NativeJITContext::throw_exception_values

    fn NativeJITContext::throw_exception_values(self : NativeJITContext, tag_addr : Int, values : Array[Int64]) -> Unit raise NativeSetupError

    Stage a module-local exception. Guest delivery occurs after the callback returns.

    NativeJITContext::throw_store_exception_values

    fn NativeJITContext::throw_store_exception_values(self : NativeJITContext, tag_addr : Int, values : Array[Int64]) -> Unit raise NativeSetupError

    Stage an imported exception using its Store tag identity.

    NativeJITContext::try_alloc

    NativeJITContinuation

    type NativeJITContinuation

    Stackful JIT invocation whose entry frame is entirely native.

    MoonBit hostcall callbacks always return before this continuation yields.

    NativeJITContinuation::cancel

    NativeJITContinuation::continue_after_hostcall

    fn NativeJITContinuation::continue_after_hostcall(self : NativeJITContinuation, retry~ : Bool) -> NativeJITContinuationEvent raise NativeFiberError

    Resume a continuation stopped at an imported hostcall.

    retry=true re-enters only the suspended hostcall before continuing the native guest frame. It never restarts the guest function from its entry.

    NativeJITContinuation::continue_with

    NativeJITContinuation::phase

    NativeJITContinuationEvent

    pub(all) enum NativeJITContinuationEvent {
    NativeSuspended(NativeSuspensionReason)
    NativeJITCompleted
    NativeJITTrapped(Int)
    } derive(Eq,
    Debug
    )

    Result of advancing a stackful JIT invocation.

    NativeJITContinuationEvent::equal

    NativeJITContinuationEvent::not_equal

    NativeSuspensionReason

    pub(all) enum NativeSuspensionReason {
    HostCall
    CooperativeYield
    AtomicWait
    } derive(Eq,
    Debug
    )

    NativeSuspensionReason::equal

    NativeSuspensionReason::not_equal

    NativeTarget

    pub(all) enum NativeTarget {
    X64
    AArch64
    } derive(Eq,
    Debug
    )

    NativeTarget::equal

    NativeTarget::not_equal

    fn NativeTarget::not_equal(x : NativeTarget, y : NativeTarget) -> Bool

    Profiler

    pub(all) struct Profiler {
    counter : CallCounter
    threshold : HotThreshold
    hot_functions :
    HashSet
    [Int]
    pending_compilation :
    HashSet
    [Int]
    compiled_functions :
    HashSet
    [Int]
    }

    Complete profiler combining call counting and hot detection
    impl Show for Profiler

    Profiler::Profiler

    fn Profiler::Profiler(threshold : HotThreshold) -> Profiler

    Profiler::get_function_temperature

    fn Profiler::get_function_temperature(self : Profiler, func_idx : Int) -> FunctionTemperature

    Get temperature for a specific function

    Profiler::get_pending

    fn Profiler::get_pending(self : Profiler) -> Array[Int]

    Get list of functions pending compilation

    Profiler::is_compiled

    fn Profiler::is_compiled(self : Profiler, func_idx : Int) -> Bool

    Check if a function is compiled

    Profiler::mark_compiled

    fn Profiler::mark_compiled(self : Profiler, func_idx : Int) -> Unit

    Mark a function as compiled

    Profiler::output

    fn Profiler::output(self : Profiler, logger : &Logger) -> Unit

    Profiler::record_call

    fn Profiler::record_call(self : Profiler, func_idx : Int) -> (Int, Bool)

    Record a function call and return whether it should be compiled Returns: (new_count, should_compile)

    Profiler::should_use_jit

    fn Profiler::should_use_jit(self : Profiler, func_idx : Int) -> Bool

    Check if a function should use JIT code

    Profiler::stats

    fn Profiler::stats(self : Profiler) -> (Int, Int, Int, Int)

    Get profiling statistics

    Profiler::to_string

    fn Profiler::to_string(self : Profiler) -> String

    RuntimeSymbol

    pub(all) struct RuntimeSymbol {
    name : String
    address : Int64
    } derive(Eq,
    Debug
    )

    RuntimeSymbol::equal

    RuntimeSymbol::not_equal

    fn RuntimeSymbol::not_equal(x : RuntimeSymbol, y : RuntimeSymbol) -> Bool

    RuntimeSymbolResolver

    pub(all) struct RuntimeSymbolResolver {
    symbols : Array[RuntimeSymbol]
    } derive(
    Debug
    )

    RuntimeSymbolResolver::RuntimeSymbolResolver

    fn RuntimeSymbolResolver::RuntimeSymbolResolver() -> RuntimeSymbolResolver

    RuntimeSymbolResolver::add_symbol

    fn RuntimeSymbolResolver::add_symbol(self : RuntimeSymbolResolver, name : String, address : Int64) -> Unit

    RuntimeSymbolResolver::resolve

    fn RuntimeSymbolResolver::resolve(self : RuntimeSymbolResolver, name : String) -> Int64?

    RuntimeSymbolResolver::resolve_symbol

    fn RuntimeSymbolResolver::resolve_symbol(self : RuntimeSymbolResolver, name : String) -> RuntimeSymbol?

    RuntimeSymbolResolver::with_wasmoon_runtime_symbols

    fn RuntimeSymbolResolver::with_wasmoon_runtime_symbols() -> RuntimeSymbolResolver

    TrapDetails

    pub struct TrapDetails {
    signal : Int
    pc : Int64
    lr : Int64
    fp : Int64
    frame_lr : Int64
    fault_addr : Int64
    brk_imm : Int
    func_idx : Int
    x0 : Int64
    x1 : Int64
    x2 : Int64
    x3 : Int64
    x6 : Int64
    x7 : Int64
    x8 : Int64
    x9 : Int64
    x10 : Int64
    x11 : Int64
    x15 : Int64
    }

    Low-level trap detail captured by the JIT signal handlers (best-effort).

    TrapDetails::TrapDetails

    fn TrapDetails::TrapDetails() -> TrapDetails

    TrapReport

    pub(all) struct TrapReport {
    trap_kind : String
    message : String
    signal : Int
    signal_name : String
    pc : Int64
    lr : Int64
    fp : Int64
    frame_lr : Int64
    fault_addr : Int64
    brk_imm : Int
    wasm_func_idx : Int?
    wasm_func_name : String?
    wasm_offset : Int64?
    wasm_frames : Array[WasmTrapFrame]
    host_frames : Array[String]
    dump_path : String?
    }

    Structured trap report for native integrations.

    VMContextLayout

    pub(all) struct VMContextLayout {
    memory0_offset : Int
    memory0_base_offset : Int
    memory0_size_offset : Int
    func_table_offset : Int
    table0_base_offset : Int
    table0_elements_offset : Int
    globals_offset : Int
    tables_offset : Int
    table_count_offset : Int
    func_count_offset : Int
    table_sizes_offset : Int
    table_max_sizes_offset : Int
    memories_offset : Int
    memory_count_offset : Int
    debug_current_func_idx_offset : Int
    gc_heap_ptr_offset : Int
    gc_heap_limit_offset : Int
    gc_heap_offset : Int
    pointer_stride : Int
    global_value_stride : Int
    table_entry_value_offset : Int
    table_entry_stride : Int
    func_table_entry_stride : Int
    }

    VMContext field offsets accessed by generated JIT code.

    The standalone legacy layout comes from native C declarations; module-shaped layouts come from the shared MoonBit layout builder. Embedders and frontends should query this value instead of copying raw offsets into lowering code.

    WasmTrapFrame

    pub(all) struct WasmTrapFrame {
    pc : Int64
    func_idx : Int
    func_name : String
    wasm_offset : Int64
    }

    A resolved wasm frame in a native trap report.

    EXCEPTION_REF_TAG

    let EXCEPTION_REF_TAG : Int64

    WASMOON_CODEGEN_REVISION

    let WASMOON_CODEGEN_REVISION : String

    Revision of the current direct native target code generator.

    Advance this value whenever compiler changes can alter emitted code while preserving the artifact format and JIT ABI. Persistent caches use it as part of their compatibility identity.

    WASMOON_JIT_ABI_VERSION

    let WASMOON_JIT_ABI_VERSION : Int

    Version of the Wasmoon internal JIT calling and runtime contract.

    alloc_guarded_memory_desc

    fn alloc_guarded_memory_desc(initial_pages : Int, max_pages : Int?, is_shared? : Bool) ->
    MemoryDescriptor

    Allocate a guarded (reserved) memory descriptor for memory32 memory0. This is required for bounds-check elimination; out-of-bounds accesses trap via guard pages.

    alloc_memory

    fn alloc_memory(size : Int64) -> Int64

    Allocate unmanaged storage for native ABI fixtures (returns 0 on failure). The caller owns its bounds and must free it exactly once. Use descriptors for linear-memory access through checked operations.

    alloc_memory_desc

    fn alloc_memory_desc(size_bytes : Int64, max_pages : Int64?, is_memory64? : Bool, page_size_log2? : Int, is_shared? : Bool) ->
    MemoryDescriptor

    Allocate a wasmoon_memory_t descriptor with owned backing memory.

    artifact_module_identity

    fn artifact_module_identity(name : String, source_module : Bytes, semantic_features : Bytes) ->
    ModuleIdentity

    atomic_fence

    fn atomic_fence() -> Unit

    atomic_notify

    fn atomic_notify(descriptor :
    MemoryDescriptor
    , offset : Int64, count : Int) -> Int

    atomic_wait_begin

    fn atomic_wait_begin(descriptor :
    MemoryDescriptor
    , offset : Int64, width : Int, expected : Int64, timeout : Int64) ->
    NativeAtomicWait
    ?

    build_artifact_manifest

    Build the exact compatibility manifest for a selected target.

    required_cpu_features contains only optional features beyond the baseline architecture contract. AArch64 Advanced SIMD and x64 SSE2 are baseline requirements of the corresponding Wasmoon targets and are therefore not repeated here.

    build_entry_trampoline_for_target

    build_host_artifact_manifest

    Build a manifest for the current process without guessing an unsupported architecture or operating-system ABI.

    build_hostcall_import_trampoline_for_target

    fn build_hostcall_import_trampoline_for_target(param_types : ArrayView[
    ValueType
    ], result_types : ArrayView[
    ValueType
    ], host_func_addr : Int, target : NativeTarget) -> HostcallImportTrampolineCode raise HostcallImportTrampolineError

    can_use_reusable_entry_trampoline

    fn can_use_reusable_entry_trampoline(param_types : ArrayView[
    ValueType
    ], result_types : ArrayView[
    ValueType
    ]) -> Bool

    classify_import_function_ptr

    fn classify_import_function_ptr(ptr : Int64) -> ImportFunctionResolution

    collect_gc_root_args

    fn collect_gc_root_args(args : Array[Int64], param_types : ArrayView[
    ValueType
    ]) -> Array[Int64]

    compile_wasm_body_artifact_function

    fn compile_wasm_body_artifact_function(function :
    Function
    , validation_context :
    WasmValidationContext
    , target : NativeTarget, function_index~ : Int, signature~ :
    Signature
    , use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int], context_shape? :
    ContextShape
    ) ->
    FunctionCode
    raise JitPipelineError

    compile_wasm_body_diagnostics_for_target

    fn compile_wasm_body_diagnostics_for_target(function :
    Function
    , validation_context :
    WasmValidationContext
    , target : NativeTarget, use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int], context_shape? :
    ContextShape
    , function_index? : Int) -> JitPipelineDiagnostics raise JitPipelineError

    Inspect Wasm MilkIR through the production compiler. Legacy layout and the unknown owner index remain defaults for existing standalone callers; module diagnostics should use a shaped NativeCompiler and the absolute function index.

    cooperative_idle

    fn cooperative_idle() -> Unit

    Briefly sleep an idle cooperative scheduler while only waits remain.

    count_entry_trampoline_slots

    fn count_entry_trampoline_slots(types : ArrayView[
    ValueType
    ]) -> Int

    decode_externref

    fn decode_externref(raw : Int64) -> Int?

    decode_funcref_idx

    fn decode_funcref_idx(raw : Int64) -> Int?

    decode_gc_heap_ref

    fn decode_gc_heap_ref(raw : Int64) -> Int?

    decode_heap_ref

    fn decode_heap_ref(encoded : Int64) -> Int

    Decode a heap reference from JIT representation Returns 0-based heap_idx for MoonBit Store/CHeap

    decode_i31

    fn decode_i31(encoded : Int64) -> Int

    Decode an i31 value from JIT representation

    decode_store_funcref

    fn decode_store_funcref(raw : Int64) -> Int?

    encode_exception_ref

    fn encode_exception_ref(index : Int) -> Int64

    encode_externref

    fn encode_externref(host_idx : Int) -> Int64

    encode_funcref_idx

    fn encode_funcref_idx(func_idx : Int) -> Int64

    encode_gc_heap_ref

    fn encode_gc_heap_ref(heap_idx0 : Int) -> Int64

    encode_heap_ref

    fn encode_heap_ref(heap_idx : Int) -> Int64

    Encode a heap reference (struct or array) for JIT heap_idx is 0-based (from MoonBit Store/CHeap) JIT uses 1-based gc_ref internally to avoid collision with null (0)

    encode_i31

    fn encode_i31(value : Int) -> Int64

    Encode an i31 value for JIT (tagged pointer with lowest bit = 1)

    encode_null_ref

    fn encode_null_ref() -> Int64

    encode_store_funcref

    fn encode_store_funcref(address : Int) -> Int64

    Stable Store function identity; executable registration is independent.

    entry_trampoline_signature_hash

    fn entry_trampoline_signature_hash(param_types : ArrayView[
    ValueType
    ], result_types : ArrayView[
    ValueType
    ]) -> Int64

    entry_trampoline_type_codes

    fn entry_trampoline_type_codes(types : ArrayView[
    ValueType
    ]) -> Array[Int]

    entry_trampoline_value_type_code

    fn entry_trampoline_value_type_code(ty :
    ValueType
    ) -> Int

    format_signal_name

    fn format_signal_name(sig : Int) -> String

    format_trap_report_message

    fn format_trap_report_message(report : TrapReport) -> String

    format_u64_hex

    fn format_u64_hex(v : Int64) -> String

    free_memory

    fn free_memory(mem_ptr : Int64) -> Unit

    Release an unmanaged allocation returned by alloc_memory. The caller must ensure no aliases remain and must not pass a descriptor backing address.

    gc_debug_set_fail_alloc

    fn gc_debug_set_fail_alloc(fail_at : Int, fail_every? : Int) -> Unit

    Configure allocation fault injection for debugging

    get_hostcall_func_addr

    fn get_hostcall_func_addr() -> Int

    Get the runtime store function address for the current JIT -> hostcall.

    This value is set by wasmoon_jit_hostcall right before invoking the MoonBit hostcall callback.

    get_hostcall_num_arg_slots

    fn get_hostcall_num_arg_slots() -> Int

    Get the number of argument slots in values_vec.

    Note: slots are 8 bytes each; V128 occupies 2 slots.

    get_hostcall_num_result_slots

    fn get_hostcall_num_result_slots() -> Int

    Get the number of result slots in values_vec.

    Note: slots are 8 bytes each; V128 occupies 2 slots.

    get_import_trampoline

    fn get_import_trampoline(_module_name : String, _field_name : String) -> Int64?

    Builtins use linked host functions and the typed hostcall bridge. No raw native fallback is provided; callers without a Store must supply imports.

    get_last_trap_details

    fn get_last_trap_details() -> TrapDetails

    Get the last captured trap details (best-effort). These fields are reset at the start of each JIT call.

    get_temperature

    fn get_temperature(count : Int, threshold : HotThreshold) -> FunctionTemperature

    Determines the temperature of a function based on its call count

    host_native_target

    fn host_native_target() -> NativeTarget raise JitPipelineError

    host_operating_system_abi

    hostcall_value_byte_count

    fn hostcall_value_byte_count(ty :
    ValueType
    ) -> Int

    hostcall_value_slot_count

    fn hostcall_value_slot_count(ty :
    ValueType
    ) -> Int

    hostcall_value_slot_read

    fn hostcall_value_slot_read(slot : Int) -> Int64

    hostcall_value_slot_write

    fn hostcall_value_slot_write(slot : Int, value : Int64) -> Unit

    i64_to_value

    Decode a runtime word to a Value based on expected type.

    A word carries no high half, so a V128 request yields a vector whose upper 8 bytes are zero. Callers reading a stored field want slot_to_value, which has the other half.

    is_cancelled_trap_code

    fn is_cancelled_trap_code(code : Int) -> Bool

    is_exception_ref

    fn is_exception_ref(raw : Int64) -> Bool

    is_funcref_ptr

    fn is_funcref_ptr(raw : Int64) -> Bool

    is_i31

    fn is_i31(value : Int64) -> Bool

    Check if a JIT value is an i31 (has tag bit set)

    is_jit_supported_module

    fn is_jit_supported_module(module_name : String) -> Bool

    Recognize the standard spectest resources shared with the interpreter.

    is_null

    fn is_null(value : Int64) -> Bool

    Check if a JIT value is null

    is_null_ref

    fn is_null_ref(raw : Int64) -> Bool

    is_wasi_exit_trap_code

    fn is_wasi_exit_trap_code(code : Int) -> Bool

    jit_trap_message

    fn jit_trap_message(code : Int) -> String

    make_cstring

    fn make_cstring(s : String) -> FixedArray[Byte]

    memory_atomic_compare_exchange

    fn memory_atomic_compare_exchange(descriptor :
    MemoryDescriptor
    , offset : Int64, width : Int, expected : Int64, replacement : Int64) -> Int64

    memory_atomic_load

    fn memory_atomic_load(descriptor :
    MemoryDescriptor
    , offset : Int64, width : Int) -> Int64

    The descriptor must remain live; its offset, width and alignment must have been checked by the linear-memory owner before entering these primitives.

    memory_atomic_rmw

    fn memory_atomic_rmw(descriptor :
    MemoryDescriptor
    , offset : Int64, width : Int, operation : Int, value : Int64) -> Int64

    memory_atomic_store

    fn memory_atomic_store(descriptor :
    MemoryDescriptor
    , offset : Int64, width : Int, value : Int64) -> Unit

    memory_descriptor_copy

    fn memory_descriptor_copy(destination_memory :
    MemoryDescriptor
    , destination : Int64, source_memory :
    MemoryDescriptor
    , source : Int64, length : Int64) -> Int

    Copy checked byte ranges between live memory descriptors.

    memory_descriptor_fill

    fn memory_descriptor_fill(mem_desc_ptr :
    MemoryDescriptor
    , destination : Int64, value : Int, size : Int) -> Int

    memory_descriptor_fill64

    fn memory_descriptor_fill64(memory :
    MemoryDescriptor
    , destination : Int64, value : Int, length : Int64) -> Int

    Fill a checked byte range of a live memory descriptor.

    memory_descriptor_grow

    fn memory_descriptor_grow(mem_desc_ptr :
    MemoryDescriptor
    , delta_pages : Int, max_pages : Int) -> Int

    memory_descriptor_grow64

    fn memory_descriptor_grow64(mem_desc_ptr :
    MemoryDescriptor
    , delta_pages : Int64) -> Int64

    memory_descriptor_layout

    fn memory_descriptor_layout() -> MemoryDescriptorLayout

    memory_descriptor_length

    fn memory_descriptor_length(mem_desc_ptr :
    MemoryDescriptor
    ) -> Int64

    memory_descriptor_move

    fn memory_descriptor_move(mem_desc_ptr :
    MemoryDescriptor
    , destination : Int64, source : Int64, size : Int) -> Int

    memory_descriptor_read

    fn memory_descriptor_read(mem_desc_ptr :
    MemoryDescriptor
    , offset : Int64, out : FixedArray[Byte], size : Int) -> Int

    Return 0 on success, -1 for an invalid descriptor, memory range or destination buffer length. Rejected operations leave the destination unchanged.

    memory_descriptor_write

    fn memory_descriptor_write(mem_desc_ptr :
    MemoryDescriptor
    , offset : Int64, data : FixedArray[Byte], size : Int) -> Int

    Return 0 on success, -1 for an invalid descriptor, memory range or source buffer length. Rejected operations leave the destination unchanged.

    memory_descriptor_write_bytes

    fn memory_descriptor_write_bytes(mem_desc_ptr :
    MemoryDescriptor
    , offset : Int64, data : Bytes, size : Int) -> Int

    Return 0 on success, -1 for an invalid descriptor, memory range or source buffer length. Rejected operations leave the destination unchanged. Return 0 on success, -1 for an invalid descriptor, memory range or source buffer length. Rejected operations leave the destination unchanged.

    native_value_slot_read

    fn native_value_slot_read(base : Int64, slot : Int) -> Int64

    Read an i64-sized slot from a JIT-owned native value area.

    native_value_slot_write

    fn native_value_slot_write(base : Int64, slot : Int, value : Int64) -> Unit

    Write an i64-sized slot in a JIT-owned native value area.

    plan_entry_trampoline_for_target

    plan_hostcall_import_trampoline_layout

    fn plan_hostcall_import_trampoline_layout(param_types : ArrayView[
    ValueType
    ], result_types : ArrayView[
    ValueType
    ], max_int_regs : Int, max_float_regs : Int) -> HostcallImportTrampolineLayout

    plan_milkir_integration_for_target

    fn plan_milkir_integration_for_target(func :
    Function
    , target : NativeTarget) -> JitIntegrationPlan raise JitPipelineError

    plan_wasm_body_aarch64_code_object

    fn plan_wasm_body_aarch64_code_object(function :
    Function
    , validation_context :
    WasmValidationContext
    , use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int]) ->
    UnlinkedCodeObject
    raise JitPipelineError

    plan_wasm_body_milkir_integration_for_target

    fn plan_wasm_body_milkir_integration_for_target(func :
    Function
    , validation_context :
    WasmValidationContext
    , target : NativeTarget) -> JitIntegrationPlan raise JitPipelineError

    plan_wasm_body_x64_code_object

    fn plan_wasm_body_x64_code_object(function :
    Function
    , validation_context :
    WasmValidationContext
    , use_subtype_indirect_check? : Bool, canonical_type_indices? : Array[Int]) ->
    UnlinkedCodeObject
    raise JitPipelineError

    resolve_import_function

    fn resolve_import_function(external_imports : Map[String, Map[String, Int64]], module_name : String, field_name : String) -> ImportFunctionResolution

    resolve_import_function_ptr

    fn resolve_import_function_ptr(external_imports : Map[String, Map[String, Int64]], module_name : String, field_name : String) -> Int64?

    sanitize_debug_filename

    fn sanitize_debug_filename(s : String) -> String

    shaped_vmcontext_layout

    slot_to_value

    Decode a C heap slot to a Value based on expected type.

    Total, and inverse to value_to_slot: every ValueType names a value this can produce, so no case has to fall back to a value of some other type the way V128 => I64(raw) once did.

    tag_funcref_ptr

    fn tag_funcref_ptr(func_ptr : Int64) -> Int64

    take_pending_trap_message

    fn take_pending_trap_message() -> String?

    untag_funcref_ptr

    fn untag_funcref_ptr(tagged_ptr : Int64) -> Int64

    value_to_i64

    fn value_to_i64(value :
    Value
    ) -> Int64

    Encode a Value as a bare runtime word, for the root array the collector scans. A root's high word would never be read, so dropping it is not a loss of information here.

    value_to_slot

    Encode a Value into a C heap slot.

    Total, and that is the point: a slot is 16 bytes, so there is no value this cannot represent and no case left to abort on.

    Encoding rules for lo:
    • i32: sign-extended to i64
    • i64: as-is
    • f32: lower 32 bits (IEEE 754 bits)
    • f64: as-is (IEEE 754 bits)
    • v128: low 8 bytes, with the high 8 in hi
    • structref/arrayref: (gc_ref) << 1, where gc_ref = idx + 1 (even, low bit = 0)
    • funcref: tagged Store function identity (0 = null)
    • externref: extern index + 1 (0 = null)
    • exnref: exception index + 1 (0 = null)
    • i31: (value << 1) | 1 (tagged, low bit = 1)
    • null: 0

    GC reference detection in gc_heap_mark uses: (lo & 1) == 0 && lo > 0

    value_type_may_hold_gc_ref

    fn value_type_may_hold_gc_ref(ty :
    ValueType
    ) -> Bool

    vmcontext_layout

    fn vmcontext_layout() -> VMContextLayout

    wasm_function_signature

    wasm_import_identity

    fn wasm_import_identity(function_index : Int, module_name : String, function_name : String, function_type :
    FuncType
    ) ->
    ImportIdentity

    wasm_runtime_symbols

    wasm_trap_payload

    fn wasm_trap_payload(reason : String) -> Int

    Map Wasm trap reasons to the payload consumed by Wasmoon's native trap handler. Native lowering only carries the integer payload; this module owns the Wasmoon-specific reason-to-payload policy.

    wasmoon_runtime_external_symbols

    fn wasmoon_runtime_external_symbols() -> Array[
    ExternalSymbol
    ]

    Stable external-symbol whitelist accepted by Wasmoon artifacts.