---
title: "Compiler"
description: "Architecture, invariants, and engineering guide for the Atoll compiler."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.atoll.workreef.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Compiler

The Atoll compiler is a staged, diagnostic-first pipeline from source files to
per-unit WebAssembly and linked deployment modules. Each stage owns one
representation, establishes explicit invariants, and hands a narrower program
to the next stage.

This section explains those ownership and handoff contracts. The
[Language Guide](https://docs.atoll.workreef.dev/language/) teaches source syntax, the [Specification](https://docs.atoll.workreef.dev/specification/)
defines language rules, and the [IR](https://docs.atoll.workreef.dev/ir/) section is the normative home for
HIR and the core IR.

**The back end was replaced.** `atoll-mir` and `atoll-codegen-wasm` — a
MIR/WasmIR pair with a canonicalization step between them — are being deleted,
and `atoll-codegen` lowers monomorphic HIR to one core IR and encodes it
directly. Chapters that documented the retired crates' internals have gone with
them; **`crates/atoll-codegen/docs/` is the design of record** for everything
right of monomorphic HIR, and the crate doc (`crates/atoll-codegen/src/lib.rs`)
draws the stages it runs.

`atoll build` runs that back end. Read the stage descriptions below as the
architecture, and `crates/atoll-codegen/docs/optimizer.md` for which passes a
given level runs.

## Chapter map

| Chapter | Focus |
| --- | --- |
| [Pipeline](https://docs.atoll.workreef.dev/compiler/pipeline/) | End-to-end stage order, gates, and artifacts |
| [Syntax](https://docs.atoll.workreef.dev/compiler/syntax/) | Lexer, arena AST, recovery, and incremental parsing |
| [Analysis](https://docs.atoll.workreef.dev/compiler/analysis/) | Resolution, types, effects, HIR, and project assembly |
| [Editor database](https://docs.atoll.workreef.dev/compiler/database/) | The language server's inputs, memoized parses, and its one compile of the project |
| [Specialization](https://docs.atoll.workreef.dev/compiler/specialization/) | Generic call discovery, canonical keys, and concrete HIR |
| [Provenance](https://docs.atoll.workreef.dev/compiler/provenance/) | Source identity through IR rewrites, line data, traces, and debugging |
| [Diagnostics](https://docs.atoll.workreef.dev/compiler/diagnostics/) | Source attribution, layers, recovery, and hard gates |
| [Reproducibility](https://docs.atoll.workreef.dev/compiler/reproducibility/) | Stable ordering and byte-identical output |
| [Testing](https://docs.atoll.workreef.dev/compiler/testing/) | Unit, snapshot, parity, determinism, and end-to-end gates |

## Crate ownership

| Crate | Owns | Must not own |
| --- | --- | --- |
| `atoll-syntax` | Tokens, source ranges, interned strings, AST arenas | Types or runtime meaning |
| `atoll-sema` | Symbols, types, effects, layouts, checked HIR | WebAssembly encoding |
| `atoll-mono` | Concrete generic function instances and instantiated layouts | Source parsing |
| `atoll-codegen` | The core IR: control flow, storage, ownership, layout, the calling convention, and WebAssembly encoding | Surface syntax and unresolved types |
| `atoll-driver` | The layered compile every command takes: dependencies sealed, then the project | Editor state |
| `atoll-lsp` | The editor's inputs, memoized parses, and features over the project's compile | A second compiler |
| `atoll-cli` | Project discovery, user options, stage orchestration, artifact writing | Hidden compiler policy |

The crates form a dependency direction, not a collection of interchangeable
passes. A lower stage may preserve source provenance from an earlier one, but
it should not reconstruct semantic decisions that the earlier stage failed to
encode.

## Design rules

Four rules apply across the compiler:

1. **Reject at the owning layer.** Unknown names belong to analysis; invalid
   suspension lifetimes belong to MIR validation; malformed WasmIR belongs to
   its verifier.
2. **Never silently lower an unsupported case.** A source diagnostic is
   preferable to a placeholder zero, skipped instruction, panic, or malformed
   module.
3. **Keep order observable and deterministic.** Parallel and incremental work
   may execute in any order, but IDs, diagnostics, units, sections, and bytes
   are reduced in canonical order.
4. **Make options explicit.** Optimization, debug information, tracing, and
   diagnostic visibility travel through configuration objects. Environment
   variables remain development and compatibility controls, not the desired
   library API.

Every transforming pass also follows a fifth operational rule: preserve or
classify provenance. A generated operation either retains the user construct
that caused it or carries an explicit synthetic reason; absence is not silently
treated as a source range.

## Maturity

The compilation path is implemented, but several internal boundaries are
actively evolving. In particular, incrementality is finer-grained in parsing,
semantic checks, and unit emission than in some whole-project
monomorphization and cross-function MIR work. The chapters describe those
mixed boundaries explicitly rather than presenting the query graph as
uniformly per-function.

For the runtime contract consumed by emitted modules, continue to
[Architecture](https://docs.atoll.workreef.dev/runtime/architecture/) and [ABI](https://docs.atoll.workreef.dev/runtime/abi/).

Source: https://docs.atoll.workreef.dev/compiler/index.mdx
