Compiler Design · Verified End to End

Architecture & Verification

WasmTarget.jl pairs Julia's own compiler frontend with a pure-Julia WasmGC backend, backed by automated verification checks, 50 TLA+ formal specifications, and differential tests against native Julia.

End-to-End Compilation Pipeline

Rather than re-implementing parsing, macro expansion, or type inference, WasmTarget.jl reads optimized typed code directly from Julia's native type inference. Every stage checks its inputs before handing off to the next.

Compilation PipelineJulia Function -> WasmGC .wasm
01Native compiler

Julia Type Inference

Julia parses, expands macros, optimizes, and specializes your entry function natively.

02WasmTarget.METHOD_TABLE

Closed-World Discovery

Collects every reachable function and applies Wasm-only method overlays at a fixed world age.

03TrimVerifier

Static Verification

Checks that every call resolves statically and reports dynamic dispatch with source locations.

04block / loop / try

Structured Control Flow

Converts Julia basic blocks, loops, and try/catch regions into structured WebAssembly control flow.

05Pure-Julia Encoder

Checked Binary Encoder

Validates operand types and control stacks as each WebAssembly instruction is written to bytes.

06Browser / Node WasmGC

Binaryen wasm-opt

Runs Binaryen optimization passes to produce a compact, standalone .wasm module.

Closed-World Inference & Verification

Compilation starts by pinning a single world age and running Julia type inference over your entry function with WasmTarget.METHOD_TABLE layered on top of Base. WasmTarget.jl collects every reachable function and immediately checks the whole call graph with Core.Compiler.TrimVerifier.

Because code generation only accepts a verified ClosedWorld value, any dynamic dispatch or unsupported call fails early with an exact source location before a single WebAssembly byte is emitted. Module constants and bindings are also snapshotted at that same pinned world age into a verified intermediate representation.

# Check trimmability without emitting bytes, or compile directly
world_age = Base.get_world_counter()
cw = WasmTarget.check_subset(f, argtypes, at, world_age; host_modules)
wasm_bytes = WasmTarget.compile(f, argtypes; world = world_age, optimize = true)

Structured Control Flow & Exceptions

Julia's typed intermediate representation expresses control flow as a flat list of basic blocks with arbitrary jumps, phi values, and exception regions. WebAssembly requires structured control flow (block, loop, br, try/catch).

WasmTarget.jl transforms Julia's control-flow graph and dominator tree into nested WebAssembly blocks and loops, handling irreducible loops, phi-node copies, and try / catch / finally exception scopes cleanly.

Julia to WasmGC Type Mapping

Every concrete Julia type maps directly into the WebAssembly GC type section. Heap objects are managed by the browser or Node.js garbage collector with no linear-memory allocator overhead.

Julia TypeWasmGC RepresentationNotes
Int32 / Int64i32 / i64Unboxed scalar integers; smaller integer types pack cleanly in struct and array fields.
Float32 / Float64f32 / f64IEEE-754 scalars; Float16 converts through standard half-precision arithmetic.
struct / mutable structstruct (WasmGC)Immutable or mutable typed fields with runtime type IDs for subtype dispatch.
Tuple / NamedTupleRecord structFixed-arity typed records with compile-time field layout.
Vector{T} / Memory{T}struct + WasmArray{T}Mutable GC-managed backing array with length and optional unassigned-element tracking.
StringWasmArray{WasmI8}UTF-8 byte array internally; crosses to JS via wasm:js-string builtins.
WasmExternRefexternrefOpaque host reference for JS strings, DOM nodes, and canvas contexts.
Union{A, B} / ClosuresType ID + dispatch tableSmall unions branch on runtime type IDs; closures compile to typed capture structs.

Correctness Guarantees

WasmTarget.jl relies on automated verification checks throughout the compiler and CI pipeline so bugs are caught before they reach users.

GuaranteeHow It Is Checked
Julia is ground truthDifferential tests run native Julia and compiled WasmGC side by side and assert identical results.
Type-checked before code generationCore.Compiler.TrimVerifier rejects dynamic dispatch with located OutsideSubset errors.
Valid WebAssembly instructionsThe pure-Julia binary encoder validates operand types and control stacks as every instruction is written.
Single pinned world ageInference, method overlays, and constant lookups all read the same pinned world age.
Formal TLA+ specificationsCore compiler algorithms are specified in TLA+ and exhaustively model-checked with TLC.
Zero regressions across Julia versionsFull test, fuzz, and QA matrices run across supported Julia releases in CI.

TLA+ Specifications, Fuzzing & Package QA

Core compiler passes carry formal TLA+ specifications under dev/formal/ (50 models verified with TLC, including negative counterexample checks that TLC must reject). Alongside formal model checking, differential fuzzing tests randomized Julia programs against native execution.

LayerScopeTooling
Formal SpecsControl-flow structuring, exception handling, phi elimination, subtype dispatch, and record layout (50 models)TLC + dev/formal/run_tlc.sh
Differential Fuzzing5 bit-exact property suites (numerics, control flow, structs, vectors, strings) tested with optimize=false and optimize=trueSupposition.jl + Node 26+
Package QAMethod ambiguities, unbound type args, undefined exports, compat bounds, piracies, and single-dependency checkAqua.jl