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.
Julia Type Inference
Julia parses, expands macros, optimizes, and specializes your entry function natively.
Closed-World Discovery
Collects every reachable function and applies Wasm-only method overlays at a fixed world age.
Static Verification
Checks that every call resolves statically and reports dynamic dispatch with source locations.
Structured Control Flow
Converts Julia basic blocks, loops, and try/catch regions into structured WebAssembly control flow.
Checked Binary Encoder
Validates operand types and control stacks as each WebAssembly instruction is written to bytes.
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 Type | WasmGC Representation | Notes |
|---|---|---|
Int32 / Int64 | i32 / i64 | Unboxed scalar integers; smaller integer types pack cleanly in struct and array fields. |
Float32 / Float64 | f32 / f64 | IEEE-754 scalars; Float16 converts through standard half-precision arithmetic. |
struct / mutable struct | struct (WasmGC) | Immutable or mutable typed fields with runtime type IDs for subtype dispatch. |
Tuple / NamedTuple | Record struct | Fixed-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. |
String | WasmArray{WasmI8} | UTF-8 byte array internally; crosses to JS via wasm:js-string builtins. |
WasmExternRef | externref | Opaque host reference for JS strings, DOM nodes, and canvas contexts. |
Union{A, B} / Closures | Type ID + dispatch table | Small 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.
| Guarantee | How It Is Checked |
|---|---|
| Julia is ground truth | Differential tests run native Julia and compiled WasmGC side by side and assert identical results. |
| Type-checked before code generation | Core.Compiler.TrimVerifier rejects dynamic dispatch with located OutsideSubset errors. |
| Valid WebAssembly instructions | The pure-Julia binary encoder validates operand types and control stacks as every instruction is written. |
| Single pinned world age | Inference, method overlays, and constant lookups all read the same pinned world age. |
| Formal TLA+ specifications | Core compiler algorithms are specified in TLA+ and exhaustively model-checked with TLC. |
| Zero regressions across Julia versions | Full 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.
| Layer | Scope | Tooling |
|---|---|---|
| Formal Specs | Control-flow structuring, exception handling, phi elimination, subtype dispatch, and record layout (50 models) | TLC + dev/formal/run_tlc.sh |
| Differential Fuzzing | 5 bit-exact property suites (numerics, control flow, structs, vectors, strings) tested with optimize=false and optimize=true | Supposition.jl + Node 26+ |
| Package QA | Method ambiguities, unbound type args, undefined exports, compat bounds, piracies, and single-dependency check | Aqua.jl |