Skip to content

Tooling

The atoll command line — building, running, testing, and benchmarking Atoll code.

The atoll binary is the single entry point for working with Atoll source. The Language guide uses three of its subcommands constantly.

Command What it does
atoll check <input> Parse, resolve, and type/effect check. Reports diagnostics; emits nothing.
atoll build <input> Everything check does, then lower to WebAssembly and write a unit artifact.
atoll run <input> [args...] Build, then execute through the runtime. See Running a program.
atoll test <input> Discover and run the test "…" items. See Testing.
atoll bench <input> Discover and run the bench "…" items with timing statistics.
atoll lint <input> check, but exits non-zero on warnings too. For CI gates.
atoll new <name> Scaffold a new project; --lib a library, --web a site.
atoll dev [input] For a site: build the program its pages run and run its server, and both again on every change, each open page loading itself again.
atoll init Make the directory you are in a project; keeps any .at source already there.
atoll fmt [input...] Rewrite source in canonical style. See Formatting.
atoll doc [input] Write the API of a file or package as Markdown; --std reads the standard library. See Documentation.
atoll repl An interactive session: an expression prints its value and type, and a statement (x := 5) or a declaration (fn …) joins the session for the lines after it. Each line runs the session again, showing only new output.
atoll add / deps / lock Dependency management against atoll.toml.
atoll migrate Database schema migration against a live datasource.
atoll i18n export / import A package’s messages to and from translators as PO or XLIFF; the lines are written into the message declarations. See Messages.

The input to check, build, run, and test may be a single .at file or a directory. A directory is walked recursively and compiled as one project, using an atoll.toml at or above it when present.

Running a program

atoll run builds the program and runs it. Anything after the input is the program’s own arguments, and -- starts them when the input is the project in the current directory:

atoll run . data.csv --strict      # the project here, given two arguments
atoll run -- --verbose report.csv  # the same project; `--` ends atoll's options
atoll run tool.at input.txt        # a single file, given one argument

The program reads them, and its environment, through process:

import process

fn main() int {
    files := process.args()
    if files.len() == 0 {
        eprintln("usage: tool <file>...")
        return 2
    }
    for f in files {
        println("reading ${f}")
    }
    who := process.env("USER") ?? "someone"
    println("done, ${who}")
    return 0
}

process.args() is the arguments after the program’s own name — atoll run . a b gives ["a", "b"] — and process.env(name) is None for a variable that is not set. eprintln writes a line to standard error, so a tool’s messages stay out of the output a caller pipes on.

main’s value is the exit status, or it is printed. A void main exits 0. An int main (or one of any integer width) exits with what it returns, and atoll run says so on standard error when it is not 0 (atoll run: main returned 2), so a script can tell success from failure. A status is a byte: a value outside 0–255 exits 1. Any other result is not a status: a string, a float, a bool, an optional, a list, a struct or a union is printed on standard output, the way println("${value}") prints it, and the run exits 0.

$ cat hello.at
fn main() string {
    return "hello"
}
$ atoll run hello.at
hello

A main declared T ! E prints its T the same way, or exits with its status when T is an integer. One that returns its error exits 1, and says the error. A result println cannot render is refused before the program runs, naming its type. A main with no return type written that returns a status on some paths and reaches its end on others is refused, since that end has no status: declare it fn main(): int and end it with return 0.

A program that traps says what failed, then where, in its own terms: the sentence, then the calls that led there, innermost first, with the line of source under the first:

$ atoll run
atoll run: trap: division by zero
  at div (main.at:2:5)
  2 |     return a / b
    |     ^^^^^^^^^^^^
  at main (main.at:6:5)

The standard library’s own frames are left out, unless ATOLL_BACKTRACE=full asks for them. See Panics.

A runaway recursion is said once — call stack exhausted, its usual cause, and the repeated frame with a count. ATOLL_BACKTRACE=1 adds the engine’s own backtrace, for work on the compiler.

console.stdout_is_terminal() (import console) answers whether the program’s output reaches a terminal — false when it is piped, redirected or collected by atoll test — so colour and cursor codes go only where they mean something.

Compiled ahead of time

atoll build writes a .wasm, and every atoll run of it compiles it to machine code before it starts. atoll build --aot does that compile once and writes the result instead: one .aot file holding the module and its machine code, which atoll run starts with nothing to compile.

atoll build --aot main.at        # writes target/atoll/main.aot
atoll run target/atoll/main.aot  # runs it, with no compile

--aot compiles with Cranelift, the compiler atoll run compiles a .wasm with. --aot=winch compiles with Winch, wasmtime’s baseline compiler, instead: the compile takes a fraction of the time, and the code it writes runs slower.

It answers what the .wasm answers, traps with the same stack, and is told apart by its contents rather than its name. It is machine code for the CPU that built it, and runs on any CPU with every feature that one has: a newer one with more is fine. On one that lacks any of them it is refused with a message saying to rebuild it there, whether or not the program would have used the missing one; so is a file built by another atoll, or one that was cut short or changed on the way. Treat it as you would an executable: run only one you built, or got from someone you would take an executable from.

To build one file for every machine of an architecture, compile for its baseline instead of for this CPU:

atoll build --aot --aot-cpu=baseline main.at   # runs on any x86-64 CPU

The code does without the instructions newer CPUs add, so it can run slower: a few percent on most programs, more on one that counts bits or does much floating-point or vector work. --aot-cpu=native, the default, is this machine’s CPU. Winch writes x86-64’s vector instructions only with AVX, which the baseline does not have, so --aot=winch --aot-cpu=baseline refuses a program that uses them when it builds, saying which function and what to do instead; Cranelift compiles any program for the baseline.

Between the two, --aot-cpu=avx2 compiles for x86-64 with SSE4.2, POPCNT, AVX, AVX2, BMI1, BMI2, FMA and LZCNT, which every x86-64 CPU of about the last ten years has. The file runs on a CPU with all of them, is refused with a message to rebuild it on one without, and is refused when it is built for any other architecture. It costs next to nothing against native on a CPU that has more, and Winch compiles every instruction of it.

Formatting

atoll fmt rewrites source in the one canonical style. It takes any number of files or directories, - for standard input, or nothing at all — which means the current directory.

atoll fmt src/              # rewrite every .at file under src/
atoll fmt --check .         # exit non-zero, naming what would change
atoll fmt --stdout one.at   # print, don't write
cat x.at | atoll fmt -      # a pipe

A directory walk takes .at files. Pass --markdown to also format the Atoll inside fenced ```atoll blocks in .md / .mdx pages; a markdown file named directly is always formatted that way. Everything outside the fences, including the info string on it, is left exactly as it was.

What it does

Indentation, trailing whitespace, runs of blank lines, and the trailing newline are normalized. A declaration list is given one shape — comma-separated on one line, no separators across lines — and its types are aligned. Signatures are written with the bare type spelling.

A declaration’s decorators come first and its modifiers — pub, internal, private, unsafe — stand on its keyword’s line. private @inline fn, and private on a line of its own above @inline and fn, are both written:

@inline
private fn larger(a int, b int) int {
    if a > b { return a }
    return b
}

A head already in that order is left as written, so @inline private fn on one line stays on one line; a head holding a comment is left alone.

Then a width-aware pass lays out anything that does not fit the column budget, breaking one item per line:

fn record_measurement(
    sensor_name string,
    recorded_at int,
    celsius float,
    humidity float,
    station_id int
) int {
    return station_id
}

A method chain breaks down its dots, keeping the receiver and its first call together:

fn f(source List[int]) int {
    result := source.filter(x => x > 0).map(x => x * 2).collect().len()
    return result
}

An operator chain breaks at its operators, and a match takes one arm per line:

fn f(a bool, b bool, c bool, x int) int {
    ready := a && b && c
    return match x {
        0 => 1
        _ => 2
    }
}

It models delimited lists — call arguments, array, tuple, struct and record literals, parameter lists — method chains, operator chains and match arms. Only one operator flattens at a time, so a + b * c keeps b * c whole as a single operand.

Comment prose is re-wrapped to the budget as well, but only where it can be proved to be prose: a run of // lines, all one marker, none of them a heading, a list, a table, a fence or an indented sample, and at least one of them over the budget. Anything else is left exactly as written, because re-flowing a diagram or a table destroys what it says.

Three rules are worth knowing because they hand a decision back to you:

  • Write the separators and the layout is the formatter’s; leave them out and the column is yours. A list written with commas is joined when it fits and broken when it does not, and the broken form keeps its commas so a wider budget rejoins it. A list written across lines without separators is a column: one field per line, values aligned on the widest name, left alone at any width. A match reads its arms the same way.

fn f(a int, bbb int) int { // The formatter’s: joined, broken and rejoined by width. flexible := { alpha: a, beta: bbb } // Yours: a column, at every width. fixed := { alpha: a beta: bbb } return flexible.alpha + fixed.beta }


This is what makes the formatter **convergent**: running it at a narrow width
and then a wide one gives the same result as running it wide directly. A rule
that read the line break instead could not tell its own output from your
choice, so a narrow pass was sticky.

```atoll
fn f() int {
  item := {
      field:     1
      field_two: 2
      three:     3
  }
  return item.field
}

Written flat, it stays flat and keeps its commas. Call arguments and arrays have no such convention and are rejoined when they fit.

  • A construct holding a comment is never re-laid-out. The formatter has nowhere to put a comment inside a layout it is inventing, so it leaves the whole construct exactly as you wrote it.
  • A construct too small to be the reason its line is long is left alone. Breaking xs.unwrap_or("") out of a 120-column chain makes three lines that are still too long.

Configuration

Flag atoll.toml [fmt] Default
--indent N indent = N 4
--tabs tabs = true off
--width N width = N 100

Each file resolves against the nearest atoll.toml at or above it, so one invocation spanning two projects honours both. A flag overrides the file.

The editor uses the same formatter through the language server — on save, on a selection, and on typing a } — so format-on-save and atoll fmt --check in CI cannot disagree about what canonical means. Where a project’s atoll.toml says nothing, the language server falls back to the editor’s own indent settings.

Documentation

atoll doc writes what a package exports — each pub item with its signature, and its /// doc comment when it has one — as Markdown:

$ atoll doc
atoll doc: wrote 3 pages and ./target/doc/index.md

In a package it reads the source a build reads (src/, not the _test.at files) and titles the index with the module. Given one file, it writes <file>.md beside it, or prints it with --stdout. --all adds what is internal and private.

--std reads the standard library this atoll carries: on its own it lists the root files, which need no import, and the modules, and with a name it prints that part’s API:

atoll doc --std            # what there is
atoll doc --std string     # every method of `string`
atoll doc --std fs         # the `fs` module

Check is not the whole story

atoll check stops after semantic analysis. That is fast and gives the best diagnostics, but it does not prove a program can be compiled: a stdlib method can type-check and still have no lowering path, which only atoll build discovers.

`main` (#6220) did not lower: [UnloweredIntrinsic("zeroed")]

When you are checking whether something really works, build it.

Only code reachable from an entry point (fn main or fn entry_*) is lowered, so a file of uncalled declarations builds trivially. Exercise what you want verified from an entry point.

Optimization levels

build, run, test, and bench accept -O:

Level Meaning
-O0 Lowering core only — fast compiles, debuggable output
-O1 Balanced: full pipeline, small budgets
-O2 Full optimization (the default)

--no-preempt builds without preemption poll sites: a task switches only at its own suspending calls. [build] preempt = false in the manifest says the same. See Execution for what that changes, and why --debug is refused with it.

--trace-max <LEVEL> compiles out every tracing callsite more verbose than the level, which is off, error, warn, info, debug or trace; the callsites are still checked. [trace] max in the manifest says the same.

Rebuilding after an edit

atoll build --watch and atoll check --watch stay running and do the command again each time a source file changes. Between runs they hold what they compiled: the standard library, each file’s parse, the declarations, and the checks of functions an edit did not touch.

A resident worker holds the same for a command that is not watching. The worker is a process of the compiler, started for one command as given (the same directory, arguments and environment), that answers that command each time it is run again, until it has been idle for twenty minutes. Its answer is the module and the diagnostics a new process would give, byte for byte.

  • A build or check uses a worker that is already running for it, and otherwise runs in its own process.
  • ATOLL_RESIDENT=1, or resident = true in the manifest’s [build] table, starts one where none is running.
  • ATOLL_RESIDENT=0 runs the command in its own process even beside a running worker.

Diagnostics and tracing

atoll explain captures stage-tagged events from the compilation pipeline, and atoll dump --stage <ast|hir|mir|wasmir> prints one stage’s IR text. Both are compiler-development tools rather than everyday commands; see Diagnostics for reading ordinary compiler output.

Type to search…

↑↓ navigate↵ selectEsc close