Skip to content

Pipeline

The stages, gates, and artifacts that transform Atoll source into WebAssembly.

Compilation narrows the program through three semantic representations and two WebAssembly artifacts:

source files
    ↓  lex, parse, recover
tokens + AST
    ↓  hoist, resolve, check, infer, lower
typed HIR
    ↓  discover and materialize generic instances
monomorphic HIR
    ↓  lower to SSA over values, not slots
core IR
    ↓  optimize, then insert retain/release, then verify
core IR, ownership explicit
    ↓  destruct SSA, reloop, stackify, encode
WebAssembly

Two intermediate representations, not three. The retired back end had one choose control flow and ownership and a second lower those to primitive WebAssembly values, with a canonicalization step between — so every fact mattering to both was stated twice, in two vocabularies that could disagree. See IR.

atoll build runs the new back end, whose stages atoll-codegen’s crate doc (crates/atoll-codegen/src/lib.rs) draws.

The arrows are contracts. A stage consumes only the previous stage’s public facts, establishes the invariants needed by the next stage, and returns diagnostics when it cannot do so.

Driver entry

atoll build accepts a file, a bare directory, or a path within a manifest project:

Input Compilation scope
File outside an atoll.toml project That file, using the single-file compatibility path
Bare directory Every discovered .at file as an ad-hoc project
Path at or below atoll.toml The complete manifest project

Project builds, of a manifest project or a bare directory, go through the layered compile in atoll-driver: each dependency is sealed into a layer kept on disk, and the project’s own files are compiled over the sealed world. The language server holds its open files in atoll_lsp::db and compiles the project through the same pipeline.

atoll check stops after parsing and semantic analysis. atoll build continues through specialization and WebAssembly emission. atoll run selects an emitted unit and hands it to the runtime. These commands should agree on front-end diagnostics because they share the same parsing and semantic pipeline.

Stage contracts

Syntax

The syntax crate turns bytes into typed tokens and an arena-backed AST. It interns source strings, attaches byte ranges, and attempts error recovery so a single malformed construct does not erase the remainder of the file. The AST contains syntax, not resolved identities or inferred types.

Analysis

Semantic analysis combines files into one project:

  1. install the compiler stdlib and project configuration;
  2. hoist declaration surfaces;
  3. resolve module imports and names;
  4. lower bodies while checking types, effects, visibility, and decorators;
  5. register layouts and data-query metadata;
  6. return typed HIR and diagnostics.

This is the last stage allowed to decide language meaning. Later stages may validate their own representation invariants but should not invent a missing type, effect, layout, or overload decision.

Specialization

Generic source functions remain useful semantic definitions, but the backend requires concrete bodies. Monomorphization walks reachable calls, derives a canonical substitution for each generic callee, reuses an existing specialization on a cache hit, and otherwise clones and substitutes the body. Calls are rewritten to concrete symbols. Instantiated nominal types receive concrete layouts at the same boundary.

Core IR

lower_hir turns monomorphic HIR into SSA over values, not slots: control flow and suspension become explicit, a call’s convention is chosen from the resolved callee, and every value carries the storage class the layout table assigned it.

Order matters here and is not a convenience. opt runs before ownership exists, so no pass has ever seen a retain or a release and none owes anything to the ownership verifier. rc then places retain/release by Perceus occurrence counting, and verify judges the result against linear lifetimes.

Encoding

emit destructs SSA, restructures the control-flow graph into WebAssembly’s structured form, stackifies, and encodes — one module, validator-clean. The release walks a type owes are generated here from the layout table rather than written by hand.

The structure is read off the dominator tree (crates/atoll-codegen/src/reloop.rs, after Ramsey’s Beyond Relooper): each source loop becomes a wasm loop and a back edge one br to it, and a join is the code after a block its forward edges leave. A function that suspends is the exception. The scheduler resumes it at a block it names by index, so its blocks sit under one dispatch loop and a br_table over that index.

Unit discovery, per-unit modules and the program linker were the retired back end’s; nothing in atoll-codegen supplies them yet.

Hard gates

Each transition has a stop condition:

Gate Failure behavior
Parse or semantic errors No specialization or code generation
Specialization errors No partial unit artifacts
Core-IR invariant or ABI errors Diagnostic attributed to the IR layer
Codegen errors Unit bytes are not written as a successful build
Invalid encoded module Backend failure; validation must not be bypassed
Link invariant mismatch Link error naming the input module or unsupported section

Warnings and hints can survive a successful build. Error-severity diagnostics cannot. The CLI aggregates diagnostics by layer so users can see the source problem while compiler tests can assert which stage owned it.

Optimization modes

The command-line optimization levels select a policy rather than different languages:

Mode Intent
-O0 / --debug Lowering core, debuggable output, minimal optional optimization
-O1 Balanced optimization
-O2 / --release Full release pipeline; current default

All modes must preserve observable language behavior and emit valid modules. Pass-disable and trace controls are debugging tools; a fixed source, compiler revision, and effective option set must still produce deterministic output.

Artifacts and identity

An Atoll unit is a compiler work item rooted at an entry function. The current discovery convention recognizes main and entry_*, with extra roots available to test infrastructure. A unit owns a stable name, root symbol, source range, and ordered static closure.

A per-unit module is not yet a deployed instance. The linker can combine units into one or more link groups and embeds the atoll.units metadata consumed by the runtime. The runtime then instantiates the module with its own scheduler and arena state. See Units for the distinction.

Observability

The compiler can expose AST, HIR, MIR, WasmIR, and WebAssembly-oriented dumps. Typed trace events connect transformations across stages, while source-origin tables connect lower operations back to expressions. Provenance defines how those identities survive relocation, optimization, instruction expansion, and encoding. Debug output must remain optional: enabling it may add debug sections or trace side channels, but it must not change program semantics.

Continue with Syntax for the first stage or Diagnostics for the cross-stage failure model.

Type to search…

↑↓ navigate↵ selectEsc close