wasmoon_jit

Wasmoon-specific JIT integration and native runtime glue

wasm
jit
runtime
native
Download zip
Author
Version
0.14.0
License
Apache-2.0
Last updated
16 hours ago
Downloads
114

#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, v9 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, v9 artifacts, and installed-code lifecycle management.

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 = 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 v9 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.

#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.

ArtifactIncompatible

pub suberror ArtifactIncompatible {
TargetMismatch(expected~ :
TargetSpec
, actual~ :
TargetSpec
)
MissingCpuFeature(name~ : String)
DuplicateCpuFeature(name~ : String)
JitAbiVersionMismatch(expected~ : Int, actual~ : Int)
CodegenRevisionMismatch(expected~ : String, actual~ : String)
ModuleIdentityMismatch(expected~ :
ModuleIdentity
, actual~ :
ModuleIdentity
)
CompilationPolicyMismatch(expected~ :
CompilationPolicy
, actual~ :
CompilationPolicy
)
DuplicateFunctionIndex(index~ : Int)
DuplicateSymbol(name~ : String)
UnknownSymbol(kind~ : String, name~ : String)
} derive(Eq,
Debug
)

ArtifactIncompatible::equal

ArtifactIncompatible::not_equal

ArtifactLoadError

ArtifactLoadError::equal

ArtifactLoadError::not_equal

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

CHeapError

pub(all) suberror CHeapError {
OutOfBoundsArrayAccess
NullReference
OutOfMemory
}

CHeap error types for runtime errors

GCSetupError

pub(all) suberror GCSetupError {
MissingJITContext
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

JitInstallError

pub suberror JitInstallError {
ResolutionFailed(kind~ : String, name~ : String)
AllocationFailed(function_index~ : Int)
RelocationFailed(function_index~ : Int, message~ : String)
ProtectionFailed(function_index~ : Int)
RegistrationFailed(function_index~ : Int, message~ : String)
PublicationFailed(message~ : String)
TrampolineAllocationFailed(code_size~ : Int)
} derive(Eq,
Debug
)

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

JitInstallError::equal

JitInstallError::not_equal

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

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

NativeExecutionStateError

pub suberror NativeExecutionStateError {
ExecutionStateSealed
UnknownInvocation(Int64)
InvocationNotActive(Int64)
InvocationNotParked(Int64)
InvocationNotCurrent(Int64)
} derive(Eq,
Debug
)

Invalid transition in the Store-owned native invocation state machine.

NativeExecutionStateError::equal

NativeExecutionStateError::not_equal

NativeExecutionStateError::output

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

NativeExecutionStateError::to_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

ArtifactCompatibility

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

ArtifactCompatibility::equal

ArtifactCompatibility::not_equal

BacktraceFrame

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

Backtrace frame

CHeap

pub struct CHeap {
ptr : Int64
} derive(
Debug
)

C-managed GC Heap The heap is automatically freed when this object is garbage collected.

CHeap::CHeap

fn CHeap::CHeap(capacity? : Int) -> CHeap

Create a new C heap with the given initial capacity

CHeap::alloc_array

fn CHeap::alloc_array(self : CHeap, type_idx : Int, len : Int, init_value :
Value
) -> Int raise CHeapError

Allocate a new array with initial value Returns gc_ref (0-based index for external use)

CHeap::alloc_array_from_values

fn CHeap::alloc_array_from_values(self : CHeap, type_idx : Int, elements : Array[
Value
]) -> Int raise CHeapError

Allocate a new array from existing values Returns gc_ref (0-based index for external use)

CHeap::alloc_struct

fn CHeap::alloc_struct(self : CHeap, type_idx : Int, fields : Array[
Value
]) -> Int raise CHeapError

Allocate a new struct Returns gc_ref (0-based index for external use)

CHeap::array_copy

fn CHeap::array_copy(self : CHeap, dst_idx : Int, dst_offset : Int, src_idx : Int, src_offset : Int, count : Int) -> Unit raise CHeapError

Copy array elements

CHeap::array_fill

fn CHeap::array_fill(self : CHeap, array_idx : Int, offset : Int, value :
Value
, count : Int) -> Unit raise CHeapError

Fill array elements with a value

CHeap::array_get

fn CHeap::array_get(self : CHeap, array_idx : Int, elem_idx : Int, elem_type :
ValueType
) ->
Value
raise CHeapError

Get an array element

CHeap::array_len

fn CHeap::array_len(self : CHeap, array_idx : Int) -> Int

Get array length

CHeap::array_set

fn CHeap::array_set(self : CHeap, array_idx : Int, elem_idx : Int, value :
Value
) -> Unit raise CHeapError

Set an array element

CHeap::collect

fn CHeap::collect(self : CHeap, roots : Array[
Value
]) -> Int

Perform garbage collection with given roots Returns the number of objects collected

CHeap::free

fn CHeap::free(self : CHeap) -> Unit

Free the C heap (called explicitly if needed before GC)

CHeap::get_barrier_writes

fn CHeap::get_barrier_writes(self : CHeap) -> Int

Get total number of write-barrier calls recorded

CHeap::get_base

fn CHeap::get_base(self : CHeap) -> Int64

Get heap base pointer (for JIT inline access)

CHeap::get_capacity

fn CHeap::get_capacity(self : CHeap) -> Int64

Get heap capacity (total allocated bytes)

CHeap::get_kind

fn CHeap::get_kind(self : CHeap, idx : Int) -> Int

Get the kind of an object (1=struct, 2=array)

CHeap::get_object_count

fn CHeap::get_object_count(self : CHeap) -> Int

Get number of objects in heap

CHeap::get_offset

fn CHeap::get_offset(self : CHeap, idx : Int) -> Int

Get object offset in heap (for JIT inline access)

CHeap::get_ptr

fn CHeap::get_ptr(self : CHeap) -> Int64

Get the raw C pointer (for JIT)

CHeap::get_size

fn CHeap::get_size(self : CHeap) -> Int64

Get current heap size (bytes used)

CHeap::get_total_allocations

fn CHeap::get_total_allocations(self : CHeap) -> Int

Get total number of allocations since heap creation

CHeap::get_total_collections

fn CHeap::get_total_collections(self : CHeap) -> Int

Get total number of GC cycles performed

CHeap::get_type_idx

fn CHeap::get_type_idx(self : CHeap, idx : Int) -> Int

Get the type index of an object

CHeap::get_usage_ratio

fn CHeap::get_usage_ratio(self : CHeap) -> Double

Get heap usage ratio (0.0 to 1.0)

CHeap::is_array

fn CHeap::is_array(self : CHeap, idx : Int) -> Bool

Check if this is an array

CHeap::is_struct

fn CHeap::is_struct(self : CHeap, idx : Int) -> Bool

Check if this is a struct

CHeap::is_valid

fn CHeap::is_valid(self : CHeap, idx : Int) -> Bool

Check if an object reference is valid

CHeap::make_allocation_rollback

fn CHeap::make_allocation_rollback(self : CHeap, roots : () -> Array[
Value
]) -> (() -> Unit)

Return an owner-bound action that reclaims later allocations unless they remain reachable when the action runs. Retained object-table indices are never reused.

CHeap::should_collect

fn CHeap::should_collect(self : CHeap, threshold? : Double) -> Bool

Check if GC should be triggered based on heap usage Default threshold is 75% of capacity

CHeap::struct_get

fn CHeap::struct_get(self : CHeap, struct_idx : Int, field_idx : Int, field_type :
ValueType
) ->
Value

Get a struct field value

CHeap::struct_set

fn CHeap::struct_set(self : CHeap, struct_idx : Int, field_idx : Int, value :
Value
) -> Unit

Set a struct field value

CHeap::to_repr

CHeap::verify

fn CHeap::verify(self : CHeap, verbose? : Bool) -> Bool

Verify heap invariants (for debugging)

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

CompilationDecision

pub(all) enum CompilationDecision {
Interpret
CompileAndExecute(CompilationMode)
ExecuteCompiled
}

Decision about what to do with a function call

CompilationDecision::output

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

CompilationDecision::to_string

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

CompilationMode

pub(all) enum CompilationMode {
Interpret
Baseline
Optimized
}

The compilation mode for a function

CompilationMode::output

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

CompilationMode::to_string

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

CompilationQueue

pub(all) struct CompilationQueue {
requests : Array[CompilationRequest]
max_size : Int
}

Queue of pending compilation requests

CompilationQueue::CompilationQueue

fn CompilationQueue::CompilationQueue(max_size : Int) -> CompilationQueue

CompilationQueue::clear

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

Clear the queue

CompilationQueue::contains

fn CompilationQueue::contains(self : CompilationQueue, func_idx : Int) -> Bool

Check if a function is in the queue

CompilationQueue::dequeue

Get the next request to process

CompilationQueue::enqueue

fn CompilationQueue::enqueue(self : CompilationQueue, request : CompilationRequest) -> Bool

Add a compilation request to the queue

CompilationQueue::is_empty

fn CompilationQueue::is_empty(self : CompilationQueue) -> Bool

Check if queue is empty

CompilationQueue::length

fn CompilationQueue::length(self : CompilationQueue) -> Int

Get queue length

CompilationRequest

pub(all) struct CompilationRequest {
func_idx : Int
mode : CompilationMode
priority : Int
}

A request to compile a function

CompilationRequest::CompilationRequest

fn CompilationRequest::CompilationRequest(func_idx : Int, mode : CompilationMode) -> CompilationRequest

CompilationRequest::with_priority

fn CompilationRequest::with_priority(func_idx : Int, mode : CompilationMode, priority : Int) -> CompilationRequest

CompilationStrategy

pub(all) struct CompilationStrategy {
profiler : Profiler
queue : CompilationQueue
config : TieredConfig
decisions_interpret : Int
decisions_compile : Int
decisions_compiled : Int
}

The main compilation strategy manager

CompilationStrategy::CompilationStrategy

fn CompilationStrategy::CompilationStrategy(config : TieredConfig) -> CompilationStrategy

CompilationStrategy::decide

fn CompilationStrategy::decide(self : CompilationStrategy, func_idx : Int) -> CompilationDecision

Make a compilation decision for a function call

CompilationStrategy::is_compiled

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

Check if a function is compiled

CompilationStrategy::mark_compiled

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

Mark a function as compiled

CompilationStrategy::next_to_compile

Get the next function to compile (for background compilation)

CompilationStrategy::output

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

CompilationStrategy::schedule_compilation

fn CompilationStrategy::schedule_compilation(self : CompilationStrategy, func_idx : Int, mode : CompilationMode) -> Bool

Schedule a function for background compilation

CompilationStrategy::stats

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

Get strategy statistics

CompilationStrategy::to_string

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

DWARFBuilder

pub struct DWARFBuilder {
// private fields
}

DWARF debug info builder Accumulates function metadata and generates DWARF sections

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 the debug info if it was registered

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) -> Unit

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. 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

ExecCode

type ExecCode

GC-managed executable code block wrapper.

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

GcSlot

pub struct GcSlot {
lo : Int64
hi : Int64
} derive(Eq,
Debug
)

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.

GcSlot::equal

fn GcSlot::equal(GcSlot, GcSlot) -> Bool

GcSlot::not_equal

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

GcSlot::to_repr

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

InstalledCode

pub struct InstalledCode {
// private fields
}

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.

InstalledCode::entry_address

fn InstalledCode::entry_address(self : InstalledCode, function_index : Int) -> Int64?

InstalledCode::functions

InstalledCode::imports

InstalledCode::release

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

Release every executable mapping owned by this installation.

The embedding must ensure that no invocation or continuation can still enter these addresses. Repeated calls are harmless.

InstalledFunction

pub struct InstalledFunction {
// private fields
}

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.

InstalledFunction::code_address

fn InstalledFunction::code_address(self : InstalledFunction) -> Int64

InstalledFunction::code_size

fn InstalledFunction::code_size(self : InstalledFunction) -> Int

InstalledFunction::entry_address

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

InstalledFunction::entry_offset

fn InstalledFunction::entry_offset(self : InstalledFunction) -> Int

InstalledFunction::frame_size

fn InstalledFunction::frame_size(self : InstalledFunction) -> Int

InstalledImport

pub struct InstalledImport {
// private fields
}

A resolved import retained by a committed installation.

InstalledImport::address

fn InstalledImport::address(self : InstalledImport) -> Int64

InstalledTrampoline

pub struct InstalledTrampoline {
// private fields
}

Opaque ownership of process-local executable trampoline code.

InstalledTrampoline::entry_address

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

InstalledTrampoline::release

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

Release this trampoline after its owning execution context is closed.

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

JITTable

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

JITTable::get_entry_type

fn JITTable::get_entry_type(self : JITTable, table_idx : Int) -> Int

Read raw entry type index from the shared table.

JITTable::get_entry_value

fn JITTable::get_entry_value(self : JITTable, table_idx : Int) -> Int64

Read raw entry value bits from the shared table.

JITTable::get_max

fn JITTable::get_max(self : JITTable) -> Int?

Get the table max size.

JITTable::get_size

fn JITTable::get_size(self : JITTable) -> Int

Get the table size.

JITTable::raw_ptr

fn JITTable::raw_ptr(self : JITTable) -> Int64

Get the raw shared table pointer.

JITTable::set

fn JITTable::set(self : JITTable, table_idx : Int, func_ptr : Int64, type_hash : Int) -> Unit

Set an entry in the shared table.

JITTable::to_repr

JITTableOwner

type JITTableOwner derive(
Debug
)

Destruction capability for one shared JIT table allocation.

JITTableOwner::close

fn JITTableOwner::close(self : JITTableOwner) -> Unit

Release the owned shared table allocation. Repeated close calls are harmless.

JITTableOwner::table

fn JITTableOwner::table(self : JITTableOwner) -> JITTable

Borrow the table without transferring its destruction capability.

JITTableOwner::try_alloc

fn JITTableOwner::try_alloc(size : Int, max : Int?) -> JITTableOwner?

Create a new owned shared JIT table. Note: size 0 is valid (empty table that can grow later).

JitCodeInstaller

pub struct JitCodeInstaller {
// private fields
}

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

JitCodeInstaller::current

Return the last fully committed installation, if any.

JitCodeInstaller::install

Install one verified live or decoded artifact as a single transaction.

JitCodeInstaller::install_trampoline

fn JitCodeInstaller::install_trampoline(self : JitCodeInstaller, code : Array[Int]) -> InstalledTrampoline raise JitInstallError

Install process-local trampoline bytes without exposing allocation, copying, permission changes, or instruction-cache mutation.

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

A decoded artifact whose manifest and every code object have been checked.

MemoryDescriptorLayout

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

Fixed prefix layout of wasmoon_memory_t accessed by generated JIT code.

Keep these offsets in sync with jit_ffi/jit_ffi.h::wasmoon_memory_t.

MemoryInfo

pub struct MemoryInfo {
ptr : Int64
size : Int64
max_pages : Int?
}

Memory information for JIT execution.

MemoryInfo::MemoryInfo

fn MemoryInfo::MemoryInfo(ptr : Int64, size : Int64, max_pages : Int?) -> MemoryInfo

Create a new MemoryInfo.

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::new

NativeExecutionState

type NativeExecutionState

Store-scoped owner of native invocation lifetimes.

The active stack models nested native entry. Parked invocations remain in invocations but are absent from active, so any number of component tasks can retain distinct native resources without sharing an execution stack.

NativeExecutionState::NativeExecutionState

fn NativeExecutionState::NativeExecutionState() -> NativeExecutionState

NativeExecutionState::active_depth

fn NativeExecutionState::active_depth(self : NativeExecutionState) -> Int

NativeExecutionState::begin

NativeExecutionState::current_invocation

fn NativeExecutionState::current_invocation(self : NativeExecutionState) -> Int64?

NativeExecutionState::live_count

fn NativeExecutionState::live_count(self : NativeExecutionState) -> Int

NativeExecutionState::parked_count

fn NativeExecutionState::parked_count(self : NativeExecutionState) -> Int

NativeExecutionState::release_if_live

fn NativeExecutionState::release_if_live(self : NativeExecutionState, id : Int64) -> Unit

Best-effort scope cleanup after an error.

Strict user-visible transitions use complete and cancel; this method is intentionally idempotent so a defer can release an unfinished invocation without masking the original trap.

NativeExecutionState::seal

Irreversibly reject new invocations while preserving cleanup operations for existing handles.

NativeExecutionState::to_repr

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
HostcallTrap(Int)
HostcallSuspended
} derive(Eq,
Debug
)

Typed result returned by a JIT hostcall dispatcher.

NativeHostcallOutcome::equal

NativeHostcallOutcome::not_equal

NativeInvocationHandle

type NativeInvocationHandle

Stable handle for one Store-owned native invocation.

NativeInvocationHandle::cancel

NativeInvocationHandle::complete

NativeInvocationHandle::id

NativeInvocationHandle::park

NativeInvocationHandle::reactivate

NativeInvocationHandle::release_if_live

fn NativeInvocationHandle::release_if_live(self : NativeInvocationHandle) -> Unit

NativeInvocationHandle::resource_id

NativeInvocationHandle::to_repr

NativeInvocationPhase

pub(all) enum NativeInvocationPhase {
Active
Parked
} derive(Eq,
Debug
)

Lifecycle phase of a Store-owned native invocation.

NativeInvocationPhase::equal

NativeInvocationPhase::not_equal

NativeJITContext

type NativeJITContext

NativeJITContext::alloc_guarded_memory

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

NativeJITContext::alloc_indirect_table

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

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

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::clear_wasi_stdin_buffer

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

NativeJITContext::clear_wasi_stdin_callback

fn NativeJITContext::clear_wasi_stdin_callback(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::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

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_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::init_wasi

fn NativeJITContext::init_wasi(self : NativeJITContext, args : Array[String], env : Array[String], preopens : Array[(String, String)], quiet? : Bool) -> Unit

NativeJITContext::memory_ptr

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

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_cancellation_callback

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

NativeJITContext::set_func

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

NativeJITContext::set_gc_heap

fn NativeJITContext::set_gc_heap(self : NativeJITContext, heap : CHeap) -> Unit

NativeJITContext::set_gc_heap_ptr

fn NativeJITContext::set_gc_heap_ptr(self : NativeJITContext, heap_ptr : Int64) -> Unit

NativeJITContext::set_globals

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

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

fn NativeJITContext::set_memory(self : NativeJITContext, mem0_ptr : Int64) -> Unit

NativeJITContext::set_memory_pointers

fn NativeJITContext::set_memory_pointers(self : NativeJITContext, memories : Array[MemoryInfo]) -> Unit

NativeJITContext::set_table_pointers

fn NativeJITContext::set_table_pointers(self : NativeJITContext, jit_tables : Array[JITTable?]) -> Unit

NativeJITContext::set_wasi_stderr_capture

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

NativeJITContext::set_wasi_stdin_buffer

fn NativeJITContext::set_wasi_stdin_buffer(self : NativeJITContext, data : Bytes) -> Unit

NativeJITContext::set_wasi_stdin_callback

fn NativeJITContext::set_wasi_stdin_callback(self : NativeJITContext, callback : () -> Bytes) -> Unit

NativeJITContext::set_wasi_stdout_capture

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

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

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::take_wasi_stderr

fn NativeJITContext::take_wasi_stderr(self : NativeJITContext) -> Bytes

NativeJITContext::take_wasi_stdout

fn NativeJITContext::take_wasi_stdout(self : NativeJITContext) -> Bytes

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

NativeJITContext::throw_exception_values

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

NativeJITContext::try_alloc

fn NativeJITContext::try_alloc(total_funcs : Int) -> NativeJITContext?

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 {
NativeHostcallSuspended
NativeJITCompleted
NativeJITTrapped(Int)
} derive(Eq,
Debug
)

Result of advancing a stackful JIT invocation.

NativeJITContinuationEvent::equal

NativeJITContinuationEvent::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

TieredConfig

pub(all) struct TieredConfig {
baseline_threshold : Int
optimize_threshold : Int
synchronous : Bool
max_concurrent : Int
}

Configuration for tiered compilation

TieredConfig::default

fn TieredConfig::default() -> TieredConfig

TieredConfig::deferred

fn TieredConfig::deferred() -> TieredConfig

TieredConfig::eager

fn TieredConfig::eager() -> TieredConfig

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
}

Fixed VMContext prefix layout accessed by generated JIT code.

Keep these offsets in sync with jit_ffi/jit_ffi.h::jit_context_t. 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.

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?) -> Int64

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 linear memory for WASM (returns 0 on failure).

alloc_memory_desc

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

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

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

fn build_entry_trampoline_for_target(param_types : Array[
ValueType
], result_types : Array[
ValueType
], target : NativeTarget) -> Array[Int] raise HostcallImportTrampolineError

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 : Array[
ValueType
], result_types : Array[
ValueType
], host_func_addr : Int, target : NativeTarget) -> HostcallImportTrampolineCode raise HostcallImportTrampolineError

can_use_reusable_entry_trampoline

fn can_use_reusable_entry_trampoline(param_types : Array[
ValueType
], result_types : Array[
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 : Array[
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]) ->
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]) -> JitPipelineDiagnostics raise JitPipelineError

count_entry_trampoline_slots

fn count_entry_trampoline_slots(types : Array[
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

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

entry_trampoline_signature_hash

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

entry_trampoline_type_codes

fn entry_trampoline_type_codes(types : Array[
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

free_memory_desc

fn free_memory_desc(mem_desc_ptr : Int64) -> Unit

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?

Get trampoline function pointer for an import. Returns None if the import is not supported by JIT.

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_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

Check if a module is known to JIT (has trampoline support).

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

load_artifact

fn load_artifact(bytes : Bytes, compatibility : ArtifactCompatibility, limits? :
DecodeLimits
) -> LoadedArtifact raise ArtifactLoadError

Decode, check compatibility, and reconstruct verified unlinked code objects.

Decoded and live artifacts converge on verify_artifact, before the shared installer resolves any symbol or allocates executable memory.

make_cstring

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

memory_descriptor_fill

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

memory_descriptor_grow

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

memory_descriptor_layout

fn memory_descriptor_layout() -> MemoryDescriptorLayout

memory_descriptor_length

fn memory_descriptor_length(mem_desc_ptr : Int64) -> Int64

memory_descriptor_move

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

memory_descriptor_read

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

memory_descriptor_write

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

memory_descriptor_write_bytes

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

memory_init

fn memory_init(mem_ptr : Int64, offset : Int64, data : Bytes) -> Bool

Initialize memory with data at offset.

memory_read

fn memory_read(mem_ptr : Int64, offset : Int64, size : Int) -> Bytes

Read size bytes from linear memory at offset.

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 : Array[
ValueType
], result_types : Array[
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

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

fn value_to_slot(value :
Value
) -> GcSlot

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: function index + 1 (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

verify_artifact

Check compatibility and reconstruct verified unlinked code objects from an in-memory artifact produced by the live compiler.

No symbol is resolved and no executable memory is allocated or published.

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.