Operational semantics
This document specifies what Hale programs do when they run. Where grammar.ebnf says what's syntactically valid and types.md says what's meaningfully valid…
Reference material, synced from the compiler repo’s
spec/. The guide is the gentler path in.
This document specifies what Hale programs do when they
run. Where grammar.ebnf says what’s syntactically valid and
types.md says what’s meaningfully valid, this document says
what happens at runtime.
The semantics are described informally (engineering-grade prose), not as formal small-step rules. Formal operational semantics are deferred to v1+; the framework’s substrate-invariance claim is not blocked on full formalization.
Program startup
Section titled “Program startup”- The runtime initializes:
- Region allocator, schedulers (one per CPU core; cooperative within each), bus router, lifecycle dispatcher.
- Establishes the runtime root locus as the implicit
parent of
main’s implicit locus.
- Bus topics with
bindings { Topic: ...; }entries in themainlocus are registered against their declared transports. Topics without a binding stay same-process via the cooperative queue. fn main()is invoked.
Function call
Section titled “Function call”A fn name(args) -> ret { body } invocation:
- Caller passes args by value.
- Implicit locus is allocated for the function’s scope.
- Body executes statement-by-statement.
- Locally bound handles are bound to local names.
- Anonymous-child loci with ongoing-work surface attach to the implicit locus.
- On
return value;, control flows back to caller. Before return, the implicit locus drains and dissolves (waits for all children to finish; depth-first cascade per F.4).
Receiver calls on text values
Section titled “Receiver calls on text values”For x of type String, StringView or std::str::ByteView, a call
x.f(args) is the call std::str::f(x, args); for x of type Bytes,
BytesView or BytesMut, it is std::bytes::f(x, args) (GH #2068,
F.59). It applies when that fn is public and takes a value of x’s type
first (v.find("\n", 0) on a ByteView is std::str::find(v, "\n", 0)):
fn main() { let raw = " Key = Value "; let (k, v) = raw.cut("=") or { return; }; println(k.trim().lower(), "|", v.trim()); let b = std::bytes::from_string("hale"); println(b.at(0) or -1);}- It is the path call. The check types
x.f(args)asstd::str::f(x, args)and records it; the program is then read with the path call written in its place, so every analysis after the check (effects, allocation, ownership, the summaries) and lowering see one call, classified as the path call is. A diagnostic about the call (an argument’s type, an unaddressed failure) is the path call’s, at the namef. - Calls chain left to right, each receiver the value the call
before it returned:
raw.trim().lower(). - Text sources. In a
forloop’s source and an element chain’s,x.split(sep),x.lines()andx.words()on a string are the sourcesstd::str::split(x, sep),std::str::lines(x)andstd::str::words(x)(§ Text sources). Whetherxis a string is the check’s to say, so such a loop or chain is desugared once the receiver calls are written as path calls: on a string it is the text source’s scan, and on any other value (a locus’s ownwords()) it is the loop over that method’s result it always was. - Nothing else is a receiver call. A record type has no methods, a
locus’s methods are its own, and a fn of the program’s is never called
on a value (
s.shout()is refused; writeshout(s)). On a text value, a name that is no fn of the namespace taking that type first is a type error at the name, with the nearest fns (“no fn `trimm` in `std::str` takes a `String` first, so `.trimm` names nothing on it — the nearest are `.trim`, …”);s.len()points to the builtinlen(s).x.fwithout the call is no value. - Generic bodies. A receiver call is resolved on the body’s own types: on a value of a type parameter it calls nothing, and a specialization that would make it text is refused (“write `std::str::trim(…)`”).
Implicit Int → Float widening at call sites
Section titled “Implicit Int → Float widening at call sites”When a function parameter has type Float and the call-site
argument has type Int, codegen inserts an implicit
sitofp widening at the call site. The same rule fires at
let-binding type ascriptions: let nf: Float = self.n;
where self.n: Int succeeds. The widening is one-way
only — Float → Int narrowing remains explicit, and
Decimal never participates in implicit cross-type
conversion. Phase 2c. See F.23 in
spec/design-rationale.md and the Phase 2c entry in
spec/stdlib.md.
Expressions — if and block tails
Section titled “Expressions — if and block tails”A { ... } block whose last item is an expression without
a trailing ; carries that expression as its value. In
expression position (let-RHS, fn-call argument, if-arm body)
the value is consumed; in statement position (loop body,
Stmt::If / Stmt::Match block) the trailing expression is
evaluated for side effects and the value is discarded —
semantically equivalent to having added the ;. A call there is the
call statement, a builtin’s or a fn’s that returns nothing included:
if c { println("x") } and a statement match‘s arm P -> { println("x") } build as if c { println("x"); } does. An if, a
match (an if let included) or a block there is the statement of
that shape, its own arms’ tails statements in turn: a value-shaped
trailing if c { println("a") } else { println("b") } (below) ending a
body that returns nothing is that if statement. (GH #2016; until then
the check passed these and the build refused the call as having no
binding.)
A fn-shaped body (free fn, locus method) with a
declared return type treats its trailing expression as an
implicit return: fn double(n: Int) -> Int { let d = n * 2; d } returns d (2026-08-11 — previously the typechecker
accepted this form and codegen rejected it as a fall-through).
The tail is checked as that return is: against the return type
(a fallible body’s success type), a set’s member flowing into the
set, an Int widening to a Float (2026-11-15 — previously the
check judged only a Decimal tail’s scale, and the build refused a
tail of another type, a member included, with no place). A
fallible locus method’s tail is its return as every other body’s
is.
A body with no declared return type keeps statement-position
semantics: the tail is evaluated for side effects. So does a () fallible(E) body’s, an or included (fn fwd() -> () fallible(E) { touch() or fail err } lowers as the statement touch() or fail err;;
GH #2005).
The same body’s last statement is its value when it is a match,
an if or a block: its arms and tails carry the value down, each leaf a
return (§ “Definite return”, below).
Such a body returns nothing, so a return in it carries no value: a
return <expr>; in a fn with no -> T (a fallible fn’s
success type is then ()) or in a lifecycle hook (birth, run,
accept, drain, …) is a type error at the value, a call with no
value of its own included (return touch() or fail err; in a
() fallible(E) fn: write the call as a statement, then return;). fn main is the
exception: its return n; is the process exit code (§ “Process
exit”).
main.hl:1:66: type error: `return` carries a value, but this bodyreturns nothing: a fn with no `-> T`, or a lifecycle hook, whichnever returns a value. Declare the return type (`fn f() -> T`),or write `return;`.if cond { ... } else { ... } is dual-position:
- As statement (
if c { foo(); }— noelse, or any arm whose block has no trailing expression): no value; trailing expressions in either arm are evaluated for side effects. - As expression (e.g.,
let x = if cond { i } else { j };): the then- and else-arms’ trailing expressions are phi-merged at the join basic block. The else branch is required; arm trailing-expression types must match; arms may carry their own let-bindings before the tail (the bindings are scoped to the arm).
The two positions are distinguished by shape, not syntactic
context (WS3.2). A trailing if — the last item
of a block, with no ; — becomes that block’s tail expression
when it is value-producing: every arm (then, else, and each
else if) must end in a trailing expression. This is what lets
an if nest as a block value:
let x = if a { if b { p } else { q } } else { r };// \__ then-arm block whose tail is the inner if __/The inner if is the then-arm block’s tail, so the outer
if’s then-value is the inner if’s value. A trailing if
that is not value-producing (no else, or an arm with no
tail) stays a statement — it has no value to carry, and forcing
it into the value path would leave a tail-less arm with nothing
to yield.
else if chains carry through the value path —
ElseBranch::ElseIf recurses and the innermost arm’s tail
feeds the phi at the outermost merge.
Phase 2b introduced if-as-expression; WS3.2
(2026-06-11) made a value-producing trailing if compose as a
block tail. See F.24 in spec/decisions.md and the
Phase 2b entry in spec/stdlib.md.
match is dual-position too (Gap C, 2026-07-17):
- As statement: arm bodies are evaluated for side effects;
heterogeneous arm-body types are legal (values discarded). A
statement match whose every arm diverges (
return,fail,break, …) ends its block, so a fn whose last statement is such a match returns on every path (friction sweep 2026-10-12: the check said so and the build refused it as falling through). The no-arm-matched edge, unreachable under F.18 exhaustiveness, panics (MatchFellThrough) rather than run on. - As expression (
let x = match n { 0 -> 10, _ -> 20, };): every arm body’s value is phi-merged at the join block, so all value-producing arms must agree on one type (checked at typecheck with the match’s span;matchexpression works with every pattern form the statement supports — literal / binding / wildcard / tuple / enum-constructor patterns, guards, and block arm bodies with trailing expressions). A block arm’s value is its tail, or its trailingmatch’s (below); a block arm with neither that does not leave produces no value,(), so it disagrees with a valued arm:match c { 1 -> 5, _ -> {} }is refused at the match (“match expression arms have mismatched types: `Int` vs `()`”), as anifexpression’s mismatched arms are. A block arm that leaves on every path, as § “Definite return” judges a path (areturn,fail,break,continue, an endless loop, or anif/matcheach of whose branches leaves, wherever it stands in the block:0 -> { return 2; println("x"); }leaves before its unreachable last statement), is a diverging arm and supplies no type (GH #2046; v0.34.0 judged only the arm’s last statement and refused that arm as()). Until GH #2016 the check judged only expression arms (and a binding as an arm’s value carried no type), soS::B(v) -> v, _ -> "s"and the block arm above checked and the build refused them. F.18 exhaustiveness applies in both positions. The only reachable no-arm-matched case in expression position is a match whose arms are all guarded and every guard is false at runtime; it yields the zero value of the result type (0/0.0/false/ empty for pointer-shaped types), mirroring the statement form’s silent-no-op fallthrough. - As a block’s value (2026-11-06): a trailing
match— the last item of a block, with no;— stays a statement in the grammar (unlike a trailingif, above: a side-effectmatchends many fn bodies), and is the block’s value wherever the block is used as one: alet’s block, a match arm’s block in a match expression, anifexpression’s arm, anor { … }substitute. There it is typed and lowered as a match expression (every arm one type), soKind::A -> { let m = n + 1; match m { 1 -> "one", _ -> "many" } }is an arm of aStringmatch. A diverging arm beside a valued one is the join (only the valued arms reach it). A trailingmatchwhose every arm leaves without a value (areturn,fail,break, an endless loop, transitively through nested blocks,ifs andmatches) makes the block a diverging one, legal wherever a diverging expression is: a match expression’s block arm (beside arms that supply the value, or beside none, as a match whose every arm returns is), anifexpression’s arm beside one that supplies the value (theifis that arm’s value and has its type; until GH #2111 a leavingthenarm left theifuntyped, solet s: String = vof anIntarm checked), anor { … }substitute (the call’s success is the value). Where a value is required of the block and nothing else supplies one — alet’s block, a call argument, areturn, an assignment, a field, a condition, an operand of&&or||, awhilecondition, a match guard — the check refuses the block (“this block ends in a `match` whose every arm leaves without a value … give an arm a value, or end the block with `return`”), as it refuseslet x = { return 1; };. In a block used as a statement (a loop body, a body that returns nothing) it stays the statement it reads as; at the end of a body with a declared return type it is the body’s value (§ “Definite return”, GH #1940). Until 2026-11-06 the check passed the arm above and the build refused it as a block with no trailing expression, where the same arm ending inif … else …built (downstream handoff); 2026-11-07 refused the all-leaving trailingmatchin every position, a match arm’s included, where v0.32.7 had built it (downstream handoff review).
An enum-constructor pattern’s values are each a binding, _ or a
literal: a nested pattern there (Op::Pair((a, b))) is a type error at
the nested pattern; bind the value and match or read the binding in the
arm.
.Variant patterns (GH #2069, F.58). Against a value whose type
is an enum (directly, through an alias, or a generic enum’s
instantiation), a pattern may name a variant with a leading dot:
type Outcome = enum { Result(Int), Refused(String), Pending };
fn index_or(o: Outcome, fallback: Int) -> Int { return match o { .Result(n) -> n, .Refused(_) | .Pending -> fallback, };}.Vand.V(p, …)mean exactlyE::VandE::V(p, …),Ethe enum of the value matched, in every position a constructor pattern is written: a match arm, an or-pattern’s alternative,if let,let … elseand a patternlet. Exhaustiveness, redundancy, the binding rules and lowering read it as that pattern, and the two spellings mix in one match. Inside a tuple pattern or a variant’s values it is the nested patternE::Vwould be, refused the same way (below).- The dot is written against the name:
. Vis a parse error. - Against a value whose type is no enum (an
Int, a set, a generic body’s type parameter once a call specializes the body) it is a type error at the pattern (“`.V(…)` names a variant of the value’s enum, and the value matched is of type `Int`, which is no enum”); against a set, whose members are matched by their types’ names, the message says to writeMember(…). - A name that is no variant of the value’s enum is a type error at the pattern with the nearest variant, or the list of them (“`.Wrok(…)`: enum `Place` has no variant `Wrok` — did you mean `.Work`?”).
.Vis a pattern only, never an expression.
The checker resolves each .V against the type it gave the scrutinee
and records the variant; lowering reads that record rather than naming
the enum again, and in a generic body each specialization resolves the
pattern against its own instantiation.
A variant’s pattern names all of its values or none: E::V (and
.V) with no parentheses matches the variant whatever it carries, and
one with parentheses names each value the variant declares. A count that
differs (Job::Work(1, 2) against Work(Int), .Rest(x) against a
variant that carries nothing) is a type error at the pattern (“the
variant `Work` carries 1 value, and this pattern names 2”). Until GH
#2069 the check passed it and the build refused it.
A pattern’s bindings are locals of their arm (its guard and its
body), each of the type of what it binds: a bare binding is of the
scrutinee’s type, a variant’s value of the variant’s declared field
type (a set member’s of the member’s type), a tuple pattern’s part of
the element’s type. A binding is typed at its uses as any other local
is, so with type S = enum { A, B(Int) }, S::B(v) -> { let t: String = v; … } is a type error at v. An or-pattern’s bindings are the first
alternative’s (every alternative binds the same names at the same
types, below). Until GH #2016 a binding was entered untyped, and that
let passed both the check and the build.
A literal in a pattern is a value of the type it is matched
against, compared as lowering compares them (an identity’s or a
range’s scrutinee is its Int): match n { "a" -> … } over an
Int, or the 2 of (1, 2) against an (Int, String), is refused
at the literal (“this pattern is of type `String`, and the value
matched is of type `Int`”). A quantity literal in a pattern is the
quantity it is in an expression, converted into the scrutinee’s
denomination: match d { 1min -> … } over a Duration matches sixty
seconds. A Decimal literal takes the scrutinee’s scale. The values in
an enum constructor’s pattern (Fee::Flat(2.50d)) are matched against
the variant’s declared types the same way.
Or-patterns (GH #1995 E2). An arm’s pattern may be two or more
alternatives separated by |; the arm matches when one of them does:
type CtlError = enum { Invalid(String), NotFound(String), NotReady(Int) };
fn problem(e: CtlError) -> String { return match e { CtlError::Invalid(p) | CtlError::NotFound(p) -> p, CtlError::NotReady(h) -> f"not ready: {h}", };}
fn usage(verb: String) -> String { return match verb { "assign" | "unassign" -> verb + " <name>", "close" -> "close <name>", _ -> "unknown", };}- Every alternative binds the same names at the same types, since the guard and the body read them whichever alternative matched. A name one alternative binds and another does not, or binds at another type, is a type error at the alternative (or its binding), naming the name and both alternatives.
- Alternatives are tried left to right. A guard covers the whole arm: it is evaluated with the bindings of the alternative that matched, and when it is false the next alternative that matches is tried with its own bindings, before the next arm. The arm behaves exactly as its alternatives written as consecutive arms with the same guard and body would.
- F.18 exhaustiveness counts each alternative of an unguarded arm as the
arm it could have been written as:
true | falsecovers aBool, and enum variants covered through alternatives need no_. |is top level only, as patterns are flat: inside a tuple pattern or a variant’s values a pattern is one pattern, and a|there (E::A(1 | 2)) is a parse error; writeE::A(1) | E::A(2).- An alternative an earlier unguarded arm, or an earlier alternative of the same arm, already covers is never tried, and the check warns at it (“the alternative … is never tried”). (A guarded arm that binds names does not make its own later alternatives redundant, since the guard is tried again with theirs.)
- A pattern is not an expression, so the
|between alternatives is never the bitwise operator; the guard and the body are expressions, wherex | yis.
The body is lowered once: each alternative’s test branches to the arm’s one guard or body block, its bindings merged there.
Matching strings. A String scrutinee matches string-literal
patterns by value ("assign" | "unassign" -> …). A ladder of three or
more if tests comparing one String place with literals, chained with
else if or as consecutive if statements, is the same decision, and
--warn-string-match (on hale check or hale verify) warns at its
first test with the match it reads as. The advisory is off by default
for every verb, hale verify included, and never reports stdlib
source.
Scrutinee-less form. match { cond -> body, else -> body }
omits the scrutinee and tests guards directly:
let tier = match { n < 10 -> "small", n < 100 -> "medium", else -> "large",};Arms are tried in written order and the first whose condition is
true wins. else is the catch-all and carries no condition.
This is sugar, desugared at parse into the guarded form it
replaces — match { c -> b, else -> d } is
match true { _ if c -> b, _ -> d }. Everything downstream sees an
ordinary match, so both positions, block arm bodies, the trailing
comma rule, and the all-guards-false fallthrough above behave
identically.
The form exists because first-match-wins over conditions is common where dispatch is a ladder of tests rather than a shape match, and the scrutinee in that case is a value the author invents only to ignore.
match { is not ambiguous with matching on a block expression:
that shape is written match (…) { … }.
if let and let … else (GH #1995 E3). Two spellings of a
two-arm match, for the test of one pattern:
type Side = enum { Buy, Other(String) };type Outcome = enum { Result(Int), Refused(String) };
fn note(side: Side) -> String { if let Side::Other(raw) = side { "other: " + raw } else { "buy" }}
fn index_of(o: Outcome) -> Int { let Outcome::Result(index) = o else { return -1; }; return index * 2;}if let P = e { A } else { B }ismatch e { P -> { A }, _ -> { B } }, written by the parser, so the check, the analyses and lowering see that match. With noelsethe_arm is empty.Pis any arm’s pattern, an or-pattern included under the same binding rule, and its names are in scope in the then-block only. It is an expression asifis: used as a value it needs anelse, and both arms are typed as anif’s are (a mismatch is “`if let` arms have mismatched types: then=…, else=…”); a trailingif letevery arm of which ends in a value is its block’s value, as a trailingifis. Links chain both ways:if let … else if let … else, andif c { … } else if let … { … }.let P = e else { B };bindsP’s names in the enclosing block, after the statement. It islet x = match e { P -> x, _ -> { B } };(a tuple of the names when there are several, a statement match when there are none).Bruns whenPdoes not match and must leave, as § “Definite return” judges a path:return,fail,break,continue,terminate,violate, or a statement every branch of which does. A call completes,std::process::exitincluded. Anelsethat can complete is refused at the block, the completing path named (“the `else` of a `let … else` must leave …: what follows the statement runs only when `P` matches; this `else` can complete: …”). A name or a tuple of names takes anelsetoo; whenPmatches every value of its type theelsenever runs, and the check warns.- A plain
lettakes a pattern that matches every value of its type: a one-variant enum’s constructor (let Meters::M(n) = m;), a tuple of names, as it always did. One that can fail to match is refused at the pattern, “`P` can fail to match a `T`, so a plain `let` cannot bind it: add `else { … }` that leaves when it does not match …”. Until GH #1995 aletof anything but a name or a tuple of names did not parse. - A
letof a pattern takes no type annotation;let mut P = e else { … };binds its names mutable. - The names
Pbinds, in either spelling, are typed as a match arm’s bindings are (§match, a pattern’s bindings):indexabove is anInt, and is checked as one wherever it is used (GH #2016).
if let is the enum counterpart of or { return …; }, and it
introduces no Option (F.52). No keyword is added.
Definite return
Section titled “Definite return”A body with a declared return type (a fn, a locus method, a fallible fn with a success type) returns a value on every path that reaches its end.
The result position. Its tail is its value (above), and when its
last statement is a match, an if or a block, that statement is the
value: every arm of the match (an expression arm, or a block arm’s
own result position), the if’s then-block, each else if and its
else, and a block’s tail or last statement in turn. A leaf in result
position is checked as the return it is, against the return type
(“this is the body’s value (its last statement’s arm or tail): expected
`String`, got `Int`”), and lowered as one, for every result type:
fn word(n: Int) -> String { match n { 1 -> "one", _ -> "other" }}
fn sign(n: Int) -> Int { if n > 0 { return 1; } else if n < 0 { -1 } else { 0 }}A leaf that leaves (return, fail, …) is unchanged. A trailing
match stays a statement in the grammar, and a trailing if some arm
of which has no tail stays one too (§ “Expressions — if and block
tails”); in a body that returns a value, the result position is what
makes them its value.
Reaching the end. A path leaves without reaching the end when
it meets return, fail, break, continue, terminate or
violate; an if with an else each of whose branches leaves; a
match each of whose arms leaves (F.18 makes it exhaustive); a block
that leaves; a while true loop no break leaves (a break inside a
nested loop leaves that loop, not this one); or a statement whose value
is a match, an if … else or a block expression that leaves on every
path. Any other statement can complete, and the body can reach its end
when its last statement can, or when it is empty. Such a body is a type
error at the declaration’s name, naming the path as a secondary
location:
main.hl:1:4: type error: fn `sign` returns `Int`, and its body can reachits end without a value: this `if` has no `else`, so when its conditionis false the body ends after it. Return a value on that path, or end thebody with its value (a tail expression, or a `match`, an `if … else` ora block whose every arm ends in one) note: the path that reaches the end without a value at main.hl:2:5The paths it names: an if with no else, and an if let with
none (GH #1995); a while loop whose
condition can be false, and a for loop; the break that leaves a
while true; an arm or block whose last statement completes; an empty
body, block or arm. The judgment is the program’s shape, not its
values: while n > 0 { return n; } can finish as far as it is
concerned, and a call that never returns (std::process::exit) is a
call that completes. Until GH #1940 the check passed such a body and the
build refused it as falling through, with no file or line; a tail
match was refused the same way.
Expression statements
Section titled “Expression statements”An expression followed by ; is a statement only when evaluating
it does something: a call (a fn, a method, a builtin — its value,
if any, is discarded), a locus literal (an instance built in
statement position, § “Locus instantiation”), or an or over a
fallible call. Any other expression — an arithmetic or comparison,
a name, a field read, an index, a literal — only computes a value
and discards it, and is a type error at the expression:
main.hl:1:24: type error: this expression's value is unused: astatement that only computes a value does nothing. Bind it(`let v = ...;`), assign it (`self.f = ...;`), pass it to a call, ordelete the statement.A block’s trailing expression with no ; is not a statement and
is not judged here (§ “Expressions — if and block tails”). Before
this rule the checker accepted a + 2; and the backend refused it
with no file or line.
Expressions with no value
Section titled “Expressions with no value”A call to a fn that returns nothing, an or on a () fallible(E)
call (push(self.marks, t) or { }, write_file(p, s) or discard),
and an if / match / block with no tail value produce no value:
their type is (), and there is no () value to bind, store or
compute with. Such an expression is a statement or nothing. Where a
place takes the type of what it is given rather than checking it
against a declared one — a let (with or without an annotation),
a tuple or array element, an operand, a generic fn’s argument — the
check refuses it at the expression:
main.hl:7:20: type error: let `full` needs a value, and thisexpression produces none (its type is `()`): a call to a fn thatreturns nothing, an `or` on a `() fallible(E)` call, or an `if` /`match` / block with no tail value. Write it as a statement of itsown (`call() or { ... };`), or give it a value to produce.A place with a declared type (a parameter, a field, a condition, a
return) already refused () as a type mismatch. Until 2026-10-13
the others checked clean and the build refused them with no file or
line.
Operators and their operand types
Section titled “Operators and their operand types”== != < > <= >= and the arithmetic, bitwise and logical
operators apply to these operands (both of one type; an Int widens
into a Float, F.23):
| Operand | Operators |
|---|---|
Int (an identity’s and a range’s are the unit dialect’s, spec/units.md) |
+ - * / %, & | ^ << >>, unary - ~, every comparison |
Float |
+ - * /, unary -, every comparison |
Decimal<S> |
+ - * / %, unary -, every comparison (one scale) |
U64 |
+ - * / % (checked and unsigned: an overflow or a division by zero is a violation), & | ^ ~, << >> by an Int count from 0 to 63, every comparison (unsigned); no unary -; an integer literal operand is a U64, and nothing else mixes in (spec/types.md § U64) |
I32, U32, I16, U16, I8, U8 |
+ - * / % (checked at the width: an overflow, a division by zero, or a signed minimum divided by or negated through -1, is a violation), & | ^ ~, << >> by an Int count below the width (>> arithmetic on a signed one), every comparison (signed or unsigned as the type is), unary - on a signed one; an integer literal operand is the other’s type, and operands never widen (spec/types.md § Fixed-width integers) |
U256, I256 |
+ - * / % (checked: an overflow or a division by zero is a violation), & | ^ ~, << >> by an Int count, unary - (an I256’s only), every comparison; never mixed with another type (spec/types.md § U256 and I256) |
Duration, Time, a quantity, a point |
the unit dialect’s algebra (spec/units.md) |
Bool |
== !=, && ||, unary ! |
String |
+ (concatenation; String + <printable> renders the other side), every comparison |
| an enum | == !=: the tag, then each payload by its own == (a nested enum’s included), so only when every payload type of every variant has ==; a generic enum’s instance by its payloads with its arguments in place (Value<P> compares only when P does) |
Bytes, a struct, a tuple, an array, a bounded, a locus, an interface |
none |
Anything else is refused at the operator, naming the operand and
what its type has: “`<` does not apply to `Bool`: a `Bool` has
`==`, `!=`, `&&`, `||` and `!`”. A compound assignment
(x += v) is its operator’s: b += true on a Bool is refused the
same way. A struct, tuple or array is compared or combined through its
parts, and so is an enum one of whose payloads is one (“`==` does not
apply to `E`: its variant `B` carries `Inner`, whose variant
`X` carries a struct (`P`), which has no `==` …”; until 2026-10-17
the check passed it and the build refused it, “match on TypeRef not
supported”, and an enum payload of an enum was refused at the build even
when it compared). Until 2026-10-13 the check held only that the two sides were
one type, and the build refused true < false, p == q of two
structs, b"a" + b"b" and !n with no file or line.
String slicing
Section titled “String slicing”A range in an index’s brackets slices a String by byte offset and
yields a new String holding a copy of those bytes:
| Form | Bytes | Same as |
|---|---|---|
s[lo..hi] |
lo up to, not including, hi |
std::str::substring(s, lo, hi) |
s[lo..=hi] |
lo through hi |
s[lo..(hi + 1)] |
s[lo..] |
lo to the end |
s[lo..len(s)] |
s[..hi] |
the start up to, not including, hi |
s[0..hi] |
s[..=hi] |
the start through hi |
s[0..(hi + 1)] |
s[..] |
every byte (a copy) | s[0..len(s)] |
The bounds are Int expressions, evaluated left to right after the
receiver, and the receiver is evaluated once in every form:
next_line()[4..] calls next_line once, as a closed slice does.
Bounds clamp and never fail: a start below 0 is 0, a bound past the
end is the end, and an end before the start gives "". Offsets are
bytes, not characters, so a slice can cut a multibyte UTF-8 character
in two; std::str::cp_at and cp_size walk code points.
A bound is left out only inside an index’s brackets (GH #1995): a
bare 3.. or ..3 anywhere else, for i in 0.. included, is a
parse error. ..= needs its end (s[lo..=] is refused). An open
form is the closed form it reads as before anything checks or
lowers it, so hale check and the build accept exactly the same
open slices as closed ones. Only a String slices: a range index on
an array, a bounded, Bytes or a view is refused at the check
(spec/types.md § What the compiler cannot compile yet;
std::bytes::slice copies a range of
bytes, std::str::slice a range of a ByteView).
Each slice measures the receiver and copies the bytes (O(n) + O(hi - lo), spec/stdlib.md § Linear byte scanning), so walking
a long string by re-slicing its tail is quadratic; a text source
(§ Text sources, below) or a ByteView walks it in one pass
(spec/styleguide.md S16).
An index that is not a range (s[i]) is refused at the check: one
position of a String could mean a byte or a character, and Hale
picks neither. The refusal names both ways to say which: “`s[i]`: a
`String` has no element to index, since one position could mean a
byte or a character. Read bytes through a view (`let v =
std::str::bytes_view(s);` then `std::str::byte_at(v, i)` …), or
slice the text (`s[i..(i + 1)]`, `s[i..]`)”. Until GH #1995 the
check passed it and the build refused it (“indexing a non-array
value”).
A byte read that way is an Int (0..=255), and a byte literal
names one by its character: b'/' is 47, so
std::str::byte_at(v, i) == b'/' reads as the test it is (GH #1995,
spec/tokens.md § Integer literals). A byte literal is an integer
literal in every respect: it types as Int, folds in a constant,
and matches in an arm’s pattern, or-patterns included
(b'a' | b'A' -> …). It is the lexer’s, so hale check and the
build accept exactly the same ones, and refuse the same ones (no
byte, several bytes, a non-ASCII character) at the literal.
Text sources
Section titled “Text sources”std::str::split(s, sep), std::str::lines(s) and
std::str::words(s) are for sources: each names the parts of a
text for a for loop to visit, one per iteration (GH #1995). They are
not values. Hale has no sequence value for them to return, which is
also why std::str::split_into writes into storage the caller owns.
fn main() { let row = "id,name,,note"; for field in std::str::split(row, ",") { println("[" + field + "]"); } for line in std::str::lines("first\r\nsecond\n") { println(line); } for w in std::str::words(" any amount of space ") { println(w); }}| Source | The parts |
|---|---|
split(s, sep) |
The text between occurrences of sep, empty parts included, as split_into writes them: "a,,b," is a, an empty part, b, an empty part. "" is one empty part, and s with no sep in it is s. An empty sep gives no parts. |
lines(s) |
The text between \ns, each without one \r before its \n (or before the end of the text). A final \n starts no line: "a\r\nb\n" is a, b. "" is no lines, and "\n" is one empty line. |
words(s) |
The runs of bytes that are not ASCII whitespace (space, tab, LF, vertical tab, form feed, CR). There is never an empty word, so "" and " " are no words. |
- The arguments are evaluated once, left to right, before the first part. Assigning a variable the arguments were read from inside the body does not change the scan.
- Each part is a new
String, bound to the loop variable for its iteration and not assignable, like any loop variable. The body owns it: it can keep it in an outer variable, return it or store it. breakleaves the loop andcontinuegoes to the next part, as in anyfor;returnreturns from the enclosing fn. Loops over sources nest, and an innerbreakleaves only the inner loop.- Bytes, not characters. A separator is matched byte for byte, so
a valid UTF-8 separator never cuts a character, and a non-ASCII
space (U+00A0) is text to
words. - One scan.
sis measured and copied once into aByteView(spec/stdlib.md § Linear byte scanning). Each part costs a search from where the last one ended and a copy of the part, so a loop is linear in the text, where the hand loop it replaces (rest = rest[(sp + 1)..], a measure and a copy of the rest per part) is quadratic.words_source_scales_linearly_where_the_hand_loop_does_notincrates/hale-codegen/tests/stdlib_str.rspins it. - Pure. A loop over a source has the effects of its body and no
others, so it is legal in
@deterministic @no_syscallcode.
Before anything checks it, the loop is rewritten as one while over a
view of s (hale_syntax::str_sources, in the desugar sequence every
entry point runs). The checker, the analyses and lowering see that
loop, so hale check and hale build accept the same programs, and a
diagnostic in the body points where the body was written.
A source starts a chain (§ Element chains, GH #1995 S2). A call of
a source of its own arity, followed by a stage or a terminal, is an
element chain whose elements are the parts, each it for its turn:
fn main() { let text = "id,name,,note"; println(std::str::split(text, ",").filter(len(it) > 0).count()); // 3 let longest = std::str::words("pear fig banana").max(len(it)) or ""; println(longest); // banana}The parts are the loop’s, by the same scan: the chain’s stages and
terminal are the loop’s body, the arguments are evaluated once, and
break, continue and return in an each block act as in the loop.
Every stage and terminal applies, and on a source every terminal is
recognized with no stage before it (std::str::words(s).count()), since
the receiver is the standard library’s call and no facade of a program’s
can be hiding behind it. first, find, min and max answer the part
they picked, and an empty selection fails with the IndexError an empty
vec’s does, so or supplies the fallback. A chain over a source keeps
no list of the parts: like the loop, it makes one String per part, for
that iteration, and min and max keep the best part’s offsets (and
its key), not the part.
A source used as anything other than a loop’s iterand or a chain’s source is refused at the check, with the ways to keep the parts: “`std::str::split` is a `for` source and a chain’s source, not a value: write `for part in std::str::split(s, sep) { … }`, or a chain over it (`std::str::split(s, sep).filter(…).count()`). Hale has no sequence value to return; to keep the parts, write them into storage you own with `std::str::split_into(s, sep, v)` or a chain’s `into(v)`”. So is a call with the wrong number of arguments (“`std::str::lines(s)` takes 1 argument, got 2”), and an argument that is not a string, at the argument (“`std::str::split(s, sep)`: `sep` takes a `String`, not a `Int`”).
A for over a String itself is refused at the check: “`for` over a
`String`: a string is not a sequence. Iterate
`std::str::split/lines/words`, or a `bytes_view` by index”. Until GH
#1995 the check passed it and the build refused it (“for-loop iterator
must be an array”).
Binary data — Bytes and conversion
Section titled “Binary data — Bytes and conversion”Bytes is the binary-safe sibling of String. Same
single-pointer ABI; the underlying blob is
[i64 len][u8 data[len]]. The i64 len prefix means
embedded NUL bytes survive, unlike String’s strlen-based
view.
Producing a Bytes:
std::io::fs::read_bytes(path) -> Bytes fallible(IoError)(m89; IoError flip 2026-05-16). Caller addresses withor raise/or fallback(err).Stream.recv_bytes(max: Int) -> Bytes fallible(IoError)— binary-safe TCP receive (Phase 2g; fallible since #209 — EOF/timeout return empty, only genuine errors fail).std::bytes::from_string(s: String) -> Bytes— copies the strlen-measured body into a length-prefixed blob (Phase 2g).std::bytes::slice(b, lo, hi) -> Bytes— half-open range copy with bound clamping (Phase 2g).
Consuming a Bytes:
len(b) -> Intreads the length prefix.std::bytes::at(b, i) -> Int fallible(IndexError)— byte-as-Int (0..255). Address out-of-bounds viaorclause (Phase 2g; IoError flip 2026-05-16 swapped the pre-flip-1sentinel for the fallible channel).Stream.send_bytes(b)— length-preserving TCP send (m89;fallible(IoError)with Unit success since #209).std::str::from_bytes(b) -> String— copies into a NUL-terminated buffer; embedded NULs persist but downstream strlen-based String operations truncate at the first (Phase 2g).
All returned Bytes values from the path-call surface are
anchored in the lazy global payload arena, so callers can
stash the pointer past the call site without m49 deep-copy
plumbing.
Rendering values as text
Section titled “Rendering values as text”println, print, to_string, String + x, and f-string
interpolation all render through one rule. The set of types
that rule accepts is called the printable set.
A type is printable when it is:
- a scalar primitive —
Int,Float,Bool,Decimal,Duration,Time— orString/StringView; - an enum (rendered
Enum::Variant, orEnum::Variant(a, b)when the variant carries a payload).Enumis the declaration’s own name, whether the value’s type was declared in this seed or reached through animport: an importedColor::RedrendersColor::Red, not the import alias and never the mangled symbol the declaration was renamed to (2026-09-20, GH #885; before it, every print path rendered__lib_<alias>_<stem>_Color::Red— a name that appears nowhere in the author’s program). The alias is deliberately absent: it is per-importing-file (spec/projects.md§ Scoped imports), and the rendering is a property of the value, not of the file that printed it; - a
typerecord whose fields are all printable, renderedName { field: v, other: w }in declaration order; - a tuple of printable elements, rendered
(a, b); - a
[T; N]orbounded[T; N]whose element type isInt,Float,Bool,DecimalorDuration, rendered[a, b, c].
Three exclusions are load-bearing rather than incidental:
- A locus is never printable. A locus is flow, not shape; and
since a
@sealedlocus confines itsparams(see GH #436), a printable locus would be a way to read the confined state back out. There is no printable path to a sealed value. Bytesis not printable. The useful rendering — hex, a length, a UTF-8 attempt — is a choice the author must make.- An unsized
[T]is not printable. There is no length to walk at the render site.
Rendering is defined recursively, with two rules about the nesting:
- A
Stringinside a composite is quoted with"; aStringrendered on its own is not.to_string(s)is identity, and it stays identity — butUser { name: a, b }is ambiguous about its arity in a wayUser { name: "a, b" }is not. - A composite longer than 32 elements is truncated with a
trailing
…inside the brackets. Forbounded, the marker depends on the live count, not the declared capacity.
Rendering has no user-visible ordering or allocation guarantees
beyond producing the text above; results are owned by the caller’s
arena like any other constructed String. A StringView renders as
its text, copied as std::str::clone copies it, so the String that
to_string(view), "x=" + view or f"{view}" produces does not
follow the builder the view reads (2026-10-05, F.40 phase 4: before
it, only println and print rendered a view, and the other three
passed the check and were refused at build).
The checker and lowering read one definition of this rule
(hale_types::printable): the checker refuses a value outside the
set at its span, and lowering renders a record only when every
field is printable, as the checker does.
Declared templates: @display (RFC #2035, decisions F.54)
Section titled “Declared templates: @display (RFC #2035, decisions F.54)”A record, or an enum’s variant, may declare the text its values render as for people:
@display("${dollars}.{cents:0>2} {currency}")type Money { dollars: Int; cents: Int; currency: String; }
type Side = enum { @display("buy") Buy, @display("other: {0}") Other(String), Unlisted(Int),};- A template is literal text and holes. A hole names a field of
the record, or a payload position of the variant (
{0},{1}), with an optional f-string format spec ({cents:0>2},{px:.2},{n:>8}, spec/tokens.md).{{and}}are a literal brace. No expression, call or conditional can be written in one, so rendering through it cannot fail or run anything. - Checked as the f-string it stands for. The parser refuses a hole that names no field or no payload position, a hole holding an expression, and a spec outside the grammar; the checker refuses a hole whose field is not printable and a spec that does not fit its field, at the hole. Both are located in the template.
- It never widens the printable set.
@displayis allowed only on a record that is already printable, every field of it, whatever fields the template names; a record holding aBytestakes no template, so{x:?}always has a form to show. - Where: a record
type, not generic; an enum’s variants, each its own (a variant without one renders structurally), not of a generic enum. Not on an enum as a whole, a set (a set renders as its member does), an alias or a scalar (each renders as what it names) or a locus (never printable). Each is refused at the annotation. - One rule, everywhere.
println,print,to_string,String + xand f-string interpolation all render a value of the type through its template, as they all render the structural form otherwise. A nested value renders by its own type’s template when it has one, else structurally; the text a template produces is not quoted inside a composite (it is noStringvalue). - It attaches to the declaration. An alias renders as the type it names, and an imported type as its declaration does.
T::display(v) -> Stringnames the rendering: written by the compiler for a record with a template and for an enum with a templated variant, asE::nameis (F.53), a type-path function and no method. It is a value too:apply(Money::display, m).- Cost. The template is a function the compiler writes, and a
rendering of a value of the type is a call of it: its output is
allocated in the caller’s frame, exactly as the equivalent
hand-written f-string’s would be, and the allocation summary and
the hot-path budget (
@budget(alloc_per_call = …)) count it so,T::displaypassed as a value included. A template is not cheap for containing no call.
{x:?}, the structural form. The format-spec kind ? renders a
value by the structural rule above whatever its template, at every
depth: a nested value with a template of its own renders structurally
too. A String inside a composite is quoted and a composite over 32
elements truncated, as always. It is what a test failure, a log of
internals or a debugger wants, and it exists for every printable
value. An assertion of std::test that renders a value shows both
forms when they differ; today’s assertions take Bool, Int,
String and Float, which have no template.
Format specs
Section titled “Format specs”f"{expr:spec}" renders expr under spec instead of under the
default rule. The grammar is in spec/tokens.md. Ordering is
fixed: the value is rendered first (honouring precision or
a hexadecimal kind, both of which need the value) and the text is
padded second (width, fill, align).
An absent alignment resolves from the value’s type — numeric values pad on the left, everything else pads on the right — so a column of figures lines up on the ones place and a column of names lines up on the first letter without either being asked for.
Grammatical errors in a spec are reported by the parser;
spec/value mismatches (hexadecimal of a String, a precision on
an Int) are reported by the typechecker. Neither reaches codegen.
Locus instantiation
Section titled “Locus instantiation”LocusName { params }:
- Compute params (overrides applied to declared defaults).
selfresolves lexically: inside a default expression — including the field inits of a nested locus literal written in that default —self.Xreads the locus being instantiated (earlier-declared siblings only; a default that reads a later-declared sibling, or its own param, is a type error at the read, since defaults run in declaration order). Inside an override expression,selfbelongs to the code that wrote the literal — the enclosing method’s locus, or the enclosing params block when the literal itself sits in a default (F.4 call-site rule). This holds regardless of where the instantiation executes (fn main, a params-init, or another locus’s method body — 2026-07-14 fix). For a locus placedpinned, the defaults, and every locus nested under it with its whole instantiation, are computed on the locus’s own thread, and the literal completes once they are; an override is still evaluated where the literal is, except a locus it builds as the field’s value, which is part of the pinned subtree (runtime.md§ “Placement classes”, m27 + m28a). For a field placed oncooperative(pool = X)the same holds on X’s worker, as the first job of that field: its defaults and every locus nested under it are computed there, and the literal completes once they are (the pool side of m27 + m28a); the field’s ownbirth()still runs where the literal is. - The nearest enclosing ancestor that declares
accept(c: I)for the child’s type — the type itself, or an interface the type satisfies (see “An interfaceaccept” below) — is the owner (innermost-wins — interest-based ownership / accept bubbling; see below andruntime.md). Itsaccept(c)runs once the child’s region exists and its params are built, before the child’sbirth(), and it cannot reject (runtime.md§ “Lifecycle obligations”, line 5). With no accepting ancestor the child is a transient throwaway (no owner). - Region allocated as a sub-region of the owner’s region (the accepting ancestor — not necessarily the direct parent); size determined by projection class.
- Bus subscriptions wire up, before
birth(), so thatbirth()may publish to its own subscriptions; delivery to the locus becomes eligible oncebirth()(and itsbirth_check) has completed, and what was published to it before waits, in order (runtime.md§ “Lifecycle obligations”, line 6). A cooperative locus’s subscriptions that take no key wire up as soon as its region exists, before its params are built, so what its params’ children publish to it while they are born or run waits for it too (2026-10-12); a keyed one waits for the params its key reads, a pinned locus’s and an accepted child’s for step 2’saccept, and one bound to anshm_ring(its reader calls the handler outside the window) for the params too. A publish made before its subscriber is built at all reaches no subscription of it;hale checkwarns where it can see one in a body. birth(args)runs synchronously.- Its
fnmembers are reachable for invocation. - If
rundeclared, scheduled to run on the locus’s scheduler. For a locus placedpinnedor on a cooperative pool other thanmain, “scheduled” means handed to that thread or worker and the instantiation returns immediately. For a locus that runs inline on the main thread — the default placement, and an explicitcooperative(pool = main)—run()executes synchronously here, and step 8 does not happen until it returns. See § Birth order is load-bearing. - Expression returns the locus handle.
The instance before its params. Step 1 can already reach the
locus being built: a default’s child is instantiated inside the
literal (its run() inline, step 7), and an I{} it births
bubbles to this locus when this locus is the accepting ancestor.
So the locus’s own state is initialized before step 1, as soon as
its region exists, before anything can reach it: its accepted
children (self.children, empty), its restart, quarantine and
drain state, its failure route and its owner link. Nothing later
in the instantiation resets it. A child accepted during step 1
stays in self.children and is torn down with the locus, like
any other accepted child. The params themselves follow step 1’s
order: a field is its value once its turn comes, whatever an
accept wrote to it before.
Accept bubbling. The owner in step 2 need not be the direct
parent. An I{} instantiated anywhere in a subtree bubbles to
the nearest enclosing ancestor that declares accept(I)
(innermost-wins); resolution is entirely static (the closed-world
instantiation graph fixes every owner edge at compile time). The
owner may live in a different tower or on a different pool: a
cross-pool owner is served by an async handoff over the bus, so a
cross-pool I{} is fire-and-forget — it may only appear as a
bare statement, and using the instance as a value is rejected at
compile time. So is a value use where the enclosing locus runs both
on the owner’s thread and off it (its birth is a same-tower
allocation in some instances and a cross-pool post in others,
chosen at a bare statement): the typechecker refuses it at the
literal, naming the instances and their threads. The rule holds at every expansion of a default, since
a default is lowered where it is expanded, not where it is written.
The typechecker rejects it at the literal: in a member body (a
closure’s assertion included), under the locus whose body it is; in
a params default, under each locus that builds the defaulting
locus and leaves that field to its default (the default is expanded
there, and a default is a field’s value, never a bare statement). A
fn’s or a locus method’s argument default is judged per invocation:
each call that leaves the argument out expands the default in the
caller, under the caller’s locus, and is rejected at the call when
the default builds a cross-pool I{} there; a call that supplies
the argument expands nothing, and a caller on the owner’s thread is
not rejected. Chains of defaults of either kind are followed. A
const’s value and a type’s field default are expanded at every
use, under whichever locus uses them, so one that builds an I{}
some locus would post is rejected at the position. See runtime.md
“Interest-based ownership (accept bubbling).”
A cross-pool child is born on the owner’s thread from a marshaled copy
of its params, and nothing of it runs on the far side but that birth:
each param must be a type the spawn marshals (a scalar of Int,
Float, Bool, Decimal, Duration and Time, a String, a
Bytes, a struct whose fields the bus carries, a fixed array of those),
and the child keeps params, an optional birth, drain or dissolve,
and a contract, never a non-empty run(), bus subscriptions, closures,
capacity slots or an accept of its own. hale check refuses a child
that breaks either, once, at the first literal the bubble plan posts
across (“cross-pool spawn `Ship{ }`: it is born on `World`’s thread
from a marshaled copy of its params, and hale can’t compile this child
that way yet: its param `t` is `(Int, Int)`, a tuple, …”); the build
refused it after a passing check (GH #1942).
An interface accept. accept(c: I) may name an interface
(spec/types.md § Interface types). It accepts every locus that
satisfies I — conformance as a coercion into I judges it, error
channels included — and nothing else. Resolution is static, like
every owner edge: every locus is born from a literal of a concrete
type, so the clause stands for one concrete accept(c: L) per locus
L it admits, and the ownership relation holds those concrete edges.
There is no runtime type test and no dispatch through a vtable:
- Precedence. A locus declares one
accept(§accept(c)), so the only choice between clauses is by depth, and innermost-wins decides it whatever the clauses’ kinds: the nearest ancestor whose clause admits the child’s type owns it, whether that clause names the type or an interface it satisfies. A concrete owner below an interface owner keeps its own type and lets every other type bubble past it; an interface owner below a concrete one keeps every type it admits. A type satisfying two interfaces is owned by the nearer ancestor accepting either. - Monomorphization. The body is compiled once per admitted type,
the child typed as that type, so a call through it is a direct call
to that type’s method. The checker types the child as the interface,
so the body may use only the interface’s methods — the members every
admitted type has — and passing the child on as an
Ivalue coerces it as any locus does.release(c: I)is compiled the same way. - Children. The owner keeps its children one type at a time: each
child is tracked, removed when it completes (a flow) and reclaimed
in the owner’s cascade by its own type’s teardown; the cascade walks
one type’s tracker after another, the types in name order.
self.children.countandself.children.is_emptyread the sum.for c in self.childrenis refused at the check, since the children share no element type. - Unchanged. The child’s region is a sub-region of the owner’s
(step 3), its placement is its own type’s, a cross-pool owner is
served by the handoff below, and the model’s owner edges and call
edges name the concrete owner and the concrete callee. A generic
locus’s specializations are no interface’s: an interface
acceptadmits none of them.
Whether the owner is on another pool is a fact of each instance
of the enclosing locus, not of its type: a locus nested under a
root field placed off main runs on that field’s thread, and one
type can have instances on several threads. The owner is resolved
once, for every instance; the delivery is chosen per instance. When
some instances of the enclosing locus run on the owner’s thread and
others do not, and the owner is a main locus, a bare I{}; is
born in the owner’s region where the enclosing instance runs on the
owner’s thread, and handed off where it does not. Where that choice
cannot be made — a value use of the literal, or an owner with more
than one instance, which has no single thread to hand off to — the
literal is refused at compile time, naming every instance of the
enclosing locus and the thread it runs on. A resolved owner is never
dropped for a transient birth.
Birth order is load-bearing
Section titled “Birth order is load-bearing”A parent births its params fields in declaration order, one
at a time, and step 7 above runs an inline locus’s run()
synchronously. Composing those two rules: a params field whose
run() does not return prevents every field declared after it
from being born at all.
Not merely from running — from being born. The later locus’s
birth() never executes, so the subscriptions it registers, the
sockets it binds, and the children it accepts never come into
existence. Nothing fails and nothing is logged; the process
completes what looks like a normal boot and then sits idle. This
is the single most expensive way to misread a Hale program, and
the symptom points nowhere near the cause — it typically presents
as “my handler never fires”, which sends you looking at the bus.
main locus App { params { server: Server = Server { }; // run() { while true { ... } } metrics: Metrics = Metrics { }; // NEVER BORN }}Only the blocker’s placement matters. Moving the later field
off the main thread does not rescue it — the instantiation itself
runs inline on main, so even a pinned sibling declared after a
blocking field waits. The four placements behave as:
| Placement of the blocking field | Blocks later births? |
|---|---|
| default (no placement entry) | yes |
cooperative(pool = main) |
yes |
cooperative(pool = io) (any non-main pool) |
no — run() is posted to a worker |
pinned |
no — run() gets its own thread |
Two remedies, both sound: declare the non-returning field last,
or place it off the main thread. The compiler warns whenever it can
prove the shape — a terminal while loop with no
break/return/terminate, in a field that runs inline on main,
with at least one field declared after it. The proof is
deliberately conservative, so a loop the compiler cannot prove
non-terminating is not reported: absence of the warning is not a
guarantee of correct ordering.
This rule is why a child’s run() is the wrong place to put work
that must happen after its siblings exist. The main locus’s
run() is the right place — it begins only after params-init
completes, so by then every child has been born.
Dissolve timing rules
Section titled “Dissolve timing rules”Five shapes, three timings (m82 — “locus all the way down”; expression position generalized from receivers to every position by GH #711 / #812).
Who reclaims a locus is decided before any code is emitted.
One pass over the program gives every locus-producing expression
— a literal, a proven-fresh factory call, and each branch, arm
and element of an or, a carrier or a composite separately — the
owner the rules below name, and lowering reads that decision
rather than making one as it goes. An instantiation the pass
left undecided is refused, so the rules here hold by
construction rather than by the order things happen to be
lowered in (spec/decisions.md F.39).
- Statement-position literal (
LocusName { ... };, no binding and nothing done with the value): birth → run → drain → dissolve all fire at the statement boundary. Fire-and-forget. The handle is discarded. - Let-bound literal (
let h = LocusName { ... };): birth- run fire at the construction site. Drain and dissolve are
deferred to the enclosing fn’s scope-exit flush
(
runtime.md§ “Lifecycle obligations”, line 11). The user-visible bindinghis the handle; the locus instance lives untilhgoes out of scope. This is what makeslet s = Stream { conn_fd: fd }; s.send(msg) or raise;work —sstays valid for the method call because dissolve hasn’t fired yet.
- run fire at the construction site. Drain and dissolve are
deferred to the enclosing fn’s scope-exit flush
(
- Expression-position literal (a literal used as a value:
a method receiver
LocusName { ... }.method(), a call argumentserve(LocusName { ... }), a field readLocusName { ... }.field, an operand): the expression that consumes it is the handle, so the literal has the same timing as a let-bound one — dissolve is deferred to the enclosing fn’s scope-exit flush. Naming the literal withletfirst and using it inline are the same program, in every position. In particular the literal is alive for the entire call it is the receiver or argument of, including any allocation churn or drain point inside it, and for as long as a callee that retains it holds on to it. This holds in statement position too (LocusName { ... }.method();): only a literal whose value is discarded is torn down at the literal’s own boundary. - Factory result (
let h = make(...);, or the call used directly as a value —serve(make(...))): the locus is built inside the callee and handed back, so the expression that consumes the handle is its owner, with the same timing as a let-bound literal. A binding owns what it names; a call result nothing names is owned by the enclosing fn’s scope. A result discarded in statement position (make(...);, or a call through a fn value,f(...);) is torn down at the statement, as a discarded literal is: nothing can reach it after the;(GH #1569). What a binding names is the expression written at that position, not a factory call nested inside it: inlet x = combine(a, make());— and inreturn combine(a, make());, where the caller is the owner — the binding (or the caller) ownscombine’s result, andmake’s is a result nothing names, owned by the enclosing fn’s scope and reclaimed at its exit (GH #837). Anif, amatchor a block written as a value is not the value either: it hands back one arm’s, and exactly one arm runs — so the rule applies per path, to each arm’s tail expression, which is what is written at that position on the path that produces it.return if c { make(1) } else { make(2) };hands the caller whichever arm ran, and the frame that built it reclaims neither;let x = if c { make(1) } else { make(2) };reclaims whichever arm ran exactly once, at the enclosing fn’s scope exit. A factory call anywhere else inside such a carrier — in the condition, in the scrutinee, in a statement before a block’s tail — is a result nothing names, reclaimed at that scope’s exit like any other. An ascribed array or tuple literal is likewise what the site names, never one of its elements:let xs: [Thing; 2] = [make(1), make(2)];names the array, and each element’s result is one nothing names, reclaimed at the enclosing fn’s scope exit (GH #883). This is the same rule in the fallible spelling, where the call is reached throughor—let c = std::process::spawn(argv) or raise;is reclaimed exactly aslet h = make(argv);is, and so isor <substitute>, where whichever branch produced the value is the branch that gives it an owner (GH #793). Two positions are excluded, because there the handle is handed on rather than consumed: a result written directly as a locus- or interface-typed field of a locus literal, which the literal owns (F.17), and a binding the enclosing fn returns, which the caller owns — dissolving either would free a value another owner still holds. A value the fn returns through a call that hands back its argument is the caller’s in the same way, whichever binding or temporary of the frame held it: withfn pass(a: T) -> T { return a; }, bothlet x = make(1); return pass(x);andreturn pass(make(1));handmake’s result to the caller, and the frame does not reclaim the locus it returns. Read through such calls, a fn whose every return is fresh is a factory like any other, so its caller’s binding owns the result (fns handing back each other’s calls are factories when every return of theirs that is not such a call builds:fn a(n) -> W { if n == 0 { return W { }; } return b(n - 1); }withfn b(n) -> W { return a(n); }; a cycle with no way out returns nothing, GH #1569); a call that can hand back one of several arguments (return pick(x, y, c);) hands back the one it returned, and the frame reclaims the rest. (Until the friction sweep of 2026-10-12 the frame reclaimed it on the way out, and a caller outsidemainread a dissolved locus: a@form(vec)whose buffer was gone,len()0.) The first of those two is an ownership transfer, not an exemption:Router { quick: make(5) }is the same program asRouter { quick: Quick { } }— the field’s value is reclaimed by the owner’s teardown cascade, at the owner’s timing, whether the field is written at the call site or as the param’s default, and whether the call is bare or reached through a divergingor(or raise,or fail), where the factory’s result is the only value the field can hold (GH #836).or <substitute>transfers on both branches: the field holds whichever branch ran and owns that value, soRouter { quick: make_f(5) or make2() }reclaims exactly the locus that was built, once, from the owner’s cascade — the substitute is not also a temporary of the frame that built the owner, which would flush it at that frame’s exit with the field still pointing at it (GH #853). The claim needs every branch to transfer: a proven-fresh factory call of the field’s own locus, a locus literal, or a nestedorof those. A call in that position that transfers nothing is excluded exactly as an external handle is — one that returns a locus it did not build (one of its arguments, a handle it was given), and anorwhose ok value or substitute is such a call — and the value is left to its real owner. - Long-lived (locus has
bus subscribe): always deferred, irrespective of binding shape — the locus must stay alive to receive published events between birth and the enclosing scope’s exit.
Multiple deferred dissolves in the same scope fire in reverse instantiation order at scope exit (LIFO), matching the F.4 depth-first cascade. The reason: a later-created locus may depend on an earlier-created one, so the later one must dissolve first.
Whichever of the four shapes applies, the timing is the
timing of the whole owned tree, not of one level of it.
A locus held as another locus’s param field never has a
teardown of its own — its instantiation is parent-owned, and
the owner’s teardown cascades into it (F.29). That cascade
runs to the leaves: a grandchild’s drain(), its dissolve()
body, its capacity slots and its arena are the owner’s
responsibility just as a child’s are, at exactly the moment
the owner’s timing fires. Every level’s arena is destroyed,
none outlives the owner, and the count of live arenas a
finished program leaves behind is zero. “Constructed by the
owner” covers both spellings of construction: a nested literal
(Mid { leaf: Leaf { } }) and a factory call whose result the
field takes (Mid { leaf: make_leaf() }, in the
diverging-or spelling too, and as a param default). A field
the owner did NOT construct (Mid { leaf: shared }, an
external handle passed in; or a call that hands back a locus
somebody else built) is excluded at whatever depth it appears,
and is torn down once by its real owner, at its owner’s timing.
An array or a tuple of loci is the same tree. A param holding an
array or a tuple of a locus type (cs: [C; 2] = [C { }, C { }], t: (C, D) = (C { }, D { }), or the same written at the owner’s literal) holds
each element its initializer builds as a parent-owned child: built in
the owner’s arena, drained before the owner in declaration order with
element order inside, torn down after the owner’s dissolve() body in
the same order, each reclaimed once — whatever the owner’s placement. An
element written into the field later (self.cs[i] = c) is not the
owner’s: the element it replaces, while still one the literal built, is
reclaimed at the store, and the instance written in is left to its own
owner. A locus literal written into an element (self.cs[i] = C { },
self.t.0 = C { }, h.cs[i] = C { } through a handle), or a literal of
the whole array or tuple written over the field (self.cs = [C { }, C { }]), is the reassignment of a locus field, element by element: the
element it replaces reclaimed while the owner owns it, the new one built
in the owner’s arena as its child and torn down with the owner, not with
the method that wrote it. A whole array or tuple written from anywhere
else (self.cs = xs) leaves the instances written in to their owners.
The value is read before the store, and an element the owner owns is
reclaimed once the field no longer holds it: one written back in
(self.cs = [self.cs[1], self.cs[0]]) stays the owner’s, at its new
place. The owner tracks every element, whatever the array’s length, and
a path to the owner is evaluated once (ls[next()].cs[0] = C { } calls
next once). The placement table holds a row per element (cs.0,
t.1), and the lifecycle plan owes each one its teardown, in element
order. A name handed whole (cs: shared) is a borrow, as above. A param
written without a type takes its default literal’s (cs = [C { }, C { }] is cs: [C; 2], t = (C { }, 1) is t: (C, Int), n = [1, 2] is
n: [Int; 2]): an array of one type’s literals, a tuple of literals, a
locus or record literal.
A locus handed back inside a tuple or an array (fn both(w: W) -> (H, W) { return (H { w: w }, w); }) is owned by whatever holds the
aggregate (GH #1569): a param holding it (p: (H, W) = both(W { }))
holds each part the fn built, and each argument handed back as a part,
as its children, exactly as one built from a literal; a binding leaves
them to the frame, which tears them down at its flush (each iteration’s
in a loop, before the next builds its own); a call whose result is
discarded has them torn down at the statement, in order, then the
arguments they kept. An argument a part keeps in a field (H { w: w })
goes with the last part keeping it, so every part that keeps it is torn
down first. A builder that keeps an argument in a literal nested in the
locus it returns (K { a: H { w: w } }) gives it to that nested holder.
A tuple’s parts of other types (fn mk2() -> (W, Int) { return (W { }, 1); }) change none of this: each locus part the fn builds is owned as a
factory’s direct return is, and so is each one a call through a fn value
hands back, or a fn handing back such a call’s result (fn apply(f: fn() -> (W, Int)) -> (W, Int) { return f(); }). A param holding a tuple with
a locus part (t: (W, Int) = (W { }, 5)) holds it as an array or a
tuple of loci holds its elements.
What the field is DECLARED as does not change any of this.
A param typed by a contract — an interface the child
satisfies (params { j: Counter = Churner { } }) — holds a
parent-owned child exactly as a locus-typed param does, and the
cascade reaches it and everything under it. Which locus satisfies
the contract is a per-instantiation choice: an impl written at the
literal overrides one written as the param’s default, and the child
torn down is the one that was actually constructed. Both spellings
of construction reach a param typed by a contract: Queries { j: make_churner() } is the same transfer as Queries { j: Churner { } }. The child reclaimed is the impl that was actually built rather than
the one the param’s default names (GH #895), and the or
spellings transfer here exactly as they do into a locus-typed
param — the diverging ones, where the factory’s result is the
only value the field can hold, and or <substitute>, where the
field owns whichever branch ran.
A locus literal written as a call’s argument is an expression-position
temporary of the frame unless the callee keeps it (GH #1566): a free fn
that hands the argument back unchanged (fn id(w: W) -> W { return w; }) makes it the call’s value, owned wherever the call’s value is
(Routes { w: id(W { }) } is Routes { w: W { } }), and a fresh factory
that keeps it in a field of the locus it builds and returns (fn mk(w: W) -> Routes { return Routes { w: w }; }, or through a let bound to
that literal) makes it that field’s child, torn down with the returned
locus — when the returned locus is held by a field, a placement or a
binding. Which fns do either is read from their bodies: the parameter
named nowhere but in the value handed back. Before, such an argument
was reclaimed when the frame that built it ended, while the locus the
call built still held it.
A locus literal written inside the initializer of a param that
cannot hold a locus is not an ownership transfer, because
there is no field for the owner to cascade from. In Lonely { n: Queries { }.total() } the Queries literal is an ordinary
expression-position literal, owned by the enclosing fn’s scope
and reclaimed by its scope-exit flush, exactly as it would be
written on a line of its own.
A deferred dissolve is scoped to the enclosing fn, not to
the enclosing block — the slot a let binds lives until the fn
exits, including after the loop that bound it, while the name
is the block’s: a let is visible from its statement to the end
of its block, and a let that reuses a parameter’s or an outer
let’s name inside a block shadows it there and there only (GH
#1132) — but a locus
created in a loop is reclaimed when its slot is reused, and
only the last one at scope exit. Control arriving at the same
instantiation a second time is the end of the previous
instance’s life: it is torn down there, with the same
drain → dissolve → arena reclaim the scope-exit flush runs,
before the new one takes its place. This holds for every
spelling — let h = L { };, a fresh literal used as a value, a
let bound to a locus-returning factory, and a let whose RHS
is an if / match / block or an ascribed array or tuple, where
the reclaim is per ARM and per ELEMENT because that is where the
value is built — so a loop’s residency is one instance per
site, not one per iteration. Ownership follows the binding, not
the name: a let that shadows a binding the fn hands back is a
binding of its own, reclaimed like any other, and only the binding a
return resolves to where it is spelled — or a binding whose value
flows into it — passes to the caller (GH #1140). A
locus that ESCAPES the iteration is unaffected, because it
never had a slot here to begin with: a literal written directly
as another locus’s param field is parent-owned, and so are an
accept’d child and a locus the fn returns. A handle the loop
passes in to an owner (Keeper { held: h }) keeps its own
slot and is reclaimed here — the owner’s cascade steps over a
field it did not construct, as it always did (F.29).
Each instantiation reclaims its own previous instance, where
it stands, so within one iteration the reclaims run in
instantiation order — the reverse of the LIFO order the
scope-exit flush uses. Two loci bound in the same iteration are
independent; a dissolve() body that reads a sibling handle it
does not own sees the sibling’s next instance.
Every exit path flushes independently, and a return takes
nothing away from the others. A fn — fn main included — may
leave through an early return, through a later return, or by
falling off the end. Each of those paths dissolves everything the
fn owns at that point, in reverse instantiation order, and the
paths do not interact: a return in the middle of a body does
not shorten the set the fall-through exit dissolves. So in
fn main() { let a = Noisy { tag: "a" }; if bad_usage { return 2; } // dissolves `a`, then exits 2 let b = Noisy { tag: "b" };} // dissolves `b`, then `a`the guarded exit dissolves a, and the ordinary exit — the one
taken when the guard does not fire — dissolves b and then
a. A locus bound only inside the branch that returns is listed
on the other paths too but was never instantiated there, so those
paths skip it: it dissolves exactly once, on the one path that
built it. return f() evaluates f before any teardown begins,
and a locus f itself bound is dissolved by f’s own exit
(GH #789).
terminate
Section titled “terminate”terminate; ends the current locus’s lifecycle
from inside one of its own methods — the locus analogue of
return (which ends a fn). It is only valid inside a locus
method body. It does not free anything directly: it sets
the locus’s __drain_requested latch and exits the current
method like return;. When the method’s run() coro completes
with the latch set, the runtime runs the locus’s normal
drain → dissolve → arena reclaim — i.e. terminate invokes
the declarative teardown early; it is never a manual free.
Its purpose is per-child reclamation on completion for an
accept’d child whose lifetime is its own flow rather than its
parent’s. An accept’d child on a daemon parent is otherwise
reclaimed only when the parent dissolves (never, for a daemon),
so per-connection children accumulate. A connection child whose
run() is a recv/park loop ending on EOF can terminate; (or
just return; once run-completion-reclaim for declared flows
lands) so its arena is reclaimed the moment its flow ends, while
the parent and the rest of the program keep running. Reclamation
is idempotent (the arena-destroy latch), so a terminate that
races the parent’s eventual dissolve is torn down exactly once.
The reclaim runs on the coro’s own pool worker, after run()
returns, while the locus’s arena is still valid — never seizing
a still-executing frame. (A child that terminates mid-run()
exits run() immediately, like return; code after terminate
in the same method does not execute.)
Validity (typecheck). terminate; in a free
function is a typecheck error — there is no enclosing locus whose
lifecycle to end. It is accepted in any locus method body
(lifecycle method or member fn).
From a bus handler. terminate; is no longer
limited to run(). A subscriber can end its own life from inside
a bus handler (e.g. on_close receives a shutdown message and
calls terminate;). The reclaim runs when the handler returns —
the dispatch path checks the __drain_requested latch after each
handler and runs the spine on the handler’s own worker. This is
the resident-subscriber analogue of the connection child that
terminates from its run() recv loop. A handler that violates
sets the same latch and is reclaimed the same way — unless its owner
still holds it (below).
A child reclaimed this way may still be named by its owner — a
param field (c: Child = Child { }) keeps its handle. Both halves of
the owner’s teardown cascade — the drain walk and the dissolve walk —
test the child’s arena-destroy latch (__arena, slot 0 of a struct
that lives in the owner’s arena) before the per-child body, and
step over a child already reclaimed: its drain() and dissolve()
do not run twice, and its own children, which lived in its freed
arena, are not visited again (GH #1036).
A failed child its owner holds is kept (GH #1069). terminate
is a child ending its own life; a failure is not. A child whose
run() or handler failed — a violate, a failed birth_check —
and that its supervisor did not restart (it absorbed the failure,
quarantined the child, or spent restart(c) for N) stops: its
run() has returned, and on the wrapper paths that would have
reclaimed it its bus subscriptions are dropped. But while anything
still holds it — a param field, a binding, a value the enclosing
expression uses — its memory stays until that owner’s teardown,
where its drain() and dissolve() run once. The owner’s handle
therefore always names a live child: self.c.why after an absorbed
failure reads what the child last stored. Only a child nothing else
reclaims tears itself down when it fails: an accept’d child (its
owner’s tracker expects it gone) and a bare statement literal (its
statement’s own teardown then steps over it, on the same latch).
A child that fails from a bus handler is recovered as one that fails
from run() is (GH #2028). When the handler returns and no run()
of the child is running, the supervisor’s decision is carried out
there: a restart(c) lowers the drain latch, re-runs birth() (the
birth-epoch closures and birth_check with it) and then run(),
and puts back the subscriptions; an absorb stops the child, as
above. When the handler ran inside the child’s run() (at a yield
or the drain its body ends with), a held child stops at once and the
rest is decided once run() returns, as for a failure run()
raised. Until GH #2028 neither happened after a handler’s failure.
A held child stops as it fails: its subscriptions are dropped where
the failure is raised, before the handler or run() it was raised in
goes on, and well before the supervisor has decided (the failure is
delivered on the owner’s thread, and the child’s thread runs its other
work while it waits). So nothing published after the failure reaches
the failed child — a publish whose topic fails on no subscriber takes
its or, as for any stopped child — even while the handler that
failed is still running; until GH #2091 the stop came when that
handler returned, and a delivery published in answer to what the
handler said after its failure (a std::api receiver’s server error)
could reach the failed child, or be dropped at the stop unannounced.
A restart the supervisor then decides takes that stop back: the
restarted child has every
subscription it had before it failed, so a bound receiver restarted
after the call it was executing returned is served again (spec/api.md
§ Receiver failure and generations).
A delivery queued for the child before it stopped, and not yet begun,
is dropped unrun when its turn comes, unless a restart has put the child
back by then, in which case the restarted child is delivered it. A
dropped delivery is announced to nobody, except that a std::api
receiver’s stop (and a quarantine that ends a receiver still live)
tells each exposure bound to it that its incarnation is gone, as its
dissolve() does, so the calls it was handed and had not started are
answered unavailable rather than never (GH #2098).
release(c) and flow children
Section titled “release(c) and flow children”release(c: Child) { ... } is the death-side
bookend, symmetric to accept(c: Child). Declaring it on a
parent has two effects:
- It marks
Childa flow. A flow child is reclaimed when itsrun()completes — a plainreturn(or running off the end ofrun()), no explicitterminate;required. This is the connection model:run()is the connection’s flow (a recv/park loop that returns on EOF), and the child’s arena is reclaimed the moment that flow ends. A child whose type is NOT declared in any parent’sreleaseis a resident: itsrun()returning means “ready” (it lives on as a subscriber), and it is reclaimed only when the parent dissolves. The samerun()-returns event thus means “reclaim me” for a flow and “ready” for a resident — disambiguated by the parent’s declaration, never guessed. - It fires on each completion. When a flow child completes
(via run-completion OR
terminate;), the runtime callsparent.release(owner, child)— after the child drains, before it dissolves — so the parent observes the completion and reads the child’s final settled state (the mirror ofaccept(c), which reads it fresh).releaseis policy only: it does not free. The owner is the accept’ing parent, recorded at accept time;releasedoes not fire if a flow-typed locus is instantiated outside an accept context (no owner).
release(c: I) naming an interface makes every locus that satisfies
I a flow, as accept(c: I) accepts each, and is compiled once per
such type (§ Locus instantiation, “An interface accept”). The clause
must name the same type as the locus’s accept (the validity rule
below).
Several parent types may accept the same child type; each child
carries its accept’ing owner AND that owner type’s release fn
(stored at accept dispatch), so the body that fires is the actual
owner’s own, never another parent type’s (2026-09-05, GH #526 F.6:
the reclaim spine used to pick the first declared release(c: T)
program-wide). Where more than one owner type tracks T (two
concrete owners, or an interface owner beside another), the child also
carries the accepting owner’s children tracker, so a completed flow
leaves the tracker of the owner that accepted it, never none (the
removal used to be skipped there, and the tracker grew without bound
under churn). Whether T is a flow remains a type-wide fact: if
any parent declares release(c: T), every T reclaims on
run-completion, and an owner that declares no release simply has
no bookend called.
Whether T is a flow is decided over the whole program, imported
seeds and the standard library’s own loci included (a stdlib owner’s
release, the TCP substrate’s connections on an async_io pool,
reclaims its children as a user owner’s does), and a clause on a locus
that is never instantiated counts all the same. hale check --flows reports every flow type with
each release(c: T) clause that makes it one, by its declaring locus,
file and line, as the declaring seed spells it, never a mangled symbol
(GH #736), and an interface’s clause with the loci it admits; a qualified type is the whole path, so a local Stream is
never mistaken for std::io::tcp::Stream. It is an
opt-in report, never a diagnostic, since a release declaration is
legitimate. It lists the program’s own clauses: a stdlib child type is
internal to the stdlib locus that owns it, and is not listed.
Three ends, kept apart. A flow ends by completing: its run()
returns (or it terminates), and it is reclaimed on the spot, its
owner’s release firing between its drain and its dissolve. A
resident never completes that way — its run() returning means
“ready” — and ends one of two other ways: by its own terminate;,
typically from a bus handler (the handler returns, then it drains and
dissolves; no release fires, for none names its type), or in its
owner’s dissolve cascade, which tears it down before the owner’s slots
and arena are freed. A resident that disappears
when its run() returns is a flow by some clause elsewhere; the report
above names it.
A resident and what a handler hands it. A payload delivered to a
handler, and any container the handler builds while it runs, belong
to that dispatch and are reclaimed when the handler returns. A child
born from the handler that must keep them copies them in its own
birth() — cloning Strings, rebuilding rows — into storage it owns;
holding the handler’s pointers past the dispatch is a use after
free. The transfer rule is: a value is copied at the store; a
locus is borrowed, and a borrow must outlive its holder. A String,
a row or a payload’s field handed to a resident is copied into the
resident’s own storage as it is stored, so the resident reads it after
the handler has returned. A container that is a locus (a @form(vec)
the handler built) handed to a resident by name is a borrow, and the
checker refuses it at the argument, in check, build, run and
test alike, naming this rule (GH #712, decided by the table under
“A borrow outlives its holder”); the working shape is the copy in
birth() above, which is sound because a borrow read only in
birth() lives no longer than the instantiation.
release has the same shape as accept — one typed child
param — and the same fn signature (parent_self, child_self).
Validity (typecheck). A release(c: T) with no
matching accept(c: T) on the same locus is a typecheck error: a
locus that never accepts a T child can never release one, so
the declaration is dead (almost always a wrong child type or a
forgotten accept).
Parent-dissolve reclaim. When a parent that
accepts children dissolves, it reclaims each accept’d child it
still tracks — running the child’s full teardown (drain →
dissolve → arena reclaim) before the parent’s own arena (which
backs the children’s subregions) is freed. A parent that accepts
tracks every child it accepted, whether or not any of its methods
iterates self.children, because this cascade is what the
tracker exists for; and the cascade runs on every path that
dissolves the parent — graceful shutdown, a reclaimed flow, and a
mid-life reassignment of the field that holds it — so a child’s
bus subscriptions are deregistered before the memory they point
at is freed, never left to receive into whatever reuses it. The
order within the parent’s teardown is children first, then the
parent’s own capacity slots, then its arena: a child may hold a
slot borrowed from the parent (as_parent_for), and a borrowed
slot is never destroyed by the child. This is what makes the
“resident reclaimed only when the parent dissolves” rule above
observable: a resident’s dissolve() body (fd close, flush)
runs at the parent’s graceful shutdown, rather than the child
being silently swallowed by the parent’s wholesale arena free.
Flow children that already self-reclaimed mid-life are no longer
tracked, so they are not torn down twice; the per-child teardown
is idempotent regardless (an __arena-null latch). The cascade is
single-threaded-safe: cooperative pool workers are joined before
the dissolve cascade runs at program exit, so no worker can be
mid-dispatch to a child being reclaimed. (A parent reclaims only
children it tracks — i.e. one whose body iterates
self.children; a dispatcher that accepts but never iterates
holds no per-child handle and relies on flow/terminate reclaim.)
Locus method dispatch
Section titled “Locus method dispatch”Methods on loci may not return locus values. This is the
load-bearing rule for locus method dispatch in Hale. The
compiler rejects any fn member of a locus whose declared
return type (or fallible-payload type) names a user-declared
locus.
Why this rule
Section titled “Why this rule”Five design principles converge on the same constraint, which is why the rule is shaped this narrowly:
- CQRS — queries return data; entities (loci) are managed structurally, not returned. A method returning a locus mixes command and query semantics in one call.
- Law of Demeter — a method that returns an entity puts that entity into a stranger position at every call site. The only ways to use it are LoD violations (call methods on a stranger) or pass-through (forward to another callee). Both shapes signal the method shouldn’t have existed.
- Dependency Inversion — depending on a returned entity is
depending on a concretion. The bus and
contract-exposed fields are the abstraction surfaces for cross-locus coordination. - Single Responsibility — a locus whose only purpose is to be the return value of a factory method has no responsibility of its own; it’s a method-dispatch wrapper around state that lives elsewhere.
- Mechanical sympathy — every “method returns locus” call site triggers a per-call allocation outside the frame through the m90 routing (released at the instance’s reclaim since GH #1570, but still an allocation and a reclaim per call). Removing the shape removes the allocation.
These aren’t five rules layered on top of each other — they’re five lenses pointing at one structural error. The compiler enforces it once.
The factory train wreck
Section titled “The factory train wreck”The motivating violation is the cross-tower factory pattern:
locus Counter { store: Store; // borrowed reference back to caller's state key: String; fn inc() { self.store.touch(self.key); }}
locus Registry { fn counter(name: String) -> Counter { // ← rejected return Counter { store: self.store, key: name }; }}
// caller:self.reg.counter("ticks").inc(); // would leak per callThe counter() method declaration is the rejection site. The
diagnostic names three canonical alternatives:
Expose entries bind what the locus declares: an expose entry
must bind a real params field or fn member at a matching type (M3
stage 4); an entry named like a method is checked against its
declared return.
-
Parent-child + contract reads.
Counterbecomes an accepted child ofRegistry;Registryreads counter state through the contract:locus Counter {params { name: String; value: Int = 0; }contract { expose value: Int; }fn inc() { self.value = self.value + 1; }}locus Registry {accept(c: Counter) { /* default registration */ }fn inc(name: String) {// iterate self.children, find the matching counter,// call c.inc(). Vertical method dispatch on owned// child — friend access, no LoD violation.}} -
Bus topic (mediator). Counters publish events; Registry subscribes:
topic Inc { name: String };Counter::Inc { name: "ticks" } -> Inc;Closed-world rewrite (when its preconditions hold) collapses the bus round-trip to a direct dispatch — same cost as delegation, without the typed-handle loss.
-
Delegation.
Registryexposes the operation directly:self.reg.inc("ticks");Loses the typed handle but doesn’t allocate. Acceptable when the caller has only a few counters to touch.
Owned-child + contract is the canonical “B’s data feeds A” shape
Section titled “Owned-child + contract is the canonical “B’s data feeds A” shape”When locus A needs to read and update derived state computed
from its own input, the canonical pattern is B as an
owned-child field of A, with the update going through a
vertical command (self.b.compute(...)) and reads going through
a vertical contract exposure or method call on the child:
locus Segment { params { /* accumulator state */ } fn clear() { /* reset */ } fn push(t: Float, v: Float) { /* update */ } fn slope() -> Float { /* compute */ } fn intercept() -> Float { /* compute */ }}
locus LeadingEdge { params { // ring buffer fields seg: Segment = Segment { }; // owned-child field } fn fit() { // command, returns nothing self.seg.clear(); // replay ring contents into self.seg } fn slope() -> Float { // query, returns data self.fit(); return self.seg.slope(); // vertical method on owned child }}The 54-geom-leading-edge example fixture demonstrates this
shape end-to-end. The earlier “factory return” form
(fn fit() -> Segment) was the pattern this rule rejects.
What’s not rejected
Section titled “What’s not rejected”The rule fires only on fn members of a locus. It does not
catch:
- Free fns returning loci — entity creation patterns like
std::io::file::open(path: String) -> File fallible(IoError)are constructors, not factory methods on existing loci. - Methods returning primitives, records, or fallible-of-those.
BytesBuilder.finish() -> Bytes fallible(ClosureViolation)is fine;LeadingEdge.slope() -> Floatis fine. - Methods returning nothing. Commands stay commands.
- Namespace-lotus pattern.
__StdLangLang.parse(src) -> Intis fine — the locus’s methods return data, not loci. - Lifecycle / failure handler bodies. These don’t have value-bearing return types.
Migration
Section titled “Migration”There is no opt-out annotation. The rule is the language’s structural axiom for locus methods — programs that violate it are mis-designed, and the diagnostic names the canonical alternatives. Migrating from the factory shape to one of the three alternatives is a refactor, not a switch flip.
The runtime m90 routing (see § Method-returning-locus heap allocation below) survives only to cover the few remaining shapes where a locus value transits through the m90 path indirectly (e.g., interface returns from free fns). With factory methods stopped at the declaration site, the dominant trigger of the m90 leak goes away by construction.
Method-returning-locus heap allocation (m90)
Section titled “Method-returning-locus heap allocation (m90)”When a fn or a method declares -> Some (or a tuple, an array or an
interface that holds a Some) and instantiates a Some in its body,
the instance’s struct cannot live in the callee’s frame: a stack slot
is dangling the moment the fn returns, so the first read after the
return sees still-valid memory and the second sees overwritten state.
The struct is allocated outside the frame, and both the eager dissolve
and the deferred-frame push are suppressed at the instantiation site;
the locus moves to the caller, whose binding, holder or statement owns
it (§ “Ownership”, GH #1569). This covers both return Some { ... };
and let s = Some { }; ...; return s;, and the locus literals the
returned instance’s params build.
The struct goes back at the end of the instance’s reclaim (GH
#1570). It comes from the runtime’s returned-struct allocator
(lotus_returned_struct_alloc) and is released at its reclaim’s
ReleaseStruct step, the last one: after the latch, the cancel of
its queued runs, the wait for its admitted runs (a deferred reclaim
releases when its runs end) and its arena’s release. A loop over a
factory therefore holds what is alive, not what was ever built: a
discarded mkw(i);, a let w = mkw(i); and a call through a fn
value each leave memory flat, however many locus types the loop hands
back. A released struct is listed for reuse by a later struct of the
same size, on a list of its own size (every size reachable, none scanned
past a cap), and never returned to the
operating system, as an accepted child’s struct is: a stale teardown
path reading the instance’s __arena latch still reads memory the
process owns, and finds it null. Where chunk recycling is off
(LOTUS_NO_CHUNK_POOL, the default under a sanitizer, GH #816) each
struct is allocated and freed on its own, so a read after the release
is a sanitizer report.
Which instances came from the allocator is decided per site and is
not a property of the type, since a literal of the same type in a
frame or a field lives elsewhere; the allocator records what it
handed out and the release answers only for those. Codegen emits the
release only in the reclaim of a type some fn’s or method’s declared
return type names (through a tuple, an array or an interface it
satisfies) or that is a locus field of one; a program that returns no
locus from a fn emits nothing new. A literal of a type outside that
set (a generic fn’s T) and the program-lifetime literals codegen
builds for bindings { } transports, adapters and codecs keep the
program-lifetime payload arena. Deferred bloom (#1553), where a fn
returns its plan and the locus is born at the consuming position, is
the direction; this allocator is what the struct does until then.
@sealed and a revealed secret
Section titled “@sealed and a revealed secret”A @sealed locus confines its params: only its own methods read them
(spec/verification.md § “Secrets”, GH #436). A parameter’s default
reads them as the caller that leaves it does, since that is where it is
evaluated: a default that reaches a sealed field is refused unless every
call that leaves it is inside the sealed locus. A value of a sealed
generic locus’s specialization (Box<Int>) is that locus: its params
are confined the same. A generic body reads a field of a parameter type
as each specialization binds it: self.inner.key with inner: T is
refused when a specialization binds T to a sealed locus, and so is a
chain of fields of any depth reaching one, a field typed as another
generic applied to the parameters included (self.h.s.key with
h: Holder<T> and Holder<A>’s s: A).
std::secret::Credential
is sealed, and its reveal() / reveal_text() are the one named way
its material leaves as a Bytes or String — a raw token or password
has to leave as text to be put on a wire at all. The checker holds every
reveal to that one use, on the path hale check, build, run and
test share. A revealed secret is consumed in the statement that
reveals it:
- A reveal is called in a locus method (a fn, lifecycle method
or
on_failureof a locus), never a free fn, a constant, a param default or any other place. - Its value reaches a consumer within the same statement:
- the payload of a wire write: the data argument of
std::io::tcp::send_fd,std::io::tls::send_bytes,std::io::udp::send,std::io::tcp::Stream.send/send_bytes; the body or content type ofstd::http::post/std::http::Client.post; theheadersorbodyof astd::http::ClientRequest { … }literal handed tostd::http::request/Client.request, or written as thereqof astd::http::BodyReader { … }/SseReader { … }literal that does not namedeferred(or names itfalse): its birth sends it, asrequestdoes (following any redirect itsfollow_redirectsallows), and then blanks the request’sheadersandbody, so read back through the reader’sreqthey are empty and nothing it sent is retained; anAuthorizationline is not sent on once a redirect changes the origin. A reader whose literal namesdeferredsends nothing at birth and keeps itsreq, readable, until the opening, so a reveal into its request is refused; such a reader presents a credential asbearer: c, which the credential writes onto the wire itself, nothing revealed (spec/stdlib.md§ “Reading a streamed body”). A descriptor, host, port, URL or method is not the wire’s: anHttpErrorrepeats the host back, so a secret there is refused; - a comparison of the whole value:
==,!=, amatchwhose patterns bind nothing,Credential.matches. Taken apart or combined first (t[0..1] == c,t < "m"), a comparison answers a question about part of the secret, one call at a time, and is refused.Credential.matchescompares in constant time;==does not; - a parameter declared
@secret.
- the payload of a wire write: the data argument of
- On the way to a wire write it passes only through composition that
cannot keep it:
+and the other operators, aniformatcharm, a record, tuple or array literal that is itself handed on, and a call whose result carries it on — a stdlib fn on the checker’s list of value fns (a positive list: aPUREeffect class says nothing of an out-parameter, andstd::str::builder_appendis pure and keeps what it is handed),lenorto_string, or a free fn the checker proves transparent (every call it makes is to such a fn, or writes a builder it made itself; it calls no method or fn value, builds no locus, assigns only its own locals, and sends, stores and prints nothing). The list holds the conversions, encodings, hashes and percent-encoding (std::url::encode,decode,decode_query). A secret that reaches a fn of the program’s own that is not transparent is refused there, and the diagnostic names the first thing in that fn’s body that keeps it from being one (`tag` calls `println`, which may keep what it is handed). - It is never bound to a
letor amatchpattern, assigned, stored in a field, a param default or a locus literal, returned, raised, published, printed, iterated, used to decide a branch, or handed to anything instd::process(an argv, an environment, a child’s stdin).
The check fails closed: a receiver whose type it cannot see (a pattern
binding, a call’s result, an alias) is taken to be a Credential, a
call it cannot follow keeps what it is handed, and a reveal outside the
bodies it walks (a contract, a closure, a claims block) is refused.
// the header line is the wire write: one statementreturn std::http::request(std::http::ClientRequest { method: "POST", url: u, headers: "Authorization: Bearer " + std::secret::Credential { vault: "api-key" }.reveal_text(), body: b}) or raise;A @secret parameter is a declared consumer, so the rule holds
inside its fn as well: the parameter may reach only a wire write, a
comparison, or another @secret parameter, through the same
composition, and the checker verifies that body. A chain of them ends at
the wire — write_str(@secret s) → write(@secret b) →
std::io::tls::send_bytes(fd, b) — each hop one statement. A one-way
derivation is not a consumer: a hash, an HMAC, a PBKDF2 of a
password is password-equivalent — a SCRAM client key authenticates
exactly as the password does — so a derived value carries the secret on
like any other composition, and binding it is refused the same way.
For a tool that reads a secret from a file rather than a wire,
Credential.write_private(path) writes it on the sealed side, with
nothing revealed: path is a new file, created mode 0600 by openat(2)
itself, in a directory the effective user owns with no group or world
access, outside any git work tree (spec/stdlib.md § std::secret).
The rule follows a value, not a file: once written, the file is the
tool’s to read, and a program that reads it back itself holds the secret
in the open. Making the private directory, handing the path to the tool
and removing both afterwards are the caller’s.
Four sites wait on one change, pq taking a Credential for the
Postgres DSN and its SCRAM exchange: dna::role_password,
dna::ReferenceInfrastructure.knowledge_database, pq::salted_password
and pq::compute_client_final are allowed by qualified name and by
the body that was reviewed — the checker pins each declaration’s
text, wherever the seed is and under whatever alias it is imported — each
finding in them a warning naming that deferral. A fifth site, or one of
the four with anything changed in its body, is refused.
Capacity slot lifecycle and dispatch (F.22)
Section titled “Capacity slot lifecycle and dispatch (F.22)”A locus’s capacity { pool X of T; heap Y of T; ... } block
declares slots 1..N — additional storage disciplines
beyond slot 0 (the locus’s own Arena, implicit). Slot order in
the declaration is significant.
Slot lifetime ordering
Section titled “Slot lifetime ordering”Slot init runs at instantiation, in declaration order, after slot 0 (arena) is set and before the locus’s own field initializers run:
- Slot 0 (arena) — fresh
lotus_arena_create(), or a sub-region of the parent’s arena if the parent’s projection class is Chunked / Recognition and accepts this locus. - For each declared slot in declaration order: call
lotus_pool_create(size_of(T), 8)orlotus_heap_create( size_of(T), 8). Store the returned allocator pointer in the slot’s__slot_<name>: ptrfield. - Locus’s user fields (params + their defaults / overrides).
- Synthetic flags (
__restart_count,__quarantined, etc.).
Slot destroy runs at dissolve, in reverse declaration order, before slot 0:
- Drain + dissolve closures + user
drain()/dissolve(). - For each slot in reverse declaration order: call
lotus_pool_destroy(allocator)orlotus_heap_destroy( allocator). - Slot 0 arena destroyed via
lotus_arena_destroy(arena).
Reverse-order destroy matches F.4’s reverse-instantiation cascade rule for let-bound loci; the same principle applies to slots within a locus.
Slot restrictions (v1)
Section titled “Slot restrictions (v1)”- Slot element type must be a value-shape, not a LocusRef.
Loci have lifecycle; cell recycling (Pool.release) or
individual free (Heap.free) would orphan the locus. Use
accept(c: Child)for locus membership; slots are for value-shaped types. Enforced at typecheck (with a span-targeted diagnostic) and again at codegen as defense in depth. - Slot pointers don’t cross the bus. Structurally enforced: slot names aren’t typeable identifiers, so they cannot appear as bus payload struct fields. No runtime check is needed; the type system makes the case unreachable.
- Duplicate slot names rejected. Two slots sharing a
name (even across separate
capacity { ... }blocks on the same locus, though v1 grammar admits only one block per locus in practice) fail at both typecheck and codegen.
Method-shaped slot dispatch
Section titled “Method-shaped slot dispatch”The user-facing surface is self.<slot>.<method>(args). The
parser and typechecker both recognize self.<slot> as a
slot reference rather than a missing field; the codegen
intercepts the method-call shape and routes directly to the
matching C primitive:
| Slot kind | acquire / borrow | release / return |
|---|---|---|
pool X of T |
self.X.acquire() -> Cell<T> (no args) |
self.X.release(c) (one Cell |
heap Y of T |
self.Y.alloc() -> Cell<T> (no args) |
self.Y.free(c) (one Cell |
Calling a pool method on a heap slot (or vice versa), or any other method on a slot, is a type error at the method name that names the right methods for the slot kind:
main.hl:7:38: type error: pool slot `entries`: method `alloc` is notavailable (`alloc` is a heap slot's) — use `acquire()` to borrow acell and `release(cell)` to return itThe Cell<T> cell type is documented in
types.md; struct cells support cell.field read/write (v1.x-2)
and Cell<T> carries slot-of-origin so cross-slot release is
a type error at the cell (v1.x-5). Primitive cells (Cell<Int> etc.)
still reject field access, at the field name — direct
load/store through a primitive Cell handle (e.g. *cell) is
the natural next surface but no current workload demands it.
Slot access outside a method-call receiver position (e.g.,
let x = self.entries; to hold a slot handle as a value) is
not supported at v1 — slots have no value-level CodegenTy
that survives outside the dispatch path. Codegen errors with
“no field on locus self” if the standalone access slips past
typecheck. v1.x can lift this if a workload demands first-
class slot-handle values.
Slot 0 parent-override
Section titled “Slot 0 parent-override”When a locus is accepted by an owner (the accepting ancestor —
see “Accept bubbling,” not necessarily the direct parent) whose
projection class is Chunked or Recognition, the child’s
slot 0 (arena) is allocated either as a sub-region of the owner’s
arena (Chunked, via lotus_arena_create_subregion) or out of the
owner’s recpool (Recognition with the matching sub-mode, via
lotus_recpool_fixed_acquire / lotus_recpool_slab_acquire).
The child is freed wholesale when the owner dissolves.
Rich-class owners do not sub-region-allocate; accepted
children get their own top-level arenas. When bubbling crosses a
pool, the child is born in — and reclaimed by — the owner’s
thread via an async bus handoff (runtime.md). See memory.md
Per-projection-class allocation table.
F.22 names this as “projection class governs parent-override
of slot 0.” Slot 1..N parent-override (pool entries of Int as_parent_for Child;) shipped via v1.x-4 (surface) + v1.x-4b
(runtime mechanic, commit d50ab79): the borrow-mask
__slot_borrowed_mask field carries one bit per slot, set when
the slot was borrowed from a parent’s matching slot at accept
time; the dissolve pass skips destroy on borrowed slots so the
parent retains ownership of the underlying allocator. The child’s
slot takes the parent’s allocator, so it is declared with the same
name, the same kind (pool or heap) and the same cell type; each
mismatch is a type error at the as_parent_for clause’s locus name.
Lifecycle method invocation
Section titled “Lifecycle method invocation”birth()
Section titled “birth()”Runs once, synchronously, after region allocation and before
the locus is “live” for any other purpose. A failure during
birth (a birth-epoch closure or birth_check) is a
ClosureViolation: the region is kept, and the parent’s
on_failure(c, ClosureViolation { ... }) runs at that epoch,
held while the parent’s params are open, so the handler can read
the child and restart it (runtime.md § “Lifecycle obligations”,
line 8). There is no StructuralFailure.
accept(c)
Section titled “accept(c)”Runs after child c’s region is allocated and its params are
built, and before its birth(). Receives c with its params set
(not its running state). Its result is not read: accept admits
the child and cannot reject it; an admission interface is
separate work (runtime.md § “Lifecycle obligations”, line 5).
After accept returns, the child registers in self.children
(per F.11).
A locus declares at most one accept (single-accept-type per
parent, types.md F.11). A second accept clause is a typecheck
error naming both clauses; the first clause remains the locus’s
accept type. The one clause may name an interface, accepting every
locus that satisfies it (§ Locus instantiation, “An interface
accept”). A parent that must own two child types gives one of
them a different owner. (2026-09-04, GH #525: a second clause used
to overwrite the first silently.)
accept’s param (and release’s) names a child: a locus type, or
an interface the child’s locus satisfies (§ “Locus instantiation”).
A param of any other type — a primitive, a type —
is a typecheck error at the param’s type:
main.hl:1:44: type error: `accept(c: Int)`: `accept()` takes a locusor an interface: it adopts a child, so its param names the child'slocus type (or an interface that locus satisfies), and `Int` isneither. A value is not a child: pass it to the child as a param whenthe child is built.Before this rule the check accepted such a param and the backend refused it with no source location.
Runs continuously until drain is requested or run returns
naturally. Cooperative — yields at every bus dispatch, every
time::sleep, every explicit yield point. The scheduler may
run other loci while this run is yielded.
If run() returns naturally, the locus exits run-state and proceeds to drain.
A locus that declares no run() has an empty one: the two
spellings are the same program (GH #735, 2026-09-22). In particular
a flow child — a type some parent releases — is reclaimed when its
empty run completes, right after its birth, whether the empty run() { } is written or omitted; it does not live until its owner’s exit
because the hook was left out. A resident is unaffected: an empty
run means “ready” either way.
A violate in run(), or a closure that fails there, is a
ClosureViolation, delivered to the parent’s on_failure(c, ClosureViolation { ... }) at that point (runtime.md §
“Lifecycle obligations”, lines 8 and 9). run() has no panic.
drain()
Section titled “drain()”Runs once, when the locus is asked to drain. Drain cascades depth-first (per F.4): drain runs on all children first, synchronously; then runs on self.
During drain:
- New child accepts are refused.
- In-flight handler invocations complete.
- New bus messages are not accepted; in-flight messages on bus subscriptions are delivered.
- Closure tests at
tickepoch may fire (if not already fired).
Default drain: no-op (just transitions state from running to drained).
dissolve()
Section titled “dissolve()”Runs once, after drain completes, in this order
(runtime.md § “Lifecycle obligations”, line 10):
- Closure tests at
dissolveepoch fire (per F.9). A failure is delivered then, to the parent’son_failure(c, ClosureViolation { ... }). - The user-supplied cleanup code runs, if any.
- Region freed wholesale.
- Without a failure, the parent sees normal child-dissolution.
Default dissolve: free region.
on_failure(c, err)
Section titled “on_failure(c, err)”Runs when a child of self fails: a ClosureViolation, or, for
main’s bindings, a transport’s loss. Receives the child handle
and the typed error.
The handler may:
-
Return normally (absorb): treat as collapsed — the child stops, and a child the parent holds stays readable until the parent’s teardown (§
terminate, “A failed child its owner holds is kept”). Areturn;anywhere in the body is this exit taken early: the loci the handler bound so far are torn down, as at its end, and the handler returns. The handler returns nothing, so areturncarrying a value is a type error at the value:main.hl:8:35: type error: `return` in an `on_failure` body carriesno value: the handler returns nothing. Write `return;` to end itearly. -
Call
restart(c): run the child again —birth(), thenrun()— on the same instance (see § Recovery primitives). -
Call
restart_in_place(c): re-init in place (preserve arena). -
Call
quarantine(c): keep child in a halted state with arena preserved; future inspection possible. -
Call
bubble(err): pass the failure to self’s parent. -
Call
dissolve(c)explicitly: free child’s region.
Default on_failure: bubble(err). The runtime root’s default
is process exit with stack trace.
Which handler runs. A locus may declare one on_failure per
child type — on_failure(a: Alpha, err: ClosureViolation) beside
on_failure(b: Beta, err: ClosureViolation), a stdlib locus such
as std::http::Server included. Every handler takes the same
error type, so the failing child’s own locus type is what selects
one: an Alpha’s failure runs the Alpha handler and only it,
whatever order the handlers are declared in. A child whose type
has no handler on its parent gets the default. A second handler
for a child type that already has one is an error: the first
declared is the one a failing child reaches, so the second could
never run, and hale check refuses it where it stands, pointing at
the first.
Which locus is the parent. A child locus held in a param
field is supervised by the locus that holds it, whichever way
the literal is written: as the field’s default in the parent’s
params { }, or at the call site in the parent’s literal
(App { b: Boom { why: w } }), in any branch of an if or match
that the field’s value names, and one level at a time
through nesting (App { w: Wrap { b: Boom { } } } — Boom’s
parent is Wrap). Where the holder itself is built does not
matter: let s = Sup { }; inside another locus’s method gives
Sup’s default child to Sup, not to the method’s locus (GH
#1074). An override expression is otherwise lowered
in the caller’s context (self.x in it reads the caller), but
the literal it builds belongs to the parent. A locus built
elsewhere and passed in by name — a let binding, a factory’s
return — keeps the route of the place it was built: the locus
whose method body built it, or none from a free fn or fn main.
When it runs: never before the parent’s params are settled.
A child can fail while its parent is still setting params — a
cooperative child’s run() executes inside that loop (§ Birth
order is load-bearing) and a pinned child’s thread starts in it.
The failure is held and delivered once the parent’s last
param is stored, before the parent’s birth(); several are
delivered in the order they arrived, on the thread settling the
parent. So a handler always reads params that hold their values,
and nothing it writes is overwritten by a default stored after
it. The failing child outlives its held failure: a child whose
run() has already ended — a cooperative child’s returns right
after its violate — is reclaimed only after its handler has
run, so the handler’s c is always a live child.
The rule holds the handler back, not the children. The other
reading — every param settled before any child runs — would undo
§ Birth order is load-bearing: a later param’s default may read
what an earlier child computed (total: Int = self.loader.count
after loader’s inline run() filled it), and that only works
because the children are born, and inline ones run, one at a time
in declaration order.
A restart requested from a held handler takes effect when the
handler returns, in the same delivery step: on the parent’s
thread for a cooperative child (the one settling the parent, which
the child was running on), on the child’s own thread for a pinned
one — that thread waits for the handler’s decision rather than
deciding by timing — and on its pool for a child placed on a worker
pool, whose birth ran on the pool’s worker: the restart is posted
there as the child’s run, so the re-run birth() and the run()
after it execute where the first ones did, never on the thread
settling the parent (whose own run() would otherwise wait behind
a child run() that never returns). The child the handler restarts
is the one it was handed, kept alive for it. A birth-epoch failure
is held like any other: a child whose birth failed does not start
run() until its handler has returned, and then starts it,
restarts, or stays quarantined as the handler decided.
A handler may replace a sibling whose own failure is still
outstanding (self.b = Kid { … } in the handler for a, with
b’s failure not yet delivered): the field holds the new child at
once, the replaced child’s failure is still delivered to the owner,
after the running handler returns (handlers never run inside one
another), and the replaced child is kept for that handler and
reclaimed right after it.
The reclaim wins. A decision about a child the handler has
replaced, or whose owner’s reclaim reached it while its failure was
outstanding, is not performed: restart(c) and
restart_in_place(c) on such a child leave it as if the handler had
returned without asking, so it is reclaimed once, after its handler,
and no birth() or run() of it starts again, while the new child in
the field is untouched. (An owner’s teardown that reaches the child
through a pool join before its reclaim does not refuse it yet:
spec/runtime.md § “Lifecycle obligations”, “Restart during drain”.)
One failure cannot wait and is delivered at once: a dissolve-epoch closure’s, because the child’s region is released right after.
The bracket costs a locus nothing unless it declares
on_failure and holds a locus-typed field or computes a
default; one that does pays two uncontended lock round trips per
instantiation.
Reassigning a locus-typed field (WS1#4)
Section titled “Reassigning a locus-typed field (WS1#4)”Assigning a fresh locus literal to a locus-typed field —
self.<field> = SomeLocus { … }; — is a lifecycle
transition, not a value store. It is lowered break-before-make:
- The instance currently in the field runs its teardown spine:
drain → dissolve, including its child cascade. Cleanup such as
closing
@ffihandles happens before the replacement’s birth. Its storage is released once started runs have given up their holds, as in the teardown when its parent dissolves. - A new instance is constructed from the literal into self’s own arena, owned by the field (not scope-bound) — so it outlives the enclosing method and is reclaimed through the field when self later dissolves, exactly like a field-default child from params-init.
- The field is repointed at the live new instance.
The same transition runs when the field is replaced from outside its
owner (h.loc = L { … } in a free fn, hs[i].loc = L { … }), with
the owner — the locus the store’s path reaches — in place of self
(GH #1561; types.md § A store into a locus’s field is the locus’s
own). Before, the new instance was the replacing frame’s temporary,
dissolved when that frame returned, and the old one was never
dissolved.
The old instance’s drain and dissolve finish before the new instance
is constructed, unless its own failure is still outstanding: then
its whole teardown follows its handler, and a restart that handler
asks for about it is not performed (§ “on_failure(c, err)”, “The
reclaim wins”).
There is one storage-retention exception: when a
queued main-thread handler performs the replacement, waiting for an
old run inside that handler could deadlock a reply queued behind it.
Physical release is then deferred until the handler returns. The old
run retains its arena, forms and owned descendants until it finishes;
their storage is released before the containing owner’s storage.
This does not postpone dissolve() or keep resources closed by that
method open. Handler bodies keep their completion order. Outside a
handler, replacement waits for the old run while servicing the queue.
For “same instance, reconfigure,” use in-place mutation
(self.<field>.<x> = v;), which stays the cheap path and triggers
no teardown. v1 scope: the new instance inherits the parent’s pool;
reassigning a pinned-placed field does not re-apply the pinned
placement.
The right-hand side must be a locus LITERAL (error). Assigning
a locus value produced somewhere else — self.held = make_row(…);,
or let c = Conn { … }; self.conn = c; — is rejected, because
ownership would be ambiguous: the field claims the instance (its
teardown reclaims it when self dissolves) and so does the frame
that produced the value (its scope exit reclaims what it built).
Nothing in the language decides between them.
That ambiguity is not hypothetical. Until this rule, a locus returned from a free fn was routed to a program-lifetime arena and never reclaimed, which is what made such a store appear to work: the field’s pointer stayed valid because nothing ever freed it — the leak was the safety mechanism. Every attempt to give those loci a real lifetime produced either a use-after-free or silently wrong values.
Three remedies, all existing shapes:
-
Assign a literal — construction in place, the lifecycle transition above, unambiguously owned by the field.
-
Route membership through
accept(c: L)— parent/child ownership, which is the language’s answer for “this locus holds that one” whenever the child is not aparamsfield. -
Transfer the STATE, not the instance — where a locus is a handle over an external resource, the module that owns the resource may publish a transfer operation that writes the handle’s state into the instance the field already holds and leaves the source at its not-acquired sentinels. That is not a locus store at all: no second instance enters the field, and the disarmed source’s own teardown releases nothing.
std::process::adopt(dest, src)(GH #716) is the shipped instance — the pid and three pipe fds of a spawnedChildmove into the field, whatever the field held is released first, and the source is disarmed. The first two remedies cannot reach that case: the resource is acquired by a syscall inside a factory, so there is no literal to write andaccept()cannot adopt what a free fn built.This is a module-provided operation, not a language feature. The language does not gain move semantics: the transfer is ordinary field assignment written inside the module that defines the handle, and it is sound only because that module knows what “one owner” means for its resource (which descriptors, whose teardown, in which order). A locus with no external resource has nothing to transfer and needs none of this.
Contract-typed fields hold a borrow when assigned a handle (GH
#967). An interface-typed field cannot be
assigned a locus literal (the literal’s type is not the field’s), and
the only values that reach self.<field> = v are interface VALUES —
a parameter, another field: a handle somebody else owns. That store
is a borrow, the same decision F.39 makes for a name in a field
initialiser (Owner::Borrowed), applied to assignment:
- The instance the field owned until then — its default, or a literal it was built with — is reclaimed, break-before-make as above.
- The field is marked borrowed: the holder’s cascade never reclaims what it now points at. The handle’s own owner does, at its own time.
- The handle is stored.
A field that already held a borrow releases nothing when assigned again. What the rule does not decide is lifetime: the borrowed instance has to outlive the holder, exactly as one passed by name at construction has to — that is the contract of every handle, and the checker’s question in GH #730. Before this rule the store was a plain value store: the field kept describing the default it was built with, so the holder’s teardown reclaimed the handed-in instance (its owner then read freed memory, or reclaimed it a second time) and the default leaked.
A borrow outlives its holder (GH #730, 2026-09-22). A handle
stored by name into a locus-carrying param field — LocusRef,
interface — is borrowed, never the holder’s to
reclaim, so what owns it must outlive the holder. Ownership is
structural and reclamation a tree cascade, so the checker decides
this from position, with no annotation — on the path hale check,
build, run and test share, so a program check refuses never
builds:
| the handle comes from | holder owned by the frame | by self (a field, an accepted child) |
by the caller (returned) |
|---|---|---|---|
a field of self |
sound | sound | refused |
a let of this frame |
sound while the binding is in scope | refused | refused |
| a bus handler’s payload | sound | refused (GH #712) | refused |
| a parameter | sound | every caller is asked | left alone |
For a parameter, every call site of the method is classified by the
same table; the first caller that hands a let of its own frame or a
handler payload is the witness the refusal names, and a parameter at
the caller recurses to a bounded depth. Nothing else is refused: a
chain the walk cannot follow is left alone, never guessed at. A
borrow the holder reads only in birth() is birth-scoped and sound —
the instantiation runs inside the frame that owns the handle — which
is the shape a resident uses to copy what it was handed before the
dispatch ends. The other axis of a borrow, the thread domain, is a rule
of its own (GH #984): a borrow is read from its holder’s thread, so a
handle whose instance runs on another pool is refused where it is handed
over, naming both domains and the hand-over (spec/types.md § “One
instance is never shared across pools”, GH #1566); a type that
synchronizes access from another domain is admitted, and a value that
crosses by the bus is a copy, not a borrow. A program wrong on one axis
is told that axis alone. A container a handler built and handed to a resident’s
form-typed field is the let row of this table (GH #712); the data
it holds is copied at the store and is not a borrow.
A handle a method keeps is the same borrow (GH #1048). A method
keeps a parameter of a locus-carrying type when its body stores it
into self: assigns it to a field, hands it (alone, or inside a
record, a tuple or an array) to a mutator of a @form container of
self’s (push, set, insert, put, append, …), or passes it to
a method of a place under self that keeps it in turn. The checker
reads that from the body — the stdlib’s and an imported seed’s
included: std::http::Router.add keeps its handler and use its
middleware. The argument at a call to such a method is a borrow the
receiver holds, decided by the table above with the receiver as the
holder, by the receiver’s root binding:
- a place under
self(self.router) isself’s, and so is a place under the child anacceptreceives; - a parameter is the caller’s, and so is a binding the body hands back
— by
return r;, a tail, or a record, tuple or array literal carrying it out — resolved by binding, not by name, throughletaliases (let r2 = r;) either way; - any other binding is the frame’s.
A receiver’s locus is known when its root binding holds a locus
literal, a call to a free fn declared to return a locus, or an alias of
either, and through the declared field types below it (a.router). A
locus literal written as the argument is a temporary of the frame that
builds it, so it counts as that frame’s let — also where a parameter
carries it into a keeping method, when the caller is asked:
fn build(dir: String) -> std::http::Router { let r = std::http::Router { }; r.add("GET", "/x", Echo { s: dir }); // refused: r is returned return r;}The router would dispatch into a handler its building frame reclaimed.
Within one frame the holder and the argument end together, except in a
loop: a locus built in a loop body is reclaimed when the next iteration
reuses its slot, so a literal or let inside a loop kept by a router
declared outside it is refused; one inside an if block lives to the
frame’s end and is sound. A handler that is a field of the locus owning
the router (self.router.add("GET", "/x", self.echo)) lives as long as
the router and is sound. The birth-scoped exemption above does not
apply to a kept handle: birth() can hand the router on to something
that outlives it. A keeping method called on self itself
(self.observe(j)) is a store into self spelled as a call, left where
an assignment self.observed = j is left (GH #967). A call through a
value this walk cannot type (an interface, a call’s result used in
place) is left alone.
This is the same principle as the no-locus-return rule on methods
(fn get() -> SomeLocus is rejected): a locus is structure, not
a value to hand around. Ordinary let-bound loci — including
factory results — are unaffected; they are owned by the binding
that names them. A factory result written as a locus- or
interface-typed field of a locus literal — Router { quick: make("q") }, in a body, a default, or another factory — is owned
by that literal: the literal is the construction site, so this is
not the ambiguous store above, and the frame that made the call
does not reclaim the result at its exit (dna/FRICTION.md F.17).
Topic declarations
Section titled “Topic declarations”A topic Foo { payload: T; } declaration names a typed pub/sub
channel at top level. Subscribers, publishers, and send sites
reference the topic by name; the payload type travels with the
declaration instead of being repeated at every subscribe ... of type T site.
type Tick { n: Int; }topic Ticks { payload: Tick; }
locus Counter { params { count: Int = 0; } bus { subscribe Ticks as on_tick; } // no `of type T` fn on_tick(t: Tick) { self.count = self.count + 1; }}
locus Pub { bus { publish Ticks; } // no `of type T` run() { Ticks <- Tick { n: 1 }; // identifier subject, not "Ticks" }}Type-check rules:
- Every subscriber’s handler signature must match
Topic.payloadexactly — a static error cites both sites if they diverge. (Enforced 2026-08-11 — downstream handoff; this rule was written but never implemented, and the reinterpreted payload surfaced a String field’s heap pointer through an Int parameter from safe code. The check covers both subject forms — declared topics and string subjects withof type— plus arity, acceptsDrain<T>batch handlers by their element type, and names the topic-as-parameter-type mistake (fn on_h(msg: Hello)whereHellois the topic) specifically. Payloads that resolveUnknown— cross-seed topics — stay permissive by the milestone-2 rule; stdlib paths resolve to their real nominal types since GH #470 and are checked like any user type.) - The send-expression’s type at a topic-ref
<-site must matchTopic.payload. - The
of type Tclause is forbidden on topic-ref subscribe / publish; the topic carries the payload type. - A topic identifier outside subscribe / publish / send-subject
position (e.g.
let x = Foo;) is a type error — topics are not values, they only address bus channels.
topic is a contextual keyword: lexes as IDENTIFIER except in
top-level declaration position, so existing names (struct fields
called topic, local variables named topic) continue to work.
Lowering: codegen and runtime work against the legacy
string-subject form. A desugaring pass between typecheck and
codegen rewrites BusSubject::Topic(Foo) → BusSubject::Literal { subject: "Foo" } and fills in the elided payload type, so the
downstream pipeline (cooperative queue, mailbox post, transport
fanout) is unchanged from the string-subject path. The wire-format
subject for a topic named Foo is the bare string "Foo".
Coexistence: the literal-string form (subscribe "S" as h of type T;) is still accepted because the log namespace lotus
relies on wildcard publish (publish "log.**" of type LogEvent;)
- runtime-computed subject strings (
subj <- LogEvent { ... }wheresubjis"log." + self.full_path), and the topic-decl form has no equivalent at v1. The two forms can be mixed within one program; they only collide if a topic name and a literal subject share the same wire-format string, which the type checker catches via the standard duplicate-symbol diagnostic.
Canonical form for new code: prefer the topic-decl form
(topic Foo { payload: T; subject: "wire.subject"; } +
subscribe Foo as h;). Reach for the literal-string form only
when you need a wildcard subscription or a runtime-computed
publish subject — those are the cases the topic system doesn’t
cover at v1.
Computed publish subjects are confined to their declaration
Section titled “Computed publish subjects are confined to their declaration”A send whose subject is not a literal (subj <- v) requires the
enclosing locus to declare a wildcard publish whose payload
accepts v. That declaration is an authorization, and it is
enforced — not merely required at the declaration site:
- Pattern. At the send, the computed subject must lie under one
of the locus’s declared publish patterns. A locus declaring
publish "io.tcp.**"cannot publish"app.order". Violating this raisesBusPublishUnauthorized. - Payload. The computed subject must not reach a subscription
declared for a different payload type. Violating this raises
BusPayloadMismatch.
Both are runtime checks on the computed path only; a literal subject is bound to its declaration at compile time and pays nothing for either. The payload check reads the subjects every subscription recorded when it registered, which may be on any thread (a pinned or pool anchor initializes its subtree on its own). A send reads them with no lock while another thread may be recording more; a subscription recorded while the read is under way is not checked by that send. (The runtime’s subject-to-payload table has the registration table’s publication scheme: rows that never move, behind an array published as a pointer and a count, appended under a lock, a replaced array kept until teardown.)
They are not stylistic. Without them the computed string reached
dispatch verbatim, so a subject outside the declared pattern was
delivered to whatever subscribed to it and the payload was
reinterpreted as that subscriber’s type — a two-field
LogEv { a, b } published on "app.order" arrived at an Order
handler as id=a qty=b, with hale check reporting ok.
Statically, a subscription that sits under another locus’s declared
wildcard pattern while expecting a different payload is a
warning: whether the hazard is live depends on whether that
locus ever publishes a subject reaching it (a std::log::Logger
declares all of log.** but publishes only under its own path), so
it names the risk without refusing the program.
The pattern also bounds analysis. Because a computed publish
cannot escape its declaration, an unresolved publish inside a locus
declaring "io.tcp.**" provably cannot produce a publisher of an
application topic. Subject-specific questions — how many publishers
a topic has, whether @effects(depends:) names the complete
inbound surface — are answered against the patterns rather than
against one program-global “some publish is unknown” bit. Residue
that carries no pattern (an unfollowable call, a truncated
frontier, a publish whose subject expression resolves to nothing)
stays unbounded and still withdraws every subject.
Phase 2: hierarchy, subjects, bindings, closed-world optimization
Section titled “Phase 2: hierarchy, subjects, bindings, closed-world optimization”Phase 2 extends topic declarations with three orthogonal pieces:
1. Hierarchical topics + wire subject. A topic may declare a parent and an own-subject segment. The materialized “wire subject” is the dot-joined chain of segments root-to-leaf:
topic Events { payload: Event; subject: "events"; }topic Login : Events { payload: Login; subject: "login"; }// Login's wire subject is "events.login".Defaults: own-subject defaults to the topic’s name (verbatim), so
top-level topic Ticks { payload: Tick; } keeps Phase-1’s
behavior of wire subject "Ticks". Parent must reference a
declared topic; cycles + missing parents are typecheck errors. Two
distinct topics that produce the same wire subject are also
errors — path-shaped routing would be ambiguous.
The desugar pass rewrites BusSubject::Topic(Login) to
BusSubject::Literal { subject: "events.login" } so codegen and
the bus runtime see only the wire form.
2. main locus + bindings { } block. A locus prefixed with
main is the binary’s entry-point holder and is the only place a
bindings { } member is legal. Bindings choose a transport per
topic; the same library compiles to in-process or external in
different binaries by varying the main locus. An entry may name an
imported topic — dna::ReviewVerdict: unix(...) binds the
declaration the library owns, never a re-declaration of it — and
resolves exactly as a qualified bus subject does (GH #527 B6).
main locus App { bindings { // Beat: not bound — same-binary cooperative queue (default). Login: unix("/tmp/login.sock"); // role inferred Events: unix("/tmp/events.sock", role: listen); // explicit override Remote: MyNatsAdapter { url: "nats://..." }; // adapter locus }}The publish contract (GH #227, 2026-07-22). T <- value
succeeding means the broker accepted the message; what
“accepted” obligates the broker to is defined per binding, and
the broker may never accept a message it already knows it cannot
handle under that binding’s guarantee. Per binding:
| Binding | “Accepted” means |
|---|---|
| none (in-process) | dispatched to every born subscriber in this binary |
unix(...) |
handed to the peer connection, message boundaries preserved |
udp://... |
handed to the local IP stack; lossy from there by declaration |
shm_ring(...) |
slot claimed + committed, under the declared on_overflow policy |
| adapter locus | whatever the adapter’s own contract says (it owns delivery) |
hub (Topic: self.hub) |
a stream: handed to every admitted subscriber’s queue under the row’s bound and on_full (spec/api.md § Streams) |
This contract is what lets <- be an infallible statement: the
error channel isn’t missing, it’s relocated to where it can be
acted on. Consequences, all normative:
- Binding realization failure is a birth failure of the
declaring locus. A
bindings { }entry (orLOTUS_BUS_CONFIGroute) whose transport cannot be opened — socket/bind/listen/addr failure, connect-retry timeout, unparseable route — refuses the boot. There is no code path where a binding fails to open and subsequent publishes report success. Bindings live on themainlocus, whose parent is the root, so the unhandled default is the root failure shape: the structural diagnostic on stderr + non-zero exit (the same seatlotus_root_panicoccupies; routing through a main-locuson_failureis the planned extension of that seat). The runtime primitive islotus_bus_binding_fail(subject, url). Listener-side realization is synchronous at registration (socket + bind + listen; UDP: parse + bind + group join) — only the blocking accept / recv loop runs on the reader thread, so a dead binding can never fail invisibly on a detached thread. - Per-send transient errors on a lossy transport are not
structural. A UDP
sendtofailure is logged (once per errno class), not fatal: the binding’s guarantee is best-effort by declaration, so downstream loss is within contract. - Peer EOF on a listen binding is not loss. The listener is still bound; the serve loop re-arms and accepts the next peer (GH #233 step 2), so rolling restarts of connect-side binaries work without policy.
- Listen-side ingress the kernel accepted is delivered
(GH #468). Three normative pieces, closing what used to be
silent loss at the registry’s edges:
- Binding readers imply the locked queue. Any
bindings { }block makes the program off-thread for queue purposes (compile-time, same flag as pinned placement), and the runtime re-asserts it whenever it spawns a reader thread (coversLOTUS_BUS_CONFIG) — a concurrent reader enqueue can never race the owner’s drain on the unlocked single-threaded path. This was the actual mechanism behind “a loaded run occasionally loses a mid-stream wire message”: two binding readers and the drain on an unlocked queue. - The boot window buffers. A message received between
transport realization and the same birth’s (later)
subscriber registrations is buffered — bounded, per
binding: 64 messages / 1 MiB, oldest-first eviction,
counted (
buffered_early/dropped_earlyin the counters dump) — and flushed FIFO the moment a matching registration lands. A relay-shaped program with no local subscriber degrades to the old drop behavior at the cap, counted instead of silent. Post-boot, a message with no registered deserializer remains the documented relay-shaped skip. - Exit quiesces before teardown. At every main-exit point,
before pools join and loci dissolve, each listener’s reader
is told to stop (new connections are no longer awaited;
queued data and already-accepted backlog connections stay
readable), readers drain what is queued through the
still-intact registry, buffered boot-window residue is
flushed, and one final local drain delivers to still-alive
handlers. Bounded:
LOTUS_BUS_QUIESCE_MS(default 500,0disables), loud if exceeded — a silent peer holding a connection open cannot stall exit. Wire data arriving after the stop arrived after exit and is outside the contract. Audp://listener’s reader is stopped by an explicit wake, a pipe it polls beside its socket, the same on Linux and macOS: it reads the datagrams the kernel has queued, then ends. An empty datagram is an ordinary frame to it, rejected as too short and counted as a drop (dropped_decode; § Payload type below), never its stop (2026-11-06, downstream handoff: a zero-byte datagram was the reader’s stop sentinel — what ashutdown()of the socket produced on Linux — so one ended ingress for good and every later datagram went unread, silently; and Darwin does not honourshutdown()on an unconnected UDP socket, so an idle reader there never woke and the exit waited out the bound, then hung on the join). Aunix://listener’s reader is stopped the same way (GH #1991): on the pipe’s wake it admits the connections already in the listener’s backlog, reads what every peer has queued, and ends when no peer has anything left; nothing isshutdown(). Darwin answers ashutdown()of a listening socket withENOTCONNand wakes nobody, so on macOS every unix listener, served or not, waited out the bound at each exit until 2026-11-17.
- Binding readers imply the locked queue. Any
- Connect-side loss is structural, with reconnection as
supervision policy (GH #233 steps 3–4). A send failure on a
source-declared connect binding marks the entry lost
(fanout skips it — publishes during the window are dropped,
never falsely “delivered”) and queues a loss event dispatched
on the owner thread at the next queue drain. Default: the
structural exit, diagnostic naming the subject. Handled: the
main locus declares
on_failure(t: std::bus::UnixTransport, err: ClosureViolation)— the handler receives a syntheticlink_lostviolation, andrestart(t);re-runs the connect-with-retry; on success the binding resumes, on failure (or a handler that declines) the structural exit fires. Reconnection is a supervision decision, not a transport feature.LOTUS_BUS_CONFIGconnect routes sit outside the supervision tree (no locus to route through) and keep logged-only send failures. - Malformed
LOTUS_BUS_CONFIGlines stay warn-and-skip (the file is an operator-layered override and the diagnostic names the line); a well-formed line whose route cannot be opened fails the boot like abindings { }entry.
The api binding (retired)
Section titled “The api binding (retired)”A program’s API is no longer an entry in the main locus’s bindings { }.
bindings { api: … }, @gated, serve: and an expose member read as an
API are refused with one diagnostic that names the replacement, and the
compiler carries no code to accept them. spec/api.md is the contract:
- what the program offers is a surface: an
api NAME { rpc Locus::handler requires: [role]; … }block, or@rpcon a handler (§ Surfaces and their rows). A call is a call of the handler, authorized against the row’srequires; a read is anrpcwhose handler returns the value; - where and how it is offered is a serve site, the literal of an
exposure param,
web: api::Exposure = api::serve(Surface, unix::Rpc { … } | http::Rpc { … } | mcp::Rpc { … }, as: "name", bound: N, on_full: refuse);, in the params of the locus that holds it (§ Serving; GH #1565), over a transport that is a locus with lifecycle (§ TheRpcinterface), under a role source and a bearer source the program supplies (§ Identity sources); - a stream is a topic bound to a hub,
bindings { Topic: self.hub requires: [role], bound: N, on_full: drop_old; }over aws::Hubor audp::Hub(§ Streams); - what a client reads is the description of one exposure for the caller
(§ The description):
{"describe": true}over the socket,GET /.descriptionover HTTP,hale check --apifrom the rows.hale describe,call,watch,adminandmcp --appare clients of it.
What stays here, because it is not the API’s: the publish contract (§ “The
publish contract”, above) and the bus codec clause codec(…) of a binding
(F.36) apply to every bindings { } entry, a topic bound to a hub among them.
A message that did not come through a transport is not a call: std::api::Context
(spec/stdlib.md § std::api) is built by the exposure for a handler that
declares it, and a handler called any other way gets the caller it names.
Transport surface:
-
unix("/path")orunix("/path", role: connect|listen)— AF_UNIX framed-byte transport. Substrate-provided as a locus (GH #233 / F.37): the entry is sugar that instantiates__StdBusUnixListenTransport/__StdBusUnixConnectTransport(stdlibbus.hl) as a cooperative child of the main locus, converging with the adapter path.birth()realizes the transport synchronously on the boot path (so a dead binding fails the boot, per the publish contract above); the listen side’s birth spawns the C serve thread, whose loop accepts a peer, fans recv’d payloads into the local handler set, and re-arms on peer EOF (closes the dead connection and accepts the next peer — a restarted connect-side binary reconnects without the subscriber noticing);dissolve()interrupts + joins the serve thread and destroys the transport.role: connectopens a write-side transport that publish-site dispatch sends to. Whenrole:is omitted, the typechecker infers it from the bus block (publishonly → connect,subscribeonly → listen); if both publish and subscribe touch the topic, the binding is rejected with a “specifyrole:” diagnostic. -
LocusName { field: value, ... }— user-supplied protocol-layer adapter. Any locus that declaresfn send(subject: String, bytes: Bytes)satisfies the__StdBusAdaptercontract and may appear on the right-hand side of a binding. The bus router dispatches outbound payloads for the bound topic through the adapter’ssendmethod; framing, retry, ordering, and connection management are the adapter body’s concern. The adapter’s ownparamsblock carries protocol configuration (broker URL, credentials, timeouts, point-to-point role for p2p shapes). The grammar distinguishes substrate vs adapter by the head’s case (lowercase keywordunixvs capitalized locus name). An adapter declared by an imported library is named through the import alias,alias::Adapter { ... }, and binds exactly as one declared in the program’s own seed; the case rule reads the last segment. The same holds for acodec(alias::Codec { ... })clause (GH #1034). Inbound dispatch from an adapter into the local handler set is handled bystd::bus::__local_dispatch(subject, bytes)(m105): it reconstructs the payload against the subject’s registered deserialize fn and fans into local subscribers vialotus_bus_dispatch_wire. Placement. A bound adapter is pinned by construction (F.31): itsrun()gets a thread of its own, and every subscription the adapter declares is delivered on that thread, at itsrun()’s next yield (asleep, a park) or afterrun()returns.sendis the exception: the runtime calls it on the PUBLISHER’s thread. A publish from insidesendonto a topic the adapter itself subscribes therefore goes through the bus to the adapter’s thread — never the closed-world direct call (§ “Closed-world topology optimization”) — so one locus can own a socket and be both itssendand its receive loop, with every write on its own thread (GH #1032). Thebytesasendcall receives are valid for that call: the runtime builds them in an arena of the call’s own, freed whensendreturns, so publishing through an adapter holds memory only for the sends in flight — none per message, whethersendreturns at once or parks (asleepor arecvon anasync_iopool) while other publishes overlap it (GH #1038). Asendbody that keeps the bytes — stores them in a field, publishes them onward — keeps a copy, as it would any stored value. Whateversenddoes, every other route of the same subject — an env-routedunix://orudp://connect (LOTUS_BUS_CONFIG) — sends the bytes the program published: asendthat publishes, or parks while another publish runs on its thread, cannot change what the routes after it see (GH #1058). -
shm_ring("/name", slot_count: N, on_overflow: <policy>)— POSIX SHM ring substrate backing the zero-copy route. Name is the shm_open object name, at most 31 bytes with its leading/(macOS’sPSHMNAMLEN; Linux allows 255, and the check holds every program to the smaller limit, so a seed builds on both): a longer name is a type error at the binding, where it failed the open at startup until GH #2030. slot_count defaults to 128 when not specified.on_overflowis REQUIRED — see “Back-pressure” below. Satisfiesintra_machineandzero_copyconstraints intrinsically. Slot size is derived at codegen from the topic’s payload type, which must satisfyis_flat_shapeable(§ “Payload-shape compatibility” below) on every native ring, whether or not the binding sayswhere zero_copyor carries acodec(...)clause (the native publish never calls its encoder): the publish copies the payload’s bytes into the slot, so aStringfield would cross as a pointer into the publisher’s arena. A binding whose payload is not flat is a type error at the binding (“`Notes: shm_ring(…)`: topic `Notes`’s payload `Note` is not flat-shapeable: …”); until GH #2030 only azero_copybinding was held to it. Variable data travels on aunix(...)binding, or as aBytesViewraw frame on alayout:ring. Substrate-provided: the runtime’slotus_shm_ring_*primitives inruntime/lotus_shm_ring.cown the lifecycle.At codegen, each shm_ring binding emits a
lotus_bus_register_shm_ring(subject, slot_size, slot_count, name)call into main’s prelude (alongside the existinglotus_bus_register_remotefor unix bindings). SubsequentTopic <- value(Send) statements on the bound topic short-circuit tolotus_bus_publish_shm_ring(subject, &value, sizeof(value))— the C runtime owns claim + memcpy + commit. This is the one-memcpy path: 1.6x faster than the m28b two-memcpy baseline perexperiments/k2-zero-copy/bench.c.Explicit
let slot = topic.claim(); slot.field = ...; slot.commit();surface (the slot-as-locus design in [[slot-locus-design]]) for the zero-memcpy path is post-v1; the implicit<-path covers the common case.Subscribers (Form K6b). Hale-side
bus subscribefor shm_ring-bound topics is wired. Codegen emits alotus_bus_register_subscriber_shm_ring(...)call at the subscriber locus’s birth lifecycle; the C runtime opens the ring, spawns a dedicated reader thread per binding, and dispatches each newly-committed slot to the user’sfn on_foo(p: T)handler withppointing directly into the ring slot (no memcpy on the subscriber side).Batch / drain dispatch (
Drain<T>). The dispatch mode is selected by the handler’s PARAMETER TYPE, using the samesubscribe Topic as on_x;keyword:fn on_x(t: T)— per-record (above). The reader thread calls the handler once per committed slot.fn on_x(feed: Drain<T>)— BATCH. The reader thread calls the handler ONCE per available batch, passing aDrain<T>handle. The handler consumes the batch with an inlinefor t in feed { ... }loop — there is NO per-record function call, and no per-call handler arena scratch. This is the throughput path for high-rate cross-process feeds, where the per-record call + scratch overhead is what loses to a bare consumer loop.
Drain<T>is a built-in 1-arg type constructor (not a user generic). It is only spellable as a batch handler’s single param and as the iterable offor t in feed; the loop bindstto each record read zero-copy through the ring slot —t.fieldaccesses GEP directly into the mapped slot, exactly like the per-record handler’s payload param. A batch handler registers throughlotus_bus_register_subscriber_shm_ring_batch(...)(which spawnsshm_ring_batch_reader_thread) instead of the per-record registration; the handle’s runtime ABI is{ void* ring, int64_t start_seqno, int64_t end_seqno }. The consumer cursor is release-stored once per batch (not per record). Batch handlers on alayout:-bound (foreign) ring are not supported yet — use a per-record handler there.Threading constraint. The handler runs on the reader thread, NOT the cooperative scheduler. Handlers must be thread-safe and avoid touching shared scheduler state. Users who need cooperative dispatch should use
unix(...)instead. Future versions may add an optional cooperative-queue routing mode at the binding level.Staleness. v1 ships without a stamped-epoch read guard — handlers must finish fast enough that the ring doesn’t wrap past the slot they’re reading. If a slot has wrapped at the moment the reader thread fetches it, the slot is skipped silently (lotus_shm_ring_read_slot returns NULL). Post-v1 work will generalize F.30b’s stamped-epoch guard for per-field read checks.
Back-pressure (Form K7).
on_overflow:is required on every shm_ring binding — there’s intentionally no default. Three policies:block— publisher’sclaim()spins with 100µs nanosleeps until the consumer’s release-storedconsumer_seqnoadvances enough for a free slot. No timeout in v1; deadlocks if the consumer dies. Right for control-plane topics where latency tolerates backpressure but data must not be lost. When the consumer is a reader of this process, the wait is one only teardown ends: the reader runs until the teardown spine’s reader stop, after the pool join (a pool’s job publishing onto the ring finishes against it), and a claim still waiting once it has stopped ends like an abortedor wait— the publish is not a success and raisesBusWaitAborted(a producer on a pinned thread, joined after the reader stop, can meet this). A claim on a ring another process consumes waits for that consumer.drop— publisher’sclaim()returns the next slot unconditionally (pre-K7 behavior). Slow consumers silently miss messages. Right for stale-is-worthless feeds (market data tickers, telemetry).fail— publisher’sclaim()returns NULL when the ring is full; thepublish_shm_ringwrapper panics with a clear stderr diagnostic and_exit(1). Process-level visibility into back-pressure events. Graceful caller-side handling via fallible-<-is a K7b follow-up; today, fail = process exits.
The consumer’s reader thread release-stores the cursor after each batch of dispatches; the cursor lives on its own cache line (separate from the producer’s
seqno) so the two sides don’t pingpong each other’s writes.Birth-order trap (single-binary +
block). Hale births child loci inparams-declaration order. In a single-binary deployment where a Producer’sbirth()immediately publishes onto ablock-policy ring, the Consumer locus MUST be declared before the Producer in the parent’sparamsblock — otherwise the Producer’s first overflow blocks on aconsumer_seqnothat no live reader will ever advance, and the process hangs. Order the consumer first, or move the publishing into the main locus’srun(), which does begin after all child births. Moving it into a child’srun()does NOT help: a cooperative child’srun()runs inline during its own birth, before its later siblings are born — see § Birth order is load-bearing. (Cross-binary deployments aren’t affected — the subscriber lives in a different process and exists before the publisher process starts.)
Foreign rings via ring_layout (Proposal B).
The shm_ring transport above reads/writes the native Lotus
ring (the LRSRNG1 header + equal-sized slots). To read a ring
defined by another program — an externally-defined binary
broadcast ring — a ring_layout declaration describes that
ring’s binary shape, and a binding references it with the
layout: kwarg:
ring_layout ForeignRing { magic 0x52494E47464D5431; // expected header magic at offset 0 version 1 at 8 : u32; // header field `version`: expect 1 buffer_size at 12 : u32; // ring data capacity, read from header data_at 128; // first-record byte offset cursor published { // the published byte cursor at 64; repr atomic_u64; load acquire; unit bytes; } framing byte_records { // records are [u32 len][payload] len_prefix u32; align 8; pad_sentinel 0xFFFFFFFF; } overflow lap_detect;}
main locus App { bindings { Ticks: shm_ring("/foreign.ticks", on_overflow: drop, layout: ForeignRing) where zero_copy; }}The layout: reference must resolve to a declared ring_layout
(else a typecheck diagnostic). A binding with no layout: is the
native ring, unchanged.
Record headers (record_header_bytes). The default byte_records
shape is [len_prefix][payload] — the prefix is the whole per-record
overhead. A real foreign producer often prepends a fixed header
(sequence number, kernel timestamps, opcode) before the payload. Set
record_header_bytes N on the byte_records framing to describe it:
the payload then starts N bytes into the record and the stride is
N + align(len) (the len field is still read at record offset 0 with
len_prefix). N must be a multiple of align. A producer that marks
a tail pad with a header field rather than a len sentinel (e.g. a
kind byte where 1 means padding) declares
pad_field_offset / pad_field_width / pad_field_value; a record
whose field equals that value is skipped to the wrap. The in-band
header scalars are surfaced to the handler by declaring their offsets
(seq_offset / seq_width, kernel_ns_offset / kernel_ns_width,
user_ns_offset / user_ns_width): the reader decodes them per record
into thread-locals the subscribe handler reads via
std::shm::last_record_{seq, kernel_ns, user_ns}() — the errno-style
idiom of recv_stamped’s last_recv_*_ns. The payload itself is still
delivered as the BytesView / typed value.
recheck post_copy adds a torn-read guard: each record is copied out,
an acquire fence taken, and the cursor re-read; if a free-running
producer lapped the record during the copy it is discarded rather than
handed to the handler.
Slot rings (framing slots). The example above is a variable-length
byte_records ring. A slots framing describes a fixed-stride slot
ring instead — the shape of the native Lotus ring itself. The geometry
(slot_size, slot_count) is read from the foreign header rather than
fixed in the layout, the cursor is the published seqno (1-based; unit slots), and slot S lives at data_at + (S mod slot_count) × slot_size. A consumer skips a seqno the producer has already lapped
(published − S ≥ slot_count) rather than read a torn slot — matching
the native reader. This makes the native LRSRNG1 ring expressible as a
ring_layout, read through the same abstraction as a foreign one:
ring_layout LotusRing { magic 0x4C5253524E4731; // "LRSRNG1" slot_size at 8 : u64; // geometry read from the header slot_count at 16 : u64; data_at 128; // first slot (after the 2-cache-line header) cursor published { at 24; repr atomic_u64; load acquire; unit slots; } framing slots { } overflow lap_detect;}The producer side for a foreign slots ring (a Hale writer) is not yet
offered; slots is a consumer framing at this version.
The layout contract. A ring_layout is validated at typecheck
(hale-types::check), so a malformed layout fails the build, not
the read. The rules:
- Each scalar
reprmust be a known fixed width —u8/u16/u32/u64,i8/i16/i32/i64,f32/f64. - A
cursorblock needs anatoffset, a knownrepr(atomic_u64), a knownloadmemory ordering (relaxed/acquire/release/acq_rel/seq_cst), and aunitofbytesorslots. At least one cursor is required. framingkind isbyte_recordsorslots.byte_recordsrequires alen_prefix(and reads capacity from abuffer_sizescalar);slotsrequiresslot_sizeandslot_countscalars (the consumer reads the slot geometry from the foreign header, and derives capacity as their product).- All offsets are non-negative.
- A
ring_layoutis a declaration, not a value — referencing its name in expression position is an error.
Cross-field conformance. Because the foreign format is fixed and unchangeable, a layout that mis-transcribes it is the program’s own bug — and several of these fields silently corrupt the reader if wrong, so they are caught at compile time:
- Every header scalar and the cursor (an 8-byte atomic) must lie
before
data_at— a field whose[at, at+width)overruns the data region is rejected. - No two header fields (or a field and the cursor) may overlap.
byte_recordsalignmust be a power of two — it is the record-stride alignment the reader masks with.pad_sentinelmust fit in thelen_prefixwidth; otherwise wrap detection reads a truncated value and never fires.len_prefixwidth must be<= align, and a producer’s compile-timebuffer_size:must be a multiple ofalign— else a record header could land in(cap - len_prefix_width, cap)and read or write past the data region.- An
atomic_u64cursor’satmust be 8-byte aligned (an unaligned atomic load is undefined);magic,data_at(forbyte_records), and abuffer_sizescalar must all be present.
Payload conformance at the binding. A layout:-bound topic’s
payload picks the consumer mode:
- A flat-shapeable struct → typed mode: the record is read by a
direct pointer-cast (and, on the producer side, written by a
memcpyof the payload struct — the foreign record bytes are the Hale struct, bindgen-style). The framedlenmust equal the struct’s fixed size or the record is resynced (the OOB guard above). Enforced whether or not the binding also assertswhere zero_copy. - A
BytesView→ raw-frame mode: for heterogeneous / variable-length rings (e.g. a discriminated-union feed). The consumer can’t assume a fixed size, sovalue_sizeis 0 (the size gate is off) and the handler receives a boundedBytesViewover each record — it decodes withstd::bytes::read_*+ a discriminator branch. The framed-size bounds checks against the ring still apply; the record payload is copied into a Bytes-shaped scratch blob (the pack readers need that prefix, and the mapping is read-only), so raw-frame mode is not zero-copy. The producer side is symmetric:Recs <- bytes(aBytesorBytesViewvalue, e.g. built with aBytesBuilder) frames[len_prefix len][bytes]wherelenis the value’s actual byte length, so a producer can emit heterogeneous / variable-width records — the runtime publish path is size-generic. For a zero-copy write,Topic.write(max) { w => ... ; len }reserves up tomaxbytes, binds a writableBytesMutviewwover the slot (written with thestd::bytes::write_*family, the bounds-checked mirror of the readers), and commits the byte count the body’s tail yields — the producer writes record fields directly into the mapped ring with no intermediate buffer. The reserve and commit are scoped to the block, so the view can’t escape and the commit can’t be forgotten. - A struct field may carry a Go-style backtick metadata tag after its
type (
price: Intrepr:“u32_le”;) — free-formkey:"value"metadata stored on the field. Arepr:"<wire-type>"key makes the struct a binary layout:Type::field(v)reads that field from aBytes/BytesViewandType::set_field(w, x)writes it into aBytesMut, at the field’s offset (computed in declaration order over the tagged fields, or pinned with,at=N). These desugar to the matchingstd::bytes::read_*/write_*call, so they share the primitives’ bounds-checking and cost. - A
json:"<key>"tag is the second tag consumer: a struct with at least onejson:tag gets a generatedType::from_json(s) -> Type fallible(JsonError)that parses the object in a single pass (driving thestd::jsonobject cursor), dispatching each key to the matching field and reading the value by the field’s declared type. A field is what the api surface’s JSON codec carries of one (spec/api.md § Codecs): a scalar (Int/Float/Bool/String/Decimal<S>/U64/U256/I256, aU64or a 256-bit integer as a JSON string of its decimal digits or0xhex, or an integer number that fits), a scalar of the unit dialect as the integer it counts (anInt, or aU64as aU64is, GH #2131), aTimeas its RFC 3339 text, aDurationas its nanoseconds, astd::json::Valueas its text, an enum (a payload-free variant as its name in a JSON string,"Buy", one with values as the api codec writes it,{"Circle": 1.5}; a name no variant has is the field’sJsonError { kind: "wrong_type", field }), a record of the same seed (the nested object’s raw text is handed to that record’s own generated codec, whether or not it declares ajson:tag itself; a nested failure propagates), and abounded[T; N]or[T; N]of any of those as a JSON array (more elements thanNistoo_long, fewer than a fixed array’stoo_short; an absentboundedfield is empty), and a map of records (bounded[T; N] indexed_by <key>, GH #1944) as the api codec carries one, an object keyed by each record’s key. ADecimal<S>field is a JSON number, or a JSON string holding one ("97000.50"; 2026-11-14, downstream handoff), read at the field’s scale, every digit kept and no float on the way, an exponent applied exactly (1e-7,1.50E+1; 2026-11-07, downstream handoff); a number with a nonzero digit past the scale, one whose mantissa no i128 holds, a spelling that is no JSON number (+1,.5,1.,01, or a string holding one of those, a space or an escape), or not a number isJsonError { kind: "wrong_type", field }, never truncated or read as zero (spec/types.md § Decimal, spec/api.md § Codecs). The key is the tag value before its first comma (so a key holds no comma), else the field name (a tag of options alone,json:",string", keeps the name); the options arestring, on aDecimal<S>field or a list of them, whichto_jsonwrites as a JSON string of the digits ("97000.5"), andhex(GH #1934), on anInt,U64,U256orI256field or a list of them, whichto_jsonwrites as0xand lowercase hex digits in a JSON string ("0x4dc"; a negativeIntas its JSON number) and with which anIntfield also reads0xhex text (aU64or a 256-bit field reads decimal or hex text either way); any other option, or an option on a field it is not for, is refused at the field. Unmatched keys (and nested objects/arrays under them) are skipped. A record marked@positional(@positional type Candle { t: Int; close: Decimal<2>; }) has the codec without a tag and crosses as an array of its fields in declaration order ([1688666400, "3005.5"]), a field or a list’s element of it too; its rules are the api codec’s (spec/api.md § Codecs, Positional records): an element past the last field is skipped, a field the row ends before is absent (its default, ormissing_fieldnaming<Type>.<field>), and its fields’ tags name no key. A missing field raisesJsonError { kind: "missing_field", field }unless the field declares a default, which fills it: a literal (= "USD",= -1), an enum variant (= Side::Buy), a record literal (= Instrument { sym: "Y", tick: 2 }, its own fields’ defaults filling what it leaves out), or any expression a field default may be; the codec builds it when the key is absent, exactly as the record’s own literal would. A key sent asnullis a key absent (2026-11-07, downstream handoff): the field takes that same default, whatever its shape, or ismissing_fieldwith none, and anullafter a value leaves nothing of it (the last of a key sent twice wins); astd::json::Valuefield alone holdsnullas its text.from_jsonisfallible, so callers must address it. The same tags drive emit:Type::to_json(v) -> Stringserializes a value back (bare numbers/bools, a Decimal’s exact digits at its scale (in a string where its tag saysstring), escaped strings, an enum’s variant name, nested structs and lists recursed), round-tripping withfrom_json; it is not fallible. The check is the gate: a tagged struct with a field the codec does not carry (Bytes, an unbounded[T], a tuple, a record of another seed), in it or in a record or an enum it reaches, has no codec, and the call is refused naming the field (“Export::from_json:Exporthas a fieldraw: Bytes, which the JSON codec does not carry”), asT::from_jsonof a record with nojson:tag is (“Plain::from_json:Plaindeclares nojson:field tag, which is what gives a record its JSON codec; tag a field,id: Intjson:“id”;“), of an enum, and a call of another arity; a program the check admits builds. Through an import the call names the library’s declaration as a construction through an import does (pricing::Observation::from_json(text),pricing::Observation::to_json(v)), and the library’s ownObservation::to_jsonis the same codec. An unbounded[T]is not a field’s: Hale sequences are locus-owned (there is no heap-owning value collection), so a JSON array of unknown length is read by walking the array cursor and pushing into a@form(vec)locus cell (seenotes/value-collections.md). Further tag keys remain reserved for future consumers (validation, db mapping). - An enum’s variant takes the same backtick tag after its values (GH
#1951 item 5):
Sell `json:"sell"`,Fill(Int) `json:"fill"`,Other(String) `json:",other"`. Itsjson:key renames the variant on the JSON wire, infrom_json/to_jsonand the api codecs alike: a payload-free variant is written and read as the name ("sell"), one with values is the key of the object that holds them ({"fill": 3}), and the declared name is no longer read. The one option isother, which makes the variant the enum’s catch-all: a JSON string that names no payload-free variant decodes to it, keeping the string when it holds oneString(lossless, and it writes that string back) or only that the string was unknown when it is payload-free (lossy, and it writes its own wire name); an unknown object key stayswrong_type. The check refuses, each at the variant: two variants with one wire name, a second catch-all, a catch-all holding anything but oneString, a wire name on a lossless catch-all (it writes what it holds), and any option butother. A set’s member (type S = A | B;) takes no tag: a tag after one is a parse error. Other keys of a variant’s tag are ignored, as a field’s are (spec/api.md § Codecs has the wire, the description and the protobuf rules).
Any other payload (with String, Bytes, or variable-size fields and
not itself BytesView) is rejected.
Out-of-bounds safety. The guarantee is that a wrong layout — or a
non-conforming / hostile foreign producer — yields wrong values,
never an out-of-bounds access. It holds given the checks above
plus the runtime’s boundary defenses: the consumer rejects, at
attach, a foreign buffer_size that isn’t a multiple of align;
each record’s len-prefix read is clamped within the data region; and
the framed len must equal the bound payload’s fixed size before the
handler is invoked (a short record is resynced, never dispatched), so
the handler cannot read past a record near the wrap. The bound checks
are overflow-safe against a hostile len or offset.
The member token positions (acquire, atomic_u64, bytes, and
words that collide with keywords like release) are layout
words, not Hale type expressions — bare identifiers (or
keyword-spelled words) checked against the sets above, never
resolved as types.
Consumer (read). A subscriber on a layout-bound topic registers
via lotus_bus_register_subscriber_shm_ring_layout(subject, name, desc, self, handler), where desc is a flat 16-entry descriptor
codegen builds from the resolved layout. The runtime attaches the
foreign segment read-only (it never creates it — the foreign
producer owns the ring), validates the magic and version, reads
buffer_size for the data-region capacity, then runs a
byte_records reader thread: acquire-load the published byte
cursor, and for each record walk data_at + local % capacity,
read the len_prefix, skip a pad_sentinel tail-pad to the wrap,
hand the payload view to the handler, and advance by
align_up(len_prefix + len, align). Field roles are read by
convention from the layout — a scalar named version (with an
expected value) is the version check; one named buffer_size is
the capacity source.
Producer (write). If the bundle publishes a layout-bound topic,
it is the ring’s single producer (SPMC): the prelude CREATES the
segment via lotus_bus_register_shm_ring_layout(subject, name, desc, capacity) — sizing it data_at + capacity, writing the
header (magic, version, buffer_size = capacity) and zeroing the
cursor — and each Topic <- value routes through
lotus_bus_publish_shm_ring_layout, the exact inverse of the
reader: reserve align_up(len_prefix + payload, align), write a
pad_sentinel and wrap if the record would straddle the end, write
the length prefix + a memcpy of the (flat) payload, then
release-store the cursor. Capacity comes from the binding’s
buffer_size: kwarg (bytes; a per-transport default applies when
omitted). A layout binding that is only subscribed in this bundle
creates nothing — it attaches the foreign producer’s ring.
Limitations (v1). A subscriber reads records published after
it attaches (no historical replay): it starts at the producer’s
cursor as it stands when the subscription is registered, so every
record published after that is delivered, however late the reader
thread first runs; a record published before it is not. Lap
handling is lossy + safe: if the producer runs more than capacity
bytes ahead, the missed bytes are gone, so the reader resyncs to the
producer’s cursor (a commit boundary) and resumes rather than
reading a torn record. Handlers run on the reader thread (same
constraint as the native subscriber), so the readers stop at the
teardown spine’s reader stop (spec/runtime.md § Lifecycle
obligations, line 7): after the wait-abort and the cooperative pools’
join (a pool’s job still publishing finishes against a live reader),
and before the pinned joins and the dissolve cascade. A handler in
flight finishes, what was published when a reader stops is
delivered, and a record published after that is not (a main locus
built as a statement with no run() is torn down at once, and its
subscribers with it). The slots (fixed-stride)
framing kind ships for consumers, and the zero-copy writable
producer view ships as Topic.write(max) { w => … } (A1 — fields
written directly into the reserved slot, no intermediate copy). What
remains post-v1: a slots producer with parameterized slot
geometry, and multi-cursor back-pressure.
In-memory delivery is absence-of-entry. A topic with no
binding entry is delivered same-process via the cooperative
queue. There is no in_memory variant — the runtime default
covers the case and explicit syntax would be ceremony.
Operational constraints (Form K). A binding
entry may carry an optional where clause listing
constraint keywords the dev team asserts the route must
satisfy:
bindings { L2Updates: unix("/sock") where intra_machine, zero_copy;}Constraints split into two orthogonal axes:
- Scope — where the bus may reach.
intra_process(same OS process),intra_machine(cross-process, same machine; SHM-capable),cross_machine(network in scope). Hierarchy:intra_process ⊂ intra_machine ⊂ cross_machine. - Behavior —
zero_copy(no memcpy at locus boundary; requires the payload type to satisfyis_flat_shapeable).
The typechecker validates three classes of constraint issue (Form K4a):
-
Intra-constraint consistency. At most one scope keyword per binding (
intra_machine+intra_processis rejected as ambiguous).zero_copy+cross_machineis rejected as a contradiction — network transports require serialization. -
Transport-constraint compatibility. Each declared constraint is checked against the binding’s transport variant:
unix(...)satisfiesintra_machine. Rejectsintra_process(sockets cross processes),cross_machine(AF_UNIX is host-local), andzero_copy(kernel memcpy at the socket boundary).- Adapter loci: trusted for scope constraints (the adapter
body knows where its protocol routes). Rejected for
zero_copy— the Adapter contract (fn send(subject, bytes)) requires serialization.
-
Payload-shape compatibility.
zero_copyrequires the topic’s payload to satisfyis_flat_shapeable: its bytes are the whole value, so a raw memcpy of it is the value on the other side. Flat are the fixed-layout primitives (Int,Float,Decimal,Bool,Time,Duration), a struct whose fields are all flat, an identity or a range (its integer), and a fixed-size array ofInt,Float,Bool,DecimalorDuration(and abounded[T; N]of those): codegen lays a scalar-element[T; N]field out inline in its struct ([N x T], since 2026-07-01), so its elements travel in the slot. Not flat:String,Bytes,BytesViewandStringView(heap-shaped or fat pointers); a fixed-size array of anything else ([P; 2]of a struct,[Time; 2]), which keeps the out-of-line layout, a pointer that would dangle across the zero-copy / shm boundary; an unbounded array[T]; a tuple (a pointer to its block); aboundedlist of strings, bytes, records or enums; and an enum. The bus wire carries all of these (§ Payload type); a raw copy does not. The binding is refused at typecheck, at itszero_copy, rather than compiled into a cross-process use-after-free: “binding for topicTArequireszero_copybut payload typePayAis not flat-shapeable — it contains a String, Bytes, fixed-size array, tuple, enum or list-of-pointers field, …”. A nativeshm_ringbinding is held to the same rule withoutzero_copy(GH #2030). Send variable data on aunix(...)binding, or as alayout:-boundBytesViewraw frame.
The shm_ring(...) transport variant above satisfies zero_copy
(and intra_machine) intrinsically; its slot size is derived from
the payload’s flat layout. Existing bindings without a where
clause continue to work unchanged.
The entry locus. A program’s entry is its seed’s own main locus; the checker reads it from one row (hale_types::entry, the
registry’s entrypoint family) for rule 1’s count and rule 9’s closed
world, and --env and --matrix read the same row for what an
entrypoint is. An imported main locus — a library’s, renamed
with its seed — is not the entry (F.40 phase 3, E0): it is a
declaration the importing seed does not run. A seed whose only main locus is imported has no entry and checks as a seed with no main
does: the library’s placement seeds nothing, and the world is not
closed.
With more than one candidate (rule 1’s error) the checker reads the last.
The build deploys the entry and nothing else (F.40 phase 3, L4): its
placement, its bindings, its pinned threads. The placement-safety
rules (the pool map behind the cross-pool method call error,
spec/types.md § “Single-threaded-method invariant (F.31)”, the
pinned-in-a-loop rule, placement rule 17, the instance-aliasing
warning, one locus shared by two of the root’s fields placed apart,
#334, which reads where each field runs from the placement table, and
the async_io advisory, spec/verification.md § “Placement-implied
contracts”) judge the entry. The api binding is generated into the
entry, and the editor’s hale/placement view and the model’s
entrypoint name it (main when there is none, as for a seed whose
only main locus is imported).
The entry is started by the seed’s top-level fn main, which
instantiates it; a main locus does not start itself. A seed that
declares its own top-level main locus and no fn main has nothing
that starts the locus, so hale check, the editor, hale build, hale run and hale test refuse it with one located error at the locus’s
name (until GH #2108 hale check accepted it and only the build
refused it; until 2026-10-14 the build’s error was the spanless
program has no fn main()). It is one of the rules a build refuses
beside the check (hale_types::build_rule_diags, which hale check
runs too), not an error of the typing, so the seed still denotes its
model and its laws are judged while its fn main is missing:
main.hl:1:12: type error: a `main locus` is started by `fn main`, and this seed has none: add `fn main() { App { }; }`An application another seed imports and starts is checked through
that importer, where its main locus is imported and not the entry.
Checked alone it is a program like any other, and starts its main locus with a fn main of its own; an importer runs its own fn main, never the imported seed’s, which is renamed with its seed.
Two programs start somewhere other than a fn main of their own, and
the rule does not apply to them: a module that @exports, the wasm
entry inversion’s (an export-only module needs no fn main:
spec/ffi.md § “@export — exports”; a native target refuses the
inversion itself), and a *_bench.hl file, which declares no fn main because hale bench appends its driver’s (spec/testing.md). A
*_test.hl file is a program hale test builds as it stands, so the
rule holds there. A seed whose fn main does not instantiate its
main locus checks and builds: the locus is a declaration nothing
runs.
A program with neither says program has no fn main(): a native program starts at its top-level fn main when it is built; it checks
clean, as a library seed does.
Whether a thread runs beside the bus’s main drain, so that the bus
queue takes its lock, is decided from what the build deploys (F.40
phase 3, E2): a domain of the placement table that is not main (a
pinned field, a non-main cooperative pool, an adapter binding, the
api binding’s pool), or an entry of the entry’s bindings { }. An
imported main locus’s placement { } block and bindings { }
start nothing, so a program that imports one keeps the
single-threaded queue.
Bundle-wide rules:
- At most one
mainlocus per bundle, counting the entry program’s own. Amain locusthat arrives throughimportbelongs to the imported seed, not to the entry: it does not count (rule 3), so a program may import a seed that has one and declare its own (GH #1059). Zero is fine — the classic barefn main()shape is still legal. - Each
bindingsentry’s topic must name a declaredtopic. - A topic may appear at most once across the entrypoint’s bindings.
An imported seed’s
main locusis renamed with its seed and its bindings are inert: they bind nothing, count toward nothing here, and do not make a secondmain(GH #1104 piece 5). - Bindings only legal in a
main-modified locus. The parser rejects them in any other locus position. - Every binding’s role must be either explicit (
role:kwarg) or unambiguously inferable from the bus block.
Codegen emits one runtime registration call per binding entry
into fn main’s prelude, right after the bus queue is published:
- Unix bindings call
lotus_bus_register_remote(subject, url, role). - Adapter bindings first instantiate the adapter locus with
program-lifetime allocation (the payload arena, which the
-> LocusRef(L)return path also used before GH #1570), resolve the locus’ssendmethod’s function pointer, then calllotus_bus_register_remote_adapter(subject, self, send_fn). The adapter literal is lowered there, before themainlocus that declares the binding is built, so the checker checks it as an expression of a free fn: noself, no enclosing locus. A read ofselfanywhere in its inits (Remote: Relay { url: self.url }), a statement that acts on an enclosing locus (terminate,violate,<-), an unknown name or a field of the wrong type is refused at check time, where it is written, with the free fn’s diagnostic and why it applies, rather than reaching lowering. Its values are written in the literal or are the adapter’s ownparamsdefaults.
Subjects use the desugared wire form (so a binding for
hierarchical Login registers as "events.login"). Topics with
no binding entry get no register call and stay same-process via
the cooperative queue.
3. Closed-world topology optimization. When a topic has no
binding and the publisher / subscriber relationship is statically
unambiguous, the desugar pass rewrites the publisher’s
Stmt::Send into a direct method call. Two shapes qualify:
- Intra-locus (same-type): publisher locus type == subscriber
locus type. Every Send happens inside an instance of the same
locus that hosts the handler. Rewrite:
Foo <- v→self.handler(v). Delivery to an instance becomes eligible once its birth has completed (runtime.md§ “Lifecycle obligations”, line 6). Lowering guards the receiver’s readiness, including a send in a helper reached frombirth(): a held send is queued to that exact receiver, with its payload retained until delivery. - Intra-tower (parent → child): publisher locus type P has
exactly one direct singleton field (declared in
params { }) whose type names the subscriber locus type S. Every Send in P’s body statically routes to that one child. Rewrite:Foo <- v→self.<field>.handler(v).
Common preconditions for both shapes:
- No
bindings { Topic: ... }entry exists for this topic. - Exactly one locus type publishes the topic.
- Exactly one locus type subscribes the topic.
When eligible, the publish→queue→drain→dispatch path collapses
to a synchronous method call. The subscribe / publish
entries stay declared (still type-check) but the bus runtime
never sees traffic on the optimized subject. This is a pure-perf
rewrite — observable behavior is identical modulo timing
(synchronous instead of cooperative-deferred) — provided
publisher and subscriber share an execution context (see the
placement carve-out below; that condition is what keeps the
rewrite observably transparent), and provided nothing the
publishing thread sent earlier still waits on its own queue:
one publisher’s order holds across topics (runtime.md § “Bus
message router”, “One publisher’s order”), so while such a cell
waits the send is queued to its subscriber behind it, and only
otherwise is it the direct call (2026-10-12: before, TA <- a; TB <- b; ran TB’s rewritten handler ahead of TA’s queued ones).
Out of scope for v1 (fall through to bus dispatch unchanged):
- Multi-hop towers (
Outer → Middle → Leaf). - Plural / vec / capacity-slot children — broadcast semantics don’t match the singleton-rewrite shape.
- Child-publishes-parent-subscribes — needs a parent-reference mechanism that doesn’t exist in v1.
- A parent with multiple direct fields of the subscriber type (ambiguous receiver).
- A child a failure can come from (GH #2028). When the
subscriber of the intra-tower shape declares a
closureor abirth_check, its publishes take the bus. A failure its handler raises is carried out by its handler wrapper, which the direct call bypassed: after the supervisor’srestart(c)neitherbirth()norrun()ran again, and after an absorb the child kept handling the next message. The intra-locus shape stays a direct call, since it reaches that instance alone; a failure its handler raises is carried out right after the call as the handler wrapper would (a held child stops; outside arun()of it, a restart re-runsbirth()andrun()), and a child that failed and was not restarted does not handle what it publishes to itself afterwards. - Bus adapters (GH #1032). A locus named as an adapter in a
bindings { }entry is never the publisher of a rewrite: the runtime calls itssendon the publisher’s thread, so a publish inside it may execute off the adapter’s own thread, and a direct call would run the handler there. Its publishes take the bus, which posts to the adapter’s mailbox. - Off-thread subscribers (F.31 placement). When the
subscriber is a main-locus field placed on a cooperative pool
other than
main, or on a pinned thread, the direct call would run the handler on the publisher’s thread instead of the subscriber’s pool worker — breaking the single-threaded-pool invariant and dropping the pool context that any locus the handler instantiates must inherit (an accept’d child’srun()would otherwise go synchronous, and itssubscribes would register on the global queue rather than the pool). Such publishes stay on the bus dispatch path, which posts to the subscriber’s pool vialotus_coop_pool_post.cooperativewith no pool (orpool = main) keeps the subscriber on the publisher’s thread, so it remains eligible.
A bound topic is never optimized: the binding may publish to remote subscribers that aren’t visible at compile time.
Phase 3: routing keys (v0.1 proposal)
Section titled “Phase 3: routing keys (v0.1 proposal)”Phase 3 extends topic declarations with a per-message routing
key so the bus can shard dispatch by key value at the
(subject, key) granularity, rather than fanning every published
message to every subscriber on the subject. Motivated by a
downstream market-data workload: one
reader thread publishes book frames for N symbols; N per-symbol
loci each want only their own symbol’s frames. Without routing
keys, every BookSignal would receive every L2Data frame and have
to filter in user code — O(N × messages) dispatches; per-symbol
state corruption pressure if filtering is forgotten.
Routing keys are also reusable for any “many similar loci sharing one publisher” pattern (per-tenant request streams, per-account ledger updates, etc.).
Surface — three pieces.
type L2Data { sym_id: Int; // i64 routing key field bids: [BookLevel; 100]; asks: [BookLevel; 100];}
topic MarketL2 { // (1) topic-decl additions payload: L2Data; subject: "market.l2"; keyed_by sym_id; // ← new on_unmatched: swallow; // ← new (default if absent)}
locus BookSignal { params { sym_id: Int = 0; ... } bus { // (2) subscribe-clause filter subscribe MarketL2 as on_l2 where key == self.sym_id; // ← new } fn on_l2(d: L2Data) { /* d.sym_id == self.sym_id, statically */ }}
main locus Ingest { // (3) per-instance bindings params { btc: BookSignal = BookSignal { sym_id: 1 }; eth: BookSignal = BookSignal { sym_id: 2 }; sol: BookSignal = BookSignal { sym_id: 3 }; }}Width is inherited from the keyed_by field’s type. No
separate width annotation. Acceptable field types and their bus
storage at v0.1:
| Field type | Bus storage | Compare cost |
|---|---|---|
Bool |
u64 (zero-extended) | one i64 cmp |
Int |
u64 | one i64 cmp |
Time, Duration |
u64 (ns since epoch) | one i64 cmp |
no-payload enum |
u64 (i32 tag zero-extended) | one i64 cmp |
Decimal |
u128 (i64 pair) | two i64 cmps |
String |
u64 hash + owned copy | one i64 cmp; full compare on hash match |
The bus runtime stores both halves of a u128 uniformly
(key_lo: u64, key_hi: u64) — narrower types zero-extend. Apps
that need compound keys ((sym_id, venue, side)) pack them into
a Decimal field themselves; the language does not bake compound-
key derivation at v0.1.
String keys (2026-07-17) hash-gate the per-entry compare: the
registry stores the subscriber key’s 64-bit hash plus its own
copy of the string (capture-by-value — see “Key stability”
below), the publish site hashes the payload’s keyed_by field,
and only a hash match pays the full string compare, so a
mismatched key still costs one i64 compare per entry. StringView
and Bytes are not key-eligible. Remote fanout is unkeyed for
String keys just as for scalars — no key material crosses a
process boundary. The RECEIVE side of a binding derives the key
instead (2026-09-09, DNA F.12): codegen synthesizes one extractor
per keyed wire subject, the publish site’s exact computation over
the deserialized payload, and every inbound path (unix serve loop,
boot-window flush, UDP reader, adapter inbound) dispatches keyed.
A where key == … subscription therefore means the same thing on
both sides of a socket; before this it received nothing over a
binding. An adapter’s inbound delivery
(std::bus::__local_dispatch(subject, bytes)) carries wire bytes
and no key, so for a keyed subject the runtime decodes the bytes
once — through the binding’s codec(...) when it has one — into an
arena of the delivery’s own, derives the key, and delivers keyed:
matching where key == subscribers and unfiltered ones hear it,
non-matching ones do not, and each subscriber still gets its own
decoded copy (GH #1041). That arena is freed when the delivery
returns and draws its memory from the thread’s chunk pool, so
deriving the key costs no heap allocation in steady state. An unkeyed subject takes the
unkeyed wire path unchanged.
where key == EXPR — what EXPR can be.
The RHS is evaluated at the subscribing locus’s instantiation (the
point where its params defaults are resolved), and the resulting
key value is captured into the bus registry alongside the
handler’s self pointer. v0.1 restricts EXPR to:
- An integer / decimal / string literal:
where key == 42,where key == "lobby" - A const identifier resolving to a scalar of the topic’s key type
- A
self.<field>path read, where<field>is aparams-block field of the subscribing locus (for a String-keyed topic, aStringfield — e.g.where key == self.name) - The bare word
replica(2026-08-12, contextual — only this exact RHS position): the subscribing INSTANCE’s 0-based replica index. Each instance of apinned(..., replicas = K)fan-out registers its own index, so K replicas shard an Int-keyed topic with one subscribe line and K spelled once, in the placement entry; a non-replicated instance is replica 0. Requires an Int-family key (String keys rejected — the index is a number). This is the bridge between the placement scale axis and the delivery axis, built so that placement itself stays semantics-free: the filter is still written on the subscription; the placement only decides how many indices exist.
A where key == … filter of any shape requires a KEYED topic
(2026-08-12): an unkeyed publish never runs the key match, so a
filtered subscriber would silently receive nothing — previously
accepted without a word, now a type error.
Higher-shape expressions (self.a + self.b, method calls in the
filter, cross-locus reads) are reserved for later. The
restriction keeps the static check simple (“EXPR is a let-
bindable expression with no side effects, types to the topic’s
key type”) and avoids surprising semantics at registration time.
Key stability — captured by value at register.
A routing-key subscription captures its key value at the locus’s
instantiation (or restart). The key expression is evaluated once,
when the subscription is registered: at the instance’s
construction, before birth() runs (GH #737). A key a locus
computes in birth() is therefore not the registered one — the
field’s default is — so a key comes in as a param at the literal
(Feed { symbol_id: 7 }); registering the default on purpose stays
valid. hale check warns at an assignment to a keyed field that runs
during birth(): one anywhere in its body (inside an if, a match
arm, a loop or a block) or in a method of the locus’s own that
birth() calls as self.<m>(…), at any depth (GH #2027). The same holds for a subscription a locus imported from
another module declares. Subsequent mutations to fields the
filter expression references do not change which messages the
handler receives. If dynamic re-keying is needed, dissolve and
re-instantiate the locus. The alternative — re-evaluating the
filter on every dispatch — would break the bus’s “register once,
dispatch many” cost model and introduce ordering complexity
against concurrent self mutation; the capture-by-value rule is
the right default, and a re-subscribe API is a follow-up if a
workload demands it.
on_unmatched: V — policy when no subscriber’s key matches.
A keyed publish may find zero subscribers whose where key == X
filter matches the message’s key. Topic-level config picks the
behavior; default is swallow (matches today’s no-subscriber
semantics on unkeyed topics).
on_unmatched: |
Behavior |
|---|---|
swallow (default) |
Drop the message silently. Diag visible only with LOTUS_BUS_LOG_UNMATCHED=1 env var (per-publish stderr line citing subject + key + subscriber counts). |
fail |
Publish becomes a fallible expression. Caller must attach an or disposition: K <- value or raise panics via lotus_root_panic with a BusUnmatchedKey marker; K <- value or discard silently swallows on no-match. The err-payload-carrying dispositions (or handler(err) / or fail <p>) are reserved for v0.2 — they require synthesizing BusUnmatchedKey { subject: String, key_lo: Int, key_hi: Int } as a stdlib type, which is a small follow-up. or <substitute> is permanently rejected: Send produces no value, nothing to substitute. |
fallback |
A catch-unmatched subscriber on the subject — subscribe T as h where key == _ — receives the message. At least one such subscriber is required; cross-module resolve-time check rejects the topic otherwise. The _ sentinel is legal only on fallback topics. |
Static checks at typecheck:
keyed_by FIELD— FIELD must be a declared field of the topic’s payload type; FIELD’s type must be one of the table above; the topic must not also declare akeyed_byvia a parent topic with a different field.where key == EXPR— EXPR’s type must match the topic’s keyed-by field type after width inference.where key == EXPRis forbidden on topics withoutkeyed_by; rejecting prevents silent-no-match bugs from typo’d filters.where key == _is forbidden except on topics withon_unmatched: fallback.failtopics: everyTopic <- valuesend site must carry anordisposition clause (or raise/or discardat v0.1 of the impl;or handler(err)/or fail <p>reserved for v0.2). Theorclause attaches to the Send statement, not the value expression — the parser strips it off the value’sExpr::Orwrapping intoStmt::Send.or_disposition. Conversely, anorclause on a Send to a non-failtopic is rejected.fallbacktopics: at least one program-widewhere key == _subscriber must exist; checked at resolve after import merging.
Routing keys are orthogonal to topic hierarchy (Phase 2): a
parent’s keyed_by and on_unmatched are inherited by children
that don’t override; children may override either independently.
A child topic re-declaring keyed_by must agree with the
parent’s key type (subjects derived from a parent’s wire prefix
share the parent’s key shape — anything else makes dispatch
ambiguous on the wire).
Runtime — lotus_bus_entry_t extension.
The bus router’s subscriber-entry struct
(crates/hale-codegen/runtime/lotus_arena.c, around line 4034)
gains a tri-state filter and a u128 key value:
typedef struct { /* ...existing fields: subject, self_ptr, handler, etc... */ uint8_t key_filter_kind; /* 0 = no filter (receive-all) * 1 = specific key * 2 = catch-unmatched (`_`) */ uint64_t key_lo; /* i64 key, or low half of i128 */ uint64_t key_hi; /* 0 for i64 / narrower types */} lotus_bus_entry_t;Dispatch (lotus_bus_local_dispatch_keyed):
int matched_specific = 0;for (entry in the registration table with matching subject): if (entry.key_filter_kind == 1 && entry.key_lo == msg.key_lo && entry.key_hi == msg.key_hi) { fire(entry); matched_specific = 1; } else if (entry.key_filter_kind == 0) { fire(entry); /* unkeyed receive-all */ }if (!matched_specific) { for (entry in the registration table with matching subject): if (entry.key_filter_kind == 2) fire(entry);}Walk cost is O(N_subscribers_on_subject) for the specific pass,
with a second pass only when there’s no specific match (fallback
case). For workloads with thousands of keyed subscribers per
subject, a per-(subject, key_lo, key_hi) open-addressing index
can be added later — YAGNI until a workload demands.
A registration may come from any thread (the instantiating thread,
a pinned anchor’s thread initializing its subtree, a pool’s worker
initializing a pool root’s), while any thread dispatches. The table
is append-only: a registration appends under a lock, and a dispatch
walks the entries published when the walk began, without one; an
entry registered meanwhile is not in that walk (spec/runtime.md
§ “Bus message router” and lotus_arena.c, inventory row R50).
Two new runtime symbols:
void lotus_bus_register_keyed( const char *subject, void *self, lotus_handler_fn handler, /* ...existing... */, uint8_t key_filter_kind, uint64_t key_lo, uint64_t key_hi);
int lotus_bus_dispatch_keyed( /* returns match count; * `fail` topics check this */ lotus_bus_queue_t *queue, const char *subject, const void *payload, size_t payload_size, uint64_t key_lo, uint64_t key_hi, lotus_serialize_fn serialize_fn);Existing lotus_bus_register / lotus_bus_dispatch stay as
the unkeyed entry points (compat for unkeyed topics).
Backward compatibility. Topics without keyed_by and
subscribers without where key == behave exactly as today —
the new fields default to key_filter_kind = 0 (receive-all)
and the dispatch dispatches uniformly. Existing programs need
no source change to keep working; new programs opt in
per-topic.
v0.2 — err-payload Send dispositions.
On on_unmatched: fail topics, all four or disposition shapes
are now supported:
or raise— no-match panics vialotus_root_panic(v0.1 shape; unchanged).or discard— no-match silently swallowed (v0.1 shape; unchanged).or <expr>— evaluates<expr>for side effects on no-match, witherr: BusUnmatchedKeyin scope. The expression’s value is discarded (Send is statement-level). Canonical use:or log_unmatched(err)— a free fn that takes the err payload and logs / metrics / etc. A block is such an expression,or { println("unmatched: ", err.subject); }, and one that leaves (return) ends the statement there (until GH #2025 the block form checked and the build refused it).
What counts as a match is what the dispatch delivers to: a
specific-key subscriber whose key equals the publish’s, a
String key compared by its text (until GH #2025 the signal
compared a String key’s hash and the publisher’s pointer, so a
delivered publish read as unmatched and or raise panicked); and
an open reservation (runtime.md § “Lifecycle obligations”, line
6), a subscriber of the same static tree still being built, which
takes its key when it claims and is owed what it parked. A cell a
reservation holds for a key no claimant takes is reported on
stderr when the reservation closes.
or fail <payload>— only legal inside an enclosingfallible(E)fn. On no-match, evaluates<payload>(witherr: BusUnmatchedKeyin scope), stores it into the enclosing fn’s err slot, and diverts to the fn’s err-exit path. Symmetric toor failon fallible-method calls.
BusUnmatchedKey is a synthesized stdlib type, injected into
scope when any topic declares on_unmatched: fail. Layout:
type BusUnmatchedKey { subject: String; // wire subject of the failing publish key_lo: Int; // low 64 bits of the unmatched key key_hi: Int; // high 64 bits (0 for i64 keys)}Codegen allocates a fresh BusUnmatchedKey in the current
arena on the no-match branch and binds it as err for the
disposition expression’s lowering. Mirror of the existing
KeyError / IndexError / IoError synthesis pattern.
Out of scope at v0.1 (explicit non-goals):
- Multi-field / tuple
keyed_by(keyed_by (sym_id, side)). Apps that need compound keys pack into aDecimalfield in user code. Eligible for a v0.2 sugar once a workload’s ergonomics surface the friction. - Wildcard key sets (
where key in [1, 2, 3]). - Range predicates (
where key > 100). Equality match is the workload-driven sweet spot; broader predicates would defeat the O(1)-dispatch cost model. - String routing keys. String-equality match defeats the perf goal; only int-shaped scalars at v0.1.
- Method blocks on enums to make enum-typed routing keys ergonomic. Treated as a separable language feature; users at v0.1 use bare Int / Decimal or existing no-payload enums.
- Per-publish key override (publishing with a key value that isn’t derived from the payload field). Tied to the payload’s identity so wire-format consumers see a consistent key.
- Cross-process keyed dispatch (over the remote-fanout path). v0.1 ships keyed dispatch for the intra-process bus only; remote subscribers still fanout per-subject and filter in their own bus router after deserialize.
or <substitute>on Send for SUCCESS-value substitution. Send produces no value to substitute. v0.2’sor <expr>disposition on fail topics is a side-effect handler call (evaluates<expr>witherrin scope, discards the value), not a value substitution.
Send dispositions
Section titled “Send dispositions”A send is refusal-fallible when its topic can refuse it: the topic
declares on_full: fail (with bounded(N): a subscriber at the
topic’s capacity refuses the send, GH #255 phase 2) or
on_unmatched: fail (a keyed send no subscriber’s filter matches
is refused, § “Phase 3: routing keys”). A refusal-fallible send
must carry an or disposition, and only such a send may carry one
(or wait aside, below). Which ones each policy admits (GH #2146):
| topic declares | or raise |
or discard |
or wait |
or <expr> |
or fail <p> |
|---|---|---|---|---|---|
on_full: fail |
yes | yes | yes | no | no |
on_unmatched: fail |
yes | yes | no | yes | yes |
| both | yes | yes | no | no | no |
or raisepanics with the refusal:BusFullat the send site for a full topic, the unmatched-key panic for an unmatched one.or discardproceeds: a subscriber at capacity sheds the newcomer (counted), an unmatched send is dropped.or waitparks the publisher until the drain frees space. A full queue is a transient condition; an unmatched key is not, soor waiton anon_unmatched: failtopic is refused (“or waitis not an unmatched-key disposition”). On a topic with neither policyor waitneeds a declared transport binding (the loss window it outwaits, GH #255 phase 1).or <expr>andor fail <p>binderr: BusUnmatchedKey; theBusFullpayload they would need on a full topic is not wired, so there they are refused with a pointer toor raise,or discardandor wait.
The rule holds whether or not the topic is keyed: an unkeyed
bounded(N); on_full: fail; topic takes or raise and
or discard (until GH #2146 the check read only on_unmatched, so
it asked such a send for a disposition and refused every one but
or wait, while hale build took them). A send with no
disposition to a topic declaring both policies is asked for one
once.
Placement block (F.31)
Section titled “Placement block (F.31)”The placement { } block on main locus controls per-locus
thread placement, parallel to bindings { } for bus topology.
Placement is a deployment seam — same library, different
placement entries, different binary behavior. See
spec/decisions.md § F.31 for the intrinsic-vs-
deployment axis the block sits on, and spec/runtime.md §
“Placement classes” for the runtime semantics.
Syntax
Section titled “Syntax”main locus App { params { gateway_a: Gateway = Gateway { venue: "venue-a" }; gateway_b: Gateway = Gateway { venue: "venue-b" }; metrics: MetricsServer = MetricsServer { port: 9100 }; ui: Renderer = Renderer { }; } placement { gateway_a: pinned(core = 1); gateway_b: pinned(core = 2); metrics: cooperative(pool = io); ui: cooperative(pool = render); // unspecified main-locus params → cooperative(pool = main) }}Type-check rules
Section titled “Type-check rules”These placement/bus rules are part of the broader compile-time verification surface;
spec/verification.mdis the canonical catalog of every static check (with severities and enforcing passes).
-
placement { }ismain locusonly. Any other locus declaringplacement { }is a parse error (same shape asbindings { }). -
Keys reference main-locus
paramsfield names. The key on the left of eachplacement_entrymust match a declaredparamsfield on the enclosingmain locus. Unknown field name → typecheck error pointing at the params block. -
Field values are locus types. A placement entry on a non-locus field (
port: Int,host: String) is a typecheck error — placement applies only to locus instances. An exposure param (web: api::Exposure = api::serve(…), GH #1565) is one, and its row places the exposure’s listener and the connections it starts while the exposure stays withmain, beside the sources it calls: the row iscooperative(pool = X) where async_io, and any other is refused (spec/api.md § Serving). A server locus’s listener runs where the row of the param that holds it places it, when that row hostsasync_io. -
At most one placement entry per field. Duplicate keys are a parse error.
-
Pool names use snake_case Idents. The set of pool names is inferred from
cooperative(pool = X)references across all placement entries in the bundle. Poolmainis always available; it refers to the program’s main OS thread. -
Locus-pinning compatibility. A locus placed
pinnedis subject to the pinned-class restrictions: noaccept(c: Child)accept-method, and no closure whose epoch isbirthordissolve(dissolve is the default when noepochclause is written). Those two epochs fire inside the lifecycle cascade, which the owner’s thread runs and cannot route across the pinned thread; a tick, duration, explicit or inline closure fires on the pinned thread itself and is permitted (a pinned heartbeat withepoch duration, a pinned connection with an inline closure). These restrictions belong to the placement site, not the declaration: the typechecker applies them to every instance that runs pinned — apinnedentry’s field (each of its replicas) and an adapter inline inbindings { }, which has a thread of its own with no entry — and judges the locus the instance realizes (a construction site’s override literal, astd::locus), at the entry’s span. The refusal carries its witness as related locations, in order: the entry that runs the instance pinned (the placement entry, or the binding entry), the declaration the instance realizes, and the member that conflicts (theaccept, or the closure’s assertion). A locus that uses neither feature can be placed either cooperative or pinned at the deployment’s discretion. (F.40 phase 0: until then the rule was stated as “no closure declarations” while lowering refused only birth and dissolve closures; the rule now says what ships, and the typechecker judges it. Phase 3, C7: it is judged over the placement table’s rows, so the adapter, anaccept()with no parameter and a field whose written type the entry walk could not resolve are judged too, and lowering keeps no refusal of its own. Phase 4, W2: the refusal’s message is unchanged, and the witness is new.) -
Dead bus receiver (error). A locus that declares
bus { subscribe ... }, is placedcooperative(pool = X)withX != main(and notwhere async_io), and whoserun()makes a known-blocking stdlib call is rejected. A cooperative locus receives cells only while its pool thread is free to run the dispatch (the cross-process transport reader dispatches into the handler set; the in-process cooperative queue is drained at yield points). A blocking call monopolizes the pool thread, so the dispatch never runs and the subscriber’s handlers never fire. Placement alone is not the condition — an event-driven subscriber that yields (handlers plus atime::sleeploop, orwhere async_io, which parks) receives fine and is not flagged; only the blocking-and-subscribing combination is rejected. A subscription to a topic the locus also publishes is also spared (an intra-locus self-publish→subscribe is devirtualized to a direct call). Fix:pinned(own thread + a mailbox drained at sleep/yield) or keeprun()non-blocking. (Corrected 2026-06-03: an earlier form rejected on placement alone and over-fired on event-driven non-main cooperative subscribers, which receive reliably.) The rule is judged over the bus graph (rule 9): a topic the locus publishes by its declared name and subscribes by its literal subject is one subject under the graph’s canonical key, so that subscription is spared as a self-publish, and the error lists the handlers of the subjects the locus subscribes and does not publish. A subscription whose subject the graph cannot resolve is compared as written. (F.40 phase 3, C4.) -
Blocking syscall on a cooperative pool (warning). A locus placed
cooperative(pool = X)withoutwhere async_iowhoserun()calls a known-blocking stdlib op (tcp/tls recv, accept,process::run/wait) but is not a dead receiver (rule 7) gets a warning (not an error — hale’s only non-fatal diagnostic). A blocking call holds the pool’s OS thread for its whole duration, stalling every other locus scheduled on that pool and the pool’s bus drain. The fix ispinned(its own thread — the prescribed shape for blocking I/O) orcooperative(pool = X) where async_io(parks on I/O readiness). It is a warning rather than an error because a single-purpose blocking server with nothing co-scheduled is legitimate. Detection is interprocedural: it follows the call graph, so arun()that blocks indirectly — through a helper fn or aself.methodit calls (transitively) — is flagged too, with the diagnostic naming the offending call. It remains best-effort at the edges (blocking via a handle method likestream.recv, or across a cross-locusself.field.method()hop, isn’t traced). Note rule 7 (the dead-receiver error) stays direct-call-only — it is not widened onto indirect paths, so the higher-stakes diagnostic keeps its precision. Rules 7 and 8, the pool-starvation warning and the birth-order trap read where each field runs from the placement table: they judge themain locuslowering deploys, the entry (one lowering does not deploy, an imported one, spawns nothing and is not judged), and each field by the locus it realizes, an alias or an imported seed’s qualified path included (a stdlib locus’srun()is judged by the known-long-running list, as before). -
Orphan bus topic (warning). In a closed-world program (one with an entry: the seed’s own
main locus; an imported one is not the entry: “The entry locus”, § “Phase 2: hierarchy, subjects, bindings, closed-world optimization”), a bus subject — a declaredtopicor a literal string — wired to only one end is flagged: published with no subscriber (the cells go nowhere) or subscribed with no publisher (the handler can’t fire), and a declared topic touched by neither is dead wiring. Suppressed when the other end is plausibly external: a transport binding (bindings { T: ... }implies a cross-process peer), a wildcard subscriber/publisher covering the subject (log.**coverslog.app), a cross-seed reference (alias::Foo— the other seed owns the other half), an external ingress — astd::bus::__local_dispatch(subject, bytes)call, the inbound side of an adapter, which publishes the subject its literal names or, computing it (a NATS connection dispatches whatever subject arrives), any subject (friction sweep 2026-10-12) — or the same locus being both publisher and subscriber. (A topic is no longer reachable by a caller because a locus subscribes it: the retired api binding’s lift of this rule went with it, and a served surface reaches handlers, not topics.) The closed- world gate is why this is skipped for library seeds (nomain): their consumers are downstream, out of the bundle. (GH #18 #4.) Rules 9 and 10 and the dead-receiver rule (7) are judged over the bus graph. The graph carries as columns what the walk computed: whether a topic is bound to a transport, whether a subject crosses a seed, whether a subscription is a wildcard, whether an external ingress may deliver on it; rule 9’s closed world is the entry row’s. A subject is compared under the graph’s canonical key, its wire subject (spec/model.md rule 8): a topic published by its declared name and subscribed by its literal subject is one subject, wired at both ends. Where the graph cannot resolve a subject (a topic name no declaration answers, a qualified path through an import the bundle never resolved, an open world), the rule does not fire: an unresolved subject is not a proven orphan, and the row records the hole. The silence is about the orphan judgment, not about admitting the reference: in a whole program a qualified subject that names no declaration is a located “unknown topic” error at the check (spec/projects.md, “An unresolvable qualified name is a located error”), as a local one is. (F.40 phase 3, C4.) -
Bus cycles. An edge
S →(L) Dexists when locusLsubscribes subjectSwith a handler that sends to subjectD. A cycle in this graph is a publish→subscribe→publish loop, and the dispatch model splits it two ways:- A cross-locus cycle (edges from ≥2 loci) hops between loci through the cooperative queue (drained at yield) — it spins the queue / livelocks → warning.
- An intra-locus cycle (every edge in one locus) whose every
send the intra-locus rewrite turns into a direct synchronous
call (rule 7) recurses on one thread without bound → stack
overflow → error. To keep the error precise, only
unconditional sends form intra-locus edges: a
self-republish guarded by an
if/match/loop is a terminating state machine, not unbounded recursion, and is not flagged. (GH #18 #4.) - An intra-locus cycle with a send the rewrite leaves on the bus is carried by the queue like a cross-locus one: each cell is handled at a later drain, so the stack does not grow, and it is the queue’s warning. The rewrite makes a direct call only where its preconditions hold (§ “Phase 2: hierarchy, subjects, bindings, closed-world optimization”, Closed-world topology optimization), and it counts only a subscription by the topic’s declared name, so a topic sent by name and subscribed by its literal subject cycles through the queue. The check reads which sends lowering rewrites from the rewrite’s own relation, keyed by each send’s identity, never from the subjects’ spelling. (F.40 phase 3, C4.)
The graph’s edges are keyed by declaration identity: a handler body belongs to the declaration that wrote it, so two loci of one name have their own edges, and the cycles follow the edges, not the name — a cycle whose edges two declarations of one name wrote is cross-locus, and neither declaration’s intra-locus check sees the other’s edges. An edge joins canonical subjects (rule 9): a send by a topic’s declared name meets a subscription by its literal subject, and a send whose subject the graph cannot resolve (an unresolved path, a computed subject) forms no edge. (F.40 phase 3, C4.)
-
Bus backpressure (warning). A locus that publishes to the bus inside an unbounded
while trueloop carrying no flow-control or exit point — no cooperativeyield, notime::sleep/tickthrottle, no input-pacing blockingrecv, nobreak/return— has no backpressure: it posts cells faster than any subscriber can drain, so the queue and the payload arena grow without bound. A full producer-vs-consumer rate analysis is undecidable, so this is a deliberately narrow structural heuristic (warning): only literalwhile trueloops are considered (boundedfor/while condloops never are), and any flow-control point anywhere in the loop body clears it. (GH #18 #4.) -
Bus subject type-mismatch (error). Every publish/subscribe site addressing the same literal subject string must declare the same
of typepayload — otherwise a subscriber decodes the publisher’s bytes as the wrong type at runtime. A declaredtopicis already unified by its declaration (andof typeis forbidden on topic refs), so this closes the literal-subject gap. Grouping is by exact subject string, which excludes wildcards (log.**andlog.appare different strings, never cross-compared). The fix is to declare atopic(one payload type, fixed in one place) or align theof typeannotations. (GH #18 #4.) -
Empty / degenerate
pinned(cores = …)(error). A cpuset affinity spec that selects no cores is rejected statically: an exclusive range whose upper bound is≤its lower (4..4,8..4), an inclusive range that runs backwards (8..=4), or a set with a duplicated element ({2, 4, 2}). Bounds/elements are integer literals — placement is closed-world — so the selected core list is known at compile time and a spec that reduces to “no cores” (or a redundant one) is an authoring error, not a deploy-box question. Whether the selected cores exist on the target stays best-effort at runtime (out-of-range indices are skipped, exactly aspinned(core = N)degrades on a smaller machine). Linux-only affinity; a no-op on other hosts. (Topology Phase 1a, 2026-07-04.) -
topology { }consistency +pinned(node/l3)resolution (error). The declare-onlytopology { }block is validated statically: NUMAnodeids must be unique; L3-domain names must be globally unique (they’re referenced bypinned(l3 = name)without node qualification); eachcoresspec must be well-formed (rule 13); a core may belong to at most one L3 domain (overlap is ambiguous affinity); and a domain core may not overlap areserved range (reserved cores are held back for the OS / main). Apinned(node = N)/pinned(l3 = name)placement entry must reference a domain the block declares — using either with notopology { }block, or naming an undeclared node/domain, is an error. Resolution is closed-world (ids and domain cores are literals), so the selected core set is known at compile time. Whether those cores exist on the deploy box stays best-effort at runtime. Apinned(node/l3)locus gets thread + memory co-location: its thread is affinity-masked to the domain’s cores (Phase 1a cpuset path) and its arena — including method-scratch sub-regions — ismbind-bound to the node, so its working set lives on the node its thread runs on. Node binding is a rawmbindsyscall (no libnuma dependency), Linux-only and best-effort (falls back to first-touch when the node can’t be honored); non-node arenas are unchanged. (Topology Phase 1b, 2026-07-05.) -
replicas = K(error onK < 1; pinned-only). Apinned(..., replicas = K)entry fans the field into K single-threaded instances — replicaipinned to one core of the affinity set (round-robin), each on its own OS thread.Kmust be>= 1(0/ negative is rejected).replicasis valid only onpinned: K cooperative loci on one pool would share a single thread (not parallel), socooperative(..., replicas = K)is rejected at parse with guidance toward the pinned form. The point is that parallelism comes from more single-threaded units, never a multi-worker pool — each replica is its own single consumer, so the lock-free rings, bus devirtualization, and single-threaded-method guarantee all hold. Replicas compose withnode/l3(each replica’s arena binds to the target node) and are non-addressable (nofield[i]surface; they are bus-subscribing or run-loop workers). All K are joined and dissolved at parent teardown. (Topology Phase 1c, 2026-07-05.) Replicas compose with KEYED DELIVERY viawhere key == replica(2026-08-12) — see the routing-key filter rules. -
Pool affinity (2026-08-12).
cooperative(pool = X, core/cores/node/l3 = …)binds pool X’s worker THREAD to the core set — the same affinity formspinnedtakes, resolved againsttopology { }, same best-effort contract. The pool has one worker, so entries naming one pool must agree: a second entry may name the pool bare (it inherits) but a different affinity is a type error citing both entries. Affinity without a named pool (or on poolmain) is rejected — the main pool is the program’s main thread, whose affinity belongs to the operator. Thread affinity only; pool workers own no arena to node-bind (handler scratch lives in each locus’s own arena). -
A
pinnedplacement forbids a loop (error). A locus whoseplacement { }block pins any field may not be instantiated inside a loop body — awhile/forat any nesting depth, in a free fn, a locus method or a lifecycle hook.pinnedgives its field its own OS thread, spawned during the placing locus’s params-init and joined at the instantiating scope’s exit, and the join record (the deferred-dissolve slot plus the thread handle beside it) is one slot per instantiation site: a second pass over the site overwrites the record of the first, so only the LAST instance is joined and arena-destroyed and every earlier pinned thread is orphaned with its arena still live. Placement names static resources — a core, a NUMA node,replicas = K— one thread per entry for the program’s life, so a per-iteration thread is a category error rather than a reclaim policy to pick.placement { }is main-only (rule 1), so the shape this rejects is the deployment root booted once per iteration, and the placement it reads is the deployment root’s (an importedmain locusis not deployed and pins nothing: “The entry locus”, § “Phase 2: hierarchy, subjects, bindings, closed-world optimization”). The fix is to instantiate it once outside the loop; a loop that calls a fn holding the literal is unaffected and correct (each call joins its own thread at that fn’s exit), and the rule is positional on that literal, so it is not a rule about the whole call graph. The typechecker judges it over the placement table’s constructions of the root (every literal of the root declaration, as resolved, in a fn or locus body), and over the root literals written in another locus’sparamsdefault: such a literal is built wherever a literal of that locus takes the default, so it inherits that literal’s loop, through any depth of defaults, and is rejected at the outermost literal written in a loop (for i in 0..3 { Holder { }; }, whereHolder’s default isApp { }, atHolder { }). A root literal written in a position lowering emits again at every use — aconst’s value (at each read of the const), a type’s field default (at each literal of the type that takes it), a closure’s assertion (at each evaluation of the closure) — or reached throughparamsdefaults from a literal written in one, has no construction the table records, so the position does not let the compiler show the root is built once: when the root pins a field it is rejected outright at that position’s literal, loop or no loop, and the fix is to build it in a locus’sparamsor a fn body. A root literal in an adapter’s inits is built once, by the bindings prelude, and is not judged. Aconstortypewritten in a locus body is refused on its own rule. The test harness’s build, which skips the rest of the check, judges it too, so lowering keeps no refusal of its own. (GH #826, 2026-09-20; F.40 phase 3, C7.) -
Every entry is consumed by exactly one instantiation (error). A placement entry is carried by the locus LITERAL lowered for its field, and by nothing else: the thread class, the cooperative pool and the NUMA node all ride an override that the next
T { }takes. So a placed field whose value arrives any other way — a factory call, a fallible call, a conditional, a reference to an instance somebody else built — leaves the entry untaken, and the next field’s turn through the params-init loop resets it. Nothing is placed and nothing is said. That shape is rejected at the initialiser, with the literal form spelled out. The entry’s value is the init written at the instantiation site when the literal supplies one, and theparamsdefault otherwise, so both spellings are checked — and a default every site overrides is dead text, not a dropped placement. The entry is not applied after the fact because there is nothing left to place: the pinned path does not mark an instance, it spawns a thread that runs the locus’s whole lifecycle — birth,run(), the mailbox loop, drain, dissolve — and a factory’s literal has already run birth andrun()(and registered its subscriptions against the global queue) before the value returns. Scope matches rule 17’s: an imported seed’s main locus is renamed__lib_*, is not the deployment root, and its entries never reach the plan; the instantiation sites judged are every literal of the root declaration as resolved, wherever it is written: the placement table’s constructions of the root (a literal in a fn or locus body), and the literals the table records where no body reaches — another locus’sparamsdefault, at any depth of defaults, a const, a type’s field default — which lowering expands wherever their holder is built (locus Holder { params { app: App = App { w: make_worker() }; } }is rejected atmake_worker()). The root’s own default is live when one of those literals leaves the field to it, or when no literal lowering emits builds the root (no construction, and no such literal whose holder something builds): lowering then builds no root at all, but a library seed checked on its own takes the default, and so does the rule. SoApp { w: Worker { } }inHolder’s default, withHolder { }built, leaves amake_worker()default dead. The test harness’s build, which skips the rest of the check, judges it too, so lowering keeps no refusal of its own. (GH #890, 2026-09-20; F.40 phase 3, C7.) -
Uncarriable bus payload (error). An
of type Tclause on apublish/subscribemust name a type the bus can carry — a usertype, an enum with a payload variant, orBytesView(§ Bus subscription dispatch → Payload type, below, has the full statement of what the wire carries). A primitive, a tuple, an array,bounded[T; N]or a no-payload enum is rejected at the clause’s own span. Before this ruleof type Intchecked clean and could not be lowered: codegen refused the publish (bus send payload must be a user-type or has-payload enum value) and the subscribe (m60 requires a TypeRef, has-payload Enum, or BytesView), unlocated and from another layer. A payload type the bundle cannot resolve — a qualified path into a seed it does not hold, a generic instantiation, a name nothing declares — is left alone: the rule is about what the bus carries, not about which names are in scope. Atopic’spayload:is under the same contract, but the checker does not desugar topics (lowering does), so that half is still diagnosed during lowering. (GH #876, 2026-09-20.) -
Unowned subscriber (error). A locus with bus handlers that is born in another locus’s bus handler — a literal in the body of a
fnthat one of itsbus { subscribe … as h }entries names — must be owned: a handler returns after each message, so a local it binds dissolves at its return, and the subscription could never fire for a later message. A locus with bus handlers is owned: it is the entry’s root, a replica or field of an owned locus, a binding’s instance, or accepted by an ancestor through anacceptedge of the ownership graph. The judgment reads the graph’s edges, which are keyed by declaration identity: anacceptthat names the subscriber’s declaration through an alias, an import path or a generic specialization owns it; a name that merely matches the declaration’s last segment, or its template, does not. When two declarations share a name, the graph orders them by declaration order and the diagnostic names the declaration it judged. Where the graph cannot decide which locus is born, or whether the tower is complete (an unresolved type, an open world), the rule does not fire: unknown ownership is not proven absence, and the row records the hole. An unknown construction path cuts the other way: it proves no owner. A literal in a handler’s body is not the entry’s root, a replica or a binding’s instance, so the rule reads itsacceptedges: the nearest accepting ancestor owns it as it owns any other birth, and a literal assigned to a field ofselfis judged by those edges too, since the graph records no assignment target. An ancestor owns it only if one accepts it on every construction path of the handler’s locus: the paths the placement table records (each instance row under its owner’s declaration; at a template’s top, a literal directly infn main, the root’s construction, the entry’s implicit one or abindings { }adapter, none of which has an ancestor; each dynamic site in a locus’s bodies, or in a free fn, whose callers are not followed), together with the graph’s own edges (a literal in a locus’s bodies or params defaults). A path that reaches no acceptor, a free fn or a hole of the table (a held instance it does not link, a field whose initializer is no literal, a dynamic site of unknown domain) refuses the birth, and the diagnostic names that path: an accepting parent somewhere is no proof that every instance has one. The graph cannot decide in an open world (no entry, so a consumer may complete the tower), for a generic template no declared type specializes, or for a qualified path that names no declaration. A subscriber born inrun(),birth()or a plain method is not judged: it lives for that scope and can receive what is published during it.--allow-unowned-subscriberallows the shape for a program that manages the subscriber’s lifetime another way. (2026-05-29; judged over the ownership graph since F.40 phase 3, C4.)
Single-threaded-method invariant
Section titled “Single-threaded-method invariant”A locus’s methods may be invoked only on the OS thread that owns the locus’s placement’s pool. This is enforced at typecheck via a static call-graph walk starting from each top-level placement entry:
- Seed each placement entry with its pool:
gateway_a→ pinned (own thread),metrics→ cooperative poolio, etc. - For each method call expression
recv.foo(args), determine the receiver’s pool from the receiver’s static type and the surrounding pool context. - Cross-pool direct method calls are rejected with a focused
diagnostic naming both pools and pointing at the
placement { }entries that picked them. - Bus publishes (
Topic <- payload;/"subj" <- payload;) are unrestricted — they route through the substrate’s cross-thread dispatch machinery (the existing m28b condvar+memcpy mailbox path generalized to cooperative pools).
This invariant is the substrate enforcement that makes M:N safe. Without it, multi-pool deployments would silently race on locus arenas (which are unsynchronized bump allocators by design).
A form’s sync discipline
Section titled “A form’s sync discipline”Step 3 has one exemption, and it belongs to the receiver’s form.
Every @form declaration has one resolved row (F.40 phase 3, C1)
that keeps two facts apart:
- Its configuration, what the author wrote: no
sync =argument;sync = none,serialized,stripedorlockfree; or async =argument that names no discipline (sync = fast), which the form check refuses. - Its effective discipline: the written one; for a
@form(hashmap)declared at the top level with nosync =argument, the one sync inference picks from the pools itsset/bump/remove(writers) andget/has/len/key_at/entry_at(readers) are called from — none when one pool calls them,serializedfor at most one writer pool,stripedfor several writer pools when a mutate is hot (inside a loop or anon_handler), elseserialized; none for any other form. The rule is applied per instance: aself.field.set(..)call reaches the caller’s ownfield, from the caller instance’s pool, so two maps each touched by its own owner on its own pool need nothing, and the declaration gets the most synchronized discipline any of its instances needs. One instance two holders share (handed to both byfn main) collects both holders’ pools. An instance the placement table cannot identify (one held through a parameter orself.field, or a literal in a method body whose pools are unknown) is called from a pool apart from every other, never main.
Two questions are asked of the row:
- Is it explicitly configured? Any
sync =argument,noneincluded. Inference runs only over a form that is not, so an author who writessync = nonekeeps the map unsynchronized. - Is it safe for cross-domain access? Its effective
discipline synchronizes:
serialized,stripedorlockfree, written or inferred. A cross-pool method call into a receiver whose form is safe is accepted; any other is rejected by step 3.sync = noneis configured and not safe, so a cross-pool call into async = nonemap is rejected, as one into a map inference left unsynchronized is.
The build lays each map out by the same row: the discipline a
program runs with is its form’s effective one, and no sync =
argument is ever written into the program on the author’s
behalf. Three readers ask whether a form synchronizes as one
question — the depends law (a held form is an input channel
outside the bus graph), the effects contracts (a call into the
form or a locus holding it may take its lock, which @no_block
and @deterministic refuse) and the instance-aliasing rule (a
field behind a discipline is not unsynchronized state) — and they
ask the second question alone. An explicit sync = none is
configured, unsynchronized, and holds no lock: a @no_block
method may read the map, a depends: locus may hold it, and one
instance holding it, reached from two pools, gets the
unsynchronized-state warning.
Nested instantiation
Section titled “Nested instantiation”Loci instantiated nested in another locus’s body (birth /
run / lifecycle methods, let-bound children, or params
fields of non-main loci) inherit their containing tower’s
pool by construction:
main locus App { params { gw: Gateway = Gateway { }; } placement { gw: pinned(core = 1); }}
locus Gateway { params { // Cache instantiated nested in Gateway's params — // inherits Gateway's pool (the pinned thread). No // placement entry is permitted on `cache` at any // main locus. cache: Cache = Cache { }; }}Placement entries on nested fields are a typecheck error — placement is a top-level main-locus surface only. To run a nested locus on a different pool, hoist it to a main-locus sibling.
Default placement
Section titled “Default placement”Main-locus params fields with no explicit placement { }
entry default to cooperative(pool = main). The pre-F.31
shape (: schedule cooperative on every cooperative locus
declaration, with a single shared main thread) is exactly the
behavior a program without any placement { } block
receives. Existing programs that don’t declare placement see
no observable change.
Pool inference
Section titled “Pool inference”The set of cooperative pools is the union of X values
appearing in cooperative(pool = X) references across all
placement entries, plus the implicit main pool. The runtime
spawns one OS worker thread per inferred pool name beyond
main. No threads { } declaration block at v1 — pools are
named purely by use site, and the runtime materializes them
on demand at startup.
Probes
Section titled “Probes”A param of the main locus of type std::observe::Probes (GH #1477,
2026-10-19) asks the runtime to serve the process’s health over HTTP on
its port, every interface:
params { probe_port: Int = 9090; probes: std::observe::Probes = std::observe::Probes { port: self.probe_port };}Since #1565 what the runtime serves is an ordinary param of main,
recognized by its type as a hub and an exposure are; there is no
keyword. The check allows one, on the main locus, built by its default:
a param of the type on another locus, a second one, and a construction
of the main locus that supplies it are refused. Its port is a param
literal’s field, checked as one, and a default reading self.<param>
is a default like any other. Nothing is served, and nothing is sampled,
in a program that declares none.
The param’s birth() starts the probes on a thread of the runtime’s
own, not on a pool or a thread the program places: the probes judge the
program’s pools and its main thread, so they must answer while any of
those is wedged or busy. The param is declared and named like any
other; a placement does not apply to the thread. A port that cannot be
bound fails the start. wasm32 has no threads or sockets and serves
none.
| path | answers |
|---|---|
GET /healthz |
liveness: 200 ok, unless a queue holds work its consumer has not touched for the stall window (main’s queue, each cooperative pool’s; 10 s, LOTUS_PROBES_STALL_MS), then 503 and stalled: <queue> … (main, pool:<name>) |
GET /readyz |
readiness: 503 starting until the main locus’s births are done (its params’ children born, a placed child’s readiness awaited, its bindings open, its boot subscriptions in place, its run() not yet entered), 200 ready from then, 503 draining once the process drains (a signal’s drain or the main locus’s tree drain, self.draining) |
GET /capacity |
application/json: {"ready", "draining", "queues": [{"name", "pending", "capacity", "stalled_ms"}]}, a queue’s cells waiting, the cells it holds before it grows or spills, and how long it has stalled (0 while it moves) |
Any other path is 404, and any method but GET and HEAD is 405;
each connection gets one response and closes. The readings cost the
program nothing on its own paths: once a second the probe thread reads
each queue’s depth and its consumer’s heartbeat (the count every drain
and every cell taken bumps), and a queue is stalled while it holds work
and that count stands still. A pool worker running one long cell with
nothing waiting is not stalled.
Observe backends (GH #1592)
Section titled “Observe backends (GH #1592)”A program is observed through a backend it holds as a param of its main
locus, beside the others, and places with placement { } as any other
(§ Placement block). Nothing is observed unless the
program holds one.
main locus App { params { reg: std::metrics::Registry = std::metrics::Registry { namespace: "app" }; metrics: std::observe::Scrape = std::observe::Scrape { port: 9100 }; } placement { metrics: pinned; }}
fn main() { App { }; }Recognized by its type. The compiler recognizes a backend param by
its type, std::observe::Scrape (metrics) or std::observe::Otlp
(lifecycle events, S4), as it recognizes a hub
(observe_expand, beside hub_expand):
- it numbers it: the default literal carries the param’s number
(
oid), which marks it as the program’s backend; - a construction that supplies the param is refused at the field: its default is the backend;
- a main locus holds one backend of each type; a second is refused at its param;
- the backends’ source (
observe.hl) is appended only to a program that holds one.
Its literal is checked as any param’s default: it may read an earlier
param (port: self.metrics_port) or the environment.
How it runs. Scrape is an ordinary locus whose run() serves a
std::http::Server on its host and port, answering its path.
It runs wherever placement puts it: pinned gives it a thread of its
own; left unplaced it serves on main’s pool, as an unplaced server
does. It is born, drained and torn down as any param of the main locus:
a signal’s drain stops its listener, and main’s run() returning does
not (§ “Drain cascade (whole-process)”).
Otlp is a locus whose run() drains the runtime’s event ring and
sends it to an OpenTelemetry collector until the tree’s drain or a
signal’s (spec/runtime.md § “Observe backends”); holding one turns the
event ring on, and nothing in a program that holds none.
What holding one turns on. Three things, and only in a program that
holds one (a program without it lowers none of them and pays nothing):
every std::metrics::Registry registers in the process-wide series
table the scrape renders, and every handle mirrors its updates there;
restarts and delivered failures are counted; and the runtime counts in
counters-only mode (spec/runtime.md § “Observe backends”).
One port. Scrape’s port is required, and it is a listener of
its own. std::observe::Probes (§ Probes) is a second listener on its
own port and does not serve /metrics, so a deployment that holds both
annotates two ports.
In the topology artifact. Schema 1.21’s observe section lists
each backend param with its endpoint (param, kind, backend, and a
scrape’s host, port and path or an OTLP backend’s endpoint; a field the literal does not write is its
declared default, a value the source computes is null), so a
deployment elaborator renders the scrape annotations without parsing
the source.
A seam (GH #1530, 2026-10-17) stitches a producer whose output is a set to
a consumer whose methods cover it, inside one locus tower. It is a member
of a locus, beside bus, in one of two shapes:
locus Gateway { params { feed: Feed = Feed { }; wire: Wire = Wire { }; desk: Desk = Desk { }; log: Log = Log { }; } seam { self.feed.next() -> self.wire.decode -> self.desk -> self.wire.encode -> self.log.write; or end; }}
locus Counter { params { wire: Wire = Wire { }; desk: Desk = Desk { }; } seam answer(frame: String) -> String { frame -> self.wire.decode -> self.desk -> self.wire.encode; }}The closed flow (no name) has a source, a call of a method of the
locus or of a child that makes the entry value, and ends at a sink, a
method that takes the last value and returns nothing. It is the locus’s
run: while the locus is not draining, it pulls a value from the source
and runs the chain on it; a failing source ends the flow (the source has
ended). A locus with a closed seam declares no run of its own. The
callable form, seam name(x: T) [-> R] { x -> … ; }, is the method
name, which runs the chain on its parameter and returns the last hop’s
value: of R when written (each path’s value flows into it), else of the
one type every path ends in, which is refused when the paths end in more
than one (“declare what it returns, a set holding them all”).
A hop is self.m or self.child.m, one method, or self or
self.child, a locus, where the compiler writes the dispatch: each member
of the incoming set goes to the locus’s method whose one parameter takes
it. A child is a params field holding a locus; a hop on an interface is
refused (its method is not known statically), and so is a hop on a child
that placement puts on another pool than the seam’s (a seam is one
tower; the bus crosses pools).
Coverage is one check applied at every boundary, both ways. At a locus hop, every member of the incoming set (a type that is no set is a set of one) has exactly one eater: a method whose parameter is the member or a set holding it. A member with none is refused, naming the member, what produced it and the locus; one with two names both methods. Methods no member reaches are ordinary methods. At a method hop and at the sink, every incoming member is in the parameter’s set (or is its type), and one that is not is refused by name. A locus hop’s output is the union of the dispatched methods’ results; a method returning nothing ends the chain.
Failures. A hop declared fallible(E) has its failure placed: entering
the chain at the first later hop whose parameter set holds E (so an
Outbound that includes WireError lets encode answer it as a
protocol-level reject); else by the seam’s or end; (the closed flow
ends, as run ends; the callable seam fails with E, declared
fallible(E), and it fails with one type) or or violate NAME; (the
closed flow violates the locus’s closure NAME); a failure placed nowhere
is refused, naming the hop and E. A refused callable seam still declares its
method, from what the seam spells: its parameter, its result when written
(else unknown) and, under or end;, a failure of unknown type. So its
callers check, and the refusal is the seam’s one error.
Lowering. A seam is expanded before the check into the methods it
means, which are then checked as any methods are. The chain is direct
calls, written a path per member: where a set meets a locus hop the
expansion writes a match whose arm for each member runs the rest of the
chain on that member, so a member keeps its static type from the
producer’s return to the sink and no union is built that the program did
not declare. Each hop call is inlined into the seam. Where the seam
splits the set a hop returns, and the split is the result’s one use, the
seam calls the hop’s fused clone: the method lowered a second time
with one more parameter, storage for the set in the seam’s frame. Each
return of the clone deep-copies a member into the caller’s arena as
the member it is, writes it there beside its tag as a constant, and
returns that storage (a value of the whole set is copied out as the set,
then into the storage). Inlined, each return site goes straight to its
arm: the dispatch reads no tag back and switches on none. A program with
no seam has no clone, and a hop whose set the seam hands on whole is
called as written.
A closed flow’s frame is a method of its own, __seam_turn() -> Int (the
source pulled, the chain run), which answers whether the flow goes on,
has ended (the source ended, or or end;) or met a failure routed to
or violate NAME;. The locus’s run calls it while the locus is not
draining, returns when the flow has ended, and violates NAME itself
when the turn says so (a method that returns a value may not violate),
so the violation is the lifecycle’s, as before. What a frame’s hops make
is reclaimed when the turn returns (spec/memory.md), as a callable
seam’s is at its return.
Element chains
Section titled “Element chains”xs.filter(<expr>).count() and xs.filter(<expr>).into(target) are
recognized forms, not values. A chain is rewritten to a single
loop by a post-parse pass, so typecheck and codegen both see an
ordinary while and neither knows chains exist.
self.users.filter(it.active).into(self.actives)it is bound to the current element by the rewrite. Stages fuse: two
filters are one pass, because nothing is produced between them.
Why a form and not a value. A chain that produced something at each step would need either a lazy object or an intermediate collection. Both are sequence values, which need an owner, which reopens arenas and placement — the knot that made composition look like a language-sized change. A recognized form produces nothing at any step, so the question does not arise.
Three properties follow, and they are the contract:
- A chain allocates nothing. It is therefore legal inside
@budget(alloc_per_call = 0)and@hot. A design that returned a new collection would have been illegal in exactly the code Hale exists for. - A chain is eager. A predicate’s effects are attributed to the predicate’s own source position. A lazy chain would execute it at the terminal and the witness path would name the wrong line.
- A chain needs no lambdas. The predicate is an argument position the compiler knows about, not a value, so there is no closure to represent — no capture modes, no escape analysis, no cross-thread question.
Boundary. Elementwise operations fuse. Whole-set operations
(sort_into, reverse_into, group_count_into) cannot — they need
every element before producing any — so they are terminals that
materialize into caller storage: the loop fills (or bumps) a target
the caller owns, and any reordering runs on that target after the
loop. The chain itself still allocates nothing. Over a stream source
(a bus subscription, where the driver is delivery rather than a
loop) they are rejected outright: “needs an end” is a property the
compiler can decide.
A bare method call with no stage (v.count()) is an ordinary form
method, not a chain, and is left alone. A chain over a non-form
receiver fails with the ordinary “no method get” diagnostic.
Vocabulary
Section titled “Vocabulary”Elementwise stages (fuse into the one loop):
| stage | meaning |
|---|---|
filter(pred) |
drop elements where the it-predicate is false |
map(expr) |
rebind the element to the it-expression’s value |
take(n) |
stop the whole chain once n elements have passed this point (2026-08-11) |
skip(n) |
drop the first n elements that reach this point (2026-08-11) |
enumerate() |
bind idx — the 0-based count of elements reaching this stage — in every later stage and the terminal (2026-08-11) |
take and skip count elements arriving at their own position,
so filter(p).skip(2) skips the first two matches, not the first
two source elements; their limits are evaluated once, before the
loop. enumerate is an explicit opt-in stage rather than an
always-bound name so a chain never captures a user’s own idx
local; written after a filter, idx counts the filtered stream.
A min/max key mentioning idx is left unrecognized (the best
element’s key is re-derived from the element at compare time, and
its enumerate count is not recoverable from it — rejecting beats a
silently wrong comparison).
Terminals:
| terminal | result |
|---|---|
count() |
Int |
sum() / sum(seed) |
sum() is Int; sum(seed) seeds the accumulator and the seed is its typed zero — sum(0.0) sums Float elements, sum(100) starts an Int sum at 100 (2026-08-11) |
into(target) |
pushes each surviving (mapped) element |
any(pred?) |
Bool; empty selection ⇒ false (vacuous) |
all(pred) |
Bool; empty selection ⇒ true (vacuous) |
first() |
the first surviving element — fallible on empty |
find(pred?) |
find(p) ≡ filter(p).first() |
min(key?) / max(key?) |
the element with the least/greatest key (min_by_key shape; bare form compares elements) — fallible on empty |
each { … } |
run the block per surviving element |
sort_into(target, cmp?) |
push survivors into the caller’s vec, then reorder it in place — sort() (primitive ordering) or sort_by(cmp) with a named comparator (2026-08-11) |
reverse_into(target) |
push survivors, then swap ends inward on the caller’s vec (2026-08-11) |
group_count_into(target, key?) |
one hashmap bump(key) per survivor — increment-or-init tallying into the caller’s @form(hashmap); the bare form keys on the element itself (2026-08-11) |
Chain sources. A chain rewrites to a loop that fetches each
element through the source’s get(Int) -> T fallible(IndexError),
so answering that name is exactly what makes a form chainable:
| source | accessor |
|---|---|
@form(vec) |
its synthesized get |
@form(hashmap) via .entries |
entry_at, same shape |
[T; N] |
get, over all N slots |
bounded[T; N] |
get, over the live slots (not capacity) |
std::str::split(s, sep), lines(s), words(s) |
a cursor: the source’s own scan (below) |
A cursor source (GH #1995 S2). A text source has no index to get
a part by: finding the ith part again on every turn would make the
chain quadratic. It is the one source that is a cursor instead. The
rewrite recognizes it by its call (std::str:: and the source’s name,
of the source’s arity), and the chain’s loop is the scan § Text sources
describes, moved part by part (hale_syntax::str_sources::scan, which
the for loop’s rewrite uses too), with the part bound as the element
before the stages run. An element-valued terminal (first, find,
min, max) cannot re-fetch its pick through get, so it keeps the
picked part’s offsets in the scan’s view, two Ints, and its value is
that part read through a one-element array’s own get: index 0 when a
part was picked, -1 when none was, the ordinary IndexError. The best
part is never copied out again to be compared: min() and max()
compare each later part with it where it lies in the view, byte by byte
as < compares Strings, and min(key) and max(key) keep the best
part’s key. A key’s type is known only from the first part picked, so
the scan that finds it goes on inside its body, from the same cursor,
with the key bound, and leaves when that inner scan ends. No other
source is a cursor; a form keeps answering get. Unlike every other
source, a text source’s chain allocates, one String per part (the
part itself), so property 1 above holds for it only in the sense that
no intermediate list of the parts exists.
The two type-level collections are a deliberate exception to the
types-have-no-methods axiom, and the only one: their operations are
otherwise grammar intrinsics (at(f, i), count(f)), and at
remains the idiomatic spelling for a direct index. get exists so
the chain source protocol is uniform, and is identical to at in
signature and semantics — on bounded it is at.
The rewrite happens post-parse, before typecheck, so it cannot
dispatch on the source’s type; a form that does not answer get
fails with an ordinary no-method diagnostic at the chain’s site.
A chain over a bounded[T; N] or an array walks it by its type,
however it is reached and whatever it is named: a local, a param, a
record’s or a locus’s field, a path of fields (`o.inner.tags.filter(it
1).count()
). Its element cursor is the collection's ownat, so the effect and allocation analyses read it as that intrinsic (no effect, no allocation) and the chain holds under@no_syscalland@budget( alloc_per_call = 0)(GH #1984)..itemsand.entriesanchor a chain on a form's iteration surface, and the rewrite strips the anchor before any type is known; the receiver's type then decides what it was: a@formlocus, or one that declares the cursor itself, keeps the pseudo-field, and a receiver with a real field of the anchor's name (a record'sitems: bounded[T; N]`) walks that field.
Fallible terminals ride the source’s own get. first / find
/ min / max lower to an index search whose value is
src.get(idx) — an empty result is the ordinary IndexError, so
or raise / or fallback / or handler(err) all apply with no new
error machinery:
let bob = users.find(it.id == want) or User { id: 0, age: 0, name: "?" };let oldest = users.max(it.age) or raise;For the same reason they do not compose with map (the or
fallback would need the mapped type while get yields the source
element): project after the find, on the returned element.
each takes a block, not a lambda. The block is spliced as the
fused loop’s body with it bound — it executes in the enclosing
scope, so there are no capture semantics to define, and break /
continue act on the fused loop (continue advances to the next
element):
users.filter(it.age >= 18).each { total = total + it.age;}Recognition is conservative so user facade methods sharing these
names never get hijacked: with at least one stage, every terminal is
recognized (no ordinary method chain looks like that); stage-less, a
terminal is recognized only when its argument mentions it — which
is unbound outside a chain, so no valid ordinary call can look like
that — or when it is each with a block. Bare xs.sum() /
xs.first() therefore stay ordinary method calls (stage-less first
is just xs.get(0) or …; a stage-less sum can be written
xs.map(it).sum()). A text source is the exception: on
std::str::split / lines / words, every terminal is recognized
with no stage (§ Text sources). On a fixed array or a bounded[T; N], which
has no member of a terminal’s name, the check’s “no field sum on
[Decimal; 2]” says so: an element chain needs a stage before its
terminal, ….map(it).sum(…) (friction sweep 2026-10-12). The
whole-set terminals (sort_into /
reverse_into / group_count_into) are recognized stage-less too:
xs.sort_into(sorted) is their natural spelling, and the compound
*_into names belong to this vocabulary — unlike bare into, no
plausible user facade carries them (2026-08-11).
Every stage and terminal above is recognized only after a .,
so a free fn map(...) / fn first(...) / fn count(...) is
admissible and is called as written. The exceptions are the
names the compiler claims at a BARE call site — sum, prod,
min, max among them — which a free fn may not take; see
tokens.md § Built-in identifiers for the full set,
the rule and the diagnostic. A locus method may still carry any
of them (2026-09-20, GH #863 / GH #880).
Vectorized loops
Section titled “Vectorized loops”@vectorize on a fn (a free fn or a locus method) asserts that every
innermost loop written in its body — each for and while that holds
no loop, an element chain’s loop included — is vectorized by the build’s
optimizer on the build’s target. @vectorize(min_width: N) asks too that
each is vectorized at least N lanes wide (N from 2 to 1024). It
changes nothing the program computes: it asks no transformation of the
optimizer, permits no reordering of Float arithmetic, and overrides
no cost model (spec/decisions.md F.63).
@vectorizefn total(xs: bounded[Int; 1024]) -> Int { let mut s = 0; for x in xs { s = s + x; } return s;}What the check refuses. hale check cannot run the optimizer, so
it refuses what it can see that no target’s vectorizer takes, at the
thing that stops the loop:
- a loop that leaves by a
breakorreturnbesides its own condition (a vectorized loop has one exit;while true { … }with onebreak, which is how an element chain’s loop is written, has one); - a call to a fn with effects (
println, I/O, time, randomness, an allocating fn), an allocation, a locus built and a publish or bus send: each a call into the runtime; - a call to a fn with a loop of its own: inlined, it makes the loop an outer one, which the vectorizer never takes;
- and a
@vectorizefn with no loop at all.
main.hl:6:17: type error: `@vectorize` on `f`: this loop cannot vectorize on any target: it holds a call to `noisy`, which has effects (syscall, stdio). Move it out of the loop, or drop `@vectorize` (spec/semantics.md § Vectorized loops)A fallible step, a text value read in the loop and a call through a fn
value are not refused: each may still vectorize (bounds-check
elimination removes a get … or …’s failure branch, an unchanging text
read is hoisted out of the loop, a fn value known where the fn is
inlined is called directly), so the build answers for them.
What the build checks. What is left depends on the target, and is a build assertion: the build reads what LLVM’s loop vectorizer reported of each loop (its optimization remarks, traced back to the loop through its debug locations; a build that emits no DWARF gives the loops locations for the check alone and strips them before the object is written). A loop it did not vectorize fails the build at the loop, with the target, the reason in the program’s terms and LLVM’s own words:
main.hl:5:5: codegen error: `@vectorize` on `until`: this loop does not vectorize on x86_64-unknown-linux-gnu (x86-64-v3): its trip count is not known when the loop starts (an exit that depends on what the loop computes) (LLVM: could not determine number of loop iterations)The same loop can pass on one target and fail on another. A Float
sum or product keeps its written order (Hale does not reassociate
floating-point arithmetic), so it vectorizes only where the target has
an in-order vector reduction (aarch64) and not where it has none
(x86-64). The cost model decides as well: a 64-bit integer multiply has
no fast vector form on NEON. The assertion holds on the target the
build is for — the host’s CPU by default, --target-cpu, or a cross
target’s (generic) CPU — and a build for another target is judged on
its own.
Where the loop is judged:
-
Only innermost loops are held: an outer loop is never vectorized by LLVM’s loop vectorizer, and may do what it likes between its inner loops.
-
The loop as it is in the optimized program: a
@vectorizefn inlined into its callers is judged in each copy, and every copy must vectorize. A loop the optimizer removed (a trip count it folded, a loop fully unrolled) has nothing left to run scalar and passes, and a fn nothing calls is not built and asserts nothing. -
The assertion is checked where the pipeline vectorizes: at the release optimization level. A dev build (
--dev,HALE_DEV, andhale test, which build at O1), an AddressSanitizer build (which runs no optimization pipeline) and a wasm build (built withoutsimd128) do not check it, andhale buildsays so:note: `@vectorize` was not checked: a dev build (`--dev`, `HALE_DEV`, `hale test`) optimizes at O1, which does not vectorize
Check/build agreement. A program the check accepts that the build
refuses only by this assertion is the target’s answer, not a gap
between them: the check/build parity gate counts such a refusal apart
(Verdict::TargetAssertion in
crates/hale-codegen/tests/parity/gate.rs) and never lists it as a
divergence.
Bus subscription dispatch
Section titled “Bus subscription dispatch”A bus { subscribe SUBJECT as HANDLER of type T; } declaration
wires:
- The runtime registers HANDLER as the receiver for SUBJECT on the bound transport.
- Inbound messages on SUBJECT are decoded as
T, then HANDLER(payload) is invoked. - HANDLER runs in the locus’s scheduler context. It may
call
publish(SUBJECT, msg)to emit responses (subject tobus { publish ... ; }declarations). - HANDLER yields naturally on completion; scheduler returns to other loci.
If HANDLER panics:
- The current message is dropped.
on_failure(self, BusHandlerFailure { subject, payload, err })invoked on the parent if any.- The subscription itself is not removed; future messages continue to dispatch.
Payload type — what a subject may carry
Section titled “Payload type — what a subject may carry”A subject’s payload type — T in of type T, or a topic’s
payload: — must be one of exactly three things:
-
a user
type(type T { ... }); -
an
enumwith at least one variant that carries a payload, which travels as its tag and the variant’s values (below; one whose every value is a scalar or a payload-free enum travels as its storage struct, the bytes it always had); -
BytesView(std::bytes::BytesView), the raw-frame path: the payload is not typed at all, and the handler receives a bounded view over each record. This is how a foreign writer’s ring is consumed. Only a ring with a declared record layout carries raw frames, so a topic of this payload is bound in main’sbindings { }toshm_ring(..., layout: <ring_layout>)(or carried by acodec(...)clause). Subscribed or sent with no such binding, it is rejected at typecheck at the subscribe or the<-; bound to a native ring (nolayout:), at the binding entry:main.hl:3:11: type error: subscribe `Recs`: topic `Recs` declares`payload: BytesView`, the raw-frame path, which only a ring with adeclared record layout carries: there is no serializer for a`BytesView` on any other route. Bind the topic in main's`bindings { }` to that ring, `Recs: shm_ring("/<name>",on_overflow: drop, layout: <ring_layout>);`, or give it a user`type` payload.
A delivery is a serialized struct, so the payload needs a field
layout: of type Int has none, and neither does a tuple, an
array, or a no-payload enum. An of type clause naming one is
rejected at typecheck, at the clause (rule 18 above). A topic
whose payload: names one is rejected at typecheck where it is
delivered: at each subscribe of the topic and each <- to it,
naming the topic’s payload and the repair (wrap it in a user
type). A topic that is declared, or listed publish, and never
subscribed or sent carries nothing and is not judged.
main.hl:3:11: type error: subscribe `Chunk`: topic `Chunk` declares`payload: String`, which the bus cannot carry. A delivery is aserialized struct, so a topic's payload needs a field layout: a user`type`, an enum with a payload variant, or `BytesView` (the raw-framepath). To send one, wrap it in a user `type` and declare the topic's`payload:` as that.Within a payload, every value a type may hold is carried, at
any depth (GH #1951 item 4). Serialize walks the value in declaration
order and deserialize allocates each pointer-shaped value (a string, a
record, a list’s or an array’s element, an enum’s cell, a tuple) in the
lazy global payload arena. The encodings are the wire format’s carriage
table, hale_types::wire_carriage::WIRE_TABLE; the check’s refusal and
the serializer both read it, so the list a refusal prints is the list
the serializer encodes. The format is internal (F.36): Hale talks to
Hale with it, and a foreign peer goes through a codec(...) clause.
Little-endian, nothing between values:
| Value | Wire bytes |
|---|---|
Int, U64, Float, Bool, Duration, Time, a unit type over an Int or a U64 |
8 bytes |
I32 / U32, I16 / U16, I8 / U8 (GH #2132), a unit type over one |
4, 2, 1 bytes |
Decimal |
16 bytes |
U256, I256 |
32 bytes |
| a payload-free enum | its tag, a u32 (the variant’s declaration index) |
String, Bytes |
an i64 length, then its bytes |
| a record | its fields, in declaration order |
bounded[T; N], T a scalar or a payload-free enum |
its inline storage: the i64 count and all N slots |
bounded[T; N], T a String, Bytes, record or enum with payloads |
an i64 count, then that many elements, each as a value of T |
[T; N] |
its N elements (an array of scalars as one block, as before) |
| an enum with payloads | its u32 tag, then the variant’s values in order |
| a tuple | as a record of its elements |
std::json::Value |
its text, as a String |
What no frame can hold stays refused, naming the part and the carried
set: a fn value, a locus handle, a view (BytesView, StringView,
BytesMut as a field), a projection, an array of no fixed length, and a
type that reaches itself (type Node { kids: bounded[Node; 4]; }),
whose frame has no bound. A topic whose payload holds one is rejected
at typecheck where it is delivered, as above (“topic `Ev` declares
`payload: Msg`, whose field `f` is a fn value (`fn(Int) -> Int`),
which the wire format does not carry: a delivery serializes each value,
and carries scalars (…), …, and records of these”). Until
2026-11-16 the check refused an enum with payloads, a tuple, a bounded
of strings, bytes or records and an array of strings as a field, and the
build refused a top-level enum with a String value with no place
(and copied any other pointer value of one as the pointer).
A frame is decoded only as far as it reaches (2026-11-07, downstream
handoff): one shorter than its type’s minimum encoded size (its
fixed fields, length prefixes, list counts and enum tags; the empty
datagram included) is refused before any field is read, and every read
after that — a fixed field, a length prefix, the bytes a String or
Bytes length announces, a list’s count, an enum’s tag, a nested
struct’s or an element’s fields — is held to what remains of the frame
after it, never to the frame’s whole length. A list count below zero or
past the list’s N, and an enum tag past its last variant, are refused
too. A refused frame is dropped by the reader that received it and
counted (dropped_decode in the counters dump), and nothing of the
reader’s previous frame is delivered as part of it. It used to be
that an empty datagram was delivered as a zero-filled record, one
after a valid frame replayed that frame, and a one-byte one delivered
the previous frame with its first byte replaced. The rule is the
transport readers’ (the udp:// and unix:// readers, the
early-ingress flush, the replay injector): a local cell is not a wire
frame. In-process delivery — a publish materialized on the owner’s
thread, a cross-pool create cell — holds the program’s own
serializer’s bytes and is decoded straight through, unchecked, so a
create cell’s dispatch stays one straight-line block (accept, the
children’s push, then birth, in the text’s order). For that reason a
cross-pool spawn’s params keep to the shapes the walk takes without a
loop or a switch: a counted list, an enum’s cell and a tuple are refused
there (lowering_laws::cross_pool_child_shape).
The flat paths are unchanged: a zero_copy binding and a layout:
ring copy the payload’s bytes raw, so every new shape (a counted list,
an enum’s cell, a tuple, an array of strings) is not flat-shapeable and
is refused at the binding, as a String field is; a keyed_by key is
one of the key table’s types.
A literal subject’s of type struct (subscribe "m" as on_m of type M) is held to the same rule, once per payload type, at the first clause
that names it; it reached the build until GH #1942. So is a binding’s
transport: a native shm_ring
holds fixed-size struct slots, so a topic whose payload is an enum is
refused at its entry, and a layout: ring hands its subscriber one
record at a time, so a Drain<T> batch handler on one is refused at
the subscribe.
Size. A delivery is as large as its fields make it, and local
delivery is bounded only by the payload arena (spec/memory.md):
the synthesized serializer honours the cap it is handed — it writes
nothing past it and answers the size the payload needs — and the
runtime serializes a payload past its 64 KiB wire buffer again into
a buffer of that size (GH #1155). A remote transport’s frame is
64 KiB (LOTUS_PAYLOAD_MAX): a payload past it reaches every local
subscriber and is dropped, uncorrected, for every remote one —
there is no fallible-publish path or counter a program can observe
this through yet; the runtime says so on stderr once per subject,
for an operator reading logs, not for the program. A publisher that
must reach a remote peer keeps every payload on that subject under
64 KiB on the wire until this gets a program-visible signal.
Before this fix the serializer overran the buffer, and a reply
carrying a String past 64 KiB died in it.
Closure-test evaluation
Section titled “Closure-test evaluation”For each closure NAME { LEFT ~~ RIGHT within TOL; epoch ... }:
- At each declared epoch boundary, runtime evaluates LEFT and RIGHT in the locus’s scope.
- Computes
|LEFT - RIGHT|. - If
<= TOL: closure passes silently. - If
> TOL: flips the locus’s “exploded” flag; emits a typedClosureViolationevent.
The band is computed in one type: LEFT, RIGHT and TOL are all Int
(a Duration, a Decimal) or all Float. An Int beside a Float
— most often a literal beside mean(self.x), which is a Float, or a
Float beside count(), which is an Int — is
refused by hale check at the Int (“closure `band`: the band is a
`Float` (the other side is one), and its tolerance is an `Int`; …
write it as a `Float`”).
The accumulators sum(…), count() and mean(…) are a closure
assertion’s, sampled once per epoch, and each accumulates one field of
the locus (sum(self.x), mean(self.x)). Outside a closure assertion
they name nothing the build can call, an accumulator over a wider
expression (sum(self.a + self.b)) has no slot to sample, and
prod(…), which the grammar reserves, has no lowering: hale check
refuses each at the accumulator (“`sum(…)` is a closure assertion’s
accumulator …, and is compiled only there”; “hale can’t compile the
`prod(…)` accumulator yet”), where the build refused it after a
passing check (GH #1942). A running product, or a sum of two fields,
is kept in a field the locus updates, and asserted on.
Epoch boundaries:
epoch dissolve(default): fires once, as part of dissolve sequence.epoch tick: fires on each runtime tick (configurable cadence).epoch duration(d): fires everydof monotonic time.epoch birth: fires once, after birth completes.epoch explicit: fires only when the locus’s own code callscheck_closures();— a statement taking no argument, which evaluates everyepoch explicitclosure ofselfat once and routes a violation to the parent’son_failureas the other epochs do (a no-op on a locus with none). There is no per-closure form:epoch_advance(NAME), which this section once named, was never shipped.epoch inline(F.27, v1.x-VIOLATE): never fires automatically; fires only when user code executesviolate NAME;. The closure body has no assertion (no LEFT / RIGHT / TOL to evaluate). See “Inline closure violation” below.
Per-epoch field reset (F.34, v1.x-WINDOWED)
Section titled “Per-epoch field reset (F.34, v1.x-WINDOWED)”A closure paired with epoch duration(N) may declare
resets_per_epoch(field1, field2, ...);. The named locus fields
are zeroed by the runtime after the assertion fires at each
duration boundary. Ordering matters: the assertion sees the
window’s accumulated value; the reset prepares the next window.
closure low_corrupt_rate { self.corrupt_per_min ~~ 0 within 10; epoch duration(1min); resets_per_epoch(corrupt_per_min);}Restrictions enforced at typecheck:
- The closure MUST declare
epoch duration(N). The clause is rejected ontick/birth/dissolve/inline/explicit— other epochs either don’t recur or recur too fast for a rate-budget framing. - Each named field MUST be declared on the enclosing locus and
MUST have numeric type (
Int,U64,Float,Decimal). Booleans, strings, and structs are rejected — zero is not a meaningful reset value for them.
User code increments / decrements the field as the window
accumulates. The closure assertion is the structural contract
(rate bounded by a per-window budget); resets_per_epoch
keeps the substrate honest about which window the counter
belongs to without forcing the user to maintain a last_reset_at
field or a parallel pre-fire hook.
Recovery events (persists_through, resets_on)
Section titled “Recovery events (persists_through, resets_on)”A closure’s accumulators (sum, count, mean) are zeroed when its
locus goes through a recovery event, unless the closure persists
through that event:
closure within_band { sum(self.delta) ~~ 0 within 100; epoch tick; persists_through(quarantine);}The recovery events are a closed alphabet, the recovery statements a
parent applies to a failed child: restart, restart_in_place and
quarantine (a spent restart(c) for N bound quarantines, and is the
quarantine event). The check holds each name a clause writes to it:
- A name outside the alphabet is an error at the name, which names
the alphabet; a misspelling one edit away from an event suggests it
(
verification.md§ Structural & design rules, Recovery event alphabet). dissolveinpersists_through(...)is an error: an accumulator does not outlive its locus’s dissolve, so the clause can mean nothing (Persisting through dissolve).
resets_on(...) states the default. An accumulator resets on every
recovery event its closure does not persist through, whether or not
resets_on names it, so resets_on(E) adds nothing at run time; it
is a statement the check holds to the alphabet like any other, and an
event a closure names in both clauses is an error at the resets_on
name, with the persists_through name as its witness (Contradicting
recovery clauses).
Two warnings say when a clause cannot take effect:
- In a closed world (the program has an entry), an event a closure of
the program’s own seed names that no recovery applies to its locus:
no parent’s
on_failurefor the locus’s type performs it, and no recovery statement outside a handler performs it on a child of that type. A statement’s child is the type the checker gives its receiver, whatever the receiver is (a param, a local, a field of another value, a call’s result); in a generic body, the type each specialization gives it. The witness lists each handler and statement that names the locus, with the events it applies. A library checked alone has no parents, so it is not judged; nor is an imported locus, nor an event some recovery applies to a child the check cannot name (a generic supervisor’s handler’s type parameter, a receiver of a type parameter in a generic body no specialization binds) (Unreached recovery event). persists_through(...)on a closure whose assertion accumulates nothing keeps nothing (Persistence with no accumulator).
Inline closure violation
Section titled “Inline closure violation”(F.27, v1.x-VIOLATE.) Inline closures provide a pull-only
structural-failure channel for locus method bodies that catch a
value error and want to escalate it. The declaration carries no
assertion; the optional captures: clause names locus fields
whose values are snapshotted into the ClosureViolation payload
at fire time.
closure fatal_io { captures: last_error; epoch inline; }violate NAME; (optionally violate NAME with EXPR;) fires the
closure synchronously at the call site:
- Runtime synthesizes a
ClosureViolationvalue carrying:locus,closure— string names of the failing locus and the inline closure (always present).- The captured fields named in the closure’s
captures:clause are NOT materialized on theClosureViolationstruct, which has a fixed shape. The access pattern for captured state is to read the frozen child through the child handle inon_failure(c, err)— see “Reading the audit state” below. - If
with EXPRwas given, EXPR is evaluated for side effects (and to detect typecheck errors on the payload type) but nopayloadfield is materialized on theClosureViolation. - The assertion-shape fields (
left,right,tolerance) are not fields of the struct, anddiffis 0 for an inline violation.
- The locus’s exploded flag is set (same as the auto-epoch path; downstream observers can’t tell from the flag whether the fire was auto-epoch or inline).
- The synthetic
__drain_requestedfield on the locus is set. Readable from user code asself.draining. - The parent’s
on_failure(child, ClosureViolation { ... })handler runs — same routing as for auto-epoch closure violations. - The method exits. In a
fallible(ClosureViolation)fn the violation is the call’s failure: the caller’sordisposition runs, witherrbound to theClosureViolation, and no value is produced. In a fn returning nothing the method exits as areturndoes and the caller continues. The owner’son_failure(step 4) runs first, posted to the owner’s domain and awaited when the pools differ (decision L0-1); then the caller’sordisposition runs. Either way, loci the methodlet-bound dissolve and its per-call scratch is freed (GH #1036;violateused to skip both).
A value-returning method that may violate is fallible
Section titled “A value-returning method that may violate is fallible”(F.42.) A value-returning fn or locus method whose body may
violate is declared fallible(ClosureViolation), so that its
callers say what happens when the locus fails instead of reading a
value nothing computed:
locus Picker { params { picked: Int = 0; } closure exhausted { epoch inline; }
fn take() -> Int fallible(ClosureViolation) { if self.picked >= 3 { violate exhausted; } self.picked = self.picked + 1; return self.picked; }}
// in the owner, which handles Picker's failures:let n = self.p.take() or 7; // 7 once `take` has violatedA fn may violate when its own body holds a violate
statement, or when it calls a value-returning fn that may violate
and is not fallible (a fallible callee is answered at its call
by the bare-call law, below, and once this law holds no other kind
is left). A violation in a method that returns nothing is not the
caller’s failure: calling one does not make the caller one that
may violate. Lifecycle bodies, bus handlers (the fns a subscribe … as names) and fn main are exempt: the runtime is their
caller.
- A value-returning fn that may violate and is not
fallibleis a type error: “`Picker.take` returns a value and may violate (`violate exhausted`): declare it `fallible(ClosureViolation)`; its callers then say what happens when the locus fails”. The parenthesis names the path: the closure aviolatein the body names, or “through `helper`” for a call; the diagnostic’s notes give each location. - A fn that may violate and is declared
fallible(E)with any otherEis a type error: a fn has one error type, and the violation record is the one a violator carries. - A fn returning nothing that may violate and is not
fallibleis a warning with the law’s wording and “This becomes a law in a later release”. Nothing else changes for it.
The call to a fallible(ClosureViolation) method follows the
bare-call law unchanged: an or disposition is required, and the
err that or handler(err), or { … } and or fail see is the
ClosureViolation the owner’s on_failure received. or raise
in a fn that is not fallible ends the process (§ “Process
exit”), which is what a caller says when the activation should not
continue past the locus’s failure. The stdlib’s two such methods
are BytesBuilder.snapshot and finish (a failed allocation
violates alloc_failed, F.27).
Reading the audit state
Section titled “Reading the audit state”The portable access pattern in on_failure(c, err) is to read
the child’s frozen locus state through the child handle:
on_failure(c: Child, err: ClosureViolation) { log::error(err.closure, " ", c.last_error, " fd=", c.conn_fd);}violate is divergent — the method body’s remaining statements
do not execute, so the child’s locus state is frozen at the
violate moment. c.last_error reads exactly the value the
violate site observed.
The ClosureViolation value carries err.locus and
err.closure (Strings) and err.diff (an Int: left - right
for an Int or Duration assertion, 0 otherwise); it does not
materialize the captured fields. Source that reads
err.last_error is a type error at the read (“no field
last_error on ClosureViolation”): read captured state through
the child handle (c.last_error) instead. (Until F.40 phase 4,
S8 the checker left ClosureViolation unresolved, so such a read
passed hale check and failed at build without a location.)
The violate statement is divergent: the typechecker treats it
as Never, the same as fail in fallible fn bodies and
bubble in on_failure. No statement after violate in the
same block is reachable; the typechecker does not require a
trailing return on a violate branch.
birth_check synthesis hook
Section titled “birth_check synthesis hook”(F.27 v2, 2026-05-20.) A declarative form for construction-time invariants:
locus L { params { x: Int = 0; } closure invariant_broken { captures: x; epoch inline; } birth() { /* set up state */ } birth_check { self.x < 0 } -> violate invariant_broken;}After birth() body completes and birth-epoch closures have
fired — at the first birth and at every restart’s re-birth (§
“restart(child)”) — each declared birth_check clause’s cond
expression is evaluated. A true result fires the named closure with the
locus’s fully-constructed state — every field reads its
declared post-birth value, so the on_failure handler’s
capture-snapshot sees coherent state. Multiple clauses evaluate
in declaration order; the first to fire short-circuits the
rest.
Why a separate clause vs. calling violate NAME; inside the
birth body: a violate mid-birth leaves the locus partially
constructed (some fields set, others at defaults) when the
on_failure handler reads captures. birth_check runs the body
to completion before the check fires, so the post-birth invariant
of “every field has its declared value” holds at violation time.
The runtime-routing semantics are otherwise identical to a
regular violate (drain_requested set, parent on_failure
absorbs or process exits non-zero with diagnostic). The codegen
emits the check + violate routing INLINE at the instantiation
site, branching to a continuation block on absorbed violations
rather than returning from the caller’s fn — the absorbed-then-
continue contract matches what users expect when wrapping the
instantiation in a parent that handles the failure.
The check expression is read-only against self.X fields; the
closure name must resolve to a declared epoch-inline closure on
the same locus, same constraint as a regular violate.
self.draining
Section titled “self.draining”While the locus is draining — after violate on it, or once the
process drains on SIGINT / SIGTERM (§ “Drain cascade
(whole-process)”) — the synthetic self.draining field reads
true from any locus method body. Reading it is optional: the
runtime stops a run() that never reads it on a signal by itself
(GH #1858). A run() that reads it takes the drain into its own hands
(no back-edge stops; § “Drain cascade (whole-process)”), the canonical
shape a loop that ends on it (while !self.draining { … }) and then
flushes. Elsewhere it suppresses downstream sends once the locus has
escalated:
fn on_tick(t: Tick) { if self.draining { return; } // this locus violated earlier Sampled <- self.count;}An error-check method that substitutes a value or escalates is
fallible(ClosureViolation) (§ “A value-returning method that may
violate is fallible”), and its caller says what an escalation
means at the call: let r = expr or (self.handle_io(err) or { return; });.
self.draining is one of the three synthetic members exposed by
name to user code (with self.children and self.k_max); its
backing field __drain_requested is internal-only. All three
names are reserved — a locus may not declare a member that
shadows one; see types.md § Reserved member names.
Rejection contexts
Section titled “Rejection contexts”violate is rejected at typecheck in:
- Free fn bodies. No
selfto resolve the closure name against. A free fn helper called from a locus method body cannot violate transitively:violateis lexically scoped to the locus method body it appears in. on_failurebody. Usebubble(err)—on_failureis the parent-side handler for child failures; re-firing a self- closure from there mixes the two channels.
Allowed everywhere else that has self: named locus method
bodies, bus-handler methods (subscribe X as foo → fn foo),
run(), lifecycle methods (birth(), dissolve(), drain()).
The same body shape gets the same primitive.
Recovery primitives
Section titled “Recovery primitives”restart(child) / restart(child) for N
Section titled “restart(child) / restart(child) for N”Restarts the child on the same instance — its arena, its subscriptions and its param values as they stand (a restart never re-evaluates a default):
- The failure’s drain request is lowered: the child is live again.
birth()runs again, then the birth-epoch closures, then thebirth_checkclauses — every birth is checked, the first and each restart’s alike.run()runs again.
When it takes effect depends on where the failure came from. A
birth-epoch closure’s failure re-runs birth right after the
handler returns, before run() has started. So does any other
failure of the birth — a violate in birth(), a failed
birth_check — whether its handler ran in place or was held: the
decision is read against the restart count as the birth began, so a
handler that had already returned by the time birth() did is not
missed, and a restart whose birth fails again — a violate in its
birth(), a birth-epoch closure, a birth_check it no longer passes
— is decided the same way before run() starts: restarted again
within the bound, quarantined at it. (A restart used to skip the
birth_check clauses, so a re-birth that broke its invariant ran
on.) The restart runs on the child’s own
placement — its pinned thread, its pool’s worker — as its first
birth() and run() did. A failure raised
while run() executes — a violate in it, or for a pinned child
the tick and duration closures its thread checks after it —
restarts once run() has returned, on the thread that ran it (a
pinned child’s own thread). A failure held while the parent
was still setting params takes effect when its handler returns
(§ “on_failure(c, err)”).
A restart is not taken while the process is draining: the drain ends the child anyway.
The retry bound. restart(c) for N gives this child at most
N restarts. The count is per child instance and cumulative over
its lifetime, and it is compared before the restart, so for N
admits exactly N restarts and the failure that follows the last
one quarantines the child instead — the supervisor tried N
times and is done with it. for 0 is meaningful and quarantines
on the first failure without restarting.
Exhaustion quarantines rather than falling through: a bounded
supervisor has stated when to stop, and stopping means the child
does not run — on every placement (a pinned child’s thread used to
start its run() once anyway). This is the difference from an unbounded
restart(c), which stops re-running at the default cap of 2 but
leaves the child live.
N is an expression, evaluated at the recovery site. Without the
modifier the bound is the default 2, so an unbounded restart(c)
is unchanged.
The bound is recorded in the topology artifact as retry_bound
on the supervision row (schema 1.10), so the declared policy and
the observed restarts are comparable.
restart_in_place(child)
Section titled “restart_in_place(child)”The same as restart(child), except that before birth() runs
again every param is put back to the value this instance was
built with: the value its literal gave it, or its default as that
default evaluated when the instance was built. Params are settled
once, from the literal; a restart never re-evaluates a default. So
Worker { tag: "a" } restarts with tag "a", whatever its
declared default says, and a default that builds a locus or reads
the clock is not run again. A param that holds a locus (or an
interface handle) keeps its child: a restart re-runs
this instance, not its children’s construction. The retry bound
and the default cap are shared with restart.
Useful for transient failures that don’t invalidate the locus’s structural commitments (e.g., the locus’s k_max is fine; just had a bad message).
quarantine(child) [for d]
Section titled “quarantine(child) [for d]”- Pause child (no new messages dispatched, no new accepts permitted, no run scheduling).
- Preserve arena and state.
- If
for dclause given, automatically restart afterd. - Otherwise wait until parent explicitly resolves.
Not lowered: the for d duration clause. quarantine(c)
itself ships; quarantine(c) for d is refused by the check, at the
statement. Note that this for is a duration before an automatic
restart — a different modifier from restart(c) for N, which is a
retry count.
main.hl:6:50: type error: `quarantine(c) for d` (an automatic restartafter a duration) is specified but not implemented: `quarantine(c)`itself ships, the `for d` clause does not. Note that this `for` is aduration before an automatic restart, a different modifier from`restart(c) for N`, which is a retry count.Also not lowered: the until modifier on any recovery op, refused
by the check at the statement (`until` (restart while a condition holds) is specified but not implemented), and a for on bubble,
which restarts nothing. Each of these passed the check and stopped
the build in codegen with no location before.
reorganize(child, ...)
Section titled “reorganize(child, ...)”Reserved syntax. Semantics TBD; expected: relocate child’s
sub-children to a sibling. Not in v0: the check refuses the
statement (`reorganize(...)` is reserved syntax with no semantics yet).
bubble(err)
Section titled “bubble(err)”Re-raise the error to self’s parent. Equivalent to:
on_failure(c, err) { bubble(err); } // for self's failuresFully traverses the lotus tower upward until a handler absorbs.
dissolve(child)
Section titled “dissolve(child)”Force-dissolve child immediately. Skips drain; closure tests at non-dissolve epochs do not fire on this path. Used for forced-shutdown scenarios.
Drain cascade (whole-process)
Section titled “Drain cascade (whole-process)”The drain is the runtime’s (GH #1858). A SIGINT or SIGTERM stops
every program the same way: the runtime ends every run() loop
between two iterations and wakes every blocking wait, so run()
returns, teardown runs the drain() / dissolve() hooks and the
process exits 0. An author writes nothing for it. A locus that wants
to decide for itself when to stop — flush a batch, finish a handshake —
reads self.draining in its run(), and then its loops are its own:
The locus’s run()… |
The compiler | On SIGTERM |
|---|---|---|
never reads draining |
a drain stop at each loop’s back-edge | its loops end between iterations, hooks run, exit 0 |
| reads it, and the check proves its loops stop on it | nothing to report | the author’s loop ends, hooks run, exit 0 |
| reads it, and the check cannot prove it | a warning at each such loop | the author’s code, bounded by the grace |
Manual control is the run()‘s. A locus takes the drain into its
own hands when its run() reads its locus’s draining, itself or
through a fn or method of the program it calls, transitively, through
any receiver that is the locus by declared type — self, a let alias
of it (in its block), a parameter a method or free fn binds to it (a
call on another locus that hands it this locus is followed), or a
declared field path whose type is the locus (a call on a locus whose
params declare a field of this locus’s type, or of a holder of one,
transitively, a collection or projection of it included, a type alias
of it resolved to it, is followed, and its self.<field> is this
locus: by declared types, not by construction) — or that the
declarations cannot resolve (a type name they do not know is never
taken as no locus), which is taken as a read. A read in a handler, a
drain() / dissolve() hook, or a method run() does not call, or of
another locus’s draining (a holder’s own self.draining included),
does not make the run() manual (the flow rows’ watches-drain column,
registry.md § flows). The check’s
“Manual drain not honoured” rule (verification.md § Structural &
design rules) says, conservatively, whether each loop of a manual
run() stops on the flag; what it cannot prove it reports, never
refuses: the author chose manual control, and the grace is the
backstop.
Back-edge stops. In the run() of a program’s own locus that is
not manual, and in fn main’s own body (the program’s run), the
compiler places a drain check at the back-edge of every loop the body
holds lexically — while and every for, nested ones included; not a
loop in a fn or method it calls, nor one in a closure. The check is one
load of the runtime’s flag and one branch, weighted cold, on every
iteration, @hot and @budget code included — except on a counted
loop (for i in a..b, while i < n { …; i = i + 1; }) whose body calls
nothing and holds no loop, which takes it once every 4096 iterations so
the loop can be vectorized (spec/runtime.md § “Back-edge stops”, GH
#2089): such a loop ends at the end of a chunk, still between two
iterations. When a stop has begun
the loop exits there, as a break written at the end of the iteration
would: between two iterations, never inside one, with the iteration’s
state as the iteration left it. A continue goes through the same
check. Code after the loop runs (the loop is left, not the run()), so
a nested loop’s stop ends the inner loop and the outer one’s iteration
finishes, then the outer loop ends at its own back-edge. The standard
library’s loci keep their own loops (their bodies read draining
where they need to). A stop is a signal’s drain or a failed test’s
unwind (std::test); a main locus’s tree drain (below) is not one and
ends no loop by itself.
SIGINT or SIGTERM:
- The runtime raises the process drain, a stop. From then on every
locus’s
self.drainingreadstrue, on every thread, and every back-edge check above ends its loop. - Waits return early, so a loop reaches its back-edge or its check:
- A wait already in progress returns: a
std::time::sleepat its next 100 ms slice (at once on anasync_iopool) and a deadline-bounded park on anasync_iopool with its timeout, wherever they are; and an untimed blocking wait (an accept, a receive on a socket with noset_recv_timeoutof its own) made in arun()(what it calls included) or infn mainwith its existing closed or empty outcome — no new variant, so theorits caller already writes covers it (stdlib.md§ “What a drain does to a wait”): anacceptits closed-1, a TCP or TLSrecvthe empty answer a peer’s close gives (recv_into0), a UDPrecvits timeout’s, on main, a classic pool, anasync_iopool and a pinned thread alike. An untimed wait a handler, a hook or a standard-library coroutine makes (a server’s connection, which answers the calls in flight before it closes) is not ended by the stop; the listeners’ stop (step 3) and the grace bound it. - A wait that begins during the drain returns at once, in the
same way: in a manual
run()that has not yet readdrainingastrue(what it calls included; a standard-library locus’s bodies run in their caller’s frame); and in arun()the runtime stops, orfn main, asleepwritten in that body itself, and an untimed wait anywhere it calls. So a loop that was mid-iteration when the signal landed reaches its back-edge (or, manual, itswhile !self.drainingcheck) instead of starting a 30 s sleep into the grace. Asleepin a fn or method a stoppedrun()calls runs its length: a loop there has no back-edge stop, and cutting its sleeps would only spin it. A handler is not part of therun()(one delivered inside the run()’s wait neither takes its cut nor ends it by readingdraining). On anasync_iopool such a park is resumed before the pool’s shutdown abandons what is still parked, so therun()returns and is joined. Every other wait begun during the drain runs its full length: adrain()ordissolve()body pacing a flush, a manualrun()pacing a final flush after its loop has seen the drain, a handler. A drain raised again later (a second tree’s, then a signal’s) cuts a manualrun()that saw the first one until it readsdrainingagain. - What no stop can wake is a documented limit, bounded by the
grace: a blocking foreign (
@ffi) call, a subprocess the program waits for (std::process::run,wait), a connect or an HTTP call until its own deadline. (2026-11-06: a sleep begun during the drain ran its full length wherever it was made, and before GH #1858 an untimed wait was not interrupted at all.)
- A wait already in progress returns: a
- The process’s listeners stop: every named listener’s socket is
shut down (as
std::io::tcp::stop(name)does), so each accept loop — astd::http::Server’s, astd::io::tcp::Listener’s, the api runtime’s — ends wherever it waits, on main, a pinned thread or a pool, and itsrun()returns once the connections it accepted are answered (stdlib.md§ “Shutdown is a drain, never a cut”). A server used to keep accepting, and held the drain for the whole grace. (2026-10-19, downstream handoff.) - Each
run()returns: one the runtime stops at its next back-edge, a manual one when its own code says so. - Leaves dissolve first, each parent after its children, the
root last — the ordinary end-of-program teardown, which runs every
drain()anddissolve()hook and the runtime’s own (schedulers, bus router, allocator, the atexit hooks). - Process exits 0.
Exit codes. A program stopped by a signal exits 0 once its
hooks have run, whatever it reads. Before GH #1858 a program that read
draining nowhere and declared no hook died by the signal at once
(128 + signal, 143 for SIGTERM) with its hooks unrun, and one that
did (GH #1077, #1838) could hold the whole grace on a loop that never
looked and then die by the signal all the same. A supervisor or a test
that expected 143 from a stopped program now sees 0; 143 now means the
grace ran out (a manual loop that did not stop, a wait no stop can
wake) or a second signal.
The drain has a grace period: if the process has not exited
5 s after the signal (LOTUS_DRAIN_GRACE_MS sets it), the runtime
writes one record (runtime.md § Runtime diagnostics are records:
logger=lotus.drain, with signal, grace_ms and waiting_on) naming
the signal — and what the drain was still waiting on: each cooperative
pool with its mode, whether a worker is mid-iteration and in which
locus, and how many cells queue behind it — restores the signal’s
default action and re-raises it: the process dies BY the signal, as it
would with no runtime at all (a waiting parent sees it killed by that
signal; a shell reports 128 + signal). A second SIGINT / SIGTERM
ends the process the same way at once.
The handling is installed in every program a signal can reach (not on
wasm). The signal is caught, never blocked, so a subprocess the program
spawns inherits the default disposition. (GH #1039: before 2026-09-24
the runtime caught neither signal, so every program ended at the signal
and a while !self.draining loop never saw a drain. GH #1077 and #1838
then installed it only in a program that read draining or declared a
drain() / dissolve() hook, and drained only while a live instance
of such a locus was counted; GH #1858 retired the count, along with
the check’s “drain hook behind an endless run” warning: no hook is
behind an endless run unless its locus chose manual control.)
When main’s run() ends first. Teardown follows the
ownership tree: when a main locus’s run() returns, the first step
of its teardown raises the drain for its tree, steps 1–2 above
without a signal and without a stop (runtime.md § “Lifecycle
obligations”, line 15): self.draining reads true and a timed wait
in progress returns, but no back-edge check ends a loop and no untimed
wait is woken.
A child whose run() still loops on while !self.draining — pinned,
on a classic cooperative pool or on an async_io one — sees it, a
timed wait it is in returns early, its run() returns and it is
joined; the tree then dissolves, leaves first. So a main whose
run() returns at once — or that declares none — ends its program
once its children’s loops see the drain: a server stays up because
main’s run() waits (while !self.draining { std::time::sleep(…); },
or self.web.wait() on an exposure param), and SIGINT / SIGTERM end that
wait. A main that declares no run() and holds an exposure’s listener
is given the run that waits on its exposures (spec/api.md § Serving).
A child’s run() that never reads self.draining keeps the process
alive until it returns (a signal’s stop ends its loops; the tree’s
drain does not). main’s run() returning
does not cut a live listener: the tree’s drain does not take step 3
above, so a server the tree runs on main or on a pinned thread — its
own param, or one a pinned child’s run() builds — keeps accepting,
and its join keeps the process alive, until a signal’s drain stops it.
A main that only builds its tree (no run(), its children doing the
work) serves for as long as they do. (2026-10-19: GH #1659 had the
tree’s drain stop every listener, which cut such a program’s servers,
one bound before the drain and one bound after alike; downstream
handoff.) With no run() (an empty one is the same program), the
tree’s drain begins once the run() of each pinned child whose run()
does not read draining has returned, on the eager and the deferred spine
alike: a sleep such a run() is in is not cut short, a sibling that
watches the drain keeps serving until then, and what such a run()
publishes in its last moments reaches a pinned sibling that still
consumes, in any declaration order; a child whose run() reads
draining (itself or through a fn or method it calls) is what the
drain ends, so it is not waited for. A read in the child’s handler or
drain() hook does not count: such a child was not waited for, and a
pinned publisher whose hook read the flag lost its deliveries again
(GH #1858, the review of the fix below). (2026-11-06, downstream
handoff: the teardown joined the pinned children in declaration order
right after the tree was built, so the pinned subscriber declared
first was shut down while the pinned publisher declared after it was
still running, and every delivery of the program was lost, silently.)
An async_io child parked
on an untimed wait (a plain recv, an accept) is abandoned at its
pool’s shutdown (runtime.md § the wakeable park), as before. The tree’s drain ends
with its teardown: a main locus built afterwards starts undrained,
and a signal’s drain is neither masked nor ended by it. (Before
2026-10-12 a pinned or classic child’s loop kept the process alive
after main’s run() returned, until a signal ended it.)
Under hale run. hale run stands aside for the program’s
drain: it ignores SIGINT (a terminal’s Ctrl-C reaches the program
through the process group) and forwards a SIGTERM sent to its own
pid, then reports how the program ended (projects.md § “What hale run starts, hale run ends”).
Closure-failure cascade
Section titled “Closure-failure cascade”A closure violation at any epoch:
- Runtime emits
ClosureViolationevent. - Locus’s exploded flag is set.
- Subsequent epochs may also fail; flag persists.
- At the failing epoch, parent’s
on_failure(self, ClosureViolation { ... })invoked; held while the parent’s params are open (runtime.md§ “Lifecycle obligations”, line 9). - Parent’s policy decides: absorb, recover, bubble.
- If bubbled, propagates to grandparent; recursively until absorbed or reaching root (process exit).
epoch inline closures (F.27) take the same cascade path with
one addition: at step 2 they also set __drain_requested, so
the locus enters drain at the next cooperative yield rather
than continuing on its current epoch. The drain initiation is
the only divergence from the auto-epoch cascade; routing to
parent’s on_failure at step 4 is identical.
Scheduler dispatch
Section titled “Scheduler dispatch”Per runtime.md: multi-scheduler cooperative.
- N schedulers, one per CPU core (configurable).
- Each scheduler holds a queue of runnable loci.
- Scheduler picks a locus, runs it until cooperative yield.
- At yield, scheduler picks next.
- Cross-scheduler communication via bus (typed messages).
- Loci may be migrated between schedulers transparently for load balancing.
Failure-traversal flow
Section titled “Failure-traversal flow”Failures flow upward:
- Child failure → child’s parent’s
on_failure. - Parent’s handler decides absorb / restart / bubble / quarantine / dissolve.
- If bubble, → grandparent’s
on_failure. - If reaches runtime root, process exits with structured error report.
Failures never flow laterally (sibling-to-sibling) — the framework’s vertical-only-flow expressed at the runtime layer.
Fallible call semantics (v1.x-FORM-1; PR6 reframe)
Section titled “Fallible call semantics (v1.x-FORM-1; PR6 reframe)”Hale carries two orthogonal failure channels:
- Closure-violation channel — structural failure of a
locus’s closure (its assertion / invariant) fires
Signal::Bubble(ClosureViolation)and routes through the existingbubble/on_failuremachinery. See F.9. This is the substrate-facing channel: it expresses “a locus’s promised invariant broke” and propagates vertically through the locus tower per the failure- propagation-upward mechanic. - Value-error channel — value-level
fallible(T)returns are an addressing protocol between immediate caller and fallible callee. They don’t constitute a separate runtime mechanism at intermediate frames; they propagate by sret- path-indicator through the static call stack, addressed
at each level by a required
orclause. This is the application-facing channel: it expresses “this call-by-call computation might fail; address it inline.”
- path-indicator through the static call stack, addressed
at each level by a required
The two channels meet at exactly one place: the implicit main
locus’s root boundary (see “Process exit” below). Everywhere
else, the channels are independent. See
spec/design-rationale.md.
Where each channel lives (declaration sites)
Section titled “Where each channel lives (declaration sites)”The two channels are realized through different declaration sites. The mapping is canonical, not advisory:
fallible(E)may be declared on:- Free fns — pure application-layer computations whose failure shape matters call-by-call.
- Stdlib-synthesized methods on
@form(...)containers (@form(vec).get/.pop,@form(hashmap).get/.remove/.key_at/.entry_at,@form(ring_buffer).pop). Application-layer storage substrate: the container’s role is application-layer data, not locus-structural participation in the substrate’s lifecycle. - User-declared
fnmember fns on a locus (open-question #24, shipped 2026-05-25 in two phases: MVP atd565d6fwith value-only payloads, v0.2 at98910b9extending to heap-bearing payloads via the TLS caller-arena snapshot non-fallible heap-returning methods already use). The narrowed rule recognises that afnmember fn is not substrate-orchestrated — its callers hold a frame, can address the error channel inline, and the value-error path doesn’t conflict with the closure-violation channel. - Interface method signatures (GH #732). A call through
the interface carries the channel exactly as a direct call
on a fallible method does: every
orform applies, and a call that does not address the error is rejected as any unaddressed fallible call is. Seespec/types.md§ “Interface types (F.20)” for which methods satisfy one.
fallible(E)may NOT be declared on:- Lifecycle methods (
birth/run/accept/drain/dissolve/on_failure). The substrate orchestrates these — bus dispatch invokes the handler, parent invokesaccept, runtime invokesrun— and there’s no caller frame in user code to address a value error. Physically rejected at the AST level (LifecycleDeclcarries nofalliblefield). - Closure assertions. Substrate evaluates the
assertion at the epoch boundary; there’s no caller in
the expression’s frame to address a value error.
Closures route failure via their own structural channel
(assertion firing →
on_failure), not a value channel. - Bus-subscribed handlers. Verified at the
subscribe ... as handlersite rather than at the fn decl: a fn that’sfallible(E)by declaration may not also be referenced by asubscribeentry. Bus dispatch has no caller frame; subscribing a fallible fn would have nowhere to sendout_err. The typecheck diagnostic fires at the subscribe site, naming the handler fn.
- Lifecycle methods (
The rule is two-channel separation at substrate-facing
surfaces, not “no fallible on any locus method.” The
load-bearing constraint is who’s the caller — when the
substrate orchestrates a method (lifecycle, closure
assertion, bus handler) there’s no caller frame to address
the error channel, so fallible(E) would describe a
contract that cannot be satisfied. User-declared fn
members called from inside a method body or from another
locus’s method body have an addressable caller; they carry
fallible(E) like free fns do, with the same or
disposition surface.
Example shape post-narrowing:
type ParseError { msg: String; }
locus Reader { // Allowed: user-declared `fn` member with fallible(E). // The body can `fail ParseError { msg: ... }` or call // other fallible functions and propagate via `or raise`. fn parse_message(b: Bytes) -> Message fallible(ParseError) { // ... if bad { fail ParseError { msg: "bad header" }; } return Message { ... }; }
// Allowed: lifecycle method calling a fallible member fn // and addressing the error inline. run() { let m = self.parse_message(b) or default_message(); // ... }}The earlier v0 rule (blanket “no fallible on locus methods”)
was narrowed because the friction signal across multiple
apps and libraries showed devs extracting free fns just to
get a value-error channel back — losing self ergonomics
and splitting closely-related code across two top-level
decls. See notes/open-questions.md § #24 for the
narrowing’s full reasoning and the rejected alternatives.
fail statement
Section titled “fail statement”fail <expr>; inside a fallible fn body:
- Evaluates
<expr>to a valuev(typed as the fn’s declared payload type E, or as a member of E when E is a set type: the member’s value is the set’s, spec/types.md § Set types). - Exits the enclosing fallible fn body via the error path.
- The caller’s
Expr::Callsees the result asFallibleErr(v)— a tagged value the immediate caller’sorclause is required to address.
fail outside a fallible body is a typecheck error;
statement-position recognition is also parser-gated to a
fallible-body scope (so let fail = 0; outside such a body
stays admissible).
A bare fallible call is an error (GH #738)
Section titled “A bare fallible call is an error (GH #738)”One rule holds for every fallible call, whether the callee is a fn or
method the program declares, an interface method, a container’s or
an array’s get, or a stdlib entry point: only an or handles
it. The call must be the operand of an or disposition (or raise,
or <fallback>, or handler(err), or fail <payload>, or discard). In any other position the call is bare: an argument
(g(f())), an operand (f() > 1), a match scrutinee (match f() { .. }), a let initializer (let v = f();), a statement (f();), a
returned value (return f();, in a fallible fn too). A match does
not handle a fallible call.
A bare call is a type error naming the callee, the payload it can
fail with, and the shapes that address it (or raise, or <fallback>, or discard, or handler(err)). That includes the
legacy Int-status form of the stdlib write fns, let r: Int = std::io::fs::write_file(..). It is reported by hale check, hale verify, hale build, run, test and the language server alike,
one error per call. There is no flag or mode that accepts it. The rule
for stdlib calls was staged (a warning, then --strict-fallible, then
this) and the flag is removed. For any other callee the bare call was
always refused, by the build if not by the check.
A narrowing into a range (Session(n), spec/units.md § Conversions)
is fallible the same way, with a RangeError, and is bare in
the same positions; its error lists the narrowing’s own discharges
(or <fallback>, or clamp, or wrap, or handler(err), or raise).
A handled call and a deliberately discarded one (or discard, which
needs a () success type) are not reported. The stdlib entry points
concerned are the signature table’s rows with a payload
(stdlib_surface.rs): 94 at the time of the ruling, across
std::io::fs, std::process, std::http::client, std::io::tcp,
std::compress, std::tar, std::bytes, std::str and
std::time. Lowering carries no bare form of any of them: it reads
the same rows, and the last bare forms (std::bytes::at, which
answered -1, and std::io::fs’s read_file, read_bytes,
write_file, write_file_append, mkdir, file_size,
list_dir_count and list_dir_at, which answered a direct value or
an Int status) are gone (F.40 phase 4, S5). A bare call that reaches
lowering, in a build that skipped the check, is an internal error
naming the row.
Limitations to lift. These are where lowering’s support stops today, not part of the rule:
- A fallible handler. An
or’s handler that can fail itself (g() or f(err)) takes an implicitor raise(spec/types.md§ “Disposition operators (or)”) only when it is a fn the program declares (not a generic one), an imported or bundled stdlib fn written as Hale, or a locus’s member fn called onself, a local or a field ofself. Any other fallible handler is refused with the nested spelling that works,or (f(err) or raise). That covers a stdlib entry point, a generic fn, an interface’s method, and a container’s, an array’s or a stdlib handle’s method. - A call through an interface-typed value. The checker types a
local or parameter whose declared type is an interface as unknown
(an interface slot accepts any locus that satisfies it), so it does
not see a call through one as fallible: a bare
s.put(k)withs: Storepasseshale check, andhale buildrefuses it (error not addressed: `Store.put` is fallible). A call through a locus-typed value is checked.
or disposition
Section titled “or disposition”<expr> or <disp> evaluates <expr>. If the result is a
non-error value, that value is the expression’s value
(disposition is a no-op). If the result is FallibleErr(p):
<expr> is the fallible call itself (a fn’s, a generic fn’s, a
method’s, a stdlib path’s) or a narrowing conversion. Anything else
in that place — a field read of a record whose field holds a fallible
call (Box { v: f() }.v or 0), an element, a name — has no failure
of its own, and the or is a type error at it (GH #1966): the or
goes on the call where it is written.
-
or raise— propagate the error one frame up the static call stack. Inside a fallible(E) fn, this writespinto the enclosing fn’s error sret slot and exits via the enclosing fn’s error path; the enclosing caller’sorclause then addresses the error in turn. The closure- violation channel is not entered. (An application may later promote a value error to a closure violation explicitly, but no such syntax exists in v1.) The payload forwarded is the enclosing fn’s error, so the call’s error type must be the one the fn declares or one it converts from (“Converting a raised error”, below):std::os::getrandom(4) or raisein afallible(CryptoError)fn, with nothing to convert anIoErrorinto aCryptoError, is refused at theor raise, naming both types and the three ways forward (a@raiseconversion, a set holding the call’s error, oror fail CryptoError { kind: err.kind, detail: err.detail }, below) (GH #1945: the check admitted it and the build refused it in lowering’s terms). A stdlib error type spelled by its path (std::crypto::CryptoError,std::io::IoError,std::str::ParseError,std::index::IndexError,std::form::hashmap::KeyError,std::form::ring_buffer::EmptyError) is the same type as its bare name, wherever either is written. -
or <fallback>— bindserrtopin scope and evaluates<fallback>. Its result is the expression’s value. Type must match the success type.<fallback>may itself be a call (or handler(err)); the identifiererrin the fallback expression resolves to the typed payload.A diverging fallback is exempt from the type match (2026-08-03, #353): a block whose last statement is unconditionally
break/continue/return/fail/terminatenever yields, so there is no value whose type could match, and requiring one forced callers to invent a substitute that is provably never used. Deliberately conservative — only an UNCONDITIONAL divergence qualifies, because a block that can fall through genuinely does need a value, which is what the rule protects.v.get(i) or { break; }is the shape a generic desugar needs, since it cannot invent a typed default for an arbitrary element type. -
or discard(added 2026-05-16) — swallows the error and produces Unit. Sugar for the previously-idiomaticor noop(err)pattern with a no-op handler fn. On a call whose success type is Unit it is legal anywhere. On a value-bearing call it is legal where the value is thrown away anyway — the call is the whole statement (cache.put(k, v) or discard;, friction sweep 2026-10-12: there is noor ignoreword) — and the success value is dropped with the error. Where the value is used (let x = f() or discard;, an argument, an operand) the discard branch has no value to give, and the typechecker refuses it with a message pointing ator <default>,or raiseand the statement form. -
or fail <payload>(added 2026-05-17, B3 / G6) — symmetric toor raise, but the caller picks a fresh payload of the enclosing fallible fn’s declared error type instead of forwarding the inner call’s payload verbatim. Lets a caller translate one error shape into another inline (std::str::parse_int(s) or fail AppErr { msg: "bad number" }) rather than bouncing through a helper fn. The payload expression seeserrbound to the inner call’s error value, exactly as a substitute RHS does (2026-08-11), so a field-carrying translation is written inline:src() or fail DstError { kind: err.kind }. Same divergence rule: chain value type collapses to the inner success type. Typechecker rejects outside a fallible fn body with a hint to useor raiseoror <fallback>. As withfail, a member of a set error type is the set’s:or fail errhands aParseErroron in afallible(LoadError)fn, withtype LoadError = ParseError | IoError;.
Chains are right-associative: a() or b() or raise reduces
the value to the success type level by level.
Converting a raised error
Section titled “Converting a raised error”An or raise (and the implicit or raise of a fallible
handler, spec/types.md § “Disposition operators (or)”) whose
call fails with P inside a fallible(E) fn, P not E,
converts the error into an E in one of two ways, tried in
this order (GH #1951, F.50):
-
A set member (R2).
Eis a set type holdingP(spec/types.md § Set types): the error becomes the set’s member, exactly asfail p;andor fail errmake it. One relation decides all four:fail,or fail <expr>,or raiseand a fallible handler’s failure. -
A conversion (R3). One
@raise fnfromPtoEis declared: the raise isor fail conv(err), so the caller’s handler sees the converted error and every field the conversion copied.type StoreError { key: String; }type ApiError { status: Int; detail: String; }@raise fn api_from_store(e: StoreError) -> ApiError {return ApiError { status: 404, detail: "no key " + e.key };}fn lookup(key: String) -> Int fallible(StoreError) {if key == "missing" { fail StoreError { key: key }; }return len(key);}fn get(key: String) -> Int fallible(ApiError) {return lookup(key) or raise;}
A @raise fn is a free fn of one parameter, not generic and
not fallible, whose result type is not its parameter’s; each
other shape is refused at the fn. It runs on the error path of
the raise, so @raise implies the effect assertion
@effects(none: {syscall, publish, spawn, block}), held as
every assertion is (spec/verification.md): it may allocate the
error it returns and do nothing else with an effect. The
conversion’s call is not written, and every analysis of the fn
that raises reads it as the call it is, the or fail conv(err)
the raise stands for (GH #1982): its allocations count against
the raising fn’s @budget(alloc_per_call = N), an effect class it
reaches beyond the four (time, a program’s own effect class)
is one the raising fn reaches, with the conversion on the witness
path (get -> api_from_store), and @no_panic judges the raise as
the or raise it is written, a trap.
Conversions are coherent:
- The orphan rule. A
@raise fnis declared in a seed that declaresPorE. A builtin type (IoError,ParseError,CryptoError, …) belongs to no seed, so a conversion from one is declared beside the type it converts into. A conversion declared anywhere else is refused at the fn (“convconvertsIoErrorintolib::ApiError, and a@raisefn is declared in the seed of one of its two types”). - In reach. By the orphan rule every conversion from
PtoEis in the seed ofPor ofE, so the conversions anor raisesees are those two seeds’. Two of them for one pair are refused at theor raise, naming both; either alone applies. - No chaining. A conversion applies once: a
Pthat one converts intoQand another fromQintoEis not anE. Nor does a conversion apply into a set by way of a member, or to a member by way of the set.
A set member is tried first: where E is a set holding P, a
conversion from P to E is never called. Where neither
applies, the or raise is refused as above, and the error is
translated where it is raised, or fail E { … }.
Process exit
Section titled “Process exit”The runtime ends a program against its will via one of two boundary events at the implicit main locus’s root:
- Closure-violation escape (F.9). If a closure violation
bubbles past every
on_failurehandler back to the runtime root, the process exits with the violation’s payload as the structured error report. - Value-error escape (PR6). If an
or raisereaches the implicit main locus’s body with no enclosingfallible(E)frame to absorb it, the value error escapes the locus’s body. The runtime panics vialotus_root_panic(payload, size, typename)— today dprintf to stderr ("Hale panic: unhandled <T> escaping main locus") +exit(1). Architecturally this is the seat for a future routing-through-main-locus-on_failureextension: when (if) the main locus declareson_failure, the runtime will route the synthesized ClosureViolation through that handler before falling out to the dprintf+exit fallback. Until then the boundary collapses both channels to the same exit shape.
Both paths preserve the framework’s vertical-only-flow: every failure exits through the top of the recursion, never laterally.
One top-level scope
Section titled “One top-level scope”A seed’s declarations share one flat top-level scope: every file of
the seed directory declares into it, under the names it writes, and
two declarations of one name are the ordinary duplicate-name error.
There is no in-file namespace form. A module is a directory, reached
by import "<path>" as <alias>; (§ “Cross-seed namespace
resolution”); the module NAME { … } declaration that once grouped
declarations inside a file was removed (spec/decisions.md F.57), and
a program that still writes one is refused at the word module with
one located error:
main.hl:1:1: parse error: `module` declarations were removed: a module is a directory, reached by `import "path" as name;`. Move the declarations inside `module NAME { }` to the top level, or into their own file or directory and import it (spec/decisions.md F.57)module is an ordinary identifier everywhere else: a local, a field,
a parameter or a fn may be named module.
The bundled stdlib’s declarations share that one scope, under their
internal names (std::http::Server is the locus __StdHttpServer).
A program declaration of any kind that reuses one of those names is
the same duplicate-name error, in the same one namespace: hale check refuses it where it stands and names the stdlib’s
declaration. The stdlib’s own source checked as a program declares
the same thing again, not a second thing, and is not refused; and a
library’s names reach an importer mangled (__lib_…), so only a
library checked on its own can meet one. The stdlib itself declares
each name once, which its own test holds it to.
A seed’s entry point is its fn main (or the main locus that one
instantiates).
Cross-seed namespace resolution (v1.x-IMPORT)
Section titled “Cross-seed namespace resolution (v1.x-IMPORT)”A file may declare import "<path>" as <alias>; at the top.
References to library decls go through the alias as
alias::Name. Resolution is two-step:
-
Parse / merge. The CLI resolves each import’s path (per
spec/projects.md“Resolution order”), parses every.hlfile in the resolved target, applies the auto-mangler with a stable path-derived<lib_id>+ each file’s stem, and merges the mangled items into the importing program’s item list. A per-build path-rename table is built mapping["<alias>", "<Name>"]to__lib_<lib_id>__<stem>__<Name>— the<alias>is the importer’s local namespace choice; the<lib_id>is the lib’s canonical path identity, so two consumers importing the same lib under different aliases see identical mangled symbols. -
Codegen lookup. Codegen’s qualified-name resolution consults three tables in order — static
STDLIB_PATH_RENAMES, staticMOA_PATH_RENAMES, and the per-build import table — when lowering any path-qualified type expression, struct literal, or method receiver. The first matching table wins.
A qualified literal checks like a local one. alias::Type { ... } resolves to the merged declaration before its
initializers are validated, so field names, field types,
interface coercions, and missing required
fields are all checked exactly as they are for a literal on a
locally declared type — an unknown field is the same
type T has no field f error, at the offending initializer’s
span. A literal whose path resolves to no visible declaration
keeps the permissive Unknown typing. Diagnostics name the
spelling the author wrote (alias::Type), not the mangled
symbol. (GH #707, 2026-09-19 — downstream handoff. Until then
only the RESULT type was resolved: a misspelled field in an
imported literal was dropped in silence and the field’s default
constructed instead, so check reported ok on a program the
same literal on a local type would have rejected.)
Cross-seed references in user code (foo::Bar) and intra-seed
references inside the imported library (bare Bar from a file
that uses a type declared in a sibling file) BOTH resolve to
the same mangled symbol. The mangler builds a unified rename
map across every file in the imported library before
rewriting, so greet.hl’s reference to a Formatted type
declared in format.hl rewrites to the same
__lib_<lib_id>__format__Formatted symbol that format.hl’s
decl ends up at.
Local bindings (let, let mut, fn params, lifecycle params,
for-loop vars, pattern bindings, generic params) shadow
top-level names per ordinary lexical scope; the mangler’s
scope-aware walker leaves shadowed references unrewritten.
Per-importer scoped imports (A4). Imports
declared inside imported library files are followed
transitively by the resolver, but each library’s imports land
under that library’s own alias namespace — they do not become
visible to the top-level program. So library A importing
library B exposes A’s surface to the importer; B is reachable
only through A’s API surface (or by the importer re-declaring
its own import "lib/B" as ...;). This replaces the prior
strict barrier (which rejected transitive imports outright) and
unblocks composition without leaking dependency identity. See
spec/projects.md for the rationale and per-alias scoping rules.
hale run interaction. hale run compiles through the same
codegen path as hale build, and — as of WS3.3 —
the same import path: both the single-file and directory forms
(hale run ./dir) resolve cross-seed imports, build the per-build
path-rename table, and rewrite qualified alias::Name references
identically. A directory run produces the same resolved program
as the corresponding build and execs it. (Previously the
directory run form bundled files without the rename table, so
cross-seed imports only worked under build; that gap is closed.)
Region lifetime guarantees
Section titled “Region lifetime guarantees”Per memory.md:
- A locus’s region is freed atomically on dissolve.
- Sub-regions are freed before the parent’s region (drain cascade ensures this).
- No pointer-into-a-freed-region is reachable after region release (compile-time-checked + region-lifetime-checked).
Forward-looking / deferred items for this area now live in the decision log — see
decisions.md§ Deferred & future work.