On this page
Xo Language Specification (Core)
Status: draft 0.49 (2026-11-10; 0.48 tagged as toolchain v0.48.0, decision 0089)
Edition: preview (the only edition before 1.0, decision 0155)
Companion: spec/std.md (prelude methods and standard library surface)
Xo is a small, statically typed, garbage collected language for backends and web services. It keeps what makes Go productive (few keywords, one obvious way, fast builds, static binaries, a strong standard library, a compatibility promise) and is designed so that an AI agent can write, check, build, and debug programs for any OS with fast, structured, unambiguous feedback.
Changes in 0.49
None yet.
Changes in 0.48
None yet.
Changes in 0.47
None yet.
Changes in 0.46
- An interface value’s covariant effect argument widens:
Cred[fs.read]is usable asCred[(fs.read, proc)](section 6.2, decision 0582). - An
Osliteral may leave outfs,net,env,procandstdio: each omitted field is its no-access value;clock,randandtasksstay required (section 6.3, decision 0585).
Changes in 0.45
- linux/riscv64 (12.1, 12.2; decision 0571 stage 1):
TargetArchgainsRiscv64, so an exhaustivematch target.archneeds its arm; the target builds with--backend=llvmonly and is not inall. - freebsd/amd64 and freebsd/arm64 (12.1, 12.2; decision 0573 stage 1):
TargetOsgainsFreeBSD, so an exhaustivematch target.osneeds its arm; the targets cross build and are not inall. - Checksum log server (4.3; decision 0124’s addendum):
xo mod sumdb keygenandxo mod sumdb servemake a log’s key and run a log, its records kept in a data directory.xo mod proxy fillfills an S3-compatible bucket with the proxy protocol’s files (decision 0568).
Changes in 0.44
derive Json(match: fold)(decision 0550, 2.2): a type’s decoder matches keys as Go’s encoding/json does (an exact key, else the first declared field whose key folds equal; the last selecting member wins; errors in Go’s document order).matchis accepted as a derive argument name.
Changes in 0.43
- Destructuring assignment (5.2, decision 0536):
(a, b) = (b, a)and(q, r) = divmod(x, y)assign a tuple’s elements to existing places, the value first, then each place left to right;XO0539for a place named twice. - Struct targets (5.2, decision 0538):
P{x, y} = p,P{x: st.lo, y: xs[i], ..} = pand(P{x, y}, n) = (p, 3)store a struct’s fields into existing places by the rules oflet’s struct pattern. List targets followlet’s list patterns (owner, 2026-11-06):[a, b] = xsisXO0303, and[..] = xsonly evaluatesxs.
Changes in 0.42
None yet.
Changes in 0.41
- 5.5 describes native memory management (reference counting, decision 0046, and the one way a cycle forms) instead of only the Go backend’s tracing collector; no behavior change.
Changes in 0.40
xo debug PROGruns a native program under xo’s debugger on macOS arm64 (10.1, 11.5; decision 0253 stages 2 and 3), withrun,continue,step,nextandfinishand theirstopfields in the protocol,tasksandtask N [bt]from the runtime’s records andxo debug -p PID PROGto attach (stage 4), andxo debug --dapfor editors (decision 0504); darwin builds with debug information carryget-task-allow, andxo build --entitlement=KEYadds an entitlement.
Changes in 0.10 to 0.39
The header stayed at draft 0.10 through toolchain v0.39.0 (2026-10-10 to
2026-11-05) instead of moving with each minor release as decision 0089
says; the changes of those releases are listed together here, and
CHANGELOG.md has them per release.
- User capabilities on every backend (decision 0307): a program’s own
type converted to
Fs,Proc,Env,Net,Stdio,Clock, orRand, and anOsbuilt with a literal, work on the native backends as on the Go backend (they were XO1201);Rand.shuffleis derived from the value’sint. - Raw multi-line strings (1.6, decision 0320):
r"""..."""(andr#"""..."""#to hold""") is a multi-line string with no escapes and no interpolation, its common leading indentation removed as for""". - Embedded files (3.1, decision 0304):
const X: Str = embed("path"), alsoBytesandembed.Dir, puts files into the program at build time on every backend;XO1506toXO1509. - Moves end with their path (5.3, decision 0300): a move of a
Buf,StrBuilder, orBytesBuilderon a path that ends (return,break,continue, the error side of?, aNevercall) no longer reaches the code after it, soreturn Some(out.freeze())inside a loop or anifis accepted;XO0510keeps its meaning. - Debug interpolation (1.6, decision 0296):
${x:?}writes the Debug text ofx, asx.debug()does, so aResult,List, orOptionneeds no.debug().xo vetnotes${x.debug()}with the fix (XO0535). - Discarded pure results (2.6, decision 0258): an expression statement
that drops the value of a call that only computes it (
xs.reverse(),s.trim(), a function with no effects) is errorXO0209, fixed byxs = xs.reverse()orlet _ = f(). xo build --stamp NAME=VALUE(10.1, decision 0165): sets aconst NAME: Strof the main module for one build (versions, commits);XO1501when there is no such constant.std/cliwrites shell completion scripts (std.md 14.5).- Formats (std.md 16 to 19, decision 0164):
std/csvandstd/toml(every backend),std/regexpandstd/archive(gzip, tar, zip; Go backend, native builds report XO1201, planned). - Files (std.md 3.1, 3.5, decision 0163): streaming
Filehandles,append,copy, permission bits, symbolic links,glob, advisory locks, andEnv.config_dir/cache_dir. Go backend; native builds report XO1201 (planned). - Terminals (std.md 3.6, 15, decision 0162):
Stdiotells whether each stream is a terminal and its width, reads secrets without echo, and reads binary input;std/termcolors output following NO_COLOR and FORCE_COLOR. Every backend. - Commands and children (std.md 3.8, decision 0161):
Proc.cmdbuilds aCmd(directory, environment from anEnv, input, the terminal, merged streams) run byoutput,run, orspawn(aChildwith streaming reads and writes);Proc.pipelinepipes commands. Go backend; native builds report XO1201 (planned). std/cli(14, std.md 14, decision 0160): command line parsing for tools: flags of five types and repeated ones, positional and rest arguments, subcommands,--, variables as fallbacks, generated help, and usage errors with exit status 2 (parse_or_exit). Every backend.- Logging is the effect
log(6.1, std.md 6, decision 0156): thestd/logfunctions performlog; apubfunction that logs declaresuses log.xo fixadds it to existing code (XO0701 with a fix). xo audit(10.1, decision 0156): per dependency effects, lock state, ceiling, escape hatches and vouches; attenuations and the capabilities passed into dependencies.- Capability attenuation (6.3, std.md 3.2, 3.5, 3.7, decision 0156):
os.net.only(hosts),os.env.only(names), andos.proc.only(cmds)return narrowed capabilities;NetErrandProcErrgainDenied. Native builds haveonlytoo (decisions 0172 and 0175). - Effect lock (4.3, decision 0156): xo.lock records each
dependency’s effects (
<path> effects <labels|none>); an update that widens them fails every load withXO1317untilxo mod accept-effects(orxo get --accept-effects) records them. - Vouches (4.2, decision 0156): a required module’s
use clines anduse goof impure Go packages count only with avouchline in the consuming module’s xo.mod for that exact version, elseXO1316; an unvoucheduse cbinding performsffiwhatever its ownusessays. edition preview(4.2, 13, decision 0155): until 1.0 the only edition ispreview, whichxo initwrites.edition 2026stays an alias of it during the 0.x releases;xo checkgives the fixable noteXO1315on it andxo fixrewrites it. The compatibility promise of 13 starts with the first frozen edition, named at 1.0.- Receiver order (5.2, decision 0326): a by value receiver that is a
variable or a field path is read after the call’s arguments, as a
varreceiver is (0142);t.size(t.add(v))sees the itemaddpushed. - Assignment order (5.2, decision 0140): an assignment computes its value before it reads the binding it stores into, so changes the value makes to that binding are kept (the native backends dropped them).
for b in bytes(3.5, decision 0138):Bytesis iterable and yields each byte as aUInt8.while let(3.5, decision 0137):while let Some(v) = expr { }loops while a refutable pattern matches, andwhile let v = optis the Option shorthand, as forif let.- Real-time functions (6.5, decision 0133):
uses realtimeon a function declaration forbids allocation (XO1401), loops without a bound (XO1402), calls of functions that are not real-time, function values, and interface methods (XO1403), recursion (XO1404), and blocking (XO1405). Native builds defer the frees of a real-time section to its end and fault withXO-F007when it allocated. - Loop bounds (3.5):
for x in xs bound N { }andwhile cond bound N { }, a contract on any loop: a constant range longer than N isXO1402; otherwise starting iteration N + 1 faults withXO-F006.boundis a contextual word. - Builds skip inline test blocks (9.2, decision 0389):
xo buildandxo runneither declare nor check atestblock, as they read no_test.xofile (decision 0348); an error in one failsxo checkandxo test, not a build. - A fault inside
Mutex.withpoisons the mutex (5.4, decision 0482): the closure’s writes are no longer undone; laterwithandwith_readfault withXO-F010untilm.reset(v). AnErrand a cancellation still leave the value unchanged. A closure that changes a collection no longer copies it to keep the old value for a fault.
Changes in 0.9
Meaning changes: std/http over TLS speaks HTTP/2 when both sides offer
it, on every backend (below), and
one variable passed to two var parameters of a call is an error
(XO0503, 5.2, decision 0111; the Go backend shared it, the native
backends reported XO1201). A value that holds a handle (Mutex,
Chan, Task, Conn, …) or a function value is not comparable: ==,
Map keys, Set elements, and derive Eq/Hash on it are XO0404
on every backend (2.9, decision 0112; the Go backend compared the
handles, the native backends reported XO1201). Native support grew
(--no-gc, 10.1):
- Interface types as values (2.4) build natively (decision 0100).
- Newtypes (2.8, decision 0097: construction,
e.0,Email(p), Debug text, equality, Map keys) and list patterns (3.5) build natively. - Float32,
Secret[T],Buf[T], order ofderive Ordtypes, and the std value methods listed in decision 0101 build natively. std/path,task.semaphore,task.once, andtask.map_concurrentbuild natively (std.md 7, 9).- Every Fs method and attenuation,
Stdio.write, and standard input reads (7.2, 7.5: canceled by a cancellation or a stop request) build natively (decision 0102). - Error frames (11.1) are recorded natively and printed in main’s error report (decision 0104).
std/timebuilds natively (std.md 13, decision 0094), with the same per use zone data and output as the Go backend; so doDuration.from_secs,scale,ceil_seconds, andTime.parse_rfc3339(2.6).- std/http serves and calls HTTPS on every backend (std.md 4.6, decisions
0105 and 0106):
http.tls_cert,Server.with_tls,Client.with_roots, andTlsErrare new; the native backends speak TLS with Mbed TLS, so anhttpsURL is no longerXO1201there. Over TLS, servers and clients speak HTTP/2 when ALPN agrees onh2(decision 0121; the Go backend’s server spoke HTTP/1.1 only before, its client already used HTTP/2); plainhttpstays HTTP/1.1. use c "<header>" [link "<lib>"]... [as name] [uses ...]calls C from native builds (4.5, decisions 0093 and 0116): bindings generated from the header (xo bind --c), scalars, Str, Bytes, flat structs, and opaque handles at the boundary, the effectffi(6.1) unless the line narrows it,XO1104andXO1105for headers and names that do not bind, andXO1201on the Go backend.
Changes in 0.8
From the spec audit of 2026-10-09 (bench/results/spec-audit-2026-10-09.md):
no meaning changes, the spec now says what is not implemented yet.
Method syntax stays receivers (decision 0090), Map keeps insertion
order (0091), error frames are lazy and always on (0092), and foreign
calls will be recorded at the boundary (0093); std/time is accepted as
specified in std.md 13 (decision 0094).
xo build --ciexists: it fails before building on an unformatted file or adbgleft in code (10.1, 10.5, 11.4).- 10.6 lists every diagnostic and fault code with its severity, kept equal
to the toolchain’s registry by a test.
XO1001is reserved. --jsonis accepted by the commands that report results, not by every command;xo testtakes--cases=N, not--fuzz(10.1).- [later] markers for what is specified but not built:
xo why,xo debug, the task line of error traces, automatic spans and OpenTelemetry export (std/trace’s spans and std/metrics exist, 11.6), SBOMs,std/sys,OpenApiandProtoderives. - Modules (4.2, 4.3; decision 0086 steps 1 and 2):
require <path> <version>of Xo modules with minimal version selection, git fetch into a read only module cache,xo.lockhashes verified by every command,xo get,xo mod tidy,xo vendor,--offline, andxo.workworkspaces (--workspace=off). New codesXO1301toXO1308(10.6). An import from a module that is not required isXO1306. - From the Codex r2 rerun (
bench/results/codex-xo-r2-2026-10-09.md): a closure whose body never completes has result typeNeverwhen nothing else determines it (3.3);x.display()is callable on everyDisplaytype, derived and std errors included (std.md 1); severalmatcharms on one line keep parsing, with a fix that splits them (XO0175). - Effect ceilings and checked semver (4.2; decision 0086 steps 3 and 4):
require <path> <version> uses none(oruses net, fs.read) in xo.mod anduse <dir> uses ...in xo.work bound what a dependency’s functions may declare; a call above the ceiling isXO1309at the call site.xo getprints the API and effect changes of every version change (-uupgrades every requirement).xo publish [--check]compares the exports and effects with the previous tag and rejects a breaking minor or patch release (XO1310,XO1311); it never tags or pushes.xo initwrites xo.mod and gitignores xo.work. Module paths ending in/vN(N >= 2) are major version N of the same repository; the suffix is skipped for the local name (4.1). std/time(std.md 13, decision 0094) is implemented on the Go backend: zones with per use embedded data (--tzdata=systemreads the host database), civil dates and times with explicit daylight saving gaps and overlaps, and layouts with named fields. A constant layout is checked at compile time:XO0420for an unknown field (10.6),XO0177for date patterns of other languages. Native backends report it asXO1201(planned).- Import direction rules (4.2, 10.3; decision 0095):
deny <pkg> -> <pkg>, ...lines in xo.mod, with/...patterns; a forbiddenuseis the new errorXO1312at that line, a rule naming no package isXO1301.xo query importsandxo query depslist theuselines. std/timeerrors display as sentences (std.md 13.5):ZoneErrandCivilErrno longer deriveDisplay.- Newtypes (2.8; decision 0097):
e.0reads (and on avarassigns) the underlying value, and the patternEmail(p)matches it, irrefutably whenpis (let Email(s) = e). Go backend; native builds reportXO1201as for every newtype (native support added in 0.9). xo check --fix(10.1, 10.2; decision 0096) applies every unambiguous machine fix, reformats the changed files, and reports what remains with the list of applied fixes; plainxo checkstays read only. The MCPchecktool takesfix.- From the second pass of the spec audit:
x.debug()is callable on every value, as std.md 1 says every type implementsDebug(it wasXO0601on concrete types); reproducible builds are stated for the same source directory (12.1), which a test now checks. - Modules in repository subdirectories (4.2; decision 0086): the module
github.com/acme/tools/cliincli/with tagscli/vX.Y.Z; fetch, version selection, xo.lock, vendoring,xo get, andxo publishhandle the prefix. Nested modules are left out of the module around them.XO1311now also reports a subdirectory module whose path does not end with its directory. - Go calls are recorded (11.3; decision 0093 stage 1), replacing “Go calls
are not recorded”: calls with boundary values only are answered from
the trace by
xo replay; calls with a handle or a callback run again and are reported (re executed foreign call `<name>`); pure functions arereplay rerun(std’s pure packages, and xo.mod linesreplay rerun go <path> [names], 4.4). Old traces still replay. - Release builds (8, decision 0099):
xo build --releasecompiles outrequires(debug)andensures(debug)on every backend and fails while a workspace overrides a required module (XO1308, formerly reported only by--ci).--cidoes not imply--release;xo run,xo test, and plainxo buildare debug builds. - Error frames are lazy (11.1, decision 0092, Go backend): a frame keeps
copies of the parameter values and formats them, at most 64 bytes'
worth, only when the trace is printed; output is unchanged. About 10
times cheaper per propagated error with short parameters, 29 times
with 90 byte ones, and independent of parameter size. Frames are on in
release builds;
--release --error-args=falsedrops the parameter values ((...)). - Module proxies, checksum log, definition hashes (4.2, 4.3, 10.3;
decisions 0124 to 0126, completing 0086):
XO_PROXYandXO_NOPROXYwith a read only proxy protocol andxo mod proxy serve;XO_SUMDBandXO_NOSUMDBcheck every first fetch against a signed Merkle log (newXO1313,XO1314;XO1302now also covers proxies);xo query hashand the definitions list ofxo publish.
Changes in 0.7
Decisions 0041 (Go packages) and 0042 (two phase shutdown).
Request scoped arenas are on by default for HTTP handlers (5.5; decision 0066): an implementation detail with no observable effect, off with
--no-arenas.Go packages with
use go(4.4).Two phase shutdown (7.5).
Mutex.with_read, shared read only access (5.4, std.md 2.7; decision 0063). A closure parameter declaredvarwhere the expected function type takes it by value is errorXO0401(it changed a copy only).BytesBuilder, the move only builder ofBytes(5.3, std.md 2.7; decision 0078).Warning
XO0305is not reported for a_arm that hides at least 8 variants and more than half of the enum (3.5; decision 0080).A rune literal where an integer type is expected is its code point (1.6);
Int(r),Rune(n), andRune.try(n)convert betweenRuneand the integer types (2.1; decision 0079).xo build --hybridcompiled hot leaf loops to native assembly inside Go backend builds (10.1; decision 0084); deprecated since 2026-10-22 (owner): it is a plain Go backend build with a warning, and will be removed.The native backends check
ensuresand struct invariants and unwind faults (deferred code, scopes, Mutexes,task.isolate, a 500 from an HTTP handler) as the Go backend does (3.5, 8, 9.1; decision 0085).Habit diagnostics: error
XO0177(syntax from another language), and habit notes and fixes on existing codes, for Go, Rust, TypeScript, Python, Swift, and Kotlin forms (10.2; decision 0087). No program that was accepted is rejected.clock.sleep_or_cancel(d)returns cancellation asClockErr.Canceledinstead of unwinding; reading standard input is a cancellation point, and a stop request ends it too (7.2, 7.5; decision 0088).
Changes in 0.6
Driven by the independent replant of planted safety bugs
(bench/results/planted-xo-2026-10-07.md). Decision 0038.
- Reading a
Mapby index, or changing an element in place through it, is errorXO0410; useget,get_or_fault, orupdate.m[k] = vstays (3.6). - Warning
XO0305: a_arm hides variants of an enum declared in the same module (3.5). - Warning
XO0804: a value read in oneMutex.withis used, or acted on, in a laterwithon the same mutex (5.4). - Regression tests for shrunk contract fuzz failures go in the module’s
regressions_test.xo, nottestdata/regressions/(9.2). - Go packages with
use go(4.4), with thegoeffect. for x in chover channels (3.5, 7.3);task.Onceandtask.map_concurrent_untilin std.- Two phase shutdown: the first signal requests a stop (
task.stop_requested,task.stopping), cancellation follows after a grace period (7.5). - Std:
Map.get_or_fault, hex and base64 onBytes,Time.from_unix_millis,Atomic.max,Range.to_list,Patch.apply_to/apply_opt, andstd/path.
Changes in 0.5
Driven by the stage 2 benchmark (bench/results/stage2-xo-check-2026-10-07.md).
Decision 0037.
- XO0520: a mutated copy of a collection element must be stored again; reading it afterwards no longer counts (5.2).
ismay be combined with&&and||(3.5, 15).- Each arm of a tail
iformatchis in return position (2.6). testingis usable in helper signatures in_test.xofiles (9.2).
Changes in 0.4
Driven by the P1 parser and checker, the planted bug benchmark, and the harder
tasks (bench/results/planted-and-harder-2026-10-07.md,
bench/results/check-corpus-v0.3.md). Decisions 0028 to 0035.
- Task groups that can be stored in structs,
os.tasksfor program lifetime work,try_send/try_recv,task.map_concurrent(7.1, std). - Discarding a
Resultwithlet _ =is an error; use.ignore_err("reason")(2.6). - Effect arguments of generic types may be omitted (6.2).
x is Patterntests a pattern (3.5). All compound assignments, tuple fieldst.0, localconst, qualified types infrom, doc comments on fields and variants.- XO0520 also covers
.or_err(...)?copies and values mutated after being stored in a collection (5.2). Mutex.withkeep and fail pattern documented (5.4).- Grammar readings from the parser and typing readings from the checker are written into the relevant sections (1.3, 1.6, 2.1, 2.6, 2.10, 3.3, 7.1, 15).
- Streaming HTTP bodies,
Fs.write_only, fullerSet,testing.run_main(std).
Changes in 0.3
Driven by the second paper test (bench/results/paper-2026-10-07-v0.2.md).
Decisions 0021 to 0027.
- String interpolation is
${expr};{and}are literal in plain strings. Raw stringsr#"..."#may contain quotes (1.6). deferblocks are shielded from cancellation (3.5, 7.2).- XO0520 applies only to values copied out of a collection (5.2).
?works onOptionin functions returning an optional (2.6).- A line starting with
.continues the previous line (1.3). - Implicit conversions are listed in one place: there are three (2.10).
- Block and loop typing, generic literal inference, qualified variant
patterns, module local names, pure means no capability effects,
uses (...)allowed on declarations, process signals (various sections).
Changes in 0.2
Driven by the paper test in bench/results/paper-2026-10-07.md. Decisions
0011 to 0020 in knowledgebase/decisions/.
- Explicit failure with
return Err(e)and tailErr(e)(2.6). NewNevertype (2.1). Ok Err Some Nonereplaceok err some none.resultandoldare contextual insideensuresonly (1.4, 2.5, 2.6).- Full pattern syntax including
_, literals, ranges, or patterns, nested patterns, positional and named variant fields (3.5). - Unused binding rule relaxed for parameters and
_names (3.1). - Effect variables and effect subsumption (6.2). Multiple effects in a function type are parenthesized.
- Scope rules: background tasks, exit behavior, error propagation;
scope ... timeoutremoved in favor oftask.with_timeout(7). - Cancellation is observable as a
Cancelederror from fallible blocking calls (7.2). Mutex.withsignature and write back rule (5.4); lost update checkXO0520andMap.update(5.2).- Test blocks get an implicit
os: TestOs;std/testrenamedstd/testing(9.2). - Logging is ambient and untracked (6.1).
- Slicing with ranges, closure literal grammar, trailing commas, const struct
literals,
{}is always an empty map (1.6, 3.x, 15).
0. Design goals
- No guessing. Every name resolves to exactly one definition, found by
reading local code. No overloading, implicit conversions, inheritance,
macros,
init(), or hidden control flow. - The compiler is an API. All tool output is structured JSON with stable codes and machine-applicable fixes.
- Errors cannot be ignored, nil does not exist, matches are exhaustive.
- Authority is explicit. Side effects are declared in signatures and
performed only through capability values passed down from
main. - Concurrency is structured. No task outlives its scope. No shared mutable state without an explicit synchronized type.
- Every target is checked on every build. No build tags.
- Every failure is reproducible. Effects are recordable and replayable.
- Compatibility. Code that builds under an edition keeps building under that edition forever, from the first frozen edition named at 1.0 (13). New editions ship with automatic rewriters.
Staging
Each section is tagged with the phase in which it is implemented.
- [P1] Prototype:
xofrontend written in Go, emits Go source, uses the Go toolchain for codegen, GC, scheduler, and cross compilation. Since decision 0215 the toolchain is written in Xo (compiler/); the Go backend (Go source, the Go toolchain) remains one of its backends. - [P2] Own runtime: deterministic scheduler, full record/replay, task tree.
- [P3] Own backend and content addressed code store.
The language semantics do not change between phases. Only implementation quality and tooling depth change.
[later] marks a feature this draft specifies but the toolchain does not
implement yet, in a section otherwise implemented. The spec audit
(bench/results/spec-audit-2026-10-09.md) lists every such gap.
Experimental sections
None. The five rules that were experimental through draft 0.6 (value
semantics, required uses on pub functions, no module declaration, block
scoped defer, enforced naming with pub) were accepted on 2026-10-08 from
the benchmark evidence (decisions 0003, 0004, 0006, 0009, 0010).
1. Lexical structure [P1]
1.1 Source files
- Encoding: UTF-8. Extension:
.xo. - A module is a directory. All
.xofiles in a directory belong to the same module and share one namespace. There is no module declaration in the file: the directory path is the module identity. usedeclarations are per file, as in Go.- Files ending in
_test.xocontain only tests and test helpers.
1.2 Comments
// line comment
/// doc comment, attaches to the next declaration (Markdown)
There are no block comments. Fenced xo code blocks inside doc comments are
rendered by xo doc; compiling and running them as examples under xo test
is planned ([P2]).
1.3 Statement termination
Newlines terminate statements, using Go’s rule: a newline ends a statement if
the last token on the line is an identifier, literal, ), ], }, ?, or one
of return break continue. Semicolons are not written by programmers and are
removed by xo fmt.
Exception: a line whose first token is . continues the previous line, so
method chains can be split:
http.json(429, {"error": "rate limited"})
.with_header("Retry-After", "${secs}")
A line whose first token is a declaration clause (uses, requires,
ensures, invariant, derive), the -> of a result type, else after a
requires, or the { that opens a function body, also continues the
declaration above it.
A line cannot start with a binary operator: after a > 0 at the end of a
line, || b > 0 on the next would begin a new statement. End the first
line with the operator instead (a > 0 ||, then b > 0). A line
starting with ||, &&, ??, |, ^, +, /, %, <<, >>, a
comparison, or a spaced * or & is error XO0178, whose fix moves the
operator up (decision 0136). -, !, ~, and .. start expressions,
so a line starting with them is a new statement.
Consequences: } else { and } else if must be on the same line as the
closing brace. A list that spans lines needs a trailing comma after the last
element. Trailing commas are allowed in every comma separated list.
1.4 Keywords (27)
as break const continue defer else ensures
enum fn for if in interface invariant
let match pub requires return select struct
test type use uses var while
Predeclared identifiers (cannot be redefined at top level):
- Values and functions:
true false self target fault dbg - Variants:
Ok Err(ofResult),Some None(ofOption), usable without a type prefix everywhere. - Types: those in section 2.1 and the prelude interfaces in
spec/std.md. - In test blocks only:
os,expect,testing.
Contextual words (meaningful only in one position, usable as identifiers
elsewhere): derive (after a type body), from (in an enum variant),
with (postfix struct update), after (in a select arm), seed (after a
test name), result and old (inside ensures), is (binary operator
position), bound (after a loop header’s expression, 3.5), realtime (in
a declaration’s uses clause, 6.5), scope (the scope expression, written
scope NAME {, 7.1; anywhere else scope is a name, decision 0497).
To keep parsing unambiguous, an unparenthesized struct literal may not appear
in an if, while, for, match, requires, or ensures expression (the
same rule as Go). Write if (p == Point{x: 0, y: 0}) { ... }.
1.5 Identifiers and naming
- Identifiers:
[A-Za-z_][A-Za-z0-9_]*. - Naming is enforced by the compiler (error
XO0101), not left to linters:- Types, enum variants, interfaces:
UpperCamel. - Functions, methods, variables, fields, modules:
snake_case. - Constants:
UPPER_SNAKE. - Effect variables:
snake_case.
- Types, enum variants, interfaces:
- Exported names are marked with
pub, not by capitalization.
1.6 Literals
42 1_000_000 0xff 0b1010 0o755 // Int
3.14 1e-9 // Float
true false // Bool
'a' '\n' '\u{1F600}' // Rune
"hello ${name}, you have ${count + 1} items" // Str with interpolation
"GET /users/{id}" "{\"a\": 1}" // braces are literal
"price: \$5" // \$ is a literal $ before {
r"raw: no escapes, no interpolation \d+"
r#"raw, may contain "quotes": {"a": 1}"#
r"""
raw multi line: no escapes, no ${interpolation}, indentation removed
"""
"""
multi line string, common leading indentation is removed
"""
b"raw bytes\x00" // Bytes, escapes but no interpolation
5s 250ms 10us 2m 1h // Duration
[1, 2, 3] [] // List
{"a": 1, "b": 2} {} // Map
#{1, 2, 3} #{} // Set
${expr}interpolates any expression whose type implementsDisplay.Secret[T]values render as<redacted>.$not followed by{is literal.${expr:?}interpolates the Debug text ofexprinstead (decision 0296), the textexpr.debug()returns:"${xs:?}"is[1, 2],"${r:?}"isErr(NotFound),"${name:?}"is"ann"with its quotes. Every type implementsDebug(std.md 1), so any expression may be formatted this way; a type with no Debug text isXO0404("Tdoes not implementDebug, so:?cannot format it").:?is the only format spec: it follows the whole expression, so${a + b:?}formats the sum, and any other text after the expression (${x:.2}) isXO0160.- Raw strings
r"..."have no escapes and no interpolation.r#"..."#may also contain", which makes JSON fixtures easy to write. - A raw multi-line string
r"""..."""(decision 0320) has no escapes and no interpolation either, and spans lines: its common leading indentation is removed as for"""(a first line holding only the opening quotes and a last line holding only the closing ones are dropped), and CR LF reads as LF.r#"""..."""#, with any number of#, is closed only by"""and as many#, so it may contain""". - An integer literal takes the integer type expected in context (
Int32,UInt8, …), defaulting toInt. It never becomes aFloat; write2.0. Its value must fit that type: errorXO0421otherwise (300as anInt8, a negative literal as an unsigned type). A minus written on the literal makes a negative literal, so a type’s minimum is-128or-9223372036854775808; a parenthesized literal,-(128), must fit alone. - A rune literal is a
Rune, except where an integer type is expected (an annotation, a parameter, the other operand of an operator, a pattern on an integer, aconstof an integer type): there it is that type’s value of its code point, so byte level code readsb[i] == '"'andmatch c { 'a'..='z' => ... }on aUInt8(decision 0079). The code point must fit the type;Int8andUInt8take only ASCII ('é'is two bytes in UTF-8, so it is never one byte): errorXO0401otherwise. - Duration literals are an integer followed by
ns,us,ms,s,m, orh.1.5sis not a literal; write1500ms. - Escapes in
StrandBytes:\n \t \r \0 \\ \" \' \$ \xHH \u{...}. InStr,\xHHis at most\x7f. {}in expression position is always an emptyMap. An empty block used as a value is written().
2. Types [P1]
2.1 Builtin types
| Type | Description |
|---|---|
Bool | true or false |
Int | 64 bit signed. Overflow faults. |
Int8 Int16 Int32 Int64 | Sized signed integers. Overflow faults. |
UInt8 UInt16 UInt32 UInt64 | Sized unsigned integers. Overflow faults. |
Float | 64 bit IEEE 754. Float32 also exists. Converting an integer to Float or Float32 rounds once to the nearest value, ties to even, as Go does. |
Rune | Unicode scalar value |
Str | Immutable UTF-8 text |
Bytes | Immutable byte sequence |
Duration, Time | Monotonic duration and wall clock instant |
List[T] | Immutable persistent vector |
Map[K, V] | Immutable persistent hash map, insertion ordered |
Set[T] | Immutable persistent hash set, insertion ordered |
Buf[T] | Mutable, move only growable buffer (section 5.3) |
Chan[T] | Channel handle (section 7) |
Mutex[T], Atomic[T] | Shared mutable state (section 5.4) |
Secret[T] | Value that is redacted in every output path |
Option[T], written T? | Optional (section 2.5) |
Result[T, E] | Success or failure value (section 2.6) |
(A, B) | Tuple |
fn(A) -> B ! E uses fx | Function type (section 6.2) |
() | Unit |
Never | The type with no values. Type of return, break, continue, fault(...), proc.exit(...), and infinite loops. Converts to every type. |
Representation note (2026-10-26, not a language rule): with list packing
(decision 0369, Accepted 2026-10-25 and on by default; --pack-lists=off
turns it off) a List[T] element on the native arm64 and amd64 backends
and on LLVM takes the width of T for Int8, UInt8, Int16, UInt16, Int32,
UInt32, Rune and Float32 (1, 2 or 4 bytes), 8 bytes for Int,
UInt64, Float and Duration, and 8 bytes a word for a larger T (a
Str is 16); List[Bool] is 1 byte an element and Bytes is packed. A
List[UInt8] of a million elements is 1 MB, as a Bytes of them is. The
Go backend stores Go’s own sized types.
A Str is always valid UTF-8: literals are, operations on Str keep it, and
std makes outside bytes valid where they become a Str (std.md 0, decision
0259), so slicing faults only at an offset inside a sequence of valid text.
There are no implicit numeric conversions, except that an index or slice bound
of any integer type is widened to Int (3.6). Conversions are calls on the target
type: Float(i), Int(f) (truncates toward zero, faults on NaN or out of
range), Int32(x) (faults out of range), Int32.try(x) -> Int32?. Parsing
text is Int.parse(s) -> Int?, Float.parse(s) -> Float?.
A Rune is not a number, but converts both ways with an integer type
(decision 0079): Int(r) (and every sized integer type, faulting out of
range: UInt8('é') faults) is its code point; Rune(n) from any integer
type is the character with code point n and faults when n is not a
Unicode scalar value (negative, a surrogate 0xd800 to 0xdfff, or above
0x10ffff); Rune.try(n) -> Rune? is None there instead. A Rune
does not convert to Float (XO0409, with a note pointing at Int(r)).
Float comparison (decision 0053; the same for Float32):
==and!=are IEEE 754: NaN is not equal to anything, itself included, and-0.0 == 0.0. Structural==on structs, tuples, enums, options, lists, and recursive (boxed) values compares Float fields this way, so a value holding a NaN is not equal to itself (x == xis false).<,<=,>,>=use the total order ofOrd(std.md 1): every NaN sorts after+Infand equals every other NaN in the order, and-0.0and0.0are equal in the order. SoNaN < NaNis false,NaN <= NaNis true,NaN > xis true for every non NaNx,-0.0 < 0.0is false, and!(a < b)is alwaysa >= b. Because the two families differ,a <= b && a >= bdoes not implya == b(both NaN).- Unary
-flips the sign of every Float, zero included:-0.0is negative zero.
A NaN’s bits (to_bits(), std.md 1) are the CPU’s, not a language promise
(decision 0361): an operation that makes a NaN from operands that are not
(0.0 / 0.0, inf - inf) gives the architecture’s default NaN (positive
on arm64, negative on x86_64), and an operation on a NaN operand keeps that
operand’s payload on arm64 and x86_64. RISC-V’s F and D extensions never
propagate a payload: every NaN that arithmetic returns there
(linux/riscv64) is the canonical NaN, 0x7FC00000 as a Float32 and
0x7FF8000000000000 as a Float. Conversions between Float and
Float32, and Float32.from_bits and to_bits, keep a payload on every
target.
Duration may be negative (d.abs() gives the magnitude).
Operators on Duration and Time:
| Expression | Type |
|---|---|
d1 + d2, d1 - d2 | Duration |
d * n, n * d, d / n (n: Int) | Duration |
d1 / d2 | Int (truncated) |
t + d, t - d | Time |
t1 - t2 | Duration |
| comparisons | Bool (both are Ord) |
Methods (d.seconds() -> Float, d.scale(f: Float) -> Duration, and more) are
listed in spec/std.md.
2.2 Structs
pub struct User {
pub id: Int
pub name: Str
pub email: Str?
created: Time
}
Construction names every field:
User{id: 1, name: "a", email: None, created: now}. Type arguments of a generic struct are inferred from the fields or the expected type:Job{id: 1, input: "x"}is aJob[Str]. Fields with a declared default may be omitted:struct Config { port: Int = 8080 }, soConfig{}is valid.Update syntax creates a modified copy:
u with {name: "b"}.Structs are values. Assignment copies (cheaply: fields are shared because all builtin collections are immutable).
Fields may be separated by newlines or commas.
A field may name its key on the wire between its name and its type (decision 0277):
kind as "type": Str,pub api_version as "apiVersion": Str,created as "Created": Int = 0. In Xo code the field is stillkind; the derives that map fields to outside names use the wire name:Jsonkeys (and TOML keys, which std/toml decodes through JSON) andSqlRowcolumns (2.9). The name is a plain string literal, not empty (XO0412).The wire string may carry Go’s tag options after a comma (decision 0309). The one option is
omitempty:email as "email,omitempty": Str?, oras ",omitempty"to keep the field’s default key (its name, or whatcase:makes of it).derive Json’s encoder leaves such a field out when its value is empty as Go defines it:None,false, a zero number,"", or an emptyList,Map,Set, orBytes. A struct or an enum value is never empty. Decoding is unchanged: a missing key takes the field’s default. Another option, or a repeated one, isXO0422. Unlike Go,as "-"is the key-, not a skipped field.The option
string(decision 0555),n as "n,omitempty,string": Int?oras ",string", makesderive Jsonwrite a scalar field as a JSON string holding the value’s literal (5as"5",trueas"true", aStrquoted twice as Go does) and read it back the same way: the JSON value must be a string ornull, and its text exactly a JSON literal of the field’s type (an unquoted number is an error, as in Go).Noneisnull;omitemptyis decided before quoting. It applies toBool, the integers,Float,Float32,Strand anOptionof one; on any other field type it isXO0437(Go ignores it there).A field may override the shared wire name for one format (decision 0315), after its name or its
asstring:json "...",sql "...",xml "..."(json,sql, andxmlare contextual words, not keywords).- The override replaces the name and the options for that format only.
- Each format’s name is its own string, else the
asstring, else the field’s name under its derive’scase:rule. - Examples:
created_at as "createdAt" sql "created": Int?has the JSON keycreatedAtand the columncreated;note json "memo,omitempty" sql "note": Str?names each format alone. - A
jsonstring takesomitemptyandstring. Asqlstring takes no options (XO0422for one). Anxmlstring is Go’s tag text, forderive Xml(decision 0315; below, 2.9). - A format given twice on a field is
XO0423. A string for a format the struct does not derive isXO0424.
derive Json(case: camel)(alsosnake,pascal,kebab, and the same argument onderive SqlRow) converts every field without its own wire name:api_versionisapiVersionunder camel,ApiVersionunder pascal,api-versionunder kebab; a field’sas "key"always wins. An unknown argument or case isXO0413; two fields with one key under a derive the struct has areXO0411; a wire name on a struct with neither derive is the warningXO0414.derive Json(match: fold)(decision 0550;match: exact, the default, may be written) decodes keys as Go’s encoding/json does, on a struct or on an enum for its variants’ fields: each member, in document order, selects the field whose key (its name,as "key"orcase:spelling) equals it, else the first declared field whose key folds equal to it (Go’s foldName: each rune throughunicode.ToLowerthenunicode.ToUpper, so"MAJOR"and"major"selectMajor, the Kelvin sign selectsk, andßstaysß); the last member that selects a field wins. Its errors come in Go’s order: every selected member decodes, and the error is the first in document order, a via type’s (Go’s UnmarshalJSON) before any type error, a missing field’s after both. The option is per type: a field’s own struct type folds only when it says so. Encoding is unchanged. An unknownmatch:value isXO0413.struct Version { major: Int = 0 minor: Int = 0 } derive Json(case: pascal, match: fold) // {"major": 1, "MINOR": 2} decodes to Version{major: 1, minor: 2}
2.3 Enums (sum types)
pub enum LoadErr {
NotFound(id: Int)
Db(msg: Str)
Timeout
}
- Variants may carry named fields. Construction uses names:
LoadErr.NotFound(id: 42). A single field variant may also be constructed positionally:LoadErr.NotFound(42). - The enum prefix may be omitted when the expected type is known (in a
matcharm, an argument, a return, a typed binding, or nested inside one of those):return Err(NotFound(id: 42)). - Enums from other modules are qualified with the module:
task.Timed.TimedOut,http.ClientErr.Canceled. Type arguments of generic enums are inferred:task.Timed.Failed(e). - Enums are closed.
matchmust be exhaustive (errorXO0301). Variants with a field of typeNevercannot be constructed and may be omitted from amatch.
Valued enums (decision 0269). An enum whose variants are all field-less may
declare a value type, Int or Str, after its name, and each variant may
give its value:
enum Weekday: Int { Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun }
enum Level: Str { Debug = "debug", Info = "info", Warn = "warn" }
enum Color: Str { Red, Green, Blue } // "Red", "Green", "Blue"
A value is a constant expression of the value type (a literal, a
const, arithmetic on them forInt). A variant without one is the previous variant’s value plus one (the first is 0) forInt, and its own name forStr. Two variants with one value areXO0428. A value type other thanIntorStr, a value on an enum that names no value type, a variant with fields, type parameters, or a value that is not a constant of the value type areXO0429.e.value()is the variant’s value.E.from(v)isE?: the variant with that value, orNone.E.all()isList[E], the variants in declaration order (a list built per call in this implementation).Catch-all (decision 0493). The last variant may keep the values no other variant names, for a set a server owns and grows (AWS adds enum values after a client is built):
enum StorageClass: Str { Standard = "STANDARD" Glacier = "GLACIER" Unknown(value: Str) } derive JsonIt has one field of the value type and no value; any other variant with fields in a valued enum is
XO0434.E.from(v)is thenE, notE?: the variant with that value, elseUnknown(v).E.known(v)is the strict lookup (E?,Nonefor an unlisted value).value()of the catch-all is its field,all()leaves it out, andderive Jsonwrites it as its value and reads a value no variant has as it, so decoding never fails on an unlisted value (a value of the wrong JSON type still does). Amatchneeds an arm for it. Built from a constant that a named variant has (StorageClass.Unknown("STANDARD")) it isXO0435, since it would be a second spelling of that variant, unequal to it; built from a run time value it is thexo vetwarningXO0917(useE.from(v)).The enum stays a closed sum type:
matchis exhaustive by variant, and equality, hashing, andOrdare by variant in declaration order, not by value. Display prints the variant name.derive Jsonwrites and reads the value:Weekday.Monis1,Level.Warnis"warn". A value no variant has is a decode error that names the enum and the value, unless the enum has a catch-all (above). An enum without a value type keeps the encoding"Variant".Variant names on the wire (decision 0478):
derive Json(case: snake)on an enum (alsocamel,pascal,kebab) converts every variant’s name, split into words at its capitals (JoinRoomisjoin_room,HTTPErrorhttp_error), and its fields’ keys as 2.2’s rule does for a struct. A variant may name its own,Chat as "chat.message"(body: Str), which always wins. Decoding reads only the wire names. An unknown argument or case isXO0413, an empty nameXO0412, two variants with one nameXO0411, and a variant wire name on an enum withoutderive Jsonthe warningXO0414.Tagged enums (decision 0478):
derive Json(tag: "type")writes a variant as one object, its wire name under the tag and its fields beside it:Say(room: "r", text: "hi")is{"type":"say","room":"r","text":"hi"}(withcase: snake), a unit variant{"type":"ping"}, and a variant holding one struct (from Move) has that struct’s fields beside the tag. Addingcontent: "data"puts the payload under its own key instead, as the external form writes it:{"type":"say","data":{"room":"r","text":"hi"}}; a unit variant has no content key. Decoding finds the tag anywhere in the object and reads the fields with the struct rules (unknown keys ignored,T?and defaults may be missing); a missing tag, a tag that is not a string and an unknown name areDecodeErrs. A variant whose payload is not an object (Count(from Int)) withoutcontent:isXO0431; a field, or a wrapped struct’s field, with the tag’s key, and a content key equal to the tag, areXO0411;content:withouttag:, a tag that is not a string, andtag:on a valued enum areXO0413.A type’s own JSON form (decision 0478): a struct, enum or newtype without type parameters may travel as another Json type P,
derive Json(via: P, to: f, from: g), wherefisfn(T) -> Pandgisfn(P) -> T ! E(orfn(P) -> T), both non generic functions of T’s module, and E implements Display. Encoding a T encodesf(v); decoding decodes a P at the same path, then callsg, and anErr(e)is aDecodeErrat that path whose message ise’s Display text (at $.legs[1].amount: invalid amount "12.3.4"). The type then works wherever a Json type does (fields,List,Map,T?). Ato:orfrom:naming no such function isXO0432, a mistyped one, or an E without Display,XO0433;via:without both functions, beside any otherderive Jsonargument, or on a generic type isXO0413.
struct Money {
minor: Int
} derive Json(via: Str, to: money_text, from: parse_money)
fn money_text(m: Money) -> Str { ... } // "12.34"
fn parse_money(s: Str) -> Money ! MoneyErr { ... } // MoneyErr: Display
2.4 Interfaces
pub interface Store {
fn get(self, id: Int) -> User ! LoadErr uses net
fn put(self, u: User) -> () ! LoadErr uses net
}
- Satisfied structurally and implicitly, as in Go.
- Interfaces may be used as types (dynamic dispatch) or as generic constraints.
Neversatisfies every interface.- A type satisfies an interface through its methods whether or not they are
pub. Calling a nonpubmethod by name from another module is still an error (XO0605), except a method that implements a method of a prelude interface with its signature (displayofDisplayorError,debugofDebug), which is callable by name wherever the type is (decision 0496); other interfaces’ methods needpub. - A
debugordisplaymethod with another signature (parameters, an error, another result: a generated client’sdebug(project, zone, ...)) is an ordinary method and implements neither interface:${x:?},${x}, a frame and a genericT: Debugcall give the type’s automatic or derived text, and the method is called by name as any other. - A method whose parameter type leaves its effect arguments out (
next: Next, an implicit effect variable, section 6.2) satisfies an interface method whose parameter type writes them (next: Next[fx]): the variable takes the interface’s argument, as a call instantiates it from its argument, and the method’s effects are checked against the interface’suseswith it (decision 0540). - Every derivable name (
Display,Ord,Json, …) is also an interface and may be used as a constraint:fn reply[T: Json](v: T).
2.5 Optionals
T?isOption[T]: eitherSome(v)orNone. There is no nil, null, or zero value pointer.- A plain
Tis accepted whereT?is expected and is wrapped inSomeautomatically (one of the three implicit conversions, section 2.10). - Unwrapping:
if let Some(e) = user.email { send(e) } else { log.warn("no email") } let e = user.email ?? "unknown@example.com" let e = user.email.or_err(LoadErr.NotFound(id: user.id))? let e = user.email ?? return None let n = fields.get(k) ?? continue- The right side of
??may bereturn v,break, orcontinue(decision 0321): an expression of typeNeverthat leaves when the left side isNone, solet x = opt ?? return ris the four linematch opt { Some(v) => v None => return r }. Areturnis checked against the function’s result as a statementreturnis, andbreakandcontinueagainst an enclosing loop (XO0607). It takes only an Option on the left (XO0406); the Result form is below (2.6).xo vetsuggests it for the four linematch(XO0906), on an Option and on a Result.if let e = opt(withoutSome) is also accepted as shorthand forif let Some(e) = opt.
- The right side of
- In a function that returns
U?,opt?yields the value or returnsNone:
Usingfn retry_after(resp: http.Response) -> Duration? { let secs = Int.parse(resp.header("Retry-After")?.trim())? 1s * secs }?on anOptionin a function that returns aResultis errorXO0204, with a fix that inserts.or_err(...). A test body is the exception (9.2): thereopt?fails the test.
2.6 Results, errors, and explicit failure
A function that can fail declares its error type after
!:fn load(id: Int) -> User ! LoadErr. Such a function returnsResult[User, LoadErr]to its caller.!with no type means! Error, the builtin open error interface.fn main(os: Os) !isfn main(os: Os) -> () ! Error.T ! Neveris the same type asT: a function that cannot fail.Returning. In a function declared
-> T ! E, a returned value (a tail expression orreturn x) may be:- a
T, which means success, or Err(e)withe: E, which means failure, or- any
Result[T, E]value, returned as is.
fn parse_port(s: Str) -> Int ! ConfigErr { let n = Int.parse(s).or_err(ConfigErr.NotANumber(s))? if n < 1 || n > 65535 { return Err(ConfigErr.OutOfRange(n)) } n }If
Tis itself aResult, success must be writtenOk(x)explicitly (errorXO0203otherwise).- a
r ?? e => bodyunwraps a Result and names its error (decision 0321):let v = fetch(id) ?? e => return Err(LoadErr.Fetch(e)) let n = parse(s) ?? _ => continue let w = parse(s) ?? e => fallback(e)It is
match r { Ok(v) => v Err(e) => body }: the value is the success value, andbody(an expression, a block, orreturn,break,continue) runs withebound to the error and either gives a value of the success type or leaves._discards the error; an unusedeisXO0110as in any match arm. The left side must be a Result (XO0406), andr ?? defaultwith no arm on a Result staysXO0406, so an error is never dropped silently.xo vetsuggests it formatch r { Ok(v) => v Err(e) => return w }and thebreakandcontinueforms (XO0906).Each arm of a tail
iformatchis in return position, so arms may mixTvalues andErr(e):match x { 0 => 1 _ => Err("no") }.Propagating.
expr?on aResult[T, E2]yields theTor returns the error from the enclosing function.E2must convert to the enclosing error typeE:E2isE, orEisErrorandE2implementsDisplay, orEhas afrom E2variant.
from variants wrap other error types:
enum ApiErr { BadRequest(msg: Str) Load(from LoadErr) // `?` on a `! LoadErr` call wraps into ApiErr.Load }A
fromvariant has one positional field: construct withApiErr.Load(LoadErr.Timeout), match withLoad(inner).Mapping.
r.map_err(f)converts the error inline:json.decode[User](b).map_err(fn(e) { ApiErr.BadRequest(msg: "${e}") })?.Handling is mandatory. A
Resultvalue that is never used (not propagated with?, matched, passed, or returned) is errorXO0201. AResultbound to a name that is never used is alsoXO0201, whatever the name (including_x).Discarding needs a reason.
let _ = expron aResultis errorXO0206. Writeexpr.ignore_err("why this failure does not matter"), which yieldsT?and records the reason, so every discarded error is searchable and reviewable:let _ = dst.remove(tmp).ignore_err("best effort temp file cleanup") let nick = nickname_field(fields).ignore_err("nickname is optional") ?? ""r.ok()remains for when failure simply means “no value”.A closure whose tail is a
Resultis a failing closure; theResultis returned as is. A closure declared-> Twith no!cannot fail.A non
Resultvalue may be discarded as an expression statement, except the value of a call that only computes it: one that performs no effect (section 6), mutates novarreceiver or argument, and reaches no handle, interface, or function value through its receiver or arguments.xs.reverse()ors.trim()as a statement is errorXO0209(values are not changed in place); its fix assigns the result back (xs = xs.reverse()). Writelet _ = f()to discard such a result on purpose. Adeferstatement’s call is not reported (it runs for what it does at exit, or to fault there).
2.7 Generics
pub fn map[T, U](xs: List[T], f: fn(T) -> U) -> List[U] { ... }
pub fn largest[T: Ord](a: T, b: T) -> T { if a > b { a } else { b } }
- Square brackets, Go style. Constraints are interfaces. Effect variables are declared in the same list (section 6.2).
- Explicit type arguments at a call:
json.decode[User](body). - Monomorphized at compile time. Type arguments are inferred at call sites when
unambiguous; otherwise error
XO0402lists the candidates. - No higher kinded types, no specialization, no variadic generics.
2.8 Type aliases and newtypes
type UserId = Int // alias, interchangeable with Int
type Email struct(Str) // newtype, distinct, construct with Email("x")
type Handler = fn(http.Request) -> http.Response ! Error uses net
A newtype has the equality, hashing, and JSON of its underlying value
(decision 0097): Email("a@x.io") encodes as "a@x.io", and a newtype
field of a derive Json struct needs no derive of its own (a newtype
whose underlying type is Json is Json):
e.0is the underlying value, typed with the newtype’s type arguments (Wrap[Int]’s.0isInt); on avarit is assignable like a tuple field. Any other index isXO0601.- The pattern
Email(p)(mod.Email(p)for another module’s newtype) matches whenpmatchese.0; it is irrefutable whenpis, solet Email(s) = edestructures.Email(..)matches any value. Without parentheses, with other than one positional pattern, or against another type it isXO0302. When the value is an enum with a variant of the same name, the variant is meant. - Construction and reading are open wherever the type is visible; a type
that must guard its value is a struct with a non
pubfield. derive Ordafter the declaration (type Name struct(Str) derive Ord) orders the newtype by its value:<, sorting,min,max, andT: Ordcode seeName("a") < Name("b")as"a" < "b". The value’s type must beOrd(elseXO0404). A newtype is not ordered without it, andOrdis the only derive it takes (XO0404for any other: its equality, hashing, and JSON are its value’s already; decision 0390), apart fromderive Json(via: P, to: f, from: g), which gives it a JSON form of its own (2.3, decision 0478).
type Email struct(Str)
fn domain(e: Email) -> Str {
let Email(s) = e
s.split("@").last() ?? ""
}
fn is_blank(e: Email) -> Bool { e.0.trim() == "" }
2.9 Derived behavior
Every type automatically implements:
Debug: structural printing used by the debugger, error frames, anddbg().EqandHashwhen all fields do.
A type is comparable when it implements Eq: every field, enum payload,
tuple element, and element or type argument is comparable. Function values
and handles are not (decision 0112): Chan, Mutex, Atomic, Scope,
Task, Listener, Conn, ServerConn, File, FileLock, Child, task.Group, task.Semaphore, task.Once,
http.Router, http.Server, http.Client, http.BodyWriter,
http.TlsCert, sql.Db, sql.Tx, and the std/testing fakes
(FakeNet, FakeClock, MemFs, FakeEnv, FakeStdio, FakeProc).
A value that holds one, directly or in a field, payload, tuple, or
collection, cannot be compared with == or !=, cannot be a Map key
or Set element, and its type cannot derive Eq, Hash, or Ord
(XO0404, with a note naming the field that holds the handle). Compare
an identifying field instead (a.id == b.id). Interface values compare
through their dynamic value and stay comparable; one whose dynamic value
holds a handle or a function is equal to nothing, itself included (==
is false, as for a function value), on every backend; the opaque Go values of
use go bindings keep Go’s equality (4.4). Automatic Debug is
unaffected.
Opt in with derive on the declaration:
pub struct User { ... } derive Display, Ord, Json, OpenApi
List,MapandSetimplementDisplaywhen their element types do, with the same text asDebug:"${[1, 2]}"is[1, 2],"${m}"is{"a": 1},"${s}"is#{"x"}, in iteration order, strings quoted (decision 0525).OptionandResultdo not (unwrap with??).Derived
Displayprints the same text asDebug:NotFound(id: 42),User{id: 1, name: "a"}. ImplementDisplayby hand (fn (e: ApiErr) display() -> Str) for user facing text. Std’s error enums implementDisplayby hand and print plain messages (PATH: no such file or directory,connection refused; decision 0358); theirDebugkeeps the variant form.Json,OpenApi, andProtoderives generate codecs and schemas from the same declaration so wire formats and docs cannot drift. JSON rules are inspec/std.md. [after 1.0]OpenApiis planned for after 1.0 (owner, 2026-10-09; additive, so not a 1.0 blocker): the derive is reserved, accepted only when every field derives it too, and nothing is generated.derive Proto(decision 0530, accepted 2026-11-06) generates the Protocol Buffers wire codec, read throughprotobuf.marshalandprotobuf.unmarshal. Every field carries its number as aprototag,name proto "N": T, with the optionszigzag(sint32, sint64) andfixed(fixed and sfixed types) after a comma. A field of type Int, Int32, UInt32, UInt64, Float, Float32, Bool, Str, Bytes, an Int valued enum of the same file, or a struct that derives Proto maps to the scalar or message of that name; an Option is a field with explicit presence, a List is repeated (numbers and Bool packed, the reader accepts both forms), and a Map keyed by Int, Str or Bool is a map field. An enum with one payload field per variant (Circle as "2"(r: Int)) is a oneof, held in a field taggedproto "oneof"of typeEnum?. OneBytesfield taggedproto "unknown"keeps the fields the reader did not know. Output is wire identical to Go’sproto.Marshalwith deterministic map order; a wire type that does not match a field is read as unknown, as in Go.XO0422is a missing, repeated or reserved number or an unknown option,XO0425a field type the derive cannot map.SqlRow(structs only) generates a decoder from a std/sql row: each field is read from the column of the same name, or of its wire name orcase:rule (2.2;spec/std.md10.4).Xml(structs only, no type parameters) gives the struct Go’s encoding/xml Marshal and Unmarshal throughxml.encode_value(v, indent)andxml.decode[T](text)(spec/std.md34, decision 0315).- A field’s tag is its
xmlstring, else itsasstring, else its name, in Go’s tag text:name,name,attr,,chardata,a>b>c,,omitempty, and-.innerxmlandcommentare not yet supported (XO0426). - Field types are Str, Int, Float, Bool, a struct that derives Xml,
each alone, as an Option, or in a List (
XO0425for another type, a struct with type parameters, or a struct that does not derive Xml). - The expansion is ordinary Xo: the checker parses generated functions
(
xml_write__T,xml_zero__T,xml_merge__T,xml_from_tree__T,xml_encode__T,xml_decode__T) into the module as a file of its own, so every backend compiles the same code. A diagnostic in them is reported at the field. They are not declarations of the program:xo symbols,def,refs,doc, and the formatter leave them out. - A call of
xml.encode_valueorxml.decodeis rewritten to the generated function of its type; a type parameter or a struct that does not derive Xml isXO0427orXO0404.
- A field’s tag is its
Yaml(structs only, no type parameters; decision 0512, Accepted 2026-11-05) gives the struct gopkg.in/yaml.v3’s decoding and encoding throughyaml.decode[T],yaml.decode_all[T],yaml.encode_value[T]andyaml.encode_all[T](spec/std.md 63). A field’s key is itsyamlstring, else itsasstring, else its name; the options after a comma areomitempty,flowandinline, and the name-leaves the field out. Field types are Str, Int, Float, Bool, Duration, Bytes, a struct that derives Yaml, an Option, a List, or a Map[Str, V] of those (XO0425for another type). The expansion is ordinary Xo as forXml(yaml_zero__T,yaml_merge__T,yaml_set__T,yaml_known__T,yaml_from_node__T,yaml_decode__T,yaml_decode_all__T,yaml_write__T,yaml_fields__T,yaml_encode__T,yaml_encode_all__Tand oneyaml_dec__TYPEandyaml_enc__TYPEa field type), and a call of one of the four functions is rewritten to the generated function.Cbor(structs, and plain enums without type parameters; decision 0527) gives the struct fxamacker/cbor/v2’s typed encoding and decoding throughcbor.marshal[T],cbor.unmarshal[T]andcbor.unmarshal_prefix[T](spec/std.md 50). A field’s key is itscborstring, else itsasstring, else its name underderive Cbor(case: snake | camel | pascal | kebab)(as forJson, 2.2), else its name; the options after a comma areomitempty,omitzero,keyasintandtoarray(on the first field: the struct is an array), and the name-leaves the field out (XO0422for another option). Field types are Str, Int, Float, Bool, Bytes, Time, Duration, a cbor.Value, a struct that derives Cbor, an Option, a List, or a Map[Str, V] of those (XO0425for another type). The expansion is ordinary Xo as forYaml(cbor_zero__T,cbor_rd__T,cbor_wr__T,cbor_marshal__T,cbor_unmarshal__T,cbor_unmarshal_prefix__Tand onecbor_rd__TYPEandcbor_wr__TYPEa field type), and a call of one of the three functions is rewritten to the generated function. On an enum a unit variant is the text of its name (as "x"on the variant renames it,derive Cbor(case:)converts it asderive Jsondoes), a variant with fields a one entry map from its name to a map of its fields keyed by field name (a lone unnamedfromfield is the value itself), and a struct field of an enum type uses the same form; an unknown variant isCborErr.Type.
2.10 Implicit conversions
There are exactly four, and each applies only where the target type is already known:
- A
Twhere aT?is expected becomesSome(T). - A value where an interface type is expected (a parameter, a field, a collection element, a return) becomes that interface, if the type implements it. This includes passing a capability fake where the capability interface is expected.
- An error at a
?site converts to the enclosing error type (2.6). - An element of a list literal written as the argument for a
List[go.Any]parameter of ause gofunction (Go’s...any) becomes ago.Any, asgo.any(x)would (4.4, decision 0412); a type with no Go value isXO1106.
An if or match whose type is already known (an annotated let, an
argument, a field, a return) passes that type to each arm, so each arm
converts on its own: let s: Stream = if tls { tls_conn } else { conn }
and let x: Int? = if c { 1 } else { None } check. Without a known
type, conversions are not applied when joining branches: the arms must
already agree (let y = if c { 1 } else { None } is XO0401, branches
have different types). Conversions are not applied to the else value
of requires. Comparing opt == v
wraps v in Some.
Everything else, including all numeric conversions, is explicit.
3. Declarations and statements [P1]
3.1 Bindings
let x = 10 // immutable binding
var total = 0 // mutable binding
total += x
let (q, r) = (7 / 2, 7 % 2) // a pattern binds each name
var (lo, hi) = (0, 10) // every name mutable (decision 0384)
const MAX_USERS = 1000
const DEFAULT = Config{port: 8080}
constmay appear at top level or in a block. A block constant’s initializer must be a compile time value: literals, other constants, struct and enum construction, and collection literals of those (XO0408).- A top-level constant’s initializer may also call functions (decision
0332):
const RFC3339 = time.layout("..."),const CRC = make_table(0xedb88320). Such a constant is computed once per process, at its first read, and shared by every task: a reader that comes while another task computes it waits. The initializer must perform no effect (XO0415), and the value may hold no handle (Mutex,Chan,Atomic,Task, a file;XO0416), so a constant is an immutable value, never a global variable. A fault in the initializer is stored, and every read of the constant, the first and each later one, raises it again. A read of a constant during its own initialization (through a function it calls) faults withXO-F009. - A top-level constant may embed files at build time (decision 0304):
const PAGE: Str = embed("static/index.html")(the file’s text, valid UTF-8),const LOGO: Bytes = embed("logo.png")(its bytes), orconst SITE: embed.Dir = embed("static")(std/embed: every file a path or glob names,*,?,[a-z],**; a directory brings its files except names starting with.or_, unless the pattern starts withall:). The path is one string literal, relative to the directory of the declaring file and inside the module (no absolute path,.., or symbolic link), and the constant declares its type. The constant is a literal of the files’ contents from the check on, so every backend embeds the same bytes, and a change to an embedded file rebuilds what reads it. An embed may hold 64 MiB and a program’s embeds 256 MiB. A module that declares its ownembeduses it. Errors:XO1506(no file, too many, too large),XO1507(outside the module),XO1508(aStrthat is not UTF-8),XO1509(any other use). Anembed.Dir’s keys are those relative paths, soembed("static")holdsstatic/index.html;read,read_text, orcontainson such a constant (or a literal.subof one) with a literal path it does not hold is the warningXO1511, with the key that ends with the path as a fix. A path computed at run time is not checked. - Unused local bindings, local constants, and imports are errors (
XO0110). Not covered: function and closure parameters, names starting with_, and_itself.xo fixrenames an unused binding or local constant to_name(removing it could drop its value’s effects) and removes an unused import.xo check --wipreportsXO0110andXO0209(section 2.6) as warnings, for checking code still being written; a normal check and every build reject them (decision 0293). - Shadowing in the same block is an error. Shadowing in a nested block is allowed.
3.2 Functions
/// Returns the user with the given id.
pub fn fetch_user(db: Db, id: Int) -> User ! LoadErr
uses net
requires id > 0
{
let row = db.query_one("select id, name, email from users where id = $1", id)?
User{id: row.int("id")?, name: row.str("name")?, email: row.str_opt("email")?, created: row.time("created")?}
}
- The last expression of a block is its value.
returnexits early. An empty body{}has type(). - A block whose last item is a statement (an assignment,
let,for,while cond,defer) has type(). while { ... }with nobreakhas typeNever, so it may end a function body of any type (all exits arereturn).- Parameters are immutable unless declared
var(in out, see 3.3). Named arguments are allowed and recommended when a call has more than two parameters of the same type:transfer(from: a, to: b, amt: 5). Positional arguments must come before named ones. - Default parameter values are allowed:
fn listen(addr: Str, backlog: Int = 128). A call through an interface (an interface value or a constrained type parameter) that omits an argument uses the interface method’s default. - No variadic functions. Pass a
ListorMap. - C exports (decision 0574): a top
level
pub fnof the root package with the clauseas c "name"is the C functionnameof a library built withxo build --lib=shared(or--lib=static; the native backends and LLVM):pub fn add(a: Int, b: Int) -> Int as c "geo_add" { a + b }. Its parameters areInt(Cint64_t),Float(double),Bytes(XoBytes {const uint8_t *p; int64_t n}) orStr(XoStr {const char *p; int64_t n}, n bytes of UTF-8, no NUL needed), borrowed for the call: Xo copies the bytes, and aStr’s invalid UTF-8 arrives as U+FFFD per byte of an invalid sequence), or a value of any other type butBooland function types, which C holds as anXoHandle(auint64_tthe library’s table keeps the value under untilxo_release(h); using a released handle, or one holding another type, faults; anOption[T]of such a T is 0 forNone, else T’s handle, while an Option ofInt,Float,StrorBytesis a handle of the Option), at most 8 integer words (aBytestakes 2); its result isInt,Float,BytesorStr(C’sXoBytesorXoStr: a copy in C’s malloc with a NUL past its n bytes, which the caller frees withxo_free(p)), a value held by anXoHandle, or none, with or without an error type: a function that can fail (-> T ! E) takes a last C parameterint32_t *err, set to 0 on success and to 1 on failure (NULL: not set), returns 0 on failure ({NULL, 0}forBytesorStr), and leaves the error’s text (itsDisplay) forxo_last_error(), the calling thread’s last error (a NUL terminated string the thread’s next error replaces). The name is a C identifier outside thexo_names. It is not a method, generic, or a function withvarparameters (XO1518). The library starts the runtime when it is loaded (its constructor,xo_init(argc, argv, envp), which a C caller may also call; a second call does nothing).--libwrites the headerNAME.hbeside the library, and a package withfn mainis not a library. A fault in an export aborts the process. A program build ignores the clause. On windows/amd64 and windows/arm64--lib=sharedwrites a DLL (Xo’s PE linker;-o NAME.dll, headerNAME.h, import libraryNAME.libfor MSVC’s link and lld-link) that exportsxo_init,xo_last_error,xo_release,xo_freeand theas cfunctions by name; it runs nothing while it loads (DllMain runs under the loader lock), so the runtime starts on the first call ofxo_initor of an export, and a thread’s runtime state is released when the thread exits. The header’s types are the C ABI’s own: Win64 passes and returnsXoBytesandXoStrthrough pointers, which a C compiler does from the header.--lib=staticis not yet available for windows.
3.3 Closures
let double = fn(x: Int) -> Int { x * 2 }
xs.map(fn(x) { x * 2 }) // types inferred from context
srv.handle("GET /hi", fn(req) { http.text(200, "hi") })
let load = fn(id: Int) -> User ! LoadErr uses net { store.get(id)? }
- Parameter and return types may be omitted when the expected function type is known.
- Closures capture by value. Mutating a captured
varinside a closure is errorXO0502. To share mutable state with a closure, capture aMutexorAtomichandle. - Creating a closure performs no effects; calling it does.
returninside a closure returns from the closure.- Effects of a closure are inferred from its body unless declared.
- A closure whose body never completes normally (it ends in
while { ... }withoutbreak,fault(...), or anotherNeverexpression) and whose result type nothing else determines has result typeNever, sos.spawn_background(fn() { while { ... } })needs no type argument (Task[Never, E]).
3.4 Methods
fn (u: User) display_name() -> Str { u.name }
pub fn (var a: Account) deposit(amt: Money) requires amt > 0 {
a.balance += amt
}
- A
varreceiver mutates the caller’s binding in place (in out semantics). It can only be called on avarbinding (errorXO0501), avarparameter, or a field of one (st.users.put(k, v)wherestisvar). - Methods may be declared only in the module that declares the type.
3.5 Control flow and patterns
if cond { ... } else if other { ... } else { ... } // also an expression
for x in xs { ... }
for (i, x) in xs.indexed() { ... }
for (k, v) in m { ... }
for job in jobs_chan { ... } // receives until the channel is closed and drained
for b in data { ... } // each byte of a Bytes, as a UInt8
for i in 0..10 { ... } // half open range, 0..=10 is inclusive
for _ in 0..3 { ... }
while cond { ... }
while let Some(job) = queue.pop() { ... } // until the pattern fails
while { ... } // infinite loop
for x in xs bound 64 { ... } // a loop bound: a contract (below, 6.5)
while cond bound 1000 { ... }
match code {
200..=299 => "ok"
429 | 503 => "retry later"
_ => "error"
}
ifwithoutelsehas type().foriterates over a List, Buf, Set, Map (as(k, v)tuples), Chan, Range, Bytes, or a value whose type has anext()method (below). OverBytesit yields each byte as aUInt8, in order (decision 0138); a byte compares with an ASCII rune literal (b >= 'a') and converts withInt(b). Index pairs come fromxs.indexed()on a List; for Bytes, loop over0..data.len()and readdata[i]. AStris not iterable: choose.runes()or.bytes().Iterating a user type (decision 0494). A value whose type has a method
next()with no parameters returningT?may be iterated:for x in v { body }iswhile let Some(x) = v.next() { body }. v is read again for each call when it is a place (a name or a field path), so anext(var self)updates it and it holds the last state after the loop (it must then be avar); any other v is evaluated once. Patterns,bound,breakandcontinuework as in anyfor. Whennext()returnsT? ! E, the loop says where the error goes with?after its pattern:for page? in pages { }iswhile let Some(page) = pages.next()? { }, so an error from any step propagates as?does (2.6). A?that does not matchnext()(left out where it can fail, written where it cannot or on a builtin iteration), or anext()that does not return an Option, isXO0436. To handle the error inside the loop, writeloop { match v.next() { ... } }.var pages = s3.ListObjectsV2Paginator.new(client, req) for page? in pages bound 10000 { for obj in page.contents { os.stdio.println(obj.key ?? "") } }while let pattern = value { ... }computesvaluebefore each iteration and runs the body while it matches the pattern, with the pattern’s names bound in the body; the loop ends at the first value that does not match (decision 0137). Any refutable pattern works (while let Tok.Num(n) = next()), andwhile let v = optis shorthand forwhile let Some(v) = opt, as withif let(2.5).bound Nfollows the value:while let Some(x) = q.pop() bound 64.x is Patternis aBoolexpression that tests a pattern without binding names:expect(r is Err(Timeout)),if resp is Ok(_) && retries < 3.isis a contextual word in operator position (precedence of==), so it combines with&&and||like a comparison.Compound assignment works for
+= -= *= /= %=onvarbindings and their fields. There are no bitwise compound assignments.A value counts as stored again (for XO0520) by any later
push,put,insert,set,add,update, orm[k] = vof it, including later in the same loop.Tuple fields are
t.0,t.1, …matchis an expression. Arms are separated by newlines. An arm body may be an expression, a block, or a single statement such as an assignment (type()):Timeout => last = Some(AttemptErr.Timeout).Labeled loops:
outer: for ... { break outer }.Loop bounds (decision 0133).
bound Nafter the iterated value of aforor the condition of awhilestates that the loop runs at most N iterations; N is a constant Int expression (literals,constnames,+ - * / %), not negative, elseXO1402. Aforover a range with constant ends that is longer than N isXO1402. Otherwise the bound is checked at run time on every backend: starting iteration N + 1 faults withXO-F006(loop ran past its bound of N iterations). Like arequiresclause it is a contract (9.1):xo testfuzzes a function with a bounded loop. Real-time functions (6.5) need a bound on every loop whose count is not constant.while { }takes no bound; writewhile true bound N { }.defer stmtordefer { ... }runs when the enclosing block exits (not the function, unlike Go), in reverse order, including on errors, faults, and cancellation. Values are read when the deferred code runs.Deferred code is shielded from cancellation: inside it, cancellation points do not report cancellation, so cleanup such as removing a temp file works after a timeout. A shielded
deferthat runs longer than 5 seconds of real time faults (XO-F005); the Go backend checks this when the deferred code returns, and not in test worlds, whose clock is virtual.The native backends (
--backend=llvm,--backend=arm64) run deferred code on every way out alike, faults included (decisions 0070, 0085).Deferred code that faults ends there; the deferred code registered before it and that of the blocks around it still runs, and the new fault replaces the one being unwound, if any (the last fault is reported). The task is no longer shielded afterwards. Every backend behaves this way (decision 0085, amended 2026-10-10).
Patterns are used in match, let, var, if let, while let, and for:
| Pattern | Matches |
|---|---|
_ | anything, binds nothing |
x | anything, binds x |
42, "GET", 'a', true | equal literal |
1..=9, 'a'..='z' | value in inclusive range |
p1 | p2 | either (both must bind the same names) |
(a, b) | tuple |
Some(p), None, Ok(p), Err(p) | prelude variants |
Timeout, http.ClientErr.Canceled | unit variant, bare or qualified |
NotFound(p) | variant fields positionally, in declared order |
NotFound(id: p) | variant fields by name; .. ignores the rest: Db(msg: m, ..) |
Variant(..) | variant with any fields |
User{id: p, ..} | struct fields by name |
[], [first, ..], [.., last], [a, .., z] | list shape (.. at most once, anywhere) |
(p), () | grouping, unit |
Patterns nest: Some(Ok(v)), Err(LoadErr.NotFound(id)).
A name in a pattern that is a const of the current module, or mod.NAME
for a pub const of an imported module, matches by equality with the
constant’s value instead of binding (decision 0269):
match status { OK => "done", NOT_FOUND => "missing", _ => "other" }. A
variant of the matched enum, or of the prelude, with that name wins over a
constant. A name spelled like a constant (upper case, digits and
underscores, two or more characters) that is neither a constant nor a
variant is XO0430, so a misspelled constant cannot bind a name that
matches everything. A match over a constant pattern still needs a _ or
binding arm (XO0301).
An unguarded _ (or catch all binding) arm that hides variants of an enum
declared in the same module is warning XO0305: list the variants, so that
adding one later is a compile error at every match. Enums from other modules
may use _, since their owners can add variants. A _ arm that hides at
least 8 variants and more than half of the enum is a default (“these few are
special, the rest are not”, as on a token kind enum) and is not reported; the
warning names at most 8 hidden variants, then how many more (decision 0080).
An UpperCamel name in a pattern always refers to a variant; bindings are
snake_case (1.5), so the two never collide.
let requires an irrefutable pattern (let (a, b) = pair), and so does
var with a pattern (var (a, b) = pair, var Point{x, y} = p;
decision 0384; a list pattern other than [..] can fail, [] not
matching, so it is XO0303 here): every name it binds is mutable,
as one var per name would be.
3.6 Indexing and slicing
xs[i]onList,Bytes: faults when out of range.xs.get(i)returnsT?.- The index (in a read, an assignment, and
get) and the bounds of a slice may be any integer type,Int,Int8..Int64orUInt8..UInt64(decision 0331): it is widened toIntand then bounds-checked. AUInt64aboveInt’s range wraps to a negativeIntand so is out of range (the fault prints the wrapped value). Any other type,RuneandFloatincluded, isXO0401; this is the only implicit numeric conversion (2.1 has none other). Mapcannot be read by index:m[k]in an expression, or an in place change through it (m[k].f = v,m[k] += 1,m[k].push(x)), is errorXO0410, because a missing key is the Map form of a nil dereference. Usem.get(k)(V?),m.get_or_fault(k, "why the key must exist"), orm.update(k, init, fn(var v) { ... }). On avarmap, the whole value assignmentm[k] = vis allowed and meansm.put(k, v).Strcannot be indexed by position (userunes()or slicing).- Ranges slice:
xs[1..],xs[..n],xs[a..b]onList,Bytes, andStr(byte offsets; slicing aStrinside a UTF-8 sequence faults). A range of aStrorBytesthat is not an ordered range of its length faults withslice LO..HI out of range for Str of length N(Bytesin place ofStr), and aStrslice whose ends are not UTF-8 boundaries withslice LO..HI of Str splits a UTF-8 sequence; every backend prints the same text (the corpus of internal/stdtest/testdata/faults). Slices of immutable values are O(1) and share storage: on native targets the result of slicing aStrorBytesis a view of the same buffer (no copy), so a small view keeps its whole buffer alive (as a Go substring does; there is no automatic compaction of a stored view;s.clone()makes an explicit copy when a piece must outlive a large source; std parsers copy the tokens they keep of a large input, andxo vet --costnotes a stored view of a parameter’s text, XO0911). A view is never changed in place: appending to one, or building on one, copies. AStrorBytesvalue holds at most 4294967295 bytes (4 GiB less one); an operation that would make a longer one (concatenation, appending to a builder) faults with “Str or Bytes longer than 4 GiB”, andrepeatwith “strings: Repeat output over 4 GiB”. WebAssembly and the Go backend copy a slice (no views) but keep the same limit and results. A C ABI export of the native runtime (xo_x_names, decision 0207) may not return aStr, because the second word of a view carries its offset: the compiler refuses it (“a C ABI export with aStrresult”). Decision 0330.
3.7 Holes
??? is a typed hole, valid anywhere an expression is expected.
xo checksucceeds with warnings and reports, for each hole, the expected type, the effects in scope, and in scope values or functions that fit (diagnosticXO0900, see section 10).xo buildrejects programs with holes.xo run --holesandxo test --holesallow them and fault if a hole is evaluated (evaluated a hole \???`), on the native backends and the Go backend alike (natively since 2026-10-22, owner;–holes` chose the Go backend before).
Holes let an agent write a type correct skeleton first and fill it in steps.
4. Modules and dependencies [P1, content addressing P3]
4.1 Imports
use std/http
use std/json as j
use github.com/acme/billing/invoice
- The last path segment is the local name unless
asis given, with-replaced by_(use acme/rate-limitbindsrate_limit). A/vNmajor version suffix of a module path is skipped (use github.com/acme/tick/v2bindstick). If the result is still not a valid identifier, or is a keyword,asis required (XO0602). - A path is segments of ASCII letters, digits,
_,-, and.separated by/(PathSeg, section 15). Only the last segment becomes the local name, so dashes elsewhere need nothing (use github.com/xo-lang/xo/lexerbindslexer). A leading or trailing/, an empty segment, or a segment that is exactly.or..isXO0158: import paths are absolute, never relative (use ./lib), and name each package one way, sodenyrules (4.2) see every import. A.inside a segment is fine (example.com,.github,v1.2). - Imports are explicit. There is no dot import or glob import.
- Cyclic package imports are an error (
XO0604): package a importing b and b importing a, whether the two are in one module or in two. Requirement cycles between modules are allowed (4.2). std/internalholds primitives for std’s implementation and the Xo toolchain’s own modules (decision 0214) and is not part of std (std.md does not list it): only std modules and modules whose path isgithub.com/xo-lang/xoor below it may import it. For any other moduleuse std/internalisXO0601(module not found), as the native backends’ intrinsics (native/...) are.- Std-internal names (decision 0319): a
pubitem of a native std implementation module (std/native/M.xo, imported asnative/M) is visible to the other native std modules and to nothing else, since only std modules may importnative/...anduse std/Msees only std/M.xo’s declarations. A std module calls another’s internals this way (std/websocket’s connection hand-off isnative/http’shandoff_response) instead of a registry or a marker value; std.md lists none of these names.
4.2 xo.mod
module github.com/acme/api
edition preview
require github.com/acme/billing v1.4.0
edition names the module’s edition (13); without the line a module is
on the current one. Before 1.0 that is preview, the only edition;
edition 2026, its old name, is an alias that builds and gets the fixable
note XO1315 (decision 0155). Any other name stops the check.
[P1] Dependencies (decision 0086):
require <module path> <version>requires another Xo module. The module path is its git location (github.com/acme/billingis fetched from https://github.com/acme/billing.git; the module is the repository root and its xo.mod declares the same path); the version is a tagvX.Y.Z(-prereleaseallowed). A module is required once.require go <module> <version>pins a Go module foruse goinstead (4.4).- A module may live in a subdirectory of its repository, as in Go:
github.com/acme/tools/cliis the directorycli/of the repositorygithub.com/acme/tools, its versions are the tagscli/vX.Y.Z, and a version is that directory’s tree at the tag. On github.com, gitlab.com, and bitbucket.org the repository is the first three path elements; on other hosts the longest prefix of the path that git answers for is the repository. A directory holding its own xo.mod is never part of the module around it (it is not fetched, hashed, or vendored with it), and the module around it imports its packages only by requiring it, as any other module (XO1306without the requirement). When a subdirectory module’s tree has no file namedLICENSEand the repository root has one at the tag, the root’sLICENSEis part of the version’s tree (its hash, zip and vendored copy), as Go’s module zips (decision 0590). - There is no
replace,exclude, orretract(XO1301); local copies are reached only through a workspace (below). - Minimal version selection: the build uses, for each module, the highest version that any reached xo.mod requires (the main module’s, then those of every required version, transitively). No ranges, no solver; a version changes only when an xo.mod changes. Requirement cycles are allowed and resolved the same way, as in Go (a root module requiring a nested one that requires the root back: each module’s highest required version is selected, the main module’s own path aside).
- Imports resolve inside the main module, the embedded
std, and the selected module versions (the longest module path that prefixes the import path). A module must require every module it imports from: importing a package of a module xo.mod does not require, even one in the build because another module requires it, isXO1306. - Fetching runs git and extracts the tag’s tree (
git archive) into a read only module cache; no code from a module runs at fetch or build setup (no scripts, no hooks). A version that cannot be fetched isXO1302. - Module proxies (decision 0126):
XO_PROXYlists where versions come from, in order: proxy URLs (http://,https://),direct(git), andoff(no fetching); the default isdirect. After a comma the next source is tried only when a proxy answers 404 or 410, after a pipe on any error.XO_NOPROXY=<patterns>(comma separated globs over leading path elements,github.com/acme/*) always goes direct. The protocol is read only HTTP:<path>/@v/list,<path>/@v/<version>.mod,.zip(the tree, files under<path>@<version>/), and.lock(the xo.lock lines), the path and version escaped as in the module cache (!before a lower cased capital). A proxy is not trusted: its tree must declare the module path and match xo.lock as a git fetch must.xo mod proxy serve [--addr=host:port] [--fetch] [<cache dir>]serves a module cache this way (--fetchfills it from git). A malformedXO_PROXYisXO1314. - Offline (
--offlineon any command, orXO_OFFLINE=1) nothing is fetched: every version must be in the module cache or vendored, elseXO1303. xo vendorcopies every selected version intovendor/<module path>/withvendor/modules.txt. Whenvendor/modules.txtexists, builds use only vendor/ (no cache, no network); a requirement it lacks isXO1307.- Commands:
xo get <path>[@version|@latest|@none]sets a requirement (latest tag by default) and rewrites xo.mod and xo.lock, and says which module version still requires a higher version when the build does not select the one set;xo mod tidyrequires every imported module, removes requirements nothing imports (unless they raise a version the graph selects), and rewrites xo.lock;xo mod graphprints the requirement graph as Go’sgo mod graphdoes, one<module>[@version] <module>@<version>edge per line (the main module without a version), and with--jsonthe version selected for each module.
[P1] Workspaces: an xo.work file at or above the main module makes
the modules it lists build from their directories:
xo preview
use ./api
use ./billing
xo <edition>names an edition as xo.mod’seditionline does:preview, or its old name2026, which builds and gets the fixable noteXO1315(xo fixwritesxo preview); any other name isXO1301(decision 0155).- A listed module overrides every
requireof it; minimal version selection runs over the requirements of all listed modules. - The workspace applies when it lists the main module;
--workspace=off(orXO_WORK=off) ignores it,XO_WORK=<file>names another one. xo test,query,edit, andmcptake every listed module as one program (a rename reaches all of them, atomically).xo checkdoes when it is given the workspace’s own directory or a walk of it (./...there); a walk below it (DIR/...) checks the modules under DIR, andxo check DIRof a plain directory DIR’s module, each with the workspace modules they import, transitively, so modules nothing imports cost nothing (decision 0511).- xo.lock is never written with workspace overrides (
xo get,xo mod tidy, andxo vendorignore the workspace); builds record the local directories in build information only. A release build (xo build --release, 8) andxo build --cifail while a workspace overrides a required module (XO1308). xo.workis gitignored byxo initin a single module repository (xo initwrites .gitignore only in a git repository: a .git at or above the module directory); a monorepo may commit it.
[P1] Effect ceilings (decision 0086 step 3): a uses clause after
the version bounds the effects of a dependency.
module github.com/acme/api
require github.com/acme/billing v1.4.0 uses none
require github.com/acme/geo v2.1.0 uses net.dial, fs.read
- Every call from the requiring module into the dependency (any of its
packages), and every use of one of its functions as a value, may
perform only effects within the ceiling (
fsadmitsfs.read;uses noneadmits nothing), elseXO1309at the call site naming the dependency, the ceiling, and the effect. The effects counted are those the dependency’s function declares; effect variables (6.2) carry the caller’s own effects and do not count. - An upgrade whose new version adds an effect to a function this module
calls therefore fails at that call. A require without
useshas no ceiling. Unknown labels areXO1301. - In a workspace,
use ./billing uses nonein xo.work sets the ceiling of that module for calls from the other workspace modules; their xo.mod ceilings apply as well. xo getprints, for every requirement whose version changes, the exports added, removed, or changed and the effects added or removed, and the exports above the ceiling;xo get -uupgrades every requirement to its latest version.
[P1] Vouches (decision 0156): an escape hatch is code whose
authority the checker cannot see, a use c line (4.5) or a use go of a
Go package that is not pure (4.4; the pure ones are the std packages
marked replay rerun by default there). In a module the build gets as a
required version (the module cache or vendor/), each escape hatch needs a
vouch line in the xo.mod of a consuming module: the main module, or a
module of the active workspace.
vouch github.com/acme/zip v1.2.0 c "zlib.h" uses none
vouch github.com/acme/img v0.3.1 c "png.h"
vouch github.com/acme/pg v1.0.0 go "github.com/jackc/pgx/v5"
vouch <module path> <version> c "<header>" [uses <effects|none>],vouch <module path> <version> go "<Go import path>". The header or package is the string of the dependency’suseline; the version is the exact version the build selects (a vouch reviews one version’s code, so an upgrade needs a new one). Malformed lines areXO1301.- A dependency’s own vouch lines are ignored: it cannot vouch for itself
or for its dependencies. The main module’s and the workspace modules'
own
use canduse golines need no vouch. - A vouched
use cbinding performs the vouch’suses(the consumer’s word, not the dependency’s), orffiwithout one. An unvouched escape hatch, or one vouched for another version, is errorXO1316on the dependency’suseline, naming the line to add; an unvoucheduse cbinding performsffiwhatever its ownusessays. There is no machine fix: a vouch is a human review.xo getandxo mod accept-effectsrefuse a selected version with an unvouched escape hatch (XO1316, in any of its source files, from syntax) before writing xo.mod or xo.lock,--accept-effectsincluded: it accepts effects, not escape hatches.xo mod tidydoes not refuse; the check then reports them.
[P1] Releases (decision 0086 step 4): a version is a vX.Y.Z tag of
the repository whose root holds the module, or a <dir>/vX.Y.Z tag for a
module in the directory <dir>. xo publish [--check] [--version vX.Y.Z] compares the exports (the declarations xo query api
lists, in every package of the module) and their effects with the
previous tag:
- A removed export, a changed signature, or an effect added to a
function needs a major version; in a minor or patch release each is
XO1310(before v1.0.0, a minor release may break and a patch may not). Added exports need a minor version. - Without
--versionthe release is the next minor version (the next patch before v1.0.0), so a breaking change fails unless a major version is asked for. The JSON result lists every change, the breaking ones, the bump they need, and the smallest version they allow. XO1311when the release cannot be made: the module is not in a git repository, a module in a subdirectory has a path that does not end with that directory, the tag exists or is not above the last release, or the major version does not match the module path. Without--check, uncommitted changes areXO1311and the module must load and check without a workspace.- Publishing is tagging:
xo publishprintsgit tag vX.Y.Z && git push origin vX.Y.Z(git tag cli/vX.Y.Z ...incli/) and runs neither. - Major versions 2 and above live at a module path ending in
/vN(github.com/acme/billing/v2), in the same repository: the xo.mod of those tags declares that path, and a require of a path without the suffix takes only v0 and v1 tags (XO1301otherwise).
[P1] Import direction rules (decision 0095): deny lines state which
packages of the module may not import which.
module example.com/notes
deny example.com/notes/domain -> example.com/notes/store, example.com/notes/api
deny example.com/notes/store -> example.com/notes/api/...
deny <pattern> -> <pattern>, ...: a package matching the left pattern may notusea package matching any pattern on the right. A pattern is a package import path (of this module, a required module, or std), or such a path ending in/..., which matches the path and every package under it (example.com/notes/...is the whole module, so “domainimports only std” isdeny example.com/notes/domain -> example.com/notes/...).- Every direct
useline is checked, whether the import is used or not: a forbidden one is errorXO1312at theuseline, naming the rule and its xo.mod line; it has no machine fix (removing an import is a design change). Transitive edges are not checked: a chain is caught at its first forbidden step. - Rules apply to the packages of the module whose xo.mod holds them (the main module, and each workspace module checked as one); a dependency’s rules are checked when it is built as a main module.
- A malformed
denyline, or a pattern that names no package, isXO1301on its line.xo mod tidyandxo getkeepdenylines. xo testchecks first, so a broken rule fails the tests too.xo query imports <package>andxo query deps <package>list theuselines (10.3).
[P1] gc lines tune the garbage collector of a program whose main
module this is (decision 0065); they are ignored in imported modules:
gc min_heap 64MiB // floor of the heap goal
gc percent 200 // GOGC: goal growth over the live heap, or `off`
gc memory_limit 1GiB // soft memory limit (GOMEMLIMIT)
Sizes take B, KiB, MiB, GiB, TiB (or KB, MB, GB, TB, powers
of 1000). Without gc lines a program’s heap goal is the live heap plus 100
percent of it (as Go’s GOGC=100), but never below a floor of 2 MiB per
processor (GOMAXPROCS), at least 16 MiB; there is no memory limit. The
environment always wins: GOGC set turns the floor off and sets the
percent, GOMEMLIMIT replaces memory_limit, XO_GC_MIN_HEAP replaces
min_heap (0 turns the floor off).
4.3 xo.lock
Written only by the toolchain. Maps every imported definition actually used to its content hash.
- [P1] Hash is per module version (source tree hash), like Go’s
go.sum:<path> <version> h1:<hash>for the tree of every selected version and<path> <version>/xo.mod h1:<hash>for the xo.mod of every version version selection read.xo getandxo mod tidywrite it; every command that loads the program recomputes the hashes from the module cache or vendor/ and compares them. A mismatch (a moved tag, an edited cache or vendor copy) isXO1304and nothing builds; a version with no entry isXO1305(runxo mod tidy). Malformed lines areXO1301. - Pinned Go modules (decision 0356): for each
require go <module> <version>line, xo.lock records Go’s own go.sum hashes,go <module> <version> h1:<hash>(the module zip) andgo <module> <version>/go.mod h1:<hash>, taken from the binding workspace’s go.sum. Every check compares them with the binding’s go.sum: a different hash isXO1304, a missing lineXO1305;xo mod tidyandxo getwrite them, and a rewrite keeps a line no binding has fetched yet. - [P1] Effect lock (decision 0156): xo.lock also records, for each
selected module (not workspace modules), the effects its exported API
can reach:
<module path> effects <labels|none>(github.com/acme/billing effects net.dial,stdio), the union of the effect labels in theusesclauses of itspubfunctions and methods (every package, test files left out). The line is keyed by module path, so it survives an upgrade. Every command that loads the program compares each module’s effects with its line: an effect the line does not admit (fsadmitsfs.read) isXO1317on that line.xo getandxo mod tidyrecord a module without a line as it is, narrow a line whose module needs less, and fail withXO1317(writing nothing) when a module needs more.xo mod accept-effects [<module path>...](all modules when none is named) andxo get --accept-effectsrecord the wider effects;xo checkandxo buildnever do. A module with no line (a lock written before decision 0156) is not checked. - [P1] Checksum log (decision 0124): with
XO_SUMDB=<name>+<key id>+<public key> [<URL>](defaultoff), the first fetch of every module version, from git or a proxy, is checked before it enters the module cache: the log’s record of the version (its two xo.lock lines) must equal the fetched tree’s hashes, the record must be in the log’s signed Merkle tree (inclusion proof), and that tree must extend every tree of the log this module cache saw before (consistency proof). A failure isXO1313and nothing is cached; a log that cannot be consulted, or malformed settings, isXO1314.XO_NOSUMDB=<patterns>(asXO_NOPROXY, 4.2) names private modules that are never looked up.xo mod sumdb keygen <name> <key file>makes a log’s key (the verifier key, printed, is whatXO_SUMDBnames) andxo mod sumdb serve --key=<key file> [--addr=127.0.0.1:7071] [--fetch] <data dir>runs a log, its records kept in the data directory (decision 0124);--copy-to=<bucket URL>copies each new record to an S3-compatible bucket before adding it,--fill-to=<bucket URL>writes each version it adds to a proxy bucket asxo mod proxy filldoes,xo mod sumdb restore --from=<bucket URL> <data dir>rebuilds the log from the copies,--ratelimits the lookups that add a version per client and minute (default 60), andGET /index?since=<RFC 3339 time>lists records added since as JSON lines (decision 0568).xo mod proxy fill --to=<bucket URL> <module path>[@version]...writes versions, checked against the log, and their lists into an S3-compatible bucket that serves the proxy protocol as static files (4.2; decision 0568). - [P1] Definition hashes (decision 0125, step 5 of decision 0086):
every top level definition (function, method, type, constant) has a
content hash
d1:<base64 SHA-256>over its syntax tree with positions, comments, and doc comments dropped, its own name left out (functions and constants; a type’s name is part of it), local names erased (numbered by first binding:let,var, patterns, loops, closure parameters, type parameters, receivers, labels; the parameters of declared functions keep their names, which named arguments use), imports by path rather than by local name, and the definitions of the same module it references replaced by their hashes (mutually recursive ones hashed together).hashcovers that closure,ownthe definition alone.xo query hash <name>prints them (10.3);xo publishlists every definition, exported or not, whose hash differs from the previous release (changed, orchanged_viawhen only a definition it uses changed), next to the API comparison. The hashes are syntactic (no types): a method called on a value and other modules’ definitions are referenced by name. xo.lock does not record them; decision 0125 proposes how it would. - [P3] Hash is per definition: the normalized AST with local names erased
and referenced definitions replaced by their hashes. Consequences:
- Two versions of a dependency coexist without conflict. Types from different versions are the same type if and only if their hashes are equal.
- An upgrade that does not change a definition is a no-op for code using it.
- A name that does not resolve to a hash fails at once with the nearest real
names suggested (
XO0601). APIs cannot be hallucinated silently.
4.4 Go packages [P1]
Until Xo has its own ecosystem, Go packages can be used directly (decision 0041):
use go "regexp"
use go "github.com/google/uuid" as uuid
fn main(os: Os) ! {
let re = regexp.must_compile("[a-z]+")
os.stdio.println("${re.find_string("123abc")} ${uuid.new_string()}")
}
xo check,build,run, andtestgenerate bindings automatically into.xo/gobind/(or$XO_GOBIND_DIR);xo bind <path>does it explicitly. A package outside Go’s standard library needs its Go module pinned,require go <module> <version>in xo.mod (4.2), or the use isXO1319(decision 0356): its fix adds the line with the version Go’s module resolution picked, andxo mod tidyadds missing pins and records their go.sum hashes in xo.lock from the binding (a pin whose hashes no binding has fetched and xo.lock lacks isXO1320: runxo checkonce first). The pin is of the package’s own module: a package in a nested Go module (aws-sdk-go-v2’sservice/s3, a module insidegithub.com/aws/aws-sdk-go-v2’s path) needs its own line, and a pin of the enclosing module pins only that module, which the nested one resolves beside. Go’s standard library packages need no line; the Go toolchain’s version decides them.Names are converted to Xo naming: functions and methods to
snake_case(Splitissplit,EncodeToStringisencode_to_string), types stayUpperCamel.Types at the boundary:
(T, error)becomesT ! go.Error; a pointer result that may be nil becomesT?; mutable Go objects become opaque handles; a handle keeps Go’s equality (2.9): a comparable type the package hands out as a value,Tin a signature or field (netip.Addr,uuid.UUID), compares and hashes by value, a struct it passes only as*T(url.Parse’s*url.URL) by pointer, as Go’s==on the pointers, and an interface by its dynamic value; a named Go type is one Xo type in every binding that uses it, declared by its own package’s binding (net’s functions takenetip.AddrPort), which is bound with it even when the program does not name that package (decision 0392); a type of a package a program cannot import (internal) is skipped; a parameter of an unexported Go type is skipped; a[]byteparameter Go writes into (aRead*function’s, or one nameddst, unless a result is a[]byte) is anInt, the buffer’s length, namedmax, and the bytes Go wrote come back in place of the leadingn intresult, or as the whole buffer when there are no results (decision 0445):r.read(4096) -> Bytes ! go.Error,hex.decode(max, src) -> Bytes ! go.Error; data that comes withio.EOFis returned, and the next call gives the EOF; a function with two such buffers (ReadMsgUDP) or other results is skipped; slices and maps are copied in and out; Go’sany(interface{}, or a named empty interface) isgo.Any, an opaque Go value (decision 0412, std.md 12):go.any(x)makes one from a value with a Go form, the elements of a list literal for...anyconvert implicitly (2.10),as_int(),as_str(), … read one back (None on another Go type), and a Go function that fills a value throughany(rows.scan,json.unmarshal) takesgo.out[T]()’s.any(), read with.get()after the call; a generic Go function is an Xo generic (decision 0415):anyis no constraint,comparableisEq,cmp.OrderedisOrd, a~[]Eor~map[K]Vtype parameter isList[E]orMap[K, V], other constraints are skipped, and Go’sslicesandmapsare not bound (the prelude’s List and Map methods cover them); a type argument forcomparableorcmp.Orderedneeds a Go value Go can compare or order, elseXO1106, while one foranymay be any Xo type, which Go holds without looking inside; a generic Go type is a generic handle (lru.Cache[K, V]isCache[K: Eq, V], its methods bound withKandV) when its constraints map, and an instance over type parameters or types Go and Xo share (Str,Bool, a type parameter) is that handle’s instance; a constraint interface (one with a type term, such asinterface{ ~int | ~float64 }) is not a type and is not bound; acontext.Contextparameter is supplied from the current task (deadline and cancellation); a panic becomes a fault.A named Go type over a basic type (
time.Month,fs.FileMode) is that basic type in Xo, and each method it has with a value receiver is a package function named<type>_<method>in snake case that takes the value first (decision 0416):time.month_string(m: Int) -> Str,fs.file_mode_is_dir(m: UInt32) -> Bool. A pointer receiver method is not bound (Xo passes a copy), and neither is one whose name a package function already has.A Go struct’s embedded fields are bound as its other fields are (decision 0491 A): an exported embedded field gets a getter and a setter named after it (observer.LoggedEntry’s
le.entry(),le.set_entry(v)); an embedded struct held by value is a handle of the outer value’s field, so a change through it is the outer value’s, as Go’s&le.Entryis; an embedded*TisT?, an embedded interface its interface handle. Every field Go’s selector reaches through embedded structs gets accessors on the outer handle (le.message(),le.set_message(s)), by Go’s rules: the shallowest name wins, a name two embedded fields have at one depth is ambiguous and not bound, and a method or a shallower field of the name wins. Promoted methods are bound as the type’s own.A List, Map or Set given to Go is a copy: a Go function that changes its argument in place (through
any, an interface, or a slice parameter) changes the copy, and the Xo value stays as it was; take the result Go returns, or usego.out[T]()for a function that fills a value.xo checkwarnsXO1107where one is given as Go’sany(go.any(xs)for ananyparameter, or an element of a...anylist), except in a call of a function known only to read it (the reviewed list in compiler/check/goreads.xo: encoding/json and encoding/xml’s encoders, fmt’s print family, log, log/slog, zap’s field constructors, database/sql’s query arguments, the templates'execute), or with// xo:allow XO1107 <reason>on the line or the line above (decision 0491 B).A named Go map type (
jwt.MapClaims,map[string]any) is a handle withT.of(m), which makes one from an Xo Map (copied in), andto_map(), which copies it out; its methods and the interfaces it implements (as_claims()) are bound as for any handle.An Xo function passed to Go as a callback that Go calls during the Go call, on the calling task’s goroutine, runs as the calling task. A call from another goroutine (
sync.WaitGroup.go_, a timer) runs as a task of its own, a child of the calling task (canceled with it), with its own held mutexes (decision 0067); under the deterministic scheduler such a call waits for a turn like a spawned task and is recorded by--record(core 7.4, 11.3).A callback whose Go type ends in an
errorresult (func(int) error,func(string) (int, error)) is an Xo function-> T ! go.Error(-> () ! go.Errorwith no other result; decision 0416): itsErr(e)is Go’s error, the Go errorecame from when Go made it (soerrors.Issees a sentinel such asio.EOF), else one withe’s text;go.error(msg)makes one. A callback with several results (func() (int, string),func(string) (int, bool, error)) returns them as a tuple,-> (Int, Str), its error still the! go.Error.A variadic of an unnamed Go function type, Go’s functional options (
optFns ...func(*s3.Options)), is a List of Xo functions, each a callback by the rules above, which Go calls in order (decision 0422):s3.new_from_config(cfg, [fn(o: s3.Options) { o.set_use_path_style(true) }]), or[]for none. A variadic of a named function type (...EOption) stays a List of handles, which Go’s option helpers return.A struct field or package variable of a Go function type has a setter that takes an Xo function, a callback by the rules above (
s.set_on_error(fn(msg: Str) { log.send(msg) }),hook.set_logf(f)); Go may call it later, from any goroutine.A Go function value Go gives Xo (a result, a field or variable read) is an Xo function
uses gothat calls it, its arguments and results converted as a bound function’s are and a finalerrorits! go.Error(fnval.adder(2)isfn(Int) -> Int uses go; a value of a named function type, such as a functional option orhttp.HandlerFunc, stays a handle that goes back to Go; in a result it is parenthesized,-> (fn(Int) -> Int uses go) uses go). Calling a nil Go function faults; several results are a tuple. It cannot be passed back to Go, and one taking a function is not bound.Go’s
erroranywhere but a function’s final result (a parameter, a field, a result before the last) isgo.Error?,nilbeingNone(errors.is(err: go.Error?, target: go.Error?) -> Bool); anerrorthat is a function’s only result stays! go.Error(nilisOk); a Go error variable is a function returning it as ago.Error(io.eof()). A go.Error that came from Go goes back as the same Go error (decision 0416).A Go pointer to a basic type (
*bool,*string,*int,*float64) isT?(decision 0419):nilisNone, otherwise the value it points to. It is a copy, not an alias: Xo reads the value when it crosses the boundary and passesSome(v)to Go as a pointer to a fresh copy ofv, so a write Go makes through the pointer later is not seen (read the field again). A parameter Go writes through (sync/atomic, a*Varfunction such asflag.int_var, an output parameter) is not bound.A Go channel Go gives Xo (
<-chan Torchan Tas a result, a field or a variable) isgo.Recv[T](decision 0421):recv()waits for the next value (None once the channel is closed and empty),try_recv()does not wait,each(f)receives until it is closed. Xo does not send on, close or pass back a Go channel (a send only channel or a channel parameter is not bound), and a nil one is closed. A waitingrecvis a cancellation point: the task’s cancellation or atask.with_timeoutdeadline ends it. Under the deterministic scheduler it gives the task’s turn away while it waits;--recordkeeps each received value that holds no handle. Go timer channels (time.after,time.tick,Timer.C) are not bound: Xo’s clock is a capability they would bypass.An Xo program implements a Go interface with functions (decision 0416): a binding declares, for each named interface whose methods all map as callbacks, a constructor named after the interface (
implement_and the name when that is taken) with one function parameter per method, named after it, returning the interface’s handle:let w = io.writer(write: fn(p: Bytes) -> Int ! go.Error { sink.send(p) p.len() }) let h = http.handler(serve_http: fn(w, r) { w.write_header(204) })The functions are callbacks (the rules above: the calling task, or a task of its own for a call from another goroutine, with spawn’s rules for what they capture). A method that fills a byte buffer (
Read(p []byte) (int, error),ReadAt) is a function given the buffer’s length that returns the bytes (fn(max: Int) -> Bytes ! go.Error): they are copied into the buffer, more than it holds is a fault, and none with no error isio.EOF.Xo does not convert one handle to another. A handle whose Go type Go would assign to another interface of its package, or to one of io’s I/O interfaces (
Reader,Writer,Closer,ReadCloser,WriteCloser,ReadWriter,ReaderAt,WriterTo,ReaderFrom,StringWriter,ByteReader) orfmt.Stringerwhen its package depends on io or fmt, or to another package’s interface that its package’s signatures name (chi’sMux.Handletakes net/http’sHandler) or that a package it imports exports (aws credentials’ providers asaws.CredentialsProvider), has a method that gives it as that interface:io.read_all(resp.body().as_reader()),buf.as_writer(),httptest.new_server(mux.as_handler())(decision 0416 and its addendum).A bound call runs its binding’s adapter (the argument and result conversions and the panic boundary) in a frame at the Xo call’s line (decision 0441: the Go backend pastes the adapter’s body at the call under the call’s
//line, 10), so a Go library that records its caller withruntime.Callersees the Xo line: zap’s AddCaller logs"caller":"main.xo:LINE"with no caller skip (a call through an interface value, or of a generic function, still runs the adapter in Xo’s runtime package,rt/xo_gobind_PKG.go).Every call into Go performs the effect
go, whichpubfunctions must declare. Go code can reach files and the network without a capability, souses gomarks that authority escape in signatures. In a required module, ause goof a package that is not pure (the pure std packages listed below) needs the consuming module’svouchline (4.2, decision 0156), elseXO1316.Exported names whose signatures cannot be mapped are skipped and listed at the top of the generated binding; using one is
XO1102. A package that cannot be bound isXO1101.C headers are the native backends’ counterpart (4.5).
Calls into Go take part in record and replay (11.3, decision 0093): each binding’s doc comment says how (
/// Replay: ...). A pure function can be markedreplay rerunin xo.mod, so a replay calls it again instead of answering it from the trace and the trace does not record it:replay rerun go github.com/acme/slug replay rerun go os getpid File.nameThe line names a Go import path and optionally the functions (
name) and methods (Type.method) it marks; without names it marks every function of the package. The pure std packages (strconv,strings,bytes,unicode,unicode/utf8,unicode/utf16,math,math/bits,regexp,regexp/syntax,path,html,net/url,encoding/hex,encoding/base64,encoding/base32) are marked already, except functions that take or return a handle of another package (regexp.Regexp.match_reader).
4.5 C headers [P2, native builds]
Native builds (--no-gc, 10.1) call C through bindings generated from a
header (decisions 0093 and 0116):
use c "tiny.h" link "tiny.c"
use c "zlib.h" link "z" uses none
fn main(os: Os) {
os.stdio.println("${tiny.tiny_add(2, 40)} ${zlib.crc32(0, b"hello")}")
}
use c "<header>"names a header relative to the module directory, or one on the C compiler’s include path (zlib.h).link "<x>", repeated as needed, names what to link: a C source, object, or archive relative to the module directory (tiny.c,libtiny.a), or a library name without/or extension (zlinks-lz).assets the local name; the default is the header’s base name in snake_case.- The checker binds the header with clang’s AST dump
(
xo bind --c <header>does it explicitly) into.xo/cbind/(or$XO_CBIND_DIR): an Xo declaration file and a C adapter that the native build compiles and links with the program. Function names become snake_case (zlibVersioniszlib_version); struct tags become UpperCamel types. A Cenumthe header defines is also bound as a valued enumenum EnumcMode: Int { Up = 0, Down = 1 }(UpperCamel tag; the prefix every enumerator shares, up to a_, is dropped and the rest is UpperCamel) withvalue(),E.from(v)andE.all()(2.3). An enumerator with a value an earlier one has is aconstalias of that variant. A parameter or result of the enum type is stillInt32(decision 0269 part 4 stage 1). - Types at the boundary (decision 0093), all copied, none pointing into Xo
memory after the call returns:
intisInt32,unsignedUInt32,longandlong longInt, their unsigned formsUInt64,short,char, and their unsigned forms the sized integers,floatFloat32,doubleFloat,_BoolBool, an enumInt32; aconst char *parameter is aStr(copied and NUL terminated) and aconst char *result aStr(copied; NULL is “”); a const byte pointer followed by an integer length parameter is oneStr(const char *) orBytesparameter; a struct of exactly a const byte pointer then an integer (struct buf { const void *p; int64_t n; }) returned by value is aBytesresult (the n bytes at p copied, NUL bytes kept; a NULL p is empty), since aconst char *result stops at its first NUL; a struct of such scalars passed or returned by value is an Xo struct with the same fields, copied; a pointer to a struct the header declares but does not define is an opaque handle type (a result isT?, None for NULL). Handles are not comparable (2.9) and Xo never frees them: call the library’s free function. Anything else (output pointers, mutable buffers,char *results, pointers to defined structs, function pointers, arrays, variadic functions) is skipped and listed with the reason at the top of the binding; using a skipped name isXO1105. A header that cannot be bound isXO1104. - Every call performs the effect
ffi(6.1), whichpubfunctions declare. Ause cline may replace it with the effects a human vouches for,uses noneoruses fs.read, clock, as an effect ceiling of decision 0086 does for a dependency. That claim counts only in the module’s own code: in a required module the consuming module’svouchline decides the binding’s effects (4.2, decision 0156). use cis impossible on the Go backend:xo check,build,run, andtestwithout--no-gcreportXO1201on the line. (use gois likewiseXO1201on the native backends.)- A C crash is not recoverable: it ends the process (8).
4.6 Declaration files
A declaration file is an Xo source file whose functions may be declared
without a body: fn crc32(crc: UInt32, data: Bytes) -> UInt32 with no
{ ... }. The body is supplied outside Xo: by the backend’s runtime (std’s
intrinsics), by a generated adapter (Go packages, 4.4; C headers, 4.5),
or by the std module’s per-backend implementation file.
- Which files. Only these are declaration files: a std module’s
declaration file (
std/NAME.xo, andstd/native/NAME.xofor a module imported by that path, such as the native intrinsicsstd/native/rt.xo), and the binding files the toolchain generates into.xo/gobind/(4.4) and.xo/cbind/(4.5). The native implementation files that back a std module (std/native/NAME.xoforstd/NAME,std/native/llrt/) are ordinary files: every function in them has a body. A program’s or library’s own files never are: a function without a body there isXO0172(“expected{to start the body”), and an interface method is the only bodyless function a user writes. - What else is the same. A declaration file is otherwise ordinary
Xo: its types, constants, and functions with bodies are checked as in
any file, and a bodyless function’s signature (parameters, result,
errors, effects, clauses) is checked and is the contract callers see.
Doc comments,
xo docandxo deftreat the declaration as the definition. - Markers. The checker reads two markers in a std declaration file’s
doc comments, and in no other file (in user code they are ordinary
comment text):
@move_onlyon a struct: values of the type move as the builders do (5.3,XO0510; decision 0305).@internalon a struct: its fields are not visible outside std (XO0605; decision 0440).@static T.nameon a constant: it is the type constantT.name(Int.max), not a name of its module (decision 0587).
- Generated binding files are rewritten by
xo bind(Go’s begin with// Code generated by xo bind ... DO NOT EDIT.) and are never edited.
5. Values, mutation, and memory [P1]
5.1 Value semantics
All builtin types and user structs, enums, and tuples have value semantics.
There are no pointers and no reference types other than the explicit handle
types (Chan, Mutex, Atomic, capability values, Buf by move).
Because values never alias mutably, data races are impossible except through
Mutex and Atomic, which are synchronized.
What a copy costs (informative; decision 0294). The semantics above never depend on it, but the time does:
- Copying a value (a
letof another binding, an argument a function keeps, a field, list, or map store, a return, a closure’s or a task’s capture) copies its inline part and shares each of its heap fields (Str,Bytes,List,Map,Set, a box of a recursive type, a handle) by counting it up. The cost is the number of heap fields, counted through nested structs, never the size of their contents. A parameter that is only read is borrowed and costs nothing. - An argument passed to a function value (a closure, a
fnparameter, a named function used as a value) is borrowed too, unless its type is the function’s result type or one of a tuple result’s (an accumulator threaded through,fold’sfn(A, T) -> A, or afn(var T)closure’s value): that one is handed over, so the body can update it in place. The rule depends on the function type alone (decision 0337); a body that keeps a borrowed argument (returns, stores, or captures it) counts it up then. A move only value of a borrowed position stays the caller’s for the call; its first write in the body copies it. - Writing a collection or string that another value still shares copies
it first, O(n), and the writer then holds its own: later writes to it
are in place (a
pushamortized O(1)). One that nothing else holds is changed in place. - So a task that captures a struct shares every heap field of it at the
spawn and releases them when it ends, and the first change on either
side to a collection in it, while both hold it, copies that collection.
A struct of hundreds of heap fields (the compiler’s
Checker) costs hundreds of count updates per spawn: capture the fields the task uses (let part = c.fieldbefore the spawn).xo vetnotes such captures (XO0534), and a large parameter that is only stored (XO0531). var b = xs[i], a change tob, thenxs[i] = bcopies the element at the first change, becausexsstill holds it; in a loop that is a copy per pass. Changexs[i]in place instead (xs[i].push(v), decision 0169).xo vetnotes it for collection elements (XO0536); the Map form hasMap.update(XO0532).- A
Mutex.withbody with avarparameter gets the value moved out of the mutex and changes it in place: a fault poisons the mutex rather than restoring the value (5.4, decision 0482), so nothing keeps the value it was given. AnErrstill hands that value back, and so does a cancellation of a body that waits: in a body that can returnError waits, a write followed by a point that can fail or wait (a?, anErrreturn, a call that can be canceled) copies the collection it writes, once perwith.
5.2 Mutation
- Only
varbindings,varparameters, andvarreceivers can be mutated. xs.push(v)on avar xs: List[T]rebindsxsto a new persistent list sharing structure with the old one. The same holds for every mutating collection method (put,remove,update,pop,add).- Field assignment
u.name = "b"on avar urebindsuto a modified copy. Nested paths work:st.users.put(k, v),st.config.port = 9090. - An element of a
Bytescannot be assigned, even through avarbinding:Bytesis immutable (3.6).b[i] = xis errorXO0502, with a note namingBytesBuilderandList[UInt8]. - An assignment evaluates the indexes of its target, then the value, then
stores into the target (decision 0140): changes the value makes to the
target’s binding are kept, so
t.objs[o].kids = t.add_kids()keeps the objectsadd_kidspushed ontot.objs. A compound assignment (+=,-=, …) reads the target’s old value after the value, sot.n += t.bump()keeps whatbumpchanged int,nincluded (decision 0159). - Destructuring assignment (decision 0536):
(a, b) = vstores the elements of the tuplevinto the placesaandb, which may be bindings, fields, list and map elements, nested tuples of places, or_(the element is dropped).vis evaluated first and in full, then each place’s indexes are evaluated and its element stored, left to right (Python’s order), so(a, b) = (b, a)swaps and(xs[i], ys[i]) = bump(i)with avar ichanged bybumpstores at the newi. Each place follows the rules of a single assignment (XO0502per place); the value is checked against the tuple of the places’ types, so(n, s) = (0, "")withn: Int32types0asInt32. Naming the same place twice ((a, a) = ...,(p.x, p.x),(xs[i], xs[i])) isXO0539. Compound assignment takes one target. - Struct targets (decision 0538):
P{x, y} = pstores the fields of the struct valuepinto places, by the rules oflet’s struct pattern (3.5): each field isname: place,namealone (the bindingname),name: _, or a nested tuple or struct target, every field is named unless the target ends in.., andPmust be the value’s type (XO0302for a type that is not a struct or a field not named,XO0401for a value of another type or a field whose type does not fit its place). The value is evaluated first, then each named field is stored left to right, as for a tuple:P{x: y, y: x} = P{x: x, y: y}swaps. The shorthandnameand..belong to targets and patterns only: in a struct literal they areXO0160. - List targets (decision 0538, owner 2026-11-06): a list shaped
target follows the rule of
let’s list patterns (3.5), which must match every value: a list’s length is not known until it runs, so[a, b] = xs,[a, ..] = xsand[] = xsareXO0303, alone or nested in a tuple or struct target.[..] = vmatches every list: it evaluatesv, in order with the target’s other places, and stores nothing. A list of a given length is matched withif let [a, b] = xsormatch, or its elements assigned by index. A trailing..in a list literal isXO0160. - A call evaluates the place of a
varreceiver orvarargument, then every argument in order, then reads those places (decision 0142):t.get(t.add(v))on avar tsees the itemaddpushed, andxs.push(f())keeps whatfpushed ontoxs. A receiver that is notvarand is a variable or a field path (t,t.items) is read after the arguments too (decision 0326):t.size(t.add(v))with a by valuesizesees the itemaddpushed. Any other receiver (a call, an index) is evaluated first, in source order. - To change a value stored in a collection, use
update, which reads, mutates, and writes back in one call:let allowed = m.update(key, new_bucket(limit, now), fn(var b) { b.take(now) }) - Lost update check. Error
XO0520(“mutation ofbis never written back”) applies to a localvarwhose initializer copies an element out of a collection (m.get(k),m[k],xs[i],xs.get(i),first,last,find, optionally followed by??,?, or.or_err(...)?) when the binding is mutated and is not stored again after its last mutation. Storing means passing the whole value as a call argument (m.put(k, b),save(b)) or assigning it as a whole (m[k] = b). Reading or returning it does not count, because the collection still holds the old value. A plainb = valuereplaces the copy rather than changing it, so it is not a mutation (l = f.values[l].args[0]walking a chain). This catchesvar b = m.get(k) ?? new_bucket(); b.take(now)withoutm.put(k, b), and a PATCH handler that returns the edited copy but never stores it. For an intentional scratch copy, copy through a local first (let base = m.get(k)?; var scratch = base). Values derived withwithare not tracked, since views such as redacted copies are common. It also applies to any localvarthat is mutated after being stored into a collection (xs.push(v),m.put(k, v)) and then not stored again, since the stored copy does not see the change. Reads insidedefercount. Parameters, includingvarclosure parameters, are never checked. - No aliased
vararguments (decision 0111). One call may not pass the same variable, or two overlapping places, to twovarparameters (avarreceiver counts as one):both(xs, xs),one(p, p.x),p.add(p.y)with avarreceiver, andboth(g[i], g[j])areXO0503. Places overlap when they start at the same binding and one path of fields and indexes is a prefix of the other; two different field names, or two indexes that are different integer or string literals (g[0],g[1]), keep them apart. Copy one into a temporary first. With aliasing ruled out, passing by reference (the Go backend) and copying in and out (the native backends) give one result.
5.3 Move only buffers
Buf[T], StrBuilder, and BytesBuilder are mutable in place and move
only (affine):
var b = Buf[Int].with_capacity(1024)
b.push(1)
let xs = b.freeze() // moves b, returns an immutable List[Int] in O(1)
b.push(2) // error XO0510: use of moved value `b`
- Assigning, passing, sending on a channel, or capturing in a spawned task moves
the buffer. The compiler tracks moves only for these types and for the
std handles whose declaration is documented
@move_only(std/compress’s Compressor and Decompressor, decision 0305). The marker is read only in std’s declaration files: in user code it is an ordinary comment, so a user type cannot be made move only. There is no general borrow checker. - A move on a path that ends (a
return, abreakorcontinue, the error side of?, a call of a function whose result isNever) does not reach the code after that point. A use isXO0510only when some path that can reach it moved the value and did not assign it again (decision 0300). Abreakcarries its moves to the code after its loop and acontinueto the loop’s next iteration:
fn decode(s: Bytes) -> Bytes? {
var out = BytesBuilder.new()
for c in s {
if c == 61 {
return Some(out.freeze()) // the path ends: no move reaches below
}
out.write_byte(c)
}
Some(out.freeze())
}
5.4 Shared mutable state
let cache = Mutex[Map[Str, User]].new({})
cache.with(fn(var m) { m.put(key, user) })
let n = cache.with(fn(m) { m.len() }) // read only access
let size = cache.with_read(fn(m) { m.len() }) // shared with other readers
let hits = Atomic[Int].new(0)
let now_hits = hits.add(1) // returns the new value
Mutex[T].with has the signature
fn (m: Mutex[T]) with[R, E, fx: Effects](f: fn(var T) -> R ! E uses fx) -> R ! E uses fx
- The closure’s return value (or error) is the result of
with. - Mutations to the
varparameter are written back when the closure returns successfully. If it returns an error, the protected value is left unchanged. - If a fault unwinds out of the closure, the mutex is poisoned (decision
0482): the writes the closure made are not undone, and no later code sees
them, since every later
withandwith_readon that mutex faults withXO-F010untilm.reset(v)stores a new value and clears the poison. A cancellation of the task while the closure waits (on a lock, a channel, a task, I/O) leaves the value unchanged and does not poison.let r = task.isolate(fn() -> Int ! () { add(cache, entry) }) // add faults inside with if r.is_err() { cache.reset({}) // poisoned until here } - A closure parameter declared without
vargets a read only view. - Warning
XO0540: the closure writes itsvarvalue and a later path can returnErr(return Err(...),?, or a call that can fail as its result), so the write is undone. A sticky error is the common case:m.with(fn(var st) -> () ! E { st.err = Some(e) // undone by the Err below Err(e) // XO0540 }) - To keep changes and still report failure, return the outcome as the
closure’s success value and apply
?outside:let outcome = q.state.with(fn(var st) -> Result[Job, QueueErr] { st.expire_leases(now) // kept if !st.token_valid(id, token) { return Err(QueueErr.StaleToken) } Ok(st.ack(id)) }) outcome? - Warning
XO0804(split critical section): a value read inside onem.with(...), or derived from one, is used inside a laterm.with(...)on the same mutex, or a branch on it decides whether the laterwithruns. Another task may have changed the state in between (check then act). Do the check and the action in onewith. withcannot be called re entrantly on the same mutex within one task (faultXO-F004with both acquisition sites).m.with_read(f)(std.md 2.7) is shared read only access:fgets the value read only, readers run together, andwithexcludes them. Writers are preferred, so a reader must not wait for a reader that has not entered yet. A value read inwith_readand used in a laterwithgetsXO0804like one read inwith.
5.5 Memory management
Native builds (the default, 10.1 Backends) reference count their memory (decision
0046): a value is freed when its last reference goes, with no collector and
no pauses. Values cannot form cycles, since Xo has no mutable references; a
cycle can form only through a shared handle (a Mutex, an Atomic, or a
std handle such as a WebSocket connection) that stores a closure capturing
the handle itself, and such a cycle is never freed, so the owner drops what
it stored when nothing can call it again (conventions.md 6.1). The Go
backend (--backend=go) uses Go’s tracing garbage collector, plus request
scoped arenas (decision 0066; on by default, off with --no-arenas). An arena is memory owned by one HTTP request served by
http.server (std.md 4.4) and reused by a later request once the handler has
returned and the response is written. The compiler and the runtime place in it
only memory that provably cannot outlive the request: the request’s header,
parameter, and query tables and its body when the handler uses the request
only through json, param, param_int, query, header, and its Str
fields (and not in a nested closure); the response built by http.json or
http.text that is directly the handler’s result; and the List made by
m.values(), m.keys(), m.entries(), or s.to_list() when it is only
consumed in its own expression. Everything else, including every value a
program stores, sends, captures, returns, or hands to Go, is ordinary garbage
collected memory, so arenas are invisible: a program prints the same with and
without them. A user written arena scope block remains [P2].
6. Effects and capabilities [P1 checking, P2 replay]
6.1 Effect labels
The builtin effects are:
| Effect | Sub effects | Authority |
|---|---|---|
net | net.dial, net.listen | Sockets, HTTP, DNS |
fs | fs.read, fs.write | Files and directories |
clock | Wall clock, timers, sleep | |
rand | Randomness (crypto and math) | |
env | Environment variables, args | |
proc | Spawn processes, signals, exit | |
stdio | Standard input, output, error | |
secrets | secrets.read, secrets.write | The user’s OS secret stores: Linux keyring, macOS Keychain, Windows DPAPI (decision 0584) |
ffi | Calls into C through use c (4.5, native builds) | |
log | Writing a std/log record (debug, info, warn, error) |
A function with no uses clause is pure: it performs no capability
effects. It may still allocate, fault, be cancelled, and use
synchronized state (Mutex, Atomic, Chan).
Logging (std/log) performs the log effect (decision 0156): a pub
function that logs declares uses log, so a dependency’s logging is
visible in its signatures, a ceiling can forbid it, the effect lock
catches an update that starts logging, and xo audit lists it. log
needs no capability (there is nothing to pass from main); it is
inferred for non pub functions like any effect, so main and helpers
are unchanged. log.configure performs stdio, not log. std’s own
records (a handler fault, an ignore_err) stay attributed to std and do
not make std functions perform log. Log output goes to the sink
configured in main (standard error by default) and is recorded during
record and replay like any other output. Each record a required
module’s code writes names it (decision 0173): a text record reads
<time> <LEVEL> [<module>@<version>] <msg> k=v ..., and a JSON record
carries the key "module" (which replaces a field of that name, so a
dependency cannot attribute its record to another module); log.Record
in tests has module ("" for the main module). The main module’s
records are unchanged. The call’s source file decides, so a main module
closure run by a dependency stays the main module’s.
Effect labels live in their own namespace: a parameter or module named fs or
net does not conflict with the effect fs or net.
6.2 The uses clause, effect variables, and subsumption
pub fn sync(src: Fs, out: Stdio) -> () ! SyncErr uses fs.read, stdio { ... }
- A function’s effects are the union of the effects of everything it calls.
pubfunctions and interface methods are not inferred: theirusesclause is the declared set, and no clause means pure. Non pub functions and closures have their effects inferred.- Performing an effect outside the declared set is error
XO0701, which shows the call chain that performs it. On a declaration its note names the corrected clause (uses (stdio, fx): the written effects, then the missing labels and effect parameters), and its fix writes it, with the same labels in each declared caller that would miss them next, so onexo fixchecks clean. The effects are not inferred: the clause stays what the source says. Declaring more is allowed (for interface stability) and noted byxo vet. - Function types carry effects. One effect:
fn(Int) -> Int uses clock. Several effects are parenthesized:fn(Int) -> Int uses (net, clock). - In a declaration clause the parentheses are optional:
uses net, clockanduses (net, clock)are the same. - Subsumption. A function value is accepted where a function type is
expected if its effects are a subset of the expected effects (
fs.readis a subset offs) and its error type converts to the expected one. A function that cannot fail is accepted where a failing one is expected. A pure function is accepted everywhere a function of the same shape is. - Effect variables let a higher order function pass through its callback’s
effects. Declare them in the type parameter list with the
Effectskind:
An effect variable is instantiated at each call from the argument’s effects, and may be empty. When one effect variable is the effects of several function parameters, it is the union of the effects of those arguments (decision 0432). Elsewhere (an effect argument of a type,pub fn run_pool[T, R, E, fx: Effects]( jobs: List[T], workers: Int, f: fn(T) -> R ! E uses fx, ) -> Report[R, E] uses fx { ... } pub fn retry[T, E, fx: Effects](clock: Clock, f: fn() -> T ! E uses fx) -> T ! E uses (clock, fx) { ... }Cache[K, V, fx]) the variable is bound exactly, and a conflict is an error. - A type’s effect arguments are exact, with one exception (decision
0582): an interface’s effect parameter that its methods name only in their
usesclauses (never in a parameter, result or error type) is covariant, so a value ofCred[fs.read]may be used as aCred[(fs.read, proc)](assignment, argument, return,push): its methods perform at most what the wider type allows. It never narrows. The widening is at the converted value’s own type only:List[Cred[fs.read]]is not aList[Cred[(fs.read, proc)]]. Every other effect argument must match exactly (XO0701). - Structs may take effect parameters (
struct Cache[K, V, fx: Effects]), and effect sets may be written as type arguments (Cache[Int, Item, net.dial]). - Effect arguments may be omitted. Writing
Cache[Int, Item]leaves the effect arguments to inference. Either all of a type’s effect arguments are written or all are omitted.- In a local binding they are inferred from the value.
- In parameter and receiver types they become implicit effect variables of
the function. These count as declared: the function may perform them
without naming them in
uses. When a method is checked against an interface, they take the interface method’s arguments (section 2.4). Such a variable is abstract, so a closure capturing the value cannot have a function type that fixes its effects (fn(...) uses net.dial): XO0701 then names the parameter, andxo fixwrites the argument as no effects (sql.Db[()], what a value performing none has), then on each caller passing the value along. - In result and error types they are inferred from the function body, so a
constructor
fn new_cache(...) -> Cache[Int, Item]returns the effects of the loader it was given. - In a struct field they become implicit effect parameters of the struct.
- A non pub function with a
usesclause is checked against it. Test blocks may perform any effect on theiros.
6.3 Capability values
Effects describe what a function may do. Capability values grant the authority
to do it. The only source of capabilities is main:
fn main(os: Os) ! {
let srv = http.server(os.net.listen(":8080")?, router(os.net))
srv.serve()?
}
Os has fields net: Net, fs: Fs, clock: Clock, rand: Rand, env: Env,
proc: Proc, stdio: Stdio, and tasks: task.Group (program lifetime task
group, core 7.1). Each capability type is a predeclared interface,
so test fakes and attenuated versions satisfy it. Their methods are in
spec/std.md.
os.fs is rooted at the filesystem root and accepts absolute paths
(/home/me/a, C:/data). Relative paths given to os.fs resolve against the
working directory. Capabilities can be attenuated. An attenuated capability
has the same type; operations outside its authority fail with a Denied
error. Inside a sub capability, paths are relative to its root:
let uploads = os.fs.sub("/var/app/uploads").read_only()
let api = os.net.only(["api.example.com"])
let config = os.env.only(["APP_PORT", "APP_DB_URL"])
let tools = os.proc.only(["git"])
Net.only, Env.only, and Proc.only (std.md 3.2, 3.5, 3.7, decision
0156) narrow the network to hosts, the environment to variables, and
processes to commands; a denied operation fails before any effect.
xo audit (10.1) lists the attenuations whose arguments are constants
and whether each capability passed into a dependency is attenuated.
A program narrows what code may do by building an Os with a literal
(decision 0307). A field the literal leaves out is that capability’s
no-access value (decision 0585): fs denies every read and write
(read_only().write_only()), net, env and proc admit nothing
(only([])), secrets holds no store (Secrets.only([]), decision 0584: every
store answers None), and stdio drops output and has no input and no terminal.
clock, rand and tasks have no no-access value and must be written
(XO0403 otherwise). A written field is the value given, so leaving a
field out can only take authority away; adding a field to Os never
breaks a literal:
let plugin_os = Os{fs: os.fs.sub("plugins").read_only(), clock: os.clock, rand: os.rand, tasks: os.tasks}
// plugin_os.net, .env, .proc deny; plugin_os.stdio is silent
A library cannot open a file or a socket unless it is handed a capability. A dependency’s reach is visible in its signatures.
6.4 Tests and fakes
See section 9.2: every test block receives os: TestOs with fake capabilities.
6.5 Real-time functions [native enforcement]
const TAPS = 32
struct Filter { coeffs: List[Float], window: List[Float], pos: Int }
fn (var f: Filter) step(x: Float) -> Float uses realtime {
f.window[f.pos] = x
f.pos = (f.pos + 1) % TAPS
var acc = 0.0
for i in 0..TAPS {
acc += f.coeffs[i] * f.window[(f.pos + i) % TAPS]
}
acc
}
uses realtime on a function or method declaration marks it
real-time (decision 0133). realtime is written in the uses clause but
is a discipline, not an effect: it is not part of the effect set and
plays no part in subsumption. A real-time function has a declared effect
set like any function with a uses clause; the only effect it may declare
is ffi. realtime in a closure, a function type, an interface method,
or a test is XO0702. In a real-time function, including its contract
clauses:
- No allocation (
XO1401): no List, Map, or Set literal, string interpolation,+or+=on Str, List, or Bytes, slicing, closure, store into a Map, or prelude method outside the bounded set: scalar methods of Int, the sized integers, Float, Rune, Duration, and Time;len,is_empty,get,first,last,contains,index_of, andset(alsoxs[i] = v) on List;len,is_empty,get,contains,get_or_faulton Map and Set;is_some,is_none,ok,err,or_faulton Option and Result; the Atomic operations;lenon Str, Bytes, Chan, Buf, and the builders;contains,starts_with,ends_with,findon Str. The arguments offault(...)are exempt. - Bounded loops (
XO1402): every loop is aforover a range with constant ends or hasbound N(3.5).for (i, x) in xs.indexed()does not build the pairs and is allowed with a bound. - Known callees (
XO1403): calls go only to real-time functions, the bounded prelude methods, and functions of ause cmodule, never to a function value or an interface method. - No recursion (
XO1404): the calls among real-time functions form no cycle, so the stack depth is bounded. - No blocking (
XO1405): no channel operation (orforover a channel), Mutex,scope,select, task,dbg, capability call, or declared effect other thanffi.
Faults stay allowed (they are bounded checks); a fault ends the section.
Initialization is all code that is not real-time: it allocates
freely and prepares what real-time code writes in place, typically
Lists of a fixed length written by index (List.set is in place on a
List nothing else references, decision 0046).
Real-time sections [native builds]. A call from code that is not real-time to a real-time function is a real-time section. Inside it the native runtime:
- defers frees: a reference count that reaches zero puts the value on a
per-thread queue of 256 entries instead of freeing it (and what it
holds); the queue is freed when the section ends. A full queue frees
at once (counted in
XO_RTSTATS=1output asrt_overflow). - counts allocations; a section that allocated faults when it ends with
XO-F007(real-time function `f` allocated n times), which catches what the rules cannot see: a shared List copied on write, the box of a recursive enum, a defaulted field with a non-empty collection (an empty[]allocates nothing until its first push on the native backends).
The Go backend checks the rules and the loop bounds; it has no sections.
7. Concurrency [P1 basic, P2 deterministic]
7.1 Scopes and tasks
let page = scope s {
let a = s.spawn(fn() { fetch_user(db, id) })
let b = s.spawn(fn() { fetch_orders(db, id) })
render(a.await?, b.await?)
}
- A scope is an expression; its value is the body’s value.
s.spawn(f)starts a foreground task and returns aTask[T, E]handle. The handle may be discarded.s.spawn_background(f)starts a background task (a daemon such as a cache evictor). Background tasks are cancelled automatically when the body finishes.t.awaitwaits for a task and yieldsT ! E.- Exit rules. When the body completes normally, the scope cancels its
background tasks and waits for all tasks to finish. When the body exits
early (
return,?,break, error, or fault), the scope cancels all tasks and waits for them to unwind. No task ever outlives its scope. - Child failure. If a task fails with an error that is not consumed by an
await, or faults, the scope cancels everything else and the error propagates out of the scope as if by?: it must convert to the enclosing function’s error type (errorXO0801otherwise). A task that fails only because it was cancelled does not count as a failure. s.cancel()cancels all tasks of the scope (not the body).- Task groups.
s.group()returns atask.Group, a handle that can be stored in a struct or passed to functions so code can start tasks later (g.spawn(f),g.spawn_background(f)). Tasks in a group belong to the scope that created it and never outlive it. A value of a type that contains aGroupcannot be returned from, or stored outside, the creating scope (errorXO0802).mainreceivesos.tasks, a group that lives for the whole program, for services such as caches that refresh in the background. Tasks started on a group must not fail with an error the creating scope cannot convert (XO0801); a failing group task fails that scope. When the group’s origin is not visible (it came from a field or parameter), a task started on it must not fail unless its handle is bound and awaited. - The escape rule applies to values derived from that scope’s
s.group().os.taskslives for the whole program and may be stored anywhere. - A task’s error is consumed only if its handle is bound with
letand awaited. - Handles from an enclosing scope may be awaited inside
task.with_timeout. - Closures passed to
spawncapture by value. Move only values are moved. - The scope tree is the context: deadlines, cancellation, request ids, and
trace spans flow down implicitly. There is no
ctxparameter. - Deadlines are set with
task.with_timeout(seespec/std.md), which runs a closure in a child scope and returnsT ! Timed[E].
7.2 Cancellation
- Cancellation is sticky: once a task is cancelled, every cancellation point it reaches reports cancellation.
- Blocking operations are cancellation points: effect calls, channel
operations,
await,clock.sleep,Mutex.withandMutex.with_readwhile waiting. - A blocking operation that already returns a
Resultreports cancellation as itsCancelederror variant (http.ClientErr.Canceled,FsErr.Canceled, …). Code may map it to its own error, for exampleFetchErr.Cancelled, but cannot continue doing blocking work. - A blocking operation that cannot fail (
clock.sleep,ch.send,ch.recv,t.awaitin a cancelled task) unwinds the task immediately, runningdeferblocks. clock.sleep_or_cancel(d) -> () ! ClockErris the sleep that reports cancellation as a value: when the task is cancelled before or during the sleep it returnsErr(ClockErr.Canceled)instead of unwinding, so code that must return its own error (a retry loop’sFetchErr.Cancelled) can. Cancellation stays sticky: the task’s next cancellation point reports it again. Inside deferred code it sleeps in full, likesleep(decision 0088).- Reading standard input (
stdio.read_line,read_all,lines) is a cancellation point also while it waits for input: a cancelled reader getsErr(IoErr.Canceled)at once, and no input is lost (a line that arrives later goes to the next read). task.is_canceled() -> Boolreports the current task’s state without blocking.- Under a resource budget (
task.with_budget, std.md 7, decision 0173) every loop iteration and every call into user code is a cancellation point too: a passed ceiling cancels the budgeted scope, and its tasks unwind at their next one. deferblocks run shielded (3.5).
7.3 Channels
let ch = Chan[Job].new(cap: 64)
ch.send(job) // blocks when full
let j = ch.recv() // Job? : None when closed and drained
ch.close()
select {
j = jobs.recv() => handle(j)
results.send(r) => count += 1
after 5s => log.warn("idle")
}
ch.try_send(x) -> Boolandch.try_recv() -> T?never block.- A
selectreceive armv = ch.recv() => ...bindsvto whatrecvreturns, aT?: a closed and drained channel’s arm is ready at once and runs withNone(sojin the example is aJob?; a loop over aselectstops onNoneitself). for x in ch { ... }receives untilchis closed and drained; each receive is a cancellation point.afterarms require theclockeffect.- Sending moves move only values.
7.4 Deterministic scheduling [P2]
Every xo test runs its tasks on a deterministic scheduler, seeded with
--seed=N (default 1): one task runs at a time, and at each scheduling point
the next task is chosen from the seed, so the same seed always produces the
same interleaving. Scheduling points are channel operations (including
select, try_*, and close), await, Mutex.with, Mutex.with_read,
Semaphore.with,
Once.get, spawn, Atomic operations, sleep, task.is_canceled(),
task.stop_requested(), and effect calls. Failing seeds are printed and can
be pinned with test "x" seed 8812.
xo test --explore=N reruns each concurrent test that passed under N further
seeds and reports the first failing seed. xo run --seed=N (or XO_SEED=N for
a binary the Go backend built, or a native one built with --seed) uses
the same scheduler with the real clock; interleavings
are then reproducible as long as timer and I/O timing does not decide them.
An Xo function that Go calls on a goroutine of its own (use go, for
example sync.WaitGroup.go_) runs as a scheduled task: Go’s goroutine waits
until the scheduler admits the call, which happens only at a scheduling
point after Go’s goroutines have settled, in a fixed order (by callback,
then arguments), so the seed decides how callbacks interleave. Once an Xo
function has crossed into Go, the return of every Go call is a scheduling
point. Go code woken by a Go timer or I/O of its own is not reproducible
(decision 0073).
Native builds (--backend=arm64, amd64 and llvm) run tasks on the real
scheduler, on a pool of threads, so a native program whose output depends on
how its tasks interleave may print differently from run to run. xo run --seed=N and xo build --seed=N build the program for the deterministic
scheduler instead (decision 0350): one thread runs every task, and at each
scheduling point a generator seeded with N (XO_SEED=N when the built program
runs, default 1) picks the next ready task, so one seed gives one
interleaving. Its scheduling points are the runtime’s: channel operations,
select, Mutex.with and with_read, spawn, await, Atomic operations
and task.is_canceled(), and every wait; effect calls are not yet. A program
built without --seed ignores XO_SEED. Native xo test uses the
deterministic scheduler when given --seed=N or --explore=N, or when a test
pins its seed (test "x" seed N): each test runs with its own seed, else
--seed’s, else 1, and --explore=N runs a test without its own seed under
seeds 1 to N until one fails, reporting how to reproduce and pin it. The
seeds that expose a race differ from the Go backend’s (its generator and
scheduling points differ). Other native tests still run on the thread pool
until decision 0350’s stage 3; xo run --record still uses the Go backend.
The rest of core 7 means the same on every backend.
7.5 Process signals and graceful shutdown
Shutdown has two phases, so programs can finish queued work without fighting sticky cancellation:
- Stop requested. The first SIGINT or SIGTERM cancels nothing. It sets
the program’s stop state:
task.stop_requested()returnstrueand the channeltask.stopping()is closed, so loops canselecton it. Servers started withservestop accepting new connections and finish in flight requests. Readers stop reading: a read of standard input that is blocked, or starts later, returnsErr(IoErr.Canceled)(decision 0088). Workers drain what is queued. - Cancel. When
main’s body has not returned after the grace period (default 30s, set withos.proc.set_grace(d)), or on a second signal,main’s root scope is cancelled as in 7.2: blocking calls unwind anddeferblocks run. A third signal exits immediately with status 130.
A program that ignores phase 1 behaves as before, only 30 seconds later; a
program that wants the old behavior calls os.proc.set_grace(0s).
fn reader(os: Os, queue: Chan[Str]) -> () ! IoErr {
defer queue.close() // workers drain the queue, then exit
while {
match os.stdio.read_line() {
Ok(Some(line)) => queue.send(line)
Ok(None) => return Ok(()) // end of input
Err(Canceled) => return Ok(()) // stop requested (or cancelled)
Err(e) => return Err(e)
}
}
Ok(())
}
A program can take SIGINT and SIGTERM over with os.proc.notify (std.md
3.7, decision 0407): while it is subscribed, that signal goes to its
channel instead of starting phase 1, and os.proc.request_stop() starts
phase 1 when the program chooses.
In tests, os.proc.signal_after(d) delivers the first signal to a program run
by testing.run_main; os.proc.signal_after(d) called again delivers the
next one.
Under testing.run_main, a third signal makes run_main return 130 after
main has unwound (the test process itself does not exit), and requests
handled in memory by a fake network observe the stop state but are not
cancelled by it.
8. Faults [P1]
A fault is a bug, not an error: overflow, out of bounds, failed contract,
failed Int32(x) conversion, evaluated hole, explicit fault("msg").
fault has type Never.
- A fault terminates the current task. Its scope treats it like a failed child
and cancels siblings. A fault reaching
mainexits the process with status 70 and writes a crash bundle (section 11.2). task.isolate(f) -> T ! Isolated[E]runsfin a child scope and converts a fault into a value.std/httpisolates every request and returns 500.- Every fault message includes the evaluated values:
index 7 out of range for List of length 5 at users.xo:41:18. - A fault reaching
mainis reported on standard error as one line,fault: MESSAGE at FILE:LINE:COL(and a detail line for a failed contract). Native builds follow it withtraceback:and a line per frame, innermost first,FUNCTION (FILE:LINE)down tomain(the line from the program’s DWARF line tables, decision 0239; inlined calls show the caller’s line), by default since 2026-10-22 (owner; a hardware fault’s report has its frames too, decision 0343);XO_TRACEBACK=0leaves the frames out. A build with no function symbols left (-s, or a program stripped after the link) printstraceback: (no function symbols: built with -s, or stripped)instead of frames it cannot name. WithXO_TRACEBACK=localseach frame is followed by its variables,NAME = VALUE(decision 0268: from the program’s DWARF, read at the fault;<unavailable>where the frame does not keep the value; numbers,Bool,Strtext, a list’s first elements (of any element type), structs’ fields, an enum’s variant with its fields, andOsby its type; a local declared at or after the frame’s line with no value yet is left out). - The native backends unwind a fault the same way (decision 0085: deferred
code, scopes, Mutexes, and references are released on the way); they
print the fault without its frames, write no crash bundle, and
Fault.framesoftask.isolateis empty there. - A hardware fault (an access violation, a bus error, an illegal
instruction, a trap) is not a fault: it is a bug below the language or
in C code behind
use c, and nothing unwinds. A native program on Linux, macOS or windows/amd64 reports it on standard error (decision 0343):fatal error: SIGNAL: TEXT (code N), withat address Afor SIGSEGV and SIGBUS (Windows:fatal error: EXCEPTION_NAME: TEXT (code 0xNTSTATUS, read|write|execute) at address Afor an access violation), then the build information’s line (build: xo VERSION, BACKEND, TARGET, id ID, debug|release (SETTINGS), decision 0354), the pc and the image’s load address, the registers, the frames’ pcs (frames:) and thetraceback:above; then the signal’s default action ends the program, with the same exit status and core file as without the report (Windows: the same exit code, the NTSTATUS; an exception C code’s own handler takes is not reported).XO_CRASH_REPORT=0turns it off;XO_CRASH_TIMEOUT(seconds, 5 by default) bounds the naming of the frames.XO_CRASH_FILE=PATH(Linux and macOS, decision 0520) appends both reports, this one and an uncaught fault’sfault:line with its traceback, to the file PATH as well as standard error; the file is opened at start and stays open. Sanitizer builds report through their own runtimes; windows/arm64 does not report yet.
There is no undefined behavior. Debug and release builds have identical
semantics; release builds may only disable contract checks that are explicitly
marked requires(debug) or ensures(debug).
xo build --releaseis a release build (decisions 0099, 0354): a preset of the settings below. Without it every setting starts at its debug value. Any setting can be given either way in any build (xo build,xo run,xo test), before or after--release; an explicit flag wins over the preset, and between two explicit flags the last wins. A bare--NAMEmeans on; booleans accepton|offandtrue|false.flag values debug release --debug-contractson, off on off --dbgon, off on off ( dbg(x)isx, 11.4)--error-argson, off on on (11.1) --debug-infoon, off, split on off --profile-supporton, off on off (XO_PROF, decision 0238) --trace-supporton, off on off (XO_TRACE, decision 0240) --optO0, O1, O2, O3 the LLVM split’s O2 --debug-contracts=offcompiles the clauses marked(debug)out on every backend,requires(debug) c else Eincluded (the function no longer returns that error); every other contract, every invariant, and every fault check stays. The other settings change what a build records or which diagnostic tools it carries, never what a program computes.--optapplies to the LLVM backend; with arm64 or amd64 it is a usage error, and the Go backend ignores it with a note.--debug-info=split(decision 0355) writes the debug information beside the program instead of in it: PROG.dSYM on darwin (matched by the Mach-O UUID), PROG.debug on linux (Xo’s ELF linker: a GNU build id in both files and a.gnu_debuglinkin the program); tracebacks,xo dev symbolize, debuggers and symbolizers find it there. It is an error on linux with a cc or clang link (use c,--ld=cc, the LLVM backend), on wasip1, and with the Go backend. A release build fails while an xo.work workspace overrides a required module (XO1308, 4.2); no flag overrides that.Every other build is a debug build:
xo buildwithout--release,xo run,xo test(whose contract fuzzing checks the debug clauses too), andxo replay, which rebuilds with the settings recorded in the program’s build information. Every binary records the effective value of each setting, native ones included (xo version -m BINARYprints them; a native crash report’sbuild:line names them).--ciis a gate, not a mode: it does not imply--release; a pipeline that ships the binary passes both.
9. Contracts and tests [P1]
9.1 Contracts
fn transfer(var from: Account, var to: Account, amt: Money) -> () ! TxErr
requires amt > 0
requires from.balance >= amt else TxErr.Insufficient
ensures from.balance + to.balance == old(from.balance + to.balance)
{ ... }
struct Account { id: Int, balance: Money } invariant balance >= 0
requires exprfaults on violation.requires expr else EreturnsErr(E)instead, which makes input validation declarative. A function may consist only of contracts and an empty body.ensuresmay referenceresult(the success value) andold(expr).invariantis checked after construction (including from defaults) and after everyvarmethod.- Contract failures print every sub expression’s value:
ensures failed: from.balance + to.balance == old(from.balance + to.balance) from.balance = 40 to.balance = 50 old(...) = 100 xo testfuzzes every function with contracts using generated inputs that satisfyrequires, and checksensures. Capability parameters receive seeded fakes. Contract clauses must be pure.
9.2 Tests
test "fetch missing user" {
let store = new_store()
expect(store.get(7)) == Err(LoadErr.NotFound(id: 7))
}
test "reverse twice" for xs: List[Int] {
expect(xs.reverse().reverse()) == xs
}
test "retries after 503" {
let calls = Atomic[Int].new(0)
os.net.handle("GET https://api.test/x", fn(_req) {
if calls.add(1) < 3 { http.empty(503) } else { http.text(200, "ok") }
})
let body = get_with_retry(os.net, os.clock, os.rand, "https://api.test/x")?
expect(body) == b"ok"
expect(os.clock.sleeps()) == [100ms, 200ms]
}
testblocks may live in any file. They are compiled only byxo test.xo buildandxo run(with--watchtoo) do not read_test.xofiles at all (decision 0348): their declarations, errors, anduselines do not exist for a build, so a helper declared only there isXO0601in production code and a test-only import is never fetched or bound.xo test,xo check,xo vet,xo fix, the language server, and the lookup tools read them.xo buildandxo runskip inlinetestblocks the same way (decision 0389): a block is neither declared nor type-checked, so an error in it does not fail a build, a helper or closure declared in it does not exist for the build, and a build does not loadstd/testingfor it.xo test,xo check,xo vet,xo fix, and the language server check every test block.- Where tests live (a note, not a rule). Both places have the same access
to the module’s private names; they differ in what else sees the edit:
- Inline
testblocks keep a test next to the code it checks, so a reader sees it as an example and an edit to the code updates it in the same place; they suit small modules, examples, and one-file tools. - A
_test.xofile keeps tests out of the files the program is built from. A tool that rebuilds or restarts on file changes (a file watcher, a cached build of the program keyed by its source files) then skips test-only edits by name, which it cannot do for an inline test. Large modules and long running servers usually keep their tests there. In the Xo repository, tests understd/andcompiler/live only in_test.xofiles (decision 0262), because the cached xo is keyed by those sources.xo run --watchneeds no such exclusion by name: it compares the built program, so an edit that does not change the binary (a test, inline or not, a comment) never restarts it (decision 0267).
- Inline
- A test body has type
() ! Error, so?fails the test with the error. opt?on an Option directly in a test body (at any depth of blocks,if,match, and loops in it, property tests included) yields the value or fails the test asopt.or_err("missing value: opt")?would,optbeing the source text of the operand (decision 0347):
An Option’stest "finds the user" { let u = store.find(7)? // --- FAIL: ... then: error: missing value: store.find(7) expect(u.name) == "Ada" }?and a Result’s?in the same test both fail it; their error types are not unified. A?inside a fn literal written in a test keeps that function’s own rules (2.5), and a helper function in a_test.xofile is not a test body:opt?there is stillXO0204orXO0205, with a note. A property test’s missing value is a failed case, shrunk like any other.- Inside a test block, and anywhere in a
_test.xofile forexpectandtesting, three names are predeclared:os: TestOswith fake capabilities (in memory filesystem, virtual clock, seeded rand, network that fails unless a handler is registered, captured stdio, fake env and proc). Fakes have extra control methods such asos.clock.advance(d)andos.fs.fail_next(...); seestd/testinginspec/std.md. Each fake satisfies the matching capability interface.expect(x)followed by any comparison:expect(a) == b,expect(n) <= 3.expect(cond)alone asserts aBool.testing, thestd/testingmodule.
- The virtual clock auto advances: when every task in the test is blocked, time jumps to the next timer, so sleeps and timeouts finish instantly.
foron a test makes it a property test over generated values.- Failures found by fuzzing or property tests are shrunk to a minimal input.
A shrunk contract fuzz failure is written as a permanent test to
regressions_test.xoin the module itself (so it can call private functions), namedregression: <function> (seed N), but only if the module still type checks with it; otherwisexo testsays why and the seed reproduces the failure. Shrunk property test failures are reported with their seed and input. - Real capabilities require
test "name" uses net { ... }andxo test --real;osthen holds real capabilities for the listed effects. Without--realsuch a test is skipped, and the summary line names every skip’s reason (ok: 1 passed, 0 failed, 1 skipped (1 uses net: run with --real); decision 0437). - The summary line counts the written tests (test blocks and property
tests); the generated contract checks (
contract fuzz: MODULE.F) are counted apart, in a note on the same line, with or without-v:FAIL: 0 passed, 1 failed, 0 skipped (contract fuzz: 1 function ok), or(contract fuzz: 3 functions: 2 ok, 1 failed). A failing contract check makes the run fail as a failing test does. A--- FAILline names the seed ((main.xo:3:1, seed 8812)) for a property or contract test, whose inputs come from it, and for any test run with a seed other than the default 1 (pinned,--seed,--explore); a plain failing test run with the default seed has only its location (owner, 2026-11-10). - A test run sees only the fakes unless
--realis given, so its result depends only on the test binary and the run’s flags: a passed native run of a binary that links nouse goor C binding may be replayed from the cache with(cached)on its summary line, and--count=1or XO_TEST_CACHE=off runs the tests (decision 0439). - Each test, and each case and shrinking step of a property test, may run
for
xo test --timeout=Dof real time (default 60s; 0 for no limit). One that does not finish fails withthe test did not finish within D of real timeand its log records, and the next test runs; on the native backends the harness kills the test’s process (decision 0235). The virtual clock does not count: only real work (a loop that never yields, a real capability that never answers) reaches the limit.
10. Toolchain and diagnostics [P1]
10.1 Commands
| Command | Purpose |
|---|---|
xo build [--targets=all|os/arch,...] [--no-gc] [--tzdata=embedded|system] [--ci] [--release] [--debug-contracts|--dbg|--error-args|--profile-support|--trace-support=on|off] [--debug-info=on|off|split] [--opt=O0..O3] [--stamp NAME=VALUE]... | Build static binaries; --stamp (repeatable, also xo run) sets a const NAME: Str = "..." of the main module to VALUE for this build, else XO1501, and is recorded in the build information so xo replay rebuilds the same program (decision 0165); --no-gc on a native backend without a garbage collector (below); --tzdata=system reads time zones from the host instead of embedding the ones the program uses (std.md 13); --ci fails before building on an unformatted file (10.5) or a dbg left in code (11.4); --release is the release preset (8, decision 0354): requires(debug) and ensures(debug) compiled out, dbg off, no debug information, the native runtime’s profiler and execution trace recorder left out, --opt=O2; each of those settings has its own flag, in any build, that wins over the preset; --error-args=off drops parameter values from error frames (11.1); -s leaves debug information and local symbols out of a native binary. Builds are debug builds otherwise, and xo run and xo test always are |
xo run [DIR] | Build and run for the host the program in exactly DIR (default .), never one below it (decision 0345); --profile=cpu|heap|cpu,heap (XO_PROF, decision 0238) and --trace=FILE (XO_TRACE, decision 0240) on a native backend; --watch [--grace=D] rebuilds after a source change and restarts the program only when the built binary changed (its builds record no source digests in the build information, so an edit that changes no code, such as a comment that moves no line, leaves it running; xo version -m of such a binary shows - for each source; a restart sends SIGTERM, up to --grace, default 5s, then SIGKILL; decision 0267). A stop request xo run gets (SIGINT or SIGTERM, 7.5) is sent on to the program as SIGTERM when standard input is not a terminal; on a terminal, Ctrl-C reaches the program through the process group |
xo trace FILE [--json OUT] [--text] | The execution trace a native program wrote under XO_TRACE as Chrome trace event JSON (Perfetto) and a summary (decision 0240) |
xo check [--backend=go] [--support[=false]] [--support-all] [--fix] | Parse and type check all targets, no codegen, by the rules of the backend a build uses: the native backends’ by default (use c is valid), the Go backend’s with --backend=go; when the check finds no error, the native backends’ support check (XO1201) follows by default, lowering every function of the named directories’ modules, a library’s too, so a use go program fails it as a native build would (decision 0523); a walk (DIR/...) runs it only with --support (then on every walked module), --support=false skips it, --support-all runs it on every module of the workspace; --fix first applies the machine fixes (below) |
xo test [--seed=N] [--explore=N] [--cases=N] [--timeout=D] [--real] [--watch] | Tests, contract fuzzing, property tests (--cases per property test and fuzzed function, default 100; --timeout the real time each test may take, default 60s, 0 for none, 9.2); deterministic scheduling. --watch reruns, after each change, only the tests the change reaches (decision 0267). Doc comment examples are [P2] (1.2) |
xo dump <pid> | Task tree of a running program (11.4) |
xo mcp | Model Context Protocol server over stdio: check (with an optional fix), query, edit, explain, fmt, test, build tools returning compact JSON |
xo lsp | Language Server Protocol server over stdio for editors: diagnostics with quick fixes, hover, definition, references, rename, document symbols, semantic tokens, formatting |
xo serve | Resident checker on a unix socket; xo check, xo query, and inside a module xo def, refs, type, symbols and doc use it automatically when it answers, reusing an answer until a file under the module root or std changes |
xo fmt | Canonical format, no options |
xo repl [--eval=TEXT] [--session=FILE] [--json] [--effects=...] [--keep] | An interactive session (decision 0572): each entry is checked, built and run as part of a session program; definitions persist, a plain binding carries to later entries as a pinned literal (its effect does not run again), a var keeps its latest value; :type, :doc, :undo, :reset, :quit; --eval runs entries and exits, --json speaks a line protocol for agents. Experimental while the decision’s later stages are open |
xo fix [--dry-run] [--from=draft-0.N] [--edition=preview] | Apply all machine fixes until none apply, xo.mod and xo.work lines included (edition 2026 becomes edition preview, xo 2026 becomes xo preview, XO1315); --from migrates code written for an older draft (interpolation, prelude variants, let _ = discards, scope timeouts, Map index reads) |
xo vet | Advisory checks, never errors (a directory, a .xo file’s findings, a std directory checked as std, or --std-module=M; decision 0289): checker warnings plus XO0207 (?? precedence trap), XO0208 (each ignore_err with its reason), XO0530 (a field’s large payload bound and shared, decision 0263), XO0531 (a large parameter only stored while each caller passes its last use, decision 0263), XO0532 (a Map value changed through a copy and stored back, Map.update instead; decision 0266), XO0534 (a task capturing a value of 32 or more heap fields, core 5.1; decision 0294), XO0703 (declared effect never performed), XO0901 (dbg left in code), XO0902 (tls.Verify.None, decision 0281), XO0903 (an Fs, Net, or Proc error defaulted away by .ok() ?? d or Err(_) => <empty>; // xo:allow XO0903 <reason> silences one), XO0904 (an embedded file git ignores or does not track; decision 0304), XO1103 (use of Go packages per module), XO0535 (${x.debug()} written as ${x:?}, with the fix; decision 0296), XO0536 (a list element copied out, changed, and stored back; decision 0294), XO0906 (a four line match that x ?? return v or r ?? e => return v writes shorter; decision 0321), XO0538 (a closure’s capture written after its creation). --cost (decision 0327) builds the program up to its reference counting and adds notes on costs its source does not show: XO0907 (a loop that copies a map’s entries first), XO0908 (an element counted up and down each iteration, or by a prelude callback walk such as xs.any(fn ...) over elements holding heap memory), XO0909 (a list updated in a loop while a holder made in the same iteration keeps it shared, so each update copies it), XO0910 (a value over 8 words copied into a closure, or out of a collection into an Option in a loop), XO0911 (a view of a parameter’s text or bytes made in a loop, or an element of its split or lines, stored in a field or a returned collection: it keeps the whole input alive; clone() it, decision 0330). |
xo def, xo refs, xo type, xo doc NAME, xo symbols | Agents’ lookups on xo lsp’s engine (decision 0261): def NAME, refs NAME, type FILE:LINE:COL, doc NAME (a name, or a module path and name: std/tls.client), symbols [DIR] [--pub] (the directory’s own declarations, private ones too); a name in any form xo query def takes, std and runtime modules included (decision 0289); --dir (a workspace root checks the modules under it); text at a terminal, --json or --text to choose; exit 0 with an answer, 1 for no match, 2 for usage |
xo query <kind> ... | Semantic queries (10.3): type, def, callers, effects, holes, api, imports, deps |
xo edit <op> ... | Semantic edits (10.4) |
xo replay, xo dump | Debugging (section 11); xo why and xo debug are [P2] and not implemented yet (11.3, 11.5) |
xo doc | Docs from doc comments; xo doc std lists the std modules this xo ships, a line each |
xo clean -cache [-n] | Remove every cache under <user cache>/xo (build directories, the native back end’s cache, GOCACHE, test binaries, watch builds, xo dev outputs, the test infrastructure’s caches) and print the bytes freed per cache; -n prints what it would remove and removes nothing. Never touches anything outside <user cache>/xo; the module cache and the prebuilt seeds stay; an entry whose build lock a running process holds is left. xo clean without -cache is a usage error |
xo debug [--batch] [--json] [--timeout=DUR] [-c CMD]... PROG [ARGS], xo debug --dap | Run a native program with its debug information under xo’s own debugger (11.5; macOS arm64, Linux and Windows amd64): break, run, continue, step, next, finish, print, locals, backtrace, frame, threads, quit; --json gives the protocol of 11.5, --dap the Debug Adapter Protocol for editors |
xo get [--accept-effects] <path>[@version], xo mod tidy, xo mod accept-effects [<path>...], xo vendor, xo mod clean, xo mod proxy serve, xo mod sumdb keygen, xo mod sumdb serve | Dependencies (4.2, 4.3): require a module version, tidy xo.mod and xo.lock, record wider effects of dependencies in xo.lock (decision 0156); xo get checks each newly required version in full once (xo check, recorded per version in the module cache) and warns about its errors, since a build checks a dependency’s bodies only as it reaches them (decision 0517; XO_GET_CHECK=0 skips it), copy dependencies into vendor/, empty the module cache, serve a module cache as a module proxy (decision 0126), make a checksum log key and run a checksum log (decision 0124). Every command takes --offline and --workspace=off |
xo audit [--json] [--no-gc] [<dir>] | Supply chain report (decision 0156): per dependency its effects, its xo.lock effects line (ok, widened, narrowed, unlocked), its ceiling, and its escape hatches (use c, impure use go) with the vouches covering them; this module’s attenuations (only, sub, read_only, write_only, cwd) with constant arguments, the capabilities it passes into dependencies and whether each is attenuated, vouches that match nothing, and the check’s diagnostics. JSON with --json or when stdout is not a terminal (an agent piping it gets JSON), text otherwise. Exit 1 when the check has errors |
xo init <path>, xo publish [--check] | Start a module (xo.mod, xo.work gitignored); check a release against the previous tag (4.2) |
xo explain <code> | Long form explanation of a diagnostic |
xo version [--json | -v], xo version -m [--json] BINARY... | The toolchain’s version and host target; --json and -v add what xo was built from (decision 0264); -m prints the build information a program built by xo carries on every backend (decision 0354): the xo, backend and target, its ID and directory, every effective setting of 8 (and --opt), the stamps, and its sources’ hashes, as go version -m does for Go |
xo bind [--json] <Go path>..., xo bind --c [--link x]... [--uses none|e,...] <header>... | Generate the bindings of Go packages (use go, 4.4) or C headers (use c, 4.5) into the project’s binding cache |
The commands that report diagnostics or results accept --json: parse,
check, build, test, fmt, fix, vet, query, edit (always
JSON), doc, explain, bind, and audit. run, replay, dump, serve, and
version print the program’s or the tool’s own output. When stdout is not a
terminal, JSON is the default for query.
What a build checks (decision 0517). xo build and xo run check
every declaration of every module, and every function body of the
modules they are given (the root modules); a dependency’s function body
is parsed and checked when the build reaches it. A dependency function
the program never calls is not checked by the build, so a type error in
it does not fail the build. Its declared effects and capabilities are
checked at every call, and a dependency’s non-pub method that another
module may call (a prelude interface’s display or debug, 2.4) is
always checked. xo check, xo test, and xo vet of a module check all
of its bodies, and xo get checks each newly required version in full
once (above). XO_DEP_LAZY=0 makes a build check every body.
Help and usage errors. xo help lists every command with a one line
purpose; xo help <command>, and -h or --help anywhere before --
(for xo run, before its directory), print that command’s usage on
stdout with exit status 0. xo alone prints the command list on stderr
and exits 2. An unknown flag, a missing argument, or an unknown command
is a usage error: the error and the usage on stderr, exit status 2.
Directories and DIR/.... A directory argument means that
directory alone (decision 0345, superseding 0210’s implicit walk):
check, vet, doc, test, build, and audit take the module in
it (plus the modules it imports; check of the xo.work workspace’s
own directory takes every module of the workspace, decision 0511), and fmt, fix, and parse its own .xo
files. A directory with no .xo file is an error that names DIR/....
Only the package pattern DIR/... (./..., cmd/..., accepted by
check, test, build, vet, doc, fmt, fix, parse, audit)
covers the directories below DIR: every directory with .xo files at or
below it (one module each, or one program for build and test),
or for fmt, fix, and parse every .xo file below it. Every such
walk skips directories named testdata or vendor (with or without
modules.txt) and names starting with . or _, as the go command
does, so a deliberately broken directory is kept out of ./... by its
name; vendored code is checked only when its directory is named. A DIR/... walk stops past 6,000 .xo files or 60,000 directory
entries with an error naming the limit, so xo build /... or
xo check $HOME/... refuses. A DIR/... with no .xo file at or below
DIR (with the skips above) is an error, xo CMD: DIR/... matched no directory with .xo files, exit status 1. Other forms (... alone,
a/.../b) are usage errors (decision 0210).
xo run takes one directory (. when none is given) and runs the
program in exactly that directory: it never looks below it, since
running code found by walking would run whatever a directory tree
holds. A directory with no .xo file or no main is an error, whose
note lists the subdirectories directly below that declare main, as a
hint. A .xo file names its directory: xo run DIR/main.xo runs the
program of DIR, every file of it (a module is a directory, 1.1).
xo run DIR/... and any other pattern are errors.
Check and fix. xo check is read only. xo check --fix first
applies every unambiguous machine fix, the same set xo fix applies
(without --from), round after round until none applies, reformats the
files it changed, and then reports the diagnostics that remain, with the
exit status of xo check on them. Its JSON adds applied, the list of
fixes made ({file, line, rule, title}, rule being the diagnostic
code); plain xo check --json has no applied field. This is the agent
loop’s check: an agent runs xo check --fix and then xo test, so a
diagnostic with an exact fix never costs a run (decision 0096). The MCP
check tool takes fix: true for the same.
Backends. xo build, run, and test compile natively by default
(decision 0248): the arm64 backend on arm64 hosts, the LLVM backend (which
needs clang) otherwise. --backend=go compiles through the Go toolchain
and is required by a program with a use go package; with no --backend
such a program is a usage error naming it. The flags only the Go backend
has (--hybrid and xo run --record) choose it when no backend is
given; xo run --seed, xo test --seed and xo test --explore build
natively for the deterministic scheduler (7.4, decision 0350). --race keeps the
native backend where a ThreadSanitizer runtime ships for the target
(darwin/arm64, darwin/amd64, linux/arm64, linux/amd64, windows/amd64)
and otherwise
takes the LLVM backend’s (decision 0273 addendum). Contract fuzzing (9.2) runs on every backend
(decision 0250): the same targets, cases, and seeds, the same tests named
contract fuzz: MODULE.F (which --run matches like any test name), and
the same regression tests; a target whose generated native test does not
check is skipped and counted per module (MODULE: contract fuzzing needs --backend=go: N contracts not fuzzed, the reason under -v). xo dump
(11.4) works on every backend (decision 0251).
Builds without a garbage collector. xo build --no-gc (also xo run,
xo test, and xo check) builds on a native backend whose memory is
reference counted instead of collected: arm64 on darwin/arm64 and
linux/arm64 hosts, LLVM otherwise; --backend=llvm, --backend=arm64, or
--backend=amd64 (Xo’s own x86_64 backend for linux/amd64, decision 0254)
picks one, and --backend=go with --no-gc is a usage error. After type
checking and before any code generation, a check reports every construct,
std API, or effect the native backends do not support as error XO1201 at
its site, naming the feature and saying whether support is planned (build
without --no-gc until then) or impossible (code from a use go package
needs Go’s runtime). A program the check accepts builds; the check is
derived from the native code generator itself, so the two cannot disagree.
xo check runs the same check without building, by default (decision
0523; every function and test block of the named modules, a library’s too). Native builds have their own
deterministic scheduler for --seed and --explore (7.4, decision 0350);
recording (--record) is the Go backend’s only (decision 0083). xo test --no-gc builds a
native test binary and runs each test in a process of its own against the
fakes of 9.2 (virtual clock, seeded Rand, fake environment, streams, and
network, MemFs, FakeProc, os.tasks) with the same report as the Go
backend; a fault fails only its test.
Property tests run there with the Go backend’s cases and shrunk inputs
(one process per case, decision 0120), --real gives real capabilities
for the declared effects (a test declaring clock, net, or proc runs
on the real clock there), contract fuzzing (9.1) is reported as skipped
(decision 0085), and error
traces are recorded natively but printed only in main’s error report
(decision 0104), and fault frames are not recorded natively.
Hybrid builds (deprecated). Since 2026-10-22 (owner) --hybrid is a
plain Go backend build that warns that it is deprecated and will be
removed: compiler/arm64 has no Go assembler mode, so nothing below
happens. As decision 0084 described it, xo build --hybrid (Go backend)
compiled the hot leaf
functions of the main module (a loop over Int, Float, Bool, and
Lists of those or of structs of Int and Float fields, with no
allocation) to native assembly linked into the Go program; everything
else, and every program the native backends cannot lower, stays Go.
Behavior is the Go backend’s, faults included, except that fault frames
omit the assembly functions and Float results may differ in the last bit
where the Go backend fuses a multiply and an add (decision 0084). Loops
in assembly yield to the scheduler and the garbage collector as Go code
does (decision 0131).
10.2 Diagnostic format
{
"code": "XO0201",
"severity": "error",
"message": "result of `fetch_user` is not handled",
"span": {"file": "api/users.xo", "line": 18, "col": 3, "end_line": 18, "end_col": 24},
"notes": [{"message": "`fetch_user` can fail with LoadErr", "span": {"file": "users/fetch.xo", "line": 4, "col": 1}}],
"fixes": [
{"title": "propagate with ?", "edits": [{"span": {"file": "api/users.xo", "line": 18, "col": 24, "end_line": 18, "end_col": 24}, "replace": "?"}]}
]
}
- Codes are stable forever within an edition.
- Codes are grouped:
01xxlexical and naming,02xxerrors and results,03xxmatch,04xxtypes and generics,05xxmutation and moves,06xxresolution,07xxeffects,08xxconcurrency,09xxholes and contracts,10xxplatform,11xxGo interop,12xxnative builds without a garbage collector (XO1201: not available with--no-gc, planned or impossible; 10.1). Every code is listed in 10.6. - The compiler reports all errors it can, not just the first, and never
cascades: a bad expression has type
<error>and suppresses dependent diagnostics. - Habits from other languages (decision 0087). Code written with the
syntax or library names of Go, Rust, TypeScript, Python, Swift, or
Kotlin gets one diagnostic per habit that names the habit and the Xo
form, with a machine fix when the rewrite is unambiguous, and checking
continues as if the Xo form had been written:
- Syntax that the grammar would otherwise reject with a generic code
(
XO0160,XO0168,XO0172,XO0175) is errorXO0177(syntax from another language): for examplefunc,x := v,let mut,T: Hash + Eq,Vec<T>,[]T,var xor&xat a call site,c ? a : b,switch/case,when,elif,and/or/not,for i := 0; i < n; i++, Gofor k, v := range m(reported by the checker, which picks the Xo form for the type ofm),x++,throw,try f(),|x| e,(x) => e,lambda,x as T,A::B,impl,trait,): Tand Go’s bare result types,(T, error)results, backtick templates, f-strings, and/* */comments.xo explain XO0177lists them. - When a specific code already describes the error, it keeps that code
and gains the habit in a note and the fix:
XO0601for names from other languages (nil,null,this,len(x),append,print,String,Vec,int,.unwrap(),.length, camelCase methods, Python’st = 0declaring by assignment, Go’sos.Argsasos.args, and a Result’s.unwrap()and.unwrap_or(x), which name?,.or_fault, andr ?? _ => x; decision 0438),XO0406(a Result operand of an operator: add?or.or_fault),XO0165andXO0160(a keyword such astestused as a name: a rename to suggest;T ! Eas the type of a parameter, a struct field or aletorvarbinding:Result[T, E]),XO0209(a method of avarbinding:xs = xs.sort()),XO0169(commas between match arms),XO0173(useafter declarations),XO0701(an effect argument left out of a parameter type, which stays an abstract effect variable; a declaration’s correctedusesclause, in its declared callers too),XO0408(TypeScript’sconst x = f()),XO0110(Kotlin’s"$name", literal text in Xo),XO0205(x?.foptional chaining in a function that does not return an optional),XO0403(a missingreason),XO0404(JSON for tuples),XO0101,XO0502, and the lexical codesXO0150(#comments,#[derive]),XO0152('text'), andXO0153(Swift’s\(x)). - A habit gets a fix only when one rewrite keeps the meaning; where the
Xo form needs a decision (
x!!needs a reason,try/catchneeds a Result handling choice,printneeds a capability in scope) the diagnostic names the form and has no fix.
- Syntax that the grammar would otherwise reject with a generic code
(
- A suggestion from edit distance (
did you mean) is a note; it is also a fix only when it is clear: a unique closest candidate at most half the name’s length away, for names of three or more characters. - An unknown method or field suggests the receiver’s own fields and
methods: the closest by edit distance, also counting a candidate
without its
to_,is_,as_, orget_prefix one further away (s.uppr()suggeststo_upper). A name another language uses for a method Xo has with the same meaning (Go’sTrimSpaceandHasPrefix, Rust’scharsand a Map’sinsert, TypeScript’ssomeandevery) names that language and the Xo method, with the rename as the fix. - A diagnostic’s first fix is the one
xo fixandxo check --fixapply (10.1); fixes whose edits overlap in one round wait for the next round.xo check --fix --jsonadds"applied": [{"file", "line", "rule", "title"}]next tomodulesanddiagnostics. xo build,xo runandxo testprint every error, but only the warnings of files in the directories the command names (and the directories below them); the others are counted on one line, andXO_WARNINGS=allprints them. A build ofcompiler/xodoes not showcompiler/ssa’s warnings although both are one module;xo checkandxo veton a directory print all of its warnings, and--jsonoutput holds every diagnostic.
10.3 Queries
xo query type api/users.xo:18:7
xo query def http.server
xo query callers users.fetch_user
xo query effects api.get_user // with the call chain per effect
xo query holes
xo query api github.com/acme/billing // exported surface of a module
xo query imports example.com/notes/domain // its `use` lines
xo query deps example.com/notes/server // the same, transitively
xo query hash users.fetch_user // content hash of a definition (4.3)
type takes FILE:LINE:COL; with --dir=DIR, a relative FILE that is
not under the working directory but is under DIR names that file (xo mcp’s query tool passes its dir this way).
What a query checks (decision 0515): a directory with .xo files of its
own (--dir, type’s file’s directory, an api, imports or deps
directory argument) is checked with the modules it imports, not the
rest of its workspace; callers adds every workspace package that
imports it, directly or through others. A name is resolved in what was
checked, so a short name ambiguous only across the whole workspace
answers for the module --dir names. def of a name (and xo def,
xo doc) at a workspace or repository root checks the packages whose
declarations name one of its segments, and everything when none does (a
std or prelude name). Several declarations (def, xo def, xo doc)
are listed in file and position order.
hash (decision 0125) answers {list}, one entry per definition the
name resolves to (a name, Type.method, pkg.name, or <package path>.name of the module holding --dir): {id, package, name, kind, pub, hash, own, refs, file, line}. It needs no check run.
imports and deps (decision 0095) answer
{package, transitive, imports, packages}: each entry of imports is a
use line {from, path, pos, std, go, test, missing, denied}, where
denied is the XO1312 message when a deny rule forbids the line, and
packages lists the distinct paths reached. deps follows every
imported package of the program (not std or Go packages).
10.4 Semantic edits [P1: rename, add-field, change-sig]
xo edit rename users.fetch_user users.load_user
xo edit add-field User created: Time = Time.UNIX_EPOCH
xo edit change-sig users.load_user "(db: Db, id: UserId) -> User ! LoadErr"
Edits update every reference atomically and are rejected if the result does not type check.
- References are found through the checker’s resolved symbols, never by text search. An edit of a program that does not check clean is rejected before anything is computed.
renamerenames a function, method, or constant and every call and use as a value, or a type and every place it is written (type expressions, struct literals, patterns, variants, receivers; decision 0289). The new name may repeat the target’s qualifier. With--dry-runthe summary carries a diff of the changes.add-fieldaddsname: Typeto the struct declaration andname: defaultto every struct literal of the type. The default is a migration value; it is not kept as a declared field default. Without= defaultthe edit is rejected when struct literals exist.change-sigreplaces the parameter list, result, and error type (not the clauses). Call arguments are matched to the new parameters by name; a parameter renamed in place keeps its position, and its uses in the body are renamed. New parameters with a default need no argument. A call that passes an argument for a removed parameter, or lacks one for a new parameter without a default, rejects the edit, listing those call sites. Arguments keep their order (and so their evaluation order); arguments that no longer match their position become named.- The result is a JSON summary:
{op, target, ok, written, reason, files, edits, diagnostics, sites}.diagnosticsholds the errors that rejected the edit;sitesthe call sites or literals that blocked it.--dry-runchecks the edit without writing.
10.5 Formatting
xo fmt produces one canonical layout from the AST. There are no options.
xo build fails on unformatted files in CI mode (--ci).
10.6 Diagnostic codes
Every code the toolchain reports, its default severity, and what reports
it: the lexer and parser (xo parse and every later command), the checker
(xo check), xo vet (advisory, never an error except XO0901 under
xo build --ci), the no GC check (--no-gc, 10.1), and module
resolution (modules: every command that loads a program reports these
on the xo.mod, xo.lock, or xo.work line, and so do xo get, xo mod tidy, and xo vendor; 4.2, 4.3), and xo publish (publish).
xo explain <code> prints the long form of each. The registry is
compiler/cli/core/explain_data.xo (internal/diag/codes.go until
decision 0215); a test (internal/repotest) keeps this table equal to it.
| Code | Severity | Reported by | Meaning |
|---|---|---|---|
XO0101 | error | checker | name breaks the enforced naming rules (core 1.5) |
XO0110 | error | checker | unused local binding or import (core 3.1) |
XO0150 | error | lexer | character that cannot start any token |
XO0151 | error | lexer | string, raw string, bytes, or triple quoted string not closed |
XO0152 | error | lexer | rune literal that is empty, unterminated, or holds more than one character |
XO0153 | error | lexer | unknown or malformed escape sequence |
XO0154 | error | lexer | bad digit, misplaced _, missing digits, or out of range integer |
XO0155 | error | lexer | unknown duration unit, fractional or non decimal duration |
XO0156 | error | lexer | ${ without a matching } in the same string |
XO0157 | error | lexer | ${} with no expression |
XO0158 | error | lexer | use not followed by a valid import path |
XO0160 | error | parser, checker | a token that does not fit the grammar here; the checker reports a struct literal’s field written name alone or its .., or a list literal’s .., which only a destructuring assignment’s target takes (decision 0538) |
XO0161 | error | parser | list element followed by a newline instead of a comma (core 1.3) |
XO0162 | error | parser | else must be on the line of the closing brace (core 1.3) |
XO0163 | error | parser | unparenthesized struct literal in a condition (core 1.4) |
XO0164 | error | parser | (, [, or { not closed before end of file |
XO0165 | error | parser | syntax that is not a pattern (core 3.5) |
XO0166 | error | parser | while cond used as an expression; only while { } is one |
XO0167 | error | parser | top level declaration (fn, struct, const, …) inside a block |
XO0168 | error | parser | statement (let, expression, …) at top level |
XO0169 | error | parser | match or select arms separated by , instead of newlines |
XO0170 | error | parser, checker | several effects in a function type must be parenthesized (core 15); the checker reports it inside type arguments, where only the arity tells a second effect from a type argument (decision 0438) |
XO0171 | error | parser | .. used more than once or not last in pattern fields |
XO0172 | error | parser | function declaration without a body |
XO0173 | error | parser | use after the first declaration (core 15: File) |
XO0174 | error | parser | bare self parameter outside an interface method signature |
XO0175 | error | parser | two statements or arms on one line |
XO0176 | error | parser | pub before something that cannot be exported |
XO0177 | error | parser | syntax from another language (Go, Rust, TypeScript, Python, Swift, Kotlin); names the habit and the Xo form (decision 0087) |
XO0178 | error | parser | a line starts with a binary operator (||, &&, +, ==, …); end the previous line with it (core 1.3, decision 0136) |
XO0179 | error | parser | retired, never reported; was: var with a tuple or list pattern; decision 0384 allows var PATTERN = e (the code stays reserved) |
XO0201 | error | checker | Result value is never used (core 2.6) |
XO0202 | error | checker | error type does not convert to the enclosing error type (core 2.6) |
XO0203 | error | checker | success of a Result typed T must be written Ok(x) (core 2.6) |
XO0204 | error | checker | ? on an Option in a function returning a Result (core 2.5) |
XO0205 | error | checker | ? where the enclosing function cannot return the failure (core 2.5, 2.6) |
XO0206 | error | checker | let _ = discards a Result; use .ignore_err("reason") (core 2.6) |
XO0207 | warning | vet | method chain on the right of ?? starts at a literal, so it applies only to the default (core 15 precedence) |
XO0208 | note | vet | .ignore_err("reason") discards an error; listed with its reason for review (core 2.6) |
XO0209 | error | checker | an expression statement discards the result of a call that only computes it, such as xs.reverse() (core 2.6) |
XO0301 | error | checker | match does not cover every case (core 2.3) |
XO0302 | error | checker | pattern does not fit the type of the matched value (core 3.5) |
XO0303 | error | checker | refutable pattern where an irrefutable one is required (core 3.5), and an assignment’s list target other than [..] (core 5.2, decision 0538) |
XO0304 | error | checker | alternatives of an or pattern bind different names or types (core 3.5) |
XO0305 | warning | checker | _ arm hides variants of an enum declared in this module (core 3.5) |
XO0401 | error | checker | value of the wrong type; only three implicit conversions exist (core 2.10) |
XO0402 | error | checker | type arguments cannot be inferred (core 2.7) |
XO0403 | error | checker | wrong arguments or fields: count, names, missing, or duplicates |
XO0404 | error | checker | type does not implement a required interface or constraint (core 2.4) |
XO0405 | error | checker | type cannot be inferred here; annotate it |
XO0406 | error | checker | operator, index, slice, or iteration not defined for the type |
XO0407 | error | checker | name used as the wrong kind of thing (a type as a value, a value that is not callable) |
XO0408 | error | checker | a block const initializer is not a compile time value (core 3.1) |
XO0409 | error | checker | invalid explicit conversion (core 2.1) |
XO0410 | error | checker | reading a Map by index; use get or get_or_fault (core 3.6) |
XO0411 | error | checker | two fields have one wire key under a derive the struct has (core 2.2, decision 0277) |
XO0412 | error | checker | empty wire name, as "" (core 2.2) |
XO0413 | error | checker | unknown derive argument or case: or match: value, or an argument on a derive that takes none (core 2.2) |
XO0414 | warning | checker | a wire name on a struct with no derive that maps fields to keys (core 2.2) |
XO0415 | error | checker | a top-level constant’s initializer performs an effect (core 3.1, decision 0332) |
XO0416 | error | checker | a constant’s value holds a handle (Mutex, Chan, Atomic, Task, a file) (core 3.1, decision 0332) |
XO0420 | error | checker | constant std/time layout is invalid: unknown field, bad field form, or stray brace (std.md 13.3) |
XO0421 | error | checker | integer literal does not fit the integer type it takes in context (1.6) |
XO0422 | error | checker | unknown or repeated wire name option; the options are omitempty and string (core 2.2, decisions 0309, 0555); for derive Proto, a bad field number, a repeated number or an unknown option (decision 0530) |
XO0423 | error | checker | a field has two wire strings for one format (json "a" json "b") (core 2.2, decision 0315) |
XO0424 | error | checker | a format’s wire string (json, sql, xml) on a struct that does not derive that format (core 2.2, decision 0315) |
XO0425 | error | checker | a field type, a type parameter list, or a nested struct that derive Xml cannot map (core 2.9, decision 0315) |
XO0426 | error | checker | a bad xml wire string: an unknown or unsupported option, attr with a path, chardata or attr on a type that cannot hold it (core 2.9, decision 0315) |
XO0427 | error | checker | xml.encode_value or xml.decode of a type parameter instead of a concrete struct (core 2.9, decision 0315) |
XO0428 | error | checker | two variants of a valued enum have the same value (core 2.3, decision 0269) |
XO0429 | error | checker | an invalid valued enum: a value type other than Int or Str, a value on an enum with no value type, a variant with fields, type parameters, or a value that is not a constant of the value type (core 2.3, decision 0269) |
XO0430 | error | checker | a pattern name spelled like a constant (upper case) that is neither a const in scope nor a variant: a misspelled constant pattern (core 3.5, decision 0269) |
XO0431 | error | checker | a variant of an internally tagged enum (derive Json(tag: "type") without content:) whose payload is not an object: one field that is not a struct (core 2.3, decision 0478) |
XO0432 | error | checker | derive Json(via: P, to: f, from: g) whose to: or from: names no non generic, non method function of the type’s module (core 2.3, decision 0478) |
XO0433 | error | checker | a mistyped to: or from: of derive Json(via: ...): to must be fn(T) -> P with no error, from fn(P) -> T ! E with E implementing Display (core 2.3, decision 0478) |
XO0434 | error | checker | a variant with fields in a valued enum that is not its catch-all: the catch-all is the last variant, with one field of the value type and no value (core 2.3, decision 0493) |
XO0435 | error | checker | a valued enum’s catch-all built from a constant that a named variant has (StorageClass.Unknown("STANDARD")): a second spelling of that variant, unequal to it (core 2.3, decision 0493) |
XO0436 | error | checker | for over a type with next() whose ? does not match it: for x in v where next() can fail (write for x? in v), for x? in v where it cannot or over a builtin iteration, or a next() that does not return T? (core 3.5, decision 0494) |
XO0437 | error | checker | the string wire option on a field that is not a Bool, integer, float or Str, or an Option of one (core 2.2, decision 0555) |
XO0438 | warning | checker | an argument of a log.debug, log.info, log.warn or log.error call (or a Logger’s) performs an effect other than log; it runs only when the record is at or above the configured level (decision 0558, std.md 6) |
XO0501 | error | checker | var method called on a non var binding (core 3.4) |
XO0502 | error | checker | assignment to an immutable binding, to a captured variable, or to an element of Bytes (core 5.2, 3.3) |
XO0503 | error | checker | one variable or overlapping places passed to two var parameters of one call (core 5.2, decision 0111) |
XO0510 | error | checker | use of a moved Buf, StrBuilder, BytesBuilder, or std move only handle (core 5.3) |
XO0520 | error | checker | mutation of a copied or stored collection element is never written back (core 5.2) |
XO0530 | warning | vet | binding the payload of a field shares every heap field of a large value (decision 0263) |
XO0531 | warning | vet | a large parameter is only stored while each caller passes its last use, so its heap fields are shared and dropped again (decision 0263) |
XO0532 | note | vet | a Map value read into a var, changed, and stored back; Map.update does it in one lookup (decision 0266) |
XO0534 | note | vet | a task captures a value with many heap fields (32 or more), sharing each at the spawn (core 5.1, decision 0294) |
XO0535 | note | vet | ${x.debug()} in a string, which ${x:?} writes shorter; its fix rewrites it (core 1.6, decision 0296) |
XO0536 | note | vet | a collection copied out of a list element, changed, and stored back, so its first change copies all of it; change the element in place (core 5.1, decision 0294) |
XO0537 | warning | vet | retired, never reported; was: a by value receiver read before an argument that changes it; decision 0326 defines that order, so the check is gone (the code stays reserved) |
XO0538 | warning | vet | a var local written after a closure that reads it was created and before the closure is used: the closure keeps the value from its creation (core 5.1) |
XO0539 | error | checker | a destructuring assignment names the same place twice (core 5.2, decision 0536) |
XO0540 | warning | checker | a Mutex.with closure writes its var value, then a path returns Err, which undoes the write (core 5.4) |
XO0541 | warning | vet | a slice of a raw.bytes_buf buffer that a loop reads into again is kept past the iteration (pushed, stored outside the loop, returned) without .clone(): the next read changes it (decision 0330 views) |
XO0542 | warning | vet | x ?? lit <op> z: an operator binding tighter than ?? after a literal default applies only to the default (x ?? (lit <op> z)); (x ?? lit) <op> z is likely meant (core 15 precedence) |
XO0601 | error | checker | name does not resolve (core 4.3) |
XO0602 | error | checker | import path does not yield a valid local name (core 4.1) |
XO0603 | error | checker | name declared twice in one scope, or a predeclared name redefined (core 3.1, 1.4) |
XO0604 | error | checker | cyclic package imports (core 4.1) |
XO0605 | error | checker | name is not pub in its module, a field of a std struct documented @internal outside std (decision 0440), or the std type is an opaque handle (core 1.5) |
XO0606 | error | checker | method declared outside the module of its type (core 3.4) |
XO0607 | error | checker | break or continue outside a loop, or an unknown label (core 3.5) |
XO0608 | error | checker | two C ABI export modules of the native std (std/native/llrt/cabi*.xo) define the same function name, one symbol xo_x_<name> (decision 0207) |
XO0609 | error | checker | a merged std module calls an intrinsic of native/rt that is not portable (decision 0597: only rt.cast) |
XO0701 | error | checker | effect performed outside the declared set (core 6.2) |
XO0702 | error | checker | unknown effect label (core 6.1) |
XO0703 | warning | vet | effect declared in uses is never performed (core 6.2) |
XO0801 | error | checker | child or group task error does not convert to the enclosing error type (core 7.1) |
XO0802 | error | checker | scope handle, or a value containing a task group, escapes its scope (core 7.1) |
XO0803 | error | checker | task started without a scope handle (core 7.1) |
XO0804 | warning | checker | value read in one Mutex.with is written back in a later one (core 5.4) |
XO0900 | warning | checker | typed hole report (core 3.7) |
XO0901 | warning | vet | dbg(...) left in code (core 11.4) |
XO0902 | warning | vet | tls.Verify.None: a TLS client that checks no certificate (std.md 27, decision 0281) |
XO0903 | warning | vet | the error of a filesystem, network, or process call turned into a default (.ok() ?? d, or Err(_) => <empty> with no NotFound arm), so a transient error gives a smaller answer instead of an error; // xo:allow XO0903 <reason> on the line or above it allows one |
XO0906 | note | vet | a match that only unwraps an Option or a Result or leaves, which x ?? return v (r ?? e => return v) writes in one line (core 2.5, 2.6, decision 0321) |
XO0907 | note | vet –cost | a loop that copies every entry of a map before it starts (a log-mode map through a forked view, or a body the in-place walk does not take; decision 0327) |
XO0908 | note | vet –cost | in a loop, an element of a collection made outside it is counted up and down each iteration (passed to a function value whose result has its type, which takes it), or a prelude method hands each element holding heap memory to such a function value (map, filter, find, any, all, fold of a List, Map, or Set; decisions 0327, 0337) |
XO0909 | note | vet –cost | a list update in a loop that copies the whole list every iteration: the list is also kept in the same iteration (stored, captured, or a name used after the update), so it is shared when the update runs (decision 0327) |
XO0910 | note | vet –cost | a value over 8 words copied where the source shows no copy: captured by a closure, or, in a loop, an element of a collection wrapped whole in an Option or enum value (decision 0327) |
XO0911 | note | vet –cost | a view of a parameter’s text or bytes (a slice, trim or cut made in a loop, or an element of its split or lines) stored in a field or a returned collection keeps the whole input alive; clone() it (decision 0330) |
XO0912 | warning | vet | retired in 0.34.0 (no longer reported): u.0, the pattern uuid.Uuid(p), or uuid.Uuid(s) on a uuid.Uuid was deprecated in 0.33.0; a uuid.Uuid is now two Ints and those uses are type errors (std.md 24, decision 0387) |
XO0913 | note | vet –cost | in a loop, a slice of a Str or Bytes read only by index, length or equality: each iteration makes a view (a range check, a count and a drop); read the whole by offsets (knowledgebase/std-performance-guide.md) |
XO0914 | note | vet –cost | in a loop, a List of at most 8 elements made and only filled and read in the iteration: an allocation and a free every iteration; keep the values in locals or reuse one list made before the loop (knowledgebase/std-performance-guide.md) |
XO0915 | warning | vet –cost | a raw address (raw.data, raw.bytes_addr, rt.obj_addr, std internals) used after its value was released in the same block: a value is released at its last use, even inside the arguments of the call that takes its address, so the call reads freed memory; keep it alive with raw.alive or raw.alive_str after the last access (gotchas/raw-address-outlives-bytes.md) |
XO0916 | warning | vet | time.format or time.parse called with a layout that is a compile time string (a literal, a constant, or a + of them): each call parses the layout text again (5.4 and 4.7 of Go’s wall), where a const Layout made with time.layout is parsed once (2.0 and 1.9); a layout built at run time is not reported, and // xo:allow XO0916 REASON silences a cold call (decision 0464) |
XO0917 | warning | vet | a valued enum’s catch-all built directly from a run time value (StorageClass.Unknown(s)): a value a named variant has would become a second spelling of it; E.from(s) picks the named variant (decision 0493) |
XO0904 | warning | vet | a file an embed constant embeds is ignored or untracked by git, so a build of a clean checkout embeds something else or fails (decision 0304) |
XO1001 | error | reserved | std/sys/<os> used outside the matching target arm (core 12.2) |
XO1101 | error | checker | Go package cannot be bound (not found, does not build, main package, or binding error) |
XO1102 | error | checker | Go name exists but its signature does not map to Xo, so the binding skipped it |
XO1103 | note | vet | per module report of use go packages and the functions that perform go (decision 0041) |
XO1104 | error | checker | C header cannot be bound (not found, clang cannot read it, a link file is missing, or an unknown effect in its uses) |
XO1105 | error | checker | C function exists in the header but its signature does not map to Xo, so the binding skipped it |
XO1106 | error | checker | a value with no Go value passed to Go as any: go.any(x)’s argument or an element of a list literal for a ...any parameter (decision 0412) |
XO1107 | warning | checker | a List, Map or Set given to a Go function as any (go.any(xs) for an any parameter, or an element of a ...any list): Go receives a copy, so a change it makes is not seen; not for a function compiler/check/goreads.xo lists as only reading, nor with // xo:allow XO1107 <reason> (core 4.4, decision 0491) |
XO1201 | error | no GC check, checker (use c without --no-gc) | construct, std API, or effect not available on the native backends (arm64, amd64, LLVM); planned or impossible |
XO1301 | error | modules | malformed xo.mod require or deny line, xo.lock, or xo.work line, or a deny rule naming a package that does not exist (core 4.2, 4.3) |
XO1302 | error | modules | module version cannot be fetched from git or a module proxy (XO_PROXY): repository, tag, or version missing, or its xo.mod declares another path |
XO1303 | error | modules | module version is not in the module cache and the build is offline (XO_OFFLINE, –offline) |
XO1304 | error | modules | module tree does not match its xo.lock content hash (core 4.3) |
XO1305 | error | modules | xo.lock has no hash for a module version the build uses; run xo mod tidy |
XO1306 | error | checker | import of a package from a module that xo.mod does not require |
XO1307 | error | modules | vendor/ does not match xo.mod; run xo vendor |
XO1308 | error | build | release build (xo build --release, or --ci) while an xo.work workspace overrides required modules |
XO1309 | error | checker | call into a dependency performs an effect above its ceiling (require ... uses ... in xo.mod, use ... uses ... in xo.work) |
XO1310 | error | publish | xo publish: a minor or patch release removes or changes an export, or adds an effect to one |
XO1311 | error | publish | xo publish: the release cannot be made (not in a git repository, a subdirectory module path not ending in its directory, uncommitted changes, tag exists, version not above the last, wrong /vN path) |
XO1312 | error | checker | use of a package that a deny rule of xo.mod forbids (decision 0095) |
XO1313 | error | modules | a fetched module version disagrees with the checksum log (XO_SUMDB), or the log’s signature or proofs do not verify (4.3, decision 0124) |
XO1314 | error | modules | the checksum log cannot be consulted, or XO_PROXY, XO_SUMDB, XO_NOPROXY, or XO_NOSUMDB is malformed (4.2, decisions 0124, 0126) |
XO1315 | note | checker | edition 2026 in xo.mod (or xo 2026 in xo.work) is the old name of edition preview; the fix rewrites it (13, decision 0155) |
XO1316 | error | checker, xo get | use c or use go of an impure Go package in a required module without the consumer’s vouch for that version (4.2, decision 0156) |
XO1317 | error | modules | a dependency’s effects are wider than its effects line in xo.lock (4.3, decision 0156) |
XO1318 | error | modules | a module’s tree cannot be read (an I/O error) for its content hash, the effect or escape hatch audit, or xo mod tidy’s import scan, so none of them answers from a partial tree (4.3, decision 0156) |
XO1319 | error | modules | a use go of a package outside Go’s standard library whose Go module has no require go line in xo.mod (builds would follow its latest version); the fix adds the line with the version the binding resolved, and xo mod tidy adds it too (decision 0356) |
XO1320 | error | modules | xo mod tidy with a require go pin whose go.sum hashes no binding has fetched yet (a fresh clone: .xo/gobind is not committed) and xo.lock does not hold: nothing is written; run xo check once, then tidy again (decision 0356) |
XO1401 | error | checker | allocation in a real-time function (literal, interpolation, + on Str or List, closure, growth method) |
XO1402 | error | checker | loop without a provable bound in a real-time function, or a bound N that is not a constant or is exceeded by a constant range |
XO1403 | error | checker | call in a real-time function of a function that is not real-time, a function value, or an interface method |
XO1404 | error | checker | recursion among real-time functions |
XO1405 | error | checker | blocking operation (channel, Mutex, scope, select, task) or capability effect in a real-time function |
XO1501 | error | build | --stamp NAME=VALUE names no const NAME: Str = "..." (a plain string literal) of the main module (decision 0165) |
XO1502 | error | build | the go command the Go backend runs ($XO_GO, else go on PATH) is older than Go 1.24, the oldest Go that builds generated programs and the runtime (decision 0176) |
XO1503 | error | build | the Go backend finds no go command: $XO_GO is not an executable file, or there is no go on PATH; the native backends need none (decision 0176) |
XO1504 | error | build | the program uses a std API the native runtime does not support on the build’s target yet: reported by no build since stage 2 of decision 0197 (2026-10-12; stage 1 left out processes on Windows), and Windows builds default to the amd64 backend (decisions 0254, 0270); the message would name them, and the Go backend builds the program |
XO1505 | error | build | the LLVM backend’s clang ($XO_CLANG, else clang, or --cc) is an LLVM clang older than 16, whose LLVM lacks llvm.threadlocal.address; Apple’s clang (numbered apart) is not checked (gotchas/llvm-thread-local-constant.md) |
XO1506 | error | checker | embed("...") names no file, more than one for a Str or Bytes constant, a file that cannot be read, or more than an embed may hold (64 MiB each, 256 MiB a program; decision 0304) |
XO1507 | error | checker | an embed path leaves the module: absolute, .., ., an empty segment, or a symbolic link (decision 0304) |
XO1508 | error | checker | a Str embed constant’s file is not valid UTF-8; declare it Bytes (decision 0304) |
XO1509 | error | checker | embed used other than as the initializer of a constant typed Str, Bytes, or embed.Dir, with one plain string literal (decision 0304) |
XO1510 | error | build | a function the native backends are about to generate disagrees with this build’s definitions: a call’s argument or result types, a closure, or a field or payload access do not match the callee or type (decision 0342: a stale cached piece, such as a front end body naming a helper this build defines otherwise, or, when it repeats with the cache off, a code generator bug such as a call resolved to the wrong method); rebuild with XO_BACKEND_CACHE=off and report it |
XO1511 | warning | checker | read, read_text, or contains on an embed.Dir constant, or a literal .sub of one, with a literal path it holds no file at; a key ending in the path is offered as a fix (decision 0304) |
XO1512 | error | build | under XO_BACKEND_CACHE=verify, a build, run, or test the run cache would have served differs from its rebuild, in the binary or in what the build printed: an input the entry does not list, or a build that is not reproducible (decision 0360) |
XO1513 | error | build | a command the WASI build of xo (xo built for wasip1/wasm) does not offer: it needs a process, a socket or a system tool that WASI preview1 does not have (run, test, serve, get, build --backend=llvm, …); printed as xo: COMMAND is not available in the WASI build, exit status 2 (decision 0405) |
XO1514 | error | build | a program that calls http.serve_component built for wasip1/wasm, which --backend=wasm alone is; it builds with --targets=wasip2/wasm (decision 0447) |
XO1515 | error | build | a program built for wasip2/wasm reaches what its world does not have: processes, or files or sockets in a wasi:http component (a command has wasi:filesystem since 2026-11-02 and wasi:sockets since 2026-11-03); the message names the call and how it is reached (decision 0447); on wasip3/wasm also a program that is not a wasi:http component (stage 5) |
XO1516 | error | build | a program built for wasip2/wasm whose main never calls http.serve_component (decision 0447); no longer reported since stage 3 (2026-11-02), when such a program became a wasi:cli/command component |
XO1517 | error | build | a windows program’s resource input that cannot be used: the --versioninfo JSON cannot be read or parsed, an --icon file cannot be read or is not an icon, a --manifest file cannot be read; the message carries goversioninfo’s text (decision 0560) |
XO1518 | error | checker | a function’s as c "name" clause breaks a C export rule: a method, not pub fn, generic, a var parameter, a Bool or function type parameter, more than 8 integer parameter words, a Bytes, Str, Bool or function type result, a name that is not a C identifier or starts with xo_ (decision 0574) |
XO1001 is reserved: no std/sys/<os> module exists yet (14), so it is
never reported.
Faults (8) that have a stable code print it in their message:
| Code | Fault |
|---|---|
XO-F001 | deadlock: every task is blocked on another task (11.4) |
XO-F004 | Mutex.with or with_read called re entrantly on a mutex the task holds (5.4) |
XO-F005 | a shielded defer ran longer than 5 seconds (3.5) |
XO-F006 | a loop started more iterations than its bound N (3.5) |
XO-F007 | a real-time section allocated (6.5, native builds) |
XO-F008 | shielded code under a resource budget ran past twice a ceiling (std.md 7, decision 0173) |
XO-F009 | a constant read during its own initialization, through a function its initializer calls (core 3.1, decision 0332) |
XO-F010 | Mutex.with or with_read on a mutex poisoned by a fault inside an earlier with, until reset (5.4, decision 0482) |
11. Debugging [P1 basics, P2 replay]
11.1 Error traces
Each ? that propagates an error appends a frame:
LoadErr.Db(msg: "timeout")
at users.fetch_user(id=42) users/fetch.xo:18
at api.get_profile(req=GET /u/42) api/profile.xo:7
- Frames record function, location, and parameters that implement
Debug, truncated to 64 bytes each.Secret[T]prints<redacted>. Capability parameters are left out. Frames are built only when an error propagates; the success path records nothing. - Frames are recorded in every build, debug and release (decision 0092).
A frame keeps a copy of each parameter value and produces its
Debugtext only when the trace is printed (the error report ofmain, a crash bundle, a test failure, a handler’s error log), formatting no more of a value than the 64 bytes it shows. The text is what it would have been at the?: values are immutable or copied on write, and the few whoseDebugtext can change in place (Buf,Atomic) are formatted when captured. --error-args=off(any build, decision 0354;--error-args=falsetoo) records the function and location only and prints(...)for the parameters:at users.fetch_user(...) users/fetch.xo:18.- [later] A last line naming the task and its scope
(
in task "handler#913" (scope api.serve)) is planned. - Native backends (
--no-gc, LLVM, arm64) record the same frames (decision 0104) and print them in main’s error report; test reports, handler logs, and crash bundles do not show them there yet (10.1).
11.2 Crash bundles
On a fault reaching main, an unhandled error from main, or an isolated
fault in a server, the runtime writes <name>-<time>.xocrash containing: the
error or fault with frames, the task tree, build id, source hashes, target, and
[P2] the effect trace for the failing request, and prints its path on
standard error (crash bundle: PATH). Bundles go to $XO_CRASH_DIR, else
<user cache>/xo/crash, which keeps the newest 100 (owner, 2026-10-22)
and which xo clean -cache does not empty. Native builds (--no-gc)
write none yet (decision 0085).
11.3 Record and replay [P2]
All effect calls go through capability values, so the runtime can log each call and its result, plus scheduler decisions.
xo run --record=trace.xotrace(orXO_RECORD=trace.xotracefor any built binary) records a full run. Values of typeSecret[T]are recorded redacted;xo replaythen requires them from the environment and exits with status 3 naming the missing one.- Calls into Go packages (
use go, 4.4) are recorded at the boundary (decision 0093). A call whose arguments and results are all boundary values (scalars,Str,Bytes,Time,Duration, lists and maps of those,go.Errorwith its text and Go type) and that takes no callback is an effectgo.call(<name>, <argument hash>)with its results;xo replaychecks the name and the hash (a different argument diverges) and returns the recorded results without calling Go. A Go panic is recorded and raised again as the same fault. A call whose result, an argument, or the receiver is a Go handle, or that takes an Xo callback, runs again in the replay: a handle’s Go state exists only if the calls that make and change it run (sync.WaitGroup.waitmust wait for real). The trace marks such a call ("x": "handle"or"callback"), the replay checks that it comes at the same point, andxo replayreports it once per name:re executed foreign call `os.open`. Functions markedreplay rerun(4.4) run again and are not recorded. A trace written before decision 0093 (no"foreign"field in its header) runs every Go call again, as before. - Calls into C (
use c, 4.5) follow the same rule once native builds record (10.1: they do not yet): a call whose arguments and results are boundary values is answered from the trace asffi.call(<name>, <argument hash>), and one that passes or returns a C handle runs again. Each binding’s doc comment already says which applies (/// Replay: by valueor/// Replay: a C handle crosses). - An Xo callback that Go calls on a goroutine of its own is recorded (where the scheduler admitted it, with its arguments) and replayed at the same point, and a replay diverges when Go calls it with other arguments (decision 0073).
- In production, a per request ring buffer (
XO_RING=Nrequests) is kept and attached to crash bundles. xo replay trace.xotrace(or a.xocrash) re executes the program offline with identical effect results and interleavings.- [later]
xo debug --replay trace.xotracesteps backward (11.5’sxo debugruns forward only). xo why <expr> --at file:linetraces where a value came from (the assignments, calls, and effect results that produced it) using the replay.
11.4 Live inspection
xo dump <pid>(or SIGQUIT) prints the task tree: each scope, its children, and what each task is blocked on, with locations. The program keeps running (unlike a Go program’s default SIGQUIT, which exits); the dump goes to the program’s standard error and to$XO_DUMP_DIR(or the temp dir) asxo-dump-<pid>.txt, a new file of mode 0600 that replaces an earlier one and is never written through a symbolic link. On the native backends (decision 0251) a task’s wait is named as on the Go backend (blocked in receive at main.xo:5); the scopes’ own sites and the holders of a mutex are not shown yet. A test binary has no dump.- [P2] Deadlocks are detected by the runtime and reported as a wait cycle
with locations (fault
XO-F001, exit status 70, crash bundle). A task counts as blocked when it waits on another task (channel, mutex, semaphore,await, scope end,Once); waits on timers,after,task.stopping(), signals, and I/O do not. In test worlds the report is immediate; real runs report after 200 ms with no progress. A task inside a Go call (use go) counts as blocked only while it waits for its own Go callbacks running on goroutines of Go’s, those callbacks are blocked in turn, and every goroutine’s stack shows that nothing else can move (the Go call parked in asyncwait, no goroutine running, sleeping, or in I/O); the report shows the edge asblocked in Go call sync.(*WaitGroup).Wait at ... for callback 3. A Go call waiting on a Go channel, select, or timer is never reported, and nothing is reported while any Go runtime timer is pending (atime.AfterFuncmay release the wait; the check looks again after it fires); builds for targets other than darwin and linux never report it (decision 0073). Native builds (decision 0068), which have no timers, I/O, or signals, report at once when every task is blocked and none is queued, with the fault’s first line only (no location or list of blocked tasks yet). dbg(expr)prints the expression source and itsDebugvalue, returns the value, and is rejected byxo build --ci(decision 0265). It prints one line on standard error,[file.xo:LINE:COL] expr = value, on every backend,--no-gcincluded. It needs no capability: it is the one output a function may produce withoutStdio, and it is not part of a function’s effects, so adding one changes no signature.xo build --releaseand--dbg=off(any build, decision 0354) compiledbg(expr)toexpr(the value is computed, nothing prints); other builds keep it, and--release --dbg=onkeeps it in a release build.xo vetwarns (XO0901), and real-time functions reject it (XO1405) because its write blocks.
11.5 Debugger protocol
What is built (decision 0253 stage 2, 2026-11-05): xo debug [--batch] [--json] [-c CMD]... PROG [ARGS] runs PROG, a native executable with its
debug information, under the debugger on macOS arm64: started stopped
with ASLR off (its addresses are its file’s DWARF addresses), break
plants a trap (brk #0) at each of the location’s addresses, run
starts it and continue resumes it (over the trap it stopped at by one
single stepped instruction) until a breakpoint, a fault (stopped by exception N, the Mach exception), or its exit (the program exited with status N); at a stop every thread of the program is suspended, and
backtrace, frame, locals, print and threads read the stopped
thread and the program’s memory. step (stage 3) runs the stopped
thread alone, an instruction at a time, to the start of a statement of
another line (the line table’s is_stmt rows), into a call (inlined or
not; a call into code without line information is run over); next
runs calls over (with every thread, to a temporary trap at the return
address in the same frame) and calls inlined from the same line, so it
stops at the frame’s next line (a call inlined from another line stops
it at that call’s first statement with the frame selected); finish
runs the selected frame out: an inlined call until its code is left
(its caller’s frame selected), a function to its caller’s return
address in the caller’s frame. A frame is told by its canonical frame
address (the unwinder’s) and then its inlined depth, so recursion and a
tail call are handled. A breakpoint or fault on the way stops them. The commands come from -c (--batch
echoes each as (xo) CMD), else from standard input; the program is
ended after the last one or quit. The process needs the
com.apple.security.cs.debugger entitlement on xo, or get-task-allow
on the program, and Developer Mode: a darwin build with debug
information that is not --release or -s carries get-task-allow in
its ad hoc signature, xo build --entitlement=KEY adds others, and the
checkout’s and a release’s xo carry the debugger’s (decision 0253
point 5).
On Linux (stage 6, 2026-11-05: arm64, then x86_64) the same commands
run the program under ptrace: started with fork, seized (PTRACE_SEIZE,
with every thread it makes traced and the program ended with xo), and
stopped at its exec; Xo’s executables are fixed address (ET_EXEC), so
nothing turns ASLR off. A trap is brk #0 (arm64) or int3 (x86_64,
the pc moved back on it at the stop), written with PTRACE_POKEDATA; a
stop interrupts every other thread (PTRACE_INTERRUPT); memory is read
with process_vm_readv; a fault is reported as stopped by exception N
with the Mach numbering (1 bad access, 2 bad instruction, 3 arithmetic)
and its signal delivered when the program runs on; signals the program
handles itself (SIGURG’s preemption, SIGCHLD, SIGPIPE) pass without a
stop. attach and -p read the process’s threads from /proc/PID/task,
seize each (no kill on the debugger’s exit) and stop it, until no new
thread appears, and find the executable’s load address from its ELF
header in memory; quit detaches and the program runs on. A security
module may forbid ptrace: Yama’s ptrace_scope 1 (the default of many
distributions, and of WSL) lets a process attach only to its own
descendants, so -p of an unrelated process fails there (the error
says so) unless the debugger runs as root or the scope is 0.
On Windows (amd64) the debugger uses the system’s debugging functions: the
program is started with CreateProcessW and DEBUG_ONLY_THIS_PROCESS (through
std’s process launch, so its standard handles are set up as xo run’s), its
debug events come from WaitForDebugEventEx, memory through
Read/WriteProcessMemory with FlushInstructionCache after a trap’s write,
registers and the trap flag (a step) through Get/SetThreadContext, and the
other threads are suspended at a stop (SuspendThread). The image is loaded
where ASLR puts it, so the debug information is moved by its load address
at each run. attach and -p use DebugActiveProcess, and quit detaches
(DebugActiveProcessStop), leaving the program running. Frames are unwound by
the image’s .pdata and its unwind codes (a PE has no .eh_frame), with an
epilog’s own instructions at the first frame. Breakpoint files match with
either separator and a drive’s path in any case.
tasks and task N [bt] (stage 4, 2026-11-05) read the stopped
program’s tasks from the runtime’s own records in its memory, as xo dump walks them from inside (decision 0251): the static words from the
xo_static DWARF variable (else its symbol), the root contexts'
registry, and each root’s cancellation nodes. tasks lists the tree as
xo dump does, one line each (main is task 1, numbered depth first; a
scope’s line has no number): task N (spawned at FILE:LINE) and its
state: running, ready, blocked in OP at FILE:LINE (OP one of
receive, send, select, Mutex.with, await, sleep, network I/O, serve,
advance; the location the first frame of the program’s own code, not
std’s), in scope, or waiting for its tasks (a scope’s body),
(canceled) after a canceled one. task N selects a blocked task’s
frames, read from its fiber’s saved stack (or a root’s wait from the
park’s frame pointers), with the frame of the program’s code where it
waits selected, so locals, print and frame read the task there
until the next stop; task N bt also prints its backtrace. A running
task’s frames are its thread’s: the worker whose running fiber is the
task’s, and the thread whose stack pointer is in that fiber’s stack,
with its live registers. A ready task has no frames to read, and
neither does a task run inline on another’s fiber. The record layouts the debugger reads are copies of
std/native/llrt’s, each marked with its source and checked by
TestRuntimeLayoutCopies.
xo debug -p PID PROG (stage 4) attaches to a running process instead
of starting one (the command attach PID, run first): every thread is
suspended and the first one selected; the executable’s ASLR slide is
found from the threads (a return address into it, then the page aligned
slide whose memory holds the executable’s Mach-O header and load
commands byte for byte), and the debug information and unwind tables are
moved by it. PROG must be the process’s executable (else the attach is
refused). quit detaches: the traps are taken out, the exception ports
reset to none, and every thread resumed, so the program runs on; run is
refused in an attached session; the program’s end is the program ended
(its exit status is its parent’s).
Before it (decision 0253 stages 1 and 5’s protocol, 2026-10-17):
xo dev debug (hidden) runs the debugger’s commands on a recorded,
stopped thread (--snap FILE, as lldb or gdb recorded it): break
resolves a FILE:LINE or a function to its addresses, and backtrace
(inlined calls as frames), frame, locals, print (a field path),
threads and quit read the snapshot through the program’s DWARF and
unwind tables. With --json each command gives one JSON line, the
protocol’s version 1 below; with no -c it reads commands from standard
input. There run and continue answer that the session is a recorded
thread.
[later] Not built: conditional
breakpoints, a break on a contract failure, evaluating expressions
(beyond print’s field path), stepping back over a replay (11.3), and
DAP’s pause.
xo debug --dap (decision 0504, 0253’s stage 7, 2026-11-05) serves the
Debug Adapter Protocol on standard input and output (Content-Length
framing) for editors, each request mapped onto the session’s commands
through this protocol: initialize; launch (program, args, cwd)
answered and followed by the initialized event; setBreakpoints (a
source’s lines, by its path, else its base name; verified when the line
has code); configurationDone runs the program; continue, next,
stepIn, stepOut are continue, next, step, finish; threads,
stackTrace (inlined calls as frames, from the frame the stop selected;
a source’s path absolute: relative to cwd, std’s files in xo’s std),
scopes (one, Locals), variables (a struct value’s fields as children),
evaluate (print’s field path); disconnect. Stops are stopped events
(breakpoint, step, exception, every thread stopped), the end is
exited then terminated, and the program’s standard output and error
(written to a file, since standard output is the protocol) are output
events at each stop. While the program runs, the adapter reads no request
(no pause). An attach request (processId, else pid, and
program, its executable) takes a running process instead (stage 4’s
attach PID): configurationDone attaches and reports a stopped
event (pause, every thread stopped), and disconnect detaches,
leaving it running; its output is not captured.
The protocol’s version 1 (decision 0253; compiler/debug session.xo;
xo debug --json, and xo dev debug --json on a recorded thread): each command (decision 0253 point 4) gives one line, an
object with v (1), cmd (the command’s long name: break, delete,
run, continue, step, next, finish, print, locals,
backtrace, frame, tasks, task, threads, attach, quit; "" for a line
that is not a command), and ok. With ok false the object has error
(the text), nothing else. With ok true, by command:
break:id,locations(each{pc, file, line};pcis a"0x..."string,filea base name).delete:id.run,continue,step,next,finish:stop:"step"(a step or next that reached its line) or"finish"withthreadandframe;"breakpoint"withid,threadandframe(the innermost, as inbacktrace);"exception"withexception,code,subcode(the Mach exception’s; on Windows the faulting instruction’s address),slide(the executable’s load address less its linked one, sosubcode - slideis the address in its disassembly),threadandframe;"exited"withstatus;"signaled"withsignal;"timeout"withms(--timeout: no stop within it, the program ended or, attached, detached and left running);"ended"(an attached program’s end).attach:stop"attached"withpid,slide("0x..."),threads(their count),threadandframe.backtrace:frames, each{index, pc, function, inlined, file, path, line, selected}(paththe file as the line table names it); an inlined call is a frame of its own (inlinedtrue) with its physical frame’spc, innermost first.frame:frame, one frame as inbacktrace.locals:frame(the selected frame’s index),vars, each{name, type, param, text}andvalue, orerrorinstead ofvaluewhen the variable cannot be read there (textthen says why, as<optimized out>).print:frame,path(p.a.x),text,value.tasks:tasks, each{id, depth, kind, spawned, state, op, at, canceled}(kindmain, runtime, task or scope;id0 for a scope;staterunning, ready, blocked, in scope or waiting).task:task(one as intasks) andframes, the task’s frames as inbacktrace(the selected one marked).threads:threads, each{id, selected}(andrecordedfor a recorded thread).quit: no more fields.
A value is {"text": T} for a scalar (T its text: an integer keeps
its 64 bits, a float has Xo’s float text, true or false, a pointer
0x...), {"type": NAME, "fields": [{"name", "value"}, ...]} for a
structure, and {"type": "[N]", "elements": [value, ...]} for an array.
Fields are added to a version without changing v; removing or changing
one takes the next v, as an XOnnnn code keeps its meaning.
[P1] The generated Go code carries //line file.xo:N directives, so Delve,
Go stack traces, and pprof report Xo source locations.
11.6 Observability [P1, export later]
What exists (decision 0325): std/metrics (std.md 37) has counters,
gauges and histograms with label values in a registry that main makes and
passes on, their Prometheus text exposition (Registry.text, the
GET /metrics handler Registry.handler), and an HTTP middleware that
counts and times every request. std/trace (std.md 38) gives each request
an id and keeps a bounded ring of spans (a request’s span and a program’s
own), which a handler reads; it has no exporter.
Not implemented yet [later]: spans are a program’s own (a scope or an
effect call is not a span by itself), log records do not carry the
current span or request id automatically, and there is no OpenTelemetry
(OTLP) export: XO_OTEL_ENDPOINT is not read. A traceparent-style
exporter is a program’s own code over Ring.spans.
12. Targets and platform code [P1]
12.1 Targets
xo build --targets=all builds every supported target from any host:
linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64 wasi/wasm32.
With no --backend, each target builds with its own native backend
(arm64, amd64, or wasm for wasi), and all is the six targets a native
backend builds: windows/arm64 needs --backend=go, whose all is all
seven, and a note says so (decision 0270 addendum, owner 2026-10-22).
Naming windows/arm64 in a list with no --backend is an error, reported
after the other targets are built (exit status 1). Several targets write
NAME-OS-ARCH binaries (.exe for windows, .wasm for wasi) into -o’s
directory; -o NAME for a windows target with no extension writes
NAME.exe.
--targets=linux/riscv64, not part of all, builds for 64-bit RISC-V
Linux (RV64GC, the lp64d ABI) with --backend=llvm only (decision 0571);
naming it with no --backend is an error that names --backend=llvm,
reported after the other targets are built (exit status 1).
It cross links against a riscv64 glibc sysroot (XO_LINUXSYSROOT). Fault
traces, XO_PROF and asynchronous preemption work as on linux/arm64
(decision 0571 stage 2).
--targets=freebsd/amd64 and --targets=freebsd/arm64, not part of
all, build static FreeBSD 14 executables with the native backends and
Xo’s ELF linker, from any host (decision 0573). A use c binding’s C is
compiled freestanding by clang against FreeBSD’s headers (XO_FREEBSDSYSROOT)
and linked with no C library: it may call the part of the C library Xo’s
runtime defines (malloc, calloc, realloc, free, the mem and str functions,
strtol, atoi and the like) and C the compiler adds beside the binding:
printf’s family (printf, fprintf to stdout and stderr, snprintf, sprintf,
vsnprintf, puts, putchar, fputs; the d, i, u, x, X, o, c, s, p and f
conversions with their flags, width, precision and length modifiers) and
<ctype.h> for the C locale; and what std/sqlite’s unix VFS calls
(pthread’s mutexes, fstat, fsync, ftruncate, lseek and the like), so
std/sqlite works on FreeBSD (its localtime is UTC). Other C library
functions do not link (the link names each missing function), and a
binding’s link libraries are an error. Programs run on FreeBSD 14 (decision 0573 stages 2 and
3; every LLVM golden that builds passes in FreeBSD 14.5 VMs on both
architectures): threads, the poller (kqueue), signals, time, the file
system, processes, networking, fault traces with frames, XO_PROF and
std/debug profiles, and asynchronous preemption (SIGURG through
thr_kill, as on Linux) work as on Linux. Runtime calls that exist only
on Linux (statx, sched_getaffinity, sysinfo) fail with ENOSYS there.
--targets=wasip2/wasm, not part of all, builds a WASI 0.2 component and
is named alone (decision 0447). A program that calls http.serve_component
is a wasi:http 0.2 component (the wasi:http/proxy world); any other
program is a wasi:cli/command component, whose wasi:cli/run export runs
main (stage 3, 2026-11-02): its arguments and environment are
wasi:cli/environment’s, its input wasi:cli/stdin’s (as standard input
is fd_read’s on wasip1/wasm; a wasi:http component’s is empty), its output
wasi:cli/stdout and stderr’s, its files wasi:filesystem’s (the
host’s preopened directories named . and /, which a relative and an
absolute path resolve against, as on wasip1/wasm; wasmtime run --dir .::. --dir /::/; file modes, locks and times before 1970 are refused as on
wasip1/wasm), and
an exit status other than 0 (a fault, proc.exit(n)) is wasi:cli/exit’s
err, which a host reports as status 1. http.serve_component on
wasip1/wasm is XO1514; on wasip2/wasm a program that reaches processes,
or a wasi:http component that reaches files or sockets, is XO1515 (XO1516, a program with no router, is no
longer reported: such a program is a command). Each component’s imports
are @0.2.0. http.Client works through the host’s
wasi:http/outgoing-handler, imported only by a program that reaches it (see
spec/std.md). A command’s TCP network is wasi:sockets’ (2026-11-03):
Net.listen, Net.dial, Net.dial_timeout, Net.lookup_host, Net.only,
Listener and Conn with their deadlines, with the native targets’ NetErr
values and texts; no Unix domain sockets (unix: is Io) and no service
names for ports. A component that imports wasi:sockets/tcp needs its
host’s network (wasmtime run -S inherit-network=y), one that imports
wasi:sockets/ip-name-lookup name lookup (-S allow-ip-name-lookup=y);
a component that imports neither needs neither. HTTP servers and clients
over the native sockets, TLS, UDP and DNS records are not yet available in
a command. A handle_stream route
reads the request body from the host’s input-stream as it arrives, with its
trailers (incoming-body.finish); an http.stream response’s body goes to
the host’s output-stream as it is written, and its trailers through
outgoing-body.finish.
--targets=wasip3/wasm, not part of all and named alone, builds a
program that calls http.serve_component as a WASI 0.3 wasi:http
component (decision 0447 stage 5, steps 1 and 2, 2026-11-03): it
exports wasi:http/handler@0.3.0’s handle, an async function lifted
with a callback, and imports wasi:http/types@0.3.0, and
wasi:http/client@0.3.0 when it makes outgoing requests; its output and
clocks are the @0.2.0 interfaces a wasip2/wasm component imports. Main
runs inside handle. A handle_stream route reads the request body as
it arrives (stream<u8>), with its trailers (a future); a response’s
body goes to the host as main writes it, then its trailers. http.Client
sends through client.send, lowered async, writing the request body
while the call runs. Several requests run at once in an instance
(step 3, 2026-11-04): each runs main in a task of its own, and a task
that waits for the host lets the others run; no state outlives main, so
the requests share nothing but the instance’s memory.
On wasip3/wasm, a program that does not call http.serve_component is
XO1515.
Binaries are static and builds are reproducible: the same source in the
same directory, lockfile, and toolchain version produce byte identical
output (the binary records the absolute source directory, which crash
bundles and xo replay use, so a copy elsewhere differs in those bytes).
Each build writes an SBOM (<bin>.sbom.json). [later] No SBOM is
written yet.
12.2 Platform specific code
There are no build tags and no filename based platform selection.
target is a predeclared compile time constant with fields
os: TargetOs (Linux Darwin Windows Wasi FreeBSD) and arch: TargetArch
(Amd64 Arm64 Wasm32 Riscv64):
pub fn config_dir(env: Env) -> Str ! Error uses env {
match target.os {
Linux => env.get("XDG_CONFIG_HOME") ?? "${env.home()?}/.config"
Darwin => "${env.home()?}/Library/Application Support"
Windows => env.get("APPDATA").or_err("APPDATA not set")?
Wasi => "/config"
}
}
- A
matchontarget.osortarget.archis resolved at compile time; only the chosen arm is code generated. - Every arm is type checked for every target on every
xo checkandxo build, so a broken Windows branch fails on a macOS machine. A missing OS is a non exhaustive match error. - Platform specific APIs live in
std/sys/<os>and can only be referenced from inside the matching arm (errorXO1001otherwise). [later] Nostd/sys/<os>module exists yet, soXO1001is reserved (10.6). - The native backends build
targetas a constant of the build’s target, so only the chosen arm is code generated (decision 0107).
13. Editions and compatibility [P1]
The written policy, what 0.x promises today and what 1.0 will promise, is decision 0567; this section is its source for the 1.0 promise.
xo.moddeclares anedition. The compiler supports every edition ever released. Modules on different editions link together.- Before 1.0 the only edition is
preview(decision 0155). It is not frozen: during the 0.x releases a minor release may change it (decision 0089), andxo fixcarries the migration.edition 2026, its name before decision 0155, is an alias ofpreviewduring the 0.x releases;xo checkreports the fixable noteXO1315on it andxo fixrewrites it. - During 0.x every breaking change ships with an
xo fixrewrite (or a diagnostic that names the replacement) and a CHANGELOG entry marked Breaking; a deprecated form is removed no sooner than one minor release after its deprecation is announced; a diagnostic code never changes meaning (decision 0567). - At 1.0 the first frozen edition is named and
xo fixrewritesedition previewto it mechanically. The compatibility promise below starts with that edition, not withpreview. - A new edition may change syntax and defaults, never the meaning of code in older editions.
xo fix --edition=<name>migrates a module mechanically and must leave it compiling. An edition is not released until its rewriter is complete.- The standard library follows the same rule:
stdAPIs are never removed within an edition; deprecated APIs ship rewrites inxo fix.
14. Standard library
The prelude (methods on builtin types) and the standard library surface are
specified in spec/std.md. Modules:
| Module | Contents |
|---|---|
std/http | Router, server, client, requests, responses, middleware, error to status mapping |
std/json | Derive based encode and decode, Patch[T] for partial updates |
std/log | Structured logging; performs the log effect (6.1) |
std/task | isolate, with_timeout, is_canceled, Semaphore |
std/time | Time zones, civil dates and times, layouts with named fields (arithmetic is in the prelude; std.md 13) |
std/testing | Fake capability types, generators, captured logs |
std/sql | Database handles over drivers, in memory driver (draft) |
std/crypto | SHA-256, HMAC, constant time compare, random tokens, password hashing |
std/path | Pure helpers for / separated paths |
std/cli | Command line parsing: flags, arguments, subcommands, help, usage errors (std.md 14) |
std/term | Terminal colors that follow NO_COLOR and FORCE_COLOR (std.md 15) |
std/csv | CSV and TSV parsing and formatting (std.md 16) |
std/regexp | RE2 regular expressions (std.md 17), on every backend (natively in Xo, decision 0172) |
std/archive | gzip, tar, and zip in memory (std.md 18), on every backend (natively in Xo, decision 0172; zip64 archives are an error natively) |
std/toml | TOML 1.0 documents decoded with the JSON rules (std.md 19) |
std/go | go.Error, the error of a Go call (4.4) |
std/trace, std/config, std/text, std/sys/<os> | Later drafts |
15. Grammar summary (informal EBNF)
Every comma separated list allows a trailing comma and may span lines. The
parser of xo (compiler/parser; internal/parser until decision 0215)
is the reference implementation of this grammar.
File = { UseDecl } { TopDecl } .
UseDecl = "use" ImportPath [ "as" ident ]
| "use" "go" string [ "as" ident ] // 4.4
| "use" "c" string { "link" string } [ "as" ident ]
[ "uses" ( "none" | Effect { "," Effect } ) ] . // 4.5
ImportPath = PathSeg { "/" PathSeg } . // std/http, github.com/acme/x
PathSeg = PathChar { PathChar } . // xo-lang, rate-limit, v2, example.com
PathChar = letter | digit | "_" | "-" | "." . // ASCII only; no empty, `.`, or `..` segment (XO0158)
TopDecl = { DocComment } [ "pub" ] ( FnDecl | StructDecl | EnumDecl | IfaceDecl
| TypeDecl | ConstDecl ) | TestDecl .
FnDecl = "fn" [ Receiver ] ident [ TypeParams ] Params [ "->" Type ] [ ErrSpec ]
{ FnClause } Block .
FnSig = "fn" ident [ TypeParams ] Params [ "->" Type ] [ ErrSpec ] { FnClause } .
Receiver = "(" [ "var" ] ident ":" Type ")" .
TypeParams = "[" TypeParam { "," TypeParam } "]" .
TypeParam = ident [ ":" ( Type | "Effects" ) ] .
Params = "(" [ Param { "," Param } ] ")" .
Param = [ "var" ] ( ident ":" Type [ "=" Expr ] | "self" ) . // self: interface methods only
ErrSpec = "!" [ Type ] .
FnClause = "uses" ( EffectList | "(" EffectList ")" )
| "requires" [ "(" "debug" ")" ] Expr [ "else" Expr ]
| "ensures" [ "(" "debug" ")" ] Expr
| "as" "c" string . // a C export (3.2, decision 0574)
EffectList = Effect { "," Effect } .
Effect = ident [ "." ident ] .
Type = BaseType { "?" } .
BaseType = QualName [ "[" TypeArg { "," TypeArg } "]" ]
| "(" ")" | "(" Type ")" | "(" Type "," [ Type { "," Type } ] ")"
| FnType .
TypeArg = Type | EffectList . // effect sets for fx parameters
FnType = "fn" "(" [ FnTParam { "," FnTParam } ] ")" [ "->" Type ] [ ErrSpec ]
[ "uses" ( Effect | "(" EffectList ")" ) ] .
FnTParam = [ "var" ] Type .
StructDecl = "struct" ident [ TypeParams ] "{" { Field } "}" [ Invariant ] [ Derive ] .
Field = { DocComment } [ "pub" ] ident [ "as" ( string | rawstring ) ] ":" Type [ "=" Expr ] .
Invariant = "invariant" Expr .
Derive = "derive" DeriveItem { "," DeriveItem } .
DeriveItem = QualName [ "(" DeriveArg { "," DeriveArg } ")" ] .
DeriveArg = ident ":" ( ident | string | rawstring ) .
EnumDecl = "enum" ident [ TypeParams ] "{" { Variant } "}" [ Derive ] .
Variant = { DocComment } ident [ "as" ( string | rawstring ) ] [ "(" VField { "," VField } ")" ] .
VField = ident ":" Type | "from" Type .
IfaceDecl = "interface" ident [ TypeParams ] "{" { FnSig } "}" .
TypeDecl = "type" ident [ TypeParams ] ( "=" Type | "struct" "(" Type ")" [ Derive ] ) .
ConstDecl = "const" ident [ ":" Type ] "=" Expr .
TestDecl = "test" string [ "for" Param { "," Param } ] [ "seed" int ]
[ "uses" EffectList ] Block .
Stmt = "let" Pattern [ ":" Type ] "=" Expr
| "var" ident [ ":" Type ] "=" Expr
| ConstDecl
| Place AssignOp Expr
| "defer" ( Stmt | Block ) | "return" [ Expr ]
| "break" [ ident ] | "continue" [ ident ]
| ForStmt | WhileStmt | Expr .
AssignOp = "=" | "+=" | "-=" | "*=" | "/=" | "%=" .
Place = ident { "." ident | "." int | "[" Expr "]" } .
ForStmt = [ ident ":" ] "for" Pattern [ "?" ] "in" Expr [ "bound" Expr ] Block .
WhileStmt = [ ident ":" ] "while" [ ( Expr | "let" Pattern "=" Expr ) [ "bound" Expr ] ] Block .
Expr = IfExpr | MatchExpr | ScopeExpr | SelectExpr | Block | FnLit | Binary
| "while" Block | "???" . // infinite loop as an expression, type Never
Binary = Operand { BinOp Operand } [ "??" ( Exit | ErrArm ) ] .
ErrArm = ident "=>" ( Expr | Stmt ) . // r ?? e => body (decision 0321)
Exit = "return" [ Expr ] | "break" [ ident ] | "continue" [ ident ] . // type Never
Operand = Unary [ "is" Pattern ] . // `is` binds like `==`
FnLit = "fn" "(" [ LParam { "," LParam } ] ")" [ "->" Type ] [ ErrSpec ]
[ "uses" ( EffectList | "(" EffectList ")" ) ] Block .
LParam = [ "var" ] ident [ ":" Type ] .
IfExpr = "if" ( Expr | "let" Pattern "=" Expr ) Block [ "else" ( IfExpr | Block ) ] .
MatchExpr = "match" Expr "{" { Pattern [ "if" Expr ] "=>" ( Expr | Stmt ) } "}" .
ScopeExpr = "scope" ident Block .
SelectExpr = "select" "{" { SelectArm } "}" .
SelectArm = ( [ ident "=" ] Expr | "after" Expr ) "=>" ( Expr | Stmt ) .
Postfix = Primary { "." ident | "." int | Call | Index | "?" | "with" StructLit } .
Index = "[" ( Expr | [ Expr ] ( ".." | "..=" ) [ Expr ] ) "]" .
Call = [ "[" TypeArg { "," TypeArg } "]" ] "(" [ Arg { "," Arg } ] ")" .
Arg = [ ident ":" ] Expr .
Literal = int | float | duration | string | rawstring | bytes | rune | "true" | "false" .
Pattern = PatAlt { "|" PatAlt } .
PatAlt = "_" | ident | [ "-" ] Literal [ ( ".." | "..=" ) [ "-" ] Literal ]
| "(" ")" | "(" Pattern ")" | "(" Pattern "," [ Pattern { "," Pattern } ] ")"
| [ QualName "." ] ident [ "(" ( ".." | PatFields ) ")" ] // variant
| QualName "{" PatFields "}"
| "[" [ PatElem { "," PatElem } ] "]" . // ".." at most once
PatElem = Pattern | ".." .
PatFields = PatField { "," PatField } [ "," ".." ] .
PatField = [ ident ":" ] Pattern .
QualName = [ ident "." ] TypeName . // optional module prefix
TypeName = ident .
Operator precedence, highest first: postfix (. () [] ?), unary (- ! ~),
* / % << >> &, + - | ^, .. ..=, == != < <= > >= is, &&, ||, ??.
Parsing rules the grammar alone does not settle:
- Type arguments vs. indexing.
x[...]holds type arguments when every element looks like a type (UpperCamel,mod.UpperCamel,(, orfn) and either(follows orxis anUpperCameltype name; otherwise it is an index. Sojson.decode[User](b)andMutex[Int].new(0)take type arguments, whilexs[i]andm[Red]index. An effect argument (a lowercasenameorname.sub) also counts as a type element, except that a base spelled like a constant (UPPER_SNAKE) with only lowercase names in the brackets is an index:NAMES[i](decision 0143). {in expression position is an empty map when it is{}, a map literal when a:appears at depth zero before the first newline, and a block otherwise. A match arm=> {}is therefore an empty map; write()for unit.- Function types in return position take a trailing
usesthemselves:-> fn(A) -> B uses clock {gives the effect to the returned function. Write-> (fn(A) -> B) uses clock {to put it on the declaration. - In a function type, a
useslist with more than one effect must be parenthesized, because a following comma would otherwise be ambiguous. - Only
while { }(no condition) may appear in expression position. - Triple quoted strings support escapes and interpolation; a blank first and last line are dropped; the common indentation is measured on the source.
- An interpolation is
"${" Expr [ ":?" ] "}"(1.6)::?asks for the Debug text (decision 0296).
Appendix A: complete example
// api/main.xo
use std/http
use std/log
pub struct User {
pub id: Int
pub name: Str
pub email: Str?
} derive Json
pub enum ApiErr {
BadRequest(msg: Str)
NotFound(id: Int)
}
// http maps handler errors to responses through this interface.
fn (e: ApiErr) status() -> Int {
match e {
BadRequest(_) => 400
NotFound(_) => 404
}
}
fn (e: ApiErr) display() -> Str {
match e {
BadRequest(msg) => msg
NotFound(id) => "user ${id} not found"
}
}
struct Store {
users: Mutex[Map[Int, User]]
}
fn (s: Store) get(id: Int) -> User ! ApiErr
requires id > 0 else ApiErr.BadRequest(msg: "id must be positive")
{
s.users.with(fn(m) { m.get(id) }).or_err(ApiErr.NotFound(id: id))?
}
fn routes(store: Store) -> http.Router {
var r = http.router()
r.handle("GET /users/{id:Int}", fn(req) -> http.Response ! ApiErr {
let u = store.get(req.param_int("id"))?
http.json(200, u)
})
r
}
fn main(os: Os) ! {
let store = Store{users: Mutex.new({1: User{id: 1, name: "Ada", email: None}})}
let srv = http.server(os.net.listen(":8080")?, routes(store))
log.info("listening", {"addr": ":8080"})
srv.serve()?
}
test "missing user is 404" {
let store = Store{users: Mutex.new({})}
let resp = routes(store).call(http.new_request("GET", "/users/9"))
expect(resp.status) == 404
}
Appendix B: open questions
Tracked in knowledgebase/decisions/ once decided.
Method syntax: Go style receivers orDecided in 0090: receivers.implblocks.Decided in 0091: insertion order.Mapiteration order.Error frame capture cost in release builds.Decided in 0092: frames on in every build, captured lazily (implemented on the Go backend; the native backends record them too, decision 0104).HowDecided in 0019.httphandler errors map to status codes.FFI design and record/replay.Decided in 0093:use goand nativeuse c, foreign calls recorded at the boundary (use gorecording implemented;use cis implemented (4.5, decision 0116) without recording, since native builds do not record yet).Interpolation syntax.Decided in 0021:${x}.