Skip to content

Decorators

Attach checked compiler, tooling, runtime, and data metadata to source declarations.

A decorator begins with @ and precedes the declaration, field, parameter, or binding it modifies. It never changes what an expression evaluates to — it tells one compiler pass, tool, or subsystem something extra about the target.

@inline
fn small(value int) int {
    return value + 1
}

@sealed
trait Protocol {
    fn execute(&self) int
}

struct Runner {
    private secret int
    id     int

    fn made(secret int, id int) Runner {
        return Runner { secret: secret, id: id }
    }
}

impl Protocol for Runner {
    fn execute(&self) int { return self.id + self.secret }
}

fn main() void {
    r := Runner.made(5, 7)
    println("${small(r.execute())}")   // 13
}

The parser accepts arbitrary decorator syntax. A decorator has behavior only when a compiler pass, tool, runtime adapter, or domain subsystem recognizes it by name.

Syntax

A decorator name is lowercase and may be dotted for a subsystem namespace. Arguments are parsed as ordinary expressions, but each recognized decorator imposes its own narrower contract on them. Written without parentheses, a decorator has no arguments.

Several decorators can stack on one target, and their source order does not change their meaning:

@host
@suspend
fn monotonic_time() int

@host
fn coarse_time() int

fn main() void {
    start := coarse_time()
    now := monotonic_time()
    println("${now - start}")
}

A decorator attaches to the immediately following supported target. It does not float across an unrelated declaration, and one left with no target is a syntax error rather than file-level metadata:

@inline
fn orphan() int { return 1 }

@inline

Decorator arguments are compile-time metadata, not runtime expressions. The recognizing consumer decides which shapes it accepts and diagnoses the rest — @derive, for instance, insists on bare trait names:

@derive("Equatable")
struct Coordinate {
    x int
    y int
}

Compilation

These decorators are read during ordinary compilation:

Decorator Target Meaning
@allow(naming) Supported declaration Suppress its naming-lint warning
@sealed Trait Restrict implementations to the declaring file
@inline Function Raise the inliner’s threshold for this callee
@inline(always) Function Inline regardless of size
@noinline Function Never inline
@cold Function A slow path: never inlined, and calls to it are expected rarely
@nosuspend Function or trait method The body, or every implementation’s, must not suspend; checked through everything it calls (ATOLL1071)
@linear Local binding Give the local single-owner (move, not retain) RC mode
@owned Nothing Retired. A receiver is spelled self, mut self, &self or &mut self, so @owned self is refused (ATOLL1048); on a field it is refused (ATOLL1073): a ^T field owns its block and &T borrows
@externalizable Nothing Retired, and refused by the parser (ATOLL1098). JSON needs no decorator: json.encode derives json.Encode for every struct and enum it is used on
@extern Nothing Retired with @externalizable, and refused the same way (ATOLL1098)
@derive(Trait, ...) Struct or enum Parsed and validated; a bare name is read by nothing yet, and a derivable trait through its module (@derive(json.Encode)) is checked when the package that writes it is built

Field privacy is the private keyword, not a decorator — see Visibility.

Inlining

@inline, @inline(always), and @noinline steer one per-callee decision in the optimizer. They are pure hints: removing all three must not change what the program computes.

@inline(always)
fn clamp(value int, low int, high int) int {
    if value < low { return low }
    if value > high { return high }
    return value
}

@noinline
fn report(label string, value int) void {
    println("${label}=${value}")
}

fn main() void {
    for raw in [-5, 3, 99] {
        report("clamped", clamp(raw, 0, 10))
    }
}

@inline(always) lifts the two refusals that are about cost — a callee too large for the budget, and a callee that loops — and none of the ones about correctness: a body that suspends, or one the reference counter has already placed releases in, is never spliced, whatever it is marked. The standard library marks its one-op helpers this way, which is how a list’s element access and a map’s slot arithmetic disappear into the loops that use them, including the library’s own.

@cold marks a function as the slow path its callers take rarely — the standard library’s list growth is one, reached from push and pop past a test that almost always says no. It is never inlined, and a loop that calls it keeps the values it carries out of the call’s way: they are put aside just before the call and taken back after it, so on the turns that make no call they stay in registers. Like the inlining hints, it never changes what a program computes.

@cold
fn refill(buffer &mut []int, n int) void {
    mut i := 0
    for i < n {
        buffer.push(i)
        i = i + 1
    }
}

fn main() void {
    mut buffer: []int = []
    mut total := 0
    mut step := 0
    for step < 1000 {
        if buffer.len() == 0 {
            refill(&mut buffer, 64)
        }
        total = total + (buffer.pop() ?? 0)
        step = step + 1
    }
    println("${total}")
}

Sealing a trait

@sealed restricts implementations of a trait to the file that declares it, so the set of implementing types is closed and reviewable. An impl in the same file is fine; a cross-file one raises ATOLL2106.

@sealed
trait Codec {
    fn tag(&self) int
}

struct Json { version int }
struct Binary { version int }

impl Codec for Json {
    fn tag(&self) int { return 1 }
}

impl Codec for Binary {
    fn tag(&self) int { return 2 }
}

fn main() void {
    println("${Json { version: 1 }.tag()} ${Binary { version: 1 }.tag()}")
}

Must not suspend

@nosuspend is a checked constraint: the function’s body may not reach anything that parks the task, directly or through what it calls — a @suspend host call, a task join or await, a select, a channel operation, a spawn. On a trait method it is declared once, in the trait, and every implementation is held to it; an implementation may restate it, and cannot leave it out. Drop.drop is the standard library’s own case.

trait Flush {
    @nosuspend
    fn flush(&self) int
}

struct Sink { pending int }

impl Flush for Sink {
    fn flush(&self) int { return self.pending }
}

@nosuspend
fn total(a int, b int) int { return a + b }

fn main() void {
    s := Sink { pending: 2 }
    println("${total(s.flush(), 1)}")
}

A body that may suspend is refused at the call that reaches the suspension, with the chain from there to what parks, each step a label at its own call, and the declaration of the constraint:

import task

fn inner() int {
    task.yield_now()
    return 1
}

fn middle() int { return inner() + 1 }

@nosuspend
fn outer() int { return middle() + 1 }

fn main() void {
    println("${outer()}")
}
error[ATOLL1071]: `outer` may not suspend: it is declared `@nosuspend`; but its call of `middle` suspends through `inner` and `yield_now`, a suspending runtime operation

It is the opposite of @suspend, which a function with a body never carries: whether a body suspends is inferred, and @nosuspend is how to say that it must not.

Owned fields

A ^T field is responsible for the block behind the pointer: releasing the struct releases what the field points at, and so on down the structure. Write &T for a field that only holds an address and owes nothing.

That is the default rather than a decorator, and @owned on a field is ATOLL1073 — see Pointers.

struct Node { v int, next ^Node? }

fn main() int {
    n: ^Node = ^Node { v: 7, next: ^Node { v: 5, next: None } }
    return n.v
}

There is no weak-field decorator, and none is needed: a back pointer is an ordinary field, and the cycle it closes is reclaimed by trial deletion. See Values.

Naming lint

The naming lint is on by default. @allow(naming) suppresses the warning for one declaration, which is what you want for a name that mirrors an external protocol.

@allow(naming)
fn XMLPayload() int { return 2 }

fn main() void {
    println("${XMLPayload()}")
}

Suppression is retained on functions, structs, enums, error types, traits, error unions, and implementation blocks; enum-level suppression also covers variants. Aliases and constants do not currently retain it. See Naming conventions.

On an enum variant

A variant is a target like any other, and what sits above it is retained rather than interpreted — the same rule an unrecognized name follows everywhere else:

enum Request {
    @acme.audited
    Delete { id: int }
    @acme.audited
    Rename { id: int, to: string }
    Read   { id: int }
}

fn main() void {
    r := Request.Read { id: 1 }
    match r {
        Read(id) => println("${id}")
        Delete(id) => println("${id}")
        Rename(id, to) => println("${id} ${to}")
    }
}

What tells a decorated variant from a decorated method is what follows the decorators, not the @ itself: a name begins a variant, and fn, const or a visibility keyword begins the method block that ends the variant list.

Derive, honestly

@derive(Trait, ...) parses, validates that every argument is a trait name, and stores the list. A bare name (@derive(Equatable, Hashable)) is read by no pass, so it synthesizes nothing today: write it as forward-looking documentation if you like; do not depend on it.

A trait a deriver derives, named through the module that declares it (@derive(json.Encode)), is the one argument that does something. It says the type is derivable, and the compile of the package that writes it checks that it is: a library writes it on a public type to learn, in its own atoll check and CI, that json.encode of the type will work for whoever uses it, and a type that cannot be derived is ATOLL8016 at the decorator, with the field it stops at. A consumer never reads a dependency’s markers: it derives what it uses, as it does without them.

import json

@derive(json.Encode, json.Decode)
pub struct Settings {
    pub name    string
    pub retries int
}

You rarely need it. Structural equality, ordering, and hashing already work on any struct whose fields support them, and any enum whose payloads do, with no declaration at all:

struct Coordinate {
    x int
    y int
}

fn main() void {
    a := Coordinate { x: 1, y: 2 }
    b := Coordinate { x: 1, y: 2 }

    println("${a == b} ${a < b}")

    mut seen := Set.new[Coordinate]()
    seen.put(a)
    seen.put(b)
    println("${seen.len()}")   // 1 — structurally equal, one entry
}

The same synthesis satisfies a generic bound such as T: Comparable[T], so sorted() takes a list of them. Write the impl when the order should be a different one — see Operators.

Tooling

Tests and benchmarks are items, not decorators: test "name" { … }, bench "name" { … } and skip test "name" { … }, written at the top of a file. See Testing.

The decorators that used to mark them are retired and refused wherever they are written — @test (ATOLL1104), @bench (ATOLL1105) and @ignore (ATOLL1106) — because a spelling that still compiled would keep a test in every build. atoll fix rewrites a function they marked that takes no parameters and returns nothing into the item.

fn checksum(values []int) int {
    mut total := 0
    for v in values { total = total * 31 + v }
    return total
}

@test
fn checksum_is_order_sensitive() void {
    assert(checksum([1, 2, 3]) != checksum([3, 2, 1]), "checksum ignored element order")
}

Runtime

The stdlib and the runtime adapter use a lower-level set that defines the compiler/runtime ABI:

Decorator Meaning
@host Bind a body-less function to a typed wasm import
@suspend A body-less host or runtime function may yield to the runtime event loop
@builtin The implementation is supplied by compiler lowering
@intrinsic Bind a function to its same-named intrinsic
@intrinsic("name") Bind to an explicitly named intrinsic
@niche Select a compiler-known niche (arena-handle) representation

@host, @builtin, @suspend, @nosuspend and @niche take no arguments. A @host is bound by the module it is declared in and its own name (Type.method for a method), so no two declarations share a binding. A host function is synchronous unless it is @suspend.

@suspend is for a declaration with no Atoll body, whose suspension nothing else can tell. On a function with a body, or on a trait method, it is refused (ATOLL2026) with a fix that removes it: whether a body suspends is inferred from what it calls.

import task

@suspend
fn pause() int {
    task.yield_now()
    return 1
}

The standard library marks two more on its own declarations: @runtime, an operation the runtime answers itself, and @pure, an operation that touches nothing outside the program, which [host] allow does not gate. A program that writes either is refused.

The combination rules are enforced, not conventional:

@builtin
@host
fn broken() int

A @suspend binding makes every transitive caller suspending, which shows up in effect rows; a host binding without it is synchronous and does not.

@kind is not a routing decorator: writing it produces a migration diagnostic (ATOLL2025) pointing at @host:

@kind(3)
fn legacy() int

Application code should call safe standard-library functions rather than declare new host imports or intrinsics.

@cycle_free is refused — ATOLL1067

It asserts that a type can never take part in a reference-count cycle, and honouring it would mean believing it: the marked type would be subtracted from the cycle filter’s own output, so its blocks would be carved from the plain half of the allocator with no shadow count and no candidate-buffer entry.

That filter is contracted to answer conservatively yes, and the two failure directions are not symmetric — saying not cyclic of a type that is costs an unbounded leak and a Drop body that never runs, while saying cyclic of one that is not costs a buffer slot. It would be the only input that could take the first direction, and being wrong about it is not a diagnostic: every reference balances and every counter reads zero.

@cycle_free
struct Label {
    text string
}

Nothing replaces it. A cycle is reclaimed by trial deletion, so an ordinary self-referential struct is the supported shape and there is nothing to promise:

struct Label {
    text string
}

fn main() void {
    l := Label { text: "release-1" }
    println(l.text)
}

Data

The data layer recognizes @id, @unique, @sql.name, @sql.function, full-text metadata, vector dimensions, and index options. Models live in a unit that also declares a schema:

schema directory

@sql.name("people")
model Person {
    @id
    id: int

    @unique
    email: string

    display_name: string
}

fn main() void {
    p := Person { id: 1, email: "ada@example.com", display_name: "Ada" }
    println("${p.id} ${p.email} ${p.display_name}")
}

Their valid targets, arguments, and engine restrictions are documented in Models and Schemas.

Unknown names

Core parsing retains a decorator it does not recognize, so domain-specific tools can inspect it. Sema otherwise ignores the name and does not check the arguments:

@acme.reviewed("2026-07")
fn calculate() int => 42

@totally.unknown(1, "two", [3])
struct Widget {
    id int
}

fn main() void {
    println("${calculate()} ${Widget { id: 1 }.id}")
}

Preservation does not mean the decorator executes, validates its arguments, changes code generation, or exists at runtime. A subsystem has to implement those semantics.

Review

When a decorator changes correctness rather than optimization, document the contract beside the target:

Kind Review question
Representation Which layout or ABI invariant does the compiler assume?
Host binding Which capability, operation name, error, and suspension contract applies?
Visibility/ownership Which source boundary or lifetime rule changes?
Tooling Does omitting the tool still leave valid program semantics?
Data Which schema, migration, or dialect behavior changes?

Optimization hints such as @inline must not change program meaning. Low-level ABI markers such as @niche or @intrinsic carry proof obligations and should stay in compiler/stdlib code unless their subsystem explicitly supports application use.

There is no assertion-style decorator. @cycle_free would be one, and it is refused: an unchecked promise that turns off a safety filter is a proof obligation the compiler cannot audit and the failure it buys is silent.

The legacy docs/decorators/ catalog proposes actor, job, UI, auth, AI, MCP, HTTP-routing, and event decorators. Those application systems are not current core-language features and remain classified under Feature Status.

Type to search…

↑↓ navigate↵ selectEsc close