JIT

The JIT compiles hot functions from LIR to native code using Cranelift.

Architecture

LIR → FunctionTranslator → Cranelift IR → Native code → JitCode

Key types

runtime helper symbols, tracks compilation stats

emitting Cranelift IR

alive for the code's lifetime

VM (allocation, GC barriers, signal checks)

Function selection

Functions become JIT candidates based on a hotness threshold (default 10, controlled by --jit=N). The VM increments a counter on each call; when it crosses the threshold, the function is compiled.

Rejection tracking

Not all functions can be JIT-compiled. The JIT rejects functions that:

Rejected functions are marked so the VM doesn't retry them.

Yield-through-call

For functions that call other functions which might yield, the JIT collects yield-site metadata during LIR emission. This enables proper save/restore sequences so a yielded fiber can resume into JIT code.

CLI flags

--jit=0       Disable JIT entirely
--jit=N       Compile after N-1 calls (default: --jit=11, threshold 10)
--jit=1       Compile on first call
--stats       Print compilation stats on exit

Files

src/jit/compiler.rs    JitCompiler, module management
src/jit/translate.rs   FunctionTranslator, LIR → Cranelift IR
src/jit/code.rs        JitCode wrapper
src/jit/vtable.rs      Runtime helper dispatch table
src/jit/dispatch.rs    JIT dispatch integration with VM

See also