---
title: "Effects"
description: "The five effects the compiler infers, what ATOLL2031 and ATOLL2032 mean, and the rarely-needed `using [...]` row."
---

> 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.

# Effects

An *effect* is something a function may do beyond returning a value: suspend,
fail, allocate, spawn, or cancel. The compiler tracks all five for you.

**You almost never write an effect down.** Effects are inferred from what a
function calls, and ordinary Atoll code carries no effect annotations at all —
there is not a single one in the compiler's sample projects or its stdlib. A
function that writes none is told nothing about its effects: the two diagnostics
below are about a row somebody wrote.

```atoll
import task

fn checksum(data []byte) int {
    mut sum := 0
    for b in data {
        sum = sum + b.to_int()
    }
    return sum
}

fn checksum_in_turn(data []byte) int {
    task.yield_now()
    return checksum(data)
}
```

`checksum` only computes. `checksum_in_turn` calls `task.yield_now()`, from
`import task`, a `@suspend` host op that hands the turn to another task, so the compiler infers `Suspend`
for it — and for everything that calls it. That inference is what drives the
CPS transform in the backend; it is not a style rule you are being asked to
follow.

Not every host call suspends. `println` writes and returns, so a function that
only prints carries no effect at all; the ones that wait — `task.yield_now()`,
`time.sleep`, file and network I/O — are `@suspend`. That decorator is the host declaration's:
a function with a body never carries it (`ATOLL2026`), because its `Suspend` is
whatever inference finds. The converse is declarable and checked: `@nosuspend`
refuses a body that may suspend, by any route, with `ATOLL1071` — see
[Suspension](https://docs.atoll.workreef.dev/language/concurrency/suspension/#saying-a-function-must-not-suspend).

The explicit `using [...]` row exists, and the rest of this page shows it,
because it is how you would pin a contract on a published API boundary — and
the two diagnostics below are about a row written that way. Treat it as a
specialist tool.

## The five effects

There are exactly five. Any other name in a `using` clause is an error.

| Effect | A function carries it when it may... |
| --- | --- |
| `Suspend` | pause and resume later — a `@suspend` host call, a task `await` or `join`, a blocking `select`, a channel `send` or `recv` |
| `Error` | leave through the error channel — `error V`, or `?` on a `Result` |
| `Alloc` | allocate in managed arena storage — build a `List`, `Map`, `Set`, or interpolated `string` (declarable; not yet inferred — see [Current precision](#current-precision)) |
| `Spawn` | start a child task — `spawn`, or `race` (which spawns each arm) |
| `Cancel` | request cancellation — `Task.cancel()`, or `race` (which cancels losers); a call to `cancel()` does not seed it yet — see [Current precision](#current-precision) |

Each one, in isolation:

```atoll
import time

error DecodeError { Truncated }

fn may_suspend() void using [Suspend] {
    time.sleep(time.Duration.of_millis(1))
}

fn may_error(input string) int ! DecodeError using [Error] {
    if input.is_empty() { error Truncated }
    return input.len()
}

fn may_allocate(n int) []string using [Alloc] {
    mut out: []string = []
    mut i := 0
    for i < n {
        out.push("row ${i}")
        i = i + 1
    }
    return out
}

fn may_spawn(n int) int using [Spawn, Suspend] {
    child := spawn { n * 2 }
    return child.await().unwrap_or(0)
}

fn may_cancel(n int) void using [Spawn, Suspend, Cancel] {
    child := spawn { n * 2 }
    child.cancel()
}
```

`spawn` always brings `Suspend` along with `Spawn`, because the join that
follows it can pause. `race` brings all three of `Spawn`, `Suspend`, and
`Cancel`.

An effect is a conservative *may* fact. `Suspend` does not mean every call will
yield — awaiting an already-completed task takes a synchronous fast path. It
means the caller must be compiled to permit a yield on some reachable path.

The `unwrap_or` above is not about effects: `await()` answers `T?`, where `None`
is a task that was cancelled rather than one that produced nothing. The row is
`[Spawn, Suspend]` either way.

Rows are sets. Repeating a name adds nothing, and the row records neither how
many times an operation happens nor in what order.

## Inference

Most functions should not declare a row at all. Omit the clause and the compiler
computes one, unioning the rows of everything the body calls until the whole call
graph reaches a fixed point.

```atoll
import task

fn fetch(id int) int {
    task.yield_now()
    return id
}

fn fetch_pair(a int, b int) int {
    return fetch(a) + fetch(b)
}

fn report(a int, b int) int {
    return fetch_pair(a, b)
}
```

None of these declare anything, and all three end up carrying `Suspend`:
`task.yield_now()` seeds it, `fetch` inherits it, `fetch_pair` inherits it from
`fetch`, and `report` from `fetch_pair`. Recursion converges the same way — to
the union of everything reachable in the recursive component. And none of them
is told about it: checking that unit prints `OK (0 diagnostics)`.

## ATOLL2031 — the inheritance hint

`ATOLL2031` is a **hint**. It fires for a function that declares its row, when
the row picks up an effect it lists from a *called* function rather than from an
operation in its own body. It is a trace, not a complaint.

```atoll
import task

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

fn twice() int using [Suspend] {
    return tick() + tick()
}
```

Checking that unit prints:

```text
hint[ATOLL2031]: fn `twice` inherits effect `suspend` from a transitively-called callee at src/main.at:7:12
  label: `tick` calls `yield_now` here at src/main.at:2:5
  help: fn `twice` inherits `suspend` because it calls `tick`
fn `tick` inherits `suspend` because it calls `yield_now`
fn `yield_now` is where `suspend` is introduced
```

The declaration is correct and complete; the hint simply tells you *where*
`Suspend` came from — each call on the way, and where it is — so you can follow
the chain when a row surprises you. Diagnostics render normalized lowercase
names (`suspend`, `alloc`); source uses the PascalCase spellings.

There is nothing to fix. Hints never fail a build. A function with no `using`
clause gets no hint: there is no row of yours to explain.

## ATOLL2032 — the row-violation warning

`ATOLL2032` is a **warning**. It fires when a function that declares its row
inherits, through a call, an effect the row does not list. A function with no
`using` clause declares nothing and promises nothing, so it is never warned —
which is why ordinary code, writing no rows, sees neither this nor the hint.

```atoll
import task

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

fn refresh() int using [] {
    return poll_backend()
}
```

That unit still compiles, but reports:

```text
warning[ATOLL2032]: fn `refresh` inherits effect `suspend` from a transitively-called callee but its declared `using [..]` row does not list `suspend` at src/main.at:7:12
  label: `poll_backend` calls `yield_now` here at src/main.at:2:5
  help: fn `refresh` inherits `suspend` because it calls `poll_backend`
fn `poll_backend` inherits `suspend` because it calls `yield_now`
fn `yield_now` is where `suspend` is introduced
```

It is a warning, so `atoll check` passes and `atoll lint` does not. The
responses:

1. **Widen the row** — when this function is a contract boundary and its callers
   should permit the capability.
2. **Stop calling the effectful thing** — if you *wanted* this function to stay
   pure, move the work to a caller and take the result as a parameter. The
   warning is the signal that purity slipped.
3. **Make the boundary polymorphic** — if the effect arrives through a callback,
   thread it with a row variable (below) rather than hard-coding it.
4. **Delete the clause** — if you did not mean to pin a contract here. An
   inferred row is shorter, and stays right when the body changes.

Widening is the fix here:

```atoll
import task

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

fn refresh() int using [Suspend] {
    return poll_backend()
}
```

Response 2 is worth seeing too, because it is the one that keeps a row narrow:

```atoll
import task

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

fn interpret(sample int) string using [] {
    return if sample > 0 { "up" } else { "flat" }
}

fn refresh() string using [Suspend] {
    return interpret(poll_backend())
}
```

`interpret` does the decision-making and stays provably effect-free; only the
thin outer function carries `Suspend`.

Do not reflexively add all five effects to silence the warning. `using []` is
worth writing precisely because it turns "this stayed pure" into a checked
statement.

Note the boundary of the check: `ATOLL2032` is about *inherited* effects. An
operation written directly in the body of a `using []` function is not currently
reported, so the row is an assertion about your call graph, not a sandbox.

## Unknown effect names are errors

Unlike the two diagnostics above, a bad name in a `using` clause fails the build.

```atoll refused=ATOLL2021
fn f() int using [Blocking] {
    return 1
}
```

That is `ATOLL2021: unknown effect name 'Blocking' in using clause`. The
lowercase spellings that appear in diagnostics are not accepted in source either:

```atoll fail
fn f() int using [suspend] {
    return 1
}
```

## Row variables

A higher-order function should not have to claim its callback's effects. Bind a
generic parameter and use it as a row:

```atoll
error ParseError { Empty }

fn apply[T, R, E](value T, op fn(T) using [E] -> R) R using [E] {
    return op(value)
}

fn checked(s string) int ! ParseError {
    if s.is_empty() { error Empty }
    return s.len()
}

fn pure_twice(n int) int {
    return n * 2
}

fn use_pure() int using [] {
    return apply(21, pure_twice)
}

fn use_failing() int using [Error] {
    return apply("12", checked).unwrap_or(0)
}
```

One `apply`, two specializations. With `pure_twice` the row variable resolves to
the empty row, so `use_pure` stays `using []`. With `checked`, which can fail,
it resolves to `[Error]`, and `use_failing` lists it. (A caller that leaves an
effect arriving through a row variable out of its own row is not yet told: see
[Current precision](#current-precision).)

A callback that suspends binds the row variable to `[Suspend]`, whatever its own
type says: a closure's body is what decides, and the compiler knows it once it
has inferred the body's row. The specialization of `apply` it reaches suspends,
and so does its caller; a callback that does not suspend reaches the
specialization that does not. That takes the variable in the higher-order
function's own row, as `apply`'s `using [E]` has it; a function that calls a
callback written with no `using` infers it too, generic or not, so `fn
apply(value int, op fn(int) -> int)` has a specialization for each kind of
callback. `List.map` keeps its callback in the iterator it returns and calls it
later, from `collect`: the iterator is a struct whose field takes the callback's
row (below), so the `collect` of a `map` over a closure that suspends suspends.

```atoll
import task

fn apply[T, R, E](value T, op fn(T) using [E] -> R) R using [E] {
    return op(value)
}

fn slow_double(n int) int {
    task.yield_now()
    return n * 2
}

fn run() int {
    return apply(20, (x int) => slow_double(x)) + apply(1, (x int) => x * 2)
}
```

A row variable may sit behind a fixed prefix. `using [Error, E]` means "may
always fail, plus whatever the callback contributes":

```atoll
error Closed { Shut }

fn guarded[T, E](open bool, op fn() using [E] -> T) T ! Closed using [Error, E] {
    if !open { error Shut }
    return op()
}

fn make_answer() int {
    return 42
}

fn run() int using [Error] {
    return guarded(true, make_answer).unwrap_or(0)
}
```

The identifier must be a generic parameter of the enclosing declaration. A bare
capital letter that binds nothing is just an unknown effect name:

```atoll fail
fn f() int using [E] {
    return 1
}
```

## Effects in function types

Effect rows are part of a function type, so they participate in assignment
compatibility.

```atoll
type PureTransform = fn(string) using [] -> string

fn upper(s string) string using [] {
    return s.trim().clone()
}

fn run() string {
    quiet: PureTransform = upper
    return quiet("a")
}
```

The `using []` on `upper` is load-bearing: matching a function *type* that names
a row requires a *declared* row on the function value.

**A row that lists `Suspend` says a call through the value may suspend.** A
closure or a named function whose body suspends may be stored as a value of such
a type — in a local, a parameter, a field or a list — and called through it.
The call suspends as a direct call of the function would: the caller waits for
it, and a task cancelled while it is parked inside unwinds through the callee's
`defer`s and then its own.

```atoll
type WaitingTransform = fn(string) using [Suspend] -> string

fn announce(s string) string using [Suspend] {
    println(s)
    return s
}

fn run() string using [Suspend] {
    loud: WaitingTransform = announce
    return loud("b")
}
```

A closure literal, and a function named as a value, take the row of the function
type they are written against, as a Rust closure takes the signature it is
passed as — so a struct field or a list of handlers is written once, with the
row, and filled with closures that say nothing about it:

```atoll run=23
import task

struct Handler {
    name string
    run  fn(int) using [Suspend] -> int
}

fn handlers() []Handler {
    mut out: []Handler = []
    out.push(Handler { name: "wait", run: (n int) => {
            task.yield_now()
            return n + 1
        } })
    out.push(Handler { name: "now", run: (n int) => n * 10 })
    return out
}

fn main() int {
    mut total := 0
    for h in handlers() {
        total += h.run(2)
    }
    return total
}
```

A function that does not suspend may be used where the type allows suspension,
as the second handler above is. The call through the value tests which kind of
body it reached and calls one that does not suspend as an ordinary function.

**A row written nowhere is inferred.** A closure bound with no type written has
a row of its own, as a callback parameter has, so it may suspend: called where
it is written, kept in a list the function walks, chosen by an `if`, or handed
to a function that calls it. A call through it suspends where the function
making the call does, and a function that writes a closure whose body suspends
does:

```atoll run=3
import task

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

fn twice(op fn() -> int) int {
    return op() + op()
}

fn main() int {
    g := () => slow()
    return g() + twice(g)
}
```

**A struct field infers its row too.** A struct whose field holds a function
type written with no `using` takes the row of what it holds as a parameter of its
own, which no program writes: a `Handler` of a closure that suspends is an
instance apart from a `Handler` of a plain one, and a call through its field —
in a method, in a function handed it, from a list of them — suspends exactly where
what it holds does. `List.map` keeps its callback in the iterator it returns the
same way, so a closure that suspends may be mapped:

```atoll run=23
import task

struct Handler {
    name string
    run  fn(int) -> int
}

fn handlers() []Handler {
    mut out: []Handler = []
    out.push(Handler { name: "wait", run: (n int) => {
            task.yield_now()
            return n + 1
        } })
    out.push(Handler { name: "now", run: (n int) => n * 10 })
    return out
}

fn main() int {
    mut total := 0
    for h in handlers() {
        total += h.run(2)
    }
    return total
}
```

A function's answer infers its row the same way: `fn make() fn() -> int`
answers a function of the row of the closure its body builds, and a call of
`make` holds one that suspends where that closure does. `fn compose(f fn(int)
-> int) fn(int) -> int` answers the row of the `f` it is handed.

An enum variant's payload infers its row as a struct's field does: `Run(fn(int)
-> int)` holds a function that suspends where the closure it was built from
does.

What is refused is a function that suspends kept where its type says it does
not: a field, a payload, a local or an answer written `using []`. A call
through it there would be made as a plain call, with no continuation for the
body to come back to:

```atoll refused=ATOLL1061
import task

struct Plain {
    run fn(int) using [] -> int
}

fn slow(n int) int {
    task.yield_now()
    return n * 2
}

fn main() {
    p := Plain { run: (x int) => slow(x) }
    println("${p.run(2)}")
}
```

**What it costs.** A call through a type whose row does not list `Suspend` is an
ordinary indirect call, as it always was. A call through one that does tests the
value's code word — a load and a branch — before it calls. Where the callee is
known, as a closure literal handed straight to a higher-order function is (the
function is specialized for it), the call names the body and there is no test.

## Effects are not error types

`Error` and the `T ! E` signature answer different questions. The signature says
*which* error values can escape; the effect says *that* an error exit exists.

```atoll
error StoreError { Missing, Conflict }

fn read(key string) string ! StoreError using [Error] {
    if key.is_empty() { error Missing }
    return "value"
}

fn read_or_default(key string) string using [Error] {
    return read(key).unwrap_or("fallback")
}
```

`read_or_default` discharges the `Result` with `unwrap_or`, so no error value can
escape it — yet it still declares `Error`, because the effect travels along the
call edge to `read` regardless of how the result is consumed. Dropping `Error`
from that row yields an `ATOLL2032` warning, not a narrower contract; dropping
the whole clause leaves the row to inference, which finds `Error` itself and
says nothing.

Likewise, `Suspend` does not say *why* a function waits, and `Alloc` does not
expose an allocator. Effects are static contracts used for checking, ABI
selection, and lowering. They are not runtime handlers, they do not authorize
unsafe memory access, and they are not a security boundary.

## When to declare a row

Write one explicitly for:

- public library signatures whose capability set is part of the contract;
- callback parameters and generic adapters (use a row variable);
- host and compiler boundaries;
- functions where "this is effect-free" is the point.

A row is a contract the diagnostics warn about (`ATOLL2032`). When the point is
only that a function must never suspend, `@nosuspend` says so and is an error
when broken.

Leave it off for ordinary internal functions. Inference is shorter and it stays
correct when the body changes.

## Current precision

Two places over-approximate, and the diagnostics reflect the approximation rather
than runtime behaviour:

- **`select`** records `Spawn`, `Suspend`, and `Cancel`, even though a
  source-level selection spawns nothing and cancels nothing. A `select` with a
  `default` arm uses a non-blocking poll and still carries the full row.
- **Spawn bodies** are checked inside the enclosing function, so an effect used
  only inside a child can widen the parent's inferred row.

```atoll
fn work() int { return 1 }

fn dispatch() int using [Spawn, Suspend, Cancel] {
    a := spawn { work() }
    b := spawn { work() }
    mut chosen := 0
    select {
        v := a => chosen = v.unwrap_or(0)
        v := b => chosen = v.unwrap_or(0)
    }
    return chosen
}
```

`dispatch` never calls `cancel`, but the declared row needs `Cancel` to stay
warning-free. Treat the explicit row as the contract, and let the diagnostics
tell you which capability the current analysis wants.

And three places under-approximate, so a declared row does not catch them yet:

- **`Alloc` is never inferred.** Nothing seeds it — not a `List` built, not an
  interpolated `string` — so a function that allocates through a call under a
  `using []` row is not told.
- **`cancel()` does not seed `Cancel`.** A function that cancels a task through
  a call inherits `Spawn` and `Suspend` from it, and not `Cancel`.
- **An effect that arrives through a row variable is not held to a `using []`
  caller.** `apply("12", checked)` above, in a function declared `using []`, is
  not reported; declared `using [Error]`, the hint shows `Error` arriving.

Source: https://docs.atoll.workreef.dev/language/concurrency/effects/index.mdx
