<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Avin</title>
  <link href="https://avinlang.dev/feed.xml" rel="self"/>
  <link href="https://avinlang.dev/"/>
  <id>https://avinlang.dev/feed.xml</id>
  <updated>2026-11-25T23:48:40.523555309Z</updated>
  <author><name>Ed Maxedon</name></author>
  <entry>
    <title>Union types</title>
    <link href="https://avinlang.dev/spec/unions/"/>
    <id>https://avinlang.dev/spec/unions/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>A | B written in annotations: an anonymous tagged sum, made at a single site, taken apart by match, and the way ? combines distinct errors.</summary>
    <content type="html">&lt;p&gt;A &lt;strong&gt;union type&lt;/strong&gt; &lt;code&gt;A | B&lt;/code&gt; holds a value of &lt;code&gt;A&lt;/code&gt; or a value of &lt;code&gt;B&lt;/code&gt;. It is written in annotations only,
never inferred; it compiles to an anonymous tagged sum; a &lt;code&gt;match&lt;/code&gt; takes it apart by type, and must
cover every member; and &lt;code&gt;?&lt;/code&gt; uses it to pass on errors of several types from one function.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;type Num = int | long

describe(x: int | string) -&amp;gt; string = x match
    n: int -&amp;gt; s&amp;quot;number $n&amp;quot;
    s: string -&amp;gt; s&amp;quot;text $s&amp;quot;

load(path: string) -&amp;gt; Result[Config, IoError | ParseError]
    val text = readText(path)?           // a Result[string, IoError]
    val doc = parseDocument(text)?       // a Result[Document, ParseError]
    configOf(doc)

describe(3)          // the int becomes an `int | string` at the argument
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A union is the light choice between types a program already has. A choice that has a name of its
own, variants of its own or methods is a &lt;code&gt;data&lt;/code&gt; type, and a value of any type at all is an &lt;code&gt;Any&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;writing-a-union&quot;&gt;Writing a union&lt;/h2&gt;
&lt;p&gt;A union is written wherever a type is written by hand: a parameter, a result, a &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt;
annotation, a field of a data type or a class, a type argument, a part of a tuple or a function
type, and the body of a &lt;a href=&quot;/spec/declarations/#type&quot;&gt;type alias&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Cell(content: int | string)
val cells: Vector[int | string] = [1, &amp;quot;two&amp;quot;]
val pair: (int | string, bool) = (1, true)
f[int | string](x)
type Key = int | string
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;|&lt;/code&gt; binds more tightly than &lt;code&gt;-&amp;gt;&lt;/code&gt; and more loosely than everything else in a type.&lt;/strong&gt; So:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;(A) -&amp;gt; B | C&lt;/code&gt; is a function returning &lt;code&gt;B | C&lt;/code&gt;, and &lt;code&gt;A | B -&amp;gt; C&lt;/code&gt; a function taking an &lt;code&gt;A | B&lt;/code&gt;.
A union of function types puts each in parentheses: &lt;code&gt;((int) -&amp;gt; int) | string&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Option[A | B]&lt;/code&gt; is an option of a union, and &lt;code&gt;Option[A] | B&lt;/code&gt; a union one of whose members is an
option; the two are different types.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[]A | B&lt;/code&gt; is &lt;code&gt;Vector[A] | B&lt;/code&gt;, since the element of &lt;code&gt;[]&lt;/code&gt; is a name or a parenthesized type;
&lt;code&gt;[](A | B)&lt;/code&gt; is a vector of the union.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@sendable (A) -&amp;gt; B | C&lt;/code&gt; marks the function type, whose result is the union.&lt;/li&gt;
&lt;li&gt;Parentheses group as anywhere in a type: &lt;code&gt;(A | B)&lt;/code&gt; is &lt;code&gt;A | B&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A union written in a type pattern is parenthesized, as a function type there is, since a &lt;code&gt;|&lt;/code&gt; in a
pattern separates &lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;alternatives&lt;/a&gt;: &lt;code&gt;x: (int | string) -&amp;gt;&lt;/code&gt;
binds a union, and &lt;code&gt;_: int | _: string -&amp;gt;&lt;/code&gt; is two alternatives, which bind nothing. A type pattern
followed by &lt;code&gt;|&lt;/code&gt; and a type name is reported with the parenthesized form to write instead:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;v match
  x: int | string -&amp;gt; … // error: a union in a type pattern is written in parentheses,
  // `x: (int | string)`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The parser tells the three uses of &lt;code&gt;|&lt;/code&gt; apart by position.&lt;/strong&gt; Where a type is expected (after the
&lt;code&gt;:&lt;/code&gt; of a parameter, a field, a binding or a type pattern, after &lt;code&gt;-&amp;gt;&lt;/code&gt; in a signature, inside the
brackets of type arguments, after &lt;code&gt;type Name =&lt;/code&gt;) it is a union. In a pattern it separates
alternatives, and in a clause head after the arguments it begins a
&lt;a href=&quot;/spec/declarations/#clauses&quot;&gt;guard&lt;/a&gt;. Everywhere else it is the
&lt;a href=&quot;/spec/operators-and-control-flow/#operators&quot;&gt;bitwise or&lt;/a&gt;, or the method &lt;code&gt;|&lt;/code&gt; of a type that has one.
The positions never overlap: an expression never stands where a type does, and an explicit type
argument list &lt;code&gt;f[int | string](x)&lt;/code&gt; holds types. A union breaks across lines only inside brackets or
parentheses, after a &lt;code&gt;|&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;normal-form&quot;&gt;Normal form&lt;/h2&gt;
&lt;p&gt;A union is a set of members. Before anything else is decided about it, it is brought to a normal
form, so that two unions that hold the same values are one type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Nested unions flatten&lt;/strong&gt;: &lt;code&gt;A | (B | C)&lt;/code&gt; is &lt;code&gt;A | B | C&lt;/code&gt;, and so is a member that is an alias of a
union (&lt;code&gt;Num | string&lt;/code&gt; with &lt;code&gt;type Num = int | long&lt;/code&gt; is &lt;code&gt;int | long | string&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order does not matter&lt;/strong&gt;: &lt;code&gt;A | B&lt;/code&gt; and &lt;code&gt;B | A&lt;/code&gt; are one type, so two overloads differing only in
the order are the same overload, and a &lt;code&gt;Map[int | string, V]&lt;/code&gt; is a &lt;code&gt;Map[string | int, V]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A member that converts to another member is absorbed into it&lt;/strong&gt;, at a single site without a
change of meaning, as a subtype does and as a value boxes into a trait it implements: &lt;code&gt;Dog | Animal&lt;/code&gt;
is &lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;int | Display&lt;/code&gt; is &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;A | Any&lt;/code&gt; is &lt;code&gt;Any&lt;/code&gt;, and &lt;code&gt;A | Nothing&lt;/code&gt; is &lt;code&gt;A&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union left with one member is that member&lt;/strong&gt;: &lt;code&gt;int | int&lt;/code&gt; is &lt;code&gt;int&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Written out by hand, each of these but flattening and order is a mistake, and an error that names
the type to write:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val a: int | int = 1 // error: `int` is named twice in this union
val b: Dog | Animal = rex // error: a `Dog` is already an `Animal`, so `Dog | Animal` is
// `Animal`; write `Animal`
val c: string | Any = &amp;quot;x&amp;quot; // error: every member converts to `Any`, so this union is `Any`;
// write `Any`
val d: int | Nothing = 1 // error: `Nothing` adds no value to a union; write `int`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where the members come together through a type argument or an alias, the same cases are absorbed
silently, since nothing written was wrong: &lt;code&gt;T | int&lt;/code&gt; at &lt;code&gt;T = int&lt;/code&gt; is &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;T | Animal&lt;/code&gt; at
&lt;code&gt;T = Dog&lt;/code&gt; is &lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;T | string&lt;/code&gt; at &lt;code&gt;T = int | bool&lt;/code&gt; is &lt;code&gt;int | bool | string&lt;/code&gt;, and
&lt;code&gt;Key | string&lt;/code&gt; with &lt;code&gt;type Key = int | string&lt;/code&gt; is &lt;code&gt;int | string&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Two members that are both supertypes of some third type stay apart: &lt;code&gt;Named | Pet&lt;/code&gt;, for unrelated
traits &lt;code&gt;Named&lt;/code&gt; and &lt;code&gt;Pet&lt;/code&gt;, is a union of two members, even though a &lt;code&gt;Parrot&lt;/code&gt; may be both (see
&lt;a href=&quot;#making-a-union-value&quot;&gt;making a union value&lt;/a&gt;). Instances of one generic type at different
arguments are different members: &lt;code&gt;Option[int] | Option[string]&lt;/code&gt; has two.&lt;/p&gt;
&lt;p&gt;A recursive union is a data type: &lt;code&gt;type Json = Vector[Json] | string&lt;/code&gt; is an alias naming itself, an
error as it is for &lt;a href=&quot;/spec/declarations/#type&quot;&gt;any alias&lt;/a&gt;. A union may name a data type that names
the union back: &lt;code&gt;data Node(kids: Vector[Node | string])&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Compiler messages print a union with its aliases expanded and its members flattened, in the order
they were written: &lt;code&gt;int | long | string&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;unions-are-written-never-inferred&quot;&gt;Unions are written, never inferred&lt;/h2&gt;
&lt;p&gt;Inference never forms a union from values of different types. The branches of an &lt;code&gt;if&lt;/code&gt; and the arms
of a &lt;code&gt;match&lt;/code&gt; join as they always have, and two that agree on no type are an error, which now names
the union to declare where both are wanted:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val x = if ok then 1 else &amp;quot;none&amp;quot;
// error: the branches of this `if` agree on no type: `int` and `string`; to keep either, declare
// the type it yields, such as `int | string`

val y: int | string = if ok then 1 else &amp;quot;none&amp;quot; // each branch becomes the union
val zs: Vector[int | string] = [1, &amp;quot;two&amp;quot;, 3] // each element too
val w = (1: int | string)                      // an ascription writes it in place
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An &lt;a href=&quot;/spec/types/#type-ascription&quot;&gt;ascription&lt;/a&gt; writes the union where the value stands, as a
declared type does: &lt;code&gt;(n: int | string)&lt;/code&gt; is the member &lt;code&gt;n&lt;/code&gt; as the union, and &lt;code&gt;(u: int)&lt;/code&gt; of a union
&lt;code&gt;u&lt;/code&gt; is refused, since an ascription never narrows.&lt;/p&gt;
&lt;p&gt;The same holds for collection literals, generic calls and lambdas: &lt;code&gt;[1, &amp;quot;two&amp;quot;]&lt;/code&gt; is an error, and
&lt;code&gt;pair[T](a: T, b: T)&lt;/code&gt; called as &lt;code&gt;pair(1, &amp;quot;one&amp;quot;)&lt;/code&gt; is an error, not a &lt;code&gt;pair[int | string]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Inference does &lt;strong&gt;carry&lt;/strong&gt; a union it is given. A value already of a union type gives it as any type
is given: &lt;code&gt;val u2 = u&lt;/code&gt; is an &lt;code&gt;int | string&lt;/code&gt;, &lt;code&gt;Some(u)&lt;/code&gt; an &lt;code&gt;Option[int | string]&lt;/code&gt;, and &lt;code&gt;id(u)&lt;/code&gt; takes
&lt;code&gt;T = int | string&lt;/code&gt;. Where a union and one of its members meet, they join to the union, as a class
and its superclass join to the superclass: &lt;code&gt;if c then u else 3&lt;/code&gt; is an &lt;code&gt;int | string&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A type parameter that is a member of a union in a parameter’s type takes what the argument leaves
over once the other members are taken out:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;orText[T](x: T | string) -&amp;gt; string = …

orText(3)          // T = int
orText(&amp;quot;a&amp;quot;)        // `string` is a member already: T is not decided here, and with nothing else
                   // to decide it the call is an error naming `T`
orText(u)          // u: int | bool | string, so T = int | bool
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;making-a-union-value&quot;&gt;Making a union value&lt;/h2&gt;
&lt;p&gt;A value becomes a union value where a union is expected of it, at a single site, as a value becomes
an &lt;code&gt;Any&lt;/code&gt;: an argument, a binding, an assignment, a field, a result, a part of a tuple written out,
each branch of an &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; expected to yield the union, each element of a collection literal,
and a field given in &lt;a href=&quot;/spec/declarations/#changing-fields-with&quot;&gt;&lt;code&gt;with { … }&lt;/code&gt;&lt;/a&gt;. This is the
&lt;strong&gt;injection&lt;/strong&gt; of the value into the member it belongs to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A value whose type is a member is that member.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Otherwise it is the one member its type converts to: a &lt;code&gt;Dog&lt;/code&gt; given to an &lt;code&gt;Animal | int&lt;/code&gt; is the
&lt;code&gt;Animal&lt;/code&gt;, and a &lt;code&gt;(string, int)&lt;/code&gt; given to &lt;code&gt;(Any, int) | bool&lt;/code&gt; is the tuple.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A value that converts to several members is an error naming them, since the program has to say
which one it means:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val p: Named | Pet = Parrot(&amp;quot;polly&amp;quot;)
// error: a `Parrot` is both a `Named` and a `Pet`, so it could be either member of
// `Named | Pet`; give it the type you mean first, as in `val n: Named = …`
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An integer or real literal is its own default type where that is a member (&lt;code&gt;int&lt;/code&gt;, then &lt;code&gt;long&lt;/code&gt;
for a literal too large for &lt;code&gt;int&lt;/code&gt;; &lt;code&gt;real&lt;/code&gt;), otherwise the one numeric member it fits; where it
fits several and its default is none of them, the error names them:
&lt;code&gt;val n: byte | long = 3&lt;/code&gt; is an error, and &lt;code&gt;val m: int | long = 3&lt;/code&gt; is the &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;None&lt;/code&gt;, an empty collection literal and &lt;code&gt;Ok(x)&lt;/code&gt; take their type from the member they are given to,
where exactly one member is an instance of their type: &lt;code&gt;val o: Option[int] | string = None&lt;/code&gt; is an
&lt;code&gt;Option[int]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A union value given where a wider union is expected is the same value in the wider union:
&lt;code&gt;int | string&lt;/code&gt; converts to &lt;code&gt;int | string | bool&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A value of another union converts only where each of its members converts to a member of the
target.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A value already made converts only where it already has the target’s layout, as
&lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;&lt;code&gt;Any&lt;/code&gt;&lt;/a&gt; does: see &lt;a href=&quot;#representation&quot;&gt;representation&lt;/a&gt;. A
&lt;code&gt;Vector[Dog]&lt;/code&gt; is a &lt;code&gt;Vector[Dog | Cat]&lt;/code&gt; with no conversion, and a &lt;code&gt;Vector[int]&lt;/code&gt; is not a
&lt;code&gt;Vector[int | string]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Overloads.&lt;/strong&gt; A union parameter accepts every value that injects into it, and an overload whose
parameter is the argument’s own type is more specific than one taking a union it belongs to, just as
it is more specific than one taking a trait. A union is more specific than any type its members all
convert to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;show(n: int) -&amp;gt; string = &amp;quot;int&amp;quot;
show(x: int | string) -&amp;gt; string = &amp;quot;int or string&amp;quot;
show(x: Any) -&amp;gt; string = &amp;quot;any&amp;quot;

show(1)            // int
show(&amp;quot;a&amp;quot;)          // int or string
show(true)         // any
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Two unions neither of which converts to the other leave a call ambiguous where the argument fits
both: with &lt;code&gt;f(x: int | string)&lt;/code&gt; and &lt;code&gt;f(x: int | bool)&lt;/code&gt;, &lt;code&gt;f(1)&lt;/code&gt; is an error listing them, and
&lt;code&gt;f(u)&lt;/code&gt; with &lt;code&gt;u: int | string&lt;/code&gt; calls the first. A union argument does not choose among overloads of
its members: &lt;code&gt;width(n: int)&lt;/code&gt; and &lt;code&gt;width(s: string)&lt;/code&gt; called with an &lt;code&gt;int | string&lt;/code&gt; is an error, since
overloads are chosen while compiling and the member is known only while running; the message
suggests a &lt;code&gt;match&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;References to named functions.&lt;/strong&gt; A named function or method written where a function type is
expected whose parameters inject into its union parameters is made at that site as a function that
injects them, as a lambda would be: &lt;code&gt;val f: (int) -&amp;gt; string = describe&lt;/code&gt; with
&lt;code&gt;describe(x: int | string)&lt;/code&gt;. A function value already made converts only where its layout already
fits, by the variance of &lt;a href=&quot;/spec/generics/#variance&quot;&gt;function types&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;subtyping&quot;&gt;Subtyping&lt;/h2&gt;
&lt;p&gt;A union takes part in subtyping by its members:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;A &amp;lt;: A | B&lt;/code&gt;&lt;/strong&gt;: a member converts to the union.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;A | B&lt;/code&gt; converts to &lt;code&gt;C&lt;/code&gt; exactly when each member does&lt;/strong&gt;: &lt;code&gt;Dog | Cat&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;int | long&lt;/code&gt;
an &lt;code&gt;Any&lt;/code&gt;, and &lt;code&gt;int | string&lt;/code&gt; a &lt;code&gt;Display&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;A | B&lt;/code&gt; converts to &lt;code&gt;C | D&lt;/code&gt; exactly when each member converts to a member of &lt;code&gt;C | D&lt;/code&gt;.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Through generics, variance holds where the layouts agree&lt;/strong&gt;, as the
&lt;a href=&quot;/spec/generics/#variance&quot;&gt;variance rules&lt;/a&gt; already say for &lt;code&gt;Any&lt;/code&gt;: where every member of the union
is a type an &lt;code&gt;Any&lt;/code&gt; holds without a box (a string, a tuple, a function, a data type, a class, a
trait or &lt;code&gt;Any&lt;/code&gt;), the union is laid out as an &lt;code&gt;Any&lt;/code&gt; is, and a covariant argument converts through it
with no conversion: &lt;code&gt;List[Dog] &amp;lt;: List[Dog | Cat]&lt;/code&gt;, &lt;code&gt;Option[Dog | Cat] &amp;lt;: Option[Animal]&lt;/code&gt;,
&lt;code&gt;Result[T, IoError] &amp;lt;: Result[T, IoError | ParseError]&lt;/code&gt;. A union with a member that would need a box
(a number, a &lt;code&gt;char&lt;/code&gt;, a &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;) is a value laid out by its tag, so &lt;code&gt;List[int]&lt;/code&gt; is not a
&lt;code&gt;List[int | string]&lt;/code&gt;, nor is a &lt;code&gt;List[int | string]&lt;/code&gt; a &lt;code&gt;List[int | string | bool]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Function types&lt;/strong&gt; follow the same terms: &lt;code&gt;(Dog | Cat) -&amp;gt; int&lt;/code&gt; is a &lt;code&gt;(Dog) -&amp;gt; int&lt;/code&gt;, and
&lt;code&gt;() -&amp;gt; Dog&lt;/code&gt; a &lt;code&gt;() -&amp;gt; Dog | Cat&lt;/code&gt;; &lt;code&gt;(int | string) -&amp;gt; int&lt;/code&gt; is not an &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt; as a value already
made, though a named function is made into one where it is written, as above.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;taking-a-union-apart&quot;&gt;Taking a union apart&lt;/h2&gt;
&lt;h3 id=&quot;match&quot;&gt;match&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; on a union value takes it apart by type, and must cover every member. A type pattern
covers a member when every value of the member matches it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Token(text: string)

render(v: int | string | Token) -&amp;gt; string = v match
  n: int -&amp;gt; s&amp;quot;$n&amp;quot;
  s: string -&amp;gt; s
  Token(t) -&amp;gt; t
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type patterns&lt;/strong&gt; test the member, as they test any value: &lt;code&gt;n: int&lt;/code&gt;, &lt;code&gt;_: string&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A supertype of a member&lt;/strong&gt; covers that member: &lt;code&gt;a: Animal&lt;/code&gt; on a &lt;code&gt;Dog | int&lt;/code&gt; covers the &lt;code&gt;Dog&lt;/code&gt; and
binds it as an &lt;code&gt;Animal&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A subtype of a member&lt;/strong&gt; covers part of it, by the usual rules for that type: &lt;code&gt;d: Dog&lt;/code&gt; on an
&lt;code&gt;Animal | int&lt;/code&gt; needs another arm for the rest of the animals.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A sub-union pattern&lt;/strong&gt; covers each member it names and binds the smaller union:
&lt;code&gt;x: (int | string) -&amp;gt; …&lt;/code&gt; on an &lt;code&gt;int | string | bool&lt;/code&gt; leaves the &lt;code&gt;bool&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Any other pattern applies to the one member it can match.&lt;/strong&gt; A literal, a range, a comparison
pattern, a constructor, a list or sequence pattern, a tuple and an extractor are each checked
against the member they belong to, and count toward covering that member alone:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;sign(v: int | string) -&amp;gt; string = v match
  n &amp;lt; 0 -&amp;gt; &amp;quot;negative&amp;quot; // the int member
  0 -&amp;gt; &amp;quot;zero&amp;quot;
  _: int -&amp;gt; &amp;quot;positive&amp;quot;
  &amp;quot;&amp;quot; -&amp;gt; &amp;quot;empty&amp;quot; // the string member
  _: string -&amp;gt; &amp;quot;text&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A pattern that more than one member could match is an error that names them and suggests a type
pattern first: &lt;code&gt;Some(x)&lt;/code&gt; on an &lt;code&gt;Option[int] | Option[string]&lt;/code&gt; must be written
&lt;code&gt;o: Option[int]&lt;/code&gt; and matched again, or &lt;code&gt;Some(n: int)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A type pattern that names no member and no type a member could hold&lt;/strong&gt; is an error, as a type
pattern that can never match is on any value:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;v match
  b: bool -&amp;gt; … // error: `bool` is no member of `int | string`, so this pattern can never
  // match
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;_&lt;/code&gt; and a bare binding&lt;/strong&gt; cover every member; a binding binds the union.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; that leaves a member uncovered names one value it leaves out, as a pattern:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;kind(v: int | string | bool) -&amp;gt; string = v match
  _: int -&amp;gt; &amp;quot;int&amp;quot;
  _: string -&amp;gt; &amp;quot;string&amp;quot;
// error: this `match` does not cover every `int | string | bool` value, such as `_: bool`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unreachable arms are errors as anywhere: &lt;code&gt;_: int&lt;/code&gt; after an arm that already covered the int member.
Where a union of reference members holds a value that two arms’ types both match (a &lt;code&gt;Parrot&lt;/code&gt; in a
&lt;code&gt;Named | Pet&lt;/code&gt;, tested by &lt;code&gt;n: Named&lt;/code&gt; and then &lt;code&gt;p: Pet&lt;/code&gt;), the first arm in order takes it, as for any
value; the program cannot tell which member the value was made as, and need not.&lt;/p&gt;
&lt;p&gt;A function’s &lt;a href=&quot;/spec/declarations/#clauses&quot;&gt;clauses&lt;/a&gt; take a union parameter apart the same way, each
clause naming a member:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;size(x: int | string) -&amp;gt; int
size(n: int) = n
size(s: string) = s.charCount
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;is&quot;&gt;is&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;x is P&lt;/code&gt; tests a union value against any pattern a &lt;code&gt;match&lt;/code&gt; arm takes, and binds the names &lt;code&gt;P&lt;/code&gt; binds
where the test is known to have matched, as &lt;a href=&quot;/spec/operators-and-control-flow/#is&quot;&gt;&lt;code&gt;is&lt;/code&gt;&lt;/a&gt; does on any
value:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;lengthOf(v: int | string) -&amp;gt; int
  if v is s: string then return s.charCount
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The union value itself keeps its type: &lt;code&gt;if v is _: string then v.charCount&lt;/code&gt; is an error, since &lt;code&gt;v&lt;/code&gt;
is still an &lt;code&gt;int | string&lt;/code&gt;; the pattern binds the narrower value to a name of its own.&lt;/p&gt;
&lt;h3 id=&quot;generic-members&quot;&gt;Generic members&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; in generic code is checked once, where it is written, against the union as written:
&lt;code&gt;T | int&lt;/code&gt; is two members there, and an arm for each is required. At an instance where the members
come together (&lt;code&gt;T = int&lt;/code&gt;), each value is matched by the first arm whose pattern it fits, so the arm
for &lt;code&gt;T&lt;/code&gt; takes every &lt;code&gt;int&lt;/code&gt; and the arm for &lt;code&gt;int&lt;/code&gt; is never reached at that instance, which is no error.&lt;/p&gt;
&lt;p&gt;At such an instance the union is its one member’s type, with that type’s layout and nothing of a
union’s: &lt;code&gt;build[T](x: T) -&amp;gt; Vector[T | int] = [x, 7]&lt;/code&gt; at &lt;code&gt;T = int&lt;/code&gt; makes a &lt;code&gt;Vector[int]&lt;/code&gt; of plain
&lt;code&gt;int&lt;/code&gt;s, &lt;code&gt;T | real&lt;/code&gt; at &lt;code&gt;T = real&lt;/code&gt; is returned as a &lt;code&gt;real&lt;/code&gt;, and &lt;code&gt;T | string&lt;/code&gt; at &lt;code&gt;T = string&lt;/code&gt; is a
string. A value of it is the same value seen as an &lt;code&gt;Any&lt;/code&gt;, so &lt;code&gt;build[int](3)&lt;/code&gt; as an &lt;code&gt;Any&lt;/code&gt; matches
&lt;code&gt;Vector[int]&lt;/code&gt;. A union that keeps more than one member at the instance (&lt;code&gt;T | int | string&lt;/code&gt; at
&lt;code&gt;T = int&lt;/code&gt;, which is &lt;code&gt;int | string&lt;/code&gt;) keeps a union’s layout, of those members.&lt;/p&gt;
&lt;h2 id=&quot;what-a-union-value-can-do&quot;&gt;What a union value can do&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Equality and hashing.&lt;/strong&gt; Every union compares with &lt;code&gt;==&lt;/code&gt; and hashes, since every type does
(see &lt;a href=&quot;/spec/equality-and-memory/#equality&quot;&gt;equality&lt;/a&gt;). Two union values are compared as two &lt;code&gt;Any&lt;/code&gt;s
holding them would be: values of the same member compare as that member does, by value or by its own
&lt;code&gt;Eq&lt;/code&gt;, and values of different members are unequal, with the sequence exception &lt;code&gt;Any&lt;/code&gt; has. The hash is
the member value’s own. So &lt;code&gt;Set[int | string]&lt;/code&gt; holds &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;&amp;quot;1&amp;quot;&lt;/code&gt; apart, and an &lt;code&gt;int | long&lt;/code&gt; holding
&lt;code&gt;int&lt;/code&gt; 1 is not equal to one holding &lt;code&gt;long&lt;/code&gt; 1. &lt;code&gt;a == b&lt;/code&gt; with &lt;code&gt;a&lt;/code&gt; a union and &lt;code&gt;b&lt;/code&gt; a member’s value
injects &lt;code&gt;b&lt;/code&gt; first; a &lt;code&gt;b&lt;/code&gt; that is no member is an error, as comparing two types with no common type is.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Identity.&lt;/strong&gt; &lt;code&gt;===&lt;/code&gt; is defined where every member is a class or a function type; a union with any
other member may hold a value with no identity, and is an error with the same message
&lt;a href=&quot;/spec/equality-and-memory/#identity&quot;&gt;identity&lt;/a&gt; gives an &lt;code&gt;Any&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Traits a union conforms to.&lt;/strong&gt; A union conforms to a trait when every member does and the trait’s
methods take &lt;code&gt;Self&lt;/code&gt; only as their receiver: no parameter, result or static member of type &lt;code&gt;Self&lt;/code&gt;.
&lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt; and a library’s &lt;code&gt;JsonEncoder&lt;/code&gt; are such traits; a call through one runs the
member’s own method. So &lt;code&gt;println(u)&lt;/code&gt; writes the member as it would write it alone (&lt;code&gt;3&lt;/code&gt;, &lt;code&gt;two&lt;/code&gt;),
&lt;code&gt;debug(u)&lt;/code&gt; its debug form (&lt;code&gt;&amp;quot;two&amp;quot;&lt;/code&gt;), and a &lt;code&gt;[T: Display]&lt;/code&gt; takes &lt;code&gt;T = int | string&lt;/code&gt;. &lt;code&gt;Eq&lt;/code&gt; takes
&lt;code&gt;Self&lt;/code&gt; as a parameter, and a union has it by the rule above. &lt;code&gt;Ord&lt;/code&gt; does not hold: a union has no order
between its members, and sorting a &lt;code&gt;Vector[int | string]&lt;/code&gt; is an error saying so. &lt;code&gt;Sendable&lt;/code&gt; holds where
every member is sendable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Member calls.&lt;/strong&gt; &lt;code&gt;u.m(args)&lt;/code&gt; on a union is looked up where it would be on the members’ join, the
type the branches of an &lt;code&gt;if&lt;/code&gt; yielding each member agree on, and in the traits the union conforms to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;pet(a: Dog | Cat) -&amp;gt; string = a.name()        // Dog and Cat join to Animal, which has `name`
shown(v: int | string) -&amp;gt; string = v.toString()     // Display
v.charCount
// error: `int | string` has no member `charCount`: its members share no type that has one; take it
// apart with a `match` or `is` first
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A name found on more than one of those types is an error that names them. A trait with type
parameters counts through the one instance every member holds: &lt;code&gt;Vector[int] | List[int]&lt;/code&gt; has
&lt;code&gt;Seq[int]&lt;/code&gt;‘s &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt;. What is found is called, named as a value, or, for a field of the join
class, read, with the union seen as that type, as an &lt;code&gt;Any&lt;/code&gt; holding its member is.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Derivations.&lt;/strong&gt; A data type or class with a union field derives &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;
as with any field. &lt;code&gt;derives Ord&lt;/code&gt; is an error naming the field, as for any field type without &lt;code&gt;Ord&lt;/code&gt;. A
&lt;a href=&quot;/spec/derivation/#derive-templates&quot;&gt;derive template&lt;/a&gt; sees a union field as a field of that type, and
needs the union to meet its bound, as above.&lt;/p&gt;
&lt;h2 id=&quot;errors-and&quot;&gt;Errors and &lt;code&gt;?&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A function may declare a union of errors, and &lt;a href=&quot;/spec/errors/#the-operator&quot;&gt;&lt;code&gt;?&lt;/code&gt;&lt;/a&gt; passes each kind on
without a wrapper type:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;load(path: string) -&amp;gt; Result[Config, IoError | ParseError]
  val text = readText(path)? // Result[string, IoError]
  val doc = parseDocument(text)? // Result[Document, ParseError]
  configOf(doc) // Result[Config, ParseError], converted as a result
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On &lt;code&gt;Err(e)&lt;/code&gt;, with &lt;code&gt;e&lt;/code&gt; of type &lt;code&gt;E&lt;/code&gt; and the enclosing function yielding errors of &lt;code&gt;F&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Where &lt;code&gt;E&lt;/code&gt; converts to &lt;code&gt;F&lt;/code&gt;, &lt;code&gt;e&lt;/code&gt; is passed on as an &lt;code&gt;F&lt;/code&gt;.&lt;/strong&gt; This is the existing rule’s “&lt;code&gt;E&lt;/code&gt; is an
&lt;code&gt;F&lt;/code&gt;“, widened to the conversions above: &lt;code&gt;E&lt;/code&gt; a member of the union &lt;code&gt;F&lt;/code&gt;, a subtype of a member, or
itself a union every member of which converts to a member of &lt;code&gt;F&lt;/code&gt; (a &lt;code&gt;Result[_, IoError | ParseError]&lt;/code&gt;
inside a function yielding &lt;code&gt;IoError | ParseError | Invalid&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Otherwise, where &lt;code&gt;F&lt;/code&gt; is a union, the one member of &lt;code&gt;F&lt;/code&gt; that implements &lt;code&gt;From[E]&lt;/code&gt;&lt;/strong&gt; makes the
error passed on: with &lt;code&gt;F = ConfigError | NetError&lt;/code&gt; and &lt;code&gt;impl From[IoError] for ConfigError&lt;/code&gt;, an
&lt;code&gt;IoError&lt;/code&gt; becomes a &lt;code&gt;ConfigError&lt;/code&gt;. Two members implementing it is an error naming both.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Otherwise, where &lt;code&gt;E&lt;/code&gt; is a union, each member of &lt;code&gt;E&lt;/code&gt; is converted on its own&lt;/strong&gt; by rules 1 and 2
and the existing &lt;code&gt;From&lt;/code&gt; rule, and the error names each member with no conversion:
&lt;code&gt;Result[_, IoError | ParseError]&lt;/code&gt; inside a function yielding &lt;code&gt;ConfigError&lt;/code&gt;, which implements
&lt;code&gt;From[IoError]&lt;/code&gt; and &lt;code&gt;From[ParseError]&lt;/code&gt;, converts each kind through its own &lt;code&gt;from&lt;/code&gt;; inside one
yielding &lt;code&gt;ConfigError | Invalid&lt;/code&gt;, each kind becomes a &lt;code&gt;ConfigError&lt;/code&gt; by rule 2.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Otherwise the existing rule applies&lt;/strong&gt;: &lt;code&gt;F.from(e)&lt;/code&gt; through &lt;code&gt;F&lt;/code&gt;‘s &lt;code&gt;From[E]&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;fetch(url: Url) -&amp;gt; Result[Page, NetError]

load(path: string) -&amp;gt; Result[Config, IoError | ParseError]
  val page = fetch(url)?
// error: `?` cannot pass on a `NetError` from a function whose errors are `IoError | ParseError`:
// it is no member of the union, and no member implements `From[NetError]`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A union has no &lt;code&gt;impl&lt;/code&gt;, so it never implements &lt;code&gt;From&lt;/code&gt; itself: an error union is widened by naming the
new member in the result type, not by writing a conversion.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Result&lt;/code&gt; already made converts to a wider error union with no conversion where both are laid out
as an &lt;code&gt;Any&lt;/code&gt; is (every error a data type or a class, which is the common case): a
&lt;code&gt;Result[T, IoError]&lt;/code&gt; returned from a function yielding &lt;code&gt;Result[T, IoError | ParseError]&lt;/code&gt; is that
result. Where an error member is a number or another scalar, the result is rebuilt by
&lt;code&gt;r.mapErr(e -&amp;gt; e)&lt;/code&gt;, whose lambda’s result injects.&lt;/p&gt;
&lt;p&gt;The function’s error union is the one its result type declares; &lt;code&gt;?&lt;/code&gt; never adds a member to it. A
function whose result type is inferred cannot use &lt;code&gt;?&lt;/code&gt;, as before.&lt;/p&gt;
&lt;h2 id=&quot;representation&quot;&gt;Representation&lt;/h2&gt;
&lt;p&gt;A union is an anonymous tagged sum, and how it is laid out is the compiler’s choice, invisible except
in cost. The layout is decided by the type alone, before any optimization, so a program behaves the
same at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every member a type an &lt;code&gt;Any&lt;/code&gt; holds without a box&lt;/strong&gt; (strings, tuples, functions, data types,
classes, traits, &lt;code&gt;Any&lt;/code&gt;): the union is one pointer, laid out exactly as an &lt;code&gt;Any&lt;/code&gt; holding the member.
The tag is the object’s header, which names its exact type, so injecting a value costs what
converting it to an &lt;code&gt;Any&lt;/code&gt; costs, a &lt;code&gt;match&lt;/code&gt; is the type tests it would be on an &lt;code&gt;Any&lt;/code&gt;, and such a
union nests in covariant containers with no conversion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Any member a scalar&lt;/strong&gt; (a number, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;): the union is a value of a tag and a
payload. The tag says which scalar member it holds, or that it holds a reference, whose header then
names its type. The scalar’s bits and the reference are kept in slots of their own, so the
collector’s roots stay exact: the reference slot holds a pointer or nothing, never a number. A
union of scalars alone has no reference slot. Injecting a scalar writes the tag and the bits, and
allocates nothing; neither does passing the union, returning it, matching it, comparing it with
&lt;code&gt;==&lt;/code&gt;, hashing it or showing it, each of which reads the tag. Seen as an &lt;code&gt;Any&lt;/code&gt; or as a trait, a
scalar member is boxed there, as any scalar is.&lt;/li&gt;
&lt;li&gt;The tag numbering is fixed by the normal form, not by the order written, so &lt;code&gt;int | string&lt;/code&gt; and
&lt;code&gt;string | int&lt;/code&gt; are one layout.&lt;/li&gt;
&lt;li&gt;An integer member wider than 64 bits does not fit the bits slot: the union keeps it boxed in its
reference slot, as it keeps a reference, so &lt;code&gt;i128 | int&lt;/code&gt; has a reference slot and injecting an
&lt;code&gt;i128&lt;/code&gt; allocates its box. Every bit of it is kept.&lt;/li&gt;
&lt;li&gt;Wherever a union with a scalar member is stored, it is stored as its slots: a field of a data
type, a class or a tuple, an element of an &lt;code&gt;Array&lt;/code&gt; (and so of a &lt;code&gt;Vector&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt; or a map), a
closure’s captures, a captured &lt;code&gt;var&lt;/code&gt;, a module-level value and an actor’s message. Storing one and
reading it back allocates nothing, and the collector traces its reference slot and never the tag
or the bits. The one exception is &lt;code&gt;Atomic&lt;/code&gt;, whose value is one word its operations read and write
indivisibly: an &lt;code&gt;Atomic&lt;/code&gt; of such a union holds a reference to an object of its slots.&lt;/li&gt;
&lt;li&gt;Generic code is compiled per instance, as all generic code is, so &lt;code&gt;Vector[T | int]&lt;/code&gt; at &lt;code&gt;T = string&lt;/code&gt;
stores &lt;code&gt;string | int&lt;/code&gt; values in the vector’s own elements, unboxed, and at &lt;code&gt;T = int&lt;/code&gt; stores &lt;code&gt;int&lt;/code&gt;s.&lt;/li&gt;
&lt;li&gt;A union in a heap field, an array element or a module-level &lt;code&gt;var&lt;/code&gt; is several words, so, as with
an integer wider than 64 bits, a racing read may combine the words of two writes (see
&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;). It still reads as a value of one of the members: the tag is believed
to name a reference only beside a reference, so a racing read never gives a reference that no
write stored.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-is-refused&quot;&gt;What is refused&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A union is never inferred&lt;/strong&gt; (above).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No &lt;code&gt;impl&lt;/code&gt; names a union&lt;/strong&gt;, and no extension: an &lt;code&gt;impl&lt;/code&gt; names a declared type.
&lt;code&gt;impl Display for int | string&lt;/code&gt; is an error: &lt;code&gt;an `impl` names a declared type, and `int | string` is a union; declare a data type to give it methods&lt;/code&gt;. An alias of a union is
refused the same way, as any alias is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union is no parent&lt;/strong&gt;: a class or trait cannot list &lt;code&gt;A | B&lt;/code&gt; after &lt;code&gt;:&lt;/code&gt;: &lt;code&gt;a union is no parent: a class or trait lists a class and traits after `:`, and `A | B` is a union&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union is no bound&lt;/strong&gt;: &lt;code&gt;[T: A | B]&lt;/code&gt; is an error, since a bound is a trait: &lt;code&gt;a bound is a trait or a class, and `A | B` is a union&lt;/code&gt;; &lt;code&gt;[T &amp;gt;: A | B]&lt;/code&gt;, a lower bound, is a type and is allowed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union does not cross a binding.&lt;/strong&gt; A parameter, result or field of an &lt;code&gt;@sysl&lt;/code&gt; or &lt;code&gt;@c&lt;/code&gt;
declaration, or of a mirror, may not be a union: &lt;code&gt;`int | string` cannot cross a binding: a union has no Sysl or C type; bind one function per member, or pass a data type&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field path does not go through a union&lt;/strong&gt; in &lt;code&gt;with { … }&lt;/code&gt;: with &lt;code&gt;v: A | B&lt;/code&gt;, &lt;code&gt;p with { v.x = 1 }&lt;/code&gt;
is an error saying &lt;code&gt;v&lt;/code&gt; is a union, to be taken apart with a &lt;code&gt;match&lt;/code&gt; first. Replacing the whole field,
&lt;code&gt;p with { v = 1 }&lt;/code&gt;, injects as any value does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No member is reached without a test&lt;/strong&gt;: there is no cast, and a union is not callable as a
function (&lt;code&gt;a union is not called: `((int) -&amp;gt; int) | string` may hold a value that is no function; take it apart with a `match` first&lt;/code&gt;), constructed, or used as a companion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;derives&lt;/code&gt; and annotations&lt;/strong&gt; have nowhere to go on a union: it is not declared, and an alias takes
none.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intersection types&lt;/strong&gt; (&lt;code&gt;A &amp;amp; B&lt;/code&gt;) are not part of Avin.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>User interfaces</title>
    <link href="https://avinlang.dev/spec/ui/"/>
    <id>https://avinlang.dev/spec/ui/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>The ui package — syslui&apos;s views, controls and signals, and syslui-sdl&apos;s window and frame loop, bound for Avin; drawing and tapping a tree with no window.</summary>
    <content type="html">&lt;p&gt;A program with a window reaches it through the &lt;strong&gt;&lt;code&gt;ui&lt;/code&gt; package&lt;/strong&gt;, which binds two Sysl packages:
&lt;strong&gt;syslui&lt;/strong&gt;, which lays a tree of views out, paints it, measures its text and routes its events, and
&lt;strong&gt;syslui-sdl&lt;/strong&gt;, which opens the window, runs the frame loop and turns the platform’s events into
syslui’s. The package is a thin binding: every view, control and signal in it is syslui’s own,
reached through &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;handles&lt;/a&gt;, and its functions are syslui’s under Avin’s
names. On it stands a layer written in Avin, &lt;a href=&quot;#components-and-state&quot;&gt;components and state&lt;/a&gt;: an
interface built by functions from state the program keeps, and built again when the state changes.&lt;/p&gt;
&lt;p&gt;The package lives in this repository at &lt;code&gt;packages/ui&lt;/code&gt;, its module is &lt;code&gt;ui&lt;/code&gt;, and a program names it as
a dependency:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;dependencies {
  ui { path = &amp;quot;../../packages/ui&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It names &lt;code&gt;syslui-sdl&lt;/code&gt; 0.2.33 in its own &lt;code&gt;sysl-dependencies&lt;/code&gt;, which brings syslui 0.2.6 and SDL3,
so a program using it names no Sysl package itself, and is linked with SDL3.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import ui.{View, app, button, column, invalidate, run, text}

var count = 0

add()
  count += 1
  invalidate()

screen() -&amp;gt; View = column([text(s&amp;quot;$count&amp;quot;), button(&amp;quot;Add one&amp;quot;, add)], 16)

main() -&amp;gt; int = run(app(&amp;quot;Counter&amp;quot;, screen, () -&amp;gt; 0x1E1E2E)) match
  Ok(_) -&amp;gt; 0
  Err(_) -&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;views&quot;&gt;Views&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;View&lt;/code&gt; is a handle on syslui’s &lt;code&gt;View&lt;/code&gt; trait: whatever view a binding answered, a leaf, a container
or a modifier wrapping another. Each modifier answers a new view wrapping its receiver, so a chain
reads from the innermost view out: &lt;code&gt;text(&amp;quot;hi&amp;quot;).padding(8).panel()&lt;/code&gt; is a padded label on a surface.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;View&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;text(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One run of text; Unicode is measured and drawn whole&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;spacer()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A gap taking one share of what its column or row has left over&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;column(children, spacing = 0)&lt;/code&gt;, &lt;code&gt;row(children, spacing = 0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Children top to bottom, or left to right, &lt;code&gt;spacing&lt;/code&gt; apart; &lt;code&gt;children&lt;/code&gt; is a &lt;code&gt;Vector[View]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;grid(children)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Children on a grid of columns, each spanning what its &lt;code&gt;cell&lt;/code&gt; says, the whole width without one&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scroll(child, offset, height)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;child&lt;/code&gt; in a window &lt;code&gt;height&lt;/code&gt; tall, scrolled down by an &lt;code&gt;IntSignal&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;divider(thickness = 1)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A line across its container&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Modifier&lt;/th&gt;&lt;th&gt;Effect&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;padding(n)&lt;/code&gt;, &lt;code&gt;pad(top, right, bottom, left)&lt;/code&gt; (each defaulting to 0), &lt;code&gt;padded()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Inset on every side, on the sides named, or by the theme’s padding&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;panel()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;On a surface the theme draws&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;background(color, radius = 0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The rectangle behind it filled with a &lt;a href=&quot;#colours&quot;&gt;colour&lt;/a&gt;, its corners rounded by &lt;code&gt;radius&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;border(color, width = 1, radius = 0, dash = 0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Outlined &lt;code&gt;width&lt;/code&gt; thick inside the rectangle it was given, so nothing moves; dashes &lt;code&gt;dash&lt;/code&gt; long where &lt;code&gt;dash&lt;/code&gt; is not 0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;foreground(color)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text inside drawn in &lt;code&gt;color&lt;/code&gt;; the innermost one in force wins&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tinted(color)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The controls inside in &lt;code&gt;color&lt;/code&gt; where they name no &lt;code&gt;Role&lt;/code&gt;: the theme’s primary colour&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textStyle(style)&lt;/code&gt;, &lt;code&gt;fontSize(pt)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text inside at one of the theme’s sizes (&lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Title&lt;/code&gt;, &lt;code&gt;Body&lt;/code&gt;, &lt;code&gt;Caption&lt;/code&gt;), or at &lt;code&gt;pt&lt;/code&gt; points&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;frame(w, h)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Exactly &lt;code&gt;w&lt;/code&gt; by &lt;code&gt;h&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flex(n = 1)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;n&lt;/code&gt; shares of a column’s leftover height or a row’s leftover width; the last link of a chain&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cell(span, offset = 0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;span&lt;/code&gt; of a grid’s columns after skipping &lt;code&gt;offset&lt;/code&gt;; the last link of a chain&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;onTap(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Calls &lt;code&gt;f&lt;/code&gt; when tapped&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;named(name)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A name a snapshot reports and a tap by key finds; nothing is drawn differently&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;weight()&lt;/code&gt; answers the shares a view asks of its container’s leftover: 0 for a leaf and any modifier
but &lt;code&gt;flex&lt;/code&gt;, 1 for a spacer and &lt;code&gt;n&lt;/code&gt; for &lt;code&gt;flex(n)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A view’s children cross into syslui as &lt;a href=&quot;/spec/sysl-bindings/#collections-of-handles&quot;&gt;a collection of handles&lt;/a&gt;:
each is shared for the call, so one view may be the child of several containers, and a container
outlives the vector it was made from. A view closed with &lt;code&gt;close()&lt;/code&gt; and then given to a container
stops the program at the call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `View` is closed at main.avin:11:13
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;colours&quot;&gt;Colours&lt;/h3&gt;
&lt;p&gt;A colour is an &lt;code&gt;int&lt;/code&gt; holding &lt;code&gt;0xRRGGBB&lt;/code&gt;, as syslui draws it, so a hex literal is one: there is no
alpha, since nothing in syslui composites. syslui takes it as a &lt;code&gt;u32&lt;/code&gt;, which an Avin &lt;code&gt;int&lt;/code&gt; reaches as
any &lt;a href=&quot;/spec/sysl-bindings/#integer-parameters&quot;&gt;integer parameter&lt;/a&gt; does, converted with a check: a
negative colour stops the program where the modifier was called.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: value out of range for u32 at main.avin:11:12
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Colour&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;rgb(r, g, b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Of the channels &lt;code&gt;r&lt;/code&gt;, &lt;code&gt;g&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, each from 0 to 255; a channel outside that range stops the program&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;mix(a, b, pct)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;a&lt;/code&gt; moved toward &lt;code&gt;b&lt;/code&gt; by &lt;code&gt;pct&lt;/code&gt; percent, channel by channel; a percentage outside 0 to 100 is taken as the nearer end&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lighten(c, pct)&lt;/code&gt;, &lt;code&gt;darken(c, pct)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;c&lt;/code&gt; moved toward white, or black, by &lt;code&gt;pct&lt;/code&gt; percent&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;text(&amp;quot;Saved&amp;quot;).foreground(0xFFFFFF).padding(8).background(darken(0x3E9B5F, 20), 6)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;controls&quot;&gt;Controls&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Control&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;button(label, onTap, role = Primary, variant = Filled)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Calls &lt;code&gt;onTap&lt;/code&gt; when tapped&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;switch(on, role)&lt;/code&gt;, &lt;code&gt;checkbox(on, label, role)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Flip a &lt;code&gt;BoolSignal&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;radio(chosen, at, label, role)&lt;/code&gt;, &lt;code&gt;radioGroup(labels, chosen, role, spacing = 6)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Make an &lt;code&gt;IntSignal&lt;/code&gt; hold an option’s index&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;slider(value, lo, hi, width, step, role, id)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Over an &lt;code&gt;IntSignal&lt;/code&gt; and &lt;code&gt;int&lt;/code&gt; bounds, or a &lt;code&gt;RealSignal&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt; bounds; a step of zero moves by one, or continuously&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;progress(fraction, width, role)&lt;/code&gt;, &lt;code&gt;meter(value, lo, hi, width, band, target, role)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Show a value; take no input&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textField(text, id, width, hint, onEnter, onEscape)&lt;/code&gt;, &lt;code&gt;textArea(text, id, width, rows, hint, onEscape)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Edit a &lt;code&gt;StringSignal&lt;/code&gt;, focused by a nonzero &lt;code&gt;id&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tabs(labels, chosen, body)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Headers over an &lt;code&gt;IntSignal&lt;/code&gt;, and the view &lt;code&gt;body&lt;/code&gt; answers for the chosen index&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;Role&lt;/code&gt; (&lt;code&gt;Primary&lt;/code&gt;, &lt;code&gt;Secondary&lt;/code&gt;, &lt;code&gt;Accent&lt;/code&gt;, &lt;code&gt;Success&lt;/code&gt;, &lt;code&gt;Warning&lt;/code&gt;, &lt;code&gt;Error&lt;/code&gt;) names which of the theme’s
colours a control takes, and &lt;code&gt;Variant&lt;/code&gt; (&lt;code&gt;Filled&lt;/code&gt;, &lt;code&gt;Outline&lt;/code&gt;, &lt;code&gt;Dashed&lt;/code&gt;, &lt;code&gt;Soft&lt;/code&gt;) how it wears it; both
are &lt;a href=&quot;/spec/sysl-bindings/#mirrors&quot;&gt;mirrors&lt;/a&gt; of syslui’s enums. Every callback a control is given runs
on the thread that runs the frame loop, the thread that called &lt;code&gt;run&lt;/code&gt;, so none is &lt;code&gt;@threaded&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;signals&quot;&gt;Signals&lt;/h2&gt;
&lt;p&gt;A control that holds a value reads and writes a &lt;strong&gt;signal&lt;/strong&gt;: a handle on one instance of syslui’s
&lt;code&gt;Signal[T]&lt;/code&gt;, made by &lt;code&gt;intSignal&lt;/code&gt;, &lt;code&gt;realSignal&lt;/code&gt;, &lt;code&gt;boolSignal&lt;/code&gt; or &lt;code&gt;stringSignal&lt;/code&gt; and read and written
with &lt;code&gt;read()&lt;/code&gt; and &lt;code&gt;set(v)&lt;/code&gt;. The four classes are &lt;code&gt;IntSignal&lt;/code&gt;, &lt;code&gt;RealSignal&lt;/code&gt;, &lt;code&gt;BoolSignal&lt;/code&gt; and
&lt;code&gt;StringSignal&lt;/code&gt;, one for each instance a control takes.&lt;/p&gt;
&lt;p&gt;A control writes the application’s own signal, the one the program made and holds, never a copy:
a tap’s write is read by the program at once, the next build of the tree shows it, and every other
control over the same signal shows it too. A signal outlives the views made over it, so a tree
built afresh each frame hands its controls the same signals each time:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val done = boolSignal(false)
val tree = () -&amp;gt; column([switch(done), checkbox(done, &amp;quot;Done&amp;quot;), text(s&amp;quot;done=${done.read()}&amp;quot;)])
// a tap on the switch: done.read() is true at once, and the next tree() shows the checkbox checked
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Work &lt;a href=&quot;#threads&quot;&gt;handed to the main thread&lt;/a&gt; and a control may both write one signal in a frame: the
work runs at the frame’s start and the control’s write comes after it, each is one write, and the
later is the value the build shows.&lt;/p&gt;
&lt;p&gt;Every &lt;code&gt;set&lt;/code&gt; is one write, whatever it writes, and &lt;code&gt;invalidate()&lt;/code&gt; is one more; &lt;code&gt;writes()&lt;/code&gt; answers how
many there have been. The frame loop builds the tree again on the frame after the count has moved,
so a program keeping its state in Avin variables changes them and calls &lt;code&gt;invalidate()&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;the-application&quot;&gt;The application&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;app(title, tree, ground, width = 900, height = 660)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An &lt;code&gt;App&lt;/code&gt;: the window’s title, the function building its tree, the function answering its colour, &lt;code&gt;0xRRGGBB&lt;/code&gt;, and its size in points. Nothing is opened&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;run(a)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Opens the window and runs the frame loop until the window is closed or &lt;code&gt;stop()&lt;/code&gt; is called; &lt;code&gt;Err&lt;/code&gt; holds SDL’s sentence where the window could not be made&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stop()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Ends the loop after the frame it is in&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setTitle(title)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Retitles the running window; &lt;code&gt;false&lt;/code&gt; with none&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;saveFrame(file)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes the next finished frame to a PNG file&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;run&lt;/code&gt; is &lt;code&gt;blocking&lt;/code&gt;: while the loop waits for events the thread is safe for the collector, and it is
running for each call of &lt;code&gt;tree&lt;/code&gt; and &lt;code&gt;ground&lt;/code&gt; and every control’s callback. A window runs on the
&lt;a href=&quot;/spec/threads/#lightweight-threads&quot;&gt;main thread&lt;/a&gt;, the operating system thread &lt;code&gt;main&lt;/code&gt; was called
on, which is never a lightweight thread; at the start of every frame the loop runs the
&lt;a href=&quot;#threads&quot;&gt;work other threads have handed it&lt;/a&gt;, and when the loop ends &lt;code&gt;run&lt;/code&gt; runs what is still
waiting before it returns. &lt;code&gt;ground&lt;/code&gt; answers a
&lt;code&gt;long&lt;/code&gt;, which Sysl takes as the &lt;code&gt;u32&lt;/code&gt; syslui asks for, &lt;a href=&quot;/spec/sysl-bindings/#callbacks&quot;&gt;checked&lt;/a&gt;: an
answer below 0 or past &lt;code&gt;0xFFFFFFFF&lt;/code&gt; stops the program.&lt;/p&gt;
&lt;p&gt;Only the account at the screen can open a window: &lt;code&gt;run&lt;/code&gt; from a process with no window session waits
for one for ever. A test draws with no window instead.&lt;/p&gt;
&lt;h2 id=&quot;drawing-with-no-window&quot;&gt;Drawing with no window&lt;/h2&gt;
&lt;p&gt;syslui’s &lt;strong&gt;recording canvas&lt;/strong&gt; lays a tree out against a fixed font, eight points a byte and sixteen
a line by default, and writes down every operation instead of drawing it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;recorder(charW = 8, lineH = 16, size = 16.0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A new recording canvas, which is also the pointer a test presses&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;render(v, c, at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lays &lt;code&gt;v&lt;/code&gt; out in the &lt;code&gt;Rect&lt;/code&gt; &lt;code&gt;at&lt;/code&gt; and draws it on &lt;code&gt;c&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.dump()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;What was drawn, one operation a line&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.point(x, y, down)&lt;/code&gt;, &lt;code&gt;c.release(x, y)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Moves the pointer, held or not, and lets it go; a press and a release in one control is a tap&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;snapshot(v, c, at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;Snapshot&lt;/code&gt; of what &lt;code&gt;v&lt;/code&gt; puts on screen: &lt;code&gt;len()&lt;/code&gt;, &lt;code&gt;dump()&lt;/code&gt;, &lt;code&gt;toJson()&lt;/code&gt;, and &lt;code&gt;clickPoint(key)&lt;/code&gt;, where to tap a control’s name or its reference &lt;code&gt;@n&lt;/code&gt;, or a &lt;code&gt;Missed&lt;/code&gt; saying why there is nowhere (&lt;code&gt;Unknown&lt;/code&gt;, &lt;code&gt;Duplicate&lt;/code&gt;, &lt;code&gt;Covered&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tap(v, key, at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Draws &lt;code&gt;v&lt;/code&gt; in &lt;code&gt;at&lt;/code&gt; on a new canvas and taps the control &lt;code&gt;key&lt;/code&gt; names, at the centre of what of it is shown, drawing a frame while the pointer is held so a slider moves to it&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A key no control on screen answers to, and a name two controls share, are &lt;code&gt;Err(Missed(…))&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Unknown: nothing on screen is called &apos;nothing&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;components-and-state&quot;&gt;Components and state&lt;/h2&gt;
&lt;p&gt;An interface is a function of the program’s state, built again whenever that state changes. The
state is held in &lt;strong&gt;&lt;code&gt;State[T]&lt;/code&gt;&lt;/strong&gt;, an Avin object holding a value of any type, made by &lt;code&gt;state(v)&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;get()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The value&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;set(v)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Replaces it; one write, which the frame loop builds again after&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;update(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;set(f(get()))&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A set is one write whatever it writes, the same value included, so nothing else is called after
one. A state of a reference holds the reference: changing the object in place is no write.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import ui.{View, button, column, component, root, text}

counter(step: int) -&amp;gt; View = component c -&amp;gt;
  val count = c.state(0)
  column([text(s&amp;quot;${count.get()}&amp;quot;), button(s&amp;quot;Add $step&amp;quot;, () -&amp;gt; count.update(n -&amp;gt; n + step))])
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;components&quot;&gt;Components&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;component&lt;/strong&gt; is a function building a view, whose body is written &lt;code&gt;component c -&amp;gt; …&lt;/code&gt;: the
body is given the component’s &lt;strong&gt;&lt;code&gt;Scope&lt;/code&gt;&lt;/strong&gt;, which keeps values from one build to the next. Its props
are its function’s parameters, read afresh on every build.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Scope member&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.state(init)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;State&lt;/code&gt; holding &lt;code&gt;init&lt;/code&gt; on the component’s first build, the same state on every build after; &lt;code&gt;init&lt;/code&gt; is by-name, evaluated only then&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.remember(make)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any value, made by the by-name &lt;code&gt;make&lt;/code&gt; on the first build and kept&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.derived(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The value of a &lt;a href=&quot;#derived-values&quot;&gt;derived&lt;/a&gt; &lt;code&gt;f&lt;/code&gt;, kept across builds&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A scope answers by order: the component’s &lt;em&gt;n&lt;/em&gt;th request on every build is the same value. A request
for another type than the last build’s in that place, or a request made after the build, from a
callback the build left behind, stops the program:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: a component asked for the values it keeps in a different order from its last build
avin: trap: a component&apos;s scope was asked for a value outside the component&apos;s build
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;root(body)&lt;/code&gt;&lt;/strong&gt; answers the function a frame loop calls for its tree, &lt;code&gt;app(title, root(screen), ground)&lt;/code&gt;: each call is one &lt;strong&gt;build&lt;/strong&gt;, and every component built during it is in the root’s tree. A
component is found again on the next build by its &lt;strong&gt;place&lt;/strong&gt; among the components its parent builds
without a key, the first, the second, and so on; &lt;strong&gt;&lt;code&gt;keyed(key) c -&amp;gt; …&lt;/code&gt;&lt;/strong&gt; finds it by its key, a
&lt;code&gt;string&lt;/code&gt; or an &lt;code&gt;int&lt;/code&gt; (an &lt;code&gt;int&lt;/code&gt; key and its decimal string are one key), wherever among its parent’s
components it is built. A list reordered keeps its keyed components’ state; unkeyed, the state stays
in its place, and a component that disappears from before another gives that one its state.
Components nest: each keeps its own inside its parent’s, and separate roots keep separate trees.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A component the build of its parent leaves out is gone&lt;/strong&gt;, with everything it kept and every
component inside it: a component shown again after a build without it starts afresh. A component
built in a tab’s body is built during the build, and is one place whichever tab shows it.&lt;/p&gt;
&lt;p&gt;Two components built under one parent with one key, a component built while no root is building,
and a root built inside its own build each stop the program:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: two components built under one parent have the key &apos;x&apos;
avin: trap: a component was built outside the build of a root
avin: trap: a root was built again inside its own build
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A root built inside a component’s build is a tree of its own, and is fine.&lt;/p&gt;
&lt;h3 id=&quot;controls-over-state&quot;&gt;Controls over state&lt;/h3&gt;
&lt;p&gt;Every control that holds a value has an overload taking a &lt;code&gt;State&lt;/code&gt; in place of a signal:
&lt;code&gt;switch&lt;/code&gt;, &lt;code&gt;checkbox&lt;/code&gt;, &lt;code&gt;radio&lt;/code&gt;, &lt;code&gt;radioGroup&lt;/code&gt;, &lt;code&gt;slider&lt;/code&gt; over a &lt;code&gt;State[int]&lt;/code&gt; or a &lt;code&gt;State[real]&lt;/code&gt;,
&lt;code&gt;textField&lt;/code&gt;, &lt;code&gt;textArea&lt;/code&gt;, &lt;code&gt;tabs&lt;/code&gt; and &lt;code&gt;scroll&lt;/code&gt;. It reads and writes the state’s own signal,
&lt;code&gt;State.signal(s)&lt;/code&gt;, which is made from the state’s value on the first call and is from then on
where the value lives: a control’s write is the state’s value at once, with no build in between,
and a set is the signal’s write. There is one value, so no write echoes back, and either way a
change is one write.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val done = state(false)
checkbox(done, &amp;quot;Done&amp;quot;)              // a tap flips `done`
done.set(true)                      // the next build shows it checked
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;derived-values&quot;&gt;Derived values&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;derived(f)&lt;/code&gt; is a &lt;code&gt;Derived[T]&lt;/code&gt; whose &lt;code&gt;get()&lt;/code&gt; computes &lt;code&gt;f&lt;/code&gt; when first asked, and again only after
something has been written since: a state’s set, a signal’s write, an &lt;code&gt;invalidate()&lt;/code&gt;. Otherwise it
answers the value it kept. Derived values may read other derived values.&lt;/p&gt;
&lt;h3 id=&quot;threads&quot;&gt;Threads&lt;/h3&gt;
&lt;p&gt;The interface runs on the thread that called &lt;code&gt;run&lt;/code&gt;, and its state belongs to that thread. A
&lt;code&gt;State&lt;/code&gt;, a &lt;code&gt;Derived&lt;/code&gt; and a &lt;code&gt;Scope&lt;/code&gt; are mutable, so none is &lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;sendable&lt;/a&gt;,
and a closure for another thread cannot capture one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: what is passed for `body` of `spawn` may use only sendable values from around it, but it uses `count`, a `State[int]`, whose field `held` is a `var`; make it a `val`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Another thread changes the interface by handing the main thread something to do, and the main
thread does it at the start of a frame. An &lt;strong&gt;inbox&lt;/strong&gt; takes messages: &lt;code&gt;inbox(handle)&lt;/code&gt;, made on the
main thread, is an &lt;code&gt;Inbox[T, R]&lt;/code&gt; whose handler &lt;code&gt;handle: (T) -&amp;gt; R&lt;/code&gt; runs on the main thread with the
interface’s state in reach, and an inbox is sendable, so threads are handed it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inbox(handle)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An &lt;code&gt;Inbox[T, R]&lt;/code&gt; whose messages &lt;code&gt;handle&lt;/code&gt; handles on the main thread; &lt;code&gt;T&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt; are sendable&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;box.send(m)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Queues &lt;code&gt;m&lt;/code&gt; and answers at once a &lt;code&gt;Future[R]&lt;/code&gt; of the handler’s answer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;box.ask(m)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Queues &lt;code&gt;m&lt;/code&gt; and waits for the handler’s answer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;post(work)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Queues the &lt;code&gt;@sendable () -&amp;gt; unit&lt;/code&gt; &lt;code&gt;work&lt;/code&gt; to run on the main thread, and returns at once&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;handlePosted()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Runs every message and piece of work waiting, on the main thread, and answers how many&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.threads.{sleep, spawn}
import avin.time.millis
import ui.{inbox, state}

val ticks = state(0)
val tick = inbox((n: int) -&amp;gt; ticks.set(n))
spawn(() -&amp;gt;
  for n in 1 .. 10
    sleep(millis(100))
    tick.ask(n))
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Everything runs on the main thread, in the order it was sent.&lt;/strong&gt; Messages to every inbox and
posted work wait in one queue, so what one thread sends and posts runs in the order it did them,
whichever inboxes they went to, and a send happens before its handling. Among many senders each
thread’s order is kept.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The frame loop runs what is waiting at the start of every frame&lt;/strong&gt;, before it decides whether to
build the tree again, so a state the work sets is built in that same frame. &lt;code&gt;run&lt;/code&gt; runs what is still waiting
once more when the loop ends. A program with no window, a test among them, calls
&lt;code&gt;handlePosted()&lt;/code&gt; itself.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Then it runs the threads pinned to the main thread.&lt;/strong&gt; A handler that has to wait, for a worker’s
result, a future or an ask, starts a &lt;a href=&quot;/spec/threads/#pinned-to-the-main-thread&quot;&gt;thread pinned to the main
thread&lt;/a&gt; with &lt;code&gt;spawnOnMain&lt;/code&gt;, which parks while it waits
rather than holding the frame, and carries on on the main thread with the interface’s state in
reach:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;button(&amp;quot;Load&amp;quot;, () -&amp;gt;
  spawnOnMain(() -&amp;gt;
    shown.set(&amp;quot;loading&amp;quot;)
    shown.set(spawn(() -&amp;gt; fetch(url)).join())))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;handlePosted&lt;/code&gt; runs the messages and posted work waiting, then each pinned thread ready by then,
in the order they became ready (&lt;code&gt;runMainThreads&lt;/code&gt;), and answers how many it ran of both. A pinned
thread that a message or posted work makes ready runs in the same call; one that another pinned
thread makes ready runs at the next, as work that work posts does. The loop polls every frame, so
it needs no wake of its own: what a worker makes ready runs at the next frame. A pinned thread
still parked when &lt;code&gt;run&lt;/code&gt; returns stays parked, and runs again whenever the main thread next runs
them, in a later &lt;code&gt;run&lt;/code&gt;, a &lt;code&gt;handlePosted&lt;/code&gt; or a wait of its own.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What the work sends or posts waits for the next frame.&lt;/strong&gt; &lt;code&gt;handlePosted&lt;/code&gt; runs only what was
waiting when it was called, so work that posts itself again runs once a frame rather than holding
the frame for ever.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An ask parks.&lt;/strong&gt; A lightweight thread waiting in &lt;code&gt;ask&lt;/code&gt;, or in &lt;code&gt;await&lt;/code&gt; on what &lt;code&gt;send&lt;/code&gt; answered,
frees its worker until the main thread has handled the message; a pinned thread parks too, until
the frame that handles it. An ask in the main thread’s own code, which would wait for itself,
stops the program:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: an inbox was asked from the main thread, which would wait for itself to handle the message
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A send or a post from the main thread, from a handler too, is queued like any other.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Only the main thread makes an inbox, handles what is waiting and runs a window&lt;/strong&gt;, and only its
own code runs a window: a pinned thread makes an inbox and handles what is waiting, but &lt;code&gt;run&lt;/code&gt; on a
pinned thread stops the program, since the frames that would run the pinned threads would be its
own. Each reaches
the main thread’s own state, so code for another thread that does one of them is refused where it
is compiled, as reaching any module-level mutable state is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: what is passed for `body` of `spawn` may run on another thread, which shares the program&apos;s module-level state, but through `handlePosted` → `handleOne` it reaches `handlers`, a module-level value holding a `Map[int, () -&amp;gt; unit]`, which is mutable; an immutable copy (`toMap`) is sendable
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A message, an answer and posted work cross threads, so each is sendable&lt;/strong&gt;; a handler is not,
since it stays on the main thread, and may capture a &lt;code&gt;State&lt;/code&gt;. An inbox lasts as long as the
program. When &lt;code&gt;main&lt;/code&gt; returns the program ends, as it always does: work still waiting is never
run, and a thread parked on an ask does not hold the program open.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-is-not-bound&quot;&gt;What is not bound&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Overlays (&lt;code&gt;popover&lt;/code&gt;, &lt;code&gt;modal&lt;/code&gt;, &lt;code&gt;menu_bar&lt;/code&gt;), tables, images, selection, the theme and its
&lt;code&gt;restyle&lt;/code&gt;, keyboard input to a recording canvas, &lt;code&gt;on_event&lt;/code&gt;, &lt;code&gt;on_frame&lt;/code&gt; and the control socket;
each is bound when something needs it.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>Types</title>
    <link href="https://avinlang.dev/spec/types/"/>
    <id>https://avinlang.dev/spec/types/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Built-in types, numbers, strings, unit, tuples, functions, and the top and bottom types.</summary>
    <content type="html">&lt;h2 id=&quot;built-in-types&quot;&gt;Built-in types&lt;/h2&gt;
&lt;p&gt;Built-in type names are lowercase and belong to the language itself: they have no module path and
cannot be shadowed by an import. In a pattern each is a
&lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;type pattern&lt;/a&gt; by itself, &lt;code&gt;x is int&lt;/code&gt;, so none names a
local, a parameter or a field. Their methods are defined in the core standard library with
ordinary &lt;code&gt;impl&lt;/code&gt; blocks.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Alias of &lt;code&gt;i32&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Alias of &lt;code&gt;i64&lt;/code&gt;; &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; are the only integer aliases&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;iN&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Signed integer of exactly N bits, 1 ≤ N ≤ LLVM’s limit (&lt;code&gt;i8&lt;/code&gt;, &lt;code&gt;i64&lt;/code&gt;, &lt;code&gt;i128&lt;/code&gt;, &lt;code&gt;i257&lt;/code&gt;, …)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;byte&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An octet, 0–255: the unit of binary data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;IEEE-754 binary64. There is no single-precision type&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;char&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A Unicode scalar value (U+0000–U+10FFFF, excluding surrogates)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Immutable UTF-8 text&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One value, written &lt;code&gt;()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;All other types — user types, library types, collections — are PascalCase by convention.&lt;/p&gt;
&lt;h2 id=&quot;integers&quot;&gt;Integers&lt;/h2&gt;
&lt;p&gt;Arithmetic keeps the operand width: &lt;code&gt;i8 + i8&lt;/code&gt; is &lt;code&gt;i8&lt;/code&gt;. Mixed widths need an explicit conversion
(&lt;code&gt;long(x)&lt;/code&gt;); there is no implicit widening. Diagnostics name &lt;code&gt;i32&lt;/code&gt; and &lt;code&gt;i64&lt;/code&gt; by their aliases, and
an operation or comparison on two number types names the conversion that joins them, pointing at
the operand to convert: &lt;code&gt;error: `*` needs two numbers of one type, not long and int; write `long(n)` &lt;/code&gt; (an integer converts to the wider integer or to &lt;code&gt;real&lt;/code&gt;, a byte to the other side’s
type; a compound assignment’s target keeps its type, so there the value converts to it). A literal takes its width from context (an annotation,
a parameter, the other operand, the other branches of an &lt;code&gt;if&lt;/code&gt; or elements of a collection literal) and defaults to &lt;code&gt;int&lt;/code&gt;; a literal that does not fit is a compile error.
Where a &lt;code&gt;real&lt;/code&gt; is expected, an integer literal is that real (&lt;code&gt;x * 2&lt;/code&gt;), provided it is exact: its
magnitude is at most 2^53.&lt;/p&gt;
&lt;p&gt;Conversions: widening sign-extends; narrowing traps when the value does not fit the narrower width
(&lt;code&gt;i8(300)&lt;/code&gt; traps, &lt;code&gt;i8(127)&lt;/code&gt; is &lt;code&gt;127&lt;/code&gt;), and &lt;code&gt;i8.wrap(300)&lt;/code&gt; is the explicit wrapping form, which keeps the low
bits (&lt;code&gt;44&lt;/code&gt;); real-to-integer
truncates toward zero, saturates at the bounds and maps NaN to zero; &lt;code&gt;char(n)&lt;/code&gt; traps on a value that
is not a Unicode scalar. Conversions are written as a call of the target type, and these exist: between
any two integer types; integers and &lt;code&gt;real&lt;/code&gt; in both directions; an integer or &lt;code&gt;byte&lt;/code&gt; to &lt;code&gt;byte&lt;/code&gt; and
&lt;code&gt;char&lt;/code&gt;; &lt;code&gt;byte&lt;/code&gt; and &lt;code&gt;char&lt;/code&gt; to any integer type; &lt;code&gt;byte&lt;/code&gt; to &lt;code&gt;real&lt;/code&gt;. A conversion to the same type is
allowed and does nothing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Limits.&lt;/strong&gt; Every integer type has its least and greatest value as constants, &lt;code&gt;MinValue&lt;/code&gt; and &lt;code&gt;MaxValue&lt;/code&gt;:
&lt;code&gt;int.MaxValue&lt;/code&gt;, &lt;code&gt;long.MinValue&lt;/code&gt;, &lt;code&gt;i8.MaxValue&lt;/code&gt;, &lt;code&gt;i1.MinValue&lt;/code&gt;, &lt;code&gt;i257.MaxValue&lt;/code&gt;, and &lt;code&gt;byte.MaxValue&lt;/code&gt; (255)
and &lt;code&gt;byte.MinValue&lt;/code&gt; (0). &lt;code&gt;char.MaxValue&lt;/code&gt; is U+10FFFF and &lt;code&gt;char.MinValue&lt;/code&gt; U+0000. &lt;code&gt;real&lt;/code&gt; has &lt;code&gt;MaxValue&lt;/code&gt;
(the greatest finite value), &lt;code&gt;MinValue&lt;/code&gt; (the least, its negation), &lt;code&gt;MinPositiveValue&lt;/code&gt; (the least positive
value, subnormal), &lt;code&gt;PositiveInfinity&lt;/code&gt;, &lt;code&gt;NegativeInfinity&lt;/code&gt; and &lt;code&gt;NaN&lt;/code&gt;. They are written on the type, are
folded at compile time, and have the type they are written on; a type parameter bounded by &lt;code&gt;Integer&lt;/code&gt;
has &lt;code&gt;MinValue&lt;/code&gt; and &lt;code&gt;MaxValue&lt;/code&gt; too, folded at each instance’s width (&lt;a href=&quot;/spec/generics/&quot;&gt;generics&lt;/a&gt;). Any other name written on one of these
types is an error.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Arithmetic that overflows traps.&lt;/strong&gt; &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, unary &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt; and &lt;code&gt;--&lt;/code&gt; trap when the
mathematical result does not fit the width, and so does &lt;code&gt;/&lt;/code&gt; for the one quotient that cannot fit
(&lt;code&gt;MIN / -1&lt;/code&gt;). &lt;code&gt;%&lt;/code&gt; never overflows: &lt;code&gt;MIN % -1&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt;. Division and remainder by zero trap. Code that
wants other behaviour says so with an operator: &lt;code&gt;+%&lt;/code&gt;, &lt;code&gt;-%&lt;/code&gt; and &lt;code&gt;*%&lt;/code&gt; wrap, and &lt;code&gt;+|&lt;/code&gt;, &lt;code&gt;-|&lt;/code&gt; and &lt;code&gt;*|&lt;/code&gt;
saturate at the bounds. Shifts never trap; a count at least as large as the width, or a negative
count, shifts every bit out (&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; keeps the sign, so &lt;code&gt;-1 &amp;gt;&amp;gt; 40&lt;/code&gt; is &lt;code&gt;-1&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Integers are signed; there are no unsigned integer types. Binary data uses &lt;code&gt;byte&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The integer types are one family, &lt;code&gt;iN&lt;/code&gt; for every width from &lt;code&gt;i1&lt;/code&gt; to &lt;code&gt;i8388608&lt;/code&gt;, and the closed core
trait &lt;code&gt;Integer&lt;/code&gt; has exactly them as members (&lt;code&gt;byte&lt;/code&gt; is not one). The core library implements its
traits once for the whole family, so every width compares, orders, prints in decimal and debugs
alike, and meets a bound such as &lt;code&gt;Ord&lt;/code&gt; or &lt;code&gt;Display&lt;/code&gt; as &lt;code&gt;int&lt;/code&gt; does; a parameter bounded by &lt;code&gt;Integer&lt;/code&gt;
has every integer operation and conversion (&lt;a href=&quot;/spec/generics/#bounds&quot;&gt;Bounds&lt;/a&gt;). The integers and &lt;code&gt;real&lt;/code&gt;
together are the numbers, the members of the core trait &lt;code&gt;Numeric&lt;/code&gt;, which &lt;code&gt;Integer&lt;/code&gt; requires: a
parameter bounded by it has the arithmetic, the ordering and &lt;code&gt;toReal&lt;/code&gt;. A value that fits in a
&lt;code&gt;long&lt;/code&gt; renders through it, at no cost for widths up to 64 bits; a wider one renders in chunks of
eighteen digits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Integer methods.&lt;/strong&gt; Every integer type has these methods, from one impl for the whole family, each
working at the width it is called at (an &lt;code&gt;i8&lt;/code&gt; stays an &lt;code&gt;i8&lt;/code&gt;) and trapping, as arithmetic does, when
a result does not fit:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;abs&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The magnitude; traps for &lt;code&gt;MinValue&lt;/code&gt;, whose magnitude does not fit&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sign&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;-1&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;, as an &lt;code&gt;int&lt;/code&gt; at every width&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pow(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number to the power &lt;code&gt;n&lt;/code&gt;, an &lt;code&gt;int&lt;/code&gt;; &lt;code&gt;x.pow(0)&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;0.pow(0)&lt;/code&gt; included. Traps when the result does not fit and when &lt;code&gt;n&lt;/code&gt; is negative&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;gcd(o)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The greatest common divisor, never negative; &lt;code&gt;0.gcd(0)&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt;. Traps only when it is &lt;code&gt;MinValue&lt;/code&gt;‘s magnitude, as in &lt;code&gt;MinValue.gcd(0)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lcm(o)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The least positive common multiple, &lt;code&gt;0&lt;/code&gt; when either is &lt;code&gt;0&lt;/code&gt;; traps when it does not fit&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;floorDiv(o)&lt;/code&gt;, &lt;code&gt;floorMod(o)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The quotient rounded towards negative infinity, and the remainder that takes the divisor’s sign, so &lt;code&gt;a == a.floorDiv(d) * d + a.floorMod(d)&lt;/code&gt;. They trap where &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;%&lt;/code&gt; do: a zero divisor, and &lt;code&gt;MinValue.floorDiv(-1)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;bitCount&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number of one bits of the two’s-complement form at the width: &lt;code&gt;(-1).bitCount&lt;/code&gt; is &lt;code&gt;32&lt;/code&gt; for an &lt;code&gt;int&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;leadingZeros&lt;/code&gt;, &lt;code&gt;trailingZeros&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The zero bits above the highest one and below the lowest one, an &lt;code&gt;int&lt;/code&gt;; the width for zero. &lt;code&gt;leadingZeros&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt; for a negative number&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isPowerOfTwo&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the number is &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;, &lt;code&gt;4&lt;/code&gt;, and so on; never for zero or a negative number&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toRadix(r)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The digits in radix &lt;code&gt;r&lt;/code&gt; from 2 to 36, lower case, with a &lt;code&gt;-&lt;/code&gt; for a negative number and no prefix, as &lt;code&gt;f&amp;quot;%x&amp;quot;&lt;/code&gt; and &lt;code&gt;f&amp;quot;%b&amp;quot;&lt;/code&gt; write them; any other radix traps&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number as an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt;, exactly &lt;code&gt;int(n)&lt;/code&gt; and &lt;code&gt;long(n)&lt;/code&gt;: trapping when it does not fit&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toReal&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number as a &lt;code&gt;real&lt;/code&gt;, exactly &lt;code&gt;real(n)&lt;/code&gt;; it is &lt;code&gt;Numeric&lt;/code&gt;‘s, so generic code has it too&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The bitwise operators &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt; and the shifts also work on a type parameter bounded by
&lt;code&gt;Integer&lt;/code&gt;, as the machine’s operators at each width, with both operands of one type: &lt;code&gt;x &amp;gt;&amp;gt; T(1)&lt;/code&gt;.
The methods above are not members of &lt;code&gt;Integer&lt;/code&gt;, so generic code cannot call them on a &lt;code&gt;T&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;bigint&quot;&gt;BigInt&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;BigInt&lt;/code&gt;, a class of the core library, is a whole number of any size: it holds as many digits as
its value needs, so its arithmetic never overflows. It is not a member of &lt;code&gt;Integer&lt;/code&gt;, whose widths are
fixed, but it is a number, an ordered value and a key: it implements &lt;code&gt;Numeric&lt;/code&gt; (the five operators,
unary &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;BigInt.zero()&lt;/code&gt;, &lt;code&gt;BigInt.one()&lt;/code&gt; and &lt;code&gt;toReal&lt;/code&gt;), &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt;
by value.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;var f: BigInt = 1
for i in 2 .. 100 do f *= i
println(f)                              // 100!, all 158 digits
println(f % 1000 == 0)                  // true
println(f&amp;quot;${BigInt(2).pow(100)}%,d&amp;quot;)     // 1,267,650,600,228,229,401,496,703,205,376
val big: BigInt = 123456789012345678901234567890
println(big * 2 + 1)                    // 246913578024691357802469135781
println(BigInt(&amp;quot;ff&amp;quot;, 16) + 1)           // 256
println(BigInt.parse(&amp;quot;12x&amp;quot;))            // None
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Making one.&lt;/strong&gt; A &lt;code&gt;BigInt&lt;/code&gt; takes integers by &lt;a href=&quot;#integers-meet-a-type-that-takes-them&quot;&gt;&lt;code&gt;FromInteger&lt;/code&gt;&lt;/a&gt;:
where one is expected, an integer literal of any size and base is that &lt;code&gt;BigInt&lt;/code&gt;
(&lt;code&gt;val big: BigInt = 123456789012345678901234567890&lt;/code&gt;, &lt;code&gt;val m: BigInt = 0xffffffffffffffffffffffff&lt;/code&gt;),
and an integer of any width beside one under an operator is converted to one. &lt;code&gt;BigInt(n)&lt;/code&gt; takes an
integer of any width; a literal argument there is a &lt;code&gt;long&lt;/code&gt;, so it may be as large as one.
&lt;code&gt;BigInt(text)&lt;/code&gt; reads decimal and &lt;code&gt;BigInt(text, radix)&lt;/code&gt; digits of base 2 to
36 (&lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9&lt;/code&gt;, then &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;z&lt;/code&gt; in either case), each after an optional &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt;, with at least
one digit and nothing else: no white space, separators, prefix or exponent. Text that is not that
traps, as &lt;code&gt;toLong&lt;/code&gt; does; &lt;code&gt;BigInt.parse(text)&lt;/code&gt; and &lt;code&gt;BigInt.parse(text, radix)&lt;/code&gt; answer &lt;code&gt;None&lt;/code&gt;
instead. A radix outside 2 to 36 traps under both, being the caller’s mistake. &lt;code&gt;-0&lt;/code&gt; is zero, and
zero has no sign.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arithmetic is exact.&lt;/strong&gt; &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; and unary &lt;code&gt;-&lt;/code&gt; never trap, between two &lt;code&gt;BigInt&lt;/code&gt;s or a
&lt;code&gt;BigInt&lt;/code&gt; and an integer on either side: &lt;code&gt;f * i&lt;/code&gt;, &lt;code&gt;i * f&lt;/code&gt;, &lt;code&gt;f - 1&lt;/code&gt;, &lt;code&gt;f /= n&lt;/code&gt;. The comparisons and
&lt;code&gt;==&lt;/code&gt; take an integer on either side too, chains included: &lt;code&gt;f == 0&lt;/code&gt;, &lt;code&gt;0 &amp;lt; f &amp;lt; limit&lt;/code&gt;. The bitwise,
shift, wrapping and saturating operators are the integers’ alone. &lt;code&gt;/&lt;/code&gt; rounds towards zero and &lt;code&gt;%&lt;/code&gt;
takes the dividend’s sign, as on the integer types; &lt;code&gt;floorDiv&lt;/code&gt; and &lt;code&gt;floorMod&lt;/code&gt; round towards
negative infinity, and &lt;code&gt;divRem(o)&lt;/code&gt; gives &lt;code&gt;(self / o, self % o)&lt;/code&gt; from one division. A zero divisor
traps with &lt;code&gt;division by zero&lt;/code&gt; under every one of them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Methods.&lt;/strong&gt; &lt;code&gt;isZero&lt;/code&gt;; &lt;code&gt;sign&lt;/code&gt;, &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;pow(n)&lt;/code&gt;, &lt;code&gt;gcd(o)&lt;/code&gt;, &lt;code&gt;lcm(o)&lt;/code&gt; and &lt;code&gt;toRadix(r)&lt;/code&gt; as the integer
types have them, except that nothing overflows: &lt;code&gt;pow&lt;/code&gt; traps only for a negative &lt;code&gt;n&lt;/code&gt;, and &lt;code&gt;gcd&lt;/code&gt; and
&lt;code&gt;lcm&lt;/code&gt; never. &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toInt&lt;/code&gt; give the value as that type and trap when it does not fit, with
&lt;code&gt;value out of range for long&lt;/code&gt; (or &lt;code&gt;int&lt;/code&gt;); &lt;code&gt;toLongOption&lt;/code&gt; and &lt;code&gt;toIntOption&lt;/code&gt; answer &lt;code&gt;None&lt;/code&gt; instead.
&lt;code&gt;toReal&lt;/code&gt; is the nearest &lt;code&gt;real&lt;/code&gt;, a tie going to the even one, and an infinity of the number’s sign
past the greatest finite &lt;code&gt;real&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text.&lt;/strong&gt; A &lt;code&gt;BigInt&lt;/code&gt; displays as an integer does, in decimal with a &lt;code&gt;-&lt;/code&gt; when negative, and its
&lt;code&gt;Debug&lt;/code&gt; form is the same. The integer conversions &lt;code&gt;%d&lt;/code&gt;, &lt;code&gt;%i&lt;/code&gt;, &lt;code&gt;%x&lt;/code&gt;, &lt;code&gt;%X&lt;/code&gt;, &lt;code&gt;%o&lt;/code&gt; and &lt;code&gt;%b&lt;/code&gt; take it
with every flag, width and precision, laying it out exactly as they lay out a &lt;code&gt;long&lt;/code&gt; of the same
value; like every number it is refused under &lt;code&gt;%s&lt;/code&gt;, &lt;code&gt;%f&lt;/code&gt; and &lt;code&gt;%c&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Representation.&lt;/strong&gt; The magnitude is held in limbs of nine decimal digits, least significant first,
never written once made, so a &lt;code&gt;BigInt&lt;/code&gt; is an immutable value that may be shared freely. Decimal
text is read and written a limb at a time; other bases go through division by a power of the radix.
Multiplication and division are the schoolbook algorithms, quadratic in the number of limbs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Identities.&lt;/strong&gt; &lt;code&gt;BigInt.zero()&lt;/code&gt; and &lt;code&gt;BigInt.one()&lt;/code&gt; are &lt;code&gt;Add&lt;/code&gt;‘s and &lt;code&gt;Mul&lt;/code&gt;‘s static members, kept
with &lt;code&gt;()&lt;/code&gt; as every type’s are; &lt;code&gt;val z: BigInt = 0&lt;/code&gt; is the same value.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;integers-meet-a-type-that-takes-them&quot;&gt;Integers meet a type that takes them&lt;/h3&gt;
&lt;p&gt;A type that implements the core trait &lt;code&gt;FromInteger&lt;/code&gt; takes integers, of every width and without loss.
&lt;code&gt;BigInt&lt;/code&gt; is the library’s one; a program’s own number type joins by implementing it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait FromInteger
  static fromInteger[N: Integer](n: N) -&amp;gt; Self
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A literal where one is expected is its value&lt;/strong&gt;, wherever a type is expected: an annotation, an
argument, a default, a result, a branch of an &lt;code&gt;if&lt;/code&gt;, a collection literal’s element, and the other
operand of an operator. The literal may be of any size and in any base, with separators; it is
passed to &lt;code&gt;fromInteger&lt;/code&gt; as a &lt;code&gt;long&lt;/code&gt; where it fits one, and otherwise as the narrowest wider
integer that holds it (&lt;code&gt;i128&lt;/code&gt;, &lt;code&gt;i192&lt;/code&gt;, …). A type parameter bounded by &lt;code&gt;FromInteger&lt;/code&gt; takes one the
same way: &lt;code&gt;val x: T = 42&lt;/code&gt; is &lt;code&gt;T.fromInteger(42)&lt;/code&gt; in each instance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An integer operand beside one is converted to it.&lt;/strong&gt; In &lt;code&gt;a op b&lt;/code&gt;, where &lt;code&gt;op&lt;/code&gt; is &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;,
&lt;code&gt;/&lt;/code&gt; or &lt;code&gt;%&lt;/code&gt;, and in a comparison or &lt;code&gt;==&lt;/code&gt;/&lt;code&gt;!=&lt;/code&gt;, an operand whose type is an integer, or a type
parameter bounded by &lt;code&gt;Integer&lt;/code&gt;, meets an operand of a type that takes integers as
&lt;code&gt;T.fromInteger(n)&lt;/code&gt;, on either side: &lt;code&gt;big * i&lt;/code&gt;, &lt;code&gt;i * big&lt;/code&gt;, &lt;code&gt;big &amp;lt; n&lt;/code&gt;, &lt;code&gt;0 == big&lt;/code&gt;. A chain converts
each integer beside such an operand. The converted operand is evaluated once, where it stands. A
compound assignment converts its value into a &lt;code&gt;BigInt&lt;/code&gt; target, &lt;code&gt;f *= i&lt;/code&gt;; an integer target keeps
its type, so &lt;code&gt;n += big&lt;/code&gt; is an error. Where the type has an &lt;a href=&quot;/spec/operators-and-control-flow/#operator-methods&quot;&gt;operator method&lt;/a&gt;
of the operator’s name and no overload of it takes an integer, its integer argument is converted
too, and an integer on its left calls it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nothing else converts.&lt;/strong&gt; Two integer widths still meet only through a conversion (&lt;code&gt;long(x)&lt;/code&gt;),
a &lt;code&gt;real&lt;/code&gt; or a &lt;code&gt;byte&lt;/code&gt; never converts to a type that takes integers, nor such a value back to an
integer, &lt;code&gt;===&lt;/code&gt; compares no converted value, and the bitwise, shift, wrapping and saturating
operators stay the integers’ own. An integer literal is no &lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;pattern&lt;/a&gt; for such a
type, since its value is a call and not a constant: &lt;code&gt;b match 0 -&amp;gt; …&lt;/code&gt; is an error that says to
compare with &lt;code&gt;==&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;bigdecimal&quot;&gt;BigDecimal&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;BigDecimal&lt;/code&gt;, a class of the core library beside &lt;code&gt;BigInt&lt;/code&gt;, is a decimal number of any size and any
number of places: an unscaled &lt;code&gt;BigInt&lt;/code&gt; and a scale, the count of its digits after the point, so
&lt;code&gt;19.99&lt;/code&gt; is &lt;code&gt;1999&lt;/code&gt; at scale 2. Where a &lt;code&gt;real&lt;/code&gt; holds the nearest binary fraction, a &lt;code&gt;BigDecimal&lt;/code&gt; holds
the decimal exactly, which makes it the number for money and for anything else written in decimal.
It is immutable, and a number, an ordered value and a key: it implements &lt;code&gt;Numeric&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt;
by value, &lt;code&gt;FromInteger&lt;/code&gt; and &lt;a href=&quot;#decimals-meet-a-type-that-takes-them&quot;&gt;&lt;code&gt;FromDecimal&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;main()
  val price: BigDecimal = 19.99
  println(price * 3) // 59.97
  val tenth: BigDecimal = 0.1
  println(tenth + 0.2 == 0.3) // true
  val one: BigDecimal = 1
  println(one / 3) // 0.3333333333333333333333333333333333
  println(one.div(3, scale = 4)) // 0.3333
  println(one.exactDiv(8)) // Some(0.125)
  println(one.exactDiv(3)) // None
  val x: BigDecimal = 2.345
  println(x.round(2)) // 2.34
  println(x.round(2, rounding = HalfUp)) // 2.35
  val two: BigDecimal = 2.0
  println(two == 2.00) // true
  println(BigDecimal.fromRealShortest(0.1)) // 0.1
  println(f&amp;quot;$x%.1f&amp;quot;) // 2.3
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;59.97
true
0.3333333333333333333333333333333333
0.3333
Some(0.125)
None
2.34
2.35
true
0.1
2.3
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Making one.&lt;/strong&gt; A decimal literal where a &lt;code&gt;BigDecimal&lt;/code&gt; is expected is that number, read from its
digits, never through a &lt;code&gt;real&lt;/code&gt;: &lt;code&gt;val price: BigDecimal = 19.99&lt;/code&gt; holds exactly 19.99, and &lt;code&gt;1.5e-3&lt;/code&gt;,
&lt;code&gt;1_000.25&lt;/code&gt; and &lt;code&gt;-0.5&lt;/code&gt; are read the same way. An integer literal of any size is one at scale 0, and
an integer or a &lt;code&gt;BigInt&lt;/code&gt; beside one under an operator is converted to one. &lt;code&gt;BigDecimal(n)&lt;/code&gt; takes an
integer of any width or a &lt;code&gt;BigInt&lt;/code&gt;, and &lt;code&gt;BigDecimal(unscaled, scale)&lt;/code&gt; names both parts; a negative
scale traps. &lt;code&gt;BigDecimal(text)&lt;/code&gt; reads an optional &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt;, digits with an optional point among or
around them, and an optional exponent (&lt;code&gt;e&lt;/code&gt; or &lt;code&gt;E&lt;/code&gt;, an optional sign, digits); the scale is the
digits after the point less the exponent, and 0 where that is below 0, so &lt;code&gt;&amp;quot;1.50&amp;quot;&lt;/code&gt; is scale 2 and
&lt;code&gt;&amp;quot;1.5e3&amp;quot;&lt;/code&gt; is &lt;code&gt;1500&lt;/code&gt;. Nothing else is read, no white space or separators; other text traps, and
&lt;code&gt;BigDecimal.parse(text)&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt; instead, as it does for a scale beyond an &lt;code&gt;int&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;From a &lt;code&gt;real&lt;/code&gt;, only explicitly.&lt;/strong&gt; A &lt;code&gt;real&lt;/code&gt; never converts on its own: &lt;code&gt;d + r&lt;/code&gt; is an error that
names the two conversions. &lt;code&gt;BigDecimal.fromRealExact(x)&lt;/code&gt; is the binary fraction &lt;code&gt;x&lt;/code&gt; holds, every
digit of it (&lt;code&gt;0.1&lt;/code&gt; gives &lt;code&gt;0.1000000000000000055511151231257827021181583404541015625&lt;/code&gt;), and
&lt;code&gt;BigDecimal.fromRealShortest(x)&lt;/code&gt; the shortest decimal that reads back as &lt;code&gt;x&lt;/code&gt;, as &lt;code&gt;x&lt;/code&gt; prints (&lt;code&gt;0.1&lt;/code&gt;).
Both take the least scale that holds the value, and NaN and the infinities trap. &lt;code&gt;toReal&lt;/code&gt; is the
nearest &lt;code&gt;real&lt;/code&gt;, a tie going to the even one, and an infinity of the number’s sign beyond the
greatest finite one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rounding.&lt;/strong&gt; &lt;code&gt;Rounding&lt;/code&gt; is a data type of seven variants: &lt;code&gt;HalfEven&lt;/code&gt;, the nearer neighbour with a
tie to the even digit, the default wherever a rounding is taken; &lt;code&gt;HalfUp&lt;/code&gt; and &lt;code&gt;HalfDown&lt;/code&gt;, a tie away
from and toward zero; &lt;code&gt;Up&lt;/code&gt; and &lt;code&gt;Down&lt;/code&gt;, away from and toward zero; &lt;code&gt;Ceiling&lt;/code&gt; and &lt;code&gt;Floor&lt;/code&gt;, toward
positive and negative infinity. There is no mode that traps on an inexact result: an operation that
must be exact answers an &lt;code&gt;Option&lt;/code&gt; instead. &lt;code&gt;x.round(places)&lt;/code&gt; gives the number at that scale, its
other digits rounded, and a shorter one gains zeros (&lt;code&gt;2.5&lt;/code&gt; at two places is &lt;code&gt;2.50&lt;/code&gt;); a negative
&lt;code&gt;places&lt;/code&gt; rounds to tens, hundreds and so on, written as a whole number. &lt;code&gt;x.roundSignificant(n)&lt;/code&gt;
rounds to at most &lt;code&gt;n&lt;/code&gt; significant digits. Each takes &lt;code&gt;rounding = …&lt;/code&gt; by name.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arithmetic.&lt;/strong&gt; &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; and unary &lt;code&gt;-&lt;/code&gt; are exact: a sum has the larger scale and a product the
sum of the scales. &lt;code&gt;/&lt;/code&gt; gives the quotient to 34 significant digits, rounded half to even; where the
exact quotient has no more digits than that, it is exact, with no zeros after it beyond the
dividend’s scale less the divisor’s (&lt;code&gt;1 / 4&lt;/code&gt; is &lt;code&gt;0.25&lt;/code&gt;, &lt;code&gt;6.00 / 2&lt;/code&gt; is &lt;code&gt;3.00&lt;/code&gt;). &lt;code&gt;a.div(b, scale = n, rounding = r)&lt;/code&gt; gives the quotient at &lt;code&gt;n&lt;/code&gt; places and &lt;code&gt;a.divSignificant(b, n, rounding = r)&lt;/code&gt; to &lt;code&gt;n&lt;/code&gt;
significant digits, &lt;code&gt;/&lt;/code&gt; being &lt;code&gt;divSignificant(b, 34)&lt;/code&gt;. &lt;code&gt;a.exactDiv(b)&lt;/code&gt; answers the exact quotient,
or &lt;code&gt;None&lt;/code&gt; where it never ends; where &lt;code&gt;/&lt;/code&gt; is exact the two agree. &lt;code&gt;%&lt;/code&gt; is what is left once the
quotient cut to a whole number is taken away, with the dividend’s sign, and &lt;code&gt;divRem(b)&lt;/code&gt; answers that
whole quotient and the remainder from one division. &lt;code&gt;pow(n)&lt;/code&gt; is exact. A zero divisor traps with
&lt;code&gt;division by zero&lt;/code&gt; under every one of them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Equality is by value.&lt;/strong&gt; &lt;code&gt;==&lt;/code&gt;, the ordering and the hash look at the number, not its scale:
&lt;code&gt;2.0 == 2.00&lt;/code&gt;, the two hash alike, and they are one key of a map and one member of a set. &lt;code&gt;scale&lt;/code&gt;
tells them apart, and &lt;code&gt;stripTrailingZeros&lt;/code&gt; gives the number at the least scale that holds it
(&lt;code&gt;2.500&lt;/code&gt; is &lt;code&gt;2.5&lt;/code&gt;; a whole number keeps its zeros before the point).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mixing.&lt;/strong&gt; An integer of any width and a &lt;code&gt;BigInt&lt;/code&gt; meet a &lt;code&gt;BigDecimal&lt;/code&gt; under the five operators,
the comparisons and &lt;code&gt;==&lt;/code&gt;, on either side and in chains, and in a compound assignment to a
&lt;code&gt;BigDecimal&lt;/code&gt;; a decimal literal beside one is one too (&lt;code&gt;price + 0.01&lt;/code&gt;, &lt;code&gt;0 &amp;lt; price &amp;lt; 20.0&lt;/code&gt;). A &lt;code&gt;real&lt;/code&gt;
meets one nowhere. A decimal literal is no pattern for a &lt;code&gt;BigDecimal&lt;/code&gt;; compare with &lt;code&gt;==&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parts and conversions.&lt;/strong&gt; &lt;code&gt;unscaled&lt;/code&gt;, &lt;code&gt;scale&lt;/code&gt;, &lt;code&gt;precision&lt;/code&gt; (the unscaled value’s digits, 1 for
zero), &lt;code&gt;sign&lt;/code&gt;, &lt;code&gt;isZero&lt;/code&gt; and &lt;code&gt;abs&lt;/code&gt;. &lt;code&gt;toBigInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toInt&lt;/code&gt; take the whole part, toward
zero; &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toInt&lt;/code&gt; trap with &lt;code&gt;value out of range for long&lt;/code&gt; (or &lt;code&gt;int&lt;/code&gt;) where it does not fit,
and &lt;code&gt;toLongOption&lt;/code&gt; and &lt;code&gt;toIntOption&lt;/code&gt; answer &lt;code&gt;None&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text.&lt;/strong&gt; A &lt;code&gt;BigDecimal&lt;/code&gt; is written in plain digits, never with an exponent: &lt;code&gt;0.000001&lt;/code&gt;,
&lt;code&gt;1000000000000000000000&lt;/code&gt;. Its &lt;code&gt;Debug&lt;/code&gt; form is the same. Under &lt;code&gt;%f&lt;/code&gt; the precision is its places,
rounded half to even, and with none it keeps its own; the flags &lt;code&gt;+&lt;/code&gt;, space, &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;#&lt;/code&gt; act as on a
&lt;code&gt;real&lt;/code&gt;. Like every number it is refused under &lt;code&gt;%s&lt;/code&gt;, and as one never written with an exponent it is
refused under &lt;code&gt;%e&lt;/code&gt; and &lt;code&gt;%g&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Identities.&lt;/strong&gt; &lt;code&gt;BigDecimal.zero()&lt;/code&gt; and &lt;code&gt;BigDecimal.one()&lt;/code&gt;, at scale 0.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;decimals-meet-a-type-that-takes-them&quot;&gt;Decimals meet a type that takes them&lt;/h3&gt;
&lt;p&gt;A type that implements the core trait &lt;code&gt;FromDecimal&lt;/code&gt; takes every decimal number exactly, and with it
every integer and every &lt;code&gt;BigInt&lt;/code&gt;. &lt;code&gt;BigDecimal&lt;/code&gt; is the library’s one; a program’s own type joins by
implementing it beside &lt;code&gt;FromInteger&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait FromDecimal: FromInteger
  static fromDecimal(text: string) -&amp;gt; Self
  static fromBigInt(n: BigInt) -&amp;gt; Self
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A decimal literal where one is expected is its value&lt;/strong&gt;, wherever a type is expected, as an
integer literal is for &lt;code&gt;FromInteger&lt;/code&gt;. It is &lt;code&gt;T.fromDecimal(text)&lt;/code&gt;, the text the literal as written
with its sign and any exponent and without its separators (&lt;code&gt;-1_000.5e-3&lt;/code&gt; passes &lt;code&gt;&amp;quot;-1000.5e-3&amp;quot;&lt;/code&gt;),
so no digit is rounded through a &lt;code&gt;real&lt;/code&gt;. A type parameter bounded by &lt;code&gt;FromDecimal&lt;/code&gt; takes one the
same way.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;BigInt&lt;/code&gt; operand beside one is converted to it&lt;/strong&gt;, as &lt;code&gt;T.fromBigInt(n)&lt;/code&gt;, under the operators,
the comparisons and &lt;code&gt;==&lt;/code&gt;, on either side, as an integer operand is for &lt;code&gt;FromInteger&lt;/code&gt;. A type that
takes integers alone takes no &lt;code&gt;BigInt&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;real&lt;/code&gt; value is never converted&lt;/strong&gt;, and a decimal literal is no pattern for such a type.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;byte&quot;&gt;byte&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;byte&lt;/code&gt; is an octet with a value from 0 to 255. It is the element of binary data — file contents,
network buffers, encoded text — rather than a small number, so it has equality, ordering, the
bitwise operators &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt;, and shifts, but no arithmetic. &lt;code&gt;int(b)&lt;/code&gt; gives its value
(0–255), and &lt;code&gt;byte(n)&lt;/code&gt; makes one from an integer, trapping when &lt;code&gt;n&lt;/code&gt; is outside 0–255. An integer
literal in a &lt;code&gt;byte&lt;/code&gt; context must be in 0–255: &lt;code&gt;val mask: byte = 0xf0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;real-and-char&quot;&gt;real and char&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;real&lt;/code&gt; arithmetic follows IEEE 754, including NaN and signed zero; comparisons with NaN are false
except &lt;code&gt;!=&lt;/code&gt;. &lt;code&gt;x.isNaN&lt;/code&gt;, &lt;code&gt;x.isInfinite&lt;/code&gt; (either infinity) and &lt;code&gt;x.isFinite&lt;/code&gt; (neither) classify a
value, and each value is exactly one of NaN, infinite or finite. &lt;code&gt;x.toInt&lt;/code&gt; and &lt;code&gt;x.toLong&lt;/code&gt; are
&lt;code&gt;int(x)&lt;/code&gt; and &lt;code&gt;long(x)&lt;/code&gt;, truncating toward zero, saturating at the bounds and mapping NaN to zero;
&lt;code&gt;x.toReal&lt;/code&gt; is &lt;code&gt;x&lt;/code&gt;. There is no implicit fused multiply-add. The square root, logarithms,
trigonometry and the other elementary functions are in the module
&lt;a href=&quot;/spec/system-library/#avin-math&quot;&gt;&lt;code&gt;avin.math&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;math.sqrt(x)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;x.toBits&lt;/code&gt; is the IEEE 754 binary64 encoding of &lt;code&gt;x&lt;/code&gt; as a &lt;code&gt;long&lt;/code&gt;, sign bit highest, and
&lt;code&gt;real.fromBits(bits)&lt;/code&gt; the number of an encoding: &lt;code&gt;1.0.toBits&lt;/code&gt; is &lt;code&gt;0x3FF0000000000000&lt;/code&gt;, &lt;code&gt;(-0.0).toBits&lt;/code&gt;
is &lt;code&gt;long.MinValue&lt;/code&gt;, and the two are inverses for every encoding, a NaN’s payload included. Since
there is no single-precision type, binary32 is reached through its encoding, for a file format or a
wire protocol that carries one: &lt;code&gt;real.fromBits32(bits: int)&lt;/code&gt; widens a binary32 exactly, and
&lt;code&gt;x.toBits32&lt;/code&gt; rounds &lt;code&gt;x&lt;/code&gt; to the nearest binary32, ties to even, a magnitude past binary32’s greatest
finite value becoming an infinity and one below half its least subnormal a zero of the same sign.
A NaN narrows to a quiet NaN, keeping as much of its payload as the platform’s conversion does (on
ARM64 and x86-64, the top 22 bits), so a signaling binary32 NaN comes back from
&lt;code&gt;real.fromBits32(b).toBits32&lt;/code&gt; with its quiet bit set; every other binary32 comes back as it was.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;main()
  println(1.0.toBits == 0x3FF0000000000000) // true
  println(real.fromBits(0x4000000000000000)) // 2
  println(real.fromBits32(0x3DCCCCCD)) // 0.10000000149011612
  println(0.1.toBits32 == 0x3DCCCCCD) // true
  println(1e39.toBits32 == 0x7F800000) // true
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;true
2
0.10000000149011612
true
true
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;char&lt;/code&gt; supports ordering and equality but no
arithmetic; &lt;code&gt;int(c)&lt;/code&gt; and &lt;code&gt;char(n)&lt;/code&gt; convert.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;char&lt;/code&gt; has these methods, classifying by the Unicode Character Database:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isDigit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A decimal digit of any script (category &lt;code&gt;Nd&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isLetter&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A letter of any script (categories &lt;code&gt;Lu&lt;/code&gt;, &lt;code&gt;Ll&lt;/code&gt;, &lt;code&gt;Lt&lt;/code&gt;, &lt;code&gt;Lm&lt;/code&gt;, &lt;code&gt;Lo&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isLetterOrDigit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;isLetter&lt;/code&gt; or &lt;code&gt;isDigit&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isWhitespace&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A space separator other than the non-breaking ones (U+00A0, U+2007, U+202F), or U+0009 to U+000D, or U+001C to U+001F; this is not &lt;code&gt;strip&lt;/code&gt;‘s test, which is the &lt;code&gt;White_Space&lt;/code&gt; property and so counts U+00A0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isSpaceChar&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A character of category &lt;code&gt;Zs&lt;/code&gt;, &lt;code&gt;Zl&lt;/code&gt; or &lt;code&gt;Zp&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isUpper&lt;/code&gt;, &lt;code&gt;isLower&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Cased and upper, cased and lower&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isControl&lt;/code&gt;&lt;/td&gt;&lt;td&gt;U+0000 to U+001F and U+007F to U+009F&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;displayWidth&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The columns of a terminal it takes drawn on its own: 2, 1, or 0 (&lt;a href=&quot;#display-width&quot;&gt;Display width&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toUpper&lt;/code&gt;, &lt;code&gt;toLower&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The simple case mapping, one character for one: &lt;code&gt;&apos;ß&apos;.toUpper&lt;/code&gt; is &lt;code&gt;&apos;ß&apos;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;asDigit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The digit’s value in radix 36: a decimal digit of any script gives its value, an ASCII or fullwidth letter, either case, gives 10 to 35; any other character gives -1&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;string&quot;&gt;string&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;string&lt;/code&gt; is a built-in value type with no identity: two equal strings are interchangeable, and
&lt;code&gt;===&lt;/code&gt; is not defined on them. It is immutable UTF-8.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;string&lt;/code&gt; is a built-in type, not a class. It is final; its representation is its own, a length and its
bytes inline in one object; it gets its methods from the library through &lt;code&gt;impl string&lt;/code&gt;; and it
conforms to traits through &lt;code&gt;impl&lt;/code&gt; (&lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;). A type pattern &lt;code&gt;s: string&lt;/code&gt; on an
&lt;code&gt;Any&lt;/code&gt; matches it like any other type.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;s.byteLength&lt;/code&gt; is O(1). Iteration is by &lt;code&gt;char&lt;/code&gt; (&lt;code&gt;s.chars&lt;/code&gt;) or by byte (&lt;code&gt;s.bytes&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;There is no &lt;code&gt;s(i)&lt;/code&gt; returning a char by index, because that would be O(n) behind O(1) syntax.
Slicing takes byte offsets and traps on an offset that is not a character boundary.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;+&lt;/code&gt; concatenates two strings and nothing else. Other values reach text through interpolation
(&lt;code&gt;s&amp;quot;${x}&amp;quot;&lt;/code&gt;) or &lt;code&gt;x.toString()&lt;/code&gt;, both of which use &lt;code&gt;Display&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ordering is by code point, which for UTF-8 is byte order.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The library’s methods on &lt;code&gt;string&lt;/code&gt;. Offsets and lengths count bytes and are &lt;code&gt;int&lt;/code&gt;; a string holds at
most the largest &lt;code&gt;int&lt;/code&gt; bytes. Every offset a search answers is one where a character begins, or the
end, so it can be given to &lt;code&gt;charAt&lt;/code&gt; or &lt;code&gt;slice&lt;/code&gt; again, and a search from an offset inside a
character never traps: it starts from the next character, or searching back, from the one the
offset is inside.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;byteLength&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number of bytes, O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;charCount&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number of characters, O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether it has no bytes, or some&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;startsWith(p)&lt;/code&gt;, &lt;code&gt;endsWith(p)&lt;/code&gt;, &lt;code&gt;contains(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;p&lt;/code&gt; occurs at the start, the end, anywhere; the empty string occurs in every string&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;startsWith(p, at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;p&lt;/code&gt; occurs at byte offset &lt;code&gt;at&lt;/code&gt;; false when it would reach outside the string, and the empty string occurs only where a character begins or at the end&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;byteAt(at)&lt;/code&gt;, &lt;code&gt;charAt(at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The byte at offset &lt;code&gt;at&lt;/code&gt;, and the character whose encoding begins there; each traps when &lt;code&gt;at&lt;/code&gt; is outside the string, and &lt;code&gt;charAt&lt;/code&gt; also when &lt;code&gt;at&lt;/code&gt; is inside a character’s encoding&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;slice(from, until)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes from &lt;code&gt;from&lt;/code&gt; up to &lt;code&gt;until&lt;/code&gt;; traps unless &lt;code&gt;0 &amp;lt;= from &amp;lt;= until &amp;lt;= byteLength()&lt;/code&gt; and both offsets are character boundaries&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toUpper&lt;/code&gt;, &lt;code&gt;toLower&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Each character’s simple case mapping, one character for one, as &lt;code&gt;char&lt;/code&gt;‘s methods of the same names map it: &lt;code&gt;&amp;quot;straße&amp;quot;.toUpper&lt;/code&gt; is &lt;code&gt;STRAßE&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;normalize(form)&lt;/code&gt;, &lt;code&gt;isNormalized(form)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The string in a Unicode normalization form, &lt;code&gt;Nfc&lt;/code&gt;, &lt;code&gt;Nfd&lt;/code&gt;, &lt;code&gt;Nfkc&lt;/code&gt; or &lt;code&gt;Nfkd&lt;/code&gt;, and whether it is in it already (&lt;a href=&quot;#normalization&quot;&gt;Normalization&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;strip&lt;/code&gt;, &lt;code&gt;stripLeading&lt;/code&gt;, &lt;code&gt;stripTrailing&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Without the Unicode &lt;code&gt;White_Space&lt;/code&gt; characters at both ends, the start, the end&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;trim&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Without the characters up to U+0020, the ASCII controls and the space, at both ends&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;repeat(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;n&lt;/code&gt; copies joined; empty for zero; traps when &lt;code&gt;n&lt;/code&gt; is negative&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;replace(old, new)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every occurrence of &lt;code&gt;old&lt;/code&gt;, left to right and not overlapping, replaced by &lt;code&gt;new&lt;/code&gt;; an empty &lt;code&gt;old&lt;/code&gt; occurs nowhere&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;indexOf(p)&lt;/code&gt;, &lt;code&gt;indexOf(p, from)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The byte offset of the first &lt;code&gt;p&lt;/code&gt;, a string or a &lt;code&gt;char&lt;/code&gt;, at or after &lt;code&gt;from&lt;/code&gt; (default 0; below 0 counts as 0); -1 when there is none or &lt;code&gt;from&lt;/code&gt; is past the end. The empty string is found at &lt;code&gt;from&lt;/code&gt;, or at the next character when &lt;code&gt;from&lt;/code&gt; is inside one&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lastIndexOf(p)&lt;/code&gt;, &lt;code&gt;lastIndexOf(p, end)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The byte offset of the last &lt;code&gt;p&lt;/code&gt;, a string or a &lt;code&gt;char&lt;/code&gt;, beginning at or before &lt;code&gt;end&lt;/code&gt; (default &lt;code&gt;byteLength&lt;/code&gt;); -1 when there is none. The empty string is found at &lt;code&gt;end&lt;/code&gt;, at the start of the character &lt;code&gt;end&lt;/code&gt; is inside, or at &lt;code&gt;byteLength&lt;/code&gt; when &lt;code&gt;end&lt;/code&gt; is past it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;indexWhere(f)&lt;/code&gt;, &lt;code&gt;indexWhere(f, from)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The byte offset of the first character satisfying &lt;code&gt;f&lt;/code&gt;, at or after &lt;code&gt;from&lt;/code&gt;; -1 when none does&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lastIndexWhere(f)&lt;/code&gt;, &lt;code&gt;lastIndexWhere(f, end)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The byte offset of the last character satisfying &lt;code&gt;f&lt;/code&gt; that begins at or before &lt;code&gt;end&lt;/code&gt; (default: the whole string); -1 when none does or &lt;code&gt;end&lt;/code&gt; is below 0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The first and the last character; each traps on the empty string&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Some&lt;/code&gt; of the first or the last character; &lt;code&gt;None&lt;/code&gt; for the empty string&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stripPrefix(p)&lt;/code&gt;, &lt;code&gt;stripSuffix(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Without &lt;code&gt;p&lt;/code&gt; at the start, without &lt;code&gt;s&lt;/code&gt; at the end; the string unchanged where it is not there&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;capitalize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;With a lower-case first character mapped to upper case, and unchanged otherwise&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stripMargin()&lt;/code&gt;, &lt;code&gt;stripMargin(c)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Each line with its leading characters up to U+0020 and the margin character after them (a vertical bar, or &lt;code&gt;c&lt;/code&gt;) removed; a line whose first other character is not the margin is unchanged, and the line terminators stay&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;chars&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The characters, in order, as a &lt;code&gt;Vector[char]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;bytes&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes of the encoding, in order, as a &lt;code&gt;Vector[byte]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;utf8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes of the encoding in a new &lt;code&gt;Array[byte]&lt;/code&gt;, &lt;code&gt;byteLength&lt;/code&gt; of them, which the caller owns: each call makes another, so writing to one changes neither the string nor any other. It is what a file, a socket or a request body is written from, and &lt;code&gt;string.fromUtf8(s.utf8)&lt;/code&gt; is &lt;code&gt;Ok(s)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;count(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number of characters satisfying &lt;code&gt;p&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;split(sep)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The pieces between the occurrences of &lt;code&gt;sep&lt;/code&gt;, as a &lt;code&gt;Vector[string]&lt;/code&gt;; empty pieces are kept (&lt;code&gt;&amp;quot;,a,,b,&amp;quot;.split(&amp;quot;,&amp;quot;)&lt;/code&gt; has five pieces), and a string without &lt;code&gt;sep&lt;/code&gt; is one piece. An empty &lt;code&gt;sep&lt;/code&gt; traps&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lines&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The lines as a &lt;code&gt;Vector[string]&lt;/code&gt;, each ended by &lt;code&gt;\n&lt;/code&gt; or &lt;code&gt;\r\n&lt;/code&gt; and shown without it; a terminator at the very end starts no further line, so &lt;code&gt;&amp;quot;a\nb\n&amp;quot;.lines&lt;/code&gt; is two lines and &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; has none. A &lt;code&gt;\r&lt;/code&gt; not before &lt;code&gt;\n&lt;/code&gt; stays in its line&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isBlank&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether it has only &lt;code&gt;White_Space&lt;/code&gt; characters, so the empty string is blank&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reverse&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The characters in the opposite order&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;padStart(w, c)&lt;/code&gt;, &lt;code&gt;padEnd(w, c)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;At least &lt;code&gt;w&lt;/code&gt; characters, &lt;code&gt;c&lt;/code&gt; (default &lt;code&gt;&apos; &apos;&lt;/code&gt;) repeated before, after; &lt;code&gt;w&lt;/code&gt; counts characters, not bytes, and a string already that long is unchanged&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;padTo(n, c)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;padEnd(n, c)&lt;/code&gt;, the name a sequence’s padding has&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;displayWidth&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The columns of a terminal it takes, cluster by cluster (&lt;a href=&quot;#display-width&quot;&gt;Display width&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;padStartWidth(w, c)&lt;/code&gt;, &lt;code&gt;padEndWidth(w, c)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;At least &lt;code&gt;w&lt;/code&gt; columns of a terminal wide, &lt;code&gt;c&lt;/code&gt; (default &lt;code&gt;&apos; &apos;&lt;/code&gt;) repeated before, after as often as it fits, and a space for a column a wide &lt;code&gt;c&lt;/code&gt; leaves over; a string already that wide is unchanged, and a &lt;code&gt;c&lt;/code&gt; that takes no column traps when padding is needed&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;truncateWidth(w, e)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;At most &lt;code&gt;w&lt;/code&gt; columns wide: the string itself when it fits, or else as many whole clusters from the start as fit with the ellipsis &lt;code&gt;e&lt;/code&gt; (default &lt;code&gt;&amp;quot;…&amp;quot;&lt;/code&gt;) after them; an ellipsis wider than &lt;code&gt;w&lt;/code&gt; is left off, and a &lt;code&gt;w&lt;/code&gt; of 0 or less keeps nothing&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;equalsIgnoreCase(o)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the two are equal after each character’s simple lower-case mapping&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;take(n)&lt;/code&gt;, &lt;code&gt;drop(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The first &lt;code&gt;n&lt;/code&gt; characters, all but the first &lt;code&gt;n&lt;/code&gt;; &lt;code&gt;n&lt;/code&gt; counts characters, not bytes, and is clamped to the string, so 0 or less takes none&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;takeRight(n)&lt;/code&gt;, &lt;code&gt;dropRight(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The last &lt;code&gt;n&lt;/code&gt; characters, all but the last &lt;code&gt;n&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toInt()&lt;/code&gt;, &lt;code&gt;toLong()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number written in decimal: an optional &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt;, then one or more ASCII digits and nothing else; a trap, &lt;code&gt;For input string: &amp;quot;…&amp;quot;&lt;/code&gt;, otherwise or when it does not fit the type&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toReal()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number written as a decimal fraction, correctly rounded: an optional sign, digits with an optional point, an optional exponent (&lt;code&gt;3.25&lt;/code&gt;, &lt;code&gt;-.5&lt;/code&gt;, &lt;code&gt;1e10&lt;/code&gt;); a trap, as &lt;code&gt;toInt&lt;/code&gt;‘s, for anything else, including white space, &lt;code&gt;nan&lt;/code&gt;, &lt;code&gt;inf&lt;/code&gt;, hexadecimal, and a number too large to be finite&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toIntOption()&lt;/code&gt;, &lt;code&gt;toLongOption()&lt;/code&gt;, &lt;code&gt;toRealOption()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Some&lt;/code&gt; of the number &lt;code&gt;toInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt; or &lt;code&gt;toReal&lt;/code&gt; reads, and &lt;code&gt;None&lt;/code&gt; where it would trap&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toInt(radix)&lt;/code&gt;, &lt;code&gt;toLong(radix)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;toInt()&lt;/code&gt; and &lt;code&gt;toLong()&lt;/code&gt; with digits of base &lt;code&gt;radix&lt;/code&gt;, 2 to 36: &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;9&lt;/code&gt;, then &lt;code&gt;a&lt;/code&gt;–&lt;code&gt;z&lt;/code&gt; in either case; the same trap for text that is not such a number or does not fit, and a trap for a &lt;code&gt;radix&lt;/code&gt; outside 2 to 36&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toIntOption(radix)&lt;/code&gt;, &lt;code&gt;toLongOption(radix)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Some&lt;/code&gt; of the number the radix form reads, and &lt;code&gt;None&lt;/code&gt; where its text would trap; a &lt;code&gt;radix&lt;/code&gt; outside 2 to 36 still traps, being the caller’s mistake and not the text’s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toBool()&lt;/code&gt;, &lt;code&gt;toBoolOption()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;true&lt;/code&gt; for the text &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; for &lt;code&gt;false&lt;/code&gt;, exactly (no other case, no white space); &lt;code&gt;toBool&lt;/code&gt; traps, as &lt;code&gt;toInt&lt;/code&gt; does, on any other text and &lt;code&gt;toBoolOption&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;map(f)&lt;/code&gt;, &lt;code&gt;flatMap(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A string of &lt;code&gt;f&lt;/code&gt; applied to each character: &lt;code&gt;f&lt;/code&gt; answers a &lt;code&gt;char&lt;/code&gt; for &lt;code&gt;map&lt;/code&gt; and a &lt;code&gt;string&lt;/code&gt; for &lt;code&gt;flatMap&lt;/code&gt;, and the results are joined in order&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;filter(p)&lt;/code&gt;, &lt;code&gt;filterNot(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The characters that do, or do not, satisfy &lt;code&gt;p&lt;/code&gt;, in order&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;foreach(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Calls &lt;code&gt;f&lt;/code&gt; on each character, in order&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exists(p)&lt;/code&gt;, &lt;code&gt;forall(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether some, or every, character satisfies &lt;code&gt;p&lt;/code&gt;; false and true for the empty string&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;find(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Some&lt;/code&gt; of the first character satisfying &lt;code&gt;p&lt;/code&gt;, or &lt;code&gt;None&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;takeWhile(p)&lt;/code&gt;, &lt;code&gt;dropWhile(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The longest prefix whose characters all satisfy &lt;code&gt;p&lt;/code&gt;, and the string without it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;span(p)&lt;/code&gt;, &lt;code&gt;partition(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A pair of strings: the longest prefix satisfying &lt;code&gt;p&lt;/code&gt; and the rest; the characters that satisfy &lt;code&gt;p&lt;/code&gt; and those that do not&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;splitAt(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The pair of the first &lt;code&gt;n&lt;/code&gt; characters and the rest; &lt;code&gt;n&lt;/code&gt; is clamped as &lt;code&gt;take&lt;/code&gt;‘s is&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;&lt;/td&gt;&lt;td&gt;All but the first, and all but the last, character; each traps on the empty string&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;charIterator()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The characters as an &lt;code&gt;Iterator[char]&lt;/code&gt; that decodes one character for each &lt;code&gt;next()&lt;/code&gt;, making no vector&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;split(c)&lt;/code&gt;, &lt;code&gt;split(sep, limit)&lt;/code&gt;, &lt;code&gt;split(c, limit)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;split&lt;/code&gt; with a &lt;code&gt;char&lt;/code&gt; separator; and with at most &lt;code&gt;limit&lt;/code&gt; pieces, the last holding the rest of the text with its separators. A &lt;code&gt;limit&lt;/code&gt; of 0 or less sets none, 1 gives the whole string, and an empty string separator traps&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stripLineEnd&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Without one &lt;code&gt;\n&lt;/code&gt; or &lt;code&gt;\r\n&lt;/code&gt; at its end; a lone &lt;code&gt;\r&lt;/code&gt;, or no terminator, leaves it unchanged&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;compareIgnoreCase(o)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The sign of the comparison after each character’s simple lower-case mapping: negative, zero or positive&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val word = &amp;quot;café&amp;quot;
println(s&amp;quot;${word.byteLength} ${word.charCount}&amp;quot;)   // 5 4
println(word.slice(3, 5))                               // é
println(word.slice(0, 4))                               // traps: offset 4 is inside `é`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A string has no &lt;code&gt;length&lt;/code&gt; or &lt;code&gt;size&lt;/code&gt;, since its length is counted in characters or in bytes, and
asking for one names both; nor does &lt;code&gt;*&lt;/code&gt; repeat it, and the error names &lt;code&gt;repeat&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;word.length    // string has no field `length`; a string counts its characters with `charCount` and its bytes with `byteLength`
word.toUpperCase  // string has no field `toUpperCase`; a string maps its case with `toUpper` and `toLower`, as a `char` does
&amp;quot;-&amp;quot; * 3        // `*` needs two numbers of one type, not string and int; a string is repeated by `repeat`, as in `text.repeat(n)`
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;strings-from-bytes&quot;&gt;Strings from bytes&lt;/h3&gt;
&lt;p&gt;Bytes become a string through two &lt;a href=&quot;/spec/declarations/#static-members-of-built-in-types&quot;&gt;static members&lt;/a&gt;
of &lt;code&gt;string&lt;/code&gt;, which check that the bytes are UTF-8, since a string’s bytes always are:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Static member&lt;/th&gt;&lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;string.fromUtf8(bytes: Array[byte])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Ok&lt;/code&gt; of the text the bytes encode, or &lt;code&gt;Err&lt;/code&gt; of a &lt;code&gt;Utf8Error&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;string.fromUtf8Lossy(bytes: Array[byte])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text, with U+FFFD, the replacement character, in place of each maximal run of bytes that is not UTF-8: a sequence the bytes end inside is one replacement, a stray continuation byte another&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;data Utf8Error(offset: long, truncated: bool)&lt;/code&gt; says where and why: &lt;code&gt;offset&lt;/code&gt; is the byte offset at
which the first sequence that is not a character begins, and &lt;code&gt;truncated&lt;/code&gt; is true where the bytes end
inside a sequence that more bytes could complete, and false where they hold one no continuation
could make a character. Refused are a continuation byte that begins nothing, an overlong encoding
(&lt;code&gt;C0 AF&lt;/code&gt; for &lt;code&gt;/&lt;/code&gt;), a surrogate (&lt;code&gt;ED A0 80&lt;/code&gt;), a value past U+10FFFF (&lt;code&gt;F4 90 80 80&lt;/code&gt;), a byte no
sequence begins with (&lt;code&gt;FF&lt;/code&gt;), and a sequence cut short.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val bytes = &amp;quot;naïve&amp;quot;.utf8
println(string.fromUtf8(bytes))                          // Ok(naïve)
val cut: Array[byte] = [0x61, 0xE2, 0x82]
println(string.fromUtf8(cut))                            // Err(Utf8Error(1, true))
println(string.fromUtf8Lossy(cut))                       // a�
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;normalization&quot;&gt;Normalization&lt;/h3&gt;
&lt;p&gt;The same text can be more than one sequence of characters: &lt;code&gt;é&lt;/code&gt; is one character, U+00E9, or two,
&lt;code&gt;e&lt;/code&gt; and the combining acute accent U+0301, and &lt;code&gt;==&lt;/code&gt; compares characters, so the two are not equal.
&lt;code&gt;s.normalize(form)&lt;/code&gt; puts a string in one of the four Unicode normalization forms (UAX #15), the
values of &lt;code&gt;NormalizationForm&lt;/code&gt;, and &lt;code&gt;s.isNormalized(form)&lt;/code&gt; says whether it is in that form already,
by the Unicode Character Database 17.0.0, the one &lt;code&gt;char&lt;/code&gt;‘s methods answer from:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Form&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Nfc&lt;/code&gt;&lt;/td&gt;&lt;td&gt;NFC: canonical decomposition, then canonical composition. The form for storing and sending text&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Nfd&lt;/code&gt;&lt;/td&gt;&lt;td&gt;NFD: canonical decomposition, the combining marks in canonical order&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Nfkc&lt;/code&gt;&lt;/td&gt;&lt;td&gt;NFKC: compatibility decomposition, then canonical composition: &lt;code&gt;ﬁ&lt;/code&gt; is &lt;code&gt;fi&lt;/code&gt;, &lt;code&gt;①&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt;, a fullwidth &lt;code&gt;Ａ&lt;/code&gt; is &lt;code&gt;A&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Nfkd&lt;/code&gt;&lt;/td&gt;&lt;td&gt;NFKD: compatibility decomposition, the combining marks in canonical order&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Hangul syllables compose and decompose by their algorithm; a code point unassigned in the database
is left as it is. A string of ASCII characters only is in all four forms and is returned at once,
unexamined. The compatibility forms discard distinctions, so they are for comparing and matching
rather than for storing. &lt;a href=&quot;/spec/system-library/#avin-crypto&quot;&gt;&lt;code&gt;avin.crypto.saslPrep&lt;/code&gt;&lt;/a&gt; applies NFKC
as part of preparing a password.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;main()
  val composed = &amp;quot;caf\u{e9}&amp;quot;
  val decomposed = &amp;quot;cafe\u{301}&amp;quot;
  println(composed == decomposed) // false
  println(decomposed.normalize(Nfc) == composed) // true
  println(composed.normalize(Nfd).charCount) // 5
  println(&amp;quot;\u{fb01}le \u{2460}&amp;quot;.normalize(Nfkc)) // file 1
  println(composed.isNormalized(Nfc)) // true
  println(decomposed.isNormalized(Nfc)) // false
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;false
true
5
file 1
true
false
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;display-width&quot;&gt;Display width&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;displayWidth&lt;/code&gt; is the number of columns of a terminal, in a fixed-width font, a character or a
string takes, which is what lines text up in a table or a help screen; &lt;code&gt;charCount&lt;/code&gt; is not, since a CJK
ideograph takes two columns and a combining accent none. A character on its own takes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2 when it is East Asian Wide or Fullwidth: CJK ideographs, kana, Hangul syllables, fullwidth forms,
and the emoji shown as pictures by default (&lt;code&gt;&apos;😀&apos;&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;0 when it is a nonspacing or enclosing mark (a combining accent, a variation selector), a format
character (the zero-width space and joiner, the bidirectional marks), or a Hangul vowel or final
that joins the syllable before it; the soft hyphen and the marks written before a number are
shown, and take 1;&lt;/li&gt;
&lt;li&gt;0 when it is a control character, U+0000 to U+001F and U+007F to U+009F, tab and newline included:
where one moves the cursor is the terminal’s business, not a width;&lt;/li&gt;
&lt;li&gt;1 otherwise, the East Asian Ambiguous characters and unassigned code points included.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A string is measured cluster by cluster, as a modern terminal draws it. A cluster is a character with
the zero-width characters after it, a skin-tone modifier after an emoji, and, when it is a
pictograph, each pictograph a zero-width joiner joins to it. A cluster is as wide as its first
character, except that a variation selector 16 after an emoji makes it 2 (&lt;code&gt;❤️&lt;/code&gt;, the keycap &lt;code&gt;1️⃣&lt;/code&gt;), a
skin tone makes an emoji 2, and two regional indicators are one flag of 2. A control character is a
cluster of its own. The table is the Unicode Character Database’s, version 17.0.0.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;quot;hello&amp;quot;.displayWidth          // 5
&amp;quot;日本語&amp;quot;.displayWidth          // 6
&amp;quot;e\u{301}&amp;quot;.displayWidth       // 1: an e and a combining acute
&amp;quot;👩🏽‍💻&amp;quot;.displayWidth            // 2: a skin tone and a joined pictograph
&amp;quot;日本&amp;quot;.padEndWidth(6) + &amp;quot;|&amp;quot;   // 日本  |
&amp;quot;日本語テキスト&amp;quot;.truncateWidth(7)  // 日本語…
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A formatted field’s width counts these columns too, so &lt;code&gt;f&amp;quot;${name}%-10s&amp;quot;&lt;/code&gt; lines up whatever &lt;code&gt;name&lt;/code&gt;
is written in (&lt;a href=&quot;/spec/strings-and-formatting/&quot;&gt;Strings and formatting&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&quot;unit&quot;&gt;unit&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;unit&lt;/code&gt; has the single value &lt;code&gt;()&lt;/code&gt;. It is an ordinary type: it can be a type argument, a field, a
parameter, and a pattern. A function whose body is an indented block with no &lt;code&gt;=&lt;/code&gt; and no result type
returns &lt;code&gt;unit&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;tuples&quot;&gt;Tuples&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;(A, B, …)&lt;/code&gt; is a tuple type of any arity, written and matched with parentheses: &lt;code&gt;(1, &amp;quot;one&amp;quot;)&lt;/code&gt;,
&lt;code&gt;(n, name) -&amp;gt; …&lt;/code&gt;. Elements are read with &lt;code&gt;t.0&lt;/code&gt;, &lt;code&gt;t.1&lt;/code&gt;, numbered from 0; asked for &lt;code&gt;t._1&lt;/code&gt; or
&lt;code&gt;t._2&lt;/code&gt;, the error names the part to write (&lt;code&gt;(string, int) has no field `_2`; a tuple&apos;s parts are numbered from 0, so write `.1` &lt;/code&gt;). Tuples are values with no identity and derive
&lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; when their elements do. A pair has &lt;code&gt;swap&lt;/code&gt;, the pair
with its parts the other way round: &lt;code&gt;(1, &amp;quot;one&amp;quot;).swap&lt;/code&gt; is &lt;code&gt;(&amp;quot;one&amp;quot;, 1)&lt;/code&gt;. A program adds methods to
tuples with an &lt;a href=&quot;/spec/declarations/#impl&quot;&gt;impl&lt;/a&gt; naming a tuple type built from its parameters,
&lt;code&gt;impl[A, B] (A, B)&lt;/code&gt; or &lt;code&gt;impl[A] (A, A)&lt;/code&gt;; only the core library implements a trait for tuples.&lt;/p&gt;
&lt;p&gt;Where a value fills the rest of a line, a tuple needs no parentheses: after &lt;code&gt;=&lt;/code&gt; in a function, clause
or binding, after &lt;code&gt;return&lt;/code&gt;, after &lt;code&gt;-&amp;gt;&lt;/code&gt; in a &lt;code&gt;match&lt;/code&gt; arm, and as a line of a block, including its
last. Inside brackets and in the body of a one-line &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;while&lt;/code&gt;, a comma separates other things,
so a tuple there is parenthesized, a &lt;code&gt;match&lt;/code&gt; arm’s one-line body inside brackets
&lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;included&lt;/a&gt;, and so is the last line of a block, a lambda’s
body, when that line closes a bracket opened before the block
(&lt;a href=&quot;/spec/operators-and-control-flow/#continuation-lines&quot;&gt;continuation lines&lt;/a&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;divmod(a: int, b: int) -&amp;gt; (int, int) = a / b, a % b

bounds(a: int, b: int) -&amp;gt; (int, int)
  if a &amp;gt; b then return b, a
  a, b
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A tuple is taken apart by a binding (&lt;code&gt;val q, r = divmod(17, 5)&lt;/code&gt;, &lt;code&gt;val (a, (b, c)) = t&lt;/code&gt;), by a
&lt;a href=&quot;/spec/operators-and-control-flow/#multiple-assignment&quot;&gt;multiple assignment&lt;/a&gt;, by tuple
patterns in &lt;code&gt;match&lt;/code&gt; and in clauses, and by a lambda’s parameters.&lt;/p&gt;
&lt;p&gt;Where a function of one parameter whose type is a tuple of &lt;em&gt;n&lt;/em&gt; elements is expected, &lt;em&gt;n&lt;/em&gt; at least
two, a lambda of exactly &lt;em&gt;n&lt;/em&gt; parameters takes the tuple apart: its parameters are the tuple’s
elements, in order, each typed from its element. A lambda of one parameter takes the tuple whole,
as it would anywhere.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val xs = [1, 2, 3]
xs.zip(xs).forall((x, y) -&amp;gt; x == y)          // true
xs.zip([&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;]).map((n, s) -&amp;gt; s&amp;quot;$s$n&amp;quot;) // [a1, b2, c3]
[((1, 2), 3)].map((p, z) -&amp;gt; p.0 + p.1 + z)   // [6]: an inner tuple is one element
map.filter((k, _) -&amp;gt; k != &amp;quot;skip&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;A parameter written with a type takes an element of that type, or of a narrower one as any
lambda’s parameter may, and its body sees the type written: &lt;code&gt;(a: Animal, n) -&amp;gt; …&lt;/code&gt; over
&lt;code&gt;(Dog, int)&lt;/code&gt; pairs. A declared type the element does not fit is an error naming the element.&lt;/li&gt;
&lt;li&gt;An element the expected type leaves unknown, as in a generic function’s &lt;code&gt;((A, B)) -&amp;gt; C&lt;/code&gt; whose
&lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; nothing else fixes, takes its type from the parameter’s declaration; one with neither
is an error asking for the type.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;_&lt;/code&gt; takes an element and binds nothing. Each parameter is a &lt;code&gt;val&lt;/code&gt;, as any lambda’s is.&lt;/li&gt;
&lt;li&gt;It applies only where the lambda’s parameters are not as many as the expected function’s: a
lambda of two parameters where &lt;code&gt;(A, B) -&amp;gt; C&lt;/code&gt; is expected takes two arguments. Among overloads, a
candidate that has a lambda take a tuple apart is chosen only where no candidate takes it as
written, so &lt;code&gt;Map&lt;/code&gt;‘s &lt;code&gt;map((k, v) -&amp;gt; (v, k))&lt;/code&gt; is its &lt;code&gt;(K, V) -&amp;gt; (L, W)&lt;/code&gt; overload.&lt;/li&gt;
&lt;li&gt;A lambda whose parameters are as many as neither the function’s nor the tuple’s elements is an
error naming both shapes: &lt;code&gt;expected a function of 1 parameter, (int, int), but this lambda takes 3: a lambda takes that tuple as one parameter or as 2 parameters, one for each element&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A &lt;a href=&quot;/spec/operators-and-control-flow/#match-functions&quot;&gt;&lt;code&gt;match&lt;/code&gt; function&lt;/a&gt;, &lt;code&gt;match (x, y) -&amp;gt; …&lt;/code&gt;, still
takes a tuple apart by a pattern, for shapes a list of names cannot write: nested tuples, literals,
variants.&lt;/p&gt;
&lt;h2 id=&quot;function-types&quot;&gt;Function types&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;(A, B) -&amp;gt; C&lt;/code&gt; is the type of a function taking &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; and returning &lt;code&gt;C&lt;/code&gt;; &lt;code&gt;() -&amp;gt; C&lt;/code&gt; takes nothing.
A function taking one parameter may drop the parentheses: &lt;code&gt;int -&amp;gt; string&lt;/code&gt;, &lt;code&gt;Option[T] -&amp;gt; bool&lt;/code&gt;.
&lt;code&gt;(A) -&amp;gt; B&lt;/code&gt; and &lt;code&gt;A -&amp;gt; B&lt;/code&gt; are the same type. &lt;code&gt;-&amp;gt;&lt;/code&gt; groups to the right, so &lt;code&gt;int -&amp;gt; int -&amp;gt; int&lt;/code&gt; is
&lt;code&gt;int -&amp;gt; (int -&amp;gt; int)&lt;/code&gt;, a function returning a function; a function taking a function writes the
parameter in parentheses, &lt;code&gt;(int -&amp;gt; int) -&amp;gt; int&lt;/code&gt;. A tuple parameter takes a second pair of
parentheses, &lt;code&gt;((A, B)) -&amp;gt; C&lt;/code&gt;, since &lt;code&gt;(A, B) -&amp;gt; C&lt;/code&gt; takes two parameters.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;twice(f: int -&amp;gt; int, x: int) -&amp;gt; int = f(f(x))
adder(n: int) -&amp;gt; int -&amp;gt; int = x -&amp;gt; x + n // the result is a function type
val fs: List[int -&amp;gt; int] = [adder(1), adder(2)]
val add: int -&amp;gt; int -&amp;gt; int = a -&amp;gt; b -&amp;gt; a + b
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The form works wherever a type does: parameters, fields, results, type arguments, tuple parts,
&lt;code&gt;val&lt;/code&gt; annotations and supertypes. A result of function form needs no parentheses, since the
declaration’s &lt;code&gt;=&lt;/code&gt; ends it. A type pattern in a &lt;code&gt;match&lt;/code&gt; arm is the exception: the arm’s &lt;code&gt;-&amp;gt;&lt;/code&gt; follows
the type, so a function type there is written in parentheses, &lt;code&gt;f: (int -&amp;gt; int) -&amp;gt; body&lt;/code&gt;.
Compiler messages print every function type with a parameter list, &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt;.
A by-name parameter type is written &lt;code&gt;-&amp;gt; T&lt;/code&gt; inside a parameter list; see
&lt;a href=&quot;/spec/by-name/&quot;&gt;call-by-name&lt;/a&gt;. Function types are traits: a class or trait may list a function type
among its parents after &lt;code&gt;:&lt;/code&gt;, and a data type or class may name one in an impl, and its values are
then subtypes of that function type, callable as &lt;code&gt;value(args)&lt;/code&gt; and usable wherever it is expected,
with no conversion. Such a type has an &lt;code&gt;apply&lt;/code&gt; taking exactly the function type’s parameters and
yielding its result or a subtype, and a call of the value as a function runs that &lt;code&gt;apply&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Shout: (string) -&amp;gt; string
    apply(s: string) -&amp;gt; string = s + &amp;quot;!&amp;quot;

data Lengths(extra: int)

impl (string) -&amp;gt; int for Lengths
    apply(s: string) -&amp;gt; int = s.charCount + extra

val f: (string) -&amp;gt; string = Shout()
[&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;].map(Lengths(1))      // [2, 2]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A function type in a parent list follows the variance rules of any parent: its parameters are
contravariant positions and its result a covariant one. A type is at most one function type,
counting those its superclass and traits are, and a built-in type is none. The core library’s
collections are functions this way: a &lt;code&gt;Seq[T]&lt;/code&gt; is an &lt;code&gt;(int) -&amp;gt; T&lt;/code&gt;, a &lt;code&gt;Set[A]&lt;/code&gt; an &lt;code&gt;(A) -&amp;gt; bool&lt;/code&gt; and a
&lt;code&gt;Map[K, V]&lt;/code&gt; a &lt;code&gt;(K) -&amp;gt; V&lt;/code&gt; (see &lt;a href=&quot;/spec/collections/#collections-as-functions&quot;&gt;collections&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;There is no arity limit.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Functions compose.&lt;/strong&gt; The core library adds to every function of one parameter &lt;code&gt;f.andThen(g)&lt;/code&gt;, the
function that runs &lt;code&gt;f&lt;/code&gt; and then &lt;code&gt;g&lt;/code&gt; on its result, and &lt;code&gt;f.compose(g)&lt;/code&gt;, which runs &lt;code&gt;g&lt;/code&gt; first; and to
every function of two parameters &lt;code&gt;f.tupled()&lt;/code&gt;, the function taking its two arguments as one pair. A
function type is a trait, so they reach every value that is a function of that shape: a lambda, a
reference to a function, a method value (of a method declared with a parameter list, one declared
with an empty list &lt;code&gt;()&lt;/code&gt; only where a function type is expected; a
&lt;a href=&quot;/spec/declarations/#parameterless-methods&quot;&gt;parameterless method&lt;/a&gt; has none, and &lt;code&gt;() -&amp;gt; x.head&lt;/code&gt; is the
function that reads one), and a value of a type naming a function type, a sequence or a map among
them. A type’s own method of the same name and parameter types is found first.
&lt;code&gt;identity&lt;/code&gt;, in the prelude, is the function that gives back its argument, for passing where a
function is asked for and nothing should change.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val inc = (x: int) -&amp;gt; x + 1
inc.andThen(x -&amp;gt; x * 2)(3)              // 8
inc.compose((x: int) -&amp;gt; x * 2)(3)       // 7
((a: int, b: int) -&amp;gt; a + b).tupled()((2, 3))   // 5
[1, 2, 3].andThen(n -&amp;gt; n * 10)(0)       // 10: a sequence is a function of its index
[[1], [2, 3]].flatMap(identity)         // [1, 2, 3]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A program may add methods to function types the same way, with an
&lt;a href=&quot;/spec/declarations/#impl&quot;&gt;impl&lt;/a&gt; naming one: &lt;code&gt;impl[A] (A) -&amp;gt; A&lt;/code&gt;, &lt;code&gt;impl[A, B, C] (A, B) -&amp;gt; C&lt;/code&gt;. A
&lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt; there adds only to &lt;code&gt;@sendable&lt;/code&gt; functions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;@sendable&lt;/code&gt; before a function type&lt;/strong&gt;, &lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt;, makes the type of a function that may
run on any thread: it captures only sendable values and no &lt;code&gt;var&lt;/code&gt;, and the code it runs reaches no
module-level mutable state (&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;threads&lt;/a&gt;). Such a type is &lt;code&gt;Sendable&lt;/code&gt;, and
a plain function type is not, since it does not say what its values capture. Only a function type
may be marked; &lt;code&gt;@sendable int&lt;/code&gt; is an error. A &lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt; is a &lt;code&gt;(A) -&amp;gt; B&lt;/code&gt;, with no
conversion, so it is passed wherever the plain type is expected and a vector of them is a vector of
the plain type; a plain function value is not a &lt;code&gt;@sendable&lt;/code&gt; one. A lambda, a reference to a function
and a method value written where a &lt;code&gt;@sendable&lt;/code&gt; function type is expected are made as one, and are
checked there as a thread’s body is. Inside a function, a parameter marked
&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;&lt;code&gt;@sendable&lt;/code&gt;&lt;/a&gt; that takes a function holds a &lt;code&gt;@sendable&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val step: @sendable (int) -&amp;gt; int = (x) -&amp;gt; x + 1 // checked: captures nothing
val named: @sendable (int) -&amp;gt; int = double // checked: what `double` reaches
val plain: (int) -&amp;gt; int = step // a @sendable function is a plain one
val back: @sendable (int) -&amp;gt; int = plain // error: `plain`&apos;s type does not say what it captures
adder(n: int) -&amp;gt; @sendable (int) -&amp;gt; int = (x) -&amp;gt; x + n
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Two overloads that differ only in whether a function parameter is &lt;code&gt;@sendable&lt;/code&gt; are the same
overload, as two that differ only in a by-name parameter are, since one lambda may be passed for
either. An override takes the parameter types of the method it overrides, the mark included, and
may yield a &lt;code&gt;@sendable&lt;/code&gt; function where that method yields the plain type. Messages print the mark
as it is written, &lt;code&gt;@sendable (int) -&amp;gt; int&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;placeholder-lambdas&quot;&gt;Placeholder lambdas&lt;/h3&gt;
&lt;p&gt;A call’s argument that holds &lt;code&gt;_&lt;/code&gt; is a lambda: each &lt;code&gt;_&lt;/code&gt; is a parameter of its own, in the order
written, and the argument is the body. A &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; with a declared type takes one the same way,
as does the body of a function with a declared result type, and each of its clauses’ bodies.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;xs.map(_ + 1)                 // xs.map(x -&amp;gt; x + 1)
people.map(_.name)            // people.map(p -&amp;gt; p.name)
xs.filter(0 &amp;lt; _ &amp;lt; 10)         // xs.filter(x -&amp;gt; 0 &amp;lt; x &amp;lt; 10)
xs.reduce(_ + _)              // xs.reduce((a, b) -&amp;gt; a + b)
people.sortBy(_.age)
xs.map(scale(_, 2))           // xs.map(x -&amp;gt; scale(x, 2))
orders.map(_.items.map(_ * 2))  // orders.map(o -&amp;gt; o.items.map(x -&amp;gt; x * 2))
val inc: (int) -&amp;gt; int = _ + 1
adder(n: int) -&amp;gt; (int) -&amp;gt; int = _ + n
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A branch is a place of its own.&lt;/strong&gt; Where an &lt;code&gt;if&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt; or a block stands in one of these
places, each branch of the &lt;code&gt;if&lt;/code&gt;, each arm of the &lt;code&gt;match&lt;/code&gt; and the block’s last line is a place in
turn, with the same rules, so a choice of functions reads as one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val key: (Request) -&amp;gt; string = by match
  &amp;quot;method&amp;quot; -&amp;gt; _.method
  &amp;quot;status&amp;quot; -&amp;gt; _.status.toString()
  _ -&amp;gt; _.path
xs.map(if up then _ + 1 else _ - 1)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The condition, the subject, a guard and a block’s earlier lines keep their own &lt;code&gt;_&lt;/code&gt;, and so do an
&lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; anywhere else: &lt;code&gt;val f = if up then _ + 1 else 0&lt;/code&gt;, with no declared type, is an
error, and so is a function’s body with no declared result. A branch may be a written lambda or
any other value of the function type beside the placeholder ones.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The lambda is the nearest argument holding the &lt;code&gt;_&lt;/code&gt;.&lt;/strong&gt; A &lt;code&gt;_&lt;/code&gt; is found through operators of every
precedence, member access and method calls on it, tuple parts (&lt;code&gt;(_, 0)&lt;/code&gt;), &lt;code&gt;is&lt;/code&gt;, a range’s bounds,
&lt;code&gt;with&lt;/code&gt;‘s base and a call’s callee, so &lt;code&gt;_.name.byteLength + 1&lt;/code&gt; is one lambda. Another call’s
argument is a lambda of its own: in &lt;code&gt;orders.map(_.items.map(_ * 2))&lt;/code&gt; the first &lt;code&gt;_&lt;/code&gt; is an order and
the second an item. A name ending in &lt;code&gt;:&lt;/code&gt; is written after its argument, so in &lt;code&gt;_ +: _&lt;/code&gt; the first
&lt;code&gt;_&lt;/code&gt; is the element.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;_&lt;/code&gt; that is a whole argument belongs to the argument around its call&lt;/strong&gt;: &lt;code&gt;xs.map(scale(_, 2))&lt;/code&gt;
is &lt;code&gt;xs.map(x -&amp;gt; scale(x, 2))&lt;/code&gt;, and &lt;code&gt;apply2(scale(_, 2) + _)&lt;/code&gt; is
&lt;code&gt;apply2((a, b) -&amp;gt; scale(a, 2) + b)&lt;/code&gt;. A lambda that would only call a named function with its
parameters in order, &lt;code&gt;xs.map(double(_))&lt;/code&gt;, is that function: it is an error saying to pass
&lt;code&gt;double&lt;/code&gt;. A constructor’s name is no function’s, so &lt;code&gt;xs.map(Some(_))&lt;/code&gt; is &lt;code&gt;x -&amp;gt; Some(x)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A lambda, a block, an &lt;code&gt;if&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt;, a collection literal and an interpolation keep their
own &lt;code&gt;_&lt;/code&gt;&lt;/strong&gt;: none of them is searched from around it, so &lt;code&gt;xs.map(n -&amp;gt; n + _)&lt;/code&gt; is an error, as is any
&lt;code&gt;_&lt;/code&gt; outside the places above, &lt;code&gt;val y = x + _&lt;/code&gt;; only an &lt;code&gt;if&lt;/code&gt;‘s branches, a &lt;code&gt;match&lt;/code&gt;‘s arms and a
block’s last line pass a place on. A &lt;code&gt;_&lt;/code&gt; alone as a whole argument of a call
that is itself no argument, &lt;code&gt;scale(_, 2)&lt;/code&gt; as a statement, is an error too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The parameters take their types from the function expected&lt;/strong&gt;, as any lambda’s do, and their
count must be its parameter count; a lambda of two &lt;code&gt;_&lt;/code&gt;s where a function of one tuple is
expected &lt;a href=&quot;#tuples&quot;&gt;takes the tuple apart&lt;/a&gt;, so &lt;code&gt;xs.zip(ys).map(_ + _)&lt;/code&gt; adds the pairs. A count
that fits neither is an error naming both counts, and a &lt;code&gt;_&lt;/code&gt; whose type nothing gives is an error
asking for the lambda to be written out with a type. Overloads see the lambda as they see one
written out: the number of &lt;code&gt;_&lt;/code&gt;s picks among overloads of different counts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each &lt;code&gt;_&lt;/code&gt; is used once, so a parameter read twice, or a parameter not read at all, is written as
an ordinary lambda.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The other meanings of &lt;code&gt;_&lt;/code&gt; are unchanged: a parameter &lt;code&gt;_ -&amp;gt;&lt;/code&gt; or &lt;code&gt;(_, b) -&amp;gt;&lt;/code&gt; binds nothing, a
pattern’s &lt;code&gt;_&lt;/code&gt; matches anything, &lt;code&gt;val _ =&lt;/code&gt;, a discarded part &lt;code&gt;q, _ = …&lt;/code&gt;, &lt;code&gt;for _ in&lt;/code&gt;, a clause’s &lt;code&gt;_&lt;/code&gt;
argument, the last guard &lt;code&gt;| _ =&lt;/code&gt;, the digit separator in &lt;code&gt;1_000&lt;/code&gt;, and a name that begins with &lt;code&gt;_&lt;/code&gt;,
such as &lt;code&gt;_offset&lt;/code&gt;, which is an ordinary name.&lt;/p&gt;
&lt;h3 id=&quot;partial-functions&quot;&gt;Partial functions&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;PartialFunction[-A, +B]&lt;/code&gt; is a core-library trait, and a subtype of &lt;code&gt;A -&amp;gt; B&lt;/code&gt;: a function defined at
some values of &lt;code&gt;A&lt;/code&gt; and not others. &lt;code&gt;isDefinedAt(a)&lt;/code&gt; says whether it is defined at &lt;code&gt;a&lt;/code&gt;; calling it,
&lt;code&gt;pf(a)&lt;/code&gt;, at a value it is not defined at traps, and the trap names the program’s call. &lt;code&gt;lift()&lt;/code&gt; is
the total function &lt;code&gt;A -&amp;gt; Option[B]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; where it is not defined; &lt;code&gt;applyOrElse(a, default)&lt;/code&gt; is its
value at &lt;code&gt;a&lt;/code&gt;, or &lt;code&gt;default(a)&lt;/code&gt; where it is not defined; &lt;code&gt;pf.orElse(other)&lt;/code&gt; is &lt;code&gt;pf&lt;/code&gt; where it is
defined and &lt;code&gt;other&lt;/code&gt; elsewhere. A &lt;a href=&quot;/spec/operators-and-control-flow/#match-functions&quot;&gt;&lt;code&gt;match&lt;/code&gt; with nothing before
it&lt;/a&gt;, written where a &lt;code&gt;PartialFunction&lt;/code&gt; is
expected, makes one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val half: PartialFunction[int, int] = match n if n % 2 == 0 -&amp;gt; n / 2
half.isDefinedAt(3)           // false
half.applyOrElse(3, n -&amp;gt; n)   // 3
[2, 4].map(half)              // [1, 2]: a partial function passes where `int -&amp;gt; int` is expected
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;vector-types&quot;&gt;Vector types&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;[]T&lt;/code&gt; is another way to write &lt;code&gt;Vector[T]&lt;/code&gt;: the same type, in any position a type may stand.
&lt;code&gt;xs: []int&lt;/code&gt;, &lt;code&gt;[][]int&lt;/code&gt; (a &lt;code&gt;Vector[Vector[int]]&lt;/code&gt;), &lt;code&gt;Option[[]string]&lt;/code&gt; and &lt;code&gt;([]int, string)&lt;/code&gt; all work,
and a program’s entry point may be &lt;code&gt;main(args: []string)&lt;/code&gt;. The element is a name or a parenthesized
type, so &lt;code&gt;[]int -&amp;gt; int&lt;/code&gt; is a function taking a vector, &lt;code&gt;([]int) -&amp;gt; int&lt;/code&gt;, and &lt;code&gt;[](int -&amp;gt; int)&lt;/code&gt; is a
vector of functions. A type pattern in a &lt;code&gt;match&lt;/code&gt; arm takes the form without parentheses,
&lt;code&gt;v: []int -&amp;gt; body&lt;/code&gt;. There is no fixed-length &lt;code&gt;[N]T&lt;/code&gt;; &lt;code&gt;[3]int&lt;/code&gt; is an error, and &lt;code&gt;Array[T]&lt;/code&gt; is the
fixed-length contiguous collection. Compiler messages print the type as &lt;code&gt;Vector[int]&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;any-and-nothing&quot;&gt;Any and Nothing&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Any&lt;/code&gt; is the top type. Every reference type is a subtype of &lt;code&gt;Any&lt;/code&gt;. A value type (built-ins, tuples,
&lt;code&gt;data&lt;/code&gt;) converts to &lt;code&gt;Any&lt;/code&gt; by boxing at the point of conversion; the box records the exact type, so a
&lt;code&gt;match&lt;/code&gt; on an &lt;code&gt;Any&lt;/code&gt; recovers the value.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;describe(x: Any) -&amp;gt; string = x match
  s: string -&amp;gt; s&amp;quot;text $s&amp;quot;
  n: int -&amp;gt; s&amp;quot;number $n&amp;quot;
  _ -&amp;gt; &amp;quot;something else&amp;quot;

describe(42) // the int is boxed where it becomes an Any
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value converts to &lt;code&gt;Any&lt;/code&gt; wherever one is expected of it, at a single site: an argument, a binding,
an assignment, a field, a result, a part of a tuple written out, or each branch of an &lt;code&gt;if&lt;/code&gt; or
&lt;code&gt;match&lt;/code&gt; expected to yield an &lt;code&gt;Any&lt;/code&gt;. A tuple already made converts only where each part already is
what the wider tuple holds there: a part that is an object (a string, a &lt;code&gt;data&lt;/code&gt; value, a tuple, an
instance of a class) is its own &lt;code&gt;Any&lt;/code&gt;, so a &lt;code&gt;(string, int)&lt;/code&gt; is a &lt;code&gt;(Any, int)&lt;/code&gt;, and so is a &lt;code&gt;(P, int)&lt;/code&gt;
for a data type &lt;code&gt;P&lt;/code&gt;. A part that would need a box does not convert, since its layout differs and
boxing never happens inside a value already made: an &lt;code&gt;(int, int)&lt;/code&gt; is not an &lt;code&gt;(Any, int)&lt;/code&gt;, nor is a
&lt;code&gt;(bool, int)&lt;/code&gt;. A tuple written out where the wider one is expected, &lt;code&gt;(n, 1)&lt;/code&gt;, boxes its part there.&lt;/p&gt;
&lt;p&gt;How a value is boxed is the compiler’s choice, and invisible except in cost. A string, a tuple and a
&lt;code&gt;data&lt;/code&gt; value are already objects whose header names their exact type, so they need no box; a
number, a &lt;code&gt;char&lt;/code&gt;, a &lt;code&gt;bool&lt;/code&gt; and &lt;code&gt;unit&lt;/code&gt; get one. A tuple’s type at run time is the type it was made
with: &lt;code&gt;(animal, 1)&lt;/code&gt; with &lt;code&gt;animal: Animal&lt;/code&gt; is an &lt;code&gt;(Animal, int)&lt;/code&gt;, whatever class the animal is.&lt;/p&gt;
&lt;p&gt;A value of a built-in type or a tuple converts the same way to a trait it implements, at the same
sites: &lt;code&gt;val shown: Vector[Display] = [1, &amp;quot;two&amp;quot;, (3, 4)]&lt;/code&gt;, &lt;code&gt;describe(d: Display)&lt;/code&gt; called as
&lt;code&gt;describe(42)&lt;/code&gt;. Calls through the trait reach the type’s own implementation, and a type pattern
recovers the value: &lt;code&gt;d match n: int -&amp;gt; …&lt;/code&gt;. An overload taking the value’s own type is more specific
than one taking a trait it implements.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; on an &lt;code&gt;Any&lt;/code&gt; are decided at run time by the values’ own types: values of one type
compare as that type does, by value or by identity, and values of different types are unequal (see
&lt;a href=&quot;/spec/equality-and-memory/#equality&quot;&gt;equality&lt;/a&gt;). &lt;code&gt;===&lt;/code&gt; and &lt;code&gt;!==&lt;/code&gt; need a side whose type is a class,
since an &lt;code&gt;Any&lt;/code&gt; may hold a value with no identity: &lt;code&gt;x === obj&lt;/code&gt; is defined, and &lt;code&gt;x === y&lt;/code&gt; with both
&lt;code&gt;Any&lt;/code&gt;s is an error (see &lt;a href=&quot;/spec/equality-and-memory/#identity&quot;&gt;identity&lt;/a&gt;). A type pattern recovers the
value’s type, and with it the other comparisons that type has.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Nothing&lt;/code&gt; is the bottom type: the type of &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and a call to a function that
never returns. It is a subtype of every type, and an expression of type &lt;code&gt;Nothing&lt;/code&gt; never produces a
value. An empty collection literal or &lt;code&gt;None&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; have a &lt;code&gt;Nothing&lt;/code&gt; type argument; its type
comes from context (see &lt;a href=&quot;/spec/generics/#inference&quot;&gt;inference&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A function’s result is a covariant position, so a function whose result is &lt;code&gt;Nothing&lt;/code&gt; is a function
of every result type: a named function, a lambda, a method value or any other value of type
&lt;code&gt;(A) -&amp;gt; Nothing&lt;/code&gt; may be used where an &lt;code&gt;(A) -&amp;gt; R&lt;/code&gt; is expected, and so may a &lt;code&gt;() -&amp;gt; () -&amp;gt; Nothing&lt;/code&gt; where
a &lt;code&gt;() -&amp;gt; () -&amp;gt; R&lt;/code&gt; is. It converts where it is written, in a declared type, an argument (also one
whose parameter type the other arguments decide), a result, a field, and the branches of an &lt;code&gt;if&lt;/code&gt; or
&lt;code&gt;match&lt;/code&gt; or the elements of a collection literal, which agree on the other function type; the value
is evaluated once, there. Its parameters still vary as a function’s do: an &lt;code&gt;(Animal) -&amp;gt; Nothing&lt;/code&gt; is a
&lt;code&gt;(Dog) -&amp;gt; string&lt;/code&gt;, and a &lt;code&gt;(Dog) -&amp;gt; Nothing&lt;/code&gt; is no &lt;code&gt;(Animal) -&amp;gt; string&lt;/code&gt;. Inside another type it is
not converted, as a value of a value type is not: a &lt;code&gt;Vector[(int) -&amp;gt; Nothing]&lt;/code&gt; is no
&lt;code&gt;Vector[(int) -&amp;gt; int]&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;refuse(x: int) -&amp;gt; Nothing = fail(s&amp;quot;refused $x&amp;quot;)

val f: (int) -&amp;gt; Option[int] = refuse
val g = if strict then refuse else (x: int) -&amp;gt; Some(x) // (int) -&amp;gt; Option[int]
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;union-types&quot;&gt;Union types&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;A | B&lt;/code&gt; is a value of &lt;code&gt;A&lt;/code&gt; or of &lt;code&gt;B&lt;/code&gt;, written in annotations and never inferred, made at a single
site as an &lt;code&gt;Any&lt;/code&gt; is, and taken apart by a &lt;code&gt;match&lt;/code&gt; that covers every member. &lt;code&gt;?&lt;/code&gt; uses it to pass on
errors of several types: a function yielding &lt;code&gt;Result[T, IoError | ParseError]&lt;/code&gt; may &lt;code&gt;?&lt;/code&gt; either kind.
&lt;code&gt;|&lt;/code&gt; binds more tightly than &lt;code&gt;-&amp;gt;&lt;/code&gt;, so &lt;code&gt;(A) -&amp;gt; B | C&lt;/code&gt; returns a union. The rules are in their own
chapter, &lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;describe(x: int | string) -&amp;gt; string = x match
  n: int -&amp;gt; s&amp;quot;number $n&amp;quot;
  s: string -&amp;gt; s&amp;quot;text $s&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;type-ascription&quot;&gt;Type ascription&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;(value: T)&lt;/code&gt; gives a value the type &lt;code&gt;T&lt;/code&gt; where it is written, with no conversion and no &lt;code&gt;val&lt;/code&gt; to
hold it. It is checked exactly as the value of &lt;code&gt;val x: T = value&lt;/code&gt; is, and the expression is of type
&lt;code&gt;T&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A literal takes &lt;code&gt;T&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;(3_000_000_000: long)&lt;/code&gt;, &lt;code&gt;(255: byte)&lt;/code&gt;, &lt;code&gt;(2.5: real)&lt;/code&gt;, &lt;code&gt;(1: real)&lt;/code&gt;, and
any integer literal of any size for a type that
&lt;a href=&quot;#integers-meet-a-type-that-takes-them&quot;&gt;takes integers&lt;/a&gt; (&lt;code&gt;(123456789012345678901234567890: BigInt)&lt;/code&gt;, &lt;code&gt;(7: Cents)&lt;/code&gt;) and any decimal literal for one that
&lt;a href=&quot;#decimals-meet-a-type-that-takes-them&quot;&gt;takes decimals&lt;/a&gt; (&lt;code&gt;(0.1: BigDecimal)&lt;/code&gt;). In an operation
the ascribed operand decides the other’s type: &lt;code&gt;(1: long) + 2147483647&lt;/code&gt; is a &lt;code&gt;long&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value whose type its context decides is decided by &lt;code&gt;T&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;(None: Option[string])&lt;/code&gt;,
&lt;code&gt;([]: List[int])&lt;/code&gt;, &lt;code&gt;({}: Map[string, int])&lt;/code&gt;, &lt;code&gt;(Ok(3): Result[int, string])&lt;/code&gt;, and a lambda,
&lt;code&gt;((x -&amp;gt; x * 2): int -&amp;gt; int)&lt;/code&gt;, whose parameters take &lt;code&gt;T&lt;/code&gt;‘s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value of a subtype stands as one of &lt;code&gt;T&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;(dog: Animal)&lt;/code&gt;, &lt;code&gt;(Square(3): Shape)&lt;/code&gt;,
&lt;code&gt;([1, 2]: Iterable[int])&lt;/code&gt;, &lt;code&gt;(Some(dog): Option[Animal])&lt;/code&gt;, and a member of a union as the union,
&lt;code&gt;(n: int | string)&lt;/code&gt; (&lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt;). &lt;code&gt;(x: Any)&lt;/code&gt; is the value as an &lt;code&gt;Any&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nothing else is accepted.&lt;/strong&gt; An ascription never narrows (&lt;code&gt;(animal: Dog)&lt;/code&gt;, &lt;code&gt;(u: int)&lt;/code&gt; of an
&lt;code&gt;int | string&lt;/code&gt;: test the value with &lt;code&gt;is&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt;) and never converts: &lt;code&gt;(n: long)&lt;/code&gt; of an &lt;code&gt;int&lt;/code&gt;
&lt;code&gt;n&lt;/code&gt; is an error that says to write &lt;code&gt;long(n)&lt;/code&gt;, &lt;code&gt;(k: BigInt)&lt;/code&gt; of an integer variable says
&lt;code&gt;BigInt(k)&lt;/code&gt;, a &lt;code&gt;real&lt;/code&gt; is no &lt;code&gt;BigDecimal&lt;/code&gt;, and a value of an unrelated type is refused. A literal
that does not fit is refused as it is in a declaration: &lt;code&gt;(300: byte)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is written as an item of a parenthesized list, so the &lt;code&gt;:&lt;/code&gt; never meets another meaning: a group,
&lt;code&gt;(n: long)&lt;/code&gt;; a tuple’s part, &lt;code&gt;(1: long, &amp;quot;a&amp;quot;)&lt;/code&gt;; a call’s argument, &lt;code&gt;f(None: Option[string], x)&lt;/code&gt;, the
value of a named one included, &lt;code&gt;f(k = 1: long)&lt;/code&gt;. The value before &lt;code&gt;:&lt;/code&gt; is a whole expression and the
type after it a whole type, a function type included: &lt;code&gt;(a + b: long)&lt;/code&gt;, &lt;code&gt;(f: int -&amp;gt; int)&lt;/code&gt;. A
parenthesized list followed by &lt;code&gt;-&amp;gt;&lt;/code&gt; is a lambda’s parameters, &lt;code&gt;(n: long) -&amp;gt; n&lt;/code&gt;. A name followed by
&lt;code&gt;: int -&amp;gt; body&lt;/code&gt; whose rest is no type is a lambda whose typed parameter lacks its parentheses, and
is reported so. At the start of a block’s line, &lt;code&gt;name(x: T)&lt;/code&gt; followed by &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;-&amp;gt;&lt;/code&gt;, an indented
block or a line of clauses declares a local function, as it always has; a call there with a name
ascribed is written with the ascription grouped, &lt;code&gt;retry((n: long))&lt;/code&gt;, and a call followed by nothing
is a call, so &lt;code&gt;show(n: long)&lt;/code&gt; on two lines calls &lt;code&gt;show&lt;/code&gt; twice.&lt;/p&gt;
&lt;p&gt;In a &lt;a href=&quot;#placeholder-lambdas&quot;&gt;placeholder lambda&lt;/a&gt;, &lt;code&gt;(_: T)&lt;/code&gt; is a parameter of type &lt;code&gt;T&lt;/code&gt;:
&lt;code&gt;twice((_: long) * 3, 1)&lt;/code&gt; passes &lt;code&gt;(x: long) -&amp;gt; x * 3&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val big = (123456789012345678901234567890: BigInt) * 2
val none = (None: Option[string])
println(total(([1, 2, 3]: Iterable[int])))
println(describe((7: int | string)))
val n = 3
val m = (n: long)        // error: an ascription converts nothing; write `long(n)`
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;reference-types-and-value-types&quot;&gt;Reference types and value types&lt;/h2&gt;
&lt;p&gt;Class instances, &lt;code&gt;object&lt;/code&gt;s, arrays, buffers, closures and boxes are &lt;strong&gt;reference types&lt;/strong&gt;: they live on
the garbage-collected heap and have identity. Built-in types, tuples and &lt;code&gt;data&lt;/code&gt; types are &lt;strong&gt;value
types&lt;/strong&gt;: they have no identity, and the compiler chooses their representation. See
&lt;a href=&quot;/spec/equality-and-memory/&quot;&gt;equality, identity and memory&lt;/a&gt;.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Dates and times</title>
    <link href="https://avinlang.dev/spec/time/"/>
    <id>https://avinlang.dev/spec/time/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>`avin.time`: eight types that keep the timeline, the calendar and the zone apart — `Instant`, `Duration`, `Date`, `Time`, `DateTime`, `Zone`, `Zoned` and `Period` — the two clocks, arithmetic across month ends and daylight saving, ISO 8601 text and patterns.</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;avin.time&lt;/code&gt; is the standard library’s module for clocks, lengths of time, the calendar and time
zones. It is written in Avin; the clocks, the host’s zone database and the local zone are reached
through &lt;a href=&quot;/spec/sysl-bindings/&quot;&gt;Sysl bindings&lt;/a&gt;, and the calendar arithmetic is Sysl’s &lt;code&gt;sysl.time&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.time.{now, monotonic, date, dateTime, zone, hours, months}

main()
  val start = monotonic()
  val toronto = zone(&amp;quot;America/Toronto&amp;quot;)?
  val meeting = dateTime(2026, 3, 7, 9, 0).atZone(toronto)?
  println(meeting.plusDays(1)) // 2026-03-08T09:00:00-04:00[America/Toronto]
  println(meeting + hours(24)) // 2026-03-08T10:00:00-04:00[America/Toronto]
  println(date(2026, 1, 31) + months(1)) // 2026-02-28
  println(s&amp;quot;stamped ${now()}, took ${monotonic() - start}&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;eight-types&quot;&gt;Eight types&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Each type answers one kind of question, so a question a value cannot answer does not compile.&lt;/strong&gt;
An instant has no year until a zone is named; a date has no hour; a time of day has no date.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;What it is&lt;/th&gt;&lt;th&gt;Representation&lt;/th&gt;&lt;th&gt;Made by&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a point on the timeline, with no calendar&lt;/td&gt;&lt;td&gt;&lt;code&gt;data Instant(epochMicros: long)&lt;/code&gt;, microseconds since 1970-01-01T00:00:00Z&lt;/td&gt;&lt;td&gt;&lt;code&gt;now()&lt;/code&gt;, &lt;code&gt;epochSeconds(n)&lt;/code&gt;, &lt;code&gt;epochMillis(n)&lt;/code&gt;, &lt;code&gt;epochMicros(n)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;an exact length of timeline, negative, zero or positive&lt;/td&gt;&lt;td&gt;&lt;code&gt;data Duration(micros: long)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;micros(n)&lt;/code&gt; … &lt;code&gt;weeks(n)&lt;/code&gt;, &lt;code&gt;2.hours&lt;/code&gt;; &lt;code&gt;monotonic()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a calendar date, with no time of day and no zone&lt;/td&gt;&lt;td&gt;&lt;code&gt;data Date(epochDay: int)&lt;/code&gt;, days since 1970-01-01&lt;/td&gt;&lt;td&gt;&lt;code&gt;date(y, m, d)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a time of day, with no date and no zone&lt;/td&gt;&lt;td&gt;&lt;code&gt;data Time(microsOfDay: long)&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;86_399_999_999&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;time(h, m)&lt;/code&gt;, &lt;code&gt;time(h, m, s)&lt;/code&gt;, &lt;code&gt;time(h, m, s, us)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a wall reading, a date and a time of day, with no zone&lt;/td&gt;&lt;td&gt;&lt;code&gt;data DateTime(date: Date, time: Time)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;dateTime(…)&lt;/code&gt;, &lt;code&gt;d.atTime(t)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zone&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a zone: a name and the offset its clocks show at any instant&lt;/td&gt;&lt;td&gt;a name and its rules: one fixed offset, or the bytes of the host database’s file for it, which Sysl’s &lt;code&gt;sysl.time.tzif&lt;/code&gt; decodes&lt;/td&gt;&lt;td&gt;&lt;code&gt;zone(name)&lt;/code&gt;, &lt;code&gt;localZone()&lt;/code&gt;, &lt;code&gt;utc&lt;/code&gt;, &lt;code&gt;fixedZone(offset)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a wall reading in a zone; the only zoned type&lt;/td&gt;&lt;td&gt;&lt;code&gt;data Zoned(dateTime: DateTime, offset: Duration, zone: Zone)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;t.atZone(z)&lt;/code&gt;, &lt;code&gt;dt.atZone(z)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Period&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a length of calendar: months and days&lt;/td&gt;&lt;td&gt;&lt;code&gt;data Period(months: int, days: int)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;months(n)&lt;/code&gt;, &lt;code&gt;years(n)&lt;/code&gt;, &lt;code&gt;Period(months, days)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Beside them: &lt;code&gt;Weekday&lt;/code&gt;, a &lt;code&gt;data&lt;/code&gt; type of the seven days &lt;code&gt;Monday&lt;/code&gt; to &lt;code&gt;Sunday&lt;/code&gt; in that order;
&lt;code&gt;Resolution&lt;/code&gt;, what a zone makes of a wall reading; and the error types &lt;code&gt;ZoneError&lt;/code&gt;,
&lt;code&gt;ZoneTimeError&lt;/code&gt; and &lt;code&gt;TimeParseError&lt;/code&gt;. Every one is an immutable value, &lt;code&gt;Sendable&lt;/code&gt;, and usable as a
map key. The fields are the representation and may be read; &lt;strong&gt;the makers are the checked way to
make a value&lt;/strong&gt;, and a constructor takes its fields as given, as every &lt;code&gt;data&lt;/code&gt; type’s does.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The calendar is the proleptic Gregorian calendar&lt;/strong&gt; with astronomical year numbering: year &lt;code&gt;0&lt;/code&gt;
exists and is a leap year, and the year before it is &lt;code&gt;-1&lt;/code&gt;. A day is always 86,400 seconds of
&lt;code&gt;Instant&lt;/code&gt;: leap seconds are not counted, as the host’s clock does not count them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ranges.&lt;/strong&gt; A &lt;code&gt;Duration&lt;/code&gt; and an &lt;code&gt;Instant&lt;/code&gt; are any &lt;code&gt;long&lt;/code&gt; of microseconds, about ±292,000 years
(&lt;code&gt;Instant.Min&lt;/code&gt; is &lt;code&gt;-290308-12-21T19:59:05.224192Z&lt;/code&gt;, &lt;code&gt;Instant.Max&lt;/code&gt; &lt;code&gt;+294247-01-10T04:00:54.775807Z&lt;/code&gt;).
A &lt;code&gt;Date&lt;/code&gt; is any &lt;code&gt;int&lt;/code&gt; of days, about ±5,880,000 years (&lt;code&gt;Date.Min&lt;/code&gt;, &lt;code&gt;Date.Max&lt;/code&gt;), so every instant has
a date in every zone. A maker, a conversion or arithmetic whose answer would leave its type’s range
traps, as an integer overflow does: a &lt;code&gt;Date&lt;/code&gt; or &lt;code&gt;DateTime&lt;/code&gt; beyond the instants’ range has no
&lt;code&gt;Instant&lt;/code&gt; and converting it traps; so does a &lt;code&gt;Period&lt;/code&gt; whose months or days leave &lt;code&gt;int&lt;/code&gt;.
&lt;code&gt;Duration.Min&lt;/code&gt;, &lt;code&gt;Duration.Max&lt;/code&gt;, &lt;code&gt;DateTime.Min&lt;/code&gt; and &lt;code&gt;DateTime.Max&lt;/code&gt; are the other bounds.&lt;/p&gt;
&lt;h2 id=&quot;clocks&quot;&gt;Clocks&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;now() -&amp;gt; Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The wall clock: the current point on the timeline, to the microsecond the host gives. Anyone may set this clock, so two readings may differ by any amount, negative included. Stamp things with it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;monotonic() -&amp;gt; Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The monotonic clock: the time since an origin that means nothing, never decreasing within a run. Measure with it: &lt;code&gt;monotonic() - start&lt;/code&gt; is the time elapsed since &lt;code&gt;start = monotonic()&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;monotonic()&lt;/code&gt; answers a &lt;code&gt;Duration&lt;/code&gt;, not an &lt;code&gt;Instant&lt;/code&gt;&lt;/strong&gt;: a reading of it names no point in time, so
it has no calendar, no zone and no text as a date. There is no conversion between the two clocks.&lt;/p&gt;
&lt;h2 id=&quot;durations&quot;&gt;Durations&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;micros&lt;/code&gt;, &lt;code&gt;millis&lt;/code&gt;, &lt;code&gt;seconds&lt;/code&gt;, &lt;code&gt;minutes&lt;/code&gt;, &lt;code&gt;hours&lt;/code&gt;, &lt;code&gt;days&lt;/code&gt; and &lt;code&gt;weeks&lt;/code&gt; each take a &lt;code&gt;long&lt;/code&gt; count and
answer the exact duration; a day is 24 hours and a week 7 days of timeline, whatever the clocks of a
zone do. Each is also a method on &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;, so &lt;code&gt;2.hours == hours(2)&lt;/code&gt; and
&lt;code&gt;90.seconds == minutes(1) + seconds(30)&lt;/code&gt;. &lt;code&gt;Duration(micros)&lt;/code&gt; makes one from its count.
&lt;code&gt;Duration.Zero&lt;/code&gt;, &lt;code&gt;Duration.Min&lt;/code&gt; and &lt;code&gt;Duration.Max&lt;/code&gt; are the zero, least and greatest durations.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;micros&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the count of microseconds (the field)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toDays&lt;/code&gt;, &lt;code&gt;toHours&lt;/code&gt;, &lt;code&gt;toMinutes&lt;/code&gt;, &lt;code&gt;toSeconds&lt;/code&gt;, &lt;code&gt;toMillis&lt;/code&gt;&lt;/td&gt;&lt;td&gt;how many whole units it holds, a fraction dropped toward zero: &lt;code&gt;(hours(1) + minutes(30)).toMinutes&lt;/code&gt; is &lt;code&gt;90&lt;/code&gt;, &lt;code&gt;seconds(-90).toMinutes&lt;/code&gt; is &lt;code&gt;-1&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toHoursPart&lt;/code&gt;, &lt;code&gt;toMinutesPart&lt;/code&gt;, &lt;code&gt;toSecondsPart&lt;/code&gt;, &lt;code&gt;toMicrosPart&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the part left in that unit below the next larger: &lt;code&gt;(hours(50) + minutes(7)).toHoursPart&lt;/code&gt; is &lt;code&gt;2&lt;/code&gt;; negative for a negative duration&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toSecondsReal -&amp;gt; real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the seconds with their fraction&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isNegative&lt;/code&gt;, &lt;code&gt;isZero&lt;/code&gt;&lt;/td&gt;&lt;td&gt;its sign&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;abs&lt;/code&gt;&lt;/td&gt;&lt;td&gt;without its sign; &lt;code&gt;Duration.Min.abs&lt;/code&gt; traps&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Arithmetic.&lt;/strong&gt; Durations add, subtract and negate (&lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Sub&lt;/code&gt;, &lt;code&gt;Neg&lt;/code&gt;); &lt;code&gt;d * n&lt;/code&gt; and &lt;code&gt;d / n&lt;/code&gt;
scale by a &lt;code&gt;long&lt;/code&gt;, a remainder dropped toward zero, dividing by zero trapping; &lt;code&gt;d / e&lt;/code&gt; between two
durations answers how many whole &lt;code&gt;e&lt;/code&gt; fit in &lt;code&gt;d&lt;/code&gt; as a &lt;code&gt;long&lt;/code&gt;. A count on the left, &lt;code&gt;3 * d&lt;/code&gt;, does not
compile: the built-in types’ operators cannot gain methods, so the duration is written first.&lt;/p&gt;
&lt;h2 id=&quot;instants&quot;&gt;Instants&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;epochSeconds(n)&lt;/code&gt;, &lt;code&gt;epochMillis(n)&lt;/code&gt; and &lt;code&gt;epochMicros(n)&lt;/code&gt; make the instant &lt;code&gt;n&lt;/code&gt; units after
1970-01-01T00:00:00Z (before it where &lt;code&gt;n&lt;/code&gt; is negative), &lt;code&gt;epochSeconds&lt;/code&gt; and &lt;code&gt;epochMillis&lt;/code&gt; trapping
where the count is too large; &lt;code&gt;t.epochSeconds&lt;/code&gt; and &lt;code&gt;t.epochMillis&lt;/code&gt; count back, rounding toward
negative infinity, so &lt;code&gt;epochMillis(-1).epochSeconds&lt;/code&gt; is &lt;code&gt;-1&lt;/code&gt;, and the field &lt;code&gt;t.epochMicros&lt;/code&gt; is the
exact count. The unit is in every name because no default unit is safe. &lt;code&gt;Instant.Epoch&lt;/code&gt; is the instant
&lt;code&gt;epochMicros(0)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;t + d&lt;/code&gt; and &lt;code&gt;t - d&lt;/code&gt; move an instant along the timeline by a duration, and &lt;code&gt;later - earlier&lt;/code&gt; is the
&lt;code&gt;Duration&lt;/code&gt; between two instants. &lt;strong&gt;An instant has no calendar, so &lt;code&gt;t + months(1)&lt;/code&gt; does not compile&lt;/strong&gt;,
nor does any calendar field: &lt;code&gt;t.atZone(z)&lt;/code&gt; first.&lt;/p&gt;
&lt;h2 id=&quot;calendar-values&quot;&gt;Calendar values&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Makers.&lt;/strong&gt; &lt;code&gt;date(y, m, d)&lt;/code&gt;; &lt;code&gt;time(h, m)&lt;/code&gt;, &lt;code&gt;time(h, m, s)&lt;/code&gt; and &lt;code&gt;time(h, m, s, us)&lt;/code&gt;;
&lt;code&gt;dateTime(y, mo, d, h, mi)&lt;/code&gt;, &lt;code&gt;dateTime(y, mo, d, h, mi, s)&lt;/code&gt;, &lt;code&gt;dateTime(y, mo, d, h, mi, s, us)&lt;/code&gt; and
&lt;code&gt;dateTime(date, time)&lt;/code&gt;. &lt;strong&gt;Numbers the program wrote that name no date or time trap&lt;/strong&gt;, naming what
was wrong: &lt;code&gt;date(2026, 2, 30)&lt;/code&gt; traps with &lt;code&gt;there is no such date: 2026-02-30&lt;/code&gt;, and &lt;code&gt;time(24, 0)&lt;/code&gt;,
&lt;code&gt;time(9, 60)&lt;/code&gt;, &lt;code&gt;time(9, 0, 60)&lt;/code&gt; (there is no leap second) and a &lt;code&gt;us&lt;/code&gt; outside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;999_999&lt;/code&gt; trap
naming the field and its range. Text from outside the program is a &lt;code&gt;Result&lt;/code&gt; (&lt;a href=&quot;#parsing&quot;&gt;parsing&lt;/a&gt;).
&lt;code&gt;Time.Midnight&lt;/code&gt; is &lt;code&gt;time(0, 0)&lt;/code&gt; and &lt;code&gt;Time.Noon&lt;/code&gt; &lt;code&gt;time(12, 0)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fields.&lt;/strong&gt; One word per part; a value answers only the parts it has.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;On&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;year&lt;/code&gt;, &lt;code&gt;month&lt;/code&gt;, &lt;code&gt;day&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the year, the month &lt;code&gt;1&lt;/code&gt; to &lt;code&gt;12&lt;/code&gt;, the day of the month &lt;code&gt;1&lt;/code&gt; to &lt;code&gt;31&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;weekday -&amp;gt; Weekday&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;the day of the week&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;dayOfYear&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;&lt;code&gt;1&lt;/code&gt; to &lt;code&gt;366&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;daysInMonth&lt;/code&gt;, &lt;code&gt;daysInYear&lt;/code&gt;, &lt;code&gt;isLeapYear&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;of the date’s month and year&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;monthName&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;&lt;code&gt;January&lt;/code&gt; … &lt;code&gt;December&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isoWeek&lt;/code&gt;, &lt;code&gt;isoWeekYear&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;the ISO 8601 week (&lt;code&gt;1&lt;/code&gt; to &lt;code&gt;53&lt;/code&gt;, weeks starting on Monday, week 1 holding the year’s first Thursday) and the year it belongs to: 2027-01-01 is in week 53 of 2026&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hour&lt;/code&gt;, &lt;code&gt;minute&lt;/code&gt;, &lt;code&gt;second&lt;/code&gt;, &lt;code&gt;microsecond&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;0&lt;/code&gt;–&lt;code&gt;23&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;59&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;59&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;999_999&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;date&lt;/code&gt;, &lt;code&gt;time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the fields&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;date&lt;/code&gt;, &lt;code&gt;time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;its reading’s parts&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;epochDay&lt;/code&gt;, &lt;code&gt;microsOfDay&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the fields: days since 1970-01-01, microseconds since midnight&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;isLeapYear(year)&lt;/code&gt; and &lt;code&gt;daysInMonth(year, month)&lt;/code&gt; are module functions too; &lt;code&gt;daysInMonth&lt;/code&gt; traps on a
month outside &lt;code&gt;1&lt;/code&gt; to &lt;code&gt;12&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;Weekday&lt;/code&gt;&lt;/strong&gt; is &lt;code&gt;Monday&lt;/code&gt; … &lt;code&gt;Sunday&lt;/code&gt;, ordered in that order, ISO 8601’s. &lt;code&gt;w.isoNumber&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt;
(Monday) to &lt;code&gt;7&lt;/code&gt; (Sunday), &lt;code&gt;w.plus(n)&lt;/code&gt; the day &lt;code&gt;n&lt;/code&gt; days on (any &lt;code&gt;int&lt;/code&gt;, negative included), and it
displays as its name.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Replacing a field.&lt;/strong&gt; &lt;code&gt;withYear(y)&lt;/code&gt;, &lt;code&gt;withMonth(m)&lt;/code&gt; and &lt;code&gt;withDay(d)&lt;/code&gt; on &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt; and
&lt;code&gt;Zoned&lt;/code&gt;; &lt;code&gt;withHour&lt;/code&gt;, &lt;code&gt;withMinute&lt;/code&gt;, &lt;code&gt;withSecond&lt;/code&gt; and &lt;code&gt;withMicrosecond&lt;/code&gt; on &lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt; and
&lt;code&gt;Zoned&lt;/code&gt;. &lt;code&gt;withYear&lt;/code&gt; and &lt;code&gt;withMonth&lt;/code&gt; clamp the day to the new month’s length
(&lt;code&gt;date(2024, 2, 29).withYear(2025)&lt;/code&gt; is 2025-02-28); a value out of the field’s range, and a &lt;code&gt;withDay&lt;/code&gt;
past the month’s end, trap. On a &lt;code&gt;Zoned&lt;/code&gt; the wall reading changes and the zone resolves it as
&lt;a href=&quot;#zoned-arithmetic&quot;&gt;a period does&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Starting points.&lt;/strong&gt; &lt;code&gt;startOfYear&lt;/code&gt;, &lt;code&gt;startOfMonth&lt;/code&gt; and &lt;code&gt;startOfWeek&lt;/code&gt; (the Monday) on &lt;code&gt;Date&lt;/code&gt;,
&lt;code&gt;DateTime&lt;/code&gt; and &lt;code&gt;Zoned&lt;/code&gt;, at midnight; &lt;code&gt;endOfMonth&lt;/code&gt; on the same, the month’s last day at the same
time of day; &lt;code&gt;startOfDay&lt;/code&gt;, &lt;code&gt;startOfHour&lt;/code&gt;, &lt;code&gt;startOfMinute&lt;/code&gt; and &lt;code&gt;startOfSecond&lt;/code&gt; on &lt;code&gt;DateTime&lt;/code&gt;
and &lt;code&gt;Zoned&lt;/code&gt; truncate the time of day. On a &lt;code&gt;Date&lt;/code&gt; the date-only ones answer a &lt;code&gt;Date&lt;/code&gt;; a &lt;code&gt;Date&lt;/code&gt; has no
&lt;code&gt;startOfHour&lt;/code&gt;. A start or end that falls outside &lt;code&gt;Date.Min&lt;/code&gt; to &lt;code&gt;Date.Max&lt;/code&gt; traps naming the date
(&lt;code&gt;Date.Max&lt;/code&gt;, 11 July, has no &lt;code&gt;endOfMonth&lt;/code&gt;). &lt;code&gt;d.onOrAfter(w)&lt;/code&gt; is the first date on or after &lt;code&gt;d&lt;/code&gt; falling on weekday &lt;code&gt;w&lt;/code&gt;, and
&lt;code&gt;d.onOrBefore(w)&lt;/code&gt; the last on or before it: &lt;code&gt;date(2026, 8, 28).onOrAfter(Monday)&lt;/code&gt; is 2026-08-31, and
a Friday’s &lt;code&gt;onOrAfter(Friday)&lt;/code&gt; is itself.&lt;/p&gt;
&lt;h2 id=&quot;periods&quot;&gt;Periods&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;Period&lt;/code&gt; is a length of calendar: so many months and so many days. &lt;strong&gt;Months and days never
convert&lt;/strong&gt;: a month is 28 to 31 days and a day on a zone’s clock 23 to 25 hours, so neither is
some number of the other. &lt;code&gt;months(n)&lt;/code&gt; and &lt;code&gt;years(n)&lt;/code&gt; take an &lt;code&gt;int&lt;/code&gt;, and are methods on &lt;code&gt;int&lt;/code&gt; too
(&lt;code&gt;3.months&lt;/code&gt;). &lt;code&gt;years(n)&lt;/code&gt; is &lt;code&gt;12 * n&lt;/code&gt; months, which is exact, so &lt;code&gt;years(1) == months(12)&lt;/code&gt;; &lt;code&gt;months(1) != Period(0, 30)&lt;/code&gt;. &lt;code&gt;Period.Zero&lt;/code&gt; is the empty period.&lt;/p&gt;
&lt;p&gt;Periods add, subtract and negate part by part, never carrying days into months, and &lt;code&gt;p * n&lt;/code&gt; scales
both parts by an &lt;code&gt;int&lt;/code&gt;; a part leaving &lt;code&gt;int&lt;/code&gt; traps as an integer overflow does. &lt;code&gt;p.months&lt;/code&gt; and
&lt;code&gt;p.days&lt;/code&gt; are the fields; &lt;code&gt;p.toYearsPart&lt;/code&gt; and &lt;code&gt;p.toMonthsPart&lt;/code&gt; split the months, each part
carrying the months’ sign (&lt;code&gt;months(14)&lt;/code&gt; is 1 year and 2 months, &lt;code&gt;months(-14)&lt;/code&gt; -1 and -2), and
&lt;code&gt;p.isZero&lt;/code&gt; asks for the empty period. A period has no order: whether a month is longer than 30 days
depends on the month. &lt;code&gt;p.toIsoString&lt;/code&gt; writes ISO 8601’s form, &lt;code&gt;P1Y2M3D&lt;/code&gt;: the years, the months
left over and the days, each where it is not zero, &lt;code&gt;P0D&lt;/code&gt; for the empty period, and a negative part
with its own sign (&lt;code&gt;P-1Y-2M&lt;/code&gt;, &lt;code&gt;P1M-3D&lt;/code&gt;), since the parts may differ in sign; &lt;code&gt;parsePeriod&lt;/code&gt; reads it
back (&lt;a href=&quot;#parsing&quot;&gt;Parsing&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A duration is exact timeline and may be added to an &lt;code&gt;Instant&lt;/code&gt;, a &lt;code&gt;DateTime&lt;/code&gt; or a &lt;code&gt;Zoned&lt;/code&gt;; a
period is a calendar step and may be added only to a &lt;code&gt;Date&lt;/code&gt;, a &lt;code&gt;DateTime&lt;/code&gt; or a &lt;code&gt;Zoned&lt;/code&gt;.&lt;/strong&gt; A &lt;code&gt;Date&lt;/code&gt;
takes no duration — &lt;code&gt;date + days(1)&lt;/code&gt; does not compile; &lt;code&gt;date.plusDays(1)&lt;/code&gt; or &lt;code&gt;date + Period(0, 1)&lt;/code&gt;
is the day after — and an &lt;code&gt;Instant&lt;/code&gt; takes no period.&lt;/p&gt;
&lt;h2 id=&quot;arithmetic&quot;&gt;Arithmetic&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Expression&lt;/th&gt;&lt;th&gt;Answer&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Instant ± Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt;, moved along the timeline&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Instant - Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date ± Period&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;: the months first, the day clamped to the month it lands in, then the days&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date - Date&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Period&lt;/code&gt; of days only: &lt;code&gt;date(2026, 3, 1) - date(2026, 1, 31)&lt;/code&gt; is &lt;code&gt;Period(0, 29)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime ± Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;, moved along its own wall clock&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime ± Period&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;, the date moved as a &lt;code&gt;Date&lt;/code&gt; is, the time of day kept&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime - DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Duration&lt;/code&gt; along the wall clock&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zoned ± Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;, moved along the timeline and read in the same zone&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zoned ± Period&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;, moved along the calendar (&lt;a href=&quot;#zoned-arithmetic&quot;&gt;below&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zoned - Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Duration&lt;/code&gt; between their instants&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;no arithmetic: 23:30 plus an hour is tomorrow or a fault, and a time of day does not say which; &lt;code&gt;d.atTime(t)&lt;/code&gt; first&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Month ends.&lt;/strong&gt; Adding months clamps the day to the length of the month it lands in, which keeps “the
last day of the month” on a last day: &lt;code&gt;date(2026, 1, 31) + months(1)&lt;/code&gt; is 2026-02-28 and
&lt;code&gt;date(2024, 1, 31) + months(1)&lt;/code&gt; 2024-02-29; &lt;code&gt;date(2024, 2, 29) + years(1)&lt;/code&gt; is 2025-02-28 and
&lt;code&gt;+ years(4)&lt;/code&gt; 2028-02-29. &lt;strong&gt;Months first, then days&lt;/strong&gt;: &lt;code&gt;date(2026, 1, 31) + Period(1, 1)&lt;/code&gt; is
2026-03-01, by way of 2026-02-28. Clamping makes month steps lossy, so
&lt;code&gt;date(2026, 1, 31) + months(1) - months(1)&lt;/code&gt; is 2026-01-28.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;plusYears(n)&lt;/code&gt;, &lt;code&gt;plusMonths(n)&lt;/code&gt;, &lt;code&gt;plusWeeks(n)&lt;/code&gt; and &lt;code&gt;plusDays(n)&lt;/code&gt; on &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt; and
&lt;code&gt;Zoned&lt;/code&gt; are the calendar steps by name, &lt;code&gt;+ years(n)&lt;/code&gt;, &lt;code&gt;+ months(n)&lt;/code&gt;, &lt;code&gt;+ Period(0, 7 * n)&lt;/code&gt; and
&lt;code&gt;+ Period(0, n)&lt;/code&gt;; a negative &lt;code&gt;n&lt;/code&gt; steps back.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Between dates.&lt;/strong&gt; &lt;code&gt;a.daysUntil(b)&lt;/code&gt; is the whole days from &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;b&lt;/code&gt; as an &lt;code&gt;int&lt;/code&gt;, negative where &lt;code&gt;b&lt;/code&gt;
is earlier, trapping as an integer overflow does where the count leaves &lt;code&gt;int&lt;/code&gt; (only between dates
more than about 5,880,000 years apart); &lt;code&gt;a.monthsUntil(b)&lt;/code&gt; the whole months, counted as a person counts them (2026-01-31 to
2026-02-28 is &lt;code&gt;0&lt;/code&gt; months, to 2026-03-01 is &lt;code&gt;1&lt;/code&gt;); &lt;code&gt;a.until(b)&lt;/code&gt; the &lt;code&gt;Period&lt;/code&gt; of those whole months and
the days left over, so &lt;code&gt;a + a.until(b) == b&lt;/code&gt; for &lt;code&gt;a &amp;lt;= b&lt;/code&gt;. Where &lt;code&gt;b&lt;/code&gt; is earlier both parts are
negative or zero and the same holds: &lt;code&gt;date(2026, 3, 1).until(date(2026, 1, 31))&lt;/code&gt; is &lt;code&gt;-1mo -1d&lt;/code&gt;.
&lt;code&gt;b.monthsUntil(a)&lt;/code&gt; is always &lt;code&gt;-a.monthsUntil(b)&lt;/code&gt;, but clamping makes two other round trips fail for
some pairs: &lt;code&gt;date(2026, 1, 30).until(date(2026, 3, 1))&lt;/code&gt; is &lt;code&gt;1mo 1d&lt;/code&gt; (by way of 2026-02-28), so
&lt;code&gt;b - a.until(b)&lt;/code&gt; is 2026-01-31, not &lt;code&gt;a&lt;/code&gt;, and &lt;code&gt;b.until(a)&lt;/code&gt; is &lt;code&gt;-1mo -2d&lt;/code&gt;, not &lt;code&gt;-1mo -1d&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;zoned-arithmetic&quot;&gt;Zoned arithmetic&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A duration moves a zoned reading along the timeline and a period moves its calendar&lt;/strong&gt;, and across
a change of the zone’s clocks the two differ. In Toronto the clocks went forward at 02:00 on
2026-03-08:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val t = dateTime(2026, 3, 7, 9, 0).atZone(toronto)?
t.plusDays(1)              // 2026-03-08T09:00:00-04:00[America/Toronto]: the same wall clock, 23 hours on
t + days(1)                // 2026-03-08T10:00:00-04:00[America/Toronto]: 24 hours on
(t + days(1)) - t.plusDays(1)   // 1h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A period’s answer is the wall reading moved by the calendar and resolved in the zone again. A reading
landing in the hour the clocks &lt;strong&gt;skip&lt;/strong&gt; is pushed forward past the gap by the gap’s length (02:30 on
2026-03-08 becomes 03:30). One landing in the hour the clocks &lt;strong&gt;repeat&lt;/strong&gt; keeps the offset it had
where that is one of the two, and otherwise takes the earlier.&lt;/p&gt;
&lt;h2 id=&quot;zones&quot;&gt;Zones&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zone(name: string) -&amp;gt; Result[Zone, ZoneError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A zone by its name in the tz database (&lt;code&gt;&amp;quot;America/Toronto&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;Asia/Kolkata&amp;quot;&lt;/code&gt;), &lt;code&gt;&amp;quot;UTC&amp;quot;&lt;/code&gt;, or a fixed offset &lt;code&gt;&amp;quot;+05:30&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;-08:00&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;+0530&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;Z&amp;quot;&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;utc: Zone&lt;/code&gt;&lt;/td&gt;&lt;td&gt;UTC, a value rather than a call: the one zone that cannot fail to be found. &lt;code&gt;zone(&amp;quot;UTC&amp;quot;)? == utc&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;localZone() -&amp;gt; Zone&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The host’s own zone: the one the &lt;code&gt;TZ&lt;/code&gt; environment variable names (a leading &lt;code&gt;:&lt;/code&gt; dropped; a path is read as the zone’s file and named for what follows its &lt;code&gt;zoneinfo/&lt;/code&gt;), and where &lt;code&gt;TZ&lt;/code&gt; is unset, the one &lt;code&gt;/etc/localtime&lt;/code&gt; is, named for what follows the &lt;code&gt;zoneinfo/&lt;/code&gt; of the link’s target (&lt;code&gt;localtime&lt;/code&gt; where it is a copy rather than a link). It always answers: where the host names no zone it can read — &lt;code&gt;TZ&lt;/code&gt; empty, naming no zone in the database, not a zone’s name, or a file that does not decode — &lt;code&gt;utc&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fixedZone(offset: Duration) -&amp;gt; Zone&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A zone whose clocks are always &lt;code&gt;offset&lt;/code&gt; from UTC; the offset must be whole minutes within ±23:59, and anything else traps. &lt;code&gt;fixedZone(Duration.Zero) == utc&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A zone’s name usually comes from outside the program&lt;/strong&gt;, so &lt;code&gt;zone&lt;/code&gt; answers a &lt;code&gt;Result&lt;/code&gt;. Its
&lt;code&gt;ZoneError&lt;/code&gt; is &lt;code&gt;UnknownZone(name)&lt;/code&gt; where the database has no such zone, &lt;code&gt;NotAZoneName(name)&lt;/code&gt; where
the text cannot be one — it is empty, starts with &lt;code&gt;/&lt;/code&gt;, holds a &lt;code&gt;..&lt;/code&gt; segment, or a character outside
ASCII letters, digits and &lt;code&gt;/ _ + -&lt;/code&gt; — which is decided before anything is read, and
&lt;code&gt;Malformed(name)&lt;/code&gt; where the database’s file for it cannot be decoded. It is an &lt;a href=&quot;/spec/errors/#the-error-trait&quot;&gt;&lt;code&gt;Error&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;e.message&lt;/code&gt; and its display
name the zone: &lt;code&gt;no zone is named &apos;Mars/Olympus_Mons&apos;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The database is the host’s (the directory &lt;code&gt;TZDIR&lt;/code&gt; names, otherwise &lt;code&gt;/usr/share/zoneinfo&lt;/code&gt;), kept
current by the operating system; Avin ships none. Offsets are whole minutes. A reading past the last
transition the host’s table lists takes the table’s last offset.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method of &lt;code&gt;Zone&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;quot;America/Toronto&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;UTC&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;+05:30&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;offsetAt(t: Instant) -&amp;gt; Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;how far its clocks are from UTC at &lt;code&gt;t&lt;/code&gt;: &lt;code&gt;-4&lt;/code&gt; hours in Toronto in July&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isDaylightSavingAt(t)&lt;/code&gt;, &lt;code&gt;abbreviationAt(t)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;whether &lt;code&gt;t&lt;/code&gt; falls in daylight saving there, and the clocks’ abbreviation then (&lt;code&gt;&amp;quot;EDT&amp;quot;&lt;/code&gt;); a fixed zone is never in daylight saving and its abbreviation is its name&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;resolve(dt: DateTime) -&amp;gt; Resolution&lt;/code&gt;&lt;/td&gt;&lt;td&gt;which of the three cases the wall reading is in this zone&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isFixed&lt;/code&gt;&lt;/td&gt;&lt;td&gt;whether its offset never changes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;Resolution&lt;/code&gt; is &lt;code&gt;Unique(at: Zoned)&lt;/code&gt;, &lt;code&gt;Repeated(earlier: Zoned, later: Zoned)&lt;/code&gt; where the clocks show
the reading twice, and &lt;code&gt;Skipped(before: Duration, after: Duration)&lt;/code&gt; where they never show it, with
the offsets either side of the change. Two zones are equal when their names are; a zone displays as
its name.&lt;/p&gt;
&lt;h3 id=&quot;reading-in-a-zone&quot;&gt;Reading in a zone&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Conversion&lt;/th&gt;&lt;th&gt;Answer&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;t.atZone(z)&lt;/code&gt; on an &lt;code&gt;Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the &lt;code&gt;Zoned&lt;/code&gt; reading of &lt;code&gt;t&lt;/code&gt; in &lt;code&gt;z&lt;/code&gt;; always one&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zt.atZone(z)&lt;/code&gt; on a &lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same instant read in &lt;code&gt;z&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;dt.atZone(z) -&amp;gt; Result[Zoned, ZoneTimeError]&lt;/code&gt; on a &lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the reading where &lt;code&gt;z&lt;/code&gt; shows it once; where it shows it twice or never, &lt;code&gt;Err&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;dt.atZoneEarlier(z)&lt;/code&gt;, &lt;code&gt;dt.atZoneLater(z)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;always one: in a repeated hour the earlier or the later instant; in a skipped hour both push the reading forward past the gap by its length&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;d.atStartOfDay(z)&lt;/code&gt; on a &lt;code&gt;Date&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the first instant of the day in &lt;code&gt;z&lt;/code&gt;, a skipped midnight pushed past its gap&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A wall reading a zone skips or repeats is handed back, not guessed at.&lt;/strong&gt; &lt;code&gt;ZoneTimeError&lt;/code&gt; is
&lt;code&gt;Skipped(reading, zone, before, after)&lt;/code&gt; and &lt;code&gt;Repeated(reading, zone, earlier, later)&lt;/code&gt;, and its message
says what to write instead: &lt;code&gt;2026-03-08T02:30:00 never happens in America/Toronto: the clocks go from -05:00 to -04:00; atZoneLater or atZoneEarlier takes the reading past the gap&lt;/code&gt;, and &lt;code&gt;2026-11-01T01:30:00 happens twice in America/Toronto, when the clocks go back; atZoneEarlier or atZoneLater picks one&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Zoned&lt;/code&gt; holds its reading, the offset in force (a &lt;code&gt;Duration&lt;/code&gt;, the one thing that tells the two
readings of a repeated hour apart) and its zone, as the fields &lt;code&gt;dateTime&lt;/code&gt;, &lt;code&gt;offset&lt;/code&gt; and &lt;code&gt;zone&lt;/code&gt;. Its
other methods: &lt;code&gt;toInstant&lt;/code&gt;, &lt;code&gt;isDaylightSaving&lt;/code&gt; and &lt;code&gt;abbreviation&lt;/code&gt;, and every field and step
above; &lt;code&gt;epochSeconds&lt;/code&gt;, &lt;code&gt;epochMillis&lt;/code&gt; and &lt;code&gt;epochMicros&lt;/code&gt; are its instant’s counts.&lt;/p&gt;
&lt;h2 id=&quot;conversions&quot;&gt;Conversions&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;From&lt;/th&gt;&lt;th&gt;To&lt;/th&gt;&lt;th&gt;Spelling&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;long&lt;/code&gt; count&lt;/td&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt; / &lt;code&gt;Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;epochSeconds(n)&lt;/code&gt;, &lt;code&gt;epochMillis(n)&lt;/code&gt;, &lt;code&gt;epochMicros(n)&lt;/code&gt; / &lt;code&gt;micros(n)&lt;/code&gt; … &lt;code&gt;weeks(n)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;count&lt;/td&gt;&lt;td&gt;&lt;code&gt;t.epochSeconds&lt;/code&gt;, &lt;code&gt;t.epochMillis&lt;/code&gt;, &lt;code&gt;t.epochMicros&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;, then any calendar value&lt;/td&gt;&lt;td&gt;&lt;code&gt;t.atZone(z)&lt;/code&gt;, then &lt;code&gt;.dateTime&lt;/code&gt;, &lt;code&gt;.date&lt;/code&gt;, &lt;code&gt;.time&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;toInstant&lt;/code&gt;, &lt;code&gt;dateTime&lt;/code&gt;, &lt;code&gt;date&lt;/code&gt;, &lt;code&gt;time&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;atZone(z)&lt;/code&gt; (a &lt;code&gt;Result&lt;/code&gt;), &lt;code&gt;atZoneEarlier(z)&lt;/code&gt;, &lt;code&gt;atZoneLater(z)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;date&lt;/code&gt;, &lt;code&gt;time&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt; + &lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;d.atTime(t)&lt;/code&gt;, &lt;code&gt;t.atDate(d)&lt;/code&gt;, &lt;code&gt;dateTime(d, t)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;d.atStartOfDay()&lt;/code&gt;, &lt;code&gt;d.atStartOfDay(z)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/td&gt;&lt;td&gt;count&lt;/td&gt;&lt;td&gt;&lt;code&gt;d.epochDay&lt;/code&gt;; &lt;code&gt;Date(n)&lt;/code&gt; back&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;count&lt;/td&gt;&lt;td&gt;&lt;code&gt;t.microsOfDay&lt;/code&gt;; &lt;code&gt;timeOfMicros(us)&lt;/code&gt; back, trapping outside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;86_399_999_999&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;order-equality-and-hashing&quot;&gt;Order, equality and hashing&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Instant&lt;/code&gt;, &lt;code&gt;Duration&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt; and &lt;code&gt;Weekday&lt;/code&gt; are &lt;code&gt;Ord&lt;/code&gt; by value, so &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;,
sorting and &lt;code&gt;TreeMap&lt;/code&gt; keys work, and &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; agree. A &lt;code&gt;Period&lt;/code&gt; and a &lt;code&gt;Zone&lt;/code&gt; are &lt;code&gt;Eq&lt;/code&gt; and
&lt;code&gt;Hash&lt;/code&gt; but not &lt;code&gt;Ord&lt;/code&gt;. Values of different types never compare: &lt;code&gt;date(2026, 8, 28) == dateTime(2026, 8, 28, 0, 0)&lt;/code&gt; does not compile.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;Zoned&lt;/code&gt; is equal to another only with the same instant in the same zone&lt;/strong&gt;: 09:00 in Toronto and
22:00 in Tokyo on the same day are one instant and two readings, so they are not &lt;code&gt;==&lt;/code&gt;.
&lt;code&gt;a.isBefore(b)&lt;/code&gt;, &lt;code&gt;a.isAfter(b)&lt;/code&gt; and &lt;code&gt;a.isSameInstant(b)&lt;/code&gt; compare instants alone. Its &lt;code&gt;Ord&lt;/code&gt; orders by
instant, then by wall reading, then by the zone’s name, so it agrees with &lt;code&gt;==&lt;/code&gt; and two readings of one
instant are both kept as &lt;code&gt;TreeMap&lt;/code&gt; keys.&lt;/p&gt;
&lt;h2 id=&quot;text&quot;&gt;Text&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Every type implements &lt;code&gt;Display&lt;/code&gt;&lt;/strong&gt;, so a value goes straight into &lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt; and &lt;code&gt;println&lt;/code&gt;, and honours
a format specifier’s width and alignment. The calendar types write ISO 8601, which sorts as text in
the order it sorts as time:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Display&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;2026-03-03T14:30:00Z&lt;/code&gt;, &lt;code&gt;2026-03-03T14:30:00.5Z&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;2026-03-08&lt;/code&gt;; &lt;code&gt;+10000-01-01&lt;/code&gt;, &lt;code&gt;0000-01-01&lt;/code&gt;, &lt;code&gt;-0001-12-31&lt;/code&gt; outside years &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9999&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Time&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;09:30:00&lt;/code&gt;, &lt;code&gt;09:30:07.25&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DateTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;2026-03-08T09:30:00&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zoned&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;2026-03-08T09:00:00-04:00[America/Toronto]&lt;/code&gt;; a fixed zone does not name itself again: &lt;code&gt;…T14:30:00Z&lt;/code&gt;, &lt;code&gt;…T20:00:00+05:30&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;5400s&lt;/code&gt;, &lt;code&gt;-45s&lt;/code&gt;, &lt;code&gt;0s&lt;/code&gt;, &lt;code&gt;90.5s&lt;/code&gt;, &lt;code&gt;250ms&lt;/code&gt;, &lt;code&gt;1.5ms&lt;/code&gt;, &lt;code&gt;7us&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Period&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;1y 2mo 3d&lt;/code&gt;, &lt;code&gt;14d&lt;/code&gt;, &lt;code&gt;0d&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Zone&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;America/Toronto&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Weekday&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Wednesday&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The seconds are always written and the fraction only when there is one, without trailing zeros, so
a column of readings has one shape until something below the second appears. A duration is written
in the largest of &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;ms&lt;/code&gt; and &lt;code&gt;us&lt;/code&gt; that gives it a whole part, with the rest as a decimal fraction
without trailing zeros, as it is today; a period keeps months and days apart. &lt;code&gt;Debug&lt;/code&gt; writes a
duration as &lt;code&gt;Duration(90.5s)&lt;/code&gt;, a period as &lt;code&gt;Period(1y 2mo)&lt;/code&gt; and a zone as &lt;code&gt;Zone(America/Toronto)&lt;/code&gt;, and every
other type as its display.&lt;/p&gt;
&lt;h3 id=&quot;parsing&quot;&gt;Parsing&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Reads&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseDate(text) -&amp;gt; Result[Date, TimeParseError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;YYYY-MM-DD&lt;/code&gt;, with a sign and more digits for a year outside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9999&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseTime(text) -&amp;gt; Result[Time, TimeParseError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;hh:mm&lt;/code&gt;, &lt;code&gt;hh:mm:ss&lt;/code&gt;, &lt;code&gt;hh:mm:ss.f&lt;/code&gt; with one to six digits of fraction&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseDateTime(text) -&amp;gt; Result[DateTime, TimeParseError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a date and a time joined by &lt;code&gt;T&lt;/code&gt; or one space&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseTimestamp(text) -&amp;gt; Result[Instant, TimeParseError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a date-time and an offset: &lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;±hh:mm&lt;/code&gt; or &lt;code&gt;±hhmm&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseZoned(text) -&amp;gt; Result[Zoned, TimeParseError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a timestamp and, optionally, a zone name in brackets&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseHttpDate(text) -&amp;gt; Result[Instant, TimeParseError]&lt;/code&gt;, &lt;code&gt;parseHttpDate(text, now)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;an HTTP-date in any of its three forms (below)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parsePeriod(text) -&amp;gt; Result[Period, TimeParseError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;P&lt;/code&gt;, then years &lt;code&gt;Y&lt;/code&gt;, months &lt;code&gt;M&lt;/code&gt; and days &lt;code&gt;D&lt;/code&gt; in that order, at least one, each with its own &lt;code&gt;-&lt;/code&gt; where negative: what &lt;code&gt;toIsoString&lt;/code&gt; writes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Every display of &lt;code&gt;Instant&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt; and &lt;code&gt;Zoned&lt;/code&gt; reads back&lt;/strong&gt; to an equal value,
and so does every period’s &lt;code&gt;toIsoString&lt;/code&gt;. A year of four digits has no sign; one written with a sign
has four digits or more (&lt;code&gt;+10000&lt;/code&gt;, &lt;code&gt;-0001&lt;/code&gt;, &lt;code&gt;+2026&lt;/code&gt;). A fraction means what it says: &lt;code&gt;.5&lt;/code&gt; is half a
second. &lt;strong&gt;A parse checks the calendar, not only the shape&lt;/strong&gt;: &lt;code&gt;2026-02-30&lt;/code&gt; has the right shape and is
refused, as are &lt;code&gt;24:00&lt;/code&gt;, a second of &lt;code&gt;60&lt;/code&gt;, a seventh digit of fraction (even a &lt;code&gt;0&lt;/code&gt;), an offset beyond
±23:59, and a timestamp with no offset (defaulting one would invent it). The whole text is read for
its shape first, and then its fields are checked in the order they are written, so
&lt;code&gt;2026-02-30T24:00&lt;/code&gt; is refused for its day. Without a zone name &lt;code&gt;parseZoned&lt;/code&gt;‘s zone is the offset’s
fixed zone (&lt;code&gt;utc&lt;/code&gt; for &lt;code&gt;Z&lt;/code&gt; or any zero offset); with one, the offset must be the one that zone’s clocks
show at that instant, so both readings of an autumn overlap are read and a reading in a spring gap is
refused for its offset. A period’s years are twelve months each, and &lt;code&gt;P12M&lt;/code&gt; reads as &lt;code&gt;P1Y&lt;/code&gt; does.
Digits are ASCII only; any other character, a digit of another script included, is a shape error.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;HTTP-dates&lt;/strong&gt; (RFC 9110 §5.6.7), the dates of &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Last-Modified&lt;/code&gt;, &lt;code&gt;Expires&lt;/code&gt; and
&lt;code&gt;If-Modified-Since&lt;/code&gt;. &lt;code&gt;instant.toHttpDate()&lt;/code&gt; writes the one form a sender may use, IMF-fixdate,
&lt;code&gt;Sun, 06 Nov 1994 08:49:37 GMT&lt;/code&gt;: always UTC, a fraction of a second dropped toward the earlier second,
and an instant outside the years 0000 to 9999 traps. &lt;code&gt;parseHttpDate&lt;/code&gt; reads that form and the two
obsolete ones: RFC 850, &lt;code&gt;Sunday, 06-Nov-94 08:49:37 GMT&lt;/code&gt;, and &lt;code&gt;asctime&lt;/code&gt;, &lt;code&gt;Sun Nov  6 08:49:37 1994&lt;/code&gt;
(a day under ten has a space, not a zero, before it). The match is exact: names in the capitals
shown (&lt;code&gt;sun&lt;/code&gt;, &lt;code&gt;NOV&lt;/code&gt; and &lt;code&gt;gmt&lt;/code&gt; are refused), the digit counts shown, single spaces, and no text
before or after, so a header value is trimmed first. The day name must be the one the date falls on
(&lt;code&gt;range:weekday&lt;/code&gt; is &lt;code&gt;OutOfRange(text, &amp;quot;weekday&amp;quot;)&lt;/code&gt;), a second of &lt;code&gt;60&lt;/code&gt; is refused as in every parse,
and a parse never traps. A year of two digits, RFC 850 only, is in the century of &lt;code&gt;now&lt;/code&gt;‘s year
unless that would be more than fifty years after &lt;code&gt;now&lt;/code&gt;, and then in the century before;
&lt;code&gt;parseHttpDate(text)&lt;/code&gt; takes &lt;code&gt;now&lt;/code&gt; from the clock and &lt;code&gt;parseHttpDate(text, now)&lt;/code&gt; from its argument.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TimeParseError&lt;/code&gt; is &lt;code&gt;BadShape(text, at, expected)&lt;/code&gt;, &lt;code&gt;OutOfRange(text, field)&lt;/code&gt;, &lt;code&gt;Trailing(text, at)&lt;/code&gt;
and &lt;code&gt;UnknownZone(text, name)&lt;/code&gt;, &lt;code&gt;at&lt;/code&gt; a byte offset into &lt;code&gt;text&lt;/code&gt;. &lt;code&gt;field&lt;/code&gt; is &lt;code&gt;year&lt;/code&gt;, &lt;code&gt;month&lt;/code&gt;, &lt;code&gt;day&lt;/code&gt;,
&lt;code&gt;date&lt;/code&gt; (a date past &lt;code&gt;Date.Min&lt;/code&gt; or &lt;code&gt;Date.Max&lt;/code&gt; in their own years), &lt;code&gt;hour&lt;/code&gt;, &lt;code&gt;minute&lt;/code&gt;, &lt;code&gt;second&lt;/code&gt;,
&lt;code&gt;fraction&lt;/code&gt;, &lt;code&gt;offset&lt;/code&gt;, &lt;code&gt;instant&lt;/code&gt; (a timestamp past &lt;code&gt;Instant.Min&lt;/code&gt; or &lt;code&gt;Instant.Max&lt;/code&gt;), &lt;code&gt;months&lt;/code&gt; or
&lt;code&gt;days&lt;/code&gt;. Its message quotes the text and says what was expected and where: &lt;code&gt;cannot read &amp;quot;2026-02-30&amp;quot;: day is out of range&lt;/code&gt;, &lt;code&gt;cannot read &amp;quot;2026/03/08&amp;quot;: expected &apos;-&apos; at byte 4&lt;/code&gt;, &lt;code&gt;cannot read &amp;quot;2026-03-08T&amp;quot;: expected the end at byte 10&lt;/code&gt;, &lt;code&gt;cannot read &amp;quot;…[Nowhere/Atall]&amp;quot;: no zone is named &apos;Nowhere/Atall&apos;&lt;/code&gt;. A parse never traps.&lt;/p&gt;
&lt;h3 id=&quot;patterns&quot;&gt;Patterns&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;format(pattern)&lt;/code&gt; on &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt; and &lt;code&gt;Zoned&lt;/code&gt; writes a reading the way a person wants
to read it. A run of one letter is an element, text between &lt;code&gt;|&lt;/code&gt; bars is written as it stands (&lt;code&gt;||&lt;/code&gt; is
a bar, between the bars too: &lt;code&gt;|a||b|&lt;/code&gt; writes &lt;code&gt;a|b&lt;/code&gt;), and every other character, letters that are no
element included, stands for itself. A run of &lt;code&gt;h&lt;/code&gt; followed by &lt;code&gt;12&lt;/code&gt; is one element, the hour on the
twelve-hour clock:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Element&lt;/th&gt;&lt;th&gt;Writes&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Y&lt;/code&gt; &lt;code&gt;YY&lt;/code&gt; &lt;code&gt;YYYY&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the year as written (&lt;code&gt;-1&lt;/code&gt;, &lt;code&gt;12345&lt;/code&gt;), the last two digits of its magnitude (&lt;code&gt;26&lt;/code&gt;, &lt;code&gt;01&lt;/code&gt; for &lt;code&gt;-1&lt;/code&gt;), four digits padded and signed outside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9999&lt;/code&gt; as &lt;a href=&quot;#text&quot;&gt;the display&lt;/a&gt; writes it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;M&lt;/code&gt; &lt;code&gt;MM&lt;/code&gt; &lt;code&gt;MMM&lt;/code&gt; &lt;code&gt;MMMM&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the month: &lt;code&gt;8&lt;/code&gt;, &lt;code&gt;08&lt;/code&gt;, &lt;code&gt;Aug&lt;/code&gt;, &lt;code&gt;August&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;D&lt;/code&gt; &lt;code&gt;DD&lt;/code&gt; &lt;code&gt;DDD&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the day of the month, &lt;code&gt;5&lt;/code&gt; or &lt;code&gt;05&lt;/code&gt;; the day of the year, three digits padded (&lt;code&gt;005&lt;/code&gt;, &lt;code&gt;240&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;WWW&lt;/code&gt; &lt;code&gt;WWWW&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Fri&lt;/code&gt;, &lt;code&gt;Friday&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;h&lt;/code&gt; &lt;code&gt;hh&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the hour &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;23&lt;/code&gt;, &lt;code&gt;9&lt;/code&gt; or &lt;code&gt;09&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;h12&lt;/code&gt; &lt;code&gt;hh12&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the hour &lt;code&gt;1&lt;/code&gt; to &lt;code&gt;12&lt;/code&gt;: midnight and noon are &lt;code&gt;12&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;a&lt;/code&gt; &lt;code&gt;A&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;am&lt;/code&gt; or &lt;code&gt;pm&lt;/code&gt;, &lt;code&gt;AM&lt;/code&gt; or &lt;code&gt;PM&lt;/code&gt;: &lt;code&gt;am&lt;/code&gt; before noon&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;m&lt;/code&gt; &lt;code&gt;mm&lt;/code&gt; &lt;code&gt;s&lt;/code&gt; &lt;code&gt;ss&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the minute and the second&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;f&lt;/code&gt; … &lt;code&gt;ffffff&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the fraction of a second to that many digits, cut rather than rounded&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;z&lt;/code&gt; &lt;code&gt;zz&lt;/code&gt; &lt;code&gt;zzz&lt;/code&gt; &lt;code&gt;zzzz&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;-04:00&lt;/code&gt;, &lt;code&gt;-0400&lt;/code&gt;, &lt;code&gt;EDT&lt;/code&gt;, &lt;code&gt;America/Toronto&lt;/code&gt;; UTC’s are &lt;code&gt;+00:00&lt;/code&gt;, &lt;code&gt;+0000&lt;/code&gt;, &lt;code&gt;UTC&lt;/code&gt;, &lt;code&gt;UTC&lt;/code&gt;, and a fixed zone’s abbreviation and name are its offset&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val t = dateTime(2026, 8, 28, 17, 24, 15).atZone(toronto)?
t.format(&amp;quot;WWWW, MMMM D, Y |at| h12:mm a&amp;quot;)   // Friday, August 28, 2026 at 5:24 pm
t.format(&amp;quot;YYYY-MM-DDThh:mm:ss.fffZ&amp;quot;)       // 2026-08-28T17:24:15.000Z
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;An element the value does not have is refused, never zero-filled&lt;/strong&gt;: &lt;code&gt;date.format(&amp;quot;hh:mm&amp;quot;)&lt;/code&gt; traps
saying a date has no time of day, and &lt;code&gt;z&lt;/code&gt; on a &lt;code&gt;DateTime&lt;/code&gt; traps saying only a zoned reading knows its
zone. An instant has no &lt;code&gt;format&lt;/code&gt;; read it in a zone first. A pattern is the program’s own text, so a
malformed one traps naming the fault: a run of a letter no element has that length of (&lt;code&gt;YYY&lt;/code&gt;: &lt;code&gt;a year is Y, YY or YYYY&lt;/code&gt;), or a &lt;code&gt;|&lt;/code&gt; that never closes. The whole pattern is read before anything is
written, so a malformed pattern traps as malformed whatever value it is given, before an element the
value lacks: &lt;code&gt;date.format(&amp;quot;hh YYY&amp;quot;)&lt;/code&gt; traps naming &lt;code&gt;YYY&lt;/code&gt;. Names are English; there are no locales.&lt;/p&gt;
&lt;h2 id=&quot;sleeping-and-timers&quot;&gt;Sleeping and timers&lt;/h2&gt;
&lt;p&gt;A delay is a &lt;code&gt;Duration&lt;/code&gt; throughout the library: &lt;code&gt;threads.sleep(d)&lt;/code&gt;, an actor’s &lt;code&gt;after(delay, m)&lt;/code&gt; and
&lt;code&gt;every(interval, m)&lt;/code&gt;, &lt;code&gt;ask&lt;/code&gt;‘s timeout, a command’s &lt;code&gt;withTimeout(d)&lt;/code&gt;, a socket’s &lt;code&gt;setTimeout(d)&lt;/code&gt;.
&lt;code&gt;Future.await&lt;/code&gt; and &lt;code&gt;Condition.waitFor&lt;/code&gt; take a &lt;code&gt;Duration&lt;/code&gt; beside their count of milliseconds. Every
timer and deadline runs on the monotonic clock, so setting the wall clock moves none of them; a
deadline is &lt;code&gt;monotonic() + d&lt;/code&gt;.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Threads</title>
    <link href="https://avinlang.dev/spec/threads/"/>
    <id>https://avinlang.dev/spec/threads/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Starting and joining threads, what they share, how they synchronize, and what a racing read sees.</summary>
    <content type="html">&lt;p&gt;Avin programs run threads in parallel over one shared, collected heap.&lt;/p&gt;
&lt;h2 id=&quot;starting-and-joining&quot;&gt;Starting and joining&lt;/h2&gt;
&lt;p&gt;Threads are library code in &lt;code&gt;avin.threads&lt;/code&gt;, over runtime entries that start a thread with a context
of its own and wait for it to finish. A thread runs a closure and is joined for its result:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.spawn

main() -&amp;gt; int
  val worker = spawn(() -&amp;gt; sum(1 .. 1000000))
  val mine = sum(1000001 .. 2000000)
  worker.join() + mine
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;spawn[T: Sendable](@sendable body: () -&amp;gt; T, stack: long = 8388608) -&amp;gt; Thread[T]&lt;/code&gt; starts &lt;code&gt;body&lt;/code&gt;
on a new &lt;a href=&quot;#lightweight-threads&quot;&gt;lightweight thread&lt;/a&gt; with a stack of its own (8 MiB unless asked
otherwise, 64 KiB at the least). The body
captures only sendable values, and its result is sendable (&lt;a href=&quot;#what-is-shared&quot;&gt;what is shared&lt;/a&gt;).
&lt;code&gt;join() -&amp;gt; T&lt;/code&gt; waits for it
and gives back the result; joining a second time gives the same result again. Any thread may
join, several at once: one waits for the thread and the others wait for that one, and a &lt;code&gt;Thread&lt;/code&gt;
is itself sendable. A &lt;code&gt;Thread&lt;/code&gt; is
collected like any other object once nothing reaches it; a thread that is never joined still gives
its stack back when its body returns. Once &lt;code&gt;join&lt;/code&gt; answers, the ended thread keeps nothing alive: its
body and what the body captured are collected at the next collection unless something else still
reaches them. A thread that overflows its own stack traps with
&lt;code&gt;stack overflow&lt;/code&gt; like any other thread’s trap, whatever its stack’s size: one under the least a
thread is given, the default, and a stack kept from an ended thread that is larger than the new
one asked for, which overflows at its own end.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trap in any thread stops the program&lt;/strong&gt;, as it does in a program with one thread: traps report
bugs, and a bug in one thread leaves the state the others share in doubt. Only the first thread to
stop the program reports: what was written is flushed once and one reason is printed, and a
thread that traps after it, or calls &lt;code&gt;exit&lt;/code&gt;, waits for the end. The stopping thread runs the
program’s &lt;a href=&quot;/spec/system-library/#exit-hooks&quot;&gt;exit hooks&lt;/a&gt; after its report, the others still
running.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The program ends when &lt;code&gt;main&lt;/code&gt; returns&lt;/strong&gt;, whatever other threads are still running: standard
output is flushed, the main thread runs the exit hooks, and the process exits with &lt;code&gt;main&lt;/code&gt;‘s
status, taking the other threads with it. A &lt;code&gt;main&lt;/code&gt; answering &lt;code&gt;Err&lt;/code&gt; ends it the same way, its
error line written first and with status 1 (see &lt;a href=&quot;/spec/declarations/#main&quot;&gt;&lt;code&gt;main&lt;/code&gt;&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;A library scope makes the joins structural: &lt;code&gt;scope(s -&amp;gt; …)&lt;/code&gt; returns its body’s result only once
every thread started through &lt;code&gt;s.spawn&lt;/code&gt; has finished. &lt;code&gt;s.spawn&lt;/code&gt; takes the same arguments as
&lt;code&gt;spawn&lt;/code&gt; and is called by the thread that runs the scope’s body, while the scope is open; a call
from another thread, or after the scope has returned, traps. A &lt;code&gt;Scope&lt;/code&gt; is not sendable, so a
thread the scope started cannot reach it; one that starts more uses a scope of its own.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Atomic, scope}

main() -&amp;gt; int
  val parts = (0 ..&amp;lt; 4).map(_ -&amp;gt; Atomic(0)).toVector
  scope(s -&amp;gt;
    for i in 0 ..&amp;lt; 4
      s.spawn(() -&amp;gt; parts(i).store((i + 1) * 10)))
  parts.map(p -&amp;gt; p.load()).sum
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;cancellation&quot;&gt;Cancellation&lt;/h3&gt;
&lt;p&gt;A scope can end its threads early. &lt;code&gt;s.cancel()&lt;/code&gt; cancels every thread the scope has started, and every
one it starts from then on; the scope still returns only once all of them have ended, and its body
goes on running after the call. What a program can rely on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A cancelled thread stops at its next cancellation point&lt;/strong&gt; and ends with no result: nothing of its
body runs after that point but its &lt;a href=&quot;/spec/operators-and-control-flow/#defer&quot;&gt;deferred statements&lt;/a&gt;,
which run there, innermost first, as its frames are dropped. A deferred statement runs to its end
once begun: its own waits are not cancellation points while it runs, and a cancellation that comes
meanwhile stops the thread at its next cancellation point after. Its &lt;code&gt;result() -&amp;gt; Option[T]&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;, and its &lt;code&gt;join()&lt;/code&gt; traps,
since there is no value to give back; a thread that finished before its cancellation reached it
keeps its result, and &lt;code&gt;join&lt;/code&gt; answers it as before. A thread started in a cancelled scope runs
nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every wait is a cancellation point&lt;/strong&gt;: a &lt;code&gt;sleep&lt;/code&gt;, a join, a channel’s &lt;code&gt;receive&lt;/code&gt; or a full channel’s
&lt;code&gt;send&lt;/code&gt;, timed or not, a &lt;code&gt;select&lt;/code&gt;, a &lt;code&gt;withTimeout&lt;/code&gt;‘s wait for its body, a future’s &lt;code&gt;await&lt;/code&gt;, a
promise’s future, a condition’s &lt;code&gt;wait&lt;/code&gt; (plain or timed), a wait group’s &lt;code&gt;wait&lt;/code&gt; (plain or timed), a
semaphore’s &lt;code&gt;acquire&lt;/code&gt; (plain, timed or in &lt;code&gt;withPermit&lt;/code&gt;), a read-write lock’s &lt;code&gt;read&lt;/code&gt; and &lt;code&gt;write&lt;/code&gt;
waiting to go in, a barrier’s &lt;code&gt;wait&lt;/code&gt;, a &lt;a href=&quot;#pools&quot;&gt;pool&lt;/a&gt;‘s &lt;code&gt;use&lt;/code&gt; or &lt;code&gt;lease&lt;/code&gt; waiting for a resource, a socket’s
&lt;code&gt;accept&lt;/code&gt;, &lt;code&gt;connect&lt;/code&gt;, read or write that waits for its connection, and the lookup of a host’s name
that a &lt;code&gt;connect&lt;/code&gt; or a &lt;code&gt;bind&lt;/code&gt; makes, however long the resolver takes to answer. A thread
parked in one is woken at once, however long the wait. &lt;strong&gt;So is every safepoint poll&lt;/strong&gt;, which
compiled code makes on every back edge of a loop and before every call that may recur, so a thread
that computes without waiting stops too, within a loop’s turn.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A thread is never stopped where others may be waiting on what it is doing&lt;/strong&gt;: while it holds a
lock (inside a &lt;code&gt;Mutex&lt;/code&gt;‘s &lt;code&gt;with&lt;/code&gt;, for one), while it writes a &lt;code&gt;RwLock&lt;/code&gt;, while it runs a barrier’s
action, while it initializes a &lt;code&gt;lazy val&lt;/code&gt;, while it runs what
waits for a future it completed. It goes on to the end of that region and stops at its first
cancellation point after, so a cancelled thread never leaves a mutex held or a value half made. Waiting
for a lock is not a cancellation point; waiting on a condition is, and a thread stopped there takes
its mutex again, so the deferred statements of the &lt;code&gt;with&lt;/code&gt; body run under it, and &lt;code&gt;with&lt;/code&gt; lets it go
after them. A wait that left a mark on what it waits for takes it back as it stops:
a writer or a reader waiting for a &lt;code&gt;RwLock&lt;/code&gt; no longer holds back those behind it, and a party
waiting at a &lt;code&gt;Barrier&lt;/code&gt; withdraws its arrival. A thread stopped inside a &lt;code&gt;RwLock&lt;/code&gt;‘s read body or a
semaphore’s &lt;code&gt;withPermit&lt;/code&gt; body gives its share of the lock, or its permit, back as it stops, as one
inside a pool’s &lt;code&gt;use&lt;/code&gt; or &lt;code&gt;lease&lt;/code&gt; body gives its resource back; what
such a body was doing is its own, as any cancelled code’s is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cancellation reaches down through scopes.&lt;/strong&gt; A cancelled thread that is running a scope of its own,
in that scope’s body or waiting for its threads, stops first at that scope: the scope body’s
deferred statements run, the inner scope cancels its threads and waits for them to end, each
running its own, and only then does the thread go on stopping, running those of the functions
around the scope. So every
thread below a cancelled scope has ended once that scope returns. Cancelling an inner scope cancels
only its own threads. A scope opened while its thread holds a lock is not cancelled with that
thread, since nothing stops the thread there: its threads finish, and the thread stops once it has
let the lock go.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Actors are not a scope’s threads.&lt;/strong&gt; An actor started by a scope’s thread is a top-level actor,
and its turns are threads of their own, so cancelling the scope does not reach it: it runs on and
ends as any actor ends, having handled what the cancelled thread told it, in the order told. A
thread parked in an actor’s &lt;code&gt;ask&lt;/code&gt; is parked in a future’s &lt;code&gt;await&lt;/code&gt;, so it stops at once; the
question stays in the actor’s mailbox and is handled in its place, and its reply, going to an ask
nobody awaits, is dropped, the ask’s timer with it. An actor’s turn is never cancelled by a scope,
but the scopes a turn runs are cancelled as any thread’s are.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s.isCancelled()&lt;/code&gt; answers whether the scope has been cancelled, by &lt;code&gt;cancel&lt;/code&gt; or by a cancellation of
the thread running it. &lt;code&gt;cancel&lt;/code&gt;, like &lt;code&gt;spawn&lt;/code&gt;, is called by the thread that runs the scope’s body
while the scope is open, and traps otherwise; cancelling twice is cancelling once.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A failure is a value.&lt;/strong&gt; A trap still stops the whole program, so a scope’s threads report a
failure by returning or sending a &lt;code&gt;Result&lt;/code&gt;, and the body that sees it cancels the scope and returns
it. A cancelled thread runs no code of its own as it stops: what it must leave tidy is either under a
lock, which it finishes, or its own, which nothing else reaches. The Sysl handles its body reached,
a connection for one, are handed back once the scope has waited for it, as a body that returns
hands them back itself, so the code after the scope may use or close them.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Channel, scope}

fetchAll(urls: Vector[string]) -&amp;gt; Result[Vector[string], string]
  val pages = Channel[Result[string, string]](urls.length)
  scope(s -&amp;gt;
    for u in urls do s.spawn(() -&amp;gt; pages.send(fetch(u)))
    var got: Vector[string] = []
    var failure: Option[string] = None
    while got.length &amp;lt; urls.length &amp;amp;&amp;amp; failure.isEmpty
      pages.receive() match
        Some(Ok(page)) -&amp;gt; got = got :+ page
        Some(Err(e)) -&amp;gt;
          failure = Some(e)
          s.cancel()
        None -&amp;gt; ()
    failure match
      Some(e) -&amp;gt; Err(e)
      None -&amp;gt; Ok(got))
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;lightweight-threads&quot;&gt;Lightweight threads&lt;/h2&gt;
&lt;p&gt;Every thread a program starts is a lightweight thread: the runtime runs it on one of a few operating
system threads of its own, its &lt;strong&gt;workers&lt;/strong&gt;, about one for each processor, started as threads become
ready. What a program can rely on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Threads are cheap.&lt;/strong&gt; A thread’s stack is reserved at its full size and the system commits its
pages only as the thread first touches them, so a thread that has not recursed deeply costs a page
or so of memory and a small record. A program may start a hundred thousand threads and join them
all, and a deep recursion still fits in a thread as it does in &lt;code&gt;main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A parked thread holds only the stack it is using.&lt;/strong&gt; A page of a stack stays committed once
touched, so the runtime gives pages back: a thread that has stayed parked for about a millisecond
(a tick of the runtime’s monitor, with no run between) returns every page below where it parked
but the 16 KiB just under it, and the stack of an ended thread kept for the next returns all but
its top 16 KiB. A
thread that recursed a hundred thousand calls deep and then waits costs, while it waits, what a
shallow one does; woken, it recurses as deep again on pages committed afresh. A thread parked
only briefly, as one handing values back and forth parks, has run again before its tick and is
not trimmed, so a park costs nothing more.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A wait parks only its thread.&lt;/strong&gt; A thread that waits for a lock, a condition, a channel, a join, a
future or a promise is set aside, and its worker runs another ready thread meanwhile; the thread
that ends the wait makes it ready again. Ready threads run in the order they became ready, and a
thread may resume on a different worker from the one it waited on. A timed wait parks the same way
and is made ready when its time runs out, and so does a &lt;code&gt;sleep&lt;/code&gt;: ten thousand threads sleeping at
once hold no worker between them and all wake in about one sleep. Threads whose times run out
together are made ready soonest first, two due at the same moment in the order they began to wait.
A timed wait that its event ends first answers once, as woken, and its timer goes with it.
A thread waiting on a &lt;a href=&quot;/spec/system-library/#avin-net&quot;&gt;connection&lt;/a&gt;, to accept, connect, read or
write, parks the same way on the runtime’s poller, one kernel readiness set for the whole program,
and is made ready when the socket is; a connection’s timeout parks it on a timer as well, and
whichever comes first ends the wait. So
waiting code is written as plain straight-line code:
a server may hold one thread per connection, thousands of them waiting at once on a few workers,
and a chain of futures each awaiting the one before it resolves however long it is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Threads are time-sliced.&lt;/strong&gt; A thread that has run for 10 ms while another thread is ready yields
its worker at its next safepoint poll, which compiled code makes on every back edge of a loop and
before every call that may recur, and goes to the back of the ready queue. A thread that computes
without ever waiting therefore shares its processor rather than holding it, even in a tight loop
that calls nothing, and a thread that does not overrun its slice pays nothing for it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call that blocks its operating system thread does not starve the others.&lt;/strong&gt; A Sysl binding
&lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;declared &lt;code&gt;blocking&lt;/code&gt;&lt;/a&gt; or a wait for a &lt;code&gt;lazy val&lt;/code&gt; being
initialized elsewhere holds the worker it runs on, but once such a call has held its worker
for a millisecond or two while other threads are ready, the runtime runs another worker in its
place. A worker freed again rejoins the others, or rests until it is needed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The main thread is not a worker.&lt;/strong&gt; &lt;code&gt;main&lt;/code&gt; runs on the program’s first operating system thread,
and its own waits block that thread while the workers run the rest. It stays free for work that
has to run there, a window above all, which the &lt;code&gt;ui&lt;/code&gt; package runs on it while other threads
&lt;a href=&quot;/spec/ui/#threads&quot;&gt;hand it work&lt;/a&gt;. &lt;code&gt;isMainThread()&lt;/code&gt; answers whether the calling code runs on it:
&lt;code&gt;true&lt;/code&gt; in &lt;code&gt;main&lt;/code&gt; and what it calls, and on a thread &lt;a href=&quot;#pinned-to-the-main-thread&quot;&gt;pinned to it&lt;/a&gt;,
&lt;code&gt;false&lt;/code&gt; on every other lightweight thread, a pool’s workers among them.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;pinned-to-the-main-thread&quot;&gt;Pinned to the main thread&lt;/h3&gt;
&lt;p&gt;Code on the main thread that waits blocks it, and with it a window’s frames. A thread &lt;strong&gt;pinned to the
main thread&lt;/strong&gt; waits without blocking it: &lt;code&gt;spawnOnMain(body)&lt;/code&gt; starts &lt;code&gt;body&lt;/code&gt; on a lightweight thread
that runs on the main thread only, on a scheduler of the main thread’s own, and parks as any
lightweight thread does. So a handler that has to wait for something hands the waiting to one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.threads.{Future, spawnOnMain}
import ui.state

val shown = state(&amp;quot;loading&amp;quot;)
spawnOnMain(() -&amp;gt;
  val page = Future(fetch(url)).await()
  shown.set(page))
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;spawnOnMain(body, stack)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Starts &lt;code&gt;body&lt;/code&gt; pinned to the main thread, and answers its &lt;code&gt;Thread[T]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scope.spawnOnMain(body, stack)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same, as one of the scope’s threads, which it waits for and cancels&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;runMainThreads()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Runs each pinned thread ready now, until it waits or ends, and answers how many ran&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isPinnedToMain()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the calling code runs on a pinned thread&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It runs on the main thread only, and never beside the main thread’s own code.&lt;/strong&gt; Only the main
thread runs a pinned thread: when it calls &lt;code&gt;runMainThreads()&lt;/code&gt;, which the &lt;a href=&quot;/spec/ui/#threads&quot;&gt;frame
loop&lt;/a&gt; does once a frame, and while its own code waits, on a lock, a condition, a
join, a channel, a future, a select or a sleep, so the main thread joining a pinned thread runs it.
A pinned thread made ready while the main thread computes waits for it. A wait of the main thread
on a connection, or in a call that blocks it in the system, runs none.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It parks, and carries on on the main thread.&lt;/strong&gt; A pinned thread waiting on anything parks, the
main thread goes on with its frame or its own wait, and whatever ends the wait, another thread, a
timer or the main thread itself, makes it ready for the main thread again. Ready pinned threads run
in the order they became ready; &lt;code&gt;runMainThreads&lt;/code&gt; runs those ready when it is called, each once, so
one that a pinned thread makes ready runs at the next call. Nothing slices a pinned thread: it runs
until it waits or ends, as the main thread’s own code does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It reaches what the main thread reaches.&lt;/strong&gt; &lt;code&gt;body&lt;/code&gt; is not checked as sendable: a pinned thread may
capture a &lt;code&gt;State&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt; or any other value of the main thread’s, since nothing else runs it,
and it uses the Sysl handles the main thread owns as their owner. &lt;code&gt;isMainThread()&lt;/code&gt; answers &lt;code&gt;true&lt;/code&gt;
in it. &lt;code&gt;T&lt;/code&gt; need not be sendable; the thread is, where &lt;code&gt;T&lt;/code&gt; is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Only the main thread starts one&lt;/strong&gt;, its own code or a pinned thread; a thread on the workers that
calls &lt;code&gt;spawnOnMain&lt;/code&gt; stops the program:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: a thread pinned to the main thread is started on the main thread, and `spawnOnMain` was called on another
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;runMainThreads()&lt;/code&gt; called anywhere but the main thread’s own code, a pinned thread included, runs
nothing and answers 0.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It is cancelled, joined and ended as any thread is.&lt;/strong&gt; A scope’s &lt;code&gt;spawnOnMain&lt;/code&gt; is cancelled with
the scope, and a pinned thread parked in a cancellable wait stops there. When &lt;code&gt;main&lt;/code&gt; returns the
program ends, as it always does: a pinned thread still parked, or ready and not yet run, runs no
further. One still parked when a window’s &lt;code&gt;run&lt;/code&gt; returns stays parked and runs again whenever the
main thread next runs the main scheduler.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A deadlock names it.&lt;/strong&gt; The main thread waiting without a limit on what only a parked pinned
thread could give is a deadlock like any other, and the report says which threads are pinned:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: deadlock: all threads are waiting
  main: waiting for a thread to end
  thread 1, pinned to the main thread: waiting to receive from a channel
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-is-shared&quot;&gt;What is shared&lt;/h2&gt;
&lt;p&gt;The heap is shared: every object is reachable from every thread that is handed a reference to it.
Nothing is copied when a thread starts; the closure and what it captures are simply reachable from
the new thread too. &lt;strong&gt;So what a thread is given is checked&lt;/strong&gt;: a closure that runs on another thread
captures only &lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt; values and no &lt;code&gt;var&lt;/code&gt;, and the value it gives
back is sendable, and the code it runs reaches no module-level mutable state (below). The threads
then share nothing mutable but through the synchronized types, a &lt;code&gt;Mutex&lt;/code&gt;, an &lt;code&gt;Atomic&lt;/code&gt;, a
&lt;code&gt;Channel&lt;/code&gt;, a &lt;code&gt;Once&lt;/code&gt; and a &lt;code&gt;Condition&lt;/code&gt;. The error names what is captured and why it cannot be:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: what is passed for `body` of `spawn` may use only sendable values from around it, but it uses `parts`, an `Array[int]`, which is mutable; an immutable copy (`toVector`) is sendable
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A captured &lt;code&gt;var&lt;/code&gt; lives in a box on the heap that the closure would share with the code that made
it, so it is never captured for another thread, whatever its type: the closure copies it into a
&lt;code&gt;val&lt;/code&gt; first, or the two share an &lt;code&gt;Atomic&lt;/code&gt;. A closure is checked by what it captures, the closures
it makes and the local functions it calls included; a method value captures its object, so
&lt;code&gt;spawn(counter.tick)&lt;/code&gt; needs a sendable &lt;code&gt;counter&lt;/code&gt;; and a by-name body, as &lt;code&gt;Future(body)&lt;/code&gt; takes, is a
closure too. A function value held in a &lt;code&gt;val&lt;/code&gt; of a plain function type is not sendable, since its
type does not say what it captures: the closure is written where it is passed, or the &lt;code&gt;val&lt;/code&gt; is of a
&lt;code&gt;@sendable&lt;/code&gt; function type.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;@sendable&lt;/code&gt; function type says it.&lt;/strong&gt; &lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt; (&lt;a href=&quot;/spec/types/#function-types&quot;&gt;function
types&lt;/a&gt;) is the type of a function that may run on another thread, and
it is &lt;code&gt;Sendable&lt;/code&gt;. A lambda, a function reference or a method value written where one is expected is
checked where it is made exactly as what is passed for a &lt;code&gt;@sendable&lt;/code&gt; parameter is: what it captures,
and the module-level state it reaches (below); the error names the type. A value already of a
&lt;code&gt;@sendable&lt;/code&gt; type is passed, stored, captured and sent as it is, so a data type or a class whose
fields are &lt;code&gt;@sendable&lt;/code&gt; functions is sendable by its structure, and grammars, handlers and tasks held
in module-level values may be used by every thread:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.spawn

data Rule[T](run: @sendable (string) -&amp;gt; Option[T])

val digits: Rule[int] = Rule((s) -&amp;gt; s.toIntOption())

main() = println(spawn(() -&amp;gt; digits.run(&amp;quot;42&amp;quot;)).join())
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: a `@sendable (int) -&amp;gt; int` may use only sendable values from around it, but it uses `a`, an `Array[int]`, which is mutable; an immutable copy (`toVector`) is sendable
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The checks are three marks on a parameter, which any function may use.&lt;/strong&gt; What is passed for an
&lt;strong&gt;&lt;code&gt;@isolated&lt;/code&gt;&lt;/strong&gt; parameter may use only sendable values from around it: a closure captures only
sendable values (a &lt;code&gt;var&lt;/code&gt; among them, where its type is sendable), and any other expression reads
only sendable locals and parameters; what it makes itself is its own. Nothing outside therefore
reaches a mutable value it makes or is given. An &lt;strong&gt;&lt;code&gt;@isolating&lt;/code&gt;&lt;/strong&gt; parameter asks that, and that
nothing it runs, however indirectly, reaches module-level mutable state (below), so no mutable
object it makes or is given can be stored where code outside reaches it: it is the mark of
&lt;a href=&quot;/spec/actors/#handing-over-ownership&quot;&gt;&lt;code&gt;isolate&lt;/code&gt;‘s body and &lt;code&gt;with&lt;/code&gt;‘s function&lt;/a&gt;, and of a
&lt;a href=&quot;#synchronization&quot;&gt;mutex’s value and its body&lt;/a&gt;. A &lt;strong&gt;&lt;code&gt;@sendable&lt;/code&gt;&lt;/strong&gt;
parameter asks both, and that a closure captures no &lt;code&gt;var&lt;/code&gt;, since it may run on another thread while
the code that made it goes on.
Inside the function, a parameter so marked that holds a function may be passed on for a parameter
with the same mark or a weaker one; an unmarked one may not, and the error says to mark it. A
method that overrides or implements another marks no parameter more strongly than the method it
overrides does, since a call through that method would not check what is passed.
A function type carries no marks either, so a function, a constructor or a method whose parameter
is marked is a value only where the value’s type gives that parameter a sendable type, a &lt;code&gt;@sendable&lt;/code&gt;
function type for one that takes a function: &lt;code&gt;spawn&lt;/code&gt; is a &lt;code&gt;(@sendable () -&amp;gt; T, long) -&amp;gt; Thread[T]&lt;/code&gt;,
and as a &lt;code&gt;(() -&amp;gt; unit, long) -&amp;gt; Thread[unit]&lt;/code&gt; it is refused, as &lt;code&gt;Mutex&lt;/code&gt; as an &lt;code&gt;(Array[int]) -&amp;gt; Mutex[Array[int]]&lt;/code&gt; is. Where no function type is expected, the value takes the &lt;code&gt;@sendable&lt;/code&gt; form of
each marked parameter that takes a function, so &lt;code&gt;val sp = spawn[int]&lt;/code&gt; holds it and what is passed
through &lt;code&gt;sp&lt;/code&gt; is checked where it is written. A by-name parameter so marked has no such type, so
&lt;code&gt;isolate&lt;/code&gt; is not a value. A class or a data type that is a function has an &lt;code&gt;apply&lt;/code&gt; that marks a
parameter only where its function type makes that parameter sendable likewise.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A parameter marked &lt;code&gt;@sendable&lt;/code&gt; is sendable inside its function, whatever its type&lt;/strong&gt;, since what
is passed for it was checked where it was passed: a &lt;code&gt;@sendable&lt;/code&gt; lambda captures it, and it is passed
on for another &lt;code&gt;@sendable&lt;/code&gt; parameter as it is. So what is passed for one that does not take a
function is itself sendable: a &lt;a href=&quot;/spec/operators-and-control-flow/#match-functions&quot;&gt;&lt;code&gt;match&lt;/code&gt; function&lt;/a&gt;
written in place, whose arms are checked as a lambda’s body is, by what they capture and the
module-level state they reach; a value of a sendable type; a parameter so marked; or &lt;code&gt;f.orElse(g)&lt;/code&gt;
of two of these, chains of it included, which holds only the two. A class’s &lt;code&gt;val&lt;/code&gt; parameter so
marked is a field whose value is sendable, so it leaves the class sendable by its structure; a &lt;code&gt;var&lt;/code&gt;
one does not, since it may be assigned anything later. The mark belongs to the parameter, not to its
type: a marked value copied into a local, a combination held in one, or one stored in a data field
of the trait’s type is a value of that type again. &lt;code&gt;orElse&lt;/code&gt; is sendable of sendable parts by the
standard library’s promise, &lt;code&gt;@sendable_result&lt;/code&gt;, which says a function’s result holds nothing but its
receiver and its arguments; nothing checks the promise against the body, so only the standard
library makes it, and a function of the program’s own that passes its marked arguments back is not
taken as one.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;data Rule[T](run: @sendable (char) -&amp;gt; Option[T])

pick[U](@sendable f: PartialFunction[char, U]) -&amp;gt; Rule[U] = Rule(c -&amp;gt; if f.isDefinedAt(c) then Some(f(c)) else None)

pickAgain[U](@sendable f: PartialFunction[char, U]) -&amp;gt; Rule[U] = pick(f)

val digit: Rule[int] = pickAgain(match c if &apos;0&apos; &amp;lt;= c &amp;lt;= &apos;9&apos; -&amp;gt; int(c) - int(&apos;0&apos;))

either[U](@sendable f: PartialFunction[char, U], @sendable g: PartialFunction[char, U]) -&amp;gt; Rule[U] = pick(f.orElse(g))

val sign: Rule[int] = either(match &apos;+&apos; -&amp;gt; 1, match &apos;-&apos; -&amp;gt; -1)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A lambda or a &lt;code&gt;match&lt;/code&gt; function passed for a type argument bounded by &lt;code&gt;Sendable&lt;/code&gt;, as
&lt;code&gt;take[U: Sendable](value: U)&lt;/code&gt; has, is made as a &lt;code&gt;@sendable&lt;/code&gt; function and checked as one where it is
made; a plain function type the expected type gives that argument is taken as its &lt;code&gt;@sendable&lt;/code&gt; form.
A &lt;code&gt;match&lt;/code&gt; function written where a &lt;code&gt;PartialFunction&lt;/code&gt; is expected is made of two &lt;code&gt;@sendable&lt;/code&gt;
functions there, one testing its patterns and guards and one running its arms, checked as one
function whose fault is reported once. &lt;code&gt;PartialFunction&lt;/code&gt; itself does not promise &lt;code&gt;Sendable&lt;/code&gt;, so the
bound holds at that call only where every value the call gives of the type argument is such a
&lt;code&gt;match&lt;/code&gt; function: an argument of exactly that type for each parameter whose type could give the
callee a value of it (one naming it as what a function passed takes gives none). A written type
argument is held to the bound as written.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;take[U: Sendable](value: U) -&amp;gt; U = value

val vowel: PartialFunction[char, int] = take(match
  &apos;a&apos; -&amp;gt; 1
  &apos;e&apos; -&amp;gt; 2)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.spawn

background[T: Sendable](@sendable body: () -&amp;gt; T) -&amp;gt; T = spawn(body).join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;spawn&lt;/code&gt; and &lt;code&gt;s.spawn&lt;/code&gt; take their body &lt;code&gt;@sendable&lt;/code&gt;, as do &lt;code&gt;Future(body)&lt;/code&gt;, &lt;code&gt;ex.future(body)&lt;/code&gt;, a
future’s &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt; and the &lt;code&gt;orElse&lt;/code&gt; of a future of a &lt;code&gt;Result&lt;/code&gt;, whose
functions run on a pool thread. A mutex’s value and the body of its &lt;code&gt;with&lt;/code&gt; are &lt;code&gt;@isolating&lt;/code&gt;
(&lt;a href=&quot;#synchronization&quot;&gt;synchronization&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Module-level state is shared by every thread&lt;/strong&gt;, and a body reaches it by name, not by capture.
So what is passed for a &lt;code&gt;@sendable&lt;/code&gt; parameter, directly or through every function it calls, may
read and write no module-level &lt;code&gt;var&lt;/code&gt;, and may read no module-level &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;lazy val&lt;/code&gt; or &lt;code&gt;object&lt;/code&gt;
whose type is not sendable. Avin compiles the whole program, so every function a body can reach is
known: the one a call names, every implementation a call through a trait method or an operator may
reach, every closure made on the way, an extractor a pattern calls, and the initializer of every
&lt;code&gt;lazy val&lt;/code&gt;, module-level or a field, that it reads, since its first read runs the initializer on
whichever thread makes it. Which implementations a call may reach follows the types its receiver may
have: a data type’s own, a class’s and its subclasses’, those of the types conforming to a trait or
to a type parameter’s bounds, and, in a generic function called at known type arguments, those of
the types it is called at. So &lt;code&gt;Map[int, string]&lt;/code&gt; in a body never reaches a program’s own &lt;code&gt;hash&lt;/code&gt;, and
&lt;code&gt;[Money(1), Money(2)].sum&lt;/code&gt; reaches &lt;code&gt;Money&lt;/code&gt;‘s &lt;code&gt;+&lt;/code&gt;. A module-level &lt;code&gt;val&lt;/code&gt; of an
&lt;code&gt;Atomic&lt;/code&gt;, a &lt;code&gt;Mutex&lt;/code&gt;, a &lt;code&gt;Channel&lt;/code&gt; or immutable data is the way to share state between threads; a
&lt;code&gt;lazy val&lt;/code&gt; of a sendable type is initialized once whichever threads read it. A local &lt;code&gt;lazy val&lt;/code&gt; a
body captures brings its initializer along, so what that initializer captures and reaches is held to
these rules too. The error names the
module-level item and the functions it is reached through:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;var hits = 0

record() = hits += 1

main()
  spawn(() -&amp;gt; record()).join()
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: what is passed for `body` of `spawn` may run on another thread, which shares the program&apos;s module-level state, but through `record` it reaches `hits`, a module-level `var`, which every thread would share; share it through an `Atomic` or a `Mutex` held in a `val`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With &lt;code&gt;val hits = Atomic(0)&lt;/code&gt; and &lt;code&gt;record() = hits.add(1)&lt;/code&gt; the program is legal. Printing is legal from any
thread: &lt;code&gt;print&lt;/code&gt;, &lt;code&gt;println&lt;/code&gt; and &lt;code&gt;eprintln&lt;/code&gt; reach the runtime’s streams, which keep no state of the
program’s, and each call’s output goes out whole: a line one thread prints is never split by
another’s (system-library.md § Standard input). Reading standard input is legal from any thread
too: threads read it one at a time, and a line goes whole to exactly one of them. What is passed for an &lt;code&gt;@isolating&lt;/code&gt; parameter is held to it too, though it runs at once on
the calling thread: a module-level value is where it could leave what it isolates for code that
does not take the lock. What is passed for an &lt;code&gt;@isolated&lt;/code&gt; one is not.&lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl handle&lt;/a&gt; is the exception: it belongs to one owner at a time,
and a use by any other code traps. The handles a thread’s body or a future’s body reaches move to
it when it starts, and are in transit, for the next code to use them, once it returns, before a
future’s value is published, so its awaiter may use them at once; an actor
will own its handles across every message, whichever thread runs it.&lt;/p&gt;
&lt;h2 id=&quot;synchronization&quot;&gt;Synchronization&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;avin.threads&lt;/code&gt; offers, all written in Avin over Sysl’s atomics and futex-based locks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Mutex[T](value)&lt;/code&gt;&lt;/strong&gt;, which owns the value it guards, and is sendable whatever &lt;code&gt;T&lt;/code&gt; is.
&lt;code&gt;m.with(v -&amp;gt; …)&lt;/code&gt; takes the lock, runs the
body with the value and lets the lock go when the body returns, giving back what it returned; it
is the way to a mutable value, such as a &lt;code&gt;Buffer&lt;/code&gt;, which the body changes in place. So that
nothing reaches the value but under the lock, &lt;code&gt;value&lt;/code&gt; is &lt;code&gt;@isolating&lt;/code&gt;, made in the argument
(&lt;code&gt;Mutex(Buffer[int]())&lt;/code&gt;, not a buffer the caller keeps), and so is the body, whose result is
sendable: &lt;code&gt;with[R: Sendable](@isolating body: (T) -&amp;gt; R) -&amp;gt; R&lt;/code&gt;. A body may read and assign the
caller’s &lt;code&gt;var&lt;/code&gt;s of sendable types, since it runs at once on the calling thread, and may read
module-level &lt;code&gt;val&lt;/code&gt;s of sendable types (another mutex among them), but nothing it runs may reach a
module-level &lt;code&gt;var&lt;/code&gt; or a module-level value of a type that is not sendable: storing the value
there, in a module-level collection or in an object’s field would let the program change it later
without the lock. A body reads such a &lt;code&gt;var&lt;/code&gt; through a local read before it. For a sendable
value, &lt;code&gt;get()&lt;/code&gt; reads it, &lt;code&gt;set(v)&lt;/code&gt; replaces it and &lt;code&gt;update(f)&lt;/code&gt; replaces it with &lt;code&gt;f&lt;/code&gt; of it
under the lock, giving back the new value. A mutex is not reentrant: a thread that takes one it
already holds, from inside a body, would wait for ever, so it traps instead.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Condition&lt;/code&gt;&lt;/strong&gt;, made by a mutex’s &lt;code&gt;condition()&lt;/code&gt; and waited for inside that mutex’s &lt;code&gt;with&lt;/code&gt;; like
its mutex, it is sendable.
&lt;code&gt;wait()&lt;/code&gt; lets the mutex go while it sleeps and holds it again before it returns; &lt;code&gt;notify()&lt;/code&gt; wakes
one waiting thread and &lt;code&gt;notifyAll()&lt;/code&gt; every one. A wait may end with nothing having changed, so the
state is checked again in a loop. &lt;code&gt;waitFor(timeoutMillis: long) -&amp;gt; bool&lt;/code&gt; waits at most that many
milliseconds and answers &lt;code&gt;false&lt;/code&gt; where the time ran out first; a time that is not positive
answers &lt;code&gt;false&lt;/code&gt; at once. &lt;code&gt;waitFor(timeout: Duration) -&amp;gt; bool&lt;/code&gt; is the same wait for a
&lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/a&gt;, a part of a millisecond waited for as a whole one. Waiting from a thread
that does not hold the mutex traps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Atomic[T](value)&lt;/code&gt;&lt;/strong&gt;, with &lt;code&gt;load&lt;/code&gt;, &lt;code&gt;store&lt;/code&gt;, &lt;code&gt;swap&lt;/code&gt;, &lt;code&gt;compareAndSet(expected, desired) -&amp;gt; bool&lt;/code&gt;
and &lt;code&gt;update(f)&lt;/code&gt;, and for the integers &lt;code&gt;add(n)&lt;/code&gt; and &lt;code&gt;sub(n)&lt;/code&gt;, each giving back the new value and
trapping on overflow, as &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt; do, before anything is stored. Every operation is
sequentially consistent; there are no weaker orderings in the library. &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; and
references are the types it is for, and it holds any type: a value of one word is accessed
lock-free, an integer wider than 64 bits under a lock the runtime keeps for them; an atomic
reaches another thread only where its value is sendable, as a &lt;code&gt;Channel&lt;/code&gt; does. A
compare-and-set of a reference to an object of a class compares identity, as &lt;code&gt;===&lt;/code&gt; does (even for
a class that derives &lt;code&gt;Eq&lt;/code&gt;), and of a function value likewise, so a reference held in an &lt;code&gt;Atomic&lt;/code&gt;
is also kept alive by it. A compare-and-set of a scalar compares the value (a &lt;code&gt;real&lt;/code&gt;, its bits).
A compare-and-set of a value without identity (a data value, an &lt;code&gt;Option&lt;/code&gt; among them, a tuple, a
string or an &lt;code&gt;Any&lt;/code&gt;) compares with &lt;code&gt;==&lt;/code&gt;: it succeeds where the current value is &lt;code&gt;==&lt;/code&gt; to &lt;code&gt;expected&lt;/code&gt;,
however the two were made. It loads the value, compares, and compares-and-sets the word it
loaded, trying again where another thread changed it in between. The kind is known for each
&lt;code&gt;T&lt;/code&gt;, so a scalar or a class reference costs one hardware compare-and-set. &lt;code&gt;update(f)&lt;/code&gt; retries by
the same rule.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Channel[T](capacity = unbounded)&lt;/code&gt;&lt;/strong&gt;, a queue between threads: unbounded with no capacity
(&lt;code&gt;unbounded&lt;/code&gt; is the largest &lt;code&gt;int&lt;/code&gt;), bounded with a positive one, where &lt;code&gt;send&lt;/code&gt; waits while the
channel is full, and a &lt;a href=&quot;#rendezvous&quot;&gt;rendezvous&lt;/a&gt; with a capacity of zero; a negative capacity
traps. &lt;code&gt;receive()&lt;/code&gt; waits for a value and gives &lt;code&gt;Some&lt;/code&gt; of it, or &lt;code&gt;None&lt;/code&gt; once the channel is closed
and every value sent before is received. &lt;code&gt;close()&lt;/code&gt; wakes every waiting thread, and a send to a
closed channel traps; closing twice does nothing. &lt;code&gt;trySend(x) -&amp;gt; bool&lt;/code&gt; and
&lt;code&gt;tryReceive() -&amp;gt; Option[T]&lt;/code&gt; never wait, and &lt;code&gt;isClosed()&lt;/code&gt; asks. A channel is &lt;code&gt;Iterable&lt;/code&gt;:
&lt;code&gt;for x in ch&lt;/code&gt; receives until it is closed and drained. The waits have
&lt;a href=&quot;#timers-and-deadlines&quot;&gt;timed forms&lt;/a&gt;, &lt;code&gt;receive(timeout)&lt;/code&gt; and &lt;code&gt;send(x, timeout)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Once&lt;/code&gt;&lt;/strong&gt;, whose &lt;code&gt;run(body)&lt;/code&gt; runs its body exactly once, whichever threads call it and however
many at once: every other call waits until that body has returned, and returns without running its
own. &lt;code&gt;isDone()&lt;/code&gt; says whether it has run. A body that runs its own &lt;code&gt;Once&lt;/code&gt; again traps, as a mutex
taken twice does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;WaitGroup()&lt;/code&gt;&lt;/strong&gt;, a count of work under way. &lt;code&gt;add(n)&lt;/code&gt; counts &lt;code&gt;n&lt;/code&gt; more pieces (or &lt;code&gt;-n&lt;/code&gt; finished,
where &lt;code&gt;n&lt;/code&gt; is negative), &lt;code&gt;done()&lt;/code&gt; counts one finished, and &lt;code&gt;wait()&lt;/code&gt; sleeps until the count is zero,
returning at once where it is. &lt;code&gt;waitFor(timeoutMillis: long) -&amp;gt; bool&lt;/code&gt; and
&lt;code&gt;waitFor(timeout: Duration) -&amp;gt; bool&lt;/code&gt; wait at most that long and answer whether the count reached
zero; a time that is not positive only asks. &lt;code&gt;pending()&lt;/code&gt; reads the count. It counts work, not
threads, so the pieces may be finished by threads started anywhere (a scope, an executor, an
actor) or by no new thread at all; threads a body starts and waits for itself are a
&lt;a href=&quot;#starting-and-joining&quot;&gt;scope&lt;/a&gt;‘s to count, so a wait group has no &lt;code&gt;spawn&lt;/code&gt; of its own. A count taken
below zero traps, since a piece was finished twice or never added. A wait group is sendable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Semaphore(permits: int, capacity: int = permits)&lt;/code&gt;&lt;/strong&gt;, a count of permits. &lt;code&gt;acquire()&lt;/code&gt; takes one,
sleeping while there is none; &lt;code&gt;tryAcquire() -&amp;gt; bool&lt;/code&gt; takes one only where one is free now;
&lt;code&gt;acquireFor(timeoutMillis: long) -&amp;gt; bool&lt;/code&gt; and &lt;code&gt;acquireFor(timeout: Duration) -&amp;gt; bool&lt;/code&gt; wait at most
that long; &lt;code&gt;release()&lt;/code&gt; gives one back, waking a waiter. &lt;code&gt;withPermit(body)&lt;/code&gt; takes a permit for its
body and gives it back when the body returns, giving back what it returned; a cancellation that
stops the thread inside the body gives the permit back too, and a trap inside it stops the
program even in an &lt;a href=&quot;/spec/actors/&quot;&gt;actor&lt;/a&gt;, since the permit would never come back. A semaphore holds at most &lt;code&gt;capacity&lt;/code&gt;
permits, &lt;code&gt;permits&lt;/code&gt; of them at first, so &lt;code&gt;Semaphore(0, capacity = 1)&lt;/code&gt; starts empty and signals. A
release that would hold more than the capacity traps, since it gives back a permit nobody took, as
does a semaphore made with negative permits, a capacity below one, or more permits than its
capacity. Permits belong to no thread: one thread may take a permit another gives back. Waiters
take no place in a queue, so a thread that asks just as a permit comes back may take it before one
that has waited longer. A semaphore is sendable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;RwLock[T](value)&lt;/code&gt;&lt;/strong&gt;, a value many threads may read at once and one at a time may write. It owns
its value as a &lt;code&gt;Mutex&lt;/code&gt; does, made in the argument, and its bodies are &lt;code&gt;@isolating&lt;/code&gt; and give back a
sendable value: &lt;code&gt;read[R: Sendable](@isolating body: (T) -&amp;gt; R) -&amp;gt; R&lt;/code&gt; runs alongside any other
readers, &lt;code&gt;write[R: Sendable](@isolating body: (T) -&amp;gt; R) -&amp;gt; R&lt;/code&gt; alone. A read body only reads; one
that changes a value other readers are reading races with them, which nothing checks. For a
sendable value &lt;code&gt;get()&lt;/code&gt; reads, &lt;code&gt;set(v)&lt;/code&gt; writes and &lt;code&gt;update(f)&lt;/code&gt; replaces the value with &lt;code&gt;f&lt;/code&gt; of it,
giving back the new value. &lt;strong&gt;Writers come first&lt;/strong&gt;: once a writer waits, a thread that asks to read
waits behind it, so a stream of overlapping readers never keeps a writer out; and when a write
ends, every reader that was waiting goes in before the next writer, so a stream of writers never
keeps those readers out. A write body runs to its end once begun, as a mutex’s does; a read body is
stopped by a cancellation like any other code, and its share of the lock is given back as it stops.
A trap inside either body stops the program, even in an actor, as one under a mutex does.
It is not reentrant: reading or writing inside one’s own write traps, and writing inside one’s own
read, or reading inside it while a writer waits, waits for ever. It is sendable whatever &lt;code&gt;T&lt;/code&gt; is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Barrier(parties: int, action: () -&amp;gt; unit = () -&amp;gt; ())&lt;/code&gt;&lt;/strong&gt;, a meeting point for &lt;code&gt;parties&lt;/code&gt; threads.
&lt;code&gt;wait() -&amp;gt; bool&lt;/code&gt; sleeps until that many have called it, then all go on and the barrier is ready for
the next round; the last to arrive runs the &lt;code&gt;@sendable&lt;/code&gt; &lt;code&gt;action&lt;/code&gt; first, once a round, with the
others still waiting, and its &lt;code&gt;wait&lt;/code&gt; answers &lt;code&gt;true&lt;/code&gt;, every other &lt;code&gt;false&lt;/code&gt;. The action runs to its
end once begun, and one that waits on its own barrier traps. A party whose thread is cancelled while
it waits takes its arrival back, so the round still waits for &lt;code&gt;parties&lt;/code&gt; threads. &lt;code&gt;parties&lt;/code&gt; reads the
number and &lt;code&gt;waiting()&lt;/code&gt; how many wait now. A barrier has at least one party, and is sendable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;lazy val&lt;/code&gt;s&lt;/strong&gt;, module-level, fields and locals alike (&lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;Initialization&lt;/a&gt;),
initialized by exactly one thread, as a &lt;code&gt;Once&lt;/code&gt; is run: a thread that reads one while another runs
its initializer waits, safe for the collector, and the stored value is published with a release
store that every read pairs with an acquire load, so no thread sees it half made. A read by the
initializing thread itself traps, as a &lt;code&gt;Once&lt;/code&gt; run again from its body does, and a trap in the
initializer stops the program; a read that the initializer’s own code reaches, not through a
function it hands on, is a compile error instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Channel, scope}

main() -&amp;gt; int
  val jobs = Channel[int](16)
  val results = Channel[int]()
  scope(s -&amp;gt;
    for w in 0 ..&amp;lt; 4
      s.spawn(() -&amp;gt;
        for n in jobs do results.send(n * n))
    for n in 1 .. 100 do jobs.send(n)
    jobs.close())
  results.close()
  var total = 0
  for r in results do total += r
  total % 256
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every operation that can wait marks its thread safe for the collector while it waits, so a thread
parked on a lock, a condition, a channel or a join, blocked on standard input, or writing to standard
output or standard error where they lead to a full pipe, its own trap report included, never holds up
a collection. A lightweight thread waiting for standard input from a pipe, a socket or a terminal
parks and leaves its worker to the others; that wait is not a cancellation point.
A Sysl binding &lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;declared &lt;code&gt;blocking&lt;/code&gt;&lt;/a&gt; does the same. A thread
waiting for a mutex takes it in turn: the mutex goes to the thread that has waited longest. A thread
taking a lock it already holds traps at once. A program whose threads, &lt;code&gt;main&lt;/code&gt; among them, all wait for
each other stops with a &lt;a href=&quot;#deadlock&quot;&gt;deadlock report&lt;/a&gt;; threads that wait for each other while another
still runs sleep for ever.&lt;/p&gt;
&lt;h3 id=&quot;rendezvous&quot;&gt;Rendezvous&lt;/h3&gt;
&lt;p&gt;A channel made with a capacity of zero holds no value at all: each send hands its value straight to a
receiver, so the two threads meet.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Channel, spawn}

main() -&amp;gt; int
  val handoff = Channel[string](0)
  val worker = spawn(() -&amp;gt;
    var n = 0
    for job in handoff do n += job.charCount
    n)
  for job in [&amp;quot;parse&amp;quot;, &amp;quot;check&amp;quot;, &amp;quot;emit&amp;quot;] do handoff.send(job)
  handoff.close()
  worker.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What a program can rely on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A send returns only once a receiver has the value.&lt;/strong&gt; &lt;code&gt;send(x)&lt;/code&gt; waits until a receiver takes &lt;code&gt;x&lt;/code&gt;,
and a receive waits until a sender hands it one. Everything the receiving thread did before its
receive happens before the send returns, as everything the sender did before its send happens
before the receive returns, so each side knows the other has reached the meeting point.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The &lt;code&gt;try&lt;/code&gt; forms need a partner waiting now.&lt;/strong&gt; &lt;code&gt;trySend(x)&lt;/code&gt; hands &lt;code&gt;x&lt;/code&gt; over only where a receiver is
already waiting, a plain &lt;code&gt;receive&lt;/code&gt; or a &lt;code&gt;select&lt;/code&gt; waiting on a receive arm, and answers whether it
did; &lt;code&gt;tryReceive()&lt;/code&gt; takes a value only from a sender already waiting. Neither waits. A thread that
has not yet begun to wait is not waiting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The timed forms give up cleanly.&lt;/strong&gt; &lt;code&gt;send(x, timeout)&lt;/code&gt; answers &lt;code&gt;false&lt;/code&gt; where no receiver took &lt;code&gt;x&lt;/code&gt;
within the time, and then &lt;code&gt;x&lt;/code&gt; is received by nobody; &lt;code&gt;receive(timeout)&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt; where no
sender came. A timeout of zero or less is the &lt;code&gt;try&lt;/code&gt; form.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;select&lt;/code&gt; arm hands a value over only when it is paired.&lt;/strong&gt; A send arm runs once a receiver has
taken its value, a receive arm once a sender has handed it one, and the partner may be a plain
&lt;code&gt;send&lt;/code&gt; or &lt;code&gt;receive&lt;/code&gt; or another select’s arm, waiting first or coming while the select waits. Every
arm that does not run hands nothing over, so a value meant for a send arm that lost is never
received. A select never pairs with itself: a send and a receive arm on one channel wait for other
threads. With &lt;code&gt;else&lt;/code&gt;, a select pairs only with a partner already waiting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A close ends every hand-off.&lt;/strong&gt; A sender waiting when the channel is closed traps, as any send to a
closed channel does, its value handed to nobody; a receiver waiting gets &lt;code&gt;None&lt;/code&gt;, and so does every
receive after, since a closed rendezvous has nothing to drain. A select’s send arm traps and its
&lt;code&gt;None&lt;/code&gt; arm runs, as on any closed channel.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its waits are waits like any other.&lt;/strong&gt; A thread waiting to hand a value over, or to take one, parks
only itself, is safe for the collector, and is a cancellation point: cancelled, it leaves nothing
on the channel, and the next sender’s value goes to the next receiver. A cancellation that comes
after a value was handed over stops a receiver that has it. The wait counts for the
&lt;a href=&quot;#deadlock&quot;&gt;deadlock check&lt;/a&gt;, whose report names a sender as &lt;em&gt;waiting to hand a value to a
receiver&lt;/em&gt;. Which of several waiting receivers gets a value is not specified.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sendable as any channel.&lt;/strong&gt; A channel of capacity zero is sendable where its values are, as every
channel is.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;pools&quot;&gt;Pools&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;&lt;code&gt;Pool[T, E]&lt;/code&gt;&lt;/strong&gt; holds resources that are costly to make, connections to a database or a server
for one, and lends them again and again. &lt;code&gt;use(f)&lt;/code&gt; lends one for the call of &lt;code&gt;f&lt;/code&gt;, takes it back when
&lt;code&gt;f&lt;/code&gt; returns, and answers &lt;code&gt;Ok&lt;/code&gt; of what &lt;code&gt;f&lt;/code&gt; returned, or the &lt;code&gt;PoolError[E]&lt;/code&gt; that kept the call from
getting one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;class Pool[T, E](
    create: @sendable () -&amp;gt; Result[T, E],
    maxSize: int,
    minIdle: int = 0,
    validate: Option[@sendable (T) -&amp;gt; bool] = None,
    destroy: Option[@sendable (T) -&amp;gt; unit] = None,
    idleTimeout: Option[Duration] = None,
    acquireTimeout: Option[Duration] = None,
    maxLifetime: Option[Duration] = None,
    jitter: Option[Duration] = None,
    maxWaiting: Option[int] = None
): Sendable

data PoolError[+E]
  AcquireTimedOut
  QueueFull
  PoolClosed
  CreateFailed(error: E)

data PoolStats(size: int, idle: int, lent: int, waiting: int)

data PoolCounters(
    acquires: long,
    waited: long,
    waitTime: Duration,
    timeouts: long,
    rejected: long,
    created: long,
    destroyed: long
)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A resource is made when it is wanted.&lt;/strong&gt; A call that finds a resource idle takes the one given
back last; one that finds none, with fewer than &lt;code&gt;maxSize&lt;/code&gt; made, makes one with &lt;code&gt;create&lt;/code&gt;; one that
finds all &lt;code&gt;maxSize&lt;/code&gt; lent waits for one to come back. A &lt;code&gt;create&lt;/code&gt; that fails makes the call fail with
&lt;code&gt;CreateFailed&lt;/code&gt;, carrying the error, and gives up its place, so the pool holds nothing more than
before and the next call tries again. &lt;code&gt;warm()&lt;/code&gt; makes resources until the pool holds &lt;code&gt;minIdle&lt;/code&gt;, each
left idle, answering the first failure of &lt;code&gt;create&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Waiters are served in the order they came.&lt;/strong&gt; A resource given back goes straight to the call that
has waited longest, and so does the place a destroyed resource gives up, where that call then makes
a resource of its own; a call that comes while others wait queues behind them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call waits for at most its timeout.&lt;/strong&gt; &lt;code&gt;use(timeout, f)&lt;/code&gt; waits at most &lt;code&gt;timeout&lt;/code&gt;, &lt;code&gt;use(f)&lt;/code&gt; the
pool’s &lt;code&gt;acquireTimeout&lt;/code&gt;, or for ever where there is none, and a call whose time runs out fails
with &lt;code&gt;AcquireTimedOut&lt;/code&gt;, leaving the queue as if it had never come. A timeout of zero or less takes
a resource only where one is idle, or can be made, now.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The queue may be bounded.&lt;/strong&gt; Where &lt;code&gt;maxWaiting&lt;/code&gt; calls already wait, a call that would join them
fails at once with &lt;code&gt;QueueFull&lt;/code&gt;, so a server can turn a request away instead of letting it queue;
a call that finds a resource idle, or a place to make one, is never turned away, and a zero
&lt;code&gt;maxWaiting&lt;/code&gt; means no call ever waits. With no &lt;code&gt;maxWaiting&lt;/code&gt; the queue has no bound. A negative
&lt;code&gt;maxWaiting&lt;/code&gt; traps where the pool is made.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A broken resource is destroyed, not lent again.&lt;/strong&gt; &lt;code&gt;lease(f)&lt;/code&gt; and &lt;code&gt;lease(timeout, f)&lt;/code&gt; lend the
resource as a &lt;code&gt;Lease[T]&lt;/code&gt;, whose &lt;code&gt;resource&lt;/code&gt; is the resource and whose &lt;code&gt;markBroken()&lt;/code&gt; says it is no
good any more: the pool destroys it, with &lt;code&gt;destroy&lt;/code&gt; where one is given, when the body returns.
&lt;code&gt;validate&lt;/code&gt; checks an idle resource before it is lent again, never one just made: one it answers
&lt;code&gt;false&lt;/code&gt; for is destroyed and the call looks again.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Idle resources expire.&lt;/strong&gt; A resource idle for longer than &lt;code&gt;idleTimeout&lt;/code&gt; is destroyed the next time
a call looks for one, oldest first, keeping at least &lt;code&gt;minIdle&lt;/code&gt;; &lt;code&gt;evictIdle()&lt;/code&gt; does the same at once
and answers how many it destroyed. With no &lt;code&gt;idleTimeout&lt;/code&gt; nothing expires.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Old resources retire.&lt;/strong&gt; A resource older than &lt;code&gt;maxLifetime&lt;/code&gt; is never lent again: one found idle
is destroyed instead of being lent, and the call looks again; one given back is destroyed instead
of being kept; and &lt;code&gt;evictIdle()&lt;/code&gt; destroys the idle ones however few that leaves, &lt;code&gt;warm()&lt;/code&gt; making
up &lt;code&gt;minIdle&lt;/code&gt; again. &lt;code&gt;jitter&lt;/code&gt; lengthens each resource’s &lt;code&gt;maxLifetime&lt;/code&gt; and &lt;code&gt;idleTimeout&lt;/code&gt; by its own
random part of &lt;code&gt;jitter&lt;/code&gt;, from none up to all of it, drawn when the resource is made, so resources
made together do not all expire together; it never shortens either limit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The resource always comes back.&lt;/strong&gt; It is taken back when &lt;code&gt;f&lt;/code&gt; returns and when the thread running
&lt;code&gt;f&lt;/code&gt; is cancelled inside it. A cancellation anywhere else in the call puts back what the call held:
its place among the waiters, a resource handed to it there, the place it held while &lt;code&gt;create&lt;/code&gt; ran,
a resource &lt;code&gt;validate&lt;/code&gt; was checking, which goes back as one given back does (destroyed only where
the pool is closed by then or the resource has outlived &lt;code&gt;maxLifetime&lt;/code&gt;) and is checked again before it is next lent, so a deadline passing
during a check never destroys a good resource. A trap inside &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;validate&lt;/code&gt; or
&lt;code&gt;destroy&lt;/code&gt; stops the program, even in an &lt;a href=&quot;/spec/actors/&quot;&gt;actor&lt;/a&gt;, as one inside a semaphore’s
&lt;code&gt;withPermit&lt;/code&gt; does, since what the pool counts would otherwise never come right.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;close()&lt;/code&gt; ends the pool.&lt;/strong&gt; Every call waiting fails with &lt;code&gt;PoolClosed&lt;/code&gt;, as does every call after,
the idle resources are destroyed, and &lt;code&gt;close&lt;/code&gt; waits for the lent ones to come back, destroying each
as it does; a resource whose make finishes after the close is destroyed too. Closing a closed pool
waits for the same, and a thread that closes a pool while a resource is lent to it waits for ever.
&lt;code&gt;isClosed()&lt;/code&gt; says whether it was closed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;stats()&lt;/code&gt;&lt;/strong&gt; answers what the pool holds now: &lt;code&gt;size&lt;/code&gt; resources in all, of which &lt;code&gt;idle&lt;/code&gt; wait to be
lent and &lt;code&gt;lent&lt;/code&gt; are lent, and &lt;code&gt;waiting&lt;/code&gt; calls waiting for one; the rest are being made or checked.
&lt;code&gt;maxSize&lt;/code&gt; below one, and &lt;code&gt;minIdle&lt;/code&gt; below zero or above &lt;code&gt;maxSize&lt;/code&gt;, trap where the pool is made.
&lt;strong&gt;&lt;code&gt;counters()&lt;/code&gt;&lt;/strong&gt; answers running totals since the pool was made: &lt;code&gt;acquires&lt;/code&gt; calls lent a resource,
&lt;code&gt;waited&lt;/code&gt; of them after waiting in the queue, and &lt;code&gt;waitTime&lt;/code&gt; all of them took from the call to the
lending, making or checking a resource included; &lt;code&gt;timeouts&lt;/code&gt; calls whose time ran out; &lt;code&gt;rejected&lt;/code&gt;
calls turned away with &lt;code&gt;QueueFull&lt;/code&gt;; and &lt;code&gt;created&lt;/code&gt; resources made and &lt;code&gt;destroyed&lt;/code&gt; let go, for
whatever reason. A &lt;code&gt;create&lt;/code&gt; that fails makes nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A resource belongs to one call at a time&lt;/strong&gt;, so a pool of any type is sendable, as a &lt;code&gt;Mutex&lt;/code&gt; is,
and its resources may be mutable connections. So that nothing else reaches one, &lt;code&gt;create&lt;/code&gt;,
&lt;code&gt;validate&lt;/code&gt; and &lt;code&gt;destroy&lt;/code&gt; are &lt;code&gt;@sendable&lt;/code&gt;, and a body is &lt;code&gt;@isolating&lt;/code&gt; and gives back only a sendable
value: it may not keep the resource, or its lease, or hand it to the body of another pool’s call.
Each resource given back has its &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl handles&lt;/a&gt; put in transit, so
the thread or actor it is lent to next uses them as its own.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Atomic, Pool, scope}

class Conn(val id: int): Sendable

main()
  val made = Atomic(0)
  val db = Pool[Conn, string](() -&amp;gt; Ok(Conn(made.add(1))), maxSize = 2)
  val total = Atomic(0)
  scope(s -&amp;gt;
    for n in 1 .. 10 do s.spawn(() -&amp;gt; _ = db.use(c -&amp;gt; total.add(n))))
  println(s&amp;quot;total ${total.load()}, made at most 2: ${made.load() &amp;lt;= 2}&amp;quot;)
  val st = db.stats()
  println(s&amp;quot;lent ${st.lent}, all idle: ${st.idle == st.size}&amp;quot;)
  db.close()
  println(db.use(c -&amp;gt; c.id))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;total 55, made at most 2: true
lent 0, all idle: true
Err(the pool is closed)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;select&quot;&gt;select&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;select&lt;/code&gt; block waits on several channels at once, and on connections, and runs exactly one of its
arms: the first whose channel operation can complete or whose connection has bytes to read.
&lt;code&gt;select&lt;/code&gt; ending its line opens the block of its arms, written as a match’s are; elsewhere &lt;code&gt;select&lt;/code&gt;
is an ordinary name. As with a match, inside brackets whose commas separate items a comma after a
one-line arm’s body ends the arm, the &lt;code&gt;select&lt;/code&gt; and the item, so in &lt;code&gt;f(select&lt;/code&gt; …
&lt;code&gt;ch.receive() as v -&amp;gt; v, &amp;quot;a&amp;quot;)&lt;/code&gt; the &lt;code&gt;select&lt;/code&gt; is the first argument and &lt;code&gt;&amp;quot;a&amp;quot;&lt;/code&gt; the second; a tuple
body there is written in parentheses.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.Channel
import avin.time.millis

step(jobs: Channel[int], results: Channel[int], r: int) -&amp;gt; string = select
  jobs.receive() as Some(j) -&amp;gt; s&amp;quot;job $j&amp;quot;
  jobs.receive() as None -&amp;gt; &amp;quot;no more jobs&amp;quot;
  results.send(r) -&amp;gt; &amp;quot;sent&amp;quot;
  after 100.millis -&amp;gt; &amp;quot;idle&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What a program can rely on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The arms.&lt;/strong&gt; &lt;code&gt;ch.receive()&lt;/code&gt; receives, with an optional &lt;code&gt;as&lt;/code&gt; pattern: &lt;code&gt;Some(p)&lt;/code&gt; runs for a value
and binds it by &lt;code&gt;p&lt;/code&gt;, any pattern a &lt;code&gt;val&lt;/code&gt; takes; &lt;code&gt;None&lt;/code&gt; runs once the channel is closed and every
value sent before is received; a name runs for either and binds the &lt;code&gt;Option&lt;/code&gt; received; &lt;code&gt;_&lt;/code&gt;, or no
pattern, runs for either and binds nothing. &lt;code&gt;ch.send(x)&lt;/code&gt; sends, and binds nothing.
&lt;code&gt;stream.readable()&lt;/code&gt; runs once a read of &lt;code&gt;stream&lt;/code&gt; would answer without waiting, and binds nothing:
its body reads. &lt;code&gt;sink.writable()&lt;/code&gt; runs once a write to &lt;code&gt;sink&lt;/code&gt; would send something without
waiting, and binds nothing: its body writes, with &lt;code&gt;writeSome&lt;/code&gt; to send only what goes at once.
&lt;code&gt;after d&lt;/code&gt; runs
where no other arm became ready within the &lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/a&gt; &lt;code&gt;d&lt;/code&gt;; &lt;code&gt;else&lt;/code&gt; runs where no
arm is ready now, and is written as a match’s &lt;code&gt;else&lt;/code&gt; is, with no arrow. A select has at most one
&lt;code&gt;after&lt;/code&gt; and one &lt;code&gt;else&lt;/code&gt;, and not both, since a select with &lt;code&gt;else&lt;/code&gt; never waits. Any other arm, an
&lt;code&gt;as&lt;/code&gt; pattern on a &lt;code&gt;readable()&lt;/code&gt; or &lt;code&gt;writable()&lt;/code&gt; arm among them, is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Guards.&lt;/strong&gt; Any arm but &lt;code&gt;else&lt;/code&gt; may end in an &lt;code&gt;if&lt;/code&gt; guard before its arrow, as a match arm does:
&lt;code&gt;local.writable() if pending.length &amp;gt; 0 -&amp;gt; …&lt;/code&gt;, &lt;code&gt;ch.receive() as Some(x) if open -&amp;gt; …&lt;/code&gt;, &lt;code&gt;after d if waiting -&amp;gt; …&lt;/code&gt;. Where the guard is &lt;code&gt;false&lt;/code&gt; the arm is absent from this select: its channel or
stream is not evaluated, its value is not evaluated or sent, nothing of it is watched, and it never
runs, as if it were not written. A guard is evaluated before anything is received, so unlike a
match guard it cannot name what its arm’s pattern binds. An absent &lt;code&gt;after&lt;/code&gt; leaves a select that
waits until an arm runs.
&lt;code&gt;else&lt;/code&gt; takes no guard: what follows it is its body, so &lt;code&gt;else if c then a else b&lt;/code&gt; is an &lt;code&gt;if&lt;/code&gt;. A
select whose every arm is guarded off, with no &lt;code&gt;after&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt; left, traps when it is reached,
since nothing but a cancellation could end its wait; with an &lt;code&gt;else&lt;/code&gt; it runs the &lt;code&gt;else&lt;/code&gt;, and with
an &lt;code&gt;after&lt;/code&gt; it waits its time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Evaluation.&lt;/strong&gt; The arms are evaluated once, in the order they are written, before any arm is
tried: an arm’s guard first, then, where it is &lt;code&gt;true&lt;/code&gt; or there is none, its channel or stream, its
value sent and the &lt;code&gt;after&lt;/code&gt;‘s duration. Only the arm that runs
receives or sends: every other channel keeps its values, and a value meant for an arm that does not
run is never sent. A &lt;code&gt;readable()&lt;/code&gt; arm reads nothing and a &lt;code&gt;writable()&lt;/code&gt; arm writes nothing,
whether it runs or not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Streams.&lt;/strong&gt; A &lt;code&gt;readable()&lt;/code&gt; arm’s stream is any &lt;code&gt;Readiness&lt;/code&gt; (&lt;code&gt;avin.threads&lt;/code&gt;), which every
&lt;a href=&quot;/spec/system-library/#avin-net&quot;&gt;connection&lt;/a&gt;, a &lt;code&gt;ByteStream&lt;/code&gt;, is: TCP, Unix and TLS. It is ready
where the stream’s &lt;code&gt;readable()&lt;/code&gt; answers &lt;code&gt;true&lt;/code&gt; when the arm is tried: bytes already buffered, those
a &lt;code&gt;readLine&lt;/code&gt; read beyond its line or plaintext TLS has decrypted and not yet handed over, or bytes
arrived on the socket, and also the other end having finished sending or reset the connection, or
the connection closed, each of which its read then answers. A TLS stream counts only whole records
of plaintext, so bytes of a record still arriving do not make it ready. Where it is not ready, a
select that waits watches the stream’s descriptor on the runtime’s poller under the same one wait
as its channel arms, and whichever comes first, bytes, a channel’s value, the &lt;code&gt;after&lt;/code&gt;‘s time or a
cancellation, ends it. The arm uses its stream as a read does, so only the thread a connection
belongs to may name it in a select; any other traps. This is how a thread that owns a connection
waits both for its peer and for work other threads send it: it does all of the connection’s reads
and writes, which only it may. A connection &lt;a href=&quot;/spec/system-library/#tcp&quot;&gt;split&lt;/a&gt; into a reading and
a writing half gives each half to a thread of its own, the reader’s select naming its half’s
&lt;code&gt;readable()&lt;/code&gt; and the writer’s its half’s &lt;code&gt;writable()&lt;/code&gt;.
&lt;a href=&quot;/spec/system-library/#standard-streams-as-bytes&quot;&gt;Standard input&lt;/a&gt;, &lt;code&gt;io.stdin()&lt;/code&gt;, is a
&lt;code&gt;Readiness&lt;/code&gt; too: ready where bytes are in the buffer every reader of it shares, those a
&lt;code&gt;readLine&lt;/code&gt; read past its line among them, or have arrived, or the input has ended or failed, or it
is a file. It belongs to no thread, so any thread may name it, and several at once; a select
waits on it while another thread reads it, and bytes that read leaves in the buffer end the wait
as arriving bytes do.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sinks.&lt;/strong&gt; A &lt;code&gt;writable()&lt;/code&gt; arm’s sink is any &lt;code&gt;Writability&lt;/code&gt; (&lt;code&gt;avin.threads&lt;/code&gt;): every connection, and
the writing half of a split one. It is ready where the sink’s &lt;code&gt;writable()&lt;/code&gt; answers &lt;code&gt;true&lt;/code&gt; when the
arm is tried: the socket has room, or the connection has failed or is closed, which its write then
answers. A TLS sink is ready once the record an earlier &lt;code&gt;writeSome&lt;/code&gt; began has gone, &lt;code&gt;writable()&lt;/code&gt;
sending what of it there is room for; the writing half of a split TLS connection sends each
record whole before its &lt;code&gt;writeSome&lt;/code&gt; answers, so the loop below leaves nothing behind when it ends. Where it is not ready, a select that waits watches the
descriptor for room on the poller as a &lt;code&gt;readable()&lt;/code&gt; arm watches it for bytes, and a reading and a
writing half of one connection may each wait on it at once, each woken by its own direction.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choosing.&lt;/strong&gt; Of several arms ready at once, each is as likely to run as any other: the arms are
tried in an order drawn at random each time. Where none is ready, a select with &lt;code&gt;else&lt;/code&gt; runs it, and
one without waits, parking only its thread, until an arm can complete and runs it, or until its
&lt;code&gt;after&lt;/code&gt;‘s time runs out. An &lt;code&gt;after&lt;/code&gt; of zero or less tries the arms once, as &lt;code&gt;else&lt;/code&gt; does. A select of
&lt;code&gt;after&lt;/code&gt; alone waits its duration; one of &lt;code&gt;else&lt;/code&gt; alone runs it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Closed channels behave as &lt;code&gt;receive&lt;/code&gt; and &lt;code&gt;send&lt;/code&gt; do.&lt;/strong&gt; The values sent before a close are received
first; then a &lt;code&gt;None&lt;/code&gt; arm, a name and &lt;code&gt;_&lt;/code&gt; run, every time after. &lt;code&gt;Some(p)&lt;/code&gt; is never ready on a
closed and drained channel, so a select whose only arms want values from closed channels waits for
its &lt;code&gt;after&lt;/code&gt;, runs its &lt;code&gt;else&lt;/code&gt;, or waits for ever. A send arm on a closed channel traps when it is
tried, as &lt;code&gt;send&lt;/code&gt; does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its value.&lt;/strong&gt; A select is an expression whose value is the arm that ran, the arms’ types unified as
a match’s are. Its bodies are code of the function it is in: &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; leave
an arm as they leave a match’s, and a select may be nested in another’s arm. &lt;code&gt;end select&lt;/code&gt; may close
one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Waiting.&lt;/strong&gt; A select that waits is a wait like a channel’s own: safe for the collector, and a
cancellation point, so a scope’s &lt;code&gt;cancel&lt;/code&gt; stops a thread parked in it at once. Nothing of a
select that has ended, by an arm, its time or a cancellation, is left on the channels or the
poller it waited on, and a notification a select was woken by and could not use is passed on to the next thread
waiting on that channel, so no other waiter, a plain &lt;code&gt;receive&lt;/code&gt; or another select, misses it.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.Channel

// Workers take jobs until told to stop; each result is sent where there is room for it.
work(jobs: Channel[int], stop: Channel[unit], results: Channel[int])
  var going = true
  while going
    select
      jobs.receive() as Some(j) -&amp;gt; results.send(j * j)
      jobs.receive() as None -&amp;gt; going = false
      stop.receive() as None -&amp;gt; going = false
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.io.IoError
import avin.net.TcpStream
import avin.threads.Channel

// The thread that owns a connection echoes each line its peer sends and forwards each message other
// threads put on `pushed`, until the peer finishes sending.
serve(conn: TcpStream, pushed: Channel[string]) -&amp;gt; Result[unit, IoError]
  var open = true
  while open
    select
      conn.readable() -&amp;gt; conn.readLine()? match
        Some(line) -&amp;gt; conn.writeText(s&amp;quot;echo $line\n&amp;quot;)?
        None -&amp;gt; open = false
      pushed.receive() as Some(m) -&amp;gt; conn.writeText(s&amp;quot;push $m\n&amp;quot;)?
  conn.close()
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.io.IoError
import avin.net.StreamWriter
import avin.threads.Channel

// The writing half of a split connection sends `data` a part at a time, as room comes, and stops
// early where `stop` is closed. Answers how much went.
send(w: StreamWriter, data: Array[byte], stop: Channel[unit]) -&amp;gt; Result[int, IoError]
  var at = 0
  while at &amp;lt; data.length
    select
      w.writable() -&amp;gt; at += w.writeSome(data.slice(at, data.length))?
      stop.receive() as None -&amp;gt; return Ok(at)
  Ok(at)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.io.IoError
import avin.net.TcpStream

// Relays bytes both ways between two connections on one thread. Each side is read only while
// nothing it gave is still waiting to be written, and watched for room only while something is.
relayPair(a: TcpStream, b: TcpStream) -&amp;gt; Result[unit, IoError]
  var toA: Array[byte] = Array.empty()
  var toB: Array[byte] = Array.empty()
  var aOpen = true
  var bOpen = true
  while aOpen || bOpen || toA.length &amp;gt; 0 || toB.length &amp;gt; 0
    select
      a.readable() if aOpen &amp;amp;&amp;amp; toB.length == 0 -&amp;gt;
        toB = a.read(4096)?
        if toB.length == 0
          aOpen = false
          b.shutdownOutput()?
      b.readable() if bOpen &amp;amp;&amp;amp; toA.length == 0 -&amp;gt;
        toA = b.read(4096)?
        if toA.length == 0
          bOpen = false
          a.shutdownOutput()?
      a.writable() if toA.length &amp;gt; 0 -&amp;gt; toA = toA.slice(a.writeSome(toA)?, toA.length)
      b.writable() if toB.length &amp;gt; 0 -&amp;gt; toB = toB.slice(b.writeSome(toB)?, toB.length)
  Ok(())
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;selectors&quot;&gt;Selectors&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;Selector[K]&lt;/code&gt; (&lt;code&gt;avin.threads&lt;/code&gt;) is a select whose arms are made at run time, for a set of sources
whose size is known only then: N connections, N tunnels, N workers’ channels. Each entry is added
under a key of the program’s choosing, and a wait answers the key of the entry that ran.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.io.IoError
import avin.net.TcpStream
import avin.threads.Selector

// One direction of a relayed connection pair, and what it has read and not yet written.
class Leg(val from: TcpStream, val to: TcpStream)
  var pending: Array[byte] = Array.empty()
  var open = true

// Relays bytes both ways between each pair of connections, all on one thread, until every pair has
// finished: each leg&apos;s reading side is watched while it has nothing pending, and its writing side
// while it has.
relay(pairs: Vector[(TcpStream, TcpStream)]) -&amp;gt; Result[unit, IoError]
  val legs = Buffer[Leg]()
  for (a, b) in pairs
    legs.append(Leg(a, b))
    legs.append(Leg(b, a))
  val sel = Selector[int]()
  while legs.exists(l -&amp;gt; l.open || l.pending.length &amp;gt; 0)
    sel.clear()
    for i in 0 ..&amp;lt; legs.length
      val leg = legs(i)
      if leg.pending.length &amp;gt; 0 then sel.writable(leg.to, i)
      elif leg.open then sel.readable(leg.from, i)
    val leg = legs(sel.wait())
    if leg.pending.length &amp;gt; 0
      leg.pending = leg.pending.slice(leg.to.writeSome(leg.pending)?, leg.pending.length)
    else
      val bytes = leg.from.read(4096)?
      if bytes.length == 0
        leg.open = false
        leg.to.shutdownOutput()?
      else leg.pending = bytes
  Ok(())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What a program can rely on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Entries.&lt;/strong&gt; &lt;code&gt;receive(channel, key) -&amp;gt; SelectReceive[T]&lt;/code&gt; adds a receive, ready for a value or the
channel closed and drained, and answers the entry, whose &lt;code&gt;received()&lt;/code&gt; is the &lt;code&gt;Option&lt;/code&gt; received
once a wait has answered its key. &lt;code&gt;send(channel, x, key)&lt;/code&gt; adds a send of &lt;code&gt;x&lt;/code&gt;, which a wait sends
only where it answers the key; the entry is then taken out, so a value goes once.
&lt;code&gt;readable(source, key)&lt;/code&gt; and &lt;code&gt;writable(sink, key)&lt;/code&gt; add a stream or a sink, as a select’s
&lt;code&gt;readable()&lt;/code&gt; and &lt;code&gt;writable()&lt;/code&gt; arms take them. Several entries may share a key.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The set.&lt;/strong&gt; The entries stay from one wait to the next, so a loop may keep them and change only
what changed, or &lt;code&gt;clear()&lt;/code&gt; them and add afresh. &lt;code&gt;remove(key)&lt;/code&gt; and &lt;code&gt;removeWhere(p)&lt;/code&gt; take out every
entry under a key, or whose key satisfies &lt;code&gt;p&lt;/code&gt;, and answer how many; &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;isEmpty&lt;/code&gt; count
them. The set is changed only between waits, by the thread that waits on it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Waiting.&lt;/strong&gt; &lt;code&gt;wait() -&amp;gt; K&lt;/code&gt; waits until an entry can complete, does its one operation and answers
its key. &lt;code&gt;within(timeout) -&amp;gt; Option[K]&lt;/code&gt; waits at most &lt;code&gt;timeout&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; where the time runs out
first; &lt;code&gt;until(deadline)&lt;/code&gt; waits until an &lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;Instant&lt;/code&gt;&lt;/a&gt;; &lt;code&gt;poll() -&amp;gt; Option[K]&lt;/code&gt; tries the
entries once, as &lt;code&gt;else&lt;/code&gt; does, and a timeout of zero or less does the same. A &lt;code&gt;wait&lt;/code&gt; on an empty
selector traps, as a select with every arm guarded off does; &lt;code&gt;within&lt;/code&gt; and &lt;code&gt;until&lt;/code&gt; on one wait out
their time, and &lt;code&gt;poll&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The same wait as &lt;code&gt;select&lt;/code&gt;.&lt;/strong&gt; A selector’s wait is a select’s own: entries tried in an order
drawn at random each time, so of several ready at once each is as likely to run, and none is
starved; one pass and one park on the runtime’s poller however many entries there are; at most one
operation done, no other entry receiving, sending, reading or writing; a closed channel, a send to
a closed channel, a stream used by a thread it does not belong to, cancellation and collection
all as a select’s arms meet them, above.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;timers-and-deadlines&quot;&gt;Timers and deadlines&lt;/h2&gt;
&lt;p&gt;Time reaches threads as channels and as limits on their waits, all in &lt;code&gt;avin.threads&lt;/code&gt;, each taking a
&lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/a&gt;. Every one of them waits as the other waits do: parking its lightweight
thread on the runtime’s timers, holding no worker, safe for the collector, and a cancellation point.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Channel, Ticker, after}
import avin.time.seconds

// Reports progress every second, and gives up on a result after five.
watch(results: Channel[int]) -&amp;gt; Option[int]
  val progress = Ticker(seconds(1))
  val deadline = after(seconds(5))
  var got: Option[int] = None
  var waiting = true
  while waiting
    select
      results.receive() as r -&amp;gt;
        got = r
        waiting = false
      progress.ticks.receive() -&amp;gt; println(&amp;quot;still waiting&amp;quot;)
      deadline.receive() -&amp;gt; waiting = false
  progress.stop()
  got
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What a program can rely on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;after(d) -&amp;gt; Channel[Instant]&lt;/code&gt;&lt;/strong&gt; gives a channel that delivers one value once &lt;code&gt;d&lt;/code&gt; has passed from
the call, at once for a duration of zero or less: the &lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;Instant&lt;/code&gt;&lt;/a&gt; at which the time
fell due, however late it is received. It is never delivered sooner. Only that one value ever
comes; a receive after it waits for ever, as on any channel nobody sends to, unless the channel is
closed, which ends it: nothing is delivered after a close. Of several threads receiving from one,
one gets the value. It is an ordinary channel to receive from, alone, with a timeout, or as a
&lt;code&gt;select&lt;/code&gt; arm (&lt;code&gt;after(d).receive() -&amp;gt; …&lt;/code&gt;, beside the &lt;code&gt;after d&lt;/code&gt; arm, which it does not replace).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;after&lt;/code&gt; nobody receives from costs nothing but itself.&lt;/strong&gt; The channel holds the time its value
falls due, a number, and no timer, thread or registration anywhere: the value is delivered by the
first receive or select that looks once the time has come, and a thread waiting on the channel waits
on its condition until that time at the most, its timer going with its wait. So an &lt;code&gt;after&lt;/code&gt; that is
dropped, lost in a select to another arm, or waited on by a thread that is cancelled leaves nothing
behind and is collected like any object once nothing reaches it, however long its duration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Ticker(period)&lt;/code&gt;&lt;/strong&gt; delivers a tick on its channel &lt;code&gt;ticks&lt;/code&gt; every &lt;code&gt;period&lt;/code&gt;, the first a period after
it is made, each tick the instant it fell due, so each later than the one before. The channel holds
one tick at the most: &lt;strong&gt;a tick that falls due while one is waiting to be received is dropped&lt;/strong&gt;, so a
slow receiver gets the oldest tick it has not received and then the ticks from its next period on,
never a backlog to catch up on. &lt;code&gt;stop()&lt;/code&gt; ends the ticks: none is received after it, not even one
that fell due before and was waiting; stopping twice is stopping once, and a thread waiting on
&lt;code&gt;ticks&lt;/code&gt; goes on waiting. A ticker, like &lt;code&gt;after&lt;/code&gt;, holds no timer or thread, so one dropped without
&lt;code&gt;stop&lt;/code&gt; is collected as any object is. A period of zero or less traps. A &lt;code&gt;Ticker&lt;/code&gt; is sendable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nothing sends to these channels but their clocks.&lt;/strong&gt; A &lt;code&gt;send&lt;/code&gt;, &lt;code&gt;trySend&lt;/code&gt;, timed send or &lt;code&gt;select&lt;/code&gt;
send arm on a channel &lt;code&gt;after&lt;/code&gt; or a &lt;code&gt;Ticker&lt;/code&gt; made traps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;receive(timeout: Duration) -&amp;gt; Option[T]&lt;/code&gt;&lt;/strong&gt; waits at most &lt;code&gt;timeout&lt;/code&gt; for a value: &lt;code&gt;Some&lt;/code&gt; of one, as
soon as it comes, or &lt;code&gt;None&lt;/code&gt; where the time ran out first or once the channel is closed and every
value sent before is received; &lt;code&gt;isClosed()&lt;/code&gt; tells the two apart where it matters. &lt;strong&gt;&lt;code&gt;send(x, timeout: Duration) -&amp;gt; bool&lt;/code&gt;&lt;/strong&gt; waits at most &lt;code&gt;timeout&lt;/code&gt; for room in a bounded channel, or for a
receiver to take &lt;code&gt;x&lt;/code&gt; from a &lt;a href=&quot;#rendezvous&quot;&gt;rendezvous&lt;/a&gt;, and answers whether it sent &lt;code&gt;x&lt;/code&gt;, at once on
an unbounded one; a value whose time ran out is not sent. A send to
a closed channel traps, as &lt;code&gt;send&lt;/code&gt; does, rather than answering &lt;code&gt;false&lt;/code&gt;. A timeout of zero or less is
the &lt;code&gt;try&lt;/code&gt; form, &lt;code&gt;tryReceive&lt;/code&gt; or &lt;code&gt;trySend&lt;/code&gt;. Neither waits less than its timeout where nothing comes,
a part of a millisecond waited for as a whole one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;withTimeout(timeout, s -&amp;gt; …) -&amp;gt; Option[T]&lt;/code&gt;&lt;/strong&gt; runs its body with a new &lt;a href=&quot;#starting-and-joining&quot;&gt;scope&lt;/a&gt;
for at most &lt;code&gt;timeout&lt;/code&gt;: &lt;code&gt;Some&lt;/code&gt; of what the body returns where it returns in time, &lt;code&gt;None&lt;/code&gt; where the time
runs out first. Then the body is cancelled where it is, waiting or computing, with every thread its
scope started and everything below them, as a scope’s &lt;a href=&quot;#cancellation&quot;&gt;&lt;code&gt;cancel&lt;/code&gt;&lt;/a&gt; cancels them, and
&lt;code&gt;withTimeout&lt;/code&gt; answers once they have all ended. A body that has returned keeps its result, however
close to the time it did. A timeout of zero or less runs nothing and answers &lt;code&gt;None&lt;/code&gt;. Timeouts nest:
an inner one ends at its own time or when an outer one’s runs out, whichever is sooner, and a
&lt;code&gt;withTimeout&lt;/code&gt; on a thread a scope cancels stops with that thread, its body first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The body of a &lt;code&gt;withTimeout&lt;/code&gt; runs on a lightweight thread of its own&lt;/strong&gt;, so that it can be stopped
wherever it is, even when &lt;code&gt;withTimeout&lt;/code&gt; is called from &lt;code&gt;main&lt;/code&gt;, whose own thread no cancellation
reaches. The calling thread waits for it, so the body reads and assigns the caller’s variables, uses
the Sysl handles the caller owns and those it makes are the caller’s after it, as a closure the
caller ran itself would. What tells the threads apart still does: &lt;code&gt;isMainThread()&lt;/code&gt; answers &lt;code&gt;false&lt;/code&gt; in
the body, and a lock the caller holds is not the body’s, so a body that takes it waits for ever, and
one that waits on a condition of it traps.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;request-context&quot;&gt;Request context&lt;/h2&gt;
&lt;p&gt;A piece of work, a request a server handles above all, carries a deadline and values that every call
it makes may need: the time left for a query, the request’s id for a log line. They live in the
running thread’s &lt;strong&gt;request context&lt;/strong&gt;, in &lt;code&gt;avin.threads&lt;/code&gt;, which code reads where it is rather than
being handed it through every signature on the way. A scope sets it for the code it runs:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Context, Key, withDeadline, withValue}
import avin.time.{now, seconds}

val requestId = Key[string](&amp;quot;request id&amp;quot;)

handle(id: string, request: Request) -&amp;gt; Reply
  withValue(requestId, id, () -&amp;gt;
    withDeadline(now() + seconds(5), s -&amp;gt; respond(request)) match
      Ok(reply) -&amp;gt; reply
      Err(e) -&amp;gt; Reply.unavailable(e.message))

// Far below, with no parameter for either.
log(line: string) = println(s&amp;quot;[${Context.current().value(requestId).getOrElse(&amp;quot;-&amp;quot;)}] $line&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Context.current() -&amp;gt; Context&lt;/code&gt;&lt;/strong&gt; is the calling thread’s context: what the scopes around the
running code set, or one with no deadline and no values. A &lt;code&gt;Context&lt;/code&gt; is an immutable snapshot, and
sendable: the scopes the code opens after reading it change the thread’s context, not the snapshot.
It answers &lt;strong&gt;&lt;code&gt;deadline -&amp;gt; Option[Instant]&lt;/code&gt;&lt;/strong&gt;, the instant the work must be done by, and
&lt;strong&gt;&lt;code&gt;remaining() -&amp;gt; Option[Duration]&lt;/code&gt;&lt;/strong&gt;, the time left on the monotonic clock, never less than zero;
both &lt;code&gt;None&lt;/code&gt; where no scope set a deadline. &lt;code&gt;main&lt;/code&gt; and every thread begin with an empty context.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Key[T](name)&lt;/code&gt;&lt;/strong&gt; names a value of type &lt;code&gt;T&lt;/code&gt;. &lt;strong&gt;Keys are told apart by identity&lt;/strong&gt;, not by name, so
two keys of one name are two keys: a module makes each of its keys once, as a module-level value, and
what it sets is reached by that key alone. &lt;code&gt;key.name&lt;/code&gt; is for showing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;withValue[K: Sendable, T](key: Key[K], value: K, body: () -&amp;gt; T) -&amp;gt; T&lt;/code&gt;&lt;/strong&gt; runs &lt;code&gt;body&lt;/code&gt; on the
calling thread with &lt;code&gt;value&lt;/code&gt; under &lt;code&gt;key&lt;/code&gt;, and puts the context back however the body ends, by
returning or by a cancellation. Inside, &lt;strong&gt;&lt;code&gt;value[T](key: Key[T]) -&amp;gt; Option[T]&lt;/code&gt;&lt;/strong&gt; answers &lt;code&gt;Some(value)&lt;/code&gt;,
in the body, everything it calls and the threads it starts, until a scope inside sets the key again,
which shadows it for its own body. A value of another type is not set under a key, and a lookup
answers the key’s own type, so nothing is cast; the value is sendable, since other threads read it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;withDeadline[T](deadline: Instant, body: (Scope) -&amp;gt; T) -&amp;gt; Result[T, DeadlineExceeded]&lt;/code&gt;&lt;/strong&gt; is
&lt;a href=&quot;#timers-and-deadlines&quot;&gt;&lt;code&gt;withTimeout&lt;/code&gt;&lt;/a&gt; at an instant: &lt;code&gt;Ok&lt;/code&gt; of what the body returns before
&lt;code&gt;deadline&lt;/code&gt;, and &lt;code&gt;Err(DeadlineExceeded(deadline))&lt;/code&gt; where the deadline passes first. Then the body is
cancelled where it is, with every thread its scope started and everything below them, and
&lt;code&gt;withDeadline&lt;/code&gt; answers once they have all ended. A deadline already past runs nothing. The wall clock
is read once, as the scope opens; from then on the deadline runs on the monotonic clock, so setting
the wall clock moves nothing. &lt;strong&gt;&lt;code&gt;DeadlineExceeded(deadline: Instant)&lt;/code&gt;&lt;/strong&gt; is an
&lt;a href=&quot;/spec/errors/#the-error-trait&quot;&gt;&lt;code&gt;Error&lt;/code&gt;&lt;/a&gt; whose message is &lt;code&gt;deadline exceeded&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;withTimeout&lt;/code&gt; sets the deadline too&lt;/strong&gt;, &lt;code&gt;timeout&lt;/code&gt; from the call, so code below either reads the
time it has left the same way.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A nested deadline tightens and never loosens.&lt;/strong&gt; The context keeps the sooner of a scope’s deadline
and the one around it, so the code inside a later deadline still reads the earlier one, and the
outer scope’s cancellation ends the inner one with its body: no scope can buy its body more time than
the scope around it has.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blocking calls observe the deadline through cancellation.&lt;/strong&gt; Since a deadline that passes cancels
its body, every &lt;a href=&quot;#cancellation&quot;&gt;cancellation point&lt;/a&gt; below it ends at once: a socket’s &lt;code&gt;accept&lt;/code&gt;,
&lt;code&gt;connect&lt;/code&gt;, read or write, a &lt;a href=&quot;#pools&quot;&gt;pool&lt;/a&gt;‘s &lt;code&gt;use&lt;/code&gt; or &lt;code&gt;lease&lt;/code&gt; waiting for a resource, a channel’s
&lt;code&gt;receive&lt;/code&gt; or &lt;code&gt;send&lt;/code&gt;, a &lt;code&gt;select&lt;/code&gt;, a &lt;code&gt;sleep&lt;/code&gt;, a join, a future’s &lt;code&gt;await&lt;/code&gt;, and the safepoint poll of
code that computes without waiting. Nothing inside sees an error value: the body stops, its deferred
statements run, and the error is &lt;code&gt;withDeadline&lt;/code&gt;‘s answer. Code that must tidy up when it is stopped,
a database driver telling its server to drop a query, does it in a &lt;code&gt;defer&lt;/code&gt;, whose waits run to their
end.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What a new thread takes follows what can cancel it.&lt;/strong&gt; A thread a scope starts, through &lt;code&gt;s.spawn&lt;/code&gt;
or as the body of a &lt;code&gt;withTimeout&lt;/code&gt; or &lt;code&gt;withDeadline&lt;/code&gt;, takes the starter’s whole context, its deadline
with its values, since a cancellation of the scope reaches it. A plain &lt;code&gt;spawn&lt;/code&gt;, the code of a future
(&lt;code&gt;Future(…)&lt;/code&gt;, &lt;code&gt;executor.future&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;onComplete&lt;/code&gt;) and an executor’s &lt;code&gt;execute&lt;/code&gt; task take
the values with no deadline, since nothing cancels them when it passes; a future’s callback takes the
context of the code that attached it, not of the thread that completed the future. &lt;strong&gt;An actor’s turn
takes nothing&lt;/strong&gt;, neither from the code that told the actor nor from the worker it runs on: an actor
outlives any one request, and its turns are not a scope’s threads. A value that should cross a
&lt;code&gt;tell&lt;/code&gt; goes in the message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Siblings share nothing.&lt;/strong&gt; A value a thread sets is its own and its children’s: the thread that
started it, and the threads beside it, do not see it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;futures&quot;&gt;Futures&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;Future[T]&lt;/code&gt; is a value some thread is computing. &lt;code&gt;Future(body)&lt;/code&gt; runs &lt;code&gt;body&lt;/code&gt; on a shared pool of
worker threads and gives back the future of its result at once; the body is a by-name argument, so
it is written in place or as a trailing block. Its value is sendable, as a thread’s result is, and
the body, like the functions of &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt;, is &lt;code&gt;@sendable&lt;/code&gt;:
&lt;code&gt;apply[T: Sendable](@sendable body: -&amp;gt; T) -&amp;gt; Future[T]&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.Future

main() -&amp;gt; int
  val page = Future(fetch(url))
  val counted = Future
    val words = load(path).split(&amp;quot; &amp;quot;)
    words.length
  val both = for p in page, n in counted yield s&amp;quot;${p.charCount} characters, $n words&amp;quot;
  println(both.await())
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;await() -&amp;gt; T&lt;/code&gt;&lt;/strong&gt; waits for the value and gives it back, the same value at every call, safe for
the collector while it waits. &lt;strong&gt;&lt;code&gt;await(timeoutMillis: long) -&amp;gt; Option[T]&lt;/code&gt;&lt;/strong&gt; waits at most that many
milliseconds and gives &lt;code&gt;None&lt;/code&gt; where the time ran out first; a time that is not positive asks
without waiting; &lt;strong&gt;&lt;code&gt;await(timeout: Duration) -&amp;gt; Option[T]&lt;/code&gt;&lt;/strong&gt; is the same wait for a
&lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;Duration&lt;/code&gt;&lt;/a&gt;, a part of a millisecond waited for as a whole one. &lt;code&gt;isCompleted()&lt;/code&gt; asks
and &lt;code&gt;value()&lt;/code&gt; gives &lt;code&gt;Some&lt;/code&gt; of a value already there; neither waits. Every timed wait takes a count
of milliseconds as a &lt;code&gt;long&lt;/code&gt; or a &lt;code&gt;Duration&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The combinators never wait.&lt;/strong&gt; &lt;code&gt;map(f)&lt;/code&gt; and &lt;code&gt;flatMap(f)&lt;/code&gt; give the future of &lt;code&gt;f&lt;/code&gt; of the value,
&lt;code&gt;f&lt;/code&gt; running on a pool thread once the value is there, so a &lt;code&gt;for … yield&lt;/code&gt; over futures is a future
too; &lt;code&gt;zip(other)&lt;/code&gt; pairs two values, and &lt;code&gt;onComplete(f)&lt;/code&gt; runs &lt;code&gt;f&lt;/code&gt; with the value on a pool thread,
at once where it is already there. &lt;code&gt;Future.successful(x)&lt;/code&gt; is complete from the start.
&lt;code&gt;Future.all(fs)&lt;/code&gt; is the future of every value of an &lt;code&gt;Iterable&lt;/code&gt; of futures, as a &lt;code&gt;Vector&lt;/code&gt; in the
order given, and &lt;code&gt;Future.first(fs)&lt;/code&gt; of the value of whichever completes first; the first of no
futures traps. &lt;code&gt;Future.traverse(xs, f)&lt;/code&gt; is &lt;code&gt;Future.all&lt;/code&gt; of &lt;code&gt;f&lt;/code&gt; of each element: &lt;code&gt;f&lt;/code&gt; is called for
the elements in turn on the calling thread, so their futures start in that order, and the values
come back in it however the futures finish.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A future carries no failure.&lt;/strong&gt; A computation that can fail returns &lt;code&gt;Future[Result[T, E]]&lt;/code&gt;, and
such a future also has &lt;code&gt;mapOk(f)&lt;/code&gt; and &lt;code&gt;flatMapOk(f)&lt;/code&gt;, which go on from an &lt;code&gt;Ok&lt;/code&gt; and pass an &lt;code&gt;Err&lt;/code&gt;
through unchanged, &lt;code&gt;mapErr(f)&lt;/code&gt;, which turns one failure into another, and &lt;code&gt;orElse(other)&lt;/code&gt;, which
goes on to the future &lt;code&gt;other&lt;/code&gt; gives only where this one ended in &lt;code&gt;Err&lt;/code&gt;: &lt;code&gt;other&lt;/code&gt; is by-name, so it
is not even evaluated after an &lt;code&gt;Ok&lt;/code&gt;, and its value may widen to a supertype as &lt;code&gt;Result.orElse&lt;/code&gt;‘s
does. A trap inside a body stops the program, as it does in any thread.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;Promise[T]()&lt;/code&gt;&lt;/strong&gt;, of a sendable &lt;code&gt;T&lt;/code&gt;, is completed by another thread: its &lt;code&gt;future&lt;/code&gt; field is the future it completes,
&lt;code&gt;complete(x)&lt;/code&gt; completes it and traps where it is already complete, and &lt;code&gt;tryComplete(x) -&amp;gt; bool&lt;/code&gt;
completes it only where nothing has yet, answering whether it did, for threads that race to give
the value. Every thread waiting on the future wakes with the value.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The pool&lt;/strong&gt; is started on first use, one worker at a time as work arrives with no idle worker, up
to one for each processor the machine offers. Its workers are never joined, so the program ends when
&lt;code&gt;main&lt;/code&gt; returns, whatever futures are pending. &lt;strong&gt;A body may wait for another future.&lt;/strong&gt; A worker that
waits in &lt;code&gt;await&lt;/code&gt; for a value not yet there counts as not working, and where work is queued with no
worker free, the pool starts another in its place; that one stays afterwards and is idle while there
is nothing to do. So waits nested in bodies never leave the pool without a thread to run the future
they wait for, however deep they go, and the pool grows only by as many workers as wait at once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;blocking(body)&lt;/code&gt;&lt;/strong&gt; says a body waits on something other than a future: a channel, a lock, a
blocking binding, a sleep. On a worker of a pool, the pool counts it as waiting while &lt;code&gt;body&lt;/code&gt; runs,
exactly as it counts one in &lt;code&gt;await&lt;/code&gt;, so a full pool whose workers all wait on a channel still runs
the task that fills it. A &lt;code&gt;blocking&lt;/code&gt; inside another, or an &lt;code&gt;await&lt;/code&gt; inside one, is counted once; on a
thread of no pool, &lt;code&gt;body&lt;/code&gt; simply runs. &lt;strong&gt;&lt;code&gt;sleep(d: Duration)&lt;/code&gt;&lt;/strong&gt; pauses the calling thread for at
least &lt;code&gt;d&lt;/code&gt; (from &lt;a href=&quot;/spec/time/&quot;&gt;&lt;code&gt;avin.time&lt;/code&gt;&lt;/a&gt;), safe for the collector while it
sleeps; a duration of zero or less returns at once, and one longer than about thirty years sleeps
about thirty years. A thread that sleeps parks, freeing the operating system thread it ran on, and
&lt;code&gt;main&lt;/code&gt; blocks its own. A worker of a pool that sleeps keeps its place in the pool, and
&lt;code&gt;blocking(sleep(d))&lt;/code&gt; gives it up.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{blocking, Channel, Future}

main() -&amp;gt; int
  val jobs = Channel[int]()
  val workers = (0 ..&amp;lt; 64).map(i -&amp;gt; Future(blocking(jobs.receive().getOrElse(0)))).toVector
  Future
    for n in 1 .. 64 do jobs.send(n)
  println(Future.all(workers).await().sum)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;executors&quot;&gt;Executors&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;An &lt;code&gt;Executor&lt;/code&gt;&lt;/strong&gt; is a pool of threads of one’s own, chosen explicitly. &lt;code&gt;Executor.fixed(n)&lt;/code&gt; keeps at
most &lt;code&gt;n&lt;/code&gt; tasks working at once, &lt;code&gt;n&lt;/code&gt; at least one, and starts its workers as work comes, as the shared
pool does; a worker waiting in &lt;code&gt;await&lt;/code&gt; or &lt;code&gt;blocking&lt;/code&gt; leaves its place to another there too.
&lt;code&gt;ex.future(body)&lt;/code&gt; runs &lt;code&gt;body&lt;/code&gt; on it, and &lt;strong&gt;a future runs its &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt; on the
executor it was made on&lt;/strong&gt;, so a chain begun on an executor stays there. &lt;code&gt;Executor.shared()&lt;/code&gt; is the
pool &lt;code&gt;Future(body)&lt;/code&gt; uses, the same executor every time it is asked (&lt;code&gt;Executor.shared() === Executor.shared()&lt;/code&gt;); &lt;code&gt;Future.successful&lt;/code&gt;, &lt;code&gt;Future.all&lt;/code&gt;, &lt;code&gt;Future.first&lt;/code&gt;, &lt;code&gt;Future.traverse&lt;/code&gt; and a
promise’s future belong to it.&lt;/p&gt;
&lt;p&gt;An executor is sendable, so a body on one thread may give work to an executor another made.
&lt;code&gt;ex.shutdown()&lt;/code&gt; lets the workers end once the queued work is done, and &lt;code&gt;isShutdown()&lt;/code&gt; asks. A new
body given to an executor after its shutdown traps, but the functions of futures already made on it
still run there, on a worker started for them where none is left, so no future made before is
stranded. The shared executor is never shut down: &lt;code&gt;isShutdown()&lt;/code&gt; answers &lt;code&gt;false&lt;/code&gt;, and
&lt;code&gt;shutdown()&lt;/code&gt; on it traps.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;ex.execute(task)&lt;/code&gt;&lt;/strong&gt; runs a &lt;code&gt;@sendable&lt;/code&gt; task on the executor’s workers with no future of it, the
way to give a pool work that queues itself again and again, as an &lt;a href=&quot;/spec/actors/#scheduling&quot;&gt;actor’s&lt;/a&gt;
turns do. The task runs as an owner of its own and nothing is handed to it: a Sysl handle it reaches
that the giving code owns traps there, and one in transit is taken by its first use. Work given
after &lt;code&gt;shutdown&lt;/code&gt; still runs, as the functions of futures do.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.threads.{Executor, Future}

main() -&amp;gt; int
  val io = Executor.fixed(4)
  val sizes = (1 .. 100).map(n -&amp;gt; io.future(n * n)).toVector
  val total = Future.all(sizes).await().sum
  io.shutdown()
  println(total)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;the-memory-model&quot;&gt;The memory model&lt;/h2&gt;
&lt;p&gt;Starting a thread happens before its body; its end happens before &lt;code&gt;join&lt;/code&gt; returns; releasing a
&lt;code&gt;Mutex&lt;/code&gt; happens before the next thread takes it; a &lt;code&gt;send&lt;/code&gt; happens before the &lt;code&gt;receive&lt;/code&gt; that gets the
value; an &lt;code&gt;Atomic&lt;/code&gt; store happens before every load that reads it; and completing a future happens
before every &lt;code&gt;await&lt;/code&gt; that gives its value and before every combinator’s function runs with it.
In the rest of the kit: a wait group’s &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;done&lt;/code&gt; happen before every &lt;code&gt;wait&lt;/code&gt; they let return;
a semaphore’s &lt;code&gt;release&lt;/code&gt; happens before the acquire that takes the permit it gave back; the end of a
&lt;code&gt;RwLock&lt;/code&gt;‘s write happens before every read and write after it, and the end of a read before the
write after it; and every party’s arrival at a barrier happens before that round’s action, which
happens before every party’s &lt;code&gt;wait&lt;/code&gt; of the round returns. A program whose shared
mutable state is reached only under those edges sees sequentially consistent behaviour.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A data race on a plain field or &lt;code&gt;var&lt;/code&gt; is not undefined behaviour.&lt;/strong&gt; A racing read returns some
value that was written to that location, never a mixture of two writes and never a value nothing
wrote. The compiler gives each access to a heap field, an array element or a module-level variable
LLVM’s &lt;code&gt;unordered&lt;/code&gt; atomic ordering: it costs nothing on the machines Avin targets, and it is exactly
the promise that a word is never torn and a racing load is never undefined. A reference is one word,
and so is every built-in scalar.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;An integer wider than 64 bits and a union with a scalar member are the exceptions.&lt;/strong&gt; An &lt;code&gt;i128&lt;/code&gt; or
an &lt;code&gt;i257&lt;/code&gt; is several words, and so is a union such as &lt;code&gt;int | string&lt;/code&gt; (its tag, its bits and its
reference); a field or variable of one is read and written as untorn 64-bit words, so a racing read
of it may combine words of different writes. Each word is still one some write stored, a union read
so is still a value of one of its members (never a reference no write stored), and a program that
shares such a value under the edges above, or through an &lt;code&gt;Atomic&lt;/code&gt; or a &lt;code&gt;Mutex&lt;/code&gt;, never sees a mixture.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;An object is complete before any thread can see it.&lt;/strong&gt; A constructor ends with a release fence, so
a thread that reads a reference to an object, however it got it, sees the object’s header and every
field its constructor set. Without it, a racing reader could see a reference field still zero,
which no Avin type allows. The fence is no instruction at all on x86-64 and one &lt;code&gt;dmb ish&lt;/code&gt; barrier
on arm64, paid once per object made.&lt;/p&gt;
&lt;h2 id=&quot;collection&quot;&gt;Collection&lt;/h2&gt;
&lt;p&gt;A collection stops the world. The collecting thread raises a flag, waits until every other thread is
parked at a safepoint or is in a safe region (waiting, or blocked in a call), collects alone, and
lets them go. A lightweight thread that is not running is always safe, and its frames stay roots of
every collection however long it waits. Compiled code polls the flag on every back edge of its loops and once per level of
every recursion, one load and a branch that is not taken; allocation is itself a
safepoint. A program with one thread never stops anything.&lt;/p&gt;
&lt;h2 id=&quot;actors&quot;&gt;Actors&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;/spec/actors/&quot;&gt;Actors&lt;/a&gt; handle their messages in turns, each turn a lightweight thread of its own
(&lt;a href=&quot;/spec/actors/#scheduling&quot;&gt;scheduling&lt;/a&gt;), so a turn that waits parks as any thread does. An actor
handles one message at a time, so its own state needs no lock; its mailbox is a runtime queue on the shared
heap, and a message is a reference to a heap value. A message holds only values no other actor can
change, or hands over the ownership of what it carries, and the compiler checks every message type
for it (&lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;what may be sent&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&quot;diagnostics&quot;&gt;Diagnostics&lt;/h2&gt;
&lt;p&gt;The runtime says what a program’s threads are doing in two cases: when every one of them waits for
something nothing can end, and when the program is asked for a thread dump.&lt;/p&gt;
&lt;h3 id=&quot;deadlock&quot;&gt;Deadlock&lt;/h3&gt;
&lt;p&gt;A program whose threads all wait for each other stops, as a trap does, with a list of its threads
and what each waits on:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;avin: trap: deadlock: all threads are waiting
  main: waiting for a thread to end
  thread 1: waiting for a lock
  thread 2: waiting for a lock
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The program is deadlocked when &lt;code&gt;main&lt;/code&gt; waits without a limit (for a lock, a condition, a join, a
channel, a future, a &lt;a href=&quot;#select&quot;&gt;&lt;code&gt;select&lt;/code&gt;&lt;/a&gt; with no &lt;code&gt;after&lt;/code&gt;, or anything built on them) and at that
moment&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;no lightweight thread is running or ready, so every one waits too, and&lt;/li&gt;
&lt;li&gt;nothing outside the threads can end a wait: no timer is set (a sleep, a wait with a limit, an
&lt;code&gt;ask&lt;/code&gt;‘s limit, an actor’s timer, a signal watch’s &lt;code&gt;wait&lt;/code&gt;), no thread waits on a socket, no thread
the program did not start is attached, and no callback that such a thread may call
(&lt;a href=&quot;/spec/sysl-bindings/#callbacks&quot;&gt;&lt;code&gt;@threaded&lt;/code&gt;&lt;/a&gt;) is held.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A thread in a blocking call (a &lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;&lt;code&gt;blocking&lt;/code&gt;&lt;/a&gt; binding, reading
input, waiting for a command to end) is running, so a program with one is never deadlocked, and
neither is a &lt;code&gt;main&lt;/code&gt; that runs its own work, a window’s frame loop among it. An &lt;code&gt;ask&lt;/code&gt; that nobody
answers is not a deadlock either: its limit ends it with &lt;code&gt;TimedOut&lt;/code&gt;. An actor waiting for mail
nobody can send has no thread at all, so &lt;code&gt;main&lt;/code&gt; awaiting its end is deadlocked once everything else
waits.&lt;/p&gt;
&lt;p&gt;The report lists &lt;code&gt;main&lt;/code&gt; first, then each lightweight thread still there in the order the threads
started, numbered from 1 by that order; a thread that has ended is not listed. A pool’s idle workers,
which wait for work by design and are as many as the machine has processors, are left out. What a
thread waits on is one of: a lock (a mutex’s), a condition, a thread to end (a join), receiving from
a channel, sending to a full channel, a future, or a select, &lt;code&gt;waiting in a select on 2 channels&lt;/code&gt;,
which counts its arms that name a channel. A select with an &lt;code&gt;after&lt;/code&gt; is a wait with a limit, whose
timer can always end it, so it is never part of a deadlock. The report goes to standard error after what the
program had printed is flushed, the exit hooks run after it, and the program ends as a trap ends it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Only a deadlock of the whole program is found.&lt;/strong&gt; Threads that wait for each other while another
thread still runs, or while &lt;code&gt;main&lt;/code&gt; computes or sleeps, are not reported: the program goes on, and
ends when &lt;code&gt;main&lt;/code&gt; returns.&lt;/p&gt;
&lt;h3 id=&quot;thread-dump&quot;&gt;Thread dump&lt;/h3&gt;
&lt;p&gt;The quit signal (Ctrl-\ at a terminal, &lt;code&gt;kill -QUIT&lt;/code&gt;) writes every thread’s state to standard error,
and the program goes on as it was:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;avin: thread dump
  main: running
  thread 1: waiting to receive from a channel, 250 ms
  thread 2: sleeping, 1200 ms
  thread 3: waiting on a condition with a time limit, 3 ms
  thread 4: running
  thread 5: idle, waiting for work, 40 ms
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each thread is &lt;code&gt;running&lt;/code&gt; (&lt;code&gt;running, in a blocking call&lt;/code&gt; while it is in one), &lt;code&gt;ready&lt;/code&gt; for a worker,
&lt;code&gt;ending&lt;/code&gt;, or waiting, with what it waits on as in the deadlock report, &lt;code&gt;sleeping&lt;/code&gt;, &lt;code&gt;waiting on a socket&lt;/code&gt;, or, for a pool’s worker with no work, &lt;code&gt;idle, waiting for work&lt;/code&gt;; a wait with a limit says so,
and every wait says how long it has lasted, in milliseconds. Idle workers are listed here. A dump
names no functions: a thread’s frames do not record which function they belong to.&lt;/p&gt;
&lt;p&gt;A program that &lt;a href=&quot;/spec/system-library/#avinsignal&quot;&gt;watches&lt;/a&gt; the quit signal hears of it instead, and no
dump is written while the watch lasts. A program started with the signal ignored keeps it ignored.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>System library</title>
    <link href="https://avinlang.dev/spec/system-library/"/>
    <id>https://avinlang.dev/spec/system-library/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>The standard library&apos;s modules for the world outside the program — its process, files and the rest — written in Avin over Sysl bindings.</summary>
    <content type="html">&lt;p&gt;The system library is the part of the standard library that talks to the operating system. Each
module is an ordinary Avin module under &lt;code&gt;avin&lt;/code&gt;, imported like any other, and written in Avin: what
it needs from the platform it reaches through &lt;a href=&quot;/spec/sysl-bindings/&quot;&gt;Sysl bindings&lt;/a&gt;, or, for what
only the runtime holds, through the runtime’s intrinsics. Failures a correct program can meet are
values; misuse is a trap.&lt;/p&gt;
&lt;h2 id=&quot;avin-process&quot;&gt;&lt;code&gt;avin.process&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The running program’s process: the arguments it was started with, its environment, and ending it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.process

main()
  val files = process.args()
  if files.isEmpty
    println(s&amp;quot;usage: ${process.programName()} FILE...&amp;quot;)
    process.exit(2)
  val home = process.env(&amp;quot;HOME&amp;quot;).getOrElse(&amp;quot;/&amp;quot;)
  for f in files do println(s&amp;quot;$home: $f&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;args() -&amp;gt; Vector[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The arguments after the program’s name, in order. Empty arguments are kept.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;programName() -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The name the program was started by, as the platform gave it: usually the path it was run as. Empty when the program was started with no arguments at all.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;env(name: string) -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The environment variable’s value, &lt;code&gt;None&lt;/code&gt; when it is not set; a variable set to nothing is &lt;code&gt;Some(&amp;quot;&amp;quot;)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exit(code: int) -&amp;gt; Nothing&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Ends the program now with &lt;code&gt;code&lt;/code&gt; as its exit status, after flushing what it has written and running its &lt;a href=&quot;#exit-hooks&quot;&gt;exit hooks&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;onExit(@sendable body: () -&amp;gt; unit) -&amp;gt; ExitHook&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Registers &lt;code&gt;body&lt;/code&gt; to run as the program ends; see &lt;a href=&quot;#exit-hooks&quot;&gt;exit hooks&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hook.cancel() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Takes the hook out so it does not run, answering whether it was still registered.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;main&lt;/code&gt; may take the arguments itself.&lt;/strong&gt; &lt;code&gt;main(args: Vector[string])&lt;/code&gt; receives the vector &lt;code&gt;args()&lt;/code&gt;
answers, and &lt;code&gt;main()&lt;/code&gt; is the form for a program that does not read them. The parameter is exactly
&lt;code&gt;Vector[string]&lt;/code&gt; with no default; any other parameter list is an error. &lt;code&gt;args()&lt;/code&gt; and &lt;code&gt;programName()&lt;/code&gt;
remain available everywhere.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;main(args: Vector[string]) -&amp;gt; int
  for f in args do println(f)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The program’s name is not an argument.&lt;/strong&gt; &lt;code&gt;args()&lt;/code&gt; holds only what the user typed after it, so
&lt;code&gt;args()(0)&lt;/code&gt; is the first real argument, and the name is asked for by &lt;code&gt;programName()&lt;/code&gt; when a
program wants it, for a usage line.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Arguments are strings.&lt;/strong&gt; Every argument is checked as UTF-8 when the program starts, before
&lt;code&gt;main&lt;/code&gt;; a program given one that is not UTF-8 stops there.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;exit&lt;/code&gt; never returns.&lt;/strong&gt; Its type is &lt;code&gt;Nothing&lt;/code&gt;, so it stands in any branch, as a trap does. What the
program has written to standard output is flushed first, so output that goes to a pipe or a file is
not lost, and then its &lt;a href=&quot;#exit-hooks&quot;&gt;exit hooks&lt;/a&gt; run. The status the parent sees is the platform’s: on POSIX systems, the code’s low eight bits.
Returning an &lt;code&gt;int&lt;/code&gt; from &lt;code&gt;main&lt;/code&gt; sets the status the same way without stopping early.&lt;/p&gt;
&lt;h3 id=&quot;exit-hooks&quot;&gt;Exit hooks&lt;/h3&gt;
&lt;p&gt;A program that changes something outside itself, a terminal put into raw mode on the alternate
screen, a lock file, puts it back in an exit hook, which runs however the program ends:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.process

main(args: Vector[string]) -&amp;gt; int
  print(&amp;quot;\u001b[?1049h&amp;quot;)
  process.onExit(() -&amp;gt; print(&amp;quot;\u001b[?1049l&amp;quot;))
  draw(args)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;They run when the program ends, once each, newest first.&lt;/strong&gt; The thread that ends the program runs
them, after it has flushed what the program wrote: the main thread when &lt;code&gt;main&lt;/code&gt; returns, the thread
that calls &lt;code&gt;exit&lt;/code&gt;, wherever it is, and the thread that traps, after the trap’s report, so a hook
writing to standard error writes after it. A trap is any of them: a failed check, &lt;code&gt;fail&lt;/code&gt;, an
actor’s failure escalated past every actor (reported naming the actor), running out of memory. A
trap an actor’s failure contains does not end the program and runs none. A test’s process runs
them as a program does. The program then ends as it was ending: with &lt;code&gt;main&lt;/code&gt;‘s status, with
&lt;code&gt;exit&lt;/code&gt;‘s, or as a trap.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What does not run them.&lt;/strong&gt; Running out of stack stops the program from a handler on a stack of its
own, where no Avin code can run, so no hook runs. A signal the program does not
&lt;a href=&quot;#avinsignal&quot;&gt;watch&lt;/a&gt; ends it as the signal always has, with none run; a program that wants its hooks
to run on &lt;code&gt;Terminate&lt;/code&gt; or &lt;code&gt;Interrupt&lt;/code&gt; watches the signal and calls &lt;code&gt;exit&lt;/code&gt;. A program killed (&lt;code&gt;Kill&lt;/code&gt;)
runs nothing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A hook may run on another thread than the one that registered it&lt;/strong&gt;, while the program’s other
threads go on running, so its body is &lt;code&gt;@sendable&lt;/code&gt;: it captures only sendable values, as a thread’s
body does. Hooks may be registered and cancelled from any thread, an actor or a future. A hook may
start threads and wait for them; it should not wait for one of the program’s own threads, which
may be blocked or have stopped. A thread that traps or calls &lt;code&gt;exit&lt;/code&gt; while the hooks run waits for
the end, and its trap is not reported: the first ending is the program’s.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;cancel()&lt;/code&gt;&lt;/strong&gt; answers &lt;code&gt;true&lt;/code&gt; once, for a hook still registered, which then does not run, and
&lt;code&gt;false&lt;/code&gt; after it has run, has begun to, or was cancelled. A hook registered while the hooks run is
run too, at once after the one that registered it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A hook that traps or calls &lt;code&gt;exit&lt;/code&gt; never goes on.&lt;/strong&gt; A trap is reported as &lt;code&gt;avin: trap in an exit hook: …&lt;/code&gt;, the hooks after it still run, and the program then ends as a trap ends it, even where
&lt;code&gt;main&lt;/code&gt; returned. An &lt;code&gt;exit&lt;/code&gt; inside a hook ends only that hook: the program keeps the status of the
ending that ran the hooks. A hook that traps while holding a mutex leaves what the mutex guards in
doubt, so the program stops at once, running no more hooks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tests see no arguments.&lt;/strong&gt; &lt;code&gt;avin test&lt;/code&gt; runs each test in a process of its own and chooses the test
by an argument of its own, which the test does not see: in a test, &lt;code&gt;args()&lt;/code&gt; is empty.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;avin run &amp;lt;program&amp;gt; -- ARGS&lt;/code&gt; passes everything after &lt;code&gt;--&lt;/code&gt; to the program unchanged, flags and a
second &lt;code&gt;--&lt;/code&gt; included. Everything before the &lt;code&gt;--&lt;/code&gt; is avin’s, and its options may come before or
after the program: &lt;code&gt;avin run -O2 main.avin&lt;/code&gt;, &lt;code&gt;avin run main.avin -O2&lt;/code&gt; and &lt;code&gt;avin -O2 main.avin&lt;/code&gt; are
one command.&lt;/p&gt;
&lt;h3 id=&quot;the-environment-and-the-platform&quot;&gt;The environment and the platform&lt;/h3&gt;
&lt;p&gt;What a program asks about where it runs is a function of &lt;code&gt;avin.process&lt;/code&gt;, beside &lt;code&gt;env&lt;/code&gt;;
there is no module for the environment alone and no store of properties. Each fact the platform
knows is asked for by name, and a program’s own settings are its own values.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;environment() -&amp;gt; Map[string, string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every environment variable and its value, read when called. A variable set to nothing is there with &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;currentDir() -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The directory relative paths are read from.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;homeDir() -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The user’s home directory, &lt;code&gt;None&lt;/code&gt; where the platform names none.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;executable() -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The absolute path of the running program’s file, where the platform can tell.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;processors() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;How many processors the program may run on: the number the futures’ pool grows to.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pid() -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The process’s identifier.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;userId() -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The user id the program acts as: the one the file system checks a permission against and the &lt;code&gt;owner&lt;/code&gt; of a file it creates; &lt;code&gt;0&lt;/code&gt; is the superuser.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupId() -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The group id the program acts as, which a file’s &lt;code&gt;group&lt;/code&gt; is compared with.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;userName(id: long) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The name the system’s user database gives user &lt;code&gt;id&lt;/code&gt;: &lt;code&gt;userName(0)&lt;/code&gt; is &lt;code&gt;Ok(&amp;quot;root&amp;quot;)&lt;/code&gt;. An id with no entry, and one outside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;0xffffffff&lt;/code&gt;, is &lt;code&gt;Err(NotFound)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;totalMemory() -&amp;gt; Result[long, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The physical memory the machine has, in bytes: what is installed, not what is free.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;residentBytes(pid: long) -&amp;gt; Result[long, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The memory the process &lt;code&gt;pid&lt;/code&gt; holds in RAM now, in bytes; &lt;code&gt;residentBytes(pid())&lt;/code&gt; is the program’s own. A process that is not there, a reaped child among them, and a &lt;code&gt;pid&lt;/code&gt; of zero or less are &lt;code&gt;Err(NotFound)&lt;/code&gt;; one the program may not look at is &lt;code&gt;Err(PermissionDenied)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupMembers(pgid: long) -&amp;gt; Result[Vector[long], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The live processes whose process group is &lt;code&gt;pgid&lt;/code&gt;, in no particular order: the leader, the programs it started and their children that stayed in the group. Ended programs not yet waited for are listed, waited-for ones are not. A group nobody is in is &lt;code&gt;Ok([])&lt;/code&gt;; a &lt;code&gt;pgid&lt;/code&gt; of zero or less, or past the largest process id, is &lt;code&gt;Err(Other)&lt;/code&gt;. A snapshot.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;children(pid: long) -&amp;gt; Result[Vector[long], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The live processes whose parent is &lt;code&gt;pid&lt;/code&gt;, in no particular order, direct children only: &lt;code&gt;children(pid())&lt;/code&gt; is what this program started and has not waited for. No children, or no such process, is &lt;code&gt;Ok([])&lt;/code&gt;; a &lt;code&gt;pid&lt;/code&gt; of zero or less, or past the largest process id, is &lt;code&gt;Err(Other)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;signal(pid: long, sig: int) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends the signal to the process &lt;code&gt;pid&lt;/code&gt;; a negative &lt;code&gt;pid&lt;/code&gt; is the group &lt;code&gt;-pid&lt;/code&gt;, zero the program’s own group, and &lt;code&gt;sig&lt;/code&gt; zero sends nothing and answers whether one could be sent. No such process is &lt;code&gt;Err(Other(&amp;quot;No such process&amp;quot;))&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;newSession() -&amp;gt; Result[long, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes the program the leader of a new session and group with no controlling terminal, as a daemon does, answering its number; refused for a program that already leads a group.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exec(program: string, args: Vector[string]) -&amp;gt; Result[Nothing, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Replaces the program with &lt;code&gt;program&lt;/code&gt; run with &lt;code&gt;args&lt;/code&gt;, in the same process; see &lt;a href=&quot;#becoming-another-program&quot;&gt;becoming another program&lt;/a&gt;. Answers only if that failed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exec(program: string, args: Vector[string], environment: Map[string, string]) -&amp;gt; Result[Nothing, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same, with &lt;code&gt;environment&lt;/code&gt; as the whole of the new program’s environment.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;waitPid(pid: long) -&amp;gt; Result[ExitStatus, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Waits for this program’s child &lt;code&gt;pid&lt;/code&gt; to end and answers how it ended, reaping it; see &lt;a href=&quot;#becoming-another-program&quot;&gt;becoming another program&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tryWaitPid(pid: long) -&amp;gt; Result[Option[ExitStatus], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the child &lt;code&gt;pid&lt;/code&gt; has ended, without waiting: &lt;code&gt;None&lt;/code&gt; while it runs, its status (reaping it) once it has.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;waitPidCpu(pid: long) -&amp;gt; Result[(ExitStatus, CpuTime), IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;waitPid&lt;/code&gt;, answering with the status the &lt;a href=&quot;#cpu-time&quot;&gt;CPU time&lt;/a&gt; the child used, its reaped descendants’ included.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tryWaitPidCpu(pid: long) -&amp;gt; Result[Option[(ExitStatus, CpuTime)], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;tryWaitPid&lt;/code&gt;, answering with the status the child’s CPU time.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cpuTime() -&amp;gt; CpuTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The &lt;a href=&quot;#cpu-time&quot;&gt;CPU time&lt;/a&gt; the program has used so far, every thread’s together.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;childrenCpuTime() -&amp;gt; CpuTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The CPU time of the program’s children that have ended and been reaped, each with the children it reaped in turn.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;os() -&amp;gt; Os&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The operating system the program was compiled for: &lt;code&gt;MacOS&lt;/code&gt;, &lt;code&gt;Linux&lt;/code&gt;, &lt;code&gt;Windows&lt;/code&gt;, &lt;code&gt;Android&lt;/code&gt;, &lt;code&gt;Wasi&lt;/code&gt; or &lt;code&gt;Freestanding&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Listing a group replaces a &lt;code&gt;pgrep -g&lt;/code&gt; subprocess, for instance to signal or count everything a
command left running:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;match Command(&amp;quot;/bin/sh&amp;quot;, &amp;quot;-c&amp;quot;, &amp;quot;sleep 30 &amp;amp; wait&amp;quot;).inNewGroup.start()
  Ok(child) -&amp;gt;
    val members = process.groupMembers(child.pid())   // the shell and its `sleep`
    val direct = process.children(child.pid())        // just the `sleep`
  Err(e) -&amp;gt; eprint(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Nothing sets a variable.&lt;/strong&gt; The environment is the program’s to read; a program that runs another
gives it the variables it needs through its &lt;a href=&quot;#commands&quot;&gt;command&lt;/a&gt;, which changes nothing in its own.
Text ends lines with &lt;code&gt;\n&lt;/code&gt; on every platform, so there is no line separator to ask for.&lt;/p&gt;
&lt;h3 id=&quot;becoming-another-program&quot;&gt;Becoming another program&lt;/h3&gt;
&lt;p&gt;A long-running program that upgrades itself in place saves its state, becomes the newly installed
version of itself with &lt;code&gt;exec&lt;/code&gt;, keeping its process id, and the new image takes up the children the
old one started, waiting for them by pid:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.process

upgrade(state: string, jobs: Vector[long]) -&amp;gt; Result[unit, IoError]
  fs.writeText(state, saved())?
  process.exec(installed, [&amp;quot;--resume&amp;quot;, state] ++ jobs.map(j -&amp;gt; s&amp;quot;$j&amp;quot;))?
  Ok(())

resume(jobs: Vector[long])
  for pid in jobs do report(pid, process.waitPid(pid))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;exec&lt;/code&gt; comes back only when it failed.&lt;/strong&gt; On success the process goes on, the same id, the same
parent and the same working directory, running &lt;code&gt;program&lt;/code&gt; from its beginning; there is nothing left
to return to, so its &lt;code&gt;Ok&lt;/code&gt; side is &lt;code&gt;Nothing&lt;/code&gt;, and &lt;code&gt;?&lt;/code&gt; passes the failure on. A program that is not
there is &lt;code&gt;Err(NotFound)&lt;/code&gt;, one that may not be run (a directory among them) &lt;code&gt;Err(PermissionDenied)&lt;/code&gt;,
and the program then carries on exactly as it was: everything that can fail is checked before
anything is given up.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What goes and what stays.&lt;/strong&gt; What the program has written to standard output is flushed first.
Then nothing of it is left: its other threads vanish wherever they were, its
&lt;a href=&quot;#exit-hooks&quot;&gt;exit hooks&lt;/a&gt; do not run, and its &lt;a href=&quot;#avinsignal&quot;&gt;signal watches&lt;/a&gt; end, each signal doing
again what it does by default. Its standard streams stay; every other descriptor the library opens
closes across the &lt;code&gt;exec&lt;/code&gt;, as across a &lt;a href=&quot;#commands&quot;&gt;command’s&lt;/a&gt; start. Its children stay its children.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where the program is looked for.&lt;/strong&gt; A name with a &lt;code&gt;/&lt;/code&gt; is a path; a bare name is looked for on the
&lt;code&gt;PATH&lt;/code&gt;. &lt;code&gt;exec(program, args)&lt;/code&gt; gives the new program this program’s environment;
&lt;code&gt;exec(program, args, environment)&lt;/code&gt; gives it exactly &lt;code&gt;environment&lt;/code&gt;, nothing inherited, and looks for
a bare name on the &lt;code&gt;PATH&lt;/code&gt; that holds, or the system’s default search path where it holds none.
&lt;code&gt;process.environment().updated(&amp;quot;NAME&amp;quot;, &amp;quot;value&amp;quot;)&lt;/code&gt; adds to this program’s own.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;waitPid&lt;/code&gt; and &lt;code&gt;tryWaitPid&lt;/code&gt; wait for a child no &lt;code&gt;Child&lt;/code&gt; holds&lt;/strong&gt;: one &lt;a href=&quot;#commands&quot;&gt;detached&lt;/a&gt;, or one
an earlier image of the process started before it became this program. They answer the
&lt;code&gt;ExitStatus&lt;/code&gt; a &lt;code&gt;Child&lt;/code&gt;‘s &lt;code&gt;waitFor&lt;/code&gt; answers, &lt;code&gt;Signalled&lt;/code&gt; for a child a signal ended, and the child is
reaped by the answer. A pid that is not this program’s child, a child already waited for, the
program’s own pid, and a pid of zero or less or past the largest process id are each
&lt;code&gt;Err(NotFound)&lt;/code&gt;. A thread waiting in &lt;code&gt;waitPid&lt;/code&gt; leaves its worker to the program’s other threads, as
every &lt;a href=&quot;/spec/threads/#lightweight-threads&quot;&gt;blocking&lt;/a&gt; wait does. A child a &lt;code&gt;Child&lt;/code&gt; still holds is
its &lt;code&gt;Child&lt;/code&gt;‘s to wait for: one reaped by &lt;code&gt;waitPid&lt;/code&gt; first is no longer there for &lt;code&gt;waitFor&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;cpu-time&quot;&gt;CPU time&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;CpuTime(user: Duration, system: Duration)&lt;/code&gt; is how long a processor ran a process’s own code and
the kernel’s code on its behalf, each in whole microseconds as the kernel accounts for them; &lt;code&gt;total&lt;/code&gt;
is the two added, and &lt;code&gt;CpuTime&lt;/code&gt; is &lt;code&gt;Add&lt;/code&gt;, with &lt;code&gt;CpuTime.Zero&lt;/code&gt; its zero. The kernel keeps the count
per process, and &lt;strong&gt;a process’s count is handed to its parent when the parent reaps it&lt;/strong&gt;, folded into
the parent’s own children’s count. So the CPU of a whole tree reaches the program through the one
child it started, once every process in the tree was reaped by its own parent: a shell running a
loop of programs that each exit has their time as well as its own.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;match Command(&amp;quot;/bin/sh&amp;quot;, &amp;quot;-c&amp;quot;, &amp;quot;make -j4&amp;quot;).start()
  Ok(job) -&amp;gt;
    _ = job.waitFor()
    println(s&amp;quot;${job.cpuTime().total.toSecondsReal} s of CPU&amp;quot;)   // make, the compilers it ran, theirs
  Err(e) -&amp;gt; eprint(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Only what was reaped counts.&lt;/strong&gt; A program still running counts nothing, and so does one that has
ended and not been waited for, and a grandchild that outlives its parent, or that its parent never
waited for, never reaches it. &lt;code&gt;cpuTime()&lt;/code&gt; is the program’s own, every thread’s, and only grows;
&lt;code&gt;childrenCpuTime()&lt;/code&gt; is every reaped child’s added. &lt;code&gt;waitPidCpu&lt;/code&gt; and &lt;code&gt;tryWaitPidCpu&lt;/code&gt; answer one
child’s, as &lt;code&gt;waitPid&lt;/code&gt; and &lt;code&gt;tryWaitPid&lt;/code&gt; answer its status, with the same errors; a &lt;code&gt;Child&lt;/code&gt;‘s
&lt;code&gt;cpuTime()&lt;/code&gt; answers its command’s. A program that only slept used next to none: what starting it
took.&lt;/p&gt;
&lt;h3 id=&quot;commands&quot;&gt;Commands&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;Command&lt;/code&gt; is another program to run: a program and its arguments, the directory and
variables it runs with and where its streams go, made first and run when asked. Commands combine into
pipelines and sequences, and what combines is again a command.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.process.{Command, CommandError}

sources(dir: string) -&amp;gt; Result[Vector[string], CommandError]
  val listing = Command(&amp;quot;ls&amp;quot;, dir) | Command(&amp;quot;grep&amp;quot;, &amp;quot;\\.avin$&amp;quot;)
  Ok(listing.output()?.lines)

main() -&amp;gt; int
  &amp;quot;make test&amp;quot;.run() match
    Ok(status) if status.isSuccess -&amp;gt; 0
    _ -&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Making&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Command(program: string, args: string*)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One program and its arguments, each passed as it is: no shell reads them. A program without a &lt;code&gt;/&lt;/code&gt; is looked for on &lt;code&gt;PATH&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Command.parse(line: string)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The line split at runs of white space, the first word the program; no quoting and no shell. A line with no word traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.inDir(dir: string)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same command, run in &lt;code&gt;dir&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.withEnv(name: string, value: string)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same command, with the variable set for it; the rest of the program’s environment is passed on.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.clearEnv&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same command, started from an empty environment: none of the program’s variables is passed on and none set by an earlier &lt;code&gt;withEnv&lt;/code&gt; stays. A bare program name is then looked for on the &lt;code&gt;PATH&lt;/code&gt; the command was given, or on the system’s default search path where it has none, never the running program’s.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.withoutEnv(name: string)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same command without the variable: the program’s value is not passed on and an earlier &lt;code&gt;withEnv&lt;/code&gt; of it is dropped. A name that is not set is no error.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.withEnvironment(vars: Map[string, string])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same command with exactly these variables: &lt;code&gt;clearEnv&lt;/code&gt;, then a &lt;code&gt;withEnv&lt;/code&gt; for each.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Environment changes apply in the order called; on a pipeline or a sequence the command’s come first and each part’s own after them, so a part’s &lt;code&gt;clearEnv&lt;/code&gt; discards what the command set.
| &lt;code&gt;c.withTimeout(d: Duration)&lt;/code&gt; | The same command, stopped when it has run for &lt;code&gt;d&lt;/code&gt;; its status is then &lt;code&gt;TimedOut&lt;/code&gt;. |
| &lt;code&gt;c.toFile(file: string)&lt;/code&gt;, &lt;code&gt;c.appendTo(file: string)&lt;/code&gt; | The same command, its standard output written to the file, emptied first or added to. |
| &lt;code&gt;c.fromFile(file: string)&lt;/code&gt;, &lt;code&gt;c.withInput(text: string)&lt;/code&gt; | The same command, reading the file, or the text, as its standard input. |
| &lt;code&gt;c.errorsToFile(file: string)&lt;/code&gt;, &lt;code&gt;c.errorsAppendTo(file: string)&lt;/code&gt; | The same command, its standard error written to the file, emptied first or added to. |
| &lt;code&gt;c.errorsToOutput()&lt;/code&gt; | The same command, its standard error going where its standard output goes: into the same open file, so neither empties what the other wrote, and into what &lt;code&gt;output()&lt;/code&gt; and &lt;code&gt;lines()&lt;/code&gt; capture. |
| &lt;code&gt;c.inNewGroup&lt;/code&gt; | The same command, started in a process group of its own, which every program it starts joins (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). |
| &lt;code&gt;c.pipeInput()&lt;/code&gt;, &lt;code&gt;c.pipeOutput()&lt;/code&gt;, &lt;code&gt;c.pipeErrors()&lt;/code&gt; | The same command, its standard input, output or error a pipe the program writes or reads through the &lt;code&gt;Child&lt;/code&gt; that &lt;code&gt;start()&lt;/code&gt; answers (&lt;a href=&quot;#pipes-to-a-started-command&quot;&gt;pipes&lt;/a&gt;). With &lt;code&gt;errorsToOutput()&lt;/code&gt;, standard error goes into the output’s pipe. |
| &lt;code&gt;a andThen b&lt;/code&gt; | &lt;code&gt;a&lt;/code&gt;, then &lt;code&gt;b&lt;/code&gt; only where &lt;code&gt;a&lt;/code&gt; succeeded; the status is the last one run. |
| &lt;code&gt;a orElse b&lt;/code&gt; | &lt;code&gt;a&lt;/code&gt;, then &lt;code&gt;b&lt;/code&gt; only where &lt;code&gt;a&lt;/code&gt; did not succeed. |
| &lt;code&gt;a followedBy b&lt;/code&gt; | &lt;code&gt;a&lt;/code&gt;, then &lt;code&gt;b&lt;/code&gt; whatever &lt;code&gt;a&lt;/code&gt;‘s status. |&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;a | b&lt;/code&gt; is a pipeline&lt;/strong&gt;: &lt;code&gt;a&lt;/code&gt;‘s standard output is &lt;code&gt;b&lt;/code&gt;‘s standard input, the two running at once,
and its status is &lt;code&gt;b&lt;/code&gt;‘s.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A setting on a command made of parts is every part’s&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):
a part runs in the command’s directory and with its variables unless it sets its own, a time limit
bounds the whole and a part not started in time is not started, output redirected on a pipeline is
its last stage’s and input its first’s, and a sequence’s redirected file is opened once, its parts
writing, or reading, one after the other. A started program is handed its three standard streams and
nothing else: the files, sockets and pipes the program has open, and the runtime’s own, are closed in
it.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Running&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.run() -&amp;gt; Result[ExitStatus, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Runs the command with the program’s own streams, waits, and answers how it ended. A status other than success is a value, not a failure.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.output() -&amp;gt; Result[string, CommandError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Runs it with its standard output captured as text, each ill-formed UTF-8 run replaced with U+FFFD, and standard error the program’s own; any status but success is &lt;code&gt;Failed(status)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.lines() -&amp;gt; Result[Iterator[string], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Starts it and answers its standard output’s lines as they arrive, by the rule &lt;a href=&quot;#standard-input&quot;&gt;standard input&lt;/a&gt; reads lines by. Its status is not checked.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c.start() -&amp;gt; Result[Child, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Starts it and answers at once, with the &lt;code&gt;Child&lt;/code&gt; below.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;&lt;code&gt;Child&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;waitFor() -&amp;gt; Result[ExitStatus, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Waits for the command to end; the same answer every time.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isAlive() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether it is still running, without waiting.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;kill()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends signal 15 to every program still running and starts no part not yet started.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;close() -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;Child&lt;/code&gt; is an &lt;a href=&quot;#close&quot;&gt;&lt;code&gt;io.Close&lt;/code&gt;&lt;/a&gt;: stops the command as &lt;code&gt;kill&lt;/code&gt; does where it has not been seen to end, then waits for it, the wait’s &lt;code&gt;Err&lt;/code&gt; being the answer. One already waited for is only waited for again, which answers at once; a detached one is let be, and closing it does nothing.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pid() -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The process id of the program started last: the one program, a pipeline’s last stage, a sequence’s latest part; &lt;code&gt;0&lt;/code&gt; where none started, its time having run out first.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;group() -&amp;gt; Option[long]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The process group of a command started &lt;code&gt;inNewGroup&lt;/code&gt;: the number its first program leads it by.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;signal(sig: int) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends &lt;code&gt;sig&lt;/code&gt; to the program &lt;code&gt;pid()&lt;/code&gt; names. A command seen to have ended, by &lt;code&gt;waitFor&lt;/code&gt; or by &lt;code&gt;isAlive&lt;/code&gt; answering &lt;code&gt;false&lt;/code&gt;, is &lt;code&gt;Err(Other(&amp;quot;No such process&amp;quot;))&lt;/code&gt;, its id being the platform’s to give again.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;signalGroup(sig: int) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends &lt;code&gt;sig&lt;/code&gt; to every process in the command’s group, the programs those programs started that stayed in it among them, however the command ended; an empty group is &lt;code&gt;Err(Other(&amp;quot;No such process&amp;quot;))&lt;/code&gt;, also while its last member has ended but is not yet waited for, and a command not started &lt;code&gt;inNewGroup&lt;/code&gt; &lt;code&gt;Err(Other(&amp;quot;the command has no group of its own&amp;quot;))&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;detach() -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lets go of the command without stopping it, so it outlives its &lt;code&gt;Child&lt;/code&gt; and the program, and answers &lt;code&gt;pid()&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;residentBytes() -&amp;gt; Result[long, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The memory the program &lt;code&gt;pid()&lt;/code&gt; names holds in RAM now, as &lt;code&gt;process.residentBytes(pid())&lt;/code&gt; answers it; a command seen to have ended, or with no program started, is &lt;code&gt;Err(NotFound)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cpuTime() -&amp;gt; CpuTime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The &lt;a href=&quot;#cpu-time&quot;&gt;CPU time&lt;/a&gt; the command’s programs used, each with its reaped descendants’, a pipeline’s stages and a sequence’s parts added. After &lt;code&gt;waitFor&lt;/code&gt; it is the whole command’s; before, what the programs seen to have ended used. A detached program counts nothing.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stdin() -&amp;gt; ChildInput&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The pipe the command reads its standard input from, for a command started &lt;code&gt;pipeInput()&lt;/code&gt;; the same one every time. A command that asked for none traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stdout() -&amp;gt; ChildOutput&lt;/code&gt;, &lt;code&gt;stderr() -&amp;gt; ChildOutput&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The pipe the command writes its standard output, or its standard error, into, for a command started &lt;code&gt;pipeOutput()&lt;/code&gt; or &lt;code&gt;pipeErrors()&lt;/code&gt;. A command that asked for none traps.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A started &lt;code&gt;Child&lt;/code&gt; is &lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):
it belongs to one thread at a time, as a &lt;a href=&quot;#tcp&quot;&gt;connection&lt;/a&gt; does. Handed to a thread’s or a future’s
body it is the body’s, which may wait for it, stop it and start a sequence’s later part, and the code
that handed it over traps at any use of it while the body runs, though the command has ended; when the
body returns, the next code to use it takes it back:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `Child` belongs to another thread at main.avin:12:3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What a &lt;code&gt;Child&lt;/code&gt; knows of its processes any thread may ask&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):
&lt;code&gt;pid()&lt;/code&gt;, &lt;code&gt;group()&lt;/code&gt;, &lt;code&gt;signal&lt;/code&gt; and &lt;code&gt;signalGroup&lt;/code&gt; read what was recorded as each program started and
touch none of the command’s handles, so one thread may signal a child while another waits for it,
the waiter seeing the status the signal caused. &lt;code&gt;signal&lt;/code&gt; and &lt;code&gt;kill&lt;/code&gt; differ: &lt;code&gt;signal&lt;/code&gt; reaches one
program and stops nothing else, so a sequence goes on as its status says, and &lt;code&gt;kill&lt;/code&gt; reaches every
program and starts nothing more.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;One group for a whole command.&lt;/strong&gt; A command started &lt;code&gt;inNewGroup&lt;/code&gt; puts every program it starts in one
group, the first program leading it, the outermost command’s setting deciding for its parts. A
sequence’s later part started once every member of the group has ended, the group being gone, leads
a new one, which &lt;code&gt;group()&lt;/code&gt; then answers. A group outlives its leader while any member is left, so
&lt;code&gt;signalGroup&lt;/code&gt; after &lt;code&gt;waitFor&lt;/code&gt; still reaches what the command left running:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io.IoError
import avin.process.{Command, ExitStatus}
import avin.signal
import avin.threads

stopped() -&amp;gt; Result[ExitStatus, IoError]
  val job = Command(&amp;quot;sh&amp;quot;, &amp;quot;-c&amp;quot;, &amp;quot;worker &amp;amp; worker &amp;amp; wait&amp;quot;).inNewGroup.toFile(&amp;quot;job.log&amp;quot;).errorsToOutput().start()?
  val waiter = threads.spawn(() -&amp;gt; job.waitFor())
  job.signalGroup(signal.Terminate)?
  waiter.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A started command does not outlive its &lt;code&gt;Child&lt;/code&gt; unless it is detached.&lt;/strong&gt; A &lt;code&gt;Child&lt;/code&gt; collected while
its command runs stops it. &lt;code&gt;detach()&lt;/code&gt; lets go of every program of the command still running without
stopping it (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): neither collecting the &lt;code&gt;Child&lt;/code&gt; nor the program’s
end stops them, so a server a command line program starts and leaves running is started and
detached. It answers &lt;code&gt;pid()&lt;/code&gt;, which &lt;code&gt;process.signal&lt;/code&gt; can still reach, and so can the &lt;code&gt;Child&lt;/code&gt;‘s own
&lt;code&gt;pid()&lt;/code&gt;, &lt;code&gt;group()&lt;/code&gt;, &lt;code&gt;signal&lt;/code&gt; and &lt;code&gt;signalGroup&lt;/code&gt;, which read only what was recorded as the programs
started. A sequence’s later part not yet started is never started. A detached command is no longer
the &lt;code&gt;Child&lt;/code&gt;‘s to wait for: &lt;code&gt;waitFor&lt;/code&gt;, &lt;code&gt;isAlive&lt;/code&gt; and &lt;code&gt;kill&lt;/code&gt; trap, and a second &lt;code&gt;detach&lt;/code&gt; answers the
&lt;code&gt;pid()&lt;/code&gt; again.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: a detached `Child` is not waited for, asked after or stopped at main.avin:9:5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Nothing reaps a detached program.&lt;/strong&gt; A detached program that ends while the program that started it
still runs stays a zombie, holding its process id, until that program ends, when the system adopts
and reaps it; since the &lt;code&gt;Child&lt;/code&gt; no longer sees it end, &lt;code&gt;signal&lt;/code&gt; may then reach whatever was given its
id after, and &lt;code&gt;signal(0)&lt;/code&gt; answers &lt;code&gt;Ok&lt;/code&gt; of a zombie. Detaching a command already waited for lets go of
nothing. A program that leaves its terminal’s group as well starts the command &lt;code&gt;inNewGroup&lt;/code&gt;, or
detaches itself with &lt;code&gt;newSession()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The iterator &lt;code&gt;lines()&lt;/code&gt; answers is not sendable: the thread that reads a command’s output starts it.&lt;/p&gt;
&lt;h4 id=&quot;pipes-to-a-started-command&quot;&gt;Pipes to a started command&lt;/h4&gt;
&lt;p&gt;A command started with &lt;code&gt;pipeInput()&lt;/code&gt;, &lt;code&gt;pipeOutput()&lt;/code&gt; or &lt;code&gt;pipeErrors()&lt;/code&gt; talks to the program over
pipes while it runs, a request written and its reply read, as an editor talks to a language server
(&lt;a href=&quot;/spec/decisions/#settled&quot;&gt;settled&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.process.Command

main() -&amp;gt; int
  val doubler = Command(&amp;quot;/bin/sh&amp;quot;, &amp;quot;-c&amp;quot;, &amp;quot;while read n; do echo $((n * 2)); done&amp;quot;).pipeInput().pipeOutput().start().ok.get
  val requests = doubler.stdin()
  val replies = doubler.stdout()
  for n in [1, 20, 300]
    _ = requests.writeText(s&amp;quot;$n\n&amp;quot;)
    println(s&amp;quot;$n doubled is ${replies.readLine().ok.get.get}&amp;quot;)
  _ = requests.close()
  println(s&amp;quot;after its input ended: ${replies.readLine().ok.get}, ${doubler.waitFor().ok.get}&amp;quot;)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;1 doubled is 2
20 doubled is 40
300 doubled is 600
after its input ended: None, Exited(0)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;stdin()&lt;/code&gt; is a &lt;code&gt;ChildInput&lt;/code&gt;, which is an &lt;code&gt;avin.net.StreamWriter&lt;/code&gt;, and &lt;code&gt;stdout()&lt;/code&gt; and &lt;code&gt;stderr()&lt;/code&gt; are
&lt;code&gt;ChildOutput&lt;/code&gt;s, each an &lt;code&gt;avin.net.StreamReader&lt;/code&gt;: the two halves of a &lt;a href=&quot;#split-connections&quot;&gt;split connection&lt;/a&gt;
in all but name, so code that speaks a protocol over a connection speaks it over a child’s standard
streams unchanged, and anything that takes an &lt;code&gt;io.Reader&lt;/code&gt; or an &lt;code&gt;io.ByteWriter&lt;/code&gt; takes them.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;&lt;code&gt;ChildOutput&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;read(max: int)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Up to &lt;code&gt;max&lt;/code&gt; bytes of what has arrived, waiting only while nothing has; an empty array once the output has ended, as often as asked.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readLine()&lt;/code&gt;, &lt;code&gt;readAll()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A line, &lt;code&gt;None&lt;/code&gt; at the end, or everything until the end, as a connection reads them.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readAvailable(max: int)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Some&lt;/code&gt; of what &lt;code&gt;read(max)&lt;/code&gt; would answer without waiting, &lt;code&gt;None&lt;/code&gt; where nothing has arrived. Never waits.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readable()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether a read would answer now: a &lt;code&gt;select&lt;/code&gt; waits on it with an &lt;code&gt;out.readable()&lt;/code&gt; arm, a &lt;code&gt;Selector&lt;/code&gt; with &lt;code&gt;readable(out, key)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setTimeout(d)&lt;/code&gt;, &lt;code&gt;close()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A wait longer than &lt;code&gt;d&lt;/code&gt; answers &lt;code&gt;TimedOut&lt;/code&gt;; closing it tells a command that still writes that its reader has gone.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;&lt;code&gt;ChildInput&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;write(bytes)&lt;/code&gt;, &lt;code&gt;writeText(text)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes all of it, waiting for the command to read where the pipe is full.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeSome(bytes)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes what goes without waiting, after waiting for room for the first byte, and answers how many.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writable()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether a write would write something now; a &lt;code&gt;select&lt;/code&gt; waits on it with an &lt;code&gt;in.writable()&lt;/code&gt; arm.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setTimeout(d)&lt;/code&gt;, &lt;code&gt;close()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A wait longer than &lt;code&gt;d&lt;/code&gt; answers &lt;code&gt;TimedOut&lt;/code&gt;; closing it ends the command’s input, which it reads once it has read everything written before.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A wait parks.&lt;/strong&gt; Each end is non-blocking, and a read or write that has to wait waits as a
connection’s does: a lightweight thread parks on the runtime’s poller, leaving its worker to the
others, and any other thread waits on the descriptor alone, safe for the collector.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nothing ends the program.&lt;/strong&gt; A write to a command that has ended, or has closed its input, answers
&lt;code&gt;Err(IoError(ConnectionReset, &amp;quot;write to&amp;quot;, &amp;quot;the standard input of …&amp;quot;))&lt;/code&gt;, never SIGPIPE. A command that
ends, or is killed, with output unread leaves it in the pipe: &lt;code&gt;waitFor&lt;/code&gt; answers its status, and the
reads that follow answer what it wrote and then the end. Output ends when every program holding the
stream has ended or closed it, a program the command started and left running among them. A
command’s &lt;a href=&quot;#commands&quot;&gt;time limit&lt;/a&gt; bounds every wait on its pipes too: one that would wait past it
answers &lt;code&gt;TimedOut&lt;/code&gt;, and &lt;code&gt;waitFor&lt;/code&gt; then stops the command and answers &lt;code&gt;TimedOut&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A full pipe waits for its reader.&lt;/strong&gt; A pipe holds 64 KiB; a command writing more waits until the
program reads, and the program writing more than the command reads waits for it. A program that writes
a command’s input and reads its output, both larger than that, does the two at once: in two threads,
or in one through a &lt;code&gt;select&lt;/code&gt; on &lt;code&gt;in.writable()&lt;/code&gt; and &lt;code&gt;out.readable()&lt;/code&gt; with &lt;code&gt;writeSome&lt;/code&gt; and
&lt;code&gt;readAvailable&lt;/code&gt;. Waiting for a command with &lt;code&gt;waitFor&lt;/code&gt; reads nothing, so a command that writes more
than a pipe holds is read before it is waited for.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Each end belongs to the code it is handed to, not to the &lt;code&gt;Child&lt;/code&gt;.&lt;/strong&gt; An end is used by one thread at a
time and checked at every operation, as a connection is; handed to a thread, it is that thread’s until
the thread returns. Handing the &lt;code&gt;Child&lt;/code&gt; over hands over none of its pipes, so a thread may wait for the
command while the program writes and reads them. &lt;code&gt;close()&lt;/code&gt; on the &lt;code&gt;Child&lt;/code&gt; stops and waits for the
command and leaves the pipes to their own &lt;code&gt;close()&lt;/code&gt;; an end closes too when the collector frees it.
The pipes do not keep the command running: it is the &lt;code&gt;Child&lt;/code&gt;‘s, which stops it when collected.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Only the command &lt;code&gt;start()&lt;/code&gt; starts hands its pipes over.&lt;/strong&gt; &lt;code&gt;run()&lt;/code&gt;, &lt;code&gt;output()&lt;/code&gt; and &lt;code&gt;lines()&lt;/code&gt; of a
command asking for a pipe trap, and so does a part of a pipeline or a sequence asking for one: a
pipeline’s input pipe is its first stage’s, its output pipe its last stage’s, and its error pipe every
stage’s; a sequence’s parts write into its output pipe one after the other. The program’s ends of the
pipes are closed on exec, so no other command started meanwhile, from any thread, inherits one.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data ExitStatus
  Exited(code: int)
  Signalled(signal: int)
  TimedOut

data CommandError
  Io(error: IoError)
  Failed(status: ExitStatus, command: string)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;code&gt;CommandError&lt;/code&gt; is an &lt;a href=&quot;/spec/errors/#the-error-trait&quot;&gt;&lt;code&gt;Error&lt;/code&gt;&lt;/a&gt;, as &lt;code&gt;IoError&lt;/code&gt; is, and shows as its
&lt;code&gt;message&lt;/code&gt;: an &lt;code&gt;Io&lt;/code&gt; error’s own message, or the command’s programs, as &lt;code&gt;ls&lt;/code&gt;, &lt;code&gt;ls | wc&lt;/code&gt; or
&lt;code&gt;make &amp;amp;&amp;amp; ./app&lt;/code&gt;, and how it ended: &lt;code&gt;false exited with status 1&lt;/code&gt;, &lt;code&gt;sleep killed by signal 15 (Terminate)&lt;/code&gt; (the name of a signal of &lt;code&gt;avin.signal&lt;/code&gt;, &lt;code&gt;unknown&lt;/code&gt; for any other number) or &lt;code&gt;sleep timed out&lt;/code&gt;. &lt;code&gt;Failed&lt;/code&gt;‘s &lt;code&gt;command&lt;/code&gt; is the programs alone; one built with an empty &lt;code&gt;command&lt;/code&gt; leaves it out.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;isSuccess&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; of &lt;code&gt;Exited(0)&lt;/code&gt; alone. A program that is not there fails to start: &lt;code&gt;run&lt;/code&gt;
answers an &lt;code&gt;IoError&lt;/code&gt; of kind &lt;code&gt;NotFound&lt;/code&gt;, &lt;code&gt;cannot run nosuch: no such file or directory&lt;/code&gt;, and &lt;code&gt;output&lt;/code&gt;
the same error in &lt;code&gt;Io&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A string runs as a command.&lt;/strong&gt; Importing &lt;code&gt;avin.process&lt;/code&gt; adds &lt;code&gt;run()&lt;/code&gt; and &lt;code&gt;output()&lt;/code&gt; to &lt;code&gt;string&lt;/code&gt;, as
an &lt;a href=&quot;/spec/declarations/#extensions&quot;&gt;extension&lt;/a&gt;: &lt;code&gt;&amp;quot;ls -l&amp;quot;.run()&lt;/code&gt; is &lt;code&gt;Command.parse(&amp;quot;ls -l&amp;quot;).run()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Combining is spelled with words where an operator cannot be.&lt;/strong&gt; &lt;code&gt;|&lt;/code&gt; is free on any type but the
integers and bytes, so a pipeline is &lt;code&gt;a | b&lt;/code&gt;. Running is a method rather than a postfix &lt;code&gt;!&lt;/code&gt; or &lt;code&gt;!!&lt;/code&gt;,
because no method is called postfix and &lt;code&gt;!&lt;/code&gt; is the language’s own; &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; are the
language’s, so sequencing is &lt;code&gt;andThen&lt;/code&gt;, &lt;code&gt;orElse&lt;/code&gt; and &lt;code&gt;followedBy&lt;/code&gt;, and redirection &lt;code&gt;toFile&lt;/code&gt;,
&lt;code&gt;appendTo&lt;/code&gt; and &lt;code&gt;fromFile&lt;/code&gt;, words that say what each does where &lt;code&gt;#&amp;amp;&amp;amp;&lt;/code&gt; or &lt;code&gt;#&amp;gt;&lt;/code&gt; would not.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Waiting is safe for the collector.&lt;/strong&gt; A thread waiting in &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;output&lt;/code&gt; or &lt;code&gt;waitFor&lt;/code&gt; holds
nothing the collector waits on, as &lt;code&gt;await&lt;/code&gt; does not.&lt;/p&gt;
&lt;h2 id=&quot;avin-cli&quot;&gt;&lt;code&gt;avin.cli&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A program’s command line, read against what the program takes. A &lt;code&gt;Parser&lt;/code&gt; declares the flags, the
options with a value and the positional arguments, each with a line of help; &lt;code&gt;parse&lt;/code&gt; reads &lt;code&gt;main&lt;/code&gt;‘s
&lt;code&gt;args&lt;/code&gt; into &lt;code&gt;Args&lt;/code&gt;, whose values are asked for by name and come back as the types they were
declared with. The help and the usage line are written from the same declarations.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.cli

val parser = cli.Parser(&amp;quot;wc&amp;quot;, &amp;quot;Count lines, words and characters.&amp;quot;, version = &amp;quot;1.0&amp;quot;)
  .flag(&amp;quot;lines&amp;quot;, short = &apos;l&apos;, help = &amp;quot;count lines&amp;quot;)
  .flag(&amp;quot;words&amp;quot;, short = &apos;w&apos;, help = &amp;quot;count words&amp;quot;)
  .int(&amp;quot;top&amp;quot;, help = &amp;quot;list the N commonest words&amp;quot;, value = &amp;quot;N&amp;quot;)
  .choice(&amp;quot;format&amp;quot;, [&amp;quot;text&amp;quot;, &amp;quot;json&amp;quot;], default = &amp;quot;text&amp;quot;)
  .positionals(&amp;quot;file&amp;quot;, help = &amp;quot;the files to count&amp;quot;, required = true)

main(args: Vector[string]) -&amp;gt; int
  val opts = parser.parseOrExit(args)
  for f in opts.strings(&amp;quot;file&amp;quot;)
    if opts.flag(&amp;quot;lines&amp;quot;) then println(s&amp;quot;$f: lines&amp;quot;)
  println(s&amp;quot;top ${opts.int(&amp;quot;top&amp;quot;)} as ${opts.string(&amp;quot;format&amp;quot;)}&amp;quot;)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;wc -lw --top=3 a.txt b.txt&lt;/code&gt; gives both flags, 3 and the two files; &lt;code&gt;wc --help&lt;/code&gt; writes&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Usage: wc [options] &amp;lt;file&amp;gt;...

Count lines, words and characters.

Arguments:
  &amp;lt;file&amp;gt;...                 the files to count

Options:
  -l, --lines               count lines
  -w, --words               count words
      --top &amp;lt;N&amp;gt;             list the N commonest words
      --format &amp;lt;text|json&amp;gt;  (default: text)
  -h, --help                show this help and exit
      --version             show the version and exit
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and &lt;code&gt;wc --top many a.txt&lt;/code&gt; writes to standard error, and exits with 2:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;wc: `--top` needs an int, not `many`
Usage: wc [options] &amp;lt;file&amp;gt;...
Run `wc --help` for the options.
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Declaration on &lt;code&gt;Parser&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Declares&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Parser(name, about = &amp;quot;&amp;quot;, version = &amp;quot;&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A parser of no options and no arguments. &lt;code&gt;name&lt;/code&gt; is the program’s name in the usage line and the messages, &lt;code&gt;about&lt;/code&gt; a sentence for the help; a &lt;code&gt;version&lt;/code&gt; that is not empty gives the program &lt;code&gt;--version&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flag(name, short, help)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;--name&lt;/code&gt;, given or not, any number of times.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;string(name, short, help, default = &amp;quot;&amp;quot;, required = false, repeated = false, value = &amp;quot;&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;--name&lt;/code&gt; with a text value. &lt;code&gt;value&lt;/code&gt; names the value in the help (&lt;code&gt;--out &amp;lt;file&amp;gt;&lt;/code&gt;), the option’s name when empty.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;int(…, default = 0, …)&lt;/code&gt;, &lt;code&gt;real(…, default = 0.0, …)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;--name&lt;/code&gt; with an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;real&lt;/code&gt; value, refused at parse time when it is not one.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;choice(name, choices, short, help, default = &amp;quot;&amp;quot;, required = false, repeated = false)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;--name&lt;/code&gt; whose value is one of &lt;code&gt;choices&lt;/code&gt; exactly as written; the help shows them, &lt;code&gt;&amp;lt;text\|json&amp;gt;&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;positional(name, help = &amp;quot;&amp;quot;, required = true)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One positional argument, after those declared before it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;positionals(name, help = &amp;quot;&amp;quot;, required = false)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every argument left, none or more, or one or more where &lt;code&gt;required&lt;/code&gt;. It is the last declared.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;command(sub)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The command &lt;code&gt;sub.name&lt;/code&gt;, whose options and arguments the parser &lt;code&gt;sub&lt;/code&gt; declares, listed in the help with &lt;code&gt;sub.about&lt;/code&gt;. A parser with commands takes no positional arguments.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Each declaration answers a new parser and leaves the one it was called on as it was, so a parser is
an ordinary value: built once at the top of a module, or in a function.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Reading&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parse(args) -&amp;gt; Result[Args, ArgsError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The arguments read, or why not.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseOrExit(args) -&amp;gt; Args&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;parse&lt;/code&gt;, and where it gives no &lt;code&gt;Args&lt;/code&gt; the program ends: the error’s &lt;code&gt;report&lt;/code&gt;, the help or the version to standard output and status 0, a mistake to standard error, as the name and the reason, the usage line and where the help is, and status 2.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;e.report -&amp;gt; string&lt;/code&gt;, &lt;code&gt;e.exitCode -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;For an &lt;code&gt;ArgsError&lt;/code&gt;, the whole text &lt;code&gt;parseOrExit&lt;/code&gt; writes, each line ending in a newline, and the status it exits with.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;usage -&amp;gt; string&lt;/code&gt;, &lt;code&gt;help -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The usage line, and the whole help: usage, &lt;code&gt;about&lt;/code&gt;, the arguments, then the options in the order declared, each with its help, its default where it has one, and whether it is required or may be repeated.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;a.flag(name) -&amp;gt; bool&lt;/code&gt;, &lt;code&gt;a.count(name) -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the flag was given, and how many times: 3 for &lt;code&gt;-vvv&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;a.string(name)&lt;/code&gt;, &lt;code&gt;a.int(name)&lt;/code&gt;, &lt;code&gt;a.real(name)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The option’s last value, else its default; the text of a choice or of a positional argument (empty where an optional one was left off).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;a.strings(name)&lt;/code&gt;, &lt;code&gt;a.ints(name)&lt;/code&gt;, &lt;code&gt;a.reals(name)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every value of a repeated option in order, or its default alone where none was given and it has one; every argument a &lt;code&gt;positionals&lt;/code&gt; took.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;a.given(name) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the option or argument was on the command line, rather than taking its default.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;a.command -&amp;gt; string&lt;/code&gt;, &lt;code&gt;a.commandArgs -&amp;gt; Args&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The command given, empty where the parser has none, and the arguments after it as the command’s parser read them.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;The arguments are read as a command line is.&lt;/strong&gt; An argument starting with &lt;code&gt;-&lt;/code&gt; is an option, except
&lt;code&gt;-&lt;/code&gt; alone, which is positional, as is the empty argument. &lt;code&gt;--name=value&lt;/code&gt; and &lt;code&gt;--name value&lt;/code&gt; give a
value alike. A single &lt;code&gt;-&lt;/code&gt; starts one or more one-letter options, &lt;code&gt;-lw&lt;/code&gt;, the last of which may take
the rest of the argument or the next one as its value: &lt;code&gt;-n5&lt;/code&gt;, &lt;code&gt;-n 5&lt;/code&gt;, &lt;code&gt;-lwn5&lt;/code&gt;. An option’s value is
the next argument whatever it starts with, so &lt;code&gt;--top -1&lt;/code&gt; is −1 and &lt;code&gt;--out --verbose&lt;/code&gt; writes to a
file named &lt;code&gt;--verbose&lt;/code&gt;. Every argument after &lt;code&gt;--&lt;/code&gt; is positional. Options and positional arguments
may come in any order.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A value given twice replaces the first,&lt;/strong&gt; so a later &lt;code&gt;--out&lt;/code&gt; wins, unless the option is
&lt;code&gt;repeated&lt;/code&gt;, when each is kept. A flag may always be repeated, and &lt;code&gt;count&lt;/code&gt; says how often.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Every parser has &lt;code&gt;--help&lt;/code&gt; and &lt;code&gt;-h&lt;/code&gt;,&lt;/strong&gt; unless the program declares an option named &lt;code&gt;help&lt;/code&gt; or with
the letter &lt;code&gt;h&lt;/code&gt; itself, which then is the program’s own; &lt;code&gt;--version&lt;/code&gt; likewise, where the parser has
a version. Each is acted on where it stands: &lt;code&gt;--help&lt;/code&gt; after a mistake is never reached, and a
mistake after &lt;code&gt;--help&lt;/code&gt; is not looked at.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A mistake on the command line is an &lt;code&gt;ArgsError&lt;/code&gt;, never a trap.&lt;/strong&gt; &lt;code&gt;ArgsError&lt;/code&gt; is
&lt;code&gt;HelpRequested(text)&lt;/code&gt;, &lt;code&gt;VersionRequested(text)&lt;/code&gt; or &lt;code&gt;Invalid(reason, usage, program, hint)&lt;/code&gt;, and an
&lt;a href=&quot;/spec/errors/&quot;&gt;&lt;code&gt;Error&lt;/code&gt;&lt;/a&gt;, so a &lt;code&gt;main&lt;/code&gt; answering a &lt;code&gt;Result&lt;/code&gt; may pass it on with &lt;code&gt;?&lt;/code&gt; and the program
ends with &lt;code&gt;error: &lt;/code&gt; and the reason. &lt;code&gt;program&lt;/code&gt; is the name of the parser that found the mistake,
&lt;code&gt;todo add&lt;/code&gt; for a command’s, and &lt;code&gt;hint&lt;/code&gt; the line saying where its help is (empty where the program
declared both &lt;code&gt;--help&lt;/code&gt; and &lt;code&gt;help&lt;/code&gt; itself). A program that reads one command line after another, a
shell or a script runner, calls &lt;code&gt;parse&lt;/code&gt; rather than &lt;code&gt;parseOrExit&lt;/code&gt;, writes the error’s &lt;code&gt;report&lt;/code&gt; and
carries on:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for line in io.lines()
  parser.parse(words(line)) match
    Ok(opts) -&amp;gt; run(opts)
    Err(e) -&amp;gt; if e.exitCode == 0 then print(e.report) else eprint(e.report)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The reasons name what the user wrote, as they wrote it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Command line&lt;/th&gt;&lt;th&gt;Reason&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--x&lt;/code&gt;, &lt;code&gt;-x&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;unknown option `--x` &lt;/code&gt;, &lt;code&gt;unknown option `-x` &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--verbose=yes&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;`--verbose` takes no value&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--out&lt;/code&gt; at the end&lt;/td&gt;&lt;td&gt;&lt;code&gt;`--out` needs a value&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--count abc&lt;/code&gt;, &lt;code&gt;--count 2147483648&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;`--count` needs an int, not `abc`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--scale fast&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;`--scale` needs a number, not `fast`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--format xml&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;`--format` must be one of `text`, `json`, not `xml`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;a required option left off&lt;/td&gt;&lt;td&gt;&lt;code&gt;missing required option `--to` &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;a required argument left off&lt;/td&gt;&lt;td&gt;&lt;code&gt;missing argument `&amp;lt;file&amp;gt;` &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;one argument more than declared&lt;/td&gt;&lt;td&gt;&lt;code&gt;unexpected argument `extra` &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;no command, to a parser with commands&lt;/td&gt;&lt;td&gt;&lt;code&gt;missing command; the commands are `add`, `list`, `help` &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lst&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;unknown command `lst`; did you mean `list`? &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;frobnicate&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;unknown command `frobnicate`; the commands are `add`, `list`, `help` &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A mistake in the declarations, or in asking for a value, is the program’s, and traps.&lt;/strong&gt; Two
options of one name or one letter, a name written with its dashes, a choice with no choices or a
default not among them, an argument after the one taking the rest or a required one after an
optional one, two commands of one name, a command whose name is not one word or starts with &lt;code&gt;-&lt;/code&gt;,
and a parser given both commands and positional arguments trap where they are declared; asking
&lt;code&gt;Args&lt;/code&gt; for a name never declared, or as another type than it was declared with (&lt;code&gt;a.int(&amp;quot;out&amp;quot;)&lt;/code&gt;
for a string option), or for &lt;code&gt;commandArgs&lt;/code&gt; where the parser has no commands, traps where it is
asked.&lt;/p&gt;
&lt;h3 id=&quot;commands-1&quot;&gt;Commands&lt;/h3&gt;
&lt;p&gt;A program of several commands gives its parser one parser for each, declaring that command’s
own options and arguments. A command may have commands of its own, as &lt;code&gt;git remote add&lt;/code&gt; does.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val add = cli.Parser(&amp;quot;add&amp;quot;, &amp;quot;Add a task.&amp;quot;)
  .choice(&amp;quot;priority&amp;quot;, [&amp;quot;high&amp;quot;, &amp;quot;normal&amp;quot;, &amp;quot;low&amp;quot;], short = &apos;p&apos;, default = &amp;quot;normal&amp;quot;)
  .positionals(&amp;quot;words&amp;quot;, help = &amp;quot;the task&apos;s title&amp;quot;, required = true)

val parser = cli.Parser(&amp;quot;todo&amp;quot;, &amp;quot;Keep a to-do list.&amp;quot;)
  .string(&amp;quot;file&amp;quot;, short = &apos;f&apos;, help = &amp;quot;the list&amp;quot;, default = &amp;quot;todo.txt&amp;quot;)
  .command(add)
  .command(cli.Parser(&amp;quot;list&amp;quot;, &amp;quot;List the tasks.&amp;quot;).flag(&amp;quot;all&amp;quot;, short = &apos;a&apos;))

main(args: Vector[string]) -&amp;gt; int
  val opts = parser.parseOrExit(args)
  val file = opts.string(&amp;quot;file&amp;quot;)
  opts.command match
    &amp;quot;add&amp;quot; -&amp;gt; addTask(file, opts.commandArgs.string(&amp;quot;priority&amp;quot;), opts.commandArgs.strings(&amp;quot;words&amp;quot;))
    _ -&amp;gt; listTasks(file, opts.commandArgs.flag(&amp;quot;all&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The first positional argument names the command, and every argument after it is the
command’s.&lt;/strong&gt; The program’s own options come before the command word, &lt;code&gt;todo --file t.txt add -p high milk&lt;/code&gt;, and the command’s after it; an option of the program’s after the word is unknown to
the command (&lt;code&gt;todo list --file x&lt;/code&gt; is &lt;code&gt;unknown option `--file` &lt;/code&gt;), so a command may use a name
the program does too. An option’s value is never a command, so &lt;code&gt;todo --file list add&lt;/code&gt; writes to
the file &lt;code&gt;list&lt;/code&gt;. &lt;code&gt;--&lt;/code&gt; before the word ends only the program’s options; the command reads its own.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;While a command reads its arguments, its parser is named after the program and the command,&lt;/strong&gt;
so its usage line, its help and its mistakes say &lt;code&gt;todo add&lt;/code&gt;: &lt;code&gt;todo add --help&lt;/code&gt; writes&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Usage: todo add [options] &amp;lt;words&amp;gt;...

Add a task.

Arguments:
  &amp;lt;words&amp;gt;...                        the task&apos;s title

Options:
  -p, --priority &amp;lt;high|normal|low&amp;gt;  (default: normal)
  -h, --help                        show this help and exit
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and &lt;code&gt;todo --help&lt;/code&gt; lists the commands, with their &lt;code&gt;about&lt;/code&gt;, before the options:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Usage: todo [options] &amp;lt;command&amp;gt; ...

Keep a to-do list.

Commands:
  add                Add a task.
  list               List the tasks.
  help &amp;lt;command&amp;gt;     show the help of a command

Options:
  -f, --file &amp;lt;file&amp;gt;  the list (default: todo.txt)
  -h, --help         show this help and exit
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Every parser with commands has the command &lt;code&gt;help&lt;/code&gt;,&lt;/strong&gt; unless the program declares a command of
that name, which then is its own: &lt;code&gt;todo help&lt;/code&gt; is &lt;code&gt;todo --help&lt;/code&gt;, &lt;code&gt;todo help add&lt;/code&gt; is &lt;code&gt;todo add --help&lt;/code&gt;, and &lt;code&gt;todo help remote add&lt;/code&gt; names a command of a command. &lt;code&gt;--version&lt;/code&gt; is the program’s,
before the command word.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A command not given or not known is a mistake.&lt;/strong&gt; The reason for an unknown command names the
command it was most likely meant to be: the nearest within two edits (fewer than the word has
characters), or else the one command the word begins, &lt;code&gt;rem&lt;/code&gt; for &lt;code&gt;remote&lt;/code&gt;; otherwise it lists the
commands. &lt;code&gt;todo lst&lt;/code&gt; writes to standard error, and exits with 2:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;todo: unknown command `lst`; did you mean `list`?
Usage: todo [options] &amp;lt;command&amp;gt; ...
Run `todo --help` for the commands.
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;avin-signal&quot;&gt;&lt;code&gt;avin.signal&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Signals the program watches for: a number another process, or the platform, sends to ask it to
stop, to say its terminal has gone, or for a reason of their own. A watched signal no longer does
what it did, ending the program among them; the program asks, where it chooses, whether it has
arrived, and no code of its own runs when it does. Signals are sent with &lt;code&gt;process.signal&lt;/code&gt; and
&lt;code&gt;Child.signal&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io.IoError
import avin.signal

serve() -&amp;gt; Result[unit, IoError]
  val stop = signal.watch(signal.Terminate)?
  while !stop.take()
    serveOne()
  cleanUp()
  Ok(())
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Constant&lt;/th&gt;&lt;th&gt;Signal&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Hangup&lt;/code&gt;, &lt;code&gt;Interrupt&lt;/code&gt;, &lt;code&gt;Quit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;1, 2, 3: the terminal gone, Ctrl-C, Ctrl-.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Kill&lt;/code&gt;&lt;/td&gt;&lt;td&gt;9: ends a program at once; it cannot be watched.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;BrokenPipe&lt;/code&gt;, &lt;code&gt;Alarm&lt;/code&gt;&lt;/td&gt;&lt;td&gt;13, 14.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Terminate&lt;/code&gt;&lt;/td&gt;&lt;td&gt;15: asks a program to stop; what &lt;code&gt;Child.kill&lt;/code&gt; sends.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;WindowChange&lt;/code&gt;&lt;/td&gt;&lt;td&gt;28: the terminal was resized.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;User1&lt;/code&gt;, &lt;code&gt;User2&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The user-defined signals, numbered as the platform numbers them.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Stop&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Freezes a program until a &lt;code&gt;Continue&lt;/code&gt; arrives; numbered as the platform numbers it. It cannot be watched, as &lt;code&gt;Kill&lt;/code&gt; cannot (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Continue&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lets a stopped program run again; one that was not stopped is not disturbed. Numbered as the platform numbers it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TerminalStop&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Ctrl-Z at the terminal; a program that watches it is not stopped. Numbered as the platform numbers it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Child&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A program this one started has ended, stopped or continued. The platform ignores it unless it is watched; numbered as the platform numbers it.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Sending &lt;code&gt;Stop&lt;/code&gt; and then &lt;code&gt;Continue&lt;/code&gt; with &lt;code&gt;process.signal&lt;/code&gt; or &lt;code&gt;Child.signal&lt;/code&gt; pauses and resumes one
program; a negative &lt;code&gt;pid&lt;/code&gt;, or &lt;code&gt;signalGroup&lt;/code&gt; on a command started &lt;code&gt;inNewGroup&lt;/code&gt;, pauses a child and
every program it started in the group together. A status a signal ended names each of these, as
&lt;code&gt;killed by signal 19 (Stop)&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;watch(sig: int) -&amp;gt; Result[Watch, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Starts watching &lt;code&gt;sig&lt;/code&gt;. A number the platform does not have, &lt;code&gt;Kill&lt;/code&gt; and &lt;code&gt;Stop&lt;/code&gt; are &lt;code&gt;Err(Other(&amp;quot;Invalid argument&amp;quot;))&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;w.take() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether it arrived since the last &lt;code&gt;take&lt;/code&gt; or since the watch began, marking it seen. Arrivals between two takes are one &lt;code&gt;true&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;w.wait()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Parks until it arrives, then takes it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;w.wait(limit: Duration) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same, giving up after &lt;code&gt;limit&lt;/code&gt;, and answering whether it arrived.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;w.signal() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The signal watched.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Two watches of one signal each see every arrival&lt;/strong&gt;, so a library watching for its own reasons
takes nothing from the program. When every watch of a signal has been collected, the signal does
again what it did before the first. &lt;strong&gt;A wait looks every 20 milliseconds&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;),
its lightweight thread parked between looks, so it answers at most that late. A &lt;code&gt;Watch&lt;/code&gt; is sendable,
belonging to one thread at a time as a connection does, so a thread of its own may wait on it.&lt;/p&gt;
&lt;h2 id=&quot;avin-io&quot;&gt;&lt;code&gt;avin.io&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Standard input, read as text or as bytes, standard output and error written as bytes, the error
every module that reads or writes shares, and the traits
that let one function read bytes from, or write them to, a file and a connection alike. Standard
output and standard error need no import: &lt;code&gt;print&lt;/code&gt;, &lt;code&gt;println&lt;/code&gt;, &lt;code&gt;eprint&lt;/code&gt; and &lt;code&gt;eprintln&lt;/code&gt; are in the prelude, beside the
writers &lt;code&gt;StandardOutput&lt;/code&gt; and &lt;code&gt;StandardError&lt;/code&gt;; each is one function taking &lt;code&gt;Any*&lt;/code&gt; (see
&lt;a href=&quot;/spec/strings-and-formatting/&quot;&gt;Strings and formatting&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;ioerror&quot;&gt;&lt;code&gt;IoError&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;What every module that reads or writes shares: the error an input or output operation fails with.
It says what kind of failure it was, what was being done, and what it was done to.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data IoError(kind: ErrorKind, operation: string = &amp;quot;&amp;quot;, subject: string = &amp;quot;&amp;quot;)

data ErrorKind
  NotFound
  PermissionDenied
  AlreadyExists
  IsADirectory
  NotADirectory
  DirectoryNotEmpty
  InvalidUtf8(offset: long)
  ConnectionRefused
  ConnectionReset
  TimedOut
  NoTerminal
  Other(text: string)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Kind&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;th&gt;&lt;code&gt;description&lt;/code&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;NotFound&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Nothing exists at the path, or a directory on the way to it is missing.&lt;/td&gt;&lt;td&gt;&lt;code&gt;no such file or directory&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;PermissionDenied&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The program may not read, write or search what the path names.&lt;/td&gt;&lt;td&gt;&lt;code&gt;permission denied&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;AlreadyExists&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Something is already where a new file or directory was to be made.&lt;/td&gt;&lt;td&gt;&lt;code&gt;already exists&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;IsADirectory&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A directory was used where a file was expected.&lt;/td&gt;&lt;td&gt;&lt;code&gt;is a directory&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;NotADirectory&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A file was used where a directory was expected.&lt;/td&gt;&lt;td&gt;&lt;code&gt;not a directory&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DirectoryNotEmpty&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A directory to be removed still holds entries.&lt;/td&gt;&lt;td&gt;&lt;code&gt;directory not empty&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;InvalidUtf8(offset)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Text read is not UTF-8; &lt;code&gt;offset&lt;/code&gt; is the first byte where it stops being.&lt;/td&gt;&lt;td&gt;&lt;code&gt;not UTF-8 at byte 2&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ConnectionRefused&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Nothing listens at the address a connection was made to.&lt;/td&gt;&lt;td&gt;&lt;code&gt;connection refused&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ConnectionReset&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The other end reset or closed a connection while it was in use.&lt;/td&gt;&lt;td&gt;&lt;code&gt;connection reset by peer&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TimedOut&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A read or write on a connection waited past its timeout.&lt;/td&gt;&lt;td&gt;&lt;code&gt;timed out&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;NoTerminal&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The program has no controlling terminal to read from or write to.&lt;/td&gt;&lt;td&gt;&lt;code&gt;there is no terminal&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Other(text)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any other failure, described in words.&lt;/td&gt;&lt;td&gt;&lt;code&gt;text&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;An &lt;code&gt;IoError&lt;/code&gt; names its subject.&lt;/strong&gt; &lt;code&gt;operation&lt;/code&gt; is what was being done, in words that follow
&lt;code&gt;cannot&lt;/code&gt;: &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;, &lt;code&gt;append to&lt;/code&gt;, &lt;code&gt;open&lt;/code&gt;, &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;remove directory&lt;/code&gt;, &lt;code&gt;rename&lt;/code&gt;,
&lt;code&gt;create directory&lt;/code&gt;, &lt;code&gt;list&lt;/code&gt;, &lt;code&gt;read metadata of&lt;/code&gt;, &lt;code&gt;connect to&lt;/code&gt;, &lt;code&gt;listen on&lt;/code&gt;, &lt;code&gt;accept on&lt;/code&gt;, &lt;code&gt;read from&lt;/code&gt;,
&lt;code&gt;write to&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;wait for&lt;/code&gt;, &lt;code&gt;signal&lt;/code&gt;. &lt;code&gt;subject&lt;/code&gt; is what it was done to: a path, &lt;code&gt;old to new&lt;/code&gt; for a
rename, &lt;code&gt;host:port&lt;/code&gt; or a socket’s path for a connection, a program’s name, &lt;code&gt;process 4242&lt;/code&gt;. Every
error the standard library makes has both, so it is an &lt;a href=&quot;/spec/errors/#the-error-trait&quot;&gt;&lt;code&gt;Error&lt;/code&gt;&lt;/a&gt;
whose &lt;code&gt;message&lt;/code&gt;, and so its display, is a sentence:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;fs.readText(&amp;quot;nope.txt&amp;quot;)          // Err(cannot read nope.txt: no such file or directory)
TcpStream.connect(&amp;quot;localhost&amp;quot;, 1) // Err(cannot connect to localhost:1: connection refused)
Command(&amp;quot;nosuch&amp;quot;).run()          // Err(cannot run nosuch: no such file or directory)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The sentence is &lt;code&gt;cannot &amp;lt;operation&amp;gt; &amp;lt;subject&amp;gt;: &amp;lt;description&amp;gt;&lt;/code&gt;; an error with no subject leaves it
out (&lt;code&gt;cannot read: …&lt;/code&gt;), and one with no operation either is the kind’s description alone, so a
program’s own &lt;code&gt;IoError(Other(&amp;quot;disk on fire&amp;quot;))&lt;/code&gt; shows as &lt;code&gt;disk on fire&lt;/code&gt;. &lt;strong&gt;The named kinds have one
description each, the same on every platform; &lt;code&gt;Other&lt;/code&gt; carries the platform’s own wording&lt;/strong&gt; (&lt;code&gt;File name too long&lt;/code&gt;), so a failure with no kind of its own still says what happened.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A program tells failures apart by the kind&lt;/strong&gt;, which a pattern reaches inside the error, a guard or
an &lt;code&gt;==&lt;/code&gt; reads, and the operation and subject come along to be used:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;fs.readText(path) match
  Ok(text) -&amp;gt; use(text)
  Err(IoError(NotFound, _, _)) -&amp;gt; useDefaults()
  Err(e) if e.kind == PermissionDenied -&amp;gt; eprintln(s&amp;quot;$e; try sudo&amp;quot;)
  Err(e) -&amp;gt; fail(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An operation that can fail answers a &lt;code&gt;Result[T, IoError]&lt;/code&gt;, so &lt;code&gt;?&lt;/code&gt; passes the failure on from a
function that answers one too, and &lt;code&gt;context&lt;/code&gt; wraps it in what the program was doing. Where this
chapter says an operation answers &lt;code&gt;Err(NotFound)&lt;/code&gt; or &lt;code&gt;Err(Other(&amp;quot;No such process&amp;quot;))&lt;/code&gt;, it means an
&lt;code&gt;IoError&lt;/code&gt; of that kind, naming the operation and its subject.&lt;/p&gt;
&lt;h3 id=&quot;standard-input&quot;&gt;Standard input&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io

main()
  var total = 0
  for line in io.lines()
    line.trim.toIntOption() match
      Some(n) -&amp;gt; total += n
      None -&amp;gt; eprintln(s&amp;quot;not a number: $line&amp;quot;)
  println(total)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readLine() -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The next line without its terminator, &lt;code&gt;None&lt;/code&gt; at the end of the input. An empty line is &lt;code&gt;Some(&amp;quot;&amp;quot;)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lines() -&amp;gt; Iterator[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The lines left, each as &lt;code&gt;readLine&lt;/code&gt; gives it, read as the iterator advances.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readAll() -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Everything left, terminators and all; empty when nothing is left.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inputs(paths: Vector[string]) -&amp;gt; Iterator[Result[(string, string), IoError]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The files &lt;code&gt;paths&lt;/code&gt; names, or standard input when it is empty, each as its name and all its text.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inputLines(paths: Vector[string]) -&amp;gt; Iterator[Result[(string, string), IoError]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same a line at a time: an input’s name and one of its lines.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;inputs&lt;/code&gt; and &lt;code&gt;inputLines&lt;/code&gt; are for a tool that reads the files it is given, or standard input.&lt;/strong&gt; A
path of &lt;code&gt;-&lt;/code&gt; names standard input wherever it stands, and no paths at all is one input, standard
input; a name comes back as it was written, so standard input is &lt;code&gt;&amp;quot;-&amp;quot;&lt;/code&gt;. An input is read when the
iterator reaches it, and one that cannot be read is an &lt;code&gt;Err&lt;/code&gt; naming it in its place: the iterator
goes on, so a tool reports each failure and carries on. Standard input is read to its end, so a
second &lt;code&gt;-&lt;/code&gt; finds it empty; it shares the buffer of &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;lines()&lt;/code&gt; and &lt;code&gt;readAll&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;for r in io.inputLines(args)
  r match
    Ok((name, line)) -&amp;gt; println(s&amp;quot;$name:$line&amp;quot;)
    Err(e) -&amp;gt; eprintln(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A line ends at &lt;code&gt;\n&lt;/code&gt;, and a &lt;code&gt;\r&lt;/code&gt; just before it belongs to the terminator&lt;/strong&gt;, so input written with
either convention reads the same. A &lt;code&gt;\r&lt;/code&gt; anywhere else is part of the line. The last line needs no
terminator: input ending &lt;code&gt;a\nb&lt;/code&gt; has the lines &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, and input ending &lt;code&gt;a\n&lt;/code&gt; only &lt;code&gt;a&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The three share one buffer.&lt;/strong&gt; The runtime reads standard input in large blocks and keeps what it
has read ahead, so &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;lines()&lt;/code&gt; and &lt;code&gt;readAll&lt;/code&gt; can be mixed: each takes up where the last
stopped, and nothing read ahead is lost. Reading blocks until a line is complete or the input ends,
so a program reading a terminal sees each line as it is entered.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Threads read standard input one at a time, and each read is whole.&lt;/strong&gt; A &lt;code&gt;readLine&lt;/code&gt;, a step of an
iterator and &lt;code&gt;readAll&lt;/code&gt; each take what they read in one step: a line goes whole to exactly one reader,
never split between two or given to both, and a reader that finds the input ended gets &lt;code&gt;None&lt;/code&gt;. A
lightweight thread waiting for its turn, or for the input itself, parks and leaves its worker to the
others. An iterator over standard input takes the line (or character) &lt;code&gt;hasNext&lt;/code&gt; answers for and keeps
it for &lt;code&gt;next&lt;/code&gt;, so a &lt;code&gt;true&lt;/code&gt; from &lt;code&gt;hasNext&lt;/code&gt; is never undone by another thread; a &lt;code&gt;readLine&lt;/code&gt; after
&lt;code&gt;hasNext&lt;/code&gt; reads the line after the one the iterator holds.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Input is text, and reading it does not fail.&lt;/strong&gt; Bytes that are not UTF-8 become U+FFFD, one for each
ill-formed run, as they are read; a line is always a valid string, and a program reading text is
never stopped by a stray byte. A read that fails ends the input, as its end does. Standard input is a
stream a program consumes as it arrives, where a file is read whole: &lt;code&gt;fs.readText&lt;/code&gt; answers
&lt;code&gt;InvalidUtf8&lt;/code&gt; instead, since a file’s bytes can be read again as bytes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Writing to standard error flushes standard output first.&lt;/strong&gt; Standard output is buffered, and
flushed when the program ends, exits or traps; standard error is not buffered. Each write to
standard error first flushes what the program has written to standard output, so when both go to one
terminal or one file they arrive in the order the program wrote them. &lt;code&gt;eprintln(x)&lt;/code&gt; renders &lt;code&gt;x&lt;/code&gt; (or all its arguments) and its
new line first and writes them in one write, so a line is never split.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A line printed is never split, whichever threads print.&lt;/strong&gt; &lt;code&gt;println(x)&lt;/code&gt; (with any number of
arguments) renders all its arguments and its new line first, then adds them to standard output’s
buffer in one step, and &lt;code&gt;print(x)&lt;/code&gt; does the same with no new line: one call, one piece of output.
Another thread’s output lands before the piece or after it, never inside it, however long the piece
is and wherever standard output leads (a terminal, a pipe, a file); a flush sends the buffer’s
pieces out whole and in order. Rendering is done before the step, so a value slow or large to render
holds no other thread up. Output built from several calls (&lt;code&gt;print(a)&lt;/code&gt; then &lt;code&gt;println(b)&lt;/code&gt;, or writes
to &lt;code&gt;StandardOutput&lt;/code&gt; piece by piece) is several pieces, and another thread’s may land between them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;flush()&lt;/code&gt; sends a partial line on its way.&lt;/strong&gt; &lt;code&gt;flush()&lt;/code&gt; in the prelude (and &lt;code&gt;StandardOutput.flush()&lt;/code&gt;,
and &lt;code&gt;StandardError.flush()&lt;/code&gt;, which has nothing to send) sends everything written to standard output so
far out of the buffer whether or not a line is complete, so a program that draws a frame without a
new line can show it. Nothing buffered is not an error. Reading standard input flushes standard
output first when it must wait for more, so a prompt written with &lt;code&gt;print&lt;/code&gt; is on the terminal before
the program blocks for the answer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tests see no input.&lt;/strong&gt; &lt;code&gt;avin test&lt;/code&gt; gives each test an empty standard input, so a test never waits on
the terminal it was started from. &lt;code&gt;avin run&lt;/code&gt; hands the program its own standard input.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A closed standard stream is &lt;code&gt;/dev/null&lt;/code&gt;.&lt;/strong&gt; A program started with standard input, output or error
closed (&lt;code&gt;prog &amp;lt;&amp;amp;-&lt;/code&gt;) finds &lt;code&gt;/dev/null&lt;/code&gt; there: the runtime opens it on each of the three that is
missing before it opens anything of its own, so none of its own descriptors takes the number. A
closed standard input reads as empty; what is written to a closed output or error goes nowhere.&lt;/p&gt;
&lt;h3 id=&quot;standard-streams-as-bytes&quot;&gt;Standard streams as bytes&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io

// Copies standard input to standard output byte for byte.
main()
  io.copy(io.stdin(), io.stdout()) match
    Ok(n) -&amp;gt; eprintln(s&amp;quot;$n bytes&amp;quot;)
    Err(e) -&amp;gt; eprintln(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stdin() -&amp;gt; StandardInputBytes&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Standard input as a &lt;a href=&quot;#reader&quot;&gt;&lt;code&gt;Reader&lt;/code&gt;&lt;/a&gt; of bytes and a &lt;code&gt;Readiness&lt;/code&gt;, with &lt;code&gt;readAvailable(max)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stdout() -&amp;gt; StandardOutputBytes&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Standard output as a &lt;a href=&quot;#bytewriter&quot;&gt;&lt;code&gt;ByteWriter&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stderr() -&amp;gt; StandardErrorBytes&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Standard error as a &lt;code&gt;ByteWriter&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The three answers are objects, &lt;code&gt;Sendable&lt;/code&gt;, so a thread of their own can read or write: a server’s
writing thread takes &lt;code&gt;stdout()&lt;/code&gt; as a &lt;code&gt;W: ByteWriter &amp;amp; Sendable&lt;/code&gt;. They are for input whose length is
counted in bytes, a &lt;code&gt;Content-Length&lt;/code&gt; header most of all, and for input and output that is not text.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bytes and lines share one buffer.&lt;/strong&gt; &lt;code&gt;stdin().read(max)&lt;/code&gt; takes from the buffer &lt;code&gt;readLine&lt;/code&gt;,
&lt;code&gt;lines()&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt; and &lt;code&gt;Source.stdin()&lt;/code&gt; take from, so a program reads a header as a line and the
body after it as bytes, or the other way round, and no byte is lost or read twice. A read answers
the bytes already read ahead where there are any, else waits for one read of the input, so it may
answer fewer than &lt;code&gt;max&lt;/code&gt;; it never waits for more once it has some. Byte reads take the same lock as
the text reads, one thread at a time, and a lightweight thread waiting for input parks on the
runtime’s poller, leaving its worker to the others.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The end of input is an empty array, as often as it is asked.&lt;/strong&gt; Standard input may be a terminal,
a pipe, a file or &lt;code&gt;/dev/null&lt;/code&gt;. A read that fails answers &lt;code&gt;Err(IoError(Other(m), &amp;quot;read&amp;quot;, &amp;quot;standard input&amp;quot;))&lt;/code&gt; with the platform’s sentence (standard input that is a directory: &lt;code&gt;is a directory&lt;/code&gt;), where
the text readers see the end. A &lt;code&gt;max&lt;/code&gt; below one traps, as a connection’s read does.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Standard input can be waited on with channels, timers and connections.&lt;/strong&gt; &lt;code&gt;stdin()&lt;/code&gt; is a
&lt;a href=&quot;/spec/threads/#select&quot;&gt;&lt;code&gt;Readiness&lt;/code&gt;&lt;/a&gt;, so &lt;code&gt;stdin().readable() -&amp;gt; …&lt;/code&gt; is an arm of a &lt;code&gt;select&lt;/code&gt; beside
channel arms and an &lt;code&gt;after&lt;/code&gt;, and &lt;code&gt;Selector.readable(stdin(), key)&lt;/code&gt; puts it among connections. Its
&lt;code&gt;readable()&lt;/code&gt; answers at once whether a read would answer without waiting: bytes are in the shared
buffer, those a &lt;code&gt;readLine&lt;/code&gt; read past its line among them, or have arrived on the descriptor, or the
input has ended or failed, or it is a file, whose read never waits; it answers &lt;code&gt;false&lt;/code&gt; while
another thread is in the middle of reading it. &lt;code&gt;readAvailable(max) -&amp;gt; Result[Option[Array[byte]], IoError]&lt;/code&gt; reads only what is there and never waits: &lt;code&gt;Some&lt;/code&gt; of what &lt;code&gt;read(max)&lt;/code&gt; would answer now,
an empty array once the input has ended, or &lt;code&gt;None&lt;/code&gt; where a read would wait, so a loop that is
also drawing a screen or keeping time takes what has come and goes on.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io
import avin.threads.Channel
import avin.time.millis

// Echoes what is typed, a piece at a time as it comes, and says each tick, until the input ends.
run(ticks: Channel[int])
  var open = true
  while open
    select
      io.stdin().readable() -&amp;gt; io.stdin().readAvailable(4096) match
        Ok(Some(b)) -&amp;gt; if b.length == 0 then open = false else io.stdout().write(b).getOrElse(())
        Ok(None) -&amp;gt; ()
        Err(_) -&amp;gt; open = false
      ticks.receive() as Some(t) -&amp;gt; println(s&amp;quot;tick $t&amp;quot;)
      after millis(500) -&amp;gt; println(&amp;quot;idle&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Standard input belongs to no thread, so any thread may wait on it, where a connection may be named
in a select only by the thread it belongs to. Waiting takes no lock: a select waits while another
thread reads, and bytes that read leaves in the buffer end the wait as bytes arriving do. Several
threads may wait on it at once; each is woken, and the reads that follow share the bytes, each byte
going to one of them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A byte write goes out whole before it returns.&lt;/strong&gt; Standard output’s buffer, what &lt;code&gt;print&lt;/code&gt; and
&lt;code&gt;println&lt;/code&gt; have written so far, is sent on first, so the bytes land after it; the write holds
standard output for its whole length, so another thread’s printed line lands before it or after it,
never inside it. There is nothing to flush afterwards. A write to standard error flushes standard
output first, as &lt;code&gt;eprint&lt;/code&gt; does. An empty write writes nothing and answers &lt;code&gt;Ok&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A write to a reader that has gone fails; it does not end the program.&lt;/strong&gt; A byte write to a pipe or
socket whose reader has closed answers &lt;code&gt;Err(IoError(ConnectionReset, &amp;quot;write&amp;quot;, &amp;quot;standard output&amp;quot;))&lt;/code&gt;
(or &lt;code&gt;&amp;quot;standard error&amp;quot;&lt;/code&gt;), and every later byte write answers the same; the program goes on, however
many of its threads are writing or running. A child the program starts writes to the same output
as any program does, and is ended by its broken pipe as usual. &lt;code&gt;print&lt;/code&gt;
is not changed by it: a program that only prints still ends quietly when its reader goes, as a
filter in a pipeline should.&lt;/p&gt;
&lt;h3 id=&quot;secrets-typed-at-the-terminal&quot;&gt;Secrets typed at the terminal&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io

main()
  io.readSecret(&amp;quot;Password: &amp;quot;) match
    Ok(password) -&amp;gt; login(password)
    Err(e) -&amp;gt; eprintln(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readSecret(prompt: string) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One line typed at the controlling terminal with echo off, after &lt;code&gt;prompt&lt;/code&gt; is written to the terminal. Bytes that are not UTF-8 become U+FFFD.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readSecretBytes(prompt: string) -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same line as bytes the caller owns and can overwrite when done with them.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readSecretOrLine(prompt: string) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;readSecret&lt;/code&gt;, or where the program has no terminal, &lt;code&gt;prompt&lt;/code&gt; written to standard error and a line read from standard input, shown as it arrives.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;The line is read from the terminal, not from standard input.&lt;/strong&gt; The terminal is the one the program
was started from (&lt;code&gt;/dev/tty&lt;/code&gt;), so a program whose input or output is a pipe can still ask, as &lt;code&gt;sudo&lt;/code&gt;
and &lt;code&gt;ssh&lt;/code&gt; do. The prompt goes to the terminal too, and what the program has written to standard
output is flushed before it. A program with no controlling terminal gets
&lt;code&gt;Err(IoError(NoTerminal, &amp;quot;read&amp;quot;, &amp;quot;the terminal&amp;quot;))&lt;/code&gt;; &lt;code&gt;readSecretOrLine&lt;/code&gt; is the call for a program a
script may run with its password piped in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Echo is off and the terminal is put back exactly as it was found.&lt;/strong&gt; Line editing stays on, so the
user can still correct what they type; the newline the user’s Enter did not echo is written once the
terminal is back. The terminal is put back on every way out: a line, the end of input, an error, a
cancelled thread’s stop and a signal. Ctrl-C, a hangup, terminate or quit signal arriving during
the read puts the terminal back first and then reaches the program as it would have: the program
ends, or, where it watches the signal, sees the read fail with &lt;code&gt;Other(&amp;quot;interrupted&amp;quot;)&lt;/code&gt; and the signal
in its watch. Typed-ahead input is discarded when the read starts, so nothing typed before the prompt
is taken for the secret. A stop from the terminal (Ctrl-Z) puts the terminal back before the program
stops, so a stopped program leaves the user’s shell with echo on; when it is continued, echo goes off
again, the prompt is written again and the read goes on; what was typed before the Ctrl-Z is
discarded by the terminal, as it is for any signal character.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The line has no terminator.&lt;/strong&gt; A trailing &lt;code&gt;\n&lt;/code&gt; and a &lt;code&gt;\r&lt;/code&gt; before it are dropped. A line ended by the
terminal’s end-of-file character counts if it has bytes in it; the end of input before any byte is
&lt;code&gt;Err(IoError(Other(&amp;quot;end of input&amp;quot;), _, _))&lt;/code&gt;. An empty line is an empty secret. A line is at most what
the terminal itself keeps of one: 1023 bytes on macOS, 4095 on Linux.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It never runs at the same time as a read of standard input, or another secret.&lt;/strong&gt; The read takes
the lock every reader of standard input takes: a thread that asks waits for a reader of either, and
the other way round. A thread cancelled while it waits for the line is stopped once the line has
been read, as one reading standard input is. A secret asked for with no way to clear it is still a
&lt;code&gt;string&lt;/code&gt;; &lt;code&gt;readSecretBytes&lt;/code&gt; is the form to overwrite, and the runtime clears its own copies.&lt;/p&gt;
&lt;h3 id=&quot;reader&quot;&gt;&lt;code&gt;Reader&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;Reader&lt;/code&gt; is bytes read from somewhere a piece at a time, so one function can read a file, a
connection, or a source the program writes itself, holding no more of the input than it asks for:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Reader
  read(max: int) -&amp;gt; Result[Array[byte], IoError]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;read(max)&lt;/code&gt; gives up to &lt;code&gt;max&lt;/code&gt; bytes, &lt;code&gt;max&lt;/code&gt; being at least one, waiting for at least one where the
source is still going, and an empty array once it has ended. A stream’s read allocates the bytes
it answers, not &lt;code&gt;max&lt;/code&gt;, so a small message read with a large &lt;code&gt;max&lt;/code&gt; costs what the message does.
&lt;code&gt;fs.File&lt;/code&gt; is a reader by its own
&lt;code&gt;read&lt;/code&gt;, and so is every &lt;code&gt;net.ByteStream&lt;/code&gt;: &lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;TlsStream&lt;/code&gt;; a class of the program’s own is one by
naming &lt;code&gt;io.Reader&lt;/code&gt; (or &lt;code&gt;Reader&lt;/code&gt;, imported) after &lt;code&gt;:&lt;/code&gt; and overriding &lt;code&gt;read&lt;/code&gt;. The
JSON package’s &lt;code&gt;JsonReader&lt;/code&gt; (&lt;a href=&quot;/spec/json/&quot;&gt;&lt;code&gt;dev.avinlang.json&lt;/code&gt;&lt;/a&gt;) reads JSON from any reader.&lt;/p&gt;
&lt;h3 id=&quot;bytewriter&quot;&gt;&lt;code&gt;ByteWriter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;ByteWriter&lt;/code&gt; is somewhere bytes are written, so one function can write to a file, a connection,
a streamed HTTP body, or a sink the program makes itself:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait ByteWriter
  write(bytes: Array[byte]) -&amp;gt; Result[unit, IoError]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;write(bytes)&lt;/code&gt; writes all of &lt;code&gt;bytes&lt;/code&gt; or answers why it could not; an empty array writes nothing.
&lt;code&gt;fs.File&lt;/code&gt; is a byte writer by its own &lt;code&gt;write&lt;/code&gt;, and so are every &lt;code&gt;net.ByteStream&lt;/code&gt; (&lt;code&gt;TcpStream&lt;/code&gt;,
&lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;TlsStream&lt;/code&gt;), the &lt;code&gt;StreamWriter&lt;/code&gt; half of a &lt;a href=&quot;#split-connections&quot;&gt;split connection&lt;/a&gt;
and a streamed response’s &lt;code&gt;BodyWriter&lt;/code&gt;; a write to any of them once it is closed is an &lt;code&gt;Err&lt;/code&gt;. A
class of the program’s own is one by naming &lt;code&gt;io.ByteWriter&lt;/code&gt; after &lt;code&gt;:&lt;/code&gt; and overriding &lt;code&gt;write&lt;/code&gt;, and a
generic function takes any of them as &lt;code&gt;[W: ByteWriter]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It writes bytes, and the prelude’s &lt;a href=&quot;/spec/strings-and-formatting/&quot;&gt;&lt;code&gt;Writer&lt;/code&gt;&lt;/a&gt; is where values render
as text; the two names differ, so a program sees both unqualified and one class may be both, its two
&lt;code&gt;write&lt;/code&gt;s told apart by what they take. A byte writer is not a &lt;code&gt;Close&lt;/code&gt;, as a &lt;code&gt;Reader&lt;/code&gt; is not: a
streamed body is ended by its response, not closed, and code holding a resource that is both bounds
it by both. Nor does it flush: a file’s &lt;code&gt;flush()&lt;/code&gt; is the file’s own, and whoever opened the file
closes it, which flushes it.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;io.copy(from: Reader, to: ByteWriter) -&amp;gt; Result[long, IoError]&lt;/code&gt; reads &lt;code&gt;from&lt;/code&gt; to its end and writes
everything it gives to &lt;code&gt;to&lt;/code&gt;, a piece of at most 64 KiB at a time, so a copy of any length holds no
more than one piece. It answers how many bytes it copied, or the first read’s or write’s &lt;code&gt;Err&lt;/code&gt;, after
which nothing more is read or written. It neither closes, flushes nor rewinds either side:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;upload(name: string, to: TcpStream) -&amp;gt; Result[long, IoError]
  val f = fs.open(name)?
  defer f.close()
  io.copy(f, to)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;close&quot;&gt;&lt;code&gt;Close&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;Close&lt;/code&gt; is something held outside the program that &lt;code&gt;close()&lt;/code&gt; gives back:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Close
  close() -&amp;gt; Result[unit, IoError]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every resource the library hands out is one: &lt;code&gt;fs.File&lt;/code&gt;, &lt;code&gt;fs.TempDir&lt;/code&gt;, every &lt;code&gt;net.ByteStream&lt;/code&gt;
(&lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt;, &lt;code&gt;TlsStream&lt;/code&gt;), &lt;code&gt;TcpListener&lt;/code&gt;, &lt;code&gt;UnixListener&lt;/code&gt; and &lt;code&gt;process.Child&lt;/code&gt;. &lt;strong&gt;Closing
a closed one does nothing and answers &lt;code&gt;Ok&lt;/code&gt;&lt;/strong&gt;, so a &lt;a href=&quot;/spec/operators-and-control-flow/#defer&quot;&gt;&lt;code&gt;defer&lt;/code&gt;&lt;/a&gt;
beside the code that took it gives it back on every way out of the block, and the success path may
close it first to see the &lt;code&gt;Err&lt;/code&gt;, a flush that failed or a directory that could not be removed:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;save(name: string, text: string) -&amp;gt; Result[unit, IoError]
  val f = fs.create(name)?
  defer f.close()
  f.writeText(text)?
  f.close()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A generic function takes any resource as &lt;code&gt;[R: Close]&lt;/code&gt;, and a class of the program’s own is one by
naming &lt;code&gt;io.Close&lt;/code&gt; after &lt;code&gt;:&lt;/code&gt; and overriding &lt;code&gt;close&lt;/code&gt;. A &lt;code&gt;Channel&lt;/code&gt;‘s &lt;code&gt;close()&lt;/code&gt; ends what it carries rather
than giving anything back, and is not one; a Sysl or C handle’s built-in &lt;code&gt;close()&lt;/code&gt; answers &lt;code&gt;unit&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;source&quot;&gt;&lt;code&gt;Source&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;Source&lt;/code&gt; is text to be read from somewhere, so one function can read a file, a string
or standard input alike.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io.{IoError, Source}

count(src: Source) -&amp;gt; int = src.lines().count(l -&amp;gt; !l.isEmpty)

main() -&amp;gt; int
  Source.fromFile(&amp;quot;notes.txt&amp;quot;) match
    Ok(src) -&amp;gt; println(count(src))
    Err(e) -&amp;gt; eprintln(e.message)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Source.fromFile(file: string) -&amp;gt; Result[Source, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The file’s text, read whole when the source is made, as &lt;code&gt;fs.readText&lt;/code&gt; reads it: every failure, &lt;code&gt;InvalidUtf8&lt;/code&gt; among them, is the &lt;code&gt;Err&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Source.fromString(text: string) -&amp;gt; Source&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text itself.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Source.stdin() -&amp;gt; Source&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Standard input, read as it is consumed and sharing &lt;code&gt;readLine&lt;/code&gt;‘s buffer.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.lines() -&amp;gt; Iterator[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The lines left, by the rule standard input’s lines follow.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.chars() -&amp;gt; Iterator[char]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The characters left.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.readAll() -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Everything left.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A source is read once.&lt;/strong&gt; Each of the three takes up where the last stopped, as standard input’s
functions do; a second &lt;code&gt;lines()&lt;/code&gt; over a source already read to its end has nothing. A source holds
nothing open, so there is nothing to close: a file’s is its text, and standard input stays the
program’s. &lt;strong&gt;Standard input’s characters come from the same buffer as its lines&lt;/strong&gt;, so &lt;code&gt;chars()&lt;/code&gt;,
&lt;code&gt;lines()&lt;/code&gt; and &lt;code&gt;io.readLine()&lt;/code&gt; can be mixed, and bytes that are not UTF-8 are one U+FFFD for each
ill-formed run, character by character as in a line. Asking an exhausted iterator for more traps, as
with any iterator.&lt;/p&gt;
&lt;h2 id=&quot;avin-fs&quot;&gt;&lt;code&gt;avin.fs&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Files and directories. A file is read or written whole, in one call.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.fs
import avin.io.IoError

copyNotes(from: string, to: string) -&amp;gt; Result[unit, IoError]
  val text = fs.readText(from)?
  fs.createDirAll(to)?
  fs.writeText(to + &amp;quot;/notes.txt&amp;quot;, text)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readText(file) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The whole file as text; &lt;code&gt;InvalidUtf8&lt;/code&gt; when it is not UTF-8.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readBytes(file) -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The whole file as bytes, in a new array.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeText(file, text) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes the file hold exactly &lt;code&gt;text&lt;/code&gt;, creating or replacing it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;appendText(file, text) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Adds &lt;code&gt;text&lt;/code&gt; to the end of the file, creating it if it is not there.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeBytes(file, bytes) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;writeText&lt;/code&gt;, with bytes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;appendBytes(file, bytes) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;appendText&lt;/code&gt;, with bytes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeText(file, text, createParents = false)&lt;/code&gt;, &lt;code&gt;writeBytes(file, bytes, createParents = false)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;With &lt;code&gt;createParents&lt;/code&gt;, the directories above the file that are missing are made first (&lt;code&gt;createDirAll&lt;/code&gt; of its parent).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeTextAtomic(file, text, createParents = false) -&amp;gt; Result[unit, IoError]&lt;/code&gt;, &lt;code&gt;writeBytesAtomic(file, bytes, createParents = false)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes to a new file beside &lt;code&gt;file&lt;/code&gt;, syncs it to the device and renames it over &lt;code&gt;file&lt;/code&gt;: a reader sees the whole old contents or the whole new, and a failure leaves &lt;code&gt;file&lt;/code&gt; as it was and removes the new file. The new file’s name is unique per call and per process. The replacement takes default permissions, not the old file’s.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readLines(file) -&amp;gt; Result[Vector[string], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every line without its terminator. &lt;code&gt;\n&lt;/code&gt; and &lt;code&gt;\r\n&lt;/code&gt; both end a line; a last line with no terminator is kept; a final terminator does not start an empty line, so an empty file has no lines and &lt;code&gt;&amp;quot;\n&amp;quot;&lt;/code&gt; has one empty line. Invalid UTF-8 becomes U+FFFD.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lines(file) -&amp;gt; Result[Lines, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same lines, lazily: &lt;code&gt;Lines&lt;/code&gt; is an &lt;code&gt;Iterator[Result[string, IoError]]&lt;/code&gt; holding one line at a time. The file closes when the iterator gives its last item (a line, or the &lt;code&gt;Err&lt;/code&gt; that ended it). To stop early, &lt;code&gt;close()&lt;/code&gt; it (&lt;code&gt;defer reader.close()&lt;/code&gt;); one forgotten is closed by the collector.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeLines(file, lines, createParents = false) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes each line followed by &lt;code&gt;\n&lt;/code&gt; to a made or emptied file, so the file ends in a newline; an empty collection leaves an empty file.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exists(file, followLinks = true) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether anything, file or directory, is at the path. A dangling link answers &lt;code&gt;false&lt;/code&gt;; with &lt;code&gt;followLinks = false&lt;/code&gt; the link itself is asked about, so it answers &lt;code&gt;true&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isDir(file) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the path names a directory, one the program may not read included.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isFile(file) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the path names a regular file: not a directory, and not a FIFO, a socket or a device either.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isReadable(file) -&amp;gt; bool&lt;/code&gt; / &lt;code&gt;isWritable(file) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the user who started the program may read, or write, what the path names, as its bits, owner and group say; &lt;code&gt;false&lt;/code&gt; for a path that is not there. A link is followed. The superuser may read and write anything. Opening the file is the check that counts: the answer can be stale by then.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isSameFile(a, b) -&amp;gt; Result[bool, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the two paths lead to one file: its inode and device, not its name or contents. Two hard links, and a symbolic link and its target, are the same; a copy is not. Both are followed and must exist: a missing one is &lt;code&gt;NotFound&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;remove(file) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Removes a file; never a directory, which is &lt;code&gt;IsADirectory&lt;/code&gt;. A link is removed, not what it names.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;removeDir(dir) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Removes an empty directory; &lt;code&gt;DirectoryNotEmpty&lt;/code&gt; otherwise.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;removeDirAll(dir) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Removes a directory and everything in it; a path already gone is success.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;removeAll(path) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Removes a file, a link or a directory with everything in it. A link is removed and never followed (a link to a directory leaves the directory and its contents); a path that is not there is &lt;code&gt;NotFound&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;removeIfExists(path) -&amp;gt; Result[bool, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;removeAll&lt;/code&gt;, but a path that is not there is &lt;code&gt;Ok(false)&lt;/code&gt;; &lt;code&gt;Ok(true)&lt;/code&gt; when something was removed (a dangling link included).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;rename(from, to) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Moves a file or directory in one step, replacing what is at &lt;code&gt;to&lt;/code&gt;: a file replaces a file, a directory an empty directory (&lt;code&gt;DirectoryNotEmpty&lt;/code&gt; if it holds entries); a file onto a directory is &lt;code&gt;IsADirectory&lt;/code&gt;, a directory onto a file &lt;code&gt;NotADirectory&lt;/code&gt;; a missing source or a missing directory above &lt;code&gt;to&lt;/code&gt; is &lt;code&gt;NotFound&lt;/code&gt;. The same path on both sides succeeds and changes nothing. Both names must be on one file system, or nothing moves.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;createDir(dir) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes one directory, whose parent must exist; &lt;code&gt;AlreadyExists&lt;/code&gt; if something is there.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;createDirAll(dir) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes the directory and every missing one above it; a directory already there is success; a file where &lt;code&gt;dir&lt;/code&gt; itself would go is &lt;code&gt;AlreadyExists&lt;/code&gt;, and a file where one of the directories above it would go is &lt;code&gt;NotADirectory&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;createTempDir(prefix) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes a new, empty directory in the platform’s place for temporary files, its name starting with &lt;code&gt;prefix&lt;/code&gt;, and answers its path.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tempDir(prefix) -&amp;gt; Result[TempDir, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes the directory as &lt;code&gt;createTempDir&lt;/code&gt; does and holds it as an &lt;a href=&quot;#close&quot;&gt;&lt;code&gt;io.Close&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;t.path&lt;/code&gt; is its path, &lt;code&gt;t.close()&lt;/code&gt; removes it and everything in it (closing again does nothing and answers &lt;code&gt;Ok&lt;/code&gt;; one that failed may be closed again), and &lt;code&gt;t.isClosed&lt;/code&gt; says whether it has been removed. One never closed stays on the disk.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;metadata(file) -&amp;gt; Result[Metadata, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One look at a path, as a &lt;a href=&quot;#file-metadata&quot;&gt;&lt;code&gt;Metadata&lt;/code&gt;&lt;/a&gt;. A symbolic link is followed, so a dangling one is &lt;code&gt;NotFound&lt;/code&gt;; a missing path is &lt;code&gt;NotFound&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;linkMetadata(file) -&amp;gt; Result[Metadata, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;metadata&lt;/code&gt;, but a symbolic link is described rather than followed: its &lt;code&gt;kind&lt;/code&gt; is &lt;code&gt;Symlink&lt;/code&gt;, its &lt;code&gt;size&lt;/code&gt; the length of the path it holds, and a dangling one answers &lt;code&gt;Ok&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;permissions(file) -&amp;gt; Result[int, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The permission bits of the file or directory: the nine &lt;code&gt;rwx&lt;/code&gt; bits with setuid &lt;code&gt;0o4000&lt;/code&gt;, setgid &lt;code&gt;0o2000&lt;/code&gt; and the sticky bit &lt;code&gt;0o1000&lt;/code&gt;, never the file type.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setPermissions(file, mode) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sets the permission bits to exactly &lt;code&gt;mode&lt;/code&gt;, &lt;code&gt;0o0&lt;/code&gt; to &lt;code&gt;0o7777&lt;/code&gt;; not a mask added to what is there, and the umask plays no part. A mode outside that range is an &lt;code&gt;Err&lt;/code&gt; of kind &lt;code&gt;Other&lt;/code&gt; naming it, before the path is looked at, and changes nothing.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;size(file) -&amp;gt; Result[long, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The size of the file in bytes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;modified(file) -&amp;gt; Result[Instant, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;When the contents of the file or directory last changed, to the file system’s resolution.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setModified(file, when) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sets the modification time (the access time moves with it); reading it back may round to the file system’s resolution.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;listDir(dir) -&amp;gt; Result[Vector[string], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The names of the directory’s entries, files and directories alike, sorted by code point; &lt;code&gt;NotFound&lt;/code&gt; or &lt;code&gt;NotADirectory&lt;/code&gt; when there is no directory to list.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Paths are strings&lt;/strong&gt;, and the questions follow symbolic links: &lt;code&gt;isDir&lt;/code&gt; of a link to a directory is
&lt;code&gt;true&lt;/code&gt;. &lt;code&gt;removeDirAll&lt;/code&gt; is the exception that matters: a link inside the tree is removed, never
followed, so it deletes nothing outside the directory it was given.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Size and age&lt;/strong&gt; come from one &lt;code&gt;stat&lt;/code&gt;. A cache that keeps what was used recently and reports what it
freed:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.fs
import avin.io.IoError
import avin.time
import avin.time.Duration

evictOlderThan(dir: string, age: Duration) -&amp;gt; Result[long, IoError]
  var freed: long = 0
  for name in fs.listDir(dir)?
    val file = dir + &amp;quot;/&amp;quot; + name
    val m = fs.metadata(file)?
    if m.isFile &amp;amp;&amp;amp; time.now() - m.modified &amp;gt; age
      fs.remove(file)?
      freed += m.size
  Ok(freed)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Recording that an entry was used is &lt;code&gt;fs.setModified(file, time.now())&lt;/code&gt;, which writes nothing to the file.
&lt;code&gt;m.isFile&lt;/code&gt; is true for a regular file alone, so a socket or a FIFO another program left in the
directory is passed over rather than removed.&lt;/p&gt;
&lt;h3 id=&quot;file-metadata&quot;&gt;File metadata&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;Metadata&lt;/code&gt; is everything one &lt;code&gt;stat&lt;/code&gt; answered, so its fields describe one entry:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;size: long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The size in bytes. For a directory it is the file system’s bookkeeping, not a count of entries; for a link read by &lt;code&gt;linkMetadata&lt;/code&gt;, the length of the path it holds.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;modified: Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;When the contents last changed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;accessed: Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;When the contents were last read. Whether a read moves it is the file system’s choice: one that records reads moves it to now, and one that does not (macOS’s) leaves it. &lt;code&gt;setModified&lt;/code&gt; sets it with &lt;code&gt;modified&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;changed: Instant&lt;/code&gt;&lt;/td&gt;&lt;td&gt;When the entry itself last changed: a write, a change of permissions, and &lt;code&gt;setModified&lt;/code&gt; move it to now, a read does not, and no ordinary call sets it back, which is what makes it the time a security check reads.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isDir: bool&lt;/code&gt;, &lt;code&gt;isFile: bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether it is a directory, and whether a regular file.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;kind: FileKind&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Which kind of entry it is: &lt;code&gt;Regular&lt;/code&gt;, &lt;code&gt;Directory&lt;/code&gt;, &lt;code&gt;Symlink&lt;/code&gt;, &lt;code&gt;Fifo&lt;/code&gt;, &lt;code&gt;Socket&lt;/code&gt;, &lt;code&gt;CharDevice&lt;/code&gt; (&lt;code&gt;/dev/null&lt;/code&gt;), &lt;code&gt;BlockDevice&lt;/code&gt; (a disk), or &lt;code&gt;UnknownKind(bits)&lt;/code&gt; with the type bits for any other the platform has. &lt;code&gt;Symlink&lt;/code&gt; comes only from &lt;code&gt;linkMetadata&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isLink: bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;kind&lt;/code&gt; is &lt;code&gt;Symlink&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;permissions: int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The twelve permission bits, as &lt;code&gt;permissions(file)&lt;/code&gt; answers them.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;owner: long&lt;/code&gt;, &lt;code&gt;group: long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The numeric user and group ids. &lt;code&gt;process.userId()&lt;/code&gt; is the program’s own, and &lt;code&gt;process.userName(owner)&lt;/code&gt; names the owner.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;links: long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;How many names lead to the file: more than one means a hard link.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inode: long&lt;/code&gt;, &lt;code&gt;device: long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The file’s number within its file system, and which file system: together, not either alone, they identify the file, which is what &lt;code&gt;isSameFile&lt;/code&gt; compares.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;FileKind&lt;/code&gt;‘s variants are written qualified, &lt;code&gt;m.kind == fs.Socket&lt;/code&gt;, and compare as values. A walk that
must not leave a tree asks &lt;code&gt;linkMetadata(p).isLink&lt;/code&gt; (or &lt;code&gt;isLink(p)&lt;/code&gt;); a walk that follows links
remembers each directory’s &lt;code&gt;(inode, device)&lt;/code&gt; so a link back up is seen.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Permissions&lt;/strong&gt; are written as octal literals, &lt;code&gt;fs.setPermissions(file, 0o600)&lt;/code&gt;, and read back the
same way: &lt;code&gt;fs.permissions(file)&lt;/code&gt; is &lt;code&gt;Ok(0o600)&lt;/code&gt;, and &lt;code&gt;f&amp;quot;${p}%o&amp;quot;&lt;/code&gt; prints it as &lt;code&gt;600&lt;/code&gt;. A file the
library creates asks for &lt;code&gt;0o666&lt;/code&gt;, which the process umask narrows; rewriting a file with
&lt;code&gt;writeText&lt;/code&gt; or &lt;code&gt;writeBytes&lt;/code&gt; keeps the mode it has, so a file set to &lt;code&gt;0o600&lt;/code&gt; stays so. Where the
platforms differ the platform decides and the answer says so: macOS refuses the sticky bit on a
plain file to anyone but the superuser (an &lt;code&gt;Err&lt;/code&gt;, the mode unchanged), and Linux keeps it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A temporary directory is the program’s to remove.&lt;/strong&gt; &lt;code&gt;createTempDir&lt;/code&gt; makes the directory rather than
inventing a name, so no other program can take it in between, and nothing removes it at the end:
&lt;code&gt;removeDirAll&lt;/code&gt; is the call, or &lt;code&gt;tempDir&lt;/code&gt; and a &lt;code&gt;defer t.close()&lt;/code&gt; beside it, which removes it on every
way out of the block.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bytes are copied.&lt;/strong&gt; The array &lt;code&gt;readBytes&lt;/code&gt; answers is new, and changing it changes nothing on disk;
the array given to &lt;code&gt;writeBytes&lt;/code&gt; is read once and left as it was.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A listing is names, sorted.&lt;/strong&gt; &lt;code&gt;listDir&lt;/code&gt; answers each entry’s name alone, without the directory
before it, and leaves out &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;..&lt;/code&gt;; what is inside a subdirectory is not listed. The names are
sorted by code point, as strings order (&lt;a href=&quot;/spec/collections/#sorting&quot;&gt;collections&lt;/a&gt;), so &lt;code&gt;Zed&lt;/code&gt; comes
before &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt; before &lt;code&gt;a.txt&lt;/code&gt;, and a name beyond ASCII after both; two listings of an unchanged
directory agree, whatever order the file system keeps. A name that is not UTF-8 makes the whole
listing &lt;code&gt;InvalidUtf8&lt;/code&gt; rather than leaving that name out.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for name in fs.listDir(dir)?
  if name.endsWith(&amp;quot;.txt&amp;quot;) then println(name)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;paths&quot;&gt;Paths&lt;/h3&gt;
&lt;p&gt;A path is a &lt;code&gt;string&lt;/code&gt;, and &lt;code&gt;avin.fs&lt;/code&gt; has the functions that take one apart and put one together.
They answer from the text alone and touch no disk. Paths are POSIX: &lt;code&gt;/&lt;/code&gt; separates components, and a
path that starts with &lt;code&gt;/&lt;/code&gt; starts at the root.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.fs

backupOf(file: string) -&amp;gt; string
  val dir = fs.parent(file).getOrElse(&amp;quot;.&amp;quot;)
  val stem = fs.stem(file).getOrElse(&amp;quot;file&amp;quot;)
  fs.join([dir, &amp;quot;backup&amp;quot;, stem + &amp;quot;.bak&amp;quot;])
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isAbsolute(p)&lt;/code&gt;, &lt;code&gt;isRelative(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;p&lt;/code&gt; starts with &lt;code&gt;/&lt;/code&gt;; the empty path is relative.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;components(p) -&amp;gt; Vector[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The names between the separators, empty ones dropped: &lt;code&gt;/a//b/&lt;/code&gt; has &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;. The root is not a component; &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;..&lt;/code&gt; are kept.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;join(a, b) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;b&lt;/code&gt; after &lt;code&gt;a&lt;/code&gt; with exactly one &lt;code&gt;/&lt;/code&gt; between, however many &lt;code&gt;a&lt;/code&gt; ends with. An empty side adds nothing; an absolute &lt;code&gt;b&lt;/code&gt; replaces &lt;code&gt;a&lt;/code&gt;: &lt;code&gt;join(&amp;quot;/home/me&amp;quot;, &amp;quot;/etc&amp;quot;)&lt;/code&gt; is &lt;code&gt;/etc&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;join(parts) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;Vector[string]&lt;/code&gt; joined in turn by the same rule; empty for no parts.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parent(p) -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Everything above the last component: &lt;code&gt;/a/b&lt;/code&gt; has &lt;code&gt;/a&lt;/code&gt;, &lt;code&gt;/a&lt;/code&gt; has &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;a/b/&lt;/code&gt; has &lt;code&gt;a&lt;/code&gt;. The root, the empty path and a relative path of one component have &lt;code&gt;None&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fileName(p) -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The last component; &lt;code&gt;None&lt;/code&gt; for the root, the empty path, &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;..&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;extension(p) -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;What follows the last &lt;code&gt;.&lt;/code&gt; of the file name: &lt;code&gt;gz&lt;/code&gt; for &lt;code&gt;a.tar.gz&lt;/code&gt;, the empty string for &lt;code&gt;a.&lt;/code&gt;. &lt;code&gt;None&lt;/code&gt; with no dot, and for a name whose only dot is its first: &lt;code&gt;.profile&lt;/code&gt; has none, &lt;code&gt;.config.json&lt;/code&gt; has &lt;code&gt;json&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stem(p) -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The file name without its extension and its dot: &lt;code&gt;a.tar&lt;/code&gt; for &lt;code&gt;a.tar.gz&lt;/code&gt;, &lt;code&gt;.profile&lt;/code&gt; for &lt;code&gt;.profile&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;normalize(p) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;.&lt;/code&gt; and &lt;code&gt;..&lt;/code&gt; resolved in the text, doubled and trailing &lt;code&gt;/&lt;/code&gt; dropped. A &lt;code&gt;..&lt;/code&gt; at the root is dropped (&lt;code&gt;/..&lt;/code&gt; is &lt;code&gt;/&lt;/code&gt;), one leading a relative path is kept (&lt;code&gt;a/../..&lt;/code&gt; is &lt;code&gt;..&lt;/code&gt;), and a path that cancels to nothing is &lt;code&gt;/&lt;/code&gt; or &lt;code&gt;.&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;relativeTo(p, base) -&amp;gt; Option[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;p&lt;/code&gt; written from &lt;code&gt;base&lt;/code&gt;, both normalized: &lt;code&gt;../c&lt;/code&gt; for &lt;code&gt;/a/c&lt;/code&gt; from &lt;code&gt;/a/b&lt;/code&gt;, &lt;code&gt;.&lt;/code&gt; for a path from itself. &lt;code&gt;None&lt;/code&gt; when one is absolute and the other not, or when &lt;code&gt;base&lt;/code&gt; climbs above what it names with &lt;code&gt;..&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The questions below ask the file system.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;absolute(p) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;p&lt;/code&gt; from the root, normalized, a relative path read against the current directory. Links are not resolved.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;canonicalize(p) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The one absolute path the file system gives &lt;code&gt;p&lt;/code&gt;, every link resolved; &lt;code&gt;NotFound&lt;/code&gt; when nothing is there.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isLink(p) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;p&lt;/code&gt; is a symbolic link, dangling or not.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;symlink(target, link) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Makes &lt;code&gt;link&lt;/code&gt; a symbolic link holding &lt;code&gt;target&lt;/code&gt; as written; a relative target is read from the link’s directory. &lt;code&gt;AlreadyExists&lt;/code&gt; when something is at &lt;code&gt;link&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readLink(link) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;What a link holds, as written; a path that is not a link is an &lt;code&gt;Err&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;walker(root, …) -&amp;gt; Iterator[Result[Entry, IoError]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The entries of the tree at &lt;code&gt;root&lt;/code&gt;, read as the iterator advances, with the options described below.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;walk(root, …) -&amp;gt; Result[Vector[Entry], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same entries gathered, or the first &lt;code&gt;Err&lt;/code&gt; the walk meets.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;find(root, p, …) -&amp;gt; Result[Vector[string], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The paths of the entries below &lt;code&gt;root&lt;/code&gt; that the predicate &lt;code&gt;p&lt;/code&gt; is true for, or, when &lt;code&gt;p&lt;/code&gt; is a pattern, whose path relative to &lt;code&gt;root&lt;/code&gt; fits it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;matches(pattern, p) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;p&lt;/code&gt; fits the pattern, as described below.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;matcher(pattern) -&amp;gt; (string) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;matches&lt;/code&gt; for one pattern read once, to test many paths.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;glob(pattern) -&amp;gt; Vector[string]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The paths that exist and fit the pattern.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;normalize&lt;/code&gt; reads only the text, and the difference matters.&lt;/strong&gt; Where &lt;code&gt;a/lib&lt;/code&gt; is a link to
&lt;code&gt;src/lib&lt;/code&gt;, &lt;code&gt;normalize(&amp;quot;a/lib/../main.c&amp;quot;)&lt;/code&gt; is &lt;code&gt;a/main.c&lt;/code&gt;, while the file system climbs out of
&lt;code&gt;src/lib&lt;/code&gt; into &lt;code&gt;src&lt;/code&gt;: &lt;code&gt;canonicalize&lt;/code&gt; of the same path names &lt;code&gt;src/main.c&lt;/code&gt;. Whatever decides access to
a file is decided on &lt;code&gt;canonicalize&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A walk reads the tree as it goes, in a fixed order.&lt;/strong&gt; &lt;code&gt;walker&lt;/code&gt; answers an &lt;code&gt;Entry(path, relative, depth, isDir, isLink, error)&lt;/code&gt; for each file, directory and link below the root: &lt;code&gt;relative&lt;/code&gt; is the path
from the root and &lt;code&gt;path&lt;/code&gt; the root joined with it; &lt;code&gt;depth&lt;/code&gt; is 1 for the root’s own entries. Each
directory is listed when the walk reaches it, so taking the first entries of a huge tree lists only
the directories on the way to them. The order is depth first and each directory’s names in code-point
order, as &lt;code&gt;listDir&lt;/code&gt; sorts them, so two walks of an unchanged tree agree. &lt;code&gt;walk&lt;/code&gt; takes the same options
and gathers the entries into a vector; &lt;code&gt;find&lt;/code&gt; gathers the paths of those a predicate or a pattern
picks. Every option is named and has a default:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Option&lt;/th&gt;&lt;th&gt;Default&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;maxDepth&lt;/code&gt;&lt;/td&gt;&lt;td&gt;no limit&lt;/td&gt;&lt;td&gt;Entries deeper than this are left out; a directory at &lt;code&gt;maxDepth&lt;/code&gt; is an entry but is not listed. &lt;code&gt;0&lt;/code&gt; is the root alone; a negative one fails.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;includeRoot&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The root itself is an entry, with &lt;code&gt;relative&lt;/code&gt; empty and &lt;code&gt;depth&lt;/code&gt; 0.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;postOrder&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A directory comes after what it holds rather than before.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;followLinks&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A link that names a directory is gone into as the directory is.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;prune&lt;/code&gt;&lt;/td&gt;&lt;td&gt;nothing&lt;/td&gt;&lt;td&gt;A predicate asked about each directory the walk is about to go into, the root excepted; one it answers &lt;code&gt;true&lt;/code&gt; for is an entry, and nothing in it is.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stopOnError&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A directory the walk cannot go into ends it with that &lt;code&gt;Err&lt;/code&gt;, rather than being an entry that carries the reason.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;find&lt;/code&gt; takes every option but &lt;code&gt;includeRoot&lt;/code&gt; and &lt;code&gt;postOrder&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A symbolic link is listed and, unless &lt;code&gt;followLinks&lt;/code&gt; asks, never followed&lt;/strong&gt;: its &lt;code&gt;isLink&lt;/code&gt; is true and
its &lt;code&gt;isDir&lt;/code&gt; false, whatever it names, so a link back up the tree is one entry and not a loop. Followed,
a link naming a directory has &lt;code&gt;isLink&lt;/code&gt; and &lt;code&gt;isDir&lt;/code&gt; both true and is gone into, and one naming a
directory the walk is already inside, on its own way down from the root, is an entry whose &lt;code&gt;error&lt;/code&gt;
says &lt;code&gt;file system loop&lt;/code&gt; and is not gone into, so a link back up the tree ends the walk’s descent there.
Two links to one directory from elsewhere are both gone into. The root itself is followed when it is
a link.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A directory the walk cannot list is still an entry&lt;/strong&gt;, with &lt;code&gt;isDir&lt;/code&gt; true and the reason in &lt;code&gt;error&lt;/code&gt;
(for example &lt;code&gt;Some(PermissionDenied)&lt;/code&gt;), and the walk goes on past it; with &lt;code&gt;stopOnError&lt;/code&gt;, that reason
is an &lt;code&gt;Err&lt;/code&gt; instead, the walk’s last element, and &lt;code&gt;walk&lt;/code&gt; and &lt;code&gt;find&lt;/code&gt; answer it. A root that cannot be
listed is the walk’s one &lt;code&gt;Err&lt;/code&gt; either way: &lt;code&gt;NotFound&lt;/code&gt;, &lt;code&gt;NotADirectory&lt;/code&gt; or &lt;code&gt;PermissionDenied&lt;/code&gt;. A root
that is not a directory is &lt;code&gt;NotADirectory&lt;/code&gt;, unless &lt;code&gt;includeRoot&lt;/code&gt; asks for it, when it is the one entry.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.fs
import avin.io.IoError

sourcesIn(dir: string) -&amp;gt; Result[Vector[string], IoError] =
  fs.find(dir, &amp;quot;**/*.avin&amp;quot;, prune = e -&amp;gt; fs.fileName(e.path) == Some(&amp;quot;build&amp;quot;))

firstLarge(dir: string) -&amp;gt; Option[string] =
  fs.walker(dir).flatMap(r -&amp;gt; r.toOption).find(e -&amp;gt; !e.isDir &amp;amp;&amp;amp; fs.size(e.path).getOrElse(0) &amp;gt; 1000000).map(e -&amp;gt; e.path)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A pattern is matched component by component&lt;/strong&gt;, so doubled and trailing &lt;code&gt;/&lt;/code&gt; do not matter, and an
absolute pattern fits only an absolute path. Within a component:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Pattern&lt;/th&gt;&lt;th&gt;Fits&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;&lt;td&gt;any run of characters, none included&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;?&lt;/code&gt;&lt;/td&gt;&lt;td&gt;one character: &lt;code&gt;?.txt&lt;/code&gt; fits &lt;code&gt;文.txt&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;[abc]&lt;/code&gt;, &lt;code&gt;[a-z]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;one character of the set; &lt;code&gt;]&lt;/code&gt; first in the set, and &lt;code&gt;-&lt;/code&gt; first or last, are members&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;[!a-z]&lt;/code&gt;, &lt;code&gt;[^a-z]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;one character not in the set&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\x&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the character &lt;code&gt;x&lt;/code&gt; itself&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;**&lt;/code&gt;, as a whole component&lt;/td&gt;&lt;td&gt;any number of whole components, none included: &lt;code&gt;src/**/main.c&lt;/code&gt; fits &lt;code&gt;src/main.c&lt;/code&gt; and &lt;code&gt;src/a/b/main.c&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;{a,b}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;any one of the comma-separated alternatives, which may hold &lt;code&gt;/&lt;/code&gt;, wildcards and further braces: &lt;code&gt;src/{lib,test}/**/*.{c,h}&lt;/code&gt;; &lt;code&gt;{,x}&lt;/code&gt; fits the empty text too, and &lt;code&gt;{a}&lt;/code&gt; is &lt;code&gt;a&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Alternation is written out before anything else is read&lt;/strong&gt;: &lt;code&gt;x{a,b}{1,2}&lt;/code&gt; is the four patterns
&lt;code&gt;xa1&lt;/code&gt;, &lt;code&gt;xa2&lt;/code&gt;, &lt;code&gt;xb1&lt;/code&gt; and &lt;code&gt;xb2&lt;/code&gt;, and a path fits when it fits one of them. A brace escaped with &lt;code&gt;\&lt;/code&gt; or
inside a class (&lt;code&gt;[{]&lt;/code&gt;) is a literal character, and so is a &lt;code&gt;{&lt;/code&gt; with no closing &lt;code&gt;}&lt;/code&gt;; a &lt;code&gt;\,&lt;/code&gt; or a comma
inside a class is a literal comma inside an alternative.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A name starting with &lt;code&gt;.&lt;/code&gt; is hidden&lt;/strong&gt;: only a component that starts with a literal &lt;code&gt;.&lt;/code&gt; fits it, so
&lt;code&gt;*&lt;/code&gt; does not fit &lt;code&gt;.git&lt;/code&gt;, nor do &lt;code&gt;?git&lt;/code&gt; and &lt;code&gt;[.]git&lt;/code&gt;, while &lt;code&gt;.*&lt;/code&gt; and &lt;code&gt;\.git&lt;/code&gt; do; and &lt;code&gt;**&lt;/code&gt; never passes
through a hidden name, so &lt;code&gt;**/*.c&lt;/code&gt; stays out of &lt;code&gt;.git&lt;/code&gt;. &lt;code&gt;*/x&lt;/code&gt; does not fit &lt;code&gt;../x&lt;/code&gt;, for the same reason.
Each alternative is its own pattern here, so &lt;code&gt;{.git,src}&lt;/code&gt; fits &lt;code&gt;.git&lt;/code&gt;. A walk itself lists hidden names
like any other; only a pattern leaves them out, so &lt;code&gt;find(dir, &amp;quot;**/*.c&amp;quot;)&lt;/code&gt; skips them where
&lt;code&gt;find(dir, e -&amp;gt; !e.isDir)&lt;/code&gt; does not.
&lt;strong&gt;Every pattern is valid&lt;/strong&gt;: a &lt;code&gt;[&lt;/code&gt; with no closing &lt;code&gt;]&lt;/code&gt; is a literal &lt;code&gt;[&lt;/code&gt;, and a &lt;code&gt;\&lt;/code&gt; at the end a literal
&lt;code&gt;\&lt;/code&gt;. A &lt;code&gt;**&lt;/code&gt; inside a component, as in &lt;code&gt;a**b&lt;/code&gt;, is two &lt;code&gt;*&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;glob&lt;/code&gt; answers what is there.&lt;/strong&gt; A relative pattern is read from the current directory and answers
relative paths; an absolute one answers absolute paths. The answer is in code-point order, each path
once, and every path in it fits the pattern by &lt;code&gt;matches&lt;/code&gt;. A &lt;code&gt;**&lt;/code&gt; goes through directories as &lt;code&gt;walk&lt;/code&gt;
does, never through a link; a link a literal or wildcard component names is followed. A literal last
component answers a dangling link too. A directory that cannot be read contributes nothing: &lt;code&gt;glob&lt;/code&gt;
has no &lt;code&gt;Err&lt;/code&gt;. The empty pattern answers nothing, and &lt;code&gt;/&lt;/code&gt; answers &lt;code&gt;/&lt;/code&gt;. A pattern with alternatives is
globbed once for each and the answers merged, still sorted and each path once.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for file in fs.glob(&amp;quot;tests/**/*.avin&amp;quot;)
  println(file)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;open-files&quot;&gt;Open files&lt;/h3&gt;
&lt;p&gt;A file held open is a &lt;code&gt;File&lt;/code&gt;, for a program that reads or writes a file piece by piece, follows one
another program is writing, or adds to a log.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.fs
import avin.threads.sleep

follow(log: string) -&amp;gt; Result[unit, IoError]
  val f = fs.open(log)?
  f.seekToEnd()?
  while true
    f.readCompleteLine()? match
      Some(line) -&amp;gt; println(line)
      None -&amp;gt; sleep(250.millis)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;open(file) -&amp;gt; Result[File, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The existing file, for reading, at its start; &lt;code&gt;IsADirectory&lt;/code&gt; for a directory.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;create(file)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;For writing, made if it is not there and emptied if it is.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;append(file)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;For writing, made if it is not there; every write goes to the end, whatever other handles append to the same file.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;openUpdate(file)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The existing file, for reading and writing, keeping what it holds.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;createUpdate(file)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;For reading and writing, made if it is not there and emptied if it is.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readBytesFrom(file, offset) -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every byte from &lt;code&gt;offset&lt;/code&gt; on, empty at or past the end: what was appended since a program last read to &lt;code&gt;offset&lt;/code&gt;. A negative offset traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readTail(file, maxBytes) -&amp;gt; Result[string, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The last &lt;code&gt;maxBytes&lt;/code&gt; bytes as text, reading only those.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readTailLines(file, count) -&amp;gt; Result[Vector[string], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The last &lt;code&gt;count&lt;/code&gt; lines, without terminators, fewer where there are fewer.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method on &lt;code&gt;File&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;size()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes the file holds now, other handles’ writes included.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;position()&lt;/code&gt;, &lt;code&gt;seek(offset)&lt;/code&gt;, &lt;code&gt;seekToEnd()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The position counted from the start; &lt;code&gt;seek&lt;/code&gt; past the end is allowed (a read there is empty, a write leaves zero bytes between), a negative offset is an &lt;code&gt;Err&lt;/code&gt;; &lt;code&gt;seekToEnd&lt;/code&gt; goes to the end as it is now.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;read(max)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Up to &lt;code&gt;max&lt;/code&gt; bytes, fewer only at the end of the file; empty at the end. Negative &lt;code&gt;max&lt;/code&gt; traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readAll()&lt;/code&gt;, &lt;code&gt;readText()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The rest of the file as bytes, or as text (&lt;code&gt;InvalidUtf8&lt;/code&gt;, the offset counted from the position the read began at).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readLine()&lt;/code&gt;, &lt;code&gt;readCompleteLine()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The next line, &lt;code&gt;None&lt;/code&gt; at the end. &lt;code&gt;readLine&lt;/code&gt; also answers a last line with no &lt;code&gt;\n&lt;/code&gt;; &lt;code&gt;readCompleteLine&lt;/code&gt; answers only a line ended by &lt;code&gt;\n&lt;/code&gt;, and leaves later bytes unread, so a line another program is still writing arrives whole.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;write(bytes)&lt;/code&gt;, &lt;code&gt;writeText(text)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes at the position, buffered. A file is an &lt;a href=&quot;#bytewriter&quot;&gt;&lt;code&gt;io.ByteWriter&lt;/code&gt;&lt;/a&gt; by &lt;code&gt;write&lt;/code&gt;, and an &lt;a href=&quot;#reader&quot;&gt;&lt;code&gt;io.Reader&lt;/code&gt;&lt;/a&gt; by &lt;code&gt;read&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flush()&lt;/code&gt;, &lt;code&gt;close()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;flush&lt;/code&gt; hands what is written to the platform, so other handles and programs see it. &lt;code&gt;close&lt;/code&gt; flushes and releases, answering the flush’s &lt;code&gt;Err&lt;/code&gt;; closing twice is fine and answers &lt;code&gt;Ok&lt;/code&gt;. A file is an &lt;a href=&quot;#close&quot;&gt;&lt;code&gt;io.Close&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readAt(offset, max)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Up to &lt;code&gt;max&lt;/code&gt; bytes from &lt;code&gt;offset&lt;/code&gt;, &lt;strong&gt;without moving the position&lt;/strong&gt;: fewer only where the file ends first, empty at or past the end. What this handle has written is included. A negative &lt;code&gt;offset&lt;/code&gt; or &lt;code&gt;max&lt;/code&gt; is an &lt;code&gt;Err&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writeAt(offset, bytes)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Writes all of &lt;code&gt;bytes&lt;/code&gt; at &lt;code&gt;offset&lt;/code&gt;, &lt;strong&gt;without moving the position&lt;/strong&gt;; past the end the file grows, the gap reading as zeros. A handle opened to &lt;code&gt;append&lt;/code&gt; may put the bytes at the end whatever the offset, as the platform decides. A negative &lt;code&gt;offset&lt;/code&gt; is an &lt;code&gt;Err&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setLength(length)&lt;/code&gt;, &lt;code&gt;truncate(length)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Cuts the file to &lt;code&gt;length&lt;/code&gt; bytes or extends it with zeros; the position does not move and may end up past the end. A negative length, or a file not open for writing, is an &lt;code&gt;Err&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sync()&lt;/code&gt;, &lt;code&gt;syncData()&lt;/code&gt;, &lt;code&gt;fullSync()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Hands over what is written and asks the device to keep it. &lt;code&gt;syncData&lt;/code&gt; skips details a reader of the contents does not need where the platform can; on macOS it is &lt;code&gt;sync&lt;/code&gt;, which reaches the drive but not its write cache. &lt;code&gt;fullSync&lt;/code&gt; also empties the drive’s cache (&lt;code&gt;F_FULLFSYNC&lt;/code&gt; on macOS) and is the slowest. A closed file is an &lt;code&gt;Err&lt;/code&gt;; a file opened only to read may be synced.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;deleteOnClose()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Marks the file so &lt;code&gt;close&lt;/code&gt; removes its name after releasing it; a failed removal is the &lt;code&gt;Err&lt;/code&gt; of &lt;code&gt;close&lt;/code&gt;. A file the collector frees without a &lt;code&gt;close&lt;/code&gt; is not removed.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Positioned calls on one file from several lightweight threads belong to separate handles, one per
thread, opened on the same path: each call is the platform’s own positioned read or write, so
disjoint ranges written at once come out as written.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;One position serves reading and writing&lt;/strong&gt;, and lines, &lt;code&gt;read&lt;/code&gt; and &lt;code&gt;position&lt;/code&gt; agree on it: bytes the
file has buffered ahead are never lost to a &lt;code&gt;seek&lt;/code&gt;, a &lt;code&gt;write&lt;/code&gt; or a &lt;code&gt;read&lt;/code&gt;. &lt;strong&gt;A read at the end does
not end the file’s life&lt;/strong&gt;: a file that grew meanwhile gives the new bytes to the next read, so no
reopening is needed to follow it. &lt;strong&gt;A file closed by &lt;code&gt;close&lt;/code&gt; answers every call with an &lt;code&gt;Err&lt;/code&gt;&lt;/strong&gt;, as does
reading a file opened only to write and writing one opened only to read; none of them is an empty
answer that looks like the end of the file. A forgotten file is closed when the collector frees it. A
file belongs to the thread that opened it and is not handed to another. Calls that read and write wait
as the calls of &lt;code&gt;avin.fs&lt;/code&gt; above do, which is to say they do not park a lightweight thread.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A tail starts at a whole character.&lt;/strong&gt; When &lt;code&gt;readTail&lt;/code&gt; begins in the middle of a UTF-8 sequence it
skips the rest of that sequence, so the text never starts with a stray byte; bytes that are not UTF-8
elsewhere become U+FFFD, since a log’s last lines are read to be looked at and not to be refused.
Lines are decoded the same way, a &lt;code&gt;\r&lt;/code&gt; before the &lt;code&gt;\n&lt;/code&gt; going with it.&lt;/p&gt;
&lt;h2 id=&quot;avin-time&quot;&gt;&lt;code&gt;avin.time&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Clocks, lengths of time, the calendar and time zones, in eight types: &lt;code&gt;Instant&lt;/code&gt; (a point on the
timeline), &lt;code&gt;Duration&lt;/code&gt; (an exact length), &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt; and &lt;code&gt;DateTime&lt;/code&gt; (calendar readings with no
zone), &lt;code&gt;Zone&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt; (a reading in a zone) and &lt;code&gt;Period&lt;/code&gt; (months and days). &lt;code&gt;now()&lt;/code&gt; reads the wall
clock as an &lt;code&gt;Instant&lt;/code&gt;; &lt;code&gt;monotonic()&lt;/code&gt; reads the monotonic clock as a &lt;code&gt;Duration&lt;/code&gt;, so an elapsed time is
&lt;code&gt;monotonic() - start&lt;/code&gt;. The module has a chapter of its own: &lt;a href=&quot;/spec/time/&quot;&gt;dates and times&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.time

val start = time.monotonic()
work()
println(s&amp;quot;took ${time.monotonic() - start}&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;avin-math&quot;&gt;&lt;code&gt;avin.math&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The elementary functions on &lt;code&gt;real&lt;/code&gt;, and the constants &lt;code&gt;Pi&lt;/code&gt; and &lt;code&gt;E&lt;/code&gt;. They are functions
of the module rather than methods, called through it or imported by name:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.math
import avin.math.{Pi, sqrt}

main()
  println(sqrt(2.0))
  println(math.atan2(1.0, -1.0) / Pi)
  println(math.log(0.0))
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sqrt(x)&lt;/code&gt;, &lt;code&gt;cbrt(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The square root, NaN for a negative &lt;code&gt;x&lt;/code&gt;; the cube root, negative for a negative &lt;code&gt;x&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exp(x)&lt;/code&gt;, &lt;code&gt;expm1(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;E&lt;/code&gt; to the power &lt;code&gt;x&lt;/code&gt;; &lt;code&gt;exp(x) - 1.0&lt;/code&gt;, accurate near zero.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;log(x)&lt;/code&gt;, &lt;code&gt;log10(x)&lt;/code&gt;, &lt;code&gt;log1p(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The natural logarithm; to base 10; &lt;code&gt;log(1.0 + x)&lt;/code&gt;, accurate near zero. Negative infinity at zero, NaN below it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pow(x, y)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; to the power &lt;code&gt;y&lt;/code&gt;. &lt;code&gt;pow(x, 0.0)&lt;/code&gt; is &lt;code&gt;1.0&lt;/code&gt; for every &lt;code&gt;x&lt;/code&gt;, NaN included; a negative &lt;code&gt;x&lt;/code&gt; with a &lt;code&gt;y&lt;/code&gt; that is not whole is NaN.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hypot(x, y)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;sqrt(x * x + y * y)&lt;/code&gt;, without overflow or underflow on the way.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sin(x)&lt;/code&gt;, &lt;code&gt;cos(x)&lt;/code&gt;, &lt;code&gt;tan(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Of an angle in radians.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;asin(x)&lt;/code&gt;, &lt;code&gt;acos(x)&lt;/code&gt;, &lt;code&gt;atan(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The angle in radians: &lt;code&gt;asin&lt;/code&gt; and &lt;code&gt;atan&lt;/code&gt; from &lt;code&gt;-Pi / 2&lt;/code&gt; to &lt;code&gt;Pi / 2&lt;/code&gt;, &lt;code&gt;acos&lt;/code&gt; from &lt;code&gt;0.0&lt;/code&gt; to &lt;code&gt;Pi&lt;/code&gt;; NaN outside &lt;code&gt;-1.0&lt;/code&gt; to &lt;code&gt;1.0&lt;/code&gt; for the first two.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;atan2(y, x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The angle in radians, from &lt;code&gt;-Pi&lt;/code&gt; to &lt;code&gt;Pi&lt;/code&gt;, of the point &lt;code&gt;(x, y)&lt;/code&gt;; &lt;code&gt;y&lt;/code&gt; comes first.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sinh(x)&lt;/code&gt;, &lt;code&gt;cosh(x)&lt;/code&gt;, &lt;code&gt;tanh(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The hyperbolic functions.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;floor(x)&lt;/code&gt;, &lt;code&gt;ceil(x)&lt;/code&gt;, &lt;code&gt;rint(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The whole number below, above, or nearest, as a &lt;code&gt;real&lt;/code&gt;; &lt;code&gt;rint&lt;/code&gt; takes a tie to the even one, so &lt;code&gt;rint(2.5)&lt;/code&gt; is &lt;code&gt;2.0&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;abs(x)&lt;/code&gt;, &lt;code&gt;signum(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The magnitude, &lt;code&gt;abs(-0.0)&lt;/code&gt; being &lt;code&gt;0.0&lt;/code&gt;; &lt;code&gt;1.0&lt;/code&gt;, &lt;code&gt;-1.0&lt;/code&gt;, or &lt;code&gt;x&lt;/code&gt; itself for a zero or NaN.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;max(x, y)&lt;/code&gt;, &lt;code&gt;min(x, y)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;NaN when either is; &lt;code&gt;-0.0&lt;/code&gt; is less than &lt;code&gt;0.0&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toRadians(x)&lt;/code&gt;, &lt;code&gt;toDegrees(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An angle converted.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;round(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The whole number nearest &lt;code&gt;x&lt;/code&gt; as a &lt;code&gt;long&lt;/code&gt;, a tie going away from zero: &lt;code&gt;round(2.5)&lt;/code&gt; is &lt;code&gt;3&lt;/code&gt;, &lt;code&gt;round(-2.5)&lt;/code&gt; is &lt;code&gt;-3&lt;/code&gt;. It converts as &lt;code&gt;long(x)&lt;/code&gt; does: NaN is &lt;code&gt;0&lt;/code&gt;, a value past the range, an infinity included, is the nearest bound.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;trunc(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; with its fraction dropped, towards zero, as a &lt;code&gt;real&lt;/code&gt;; &lt;code&gt;trunc(-0.5)&lt;/code&gt; is &lt;code&gt;-0.0&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;log2(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The logarithm to base 2, exact at every power of two.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fma(x, y, z)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x * y + z&lt;/code&gt; rounded once. The language never fuses &lt;code&gt;x * y + z&lt;/code&gt; by itself, so &lt;code&gt;fma&lt;/code&gt; is how a program asks for it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;copySign(x, s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The magnitude of &lt;code&gt;x&lt;/code&gt; with the sign of &lt;code&gt;s&lt;/code&gt;, a negative zero’s sign included.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;signBit(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether the sign bit of &lt;code&gt;x&lt;/code&gt; is set: &lt;code&gt;true&lt;/code&gt; for a negative value, a negative zero and a negated NaN.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ulp(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The gap from &lt;code&gt;abs(x)&lt;/code&gt; to the next &lt;code&gt;real&lt;/code&gt; above: &lt;code&gt;real.MinPositiveValue&lt;/code&gt; at zero and through the subnormals, infinity at an infinity, NaN at NaN, and at the greatest finite value the gap below it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextUp(x)&lt;/code&gt;, &lt;code&gt;nextDown(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The next &lt;code&gt;real&lt;/code&gt; above, or below: &lt;code&gt;nextUp(0.0)&lt;/code&gt; is &lt;code&gt;real.MinPositiveValue&lt;/code&gt;, the greatest finite value goes to infinity, and an infinity going outward and NaN stay as they are.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Nothing traps.&lt;/strong&gt; Every function follows IEEE 754: an argument outside a function’s domain gives
NaN, a pole gives the infinity its limit approaches, and the infinities go where their limits do
(&lt;code&gt;sqrt&lt;/code&gt; of positive infinity is positive infinity, &lt;code&gt;exp&lt;/code&gt; of negative infinity is &lt;code&gt;0.0&lt;/code&gt;). The limits
of &lt;code&gt;real&lt;/code&gt; itself, its infinities and NaN, are on the type: &lt;code&gt;real.PositiveInfinity&lt;/code&gt;, &lt;code&gt;real.NaN&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;avin-random&quot;&gt;&lt;code&gt;avin.random&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Pseudo-random numbers: a generator a program seeds to replay a run, or lets the platform
seed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.random.Random

main()
  val dice = Random(42)
  println(dice.between(1, 7))
  println(Random.nextInt(100))
  println(Random.shuffle([1, 2, 3, 4]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Random(seed: long)&lt;/code&gt; is a generator whose numbers are fixed by its seed, the same on every platform
and in every release; &lt;code&gt;Random()&lt;/code&gt; is seeded by the platform, differently each time.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextInt() -&amp;gt; int&lt;/code&gt;, &lt;code&gt;nextLong() -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any value of the type, each equally likely.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextInt(bound: int) -&amp;gt; int&lt;/code&gt;, &lt;code&gt;nextLong(bound: long) -&amp;gt; long&lt;/code&gt;&lt;/td&gt;&lt;td&gt;From &lt;code&gt;0&lt;/code&gt; up to &lt;code&gt;bound&lt;/code&gt;, not including it; a bound that is not positive traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;between(min, max)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;From &lt;code&gt;min&lt;/code&gt; up to &lt;code&gt;max&lt;/code&gt;, not including it, for &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt;; &lt;code&gt;min &amp;gt;= max&lt;/code&gt; traps, and for &lt;code&gt;real&lt;/code&gt; so do a NaN bound and an infinite &lt;code&gt;max - min&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextReal() -&amp;gt; real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;From &lt;code&gt;0.0&lt;/code&gt; up to &lt;code&gt;1.0&lt;/code&gt;, not including it, every multiple of 2^-53 equally likely.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextBoolean() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;, equally likely.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextGaussian() -&amp;gt; real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Normally distributed, mean &lt;code&gt;0.0&lt;/code&gt; and standard deviation &lt;code&gt;1.0&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextBytes(n: int) -&amp;gt; Array[byte]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A new array of &lt;code&gt;n&lt;/code&gt; bytes; a negative &lt;code&gt;n&lt;/code&gt; traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;alphanumeric() -&amp;gt; Iterator[char]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An endless run of characters from &lt;code&gt;A&lt;/code&gt;–&lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;–&lt;code&gt;z&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;9&lt;/code&gt;, equally likely.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;shuffle[T](xs: Iterable[T]) -&amp;gt; Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The elements in a new order, every order equally likely.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;choose[T](items: Seq[T]) -&amp;gt; T&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One of the items, each equally likely; an empty sequence traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;chooseWeighted(weights: Seq[real]) -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An index, with probability proportional to its weight; a zero weight is never chosen. An empty sequence, a negative, NaN or infinite weight, and weights whose sum is zero or overflows trap.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;chooseWeighted[T](pairs: Seq[(T, real)]) -&amp;gt; T&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The first of a pair, chosen by the second as above.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;setSeed(seed: long)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Starts the generator again as &lt;code&gt;Random(seed)&lt;/code&gt; would.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Repeated draws from one distribution use &lt;code&gt;Weighted&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;Weighted(pairs)&lt;/code&gt; keeps the running totals
of the weights, built once with the same checks, and &lt;code&gt;sample(rng)&lt;/code&gt; draws an item by binary search, in
O(log n); it draws exactly as &lt;code&gt;rng.chooseWeighted(pairs)&lt;/code&gt; would. &lt;code&gt;size&lt;/code&gt; is the number of items.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val weather = Weighted([(&amp;quot;sun&amp;quot;, 6.0), (&amp;quot;rain&amp;quot;, 3.0), (&amp;quot;snow&amp;quot;, 1.0)])
val rng = Random(7)
println(weather.sample(rng))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A chain is a weights row per state: &lt;code&gt;state = rng.chooseWeighted(rows(state))&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The companion is a generator too.&lt;/strong&gt; &lt;code&gt;Random.nextInt(100)&lt;/code&gt; and every other method called on
&lt;code&gt;Random&lt;/code&gt; itself use one generator the program shares, seeded by the platform on first use and safe to
call from any thread. A &lt;code&gt;Random&lt;/code&gt; a program makes is its own: it takes no lock, so threads that share
one share it through a &lt;code&gt;Mutex&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The generator is named.&lt;/strong&gt; It is PCG32 (PCG-XSH-RR, 64 bits of state, 32 of output) on the
reference implementation’s stream 54, seeded as the reference seeds it, so a seeded run can be checked
against the published algorithm: &lt;code&gt;Random(42).nextInt()&lt;/code&gt; is its first published output, &lt;code&gt;0xa15c02b7&lt;/code&gt;,
which as an &lt;code&gt;int&lt;/code&gt; is &lt;code&gt;-1587805513&lt;/code&gt;. A &lt;code&gt;long&lt;/code&gt; is two draws, the first the high half. A bound is reached without bias, by rejection rather
than a remainder. &lt;strong&gt;None of this is fit for secrets&lt;/strong&gt;: anyone who sees a few outputs can compute the
rest, so a key, a token or a password is never taken from it. Those come from &lt;code&gt;SecureRandom&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;securerandom&quot;&gt;&lt;code&gt;SecureRandom&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.random.SecureRandom

main()
  val session = SecureRandom.urlToken()
  val key = SecureRandom.nextBytes(32)
  println(SecureRandom.between(0, 10000))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;SecureRandom&lt;/code&gt; is random numbers fit for secrets.&lt;/strong&gt; Every draw is read from the operating system’s
cryptographic generator (&lt;code&gt;getentropy&lt;/code&gt;, on macOS, Linux and the BSDs), so no number of outputs says
anything about the next. It is an object, not a class: there is no seed, nothing to replay, and no
state, so any thread may call it at once. Where the operating system gives no bytes, the draw traps,
since nothing could stand in for them.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextBytes(n: int) -&amp;gt; Array[byte]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A new array of &lt;code&gt;n&lt;/code&gt; bytes, any count, past the system’s 256-byte request limit included; a negative &lt;code&gt;n&lt;/code&gt; traps.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hexToken(byteCount: int = 32) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;byteCount&lt;/code&gt; random bytes as lower-case hexadecimal, two digits a byte: 64 characters by default.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;urlToken(byteCount: int = 32) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;byteCount&lt;/code&gt; random bytes as unpadded base64url, which a URL, a header, a cookie and a file name carry as it is: 43 characters by default.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;nextInt()&lt;/code&gt;, &lt;code&gt;nextLong()&lt;/code&gt;, &lt;code&gt;nextInt(bound)&lt;/code&gt;, &lt;code&gt;nextLong(bound)&lt;/code&gt;, &lt;code&gt;between(min, max)&lt;/code&gt; for &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;nextReal()&lt;/code&gt;, &lt;code&gt;nextBoolean()&lt;/code&gt;, &lt;code&gt;alphanumeric()&lt;/code&gt;, &lt;code&gt;shuffle(xs)&lt;/code&gt;, &lt;code&gt;choose(items)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;Random&lt;/code&gt;‘s, with the same bounds, the same traps and no bias.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;32 bytes is 256 bits, beyond any guessing. &lt;code&gt;SecureRandom&lt;/code&gt; has no &lt;code&gt;nextGaussian&lt;/code&gt;, &lt;code&gt;chooseWeighted&lt;/code&gt; or
&lt;code&gt;setSeed&lt;/code&gt;: no secret is drawn from those distributions, and there is no seed to set.&lt;/p&gt;
&lt;h2 id=&quot;avin-crypto&quot;&gt;&lt;code&gt;avin.crypto&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Content digests and keyed digests: SHA-256, SHA-512, SHA-1 and MD5, HMAC over the first two,
PBKDF2, comparison of secrets in constant time, SASLprep for passwords, and hexadecimal text for any
digest.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.crypto.{sha256, hmacSha256, toHex, Sha256}

main()
  println(toHex(sha256(&amp;quot;abc&amp;quot;)))
  println(toHex(hmacSha256(&amp;quot;key&amp;quot;, &amp;quot;message&amp;quot;)))
  val file = Sha256()
  file.update(&amp;quot;a piece&amp;quot;)
  file.update(&amp;quot;and another&amp;quot;)
  println(toHex(file.finish()))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A digest is a &lt;code&gt;Vector[byte]&lt;/code&gt;, the bytes the standard defines, so it compares by value, can key a map
or a cache, and is written as text only on request. Text is hashed as its UTF-8 bytes.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sha256(x)&lt;/code&gt;, &lt;code&gt;sha512(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The 32-byte and 64-byte digest of &lt;code&gt;x&lt;/code&gt;, a &lt;code&gt;Vector[byte]&lt;/code&gt; or a &lt;code&gt;string&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sha1(x)&lt;/code&gt;, &lt;code&gt;md5(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The 20-byte and 16-byte digest of &lt;code&gt;x&lt;/code&gt;. &lt;strong&gt;Broken for security&lt;/strong&gt; (below).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hmacSha256(key, message)&lt;/code&gt;, &lt;code&gt;hmacSha512(key, message)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The 32-byte and 64-byte HMAC (RFC 2104) of &lt;code&gt;message&lt;/code&gt; under &lt;code&gt;key&lt;/code&gt;, both &lt;code&gt;Vector[byte]&lt;/code&gt; or both &lt;code&gt;string&lt;/code&gt;. Any key length is allowed, the empty key included; one longer than the algorithm’s block is hashed first, as the RFC says.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pbkdf2HmacSha256(password, salt, iterations, length)&lt;/code&gt;, &lt;code&gt;pbkdf2HmacSha512(...)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;length&lt;/code&gt; bytes of key (RFC 8018 PBKDF2 over HMAC-SHA-256 or -SHA-512) as a &lt;code&gt;Vector[byte]&lt;/code&gt;; &lt;code&gt;password&lt;/code&gt; and &lt;code&gt;salt&lt;/code&gt; both &lt;code&gt;Vector[byte]&lt;/code&gt; or both &lt;code&gt;string&lt;/code&gt; (UTF-8), either empty. &lt;code&gt;iterations&lt;/code&gt; below 1, &lt;code&gt;length&lt;/code&gt; below 1, or &lt;code&gt;length&lt;/code&gt; over 8160 (SHA-256) or 16320 (SHA-512) trap.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;constantTimeEquals(a, b) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, both &lt;code&gt;Vector[byte]&lt;/code&gt; or both &lt;code&gt;string&lt;/code&gt; (compared as UTF-8 bytes), are the same, taking as long wherever they first differ. Different lengths answer &lt;code&gt;false&lt;/code&gt; at once.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toHex(bytes) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lower-case hexadecimal, two digits for each byte: &lt;a href=&quot;#avinencoding&quot;&gt;&lt;code&gt;avin.encoding&lt;/code&gt;&lt;/a&gt;‘s, which this module offers too.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A hasher takes its input in pieces&lt;/strong&gt;, for data too large to hold whole, such as a file read in
chunks. &lt;code&gt;Sha256()&lt;/code&gt;, &lt;code&gt;Sha512()&lt;/code&gt;, &lt;code&gt;Sha1()&lt;/code&gt; and &lt;code&gt;Md5()&lt;/code&gt; each have &lt;code&gt;update(bytes)&lt;/code&gt; and &lt;code&gt;update(text)&lt;/code&gt;,
any number of times, and &lt;code&gt;finish()&lt;/code&gt;, the digest of everything added. &lt;code&gt;finish()&lt;/code&gt; answers the same
digest each time it is called, and &lt;code&gt;update&lt;/code&gt; after &lt;code&gt;finish&lt;/code&gt; traps. Hashing in any pieces gives the
one-shot digest. A hasher belongs to the thread that made it, as a handle does.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;sha1&lt;/code&gt; and &lt;code&gt;md5&lt;/code&gt; are for formats that already use them&lt;/strong&gt;: a checksum in a listing, a cache key
nobody attacks. Two different inputs with the same digest can be made for both, so neither signs,
authenticates or names untrusted content; use &lt;code&gt;sha256&lt;/code&gt; or &lt;code&gt;sha512&lt;/code&gt; for those. HMAC does not rest on
collision resistance, but only the SHA-2 variants are offered.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A secret someone sent is compared with &lt;code&gt;constantTimeEquals&lt;/code&gt;, never with &lt;code&gt;==&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;==&lt;/code&gt; stops at the
first byte that differs, so how long a rejection takes tells a patient attacker how much of a guessed
MAC tag, bearer token or password digest was right, and lets the guess be built a byte at a time.
&lt;code&gt;constantTimeEquals&lt;/code&gt; reads every byte and decides once, at the end. A length is not the secret, so
different lengths answer at once. For two digests of public data, &lt;code&gt;==&lt;/code&gt; is fine.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val expected = hmacSha256(key, body)
val ok = fromBase64(header) match
  Ok(sent) -&amp;gt; constantTimeEquals(sent, expected)
  Err(_) -&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The iteration count belongs to the protocol&lt;/strong&gt;: SCRAM-SHA-256 (PostgreSQL, MongoDB) sends it, and a
client using its own derives a different key. It buys the cost of guessing a password and nothing
else.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val salted = pbkdf2HmacSha256(password, salt, iterations, 32)
val clientKey = hmacSha256(salted, &amp;quot;Client Key&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;SCRAM prepares the password with SASLprep before deriving its key&lt;/strong&gt;, so that the same password
typed on two machines, as two sequences of characters, gives one key. &lt;code&gt;saslPrep(text) -&amp;gt; Option[string]&lt;/code&gt; is RFC 4013’s profile of stringprep (RFC 3454): each space other than U+0020
becomes U+0020 and the characters mapped to nothing (the soft hyphen, the zero-width joiners, the
variation selectors) are removed; the result is put in normalization form
&lt;a href=&quot;/spec/types/#normalization&quot;&gt;NFKC&lt;/a&gt;; and it is &lt;code&gt;None&lt;/code&gt; where that holds a prohibited character
(controls, private use, non-characters, the characters that change the display direction, tags),
a code point unassigned in Unicode 3.2 (the RFC’s version, as for a stored string), or right-to-left
text that also holds a left-to-right character or does not begin and end with a right-to-left one.
The tables are the RFC’s, held as Unicode 3.2 fixed them; normalization is by the current Unicode
Character Database, which differs from 3.2’s only for a few CJK compatibility ideographs Unicode
has corrected since.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.crypto.saslPrep

main()
  println(saslPrep(&amp;quot;I\u{ad}X&amp;quot;)) // Some(IX)
  println(saslPrep(&amp;quot;\u{2168}&amp;quot;)) // Some(IX)
  println(saslPrep(&amp;quot;pass\u{a0}word&amp;quot;)) // Some(pass word)
  println(saslPrep(&amp;quot;\u{7}&amp;quot;)) // None
  println(saslPrep(&amp;quot;\u{627}1&amp;quot;)) // None
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Some(IX)
Some(IX)
Some(pass word)
None
None
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;PostgreSQL’s client falls back to the password as it was written where SASLprep refuses it, and so
may a client written with this: &lt;code&gt;saslPrep(password).getOrElse(password)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The digests, the key derivation and the comparison are bound to Sysl’s &lt;code&gt;sysl.crypto&lt;/code&gt;, so they are the
same code Sysl programs use.&lt;/p&gt;
&lt;h2 id=&quot;avin-uuid&quot;&gt;&lt;code&gt;avin.uuid&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Universally unique identifiers (RFC 9562), 128 bits written as 32 hexadecimal digits in groups of
8-4-4-4-12.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.uuid.Uuid

main()
  val id = Uuid.random()
  println(id)
  assertEq(Uuid.parse(id.toString()), Some(id))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Uuid&lt;/code&gt; is a value: it compares and hashes by its bits, orders by them as sixteen unsigned bytes
(the first most significant), is a &lt;code&gt;Map&lt;/code&gt; key as it stands, and is &lt;code&gt;Sendable&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Uuid.random()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A version 4 identifier from &lt;code&gt;SecureRandom&lt;/code&gt;, with the version and variant bits set.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Uuid.parse(text) -&amp;gt; Option[Uuid]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The canonical 8-4-4-4-12 form in either case; &lt;code&gt;None&lt;/code&gt; for anything else (braces, a &lt;code&gt;urn:uuid:&lt;/code&gt; prefix, missing hyphens and white space are not accepted).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Uuid.fromBytes(bytes) -&amp;gt; Option[Uuid]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sixteen bytes, the first most significant; &lt;code&gt;None&lt;/code&gt; for any other length.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Uuid.Nil&lt;/code&gt;, &lt;code&gt;Uuid.Max&lt;/code&gt;&lt;/td&gt;&lt;td&gt;All zero bits and all one bits.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;bytes()&lt;/code&gt;, &lt;code&gt;toString()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The sixteen bytes, and the lower-case canonical text.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;version()&lt;/code&gt;, &lt;code&gt;variant()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The version (0 to 15), and the variant: 2 for RFC 9562’s layout, 0, 6 and 7 for the reserved ones.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A &lt;code&gt;Uuid&lt;/code&gt; implements &lt;code&gt;FromParam&lt;/code&gt; in &lt;a href=&quot;#avinnethttp&quot;&gt;&lt;code&gt;avin.net.http&lt;/code&gt;&lt;/a&gt;, so &lt;code&gt;paramAs[Uuid]&lt;/code&gt; and
&lt;code&gt;queryAs[Uuid]&lt;/code&gt; read one from a route or query parameter, an invalid one answering &lt;code&gt;400&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;avin-diff&quot;&gt;&lt;code&gt;avin.diff&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The differences between two sequences, found with Myers’ O(ND) algorithm in its linear-space form
(the search runs from both ends until the paths meet in a middle snake, which splits the problem in
two), so the memory used is proportional to the sizes of the inputs and the time to their sizes times
the number D of differences. The script is a shortest one; a run of changes lists its deletes before
its inserts, as &lt;code&gt;diff -u&lt;/code&gt; prints them.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.diff.{diff, apply, unifiedDiff}

main()
  val edits = diff([1, 2, 3, 4], [1, 3, 4, 5])
  assertEq(apply([1, 2, 3, 4], edits), [1, 3, 4, 5])
  print(unifiedDiff(&amp;quot;a\nb\n&amp;quot;, &amp;quot;a\nc\n&amp;quot;, &amp;quot;old.txt&amp;quot;, &amp;quot;new.txt&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Edit[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Keep(value)&lt;/code&gt;, &lt;code&gt;Insert(value)&lt;/code&gt; or &lt;code&gt;Delete(value)&lt;/code&gt;; a &lt;code&gt;Keep&lt;/code&gt; holds the element of the first sequence.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;diff[T: Eq](a, b) -&amp;gt; Vector[Edit[T]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The shortest script turning &lt;code&gt;a&lt;/code&gt; into &lt;code&gt;b&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;apply(a, edits) -&amp;gt; Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The sequence the edits make of &lt;code&gt;a&lt;/code&gt;; traps, naming the edit, where a &lt;code&gt;Keep&lt;/code&gt; or &lt;code&gt;Delete&lt;/code&gt; does not match the next element of &lt;code&gt;a&lt;/code&gt;, or where &lt;code&gt;a&lt;/code&gt; is not used up.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;changes(edits) -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number of inserts and deletes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Line(text, terminated)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A line without its &lt;code&gt;\n&lt;/code&gt;, and whether one ended it; only a text’s last line can be unterminated. A &lt;code&gt;\r&lt;/code&gt; stays in the line.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;splitLines(text)&lt;/code&gt;, &lt;code&gt;joinLines(lines)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Text to lines and back; &lt;code&gt;joinLines(splitLines(t))&lt;/code&gt; is &lt;code&gt;t&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;LineOptions(ignoreTrailingSpace = false, finalNewline = true)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Ignore white space (a &lt;code&gt;\r&lt;/code&gt; too) at the ends of lines; with &lt;code&gt;finalNewline&lt;/code&gt; a last line with no &lt;code&gt;\n&lt;/code&gt; differs from the same line with one, as in &lt;code&gt;diff&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;diffLines(a, b, options) -&amp;gt; Vector[Edit[Line]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The shortest script over the lines of two texts.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Hunk(aStart, aCount, bStart, bCount, edits)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A hunk, the starts 0-based.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hunks(edits, context) -&amp;gt; Vector[Hunk[T]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Each run of changes with &lt;code&gt;context&lt;/code&gt; unchanged elements on either side; runs with no more than &lt;code&gt;2 * context&lt;/code&gt; unchanged elements between them share a hunk. Traps on a negative &lt;code&gt;context&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;renderUnified(edits, fromName, toName, context = 3) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The edits of lines as &lt;code&gt;diff -u&lt;/code&gt; writes them: &lt;code&gt;---&lt;/code&gt; and &lt;code&gt;+++&lt;/code&gt; headers, &lt;code&gt;@@ -a,b +c,d @@&lt;/code&gt; (a count of 1 left out, an empty range named by the line before it), &lt;code&gt; &lt;/code&gt;, &lt;code&gt;-&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; lines and &lt;code&gt;\ No newline at end of file&lt;/code&gt;; empty when there are no changes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unifiedDiff(a, b, fromName, toName, context = 3, options)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;renderUnified(diffLines(a, b, options), …)&lt;/code&gt;, byte for byte &lt;code&gt;diff -u&lt;/code&gt;‘s output (with &lt;code&gt;--label&lt;/code&gt;) for files holding the texts.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;avin-encoding&quot;&gt;&lt;code&gt;avin.encoding&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Bytes written as text and read back, as RFC 4648 defines them: hexadecimal, base64 with its &lt;code&gt;=&lt;/code&gt;
padding, base64url, the URL- and filename-safe alphabet written without padding, and base32, written
padded, unpadded or in lower case.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.encoding.{toBase64, fromBase64, toBase64Url, fromHex}

main()
  println(toBase64(&amp;quot;hello&amp;quot;))
  println(toBase64Url(&amp;quot;hello&amp;quot;))
  println(fromBase64(&amp;quot;aGVsbG8=&amp;quot;))
  println(fromHex(&amp;quot;68656c6c6f&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toHex(x) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt;, a &lt;code&gt;Vector[byte]&lt;/code&gt; or the UTF-8 bytes of a &lt;code&gt;string&lt;/code&gt;, as lower-case hexadecimal, two digits a byte.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fromHex(text) -&amp;gt; Result[Vector[byte], DecodeError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes the digits spell, two a byte, upper or lower case.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toBase64(x) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; in base64: &lt;code&gt;A&lt;/code&gt;–&lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;–&lt;code&gt;z&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;9&lt;/code&gt;, &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;, padded with &lt;code&gt;=&lt;/code&gt; to a multiple of four characters.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fromBase64(text) -&amp;gt; Result[Vector[byte], DecodeError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes padded, standard base64 spells.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toBase64Url(x) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; in base64url: &lt;code&gt;-&lt;/code&gt; and &lt;code&gt;_&lt;/code&gt; in place of &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;, and no padding.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fromBase64Url(text) -&amp;gt; Result[Vector[byte], DecodeError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes unpadded base64url spells.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toBase32(x) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; in base32: &lt;code&gt;A&lt;/code&gt;–&lt;code&gt;Z&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt;–&lt;code&gt;7&lt;/code&gt;, padded with &lt;code&gt;=&lt;/code&gt; to a multiple of eight characters.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toBase32Unpadded(x) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; in base32 with no padding.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toBase32Lower(x) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt; in base32 in lower case (&lt;code&gt;a&lt;/code&gt;–&lt;code&gt;z&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;–&lt;code&gt;7&lt;/code&gt;) with no padding: sixteen bytes are 26 characters.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fromBase32(text) -&amp;gt; Result[Vector[byte], DecodeError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The bytes base32 spells, in upper, lower or mixed case, padded to a multiple of eight or not padded at all.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Encoding never fails, and the empty input encodes as the empty text and decodes back from it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Decoding is strict, so each byte sequence has exactly one spelling.&lt;/strong&gt; A decoder refuses whitespace
and line breaks, the other alphabet’s characters, a missing, extra or misplaced &lt;code&gt;=&lt;/code&gt;, any &lt;code&gt;=&lt;/code&gt; in
base64url, and a last digit with bits set below the last whole byte, which an encoder always leaves
zero (&lt;code&gt;Zh==&lt;/code&gt; is refused; &lt;code&gt;Zg==&lt;/code&gt; is &lt;code&gt;f&lt;/code&gt;). Two different texts therefore never decode to the same
bytes, which matters for a token or a signature carried as text. Text wrapped across lines has its
line breaks taken out before it is decoded. &lt;code&gt;fromBase32&lt;/code&gt; is as strict, except that a digit’s case
carries no bits, so either case is read, and the &lt;code&gt;=&lt;/code&gt; padding is optional: a padded text must be padded
to a multiple of eight with the right number of &lt;code&gt;=&lt;/code&gt;, and an unpadded one must end on a whole number of
bytes (2, 4, 5 or 7 digits past a multiple of eight, not 1, 3 or 6).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A refusal is a &lt;code&gt;DecodeError&lt;/code&gt;&lt;/strong&gt;, an &lt;code&gt;Error&lt;/code&gt; whose &lt;code&gt;at&lt;/code&gt; is a byte offset in the text. The checks run
in order, the characters first, then the padding, the length and the unused bits, so the offset
named is of the first thing wrong.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Case&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;BadCharacter(at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A character the encoding does not use.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;BadPadding(at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An &lt;code&gt;=&lt;/code&gt; where padding cannot stand: before the last two characters, followed by a character that is not &lt;code&gt;=&lt;/code&gt;, more than two of them, or any in base64url.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Truncated(at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text ends inside a unit: an odd number of hexadecimal digits, base64 whose length is not a multiple of four, base64url one character past one, base32 whose digits past a multiple of eight are 1, 3 or 6 or whose padding is not completed to eight. &lt;code&gt;at&lt;/code&gt; is the text’s length.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UnusedBits(at)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The last digit of the data sets bits no bytes would set.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;avin-log&quot;&gt;&lt;code&gt;avin.log&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Structured logging for programs that run for a long time: records of a level, a message and
key/value fields, written one line each as text for people or as JSON objects for machines. A
&lt;code&gt;Logger&lt;/code&gt; is a &lt;a href=&quot;/spec/contextual-parameters/&quot;&gt;given&lt;/a&gt;: the record functions take
&lt;code&gt;using logger: Logger&lt;/code&gt;, and a program declares one given, at its module’s top level or in the block
handling a request, rather than passing it down by hand.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.log
import avin.log.{Json, Level, Logger, info, warn}

given appLog: Logger = Logger(level = Level.Debug, fields = [(&amp;quot;app&amp;quot;, &amp;quot;shop&amp;quot;)])

handle(order: Order)
  given reqLog: Logger = appLog.child([(&amp;quot;order&amp;quot;, order.id)])
  info(&amp;quot;placing&amp;quot;, [(&amp;quot;items&amp;quot;, order.items.length)])
  if order.total &amp;gt; 1000 then warn(&amp;quot;large order&amp;quot;, [(&amp;quot;total&amp;quot;, order.total)])

main()
  info(&amp;quot;started&amp;quot;, [(&amp;quot;port&amp;quot;, 8080)])
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;2026-11-23T10:20:30.5Z INFO  started app=shop port=8080
2026-11-23T10:20:31.012Z INFO  placing app=shop order=a17 items=3
{&amp;quot;time&amp;quot;:&amp;quot;2026-11-23T10:20:31.012Z&amp;quot;,&amp;quot;level&amp;quot;:&amp;quot;info&amp;quot;,&amp;quot;message&amp;quot;:&amp;quot;placing&amp;quot;,&amp;quot;app&amp;quot;:&amp;quot;shop&amp;quot;,&amp;quot;order&amp;quot;:&amp;quot;a17&amp;quot;,&amp;quot;items&amp;quot;:3}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first two are &lt;code&gt;Text&lt;/code&gt;, the third the second record as &lt;code&gt;Json&lt;/code&gt;. &lt;strong&gt;A record below the logger’s level
costs one comparison&lt;/strong&gt;: the message and the fields are &lt;a href=&quot;/spec/by-name/&quot;&gt;by-name&lt;/a&gt; arguments, so
&lt;code&gt;log.debug(s&amp;quot;state ${dump()}&amp;quot;, [(&amp;quot;size&amp;quot;, measure())])&lt;/code&gt; calls neither &lt;code&gt;dump&lt;/code&gt; nor &lt;code&gt;measure&lt;/code&gt; where
&lt;code&gt;Debug&lt;/code&gt; is not written. &lt;code&gt;if logger.enabled(Level.Debug)&lt;/code&gt; guards a costly block of several records.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where the logger comes from.&lt;/strong&gt; Each record function finds the nearest given &lt;code&gt;Logger&lt;/code&gt; as any
contextual parameter does, and where there is none it writes to &lt;code&gt;DefaultLogger&lt;/code&gt;: &lt;code&gt;Info&lt;/code&gt; and above, as
text, to standard error. There is no logger to set at run time: a program configures its logging by
declaring a given at its top level, which every function of its module finds, and a request’s
handler declares a child of it as a given of its own block.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fields.&lt;/strong&gt; A field is a &lt;code&gt;(string, Any)&lt;/code&gt;. In a JSON line an &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; and finite &lt;code&gt;real&lt;/code&gt;
are written as JSON values, and every other value, a not finite &lt;code&gt;real&lt;/code&gt; too, as a string of its
&lt;code&gt;Display&lt;/code&gt;. In a text line each is &lt;code&gt;key=value&lt;/code&gt; by its &lt;code&gt;Display&lt;/code&gt;, quoted and escaped as a JSON string
where it is empty or holds a space, a control character, &lt;code&gt;&amp;quot;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt; or &lt;code&gt;\&lt;/code&gt;; a key likewise. A value not
known is left out of the fields: &lt;code&gt;None&lt;/code&gt; is written as its &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt;, like any other value.
Fields follow the message in order: the logger’s own, each child’s after its parent’s, then the
record’s. A key written twice is written twice. JSON escapes &lt;code&gt;&amp;quot;&lt;/code&gt;, &lt;code&gt;\&lt;/code&gt; and every control character
(&lt;code&gt;\b&lt;/code&gt;, &lt;code&gt;\f&lt;/code&gt;, &lt;code&gt;\n&lt;/code&gt;, &lt;code&gt;\r&lt;/code&gt;, &lt;code&gt;\t&lt;/code&gt; short, the rest and DEL as &lt;code&gt;\u00XX&lt;/code&gt;) and writes every other character,
Unicode included, as it is. A text line escapes a message’s control characters the same way, so a
record is always one line and cannot move a terminal’s cursor.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lines.&lt;/strong&gt; A text line is the time, the level’s name in upper case padded to five columns, the
message and the fields, separated by spaces. A JSON line is an object of &lt;code&gt;time&lt;/code&gt;, &lt;code&gt;level&lt;/code&gt; (its name
in lower case), &lt;code&gt;message&lt;/code&gt; and then the fields. The time is the logger’s &lt;code&gt;clock&lt;/code&gt;, &lt;code&gt;now&lt;/code&gt; unless a test
gives another, in RFC 3339 form in UTC (&lt;code&gt;Instant&lt;/code&gt;‘s display: the fraction only where there is one).
A text logger paints the level’s name (trace dim, debug cyan, info green, warn yellow, error bold
red) only where it was made with &lt;code&gt;colour = true&lt;/code&gt; (the default) and its sink takes colour; the
standard sinks take it only where their stream is a terminal, &lt;code&gt;NO_COLOR&lt;/code&gt; is not set and &lt;code&gt;TERM&lt;/code&gt; is
not &lt;code&gt;dumb&lt;/code&gt;. A JSON logger never paints.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sinks and threads.&lt;/strong&gt; A &lt;code&gt;Logger&lt;/code&gt; is &lt;code&gt;Sendable&lt;/code&gt;: its own fields are rendered when it is made, so a
child costs nothing per record and one logger serves every thread. Each line, with its &lt;code&gt;\n&lt;/code&gt;, reaches
its sink in one call, and every standard sink writes it in one write or under one lock, so lines
from many threads at once never interleave. A line a sink cannot write is dropped: logging never
stops the program it reports on.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Level&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Trace&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Info&lt;/code&gt;, &lt;code&gt;Warn&lt;/code&gt;, &lt;code&gt;Error&lt;/code&gt;, ordered so; &lt;code&gt;name&lt;/code&gt; (&lt;code&gt;&amp;quot;warn&amp;quot;&lt;/code&gt;), &lt;code&gt;label&lt;/code&gt; (&lt;code&gt;&amp;quot;WARN &amp;quot;&lt;/code&gt;), displayed by its name.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parseLevel(text) -&amp;gt; Option[Level]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A level’s name in any case, &lt;code&gt;warning&lt;/code&gt; for &lt;code&gt;Warn&lt;/code&gt;; &lt;code&gt;None&lt;/code&gt; for anything else.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Format&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Text&lt;/code&gt; or &lt;code&gt;Json&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Field&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;(string, Any)&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Logger(level = Info, format = Text, sink = stderrSink(), colour = true, clock = now, fields = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A logger writing the records at &lt;code&gt;level&lt;/code&gt; and above.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;trace&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt;, &lt;code&gt;info&lt;/code&gt;, &lt;code&gt;warn&lt;/code&gt;, &lt;code&gt;error(message, fields = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Methods of a &lt;code&gt;Logger&lt;/code&gt;, and module functions taking &lt;code&gt;using logger: Logger = DefaultLogger&lt;/code&gt;; &lt;code&gt;message&lt;/code&gt; and &lt;code&gt;fields&lt;/code&gt; by-name.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;log(at, message, fields = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A record at a level chosen while running.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;enabled(at) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether a record at &lt;code&gt;at&lt;/code&gt; would be written.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;child(fields) -&amp;gt; Logger&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same logger carrying &lt;code&gt;fields&lt;/code&gt; after its own.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;atLevel(level) -&amp;gt; Logger&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same logger with another threshold, its fields kept.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;level&lt;/code&gt;, &lt;code&gt;format&lt;/code&gt;&lt;/td&gt;&lt;td&gt;What the logger was made with.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DefaultLogger&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Logger()&lt;/code&gt;: &lt;code&gt;Info&lt;/code&gt; and above, as text, to standard error.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Sink(write, colours = false)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A sink calling &lt;code&gt;write: @sendable (string) -&amp;gt; unit&lt;/code&gt; once a line, the line ending in &lt;code&gt;\n&lt;/code&gt;; &lt;code&gt;colours&lt;/code&gt; says it takes colour.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;stderrSink()&lt;/code&gt;, &lt;code&gt;stdoutSink()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The standard streams, each line in one write, taking colour on a colour terminal.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fileSink(path) -&amp;gt; Result[Sink, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Appends to &lt;code&gt;path&lt;/code&gt;, creating it; an &lt;code&gt;Err&lt;/code&gt; where it cannot be opened. Each line is appended and on disk when the record’s call returns, under a lock, the file opened for it, so a file a rotator moved away is made again by the next line.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;writerSink(target: Mutex[W])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any &lt;code&gt;Writer&lt;/code&gt;, each line written whole under its mutex.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The access log of &lt;a href=&quot;#http-server&quot;&gt;&lt;code&gt;avin.net.http&lt;/code&gt;&lt;/a&gt; writes through a logger as well: see
&lt;code&gt;http.accessLog(logger)&lt;/code&gt; there.&lt;/p&gt;
&lt;h2 id=&quot;avin-net&quot;&gt;&lt;code&gt;avin.net&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;TCP connections, TLS over them, servers, URLs, and a small HTTP client and server that speak &lt;code&gt;https&lt;/code&gt;
too. Every operation that can fail answers a &lt;code&gt;Result[T, IoError]&lt;/code&gt;, and a connection that is reading
or writing waits safe for the collector.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.http

main() -&amp;gt; int
  http.get(&amp;quot;https://example.com/&amp;quot;) match
    Ok(r) if r.status == 200 -&amp;gt; println(r.text)
    Ok(r) -&amp;gt; eprintln(s&amp;quot;status ${r.status}&amp;quot;)
    Err(e) -&amp;gt; eprintln(e.message)
  0
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;tcp&quot;&gt;TCP&lt;/h3&gt;
&lt;p&gt;A connection and a listener are &lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt;: each holds a Sysl
handle, so a thread or an actor given one takes it over, and the code that gave it traps where it
uses it again.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TcpStream.connect(host: string, port: int) -&amp;gt; Result[TcpStream, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A connection to the first of the host’s addresses that answers; where none does, the last one’s error.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.read(max: int) -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Up to &lt;code&gt;max&lt;/code&gt; bytes, at least one, waiting for at least one; empty when the other end has finished sending.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.readLine() -&amp;gt; Result[Option[string], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The next line, as standard input reads one, &lt;code&gt;None&lt;/code&gt; at the end.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.readAll() -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Everything until the other end has finished sending.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.write(bytes: Array[byte])&lt;/code&gt;, &lt;code&gt;s.writeText(text: string)&lt;/code&gt; &lt;code&gt;-&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends all of it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.setTimeout(d: Duration) -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A read or write that waits longer for the other end fails with &lt;code&gt;TimedOut&lt;/code&gt;; zero or less takes the limit away. Each wait has the whole limit, so a write that waits for room several times fails only where one wait runs out.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.timeout -&amp;gt; Duration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The limit &lt;code&gt;setTimeout&lt;/code&gt; set, in whole milliseconds, a part of one counting as one; zero where there is none.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.shutdownOutput() -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Tells the other end nothing more will be sent; reading goes on.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.close() -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Ends the connection and answers &lt;code&gt;Ok&lt;/code&gt;; closing again does nothing. Every connection and listener is an &lt;a href=&quot;#close&quot;&gt;&lt;code&gt;io.Close&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.readable() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether a read would answer now, without waiting: bytes a &lt;code&gt;readLine&lt;/code&gt; read ahead are still to be read, bytes have arrived, the other end has finished sending or reset the connection, or the connection is closed. Never waits. A &lt;a href=&quot;/spec/threads/#select&quot;&gt;&lt;code&gt;select&lt;/code&gt;&lt;/a&gt;‘s &lt;code&gt;s.readable()&lt;/code&gt; arm waits for it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.readinessDescriptor() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The socket’s descriptor, which that arm watches on the runtime’s poller; &lt;code&gt;-1&lt;/code&gt; once closed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.writeSome(bytes: Array[byte]) -&amp;gt; Result[int, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends what of &lt;code&gt;bytes&lt;/code&gt; goes without waiting, after waiting for room for the first byte where there is none, and answers how many: at least one, unless &lt;code&gt;bytes&lt;/code&gt; is empty. After &lt;code&gt;writable()&lt;/code&gt; answered &lt;code&gt;true&lt;/code&gt; it does not wait.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.writable() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether a write would send something now, without waiting: the socket has room, or the connection has failed or is closed. Never waits. A &lt;a href=&quot;/spec/threads/#select&quot;&gt;&lt;code&gt;select&lt;/code&gt;&lt;/a&gt;‘s &lt;code&gt;s.writable()&lt;/code&gt; arm waits for it.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.writabilityDescriptor() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The descriptor that arm watches; &lt;code&gt;-1&lt;/code&gt; once closed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.split() -&amp;gt; (StreamReader, StreamWriter)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The connection divided into a reading half and a writing half, for two threads to use at once; see &lt;a href=&quot;#split-connections&quot;&gt;split connections&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TcpListener.bind(host: string, port: int) -&amp;gt; Result[TcpListener, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Listens on the host’s first address (&lt;code&gt;127.0.0.1&lt;/code&gt; for this machine alone, &lt;code&gt;0.0.0.0&lt;/code&gt; for all of its addresses); port &lt;code&gt;0&lt;/code&gt; lets the platform choose.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;l.port() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The port it listens on.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;l.accept() -&amp;gt; Result[TcpStream, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Waits for the next connection.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;l.close() -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Stops listening and answers &lt;code&gt;Ok&lt;/code&gt;; closing again does nothing.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.{TcpListener, TcpStream}
import avin.threads.spawn

main()
  TcpListener.bind(&amp;quot;127.0.0.1&amp;quot;, 0) match
    Ok(l) -&amp;gt;
      val server = spawn(() -&amp;gt; l.accept().flatMap(s -&amp;gt; s.readLine()))
      TcpStream.connect(&amp;quot;127.0.0.1&amp;quot;, l.port()).flatMap(c -&amp;gt; c.writeText(&amp;quot;hello\n&amp;quot;))
      server.join() match
        Ok(Some(line)) -&amp;gt; println(line)
        _ -&amp;gt; eprintln(&amp;quot;no line&amp;quot;)
    Err(e) -&amp;gt; eprintln(e.message)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;unix-domain-sockets&quot;&gt;Unix domain sockets&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;UnixStream&lt;/code&gt; and a &lt;code&gt;UnixListener&lt;/code&gt; connect two programs on one machine by a path in the file system
rather than a host and port. A &lt;code&gt;UnixStream&lt;/code&gt; has every reading and writing operation of a &lt;code&gt;TcpStream&lt;/code&gt;
(&lt;code&gt;read&lt;/code&gt;, &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeSome&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;shutdownOutput&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;, &lt;code&gt;readable&lt;/code&gt;, &lt;code&gt;readinessDescriptor&lt;/code&gt;, &lt;code&gt;writable&lt;/code&gt;, &lt;code&gt;writabilityDescriptor&lt;/code&gt;, &lt;code&gt;split&lt;/code&gt;) with the
same meanings, including the bytes &lt;code&gt;readLine&lt;/code&gt; reads beyond its line, and a &lt;code&gt;UnixListener&lt;/code&gt; accepts
them as a &lt;code&gt;TcpListener&lt;/code&gt; does. Both are sendable and owned by one thread at a time, and every wait is
safe for the collector, as TCP’s are.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UnixStream.connect(path: string) -&amp;gt; Result[UnixStream, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A connection to the program listening at &lt;code&gt;path&lt;/code&gt;; a path with nothing at it is &lt;code&gt;NotFound&lt;/code&gt;, and a socket file nobody listens on any more is &lt;code&gt;ConnectionRefused&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UnixListener.bind(path: string) -&amp;gt; Result[UnixListener, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Listens at &lt;code&gt;path&lt;/code&gt;, which must name nothing yet: a path already holding anything is &lt;code&gt;AlreadyExists&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UnixListener.bindReplacing(path: string) -&amp;gt; Result[UnixListener, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As &lt;code&gt;bind&lt;/code&gt;, but a socket file left behind by a program that is gone (a connection to it is refused) is removed first. A live listener’s path and anything that is not a socket file is &lt;code&gt;AlreadyExists&lt;/code&gt; and untouched.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;l.path() -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The path it listens at.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;l.accept() -&amp;gt; Result[UnixStream, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Waits for the next connection.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;l.close() -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Stops listening and answers &lt;code&gt;Ok&lt;/code&gt;; closing again does nothing. The socket file stays; &lt;code&gt;fs.remove&lt;/code&gt; or &lt;code&gt;bindReplacing&lt;/code&gt; clears it.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A path the platform’s socket address cannot carry is an &lt;code&gt;Err&lt;/code&gt;: one longer than 103 bytes on macOS (107
on Linux), an empty one, or one holding a zero byte. A missing directory on the way to a bound path is
an &lt;code&gt;Err&lt;/code&gt; too. &lt;code&gt;bindReplacing&lt;/code&gt; finds out whether a socket is live by connecting to it once, so a live
listener sees a connection that closes without a word.&lt;/p&gt;
&lt;p&gt;A connection and a listener are closed by &lt;code&gt;close()&lt;/code&gt;; one the program forgets is closed when the
collector finds it unreachable, so a lost one leaks nothing for long, but only &lt;code&gt;close()&lt;/code&gt; says when.
A read, write or &lt;code&gt;accept&lt;/code&gt; after &lt;code&gt;close()&lt;/code&gt; answers &lt;code&gt;Other&lt;/code&gt;, saying it is closed. &lt;code&gt;IoError&lt;/code&gt; gains the
variants a connection meets: &lt;code&gt;ConnectionRefused&lt;/code&gt;, &lt;code&gt;ConnectionReset&lt;/code&gt; (a reset, or a write to a
connection the other end has closed) and &lt;code&gt;TimedOut&lt;/code&gt;. A host that resolves to no address is &lt;code&gt;Other&lt;/code&gt;,
and a port outside 0 to 65535 or a read of fewer than one byte traps at the call. Bytes a &lt;code&gt;readLine&lt;/code&gt;
reads beyond its line are kept, and the next read of any kind takes them first. A timeout is kept in
whole milliseconds, a part of one counting as one, and the longest duration is a limit that never
runs out.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Waiting on a connection holds no operating system thread.&lt;/strong&gt; An &lt;code&gt;accept&lt;/code&gt;, a &lt;code&gt;connect&lt;/code&gt;, a read or a
write that has to wait for the other end parks a &lt;a href=&quot;/spec/threads/#lightweight-threads&quot;&gt;lightweight thread&lt;/a&gt;
on the runtime’s poller, and its worker runs other threads until the socket is ready: a server that
gives each connection a thread of its own serves far more connections than it has workers. &lt;code&gt;main&lt;/code&gt;,
which is not a lightweight thread, waits on the socket alone. Either way the wait is safe for the
collector and a timeout ends it. A wait ends when the other end acts: a read whose peer has closed
answers the end of the input (an empty array, &lt;code&gt;None&lt;/code&gt; from &lt;code&gt;readLine&lt;/code&gt;), and a write to a peer that has
closed fails with &lt;code&gt;ConnectionReset&lt;/code&gt;, never ending the program. Nothing else can end a wait early,
since a connection &lt;a href=&quot;#tcp&quot;&gt;belongs to one thread&lt;/a&gt;: another thread that tries to close a connection or
listener a thread is parked on traps, as any use of it from there does.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Looking up a host’s name waits the same way, and a cancellation ends it.&lt;/strong&gt; The system’s resolver
cannot be stopped halfway, so the runtime makes each lookup on a helper thread of its own, and the
&lt;code&gt;connect&lt;/code&gt; or &lt;code&gt;bind&lt;/code&gt; that asked waits for the answer as it waits on a socket: a lightweight thread
parks, &lt;code&gt;main&lt;/code&gt; waits safe for the collector, and a &lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation&lt;/a&gt; or a
&lt;code&gt;withTimeout&lt;/code&gt;‘s deadline stops the thread at once, so a connect’s time limit covers the lookup too.
The lookup it abandoned runs on to the resolver’s answer, which is thrown away. At most 64 helpers
run at once, which bounds how many abandoned lookups can still be running; a lookup asked for while
all 64 are busy waits for one to come free, and that wait too is ended by a cancellation. A numeric
address (&lt;code&gt;127.0.0.1&lt;/code&gt;, &lt;code&gt;::1&lt;/code&gt;) asks the network nothing and is resolved where it is asked.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A connection belongs to one thread at a time&lt;/strong&gt;, as every &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;handle&lt;/a&gt;
does: a server accepts a connection and hands it to the thread or future that serves it, the bytes
read ahead going with it, and the code that handed it over traps at any operation on it while the
body runs, a read served from those bytes alone and one on a connection the body has closed
included (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;); a listener’s &lt;code&gt;port&lt;/code&gt;, &lt;code&gt;accept&lt;/code&gt; and &lt;code&gt;close&lt;/code&gt; are
checked the same way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `TcpStream` belongs to another thread at main.avin:16:25
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;ByteStream&lt;/code&gt; is what the three connections share&lt;/strong&gt;: a trait with &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;,
&lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeSome&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;shutdownOutput&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;, &lt;code&gt;readable&lt;/code&gt;,
&lt;code&gt;readinessDescriptor&lt;/code&gt;, &lt;code&gt;writable&lt;/code&gt;, &lt;code&gt;writabilityDescriptor&lt;/code&gt; and &lt;code&gt;split&lt;/code&gt;, which &lt;code&gt;TcpStream&lt;/code&gt;,
&lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;TlsStream&lt;/code&gt; implement, so code that speaks
a protocol, as the HTTP client and server do, takes a &lt;code&gt;ByteStream&lt;/code&gt; and runs over any of them. It is
&lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt;, and it is an &lt;a href=&quot;#reader&quot;&gt;&lt;code&gt;io.Reader&lt;/code&gt;&lt;/a&gt; by its &lt;code&gt;read&lt;/code&gt;, so
whatever reads a &lt;code&gt;Reader&lt;/code&gt; reads any connection, a TLS one included, and an
&lt;a href=&quot;#bytewriter&quot;&gt;&lt;code&gt;io.ByteWriter&lt;/code&gt;&lt;/a&gt; by its &lt;code&gt;write&lt;/code&gt;, so whatever writes to a &lt;code&gt;ByteWriter&lt;/code&gt; writes to any
connection. It is a &lt;code&gt;threads.Readiness&lt;/code&gt; by
&lt;code&gt;readable&lt;/code&gt; and &lt;code&gt;readinessDescriptor&lt;/code&gt;, so a &lt;a href=&quot;/spec/threads/#select&quot;&gt;&lt;code&gt;select&lt;/code&gt;&lt;/a&gt; waits on any connection
beside its channels: the thread that owns a connection waits in one select for its peer’s bytes
and for what other threads send it, and does every read and write itself. It is a
&lt;code&gt;threads.Writability&lt;/code&gt; by &lt;code&gt;writable&lt;/code&gt; and &lt;code&gt;writabilityDescriptor&lt;/code&gt;, so a select’s &lt;code&gt;writable()&lt;/code&gt; arm waits
for room as a &lt;code&gt;readable()&lt;/code&gt; arm waits for bytes. &lt;code&gt;Readiness&lt;/code&gt; and &lt;code&gt;Writability&lt;/code&gt; are traits of
their own, for a source or sink that is not a connection: its descriptor may be &lt;code&gt;-1&lt;/code&gt;, and a select
then finds it ready only when it tries its arms.&lt;/p&gt;
&lt;h4 id=&quot;split-connections&quot;&gt;Split connections&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;split()&lt;/code&gt; divides a connection into a &lt;code&gt;StreamReader&lt;/code&gt; and a &lt;code&gt;StreamWriter&lt;/code&gt;&lt;/strong&gt;, each sendable and
each its own thread’s, so one thread sends while another receives over the same connection. A
connection used by one thread at a time must stop writing to read: two ends that each send more
than the buffers between them hold before they read would both wait for ever. Split, the writer
waits for room and the reader for bytes at the same time, each parking only its own lightweight
thread on the poller, both on the connection’s one descriptor.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io.IoError
import avin.net.{StreamWriter, TcpStream}
import avin.threads.spawn

sendAll(w: StreamWriter, queries: Vector[string]) -&amp;gt; Result[unit, IoError]
  for q in queries do w.writeText(q + &amp;quot;\n&amp;quot;)?
  w.close()

// Sends every query and reads every answer at once, so a long batch never waits for itself.
pipeline(c: TcpStream, queries: Vector[string]) -&amp;gt; Result[Vector[string], IoError]
  val (r, w) = c.split()
  val sending = spawn(() -&amp;gt; sendAll(w, queries))
  val answers = Buffer[string]()
  while answers.length &amp;lt; queries.length
    answers.addOne(r.readLine()?.getOrElse(&amp;quot;&amp;quot;))
  sending.join()?
  r.close()?
  Ok(answers.toVector)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The halves.&lt;/strong&gt; A &lt;code&gt;StreamReader&lt;/code&gt; is an &lt;code&gt;io.Reader&lt;/code&gt;, an &lt;code&gt;io.Close&lt;/code&gt; and a &lt;code&gt;threads.Readiness&lt;/code&gt;, with
&lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;remoteAddress&lt;/code&gt;; a &lt;code&gt;StreamWriter&lt;/code&gt; is an &lt;code&gt;io.ByteWriter&lt;/code&gt;,
an &lt;code&gt;io.Close&lt;/code&gt; and a &lt;code&gt;threads.Writability&lt;/code&gt;, with &lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeSome&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;remoteAddress&lt;/code&gt;.
Bytes the connection had read ahead go to the reader, and each half starts with the connection’s
timeout, then keeps its own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Closing.&lt;/strong&gt; Closing the writer tells the other end nothing more will be sent, as
&lt;code&gt;shutdownOutput&lt;/code&gt; does; the reader reads on, and the other end reads the end of its input. Closing
the reader stops its reading and leaves the writer sending. The connection closes once both halves
are closed, or once both are unreachable. A closed half answers an error to every use but closing
again, which does nothing and answers &lt;code&gt;Ok&lt;/code&gt;; a TCP or Unix writer’s close answers &lt;code&gt;Ok&lt;/code&gt; even where
the other end has gone, and a TLS writer’s answers whether TLS’s close notice went out. There is
no way to join the halves again.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The connection split.&lt;/strong&gt; It is used up: every operation on it answers an error saying it has
been split, it is readable and writable so that a select’s arm runs and finds that out, its
descriptors are &lt;code&gt;-1&lt;/code&gt;, and closing it does nothing. Splitting it again, or splitting a closed
connection, traps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each half belongs to one thread at a time&lt;/strong&gt;, as the connection did, its traps naming
&lt;code&gt;StreamReader&lt;/code&gt; or &lt;code&gt;StreamWriter&lt;/code&gt;. After the peer resets the connection, each half answers
&lt;code&gt;ConnectionReset&lt;/code&gt;, or the reader the end of its input, at every use, and a parked half’s wait ends
with it. A half’s thread may be cancelled while it waits, and the other half works on.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TLS.&lt;/strong&gt; The halves of a &lt;code&gt;TlsStream&lt;/code&gt; share one TLS session. Each reaches it only under a lock that
nothing holds while it waits for the connection, so the reader decrypts records as they arrive
while the writer waits for room; what TLS has to send goes out in order, a record whole, whichever
half made it, and a reader never waits for room to send anything of its own while the writer is
sending. A failure to send is the writer’s to answer whichever half was sending: the reader reads
on, and the writer answers it at every use after, its close included, so a close notice the reader
tried and failed to send is one that did not go out. A cancellation that stops a half inside an
operation lets the locks go.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A &lt;code&gt;writeSome&lt;/code&gt; hands a &lt;code&gt;TlsStream&lt;/code&gt;, or its writer, at most one TLS record of plaintext. A
&lt;code&gt;TlsStream&lt;/code&gt; sends what of the record the connection has room for; the rest goes before anything
else is sent, and &lt;code&gt;writable()&lt;/code&gt; sends it as room comes and answers &lt;code&gt;true&lt;/code&gt; once it has gone. So after
&lt;code&gt;writable()&lt;/code&gt; answered &lt;code&gt;true&lt;/code&gt;, its &lt;code&gt;writeSome&lt;/code&gt; does not wait. A read of a &lt;code&gt;TlsStream&lt;/code&gt; that has to
wait for input while such a rest is still to go waits for input or room, whichever comes first,
sending the rest as room comes, so a caller that only reads after its last &lt;code&gt;writeSome&lt;/code&gt; still has
the whole record sent, and its peer’s answer, given once that record has come, still arrives;
waiting for both, the read takes input while the peer is itself waiting to send. Its wait has the
connection’s time limit, and a rest it did not send is kept for the next read or write. The writing half of a split one sends
the whole record before it answers, waiting for room for the rest where there is too little, so what
it answers has gone even where the writer writes nothing after it; its reading half reads
meanwhile, so the wait never holds up the peer’s answers. Where the writer’s time limit runs out
first, it still answers the plaintext TLS took, and the rest goes before anything else, &lt;code&gt;writable()&lt;/code&gt;
sending it as room comes. Ciphertext a wait that failed did not send is kept, in order, to go first,
never dropped. &lt;code&gt;ReadAhead&lt;/code&gt;, the bytes a connection has read
beyond what its caller asked for and the line reading over them, is public for a connection of
one’s own: &lt;code&gt;pending&lt;/code&gt; says whether any are still to be read, and &lt;code&gt;keep(bytes)&lt;/code&gt; adds bytes that
arrived before anything asked for them.&lt;/p&gt;
&lt;h3 id=&quot;tls&quot;&gt;TLS&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;avin.net.tls&lt;/code&gt; is TLS over a &lt;code&gt;TcpStream&lt;/code&gt;, at either end, by OpenSSL, which the library reaches
through the Sysl package &lt;code&gt;openssl&lt;/code&gt; named in its own &lt;code&gt;sysl-dependencies&lt;/code&gt;. OpenSSL never touches the
socket: it works on two buffers in memory, the bytes it has to send are written on the TCP
connection, and the bytes that arrive there are handed to it. So a &lt;code&gt;TlsStream&lt;/code&gt; waits exactly as its
&lt;code&gt;TcpStream&lt;/code&gt; does, a lightweight thread parked on the poller, with the same per-wait limit and the
same &lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation&lt;/a&gt;. A program that reaches none of this builds and
links no OpenSSL.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.io.IoError
import avin.net.tls.{TlsError, TlsStream}

main() -&amp;gt; Result[unit, TlsError | IoError]
  val s = TlsStream.connect(&amp;quot;example.com&amp;quot;, 443)?
  defer s.close()
  s.writeText(&amp;quot;HEAD / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n&amp;quot;)?
  println(s.readLine()?.getOrElse(&amp;quot;&amp;quot;))
  Ok(())
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TlsStream.connect(host, port, settings: TlsClient = TlsClient()) -&amp;gt; Result[TlsStream, TlsError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A TCP connection as &lt;code&gt;TcpStream.connect&lt;/code&gt; makes one, then TLS as the client, the certificate checked for &lt;code&gt;host&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TlsStream.client(tcp: TcpStream, host, settings = TlsClient()) -&amp;gt; Result[TlsStream, TlsError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;TLS as the client over a connection the caller made, its handshake waiting with &lt;code&gt;tcp&lt;/code&gt;‘s limit. Where it fails, &lt;code&gt;tcp&lt;/code&gt; is the caller’s to close.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TlsStream.server(tcp: TcpStream, settings: TlsServer) -&amp;gt; Result[TlsStream, TlsError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;TLS as the server over an accepted connection, presenting the settings’ certificate.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.read&lt;/code&gt;, &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt;&lt;/td&gt;&lt;td&gt;As a &lt;code&gt;TcpStream&lt;/code&gt;‘s, of plaintext; the limit is the TCP connection’s, for each of its waits.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.readable() -&amp;gt; bool&lt;/code&gt;, &lt;code&gt;s.readinessDescriptor() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether a read of plaintext would answer now: plaintext is buffered or TLS holds some decrypted, a whole record of it has arrived, or the peer has closed TLS or the connection. It hands TLS the ciphertext already on the socket, so part of a record is not taken for plaintext, and never waits for more; a failure it meets is answered by the next read. The descriptor is the TCP connection’s.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.shutdownOutput()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Closes TLS (a &lt;code&gt;close_notify&lt;/code&gt;) and the TCP connection’s sending side; reading goes on.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.close() -&amp;gt; Result[unit, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Closes TLS as far as the peer can be told without waiting, then the connection; the &lt;code&gt;Err&lt;/code&gt; is a failure to send that notice, the connection being closed either way. Again does nothing and answers &lt;code&gt;Ok&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TlsClient(trusted = [])&lt;/code&gt;, &lt;code&gt;c.trust(pem: string) -&amp;gt; TlsClient&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The machine’s trusted authorities and those added: &lt;code&gt;trust&lt;/code&gt; answers a client that also trusts the certificates in &lt;code&gt;pem&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TlsServer(certificate, key)&lt;/code&gt;, &lt;code&gt;TlsServer.of(certificate, key) -&amp;gt; Result[TlsServer, TlsError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A server’s certificate (a chain, leaf first) and private key as PEM text; &lt;code&gt;of&lt;/code&gt; checks they can be used and go together, and one made directly is checked at its first connection.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;What a client checks, and what cannot be turned off.&lt;/strong&gt; The server’s certificate must chain to an
authority the client trusts: the machine’s store, read through OpenSSL’s default paths (on macOS
the &lt;code&gt;cert.pem&lt;/code&gt; of Homebrew’s OpenSSL, not the Keychain), and the authorities &lt;code&gt;trust&lt;/code&gt; adds. Its name
must cover the host connected to, a name or an address. The host’s name is sent for the server to
choose a certificate by, and the oldest protocol spoken is TLS 1.2. &lt;code&gt;trust&lt;/code&gt; only adds: there is no
way to accept a certificate these refuse, a private authority, a corporate one and a test’s own
being the same case. The choices are &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After the handshake a connection is a &lt;code&gt;ByteStream&lt;/code&gt;&lt;/strong&gt;: a failure of TLS itself while reading or
writing is an &lt;code&gt;IoError&lt;/code&gt; of kind &lt;code&gt;Other&lt;/code&gt; whose text begins &lt;code&gt;TLS:&lt;/code&gt;, and the connection’s end, by the peer’s
&lt;code&gt;close_notify&lt;/code&gt; or by the TCP connection closing, reads as the end of a TCP connection’s does.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TlsError&lt;/code&gt; says why a connection could not be made: &lt;code&gt;Transport(IoError)&lt;/code&gt;, the connection beneath
could not be made, broke or timed out; &lt;code&gt;Certificate(text, why)&lt;/code&gt;, the peer’s certificate was refused,
and &lt;code&gt;why&lt;/code&gt; is a &lt;code&gt;TlsRefusal&lt;/code&gt; saying how: &lt;code&gt;HostMismatch&lt;/code&gt; (for another host or IP address), &lt;code&gt;Expired&lt;/code&gt;,
&lt;code&gt;NotYetValid&lt;/code&gt;, &lt;code&gt;Untrusted&lt;/code&gt; (an unknown issuer, or a self-signed certificate) or &lt;code&gt;Other(code)&lt;/code&gt;, OpenSSL’s
number for a rarer verdict; &lt;code&gt;refusal()&lt;/code&gt; answers it as an &lt;code&gt;Option[TlsRefusal]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; for any other
error, and the &lt;code&gt;message&lt;/code&gt; of the error and of the refusal names it (“the certificate is for another
host”, “the certificate has expired”, “the certificate is not yet valid”, “the certificate is not
trusted”, “the certificate was refused (code N)”); &lt;code&gt;Handshake(text)&lt;/code&gt;, the two ends did not agree,
as with a peer that does not speak TLS or ends the connection in the handshake; and
&lt;code&gt;Credentials(text)&lt;/code&gt;, a certificate or key given to this end cannot be used. &lt;code&gt;message&lt;/code&gt; says it in
words. Each &lt;code&gt;TlsStream&lt;/code&gt;, &lt;code&gt;TlsClient&lt;/code&gt; and &lt;code&gt;TlsServer&lt;/code&gt; is sendable, a stream belonging to one thread
at a time as a &lt;code&gt;TcpStream&lt;/code&gt; does.&lt;/p&gt;
&lt;h3 id=&quot;servers&quot;&gt;Servers&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;TcpServer&lt;/code&gt; is a listener that serves each connection it accepts in an
&lt;a href=&quot;/spec/actors/&quot;&gt;actor&lt;/a&gt; of its own, so a connection that waits holds no operating system thread and
a bug in the code serving one ends that connection alone:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.TcpServer

main()
  val server = TcpServer.start(&amp;quot;0.0.0.0&amp;quot;, 7000, (s, _) -&amp;gt;
    while s.readLine() is Ok(Some(line))
      s.writeText(line + &amp;quot;\n&amp;quot;)).ok.get
  server.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TcpServer.start(host, port, serve: @sendable (TcpStream, TcpServer) -&amp;gt; unit, maxConnections = 1024, timeout = Duration.Zero, failed: @sendable (TcpStream) -&amp;gt; unit = _ -&amp;gt; ()) -&amp;gt; Result[TcpServer, IoError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Listens as &lt;code&gt;TcpListener.bind&lt;/code&gt; does and serves each connection by &lt;code&gt;serve&lt;/code&gt;, given the connection and the server.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.port() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The port it listens on, the one the platform chose for port 0.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.connections() -&amp;gt; int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;How many connections it holds now.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.isStopping() -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether it has been asked to stop, for code serving a connection to finish early.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.idle[T: Sendable](@sendable wait: () -&amp;gt; T) -&amp;gt; Option[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Runs &lt;code&gt;wait&lt;/code&gt;, a connection’s wait for its next piece of work, on a thread of its own; &lt;code&gt;Some&lt;/code&gt; of its result, or &lt;code&gt;None&lt;/code&gt; where the server stops first, which cancels &lt;code&gt;wait&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.stopped() -&amp;gt; Channel[unit]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A channel closed once the server is asked to stop and never sent on, so a &lt;code&gt;select&lt;/code&gt; waiting for a connection’s bytes or other work ends at once with an arm &lt;code&gt;s.stopped().receive()&lt;/code&gt;, with no thread of its own.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.stop()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Stops accepting and returns at once, cancelling the parked &lt;code&gt;accept&lt;/code&gt; and every wait in &lt;code&gt;idle&lt;/code&gt;; stopping again does nothing.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.join()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Waits until it has stopped and every connection it held has ended.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s.shutdown()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;stop()&lt;/code&gt;, then &lt;code&gt;join()&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Each connection is served in an actor’s first turn&lt;/strong&gt;, the connection handed to it, and closed
once &lt;code&gt;serve&lt;/code&gt; returns. The actor runs on a pool of the server’s own with a worker for each
connection it may hold, so a connection parked on its socket never keeps another waiting for a
worker; the workers are lightweight threads, idle ones parked.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trap in &lt;code&gt;serve&lt;/code&gt; fails that connection’s actor alone&lt;/strong&gt; (supervised with &lt;code&gt;Stop&lt;/code&gt;): the trap is
reported naming the actor, &lt;code&gt;avin: trap in Connection#7: …&lt;/code&gt;, then &lt;code&gt;failed&lt;/code&gt; runs on the
connection, which is closed, and the server goes on. A trap that leaves shared state in doubt, as
&lt;a href=&quot;/spec/actors/#supervision&quot;&gt;supervision&lt;/a&gt; says, still stops the program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;At most &lt;code&gt;maxConnections&lt;/code&gt; are held at once.&lt;/strong&gt; The next connection waits unaccepted, in the
listener’s backlog, until one ends; a limit less than one traps. Each connection’s timeout is
&lt;code&gt;timeout&lt;/code&gt; when &lt;code&gt;serve&lt;/code&gt; begins, none for zero, and &lt;code&gt;serve&lt;/code&gt; may change it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A graceful shutdown.&lt;/strong&gt; &lt;code&gt;stop()&lt;/code&gt; stops accepting at once: the acceptor’s parked &lt;code&gt;accept&lt;/code&gt; is
&lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancelled&lt;/a&gt;, no connection being made to wake it, and the listener
is closed, so a new connection is refused. The connections held go on until &lt;code&gt;serve&lt;/code&gt; returns;
&lt;code&gt;join()&lt;/code&gt; waits for them. Code serving a connection calls &lt;code&gt;stop()&lt;/code&gt;, since &lt;code&gt;shutdown()&lt;/code&gt; there would
wait for itself. The server may be shared between threads, and any of them may stop it and wait
for it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A connection idle between pieces of work ends at once.&lt;/strong&gt; &lt;code&gt;serve&lt;/code&gt; waits for the next one
through &lt;code&gt;server.idle(() -&amp;gt; s.readLine())&lt;/code&gt;: &lt;code&gt;wait&lt;/code&gt; runs on a thread of a scope the calling thread
runs, and stopping the server cancels that scope, so &lt;code&gt;wait&lt;/code&gt; ends wherever it waits, however long
its timeout, and &lt;code&gt;idle&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;; once the server is stopping, &lt;code&gt;idle&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt; without
running &lt;code&gt;wait&lt;/code&gt;. The connection &lt;code&gt;wait&lt;/code&gt; reads is handed back when &lt;code&gt;idle&lt;/code&gt; returns, as a scope hands
back the handles of its threads. Code outside &lt;code&gt;idle&lt;/code&gt;, a request being answered, is never
cancelled, so it finishes. A trap in &lt;code&gt;wait&lt;/code&gt; stops the program, as a trap in any thread does,
rather than failing the connection’s actor alone.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;serveLines(s: TcpStream, server: TcpServer)
  while server.idle(() -&amp;gt; s.readLine()) is Some(Ok(Some(line)))
    s.writeText(handle(line) + &amp;quot;\n&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;http-server&quot;&gt;HTTP server&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;http.serve&lt;/code&gt; is an HTTP/1.1 server on a &lt;code&gt;TcpServer&lt;/code&gt;, each request answered by a handler from a
&lt;code&gt;ServerRequest&lt;/code&gt; to a &lt;code&gt;Response&lt;/code&gt;; a &lt;code&gt;Router&lt;/code&gt; is a handler that chooses another by method and path:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.http
import avin.net.http.{Response, Route, Router}

main()
  val router = Router(
    [
      Route.get(&amp;quot;/hello/:name&amp;quot;, r -&amp;gt; Response.text(200, s&amp;quot;hello, ${r.param(&amp;quot;name&amp;quot;)}\n&amp;quot;)),
      Route.post(&amp;quot;/echo&amp;quot;, r -&amp;gt; Response.bytes(200, r.body, &amp;quot;application/octet-stream&amp;quot;))
    ]
  )
  http.serve(&amp;quot;0.0.0.0&amp;quot;, 8080, router.handle).ok.get.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;type Handler = @sendable (ServerRequest) -&amp;gt; Response&lt;/code&gt; names what answers a request.
&lt;code&gt;http.serve(host, port, handler: Handler, maxConnections = 1024, readTimeout = seconds(30), writeTimeout = seconds(30), idleTimeout = seconds(5), maxHeaderBytes = 16384, maxBodyBytes = 1048576, tls: Option[TlsServer] = None, errors: ErrorPage = plainError, date: bool = true, requestTimeout = seconds(60)) -&amp;gt; Result[TcpServer, IoError]&lt;/code&gt; listens as
&lt;code&gt;TcpServer.start&lt;/code&gt; does. &lt;strong&gt;Each
response carries a &lt;code&gt;Date&lt;/code&gt; header&lt;/strong&gt; (RFC 9110 section 6.6.1), the time it is sent as an IMF-fixdate
(&lt;code&gt;Sun, 06 Nov 1994 08:49:37 GMT&lt;/code&gt;, as &lt;code&gt;Instant.toHttpDate()&lt;/code&gt; writes it), on every status: a
handler’s, the server’s own &lt;code&gt;400&lt;/code&gt; or &lt;code&gt;503&lt;/code&gt;, sized, chunked, closing and event-stream responses
alike. A handler that sets &lt;code&gt;Date&lt;/code&gt; (in any case of the name) keeps its own value, and &lt;code&gt;date = false&lt;/code&gt;
sends none; the &lt;code&gt;101&lt;/code&gt; of an upgrade carries none. A &lt;code&gt;DateHeader(clock = now)&lt;/code&gt; formats its text once
a second and hands it to every connection, with no lock, so sending the header costs a clock read
and a comparison; &lt;code&gt;DateHeader.value()&lt;/code&gt; gives the text. Each
wait while a request is read may last &lt;code&gt;readTimeout&lt;/code&gt;, each wait while a response is written
&lt;code&gt;writeTimeout&lt;/code&gt;, and the wait for the next request on a connection kept alive &lt;code&gt;idleTimeout&lt;/code&gt;; and the
whole of a request, its line, headers and body, must arrive within &lt;code&gt;requestTimeout&lt;/code&gt; of its first
byte, so a client trickling bytes just faster than &lt;code&gt;readTimeout&lt;/code&gt; cannot hold a connection, and its
slot among &lt;code&gt;maxConnections&lt;/code&gt;, for ever. Each request on a kept-alive connection has a bound of its
own, and the idle wait before it is no part of it. Zero takes any of these limits away. A
&lt;code&gt;maxHeaderBytes&lt;/code&gt; less than one, a &lt;code&gt;maxBodyBytes&lt;/code&gt; less than zero or a negative &lt;code&gt;requestTimeout&lt;/code&gt; traps.
A server taking bodies larger than the default &lt;code&gt;maxBodyBytes&lt;/code&gt; from slow clients raises
&lt;code&gt;requestTimeout&lt;/code&gt; with it. The
wait for a connection’s next request, its first among them, is made through &lt;code&gt;idle&lt;/code&gt;, so a shutdown
closes a connection waiting there at once, unanswered; a request already being read or answered
finishes, its response saying &lt;code&gt;Connection: close&lt;/code&gt;, and a request read once the server is stopping
is answered &lt;code&gt;503&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;With &lt;code&gt;tls&lt;/code&gt;, the server speaks HTTPS.&lt;/strong&gt; Each connection’s actor begins with a TLS handshake
presenting the &lt;code&gt;TlsServer&lt;/code&gt;‘s certificate, each of its waits lasting at most &lt;code&gt;readTimeout&lt;/code&gt;, and
serves its requests over the &lt;code&gt;TlsStream&lt;/code&gt; exactly as over TCP, kept alive and pipelined alike. A
connection whose handshake fails, a client speaking plain HTTP among them, is closed, and the server
goes on. A handler that traps on a TLS connection has it closed without the &lt;code&gt;500&lt;/code&gt;, since the answer
would have to be written through TLS the handler’s turn held.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;ServerRequest&lt;/code&gt; has its &lt;code&gt;method&lt;/code&gt;, its &lt;code&gt;target&lt;/code&gt; as the request line gave it, its &lt;code&gt;version&lt;/code&gt;
(&lt;code&gt;HTTP/1.1&lt;/code&gt; or &lt;code&gt;HTTP/1.0&lt;/code&gt;), its &lt;code&gt;headers&lt;/code&gt; in order with &lt;code&gt;header(name)&lt;/code&gt; looking one up without regard
to case, its &lt;code&gt;body&lt;/code&gt; with &lt;code&gt;text&lt;/code&gt; reading it as UTF-8, and the &lt;code&gt;params&lt;/code&gt; its route bound, with
&lt;code&gt;param(name)&lt;/code&gt; trapping where the route has none of that name. From the target come &lt;code&gt;path&lt;/code&gt;, its
escapes decoded, &lt;code&gt;segments&lt;/code&gt;, the path’s segments each decoded (so &lt;code&gt;/a%2Fb&lt;/code&gt; is the one segment
&lt;code&gt;a/b&lt;/code&gt;, and &lt;code&gt;/&lt;/code&gt; one empty one), &lt;code&gt;query&lt;/code&gt; as written, and &lt;code&gt;queryParams&lt;/code&gt; as &lt;code&gt;Url.queryParams&lt;/code&gt; reads
them. A target is a path beginning with &lt;code&gt;/&lt;/code&gt; or an absolute &lt;code&gt;http&lt;/code&gt; URL; &lt;code&gt;ServerRequest(method, target)&lt;/code&gt; traps on any other, so a handler can be tried without a connection. A request also carries
the values a middleware handed on, read by &lt;code&gt;value[T]()&lt;/code&gt; (below).&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Response&lt;/code&gt; is the client’s: &lt;code&gt;Response.text(status, text)&lt;/code&gt; (&lt;code&gt;text/plain; charset=utf-8&lt;/code&gt;),
&lt;code&gt;Response.html(status, text)&lt;/code&gt; (&lt;code&gt;text/html; charset=utf-8&lt;/code&gt;, the text sent as given),
&lt;code&gt;Response.json(status, text)&lt;/code&gt; (&lt;code&gt;application/json&lt;/code&gt;, the text sent as given and not checked to be
JSON), &lt;code&gt;Response.bytes(status, body, contentType)&lt;/code&gt;, &lt;code&gt;Response.empty(status)&lt;/code&gt; and &lt;code&gt;withHeader(name, value)&lt;/code&gt;,
which traps on a name that is not a token or a value holding a line break; &lt;code&gt;http.reasonPhrase(status)&lt;/code&gt;
is RFC 9110’s phrase for a status, empty for one it does not name.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cookies&lt;/strong&gt; (RFC 6265). &lt;code&gt;request.cookies()&lt;/code&gt; reads every &lt;code&gt;Cookie&lt;/code&gt; header into &lt;code&gt;Cookie(name, value)&lt;/code&gt;s
in order, &lt;code&gt;request.cookie(name)&lt;/code&gt; the first value of a name; &lt;code&gt;Cookie.parse(header)&lt;/code&gt; reads one header.
Pairs are split at &lt;code&gt;;&lt;/code&gt;, space around a pair, name and value is dropped, a value in double quotes is
read without them, a name seen twice gives two cookies, an empty value is a cookie and a &lt;code&gt;=&lt;/code&gt; in a
value belongs to it. A pair that is not a cookie is skipped and the rest kept: empty, no &lt;code&gt;=&lt;/code&gt;, a name
that is not a token, a value with an octet RFC 6265 does not allow (space, &lt;code&gt;&amp;quot;&lt;/code&gt;, &lt;code&gt;,&lt;/code&gt;, &lt;code&gt;;&lt;/code&gt;, &lt;code&gt;\&lt;/code&gt;,
non-ASCII). &lt;code&gt;SetCookie(name, value, expires, maxAge, domain, path, secure, httpOnly, sameSite, partitioned)&lt;/code&gt; is a cookie to set; &lt;code&gt;header&lt;/code&gt; is its &lt;code&gt;Set-Cookie&lt;/code&gt; value, attributes in that order, &lt;code&gt;Expires&lt;/code&gt;
written by &lt;code&gt;Instant.toHttpDate()&lt;/code&gt;, &lt;code&gt;Max-Age&lt;/code&gt; in seconds (zero or less written &lt;code&gt;0&lt;/code&gt;), &lt;code&gt;sameSite&lt;/code&gt; an
&lt;code&gt;Option[SameSite]&lt;/code&gt; of &lt;code&gt;Strict&lt;/code&gt;, &lt;code&gt;Lax&lt;/code&gt; or &lt;code&gt;Unrestricted&lt;/code&gt; (written &lt;code&gt;SameSite=None&lt;/code&gt;). A cookie is checked
where it is made and traps where it breaks a rule, nothing being escaped or cut: the name is a
token; the value holds only cookie octets; &lt;code&gt;Domain&lt;/code&gt; is letters, digits, &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;; &lt;code&gt;Path&lt;/code&gt; begins
with &lt;code&gt;/&lt;/code&gt; and holds no &lt;code&gt;;&lt;/code&gt; or control character; a &lt;code&gt;__Host-&lt;/code&gt; name (any case) needs &lt;code&gt;Secure&lt;/code&gt;,
&lt;code&gt;Path=/&lt;/code&gt; and no &lt;code&gt;Domain&lt;/code&gt;; a &lt;code&gt;__Secure-&lt;/code&gt; name needs &lt;code&gt;Secure&lt;/code&gt;; &lt;code&gt;SameSite=None&lt;/code&gt; and &lt;code&gt;Partitioned&lt;/code&gt; need
&lt;code&gt;Secure&lt;/code&gt;. &lt;code&gt;response.setCookie(cookie)&lt;/code&gt; adds one &lt;code&gt;Set-Cookie&lt;/code&gt; header per cookie, never folded. On the
client side &lt;code&gt;response.cookies()&lt;/code&gt; and &lt;code&gt;SetCookie.parse(text)&lt;/code&gt; (a &lt;code&gt;Result[SetCookie, CookieError]&lt;/code&gt;)
read &lt;code&gt;Set-Cookie&lt;/code&gt; into the same type: attribute names are case-insensitive, the last of a repeated
attribute wins, and an unknown attribute, an &lt;code&gt;Expires&lt;/code&gt; that is not an HTTP-date, a non-numeric
&lt;code&gt;Max-Age&lt;/code&gt;, a &lt;code&gt;Path&lt;/code&gt; not beginning with &lt;code&gt;/&lt;/code&gt;, an empty &lt;code&gt;Domain&lt;/code&gt; and an unknown &lt;code&gt;SameSite&lt;/code&gt; are ignored;
a bad name or value, a broken prefix rule, or &lt;code&gt;SameSite=None&lt;/code&gt; / &lt;code&gt;Partitioned&lt;/code&gt; without &lt;code&gt;Secure&lt;/code&gt; is an
&lt;code&gt;Err&lt;/code&gt;, and &lt;code&gt;response.cookies()&lt;/code&gt; skips it. A cookie jar is not part of this.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Route(method, pattern, handler)&lt;/code&gt;, or &lt;code&gt;Route.get&lt;/code&gt;, &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt;, &lt;code&gt;delete&lt;/code&gt; and &lt;code&gt;patch&lt;/code&gt;, routes a
method and a pattern; a method that is not a token or a pattern not beginning with &lt;code&gt;/&lt;/code&gt; traps.
&lt;code&gt;Router(routes)&lt;/code&gt; tries its routes in order. A pattern’s segments match a request’s decoded segments
one for one, a segment &lt;code&gt;:name&lt;/code&gt; matching any one that is not empty and binding it, so Unicode paths
route whether escaped or not. A &lt;code&gt;GET&lt;/code&gt; route answers &lt;code&gt;HEAD&lt;/code&gt; too where no &lt;code&gt;HEAD&lt;/code&gt; route matches. A path
no route matches is answered &lt;code&gt;404&lt;/code&gt;, and one that routes match for other methods only &lt;code&gt;405&lt;/code&gt;, with
&lt;code&gt;Allow&lt;/code&gt; naming those methods, &lt;code&gt;HEAD&lt;/code&gt; beside &lt;code&gt;GET&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Typed parameters.&lt;/strong&gt; &lt;code&gt;paramAs[T](name)&lt;/code&gt; reads a route parameter as a &lt;code&gt;T&lt;/code&gt; and &lt;code&gt;queryAs[T](name)&lt;/code&gt; a
query parameter, its first where it is given more than once, each answering &lt;code&gt;Result[T, ParamError]&lt;/code&gt;: &lt;code&gt;Missing(place, name)&lt;/code&gt; where the query has none of that name, &lt;code&gt;Invalid(place, name, text, kind)&lt;/code&gt; where its text does not read as a &lt;code&gt;T&lt;/code&gt; (&lt;code&gt;paramAs&lt;/code&gt; traps on a name the route lacks, as
&lt;code&gt;param&lt;/code&gt; does). &lt;code&gt;queryAs(name, default)&lt;/code&gt; answers &lt;code&gt;default&lt;/code&gt; for a missing one and &lt;code&gt;queryOption[T](name)&lt;/code&gt;
&lt;code&gt;None&lt;/code&gt;. A &lt;code&gt;T&lt;/code&gt; is any &lt;code&gt;FromParam&lt;/code&gt;, a trait of two static methods, &lt;code&gt;parse(text) -&amp;gt; Option[Self]&lt;/code&gt; and
&lt;code&gt;kind()&lt;/code&gt;, the words naming it in an error (“an int”); &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt; and &lt;code&gt;bool&lt;/code&gt;
implement it, and a program’s own type may. A &lt;code&gt;ParamError&lt;/code&gt;‘s &lt;code&gt;message&lt;/code&gt; is the sentence for the
client, as in &lt;code&gt;the query parameter `n` is `x`, which is not an int&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Handlers that fail.&lt;/strong&gt; &lt;code&gt;ToResponse&lt;/code&gt; is a failure a handler can answer with, its &lt;code&gt;toResponse()&lt;/code&gt; the
response telling the client. &lt;code&gt;Response&lt;/code&gt; implements it as itself and &lt;code&gt;ParamError&lt;/code&gt; as a &lt;code&gt;400&lt;/code&gt; with its
message; a program’s own error type may too. &lt;code&gt;fromResult(answer)&lt;/code&gt; makes a &lt;code&gt;Handler&lt;/code&gt; of a function
answering &lt;code&gt;Result[Response, ToResponse]&lt;/code&gt;, an &lt;code&gt;Err&lt;/code&gt; answered with its failure’s response, and each of
&lt;code&gt;Route.get&lt;/code&gt;, &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt;, &lt;code&gt;delete&lt;/code&gt; and &lt;code&gt;patch&lt;/code&gt; has an overload taking such a function, so &lt;code&gt;?&lt;/code&gt; ends a
handler early:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;half(r: ServerRequest) -&amp;gt; Result[Response, ToResponse]
  val n = r.paramAs[int](&amp;quot;n&amp;quot;)?
  if n % 2 != 0 then return Err(Response.text(422, &amp;quot;odd\n&amp;quot;))
  Ok(Response.text(200, s&amp;quot;${n / 2}\n&amp;quot;))

val route = Route.get(&amp;quot;/half/:n&amp;quot;, half)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Forms.&lt;/strong&gt; &lt;code&gt;request.form()&lt;/code&gt; reads an &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; body as a &lt;code&gt;Form&lt;/code&gt;: its
&lt;code&gt;pairs&lt;/code&gt; in order, a name given more than once kept each time, &lt;code&gt;value(name)&lt;/code&gt; the first value of a
name and &lt;code&gt;values(name)&lt;/code&gt; every one. The body is decoded by &lt;code&gt;Url.formDecode&lt;/code&gt;, as UTF-8 whatever
&lt;code&gt;charset&lt;/code&gt; the type names. &lt;code&gt;request.multipart(limits = MultipartLimits())&lt;/code&gt; reads a
&lt;code&gt;multipart/form-data&lt;/code&gt; body (RFC 7578) as a &lt;code&gt;Multipart&lt;/code&gt;: its &lt;code&gt;parts&lt;/code&gt; in order, &lt;code&gt;field(name)&lt;/code&gt; the text
of the first part of that name that is not a file, &lt;code&gt;file(name)&lt;/code&gt; the first that is, and
&lt;code&gt;named(name)&lt;/code&gt; every part of that name. A &lt;code&gt;Part&lt;/code&gt; has its &lt;code&gt;name&lt;/code&gt;, its &lt;code&gt;filename&lt;/code&gt; where it is a file
(&lt;code&gt;isFile&lt;/code&gt;), its &lt;code&gt;contentType&lt;/code&gt; (&lt;code&gt;text/plain&lt;/code&gt; where it names none), its &lt;code&gt;headers&lt;/code&gt; with &lt;code&gt;header(name)&lt;/code&gt;,
its &lt;code&gt;body&lt;/code&gt; and &lt;code&gt;text&lt;/code&gt;. &lt;strong&gt;A filename is the sender’s text, untrusted&lt;/strong&gt;: it may hold &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;..&lt;/code&gt;, a drive
letter or anything else, and is never a path to write to as given; the library writes nothing to
disk from it. &lt;code&gt;Multipart.parse(body, contentType, limits)&lt;/code&gt; reads a body that did not come to a
server, such as a client’s response.&lt;/p&gt;
&lt;p&gt;Each answers &lt;code&gt;Result[_, FormError]&lt;/code&gt;, and &lt;code&gt;FormError&lt;/code&gt; is a &lt;code&gt;ToResponse&lt;/code&gt;, so &lt;code&gt;?&lt;/code&gt; ends a handler with it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Error&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;th&gt;When&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;NotAForm(expected, found)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;415&lt;/td&gt;&lt;td&gt;The &lt;code&gt;Content-Type&lt;/code&gt; is not the form’s type, or there is none.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;BadEncoding(UrlError)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;400&lt;/td&gt;&lt;td&gt;An urlencoded body with a malformed &lt;code&gt;%&lt;/code&gt; escape or bytes that are not UTF-8.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;NoBoundary&lt;/code&gt;&lt;/td&gt;&lt;td&gt;400&lt;/td&gt;&lt;td&gt;No &lt;code&gt;boundary&lt;/code&gt; parameter, or one that is not 1 to 70 of RFC 2046’s characters, not ending in a space.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;BadMultipart(reason)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;400&lt;/td&gt;&lt;td&gt;No delimiter, no closing delimiter, a part’s headers unended, not UTF-8 or not &lt;code&gt;name: value&lt;/code&gt;, or a part without &lt;code&gt;Content-Disposition: form-data&lt;/code&gt; and a &lt;code&gt;name&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TooManyParts(limit)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;413&lt;/td&gt;&lt;td&gt;More parts than &lt;code&gt;limits.maxParts&lt;/code&gt; (1000 by default).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;PartHeadersTooLarge(limit)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;413&lt;/td&gt;&lt;td&gt;A part’s headers longer than &lt;code&gt;limits.maxHeaderBytes&lt;/code&gt; (8192).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;FormTooLarge(limit)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;413&lt;/td&gt;&lt;td&gt;A body longer than &lt;code&gt;limits.maxBytes&lt;/code&gt; (10 MiB); the server’s own &lt;code&gt;maxBodyBytes&lt;/code&gt; bounds it first.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A multipart body is read as RFC 2046 writes one: text before the first delimiter and after the
closing one is skipped, every line ends in CRLF, a delimiter’s line may end in spaces and tabs, and
bytes that resemble the boundary but are not followed by &lt;code&gt;--&lt;/code&gt; or the end of the line stay in the
part. A name or filename is read as the WHATWG HTML standard writes one, quoted with &lt;code&gt;%22&lt;/code&gt;, &lt;code&gt;%0D&lt;/code&gt;
and &lt;code&gt;%0A&lt;/code&gt; standing for &lt;code&gt;&amp;quot;&lt;/code&gt;, CR and LF and no backslash escapes; a &lt;code&gt;filename*&lt;/code&gt; (RFC 5987) in UTF-8 or
ISO-8859-1 is preferred to &lt;code&gt;filename&lt;/code&gt;, and one in another charset or malformed is ignored. The body
is read whole, as the server has buffered it; a streaming reader for large uploads will come beside
&lt;code&gt;parse&lt;/code&gt;, with the same limits and errors
(&lt;a href=&quot;/spec/decisions/#settled&quot;&gt;decided&lt;/a&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;upload(r: ServerRequest) -&amp;gt; Result[Response, ToResponse]
  val form = r.multipart()?
  val title = form.field(&amp;quot;title&amp;quot;).getOrElse(&amp;quot;untitled&amp;quot;)
  val size = form.file(&amp;quot;doc&amp;quot;).map(p -&amp;gt; p.body.length).getOrElse(0)
  Ok(Response.text(200, s&amp;quot;$title: $size bytes\n&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Groups and middleware.&lt;/strong&gt; &lt;code&gt;type Handler = @sendable (ServerRequest) -&amp;gt; Response&lt;/code&gt;; a middleware is a
&lt;code&gt;(Handler) -&amp;gt; Handler&lt;/code&gt;. &lt;code&gt;route.wrap(middleware)&lt;/code&gt; passes a route’s handler through one, wrapping again
putting the newer outside, so it runs first; &lt;code&gt;route.under(prefix)&lt;/code&gt; puts a route’s pattern after
&lt;code&gt;prefix&lt;/code&gt;, a pattern of &lt;code&gt;/&lt;/code&gt; becoming the prefix itself. &lt;code&gt;Route.group(prefix, routes, middleware = h -&amp;gt; h)&lt;/code&gt; answers each of &lt;code&gt;routes&lt;/code&gt; under &lt;code&gt;prefix&lt;/code&gt; and wrapped by &lt;code&gt;middleware&lt;/code&gt;, and groups nest, an inner
group’s middleware running inside the outer’s. A prefix begins with &lt;code&gt;/&lt;/code&gt;, does not end with one and
may bind parameters as a pattern does; one that does not hold traps.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Values a middleware hands on.&lt;/strong&gt; &lt;code&gt;request.withValue(value)&lt;/code&gt; answers the request carrying &lt;code&gt;value&lt;/code&gt;,
and &lt;code&gt;request.value[T]()&lt;/code&gt; answers &lt;code&gt;Some&lt;/code&gt; of the value the request carries as its &lt;code&gt;T&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; where it
carries none; both take a &lt;code&gt;T: Sendable&lt;/code&gt;, since a request may be answered on any thread. A request is
a value: &lt;code&gt;withValue&lt;/code&gt; answers a new one and leaves the request it was called on as it was. The type is
the key, compared exactly, as a type pattern compares a generic type’s arguments: handing on a
second value of one type replaces the first, a value handed on as an &lt;code&gt;int&lt;/code&gt; is no &lt;code&gt;long&lt;/code&gt;, one handed
on as a trait’s type is read as that trait and not as its class, and &lt;code&gt;Vector[int]&lt;/code&gt; is not
&lt;code&gt;Vector[string]&lt;/code&gt;. Two values of one type are handed on as two types of the program’s own, a
&lt;code&gt;data RequestId(value: string)&lt;/code&gt; beside a &lt;code&gt;data TraceId(value: string)&lt;/code&gt;. The values go wherever the
request goes: through a router’s binding of parameters, groups, nested middleware (an inner one
replacing what an outer one handed on, if it hands on the same type) and the streamed and
event-stream handlers, whose &lt;code&gt;write&lt;/code&gt; reads the request it was made from. An authenticating
middleware hands its user to the handlers inside it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.http
import avin.net.http.{Handler, Response, Route, Router, ServerRequest}

data User(name: string)

// Answers `401` without a token, and hands the token&apos;s user to the handler with one.
auth(next: Handler) -&amp;gt; Handler = r -&amp;gt; r.header(&amp;quot;Authorization&amp;quot;) match
  Some(token) -&amp;gt; next(r.withValue(User(token)))
  None -&amp;gt; Response.text(401, &amp;quot;who are you?&amp;quot;)

me(r: ServerRequest) -&amp;gt; Response = r.value[User]() match
  Some(u) -&amp;gt; Response.text(200, s&amp;quot;hello, ${u.name}\n&amp;quot;)
  None -&amp;gt; Response.text(500, &amp;quot;the route is outside `auth`\n&amp;quot;)

main()
  val router = Router(Route.group(&amp;quot;/api&amp;quot;, [Route.get(&amp;quot;/me&amp;quot;, me)], auth) :+ Route.get(&amp;quot;/me&amp;quot;, me))
  http.serve(&amp;quot;0.0.0.0&amp;quot;, 8080, router.handle).ok.get.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;GET /api/me&lt;/code&gt; with an &lt;code&gt;Authorization&lt;/code&gt; header is answered &lt;code&gt;hello&lt;/code&gt; and the token; &lt;code&gt;/me&lt;/code&gt;, outside the
group, finds no &lt;code&gt;User&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Error pages.&lt;/strong&gt; &lt;code&gt;type ErrorPage = @sendable (int) -&amp;gt; Response&lt;/code&gt; renders the responses a router and a
server make themselves for an error status: &lt;code&gt;Router(routes, errors)&lt;/code&gt; its &lt;code&gt;404&lt;/code&gt; and &lt;code&gt;405&lt;/code&gt;, and
&lt;code&gt;http.serve(…, errors)&lt;/code&gt; every status of the table below. The status sent is the one given, whatever
the page answered, and a &lt;code&gt;405&lt;/code&gt; still carries its &lt;code&gt;Allow&lt;/code&gt; header. &lt;code&gt;http.plainError&lt;/code&gt;, the default, answers the
status’s reason phrase as plain text.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What a middleware sees of a request.&lt;/strong&gt; &lt;code&gt;request.remote: Option[string]&lt;/code&gt; is the client’s IP address,
written numerically without its port (&lt;code&gt;127.0.0.1&lt;/code&gt;, &lt;code&gt;::1&lt;/code&gt;), over TCP and over TLS alike; &lt;code&gt;None&lt;/code&gt; for a
request made without a connection. &lt;code&gt;request.route: Option[string]&lt;/code&gt; is the whole pattern of the route
a router chose (&lt;code&gt;/api/users/:id&lt;/code&gt; under its groups; a &lt;code&gt;GET&lt;/code&gt; route’s for a &lt;code&gt;HEAD&lt;/code&gt; it answers), &lt;code&gt;None&lt;/code&gt;
until one has, so a middleware wrapped around a whole router’s &lt;code&gt;handle&lt;/code&gt; sees &lt;code&gt;None&lt;/code&gt;.
&lt;code&gt;request.withHeaderReplaced(name, value)&lt;/code&gt; is the request with every header of &lt;code&gt;name&lt;/code&gt;, any case,
replaced by one, added last, a name that is not a token or a value holding a line break trapping. A
&lt;code&gt;ByteStream&lt;/code&gt;‘s &lt;code&gt;remoteAddress&lt;/code&gt; is where &lt;code&gt;remote&lt;/code&gt; comes from: the other end’s address for a
&lt;code&gt;TcpStream&lt;/code&gt;, accepted or connected, and a &lt;code&gt;TlsStream&lt;/code&gt;, and &lt;code&gt;None&lt;/code&gt; for a &lt;code&gt;UnixStream&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Access log.&lt;/strong&gt; &lt;code&gt;http.accessLog(sink = standardError, format = PlainLines, clock = monotonic, ids = newRequestId)&lt;/code&gt; is a middleware writing one line to &lt;code&gt;sink&lt;/code&gt;, a &lt;code&gt;@sendable (string) -&amp;gt; unit&lt;/code&gt; called once
a line with no line end, for each request once its handler has answered:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;GET /items/7 200 12 1.5ms id=4f1c…e2 remote=127.0.0.1
{&amp;quot;id&amp;quot;:&amp;quot;4f1c…e2&amp;quot;,&amp;quot;method&amp;quot;:&amp;quot;GET&amp;quot;,&amp;quot;path&amp;quot;:&amp;quot;/items/7&amp;quot;,&amp;quot;status&amp;quot;:200,&amp;quot;bytes&amp;quot;:12,&amp;quot;micros&amp;quot;:1500,&amp;quot;remote&amp;quot;:&amp;quot;127.0.0.1&amp;quot;}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first is &lt;code&gt;PlainLines&lt;/code&gt;, the second &lt;code&gt;JsonLines&lt;/code&gt;. The path is the decoded one, its spaces, quotes,
backslashes and control characters written &lt;code&gt;%XX&lt;/code&gt; in a plain line and escaped as JSON in a JSON one;
&lt;code&gt;bytes&lt;/code&gt; is the body’s length, or a streamed body’s length said beforehand, &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt; where it is
not known, as is an address. The request id is the client’s &lt;code&gt;X-Request-Id&lt;/code&gt; where
&lt;code&gt;http.isRequestId&lt;/code&gt; takes it (1 to 128 ASCII letters, digits and &lt;code&gt;-._:+/=@&lt;/code&gt;), and a new one from &lt;code&gt;ids&lt;/code&gt;
otherwise, 32 hexadecimal digits from &lt;code&gt;SecureRandom&lt;/code&gt; by default; the handler reads it in the request’s
&lt;code&gt;X-Request-Id&lt;/code&gt;, which replaces any the client sent, and the response carries it back unless the
handler set its own. The default sink writes each line to standard error in one write, so lines from
several connections never interleave. The time is read from &lt;code&gt;clock&lt;/code&gt;, a &lt;code&gt;@sendable () -&amp;gt; Duration&lt;/code&gt;,
before and after the handler. A handler that traps writes no line.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;http.accessLog(logger, clock = monotonic, ids = newRequestId)&lt;/code&gt; is the same middleware writing
through an &lt;a href=&quot;#avinlog&quot;&gt;&lt;code&gt;avin.log&lt;/code&gt;&lt;/a&gt; &lt;code&gt;Logger&lt;/code&gt;: an &lt;code&gt;Info&lt;/code&gt; record &lt;code&gt;request&lt;/code&gt; for each request, its fields
&lt;code&gt;id&lt;/code&gt;, &lt;code&gt;method&lt;/code&gt;, &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;status&lt;/code&gt;, &lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;micros&lt;/code&gt; and &lt;code&gt;remote&lt;/code&gt; after the logger’s own, a length or
an address not known left out, in the logger’s format. A logger that leaves out &lt;code&gt;Info&lt;/code&gt; records
makes none, though the request id is still found, passed on and answered.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;2026-11-23T10:20:30.5Z INFO  request svc=web id=4f1c…e2 method=GET path=/items/7 status=200 bytes=12 micros=1500 remote=127.0.0.1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Metrics.&lt;/strong&gt; &lt;code&gt;Metrics(buckets = defaultBuckets, clock = monotonic)&lt;/code&gt; counts the requests its
&lt;code&gt;middleware&lt;/code&gt; passes on, shared by every connection’s actor under a lock of its own:
&lt;code&gt;http_requests_total&lt;/code&gt; by &lt;code&gt;method&lt;/code&gt;, &lt;code&gt;route&lt;/code&gt; (the route’s pattern, &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; where none was chosen) and
&lt;code&gt;status&lt;/code&gt; class (&lt;code&gt;2xx&lt;/code&gt;); &lt;code&gt;http_request_duration_seconds&lt;/code&gt;, a histogram of &lt;code&gt;buckets&lt;/code&gt; (5 ms to 10 s by
default), a time equal to a bound counted in that bound’s bucket, with its &lt;code&gt;_sum&lt;/code&gt; and &lt;code&gt;_count&lt;/code&gt;; and
the gauge &lt;code&gt;http_requests_in_flight&lt;/code&gt;. &lt;code&gt;render&lt;/code&gt; is the Prometheus text format, series ordered by route,
method and status class; &lt;code&gt;handler&lt;/code&gt; answers it as &lt;code&gt;200&lt;/code&gt; of the type &lt;code&gt;MetricsContentType&lt;/code&gt;
(&lt;code&gt;text/plain; version=0.0.4; charset=utf-8&lt;/code&gt;), and &lt;code&gt;route(pattern = &amp;quot;/metrics&amp;quot;)&lt;/code&gt; mounts it.
&lt;code&gt;observe(method, route, status, took)&lt;/code&gt; counts a request answered another way, and &lt;code&gt;inFlight&lt;/code&gt; is the
gauge’s value. Buckets not in increasing order, or one not above zero, trap.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val metrics = Metrics()
val router = Router(Route.group(&amp;quot;/api&amp;quot;, routes, metrics.middleware) :+ metrics.route())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Wrapping a group or a route labels each request by its route; wrapping a router’s &lt;code&gt;handle&lt;/code&gt; counts the
&lt;code&gt;404&lt;/code&gt;s and &lt;code&gt;405&lt;/code&gt;s too, every request labelled &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;. A handler that traps is not counted, and leaves the
gauge one higher.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Rate limiting.&lt;/strong&gt; &lt;code&gt;RateLimiter(rate, per, burst = rate, key = clientAddress, maxKeys = 10000, clock = monotonic, errors = plainError)&lt;/code&gt; gives each key a token bucket of &lt;code&gt;burst&lt;/code&gt; tokens filled again at
&lt;code&gt;rate&lt;/code&gt; every &lt;code&gt;per&lt;/code&gt;. Its &lt;code&gt;middleware&lt;/code&gt; takes a token for each request, keyed by &lt;code&gt;key&lt;/code&gt; (the client’s
address by default, &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; for a request with none), and answers one finding its bucket empty &lt;code&gt;429&lt;/code&gt;,
rendered by &lt;code&gt;errors&lt;/code&gt;, with &lt;code&gt;Retry-After&lt;/code&gt; the seconds until the next token, rounded up and at least
one. &lt;code&gt;admit(key) -&amp;gt; Result[unit, Duration]&lt;/code&gt; takes a token directly, &lt;code&gt;Err&lt;/code&gt; saying how long until the
next. At most &lt;code&gt;maxKeys&lt;/code&gt; buckets are held (&lt;code&gt;size&lt;/code&gt; says how many): making one more forgets every bucket
full again, which a new one would equal, and where none is, the one nearest to full. A rate, burst
or &lt;code&gt;maxKeys&lt;/code&gt; below one traps, and so does a &lt;code&gt;per&lt;/code&gt; too short to give each token a whole microsecond.
The three middlewares compose as any do: &lt;code&gt;h -&amp;gt; metrics.middleware(limiter.middleware(h))&lt;/code&gt; counts the
&lt;code&gt;429&lt;/code&gt;s the limiter answers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CORS.&lt;/strong&gt; &lt;code&gt;Cors(origins = [&amp;quot;*&amp;quot;], allowOrigin = _ -&amp;gt; false, methods = [&amp;quot;GET&amp;quot;, &amp;quot;HEAD&amp;quot;, &amp;quot;POST&amp;quot;], headers = [], exposed = [], credentials = false, maxAge = None)&lt;/code&gt; is a policy whose &lt;code&gt;middleware&lt;/code&gt; lets a page from
another origin read responses. An origin is allowed if &lt;code&gt;origins&lt;/code&gt; holds it (compared exactly), holds
&lt;code&gt;&amp;quot;*&amp;quot;&lt;/code&gt;, or &lt;code&gt;allowOrigin&lt;/code&gt; says so; &lt;code&gt;allows(origin)&lt;/code&gt; asks. An allowed request’s response gets
&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt; (&lt;code&gt;*&lt;/code&gt; where the policy is &lt;code&gt;*&lt;/code&gt; without credentials, else the origin,
with &lt;code&gt;Vary: Origin&lt;/code&gt; merged into any &lt;code&gt;Vary&lt;/code&gt; the handler set, once, and left alone where it is &lt;code&gt;*&lt;/code&gt;),
&lt;code&gt;Access-Control-Allow-Credentials: true&lt;/code&gt; where &lt;code&gt;credentials&lt;/code&gt;, and &lt;code&gt;Access-Control-Expose-Headers&lt;/code&gt;
where &lt;code&gt;exposed&lt;/code&gt; names some. A request with no &lt;code&gt;Origin&lt;/code&gt;, or from one not allowed, is handled as it
is, with no CORS header. A preflight (&lt;code&gt;OPTIONS&lt;/code&gt; with &lt;code&gt;Origin&lt;/code&gt; and &lt;code&gt;Access-Control-Request-Method&lt;/code&gt;)
is answered &lt;code&gt;204&lt;/code&gt; and never reaches the handler; from an allowed origin asking for a method in
&lt;code&gt;methods&lt;/code&gt; and headers in &lt;code&gt;headers&lt;/code&gt; (compared without regard to case; any, where &lt;code&gt;headers&lt;/code&gt; is empty,
echoed back) it carries &lt;code&gt;Access-Control-Allow-Methods&lt;/code&gt;, &lt;code&gt;-Allow-Headers&lt;/code&gt;, &lt;code&gt;-Max-Age&lt;/code&gt; (whole
seconds) and the origin and credentials headers; asking for more, or from an origin not allowed, it
carries none. &lt;code&gt;*&lt;/code&gt; together with &lt;code&gt;credentials&lt;/code&gt;, and a negative &lt;code&gt;maxAge&lt;/code&gt;, trap where the policy is
made.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Streamed responses.&lt;/strong&gt; &lt;code&gt;Response.stream(status, contentType, write)&lt;/code&gt; answers a response whose body
&lt;code&gt;write&lt;/code&gt; writes as it goes, through the &lt;code&gt;BodyWriter&lt;/code&gt; it is given, each write sent to the client at
once; its &lt;code&gt;body&lt;/code&gt; is empty. Its head says &lt;code&gt;Transfer-Encoding: chunked&lt;/code&gt; and each write is a chunk, the
body ended by the empty one once &lt;code&gt;write&lt;/code&gt; returns; to an HTTP/1.0 client it says neither, and the
body ends with the connection. &lt;code&gt;Response.stream(status, contentType, length, write)&lt;/code&gt; says
&lt;code&gt;Content-Length: length&lt;/code&gt; beforehand instead: a write past it traps, a negative length traps, and a
body ending short closes the connection. &lt;code&gt;BodyWriter.write(bytes)&lt;/code&gt; and &lt;code&gt;write(text)&lt;/code&gt; answer
&lt;code&gt;Result[unit, IoError]&lt;/code&gt;: &lt;code&gt;Err&lt;/code&gt; once the client has gone or the server is stopping, and for every
write after one that failed, so the code writing a stream ends there; a failed write closes the
connection. A &lt;code&gt;BodyWriter&lt;/code&gt; is an &lt;a href=&quot;#bytewriter&quot;&gt;&lt;code&gt;io.ByteWriter&lt;/code&gt;&lt;/a&gt; by &lt;code&gt;write(bytes)&lt;/code&gt;, so
&lt;code&gt;io.copy(reader, w)&lt;/code&gt; streams a file or any other &lt;code&gt;Reader&lt;/code&gt; into a body. No body is written for
&lt;code&gt;HEAD&lt;/code&gt;, &lt;code&gt;204&lt;/code&gt; or &lt;code&gt;304&lt;/code&gt;, and &lt;code&gt;write&lt;/code&gt; is not run.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Response.events(write)&lt;/code&gt; is a stream of server-sent events, &lt;code&gt;200&lt;/code&gt; of the type &lt;code&gt;text/event-stream&lt;/code&gt;,
written through an &lt;code&gt;EventWriter&lt;/code&gt;: &lt;code&gt;send(text, event = None, id = None)&lt;/code&gt; sends an event, each line of
&lt;code&gt;text&lt;/code&gt; (split at &lt;code&gt;\r\n&lt;/code&gt;, &lt;code&gt;\r&lt;/code&gt; or &lt;code&gt;\n&lt;/code&gt;) a &lt;code&gt;data:&lt;/code&gt; line after its &lt;code&gt;event:&lt;/code&gt; and &lt;code&gt;id:&lt;/code&gt; lines, a type or an
id holding a line break trapping; &lt;code&gt;comment(text)&lt;/code&gt; sends a comment, which a client passes over; and
&lt;code&gt;retry(delay)&lt;/code&gt; tells the client how long to wait before reconnecting. &lt;code&gt;Response.events(keepAlive, write)&lt;/code&gt; sets how often a comment is sent while &lt;code&gt;untilStopped&lt;/code&gt; waits, fifteen seconds by default and
none for zero, so a client that has gone is noticed and one still there keeps the stream open.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Waiting in a handler.&lt;/strong&gt; &lt;code&gt;request.isStopping()&lt;/code&gt; says whether the server that read the request is
stopping, and &lt;code&gt;request.untilStopped(wait)&lt;/code&gt; runs &lt;code&gt;wait&lt;/code&gt;, a &lt;code&gt;@sendable () -&amp;gt; T&lt;/code&gt;, on a thread of its own
and answers &lt;code&gt;Some&lt;/code&gt; of its result, or &lt;code&gt;None&lt;/code&gt; where the server stops first, cancelling &lt;code&gt;wait&lt;/code&gt; wherever
it waits as &lt;code&gt;TcpServer.idle&lt;/code&gt; does: a long poll answers at once rather than holding the shutdown. Where
the server is already stopping &lt;code&gt;wait&lt;/code&gt; is not run. &lt;code&gt;BodyWriter&lt;/code&gt; and &lt;code&gt;EventWriter&lt;/code&gt; have both too, the
&lt;code&gt;EventWriter&lt;/code&gt;‘s sending its keep-alive comments while it waits and answering &lt;code&gt;None&lt;/code&gt; once one cannot
be sent. A request made without a server never stops, and &lt;code&gt;wait&lt;/code&gt; is then run as it is.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The connection.&lt;/strong&gt; Requests are read one after another, so several are kept alive on one
connection and pipelined ones are answered in order: in HTTP/1.1 unless either side says
&lt;code&gt;Connection: close&lt;/code&gt;, in HTTP/1.0 only on &lt;code&gt;Connection: keep-alive&lt;/code&gt;, which the response then repeats.
Empty lines before a request line are passed over, and a line may end in a bare &lt;code&gt;\n&lt;/code&gt;. A body is read
by &lt;code&gt;Content-Length&lt;/code&gt; or chunked (extensions and trailers passed over); an &lt;code&gt;Expect: 100-continue&lt;/code&gt; is
answered &lt;code&gt;100 Continue&lt;/code&gt; once the body is known to fit. The server writes &lt;code&gt;Content-Length&lt;/code&gt; and
&lt;code&gt;Connection&lt;/code&gt; itself, in place of any the handler gave, every response as &lt;code&gt;HTTP/1.1&lt;/code&gt;, and no body for
&lt;code&gt;HEAD&lt;/code&gt;, &lt;code&gt;204&lt;/code&gt; and &lt;code&gt;304&lt;/code&gt;; a streamed response’s framing is its own, as above. A handler’s status
outside 200 to 599, or a header the response cannot carry, traps.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A request the server cannot take is answered and the connection closed&lt;/strong&gt;, gently: its side is shut
and what the client still sends read and dropped for half a second at most, so the answer is not
lost to a reset and a client that goes on trickling is closed all the same.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Status&lt;/th&gt;&lt;th&gt;When&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;400&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A request line that is not three words, a method that is not a token, a malformed version, a target that is not one (a fragment, an escape that is not UTF-8 among them), no &lt;code&gt;Host&lt;/code&gt; in HTTP/1.1 or two, a header without a colon, with a name that is not a token or folded onto a second line, a &lt;code&gt;Content-Length&lt;/code&gt; that is not digits or two that differ, one beside &lt;code&gt;Transfer-Encoding&lt;/code&gt;, a coding list not ending in &lt;code&gt;chunked&lt;/code&gt;, a malformed chunk&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;408&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A wait while a request is read outlasts &lt;code&gt;readTimeout&lt;/code&gt;, or the request is not read whole within &lt;code&gt;requestTimeout&lt;/code&gt; of its first byte&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;413&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A body longer than &lt;code&gt;maxBodyBytes&lt;/code&gt;, by its length before it is read, or as its chunks arrive&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;414&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A request line longer than &lt;code&gt;maxHeaderBytes&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;417&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An &lt;code&gt;Expect&lt;/code&gt; other than &lt;code&gt;100-continue&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;431&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The request line and headers together, or a chunked body’s trailers, longer than &lt;code&gt;maxHeaderBytes&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;500&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The handler traps: it fails its connection alone, as a &lt;code&gt;TcpServer&lt;/code&gt;‘s &lt;code&gt;serve&lt;/code&gt; does (over TLS, or once a streamed response’s head is sent, the connection is closed unanswered)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;501&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A transfer coding besides &lt;code&gt;chunked&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;503&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A request read once the server is stopping&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;505&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A version other than 1.0 and 1.1&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A connection waiting for a first request waits &lt;code&gt;readTimeout&lt;/code&gt;, and for a later one &lt;code&gt;idleTimeout&lt;/code&gt;,
then is closed without an answer. &lt;strong&gt;Shutting down&lt;/strong&gt;, the server answers the request in flight with
&lt;code&gt;Connection: close&lt;/code&gt;, and one arriving on a kept-alive connection &lt;code&gt;503&lt;/code&gt;; a connection waiting for its
next request ends when its idle limit runs out, and &lt;code&gt;join()&lt;/code&gt; waits for that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Upgrades.&lt;/strong&gt; &lt;code&gt;Response.upgrade(protocol, take)&lt;/code&gt; answers &lt;code&gt;101 Switching Protocols&lt;/code&gt; with &lt;code&gt;Upgrade: protocol&lt;/code&gt; and &lt;code&gt;Connection: Upgrade&lt;/code&gt; (the protocol a token, else it traps), and once that head is
sent the connection is no longer HTTP’s: &lt;code&gt;take&lt;/code&gt; is given an &lt;code&gt;Upgraded&lt;/code&gt;, with its &lt;code&gt;stream&lt;/code&gt;, the bytes
the client sent after its request that the server had already read (&lt;code&gt;ahead&lt;/code&gt;), the &lt;code&gt;writeTimeout&lt;/code&gt;, and
&lt;code&gt;isStopping()&lt;/code&gt; and &lt;code&gt;untilStopped(wait)&lt;/code&gt; as a request has them. No request is read after it, the
connection is closed when &lt;code&gt;take&lt;/code&gt; returns, and a &lt;code&gt;take&lt;/code&gt; that traps closes it with nothing written.&lt;/p&gt;
&lt;h3 id=&quot;websockets&quot;&gt;WebSockets&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;webSocket(request, session)&lt;/code&gt; answers a WebSocket handshake (RFC 6455) from a handler, and
&lt;code&gt;WebSocket.connect(url)&lt;/code&gt; opens one as a client; each end holds a &lt;code&gt;WebSocket&lt;/code&gt; and the two speak alike:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.http
import avin.net.http.{Binary, Route, Router, Text, WebSocket, webSocket}

echo(ws: WebSocket)
  loop
    ws.receive() match
      Ok(Text(t)) -&amp;gt; _ = ws.send(t)
      Ok(Binary(b)) -&amp;gt; _ = ws.send(b)
      Err(_) -&amp;gt; return

main()
  val router = Router([Route.get(&amp;quot;/echo&amp;quot;, r -&amp;gt; webSocket(r, echo))])
  http.serve(&amp;quot;0.0.0.0&amp;quot;, 8080, router.handle).ok.get.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;webSocket(request, session, protocols = [], maxMessageBytes = 1048576, closeTimeout = seconds(5), outboxSize = 64) -&amp;gt; Response&lt;/code&gt; checks the handshake and answers &lt;code&gt;101&lt;/code&gt; with its &lt;code&gt;Sec-WebSocket-Accept&lt;/code&gt;
(&lt;code&gt;acceptKey(key)&lt;/code&gt;, the base64 of the SHA-1 of the key and the protocol’s GUID), then runs
&lt;code&gt;session&lt;/code&gt; with the WebSocket, closing it with &lt;code&gt;1000&lt;/code&gt; if &lt;code&gt;session&lt;/code&gt; returns leaving it open. Of
&lt;code&gt;protocols&lt;/code&gt;, the subprotocols the server speaks, the first the client offers in
&lt;code&gt;Sec-WebSocket-Protocol&lt;/code&gt; is chosen, answered and found in &lt;code&gt;ws.protocol&lt;/code&gt;; none where the client
offers none of them. A request that is not a handshake is answered without &lt;code&gt;session&lt;/code&gt; running:
&lt;code&gt;405&lt;/code&gt; for a method other than &lt;code&gt;GET&lt;/code&gt;; &lt;code&gt;426&lt;/code&gt; with &lt;code&gt;Upgrade: websocket&lt;/code&gt; where it does not ask to
upgrade to a WebSocket; &lt;code&gt;426&lt;/code&gt; with &lt;code&gt;Sec-WebSocket-Version: 13&lt;/code&gt; for another version; &lt;code&gt;400&lt;/code&gt; in
HTTP/1.0, without &lt;code&gt;upgrade&lt;/code&gt; in &lt;code&gt;Connection&lt;/code&gt;, or with a &lt;code&gt;Sec-WebSocket-Key&lt;/code&gt; that is not sixteen bytes
of base64. A negative &lt;code&gt;maxMessageBytes&lt;/code&gt; or &lt;code&gt;outboxSize&lt;/code&gt; traps. A route is otherwise an ordinary route, under groups
and middleware alike, and it works over TLS as every route does.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;WebSocket.connect(url, headers = [], protocols = [], tls = TlsClient(), timeout = seconds(30), maxMessageBytes = 1048576, outboxSize = 64) -&amp;gt; Result[WebSocket, WebSocketError]&lt;/code&gt; opens &lt;code&gt;ws://&lt;/code&gt; and &lt;code&gt;wss://&lt;/code&gt; URLs,
the latter over TLS checked as an &lt;code&gt;https&lt;/code&gt; request’s is, sending &lt;code&gt;headers&lt;/code&gt; and offering &lt;code&gt;protocols&lt;/code&gt;
in the handshake; &lt;code&gt;timeout&lt;/code&gt; limits each wait of the handshake and each write after it.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;WebSocket&lt;/code&gt; sends &lt;code&gt;send(text)&lt;/code&gt; and &lt;code&gt;send(bytes)&lt;/code&gt; as one message each, a message over 65536 bytes in
fragments of that many written one after another, &lt;code&gt;ping(payload = [])&lt;/code&gt; (at most
125 bytes, else it traps), and &lt;code&gt;close(code = 1000, reason = &amp;quot;&amp;quot;)&lt;/code&gt;, which sends the close frame, waits
the close timeout for the other end’s answer and closes the connection; a code is 1000 to 1003, 1007
to 1014 or 3000 to 4999 and a reason at most 123 bytes of UTF-8, either trapping where it is not.
&lt;code&gt;receive()&lt;/code&gt; answers the next &lt;code&gt;Message&lt;/code&gt;, &lt;code&gt;Text(text)&lt;/code&gt; or &lt;code&gt;Binary(bytes)&lt;/code&gt;, waiting as long as it
takes; &lt;code&gt;receive(limit)&lt;/code&gt; answers &lt;code&gt;Ok(None)&lt;/code&gt; where no whole message has arrived by then, keeping a
message that arrived in part. &lt;code&gt;isOpen()&lt;/code&gt; says whether it can still be used, and &lt;code&gt;isStopping()&lt;/code&gt; and
&lt;code&gt;untilStopped(wait)&lt;/code&gt; are the server’s, a client’s never stopping. A &lt;code&gt;WebSocket&lt;/code&gt; belongs to the code
it was given to, as its connection does.&lt;/p&gt;
&lt;p&gt;While it receives, a WebSocket keeps the protocol by itself: a ping is answered with a pong at once
and a pong passed over, a message arriving in fragments is put back together with control frames
answered between them, and a close from the other end is answered with its code, the connection
closed, and the receive answers &lt;code&gt;Err(Closed(code, reason))&lt;/code&gt; (&lt;code&gt;1005&lt;/code&gt; for a close giving no code).
Every send and receive after the WebSocket is closed answers the same error. A server stopping
closes its WebSockets with &lt;code&gt;1001&lt;/code&gt; at their next send, or at once where one is waiting in a receive,
which watches the server’s &lt;code&gt;stopped()&lt;/code&gt; channel. A thread cancelled while it receives closes the
connection, the WebSocket then closed with &lt;code&gt;1006&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&quot;sending-from-other-threads&quot;&gt;Sending from other threads&lt;/h4&gt;
&lt;p&gt;A &lt;code&gt;WebSocket&lt;/code&gt; belongs to one thread, which does all of its connection’s reads and writes. Other
threads send on it through &lt;code&gt;ws.sender()&lt;/code&gt;, a sendable &lt;code&gt;WebSocketSender&lt;/code&gt; with &lt;code&gt;send(text)&lt;/code&gt;,
&lt;code&gt;send(bytes)&lt;/code&gt;, &lt;code&gt;close(code = 1000, reason = &amp;quot;&amp;quot;)&lt;/code&gt; and &lt;code&gt;isOpen()&lt;/code&gt;. A send queues one whole message in
the WebSocket’s outbox, at most &lt;code&gt;outboxSize&lt;/code&gt; messages; the owning thread writes them while it
receives, in the one wait that also watches its connection, so its senders’ messages, its own, the
pongs and the close handshake all go on the wire from it, each message whole and never interleaved
with another, and each sender’s in the order it queued them. A thread whose session only answers
what arrives, or whose messages all come from senders, loops in &lt;code&gt;ws.serve(onMessage) -&amp;gt; WebSocketError&lt;/code&gt;, which receives until the WebSocket closes, runs &lt;code&gt;onMessage&lt;/code&gt; for every message and
answers why it closed. A broadcast chat server puts each session’s sender in a room:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.net.http
import avin.net.http.{Route, Router, Text, WebSocket, WebSocketSender, webSocket}
import avin.threads.Mutex

class Room(): Sendable
  private val members = Mutex(Vector.empty[(int, WebSocketSender)]())
  private val count = Mutex(0)

  join(s: WebSocketSender) -&amp;gt; int
    val n = count.update(c -&amp;gt; c + 1)
    _ = members.update(v -&amp;gt; v :+ (n, s))
    n

  leave(n: int) = _ = members.update(v -&amp;gt; v.filter((k, _) -&amp;gt; k != n))

  broadcast(from: int, text: string)
    for (n, s) in members.get()
      if n != from then _ = s.send(text)

chat(ws: WebSocket, room: Room)
  val me = room.join(ws.sender())
  defer room.leave(me)
  _ = ws.serve(m -&amp;gt; m match
    Text(t) -&amp;gt; room.broadcast(me, t)
    _ -&amp;gt; ())

main()
  val room = Room()
  val router = Router([Route.get(&amp;quot;/chat&amp;quot;, r -&amp;gt; webSocket(r, ws -&amp;gt; chat(ws, room)))])
  http.serve(&amp;quot;0.0.0.0&amp;quot;, 8080, router.handle).ok.get.join()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A send answers &lt;code&gt;Ok&lt;/code&gt; once its message is queued while the WebSocket is open; one the WebSocket closes
before writing is dropped. A full outbox, as a client that reads slowly leaves it, makes a send wait
up to the WebSocket’s write timeout and then answer &lt;code&gt;Err(Broken(IoError(TimedOut, _, _)))&lt;/code&gt;, the
message not queued and the WebSocket still open, so a slow client never holds up the threads
sending to every other one; the owner’s own write to such a client fails at the same timeout and
closes it. A sender’s &lt;code&gt;close&lt;/code&gt; asks the owner to close the WebSocket, which it does, as its own
&lt;code&gt;close&lt;/code&gt; would, once the messages queued before are written; every sender call from then on answers
&lt;code&gt;Err(Closed(code, reason))&lt;/code&gt;. The owner’s &lt;code&gt;close&lt;/code&gt;, a close from the other end, a failure and a server
stopping end the outbox: what is queued is dropped, and every sender call, a send waiting for room
among them, answers why. Messages queued while the owner is not receiving wait until it next is.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Close&lt;/th&gt;&lt;th&gt;When this end closes with it&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;1002&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A client’s frame not masked or a server’s masked; a reserved bit set; an unknown opcode; a control frame fragmented or over 125 bytes; a continuation with no message to continue, or a new message inside a fragmented one; a close frame of one byte or with a code no endpoint may send; a 64-bit length with its top bit set&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;1007&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A text message, or a close reason, that is not UTF-8, checked once the message is whole&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;1009&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A message longer than &lt;code&gt;maxMessageBytes&lt;/code&gt;, refused by its frames’ lengths before their payloads are read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;1001&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The server is stopping&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A frame breaking the protocol fails the connection: the close frame is sent and the connection
closed at once. A &lt;code&gt;WebSocketError&lt;/code&gt; is &lt;code&gt;Closed(code, reason)&lt;/code&gt;, which also reports &lt;code&gt;1006&lt;/code&gt; where the
other end went without a close; &lt;code&gt;Broken(error)&lt;/code&gt;, the connection having failed; and, from &lt;code&gt;connect&lt;/code&gt;,
&lt;code&gt;Refused(status, reason)&lt;/code&gt; for an answer other than &lt;code&gt;101&lt;/code&gt;, &lt;code&gt;BadHandshake(text)&lt;/code&gt; for a &lt;code&gt;101&lt;/code&gt; that is
not a WebSocket server’s (an accept key not the key’s, no &lt;code&gt;Upgrade: websocket&lt;/code&gt;, a subprotocol not
offered), and &lt;code&gt;Unreachable(error)&lt;/code&gt;, the URL, the connection or its TLS failing as an &lt;code&gt;HttpError&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;url&quot;&gt;&lt;code&gt;Url&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;import avin.net.Url&lt;/code&gt; brings in a URL as RFC 3986 reads a URI. &lt;code&gt;Url.parse(text) -&amp;gt; Result[Url, UrlError]&lt;/code&gt; reads an absolute URL, one that begins with its scheme, and &lt;code&gt;Url(text)&lt;/code&gt; reads one and
traps on text that is not, with the error’s message and the text, as &lt;code&gt;Regex(p)&lt;/code&gt; traps where
&lt;code&gt;Regex.compile(p)&lt;/code&gt; answers a &lt;code&gt;Result&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Url&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type of its components: &lt;code&gt;scheme&lt;/code&gt;, &lt;code&gt;userInfo&lt;/code&gt;, &lt;code&gt;host&lt;/code&gt;, &lt;code&gt;port&lt;/code&gt; (an &lt;code&gt;Option[int]&lt;/code&gt;),
&lt;code&gt;path&lt;/code&gt;, &lt;code&gt;query&lt;/code&gt; and &lt;code&gt;fragment&lt;/code&gt;, each optional one an &lt;code&gt;Option&lt;/code&gt;. &lt;strong&gt;An empty component is not an absent
one&lt;/strong&gt;: &lt;code&gt;http://h?&lt;/code&gt; has the query &lt;code&gt;Some(&amp;quot;&amp;quot;)&lt;/code&gt; and &lt;code&gt;http://h&lt;/code&gt; has &lt;code&gt;None&lt;/code&gt;; &lt;code&gt;file:///etc&lt;/code&gt; has the host
&lt;code&gt;Some(&amp;quot;&amp;quot;)&lt;/code&gt; and &lt;code&gt;mailto:a@b.c&lt;/code&gt;, which has no authority, &lt;code&gt;None&lt;/code&gt;. Components are kept as they were
written, percent-escapes and all, and &lt;code&gt;Url.decode&lt;/code&gt; turns one into text. A host is a name, an IPv4
address, or an address in brackets, kept with them: an IPv6 address, with an optional zone written
&lt;code&gt;%25&lt;/code&gt; and its name (&lt;code&gt;[fe80::1%25eth0]&lt;/code&gt;), or an address of a later form (&lt;code&gt;[v7.x]&lt;/code&gt;). A component may
hold characters beyond ASCII other than controls and spaces, kept as they are.&lt;/p&gt;
&lt;p&gt;The scheme and host are held in lower case (a zone’s name and a host’s percent-escapes as written),
and a port that is the scheme’s default is held as &lt;code&gt;None&lt;/code&gt;, so URLs differing only in those are
equal, and a &lt;code&gt;Url&lt;/code&gt; displays as the text it was read from with exactly those differences:
&lt;code&gt;Url(&amp;quot;HTTP://Example.COM:80/A&amp;quot;)&lt;/code&gt; displays as &lt;code&gt;http://example.com/A&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;u.portOrDefault -&amp;gt; Option[int]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The port, or where none is written the scheme’s default: 80 for &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;ws&lt;/code&gt;, 443 for &lt;code&gt;https&lt;/code&gt; and &lt;code&gt;wss&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;u.queryParams -&amp;gt; Vector[(string, string)]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The query split at each &lt;code&gt;&amp;amp;&lt;/code&gt; (an empty piece skipped) and each piece at its first &lt;code&gt;=&lt;/code&gt;, decoded, a &lt;code&gt;+&lt;/code&gt; standing for a space as a form writes one; no &lt;code&gt;=&lt;/code&gt; gives an empty value, no query no pairs.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;u.resolve(ref: string) -&amp;gt; Result[Url, UrlError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The reference, relative or absolute, resolved against &lt;code&gt;u&lt;/code&gt; by RFC 3986 §5.2: its missing components taken from &lt;code&gt;u&lt;/code&gt; and its dot segments removed, strictly, so &lt;code&gt;http:g&lt;/code&gt; stays &lt;code&gt;http:g&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;u.resolve(ref: Url) -&amp;gt; Url&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An absolute reference with its dot segments removed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;u.withScheme(s)&lt;/code&gt;, &lt;code&gt;withUserInfo(i)&lt;/code&gt;, &lt;code&gt;withHost(h)&lt;/code&gt;, &lt;code&gt;withPort(p)&lt;/code&gt;, &lt;code&gt;withPath(p)&lt;/code&gt;, &lt;code&gt;withQuery(q)&lt;/code&gt;, &lt;code&gt;withFragment(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The URL with one component replaced, as written with its escapes, held as &lt;code&gt;parse&lt;/code&gt; holds it; the optional ones take a value or an &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; taking the component away. A component the URL cannot hold traps: one with a character it may not, a port outside 0 to 65535, user information or a port without a host, a path beside a host not beginning with &lt;code&gt;/&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Url.encode(text) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every byte of the text’s UTF-8 but a letter, a digit, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt; written &lt;code&gt;%XX&lt;/code&gt; in upper case, so the result can stand as any component.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Url.decode(text) -&amp;gt; Result[string, UrlError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Each &lt;code&gt;%XX&lt;/code&gt; replaced by its byte and the bytes read as UTF-8; a &lt;code&gt;+&lt;/code&gt; is kept.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Url.formDecode(text) -&amp;gt; Result[Vector[(string, string)], UrlError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; read as WHATWG URL reads it, and as &lt;code&gt;queryParams&lt;/code&gt; reads a query: split at each &lt;code&gt;&amp;amp;&lt;/code&gt; (an empty piece skipped) and each piece at its first &lt;code&gt;=&lt;/code&gt;, a &lt;code&gt;+&lt;/code&gt; a space, each decoded; a malformed escape is &lt;code&gt;BadPercent&lt;/code&gt; and bytes not UTF-8 &lt;code&gt;InvalidUtf8&lt;/code&gt;, at their offset.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Url.formEncode(pairs) -&amp;gt; string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The pairs written as WHATWG URL writes a form: &lt;code&gt;name=value&lt;/code&gt; joined by &lt;code&gt;&amp;amp;&lt;/code&gt;, a space as &lt;code&gt;+&lt;/code&gt;, every byte but a letter, a digit, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;_&lt;/code&gt; as &lt;code&gt;%XX&lt;/code&gt;; &lt;code&gt;formDecode&lt;/code&gt; reads it back as the same pairs.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;UrlError&lt;/code&gt; says why text is not a URL, with &lt;code&gt;at&lt;/code&gt;, the byte offset of what is wrong: &lt;code&gt;MissingScheme&lt;/code&gt;
(a relative reference, or text beginning with &lt;code&gt;:&lt;/code&gt;), &lt;code&gt;BadScheme(at)&lt;/code&gt;, &lt;code&gt;BadCharacter(at)&lt;/code&gt;,
&lt;code&gt;BadPercent(at)&lt;/code&gt;, &lt;code&gt;BadHost(at)&lt;/code&gt;, &lt;code&gt;BadPort(at)&lt;/code&gt; (not digits, or above 65535) and &lt;code&gt;InvalidUtf8(at)&lt;/code&gt;;
&lt;code&gt;message&lt;/code&gt; says it in words. &lt;strong&gt;Every component’s escapes must decode to UTF-8 for the text to be a
URL&lt;/strong&gt;, so &lt;code&gt;parse&lt;/code&gt; refuses &lt;code&gt;http://h/%FF&lt;/code&gt; with &lt;code&gt;InvalidUtf8(9)&lt;/code&gt; and &lt;code&gt;queryParams&lt;/code&gt; never fails on a
&lt;code&gt;Url&lt;/code&gt; it read.&lt;/p&gt;
&lt;h3 id=&quot;http&quot;&gt;&lt;code&gt;http&lt;/code&gt;&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.get(url: string, headers = []) -&amp;gt; Result[Response, HttpError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Fetches the URL.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.head(url: string, headers = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Asks for the URL’s headers; the response has no body.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.delete(url: string, headers = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Asks the server to delete the URL.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.post(url: string, body: string, contentType: string, headers = []) -&amp;gt; Result[Response, HttpError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sends &lt;code&gt;body&lt;/code&gt;, as UTF-8, and answers the response.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.put(url, body, contentType, headers = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same with &lt;code&gt;PUT&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.patch(url, body, contentType, headers = [])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same with &lt;code&gt;PATCH&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;http.send(request: Request) -&amp;gt; Result[Response, HttpError]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any method, headers, body, timeout and TLS settings, built from &lt;code&gt;Request(method, url, headers)&lt;/code&gt; with &lt;code&gt;withHeader&lt;/code&gt;, &lt;code&gt;withHeaders&lt;/code&gt;, &lt;code&gt;withQueryParam&lt;/code&gt;, &lt;code&gt;withBody&lt;/code&gt;, &lt;code&gt;withTimeout&lt;/code&gt; and &lt;code&gt;withTls&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Every verb answers a &lt;code&gt;Result[Response, HttpError]&lt;/code&gt;, and &lt;code&gt;headers&lt;/code&gt;, a &lt;code&gt;Vector[(string, string)]&lt;/code&gt;, are
sent after the ones the client writes, in order. &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt; and &lt;code&gt;patch&lt;/code&gt; send &lt;code&gt;Content-Type: contentType&lt;/code&gt; first, so a &lt;code&gt;Content-Type&lt;/code&gt; among &lt;code&gt;headers&lt;/code&gt; follows it. &lt;code&gt;withQueryParam(name, value)&lt;/code&gt;
adds &lt;code&gt;name=value&lt;/code&gt; to the request’s URL, each encoded by &lt;code&gt;Url.encode&lt;/code&gt;, after any query it has (with
&lt;code&gt;?&lt;/code&gt; where it has none, &lt;code&gt;&amp;amp;&lt;/code&gt; otherwise, nothing after a trailing &lt;code&gt;?&lt;/code&gt; or &lt;code&gt;&amp;amp;&lt;/code&gt;) and before its fragment.
&lt;code&gt;withForm(pairs)&lt;/code&gt; sends the pairs as an urlencoded form, written by &lt;code&gt;Url.formEncode&lt;/code&gt;, and
&lt;code&gt;withMultipart(form)&lt;/code&gt; a &lt;code&gt;Multipart&lt;/code&gt; of &lt;code&gt;Part.field(name, value)&lt;/code&gt; and &lt;code&gt;Part.file(name, filename, contentType, bytes)&lt;/code&gt; parts as &lt;code&gt;multipart/form-data&lt;/code&gt; between delimiters of a fresh
&lt;code&gt;Multipart.newBoundary()&lt;/code&gt; (&lt;code&gt;avin-&lt;/code&gt; and 32 hexadecimal digits from &lt;code&gt;SecureRandom&lt;/code&gt;); each replaces the
request’s &lt;code&gt;Content-Type&lt;/code&gt; with its own. &lt;code&gt;withMultipart(form, boundary)&lt;/code&gt;, &lt;code&gt;form.encoded(boundary)&lt;/code&gt; and
&lt;code&gt;form.contentType(boundary)&lt;/code&gt; take a boundary of the caller’s, and trap on one RFC 2046 does not allow
or one a part’s body holds. A part’s name and filename are written quoted as the WHATWG HTML standard
writes them, &lt;code&gt;&amp;quot;&lt;/code&gt;, CR and LF as &lt;code&gt;%22&lt;/code&gt;, &lt;code&gt;%0D&lt;/code&gt; and &lt;code&gt;%0A&lt;/code&gt;, so the server’s &lt;code&gt;multipart()&lt;/code&gt; reads them back
exactly. &lt;code&gt;request.header(name)&lt;/code&gt; looks a header up as a response’s does.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Response&lt;/code&gt; has its &lt;code&gt;status&lt;/code&gt; and &lt;code&gt;reason&lt;/code&gt;, its &lt;code&gt;headers&lt;/code&gt; as a vector of name and value pairs,
&lt;code&gt;header(name)&lt;/code&gt; looking a name up without regard to case, its &lt;code&gt;body&lt;/code&gt; as an &lt;code&gt;Array[byte]&lt;/code&gt; and &lt;code&gt;text&lt;/code&gt;
reading that as UTF-8, a sequence that is not read as U+FFFD. &lt;strong&gt;A status is an answer, not a failure&lt;/strong&gt;: &lt;code&gt;404&lt;/code&gt; is an &lt;code&gt;Ok&lt;/code&gt;. &lt;code&gt;HttpError&lt;/code&gt; is &lt;code&gt;Io(IoError)&lt;/code&gt;,
&lt;code&gt;BadUrl(UrlError)&lt;/code&gt;, &lt;code&gt;Malformed(text)&lt;/code&gt; for a reply that is not HTTP, &lt;code&gt;Unsupported(text)&lt;/code&gt; for a scheme
other than &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt;, and &lt;code&gt;Tls(TlsError)&lt;/code&gt; for TLS that could not be set up (a connection
that could not be made, broke or timed out being &lt;code&gt;Io&lt;/code&gt;, for &lt;code&gt;https&lt;/code&gt; as for &lt;code&gt;http&lt;/code&gt;). The
client speaks HTTP/1.1, one request to a connection, reads bodies by &lt;code&gt;Content-Length&lt;/code&gt;, chunked or to
the connection’s end, and follows up to five redirects of a &lt;code&gt;GET&lt;/code&gt; or &lt;code&gt;HEAD&lt;/code&gt; (statuses 301, 302,
303, 307 and 308), each &lt;code&gt;Location&lt;/code&gt; resolved against the URL that answered by &lt;code&gt;Url.resolve&lt;/code&gt;; the sixth
is the answer. It writes &lt;code&gt;Host&lt;/code&gt;, &lt;code&gt;Content-Length&lt;/code&gt; (for a body, and for a &lt;code&gt;POST&lt;/code&gt;, a &lt;code&gt;PUT&lt;/code&gt; and a
&lt;code&gt;PATCH&lt;/code&gt; even when theirs is empty) and &lt;code&gt;Connection: close&lt;/code&gt; unless the request gives them, then the
request’s own headers in order. &lt;code&gt;HEAD&lt;/code&gt;, an interim
&lt;code&gt;1xx&lt;/code&gt; (which is skipped for the answer after it), &lt;code&gt;204&lt;/code&gt; and &lt;code&gt;304&lt;/code&gt; have no body. A method is a token
and a header’s name one too, and a header’s value holds no line break; a request where one does not
traps as it is made, whether the header came to &lt;code&gt;Request&lt;/code&gt;‘s constructor, to a verb, or by
&lt;code&gt;withHeader&lt;/code&gt; or &lt;code&gt;withHeaders&lt;/code&gt;, so nothing is sent. A request’s timeout bounds each read and write on its connection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;An &lt;code&gt;https&lt;/code&gt; URL just works&lt;/strong&gt;: the client makes the TCP connection to the URL’s port, 443 where it
gives none, sets the request’s timeout on it, so the handshake’s waits are bounded too, and speaks
the request over a &lt;a href=&quot;#tls&quot;&gt;&lt;code&gt;TlsStream&lt;/code&gt;&lt;/a&gt;, the certificate checked for the URL’s host against the
machine’s trusted authorities and those of the request’s &lt;code&gt;TlsClient&lt;/code&gt;, which &lt;code&gt;withTls(client)&lt;/code&gt; sets
(&lt;code&gt;TlsClient()&lt;/code&gt; unless it is set). A redirect between &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt; is followed like any other,
keeping the request’s TLS settings. TLS lives in the Sysl package &lt;code&gt;openssl&lt;/code&gt;, which the library
names in &lt;code&gt;library/library.hocon&lt;/code&gt;, its own &lt;code&gt;sysl-dependencies&lt;/code&gt;; a program’s shims depend on it only
where a binding the program compiles reaches it, which &lt;code&gt;avin.net.http&lt;/code&gt; and &lt;code&gt;avin.net.tls&lt;/code&gt; do and
&lt;code&gt;avin.net&lt;/code&gt; alone does not (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&quot;concurrency&quot;&gt;Concurrency&lt;/h2&gt;
&lt;p&gt;Futures and promises stay in &lt;a href=&quot;/spec/threads/#futures&quot;&gt;&lt;code&gt;avin.threads&lt;/code&gt;&lt;/a&gt;, beside the
threads and locks they are built on; there is no separate module for them. What a program writing
with futures reaches for is there, under these names:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;To&lt;/th&gt;&lt;th&gt;Write&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Run a computation on the pool&lt;/td&gt;&lt;td&gt;&lt;code&gt;Future(body)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A future already complete&lt;/td&gt;&lt;td&gt;&lt;code&gt;Future.successful(x)&lt;/code&gt;; a failure is &lt;code&gt;Future.successful(Err(e))&lt;/code&gt;, since a future carries none of its own&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Wait for the value&lt;/td&gt;&lt;td&gt;&lt;code&gt;f.await()&lt;/code&gt;, or &lt;code&gt;f.await(timeoutMillis)&lt;/code&gt; for an &lt;code&gt;Option&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Every value of several&lt;/td&gt;&lt;td&gt;&lt;code&gt;Future.all(fs)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The first value of several&lt;/td&gt;&lt;td&gt;&lt;code&gt;Future.first(fs)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A future for each element, then all of them&lt;/td&gt;&lt;td&gt;&lt;code&gt;Future.traverse(xs, f)&lt;/code&gt;, which is &lt;code&gt;Future.all(xs.map(f))&lt;/code&gt; started in order&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Go on from a failure&lt;/td&gt;&lt;td&gt;on a &lt;code&gt;Future[Result[T, E]]&lt;/code&gt;: &lt;code&gt;mapErr(f)&lt;/code&gt;, and &lt;code&gt;orElse(other)&lt;/code&gt;, which runs the by-name &lt;code&gt;other&lt;/code&gt; where the first ended in &lt;code&gt;Err&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Run on threads of one’s own&lt;/td&gt;&lt;td&gt;&lt;code&gt;Executor.fixed(n)&lt;/code&gt;, a pool of &lt;code&gt;n&lt;/code&gt; workers, and &lt;code&gt;ex.future(body)&lt;/code&gt;; &lt;code&gt;Executor.shared()&lt;/code&gt; is the pool &lt;code&gt;Future(body)&lt;/code&gt; uses. A future’s &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt; run on the executor it was made on. &lt;code&gt;ex.shutdown()&lt;/code&gt; lets its workers end once the queued work is done.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Say a body will wait on something other than a future&lt;/td&gt;&lt;td&gt;&lt;code&gt;threads.blocking(body)&lt;/code&gt;: the pool starts a worker in its place while it waits, as it does for &lt;code&gt;await&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Pause a thread&lt;/td&gt;&lt;td&gt;&lt;code&gt;threads.sleep(d: Duration)&lt;/code&gt;, safe for the collector while it sleeps&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Share costly resources, connections for one&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/spec/threads/#pools&quot;&gt;&lt;code&gt;Pool(create, maxSize)&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;pool.use(c -&amp;gt; …)&lt;/code&gt;, which lends one for the call and always takes it back&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;json&quot;&gt;JSON&lt;/h2&gt;
&lt;p&gt;JSON is not part of the standard library: it is the package &lt;a href=&quot;/spec/json/&quot;&gt;&lt;code&gt;dev.avinlang.json&lt;/code&gt;&lt;/a&gt;, in
its own repository, which a program adds to its dependencies. &lt;code&gt;import avin.json&lt;/code&gt; is an error naming
the package.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Sysl bindings</title>
    <link href="https://avinlang.dev/spec/sysl-bindings/"/>
    <id>https://avinlang.dev/spec/sysl-bindings/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Avin calls Sysl through bindings written in Avin; the compiler generates the Sysl side and lets Sysl check it.</summary>
    <content type="html">&lt;p&gt;Avin’s standard library is written in Avin. Where Sysl already provides something — files, processes,
time, hashing, text encoding, C libraries through Sysl’s own FFI — Avin code reaches it through a
&lt;strong&gt;binding&lt;/strong&gt;: an Avin declaration that names a Sysl function and states its signature in Avin types.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;module avin.fs

@sysl(&amp;quot;sysl.fs.read_text&amp;quot;)
private readTextRaw(path: string) -&amp;gt; Result[string, SyslIoError]

readText(path: string) -&amp;gt; Result[string, IoError] =
  readTextRaw(path).mapErr(IoError.fromSysl)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A binding is a top-level function declaration with no body. &lt;code&gt;@sysl&lt;/code&gt; takes one string: the Sysl
function’s module path and name. Bindings are usually private, with a public function giving the
Avin-shaped API: camelCase names, Avin error types, Avin collections. A binding is otherwise an
ordinary function: it is called, overloaded, given defaults and passed as a value like any other. A
binding that passes its arguments &lt;a href=&quot;#arguments-passed-by-name&quot;&gt;by name&lt;/a&gt; may leave a parameter with a
Sysl default to Sysl.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sysl.text.to_upper&amp;quot;)
upper(s: string) -&amp;gt; string

@sysl(&amp;quot;sysl.prints&amp;quot;)
write(s: string)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A binding whose types do not fit the Sysl function is rejected with Sysl’s own message, at the
binding:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `upper` does not match `sysl.text.to_upper`: &apos;s&apos; of &apos;sysl.text.to_upper&apos; is string, but long was given
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;how-a-binding-is-compiled&quot;&gt;How a binding is compiled&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;The Avin compiler collects every binding the program reaches.&lt;/li&gt;
&lt;li&gt;It generates a Sysl &lt;strong&gt;shim&lt;/strong&gt; module: one exported function per binding, with a fixed boundary
signature. Each shim converts its arguments, calls the named Sysl function, and converts the
result back.&lt;/li&gt;
&lt;li&gt;It builds the shim with &lt;code&gt;sysl build-c&lt;/code&gt;. &lt;strong&gt;Sysl type-checks each shim against the real
declaration&lt;/strong&gt;, so a wrong binding or a Sysl signature change fails the build with a Sysl
diagnostic that the Avin compiler maps back to the binding. Avin never guesses a mangled name or a
Sysl memory layout.&lt;/li&gt;
&lt;li&gt;The shim library is cached by a hash of its source, the Sysl version and the
&lt;a href=&quot;#sysl-packages&quot;&gt;Sysl packages&lt;/a&gt; it depends on, and rebuilt only when one of them changes. It is built together with the runtime, so the program holds one copy of Sysl’s
library, and what Sysl and Avin each write to standard output stays in order.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The Avin compiler does not need Sysl’s compiler as a library. It needs only the &lt;code&gt;sysl&lt;/code&gt; command at
build time; the produced executable does not.&lt;/p&gt;
&lt;h2 id=&quot;sysl-packages&quot;&gt;Sysl packages&lt;/h2&gt;
&lt;p&gt;A binding reaches Sysl’s standard library, and any Sysl package the package’s manifest names in
&lt;a href=&quot;/spec/packages/#sysl-dependencies&quot;&gt;&lt;code&gt;sysl-dependencies&lt;/code&gt;&lt;/a&gt;. The binding names the package’s function
by the module the package declares it in, as Sysl code importing it would:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;sysl-dependencies {
  digits { path = &amp;quot;../digits&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;avintest.digits.digit_sum&amp;quot;)
digitSum(n: int) -&amp;gt; int
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The shim package depends on each Sysl package every package of the program names, so Sysl checks a
binding against the package’s own declaration exactly as it checks one against the standard
library, and a library’s bindings build in any program that uses the library. A binding to a module
no named package holds is reported at the binding:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `digitCount` does not match `avintest.digits.digit_count`: no module is called &apos;avintest.digits.digit_count&apos;, and nothing declares it: a binding reaches Sysl&apos;s standard library and the Sysl packages the manifest names in `sysl-dependencies`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A new release of a Sysl package, a different commit, or a change to the sources of one named by
directory builds the shims again; nothing else about it does.&lt;/p&gt;
&lt;h2 id=&quot;arguments-passed-by-name&quot;&gt;Arguments passed by name&lt;/h2&gt;
&lt;p&gt;A binding passes its arguments by position: its first parameter is the Sysl function’s first, and
so on. A binding marked &lt;strong&gt;&lt;code&gt;named&lt;/code&gt;&lt;/strong&gt; passes each argument by its parameter’s name instead, spelled as
Sysl spells it: each uppercase letter becomes an underscore and its lowercase, as a
&lt;a href=&quot;#mirrors&quot;&gt;mirror’s&lt;/a&gt; fields are, so &lt;code&gt;onFrame&lt;/code&gt; is &lt;code&gt;on_frame&lt;/code&gt;. It lists only the parameters it passes,
in any order, and &lt;strong&gt;every parameter it leaves out takes the Sysl function’s own default&lt;/strong&gt;, which
Sysl evaluates at each call, exactly as for a Sysl caller that leaves the argument out. A binding
never repeats a Sysl default, so it never goes stale when the Sysl function’s defaults change.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sh.sysl.ui_sdl.app&amp;quot;, named)
private appOf(
    title: string,
    tree: () -&amp;gt; View,
    ground: () -&amp;gt; long,
    width: int,
    height: int,
    onFrame: real -&amp;gt; unit
) -&amp;gt; App
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;app&lt;/code&gt; declares &lt;code&gt;on_event&lt;/code&gt;, &lt;code&gt;font&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt; between &lt;code&gt;height&lt;/code&gt; and &lt;code&gt;on_frame&lt;/code&gt;, with defaults; the
binding passes &lt;code&gt;on_frame&lt;/code&gt; past them and leaves all three to Sysl. &lt;code&gt;named&lt;/code&gt; is written after the Sysl
function’s name, with &lt;code&gt;blocking&lt;/code&gt; where the call may also wait (&lt;code&gt;@sysl(&amp;quot;f&amp;quot;, blocking, named)&lt;/code&gt;), or
alone on a handle’s method bound by its own name (&lt;code&gt;@sysl(named)&lt;/code&gt;), whose receiver is never named.
Every parameter of a &lt;code&gt;named&lt;/code&gt; binding has a name, since its argument is passed by it.&lt;/p&gt;
&lt;p&gt;A default an Avin caller sees is the binding’s own: a binding’s parameter may have an Avin default
like any function’s, and the Avin caller that leaves it out passes that value, so Sysl’s default for
it is not used. Leaving a parameter that has no Sysl default out, or naming one the Sysl function
does not have, is reported at the binding with Sysl’s own message:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `framedNoTitle` does not match `avintest.digits.framed`: function &apos;digits.avintest.digits.framed&apos; was given no value for &apos;title&apos;, and that parameter declares no default
error: the Sysl binding `joinedWrongName` does not match `avintest.digits.joined`: function &apos;digits.avintest.digits.joined&apos; declares no parameter named &apos;d&apos; — it takes &apos;a&apos;, &apos;b&apos; and &apos;c&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;boundary-types&quot;&gt;Boundary types&lt;/h2&gt;
&lt;p&gt;Data crosses the boundary in a fixed set of shapes:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Avin type&lt;/th&gt;&lt;th&gt;Crossing&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;i8&lt;/code&gt;, &lt;code&gt;i16&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;By value; Sysl’s &lt;code&gt;u8&lt;/code&gt; is &lt;code&gt;byte&lt;/code&gt;. An integer result, and an integer a result holds, takes &lt;a href=&quot;#integer-results&quot;&gt;any Sysl integer&lt;/a&gt;; an integer parameter goes into &lt;a href=&quot;#integer-parameters&quot;&gt;any&lt;/a&gt;, and so does a callback’s integer answer &lt;a href=&quot;#callbacks&quot;&gt;too&lt;/a&gt;. A &lt;code&gt;real&lt;/code&gt; goes into and comes out of &lt;a href=&quot;#real-numbers&quot;&gt;any Sysl floating-point type&lt;/a&gt;, &lt;code&gt;f32&lt;/code&gt; among them&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Copied into a Sysl &lt;code&gt;string&lt;/code&gt; in each direction&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Array[byte]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Copied into a Sysl &lt;code&gt;[]u8&lt;/code&gt; and, as a binding’s own parameter, &lt;a href=&quot;#filled-arrays&quot;&gt;copied back&lt;/a&gt; after the call; out of a Sysl &lt;code&gt;[]u8&lt;/code&gt; or &lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Array[T]&lt;/code&gt;, &lt;code&gt;Vector[T]&lt;/code&gt; of any other boundary type&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Copied&lt;/strong&gt;, element by element: into a Sysl slice, and out of a Sysl &lt;code&gt;[]T&lt;/code&gt; or &lt;code&gt;Buf[T]&lt;/code&gt; into a new array or vector. An array of numbers, booleans or characters as a binding’s own parameter is &lt;a href=&quot;#filled-arrays&quot;&gt;copied back&lt;/a&gt;; any other array goes in as a &lt;code&gt;[]const T&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, &lt;code&gt;Result[T, E]&lt;/code&gt; of boundary types&lt;/td&gt;&lt;td&gt;Converted variant by variant by the generated shim&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;data&lt;/code&gt; declared with &lt;code&gt;@sysl(&amp;quot;…&amp;quot;)&lt;/code&gt; mirroring a Sysl struct or enum of boundary types&lt;/td&gt;&lt;td&gt;Converted field by field&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;(T1, T2, …)&lt;/code&gt;, a tuple of boundary types&lt;/td&gt;&lt;td&gt;A Sysl tuple of the same arity, converted part by part in each direction&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;class&lt;/code&gt; declared with &lt;code&gt;@sysl(&amp;quot;…&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An &lt;strong&gt;opaque handle&lt;/strong&gt; on a Sysl struct, trait or instance of a generic type, or a &lt;a href=&quot;#generic-handles&quot;&gt;generic handle&lt;/a&gt; on each of its instances: an Avin object owning one counted Sysl reference, released by &lt;code&gt;close()&lt;/code&gt; or, as a safety net, a finalizer. Its methods are bindings too.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;These shapes nest: a &lt;code&gt;Result[Option[string], IoError]&lt;/code&gt; crosses, and so do a
&lt;code&gt;Result[Vector[string], IoError]&lt;/code&gt;, a &lt;code&gt;Vector[Vector[string]]&lt;/code&gt;, a &lt;code&gt;Vector[Array[byte]]&lt;/code&gt;, a
&lt;code&gt;Vector[(string, string)]&lt;/code&gt;, an &lt;code&gt;Option[(string, (int, long))]&lt;/code&gt; and a mirror whose fields are
&lt;code&gt;Option&lt;/code&gt;s, collections, tuples or other mirrors. Sysl’s &lt;code&gt;vars()&lt;/code&gt;, a &lt;code&gt;Buf[(string, string)]&lt;/code&gt;, is
bound as a &lt;code&gt;Vector[(string, string)]&lt;/code&gt;, and a Sysl &lt;code&gt;(usize, u64)&lt;/code&gt; as an &lt;code&gt;(int, long)&lt;/code&gt;, each part
checked as an integer result is.&lt;/p&gt;
&lt;h3 id=&quot;integer-results&quot;&gt;Integer results&lt;/h3&gt;
&lt;p&gt;A binding’s integer result takes any Sysl integer, of any width and either sign, converted with a
check into the integer type the binding declares. Avin has no unsigned integers, so a Sysl &lt;code&gt;usize&lt;/code&gt;
or &lt;code&gt;u64&lt;/code&gt; result is bound as a &lt;code&gt;long&lt;/code&gt;, and a narrower type is fine where the values fit:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sysl.math.bigint.BigInt&amp;quot;)
class BigInt
  limbs() -&amp;gt; long
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value the declared type cannot hold — a &lt;code&gt;u64&lt;/code&gt; past the largest &lt;code&gt;long&lt;/code&gt;, an &lt;code&gt;i64&lt;/code&gt; result bound as
an &lt;code&gt;int&lt;/code&gt; that does not fit — stops the program where the binding was called, as an Avin conversion
does:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: value out of range for long at main.avin:13:13
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An integer a result holds converts the same way, wherever it is: the value of an &lt;code&gt;Option&lt;/code&gt;, either
side of a &lt;code&gt;Result&lt;/code&gt;, the elements of an &lt;code&gt;Array&lt;/code&gt; or a &lt;code&gt;Vector&lt;/code&gt;, the parts of a tuple, and these nested in one another. A
Sysl &lt;code&gt;Option[usize]&lt;/code&gt; is bound as an &lt;code&gt;Option[long]&lt;/code&gt;, a &lt;code&gt;Result[u32, E]&lt;/code&gt; as a &lt;code&gt;Result[int, E]&lt;/code&gt;, and a
slice of &lt;code&gt;u8&lt;/code&gt; or a &lt;code&gt;Buf[u16]&lt;/code&gt; as a &lt;code&gt;Vector[int]&lt;/code&gt;. Each value is checked as it is converted, and the
first that does not fit stops the program at the binding’s call. A &lt;code&gt;byte&lt;/code&gt; is not converted: it is
made from a Sysl &lt;code&gt;u8&lt;/code&gt; only, in a collection as anywhere.&lt;/p&gt;
&lt;p&gt;A value of any other type is not converted to an integer, and the binding is rejected:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `upperCount` does not match `sysl.text.to_upper`: an integer is made from a Sysl integer, but the value is string
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;integer-parameters&quot;&gt;Integer parameters&lt;/h3&gt;
&lt;p&gt;A binding’s integer parameter goes into whatever integer the Sysl parameter is, of any width and
either sign, converted with a check, as a &lt;a href=&quot;#callbacks&quot;&gt;callback’s answer&lt;/a&gt; is. Avin has no unsigned
integers, so a Sysl &lt;code&gt;u32&lt;/code&gt;, &lt;code&gt;u64&lt;/code&gt; or &lt;code&gt;usize&lt;/code&gt; parameter takes an Avin &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long&lt;/code&gt;, and a &lt;code&gt;long&lt;/code&gt;
reaches an &lt;code&gt;i32&lt;/code&gt; or an &lt;code&gt;i8&lt;/code&gt; too where its value fits. syslui takes a colour this way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sh.sysl.ui.View&amp;quot;)
class View
  background(color: int, radius: int = 0) -&amp;gt; View
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value the Sysl type cannot hold — a negative one for a &lt;code&gt;u32&lt;/code&gt; or a &lt;code&gt;u64&lt;/code&gt;, one past its largest
value — stops the program where the binding was called, naming the Sysl type by its sign and width.
A handle’s method converts its parameters the same way, and a &lt;a href=&quot;#calls-that-wait&quot;&gt;call that waits&lt;/a&gt;
converts them while its thread is safe for the collector:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: value out of range for u32 at main.avin:11:13
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;code&gt;byte&lt;/code&gt; is not converted: it is passed as a Sysl &lt;code&gt;u8&lt;/code&gt;. A Sysl parameter whose type is a type
parameter of a generic function, &lt;code&gt;same[T](x: T) -&amp;gt; T&lt;/code&gt;, says no integer to convert into, and is
given the Avin type itself: &lt;code&gt;T&lt;/code&gt; is then the binding’s &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long&lt;/code&gt;. So is every integer parameter
of a binding to a generic function that infers a type parameter from one of them, as syslui’s
&lt;code&gt;slider[T](value: &amp;amp;Signal[T], lo: T, hi: T, …)&lt;/code&gt; does. An integer goes into an integer only:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `joinNumber` does not match `sysl.path.join`: parameter 2 is an integer, which goes into Sysl only as an integer, but the Sysl parameter is string
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An integer a parameter holds — in an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a tuple or a collection — is passed as
the type it is declared and is not converted: an &lt;code&gt;Option[int]&lt;/code&gt; reaches an &lt;code&gt;Option[i32]&lt;/code&gt; parameter
only, and the diagnostic for any other says why:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `countOrZero` does not match `avintest.digits.count_or_zero`: &apos;n&apos; of &apos;digits.avintest.digits.count_or_zero&apos; is Option[i64], but Option[int] was given: an integer inside an `Option`, a `Result`, a tuple or a collection is passed as the type it is declared, and only a binding&apos;s own integer parameter is converted into the Sysl parameter&apos;s integer
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value narrower than 32 bits crosses widened as the C convention widens it, a signed integer
sign-extended and a byte or a bool zero-extended: as a parameter, and as a callback’s answer.&lt;/p&gt;
&lt;h3 id=&quot;real-numbers&quot;&gt;Real numbers&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;real&lt;/code&gt; goes into whatever floating-point type its Sysl place is — &lt;code&gt;f32&lt;/code&gt;, the half-precision &lt;code&gt;f16&lt;/code&gt;
and &lt;code&gt;bf16&lt;/code&gt;, or &lt;code&gt;real&lt;/code&gt; itself — and comes out of any of them. syslui-sdl’s &lt;code&gt;app&lt;/code&gt; takes its text size
as an &lt;code&gt;f32&lt;/code&gt;, and a binding gives it a &lt;code&gt;real&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sh.sysl.ui_sdl.app&amp;quot;)
appOf(
    title: string,
    tree: () -&amp;gt; View,
    ground: () -&amp;gt; long,
    width: int,
    height: int,
    onEvent: Event -&amp;gt; bool,
    font: string,
    size: real,
    onFrame: real -&amp;gt; unit
) -&amp;gt; App
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Going in — a binding’s own parameter, a mirror’s field, a callback’s answer — the value is rounded to
the nearest the Sysl type holds, a tie to the one whose last bit is zero. Nothing stops the program:
a value past the type’s largest becomes an infinity of its sign, one smaller than half its smallest
subnormal a zero of its sign, and a NaN stays a NaN. &lt;code&gt;0.1&lt;/code&gt; reaches an &lt;code&gt;f32&lt;/code&gt; as
&lt;code&gt;0.10000000149011612&lt;/code&gt;, and &lt;code&gt;16777217.0&lt;/code&gt; as &lt;code&gt;16777216&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Coming out — a result, a mirror’s field, a callback’s parameter, and a real an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a
tuple or a collection holds — the value is widened exactly, so an &lt;code&gt;f32&lt;/code&gt; that went out comes back
as the same number. A Sysl &lt;code&gt;Option[f32]&lt;/code&gt; is bound as an &lt;code&gt;Option[real]&lt;/code&gt;, and a &lt;code&gt;Buf[f32]&lt;/code&gt; as a
&lt;code&gt;Vector[real]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As with integers, a real a parameter holds — in an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a tuple or a collection — is
passed as &lt;code&gt;real&lt;/code&gt; and not rounded, and a Sysl parameter whose type is a type parameter of a generic
function takes the &lt;code&gt;real&lt;/code&gt; itself. A binding’s own real is passed as it is wherever Sysl takes a
&lt;code&gt;real&lt;/code&gt;, and rounded only where it does not, so a Sysl function overloaded at &lt;code&gt;real&lt;/code&gt; and at &lt;code&gt;f32&lt;/code&gt; is
called at &lt;code&gt;real&lt;/code&gt;, with the value unrounded. A real goes into a floating-point type only, and is
made from one of the four only — not from Sysl’s quadruple-precision &lt;code&gt;f128&lt;/code&gt;, which Sysl itself
widens a parameter into:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `countReal` does not match `avintest.digits.digit_count`: parameter 1 is a real, which goes into Sysl only as a floating-point number, but the Sysl parameter is long
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;collections-are-copies&quot;&gt;Collections are copies&lt;/h3&gt;
&lt;p&gt;A collection crosses the boundary &lt;strong&gt;as a copy&lt;/strong&gt;, so neither side ever holds the other’s memory:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Into Sysl&lt;/strong&gt;, an &lt;code&gt;Array[T]&lt;/code&gt; or a &lt;code&gt;Vector[T]&lt;/code&gt; parameter becomes a fresh Sysl slice of its
elements, each converted. A vector’s slice is a &lt;code&gt;[]T&lt;/code&gt;, which the Sysl function may take as a &lt;code&gt;[]T&lt;/code&gt;
or a &lt;code&gt;[]const T&lt;/code&gt;: a vector never changes, so what Sysl writes into its copy is never missed. An
array the Sysl function may fill is &lt;a href=&quot;#filled-arrays&quot;&gt;copied back&lt;/a&gt; after the call; any other array
goes in as a &lt;code&gt;[]const T&lt;/code&gt;, so a Sysl function that would write into it is refused.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Out of Sysl&lt;/strong&gt;, a slice or a &lt;code&gt;Buf&lt;/code&gt; of a boundary type becomes a fresh Avin collection. A binding
usually declares a &lt;strong&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/strong&gt;, the immutable sequence the standard library’s functions answer
with; it may declare an &lt;strong&gt;&lt;code&gt;Array[T]&lt;/code&gt;&lt;/strong&gt; instead, a new array no one else holds. Which of &lt;code&gt;[]T&lt;/code&gt; and
&lt;code&gt;Buf[T]&lt;/code&gt; the Sysl function returns does not matter: the shim takes either.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sysl.fs.entries&amp;quot;)
private entries(dir: string) -&amp;gt; Result[Vector[string], SyslIoError]

@sysl(&amp;quot;sysl.path.join_all&amp;quot;)
private joinAll(parts: Vector[string]) -&amp;gt; string
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A copy costs time in the length of the collection, which is the right trade for a boundary between
two memory models: a vector a binding answers is an ordinary Avin vector, collected like any other,
and the Sysl buffer it came from is released when the shim returns.&lt;/p&gt;
&lt;p&gt;A Sysl function, or a mirrored struct’s field, that takes a &lt;code&gt;Buf[T]&lt;/code&gt; rather than a slice is not
reached through a collection: Sysl’s own functions take slices. A collection whose elements do not
fit the Sysl function is reported at the binding, in each direction:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `splitInts` does not match `sysl.text.split`: `Vector[int]` is made from a Sysl `[]I` or `Buf[I]` of any integer type `I`, and the value is none of these
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;No other collection crosses: a &lt;code&gt;List&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt;, a &lt;code&gt;Map&lt;/code&gt; or a &lt;code&gt;Set&lt;/code&gt; is converted by the Avin
function that wraps the binding, and an &lt;code&gt;Array&lt;/code&gt; or a &lt;code&gt;Vector&lt;/code&gt; crosses only when its elements do.&lt;/p&gt;
&lt;h3 id=&quot;filled-arrays&quot;&gt;Filled arrays&lt;/h3&gt;
&lt;p&gt;A Sysl function that fills a buffer its caller hands it, as a stream’s &lt;code&gt;read&lt;/code&gt; does, is bound with
an &lt;code&gt;Array&lt;/code&gt; parameter. An &lt;code&gt;Array&lt;/code&gt; of &lt;code&gt;byte&lt;/code&gt;, of an integer type, of &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; or &lt;code&gt;char&lt;/code&gt; that is
the binding’s &lt;strong&gt;own parameter&lt;/strong&gt; is copied into a slice the Sysl function may write, &lt;code&gt;[]T&lt;/code&gt;, and when
the function returns, what it left in the slice is copied back into the array, element by element.
The function’s result says how much it wrote, and the rest of the array keeps what it held:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;avintest.digits.fill_digits&amp;quot;)
fillDigits(n: long, into: Array[byte]) -&amp;gt; long

main()
  val buffer = Array.fill(6, byte(9))
  println(s&amp;quot;${fillDigits(42, buffer)} $buffer&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;2 [4, 2, 9, 9, 9, 9]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A slice never grows, so the copy back covers the whole array, and an empty array is an empty
slice. A handle’s method fills an array as a function does. The array is kept as a root of the
thread’s stack from before the call until it is filled, so it lives through a collection that runs
while the call waits or while its result is made, even where nothing else holds it. A function that
takes its slice as a &lt;code&gt;[]const T&lt;/code&gt; reads the copy, and the copy back leaves the array as it was.&lt;/p&gt;
&lt;p&gt;An array anywhere else — of strings, mirrors or other collections, or held in an &lt;code&gt;Option&lt;/code&gt;, a
&lt;code&gt;Result&lt;/code&gt;, a collection or a mirror’s field — has nothing to write back into, since Sysl’s value and
the Avin one are not alike. It crosses as a &lt;code&gt;[]const T&lt;/code&gt;, a slice Sysl may only read, so a Sysl type
that would let the function write into it is reported at the binding rather than handed a copy
whose writes are lost:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `names` does not match `avintest.digits.name_all`: Sysl may write the elements of its `[]string`, and an `Array` there crosses as a copy it may only read, so what it wrote would never reach the array: an `Array` is written back only as the binding&apos;s own parameter, of bytes, integers, reals, booleans or characters
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The array is copied rather than handed to Sysl as a view of its own elements. The collector never
moves an object, so a view would be sound for the length of the call, but a Sysl slice of memory it
does not own carries no owner, and nothing stops the Sysl function from keeping it: in a structure,
a buffer, another thread. Once the call returns, the collector may free the array under that slice.
A copy keeps the rule below whole, and costs one pass over the array each way, which beside the
system call a buffer is usually filled by is nothing.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `Vector[List[int]]` cannot cross to Sysl; a binding&apos;s parameters and result are integers of 8, 16, 32 or 64 bits, `byte`, `real`, `char`, `bool`, `unit`, `string`, data types declared with `@sysl` to mirror a Sysl enum or struct, and `Array`, `Vector`, `Option`, `Result` and tuples of these
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Avin heap references never enter Sysl memory.&lt;/strong&gt; A Sysl container cannot hold an Avin object,
because Sysl’s reference counting cannot keep an Avin object alive and the collector cannot see Sysl
memory. That is why a collection crosses as a copy of its elements, never as the Avin array itself,
even an array Sysl &lt;a href=&quot;#filled-arrays&quot;&gt;fills&lt;/a&gt;.
Avin’s own collections are written in Avin, so the standard library has no need for Sysl
containers of Avin values.&lt;/p&gt;
&lt;h2 id=&quot;mirrors&quot;&gt;Mirrors&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;data&lt;/code&gt; type declared with &lt;code&gt;@sysl(&amp;quot;module.Name&amp;quot;)&lt;/code&gt; &lt;strong&gt;mirrors&lt;/strong&gt; a Sysl enum or struct: values of
either convert into the other wherever a binding’s types hold one.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sysl.fs.IoError&amp;quot;)
data IoError
  NotFound
  PermissionDenied
  AlreadyExists
  NotADirectory
  IsADirectory
  DirectoryNotEmpty
  TooManyOpenFiles
  NoSpaceLeft
  Interrupted
  NotOpen
  NotPermitted
  InvalidUtf8(offset: long)
  Other(code: int)

@sysl(&amp;quot;sysl.fs.read_text&amp;quot;)
readText(file: string) -&amp;gt; Result[string, IoError]
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An enum&lt;/strong&gt; is mirrored variant by variant: each Avin variant is the Sysl variant of the same name,
and its fields are the Sysl variant’s payload, in order.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A struct&lt;/strong&gt; is mirrored by a data type with one variant named as the type, whose fields are the
struct’s fields: &lt;code&gt;data LocalDate&lt;/code&gt; with the one variant &lt;code&gt;LocalDate(day: int)&lt;/code&gt; mirrors
&lt;code&gt;sysl.time.LocalDate&lt;/code&gt;. A field is written in Avin’s lowerCamelCase, and the compiler matches it to
the Sysl field of the same words in snake_case: each uppercase letter becomes an underscore and
its lowercase, and digits stay, so &lt;code&gt;restArePositional&lt;/code&gt; is Sysl’s &lt;code&gt;rest_are_positional&lt;/code&gt; and
&lt;code&gt;utf8Offset&lt;/code&gt; is &lt;code&gt;utf8_offset&lt;/code&gt;. A field written with an underscore is an error that names the
lowerCamelCase spelling, so a field has one spelling. Variants of an enum keep Sysl’s names,
which are PascalCase in both languages, and a variant’s fields are matched by position.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A field is a boundary type.&lt;/strong&gt; An integer field takes any Sysl integer, converted with a check in
each direction as an &lt;a href=&quot;#integer-results&quot;&gt;integer result&lt;/a&gt; is: Avin has no unsigned integers, so
Sysl’s &lt;code&gt;usize&lt;/code&gt; offset above is a &lt;code&gt;long&lt;/code&gt;, and a value the other side’s type cannot hold stops the
program where the binding was called. A real field takes any Sysl floating-point type, rounded
going in and widened coming out as a &lt;a href=&quot;#real-numbers&quot;&gt;real&lt;/a&gt; is. A collection field is copied as a
binding’s collection is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A field may be a &lt;a href=&quot;#handles&quot;&gt;handle&lt;/a&gt;&lt;/strong&gt;, by itself — not in an &lt;code&gt;Option&lt;/code&gt;, a collection or a tuple.
Into Sysl it is passed as a handle parameter is, with the same checks: a closed handle, or one
another thread owns, stops the program where the binding was called. Out of Sysl each such field
becomes a handle of its own, as a binding’s handle result does. Sysl’s &lt;code&gt;sysl.process.Stdio&lt;/code&gt; holds a
&lt;code&gt;File&lt;/code&gt; in &lt;code&gt;ToFile&lt;/code&gt; and &lt;code&gt;FromFile&lt;/code&gt;, so the ends of a pipe reach a child’s streams:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sysl.fs.File&amp;quot;)
class File
  closed() -&amp;gt; bool

@sysl(&amp;quot;sysl.process.Stdio&amp;quot;)
data Stdio
  Inherit
  ToFile(file: File)
  ToPath(path: string)
  FromFile(file: File)
  FromPath(path: string)
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A mirror has no type parameters, and none of its fields holds the mirror itself, directly or
through an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a collection or another mirror.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sysl checks a mirror against the type it names when it checks a shim that converts one, so a missing
variant, a field of the wrong type or a name Sysl does not declare is reported at the mirror, in
Sysl’s words:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl mirror `IoError` does not match `sysl.fs.IoError`: match on &apos;IoError&apos; is not exhaustive; missing PermissionDenied, …
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;methods-of-a-mirror&quot;&gt;Methods of a mirror&lt;/h3&gt;
&lt;p&gt;A method without a body in an &lt;code&gt;impl&lt;/code&gt; of a mirror is &lt;strong&gt;bound&lt;/strong&gt; to a Sysl method of the value the
mirror is: the one of the same words in snake_case (&lt;code&gt;dayOfWeek&lt;/code&gt; is &lt;code&gt;day_of_week&lt;/code&gt;), or the one its
own &lt;code&gt;@sysl(&amp;quot;name&amp;quot;)&lt;/code&gt; names. &lt;code&gt;@sysl(blocking)&lt;/code&gt; and &lt;code&gt;@sysl(&amp;quot;name&amp;quot;, blocking)&lt;/code&gt; mark a Sysl method that
may wait, and &lt;code&gt;named&lt;/code&gt; passes the arguments by name, as on a &lt;a href=&quot;#handles&quot;&gt;handle’s method&lt;/a&gt;. A method
with a body is an ordinary method, may call the bound ones, and takes no &lt;code&gt;@sysl&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sh.sysl.openssl.Refusal&amp;quot;)
data TlsRefusal
  HostMismatch
  Expired
  NotYetValid
  Untrusted
  Other(code: long)

@sysl(&amp;quot;sh.sysl.openssl.Error&amp;quot;)
data TlsFailure(reason: int, code: long, message: string, verify: long)

impl TlsFailure
  refusal() -&amp;gt; Option[TlsRefusal]
  refused() -&amp;gt; bool = refusal() is Some(_)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The receiver is converted at each call.&lt;/strong&gt; The mirror goes into Sysl as a binding’s parameter of
its type does, into a counted box of its own, and the Sysl method is called on that box, so a
Sysl method taking &lt;code&gt;self&lt;/code&gt;, &lt;code&gt;&amp;amp;self&lt;/code&gt; or &lt;code&gt;*self&lt;/code&gt; is bound alike. What a &lt;code&gt;*self&lt;/code&gt; method writes goes
into the box and is gone with it: a mirror is a value, and the call leaves it as it was.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its parameters and result cross as a binding’s do&lt;/strong&gt;: a result may be another mirror or the
mirror itself, an &lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Result&lt;/code&gt; of one, a handle, or any other boundary type, and an
integer is converted with a check as a binding’s integer is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bound methods may be overloaded&lt;/strong&gt; by their parameter types, each naming its own Sysl method.&lt;/li&gt;
&lt;li&gt;Only a mirror’s methods may go without a body, and only in an &lt;code&gt;impl&lt;/code&gt; of no trait: a method
without a body on any other data type, or one implementing a trait’s, is refused as needing a
body. A data type’s body holds its variants, so a mirror’s bound methods are always in an &lt;code&gt;impl&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sysl checks each bound method when it checks the shim, and reports a mismatch at the method, in its
own words:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `Verdict.missing` does not match `avintest.digits.Verdict`: type &apos;digits.avintest.digits.Verdict&apos; has no method &apos;missing&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;handles&quot;&gt;Handles&lt;/h2&gt;
&lt;p&gt;A Sysl value that Avin should hold without seeing inside — a checksum in progress, a mapped file, a
big integer — is reached through a &lt;strong&gt;handle&lt;/strong&gt;: a &lt;code&gt;class&lt;/code&gt; declared with &lt;code&gt;@sysl&lt;/code&gt; naming the Sysl type.
Its body declares only methods. A method without a body is bound to the Sysl method of the same words
in snake_case (&lt;code&gt;isEmpty&lt;/code&gt; is &lt;code&gt;is_empty&lt;/code&gt;), or to the one its own &lt;code&gt;@sysl(&amp;quot;name&amp;quot;)&lt;/code&gt; names; a method with a
body is an ordinary method, and may call the bound ones:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@sysl(&amp;quot;sysl.checksum.Crc32&amp;quot;)
class Crc32
  update(bytes: Array[byte])
  finish() -&amp;gt; long
  hex() -&amp;gt; string = s&amp;quot;${finish()}&amp;quot;

@sysl(&amp;quot;sysl.checksum.new_crc32&amp;quot;)
newCrc32() -&amp;gt; Crc32

@sysl(&amp;quot;sysl.math.bigint.BigInt&amp;quot;)
class BigInt
  sign() -&amp;gt; int
  neg() -&amp;gt; BigInt

@sysl(&amp;quot;sysl.math.bigint.parse&amp;quot;)
parseBigInt(s: string) -&amp;gt; Option[BigInt]
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Only a binding makes a handle.&lt;/strong&gt; A handle has no parameters and no constructor; a binding that
returns one — directly, in an &lt;code&gt;Array&lt;/code&gt;, a &lt;code&gt;Vector&lt;/code&gt;, an &lt;code&gt;Option&lt;/code&gt; or a &lt;code&gt;Result&lt;/code&gt;, as a part of a
tuple, or from a handle’s own method — makes the object, holding one counted reference to the Sysl value it was given (a
value is moved into a reference of its own; a counted reference is shared). A collection of
handles comes from a Sysl slice or &lt;code&gt;Buf&lt;/code&gt; of values or of counted references, and each element is
a handle of its own, closed and collected on its own.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle goes back into Sysl by itself&lt;/strong&gt;: as the receiver of its own methods, or as a parameter
of a binding or of another handle’s method. A trait is always held by a counted reference, and its
parameter shares the handle’s; any other type is passed as the Sysl parameter takes it — by value,
a copy; as a pointer to the handle’s own value; or, at a &lt;code&gt;&amp;amp;T&lt;/code&gt;, as the handle’s own counted
reference, so what the Sysl function sets through it the handle reads. A
&lt;a href=&quot;#mirrors&quot;&gt;mirror’s field&lt;/a&gt; that is a handle is passed the same way, and so is each element of a
&lt;a href=&quot;#collections-of-handles&quot;&gt;collection of handles&lt;/a&gt; that is a parameter. A handle inside an
&lt;code&gt;Option&lt;/code&gt;, a tuple or any other collection does not go into Sysl, nor is it a mirror’s field; a
tuple holding a handle crosses out of Sysl as a result, the value of its &lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Result&lt;/code&gt;, or
a part of a tuple that is one of these, as &lt;code&gt;accept&lt;/code&gt; answers &lt;code&gt;Result[(Socket, Address), IoError]&lt;/code&gt;,
and never sits in a collection. Its Sysl value’s fields are not the handle’s members.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@sysl(&amp;quot;sysl.net.Address&amp;quot;)
class Address
  port() -&amp;gt; int

@sysl(&amp;quot;sysl.net.Socket&amp;quot;)
class Socket
  connect(to: Address) -&amp;gt; Result[unit, IoError]

@sysl(&amp;quot;sysl.net.resolve&amp;quot;)
resolve(host: string, port: int) -&amp;gt; Result[Vector[Address], IoError]

@sysl(&amp;quot;sysl.net.socket&amp;quot;)
socket(forAddress: Address) -&amp;gt; Result[Socket, IoError]
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;close()&lt;/code&gt; gives the value back.&lt;/strong&gt; Every handle has it. Closing again does nothing; a bound method
called on a closed handle, or a closed handle passed to Sysl as a parameter or a mirror’s field,
stops the program at the call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `Crc32` is closed at main.avin:18:13
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle never closed is given back by the collector&lt;/strong&gt;, when it frees the object, through a
finalizer the shim generates for the class. When that happens is not specified: a value that holds
something scarce, such as a file, is closed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle belongs to one owner at a time.&lt;/strong&gt; Its Sysl value is held by a counted reference whose
count is not atomic, so a handle is never used by two threads at once. Each handle records its
owner, the code that made it, and every use — a bound method, the handle passed as a parameter or
a mirror’s field, &lt;code&gt;close()&lt;/code&gt; — compares it with the owner of the code running and stops the program at the call where
they differ:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `File` belongs to another thread at main.avin:31:5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The owner is not an operating system thread but whatever the runtime is running: a thread’s body,
a task on the futures’ pool (whichever worker runs it), and, once there are actors, an actor, which
keeps its handles from one message to the next whichever thread runs it. The check is one compare
of two words, the handle’s owner and the running code’s, which the runtime sets when it starts
running something else.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A trap names the handle by its class&lt;/strong&gt;, unless the class’s &lt;code&gt;@sysl&lt;/code&gt; gives it another name after
the Sysl type, &lt;code&gt;named: &amp;quot;Name&amp;quot;&lt;/code&gt;, a type’s name (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A library
value that keeps a handle only to carry its owner names the handle for itself, so the trap names
the type its user holds: a started &lt;code&gt;Child&lt;/code&gt; keeps one declared &lt;code&gt;@sysl(&amp;quot;avin.rt.Token&amp;quot;, named: &amp;quot;Child&amp;quot;)&lt;/code&gt;, and traps with “&lt;code&gt;Child&lt;/code&gt; belongs to another thread”. The name changes nothing else.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ownership moves with what is handed to code that runs elsewhere.&lt;/strong&gt; The handles a thread’s body or
a future’s body reaches — captured directly, or through any object or collection — that the
calling code owns become the body’s when it is started, and the caller’s next use of one traps.
When the body returns, what it was given and what it returns are &lt;strong&gt;in transit&lt;/strong&gt;, as is a value a
future or promise is completed with and what a callback given to &lt;code&gt;onComplete&lt;/code&gt; or &lt;code&gt;map&lt;/code&gt; reaches: a
handle in transit is taken by the first code to use it. A future’s body, or the function of its
&lt;code&gt;map&lt;/code&gt; or &lt;code&gt;flatMap&lt;/code&gt;, gives up what it was given before its value is published, so the code that
awaits the value, or a future made from it, may use those handles at once. A value sent on a
channel keeps its owner.
A message sent to an actor hands its handles to that actor (&lt;a href=&quot;/spec/actors/#handing-over-ownership&quot;&gt;actors&lt;/a&gt;).
Handing a value over follows what it holds and stops at what is shared between owners — an
actor’s reference, a future, a promise, a channel, a mutex, an atomic, a thread, an executor —
whose handles keep their owners.
How a program hands a handle over explicitly is &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The finalizer never checks the owner: a handle is finalized only once nothing can reach it, so no
other code can be using it, and the collector, which runs finalizers on whichever thread collects
while every other is stopped, gives its reference back.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle is compared by identity&lt;/strong&gt;, and has no &lt;code&gt;Display&lt;/code&gt; of its own.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The bytes a handle’s method answers may be a view of the handle’s own value; they are copied out
before anything else runs, so the Avin array never reads the Sysl value’s memory.&lt;/p&gt;
&lt;h3 id=&quot;handles-on-traits&quot;&gt;Handles on traits&lt;/h3&gt;
&lt;p&gt;A handle may name a Sysl &lt;strong&gt;trait&lt;/strong&gt;, and then holds a trait object: whatever value the binding that
made it answered, reached through the trait’s method table. Its methods are the trait’s, a default
one among them, and a method answering the trait is a handle of its own:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;syslui.View&amp;quot;)
class View
  padding(n: int) -&amp;gt; View

@sysl(&amp;quot;syslui.text&amp;quot;)
text(s: string) -&amp;gt; View
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A trait handle is everything a struct handle is: made by a binding’s result, alone or in an
&lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a tuple or a collection; passed back by itself, as a mirror’s field, as a
callback’s answer and in a collection; closed; given back by its finalizer; and owned by the code
that made it, its owner checked at every use. Its Sysl parameter takes it as a counted reference,
which the parameter shares, since a trait object is only ever reached through one.&lt;/p&gt;
&lt;p&gt;A trait object is two words, its value and its method table, and a handle’s object keeps its
reference in one: so a trait handle’s reference is kept in a cell of its own, which that word points
at. Every handle’s object is the same two words, the reference or the cell and the owner, and a
struct handle is reached as directly as it was; a trait handle’s method reads one word more.&lt;/p&gt;
&lt;h3 id=&quot;collections-of-handles&quot;&gt;Collections of handles&lt;/h3&gt;
&lt;p&gt;An &lt;code&gt;Array&lt;/code&gt; or a &lt;code&gt;Vector&lt;/code&gt; of handles that is a binding’s parameter, or a handle’s method’s, goes into
Sysl as a slice of the handles’ Sysl values, for the call, as &lt;code&gt;syslui&lt;/code&gt;‘s containers take their
children:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;syslui.column&amp;quot;)
column(children: Vector[View], spacing: int) -&amp;gt; View
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Each element is checked as a handle passed by itself is&lt;/strong&gt;: one closed, or owned by other code,
stops the program at the call, naming the handle’s class, though the others are the caller’s own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each element is shared for the call&lt;/strong&gt;: the slice holds a share of each handle’s Sysl value,
taken before the call, made the elements the Sysl parameter takes — the counted references, or,
where it asks for them, the values or pointers to them. What Sysl keeps of the slice it
keeps by its own shares, so a column outlives the vector it was made from, and a child closed
afterwards. A call that &lt;a href=&quot;#calls-that-wait&quot;&gt;waits&lt;/a&gt; takes the shares before the thread is safe for the
collector, and makes its slice from them, so it reads no Avin object.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A vector is a &lt;code&gt;[]T&lt;/code&gt;, an array a &lt;code&gt;[]const T&lt;/code&gt;&lt;/strong&gt;, as for every &lt;a href=&quot;#collections-are-copies&quot;&gt;collection&lt;/a&gt;:
an array of handles reaches only a Sysl parameter that may not write its elements. A Sysl parameter
that takes a &lt;code&gt;Buf&lt;/code&gt; is not reached, as for any collection.&lt;/li&gt;
&lt;li&gt;Only the collection itself is a parameter: a collection of collections or of options of handles, a
&lt;code&gt;List&lt;/code&gt; of them, an &lt;code&gt;Option&lt;/code&gt; holding one and a callback answering one do not go into Sysl, and a
mirror’s field holds a handle only by itself.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A slice or a &lt;code&gt;Buf&lt;/code&gt; of handles, of trait objects as of struct values, comes back out of Sysl as a
vector or an array of handles, each its own, as every collection does, so a tree built on either
side crosses both ways.&lt;/p&gt;
&lt;h3 id=&quot;handles-on-generic-instances&quot;&gt;Handles on generic instances&lt;/h3&gt;
&lt;p&gt;A handle may name an &lt;strong&gt;instance&lt;/strong&gt; of a generic Sysl type, struct or trait, with its type arguments in
brackets after the type’s name, each written as Avin writes it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;syslui.Signal[string]&amp;quot;)
class StringSignal
  get() -&amp;gt; string
  set(v: string)

@sysl(&amp;quot;syslui.signal&amp;quot;)
stringSignal(v: string) -&amp;gt; StringSignal

@sysl(&amp;quot;syslui.text_field&amp;quot;)
textField(text: StringSignal, id: int) -&amp;gt; View
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Its methods are bound at that instance, and it is a handle on that one Sysl type: a generic Sysl
function that answers the instance makes one, and a parameter that takes another instance is
refused when Sysl checks the shim. Each type argument is a boundary type that is one Sysl type —
an integer of 8, 16, 32 or 64 bits, &lt;code&gt;byte&lt;/code&gt; (Sysl’s &lt;code&gt;u8&lt;/code&gt;), &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;,
or an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt; or a tuple of these — so the instance is fixed by its name alone:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `Vector[int]` cannot be a type argument of the Sysl type a handle is on: each is one Sysl type, an integer of 8, 16, 32 or 64 bits, `byte`, `real`, `char`, `bool`, `unit`, `string`, or an `Option`, a `Result` or a tuple of these
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each instance a program binds is its own class, and two classes may name the same instance; one Avin
class for every instance of a generic type is a &lt;a href=&quot;#generic-handles&quot;&gt;generic handle&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;calls-that-wait&quot;&gt;Calls that wait&lt;/h2&gt;
&lt;p&gt;A Sysl function that may wait — for a connection, for data on a socket or a pipe, for a process to
end, for time to pass — is bound with &lt;strong&gt;&lt;code&gt;blocking&lt;/code&gt;&lt;/strong&gt; after its name. A handle’s method bound by its
own name takes &lt;code&gt;@sysl(blocking)&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sysl.net.accept&amp;quot;, blocking)
private acceptRaw(listener: long) -&amp;gt; Result[long, SyslIoError]

@sysl(&amp;quot;sysl.net.Socket&amp;quot;)
class Socket
  @sysl(blocking)
  recv(max: long) -&amp;gt; Result[Array[byte], SyslIoError]
  @sysl(&amp;quot;send_all&amp;quot;, blocking)
  write(bytes: Array[byte]) -&amp;gt; Result[unit, SyslIoError]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While a blocking call waits, its thread is &lt;strong&gt;safe for the collector&lt;/strong&gt;, as a thread waiting on a
lock, a channel or a join is (&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;): every other thread goes on allocating, and
a collection runs without waiting for this one. A call that is not declared blocking holds up every
collection for as long as it runs, so a binding that can wait for something outside the program is
declared blocking. On a program’s only thread, &lt;code&gt;blocking&lt;/code&gt; costs two stores and two loads.&lt;/p&gt;
&lt;p&gt;The shim keeps the Sysl call away from the Avin heap while the thread is safe, because the collector
may then free any object no frame still holds:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every argument is converted before the call&lt;/strong&gt;, so the call reads Sysl copies, never an Avin
object. Since a collection &lt;a href=&quot;#collections-are-copies&quot;&gt;crosses as a copy&lt;/a&gt;, no argument is a
pointer into the Avin heap.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A handle’s method takes its own share&lt;/strong&gt; of the handle’s Sysl value before it waits, so the value
outlives the call even if the handle is collected, and its finalizer run, meanwhile. A handle
passed as a parameter is held the same way: its share is taken before the call, and the copy or
pointer the parameter asks for is made from that share.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The result is converted after the call&lt;/strong&gt;, once the thread is running again, since converting
makes Avin objects. Bytes a handle’s method answers, which may be a view of the handle’s value,
are copied into Sysl memory first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;a href=&quot;#filled-arrays&quot;&gt;filled array&lt;/a&gt; is copied in before the call and back after it.&lt;/strong&gt; The Sysl
function writes its own slice while it waits, the array stays held by the calling thread’s stack
throughout, and what the function left is copied into the array once the thread is running
again, after the result is converted. A blocking &lt;code&gt;read(into: Array[byte])&lt;/code&gt; is bound this way.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;blocking&lt;/code&gt; is written alone and once, and only on a function or a handle’s method: a type does not
wait.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `blocking` is written alone, after the Sysl function&apos;s name: `@sysl(&amp;quot;sysl.net.accept&amp;quot;, blocking)`
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;generics&quot;&gt;Generics&lt;/h2&gt;
&lt;p&gt;A binding may be generic, bound once to a generic Sysl function and called at any type its type
parameters admit. Each type parameter is bounded by &lt;strong&gt;&lt;code&gt;Boundary&lt;/code&gt;&lt;/strong&gt;, the types that cross to Sysl as
one Sysl type each: the integers of 8, 16, 32 and 64 bits, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;,
&lt;code&gt;string&lt;/code&gt;, the data types declared with &lt;code&gt;@sysl&lt;/code&gt; to &lt;a href=&quot;#mirrors&quot;&gt;mirror&lt;/a&gt; a Sysl enum or struct, and
&lt;code&gt;Option&lt;/code&gt;s, &lt;code&gt;Result&lt;/code&gt;s and tuples of these. The binding’s parameters and result build on its type
parameters as on any boundary type, in collections, options, results, tuples and callbacks:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;avintest.digits.same&amp;quot;)
same[T: Boundary](x: T) -&amp;gt; T

@sysl(&amp;quot;avintest.digits.first_some&amp;quot;)
firstSome[T: Boundary](xs: Vector[Option[T]]) -&amp;gt; Option[T]

@sysl(&amp;quot;avintest.digits.applied&amp;quot;)
applied[T: Boundary, U: Boundary](x: T, f: T -&amp;gt; U) -&amp;gt; U

same(3)                          // 3
firstSome([None, Some(&amp;quot;b&amp;quot;)])     // Some(b)
applied(Spot(2, 3), s -&amp;gt; s.x * s.y)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The compiler generates &lt;strong&gt;one shim per instantiation&lt;/strong&gt; the program uses, wherever in the program it
is used, and Sysl checks each one at its types, so a type argument the Sysl function’s own bound
refuses is reported at the binding, in Sysl’s words:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `largest` does not match `avintest.digits.larger`: &apos;digits.avintest.digits.larger&apos; requires its type parameter &apos;T&apos; to implement &apos;PartialOrd&apos;, but digits.avintest.digits.Spot does not
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An Avin bound beside &lt;code&gt;Boundary&lt;/code&gt;, &lt;code&gt;[T: Boundary &amp;amp; Ord]&lt;/code&gt;, is checked by Avin at the call as any bound
is; the two are not related, and the Sysl function’s bounds are Sysl’s to check. A collection, which
crosses as a copy whose Sysl type differs by direction, a &lt;a href=&quot;#handles&quot;&gt;handle&lt;/a&gt;, which goes into Sysl
only by itself, and every other class, data type and function are not &lt;code&gt;Boundary&lt;/code&gt;, and are refused at
the call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `Plain` does not conform to `Boundary`, the bound of `T` in `same`; a value crosses to Sysl as one Sysl type where it is an integer of 8, 16, 32 or 64 bits, `byte`, `real`, `char`, `bool`, `unit`, `string`, a data type declared with `@sysl` to mirror a Sysl enum or struct, or an `Option`, a `Result` or a tuple of these
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Boundary&lt;/code&gt; is decided by the compiler from a type’s structure, so it is written only as a bound: it
is not a type, and no impl or trait declares it. A generic function passes its own type parameter on
to a binding where that parameter is bounded by &lt;code&gt;Boundary&lt;/code&gt; too, so a library’s public generic
function can wrap a private generic binding:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;echo[T: Boundary](x: T) -&amp;gt; T = rawSame(x)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A type parameter that is not bounded by it does not cross:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `T` cannot cross to Sysl; a type parameter crosses as the type it is given, which its bound holds to one Sysl type, as in `[T: Boundary]`
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;generic-handles&quot;&gt;Generic handles&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;generic handle class&lt;/strong&gt; is a handle on every instance of a generic Sysl type, struct or trait.
Its &lt;code&gt;@sysl&lt;/code&gt; names the generic type without arguments, and its type parameters are the Sysl type’s
own, in order: invariant, as Sysl’s are, and each bounded by &lt;code&gt;Boundary&lt;/code&gt;. Its methods are bound at
every instance, and a method may have type parameters of its own, bounded the same way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;syslui.Signal&amp;quot;)
class Signal[T: Boundary]
  get() -&amp;gt; T
  set(v: T)
  paired[U: Boundary](u: U) -&amp;gt; (T, U)

@sysl(&amp;quot;syslui.signal&amp;quot;)
signal[T: Boundary](v: T) -&amp;gt; Signal[T]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each instance the program uses, &lt;code&gt;Signal[int]&lt;/code&gt; or &lt;code&gt;Signal[Option[Spot]]&lt;/code&gt;, is a handle on the Sysl
type’s instance at those arguments, a class of its own with its own finalizer, and is passed to a
binding that takes that instance as any handle is. Sysl checks the instance, so a class with the
wrong number of type parameters is reported at the class. A handle names an instance in its &lt;code&gt;@sysl&lt;/code&gt;
&lt;a href=&quot;#handles-on-generic-instances&quot;&gt;by its arguments&lt;/a&gt; or has type parameters, not both:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: a Sysl handle names an instance of a generic Sysl type or has type parameters, the Sysl type&apos;s own, but not both
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A callback whose closure takes one of the Sysl function’s type parameters, as &lt;code&gt;applied&lt;/code&gt;‘s does, gives
Sysl nothing to infer the closure’s parameter types from; the shim then writes each as the Avin
type’s.&lt;/p&gt;
&lt;h2 id=&quot;callbacks&quot;&gt;Callbacks&lt;/h2&gt;
&lt;p&gt;A binding’s parameter may take a &lt;strong&gt;function&lt;/strong&gt;. Sysl is handed a closure the shim makes of it, so a
Sysl function taking a &lt;code&gt;&amp;amp;Fn(A) -&amp;gt; B&lt;/code&gt;, a &lt;code&gt;&amp;amp;sync Fn(A) -&amp;gt; B&lt;/code&gt; or a bare &lt;code&gt;A -&amp;gt; B&lt;/code&gt; takes any Avin function
of the matching type: a lambda, a closure capturing locals or objects, a method value, a local or a
top-level function, a function value held in a variable.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;ui.widgets.on_click&amp;quot;)
onClick(button: Button, handler: (Point) -&amp;gt; unit)

@sysl(&amp;quot;ui.app.run_every&amp;quot;)
runEvery(ms: long, @threaded tick: () -&amp;gt; bool)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The callback’s parameters cross out of Sysl and its result into Sysl&lt;/strong&gt;, as a binding’s result
and parameters do: any boundary type, a handle included. An integer Sysl calls it with in a wider
type is &lt;a href=&quot;#integer-results&quot;&gt;checked&lt;/a&gt;, stopping the program where the binding Sysl is running in
was called. A function is not a callback’s parameter or result, and a binding does not return
one. A type that does not fit the closure Sysl takes is reported at the binding in Sysl’s words:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `wrongParameter` does not match `avintest.callbacks.apply`: the function&apos;s parameter 1 is string, but Sysl calls it with int
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A callback’s integer answer goes into whatever integer the closure answers&lt;/strong&gt;, converted with
the same check. Avin has no unsigned integers, so a Sysl closure answering a &lt;code&gt;u32&lt;/code&gt;, a &lt;code&gt;u64&lt;/code&gt; or a
&lt;code&gt;usize&lt;/code&gt; takes an Avin function answering a &lt;code&gt;long&lt;/code&gt; (or an &lt;code&gt;int&lt;/code&gt;), and one answering an &lt;code&gt;i8&lt;/code&gt; takes
a &lt;code&gt;long&lt;/code&gt; too where its values fit. syslui asks its window’s colour this way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@sysl(&amp;quot;sh.sysl.ui_sdl.app&amp;quot;)
app(title: string, tree: () -&amp;gt; View, ground: () -&amp;gt; long) -&amp;gt; App
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An answer the Sysl type cannot hold — a negative one for a &lt;code&gt;u32&lt;/code&gt;, one past its largest value —
stops the program where the binding Sysl is running in was called, naming the Sysl type by its
sign and width:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: value out of range for u32 at main.avin:10:13
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A closure whose answer is a type parameter of a generic Sysl function, &lt;code&gt;answer_any[T](f: &amp;amp;Fn() -&amp;gt; T) -&amp;gt; T&lt;/code&gt;, says no integer to convert into, and answers the Avin type itself: &lt;code&gt;T&lt;/code&gt; is then the
binding’s &lt;code&gt;long&lt;/code&gt; or &lt;code&gt;int&lt;/code&gt;. An integer answer goes into an integer only:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl binding `integerForText` does not match `avintest.callbacks.text_op`: the function answers an integer, which goes into Sysl only as an integer, but the closure Sysl takes answers string
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A callback’s real answer is rounded into whatever floating-point type the closure answers&lt;/strong&gt;,
and a real parameter Sysl calls it with is widened out of whatever floating-point type it is, as
a binding’s &lt;a href=&quot;#real-numbers&quot;&gt;real&lt;/a&gt; is: a closure &lt;code&gt;&amp;amp;Fn(f32) -&amp;gt; f32&lt;/code&gt; takes an Avin &lt;code&gt;real -&amp;gt; real&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sysl keeps the function alive for as long as it holds the closure.&lt;/strong&gt; The closure holds a root of
the collector, made when the binding is called, so a callback Sysl stores and calls later runs
even after the Avin code that gave it has let go of it. When Sysl drops the closure, its last
counted reference, the root goes with it, and the function is collected like any other object.
A closure Sysl only calls during the binding is dropped when the binding returns. Each call of a
binding makes a closure of its own: the same function passed twice is held twice.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A call runs on the thread that makes it&lt;/strong&gt;, with that thread’s context: the program’s arguments
and results never move between threads. Calls nest to any depth, Avin calling Sysl calling Avin,
and a callback may call bindings, blocking ones included. A callback Sysl calls while its thread
waits in a &lt;a href=&quot;#calls-that-wait&quot;&gt;blocking call&lt;/a&gt; makes the thread running for the call, so it may
allocate and collect, and safe again after.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A callback belongs to the code that gave it&lt;/strong&gt;, as a &lt;a href=&quot;#handles&quot;&gt;handle&lt;/a&gt; does: one called by any
other — another thread, a task on the futures’ pool, a thread Sysl started — stops the program,
before any of the function runs:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: the callback given to `keep` belongs to another thread at main.avin:15:25
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The place is where the calling code entered Sysl; a thread Sysl started itself has no such place.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A parameter marked &lt;code&gt;@threaded&lt;/code&gt; takes a function any thread may call.&lt;/strong&gt; A thread Sysl started,
which the program never knew, is attached to the runtime for the call and detached after. The
function is checked where the binding is called: a top-level function, which captures nothing,
or a lambda, local function or method value whose every capture is a &lt;code&gt;val&lt;/code&gt; or a parameter of a
&lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt; type or marked &lt;code&gt;@sendable&lt;/code&gt;. A value of a
&lt;a href=&quot;/spec/types/#function-types&quot;&gt;&lt;code&gt;@sendable&lt;/code&gt; function type&lt;/a&gt;, and a parameter marked
&lt;code&gt;@sendable&lt;/code&gt;, are taken as they are, since each was checked where it was made or passed to be what
any thread may run. Any other function value, whose type does not say what it captures, is
refused, as is a captured &lt;code&gt;var&lt;/code&gt;, which the other thread would share; a binding with a &lt;code&gt;@threaded&lt;/code&gt;
parameter is called by name, never used as a value, so no call escapes the check.
&lt;strong&gt;A binding with a &lt;code&gt;@threaded&lt;/code&gt; parameter is &lt;code&gt;blocking&lt;/code&gt;&lt;/strong&gt; whether or not it says so: the Sysl
call may wait for another thread to call back, and that thread’s collections go on without the
waiting one. A Sysl parameter of type &lt;code&gt;&amp;amp;sync Fn&lt;/code&gt; needs the mark, and Sysl’s refusal says so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the function passed to `f` of `share`, which Sysl may call from any thread, captures `count`, a `var`, which that thread would share with the code here; capture a `val` holding its value
error: the Sysl binding `shareUnmarked` does not match `avintest.callbacks.share`: Sysl may call the function it is given from another thread, so the parameter that takes it is marked `@threaded`
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A trap inside a callback stops the program&lt;/strong&gt;, as any trap does, reported at its own place in
the callback’s code, however deep in Sysl it was called.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;avin.rt.callbacks_held&lt;/code&gt;, a function the runtime offers the library, answers how many functions
Sysl holds now.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;relationship-to-c&quot;&gt;Relationship to C&lt;/h2&gt;
&lt;p&gt;A C library is bound directly, by &lt;a href=&quot;/spec/c-bindings/&quot;&gt;C bindings&lt;/a&gt;, which are calls from Avin’s own
code rather than through a shim. Until they are built, and wherever Sysl already binds a library
well, a C library reaches Avin through Sysl: Sysl binds the C API with its own FFI, and Avin binds
the Sysl API.&lt;/p&gt;
&lt;h2 id=&quot;the-runtime-is-different&quot;&gt;The runtime is different&lt;/h2&gt;
&lt;p&gt;The Avin &lt;strong&gt;runtime&lt;/strong&gt; — program startup, the collector interface, traps, and the low-level string and
number primitives — is written in Sysl. It is reached through a private ABI that only the compiler
uses, not through bindings. Bindings are the public mechanism, and they are written in Avin. The one
exception is a plain top-level function the runtime offers the library, such as the platform’s
sentence for a file-system error: the library binds it by its module and name, &lt;code&gt;avin.rt.&amp;lt;name&amp;gt;&lt;/code&gt;, like
any Sysl function.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Strings and formatting</title>
    <link href="https://avinlang.dev/spec/strings-and-formatting/"/>
    <id>https://avinlang.dev/spec/strings-and-formatting/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>String literals, interpolation as a method call on StringContext, user-defined interpolators, and formatting through Display and Debug.</summary>
    <content type="html">&lt;p&gt;String literals are written as Sysl’s string reference describes them
(&lt;code&gt;docs/content/reference/strings.md&lt;/code&gt;). Text blocks, interpolation, format specifiers and rendering
are specified here.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Form&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&amp;quot;…&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Ordinary string with escapes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;raw&amp;quot;…&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Raw string, with no escape processing: a backslash is an ordinary character (&lt;code&gt;raw&amp;quot;C:\dir&amp;quot;&lt;/code&gt;), though &lt;code&gt;\&amp;quot;&lt;/code&gt; does not end the literal&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&amp;quot;&amp;quot;&amp;quot;…&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Text block: a literal over several lines, its incidental indentation dropped (&lt;a href=&quot;#text-blocks&quot;&gt;below&lt;/a&gt;); every prefix composes with it, &lt;code&gt;s&amp;quot;&amp;quot;&amp;quot;…&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; and &lt;code&gt;raw&amp;quot;&amp;quot;&amp;quot;…&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; included&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Interpolation: &lt;code&gt;$name&lt;/code&gt;, &lt;code&gt;${expression}&lt;/code&gt;, &lt;code&gt;$$&lt;/code&gt; for a dollar sign, &lt;code&gt;$&amp;quot;&lt;/code&gt; for a double quote&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;f&amp;quot;…&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Formatted interpolation: a specifier after a hole (&lt;code&gt;${x}%08.3f&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;name&amp;quot;…&amp;quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any interpolator: a call of the method &lt;code&gt;name&lt;/code&gt; on a &lt;code&gt;StringContext&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;text-blocks&quot;&gt;Text blocks&lt;/h2&gt;
&lt;p&gt;A literal that spans lines is written &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; … &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;. Its content begins on the line &lt;strong&gt;after&lt;/strong&gt; the
opening delimiter, which ends its line, so the column the block opens at plays no part in its value
and a block reads the same at any depth. A block written on one line is an error.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;render() -&amp;gt; string
    &amp;quot;&amp;quot;&amp;quot;
    one
      two
    three
    &amp;quot;&amp;quot;&amp;quot;
// &amp;quot;one\n  two\nthree\n&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Three things happen to each line of a block that do not happen inside &lt;code&gt;&amp;quot;…&amp;quot;&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Its incidental indentation is dropped.&lt;/strong&gt; The strip is the least indentation of the lines that
carry content, together with that of the closing delimiter’s line when the delimiter stands alone
on it, so the closing delimiter is the control: further left, the value keeps more indentation.
Lines holding only blanks say nothing about the strip and keep their line breaks. A tab and a space
are each one column.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its trailing blanks are dropped&lt;/strong&gt;, carriage returns among them, so whitespace nobody can see
never enters the value, and a file means the same with either line ending. Escapes are read after
the trimming, so a blank that is meant is written &lt;code&gt;\u{20}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;\&lt;/code&gt; at the end of a line joins it to the next&lt;/strong&gt;, the blanks before it going with the line’s
end, for data that must have no line breaks in its value.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whether the value ends with a line break needs no rule of its own: a closing delimiter alone on its
line comes after the last line’s break, and one written after content comes before any. A &lt;code&gt;&amp;quot;&lt;/code&gt;, and
&lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;, are text inside a block; the first &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; closes it, so a block cannot end with a quote except as
the escape &lt;code&gt;\&amp;quot;&lt;/code&gt;. An unterminated block is reported at its opening delimiter.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Every prefix composes with the quote form&lt;/strong&gt;: &lt;code&gt;s&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;, &lt;code&gt;f&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;, &lt;code&gt;raw&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; and any &lt;code&gt;name&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;. A prefix
says how a literal is read, the quote form how it was written. Holes, &lt;code&gt;$$&lt;/code&gt; and &lt;code&gt;$&amp;quot;&lt;/code&gt; are as in
&lt;code&gt;name&amp;quot;…&amp;quot;&lt;/code&gt;, and a hole may span lines, which are then code rather than text. The parts an interpolator
is given have the block’s indentation and trailing blanks already dropped, and their escapes as
written; since joining a line is an escape, &lt;code&gt;raw&amp;quot;&amp;quot;&amp;quot;…&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; and every interpolator but &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;f&lt;/code&gt;
receive a &lt;code&gt;\&lt;/code&gt; at a line’s end and the line break after it as written.&lt;/p&gt;
&lt;h2 id=&quot;format-specifiers&quot;&gt;Format specifiers&lt;/h2&gt;
&lt;p&gt;In an &lt;code&gt;f&amp;quot;…&amp;quot;&lt;/code&gt; literal, a &lt;code&gt;%&lt;/code&gt; written right after a hole begins that hole’s specifier, which says how
the value is laid out:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val n = 7
println(f&amp;quot;${n}%03d|${2.5}%08.2f|${&amp;quot;hi&amp;quot;}%-5s|&amp;quot;)     // 007|00002.50|hi   |
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A specifier is &lt;code&gt;%&lt;/code&gt;, then any flags, then a width, then &lt;code&gt;.&lt;/code&gt; and a precision, then one conversion
letter; everything but the &lt;code&gt;%&lt;/code&gt; and the letter may be left out. A hole with no specifier renders as in
&lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt;. A &lt;code&gt;%&lt;/code&gt; anywhere else, after text or after another &lt;code&gt;%&lt;/code&gt;, is text: &lt;code&gt;f&amp;quot;${n}%d done, 100% sure&amp;quot;&lt;/code&gt;.
There is no &lt;code&gt;%%&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Conversion&lt;/th&gt;&lt;th&gt;Takes&lt;/th&gt;&lt;th&gt;Writes&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;d&lt;/code&gt;, &lt;code&gt;i&lt;/code&gt;&lt;/td&gt;&lt;td&gt;an integer of any width, a &lt;code&gt;byte&lt;/code&gt;, or a &lt;a href=&quot;/spec/types/#bigint&quot;&gt;&lt;code&gt;BigInt&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;decimal&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;X&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;hexadecimal, in lower or upper case&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;o&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the same&lt;/td&gt;&lt;td&gt;octal, binary&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;f&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a &lt;code&gt;real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;fixed point, 6 decimals unless a precision says otherwise&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;e&lt;/code&gt;, &lt;code&gt;E&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a &lt;code&gt;real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;one digit, decimals and an exponent of at least two digits&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;g&lt;/code&gt;, &lt;code&gt;G&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a &lt;code&gt;real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;f&lt;/code&gt; or &lt;code&gt;e&lt;/code&gt;, whichever is shorter, the precision counting significant digits, trailing zeros dropped&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;c&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a &lt;code&gt;char&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the character&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a string, or any other value with &lt;code&gt;Display&lt;/code&gt; that is not a number&lt;/td&gt;&lt;td&gt;its &lt;code&gt;Display&lt;/code&gt; form&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;?&lt;/code&gt;&lt;/td&gt;&lt;td&gt;any value with &lt;code&gt;Debug&lt;/code&gt;&lt;/td&gt;&lt;td&gt;its &lt;code&gt;Debug&lt;/code&gt; form&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Integers are signed in every base.&lt;/strong&gt; A negative value is written as &lt;code&gt;-&lt;/code&gt; and its magnitude’s
digits, in hexadecimal, octal and binary as in decimal (&lt;code&gt;${-42}%x&lt;/code&gt; is &lt;code&gt;-2a&lt;/code&gt;). There is no &lt;code&gt;%u&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;real&lt;/code&gt;‘s digits are the exact value’s&lt;/strong&gt;, rounded half to even at the position the conversion
asks for (&lt;code&gt;${0.125}%.2f&lt;/code&gt; is &lt;code&gt;0.12&lt;/code&gt;, &lt;code&gt;${2.5}%.0f&lt;/code&gt; is &lt;code&gt;2&lt;/code&gt;); an infinity is &lt;code&gt;inf&lt;/code&gt; and a NaN &lt;code&gt;nan&lt;/code&gt;,
upper case under &lt;code&gt;E&lt;/code&gt; and &lt;code&gt;G&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flags&lt;/strong&gt;: &lt;code&gt;-&lt;/code&gt; pads on the right instead of the left, under every conversion. The others belong to
the numbers: &lt;code&gt;+&lt;/code&gt; writes a sign before a value that is not negative, a space writes a space there,
&lt;code&gt;0&lt;/code&gt; pads with zeros after the sign and any prefix, and &lt;code&gt;#&lt;/code&gt; asks for the alternate form: &lt;code&gt;0x&lt;/code&gt;, &lt;code&gt;0X&lt;/code&gt;
or &lt;code&gt;0b&lt;/code&gt; before a non-zero integer, a leading &lt;code&gt;0&lt;/code&gt; in octal, and a decimal point that stays in a
&lt;code&gt;real&lt;/code&gt;, with &lt;code&gt;g&lt;/code&gt;‘s trailing zeros. &lt;code&gt;0&lt;/code&gt; gives way to &lt;code&gt;-&lt;/code&gt;, and for integers to a precision. &lt;code&gt;#&lt;/code&gt; does nothing under &lt;code&gt;d&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;,&lt;/code&gt; groups the digits&lt;/strong&gt; of an integer under &lt;code&gt;d&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt;, three at a time from the right with a
comma between groups, for every width of integer and for &lt;code&gt;byte&lt;/code&gt;: &lt;code&gt;${1234567}%,d&lt;/code&gt; is &lt;code&gt;1,234,567&lt;/code&gt;,
&lt;code&gt;${-2147483648}%,d&lt;/code&gt; is &lt;code&gt;-2,147,483,648&lt;/code&gt;, and a value under a thousand has no comma. The sign comes
before the first group, and a width and &lt;code&gt;-&lt;/code&gt; pad the grouped text with spaces
(&lt;code&gt;${1234567}%,12d&lt;/code&gt; is &lt;code&gt;   1,234,567&lt;/code&gt;). The zeros a precision asks for are grouped with the
digits (&lt;code&gt;${5}%,.6d&lt;/code&gt; is &lt;code&gt;000,005&lt;/code&gt;). The zeros &lt;code&gt;0&lt;/code&gt; fills a width with are not: they come before the
grouped digits, and the commas and the sign count in the width, so the field is exactly as wide as
asked unless the number is wider (&lt;code&gt;${1234}%0,8d&lt;/code&gt; is &lt;code&gt;0001,234&lt;/code&gt;, &lt;code&gt;${-1234}%0,8d&lt;/code&gt; is &lt;code&gt;-001,234&lt;/code&gt;).
Under any other conversion the flag has no effect, which is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The width&lt;/strong&gt; is the least number of columns of a terminal the field takes, as &lt;code&gt;displayWidth&lt;/code&gt;
counts them (&lt;a href=&quot;/spec/types/#display-width&quot;&gt;Display width&lt;/a&gt;), so a CJK ideograph fills two and a
combining accent none and a column of wide text lines up: &lt;code&gt;${&amp;quot;日本&amp;quot;}%6s&lt;/code&gt; is &lt;code&gt;  日本&lt;/code&gt;. A value wider
is written whole.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The precision&lt;/strong&gt; is, for an integer, the least number of digits, so a precision of 0 writes zero as
no digits; for &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;e&lt;/code&gt; and &lt;code&gt;E&lt;/code&gt; the number of decimals, and for &lt;code&gt;g&lt;/code&gt; and &lt;code&gt;G&lt;/code&gt; of significant digits;
for &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;?&lt;/code&gt; the most characters of the value’s text that are written, whatever its type:
the value is rendered whole and its first N characters, counted as code points, fill the field,
so &lt;code&gt;${[1, 2, 3]}%.3s&lt;/code&gt; is &lt;code&gt;[1,&lt;/code&gt;, &lt;code&gt;${&amp;quot;abcdef&amp;quot;}%.2?&lt;/code&gt; is &lt;code&gt;&amp;quot;a&lt;/code&gt; and &lt;code&gt;${42}%.1?&lt;/code&gt; is &lt;code&gt;4&lt;/code&gt;. &lt;code&gt;%c&lt;/code&gt; takes none.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A width or precision may be a hole of its own&lt;/strong&gt;, counted when the program runs, written where the
digits would go: &lt;code&gt;${x}%.${n}f&lt;/code&gt;, &lt;code&gt;${s}%-${w}s&lt;/code&gt;, &lt;code&gt;${k}%0${n + 3}d&lt;/code&gt;. The count is an integer of any
width. A negative width pads on the right at its magnitude, a negative precision is as though none
were written, and a count beyond &lt;code&gt;int&lt;/code&gt; is the largest &lt;code&gt;int&lt;/code&gt;. Flags written before a counted width
still apply.&lt;/li&gt;
&lt;li&gt;Each hole, a count’s included, is evaluated once, in the order written.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;A specifier is checked while compiling&lt;/strong&gt;, against the type of the hole it follows: the conversion
is one that type takes, each flag has an effect under it, and a width or precision written as a hole
is an integer.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val n = 7
println(f&amp;quot;${n}%s&amp;quot;)       // format `%s` expects a string or another value that is not a number, but the value has type `int`
println(f&amp;quot;${n}%#d&amp;quot;)      // the flag `#` has no effect under `%d`
println(f&amp;quot;${n}%,x&amp;quot;)      // the flag `,`, which groups decimal digits, has no effect under `%x`
println(f&amp;quot;${n}%u&amp;quot;)       // `%u` is not a format conversion: integers are signed, so `%d` writes every one
println(f&amp;quot;${n}%&amp;quot;)        // this format specifier has no conversion: …
println(f&amp;quot;${2.5}%.${2.5}f&amp;quot;)  // a width or precision written as a hole is a count, so it has to be an integer, …
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value of a type that renders itself is handed what the specifier says in its &lt;code&gt;FormatSpec&lt;/code&gt;: the
width, the precision, the flags and the conversion letter, the counts of holes included.&lt;/p&gt;
&lt;h2 id=&quot;interpolators&quot;&gt;Interpolators&lt;/h2&gt;
&lt;p&gt;Every interpolated string is a method call. The text before the opening quote names a method of
&lt;code&gt;StringContext&lt;/code&gt;, the literal pieces between the holes become the context’s parts, and the holes
become the method’s arguments:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;p&amp;quot;text $a and ${b + 1}&amp;quot;
// is exactly
StringContext([&amp;quot;text &amp;quot;, &amp;quot; and &amp;quot;, &amp;quot;&amp;quot;]).p(a, b + 1)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;StringContext&lt;/code&gt; holds &lt;code&gt;parts: Vector[string]&lt;/code&gt;, always one more part than there are holes. A part
is the text as written, with its escapes unprocessed; the method decides what they mean.&lt;/li&gt;
&lt;li&gt;The call is checked like any other call: the holes must suit the method’s parameters, which may be
a fixed list or variadic (&lt;code&gt;args: Display*&lt;/code&gt;), and the method’s result is the expression’s value, of
whatever type it declares.&lt;/li&gt;
&lt;li&gt;Holes are written the same way for every interpolator: &lt;code&gt;$name&lt;/code&gt;, &lt;code&gt;${expression}&lt;/code&gt;, and &lt;code&gt;$$&lt;/code&gt; for a
dollar sign. Each hole is evaluated once, left to right.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;raw&lt;/code&gt; are ordinary methods of &lt;code&gt;StringContext&lt;/code&gt; in the core library. &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;f&lt;/code&gt;
process escapes and render each hole; &lt;code&gt;raw&lt;/code&gt; keeps the parts as written. A program may call them
directly, as &lt;code&gt;StringContext(parts).s(x)&lt;/code&gt;. Called directly, &lt;code&gt;f&lt;/code&gt; reads each specifier from the start
of the part after its hole as it runs, a counted width or precision being an &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long&lt;/code&gt;
argument of its own; there a malformed specifier, a count of another type and &lt;code&gt;%?&lt;/code&gt; (its arguments
are &lt;code&gt;Display&lt;/code&gt; values) trap, and a value under a conversion its type does not take renders in its
own form.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A program adds its own interpolator by giving &lt;code&gt;StringContext&lt;/code&gt; a method through a trait it declares
and an &lt;code&gt;impl&lt;/code&gt; of that trait. The interpolator is available wherever it is imported: in the module that
declares it, in a file that imports that module (&lt;code&gt;import sql&lt;/code&gt;), and in a file that imports one of its
declarations by name (&lt;code&gt;import sql.{Query}&lt;/code&gt;). Importing a module that itself imports &lt;code&gt;sql&lt;/code&gt; does not
bring &lt;code&gt;sql&amp;quot;…&amp;quot;&lt;/code&gt; into scope, and &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;raw&lt;/code&gt; need no import. Using an interpolator that is not
in scope is an error that names the module to import:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait SqlInterpolation
  sql(args: SqlValue*) -&amp;gt; Query

impl SqlInterpolation for StringContext
  sql(args: SqlValue*) -&amp;gt; Query = Query(parts, args)

val q = sql&amp;quot;select * from users where id = $id and name = $name&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here each hole must be a &lt;code&gt;SqlValue&lt;/code&gt;, so &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; are passed as parameters of the query, never
pasted into its text.&lt;/p&gt;
&lt;h2 id=&quot;rendering&quot;&gt;Rendering&lt;/h2&gt;
&lt;p&gt;A hole is rendered by its type’s &lt;code&gt;Display&lt;/code&gt; implementation, or by &lt;code&gt;Debug&lt;/code&gt; for &lt;code&gt;%?&lt;/code&gt;. The built-in
types display as their literals read: an integer of any width as its decimal digits with a sign when
negative, a &lt;code&gt;byte&lt;/code&gt; as its number, a &lt;code&gt;char&lt;/code&gt; as itself, a &lt;code&gt;real&lt;/code&gt; as the fewest digits that read back
as the same value, written out without an exponent (&lt;code&gt;2.5&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;0.1&lt;/code&gt;), a &lt;code&gt;bool&lt;/code&gt; as &lt;code&gt;true&lt;/code&gt; or
&lt;code&gt;false&lt;/code&gt;, &lt;code&gt;()&lt;/code&gt; as &lt;code&gt;()&lt;/code&gt;, and a string as itself. A value whose type
implements neither is a compile error. There is no fallback that prints an address. The specifier
applies to the whole rendered value.&lt;/p&gt;
&lt;p&gt;A value whose static type is &lt;code&gt;Any&lt;/code&gt; or a trait is shown by the type it has when the program runs.
&lt;code&gt;Any&lt;/code&gt; and every trait meet &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;, as every type meets &lt;code&gt;Eq&lt;/code&gt;: such a value meets a
&lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; bound, has &lt;code&gt;display&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt; and &lt;code&gt;toString()&lt;/code&gt;, and may be interpolated, whatever
the trait itself declares. It does not convert to &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; as a value: a value of either
trait holds only objects whose types implement it. It renders through its own type’s implementation, so a &lt;code&gt;Seq[int]&lt;/code&gt; holding
a vector prints &lt;code&gt;[1, 2, 3]&lt;/code&gt;, as the vector would, and a &lt;code&gt;Vector[Seq[int]]&lt;/code&gt; prints
&lt;code&gt;[[1, 2, 3], [4]]&lt;/code&gt;. A type with no &lt;code&gt;Display&lt;/code&gt; (or no &lt;code&gt;Debug&lt;/code&gt;) of its own renders as its name, &lt;code&gt;Cat&lt;/code&gt; or
&lt;code&gt;Box[int]&lt;/code&gt;, and a function value as &lt;code&gt;&amp;lt;function&amp;gt;&lt;/code&gt;, in the field the spec describes. The rule is for
values whose type is decided at run time only: a value whose static type is a class or a data type
still needs that type’s own &lt;code&gt;Display&lt;/code&gt; to be interpolated, and a type parameter its bound’s (&lt;code&gt;print&lt;/code&gt;
and &lt;code&gt;println&lt;/code&gt; take their arguments as &lt;code&gt;Any&lt;/code&gt;, so they show such a value by its name). No impl gives a trait a
&lt;code&gt;Display&lt;/code&gt; of its own; its values are always shown by their own types.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;trait Pet
  name() -&amp;gt; string

class Cat(): Pet
  override name() -&amp;gt; string = &amp;quot;cat&amp;quot;

main()
  val xs: Seq[int] = [1, 2, 3]
  val pet: Pet = Cat()
  val anything: Any = (1, &amp;quot;two&amp;quot;)
  println(s&amp;quot;$xs $pet $anything&amp;quot;) // [1, 2, 3] Cat (1, two)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The core library declares the traits:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Writer
  write(text: string)
  writeChar(c: char) = …
  writeInt(n: long) = …
  writeField(text: string, spec: FormatSpec) = …
  writeSpaces(n: long) = …

data FormatSpec(
    width: int = 0,
    precision: int = -1,
    left: bool = false,
    zeroPad: bool = false,
    plus: bool = false,
    space: bool = false,
    alternate: bool = false,
    conversion: char = &apos;s&apos;,
    grouping: bool = false
)
  withWidth[T: Integer](n: T) -&amp;gt; FormatSpec = …
  withPrecision[T: Integer](n: T) -&amp;gt; FormatSpec = …

trait Display
  display(out: Writer, spec: FormatSpec)
  toString() -&amp;gt; string = …

trait Debug
  debug(out: Writer, spec: FormatSpec)

writeDisplayed[T: Display](out: Writer, value: T, spec: FormatSpec)
writeDebugged[T: Debug](out: Writer, value: T, spec: FormatSpec)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;FormatSpec&lt;/code&gt; is the field a value fills: &lt;code&gt;width&lt;/code&gt; columns of a terminal, as &lt;code&gt;displayWidth&lt;/code&gt; counts
them, padded with spaces on the left, or on
the right when &lt;code&gt;left&lt;/code&gt;; 0 asks for no padding, and wider text is written whole. &lt;code&gt;precision&lt;/code&gt;, -1 for
none, is read by a renderer that takes one, in its own terms, under every conversion but &lt;code&gt;s&lt;/code&gt; and
&lt;code&gt;?&lt;/code&gt;. Under those two the precision is the formatter’s: &lt;code&gt;writeDisplayed(out, value, spec)&lt;/code&gt; and
&lt;code&gt;writeDebugged(out, value, spec)&lt;/code&gt;, which a formatted hole is written through, render the value
with no width and no precision, keep its first &lt;code&gt;precision&lt;/code&gt; characters and write them in the
field, so a renderer never cuts its own text. Under those two the width is the formatter’s as well:
with no precision, the value is rendered with the whole spec, and whatever it writes is padded to
the field, so a &lt;code&gt;display&lt;/code&gt; that ignores its spec, or writes no text at all, still fills &lt;code&gt;%8s&lt;/code&gt;, and
one that fills the field itself is not padded twice. &lt;code&gt;zeroPad&lt;/code&gt;, &lt;code&gt;plus&lt;/code&gt;, &lt;code&gt;space&lt;/code&gt; and
&lt;code&gt;alternate&lt;/code&gt; are the flags &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;+&lt;/code&gt;, space and &lt;code&gt;#&lt;/code&gt;, &lt;code&gt;conversion&lt;/code&gt; the letter of the specifier,
&lt;code&gt;s&lt;/code&gt; when none was written, and &lt;code&gt;grouping&lt;/code&gt; the flag &lt;code&gt;,&lt;/code&gt;, which the integers read under &lt;code&gt;d&lt;/code&gt;, &lt;code&gt;i&lt;/code&gt;
and &lt;code&gt;s&lt;/code&gt;; a renderer reads the conversions its type takes and renders its own
form under any other. &lt;code&gt;withWidth&lt;/code&gt; and &lt;code&gt;withPrecision&lt;/code&gt; set a count as a specifier’s hole does.
&lt;code&gt;writeField&lt;/code&gt; writes a text in the field a spec describes, padded with spaces, which is how most
&lt;code&gt;display&lt;/code&gt; methods end.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toString()&lt;/code&gt; renders into a &lt;code&gt;StringWriter&lt;/code&gt;, a writer building a string, and returns its &lt;code&gt;text&lt;/code&gt;.
&lt;code&gt;StandardOutput&lt;/code&gt; is the writer for standard output; it writes an integer’s digits without making
a string of them. A &lt;code&gt;StringWriter&lt;/code&gt; also answers &lt;code&gt;length&lt;/code&gt;, the number of bytes written so far (a
character of several bytes counts them all), and &lt;code&gt;isEmpty&lt;/code&gt;, and &lt;code&gt;clear()&lt;/code&gt; forgets everything
written so it is as new; a text already taken is unchanged. A &lt;code&gt;StringWriter&lt;/code&gt; is itself &lt;code&gt;Display&lt;/code&gt;:
it shows, interpolates and answers &lt;code&gt;toString()&lt;/code&gt; as its &lt;code&gt;text&lt;/code&gt;, padded to a field’s width as a
string is. &lt;code&gt;StandardError&lt;/code&gt; is the writer for standard error, which keeps no buffer.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;print&lt;/code&gt; and &lt;code&gt;println&lt;/code&gt; are each one ordinary library function, &lt;code&gt;print(values: Any*)&lt;/code&gt; and
&lt;code&gt;println(values: Any*)&lt;/code&gt;. &lt;code&gt;print&lt;/code&gt; writes its arguments to standard output separated by &lt;code&gt;, &lt;/code&gt; (they
are not a tuple), and &lt;code&gt;println&lt;/code&gt; writes them and a new line: &lt;code&gt;println(&amp;quot;total&amp;quot;, 3, (1, 2))&lt;/code&gt; writes
&lt;code&gt;total, 3, (1, 2)&lt;/code&gt;, &lt;code&gt;println(x)&lt;/code&gt; writes just &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;print()&lt;/code&gt; writes nothing and &lt;code&gt;println()&lt;/code&gt; writes
just a new line. Each argument is an &lt;code&gt;Any&lt;/code&gt;, shown as that &lt;code&gt;Any&lt;/code&gt; is shown in an interpolated string:
by its type’s own &lt;code&gt;Display&lt;/code&gt;, or by the type’s name for a type with none, so &lt;code&gt;println(pet)&lt;/code&gt; with
&lt;code&gt;pet: Pet&lt;/code&gt;, &lt;code&gt;println(xs)&lt;/code&gt; with &lt;code&gt;xs: Seq[int]&lt;/code&gt; and &lt;code&gt;println(Cat())&lt;/code&gt; for a class with no &lt;code&gt;Display&lt;/code&gt; all
print, the last as &lt;code&gt;Cat&lt;/code&gt;, and a function value as &lt;code&gt;&amp;lt;function&amp;gt;&lt;/code&gt;; &lt;code&gt;println(1, pet, xs)&lt;/code&gt; writes
&lt;code&gt;1, Cat, [1, 2, 3]&lt;/code&gt;. A sequence is one argument: &lt;code&gt;println(xs)&lt;/code&gt; prints it whole, and only &lt;code&gt;xs*&lt;/code&gt;
spreads it into the repeated parameter, where it has to be a sequence of &lt;code&gt;Any&lt;/code&gt; or of references
(&lt;code&gt;words*&lt;/code&gt; with &lt;code&gt;words: Seq[string]&lt;/code&gt;), since a number is never boxed inside a container. As a
value, &lt;code&gt;println&lt;/code&gt; is a &lt;code&gt;(Vector[Any]) -&amp;gt; unit&lt;/code&gt;. Printing costs what any &lt;code&gt;Any&lt;/code&gt; parameter does: a
number, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; or &lt;code&gt;unit&lt;/code&gt; argument is boxed, and a program that prints gives every type
record its rendering entry. &lt;code&gt;eprint&lt;/code&gt; and &lt;code&gt;eprintln&lt;/code&gt; are the same for standard error, each a single
write, so a line is never split by another writer’s. &lt;code&gt;debug(x)&lt;/code&gt; is &lt;code&gt;x&lt;/code&gt;‘s
&lt;code&gt;Debug&lt;/code&gt; form as a string, so &lt;code&gt;println(debug(x))&lt;/code&gt; prints it. Inside an implementation of &lt;code&gt;Debug&lt;/code&gt;, the
bare name &lt;code&gt;debug&lt;/code&gt; is the method, and a part is written with &lt;code&gt;part.debug(out, spec)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The built-in types’ &lt;code&gt;Debug&lt;/code&gt; forms are their &lt;code&gt;Display&lt;/code&gt; forms, except that a string and a &lt;code&gt;char&lt;/code&gt;
are written as the literals that make them: quoted, with the quote, the backslash and control
characters escaped (&lt;code&gt;&amp;quot;a\&amp;quot;b\n&amp;quot;&lt;/code&gt;, &lt;code&gt;&apos;\&apos;&apos;&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;lowering&quot;&gt;Lowering&lt;/h2&gt;
&lt;p&gt;For &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;f&lt;/code&gt;, the compiler does not call the method. It parses the specifiers while compiling and
writes the literal out to calls on one &lt;code&gt;StringWriter&lt;/code&gt; made for it, with the same result: each decoded
piece of text is written to it, each hole is rendered into it by &lt;code&gt;display&lt;/code&gt;, or by &lt;code&gt;debug&lt;/code&gt; under
&lt;code&gt;%?&lt;/code&gt;, with the &lt;code&gt;FormatSpec&lt;/code&gt; its specifier describes, a hole under &lt;code&gt;%s&lt;/code&gt; or &lt;code&gt;%?&lt;/code&gt; with a precision, or
with a width when its type is not a built-in one, through &lt;code&gt;writeDisplayed&lt;/code&gt; or &lt;code&gt;writeDebugged&lt;/code&gt;, and
the writer’s text is the value. A string hole
with no specifier is written as it is. No value is boxed to format it. Every other interpolator is
compiled as the method call it denotes.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Roadmap</title>
    <link href="https://avinlang.dev/compiler/roadmap/"/>
    <id>https://avinlang.dev/compiler/roadmap/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>The stages that build the Avin compiler, runtime and Avin-written standard library to the specification.</summary>
    <content type="html">&lt;h2 id=&quot;approach&quot;&gt;Approach&lt;/h2&gt;
&lt;p&gt;The compiler is built to the &lt;a href=&quot;/compiler/&quot;&gt;architecture&lt;/a&gt; from the first stage: every program, from
&lt;code&gt;main() = 42&lt;/code&gt; on, goes through the real pipeline — resolve, check, lower to MIR, emit — and is linked
against the real runtime. Early stages make that pipeline thin and end-to-end; later stages widen
it. No stage builds a temporary path that a later stage has to tear out.&lt;/p&gt;
&lt;h2 id=&quot;stages&quot;&gt;Stages&lt;/h2&gt;
&lt;p&gt;Each stage is one or more bounded items. Each ends green on the full gate and is merged to &lt;code&gt;dev&lt;/code&gt;
with &lt;code&gt;--ff-only&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;#&lt;/th&gt;&lt;th&gt;Stage&lt;/th&gt;&lt;th&gt;Delivers&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Specification&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;This specification, the architecture, this roadmap, the project reset&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Skeleton and test harness&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;The &lt;code&gt;compiler/&lt;/code&gt;, &lt;code&gt;runtime/&lt;/code&gt; and &lt;code&gt;library/&lt;/code&gt; packages; the lexer and parser carried over; &lt;code&gt;avin parse&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt; and &lt;code&gt;build&lt;/code&gt;; a thin end-to-end pipeline (&lt;code&gt;main() = 42&lt;/code&gt; and &lt;code&gt;println&lt;/code&gt; of a literal) through resolve, check, MIR and the LLVM emitter, linked with a minimal runtime; the Sysl-written execution-test driver in &lt;code&gt;sysl test&lt;/code&gt; (&lt;code&gt;.avin&lt;/code&gt; cases with expected output, run at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Type core and scalar programs&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;The &lt;code&gt;Type&lt;/code&gt; enum over symbols; scopes and symbol tables; local bidirectional inference with subtype constraints and &lt;code&gt;Nothing&lt;/code&gt;; integers with trapping overflow, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;; functions, local functions, &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt;/loops, guards, scalar patterns and coverage; unbounded generic functions; by-name parameters. The old execution corpus, revised to the specification, joins the suite here&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Modules and packages&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;avin.hocon&lt;/code&gt; loading, multi-file modules, imports and visibility, the prelude as an Avin file, &lt;code&gt;@intrinsic&lt;/code&gt; declarations&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Runtime and heap values&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;The collector over &lt;code&gt;sh.sysl.gc&lt;/code&gt; with shadow-stack roots; type descriptors; traps with messages and locations; &lt;code&gt;string&lt;/code&gt; as a runtime value, with &lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt; rendering the built-in types; &lt;code&gt;data&lt;/code&gt; layouts, tuples, lambdas and closures with environments; by-name parameters&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Object model&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;class&lt;/code&gt;, &lt;code&gt;trait&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;impl&lt;/code&gt;, methods, &lt;code&gt;override&lt;/code&gt;, &lt;code&gt;open&lt;/code&gt;/&lt;code&gt;abstract&lt;/code&gt;, constructors with checked initialization, companions, member access, type patterns; overloading, default and named arguments; infix method calls&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Monomorphization and dispatch&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Bounded generics, closed-world instantiation, dispatch for generic trait methods, reified headers, variance checking, devirtualization&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Sysl bindings&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;@sysl&lt;/code&gt; declarations, shim generation, the cached shim build, boundary conversions, opaque handles, diagnostics mapped back to bindings&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Core library in Avin&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Writer&lt;/code&gt;, &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, string methods, &lt;code&gt;println&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt;, &lt;code&gt;StringContext&lt;/code&gt; and interpolators, interpolation and formatting&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Collections in Avin&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterable&lt;/code&gt;/&lt;code&gt;Iterator&lt;/code&gt; (Iterator is Iterable), &lt;code&gt;Seq&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Range&lt;/code&gt;, builders, views, literals built through them, &lt;code&gt;::&lt;/code&gt;, list and sequence patterns, &lt;code&gt;for&lt;/code&gt; comprehensions&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Test runner and tooling&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;avin test&lt;/code&gt;, &lt;code&gt;avin run&lt;/code&gt;, project and package commands, &lt;code&gt;avin lsp&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;&lt;strong&gt;System library&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;avin.io&lt;/code&gt;, &lt;code&gt;avin.fs&lt;/code&gt;, &lt;code&gt;avin.process&lt;/code&gt;, &lt;code&gt;avin.time&lt;/code&gt; and the rest over Sysl bindings&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Actors and state machines&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;actor&lt;/code&gt; declarations, messages and their scheduling in the runtime; &lt;code&gt;machine&lt;/code&gt; and &lt;code&gt;state&lt;/code&gt; declarations, transitions and their checks&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;&lt;strong&gt;C bindings&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;@c&lt;/code&gt; bindings called directly from Avin’s code, checked against the library’s headers by a clang-compiled C unit; C libraries in the manifest; handles, strings, out parameters, buffers and callbacks from C threads; &lt;code&gt;avin-lang/mlt&lt;/code&gt; (MLT 7) and &lt;code&gt;avin-lang/cairo&lt;/code&gt; (Cairo 1.18) as the stressors, with &lt;code&gt;avin-lang/freetype&lt;/code&gt; (FreeType 2), which Cairo’s FreeType font faces depend on&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;14&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Lightweight threads&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Every thread a lightweight thread with a stack of its own, run by a scheduler over a few operating system threads, waits that park, time-slicing at safepoints, sockets on a poller, actors’ turns and the server library on top, as &lt;a href=&quot;/spec/decisions/&quot;&gt;settled&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Linux&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x86_64-linux&lt;/code&gt; and &lt;code&gt;aarch64-linux&lt;/code&gt; as targets, and machines in packages, by the twelve items of the &lt;a href=&quot;/compiler/linux/&quot;&gt;Linux plan&lt;/a&gt;: close-on-exec in the lookup, machine conditions in the manifest, files for one machine and &lt;code&gt;avin.target&lt;/code&gt;, the Linux image, the compiler, runtime, corpus and platform tests on Linux, the target in cache keys, Linux CI, Linux releases, and cross builds&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Until stage 8, &lt;code&gt;println&lt;/code&gt; in stage 1 was an &lt;code&gt;@intrinsic&lt;/code&gt; over a runtime entry point, declared in Avin
source like every other intrinsic; stage 8 replaced it with the library’s &lt;code&gt;println&lt;/code&gt; over &lt;code&gt;Display&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;status&quot;&gt;Status&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Stage&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;Done&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;Done&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;Done: local bindings and assignment; integer arithmetic with trapping, wrapping and saturating operators; bitwise operators and shifts; integer literals of any width, one among the branches of an &lt;code&gt;if&lt;/code&gt;, the arms of a &lt;code&gt;match&lt;/code&gt; or the elements of a collection literal taking the type the others decide; &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt; and &lt;code&gt;char&lt;/code&gt; with their operators, comparisons and conversions; comparison chains; &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, `&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;Done: a directory as a program’s root, each directory under it a module named by its path, its files sharing one namespace and headed by &lt;code&gt;module a.b&lt;/code&gt; (the root directory’s files the root module, without a header); a single file a program by itself; &lt;code&gt;import a.b.X&lt;/code&gt; and &lt;code&gt;import a.b.{X, y as z}&lt;/code&gt; per file, &lt;code&gt;import a.b&lt;/code&gt; and &lt;code&gt;import a.b as c&lt;/code&gt; binding a whole module, reached as &lt;code&gt;b.X&lt;/code&gt; for any public declaration in expressions, types and patterns, unknown, private, self-module and clashing imports rejected; &lt;code&gt;export a.b.X&lt;/code&gt;, &lt;code&gt;export a.b.{X, y as z}&lt;/code&gt; presenting another module’s public declarations (types, aliases, classes, objects, traits, machines, every overload of a function, values, variants) as names of the exporting module, the very declarations, in every file of that module and to its importers by name or through the module, chains of exports followed to the declaration, two paths to one declaration no clash, a module exporting a declaration presenting its module’s extensions, and private, unknown, whole-module, self-module, root-module, &lt;code&gt;private&lt;/code&gt;, clashing and cyclic exports rejected; &lt;a href=&quot;/spec/declarations/#exporting-members&quot;&gt;member exports&lt;/a&gt; in a class, an object or a data type’s plain impl (&lt;code&gt;export f.m&lt;/code&gt;, &lt;code&gt;export f.{m, n as k}&lt;/code&gt;, &lt;code&gt;export f.*&lt;/code&gt;, &lt;code&gt;private export&lt;/code&gt;), a use the type’s own members do not answer checked as &lt;code&gt;x.f.m&lt;/code&gt; (calls with overloads, defaults and named arguments, reads, assignments, method values, operators), through a field or a method of no parameter list read at every use, chained by name and by wildcard, an export by name implementing a trait’s method, completion and go-to-definition following the export, and unknown, untyped, private, clashing, shadowed, misplaced and cyclic exports rejected; &lt;code&gt;private&lt;/code&gt; top-level declarations, seen in every file of their module only; a file’s names resolved through its module, then its imports, then the public declarations of &lt;code&gt;avin&lt;/code&gt;, loaded from &lt;code&gt;library/&lt;/code&gt; as an ordinary module tree with the prelude one of its files; program modules named &lt;code&gt;avin&lt;/code&gt; or under it rejected; conformances checked against the module of their type or trait; an impl that only adds methods written in any module, an extension in another module than its type’s or trait’s, its methods seen by its module and by files importing the module or a declaration of it, called directly with no reach into the type’s private members, one a type’s own method always hides rejected where declared, two seen modules’ extensions of one signature rejected at the call naming both, and its private methods its module’s; companions kept to their class’s or data type’s module across files; modules importing one another in cycles, with module values initialized in dependency order across the program; object-file symbols carrying the module path; &lt;a href=&quot;/spec/packages/&quot;&gt;packages&lt;/a&gt;: &lt;code&gt;avin.hocon&lt;/code&gt; manifests read and checked with each error at its line, git dependencies fetched at their tags into the machine’s cache with the highest version asked for chosen, or pinned to a commit by &lt;code&gt;rev&lt;/code&gt; (abbreviated or full, one commit one package, two commits or a commit and a release refused), path and workspace dependencies, a dependency’s modules under their own names without its root files and tests, one module in two packages and nested manifests kept apart, &lt;code&gt;avin.sum&lt;/code&gt; checked and added to, workspaces with one selection and one sum file, and every command finding the package by walking up from its path (format details Proposed); the &lt;a href=&quot;/spec/packages/#the-standard-library-s-modules&quot;&gt;standard library’s modules&lt;/a&gt; read as a compilation needs them: the prelude, then only the library modules the program, its dependencies and the modules read import, to the end, in the library’s own order, an import of a module under &lt;code&gt;avin&lt;/code&gt; the library does not have reported at the import with the modules where it would be, and the language server reading the whole library for a library file or a completion; members of a repository (&lt;code&gt;member&lt;/code&gt; naming a directory, each member a package of its own, &lt;code&gt;&amp;lt;coordinate&amp;gt;//&amp;lt;dir&amp;gt;&lt;/code&gt;, selected and summed separately, every member at one version read from one clone whose hash its line carries, a fetched member’s &lt;code&gt;workspace = true&lt;/code&gt; and in-repository &lt;code&gt;path&lt;/code&gt; siblings read as their own coordinates at its version, its &lt;code&gt;sysl-dependencies&lt;/code&gt; reaching the program as any package’s do, and &lt;code&gt;avin add &amp;lt;coordinate&amp;gt;//&amp;lt;dir&amp;gt;&lt;/code&gt;); and &lt;code&gt;avin vendor&lt;/code&gt; copying the resolution into &lt;code&gt;vendor/&lt;/code&gt; at the project’s or workspace’s root, each copy checked against &lt;code&gt;avin.sum&lt;/code&gt; first and what is no longer read removed, a &lt;code&gt;vendor/&lt;/code&gt; present being read in place of the cache with a package it lacks refused rather than fetched, and the root’s &lt;code&gt;vendor/&lt;/code&gt; never a module.; and features: a manifest’s &lt;code&gt;features&lt;/code&gt; (&lt;code&gt;doc&lt;/code&gt;, &lt;code&gt;default&lt;/code&gt;, &lt;code&gt;modules&lt;/code&gt;, &lt;code&gt;enables&lt;/code&gt;, &lt;code&gt;requires&lt;/code&gt;, and &lt;code&gt;name = [x]&lt;/code&gt;), optional dependencies, &lt;code&gt;&amp;quot;dep:x&amp;quot;&lt;/code&gt; and &lt;code&gt;&amp;quot;dep/feature&amp;quot;&lt;/code&gt;, each error at its line, a dependency entry’s &lt;code&gt;features&lt;/code&gt;, &lt;code&gt;default_features = false&lt;/code&gt; and &lt;code&gt;-x&lt;/code&gt;, every request for a package added together across the graph, workspace members included, a module a feature that is off lists not read, an import of a gated module or an optional dependency’s module allowed only where the importer’s gate implies it whatever is selected, the package’s tests importing any of its modules with a test module read only while every module it imports is, an import refused for its module reported once however many names it imports, &lt;code&gt;--features&lt;/code&gt;, &lt;code&gt;--no-default-features&lt;/code&gt; and &lt;code&gt;--all-features&lt;/code&gt; on &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;vendor&lt;/code&gt;, and &lt;code&gt;avin test&lt;/code&gt;, &lt;code&gt;avin check&lt;/code&gt;, the language server, &lt;code&gt;avin tidy&lt;/code&gt; and &lt;code&gt;avin vendor&lt;/code&gt; with every feature on; a program of one file’s dependencies header (&lt;code&gt;// avin.hocon&lt;/code&gt; and the comment lines under it, a manifest’s &lt;code&gt;dependencies&lt;/code&gt; block), resolved, fetched and summed into &lt;code&gt;&amp;lt;file&amp;gt;.sum&lt;/code&gt; as a manifest’s are, read by &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;tidy&lt;/code&gt; and the language server, refused at its line when malformed, not at the top or in a file of a package or a program of many files, and &lt;code&gt;avin vendor&lt;/code&gt; refusing a program of one file; a first line beginning &lt;code&gt;#!&lt;/code&gt; passed over, and &lt;code&gt;avin &amp;lt;file&amp;gt; ...&lt;/code&gt; (the form a &lt;code&gt;#!/usr/bin/env avin&lt;/code&gt; line runs) for a file with one giving every argument after the file to the program, &lt;code&gt;avin run&lt;/code&gt; keeping its options&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;Done: the collector over &lt;code&gt;sh.sysl.gc&lt;/code&gt;, with exact roots on a shadow stack per thread, reached through each thread’s context, which every compiled function takes as a hidden first argument, collection when allocation since the last collection reaches what survived it, a heap limit, and the whole pages of large free runs given back to the system after a collection (gc 0.4.0, &lt;code&gt;AVIN_GC_RELEASE&lt;/code&gt;); type descriptors for &lt;code&gt;data&lt;/code&gt; variants; &lt;code&gt;data&lt;/code&gt; types, generic and recursive, with constructors, field access on one-variant types, variant patterns nested to any depth and exhaustiveness over variants; variants reached through their type, &lt;code&gt;Shape.Circle(1.0)&lt;/code&gt;, &lt;code&gt;Option[int].None&lt;/code&gt; and &lt;code&gt;m.Color.Red&lt;/code&gt;, in expressions and patterns beside the bare name, a name that is none of the type’s variants reported with the ones it has, and a variant with fields written without parentheses in a pattern reported as its bare name is; variant names shared by several data types of one module (and by machines’ states), a bare use decided by the expected type (parameter, binding, result, field, element, the other operand of a comparison, the matched value in a pattern) and refused with the types and qualified forms where nothing decides it, shared names imported or reached through their module; a nested call’s unknown settled by the call around it; functions defined by clauses, with inline guards and guard blocks; comparison patterns and &lt;code&gt;n + k&lt;/code&gt;; exhaustiveness over integers, bytes and chars by the values their literals, ranges, comparisons and &lt;code&gt;n + k&lt;/code&gt; patterns leave out; extractor patterns, &lt;code&gt;Name(p…)&lt;/code&gt; on a value whose type implements a core extractor trait, &lt;code&gt;BoolExtractor&lt;/code&gt; or &lt;code&gt;Extractor&lt;/code&gt; (an &lt;code&gt;unapply&lt;/code&gt; answering a &lt;code&gt;bool&lt;/code&gt; or an &lt;code&gt;Option&lt;/code&gt;, its value matched whole or as a tuple’s parts) or &lt;code&gt;SeqExtractor&lt;/code&gt; (an &lt;code&gt;unapplySeq&lt;/code&gt; answering an &lt;code&gt;Option&lt;/code&gt; of a sequence), the conformance and not the method’s name making the extractor, a trait’s value, a bounded type parameter, a data type’s impl and a subclass included, and a value implementing none reported with the trait to implement, the matched value held in a local and the method called once per test, nested, guarded, in &lt;code&gt;is&lt;/code&gt;, clauses and match functions and never counting toward exhaustiveness; &lt;code&gt;rest*&lt;/code&gt; and &lt;code&gt;_*&lt;/code&gt; ending a sequence pattern or an &lt;code&gt;unapplySeq&lt;/code&gt; extractor’s patterns, a list’s tail or what &lt;code&gt;drop&lt;/code&gt; answers, with exhaustiveness over every sequence type by the lengths its sequence patterns cover; tuples, made on the heap like a one-variant &lt;code&gt;data&lt;/code&gt; value, with parts read by position, tuple patterns, tuples without parentheses where they fill a line, destructuring bindings and multiple assignment; strings as references to constant objects or heap objects, joined with &lt;code&gt;+&lt;/code&gt;, compared by their bytes, and matched by literal patterns; &lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt; interpolation of the built-in types, lowered directly to rendering and joining; function types, and functions as values: lambdas, with parameter types written or taken from the expected function type, a lambda of &lt;em&gt;n&lt;/em&gt; parameters taking apart the &lt;em&gt;n&lt;/em&gt;-tuple a function of one parameter expects (an overload that needs it chosen only where none takes the lambda as written), and named, local, generic and intrinsic functions; closures that hold copies of the values they capture and share the &lt;code&gt;var&lt;/code&gt;s, which a closure’s capture moves into a box on the heap; calls of function values through each closure’s entry; closure identity with &lt;code&gt;===&lt;/code&gt;; by-name parameters, each argument a closure with no parameters evaluated at every read, forwarded unevaluated to another by-name parameter, with the mode part of a function’s type; traps that flush the output and print &lt;code&gt;avin: trap: &amp;lt;reason&amp;gt; at &amp;lt;file&amp;gt;:&amp;lt;line&amp;gt;:&amp;lt;col&amp;gt;&lt;/code&gt;, each trap site constant data with its own cold block, shared by every instance of a generic. A delayed argument that cannot escape still keeps its environment on the heap rather than the caller’s stack. The thread runtime: contexts attached and detached by each thread, a gc chunk held by each thread’s carrier, which its context points at, so that small objects are allocated with no lock (gc 0.3.1), one lock around claiming chunks, collection and the lists of contexts and carriers, stop-the-world collection with each other thread parked at a safepoint or in a safe region, and safepoint polls on every back edge and before every call that may recur, found from the call graph’s strongly connected components; programs start threads through &lt;code&gt;avin.threads&lt;/code&gt; (stage 11)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;Done: &lt;a href=&quot;/spec/declarations/#functions&quot;&gt;&lt;code&gt;def&lt;/code&gt;&lt;/a&gt;, a keyword optional before every function and method declaration (after the modifiers, on the signature of one defined by clauses), and the one way to declare a top-level or local function with no parameter list, &lt;code&gt;def now -&amp;gt; int = …&lt;/code&gt; or &lt;code&gt;def now = …&lt;/code&gt;, read by its bare name and run again at each read, with no function value, no type parameters and no assignment, the parentheses after it calling what it yields, the only function of its name in its scope, read through its module as &lt;code&gt;clock.now&lt;/code&gt;, and the declaration written without &lt;code&gt;def&lt;/code&gt; refused naming it; default and named arguments, each default a function of the parameters before it, declared beside its function and checked in the function’s declaration scope, called at each call that omits the argument; named arguments after positional ones, in any order, with the written arguments evaluated in the order written and then the defaults in parameter order; named fields for variants; defaults of by-name parameters delayed. Repeated parameters (&lt;code&gt;values: T*&lt;/code&gt;), a &lt;code&gt;Vector[T]&lt;/code&gt; inside the function, made at the call through the core library’s vector builder from the positional arguments from its position on, or one &lt;code&gt;Iterable[T]&lt;/code&gt; spliced with &lt;code&gt;xs*&lt;/code&gt; (a vector of that type passed as it is), on functions, local functions, clauses, methods, impl methods and class constructors, generic element types inferred from the arguments, an overload without one preferred, and the core library’s &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; over them. Final classes with constructor parameters as fields (plain private and immutable, &lt;code&gt;val&lt;/code&gt; public, &lt;code&gt;var&lt;/code&gt; public and mutable, &lt;code&gt;private var&lt;/code&gt;); the class body as the constructor, running statements and field initializers top to bottom; body fields with declared or inferred types; methods in every function form, clauses and type parameters of their own included, with the implicit receiver and &lt;code&gt;self&lt;/code&gt;; member access, assignment, compound assignment and &lt;code&gt;++&lt;/code&gt;/&lt;code&gt;--&lt;/code&gt; on fields; privacy per class; generic classes, their type arguments inferred or written; the constructor as a function value, and a data variant with fields as one too (bare, qualified or with type arguments, typed from the expected function type, a companion’s &lt;code&gt;apply&lt;/code&gt; and the variant chosen between as at a call); &lt;code&gt;===&lt;/code&gt; on objects, and &lt;code&gt;==&lt;/code&gt;/&lt;code&gt;!=&lt;/code&gt; on class instances, objects and closures comparing identities (rejected between types with no common class); a field read in the body before its declaration rejected. Overloading of top-level and local functions, resolved statically to the most specific overload that accepts a call, with literals and lambdas tried against each candidate, generic overloads compared by the same rule, an overloaded function value chosen by its expected type, and each overload a symbol of its own named by its parameter types. &lt;code&gt;object&lt;/code&gt; singletons, made before &lt;code&gt;main&lt;/code&gt;, with fields, methods and privacy as a class’s, passed as values of their own types; companions, the class’s name in call position its constructor and otherwise the companion, each using the other’s private members; companions of &lt;code&gt;data&lt;/code&gt; types, of one variant or several, a variant of the type’s name its constructor in call position and the type’s impls and the companion each using the other’s private members, an object named after another type’s variant or a fieldless variant of its own type’s name rejected; an object’s &lt;code&gt;apply&lt;/code&gt; methods called by its name, a companion’s overloading the class’s constructor or the data type’s variant of its name by the ordinary rules (by-name, defaults, repeated parameters, generics, trailing blocks, written type arguments the chosen candidate’s), one with the constructor’s parameter types rejected where declared, and the name where a function type is expected the constructor or &lt;code&gt;apply&lt;/code&gt; that type chooses; module-level &lt;code&gt;val&lt;/code&gt;s and &lt;code&gt;var&lt;/code&gt;s; every global initialized before &lt;code&gt;main&lt;/code&gt; after what its initializer reads through the functions it calls and the lambdas it makes, with a cycle reported by its chain; globals that hold references kept as roots of every collection. Class inheritance: &lt;code&gt;open&lt;/code&gt; and &lt;code&gt;abstract&lt;/code&gt; classes, one superclass after &lt;code&gt;:&lt;/code&gt; with its constructor arguments (generic ones with written type arguments), construction from the top down through each class’s initializer, inherited fields leading the subclass’s, &lt;code&gt;override&lt;/code&gt; checked against parameter types with covariant results, abstract methods, &lt;code&gt;super.m()&lt;/code&gt;, subclass instances conforming to their superclasses (arguments, tuples, &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt; joins, &lt;code&gt;===&lt;/code&gt;), and virtual dispatch through a method table placed before each class instance’s descriptor. Traits: abstract methods and default bodies, required traits, generic traits with written type arguments, classes and objects conforming after the superclass in the &lt;code&gt;:&lt;/code&gt; list and subclasses inheriting the conformance, &lt;code&gt;override&lt;/code&gt; on every implementation, two inherited implementations of one name rejected unless overridden, trait-typed values as plain references (arguments, tuples, &lt;code&gt;var&lt;/code&gt;s, &lt;code&gt;===&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt; branches agreeing on an expected trait), and dispatch through a position each trait has in every conforming class’s method table, chosen once for the whole program; a trait’s variance is checked and used in stage 6. &lt;code&gt;Any&lt;/code&gt;: every value converts to it where it is written (arguments, bindings, assignments, fields, results, tuple parts written out, branches), boxed where it is not already an object, with &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt; rejected on it; type patterns &lt;code&gt;x: T&lt;/code&gt; and &lt;code&gt;_: T&lt;/code&gt; in &lt;code&gt;match&lt;/code&gt;, clauses and &lt;code&gt;is&lt;/code&gt;, matching built-ins, strings, tuples, &lt;code&gt;data&lt;/code&gt; types, classes (subclasses before superclasses) and traits, generic instances told apart by their type arguments, downcasts from a trait’s or an open class’s type, never-matching patterns rejected, and coverage counting only a pattern whose type the value already has; each type a record of its ancestors, tested by one comparison or a scan of the ancestors (&lt;code&gt;==&lt;/code&gt; on &lt;code&gt;Any&lt;/code&gt; came with stage 8). &lt;code&gt;impl&lt;/code&gt;: methods added to &lt;code&gt;data&lt;/code&gt; types, classes, objects and built-in types (&lt;code&gt;impl string&lt;/code&gt;, in the core library’s module), with the implicit receiver, &lt;code&gt;self&lt;/code&gt; and a one-variant type’s fields by bare name, and private impl methods; &lt;code&gt;impl Trait for Type&lt;/code&gt; for data types, classes and objects, its methods implementing without &lt;code&gt;override&lt;/code&gt;, a conformance stated once whether in a header or an impl; generic impls naming the type’s parameters (&lt;code&gt;impl[T] Source[T] for Box[T]&lt;/code&gt;); data types dispatching through a method table every variant’s descriptor carries, fieldless variants included, and matched by &lt;code&gt;t: Trait&lt;/code&gt; patterns on &lt;code&gt;Any&lt;/code&gt;. Methods as values: a method named without a call, on a value or by bare name inside its class or impl, a closure holding the receiver, evaluated once where the value is made, of the method’s type without the receiver; for class, &lt;code&gt;object&lt;/code&gt;, trait, open-class (calling the override through the method table) and impl methods, built-in types’ included, generic classes’ with type arguments from the receiver, and a method’s own type parameters written or taken from the expected type; private methods only where they could be called. The initialization check, run once every body is checked: through a class’s or object’s last field initializer, &lt;code&gt;self&lt;/code&gt; only reads set fields and assigns fields, with method calls (bare, &lt;code&gt;self.m()&lt;/code&gt;, &lt;code&gt;super.m()&lt;/code&gt;), method values, &lt;code&gt;self&lt;/code&gt; passed, stored or returned, and lambdas, by-name arguments and local functions that use it rejected; an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class’s whole body held to the same limits, calling after its last field only methods that cannot be overridden and are safe, found by a fixed point over every method’s body. Overloaded methods in classes, objects, traits and impls, built-in types’ included: a call chooses among the methods of its name the receiver’s static type has, inherited and trait methods included, by the rules for functions, with the class’s type arguments known from the receiver; each overload a symbol of its own and a method table position of its own, overriding, trait implementation and dispatch matched by name and parameter types; an overloaded method used as a value chosen by its expected type; two abstract overloads in a row parsed as two declarations rather than clauses. Infix method calls: &lt;code&gt;a m b&lt;/code&gt; is the call &lt;code&gt;a.m(b)&lt;/code&gt;, resolved as the dotted call (overloads, dispatch, impl methods, generic methods), binding between ranges and comparisons and grouping left, continued onto an indented block only after a line ending with the method’s name; a postfix use, a method of another arity, a name that is not a method of the receiver’s type and a name starting a later line rejected with the dotted form to write. Trailing blocks: an indented block after a call’s line given to the callee’s last parameter, as a by-name parameter’s delayed expression or as the body of a lambda whose parameters end the line, past defaulted parameters, with named arguments and in overload resolution, on functions, methods and function values, a callee with no other arguments written without parentheses; never in the header of a form whose body follows, nor where a local function’s header or an infix continuation already reads the block; a last parameter that is neither by-name nor a function, already given or absent rejected. Methods named by symbols: an operator the longest run of operator characters, any run that is not the language’s own a method’s name, declared in classes, traits, objects and impls and called infix or dotted, binding at the level of the operator its first character belongs to, or tightest with a &lt;code&gt;~&lt;/code&gt; anywhere in it, a name ending in &lt;code&gt;:&lt;/code&gt; grouping right with its receiver on the right and its left operand evaluated first, left- and right-grouping operators of one level mixed without parentheses rejected (comparisons and &lt;code&gt;is&lt;/code&gt; among them); a &lt;a href=&quot;/spec/operators-and-control-flow/#a-declared-precedence&quot;&gt;declared precedence&lt;/a&gt;, `@precedence(“&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;Done: declared variance on the type parameters of data types, classes and traits. An instance of a generic type is one of another instance where each type argument follows its parameter’s variance and both arguments are references (&lt;code&gt;List[Dog]&lt;/code&gt; is a &lt;code&gt;List[Animal]&lt;/code&gt;, &lt;code&gt;List[int]&lt;/code&gt; is not a &lt;code&gt;List[Any]&lt;/code&gt;), through superclasses and traits with their arguments substituted; tuple parts are covariant and function types take contravariant parameters and covariant results on the same terms; two branches agree on the instance whose covariant arguments agree. Declarations are checked: a &lt;code&gt;+T&lt;/code&gt; only in method results, immutable fields and parents’ covariant arguments, a &lt;code&gt;-T&lt;/code&gt; only in method parameters, neither in a mutable field, with positions flipping through function parameters and following other types’ variance; private members included, and the methods an impl adds to an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class, which are in its method table (&lt;code&gt;Vector&lt;/code&gt;‘s &lt;code&gt;:+&lt;/code&gt;, &lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;updated&lt;/code&gt; and &lt;code&gt;toArray&lt;/code&gt; taking a lower-bounded &lt;code&gt;W &amp;gt;: T&lt;/code&gt;). Type patterns match through variance: each record lists, besides its ancestors, the tested types it conforms to by variance. Bounded type parameters, &lt;code&gt;[T: A &amp;amp; B]&lt;/code&gt;, on functions, methods, classes, data types and traits, each bound a trait or a class, at most one a class, none written twice, &lt;code&gt;&amp;amp;&lt;/code&gt; the one spelling (&lt;code&gt;+&lt;/code&gt; between bounds and &lt;code&gt;A &amp;amp; B&lt;/code&gt; written as a type each rejected with the form to write): a bounded value has its bounds’ methods (required traits’ included), trait &lt;code&gt;val&lt;/code&gt;s and a class bound’s fields, with overloads, defaults, infix calls, own type arguments and method values, and passes as its bounds’ types; type arguments held to their bounds where written in declarations and at calls, with a bound’s own type arguments inferred from the argument; each instance calling its type argument’s implementation directly, through the method table only for a trait type or an open class; a method’s own bounds checked as contravariant positions. A function’s or a method’s own type parameter bounded by a type parameter declared before it, &lt;code&gt;[J: I]&lt;/code&gt;, at most one: a &lt;code&gt;J&lt;/code&gt; is an &lt;code&gt;I&lt;/code&gt; with no conversion and has &lt;code&gt;I&lt;/code&gt;‘s bounds, each type argument is held to be the bounding one’s or seen as it as a covariant part is, one decided where a value is passed in takes the bounding argument where that is the narrower (`err&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;Done: top-level functions bound with &lt;code&gt;@sysl(&amp;quot;module.name&amp;quot;)&lt;/code&gt;, their parameters and results integers of 8, 16, 32 and 64 bits, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;Array[byte]&lt;/code&gt; (copied each way), &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;Vector&lt;/code&gt; of the other boundary types (copied element by element, into Sysl as a slice and out of a slice or a &lt;code&gt;Buf&lt;/code&gt; into a new array or vector, nested to any depth), an &lt;code&gt;Array&lt;/code&gt; of bytes, integers, reals, booleans or characters as a binding’s own parameter filled by the Sysl function (copied into a writable slice and back after the call, the shim keeping the array as a root meanwhile), every other array going in as a &lt;code&gt;[]const&lt;/code&gt; slice so that a Sysl type that would write into it is refused at the binding, &lt;code&gt;Option&lt;/code&gt; and &lt;code&gt;Result&lt;/code&gt; of boundary types, tuples of boundary types (a Sysl tuple of the same arity, converted part by part, nested in the other shapes and in mirrors’ fields), and &lt;code&gt;data&lt;/code&gt; declared with &lt;code&gt;@sysl(&amp;quot;module.Name&amp;quot;)&lt;/code&gt; mirroring a Sysl enum or struct; integer results, mirrors’ integer fields and the integers a result’s options, results, collections and tuples hold converted from any Sysl integer, with a check that stops the program at the binding’s call where a value does not fit; a &lt;code&gt;real&lt;/code&gt; rounded into any Sysl floating-point type (&lt;code&gt;f32&lt;/code&gt;, &lt;code&gt;f16&lt;/code&gt;, &lt;code&gt;bf16&lt;/code&gt;) as a parameter, a mirror’s field or a callback’s answer, and widened out of any as a result, a field, a callback’s parameter or a value a result holds; a generated Sysl shim per binding that converts each value and calls the Sysl function at the binding’s types, passing the arguments by position or, for a binding marked &lt;code&gt;named&lt;/code&gt;, by each parameter’s name, so the parameters it leaves out take the Sysl function’s own defaults, with one conversion per data type and direction, built with the runtime by &lt;code&gt;sysl build-c&lt;/code&gt; into one archive the program links in place of the runtime’s; Sysl’s diagnostics of a shim reported at the binding, or at the mirror for its import and conversions; the archive cached by a hash of the shims, the Sysl version and the runtime’s source; bindings to Sysl packages other than the standard library, which a manifest names in &lt;code&gt;sysl-dependencies&lt;/code&gt; (by release, commit or directory, gathered over the whole package graph, the cache keyed by each one’s release, commit or directory sources, and the C libraries they name with &lt;code&gt;@link&lt;/code&gt; or require through &lt;code&gt;pkg_config&lt;/code&gt; linked into the program); &lt;code&gt;Array[byte]&lt;/code&gt; results out of a Sysl &lt;code&gt;[]u8&lt;/code&gt; or &lt;code&gt;[]const u8&lt;/code&gt;; opaque handles, classes declared with &lt;code&gt;@sysl(&amp;quot;module.Type&amp;quot;)&lt;/code&gt;, on a Sysl struct, a trait or an instance of a generic one (&lt;code&gt;@sysl(&amp;quot;module.Signal[string]&amp;quot;)&lt;/code&gt;, its type arguments boundary types that are one Sysl type each), whose objects hold one counted Sysl reference in an untraced word (a trait object’s two words in a cell that word points at), made by the bindings that return one directly, in an &lt;code&gt;Array&lt;/code&gt;, a &lt;code&gt;Vector&lt;/code&gt;, an &lt;code&gt;Option&lt;/code&gt; or a &lt;code&gt;Result&lt;/code&gt;, or as a part of a tuple that is one of these (a collection out of a Sysl slice or &lt;code&gt;Buf&lt;/code&gt;, each element a handle of its own), passed back to Sysl as a parameter of a binding or of a handle’s method (shared as the counted reference where the Sysl type has a destructor, otherwise as the Sysl parameter takes it) or as the elements of an &lt;code&gt;Array&lt;/code&gt; or a &lt;code&gt;Vector&lt;/code&gt; that is one (each checked as a handle passed by itself is, and shared for the call as a slice of what the Sysl parameter takes) or as a mirror’s field by itself (passed and checked as a parameter is, and out of Sysl made a handle of its own), with methods without a body bound to the Sysl type’s methods (a view they answer converted before any local holds it), methods with a body written over them, &lt;code&gt;close()&lt;/code&gt; giving the reference back, a bound method on a closed handle or a closed handle passed as a parameter or a mirror’s field trapping at the call, and a finalizer per handle class, named in its descriptor, giving back the reference of an object the collector frees unclosed; each handle owned by the code that made it, a second word of its object compared with the context’s owner word at every use (a bound method, a handle passed as a parameter, &lt;code&gt;close()&lt;/code&gt;), trapping “&lt;code&gt;Name&lt;/code&gt; belongs to another thread” where it differs and the handle is not in transit, ownership handed by the runtime’s walk of what a thread’s body or a pool task reaches, its own owner whichever worker runs it, and put in transit when the body returns, by a future’s completion and by a callback’s registration; bindings and handle methods declared &lt;code&gt;blocking&lt;/code&gt;, whose shim converts the arguments and takes each handle’s own counted reference, makes the Sysl call with the thread safe for the collector, and converts the result once it is running again, a view of bytes copied before it leaves; Avin functions passed to a binding’s parameter of function type (a lambda, a closure, a method value, a top-level or local function), handed to Sysl as a closure the shim makes, which keeps the function a root while Sysl holds it and gives it back when Sysl drops it, converts each argument out of Sysl and the answer into it, and runs the function through an entry the program defines with the C convention, on the calling thread: the giver’s code only, or any thread for a parameter marked &lt;code&gt;@threaded&lt;/code&gt; (whose function is held to capturing only sendable &lt;code&gt;val&lt;/code&gt;s and parameters, a value of a &lt;code&gt;@sendable&lt;/code&gt; function type and a parameter marked &lt;code&gt;@sendable&lt;/code&gt; taken as they are, and whose binding is blocking whether or not it says so), a thread Sysl started attached for the call, a thread in a blocking call made running for it, a call from elsewhere trapping. A callback’s integer answer is converted, with a check that stops the program at the binding’s call, into whatever integer the closure Sysl takes answers, an unsigned one included (a Sysl &lt;code&gt;&amp;amp;Fn() -&amp;gt; u32&lt;/code&gt; takes an Avin &lt;code&gt;() -&amp;gt; long&lt;/code&gt;); a closure answering a generic Sysl function’s type parameter answers the Avin type, the shims built once more where Sysl could not infer one. A binding’s integer parameter, and a handle method’s, is converted the same way into whatever integer the Sysl parameter is, an unsigned one included (syslui’s colours, &lt;code&gt;u32&lt;/code&gt;), a blocking call converting it while the thread is safe; a parameter of a generic Sysl function’s type parameter, and every integer parameter of a call that left a type argument uninferred, passed as the Avin type; values narrower than 32 bits passed and answered sign- or zero-extended as the C convention says. Generic bindings: a binding’s type parameters bounded by &lt;code&gt;Boundary&lt;/code&gt;, the core library’s structural bound for the types that cross as one Sysl type each (integers of 8 to 64 bits, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, mirrors, and options, results and tuples of these), held at each call and passed on through a generic function’s own bounded type parameter, every type parameter that is not so bounded refused where it would cross, with one shim per instantiation that Sysl checks at its types (a Sysl bound’s refusal reported at the binding); generic handle classes, &lt;code&gt;@sysl(&amp;quot;m.Signal&amp;quot;) class Signal[T: Boundary]&lt;/code&gt;, a handle with its own finalizer on each instance the program uses, mirrors among its type arguments, with bound methods at every instance and methods with type parameters of their own; and a callback whose closure takes a type parameter of the Sysl function given its parameters’ types by the shim, which is built again for as long as each build finds more to say.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;In progress: &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and the right-biased &lt;code&gt;Either&lt;/code&gt; (with &lt;code&gt;Either.cond&lt;/code&gt;, and &lt;code&gt;Option.toRight&lt;/code&gt;/&lt;code&gt;toLeft&lt;/code&gt;/&lt;code&gt;okOr&lt;/code&gt;/&lt;code&gt;okOrElse&lt;/code&gt;, and &lt;code&gt;Result.toOption&lt;/code&gt; beside &lt;code&gt;ok&lt;/code&gt;) in the core library, written in Avin, with their methods, lower-bounded where the reference library’s are (&lt;code&gt;getOrElse[B &amp;gt;: T]&lt;/code&gt;, &lt;code&gt;orElse&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;, Either’s &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;filterOrElse&lt;/code&gt;, Result’s &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;orElse&lt;/code&gt;); &lt;code&gt;?&lt;/code&gt; on either, returning &lt;code&gt;None&lt;/code&gt; or the &lt;code&gt;Err&lt;/code&gt; from the enclosing function or lambda, where the error passed on must conform to the function’s error type. String methods in &lt;code&gt;impl string&lt;/code&gt;, in &lt;code&gt;library/avin/string.avin&lt;/code&gt;: &lt;code&gt;byteLength&lt;/code&gt;, &lt;code&gt;charCount&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;startsWith&lt;/code&gt;, &lt;code&gt;endsWith&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;toUpper&lt;/code&gt;, &lt;code&gt;toLower&lt;/code&gt; (the names &lt;code&gt;char&lt;/code&gt; has for its own), &lt;code&gt;trim&lt;/code&gt;, &lt;code&gt;strip&lt;/code&gt;, &lt;code&gt;stripLeading&lt;/code&gt;, &lt;code&gt;stripTrailing&lt;/code&gt;, &lt;code&gt;repeat&lt;/code&gt;, &lt;code&gt;replace&lt;/code&gt;, &lt;code&gt;padTo&lt;/code&gt;, &lt;code&gt;stripPrefix&lt;/code&gt;, &lt;code&gt;stripSuffix&lt;/code&gt;, &lt;code&gt;capitalize&lt;/code&gt;, &lt;code&gt;stripMargin&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;lastIndexOf&lt;/code&gt; (of a string or a &lt;code&gt;char&lt;/code&gt;), &lt;code&gt;indexWhere&lt;/code&gt; and &lt;code&gt;lastIndexWhere&lt;/code&gt; (an offset, -1 when there is none), &lt;code&gt;toInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toReal&lt;/code&gt; (trapping on a string that writes no number) and &lt;code&gt;toIntOption&lt;/code&gt;, &lt;code&gt;toLongOption&lt;/code&gt; and &lt;code&gt;toRealOption&lt;/code&gt; (answering with &lt;code&gt;Option&lt;/code&gt;), the character-wise methods (&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterNot&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt;, &lt;code&gt;dropWhile&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;, &lt;code&gt;partition&lt;/code&gt;, &lt;code&gt;splitAt&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt; and the lazy &lt;code&gt;charIterator&lt;/code&gt;), &lt;code&gt;split&lt;/code&gt; by a &lt;code&gt;char&lt;/code&gt; and with a limit, &lt;code&gt;stripLineEnd&lt;/code&gt;, &lt;code&gt;compareIgnoreCase&lt;/code&gt;, &lt;code&gt;toInt&lt;/code&gt; and &lt;code&gt;toLong&lt;/code&gt; (and their &lt;code&gt;Option&lt;/code&gt; forms) in a radix from 2 to 36, and &lt;code&gt;toBool&lt;/code&gt; and &lt;code&gt;toBoolOption&lt;/code&gt;, written in Avin over intrinsic methods (the length word, a checked byte load, and the runtime’s slicing, repeating and searching, each lowered at its call so a trap reports the caller’s line) and Sysl bindings for casing, replacing and Unicode white space; &lt;code&gt;string.fromUtf8&lt;/code&gt;, answering with a &lt;code&gt;Result&lt;/code&gt; whose &lt;code&gt;Utf8Error(offset, truncated)&lt;/code&gt; mirrors Sysl’s, and &lt;code&gt;string.fromUtf8Lossy&lt;/code&gt;, both bound to Sysl’s UTF-8 decoders; &lt;code&gt;chars()&lt;/code&gt; and &lt;code&gt;bytes()&lt;/code&gt; as vectors, &lt;code&gt;utf8&lt;/code&gt; as a new byte array, &lt;code&gt;split&lt;/code&gt; and &lt;code&gt;lines&lt;/code&gt;; a &lt;code&gt;length&lt;/code&gt; or &lt;code&gt;size&lt;/code&gt; asked of a string answered with an error naming &lt;code&gt;charCount&lt;/code&gt; and &lt;code&gt;byteLength&lt;/code&gt;, and &lt;code&gt;*&lt;/code&gt; between a string and an integer with one naming &lt;code&gt;repeat&lt;/code&gt;; a string capped at the largest &lt;code&gt;int&lt;/code&gt; bytes; the core library’s functions compiled only as a program reaches them. &lt;code&gt;Writer&lt;/code&gt;, &lt;code&gt;FormatSpec&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; as library traits in &lt;code&gt;format.avin&lt;/code&gt;; &lt;code&gt;print&lt;/code&gt; of any value and &lt;code&gt;debug&lt;/code&gt; over &lt;code&gt;Debug&lt;/code&gt;, both library functions; &lt;code&gt;toString()&lt;/code&gt; as &lt;code&gt;Display&lt;/code&gt;‘s default body; &lt;code&gt;StandardOutput&lt;/code&gt;, writing integers without a string, and &lt;code&gt;StringWriter&lt;/code&gt;, growing its text in place; the built-in types (every integer width, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;) implementing both, a value too wide for &lt;code&gt;long&lt;/code&gt; rendered in chunks of eighteen digits, honouring a field’s width and side, strings and chars quoted and escaped by &lt;code&gt;Debug&lt;/code&gt;; built-in types conforming to any trait through an impl, as bounds, each instance calling the impl’s method directly, every method of the trait implemented since a built-in takes no default bodies; &lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt; holes of any &lt;code&gt;Display&lt;/code&gt; type, type parameters bounded by it included, rendered through &lt;code&gt;toString()&lt;/code&gt;, and a hole of any other type rejected; defaults of variant fields; abstract methods yielding &lt;code&gt;unit&lt;/code&gt; written as bare signatures in traits and classes. &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord: Eq&lt;/code&gt; and &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Sub&lt;/code&gt;, &lt;code&gt;Mul&lt;/code&gt;, &lt;code&gt;Div&lt;/code&gt;, &lt;code&gt;Rem&lt;/code&gt;, &lt;code&gt;Neg&lt;/code&gt; as library traits, the built-in types implementing those their operators have; the closed core trait &lt;code&gt;Integer&lt;/code&gt;, whose members are every &lt;code&gt;iN&lt;/code&gt; and which nothing implements or names as a parent, requiring the arithmetic traits, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;, implemented for every width at once by the core library’s impls over the integer family (&lt;code&gt;impl[T: Integer] Ord for T&lt;/code&gt;, allowed only there), each width’s instance calling the family’s method directly and its operators the machine’s; a parameter bounded by &lt;code&gt;Integer&lt;/code&gt; converted to and from the other integer types (&lt;code&gt;long(x)&lt;/code&gt;, &lt;code&gt;T(n)&lt;/code&gt;), each instance converting at its width; operators on data types, classes and type parameters through them, &lt;code&gt;&amp;lt;&lt;/code&gt; and the rest defaulting from &lt;code&gt;compare&lt;/code&gt;; every type comparing and hashing, by value (tuples and data types field by field, through a function made per instance), by identity, or through its own &lt;code&gt;equals&lt;/code&gt; and &lt;code&gt;hash&lt;/code&gt;, a type implementing one of them implementing both; &lt;code&gt;==&lt;/code&gt; and the hash on &lt;code&gt;Any&lt;/code&gt;, trait-typed values and open classes decided at run time through equality entries in each type record. Values of &lt;code&gt;Any&lt;/code&gt; and of every trait are &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; (as bounds, as receivers of &lt;code&gt;display&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt; and &lt;code&gt;toString()&lt;/code&gt; and in interpolation, as every type is &lt;code&gt;Eq&lt;/code&gt;, without being values of either trait), shown by the type they have at run time through rendering entries in each type record: the type’s own implementation, or its name for a type with none. &lt;code&gt;derives Eq, Hash, Ord, Display, Debug&lt;/code&gt; on classes (over the constructor parameters, &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; together, &lt;code&gt;Ord&lt;/code&gt; beside an &lt;code&gt;Eq&lt;/code&gt;) and data types (&lt;code&gt;Ord&lt;/code&gt; by variant and then by field), a generic type’s &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; conditional on its type arguments, written out as methods and impls before anything is declared, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; as &lt;code&gt;Name(a, b)&lt;/code&gt; through each field’s own form and padded whole to a width; each field held to the derived trait and named when it falls short; a trait derived and also implemented, unknown or repeated rejected; &lt;code&gt;equals&lt;/code&gt; and &lt;code&gt;hash&lt;/code&gt; called on values of any type parameter. Derivation through shapes: &lt;code&gt;derive Trait for T&lt;/code&gt; templates in a trait’s module, checked once as an impl over &lt;code&gt;T&lt;/code&gt; bounded by the trait and &lt;code&gt;Shaped&lt;/code&gt; (a bound nothing else may write), and copied for each &lt;code&gt;derives&lt;/code&gt; entry naming the trait, its &lt;code&gt;T&lt;/code&gt; the deriving type, its names resolving in the trait’s module and its errors reported once, at the template, or at the entry; every data type and class deriving through a template or carrying annotations given its type, variant and field shapes as private module values made before &lt;code&gt;main&lt;/code&gt;; &lt;code&gt;T.shape()&lt;/code&gt;, &lt;code&gt;T.variantOf(x)&lt;/code&gt;, &lt;code&gt;T.walk(x, v)&lt;/code&gt;, &lt;code&gt;T.walkPair(a, b, v)&lt;/code&gt; and &lt;code&gt;T.build(b)&lt;/code&gt; written for the deriving type’s variants and fields, checked in its file, calling the visitor’s or builder’s &lt;code&gt;field&lt;/code&gt; (and &lt;code&gt;missing&lt;/code&gt;) hook once per field at its own type, directly, each field held to the hook’s bound and named at the &lt;code&gt;derives&lt;/code&gt; entry when it falls short; &lt;code&gt;build&lt;/code&gt; reading fields in any order, defaults seeing the fields before them, &lt;code&gt;duplicate&lt;/code&gt; and &lt;code&gt;missing&lt;/code&gt; from the builder, an index out of range a trap, refused for open and abstract classes; generic types bounded by the trait, recursive types, classes over their constructor parameters; annotations on types, classes, variants, fields and class parameters as values of types implementing &lt;code&gt;Annotation&lt;/code&gt;, an unknown name an error. Every data type’s &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; without &lt;code&gt;derives&lt;/code&gt;, conditional on its type arguments, replaced by an impl of its own (so &lt;code&gt;Option&lt;/code&gt; and &lt;code&gt;Result&lt;/code&gt; show as their variants and the collections keep their own forms), a type whose field lacks the trait left without it and a use needing it naming the field; a data type’s trait implementations compiled only when called and a method table position filled only once a call goes through it, so a program that never shows a value carries no rendering code. &lt;code&gt;derives Enumerable&lt;/code&gt; through the core library’s template, for a data type whose variants have no fields: &lt;code&gt;T.values()&lt;/code&gt; as a &lt;code&gt;Vector&lt;/code&gt; in declaration order, &lt;code&gt;ordinal()&lt;/code&gt;, &lt;code&gt;name()&lt;/code&gt; (the declared name, whatever &lt;code&gt;Display&lt;/code&gt; writes) and &lt;code&gt;T.valueOf(name)&lt;/code&gt; answering an &lt;code&gt;Option&lt;/code&gt;, reachable through an &lt;code&gt;E: Enumerable&lt;/code&gt; bound; a variant with fields, a type parameter or a class refused at the &lt;code&gt;derives&lt;/code&gt; entry. Tuples are &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt; and &lt;code&gt;Ord&lt;/code&gt; where their parts are, through core impls over each tuple family, &lt;code&gt;impl[A0: Ord, A1: Ord] Ord for (A0, A1)&lt;/code&gt;, written by the compiler for every arity from two up to the widest tuple the program writes, a tuple meeting one where its parts meet the impl’s bounds: &lt;code&gt;(a, b)&lt;/code&gt; through each part’s own form and padded whole, ordered part by part, with &lt;code&gt;&amp;lt;&lt;/code&gt; and the rest. Built-in values, strings and tuples as values of the traits they implement, converted where a trait is expected as to &lt;code&gt;Any&lt;/code&gt; (a number, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; and &lt;code&gt;unit&lt;/code&gt; boxed, its box’s descriptor holding the type’s method table through entries that read the value out; a string and a tuple as they are), so a call through the trait, &lt;code&gt;==&lt;/code&gt; and a type pattern reach the value’s own type, and an &lt;code&gt;Any&lt;/code&gt; matches a trait its value implements; every string, literal or made at run time, has the program’s descriptor for strings, with the type record of &lt;code&gt;string&lt;/code&gt; and its table; overloads taking a trait accept such values, one taking the value’s own type the more specific; &lt;code&gt;print&lt;/code&gt;, &lt;code&gt;println&lt;/code&gt;, &lt;code&gt;eprint&lt;/code&gt; and &lt;code&gt;eprintln&lt;/code&gt; of any value, &lt;code&gt;Any&lt;/code&gt;, trait-typed and types with no &lt;code&gt;Display&lt;/code&gt; of their own included, one or several separated by &lt;code&gt;, &lt;/code&gt;, each shown as interpolation shows it; an integer literal fitting an &lt;code&gt;Any&lt;/code&gt; parameter of an overloaded function. An interpolated string &lt;code&gt;p&amp;quot;…&amp;quot;&lt;/code&gt; is the call &lt;code&gt;StringContext(parts).p(holes)&lt;/code&gt;, with the parts as written (&lt;code&gt;library/avin/string_context.avin&lt;/code&gt;); &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;raw&lt;/code&gt; are its methods, and a program adds an interpolator with a trait and its impl for &lt;code&gt;StringContext&lt;/code&gt;. Text blocks, &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; … &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;, plain and after every interpolator’s name: the incidental indentation and each line’s trailing blanks dropped in the lexer, &lt;code&gt;\&lt;/code&gt; at a line’s end joining lines where escapes are read, and the formatter writing each block back byte for byte. &lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt; and &lt;code&gt;f&amp;quot;…&amp;quot;&lt;/code&gt; are written out directly to &lt;code&gt;Writer&lt;/code&gt; calls into one &lt;code&gt;StringWriter&lt;/code&gt;, each hole rendered by its &lt;code&gt;Display&lt;/code&gt;, or its &lt;code&gt;Debug&lt;/code&gt; under &lt;code&gt;%?&lt;/code&gt;, with no value boxed; &lt;code&gt;f&amp;quot;…&amp;quot;&lt;/code&gt; specifiers (flags &lt;code&gt;- + space 0 #&lt;/code&gt;, and &lt;code&gt;,&lt;/code&gt; grouping a decimal integer’s digits in threes, a width and a precision in digits or as holes counted when the program runs, conversions &lt;code&gt;d i x X o b f e g E G c s ?&lt;/code&gt;) are parsed and checked against the hole’s type as the literal is compiled, and &lt;code&gt;StringContext.f&lt;/code&gt; reads them as it runs; &lt;code&gt;FormatSpec&lt;/code&gt; carries the flags and the conversion, integers of every width format in every base in Avin and reals through the runtime’s exact formatter. &lt;code&gt;?&lt;/code&gt; converting an error through &lt;code&gt;From&lt;/code&gt;, a core trait with one static member, &lt;code&gt;from&lt;/code&gt;: the enclosing function’s error type’s conformance at the error’s type, or the one most specific at a type the error is a value of, a type parameter’s through its bounds, and its absence or several equally specific named in the error. A generic trait whose members are all static implemented by one type at several type arguments, by impls and in a class’s header, for data types, classes and built-in types, each conformance held to every member at its own type arguments; a call on the type picking the member by its parameter types, and through a type parameter bounded by several instances, the instance whose member the arguments fit, each instance of the code calling its type argument’s member for it. &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt; and &lt;code&gt;Result&lt;/code&gt; are &lt;code&gt;Ord&lt;/code&gt; where their parts are (&lt;code&gt;None&lt;/code&gt; before every &lt;code&gt;Some&lt;/code&gt;, every &lt;code&gt;Left&lt;/code&gt; and &lt;code&gt;Err&lt;/code&gt; before every &lt;code&gt;Right&lt;/code&gt; and &lt;code&gt;Ok&lt;/code&gt;, two on one side by their values), so they sort, have &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt;, key a &lt;code&gt;TreeMap&lt;/code&gt; and sit in a derived &lt;code&gt;Ord&lt;/code&gt;. Options of classes and strings kept as bare pointers when an &lt;code&gt;Option[Nothing]&lt;/code&gt; reaches one nested inside another value (a &lt;code&gt;Vector[Option[Nothing]]&lt;/code&gt; used as a &lt;code&gt;Vector[Option[Dog]]&lt;/code&gt;, a &lt;code&gt;Result[Option[Nothing], E]&lt;/code&gt;, a function yielding one, and through options, tuples, data fields and map values): &lt;code&gt;Option[Nothing]&lt;/code&gt; takes the form of the options it is seen as there, null beside pointers and an object beside objects; a program seeing it inside other values both ways, or as an option of a type parameter, stores every option as a full object (correct, slower). Done, the core of &lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt; (settled 2026-11-09), tested to &lt;a href=&quot;#union-types-the-test-matrix&quot;&gt;its matrix&lt;/a&gt;: the union type in annotations and aliases with its precedence beside &lt;code&gt;-&amp;gt;&lt;/code&gt;, the parenthesized type-pattern form, and `&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;Done: the collections’ pure accessors are &lt;a href=&quot;/spec/collections/#methods-every-iterable-has&quot;&gt;parameterless methods&lt;/a&gt; (&lt;code&gt;xs.head&lt;/code&gt;, &lt;code&gt;xs.size&lt;/code&gt;, &lt;code&gt;m.keys&lt;/code&gt;, &lt;code&gt;xs.toVector&lt;/code&gt;), with &lt;code&gt;iterator()&lt;/code&gt;, &lt;code&gt;toArray()&lt;/code&gt; and &lt;code&gt;toBuffer()&lt;/code&gt; keeping their parentheses, and so are the rest of the library’s pure accessors (&lt;a href=&quot;/spec/declarations/#parameterless-methods&quot;&gt;the rule&lt;/a&gt;: &lt;code&gt;opt.get&lt;/code&gt;, &lt;code&gt;r.isOk&lt;/code&gt;, &lt;code&gt;s.trim&lt;/code&gt;, &lt;code&gt;c.isDigit&lt;/code&gt;, &lt;code&gt;n.abs&lt;/code&gt;, &lt;code&gt;date.year&lt;/code&gt;, &lt;code&gt;T.values&lt;/code&gt; through a type parameter); &lt;code&gt;Iterable[+A]&lt;/code&gt; and &lt;code&gt;Iterator[+A]&lt;/code&gt; (&lt;code&gt;hasNext&lt;/code&gt;, &lt;code&gt;next&lt;/code&gt;, an iterator its own &lt;code&gt;iterator()&lt;/code&gt;; &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt; and their &lt;code&gt;Option&lt;/code&gt; forms on every &lt;code&gt;Iterable&lt;/code&gt;, a sequence and a sorted collection reaching the end at once) in the core library; &lt;code&gt;Array[T]&lt;/code&gt;, invariant, its elements stored unboxed at their own widths after the length, traced element by element when they are references, made by &lt;code&gt;Array.fill&lt;/code&gt;, &lt;code&gt;Array.tabulate&lt;/code&gt; and &lt;code&gt;Array.empty&lt;/code&gt; with every element set, with &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; (bounds-checked, trapping at the caller), &lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;copy&lt;/code&gt;, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt; and an iterator, &lt;code&gt;==&lt;/code&gt; and the hash by contents (&lt;code&gt;===&lt;/code&gt; identity) and &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; as &lt;code&gt;[1, 2, 3]&lt;/code&gt; where the elements have them; &lt;code&gt;xs(i)&lt;/code&gt; through &lt;code&gt;apply&lt;/code&gt; on any type that has one, and &lt;code&gt;xs(i) = v&lt;/code&gt;, its compound and &lt;code&gt;:=&lt;/code&gt; forms and &lt;code&gt;++&lt;/code&gt;/&lt;code&gt;--&lt;/code&gt; through &lt;code&gt;update&lt;/code&gt;; &lt;code&gt;Range&lt;/code&gt; of &lt;code&gt;int&lt;/code&gt; from &lt;code&gt;a..b&lt;/code&gt; and &lt;code&gt;a..&amp;lt;b&lt;/code&gt; values, with &lt;code&gt;by&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt; and an iterator, a zero step trapping; &lt;code&gt;for&lt;/code&gt; over a range written in place (any integer type, counted with no allocation), a &lt;code&gt;Range&lt;/code&gt; value, an array (indexed) and any &lt;code&gt;Iterable&lt;/code&gt; (through its iterator), with patterns, &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt;, and several generators, &lt;code&gt;if&lt;/code&gt; guards and value definitions written out as the loops they nest into; &lt;code&gt;Nothing&lt;/code&gt; written as a type. &lt;code&gt;List[+T]&lt;/code&gt; in the core library, &lt;code&gt;Cons(first, rest)&lt;/code&gt; or &lt;code&gt;Nil&lt;/code&gt;: &lt;code&gt;x :: xs&lt;/code&gt;, right-associative between the bitwise operators and ranges, always the core library’s &lt;code&gt;Cons&lt;/code&gt; with its element type inferred as the variant’s call infers it; &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;[a, b]&lt;/code&gt; built as a list where a &lt;code&gt;List&lt;/code&gt; is expected; &lt;code&gt;head :: tail&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;[a, b]&lt;/code&gt; patterns, mixing (&lt;code&gt;a :: [b, c]&lt;/code&gt;), nested, in &lt;code&gt;match&lt;/code&gt;, clauses and every pattern position, covered as the variants they stand for; &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;foldLeft&lt;/code&gt;, &lt;code&gt;foldRight&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;toArray&lt;/code&gt; and an iterator, every one a loop, so a million-element list needs no deeper stack; &lt;code&gt;==&lt;/code&gt; and the hash by contents and lexicographic &lt;code&gt;Ord&lt;/code&gt;, each a loop; &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; as arrays have them. The &lt;code&gt;Builder&lt;/code&gt; trait, with &lt;code&gt;clear&lt;/code&gt;, &lt;code&gt;sizeHint&lt;/code&gt; and &lt;code&gt;knownSize&lt;/code&gt;. Immutable &lt;code&gt;Map[K, +V]&lt;/code&gt; and &lt;code&gt;Set[A]&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt; types over a persistent binary trie of spread hashes, lookups a loop and updates copying one path: &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; (trapping), &lt;code&gt;getOrElse&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;updated&lt;/code&gt; and &lt;code&gt;incl&lt;/code&gt;, &lt;code&gt;removed&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;mapValues&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;subsetOf&lt;/code&gt;, iteration as &lt;code&gt;Iterable&lt;/code&gt;s, &lt;code&gt;Map.empty&lt;/code&gt;, &lt;code&gt;Map.newBuilder&lt;/code&gt;, &lt;code&gt;Set.empty&lt;/code&gt; and &lt;code&gt;Set.newBuilder&lt;/code&gt; in their companions, each builder typed as a &lt;code&gt;Builder&lt;/code&gt; of its collection so a literal’s expected type settles its bounded type arguments. Mutable &lt;code&gt;Map[K, V]&lt;/code&gt; and &lt;code&gt;Set[A]&lt;/code&gt; in &lt;code&gt;avin.collections.mutable&lt;/code&gt;, open-addressed tables probed linearly with backward-shift removal: &lt;code&gt;m(k) = v&lt;/code&gt; and its compound forms, &lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;getOrElseUpdate&lt;/code&gt;, &lt;code&gt;clear&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;, &lt;code&gt;copy&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;toMap&lt;/code&gt; and &lt;code&gt;toSet&lt;/code&gt;. All four compare and hash by contents and display as &lt;code&gt;{a: 1}&lt;/code&gt; and &lt;code&gt;{1, 2}&lt;/code&gt;, their &lt;code&gt;Debug&lt;/code&gt; as &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;, where the parts have them. A &lt;code&gt;newBuilder[T]()&lt;/code&gt; in the companions of &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;List&lt;/code&gt; (with &lt;code&gt;List.empty&lt;/code&gt;), the list’s adding in constant time. &lt;code&gt;List(1, 2, 3)&lt;/code&gt;, &lt;code&gt;Set(…)&lt;/code&gt; and &lt;code&gt;Map((k, v), …)&lt;/code&gt; through their companions’ &lt;code&gt;apply&lt;/code&gt;. &lt;code&gt;Buffer[T]&lt;/code&gt;, growable and mutable over an array whose spare capacity is zero bytes never read, doubling when full: &lt;code&gt;addOne&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt; and &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;, &lt;code&gt;appendAll&lt;/code&gt; and &lt;code&gt;++=&lt;/code&gt;, &lt;code&gt;prepend&lt;/code&gt;, &lt;code&gt;prependAll&lt;/code&gt;, &lt;code&gt;insert&lt;/code&gt;, &lt;code&gt;insertAll&lt;/code&gt;, &lt;code&gt;sizeHint&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt; (clearing the vacated element), &lt;code&gt;clear&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt;, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;toArray&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, an iterator, &lt;code&gt;==&lt;/code&gt; and the hash by contents, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; as arrays have them. &lt;code&gt;Vector[+T]&lt;/code&gt;, immutable, covariant and persistent: a radix-balanced tree of read-only &lt;code&gt;FrozenArray&lt;/code&gt;s of 32, with a prefix and a suffix at every level of six depth classes, each array exactly sized and never written once in the tree; &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;updated&lt;/code&gt; (one path copied) in time in the depth, &lt;code&gt;:+&lt;/code&gt; and &lt;code&gt;+:&lt;/code&gt; in amortized constant time, &lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeRight&lt;/code&gt;, &lt;code&gt;dropRight&lt;/code&gt;, &lt;code&gt;splitAt&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt; and &lt;code&gt;init&lt;/code&gt; in time in the depth through one slicer that shares every array it does not cut, &lt;code&gt;++&lt;/code&gt; in time in the shorter operand, a builder making each array once, leaf-walking iterators forwards and backwards, and &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;foldLeft&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;toArray&lt;/code&gt;, &lt;code&gt;toBuffer&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt; and the hash by contents, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;; crossing to Sysl, a vector is read a leaf at a time and made from an array through the core library’s functions, their addresses passed to the shim with the layouts. &lt;code&gt;ArraySeq[+T]&lt;/code&gt;, the immutable sequence over one &lt;code&gt;FrozenArray&lt;/code&gt;, each change a copy, with &lt;code&gt;toArraySeq&lt;/code&gt; on every collection. &lt;code&gt;mkString(sep)&lt;/code&gt; and &lt;code&gt;mkString(start, sep, end)&lt;/code&gt; on every sequence, set and map (a map’s entries as pairs, through &lt;code&gt;Iterable&lt;/code&gt;‘s) of &lt;code&gt;Display&lt;/code&gt; elements, and &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; (trapping when empty) and &lt;code&gt;maxOption&lt;/code&gt; and &lt;code&gt;minOption&lt;/code&gt; on every sequence of &lt;code&gt;Ord&lt;/code&gt; elements, each through an impl bounding the element type. The methods an impl adds to a class whose fields are all immutable are not variance positions. Every trap inside the core library, &lt;code&gt;fail&lt;/code&gt; and failed checks alike, reports the program’s call that last entered the library, through the context’s caller site: set by the program’s calls that may enter the library (direct, through a method table or of a function value), kept by the library across its calls that may run the program’s code, at no cost to calls between the program’s own functions. Sequence literals: a &lt;code&gt;List&lt;/code&gt; where one is expected, the expected collection’s &lt;code&gt;newBuilder()&lt;/code&gt; where it implements the core trait &lt;code&gt;Buildable&lt;/code&gt; itself (every library collection, the program’s own through an impl, a type parameter bounded by it), an expected collection without it reported by the trait’s name, and otherwise the core library’s &lt;code&gt;Vector&lt;/code&gt;; elements take the expected element type, or agree on one as &lt;code&gt;if&lt;/code&gt; branches do; an empty literal settled by a later use or reported; a literal compared with &lt;code&gt;==&lt;/code&gt; or an ordering takes the other operand’s type. &lt;code&gt;Seq[+T]&lt;/code&gt;, the core trait of &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt; and &lt;code&gt;Deque&lt;/code&gt;: &lt;code&gt;length&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; abstract, and &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;foldLeft&lt;/code&gt;, &lt;code&gt;foldRight&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;indexWhere&lt;/code&gt;, &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;, an iterator and &lt;code&gt;reverseIterator&lt;/code&gt; written once over them, a list overriding each with a walk; &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; written once on &lt;code&gt;Seq&lt;/code&gt; through impls on the trait. Sorting, every sort one stable bottom-up merge sort over insertion-sorted runs of 16 with one scratch array: &lt;code&gt;sorted()&lt;/code&gt;, &lt;code&gt;sortBy(key)&lt;/code&gt; (the key computed once per element) and &lt;code&gt;sortWith(compare)&lt;/code&gt; on every &lt;code&gt;Seq&lt;/code&gt; answering a &lt;code&gt;Vector&lt;/code&gt;, a list’s own answering a &lt;code&gt;List&lt;/code&gt;, and &lt;code&gt;sortInPlace()&lt;/code&gt;, &lt;code&gt;sortInPlaceBy&lt;/code&gt; and &lt;code&gt;sortInPlaceWith&lt;/code&gt; in place on arrays, buffers and deques, with &lt;code&gt;sortedDescending&lt;/code&gt; and &lt;code&gt;sortInPlaceDescending()&lt;/code&gt; for &lt;code&gt;Ord&lt;/code&gt; elements; the other in-place operations: &lt;code&gt;remove(i, n)&lt;/code&gt;, &lt;code&gt;trimStart&lt;/code&gt;, &lt;code&gt;trimEnd&lt;/code&gt;, &lt;code&gt;filterInPlace&lt;/code&gt;, &lt;code&gt;mapInPlace&lt;/code&gt;, &lt;code&gt;patchInPlace&lt;/code&gt;, &lt;code&gt;reverseInPlace&lt;/code&gt; and, for &lt;code&gt;Eq&lt;/code&gt; elements, &lt;code&gt;subtractOne&lt;/code&gt; on buffers and deques (the wrap-around of a deque’s ring checked against a buffer for every start and length), &lt;code&gt;reverseInPlace&lt;/code&gt;, &lt;code&gt;mapInPlace&lt;/code&gt;, &lt;code&gt;fillInPlace&lt;/code&gt; and an overlap-safe &lt;code&gt;copyTo&lt;/code&gt; on arrays, and &lt;code&gt;length()&lt;/code&gt;, &lt;code&gt;isEmpty()&lt;/code&gt; and &lt;code&gt;clear()&lt;/code&gt; on &lt;code&gt;StringWriter&lt;/code&gt;. Function types as parents: a class or trait lists one after &lt;code&gt;:&lt;/code&gt;, a data type or class names one in an impl, checked for an &lt;code&gt;apply&lt;/code&gt; of that signature, for one function type per type and for variance; every &lt;code&gt;Seq[T]&lt;/code&gt; is an &lt;code&gt;(int) -&amp;gt; T&lt;/code&gt;, every &lt;code&gt;Set[A]&lt;/code&gt; an &lt;code&gt;(A) -&amp;gt; bool&lt;/code&gt;, every &lt;code&gt;Map[K, V]&lt;/code&gt; a &lt;code&gt;(K) -&amp;gt; V&lt;/code&gt;, immutable and mutable, and every &lt;code&gt;PartialFunction[A, B]&lt;/code&gt; an &lt;code&gt;A -&amp;gt; B&lt;/code&gt;, with no conversion, a call of a function value running its descriptor’s call entry, a closure’s code or the type’s &lt;code&gt;apply&lt;/code&gt;. Sequence patterns (&lt;code&gt;[]&lt;/code&gt;, &lt;code&gt;[a, b]&lt;/code&gt;, nested, with literals and ranges) on every &lt;code&gt;Seq&lt;/code&gt;, reading the length once and each tested element by index, in &lt;code&gt;match&lt;/code&gt;, clauses and &lt;code&gt;is&lt;/code&gt;. &lt;code&gt;Deque[T]&lt;/code&gt;, a ring over an array doubling when full: &lt;code&gt;prepend&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt; (and &lt;code&gt;addOne&lt;/code&gt;), &lt;code&gt;removeHead&lt;/code&gt; and &lt;code&gt;removeLast&lt;/code&gt; (trapping when empty), &lt;code&gt;prependAll&lt;/code&gt;, &lt;code&gt;appendAll&lt;/code&gt;, &lt;code&gt;insert&lt;/code&gt; and &lt;code&gt;insertAll&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt;, &lt;code&gt;clear&lt;/code&gt;, &lt;code&gt;toArray&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt; and the hash by contents, &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt; and &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;Deque.empty&lt;/code&gt;, &lt;code&gt;Deque.newBuilder&lt;/code&gt; and literals. &lt;code&gt;for&lt;/code&gt; with &lt;code&gt;yield&lt;/code&gt;: generators separated by commas or one to a line in a block, each with &lt;code&gt;if&lt;/code&gt; guards, &lt;code&gt;yield&lt;/code&gt; on the &lt;code&gt;for&lt;/code&gt; line, on a line indented under it or after the block, checked as &lt;code&gt;withFilter&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; calls on the sources, so the first source decides the result and any type with those methods works; &lt;code&gt;withFilter&lt;/code&gt; a lazy view on lists, vectors, arrays, buffers, deques, sets, maps (entries as pairs) and ranges, &lt;code&gt;Option&lt;/code&gt;‘s its &lt;code&gt;filter&lt;/code&gt;; &lt;code&gt;flatMap&lt;/code&gt; on the library’s collections taking any &lt;code&gt;Iterable&lt;/code&gt;; &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; added to arrays, buffers and deques, to ranges (yielding vectors), &lt;code&gt;flatMap&lt;/code&gt; to vectors and sets, and maps’ &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; over pairs; generator patterns matching every element; &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and &lt;code&gt;?&lt;/code&gt; rejected inside one; value definitions, &lt;code&gt;pattern = value&lt;/code&gt; with their own guards, after any generator, evaluated once per element, a &lt;code&gt;val&lt;/code&gt; beside the element where no guard follows and otherwise paired with the element through &lt;code&gt;map&lt;/code&gt; for the guard to see, a rebound name or a leading definition reported; the mutable &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; given &lt;code&gt;withFilter&lt;/code&gt; views and the map a &lt;code&gt;map&lt;/code&gt; over pairs, so a comprehension over any mutable collection makes a new one of its kind. &lt;code&gt;match&lt;/code&gt; functions: a &lt;code&gt;match&lt;/code&gt; with nothing before it, one arm on its line or an indented block, a lambda over its arms where a function of one parameter is expected, its arms covering every value, and where a &lt;code&gt;PartialFunction&lt;/code&gt; is expected the core library’s &lt;code&gt;MatchPartialFunction&lt;/code&gt;, its arms partial, one lambda testing them for &lt;code&gt;isDefinedAt&lt;/code&gt; and one yielding &lt;code&gt;Some&lt;/code&gt; of the matching arm’s value for calls, &lt;code&gt;lift&lt;/code&gt; and &lt;code&gt;applyOrElse&lt;/code&gt;; &lt;code&gt;PartialFunction[-A, +B]&lt;/code&gt; with &lt;code&gt;isDefinedAt&lt;/code&gt;, a call trapping at the program’s call outside its domain, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;applyOrElse&lt;/code&gt; and &lt;code&gt;orElse&lt;/code&gt;; &lt;code&gt;collect&lt;/code&gt; on lists, vectors, arrays, buffers, deques, ranges (yielding vectors), sets, maps (entries as pairs) and options, and &lt;code&gt;collectFirst&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt;; a &lt;code&gt;match&lt;/code&gt; that misses values naming one of them as a pattern. A companion &lt;code&gt;from(xs)&lt;/code&gt; on every immutable and mutable collection (&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;HashSet&lt;/code&gt;, &lt;code&gt;TreeSet&lt;/code&gt;, &lt;code&gt;OrderedSet&lt;/code&gt;, &lt;code&gt;BitSet&lt;/code&gt;, &lt;code&gt;HashMap&lt;/code&gt;, &lt;code&gt;TreeMap&lt;/code&gt;, &lt;code&gt;OrderedMap&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;PriorityQueue&lt;/code&gt; and the mutable maps and sets), &lt;code&gt;Vector.iterate&lt;/code&gt;, &lt;code&gt;Vector.unfold&lt;/code&gt; and &lt;code&gt;List.unfold&lt;/code&gt;, and &lt;code&gt;toSortedSet&lt;/code&gt; and &lt;code&gt;toSortedMap&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt; of ordered elements or pairs. &lt;code&gt;OrderedMap[K, +V]&lt;/code&gt; and &lt;code&gt;OrderedSet[A]&lt;/code&gt; (traits &lt;code&gt;SeqMap&lt;/code&gt; and &lt;code&gt;SeqSet&lt;/code&gt;), the immutable maps and sets that iterate in insertion order, over a hash trie from key to slot and a vector of slots compacted when gaps outnumber the entries. &lt;code&gt;TreeMap[K: Ord, +V]&lt;/code&gt; and &lt;code&gt;TreeSet[A: Ord]&lt;/code&gt; in the core library, over a persistent tree balanced by weight, each side at most three times the other, lookups a loop and updates copying one path with its rotations: every method &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; have with the same traits, iteration in ascending key order, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;firstKey&lt;/code&gt;, &lt;code&gt;lastKey&lt;/code&gt;, &lt;code&gt;minAfter&lt;/code&gt;, &lt;code&gt;maxBefore&lt;/code&gt;, &lt;code&gt;rangeFrom&lt;/code&gt;, &lt;code&gt;rangeTo&lt;/code&gt;, &lt;code&gt;rangeUntil&lt;/code&gt;, &lt;code&gt;range&lt;/code&gt;, &lt;code&gt;iteratorFrom&lt;/code&gt; and &lt;code&gt;reverseIterator&lt;/code&gt;, the slices made by splitting and rejoining the tree, &lt;code&gt;filter&lt;/code&gt; by rejoining its kept parts, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; into tree collections of &lt;code&gt;Ord&lt;/code&gt; keys, a hash equal to the hash-based collection’s of the same contents, &lt;code&gt;empty&lt;/code&gt;, &lt;code&gt;newBuilder&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; and literals. &lt;code&gt;BitSet&lt;/code&gt;, an immutable &lt;code&gt;SortedSet[int]&lt;/code&gt; over words of 64 bits (&lt;code&gt;library/avin/bit_set.avin&lt;/code&gt;), with the set algebra a word at a time, &lt;code&gt;toBitMask&lt;/code&gt;, &lt;code&gt;BitSet.fromBitMask&lt;/code&gt;, and a negative element trapping on &lt;code&gt;incl&lt;/code&gt;; and the mutable &lt;code&gt;avin.collections.mutable.BitSet&lt;/code&gt; with &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;, the compound assignments and the in-place algebra &lt;code&gt;unionInPlace&lt;/code&gt;, &lt;code&gt;intersectInPlace&lt;/code&gt;, &lt;code&gt;diffInPlace&lt;/code&gt; and &lt;code&gt;symmetricDiffInPlace&lt;/code&gt;. The mutable &lt;code&gt;avin.collections.mutable.TreeMap&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt;, holding an immutable tree and replacing it at each update, with the mutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; API, the ordered queries, &lt;code&gt;removeFirst&lt;/code&gt;, &lt;code&gt;removeLast&lt;/code&gt; and their &lt;code&gt;Option&lt;/code&gt; forms, and iteration that goes on over the collection as it was when the loop began. &lt;code&gt;Map[K, +V]&lt;/code&gt; and &lt;code&gt;Set[A]&lt;/code&gt; traits, with the hash-based &lt;code&gt;HashMap&lt;/code&gt; and &lt;code&gt;HashSet&lt;/code&gt; and the tree collections conforming through &lt;code&gt;SortedMap&lt;/code&gt; and &lt;code&gt;SortedSet&lt;/code&gt;, which re-declare the updating methods with sorted results: the methods putting a value in take &lt;code&gt;[W &amp;gt;: V]&lt;/code&gt;, an update through a trait answers the same kind, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; through a trait answer hash-based collections, literals, &lt;code&gt;Map(…)&lt;/code&gt;, &lt;code&gt;Set(…)&lt;/code&gt;, &lt;code&gt;empty&lt;/code&gt; and &lt;code&gt;newBuilder&lt;/code&gt; make the hash-based ones and the sorted traits’ companions and literals tree ones, and maps and sets of different kinds with equal contents are equal (through the traits and &lt;code&gt;Any&lt;/code&gt;, by the library’s &lt;code&gt;anyCollectionEquals&lt;/code&gt;) and hash alike. &lt;code&gt;==&lt;/code&gt; and the hash written once on &lt;code&gt;Seq&lt;/code&gt;: two sequences of one element type, of any kinds (&lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, &lt;code&gt;Range&lt;/code&gt;, a program’s own), are equal when their elements are equal in order and hash alike, a comparison between two kinds checked and lowered as the library’s &lt;code&gt;seqEquals&lt;/code&gt; at the element type, a &lt;code&gt;Seq&lt;/code&gt;-typed value and an abstract &lt;code&gt;Vector&lt;/code&gt; included, and the per-type comparisons and hashes removed. &lt;code&gt;Range&lt;/code&gt; of &lt;code&gt;int&lt;/code&gt; a &lt;code&gt;Seq[int]&lt;/code&gt;: &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt; and their &lt;code&gt;Option&lt;/code&gt; forms answered from its bounds in constant time, a length beyond &lt;code&gt;int&lt;/code&gt; trapping while its ends and indices are still answered, and every method written once on &lt;code&gt;Seq&lt;/code&gt;, sequence patterns, &lt;code&gt;==&lt;/code&gt; and the hash working on it. Views: &lt;code&gt;view()&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt;, a lazy iterator over the collection, and &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;withFilter&lt;/code&gt; added to &lt;code&gt;Iterator&lt;/code&gt; beside its lazy &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt; and &lt;code&gt;dropWhile&lt;/code&gt;, with &lt;code&gt;zip&lt;/code&gt; taking any collection, so a view composes element by element, computes nothing until read, stops reading at what it was asked for and is forced by the conversions; a comprehension over an iterator is an iterator; &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;length&lt;/code&gt; on an &lt;code&gt;Iterator&lt;/code&gt; count the elements remaining and use it up. &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt; (&lt;code&gt;-1&lt;/code&gt; when the count needs a traversal) and &lt;code&gt;sizeCompare(n)&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt;, overridable so the answer through &lt;code&gt;Iterable[T]&lt;/code&gt; is the collection’s own, counting by iteration by default, and &lt;code&gt;size&lt;/code&gt; beside &lt;code&gt;length&lt;/code&gt; on every sequence. Set and map literals: &lt;code&gt;{a, b}&lt;/code&gt; a &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;{k: v}&lt;/code&gt; a &lt;code&gt;Map&lt;/code&gt; unless the expected type names another collection, built through that collection’s &lt;code&gt;Buildable&lt;/code&gt; conformance (&lt;code&gt;TreeSet&lt;/code&gt;, &lt;code&gt;TreeMap&lt;/code&gt;, the mutable ones, a program’s own), &lt;code&gt;{}&lt;/code&gt; the empty one expected. &lt;code&gt;NumericRange[T: Integer]&lt;/code&gt;, the range of any integer type other than &lt;code&gt;int&lt;/code&gt;, made by &lt;code&gt;a..b&lt;/code&gt; and &lt;code&gt;a..&amp;lt;b&lt;/code&gt; where the bounds are integers of that type (a literal bound taking the other’s type, bounds of two types rejected) with a step of type &lt;code&gt;T&lt;/code&gt;: a &lt;code&gt;Seq[T]&lt;/code&gt; whose &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;isEmpty&lt;/code&gt; are answered from its bounds in constant time at any width without wrapping, whose iteration never passes either end of the type, and whose &lt;code&gt;length&lt;/code&gt; traps beyond &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; and &lt;code&gt;length&lt;/code&gt; for a span beyond &lt;code&gt;long&lt;/code&gt;. Nothing is still to come for ranges. &lt;code&gt;object Iterator&lt;/code&gt; (&lt;code&gt;empty&lt;/code&gt;, &lt;code&gt;single&lt;/code&gt;, &lt;code&gt;iterate&lt;/code&gt;, &lt;code&gt;unfold&lt;/code&gt;, &lt;code&gt;continually&lt;/code&gt;, &lt;code&gt;from&lt;/code&gt; over any integer type, &lt;code&gt;fill&lt;/code&gt;, &lt;code&gt;tabulate&lt;/code&gt;), each computing an element when it is read; an iterator’s lazy &lt;code&gt;++&lt;/code&gt;/&lt;code&gt;concat&lt;/code&gt;, &lt;code&gt;scanLeft&lt;/code&gt;, &lt;code&gt;grouped&lt;/code&gt;, &lt;code&gt;sliding&lt;/code&gt;, &lt;code&gt;distinct&lt;/code&gt;, &lt;code&gt;distinctBy&lt;/code&gt;, &lt;code&gt;zipAll&lt;/code&gt;, &lt;code&gt;padTo&lt;/code&gt;, &lt;code&gt;tapEach&lt;/code&gt;, &lt;code&gt;flatten&lt;/code&gt; of an iterator of collections, and &lt;code&gt;buffered()&lt;/code&gt; answering a &lt;code&gt;BufferedIterator&lt;/code&gt; with &lt;code&gt;peek()&lt;/code&gt;/&lt;code&gt;peekOption()&lt;/code&gt;; on every &lt;code&gt;Iterable&lt;/code&gt;, the eager &lt;code&gt;scanLeft&lt;/code&gt;, &lt;code&gt;tapEach&lt;/code&gt;, &lt;code&gt;partitionMap&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;, &lt;code&gt;grouped&lt;/code&gt;/&lt;code&gt;sliding&lt;/code&gt; (through the iterator’s), &lt;code&gt;concat&lt;/code&gt; and &lt;code&gt;flatten&lt;/code&gt; of a collection of collections, answering vectors. &lt;code&gt;avin.collections.mutable.LinkedMap[K, V]&lt;/code&gt; and &lt;code&gt;LinkedSet[A]&lt;/code&gt;, the mutable map and set that iterate in insertion order, with the whole mutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; API, &lt;code&gt;putLast&lt;/code&gt;, &lt;code&gt;moveToEnd&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;removeFirst&lt;/code&gt; and &lt;code&gt;removeLast&lt;/code&gt; (the last two trapping when empty), safe removal during iteration, and the same display, equality and hash. &lt;code&gt;Queue[+T]&lt;/code&gt;, the immutable first-in first-out sequence of two lists, in &lt;code&gt;library/avin/queue.avin&lt;/code&gt;: &lt;code&gt;enqueue&lt;/code&gt;, &lt;code&gt;enqueueAll&lt;/code&gt;, &lt;code&gt;dequeue&lt;/code&gt;, &lt;code&gt;dequeueOption&lt;/code&gt;, &lt;code&gt;front&lt;/code&gt;, &lt;code&gt;frontOption&lt;/code&gt;, own-kind &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterNot&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;Queue(...)&lt;/code&gt;, &lt;code&gt;Queue.empty&lt;/code&gt; and &lt;code&gt;Queue.newBuilder&lt;/code&gt;, and &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; as any sequence. &lt;code&gt;LazyList[+T]&lt;/code&gt;, a memoized lazy list (each cell evaluated at most once and its expression dropped once it has been; a cell is one object of three words, made with the one function that evaluates it and filled in place by it through the core library’s &lt;code&gt;field_unset&lt;/code&gt; fields, read with no lock): &lt;code&gt;LazyList.empty&lt;/code&gt;, &lt;code&gt;cons&lt;/code&gt; with a by-name tail, the companion’s &lt;code&gt;from&lt;/code&gt;, &lt;code&gt;iterate&lt;/code&gt;, &lt;code&gt;continually&lt;/code&gt;, &lt;code&gt;unfold&lt;/code&gt;, &lt;code&gt;fill&lt;/code&gt; and &lt;code&gt;tabulate&lt;/code&gt; with &lt;code&gt;Iterator&lt;/code&gt;‘s names and argument orders, &lt;code&gt;toLazyList()&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt;; lazy &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterNot&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt;, &lt;code&gt;dropWhile&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;zipWithIndex&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt; with a by-name right operand and &lt;code&gt;flatMap&lt;/code&gt;; &lt;code&gt;+:&lt;/code&gt;; &lt;code&gt;head #:: tail&lt;/code&gt;, right-grouping at the cons level, through the language’s operators a companion declares with a by-name right operand (&lt;code&gt;#&lt;/code&gt; an operator character, passed over when a name’s level is decided), and a cell read while it is being evaluated trapping with a message about the lazy list; forcing &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;/&lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;force&lt;/code&gt; and every &lt;code&gt;Iterable&lt;/code&gt; method, all in loops, so a million cells are walked without deepening the stack; &lt;code&gt;Display&lt;/code&gt;/&lt;code&gt;Debug&lt;/code&gt; showing the evaluated prefix and &lt;code&gt;…&lt;/code&gt; without evaluating. A map’s &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; to non-pairs answering a collection, on every map, its filtered views and in comprehensions, chosen by a lambda’s body when the overloads agree on its parameters; every collection’s and iterator’s &lt;code&gt;flatMap&lt;/code&gt; taking an option-making function into its own kind (a map’s into a map where the options hold pairs), &lt;code&gt;flatten&lt;/code&gt; on collections and iterators of options, and an option’s &lt;code&gt;flatMap&lt;/code&gt; of a collection-making function answering a &lt;code&gt;Vector&lt;/code&gt;, so comprehensions mix collections and options. &lt;a href=&quot;/spec/types/#bigint&quot;&gt;&lt;code&gt;BigInt&lt;/code&gt;&lt;/a&gt;, a whole number of any size written in Avin (&lt;code&gt;library/avin/big_int.avin&lt;/code&gt;): limbs of nine decimal digits, schoolbook multiplication and long division, the five operators, &lt;code&gt;floorDiv&lt;/code&gt;/&lt;code&gt;floorMod&lt;/code&gt;/&lt;code&gt;divRem&lt;/code&gt;, &lt;code&gt;pow&lt;/code&gt;, &lt;code&gt;gcd&lt;/code&gt;, &lt;code&gt;lcm&lt;/code&gt;, &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;sign&lt;/code&gt;, &lt;code&gt;isZero&lt;/code&gt;, &lt;code&gt;toRadix&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt;/&lt;code&gt;toInt&lt;/code&gt; and their &lt;code&gt;Option&lt;/code&gt; forms, &lt;code&gt;toReal&lt;/code&gt;, &lt;code&gt;Numeric&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt;, made from any integer width, from text in any radix (&lt;code&gt;BigInt(text, radix)&lt;/code&gt;, &lt;code&gt;BigInt.parse&lt;/code&gt;), and written by the integer conversions &lt;code&gt;%d&lt;/code&gt;, &lt;code&gt;%x&lt;/code&gt;, &lt;code&gt;%o&lt;/code&gt;, &lt;code&gt;%b&lt;/code&gt; with every flag; a type’s static member called on its name beside its companion object (&lt;code&gt;BigInt.zero()&lt;/code&gt;). Integers meet a &lt;a href=&quot;/spec/types/#integers-meet-a-type-that-takes-them&quot;&gt;type that takes them&lt;/a&gt; (&lt;code&gt;FromInteger&lt;/code&gt;, which &lt;code&gt;BigInt&lt;/code&gt; implements): a literal of any size and base where one is expected (&lt;code&gt;val f: BigInt = 1&lt;/code&gt;), and an integer of any width beside one under the arithmetic operators, compound assignment, the comparisons and &lt;code&gt;==&lt;/code&gt;, on either side (&lt;code&gt;f *= i&lt;/code&gt;, &lt;code&gt;i * f&lt;/code&gt;, &lt;code&gt;f == 0&lt;/code&gt;). &lt;a href=&quot;/spec/types/#bigdecimal&quot;&gt;&lt;code&gt;BigDecimal&lt;/code&gt;&lt;/a&gt;, a decimal of any size and scale written in Avin (&lt;code&gt;library/avin/big_decimal.avin&lt;/code&gt;) over an unscaled &lt;code&gt;BigInt&lt;/code&gt; and a scale that is never negative: exact &lt;code&gt;+ - *&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt; to 34 significant digits half to even (exact where the quotient ends within them), &lt;code&gt;div&lt;/code&gt; at a scale, &lt;code&gt;divSignificant&lt;/code&gt;, &lt;code&gt;exactDiv&lt;/code&gt; answering &lt;code&gt;None&lt;/code&gt; for a quotient that never ends, &lt;code&gt;%&lt;/code&gt;, &lt;code&gt;divRem&lt;/code&gt; and &lt;code&gt;pow&lt;/code&gt;; the seven-mode &lt;code&gt;Rounding&lt;/code&gt; data type (&lt;code&gt;HalfEven&lt;/code&gt; the default) for &lt;code&gt;round(places)&lt;/code&gt;, &lt;code&gt;roundSignificant(n)&lt;/code&gt; and the divisions, by name; equality, ordering and hash by value across scales, with &lt;code&gt;scale&lt;/code&gt;, &lt;code&gt;unscaled&lt;/code&gt;, &lt;code&gt;precision&lt;/code&gt; and &lt;code&gt;stripTrailingZeros&lt;/code&gt;; plain-digit &lt;code&gt;toString&lt;/code&gt;, &lt;code&gt;%f&lt;/code&gt; with precision and flags, &lt;code&gt;BigDecimal(text)&lt;/code&gt;/&lt;code&gt;BigDecimal.parse&lt;/code&gt; with exponents, &lt;code&gt;fromRealExact&lt;/code&gt; and &lt;code&gt;fromRealShortest&lt;/code&gt;, &lt;code&gt;toReal&lt;/code&gt;, and &lt;code&gt;toBigInt&lt;/code&gt;/&lt;code&gt;toLong&lt;/code&gt;/&lt;code&gt;toInt&lt;/code&gt; toward zero with their &lt;code&gt;Option&lt;/code&gt; forms. Decimals meet a &lt;a href=&quot;/spec/types/#decimals-meet-a-type-that-takes-them&quot;&gt;type that takes them&lt;/a&gt; (&lt;code&gt;FromDecimal&lt;/code&gt;): a real literal where one is expected read exactly from its spelling (&lt;code&gt;val price: BigDecimal = 19.99&lt;/code&gt;), and a &lt;code&gt;BigInt&lt;/code&gt; beside one under the operators and comparisons on either side; a &lt;code&gt;real&lt;/code&gt; meets one only by an explicit conversion.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;In progress: &lt;code&gt;avin run&lt;/code&gt; builds into a directory of the program’s own in the user’s cache directory (&lt;code&gt;.avin/build/&lt;/code&gt; beside it only on a machine with none), which &lt;code&gt;avin clean&lt;/code&gt; removes (&lt;code&gt;--all&lt;/code&gt; every program’s), kept by every build within &lt;code&gt;AVIN_CACHE_LIMIT&lt;/code&gt; (5G by default) by a sweep at most every ten minutes that evicts least recently used entries (none used within the hour), removes interrupted builds’ debris, killed builds’ temporary directories and other versions’ caches three days after their last use, rebuilds an entry gone from under a build rather than linking a path to nothing, with &lt;code&gt;avin cache info&lt;/code&gt;, &lt;code&gt;trim&lt;/code&gt; and &lt;code&gt;clean [--older-than &amp;lt;age&amp;gt;] [--packages]&lt;/code&gt;, reuses an executable whose sources, library, runtime and compiler are unchanged, and forwards output, arguments and exit status (128 and the signal for a trap); &lt;code&gt;avin test&lt;/code&gt; checks and collects top-level &lt;code&gt;@test&lt;/code&gt; functions, builds one executable whose &lt;code&gt;main&lt;/code&gt; runs the test its argument numbers, runs each test in its own process, and reports &lt;code&gt;ok&lt;/code&gt;/&lt;code&gt;FAIL&lt;/code&gt; by file with the trap’s reason and the test’s output, a filter by name or file, and the exit status; tests answering with a &lt;code&gt;Result[unit, E]&lt;/code&gt;, failing on an &lt;code&gt;Err&lt;/code&gt; at the test’s name; &lt;code&gt;main&lt;/code&gt; answering with a &lt;code&gt;Result&lt;/code&gt; whose &lt;code&gt;Ok&lt;/code&gt; is unit, an integer type or &lt;code&gt;Nothing&lt;/code&gt; and whose error has &lt;code&gt;Display&lt;/code&gt; (a union’s members each), an &lt;code&gt;Err&lt;/code&gt; written to standard error as &lt;code&gt;error: &lt;/code&gt; and its &lt;code&gt;Display&lt;/code&gt; and exiting with 1; &lt;code&gt;@test&lt;/code&gt;‘s &lt;code&gt;should_trap&lt;/code&gt; (with or without the text the run must print), &lt;code&gt;timeout&lt;/code&gt; (killing the test’s process) and &lt;code&gt;ignore&lt;/code&gt; (reported as &lt;code&gt;skip&lt;/code&gt;, counted in the summary); &lt;code&gt;@setup&lt;/code&gt;/&lt;code&gt;@teardown&lt;/code&gt; around each test, the teardown in a process of its own after a test that trapped, and &lt;code&gt;@setup_all&lt;/code&gt;/&lt;code&gt;@teardown_all&lt;/code&gt; once around a module’s tests, each failure reported against the hook; &lt;code&gt;@tests&lt;/code&gt; files, checked by every command and built only for tests, whose declarations only tests, hooks and other &lt;code&gt;@tests&lt;/code&gt; files may name, with impls only for their own types and traits; &lt;code&gt;assert&lt;/code&gt; and &lt;code&gt;assertEq&lt;/code&gt; in the core library, with a trap reason made at run time; &lt;code&gt;-O0&lt;/code&gt;/&lt;code&gt;-O2&lt;/code&gt; on &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt;; &lt;code&gt;avin new &amp;lt;dir&amp;gt; [--lib]&lt;/code&gt; scaffolding a program or library package with a module, a test and a &lt;code&gt;.gitignore&lt;/code&gt;; &lt;code&gt;avin add &amp;lt;coordinate&amp;gt;[@&amp;lt;version&amp;gt;]&lt;/code&gt; recording a git dependency in the manifest, fetching it and adding its hash to &lt;code&gt;avin.sum&lt;/code&gt;; &lt;code&gt;avin tidy [--check]&lt;/code&gt; rewriting &lt;code&gt;avin.sum&lt;/code&gt; to what the package resolves to; a manifest’s &lt;code&gt;avin&lt;/code&gt;, the least Avin the package builds with, held for every package of the graph and reported on the manifest by the language server; &lt;code&gt;avin lsp&lt;/code&gt;, a &lt;a href=&quot;/getting-started/editors/&quot;&gt;language server&lt;/a&gt; over standard input and output that answers diagnostics, hover, go-to-definition, the document outline (local functions nested, tests marked), the workspace’s symbols by subsequence, folding ranges, references, highlights, rename, semantic tokens and completion from the checker’s own analysis (a rename edits every file of the program, follows a method to what it overrides and implements, and refuses the library, a keyword and a clash found by checking the program as the edit leaves it), re-checking the whole program with the library on each change; completion checks a copy of the text with a stand-in name at the cursor and answers the scope the checker had there, in about 130 ms in the largest library file. Literate &lt;code&gt;.lavin&lt;/code&gt; sources are read wherever &lt;code&gt;.avin&lt;/code&gt; files are, by every command, the corpus and the language server, at the document’s own positions; &lt;code&gt;avin tangle&lt;/code&gt; prints the program, and &lt;code&gt;avin weave&lt;/code&gt; renders the document as HTML with the program coloured by the lexer. &lt;code&gt;avin doc&lt;/code&gt; writes a program’s (or with &lt;code&gt;--std&lt;/code&gt; the standard library’s) &lt;a href=&quot;/getting-started/#api-documentation&quot;&gt;API documentation&lt;/a&gt; as static pages from the checker’s own record of its declarations: a page per module, every public declaration with the header hover shows and its doc comment as Markdown, the impls each type has, exports, a type in a signature linked to the declaration the checker resolved it to (across modules, into dependencies and the standard library, or &lt;code&gt;--std-url&lt;/code&gt;), links to declarations written in doc comments, a search box, and &lt;code&gt;--check&lt;/code&gt; failing on a link that leads nowhere or an Avin block that does not parse. The core library’s own tests, a program of &lt;code&gt;@test&lt;/code&gt; functions in &lt;code&gt;library/tests&lt;/code&gt; that is no part of the library programs are compiled with, run by the gate at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;: Option and Result, the string methods, format specifiers, List, Vector across the lengths where its tree deepens, Map and Set with colliding hashes, TreeMap and TreeSet, Buffer, Deque and the mutable Set added to or removed from themselves, and stable sorting at every run and merge width. &lt;code&gt;avin fmt [--check] [&amp;lt;path&amp;gt;...]&lt;/code&gt; and the language server’s &lt;code&gt;textDocument/formatting&lt;/code&gt; write one style over the lexer’s tokens: two spaces a level (a literate file’s program inside its four-column margin, its prose untouched), the spaces between tokens, at most one blank line and one between multi-line top-level declarations, comments kept, and lines past 120 characters broken one list item per line (a sequence or set literal of short literals and names filled, as many to a line as fit) or before a binding’s loosest operators; the result is parsed and its syntax tree and tokens compared with the source’s before it is given back, and every source file of the tests and the library formats so, stably. &lt;code&gt;textDocument/rangeFormatting&lt;/code&gt; formats the whole lines of the top-level declarations a range touches, and edits nothing else. Not yet: &lt;code&gt;textDocument/onTypeFormatting&lt;/code&gt; A build compiles a program’s LLVM text as parallel codegen units, each unit’s object cached by its text, so an edit recompiles only the units it changed (tui’s &lt;code&gt;top&lt;/code&gt; example at &lt;code&gt;-O2&lt;/code&gt;: 12.7 s to 6.4 s from an empty cache and 5.9 s after a one-line edit, with clang’s part about a second). Incremental builds, designed in the &lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;pipeline&lt;/a&gt;: every build, run and test keeps each instance’s code and text in the program’s build cache and takes an unchanged instance’s from there (&lt;code&gt;AVIN_INCREMENTAL=off&lt;/code&gt; or &lt;code&gt;verify&lt;/code&gt;), items 1 to 7 of &lt;a href=&quot;#incremental-builds-build-plan&quot;&gt;its build plan&lt;/a&gt;. Debug information, designed in the &lt;a href=&quot;/compiler/#debug-information&quot;&gt;pipeline&lt;/a&gt;: &lt;code&gt;avin build -g&lt;/code&gt; and &lt;code&gt;avin emit-llvm -g&lt;/code&gt; describe every function the source declares (literate documents and generic instances included) with its lines and its parameters and locals, and on macOS &lt;code&gt;dsymutil&lt;/code&gt; writes the &lt;code&gt;.dSYM&lt;/code&gt;, so lldb stops at an Avin line, shows the Avin call stack and reads the variables. Still to come for it: a location in the stack overflow report, and each unit carrying only the metadata it names (both &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). Still to come: the whole-program passes run only where an instance’s facts changed, and, if measured to matter, the front end (item 8). Done: &lt;a href=&quot;/getting-started/#the-interactive-session&quot;&gt;&lt;code&gt;avin repl&lt;/code&gt;&lt;/a&gt;, an interactive session: a growing program whose imports, modules (one per declaration of types, and per function or &lt;code&gt;val&lt;/code&gt; that uses no local of &lt;code&gt;main&lt;/code&gt;, which later declarations call and read, each keeping the version it was declared after) and &lt;code&gt;main&lt;/code&gt; (each input a block nested in the last, so a name may be entered again) are checked, built at &lt;code&gt;-O0&lt;/code&gt; through the instance cache and run after each input, the earlier inputs’ output passed over, an expression’s value shown with its type as &lt;code&gt;res0: int = 42&lt;/code&gt; and a &lt;code&gt;val&lt;/code&gt;‘s by its name, a trap or an ended program leaving the input out, diagnostics and trap places shown in the input as typed, &lt;code&gt;:type&lt;/code&gt;, &lt;code&gt;:imports&lt;/code&gt;, &lt;code&gt;:load&lt;/code&gt;, &lt;code&gt;:reset&lt;/code&gt;, &lt;code&gt;:help&lt;/code&gt;, &lt;code&gt;:quit&lt;/code&gt;, a multi-line editor with history and Tab completion from the language server’s at a terminal, and a package’s modules importable. Still to come for it: one live process loading each input as a shared object, so earlier inputs are not run again (their side effects repeat, unseen, and a value they compute afresh, a random one or the time, may differ from the one shown); a &lt;code&gt;var&lt;/code&gt; that declarations can reach; code of &lt;code&gt;main&lt;/code&gt; keeping a type declared again apart from the earlier one.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;In progress: &lt;code&gt;avin.process&lt;/code&gt;, with &lt;code&gt;args()&lt;/code&gt; as a &lt;code&gt;Vector[string]&lt;/code&gt; of the arguments after the program’s name, &lt;code&gt;programName()&lt;/code&gt;, &lt;code&gt;env(name)&lt;/code&gt; as an &lt;code&gt;Option[string]&lt;/code&gt; over one Option-returning Sysl binding, &lt;code&gt;environment()&lt;/code&gt; as a &lt;code&gt;Map[string, string]&lt;/code&gt; over &lt;code&gt;sysl.env.vars&lt;/code&gt;, a &lt;code&gt;Vector[(string, string)]&lt;/code&gt; across the boundary, and &lt;code&gt;exit(code)&lt;/code&gt; of type &lt;code&gt;Nothing&lt;/code&gt;, flushing standard output first; the runtime keeps the arguments &lt;code&gt;main&lt;/code&gt; is handed, checked as UTF-8 at startup, and a test sees none. The execution corpus passes arguments to a program from an &lt;code&gt;// args:&lt;/code&gt; line. &lt;code&gt;avin.io&lt;/code&gt;‘s &lt;code&gt;IoError(kind, operation, subject)&lt;/code&gt;, its &lt;code&gt;ErrorKind&lt;/code&gt; the failures a program tells apart and &lt;code&gt;Other(text)&lt;/code&gt;, showing as &lt;code&gt;cannot read nope.txt: no such file or directory&lt;/code&gt;, every error of &lt;code&gt;avin.fs&lt;/code&gt;, &lt;code&gt;avin.process&lt;/code&gt;, &lt;code&gt;avin.signal&lt;/code&gt; and &lt;code&gt;avin.net&lt;/code&gt; naming its path, program, process or address, and &lt;code&gt;CommandError.Failed&lt;/code&gt; its command; the core &lt;code&gt;Error&lt;/code&gt; trait (&lt;code&gt;message&lt;/code&gt;, &lt;code&gt;cause&lt;/code&gt;, a display chaining the causes), implemented by every library error type, and &lt;code&gt;Result.context(text)&lt;/code&gt; with &lt;code&gt;ContextError&lt;/code&gt;, over unions and &lt;code&gt;E: Error&lt;/code&gt; bounds and &lt;code&gt;?&lt;/code&gt; into &lt;code&gt;Result[T, Error]&lt;/code&gt;; &lt;code&gt;avin.fs&lt;/code&gt; over Sysl bindings, with a private mirror of Sysl’s error converted into it: whole files read and written as text or bytes, appended to, removed, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;isDir&lt;/code&gt; and &lt;code&gt;isFile&lt;/code&gt;, &lt;code&gt;createDir&lt;/code&gt;, &lt;code&gt;createDirAll&lt;/code&gt;, &lt;code&gt;createTempDir&lt;/code&gt;, &lt;code&gt;removeDir&lt;/code&gt; and &lt;code&gt;removeDirAll&lt;/code&gt;, &lt;code&gt;rename&lt;/code&gt; (replacing the destination in one step), and &lt;code&gt;listDir&lt;/code&gt;, the names of a directory’s entries as a &lt;code&gt;Vector[string]&lt;/code&gt; sorted by code point, each failure a &lt;code&gt;Result&lt;/code&gt;‘s &lt;code&gt;Err&lt;/code&gt;. Open files in &lt;code&gt;avin.fs&lt;/code&gt;: &lt;code&gt;File&lt;/code&gt;, made by &lt;code&gt;open&lt;/code&gt;, &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt;, &lt;code&gt;openUpdate&lt;/code&gt; and &lt;code&gt;createUpdate&lt;/code&gt; over &lt;code&gt;sysl.fs.File&lt;/code&gt;, with &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;position&lt;/code&gt;, &lt;code&gt;seek&lt;/code&gt;, &lt;code&gt;seekToEnd&lt;/code&gt;, &lt;code&gt;read(max)&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;, &lt;code&gt;readText&lt;/code&gt;, &lt;code&gt;readLine&lt;/code&gt; and &lt;code&gt;readCompleteLine&lt;/code&gt; through a buffer of its own, &lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;flush&lt;/code&gt; and &lt;code&gt;close&lt;/code&gt;; a file closed by the collector when forgotten, every call on a closed one, a read of a write-only one and a write to a read-only one an &lt;code&gt;Err&lt;/code&gt;, a file that grew since a read reached its end read on from there; &lt;code&gt;readBytesFrom(file, offset)&lt;/code&gt;, &lt;code&gt;readTail(file, maxBytes)&lt;/code&gt; starting at a whole character, and &lt;code&gt;readTailLines(file, count)&lt;/code&gt;. Standard input in &lt;code&gt;avin.io&lt;/code&gt;, read through &lt;code&gt;readLine()&lt;/code&gt;, &lt;code&gt;lines()&lt;/code&gt; and &lt;code&gt;readAll()&lt;/code&gt; from one buffer the runtime holds, lines ending at &lt;code&gt;\n&lt;/code&gt; or &lt;code&gt;\r\n&lt;/code&gt;, ill-formed UTF-8 replaced with U+FFFD; &lt;code&gt;readSecret&lt;/code&gt;, &lt;code&gt;readSecretBytes&lt;/code&gt; and &lt;code&gt;readSecretOrLine&lt;/code&gt; in &lt;code&gt;avin.io&lt;/code&gt;, a line typed at the controlling terminal with echo off, the terminal put back on every way out (a signal included) and the read serialized with standard input’s; &lt;code&gt;io.stdin()&lt;/code&gt;, &lt;code&gt;io.stdout()&lt;/code&gt; and &lt;code&gt;io.stderr()&lt;/code&gt;, the standard streams as a byte &lt;code&gt;Reader&lt;/code&gt; sharing the text readers’ buffer and lock and as unbuffered &lt;code&gt;ByteWriter&lt;/code&gt;s that keep printed lines whole and answer &lt;code&gt;ConnectionReset&lt;/code&gt; for a reader that has gone, standard input a &lt;code&gt;Readiness&lt;/code&gt; any thread may wait on in a &lt;code&gt;select&lt;/code&gt; or &lt;code&gt;Selector&lt;/code&gt; (buffered bytes, the end and descriptor 0 making it ready) with &lt;code&gt;readAvailable(max)&lt;/code&gt; reading only what is there, and closed standard descriptors opened on &lt;code&gt;/dev/null&lt;/code&gt; at start; &lt;code&gt;eprint&lt;/code&gt; and &lt;code&gt;StandardError&lt;/code&gt; in the prelude, every write to standard error flushing standard output first; the execution corpus feeds a program its &lt;code&gt;NAME.in&lt;/code&gt; sidecar and otherwise empty input, and a test run by &lt;code&gt;avin test&lt;/code&gt; reads empty input. &lt;code&gt;Source&lt;/code&gt; in &lt;code&gt;avin.io&lt;/code&gt;, a trait read by &lt;code&gt;lines()&lt;/code&gt;, &lt;code&gt;chars()&lt;/code&gt; and &lt;code&gt;readAll()&lt;/code&gt;, each taking up where the last stopped: &lt;code&gt;Source.fromFile&lt;/code&gt; reading the file whole through &lt;code&gt;fs.readText&lt;/code&gt;, every failure the &lt;code&gt;Err&lt;/code&gt;, &lt;code&gt;Source.fromString&lt;/code&gt;, and &lt;code&gt;Source.stdin()&lt;/code&gt; over standard input’s shared buffer, its characters decoded one at a time by the runtime as its lines are, U+FFFD for each ill-formed run. &lt;code&gt;avin.threads&lt;/code&gt;: &lt;code&gt;spawn(body, stack)&lt;/code&gt; starts a closure on an operating system thread with its own context, attached before the thread starts so the closure is always a root, and gives back a &lt;code&gt;Thread[T]&lt;/code&gt; whose &lt;code&gt;join()&lt;/code&gt; waits safe for the collector and gives the same result every time, from any thread; &lt;code&gt;scope(body)&lt;/code&gt; joins every thread started through &lt;code&gt;s.spawn&lt;/code&gt;, which traps from any thread but the scope’s own or after the scope has closed; a trap in any thread stops the program once, with one flush and one report; the program ends when &lt;code&gt;main&lt;/code&gt; returns. The corpus runs threads under GC stress and in parallel with budget collections. Synchronization in &lt;code&gt;avin.threads&lt;/code&gt;: &lt;code&gt;Mutex[T]&lt;/code&gt; owning its value, reached through &lt;code&gt;with&lt;/code&gt;, &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt;, over a runtime futex lock taken with one compare-and-swap when free, a second take by its holder trapping; &lt;code&gt;Condition&lt;/code&gt; from a mutex’s &lt;code&gt;condition()&lt;/code&gt;, with &lt;code&gt;wait&lt;/code&gt;, &lt;code&gt;notify&lt;/code&gt; and &lt;code&gt;notifyAll&lt;/code&gt;, a wait without the mutex trapping; sequentially consistent &lt;code&gt;Atomic[T]&lt;/code&gt; of any type, &lt;code&gt;load&lt;/code&gt;, &lt;code&gt;store&lt;/code&gt;, &lt;code&gt;swap&lt;/code&gt; and &lt;code&gt;compareAndSet&lt;/code&gt; each one LLVM atomic at the value’s storage width (a value wider than 64 bits under one runtime lock), &lt;code&gt;update&lt;/code&gt; and the integers’ &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; a compare-and-set loop trapping on overflow; &lt;code&gt;Channel[T]&lt;/code&gt;, bounded or unbounded, with &lt;code&gt;send&lt;/code&gt;, &lt;code&gt;trySend&lt;/code&gt;, &lt;code&gt;receive&lt;/code&gt;, &lt;code&gt;tryReceive&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt; and &lt;code&gt;isClosed&lt;/code&gt;, iterable until closed and drained; the &lt;a href=&quot;/spec/threads/#rendezvous&quot;&gt;rendezvous&lt;/a&gt;, &lt;code&gt;Channel[T](0)&lt;/code&gt;, handing each value from a waiting sender to a waiting receiver (a plain send or receive on a condition of its own, or a select’s arm that a partner claims through &lt;code&gt;select_claim&lt;/code&gt; once its round is tried, a select met mid-round woken to try again), with the &lt;code&gt;try&lt;/code&gt; and timed forms, select pairing both ways, close, cancellation and the deadlock report’s “waiting to hand a value to a receiver” (&lt;code&gt;channel_rendezvous*&lt;/code&gt;, &lt;code&gt;deadlock_rendezvous_*&lt;/code&gt;); &lt;code&gt;Once&lt;/code&gt; with &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;isDone&lt;/code&gt;; the rest of the synchronization kit, each over the runtime’s parking lock and conditions: &lt;code&gt;WaitGroup&lt;/code&gt; (&lt;code&gt;add&lt;/code&gt;, &lt;code&gt;done&lt;/code&gt;, &lt;code&gt;wait&lt;/code&gt;, timed &lt;code&gt;waitFor&lt;/code&gt;, &lt;code&gt;pending&lt;/code&gt;, trapping below zero), &lt;code&gt;Semaphore(permits, capacity)&lt;/code&gt; (&lt;code&gt;acquire&lt;/code&gt;, &lt;code&gt;tryAcquire&lt;/code&gt;, timed &lt;code&gt;acquireFor&lt;/code&gt;, &lt;code&gt;release&lt;/code&gt; trapping beyond the capacity, &lt;code&gt;withPermit&lt;/code&gt; giving its permit back when a cancellation stops its body), &lt;code&gt;RwLock[T]&lt;/code&gt; (&lt;code&gt;read&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;, and &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; for a sendable value; writers first, with the readers a write kept waiting let in before the next writer; a write body uncancellable as a mutex’s, a read body stopped and its share given back), &lt;code&gt;Pool[T, E]&lt;/code&gt; (resources made by &lt;code&gt;create&lt;/code&gt; up to &lt;code&gt;maxSize&lt;/code&gt; and lent by &lt;code&gt;use&lt;/code&gt; and &lt;code&gt;lease&lt;/code&gt;, always taken back, also on a cancellation; waiters served first come, first served; timeouts, &lt;code&gt;validate&lt;/code&gt;, broken leases, &lt;code&gt;idleTimeout&lt;/code&gt; with &lt;code&gt;minIdle&lt;/code&gt;, &lt;code&gt;warm&lt;/code&gt;, &lt;code&gt;evictIdle&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt; waiting for lent resources, &lt;code&gt;stats&lt;/code&gt;; isolated resources whose handles move to each borrower) and &lt;code&gt;Barrier(parties, action)&lt;/code&gt; (reusable, its action run by the last arrival under the lock, &lt;code&gt;wait&lt;/code&gt; answering whether the caller was last); the waits that keep state of their own (a read-write lock’s, a barrier’s) wait through the runtime’s settling condition wait, which answers a cancellation with the lock held again so the waiter takes itself back before it stops; a condition’s &lt;code&gt;waitFor(timeoutMillis)&lt;/code&gt;, through a timed runtime wait over the lock, which is a Sysl &lt;code&gt;Mutex&lt;/code&gt;. Every wait is safe for the collector, keeping what it sleeps on as a root. &lt;code&gt;Future[T]&lt;/code&gt; and &lt;code&gt;Promise[T]&lt;/code&gt; in &lt;code&gt;avin.threads&lt;/code&gt;, on a pool of workers, a module’s &lt;code&gt;lazy val&lt;/code&gt;, started as work comes, one per processor, with a worker started in place of each one waiting in &lt;code&gt;await&lt;/code&gt; while work is queued: &lt;code&gt;Future(body)&lt;/code&gt;, the companion’s &lt;code&gt;apply&lt;/code&gt;, with a by-name body written in place or as a trailing block, &lt;code&gt;Future.successful&lt;/code&gt;, &lt;code&gt;await()&lt;/code&gt; and &lt;code&gt;await(timeoutMillis)&lt;/code&gt; as an &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;isCompleted&lt;/code&gt;, &lt;code&gt;value&lt;/code&gt;, &lt;code&gt;onComplete&lt;/code&gt; on a pool thread, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; (so &lt;code&gt;for … yield&lt;/code&gt; over futures), &lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;Future.all&lt;/code&gt; in the order given, &lt;code&gt;Future.first&lt;/code&gt;, and &lt;code&gt;mapOk&lt;/code&gt; and &lt;code&gt;flatMapOk&lt;/code&gt; on a future of a &lt;code&gt;Result&lt;/code&gt;; a promise’s &lt;code&gt;future&lt;/code&gt;, &lt;code&gt;complete&lt;/code&gt; trapping a second time, &lt;code&gt;tryComplete&lt;/code&gt; and &lt;code&gt;isCompleted&lt;/code&gt;. The runtime publishes the strings, arrays, locks and conditions it makes with a release fence, and the core library ends the fill of an array it makes with the &lt;code&gt;array_publish&lt;/code&gt; intrinsic (&lt;code&gt;Array.fill&lt;/code&gt;, &lt;code&gt;Array.tabulate&lt;/code&gt;, &lt;code&gt;Deque.toArray&lt;/code&gt;, the growth of a buffer or deque). &lt;code&gt;lazy val&lt;/code&gt; at module level and in class and object bodies: a state word per value (a module-level global, or a hidden field beside the value with the initializer’s closure), read with one sequentially consistent load and a branch once ready; the first reads call the runtime, which claims the word with a compare-and-swap, makes other threads wait safe for the collector, traps a thread that reads a value its own initialization is computing, and marks it ready with a release store; module-level lazy values outside the eager initialization order, their readers depending on what the initializer reads. Local &lt;code&gt;lazy val&lt;/code&gt;s in blocks: each declaration makes a cell, the core library’s &lt;code&gt;LazyCell&lt;/code&gt;, whose initializer slot takes the lambda computing the value, so a read is the cell’s lazy field and a closure that captures the name shares the cell; the name is in scope in its own initializer, a self-read trapping, and a &lt;code&gt;@sendable&lt;/code&gt; closure capturing one holds the initializer’s captures and reach to its own rules. &lt;code&gt;avin.time&lt;/code&gt;‘s clocks and durations, step (1) of &lt;a href=&quot;#dates-and-times-build-plan&quot;&gt;its build plan&lt;/a&gt;: &lt;code&gt;Duration(micros)&lt;/code&gt; with &lt;code&gt;Duration.Zero&lt;/code&gt;, &lt;code&gt;Min&lt;/code&gt; and &lt;code&gt;Max&lt;/code&gt;, the makers &lt;code&gt;micros&lt;/code&gt;, &lt;code&gt;millis&lt;/code&gt;, &lt;code&gt;seconds&lt;/code&gt;, &lt;code&gt;minutes&lt;/code&gt;, &lt;code&gt;hours&lt;/code&gt;, &lt;code&gt;days&lt;/code&gt; and &lt;code&gt;weeks&lt;/code&gt; and the same methods on &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; (&lt;code&gt;2.hours&lt;/code&gt;), &lt;code&gt;toDays()&lt;/code&gt; … &lt;code&gt;toMillis()&lt;/code&gt; and &lt;code&gt;toHoursPart()&lt;/code&gt;, &lt;code&gt;toMinutesPart()&lt;/code&gt;, &lt;code&gt;toSecondsPart()&lt;/code&gt; and &lt;code&gt;toMicrosPart()&lt;/code&gt; dropped toward zero, &lt;code&gt;toSecondsReal&lt;/code&gt;, &lt;code&gt;isNegative&lt;/code&gt;, &lt;code&gt;isZero&lt;/code&gt; and &lt;code&gt;abs&lt;/code&gt;, arithmetic through &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Sub&lt;/code&gt; and &lt;code&gt;Neg&lt;/code&gt;, &lt;code&gt;d * n&lt;/code&gt;, &lt;code&gt;d / n&lt;/code&gt; and &lt;code&gt;d / e&lt;/code&gt; (a &lt;code&gt;long&lt;/code&gt;), and the text in the largest of &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;ms&lt;/code&gt; and &lt;code&gt;us&lt;/code&gt; (&lt;code&gt;0s&lt;/code&gt; for none); &lt;code&gt;Instant(epochMicros)&lt;/code&gt; as the wall clock, read by &lt;code&gt;now()&lt;/code&gt;, with &lt;code&gt;Instant.Epoch&lt;/code&gt;, &lt;code&gt;Min&lt;/code&gt; and &lt;code&gt;Max&lt;/code&gt;, &lt;code&gt;epochSeconds&lt;/code&gt;, &lt;code&gt;epochMillis&lt;/code&gt; and &lt;code&gt;epochMicros&lt;/code&gt; as makers and counts back rounded toward negative infinity, &lt;code&gt;t ± d&lt;/code&gt; and &lt;code&gt;later - earlier&lt;/code&gt;, and the ISO 8601 text with &lt;code&gt;Z&lt;/code&gt;, the fraction only where there is one and years outside 0 to 9999 signed; &lt;code&gt;monotonic()&lt;/code&gt; a &lt;code&gt;Duration&lt;/code&gt;, two runtime clock readings beneath; every maker and step leaving a &lt;code&gt;long&lt;/code&gt; of microseconds trapping; both types ordered, equal and hashed by value. Every delay is a &lt;code&gt;Duration&lt;/code&gt;: &lt;code&gt;Future.await&lt;/code&gt; and &lt;code&gt;Condition.waitFor&lt;/code&gt; take one beside their milliseconds, a part of a millisecond waited for whole; a command’s deadline and the actors’ timers and restart windows are &lt;code&gt;monotonic()&lt;/code&gt; readings. &lt;code&gt;avin.regex&lt;/code&gt;, written in Avin: a reader for the whole pattern language (literals and every escape, &lt;code&gt;\Q…\E&lt;/code&gt;, classes with ranges, nesting and intersection, the predefined, POSIX and Unicode general-category classes over a mirror of Sysl’s &lt;code&gt;Category&lt;/code&gt;, every quantifier greedy, reluctant and possessive, capturing, named, non-capturing and atomic groups, the four lookarounds with bounded lookbehind, back references by number and name, the anchors and boundaries, inline and scoped flags &lt;code&gt;imsxdu&lt;/code&gt; and comments mode) into a syntax tree, with the established dialect’s error descriptions and indices; a compiler from the tree to an array of operations (single-character loops, counted repetition of one-length groups, loops for the rest), and a backtracking matcher over the text’s code points with a backtrack stack of its own, an array of frames, so a repeated group over a million characters takes no deeper a call stack, and a step budget for each attempt at a start that traps, naming the pattern and the budget, on catastrophic backtracking, and the checked searches (&lt;code&gt;tryMatches&lt;/code&gt;, &lt;code&gt;tryFindFirstIn&lt;/code&gt; and the rest of the &lt;code&gt;try&lt;/code&gt; family, &lt;code&gt;trySplit&lt;/code&gt; on &lt;code&gt;Pattern&lt;/code&gt; too) answering a &lt;code&gt;Result&lt;/code&gt; with a &lt;code&gt;MatchError&lt;/code&gt; instead, the budget ending the whole search through lookarounds and atomic groups; &lt;code&gt;Regex&lt;/code&gt; with &lt;code&gt;matches&lt;/code&gt;, &lt;code&gt;findFirstIn&lt;/code&gt;, &lt;code&gt;findFirstMatchIn&lt;/code&gt;, &lt;code&gt;findPrefixOf&lt;/code&gt;, &lt;code&gt;findPrefixMatchOf&lt;/code&gt;, &lt;code&gt;findAllIn&lt;/code&gt; (a &lt;code&gt;MatchIterator&lt;/code&gt;), &lt;code&gt;findAllMatchIn&lt;/code&gt;, &lt;code&gt;unanchored&lt;/code&gt;, &lt;code&gt;anchored&lt;/code&gt;, &lt;code&gt;withStepLimit&lt;/code&gt;, &lt;code&gt;regex&lt;/code&gt;, &lt;code&gt;pattern&lt;/code&gt; and &lt;code&gt;toString&lt;/code&gt;, &lt;code&gt;Regex.compile&lt;/code&gt; answering a &lt;code&gt;Result&lt;/code&gt;, the string method &lt;code&gt;r&lt;/code&gt;, and &lt;code&gt;Match&lt;/code&gt; with byte offsets and &lt;code&gt;Option&lt;/code&gt; groups; replacing and splitting: &lt;code&gt;replaceAllIn&lt;/code&gt; with a replacement or a function of the match, &lt;code&gt;replaceFirstIn&lt;/code&gt;, &lt;code&gt;replaceSomeIn&lt;/code&gt;, the replacement syntax (&lt;code&gt;$n&lt;/code&gt;, &lt;code&gt;${name}&lt;/code&gt;, backslash escapes) with the dialect’s trap messages, &lt;code&gt;split&lt;/code&gt; and &lt;code&gt;Pattern.split&lt;/code&gt; with a limit, &lt;code&gt;Regex.quote&lt;/code&gt; and &lt;code&gt;Regex.quoteReplacement&lt;/code&gt;; a regex as an extractor, &lt;code&gt;unapplySeq&lt;/code&gt; answering the groups’ texts where the whole text matches (any part, unanchored), and &lt;code&gt;Groups&lt;/code&gt; taking apart any &lt;code&gt;Match&lt;/code&gt;; Unicode scripts, blocks, the binary properties beyond the general category (&lt;code&gt;Alphabetic&lt;/code&gt;, &lt;code&gt;Uppercase&lt;/code&gt;, &lt;code&gt;Lowercase&lt;/code&gt;, &lt;code&gt;Ideographic&lt;/code&gt;, &lt;code&gt;Word&lt;/code&gt;, &lt;code&gt;Alnum&lt;/code&gt;, the emoji properties), the &lt;code&gt;U&lt;/code&gt; flag’s Unicode classes and word boundaries, and grapheme clusters (&lt;code&gt;\X&lt;/code&gt;, &lt;code&gt;\b{g}&lt;/code&gt;), over run tables generated from the Unicode Character Database 17.0.0 by &lt;code&gt;scripts/unicode_tables.avin&lt;/code&gt; and decoded on first use; the library’s tests hold a conformance table over every construct. &lt;code&gt;avin.math&lt;/code&gt;: &lt;code&gt;Pi&lt;/code&gt;, &lt;code&gt;E&lt;/code&gt; and the elementary functions on &lt;code&gt;real&lt;/code&gt; (roots, exponentials and logarithms, &lt;code&gt;pow&lt;/code&gt; and &lt;code&gt;hypot&lt;/code&gt;, the circular and hyperbolic functions and their inverses, &lt;code&gt;atan2&lt;/code&gt;, &lt;code&gt;floor&lt;/code&gt;, &lt;code&gt;ceil&lt;/code&gt;, &lt;code&gt;rint&lt;/code&gt;, &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt;, &lt;code&gt;signum&lt;/code&gt;, and the angle conversions, then &lt;code&gt;round&lt;/code&gt; to a &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;trunc&lt;/code&gt;, &lt;code&gt;log2&lt;/code&gt;, the explicit fused &lt;code&gt;fma&lt;/code&gt;, &lt;code&gt;copySign&lt;/code&gt;, &lt;code&gt;ulp&lt;/code&gt;, &lt;code&gt;nextUp&lt;/code&gt; and &lt;code&gt;nextDown&lt;/code&gt;), each a binding to one runtime function over Sysl’s &lt;code&gt;Float&lt;/code&gt; methods, NaN and the infinities following IEEE 754 and nothing trapping. The integer methods, written in Avin in one impl for every width: &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;sign&lt;/code&gt;, &lt;code&gt;pow&lt;/code&gt;, &lt;code&gt;gcd&lt;/code&gt;, &lt;code&gt;lcm&lt;/code&gt;, &lt;code&gt;floorDiv&lt;/code&gt;, &lt;code&gt;floorMod&lt;/code&gt;, &lt;code&gt;bitCount&lt;/code&gt;, &lt;code&gt;leadingZeros&lt;/code&gt;, &lt;code&gt;trailingZeros&lt;/code&gt;, &lt;code&gt;isPowerOfTwo&lt;/code&gt; and &lt;code&gt;toRadix&lt;/code&gt;; and the bitwise and shift operators on a type parameter bounded by &lt;code&gt;Integer&lt;/code&gt;. &lt;code&gt;avin.random&lt;/code&gt;, written in Avin: &lt;code&gt;Random&lt;/code&gt;, PCG32 on the reference stream over a &lt;code&gt;long&lt;/code&gt; state with the wrapping operators, &lt;code&gt;Random(seed)&lt;/code&gt; reproducing the published sequence and &lt;code&gt;Random()&lt;/code&gt; seeded by one runtime function over the host’s entropy; &lt;code&gt;nextInt&lt;/code&gt; and &lt;code&gt;nextLong&lt;/code&gt;, their bounded forms and &lt;code&gt;between&lt;/code&gt; on &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt; unbiased by rejection (64-bit draws through &lt;code&gt;i128&lt;/code&gt;), each bad bound trapping at the program’s call; &lt;code&gt;nextReal&lt;/code&gt; from 53 bits, &lt;code&gt;nextBoolean&lt;/code&gt;, &lt;code&gt;nextGaussian&lt;/code&gt; by the polar method over &lt;code&gt;avin.math&lt;/code&gt;, &lt;code&gt;nextBytes&lt;/code&gt;, &lt;code&gt;alphanumeric&lt;/code&gt;, &lt;code&gt;shuffle&lt;/code&gt; by Fisher-Yates, &lt;code&gt;choose&lt;/code&gt;, &lt;code&gt;chooseWeighted&lt;/code&gt; (an index or an item of a pair, by running totals of the weights) and &lt;code&gt;Weighted&lt;/code&gt; for repeated draws, and &lt;code&gt;setSeed&lt;/code&gt;; the companion’s methods on one shared generator in a module’s &lt;code&gt;lazy val&lt;/code&gt; &lt;code&gt;Mutex&lt;/code&gt;, seeded by the platform on first use. &lt;code&gt;avin.crypto&lt;/code&gt; over Sysl’s &lt;code&gt;sysl.crypto&lt;/code&gt;: &lt;code&gt;sha256&lt;/code&gt;, &lt;code&gt;sha512&lt;/code&gt;, &lt;code&gt;sha1&lt;/code&gt; and &lt;code&gt;md5&lt;/code&gt; of bytes or of text as UTF-8, &lt;code&gt;hmacSha256&lt;/code&gt; and &lt;code&gt;hmacSha512&lt;/code&gt;, &lt;code&gt;toHex&lt;/code&gt;, and the incremental hashers &lt;code&gt;Sha256&lt;/code&gt;, &lt;code&gt;Sha512&lt;/code&gt;, &lt;code&gt;Sha1&lt;/code&gt; and &lt;code&gt;Md5&lt;/code&gt; (&lt;code&gt;update&lt;/code&gt;, a repeatable &lt;code&gt;finish&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt; afterwards trapping), tested against the NIST vectors (empty, abc, the 448-bit and 896-bit messages, a million &lt;code&gt;a&lt;/code&gt;), RFC 4231, Unicode, every byte value and every split point. &lt;code&gt;pbkdf2HmacSha256&lt;/code&gt; and &lt;code&gt;pbkdf2HmacSha512&lt;/code&gt; (RFC 8018, bytes or text, over &lt;code&gt;sysl.crypto&lt;/code&gt;‘s PBKDF2 through a runtime shim, trapping on fewer than one iteration or a length outside 1 to 255 digests), &lt;code&gt;saslPrep&lt;/code&gt; (RFC 4013 over RFC 3454’s tables, generated from the RFC by &lt;code&gt;scripts/stringprep_tables.avin&lt;/code&gt;; NFKC, prohibited and Unicode 3.2-unassigned code points, the bidirectional rule; tested on the RFC’s examples and every table’s edges), &lt;code&gt;string.normalize(form)&lt;/code&gt; and &lt;code&gt;isNormalized(form)&lt;/code&gt; for &lt;code&gt;Nfc&lt;/code&gt;, &lt;code&gt;Nfd&lt;/code&gt;, &lt;code&gt;Nfkc&lt;/code&gt; and &lt;code&gt;Nfkd&lt;/code&gt; (&lt;code&gt;NormalizationForm&lt;/code&gt;, a mirror of &lt;code&gt;sysl.unicode.Form&lt;/code&gt;, Unicode 17.0.0; every line of &lt;code&gt;NormalizationTest.txt&lt;/code&gt; in all four forms, and every code point it does not list), &lt;code&gt;real&lt;/code&gt;‘s IEEE 754 encodings &lt;code&gt;toBits&lt;/code&gt; and &lt;code&gt;real.fromBits&lt;/code&gt; (binary64, NaN payloads kept) and &lt;code&gt;toBits32&lt;/code&gt; and &lt;code&gt;real.fromBits32&lt;/code&gt; (binary32, widened exactly, narrowed to nearest, ties to even), and &lt;code&gt;avin.uuid&lt;/code&gt;‘s &lt;code&gt;Uuid&lt;/code&gt; (a 128-bit value: &lt;code&gt;parse&lt;/code&gt; of the canonical form, &lt;code&gt;random&lt;/code&gt; version 4, &lt;code&gt;fromBytes&lt;/code&gt;, &lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;version&lt;/code&gt;, &lt;code&gt;variant&lt;/code&gt;, lower-case display, ordering by unsigned bytes, a &lt;code&gt;Map&lt;/code&gt; key, sendable, and a &lt;code&gt;FromParam&lt;/code&gt; for HTTP parameters), tested against the RFC 7914 and well-known PBKDF2 vectors and the RFC 9562 examples. The security primitives an API server needs: &lt;code&gt;constantTimeEquals&lt;/code&gt; in &lt;code&gt;avin.crypto&lt;/code&gt; for bytes and text, over &lt;code&gt;sysl.crypto.verify&lt;/code&gt;; &lt;a href=&quot;/spec/system-library/#avinencoding&quot;&gt;&lt;code&gt;avin.encoding&lt;/code&gt;&lt;/a&gt;, written in Avin, with &lt;code&gt;toHex&lt;/code&gt; (moved from &lt;code&gt;avin.crypto&lt;/code&gt;, which exports it) and the strict decoders &lt;code&gt;fromHex&lt;/code&gt;, &lt;code&gt;fromBase64&lt;/code&gt; and &lt;code&gt;fromBase64Url&lt;/code&gt; beside &lt;code&gt;toBase64&lt;/code&gt; and &lt;code&gt;toBase64Url&lt;/code&gt;, refusing with a &lt;code&gt;DecodeError&lt;/code&gt; at a byte offset, tested against RFC 4648’s vectors, every padding case, every ASCII character, every unused-bit pattern and round trips over random bytes; and &lt;a href=&quot;/spec/system-library/#securerandom&quot;&gt;&lt;code&gt;SecureRandom&lt;/code&gt;&lt;/a&gt; in &lt;code&gt;avin.random&lt;/code&gt;, every draw from &lt;code&gt;getentropy&lt;/code&gt;, with &lt;code&gt;Random&lt;/code&gt;‘s drawing methods and &lt;code&gt;hexToken&lt;/code&gt;/&lt;code&gt;urlToken&lt;/code&gt;. &lt;code&gt;Url&lt;/code&gt; in &lt;code&gt;avin.net&lt;/code&gt;, written in Avin: &lt;code&gt;Url.parse&lt;/code&gt; answering a &lt;code&gt;Result&lt;/code&gt; with a &lt;code&gt;UrlError&lt;/code&gt; and the trapping &lt;code&gt;Url(text)&lt;/code&gt;, every component (user information, IPv4, IPv6 with a zone and later-form hosts in brackets, empty kept apart from absent), escapes checked to decode to UTF-8 through &lt;code&gt;string.fromUtf8&lt;/code&gt;, the scheme and host held in lower case and a default port left out, &lt;code&gt;portOrDefault&lt;/code&gt;, &lt;code&gt;queryParams&lt;/code&gt;, &lt;code&gt;encode&lt;/code&gt; and &lt;code&gt;decode&lt;/code&gt;, &lt;code&gt;resolve&lt;/code&gt; by RFC 3986 §5.2 with dot-segment removal, and the &lt;code&gt;with&lt;/code&gt; methods; the library’s tests hold RFC 3986’s normal and abnormal resolution examples. The futures’ additions in &lt;code&gt;avin.threads&lt;/code&gt;: &lt;code&gt;Future.traverse&lt;/code&gt;, calling its function in order on the calling thread, over &lt;code&gt;Future.all&lt;/code&gt;; &lt;code&gt;mapErr&lt;/code&gt; and &lt;code&gt;orElse&lt;/code&gt; (by-name, widening as &lt;code&gt;Result.orElse&lt;/code&gt; does) on a future of a &lt;code&gt;Result&lt;/code&gt;; &lt;code&gt;Executor&lt;/code&gt;, &lt;code&gt;fixed(n)&lt;/code&gt; keeping at most &lt;code&gt;n&lt;/code&gt; tasks working and &lt;code&gt;shared()&lt;/code&gt;, with &lt;code&gt;future(body)&lt;/code&gt;, &lt;code&gt;shutdown()&lt;/code&gt; (a new body afterwards trapping, the functions of futures made before still running) and &lt;code&gt;isShutdown()&lt;/code&gt;, every future running its &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt; on the executor it was made on, each worker enrolled by its thread’s identity so a wait on it finds its pool; &lt;code&gt;blocking(body)&lt;/code&gt;, counting a worker as waiting once however nested, as &lt;code&gt;await&lt;/code&gt; does; and &lt;code&gt;sleep(d: Duration)&lt;/code&gt;, a runtime function over Sysl’s &lt;code&gt;sleep&lt;/code&gt; bound &lt;code&gt;blocking&lt;/code&gt;. A delayed argument may yield a subtype of what its by-name parameter yields, also through a companion’s &lt;code&gt;apply&lt;/code&gt; called by its type’s name, and what it yields decides the call’s type arguments, those held to a lower bound included. TCP in &lt;code&gt;avin.net&lt;/code&gt;, written in Avin over a runtime &lt;code&gt;Connection&lt;/code&gt; holding &lt;code&gt;sysl.net&lt;/code&gt;‘s socket, with a destructor that closes it: &lt;code&gt;TcpStream.connect&lt;/code&gt; trying each resolved address, &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;readLine&lt;/code&gt; and &lt;code&gt;readAll&lt;/code&gt; sharing the bytes read ahead, &lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;shutdownOutput&lt;/code&gt; and &lt;code&gt;close&lt;/code&gt;; &lt;code&gt;TcpListener.bind&lt;/code&gt; (port 0 choosing one), &lt;code&gt;port&lt;/code&gt;, &lt;code&gt;accept&lt;/code&gt; and &lt;code&gt;close&lt;/code&gt;; every wait a blocking binding, a connection’s failures &lt;code&gt;ConnectionRefused&lt;/code&gt;, &lt;code&gt;ConnectionReset&lt;/code&gt; and &lt;code&gt;TimedOut&lt;/code&gt; in &lt;code&gt;IoError&lt;/code&gt;, and a connection handed to the thread or future that serves it. Unix domain sockets in &lt;code&gt;avin.net&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;UnixListener&lt;/code&gt; (&lt;code&gt;bind&lt;/code&gt;, &lt;code&gt;bindReplacing&lt;/code&gt;, &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;accept&lt;/code&gt;, &lt;code&gt;close&lt;/code&gt;) over &lt;code&gt;sysl.net&lt;/code&gt;‘s Unix socket calls, with a &lt;code&gt;TcpStream&lt;/code&gt;‘s reading and writing operations through the read-ahead code the two share, a path too long for the platform, a path in use and a missing path each an &lt;code&gt;Err&lt;/code&gt;. The HTTP/1.1 client in &lt;code&gt;avin.net.http&lt;/code&gt;, written in Avin over it: &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;delete&lt;/code&gt;, &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt; and &lt;code&gt;patch&lt;/code&gt;, each taking headers to send, and &lt;code&gt;send&lt;/code&gt; with a &lt;code&gt;Request&lt;/code&gt; (its headers checked as it is made, &lt;code&gt;withHeaders&lt;/code&gt;, &lt;code&gt;withQueryParam&lt;/code&gt;), &lt;code&gt;Response.json&lt;/code&gt; for a handler’s JSON text, bodies by &lt;code&gt;Content-Length&lt;/code&gt;, chunked or to the connection’s end, interim responses skipped, up to five redirects of a &lt;code&gt;GET&lt;/code&gt; or &lt;code&gt;HEAD&lt;/code&gt; resolved by &lt;code&gt;Url.resolve&lt;/code&gt;, &lt;code&gt;HttpError&lt;/code&gt;; the corpus serves it from a server written in the test. TLS in &lt;code&gt;avin.net.tls&lt;/code&gt; over the Sysl package &lt;code&gt;openssl&lt;/code&gt; 0.2.2, which the library names in &lt;code&gt;library/library.hocon&lt;/code&gt;, joining a program’s shims only where a binding the program compiles reaches it: &lt;code&gt;TlsStream&lt;/code&gt; at both ends over a &lt;code&gt;TcpStream&lt;/code&gt;, OpenSSL working on memory buffers while the bytes go through the TCP connection’s waits, so its limit and cancellation hold; &lt;code&gt;TlsClient&lt;/code&gt; with &lt;code&gt;trust(pem)&lt;/code&gt; over the machine’s store, host-name checking, SNI and TLS 1.2 at the least always on; &lt;code&gt;TlsServer&lt;/code&gt; from PEM; &lt;code&gt;TlsError&lt;/code&gt; (&lt;code&gt;Transport&lt;/code&gt;, &lt;code&gt;Certificate&lt;/code&gt;, &lt;code&gt;Handshake&lt;/code&gt;, &lt;code&gt;Credentials&lt;/code&gt;); a &lt;code&gt;ByteStream&lt;/code&gt; trait over TCP, Unix and TLS connections; &lt;code&gt;https&lt;/code&gt; URLs in the client (&lt;code&gt;withTls&lt;/code&gt;, redirects across schemes, &lt;code&gt;HttpError.Tls&lt;/code&gt;) and &lt;code&gt;http.serve(…, tls)&lt;/code&gt;; tested with a test authority’s fixtures in &lt;code&gt;tests/fixtures/tls&lt;/code&gt; (untrusted, self-signed, expired and wrong-host certificates refused, a two-mebibyte body each way, keep-alive over TLS, 64 connections at once, a handshake timed out, a parked TLS read cancelled by its scope) and an opt-in &lt;code&gt;tests/network/https_live.avin&lt;/code&gt; against real sites. A blocking binding takes a handle without a destructor as a parameter through a share taken before the call; a variant’s name is checked to be unique across a module’s files. Commands in &lt;code&gt;avin.process&lt;/code&gt;, written in Avin over &lt;code&gt;sysl.process.spawn&lt;/code&gt; and &lt;code&gt;pipe&lt;/code&gt;: a &lt;code&gt;Command&lt;/code&gt; of a program and its arguments (&lt;code&gt;Command(program, args*)&lt;/code&gt;, &lt;code&gt;Command.parse&lt;/code&gt;), with &lt;code&gt;inDir&lt;/code&gt;, &lt;code&gt;withEnv&lt;/code&gt;, &lt;code&gt;clearEnv&lt;/code&gt;, &lt;code&gt;withoutEnv&lt;/code&gt;, &lt;code&gt;withEnvironment&lt;/code&gt; (an ordered list of environment changes, a cleared or trimmed environment built whole and handed over without inheritance, a bare program name looked up on the command’s own &lt;code&gt;PATH&lt;/code&gt; or the system’s default), &lt;code&gt;withTimeout&lt;/code&gt;, &lt;code&gt;toFile&lt;/code&gt;, &lt;code&gt;appendTo&lt;/code&gt;, &lt;code&gt;fromFile&lt;/code&gt; and &lt;code&gt;withInput&lt;/code&gt;, joined by `&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;Done. Designed and settled in &lt;a href=&quot;/spec/actors/&quot;&gt;actors and state machines&lt;/a&gt;. Done: &lt;code&gt;Sendable&lt;/code&gt; in the core library, decided by the checker for every type from its structure (scalars, &lt;code&gt;unit&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt;; tuples and data types of sendable fields, recursive ones included; final classes and objects with no &lt;code&gt;var&lt;/code&gt; and sendable fields; type parameters bounded by it; Sysl handles; not &lt;code&gt;Any&lt;/code&gt;, function values, &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; classes, or traits that make no promise), held as a bound where a type is named and at each generic call, a field typed by its initializer held once it is known; the promise of &lt;code&gt;: Sendable&lt;/code&gt; in a trait’s or a class’s header or an impl, checked against the structure outside the standard library, an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class’s at each subclass, a generic trait’s at sendable arguments; the standard library’s promises for &lt;code&gt;Future&lt;/code&gt;, &lt;code&gt;Promise&lt;/code&gt;, &lt;code&gt;Channel&lt;/code&gt; and &lt;code&gt;Atomic&lt;/code&gt; of sendable values, &lt;code&gt;Mutex&lt;/code&gt; of any, &lt;code&gt;Once&lt;/code&gt; and &lt;code&gt;Vector&lt;/code&gt;, and the immutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; traits; and diagnostics naming the field, variant, part or type argument that is not sendable and what to do; and &lt;code&gt;Sendable&lt;/code&gt; held where values cross threads today: the &lt;code&gt;@sendable&lt;/code&gt; and &lt;code&gt;@isolated&lt;/code&gt; parameter marks, checked by what a closure, a by-name argument or a method value captures (a &lt;code&gt;var&lt;/code&gt; never, for &lt;code&gt;@sendable&lt;/code&gt;) and by what any other argument reads, on the bodies of &lt;code&gt;spawn&lt;/code&gt;, &lt;code&gt;s.spawn&lt;/code&gt;, &lt;code&gt;Future&lt;/code&gt; and &lt;code&gt;ex.future&lt;/code&gt; and the functions of &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;onComplete&lt;/code&gt; and &lt;code&gt;orElse&lt;/code&gt;, with their results, a promise’s value and &lt;code&gt;Future.successful&lt;/code&gt;‘s sendable; a mutex’s value and its &lt;code&gt;with&lt;/code&gt; body &lt;code&gt;@isolated&lt;/code&gt; (now &lt;code&gt;@isolating&lt;/code&gt;, below), &lt;code&gt;with&lt;/code&gt;‘s result and &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; sendable; a mark an override adds rejected; and the library’s promises for &lt;code&gt;Thread&lt;/code&gt;, &lt;code&gt;Executor&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt;, &lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;TcpListener&lt;/code&gt; and a started &lt;code&gt;Child&lt;/code&gt;, every operation of each of the last three checking a handle’s owner first (a child through a runtime token holding nothing but its owner), so a read served from the bytes a connection read ahead, a closed one, and a child whose command has ended trap in the code that handed them over; and the whole-program check that what is passed for a &lt;code&gt;@sendable&lt;/code&gt; parameter, directly or through every function, implementation, closure and extractor it reaches, touches no module-level &lt;code&gt;var&lt;/code&gt; and reads no module-level value, &lt;code&gt;lazy val&lt;/code&gt; or object whose type is not sendable, the error naming the item and the path to it, with the library’s worker registry and &lt;code&gt;Annotation&lt;/code&gt; promising &lt;code&gt;Sendable&lt;/code&gt;; and &lt;code&gt;@sendable&lt;/code&gt; function types, &lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt;, which are &lt;code&gt;Sendable&lt;/code&gt; and subtypes of the plain types: a lambda, a function reference or a method value made where one is expected checked there by its captures and the module-level state it reaches, a parameter marked &lt;code&gt;@sendable&lt;/code&gt; holding one, data and classes of &lt;code&gt;@sendable&lt;/code&gt; fields (generic ones and module-level &lt;code&gt;lazy val&lt;/code&gt; grammars among them) sendable, overloads differing only in the mark refused as one, and diagnostics printing the mark; a parameter marked &lt;code&gt;@sendable&lt;/code&gt; sendable inside its function whatever its type (captured by &lt;code&gt;@sendable&lt;/code&gt; lambdas, passed on unchecked), what is passed for one of another type being a &lt;code&gt;match&lt;/code&gt; function written in place, a value of a sendable type or a marked parameter or class &lt;code&gt;val&lt;/code&gt; field, or &lt;code&gt;orElse&lt;/code&gt; of such partial functions (the standard library’s &lt;code&gt;@sendable_result&lt;/code&gt; promise), chains of it included; and a lambda or a &lt;code&gt;match&lt;/code&gt; function passed for a type argument bounded by &lt;code&gt;Sendable&lt;/code&gt; made as a &lt;code&gt;@sendable&lt;/code&gt; function, a &lt;code&gt;match&lt;/code&gt; function where a &lt;code&gt;PartialFunction&lt;/code&gt; is expected meeting the bound where every value the call gives of the type argument is one; and &lt;code&gt;machine&lt;/code&gt; and &lt;code&gt;state&lt;/code&gt; declarations, needing no runtime: a machine read into its &lt;code&gt;Door.State&lt;/code&gt; data type, a variant per state holding its parameters and taking the machine’s type parameters, and a final class of the machine’s parameters, fields and methods, generic ones included; arms yielding the next state or &lt;code&gt;stay&lt;/code&gt;, in any branch of an arm’s value; &lt;code&gt;enter&lt;/code&gt; and &lt;code&gt;leave&lt;/code&gt;, &lt;code&gt;leave&lt;/code&gt; first, on every transition, a self-transition included, and the first state’s &lt;code&gt;enter&lt;/code&gt; after the body; the per-state coverage check of a state’s own arms and the shared &lt;code&gt;receive&lt;/code&gt; ones, naming the state, the machine and every case left out; &lt;code&gt;handle&lt;/code&gt; and &lt;code&gt;state()&lt;/code&gt;; the trap on handling from inside an arm, &lt;code&gt;enter&lt;/code&gt; or &lt;code&gt;leave&lt;/code&gt;; &lt;code&gt;Door.State&lt;/code&gt; named in its module, by an import of &lt;code&gt;Door&lt;/code&gt; and through the module, private with a private machine; and a machine reported as not sendable; and the actor runtime, in &lt;code&gt;avin.actors&lt;/code&gt;: &lt;code&gt;Behaviour[M](name, start)&lt;/code&gt;, its start a &lt;code&gt;@sendable&lt;/code&gt; function run on the first turn that makes the state and gives back the handler, &lt;code&gt;spawn&lt;/code&gt; on the shared pool or a given executor handing the behaviour’s handles to the actor, &lt;code&gt;ActorRef[-M]&lt;/code&gt; contravariant, sendable, equal and hashed by the actor and shown &lt;code&gt;Name#n&lt;/code&gt;, and &lt;code&gt;tell&lt;/code&gt;, which never waits; an actor record per actor with a lock-free mailbox (senders swap in the newest node, the actor alone takes the oldest), so one sender’s messages arrive in order; an actor queued on its executor by the send that finds it idle and never run on two threads at once, a turn handling at most 16 messages before the actor goes to the back of the queue, the worker’s owner word set to the actor’s for each turn so its handles work on any worker; actors on a shut-down executor still running; and &lt;code&gt;Executor.execute&lt;/code&gt;, a task with no future and nothing handed over; and &lt;code&gt;actor&lt;/code&gt; declarations, read into a function making the &lt;code&gt;Behaviour&lt;/code&gt; and a hidden class of the actor’s state, needing no runtime of their own: parameters with defaults, named arguments, &lt;code&gt;var&lt;/code&gt; and repeated ones, each held to &lt;code&gt;Sendable&lt;/code&gt; where the actor is declared (a &lt;code&gt;@sendable&lt;/code&gt; one exempt), and the message type where it is written after &lt;code&gt;receives&lt;/code&gt;, reported once and naming the actor; generic actors; the body as the start, its fields and statements run once on the actor’s first turn and its &lt;code&gt;var&lt;/code&gt;s kept across messages; &lt;code&gt;receive&lt;/code&gt; arms as a match’s, each value discarded, checked for exhaustiveness and naming the actor and every case left out; &lt;code&gt;self&lt;/code&gt; the actor’s reference, in the body, arms, methods and lambdas, never the state; the actor’s own private methods with the implicit receiver; the module-level state its body, arms and methods reach refused, the error naming the actor and the methods on the path; actors spawning actors; an actor declared in a module that does not import &lt;code&gt;avin.actors&lt;/code&gt;, private to it when &lt;code&gt;private&lt;/code&gt;; completion offering none of the names the compiler makes for an actor or a machine; and &lt;code&gt;actor&lt;/code&gt;, &lt;code&gt;receives&lt;/code&gt; and &lt;code&gt;receive&lt;/code&gt; keywords only where a declaration, its header and its body place them; and the lifecycle: &lt;code&gt;ActorContext[M]&lt;/code&gt;, which an actor’s state extends and a library-form start makes from its reference, trapping where other code makes or calls it, with &lt;code&gt;stop()&lt;/code&gt; after the message in hand (the mailbox dropped, a message to an ended actor dropped), &lt;code&gt;stop(child)&lt;/code&gt; (trapping for a live actor that is no child), children stopped and waited for before the parent’s &lt;code&gt;stopping&lt;/code&gt; block runs, so a tree ends from its leaves, &lt;code&gt;children()&lt;/code&gt; and &lt;code&gt;parent()&lt;/code&gt; from the runtime’s table of running actors, which gives &lt;code&gt;spawn&lt;/code&gt; the parent; a &lt;code&gt;stopping&lt;/code&gt; block, one per actor, given to the context after the body, and &lt;code&gt;onStopping&lt;/code&gt;; &lt;code&gt;watch&lt;/code&gt; with a message or a &lt;code&gt;@sendable&lt;/code&gt; function of the &lt;code&gt;Ending&lt;/code&gt; (&lt;code&gt;Stopped&lt;/code&gt;, &lt;code&gt;Failed(reason)&lt;/code&gt;), at once for an ended actor, replaced by a second watch, and &lt;code&gt;unwatch&lt;/code&gt;; &lt;code&gt;ref.ended()&lt;/code&gt;, a &lt;code&gt;Future[Ending]&lt;/code&gt;; &lt;code&gt;after&lt;/code&gt; and &lt;code&gt;every&lt;/code&gt; on one timer thread, in the order they fall due, &lt;code&gt;cancel()&lt;/code&gt; from any thread dropping a queued message too, every timer cancelled at the end; an actor’s own method names refused for its fields and methods, and its state never captured by a &lt;code&gt;@sendable&lt;/code&gt; function; and the expected type bounding a contravariant type argument of a call’s result only from below; and &lt;code&gt;ask&lt;/code&gt;, &lt;code&gt;adapter&lt;/code&gt; and &lt;code&gt;pipeToSelf&lt;/code&gt;: &lt;code&gt;ref.ask(r -&amp;gt; Get(r), timeout)&lt;/code&gt; answering a &lt;code&gt;Future[Result[R, AskError]]&lt;/code&gt;, &lt;code&gt;Ok&lt;/code&gt; of the first reply through a one-shot reference shown &lt;code&gt;Reply#n&lt;/code&gt;, &lt;code&gt;TimedOut&lt;/code&gt; from the actors’ timer thread and &lt;code&gt;Ended&lt;/code&gt; where the question could not be delivered; &lt;code&gt;adapter(f)&lt;/code&gt; translating another protocol into the actor’s mailbox at the send, the adapter equal to the actor’s &lt;code&gt;self&lt;/code&gt;; &lt;code&gt;pipeToSelf(future, f)&lt;/code&gt; delivering a future’s value as a message, at once for a future complete already; and a lambda’s parameter of a known shape with an open type argument (&lt;code&gt;Promise[T]&lt;/code&gt;, &lt;code&gt;ActorRef[R]&lt;/code&gt;) taking that argument from its body, so a request-style call infers its reply type; and failure: an actor’s start, messages and &lt;code&gt;stopping&lt;/code&gt; blocks run under a runtime return point, so a trap there is reported naming the actor (&lt;code&gt;avin: trap in Counter#3: …&lt;/code&gt;), its frames dropped back to the worker and the message in hand with them; the program stopped instead, still naming the actor, where a lock (a &lt;code&gt;Mutex&lt;/code&gt;, a &lt;code&gt;Once&lt;/code&gt;), a &lt;code&gt;lazy val&lt;/code&gt;‘s initializer or a Sysl call or callback is in progress, and on a stack overflow; &lt;code&gt;spawn&lt;/code&gt;‘s &lt;code&gt;onFailure: Supervision&lt;/code&gt;, &lt;code&gt;Escalate&lt;/code&gt; by default (the escalating actor halted until its parent’s failure stops it, the program stopped from a top-level one), &lt;code&gt;Stop&lt;/code&gt; (ending &lt;code&gt;Failed(reason)&lt;/code&gt;, watchers told) and &lt;code&gt;Restart(limit, within)&lt;/code&gt; (children stopped and waited for, timers and watches cancelled, the &lt;code&gt;stopping&lt;/code&gt; blocks run and the start run again with the mailbox kept, reported as &lt;code&gt;avin: restarting Counter#3&lt;/code&gt;, escalating past the limit, a negative limit or an empty window trapping in &lt;code&gt;spawn&lt;/code&gt;); a trap in a &lt;code&gt;stopping&lt;/code&gt; block ending the actor &lt;code&gt;Failed&lt;/code&gt;; and the functions of &lt;code&gt;pipeToSelf&lt;/code&gt; and &lt;code&gt;watch&lt;/code&gt; run in the receiving actor’s turn. Step 8, &lt;code&gt;state&lt;/code&gt; blocks in actors, is done: the machine’s desugar shared, a private &lt;code&gt;Counter.State&lt;/code&gt; data type and the current state in the actor’s class, each message matched in the current state against its own arms then the shared &lt;code&gt;receive&lt;/code&gt; arms (optional with states), the next state from each arm’s value, &lt;code&gt;leave&lt;/code&gt; then &lt;code&gt;enter&lt;/code&gt; on a transition, the first state’s &lt;code&gt;enter&lt;/code&gt; after the body (so again on a restart), per-state coverage naming the state and the actor, &lt;code&gt;state()&lt;/code&gt; the actor’s own, and an ending running &lt;code&gt;stopping&lt;/code&gt; but no &lt;code&gt;leave&lt;/code&gt;. Step 9, ownership crossing between actors, is done: a message’s Sysl handles that the sender owns handed to the receiving actor as it enters the mailbox (the sender’s later use trapping, a handle sent twice going with the first message, a dropped message leaving them the sender’s, a receiver passing them on), walked only for message types that can hold a handle (&lt;code&gt;holds_handles&lt;/code&gt;, decided per type), the walk of every hand-over stopping at the standard library’s types shared between owners (&lt;code&gt;@keeps_owners&lt;/code&gt;, carried in the type record); &lt;code&gt;Isolated[T]&lt;/code&gt; in &lt;code&gt;avin.actors&lt;/code&gt;, made by &lt;code&gt;isolate&lt;/code&gt; (a by-name body, in place or as a trailing block), &lt;code&gt;take&lt;/code&gt; once by one atomic compare-and-set, &lt;code&gt;with&lt;/code&gt; holding the objects while its function runs, each misuse trapping; and the &lt;code&gt;@isolating&lt;/code&gt; mark on &lt;code&gt;isolate&lt;/code&gt;‘s body and &lt;code&gt;with&lt;/code&gt;‘s function: only sendable values from around it and, through the whole program, no module-level mutable state reached, across modules, trait implementations, methods, generic instances and closures made in the body; and the same mark on a mutex’s value and its &lt;code&gt;with&lt;/code&gt; body, so neither can leave the guarded value in module-level state; and the standard patterns in &lt;code&gt;avin.actors&lt;/code&gt;: &lt;code&gt;Router.pool&lt;/code&gt; with &lt;code&gt;RoundRobin&lt;/code&gt;, &lt;code&gt;AtRandom&lt;/code&gt;, &lt;code&gt;SmallestMailbox&lt;/code&gt; (a counted mailbox for routees) and &lt;code&gt;ByKey&lt;/code&gt; (highest-weight hashing, so a routee leaving moves only its own keys), its routees supervised as a group and re-routing a message a routee no longer accepts; &lt;code&gt;Stash&lt;/code&gt;, whose &lt;code&gt;unstashAll&lt;/code&gt; puts its messages in front of the mailbox, a full stash trapping; and &lt;code&gt;Topic&lt;/code&gt;, publish and subscribe from any thread, a subscriber’s end dropping it; and bounded mailboxes: &lt;code&gt;mailbox = Bounded(capacity, overflow)&lt;/code&gt; on &lt;code&gt;spawn&lt;/code&gt; and &lt;code&gt;Router.pool&lt;/code&gt; (a locked queue for a bounded actor, the lock-free one kept for the rest), a full one’s &lt;code&gt;tell&lt;/code&gt; dropping the newest or the oldest and counting it in &lt;code&gt;dropped()&lt;/code&gt;, &lt;code&gt;offer&lt;/code&gt; answering &lt;code&gt;Full&lt;/code&gt; at once, &lt;code&gt;send&lt;/code&gt; waiting for room (timed, a cancellation point leaving nothing behind, &lt;code&gt;Ended&lt;/code&gt; where the actor ends first), an ask of a full mailbox answering &lt;code&gt;Full&lt;/code&gt;, the notices, timers’ and piped messages an actor arranged for itself outside the bound, and a pool’s router waiting for room in its routees. All of stage 12’s steps are done.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;In progress. Designed in &lt;a href=&quot;/spec/c-bindings/&quot;&gt;C bindings&lt;/a&gt;, its choices proposed in &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;decisions&lt;/a&gt;. The stressors are two new repositories, &lt;code&gt;avin-lang/mlt&lt;/code&gt;, binding MLT 7 (&lt;code&gt;mlt-framework-7&lt;/code&gt;), and &lt;code&gt;avin-lang/cairo&lt;/code&gt;, binding Cairo 1.18 (&lt;code&gt;cairo&lt;/code&gt;, &lt;code&gt;cairo-pdf&lt;/code&gt;, &lt;code&gt;cairo-svg&lt;/code&gt;) to the surface of the reference binding, each step unlocking a piece of both. A third, &lt;code&gt;avin-lang/freetype&lt;/code&gt;, binds FreeType 2 (&lt;code&gt;freetype2&lt;/code&gt;) to the reference binding’s surface, and &lt;code&gt;avin-lang/cairo&lt;/code&gt; depends on it for its FreeType font faces (&lt;code&gt;cairo-ft&lt;/code&gt;); its lacks are &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt; from the FreeType survey. Cairo is single-threaded and never waits, so it needs neither &lt;code&gt;blocking&lt;/code&gt; nor &lt;code&gt;@threaded&lt;/code&gt;, and it writes files whose pixels a test reads back: it is the earlier stressor, drawing its first PNG and PDF at step 3, where MLT renders first at step 6; MLT carries &lt;code&gt;as:&lt;/code&gt;, &lt;code&gt;blocking&lt;/code&gt; and C threads. Built in this order. Done: (1) &lt;code&gt;c-libraries&lt;/code&gt; in the manifest (&lt;code&gt;pkg-config&lt;/code&gt;, &lt;code&gt;link&lt;/code&gt;, &lt;code&gt;headers&lt;/code&gt;, &lt;code&gt;install&lt;/code&gt;), gathered over the dependency graph and linked into every program, statically from their archives under the root package’s &lt;code&gt;static-c-libraries = true&lt;/code&gt; (&lt;code&gt;pkg-config --static&lt;/code&gt;, archive paths, the system’s libraries kept dynamic, a missing archive an error), and chosen library by library in &lt;code&gt;c-linking&lt;/code&gt; (&lt;code&gt;default&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt;, &lt;code&gt;dynamic&lt;/code&gt;, &lt;code&gt;static-system&lt;/code&gt;, &lt;code&gt;search&lt;/code&gt;; &lt;code&gt;--static-c-libraries&lt;/code&gt;/&lt;code&gt;--dynamic-c-libraries&lt;/code&gt;; a library’s &lt;code&gt;files&lt;/code&gt;, &lt;code&gt;search&lt;/code&gt;, &lt;code&gt;include&lt;/code&gt;, &lt;code&gt;frameworks&lt;/code&gt;, &lt;code&gt;link-flags&lt;/code&gt; and &lt;code&gt;dynamic-only&lt;/code&gt;), a library’s own C &lt;code&gt;sources&lt;/code&gt; compiled with its &lt;code&gt;cflags&lt;/code&gt; and linked into the program (cached by text, flags and headers, once per build), and the C unit compiled by clang with the header check for top-level &lt;code&gt;@c&lt;/code&gt; bindings of scalars (every C integer type and typedef measured and checked, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;) and &lt;code&gt;unit&lt;/code&gt;, called directly and declared with &lt;code&gt;signext&lt;/code&gt;/&lt;code&gt;zeroext&lt;/code&gt; — unlocks the &lt;code&gt;avin-lang/mlt&lt;/code&gt; manifest and its &lt;code&gt;pkg-config&lt;/code&gt; probe, and &lt;code&gt;mlt_version_get_int&lt;/code&gt;, &lt;code&gt;get_major&lt;/code&gt;, &lt;code&gt;get_minor&lt;/code&gt; and &lt;code&gt;get_revision&lt;/code&gt;; for Cairo, the manifest’s three modules, &lt;code&gt;cairo_version&lt;/code&gt; and &lt;code&gt;cairo_format_stride_for_width&lt;/code&gt;; tested against the C library, libm, zlib through &lt;code&gt;pkg-config&lt;/code&gt;, a library package binding zlib that a program uses without naming it, and a C fixture in &lt;code&gt;tests/c&lt;/code&gt; the corpus builds and names to &lt;code&gt;pkg-config&lt;/code&gt;, covering every scalar width, sign and typedef, every checked conversion’s trap at its boundaries and every diagnostic of the header check, at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; under GC stress; (2) an integer bound as &lt;code&gt;bool&lt;/code&gt; (Cairo’s &lt;code&gt;cairo_bool_t&lt;/code&gt;: zero false, any other value true at the C type’s full width, a &lt;code&gt;bool&lt;/code&gt; passed as &lt;code&gt;0&lt;/code&gt;/&lt;code&gt;1&lt;/code&gt;; a typedef crossing as &lt;code&gt;bool&lt;/code&gt; checked to be a C &lt;code&gt;bool&lt;/code&gt; or an integer); strings, &lt;code&gt;const char *&lt;/code&gt; in from a &lt;code&gt;string&lt;/code&gt; or an &lt;code&gt;Option[string]&lt;/code&gt; (null for &lt;code&gt;None&lt;/code&gt;) copied into NUL-terminated memory off the heap, held until the result is converted, a held NUL trapping at its byte; &lt;code&gt;char *&lt;/code&gt; and &lt;code&gt;const char *&lt;/code&gt; out copied into a &lt;code&gt;string&lt;/code&gt; and UTF-8-checked (an ill-formed sequence trapping at its byte), or into an &lt;code&gt;Array[byte]&lt;/code&gt; unchecked, each perhaps in an &lt;code&gt;Option&lt;/code&gt; for null and trapping on null otherwise; borrowed results left to C, and &lt;code&gt;free:&lt;/code&gt; naming the function that frees one, checked by the C unit to take a pointer and answer nothing; string typedefs checked to be &lt;code&gt;char *&lt;/code&gt;/&lt;code&gt;const char *&lt;/code&gt; — unlocks &lt;code&gt;mlt_version_get_string&lt;/code&gt;, &lt;code&gt;mlt_environment&lt;/code&gt; and &lt;code&gt;mlt_factory_directory&lt;/code&gt;; for Cairo, &lt;code&gt;cairo_version_string&lt;/code&gt;, &lt;code&gt;cairo_status_to_string&lt;/code&gt; and &lt;code&gt;cairo_pdf_version_to_string&lt;/code&gt;; tested against the C fixture (every UTF-8 width, empty and long strings, held NULs, every kind of ill-formed UTF-8, nulls both ways, counted frees over many calls under GC stress, truth values from 0, 1, -1, 2 and high bits), the C library’s &lt;code&gt;strlen&lt;/code&gt;, &lt;code&gt;getenv&lt;/code&gt;, &lt;code&gt;strerror&lt;/code&gt;, &lt;code&gt;strchr&lt;/code&gt;, &lt;code&gt;strstr&lt;/code&gt; and &lt;code&gt;strdup&lt;/code&gt;, and zlib’s &lt;code&gt;zlibVersion&lt;/code&gt;, and every new diagnostic of the checker and the C unit. (3) handles: &lt;code&gt;@c(type:, release:, retain:, kept:, shared)&lt;/code&gt;, owned and &lt;code&gt;borrowed&lt;/code&gt; results, the closed and owner checks, &lt;code&gt;close()&lt;/code&gt; and finalizers, handle parameters, &lt;code&gt;Result[unit, int]&lt;/code&gt; status results, &lt;code&gt;keeps:&lt;/code&gt;/&lt;code&gt;consumes:&lt;/code&gt;, and &lt;code&gt;headers&lt;/code&gt; entries named by a macro (&lt;code&gt;&amp;lt;ft2build.h&amp;gt;&lt;/code&gt; then &lt;code&gt;FT_FREETYPE_H&lt;/code&gt;) — unlocks &lt;code&gt;mlt_factory_init&lt;/code&gt; and the repository, profiles, producers, playlists, consumers and the properties bag, enough to build the two-clip playlist; for Cairo, &lt;code&gt;Surface&lt;/code&gt;, &lt;code&gt;Context&lt;/code&gt;, &lt;code&gt;Pattern&lt;/code&gt;, &lt;code&gt;FontOptions&lt;/code&gt;, &lt;code&gt;FontFace&lt;/code&gt; and &lt;code&gt;ScaledFont&lt;/code&gt; over &lt;code&gt;cairo_*_reference&lt;/code&gt;/&lt;code&gt;destroy&lt;/code&gt;, the borrowed &lt;code&gt;get_target&lt;/code&gt;, &lt;code&gt;get_source&lt;/code&gt;, &lt;code&gt;get_group_target&lt;/code&gt; and &lt;code&gt;get_scaled_font&lt;/code&gt;, every drawing, path, clip, group, transform-by-scalars and toy-text call, &lt;code&gt;write_to_png&lt;/code&gt; to a file, the PDF surface with its metadata, outline, page labels and tags (flags and enums as integers) — enough to draw the reference program’s &lt;code&gt;setsourcergba.png&lt;/code&gt; and &lt;code&gt;tagged.pdf&lt;/code&gt;; for FreeType, the manifest’s macro-named headers, &lt;code&gt;FT_Error_String&lt;/code&gt; as &lt;code&gt;Option[string]&lt;/code&gt; (null where FreeType is built without error strings, as Homebrew’s is), &lt;code&gt;Library&lt;/code&gt; (&lt;code&gt;FT_Done_Library&lt;/code&gt;/&lt;code&gt;FT_Reference_Library&lt;/code&gt;) and &lt;code&gt;Face&lt;/code&gt; (&lt;code&gt;FT_Done_Face&lt;/code&gt;/&lt;code&gt;FT_Reference_Face&lt;/code&gt;) declared, kept handles held by a C reference given back after the holder’s &lt;code&gt;release&lt;/code&gt;, &lt;code&gt;keeps:&lt;/code&gt; lists, &lt;code&gt;kept:&lt;/code&gt; names in &lt;code&gt;release:&lt;/code&gt;, handle classes of another package in a binding (with that package’s headers and flags), and the scalar and status calls &lt;code&gt;FT_Set_Char_Size&lt;/code&gt; (26.6), &lt;code&gt;FT_Set_Pixel_Sizes&lt;/code&gt;, &lt;code&gt;FT_Load_Char&lt;/code&gt;, &lt;code&gt;FT_Load_Glyph&lt;/code&gt;, &lt;code&gt;FT_Get_Char_Index&lt;/code&gt; and &lt;code&gt;FT_Set_Named_Instance&lt;/code&gt; — callable once a face is made, at (5); built as handle classes whose objects hold their C pointer, owner, the C references they keep and the Avin objects they keep, given back by &lt;code&gt;close()&lt;/code&gt; or the collector’s finalizer through the C unit’s glue, methods bound with the receiver as &lt;code&gt;self&lt;/code&gt;, handles of another package checked after that package’s headers, a kept handle’s own C references taken by its holder too; tested against counted C objects in &lt;code&gt;tests/c&lt;/code&gt; that stop the process on a double free or a use after free (&lt;code&gt;tests/c/handles&lt;/code&gt;, &lt;code&gt;tests/c/shapes&lt;/code&gt; over the first’s handles with its declarations named by a macro, and &lt;code&gt;tests/c/handle_tests&lt;/code&gt;), covering close then use, double close, borrowed references, null as &lt;code&gt;None&lt;/code&gt;, statuses at every width, sign and an enumeration, keeps of a list and of &lt;code&gt;self&lt;/code&gt;, &lt;code&gt;kept:&lt;/code&gt; names, consumed handles, owner checks across threads and &lt;code&gt;shared&lt;/code&gt;, handles in data values and vectors, 10,000 handles finalized exactly once, both orders of a holder and what it keeps dying in one collection, at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; under GC stress, and every new diagnostic of the checker and the C unit. (4) &lt;code&gt;as:&lt;/code&gt; conversions between handle types, expression glue and field accessors — unlocks the &lt;code&gt;Object&lt;/code&gt; property bag on every MLT type, &lt;code&gt;Profile&lt;/code&gt;‘s fields, &lt;code&gt;Playlist.clip&lt;/code&gt; and &lt;code&gt;Tractor.track&lt;/code&gt;; field accessors over expressions with &lt;code&gt;bound:&lt;/code&gt; indices — unlocks Cairo’s &lt;code&gt;cairo_copy_path&lt;/code&gt;/&lt;code&gt;copy_path_flat&lt;/code&gt; walked into &lt;code&gt;PathElement&lt;/code&gt; data and &lt;code&gt;cairo_copy_clip_rectangle_list&lt;/code&gt;; for FreeType, &lt;code&gt;as: [&amp;quot;FT_GlyphSlot = self-&amp;gt;glyph&amp;quot;]&lt;/code&gt; for &lt;code&gt;FT_Render_Glyph&lt;/code&gt;, the face’s fields (&lt;code&gt;num_faces&lt;/code&gt;, &lt;code&gt;num_glyphs&lt;/code&gt;, &lt;code&gt;family_name&lt;/code&gt; and &lt;code&gt;style_name&lt;/code&gt; as &lt;code&gt;Option[string]&lt;/code&gt;, &lt;code&gt;units_per_EM&lt;/code&gt;, &lt;code&gt;ascender&lt;/code&gt;, &lt;code&gt;descender&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;face_flags&lt;/code&gt;, &lt;code&gt;size-&amp;gt;metrics&lt;/code&gt; in 26.6) and the glyph slot’s through field expressions (&lt;code&gt;glyph-&amp;gt;bitmap.rows&lt;/code&gt;, &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;pitch&lt;/code&gt; — negative for a bottom-up bitmap — &lt;code&gt;pixel_mode&lt;/code&gt;, &lt;code&gt;bitmap_left&lt;/code&gt;, &lt;code&gt;bitmap_top&lt;/code&gt;, &lt;code&gt;advance&lt;/code&gt;, &lt;code&gt;metrics&lt;/code&gt;), and the variation descriptor’s axes and named styles with &lt;code&gt;bound:&lt;/code&gt; indices; built as conversions made at the call, after the closed and owner checks, through the C unit’s glue, each checked by clang to make the type its entry names, and field accessors reading &lt;code&gt;self-&amp;gt;&lt;/code&gt; the field through glue whose field type the C unit names, checks and measures, every index passed as a &lt;code&gt;long long&lt;/code&gt; and checked against its bound before the read, scalars written at the field’s own width; tested against a counted chain of structs in &lt;code&gt;tests/c&lt;/code&gt; (&lt;code&gt;avin_fields.h&lt;/code&gt;, &lt;code&gt;tests/c/fields&lt;/code&gt; and &lt;code&gt;tests/c/field_tests&lt;/code&gt;) passed up two steps through a function and an expression, lending and staying the owner, closed and other-thread handles stopping at the call, &lt;code&gt;None&lt;/code&gt; passed as null, &lt;code&gt;keeps:&lt;/code&gt; and &lt;code&gt;consumes:&lt;/code&gt; of a converted handle and another package’s bindings through the declaring package’s glue, and a record whose fields of every integer width and sign at their least and greatest, truth values, a byte, &lt;code&gt;float&lt;/code&gt; and &lt;code&gt;double&lt;/code&gt;, strings (every UTF-8 width, null as &lt;code&gt;None&lt;/code&gt; or a stop, ill-formed UTF-8), nested structs, a struct through a pointer, a bounded array by an &lt;code&gt;int&lt;/code&gt; and a &lt;code&gt;long&lt;/code&gt;, a two-dimensional array, an array of a union and one of strings, and lent handles of its own and another package are read, and scalars written (each conversion’s trap at its boundary), indices at the first, the last, -1 and the bound, handles from conversions and fields finalized exactly once at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; under GC stress, and every new diagnostic of the checker and the C unit. (5) enum mirrors (upper-case prefixes too), &lt;code&gt;@c(const:)&lt;/code&gt; values (integer, &lt;code&gt;real&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt;), enum statuses as &lt;code&gt;Result[unit, E]&lt;/code&gt;, and &lt;code&gt;out&lt;/code&gt;/&lt;code&gt;inout&lt;/code&gt; parameters joined into the result — unlocks &lt;code&gt;ImageFormat&lt;/code&gt;, &lt;code&gt;AudioFormat&lt;/code&gt;, &lt;code&gt;TimeFormat&lt;/code&gt;, &lt;code&gt;mlt_service_get_frame&lt;/code&gt; and timecodes; for Cairo, &lt;code&gt;Status&lt;/code&gt; and the latched-error checks, every enum of the reference (&lt;code&gt;Format&lt;/code&gt;, &lt;code&gt;Operator&lt;/code&gt;, &lt;code&gt;FillRule&lt;/code&gt;, &lt;code&gt;LineCap&lt;/code&gt;, &lt;code&gt;Extend&lt;/code&gt;, &lt;code&gt;PdfVersion&lt;/code&gt;, …), the tag names, &lt;code&gt;get_current_point&lt;/code&gt;, &lt;code&gt;user_to_device&lt;/code&gt; and &lt;code&gt;device_to_user&lt;/code&gt; (&lt;code&gt;inout&lt;/code&gt;), the extents calls and the device offset and scale; for FreeType, &lt;code&gt;FT_Init_FreeType&lt;/code&gt; and &lt;code&gt;FT_New_Face&lt;/code&gt; answering &lt;code&gt;Result[Library, int]&lt;/code&gt; and &lt;code&gt;Result[Face, int]&lt;/code&gt; (the first library and face made, the face keeping its library), &lt;code&gt;FT_Library_Version&lt;/code&gt; as a tuple, &lt;code&gt;FT_Get_MM_Var&lt;/code&gt; answering an &lt;code&gt;MMVar&lt;/code&gt; freed through &lt;code&gt;kept:&lt;/code&gt;, &lt;code&gt;RenderMode&lt;/code&gt; and &lt;code&gt;PixelMode&lt;/code&gt; mirrors, the &lt;code&gt;FT_LOAD_*&lt;/code&gt;, &lt;code&gt;FT_KERNING_*&lt;/code&gt;, &lt;code&gt;FT_FACE_FLAG_*&lt;/code&gt; and &lt;code&gt;FT_Err_*&lt;/code&gt; constants (load flags combined with `&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;14&lt;/td&gt;&lt;td&gt;Done. Lightweight threads, designed in &lt;a href=&quot;/spec/threads/#lightweight-threads&quot;&gt;threads&lt;/a&gt; and &lt;a href=&quot;/spec/decisions/&quot;&gt;decisions&lt;/a&gt;. Done: (1) the allocation chunk belongs to the carrier, the operating system thread a context runs on, so a parked thread holds none; (2) the scheduler core: &lt;code&gt;spawn&lt;/code&gt; and a scope’s &lt;code&gt;s.spawn&lt;/code&gt; start lightweight threads on stacks reserved through &lt;code&gt;sysl.fiber&lt;/code&gt; (8 MiB unless asked, committed as touched, the default size reused; the pages below where a thread stayed parked for a monitor tick, and those of a stack kept for reuse, given back to the system), run by workers about one per processor started as threads become ready, from one ready queue in the order threads became ready; locks, conditions, &lt;code&gt;Mutex&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt;, &lt;code&gt;Once&lt;/code&gt;, channels, joins, futures, promises and the pools’ workers park instead of blocking, timed waits on a timer the monitor thread fires; a thread that overruns its 10 ms slice while another is ready yields at its next poll, the &lt;code&gt;Yield&lt;/code&gt; bit of the poll’s flag beside the collector’s &lt;code&gt;Stop&lt;/code&gt;; a worker held by a blocking call for a tick while threads are ready is replaced by another; &lt;code&gt;main&lt;/code&gt; stays on its own operating system thread; (3) &lt;code&gt;sleep&lt;/code&gt; parks a lightweight thread on a timer, freeing its worker, and the timers that sleeps and timed waits park on are a heap of their waiters, soonest first, each cancelled in one step when its event ends the wait first; (4) an &lt;code&gt;accept&lt;/code&gt;, &lt;code&gt;connect&lt;/code&gt;, read or write on an &lt;code&gt;avin.net&lt;/code&gt; socket, TCP or Unix, that would wait parks its lightweight thread on the runtime’s poller, one &lt;code&gt;sysl.io.poll&lt;/code&gt; set whose own thread makes each waiter ready once its descriptor is, every socket being non-blocking; a connection’s timeout parks on the timers beside it, and &lt;code&gt;main&lt;/code&gt; waits on the descriptor alone; (5) an actor’s turn is a lightweight thread of its own (one given an executor of its own keeps running its turns on that executor’s workers), so a turn that sleeps, awaits, asks or receives parks without holding a worker, a long turn is time-sliced, and the actor still runs one turn at a time; (6) cancellation by &lt;code&gt;scope&lt;/code&gt;: &lt;code&gt;s.cancel()&lt;/code&gt; cancels a scope’s threads, which stop at their next wait (a socket’s among them) or safepoint poll with their frames dropped, running their deferred statements first, and end with no result (&lt;code&gt;Thread.result()&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;), never while holding a lock, initializing a &lt;code&gt;lazy val&lt;/code&gt; or resolving a future they completed; a thread running a scope of its own stops first at that scope, which cancels and waits for its threads; the scope hands back the Sysl handles a cancelled thread reached; (7) main-thread scheduling for the &lt;code&gt;ui&lt;/code&gt; package: &lt;code&gt;isMainThread()&lt;/code&gt;, inboxes made on the main thread whose handlers it runs, &lt;code&gt;post&lt;/code&gt; for sendable work, one queue in the order sent that the frame loop runs at the start of every frame and &lt;code&gt;run&lt;/code&gt; once more as it ends, an &lt;code&gt;ask&lt;/code&gt; that parks its lightweight thread, and &lt;code&gt;run&lt;/code&gt; only on the main thread; threads pinned to the main thread (&lt;code&gt;spawnOnMain&lt;/code&gt;, a scope’s &lt;code&gt;spawnOnMain&lt;/code&gt;, &lt;code&gt;runMainThreads&lt;/code&gt;, &lt;code&gt;isPinnedToMain&lt;/code&gt;), on a main scheduler of their own that the frame loop runs after the posted work and the main thread’s own waits run as its threads become ready, so a pinned thread parks on a future, a channel or an ask without holding a frame and carries on on the main thread, and is named as pinned in the deadlock report; (8) the &lt;a href=&quot;/spec/system-library/#servers&quot;&gt;server library&lt;/a&gt;: &lt;code&gt;TcpServer&lt;/code&gt;, a listener serving each connection in an actor of its own (supervised with &lt;code&gt;Stop&lt;/code&gt;, so a trap ends that connection alone after a &lt;code&gt;failed&lt;/code&gt; hook answers on it) on a pool with a worker per connection it may hold, at most &lt;code&gt;maxConnections&lt;/code&gt; held and the next left unaccepted, a per-connection timeout, and a graceful &lt;code&gt;stop&lt;/code&gt;/&lt;code&gt;join&lt;/code&gt;/&lt;code&gt;shutdown&lt;/code&gt; that closes the listener at once (its parked &lt;code&gt;accept&lt;/code&gt; cancelled) and waits for the connections, and &lt;code&gt;idle&lt;/code&gt;, a connection’s wait for its next piece of work that stopping cancels, so a shutdown closes idle connections at once; and on it &lt;code&gt;http.serve&lt;/code&gt;, HTTP/1.1 with keep-alive and pipelining, bodies by length and chunked, &lt;code&gt;Expect: 100-continue&lt;/code&gt;, read, write and idle timeouts, a bound on the whole of each request from its first byte (&lt;code&gt;requestTimeout&lt;/code&gt;, &lt;code&gt;http_serve_request_timeout.avin&lt;/code&gt;), header and body limits, its waits for a request made through &lt;code&gt;idle&lt;/code&gt;, the refusals &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;408&lt;/code&gt;, &lt;code&gt;413&lt;/code&gt;, &lt;code&gt;414&lt;/code&gt;, &lt;code&gt;417&lt;/code&gt;, &lt;code&gt;431&lt;/code&gt;, &lt;code&gt;500&lt;/code&gt;, &lt;code&gt;501&lt;/code&gt;, &lt;code&gt;503&lt;/code&gt; and &lt;code&gt;505&lt;/code&gt;, and &lt;code&gt;Router&lt;/code&gt; with &lt;code&gt;Route&lt;/code&gt; patterns binding &lt;code&gt;:name&lt;/code&gt; segments, &lt;code&gt;404&lt;/code&gt; and &lt;code&gt;405&lt;/code&gt; with &lt;code&gt;Allow&lt;/code&gt;; &lt;code&gt;examples/http_server.avin&lt;/code&gt;; (9) &lt;a href=&quot;/spec/threads/#diagnostics&quot;&gt;diagnostics&lt;/a&gt;: a deadlock of the whole program, &lt;code&gt;main&lt;/code&gt; waiting without a limit with no lightweight thread running or ready, no timer, no socket wait, no foreign thread attached and no &lt;code&gt;@threaded&lt;/code&gt; callback held, stops the program with &lt;code&gt;avin: trap: deadlock: all threads are waiting&lt;/code&gt; and a line per thread naming what it waits on (a lock, a condition, a join, a channel’s receive or send, a future), idle workers left out; the quit signal writes a thread dump (each thread running, ready, ending or waiting on what and for how long) and the program goes on, unless the program watches the signal. Partial deadlocks are not found, and a dump names no functions; (10) &lt;a href=&quot;/spec/threads/#select&quot;&gt;&lt;code&gt;select&lt;/code&gt;&lt;/a&gt;, the wait on several channels at once: receive arms binding by &lt;code&gt;Some(p)&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt;, a name or nothing, send arms, &lt;code&gt;after&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt;, operands evaluated once in order, a uniformly random choice among ready arms, the runtime’s one-park wait enlisting a link on each channel’s condition with one wake-once token, a notification a select cannot use passed on, every link withdrawn, cancellable and safe for the collector, inside parentheses, nested, and in actors’ turns (syntax and semantics Proposed); &lt;code&gt;stream.readable()&lt;/code&gt; arms beside the channel arms, ready on any &lt;code&gt;threads.Readiness&lt;/code&gt; (every &lt;code&gt;ByteStream&lt;/code&gt;: TCP, Unix and TLS, whose &lt;code&gt;readable()&lt;/code&gt; counts read-ahead bytes, decrypted plaintext and whole records only, the end, a reset and a closed connection) and otherwise waiting on the runtime’s poller under the select’s one wait, its registration withdrawn on every ending, cancellation included, counted as sockets in the thread dump, only the owning thread able to name a connection; &lt;code&gt;sink.writable()&lt;/code&gt; arms on any &lt;code&gt;threads.Writability&lt;/code&gt; (every &lt;code&gt;ByteStream&lt;/code&gt; and &lt;code&gt;StreamWriter&lt;/code&gt;), with &lt;code&gt;writeSome&lt;/code&gt;, TLS’s sending one record and keeping what does not fit for &lt;code&gt;writable()&lt;/code&gt; to send (&lt;code&gt;select_writable.avin&lt;/code&gt;); &lt;code&gt;if&lt;/code&gt; guards on select arms, a false guard leaving its arm absent, and &lt;code&gt;threads.Selector&lt;/code&gt; for a set of channels and streams known at run time, waited on through the select’s own wait (&lt;code&gt;select_guard*.avin&lt;/code&gt;, &lt;code&gt;selector_*.avin&lt;/code&gt;); &lt;code&gt;split()&lt;/code&gt; of a TCP, Unix or TLS connection into a sendable &lt;code&gt;StreamReader&lt;/code&gt; and &lt;code&gt;StreamWriter&lt;/code&gt; used by two threads at once, both parked on one descriptor through the poller’s per-direction waiters, the writer’s close a half-close, a TLS session shared under locks taken from transit and handed back (&lt;code&gt;net_split_tcp_both_ways.avin&lt;/code&gt;, &lt;code&gt;net_split_tls_both_ways.avin&lt;/code&gt;, &lt;code&gt;net_split_half_close.avin&lt;/code&gt;, &lt;code&gt;net_split_reset.avin&lt;/code&gt;, &lt;code&gt;net_split_cancel.avin&lt;/code&gt;). Built on it for API servers: streamed responses (&lt;code&gt;Response.stream&lt;/code&gt;, chunked or of a length given beforehand, close-delimited to an HTTP/1.0 client, each write of a &lt;code&gt;BodyWriter&lt;/code&gt; sent at once and answering &lt;code&gt;Err&lt;/code&gt; once the client has gone or the server stops), server-sent events (&lt;code&gt;Response.events&lt;/code&gt;, an &lt;code&gt;EventWriter&lt;/code&gt; with &lt;code&gt;send&lt;/code&gt;, &lt;code&gt;comment&lt;/code&gt;, &lt;code&gt;retry&lt;/code&gt; and keep-alive comments while it waits), a handler’s waits through &lt;code&gt;untilStopped&lt;/code&gt; on the request and the writers, which a shutdown ends at once, an error page (&lt;code&gt;errors&lt;/code&gt;) for the router’s and the server’s own answers, &lt;code&gt;Result[Response, ToResponse]&lt;/code&gt; handlers so &lt;code&gt;?&lt;/code&gt; ends a handler, typed query and route parameters (&lt;code&gt;queryAs&lt;/code&gt;, &lt;code&gt;queryOption&lt;/code&gt;, &lt;code&gt;paramAs&lt;/code&gt; over &lt;code&gt;FromParam&lt;/code&gt;, a &lt;code&gt;ParamError&lt;/code&gt; answered &lt;code&gt;400&lt;/code&gt;), and &lt;code&gt;Route.group&lt;/code&gt;, &lt;code&gt;under&lt;/code&gt; and &lt;code&gt;wrap&lt;/code&gt; with middleware as functions of &lt;code&gt;Handler&lt;/code&gt;, a middleware handing values on to the handlers inside it through &lt;code&gt;withValue&lt;/code&gt;, read by &lt;code&gt;value[T]()&lt;/code&gt; and keyed by their exact type (&lt;code&gt;http_request_values.avin&lt;/code&gt;); a handler that traps while streaming has its connection closed unanswered (&lt;code&gt;tests/run/http_stream.avin&lt;/code&gt;, &lt;code&gt;http_server_hooks.avin&lt;/code&gt;, &lt;code&gt;http_api.avin&lt;/code&gt;); connection upgrades (&lt;code&gt;Response.upgrade&lt;/code&gt;, a &lt;code&gt;101&lt;/code&gt; handing the connection and the bytes read ahead to the code that carries it on) and &lt;a href=&quot;/spec/system-library/#websockets&quot;&gt;WebSockets&lt;/a&gt; on them, RFC 6455: &lt;code&gt;webSocket(request, session)&lt;/code&gt; checking the handshake (&lt;code&gt;405&lt;/code&gt;, &lt;code&gt;426&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt; refusals, subprotocols by the server’s order) and &lt;code&gt;WebSocket.connect&lt;/code&gt; for &lt;code&gt;ws&lt;/code&gt; and &lt;code&gt;wss&lt;/code&gt;, text and binary messages, fragments put back together, pings answered with pongs, the close handshake with codes and reasons, a message size limit, client frames masked and server frames not, UTF-8 checked, violations closed &lt;code&gt;1002&lt;/code&gt;, &lt;code&gt;1007&lt;/code&gt; and &lt;code&gt;1009&lt;/code&gt;, a stopping server closing its sockets &lt;code&gt;1001&lt;/code&gt; (&lt;code&gt;tests/run/websocket.avin&lt;/code&gt;, &lt;code&gt;websocket_frames.avin&lt;/code&gt;, &lt;code&gt;websocket_tls.avin&lt;/code&gt;); a sendable &lt;code&gt;ws.sender()&lt;/code&gt; whose whole messages queue in a bounded outbox the owning thread writes while it receives, in one &lt;code&gt;select&lt;/code&gt; on its stream’s &lt;code&gt;readable()&lt;/code&gt;, the outbox and the server’s &lt;code&gt;stopped()&lt;/code&gt; channel, never interleaved, large ones fragmented, a full outbox answering &lt;code&gt;Err&lt;/code&gt; at the write timeout, a sender’s close carried out by the owner, and &lt;code&gt;ws.serve(onMessage)&lt;/code&gt; (&lt;code&gt;websocket_chat.avin&lt;/code&gt;, a broadcast chat over &lt;code&gt;ws&lt;/code&gt; and &lt;code&gt;wss&lt;/code&gt;; &lt;code&gt;websocket_sender*.avin&lt;/code&gt;, &lt;code&gt;websocket_slow_client.avin&lt;/code&gt;, &lt;code&gt;websocket_outbox_trap.avin&lt;/code&gt;). (11) &lt;a href=&quot;/spec/threads/#timers-and-deadlines&quot;&gt;Timers and deadlines&lt;/a&gt;: &lt;code&gt;after(d)&lt;/code&gt;, a channel delivering one instant once &lt;code&gt;d&lt;/code&gt; has passed, and &lt;code&gt;Ticker(period)&lt;/code&gt;, ticks a slow receiver misses dropped, &lt;code&gt;stop()&lt;/code&gt;, both holding their due time in the channel rather than a timer or thread, so nothing is left when nobody receives, delivered by the receive or select that looks and woken for by a select’s park; a channel’s &lt;code&gt;receive(timeout)&lt;/code&gt; and &lt;code&gt;send(x, timeout)&lt;/code&gt;; and &lt;code&gt;withTimeout(d, s -&amp;gt; …) -&amp;gt; Option[T]&lt;/code&gt;, the body on a lightweight thread of its own cancelled with its scope’s threads when the time runs out; each a timed wait, never taken for a deadlock (Proposed). The &lt;a href=&quot;/spec/threads/#request-context&quot;&gt;request context&lt;/a&gt;: &lt;code&gt;Context.current()&lt;/code&gt; with its &lt;code&gt;deadline&lt;/code&gt;, &lt;code&gt;remaining()&lt;/code&gt; and &lt;code&gt;value(key)&lt;/code&gt; over typed &lt;code&gt;Key[T]&lt;/code&gt;s, &lt;code&gt;withValue(key, v, body)&lt;/code&gt;, and &lt;code&gt;withDeadline(t, s -&amp;gt; …) -&amp;gt; Result[T, DeadlineExceeded]&lt;/code&gt; beside &lt;code&gt;withTimeout&lt;/code&gt;, both setting the deadline, the sooner one kept; the context lives in a slot of the thread’s runtime context that every collection marks, a scope’s threads taking all of it, a plain thread, a future’s code and an executor’s task its values, and an actor’s turn none.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;In progress (&lt;a href=&quot;/compiler/linux/&quot;&gt;Linux&lt;/a&gt;, 2026-11-19): machine conditions in the manifest (item 2: &lt;code&gt;package.targets&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt; on dependencies, Sysl dependencies, C libraries and features, &lt;code&gt;install&lt;/code&gt; by condition, &lt;code&gt;link-flags&lt;/code&gt;, &lt;code&gt;avin check --target&lt;/code&gt;, &lt;code&gt;avin tidy&lt;/code&gt; and &lt;code&gt;avin vendor&lt;/code&gt; over every target); files for one machine (item 3: &lt;code&gt;name.&amp;lt;symbol&amp;gt;.avin&lt;/code&gt; and &lt;code&gt;.lavin&lt;/code&gt; read where the symbol holds, a module existing where any of its files is read, the import rule against every target, &lt;code&gt;avin check&lt;/code&gt; once per differing set of targets with each diagnostic told with its machines, and &lt;code&gt;avin.target&lt;/code&gt;‘s &lt;code&gt;os&lt;/code&gt; and &lt;code&gt;arch&lt;/code&gt; decided as the program is compiled, the untaken branch left out at every level). Still to come: the other ten items; items 4 to 8, 10 and 11 wait for a Linux Sysl (Sysl’s items 1 and 2), and item 12 for Sysl sysroots&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;dates-and-times-build-plan&quot;&gt;Dates and times: build plan&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;avin.time&lt;/code&gt; is rebuilt to &lt;a href=&quot;/spec/time/&quot;&gt;its chapter&lt;/a&gt; over &lt;code&gt;@sysl&lt;/code&gt; bindings to Sysl 0.10.0’s
&lt;code&gt;sysl.time&lt;/code&gt; and &lt;code&gt;sysl.posix.time&lt;/code&gt;, with no new C. Each step is one item, gated on its own, and
ships the tests below for what it builds; a binding that cannot hold Sysl’s &lt;code&gt;Zone&lt;/code&gt; as a handle is a
gap to report, not to route around.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Clocks and durations.&lt;/strong&gt; &lt;code&gt;Instant(epochMicros)&lt;/code&gt; as the wall clock, &lt;code&gt;WallTime&lt;/code&gt; and the monotonic
&lt;code&gt;Instant&lt;/code&gt; removed; &lt;code&gt;now()&lt;/code&gt;, &lt;code&gt;monotonic() -&amp;gt; Duration&lt;/code&gt;, &lt;code&gt;epochSeconds&lt;/code&gt;/&lt;code&gt;epochMillis&lt;/code&gt;/&lt;code&gt;epochMicros&lt;/code&gt;;
the makers &lt;code&gt;micros millis seconds minutes hours days weeks&lt;/code&gt; (from &lt;code&gt;microseconds&lt;/code&gt; and
&lt;code&gt;milliseconds&lt;/code&gt;) and their methods on &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;; &lt;code&gt;toX()&lt;/code&gt;/&lt;code&gt;toXPart()&lt;/code&gt;; &lt;code&gt;d / e&lt;/code&gt;; the
duration’s and instant’s text; &lt;code&gt;Duration.Zero&lt;/code&gt; in place of &lt;code&gt;zero()&lt;/code&gt;. Every caller moves with it:
&lt;code&gt;avin.process&lt;/code&gt;‘s command deadline (a &lt;code&gt;monotonic()&lt;/code&gt; reading), &lt;code&gt;avin.actors&lt;/code&gt;, &lt;code&gt;avin.net&lt;/code&gt;‘s
&lt;code&gt;setTimeout&lt;/code&gt;, the tests and examples that name &lt;code&gt;milliseconds&lt;/code&gt;, &lt;code&gt;zero()&lt;/code&gt;, &lt;code&gt;wallClock&lt;/code&gt;, &lt;code&gt;elapsed&lt;/code&gt;
or &lt;code&gt;WallTime&lt;/code&gt; (&lt;code&gt;git grep&lt;/code&gt; them), and the &lt;code&gt;Duration&lt;/code&gt; overloads of &lt;code&gt;await&lt;/code&gt; and &lt;code&gt;waitFor&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The calendar&lt;/strong&gt; (done). &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, &lt;code&gt;Weekday&lt;/code&gt;: makers and their traps, fields,
&lt;code&gt;with…&lt;/code&gt;, &lt;code&gt;startOf…&lt;/code&gt;, &lt;code&gt;endOfMonth&lt;/code&gt;, &lt;code&gt;onOrAfter&lt;/code&gt;/&lt;code&gt;onOrBefore&lt;/code&gt;, &lt;code&gt;isoWeek&lt;/code&gt;, &lt;code&gt;daysUntil&lt;/code&gt;,
&lt;code&gt;DateTime ± Duration&lt;/code&gt;, the ISO 8601 display. &lt;code&gt;Zoned&lt;/code&gt;‘s &lt;code&gt;with…&lt;/code&gt; and &lt;code&gt;startOf…&lt;/code&gt; come with step 3.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zones.&lt;/strong&gt; &lt;code&gt;Zone&lt;/code&gt; over the host’s database, &lt;code&gt;utc&lt;/code&gt;, &lt;code&gt;localZone()&lt;/code&gt;, &lt;code&gt;fixedZone&lt;/code&gt;, &lt;code&gt;ZoneError&lt;/code&gt;,
&lt;code&gt;Resolution&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt; with &lt;code&gt;atZone&lt;/code&gt;/&lt;code&gt;atZoneEarlier&lt;/code&gt;/&lt;code&gt;atZoneLater&lt;/code&gt;, &lt;code&gt;ZoneTimeError&lt;/code&gt;, its equality
and order, &lt;code&gt;Zoned ± Duration&lt;/code&gt;, abbreviation and daylight saving.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Periods&lt;/strong&gt; (done). &lt;code&gt;Period&lt;/code&gt;, &lt;code&gt;months&lt;/code&gt;/&lt;code&gt;years&lt;/code&gt;, &lt;code&gt;plus…&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt;/&lt;code&gt;DateTime ± Period&lt;/code&gt; with the
month-end clamp, &lt;code&gt;until&lt;/code&gt;/&lt;code&gt;monthsUntil&lt;/code&gt;. &lt;code&gt;Zoned ± Period&lt;/code&gt; and &lt;code&gt;Zoned&lt;/code&gt;‘s &lt;code&gt;plus…&lt;/code&gt;, which need the
gap and overlap rules, come with step 3.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text in&lt;/strong&gt; (done). &lt;code&gt;parseDate&lt;/code&gt;, &lt;code&gt;parseTime&lt;/code&gt;, &lt;code&gt;parseDateTime&lt;/code&gt;, &lt;code&gt;parseTimestamp&lt;/code&gt;, &lt;code&gt;parseZoned&lt;/code&gt;,
&lt;code&gt;parsePeriod&lt;/code&gt;, &lt;code&gt;TimeParseError&lt;/code&gt;; &lt;code&gt;format(pattern)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;The test matrix.&lt;/strong&gt; Each claim of the chapter is a test; these are the cases each step owes.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Clocks&lt;/em&gt;: &lt;code&gt;monotonic()&lt;/code&gt; never decreases across 10,000 reads and across threads; &lt;code&gt;now()&lt;/code&gt; is after
2020; &lt;code&gt;monotonic()&lt;/code&gt; has no &lt;code&gt;atZone&lt;/code&gt;, and &lt;code&gt;monotonic() - now()&lt;/code&gt;, a &lt;code&gt;Duration&lt;/code&gt; from
&lt;code&gt;now() - monotonic()&lt;/code&gt; (an &lt;code&gt;Instant&lt;/code&gt;, the wall reading moved back) and &lt;code&gt;now() &amp;lt; monotonic()&lt;/code&gt; do not
compile (reject tests).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Durations&lt;/em&gt;: &lt;code&gt;2.hours == hours(2)&lt;/code&gt; on an &lt;code&gt;int&lt;/code&gt; and a &lt;code&gt;long&lt;/code&gt; receiver; &lt;code&gt;(hours(1) + minutes(30)) .toMinutes == 90&lt;/code&gt;; &lt;code&gt;seconds(-90).toMinutes == -1&lt;/code&gt;; the parts of a negative duration;
&lt;code&gt;Duration.Min.abs&lt;/code&gt;, &lt;code&gt;hours(long.MaxValue)&lt;/code&gt;, &lt;code&gt;Duration.Max + micros(1)&lt;/code&gt;, &lt;code&gt;d / 0&lt;/code&gt; trap; &lt;code&gt;3 * d&lt;/code&gt;
rejected; the displays &lt;code&gt;5400s&lt;/code&gt;, &lt;code&gt;-45s&lt;/code&gt;, &lt;code&gt;0s&lt;/code&gt;, &lt;code&gt;90.5s&lt;/code&gt;, &lt;code&gt;250ms&lt;/code&gt;, &lt;code&gt;1.5ms&lt;/code&gt;, &lt;code&gt;7us&lt;/code&gt;, and the
&lt;code&gt;Debug&lt;/code&gt; forms; &lt;code&gt;Ord&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; as &lt;code&gt;TreeMap&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; keys.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Instants&lt;/em&gt;: &lt;code&gt;epochSeconds(0)&lt;/code&gt; displays &lt;code&gt;1970-01-01T00:00:00Z&lt;/code&gt;; &lt;code&gt;epochMillis(1000).epochSeconds == 1&lt;/code&gt;; &lt;code&gt;epochMillis(-1).epochSeconds == -1&lt;/code&gt;; &lt;code&gt;epochMicros(1_000_000_001)&lt;/code&gt; keeps its last digit;
&lt;code&gt;Instant.Min&lt;/code&gt; and &lt;code&gt;Instant.Max&lt;/code&gt; display as the chapter says and round-trip through
&lt;code&gt;parseTimestamp&lt;/code&gt;; &lt;code&gt;Instant.Max + micros(1)&lt;/code&gt; and &lt;code&gt;epochSeconds(long.MaxValue)&lt;/code&gt; trap; &lt;code&gt;now() + months(1)&lt;/code&gt; rejected; &lt;code&gt;now().year&lt;/code&gt; rejected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Calendar&lt;/em&gt;: &lt;code&gt;date(2026, 2, 30)&lt;/code&gt;, &lt;code&gt;date(2026, 13, 1)&lt;/code&gt;, &lt;code&gt;date(2026, 0, 1)&lt;/code&gt;, &lt;code&gt;time(24, 0)&lt;/code&gt;,
&lt;code&gt;time(9, 60)&lt;/code&gt;, &lt;code&gt;time(9, 0, 60)&lt;/code&gt;, &lt;code&gt;time(9, 0, 0, 1_000_000)&lt;/code&gt; trap with the chapter’s messages;
2024-02-29 valid and 2023-02-29 a trap; 1900 not leap, 2000 leap, year &lt;code&gt;0&lt;/code&gt; leap; &lt;code&gt;weekday&lt;/code&gt; of
1970-01-01 is Thursday and of 2026-08-28 Friday; &lt;code&gt;dayOfYear&lt;/code&gt; 240; &lt;code&gt;daysInMonth&lt;/code&gt; of every month of
a leap and a common year; &lt;code&gt;isoWeek&lt;/code&gt; across 2026/2027 (2027-01-01 in week 53 of 2026) and
2020-12-31 (week 53); &lt;code&gt;startOfWeek&lt;/code&gt; of a Monday and a Sunday; &lt;code&gt;onOrAfter&lt;/code&gt; its own weekday;
&lt;code&gt;withDay(31)&lt;/code&gt; in February traps, &lt;code&gt;withMonth&lt;/code&gt; clamps; displays of year &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;-1&lt;/code&gt;, &lt;code&gt;9999&lt;/code&gt;, &lt;code&gt;10000&lt;/code&gt;;
&lt;code&gt;Date.Min&lt;/code&gt; and &lt;code&gt;Date.Max&lt;/code&gt; display and reach no instant (&lt;code&gt;atStartOfDay(utc)&lt;/code&gt; traps);
&lt;code&gt;date(…) == dateTime(…)&lt;/code&gt; rejected; &lt;code&gt;Time&lt;/code&gt; arithmetic rejected; &lt;code&gt;Time&lt;/code&gt; ordered.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Zones&lt;/em&gt; (Toronto, Tokyo, Kolkata, Kathmandu at +05:45, Lord Howe’s half-hour change, UTC):
&lt;code&gt;zone(&amp;quot;Nowhere/Atall&amp;quot;)&lt;/code&gt; is &lt;code&gt;UnknownZone&lt;/code&gt;; &lt;code&gt;&amp;quot;../../etc/passwd&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;/etc/localtime&amp;quot;&lt;/code&gt; and a name
with a non-ASCII letter are &lt;code&gt;NotAZoneName&lt;/code&gt;; &lt;code&gt;zone(&amp;quot;UTC&amp;quot;)? == utc&lt;/code&gt;; &lt;code&gt;zone(&amp;quot;+05:30&amp;quot;)&lt;/code&gt; displays
&lt;code&gt;+05:30&lt;/code&gt; and its readings carry no bracket; &lt;code&gt;fixedZone(seconds(30))&lt;/code&gt; and &lt;code&gt;fixedZone(hours(24))&lt;/code&gt;
trap; &lt;code&gt;localZone()&lt;/code&gt; answers with &lt;code&gt;TZ&lt;/code&gt; unset, set to a zone and set to nonsense; the spring gap
(2026-03-08T02:30 in Toronto: &lt;code&gt;atZone&lt;/code&gt; is &lt;code&gt;Skipped&lt;/code&gt;, both &lt;code&gt;atZoneEarlier&lt;/code&gt; and &lt;code&gt;atZoneLater&lt;/code&gt; give
03:30-04:00) and the autumn overlap (2026-11-01T01:30: &lt;code&gt;Repeated&lt;/code&gt;, &lt;code&gt;-04:00&lt;/code&gt; then &lt;code&gt;-05:00&lt;/code&gt;, an hour
apart); a zone whose skipped hour is midnight for &lt;code&gt;atStartOfDay&lt;/code&gt;; &lt;code&gt;Zoned ==&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;TreeMap&lt;/code&gt; for
Toronto 09:00 and Tokyo 22:00 of one instant; &lt;code&gt;abbreviationAt&lt;/code&gt; EDT/EST; an offset with seconds in
the table (Toronto in 1850) held to whole minutes; a reading past the table’s last transition.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Periods&lt;/em&gt;: Jan 31 + 1 month in 2026 and 2024; Feb 29 + 1 year and + 4 years; Jan 31 +
&lt;code&gt;Period(1, 1)&lt;/code&gt; is Mar 1; &lt;code&gt;months(1) - months(1)&lt;/code&gt; after a clamp; &lt;code&gt;months(1) != Period(0, 30)&lt;/code&gt;;
&lt;code&gt;years(1) == months(12)&lt;/code&gt;; &lt;code&gt;Period * n&lt;/code&gt; overflow traps; &lt;code&gt;Date - Date&lt;/code&gt; across a leap day; &lt;code&gt;until&lt;/code&gt; and
&lt;code&gt;monthsUntil&lt;/code&gt; from month ends; &lt;code&gt;a + a.until(b) == b&lt;/code&gt; over a year of pairs; &lt;code&gt;zoned + days(1)&lt;/code&gt; against
&lt;code&gt;zoned.plusDays(1)&lt;/code&gt; across the spring change (an hour apart) and the autumn change; a period landing
in a gap and in an overlap; &lt;code&gt;Period&lt;/code&gt; has no &lt;code&gt;&amp;lt;&lt;/code&gt; (reject).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Text&lt;/em&gt;: every display of every type reads back equal through its parser, over a sweep of dates
from year -1 to 10000 and times with 0 to 6 fraction digits; &lt;code&gt;2026-02-30&lt;/code&gt;, &lt;code&gt;2026-13-01&lt;/code&gt;,
&lt;code&gt;2026/03/08&lt;/code&gt; (byte 4), &lt;code&gt;2026-03-08T&lt;/code&gt; (trailing at 10), &lt;code&gt;24:00&lt;/code&gt;, &lt;code&gt;23:59:60&lt;/code&gt;, seven fraction digits,
an offset of &lt;code&gt;-25:00&lt;/code&gt;, a timestamp with no offset, Arabic-Indic and full-width digits, a trailing
space, an empty string, a zone name in &lt;code&gt;parseZoned&lt;/code&gt; that does not exist; patterns: the chapter’s
two examples, &lt;code&gt;h12&lt;/code&gt; at 00:30 and 12:30, &lt;code&gt;DDD&lt;/code&gt;, &lt;code&gt;z zz zzz zzzz&lt;/code&gt;, a literal &lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, a Unicode
literal between bars, &lt;code&gt;YYY&lt;/code&gt; and an unclosed bar trapping, &lt;code&gt;hh&lt;/code&gt; on a &lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;YYYY&lt;/code&gt; on a &lt;code&gt;Time&lt;/code&gt; and
&lt;code&gt;z&lt;/code&gt; on a &lt;code&gt;DateTime&lt;/code&gt; trapping with the chapter’s messages; &lt;code&gt;format&lt;/code&gt; on an &lt;code&gt;Instant&lt;/code&gt; rejected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Neighbours&lt;/em&gt;: every type as a field of a &lt;code&gt;data&lt;/code&gt; type and a class, in a generic &lt;code&gt;[T: Ord]&lt;/code&gt; sort and
a &lt;code&gt;Map&lt;/code&gt; key, captured by a closure, sent to an actor and through a &lt;code&gt;Channel&lt;/code&gt;, in &lt;code&gt;s&amp;quot;…&amp;quot;&lt;/code&gt; with a width;
&lt;code&gt;threads.sleep(millis(1))&lt;/code&gt;, &lt;code&gt;await(millis(10))&lt;/code&gt;, an actor’s &lt;code&gt;after(millis(5), m)&lt;/code&gt;; the corpus runs
every time program at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; and under GC stress, with a zone held across collections.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;union-types-the-test-matrix&quot;&gt;Union types: the test matrix&lt;/h3&gt;
&lt;p&gt;Each claim of &lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt; is a test; these are the cases the item owes. Run tests
(&lt;code&gt;tests/run/union_*&lt;/code&gt;) run at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; and under GC stress; reject tests (&lt;code&gt;tests/reject/union_*&lt;/code&gt;)
carry the chapter’s exact messages, at most five per file.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Syntax&lt;/em&gt;: &lt;code&gt;int | string&lt;/code&gt; as a parameter, result, &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt;, data field, class parameter, type
argument (&lt;code&gt;f[int | string](x)&lt;/code&gt;, &lt;code&gt;List.empty[int | string]()&lt;/code&gt;), tuple part, function parameter and
result, alias body; &lt;code&gt;(A) -&amp;gt; B | C&lt;/code&gt; returns the union and &lt;code&gt;A | B -&amp;gt; C&lt;/code&gt; takes it; &lt;code&gt;((int) -&amp;gt; int) | string&lt;/code&gt; holds a function and is called after a &lt;code&gt;match&lt;/code&gt;; &lt;code&gt;Option[A | B]&lt;/code&gt; and &lt;code&gt;Option[A] | B&lt;/code&gt; are
different types (a reject assigning one to the other); &lt;code&gt;[]int | string&lt;/code&gt; vs &lt;code&gt;[](int | string)&lt;/code&gt;;
&lt;code&gt;@sendable (int) -&amp;gt; int | string&lt;/code&gt;; &lt;code&gt;(int | string)&lt;/code&gt; parenthesized; a union broken after &lt;code&gt;|&lt;/code&gt; inside
brackets; &lt;code&gt;x: int | string -&amp;gt;&lt;/code&gt; in an arm rejected with the parenthesized suggestion; &lt;code&gt;_: int | _: string -&amp;gt;&lt;/code&gt; is two alternatives; &lt;code&gt;a | b&lt;/code&gt; on ints still bitwise and a symbol method &lt;code&gt;|&lt;/code&gt; still called
in the same file; a clause guard &lt;code&gt;f(n) | n &amp;gt; 0 = …&lt;/code&gt; beside a union parameter.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Normal form&lt;/em&gt;: &lt;code&gt;A | (B | C)&lt;/code&gt; == &lt;code&gt;A | B | C&lt;/code&gt; (one overload, a duplicate-overload reject);
&lt;code&gt;int | string&lt;/code&gt; == &lt;code&gt;string | int&lt;/code&gt; (same overload, same &lt;code&gt;Map&lt;/code&gt; key type, a value made as one passed
as the other); written &lt;code&gt;int | int&lt;/code&gt;, &lt;code&gt;Dog | Animal&lt;/code&gt;, &lt;code&gt;string | Any&lt;/code&gt;, &lt;code&gt;int | Display&lt;/code&gt;, &lt;code&gt;int | Nothing&lt;/code&gt;
each rejected with its message; the same reached through &lt;code&gt;T&lt;/code&gt; (&lt;code&gt;T | int&lt;/code&gt; at &lt;code&gt;T = int&lt;/code&gt;, &lt;code&gt;T | Animal&lt;/code&gt;
at &lt;code&gt;T = Dog&lt;/code&gt;, &lt;code&gt;T | string&lt;/code&gt; at &lt;code&gt;T = int | bool&lt;/code&gt;) and through aliases (&lt;code&gt;Key | string&lt;/code&gt;) compile and
behave as the collapsed type; &lt;code&gt;Named | Pet&lt;/code&gt; kept two members; &lt;code&gt;Option[int] | Option[string]&lt;/code&gt; two
members; &lt;code&gt;type Json = Vector[Json] | string&lt;/code&gt; rejected; &lt;code&gt;data Node(kids: Vector[Node | string])&lt;/code&gt;
builds a tree, compares and prints it; messages print aliases expanded and flattened.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Inference&lt;/em&gt;: &lt;code&gt;if c then 1 else &amp;quot;a&amp;quot;&lt;/code&gt; rejected naming &lt;code&gt;int | string&lt;/code&gt;; the same for &lt;code&gt;match&lt;/code&gt; arms, a
loop’s &lt;code&gt;else&lt;/code&gt;/&lt;code&gt;break&lt;/code&gt;, &lt;code&gt;[1, &amp;quot;a&amp;quot;]&lt;/code&gt;, &lt;code&gt;pair(1, &amp;quot;one&amp;quot;)&lt;/code&gt;; &lt;code&gt;val y: int | string = if …&lt;/code&gt; accepted;
&lt;code&gt;val u2 = u&lt;/code&gt;, &lt;code&gt;Some(u)&lt;/code&gt;, &lt;code&gt;id(u)&lt;/code&gt; carry the union; &lt;code&gt;if c then u else 3&lt;/code&gt; is the union; &lt;code&gt;orText(3)&lt;/code&gt;
gives &lt;code&gt;T = int&lt;/code&gt;, &lt;code&gt;orText(u)&lt;/code&gt; with three members gives the remaining two, &lt;code&gt;orText(&amp;quot;a&amp;quot;)&lt;/code&gt; rejected
naming &lt;code&gt;T&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Injection&lt;/em&gt;: each single site — argument, binding, assignment to a &lt;code&gt;var&lt;/code&gt;, data field, class field,
result (&lt;code&gt;= 3&lt;/code&gt; and &lt;code&gt;return 3&lt;/code&gt;), tuple part written out, each &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt; branch, collection literal
element, map literal key and value, &lt;code&gt;with { v = 3 }&lt;/code&gt;, a default argument, a named argument; a
subtype (&lt;code&gt;Puppy&lt;/code&gt; into &lt;code&gt;Animal | int&lt;/code&gt;); &lt;code&gt;Parrot&lt;/code&gt; into &lt;code&gt;Named | Pet&lt;/code&gt; rejected; literals: &lt;code&gt;3&lt;/code&gt; into
&lt;code&gt;int | long&lt;/code&gt; is the int, &lt;code&gt;5_000_000_000&lt;/code&gt; the long, &lt;code&gt;3&lt;/code&gt; into &lt;code&gt;long | string&lt;/code&gt; the long, &lt;code&gt;3&lt;/code&gt; into
&lt;code&gt;byte | long&lt;/code&gt; rejected, &lt;code&gt;1.5&lt;/code&gt; into &lt;code&gt;real | string&lt;/code&gt;, &lt;code&gt;int.MaxValue&lt;/code&gt;/&lt;code&gt;long.MinValue&lt;/code&gt; boundaries;
&lt;code&gt;None&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;Ok(1)&lt;/code&gt; into a union with one fitting member, and rejected with two; &lt;code&gt;int | string&lt;/code&gt;
into &lt;code&gt;int | string | bool&lt;/code&gt;; &lt;code&gt;int | bool&lt;/code&gt; into &lt;code&gt;int | string&lt;/code&gt; rejected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Subtyping and variance&lt;/em&gt;: &lt;code&gt;Dog | Cat&lt;/code&gt; passed as &lt;code&gt;Animal&lt;/code&gt;; &lt;code&gt;int | long&lt;/code&gt; as &lt;code&gt;Any&lt;/code&gt; and matched back;
&lt;code&gt;int | string&lt;/code&gt; as &lt;code&gt;Display&lt;/code&gt;; &lt;code&gt;List[Dog] &amp;lt;: List[Dog | Cat]&lt;/code&gt;, &lt;code&gt;Option[Dog | Cat] &amp;lt;: Option[Animal]&lt;/code&gt;,
&lt;code&gt;Result[T, IoError] &amp;lt;: Result[T, IoError | ParseError]&lt;/code&gt; with no conversion (identity preserved:
the same &lt;code&gt;Array&lt;/code&gt; inside); &lt;code&gt;List[int]&lt;/code&gt; as &lt;code&gt;List[int | string]&lt;/code&gt; rejected, &lt;code&gt;List[int | string]&lt;/code&gt; as
&lt;code&gt;List[int | string | bool]&lt;/code&gt; rejected; &lt;code&gt;Array[Dog]&lt;/code&gt; as &lt;code&gt;Array[Dog | Cat]&lt;/code&gt; rejected (invariant);
&lt;code&gt;(Dog | Cat) -&amp;gt; int&lt;/code&gt; as &lt;code&gt;(Dog) -&amp;gt; int&lt;/code&gt;; &lt;code&gt;() -&amp;gt; Dog&lt;/code&gt; as &lt;code&gt;() -&amp;gt; Dog | Cat&lt;/code&gt;; &lt;code&gt;(int | string) -&amp;gt; int&lt;/code&gt;
value as &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt; rejected, the named function accepted; &lt;code&gt;@sendable&lt;/code&gt; union functions.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Overloads&lt;/em&gt;: &lt;code&gt;show(1)&lt;/code&gt;/&lt;code&gt;show(&amp;quot;a&amp;quot;)&lt;/code&gt;/&lt;code&gt;show(true)&lt;/code&gt; pick int / union / Any; &lt;code&gt;f(int | string)&lt;/code&gt; vs
&lt;code&gt;f(int | bool)&lt;/code&gt; with &lt;code&gt;1&lt;/code&gt; ambiguous and with a union argument resolved; member overloads with a
union argument rejected suggesting &lt;code&gt;match&lt;/code&gt;; generic overload &lt;code&gt;g[T](x: T)&lt;/code&gt; vs &lt;code&gt;g(x: int | string)&lt;/code&gt;;
overloads differing by member order rejected as duplicates.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;match and exhaustiveness&lt;/em&gt;: every member by type pattern; a member left out names &lt;code&gt;_: bool&lt;/code&gt;; &lt;code&gt;_&lt;/code&gt;
covers the rest; a supertype pattern covers a member; a subtype pattern needs the rest; a
sub-union pattern binds the smaller union and leaves the others; literal, range, comparison,
&lt;code&gt;n + k&lt;/code&gt;, constructor, list, sequence, tuple and extractor patterns each reach their one member and
count only for it; &lt;code&gt;0&lt;/code&gt; on &lt;code&gt;int | long&lt;/code&gt; rejected; &lt;code&gt;Some(x)&lt;/code&gt; on &lt;code&gt;Option[int] | Option[string]&lt;/code&gt;
rejected; a type pattern naming no member rejected; unreachable arm after its member is covered
rejected; guards do not cover; a &lt;code&gt;Parrot&lt;/code&gt; in &lt;code&gt;Named | Pet&lt;/code&gt; taken by the first arm; clauses by member
with a missing member rejected; &lt;code&gt;match&lt;/code&gt; functions (&lt;code&gt;match n -&amp;gt; …&lt;/code&gt;) over a union; an &lt;code&gt;Any&lt;/code&gt; matched
by &lt;code&gt;x: (int | string)&lt;/code&gt; binds the union and fails on a &lt;code&gt;bool&lt;/code&gt;; a generic &lt;code&gt;match&lt;/code&gt; on &lt;code&gt;T | int&lt;/code&gt; checked
once and, at &lt;code&gt;T = int&lt;/code&gt;, taking every value by the &lt;code&gt;T&lt;/code&gt; arm.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;is&lt;/em&gt;: &lt;code&gt;if v is s: string&lt;/code&gt;, &lt;code&gt;is not&lt;/code&gt; with early return, &lt;code&gt;while v is n: int&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; scopes;
&lt;code&gt;v.charCount&lt;/code&gt; after the test rejected (no narrowing).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Equality and hashing&lt;/em&gt;: same member equal and unequal; different members unequal (&lt;code&gt;int&lt;/code&gt; 1 vs
&lt;code&gt;long&lt;/code&gt; 1 in &lt;code&gt;int | long&lt;/code&gt;); &lt;code&gt;u == 3&lt;/code&gt; injects; &lt;code&gt;u == true&lt;/code&gt; rejected; a class member with its own &lt;code&gt;Eq&lt;/code&gt;
used; the sequence exception (&lt;code&gt;Vector[int] | List[int]&lt;/code&gt;); &lt;code&gt;Set[int | string]&lt;/code&gt; holding &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;&amp;quot;1&amp;quot;&lt;/code&gt;;
&lt;code&gt;Map[int | string, V]&lt;/code&gt; lookups; hash equals the member’s hash; &lt;code&gt;===&lt;/code&gt; on &lt;code&gt;Dog | Cat&lt;/code&gt; accepted and on
&lt;code&gt;Dog | int&lt;/code&gt; rejected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Traits and member calls&lt;/em&gt;: &lt;code&gt;println&lt;/code&gt;, interpolation, &lt;code&gt;toString()&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt; (strings quoted) and a
field width on unions; &lt;code&gt;[T: Display]&lt;/code&gt; at a union; a union without &lt;code&gt;Display&lt;/code&gt; member not displayable
(reject naming the member); a library trait with receiver-only &lt;code&gt;Self&lt;/code&gt; reached; &lt;code&gt;Ord&lt;/code&gt; refused
(&lt;code&gt;sorted()&lt;/code&gt; on &lt;code&gt;Vector[int | string]&lt;/code&gt; rejected, &lt;code&gt;TreeMap&lt;/code&gt; key rejected); &lt;code&gt;Sendable&lt;/code&gt; through
&lt;code&gt;spawn&lt;/code&gt;/an actor message when every member is, and rejected when one is not; &lt;code&gt;a.name&lt;/code&gt; through the
join; &lt;code&gt;v.charCount&lt;/code&gt; rejected; a name on two conforming traits rejected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Derivations&lt;/em&gt;: a data type and a class with a union field derive &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;;
&lt;code&gt;derives Ord&lt;/code&gt; rejected naming the field; a derive template’s bound met and not met by a union
field.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;code&gt;?&lt;/code&gt;&lt;/em&gt;: rule 1 with two error kinds; a subclass error into its superclass member; a union &lt;code&gt;?&lt;/code&gt;‘d
inside a wider union; rule 2 (&lt;code&gt;From&lt;/code&gt; on one member) and two members with &lt;code&gt;From[E]&lt;/code&gt; rejected; rule
3 (union into a wrapper with two &lt;code&gt;From&lt;/code&gt;s) and a member with no conversion rejected naming it; rule
4 unchanged; &lt;code&gt;NetError&lt;/code&gt; into &lt;code&gt;IoError | ParseError&lt;/code&gt; rejected with the message; &lt;code&gt;?&lt;/code&gt; in a lambda with
a declared union result; a returned &lt;code&gt;Result[T, IoError]&lt;/code&gt; widened with no conversion; a scalar error
union rebuilt with &lt;code&gt;mapErr(e -&amp;gt; e)&lt;/code&gt; and rejected without it; &lt;code&gt;Option&lt;/code&gt; &lt;code&gt;?&lt;/code&gt; unaffected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Representation and GC&lt;/em&gt;: a reference union and a scalar union in locals, fields, tuples, &lt;code&gt;Vector&lt;/code&gt;,
&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt; values, closures’ captures and actor messages, held across forced
collections (strings and class instances in the reference slot stay alive and intact); a scalar
union of &lt;code&gt;long | real | char | bool | unit&lt;/code&gt; round-tripping every member and boundary value
(&lt;code&gt;long.MinValue&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt; NaN and -0.0, &lt;code&gt;&apos;\u{10FFFF}&apos;&lt;/code&gt;); a union nested in a union field of a data
type nested in a vector; generic &lt;code&gt;Vector[T | int]&lt;/code&gt; at &lt;code&gt;T = string&lt;/code&gt; and at &lt;code&gt;T = int&lt;/code&gt;; the same output
at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;with and aliases&lt;/em&gt;: &lt;code&gt;p with { v = 3 }&lt;/code&gt; injects; &lt;code&gt;p with { v.x = 1 }&lt;/code&gt; through a union rejected;
&lt;code&gt;type Num = int | long&lt;/code&gt; in every position; generic alias &lt;code&gt;type OrErr[T] = T | string&lt;/code&gt;; &lt;code&gt;impl&lt;/code&gt; on
an alias of a union rejected.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Closures&lt;/em&gt;: lambdas taking and returning unions; a closure capturing a union &lt;code&gt;var&lt;/code&gt; and changing it
to another member seen outside; placeholder lambdas over a union (&lt;code&gt;xs.map(_.toString())&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Refusals&lt;/em&gt;: &lt;code&gt;impl Display for int | string&lt;/code&gt;, an extension on a union, &lt;code&gt;class C: A | B&lt;/code&gt;,
&lt;code&gt;[T: A | B]&lt;/code&gt; (and &lt;code&gt;[T &amp;gt;: A | B]&lt;/code&gt; accepted), a union in an &lt;code&gt;@sysl&lt;/code&gt; and an &lt;code&gt;@c&lt;/code&gt; parameter, result and
mirror field, calling or constructing a union, each with its message.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;refined-variants-build-plan&quot;&gt;Refined variants: build plan&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;/spec/refined-variants/&quot;&gt;Refined variants&lt;/a&gt; are designed, their choices proposed in
&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;decisions&lt;/a&gt;; steps 1 to 6 are built, step 7 is still to come. Each step is one item, gated on its own
targeted files, and ships the tests listed for it: run tests &lt;code&gt;tests/run/refined_*&lt;/code&gt; (at &lt;code&gt;-O0&lt;/code&gt; and
&lt;code&gt;-O2&lt;/code&gt;, under GC stress) and reject tests &lt;code&gt;tests/reject/refined_*&lt;/code&gt; carrying the chapter’s exact
messages, at most five per file. A step that meets a missing piece of the checker it builds on
reports it rather than routing around it.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Declaration.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-1&lt;/code&gt;):&lt;/em&gt; parsed, shown and formatted; &lt;code&gt;VariantSymbol&lt;/code&gt; holds
&lt;code&gt;params&lt;/code&gt; (the type’s, then the variant’s own) and &lt;code&gt;result&lt;/code&gt;; the six checks run, rule 6 through
&lt;code&gt;expansion.sysl&lt;/code&gt;‘s flow graph with each refined variant’s parameters as nodes of their own; tests
&lt;code&gt;tests/reject/refined_{result,parameters,variance,nested,bounds,defaults}&lt;/code&gt;,
&lt;code&gt;tests/run/refined_declaration&lt;/code&gt;, &lt;code&gt;tests/programs/reject/refined_across_modules&lt;/code&gt;, and cases in
&lt;code&gt;parse_tests&lt;/code&gt;, &lt;code&gt;formatter_tests&lt;/code&gt; and &lt;code&gt;lsp_tests&lt;/code&gt;. Where it meets &lt;a href=&quot;/spec/generics/#higher-kinded-types&quot;&gt;higher-kinded
types&lt;/a&gt;: a result refuses any form but data types, classes,
tuples, functions and parameters, so a constructor or an applied constructor parameter is refused;
step 2 adds the rest (below).
&lt;code&gt;Variant[params](fields) -&amp;gt; Type[args]&lt;/code&gt; and &lt;code&gt;Name -&amp;gt; Type[args]&lt;/code&gt; in a &lt;code&gt;data&lt;/code&gt;
body: &lt;code&gt;syntax.sysl&lt;/code&gt; (&lt;code&gt;Variant&lt;/code&gt; gains &lt;code&gt;type_params&lt;/code&gt; and &lt;code&gt;result: Option[&amp;amp;TypeExpr]&lt;/code&gt;),
&lt;code&gt;parse_decl.sysl&lt;/code&gt;, &lt;code&gt;formatter.sysl&lt;/code&gt; (round trip, &lt;code&gt;avin fmt&lt;/code&gt;-clean), &lt;code&gt;syntax_show.sysl&lt;/code&gt;,
&lt;code&gt;lsp_symbols.sysl&lt;/code&gt;; in &lt;code&gt;check.sysl&lt;/code&gt;‘s &lt;code&gt;declare_variants&lt;/code&gt;, &lt;code&gt;VariantSymbol&lt;/code&gt; gains its parameters and
its result in them, and the six declaration checks run. &lt;em&gt;Tests:&lt;/em&gt; each check’s reject (a result of
another type, a fixed &lt;code&gt;+T&lt;/code&gt; and &lt;code&gt;-T&lt;/code&gt;, a union naming a parameter beside a closed union accepted,
an unused parameter, a reused name, &lt;code&gt;Lift[A](x: Expr[Vector[A]])&lt;/code&gt; refused beside
&lt;code&gt;First[A, B](pair: Expr[(A, B)])&lt;/code&gt; accepted); parse and formatter cases for a fieldless variant with a
result, a multi-line field list, annotations and defaults on a refined variant’s fields.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Making values and layouts.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-2&lt;/code&gt;):&lt;/em&gt; step 1’s refusal is gone; a variant’s
signature is generic over its parameters, a parameter of the type it names nowhere fixed rather
than inferred or written (&lt;code&gt;Signature.fixed&lt;/code&gt;); &lt;code&gt;T[A].V&lt;/code&gt; holds the value to the instance written;
the chapter’s two messages for a value at the wrong instance, the field’s named where it is given
to one; &lt;code&gt;variant_args&lt;/code&gt;/&lt;code&gt;variant_fields_at&lt;/code&gt; read a variant’s arguments back from a concrete instance,
and &lt;code&gt;lower.sysl&lt;/code&gt; lays out only the possible variants (&lt;code&gt;AbsentVariant&lt;/code&gt; for the rest), compiles an
arm on a variant its copy’s instance cannot hold not at all, and an arm on a refined one at the
arguments read back (&lt;code&gt;Lowering.refined&lt;/code&gt;), which the derived templates’ code needs; a derivation
holds a refined variant’s own parameter to the trait where the result implies it (&lt;code&gt;implied_own&lt;/code&gt;).
Higher-kinded types: a variant’s own constructor parameter is refused, a result fixing a
constructor parameter is refused, and one keeping it in its place is accepted. &lt;em&gt;Still refused, with
“not yet” messages, for the steps that own them:&lt;/em&gt; a variant pattern of a type with refined
variants, plain variants included, outside derived code (step 3); a field read by name on a
refined type’s one variant (step 3); a value of a variant with a hidden parameter (step 5); a
value of a variant bounding its own parameter (step 6). &lt;em&gt;Tests:&lt;/em&gt; run &lt;code&gt;refined_values&lt;/code&gt;,
&lt;code&gt;refined_layouts&lt;/code&gt;, &lt;code&gt;refined_derived&lt;/code&gt;, &lt;code&gt;tests/programs/run/refined_across_modules&lt;/code&gt;; reject
&lt;code&gt;refined_making&lt;/code&gt;, &lt;code&gt;refined_shared_names&lt;/code&gt;, &lt;code&gt;refined_type_args&lt;/code&gt;, &lt;code&gt;refined_later_steps&lt;/code&gt;,
&lt;code&gt;refined_later_steps_reads&lt;/code&gt;, &lt;code&gt;refined_constructor_params&lt;/code&gt;, and the cross-module program. The plan
as written: removes step 1’s &lt;code&gt;refined_use_refused&lt;/code&gt; and its two reject tests
&lt;code&gt;refined_not_yet_built*&lt;/code&gt;. &lt;code&gt;variant_signature&lt;/code&gt; generic over the variant’s parameters; inference
from fields and the expected type; explicit arguments on the variant and on the type; the bare and
qualified names; in &lt;code&gt;lower.sysl&lt;/code&gt;, &lt;code&gt;DataLayout&lt;/code&gt; holding only the variants possible at the
instance, tags kept as declared; derived &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt; per instance; a type
pattern on an &lt;code&gt;Any&lt;/code&gt; holding one. No hidden parameters yet (refused with a “not yet built”
message, removed by step 5). &lt;em&gt;Tests:&lt;/em&gt; run: values of every &lt;code&gt;Expr&lt;/code&gt; variant printed and compared,
&lt;code&gt;Expr[int]&lt;/code&gt; and &lt;code&gt;Expr[bool]&lt;/code&gt; in one &lt;code&gt;Vector[Any]&lt;/code&gt; taken apart by type pattern, a refined value
in a class field, a closure capturing one, a &lt;code&gt;Map&lt;/code&gt; keyed by one; reject: a variant at the wrong
expected instance, a field of the wrong instance, a shared variant name decided by a refined
result.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Refinement.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-3&lt;/code&gt;):&lt;/em&gt; step 2’s two step-3 refusals are gone. Each refining
pattern is a site (&lt;code&gt;Checker.sites&lt;/code&gt;, &lt;code&gt;TProgram.refine_sites&lt;/code&gt;) whose fresh types have the owner
&lt;code&gt;pattern_owner(site)&lt;/code&gt;; &lt;code&gt;refine_variant&lt;/code&gt; solves the equalities (&lt;code&gt;solve_pair&lt;/code&gt;: fresh types first, an
occurs check, unions and constructors naming parameters taken apart not at all, a contradiction
giving none) and declares a marker local beside the pattern’s names, so &lt;code&gt;BodyState.equalities&lt;/code&gt;
hold exactly where those names are in scope. &lt;code&gt;refined_type&lt;/code&gt; applies them in &lt;code&gt;fits&lt;/code&gt;, &lt;code&gt;unify&lt;/code&gt;,
&lt;code&gt;joined&lt;/code&gt;, bounds, the expected type of &lt;code&gt;check_value&lt;/code&gt;, patterns on a type parameter, and operands
of operators and members (&lt;code&gt;refined_operand&lt;/code&gt;); a refining arm, clause, &lt;code&gt;is&lt;/code&gt; branch and block yield
the expected type (&lt;code&gt;held_to_expected&lt;/code&gt;), and a fresh type leaving its scope is refused
(&lt;code&gt;escape_checked&lt;/code&gt;, &lt;code&gt;settle_var&lt;/code&gt;). &lt;code&gt;val V = x&lt;/code&gt; takes the value apart where &lt;code&gt;V&lt;/code&gt; is a variant of a
refined type; a field of a refined one-variant type is read at what the instance says. In
&lt;code&gt;lower.sysl&lt;/code&gt;, &lt;code&gt;refine_pattern&lt;/code&gt; reads each site’s arguments back; &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt; and
&lt;code&gt;while&lt;/code&gt; fold a test impossible at the copy and leave out what holds its equalities, a block’s
rest included (&lt;code&gt;Lowering.dead&lt;/code&gt;); a lambda or local function written in a site’s scope is compiled
at what its sites read (&lt;code&gt;TProgram.refined_functions&lt;/code&gt;); a field read of an instance with no values
traps. Still refused, for the steps that own them: a pattern on, and a value of, a variant with a
hidden parameter (step 5); a value of a variant bounding its own parameter (step 6). &lt;em&gt;Tests:&lt;/em&gt; run
&lt;code&gt;refined_eval&lt;/code&gt;, &lt;code&gt;refined_scopes&lt;/code&gt;, &lt;code&gt;refined_closures&lt;/code&gt;, &lt;code&gt;refined_impossible&lt;/code&gt;, the cross-module
program; reject &lt;code&gt;refined_arm_results&lt;/code&gt;, &lt;code&gt;refined_escapes&lt;/code&gt;, &lt;code&gt;refined_contradictions&lt;/code&gt;,
&lt;code&gt;refined_attacks&lt;/code&gt;, &lt;code&gt;refined_later_steps&lt;/code&gt;, &lt;code&gt;refined_later_steps_reads&lt;/code&gt;. The plan as written: in
&lt;code&gt;check.sysl&lt;/code&gt;, a scoped substitution of the type parameters in scope, pushed
by each arm, clause, &lt;code&gt;is&lt;/code&gt; scope and destructuring binding whose pattern holds a refined variant
(solved by decomposition with an occurs check), consulted wherever two types are compared or a
member is found; arm results checked against the expected type under it; inference variables
settled as written; in &lt;code&gt;lower.sysl&lt;/code&gt;, an arm whose equalities fail at the copy is not lowered.
&lt;em&gt;Tests:&lt;/em&gt; run: &lt;code&gt;eval&lt;/code&gt; over &lt;code&gt;IntLit&lt;/code&gt;, &lt;code&gt;BoolLit&lt;/code&gt;, &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;If&lt;/code&gt;, &lt;code&gt;Pair&lt;/code&gt; (as clauses, as a
&lt;code&gt;match&lt;/code&gt;, as a match function, through &lt;code&gt;is&lt;/code&gt; with an early return, in a class’s generic method,
in a local generic function); nested refinement (&lt;code&gt;If(BoolLit(b), x, y)&lt;/code&gt;); a lambda made in an arm
and called after it; a &lt;code&gt;var&lt;/code&gt; declared outside stored in an arm; &lt;code&gt;Same&lt;/code&gt;/&lt;code&gt;cast&lt;/code&gt;; reject: an arm
result of the wrong type, arms joining with no expected type, an inference variable settled in an
arm and used outside, a refined name used outside its &lt;code&gt;is&lt;/code&gt; scope, an unknown matched type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coverage.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-4&lt;/code&gt;):&lt;/em&gt; &lt;code&gt;cases_of&lt;/code&gt; in &lt;code&gt;coverage.sysl&lt;/code&gt; keeps the variants whose
result’s equalities with the column’s instance have a solution (&lt;code&gt;possible_case&lt;/code&gt;, its own variant
parameters given &lt;code&gt;coverage_owner&lt;/code&gt; types), and each case carries what its equalities say of the
enclosing type parameters to the other columns (&lt;code&gt;case_columns&lt;/code&gt;), so a row’s equalities travel
along it; an instance with no possible variant is a column with no values. The checker hands
coverage each matched type under the equalities in scope (&lt;code&gt;refined_type&lt;/code&gt;), so a nested &lt;code&gt;match&lt;/code&gt;
in a refining arm counts the enclosing arm’s. A pattern whose equalities contradict is an error
at the pattern (&lt;code&gt;report_contradiction&lt;/code&gt;): the variant makes another instance, a cyclic equality,
or a contradiction with an earlier pattern of its row (&lt;code&gt;Checker.pattern_row&lt;/code&gt;: an arm, a clause’s
arguments, an &lt;code&gt;is&lt;/code&gt; test, a binding); a &lt;code&gt;match&lt;/code&gt; on an empty instance is an error at the value
matched. Alternatives no longer hold each other’s equalities nor the arm’s (a step-3 leak:
&lt;code&gt;IntLit(_) | BoolLit(_) -&amp;gt; 5&lt;/code&gt; checked &lt;code&gt;5&lt;/code&gt; as a &lt;code&gt;T&lt;/code&gt; that is &lt;code&gt;int&lt;/code&gt;). Two fresh types that read the
same are named apart by their patterns’ lines (&lt;code&gt;names_apart&lt;/code&gt;) in the expected/found, operand and
result messages; lowering tests each alternative at what its own patterns read back (&lt;code&gt;refine_pattern&lt;/code&gt;), where it compiled one without them. &lt;em&gt;Tests:&lt;/em&gt; run &lt;code&gt;refined_coverage&lt;/code&gt;, &lt;code&gt;refined_alternatives&lt;/code&gt;; reject &lt;code&gt;refined_coverage&lt;/code&gt;,
&lt;code&gt;refined_coverage_rows&lt;/code&gt;, &lt;code&gt;refined_coverage_more&lt;/code&gt;, &lt;code&gt;refined_names_apart&lt;/code&gt;, &lt;code&gt;refined_contradictions&lt;/code&gt;
(now an error for the cyclic arm), &lt;code&gt;refined_alternatives&lt;/code&gt;. The plan as written: in &lt;code&gt;coverage.sysl&lt;/code&gt;, &lt;code&gt;cases_of&lt;/code&gt; keeps the variants possible at the instance and the
witness search carries each row’s equalities; impossible arms and empty instances are errors with
the chapter’s messages. &lt;em&gt;Tests:&lt;/em&gt; run: &lt;code&gt;total&lt;/code&gt; on &lt;code&gt;Expr[int]&lt;/code&gt; with no &lt;code&gt;BoolLit&lt;/code&gt; arm, a pair of
&lt;code&gt;Expr[T]&lt;/code&gt;s whose contradictory row is left out, a nested &lt;code&gt;match&lt;/code&gt; inside a refined arm; reject: an
&lt;code&gt;Eq&lt;/code&gt; arm on &lt;code&gt;Expr[int]&lt;/code&gt;, a contradiction in one row, a cyclic equality, a &lt;code&gt;Same[int, string]&lt;/code&gt;
matched, a missing case naming a possible variant, an arm unreachable after the possible variants
are covered.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hidden parameters.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-5&lt;/code&gt;):&lt;/em&gt; steps 2 and 3’s step-5 refusals are gone. A
value records the types it hides (&lt;code&gt;Construct&lt;/code&gt;‘s &lt;code&gt;hidden&lt;/code&gt;, at &lt;code&gt;hidden_positions&lt;/code&gt;); in &lt;code&gt;lower.sysl&lt;/code&gt;
each list of them at an instance is a pack (&lt;code&gt;pack_layout&lt;/code&gt;, &lt;code&gt;PackLayout&lt;/code&gt;), a descriptor of the
variant’s tag laying the fields out at the pack’s types. An arm, a clause and the derived code are
compiled once per combination of packs their hidden variant patterns can stand for
(&lt;code&gt;arm_packs&lt;/code&gt;), each tested by its descriptor (&lt;code&gt;test_packs&lt;/code&gt;); an alternative, an &lt;code&gt;is&lt;/code&gt; test and a
field read by name (&lt;code&gt;pack_field&lt;/code&gt;) try each pack in turn. Packs are found as lowering reaches the
code making them, so an instance compiled for fewer than the program makes is lowered again
(&lt;code&gt;relower_stale&lt;/code&gt;), and neither kind is kept in the instance cache. A lambda or local function in
such an arm carries its pack’s arguments after its copy’s (&lt;code&gt;pack_args&lt;/code&gt;), and a local whose type a
pattern decides gets a slot of the copy’s machine type where it is bound. Equality compares
descriptors first and hashes a pack’s number. In &lt;code&gt;check.sysl&lt;/code&gt;, a fresh type has the bounds its
variant declares (&lt;code&gt;fresh_bound_key&lt;/code&gt;), so a hidden parameter’s bounds, &lt;code&gt;T: A &amp;amp; B&lt;/code&gt; included, are
checked at the call and held in the arm, while a bound on a variant’s own parameter that its
result names stays refused (step 6); a derived trait, &lt;code&gt;Sendable&lt;/code&gt; included, holds of a hidden
parameter only by its bounds (&lt;code&gt;hidden_has&lt;/code&gt;, &lt;code&gt;hidden_sendable&lt;/code&gt;); a hidden type leaving its arm has
the chapter’s message; an &lt;code&gt;is&lt;/code&gt; test binds no field naming a hidden type. In &lt;code&gt;expansion.sysl&lt;/code&gt; the
fresh types of patterns are their variant’s parameter nodes, a value’s hidden types reach them,
and a type argument holding a hidden type does not grow a parameter the matched value holds
(&lt;code&gt;fresh_edges&lt;/code&gt;), so &lt;code&gt;eval(First(p))&lt;/code&gt; is ordinary and a cycle making ever larger packs is refused.
&lt;em&gt;Tests:&lt;/em&gt; run &lt;code&gt;refined_hidden&lt;/code&gt;, &lt;code&gt;refined_hidden_plan&lt;/code&gt;, &lt;code&gt;refined_hidden_protocol&lt;/code&gt;, the program
&lt;code&gt;refined_hidden_across_modules&lt;/code&gt;; reject &lt;code&gt;refined_hidden_escapes&lt;/code&gt;, &lt;code&gt;refined_hidden_tests&lt;/code&gt;,
&lt;code&gt;refined_hidden_growing&lt;/code&gt;, &lt;code&gt;refined_hidden_bounds&lt;/code&gt;, &lt;code&gt;refined_later_steps&lt;/code&gt; (now step 6’s alone) and
&lt;code&gt;refined_later_steps_reads&lt;/code&gt;. The plan as written: fresh rigid types in an arm; the escape check; packs: one descriptor per
variant and list of hidden types the program makes, fields laid out at the pack’s types; an arm
on such a variant lowered once per pack as a function of the hidden types and called through the
descriptor, reusing the dispatch &lt;code&gt;lower.sysl&lt;/code&gt; and &lt;code&gt;devirt.sysl&lt;/code&gt; build for generic trait methods;
equality comparing descriptors first; the polymorphic-recursion check extended to cycles that make
packs. &lt;em&gt;Tests:&lt;/em&gt; run: &lt;code&gt;First&lt;/code&gt; in &lt;code&gt;eval&lt;/code&gt;; a hidden value-type field (&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, a tuple) beside
a reference one; two packs of one variant compared unequal and hashed apart; the &lt;code&gt;Plan&lt;/code&gt; example
driving a &lt;code&gt;Door&lt;/code&gt; machine; reject: a hidden type leaving its arm as a result, through a local
settled in the arm, one value’s hidden type used with another’s; a growing pack cycle.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bounds on variant parameters.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-6&lt;/code&gt;):&lt;/em&gt; step 5’s step-6 refusal is gone, with
its test &lt;code&gt;refined_later_steps&lt;/code&gt;. A variant’s own parameter that its result names has its bounds
checked where a value is made, as a call’s are (the variant’s signature is generic over it); in
the arm the fresh type has them (step 5), and in &lt;code&gt;check.sysl&lt;/code&gt; an enclosing type parameter that an
equality in scope equates with a bounded one as a whole gains its bounds there
(&lt;code&gt;gained_bounds&lt;/code&gt;, carried in &lt;code&gt;Conformances.gained&lt;/code&gt; and read by &lt;code&gt;scope_bounds&lt;/code&gt;), so
&lt;code&gt;smallest[T](c: Coll[T])&lt;/code&gt; calls &lt;code&gt;items.minOption&lt;/code&gt; in the &lt;code&gt;Sorted&lt;/code&gt; arm. In &lt;code&gt;lower.sysl&lt;/code&gt; an
instance whose arguments fail a variant’s own bounds holds no value of it (&lt;code&gt;meets_own_bounds&lt;/code&gt;):
its layout has no descriptor for the variant and an arm, &lt;code&gt;is&lt;/code&gt; test or derived code on it is not
compiled there (&lt;code&gt;refine_one&lt;/code&gt;). Whether a refined type is sendable is decided at its instance
(&lt;code&gt;structural_sendability&lt;/code&gt; reads a variant’s own parameters back from the instance’s arguments,
and leaves out a variant the concrete instance cannot hold); a hidden parameter’s &lt;code&gt;Sendable&lt;/code&gt; stays
decided by its bounds, every pack having been checked where it was made. The &lt;code&gt;Account&lt;/code&gt; protocol
at &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;unit&lt;/code&gt; and the unsendable reply type’s refusal were built by step 5
(&lt;code&gt;refined_hidden_protocol&lt;/code&gt;, &lt;code&gt;refined_hidden_bounds&lt;/code&gt;). &lt;em&gt;Tests:&lt;/em&gt; run &lt;code&gt;refined_own_bounds&lt;/code&gt;,
&lt;code&gt;refined_own_bounds_actors&lt;/code&gt;, the program &lt;code&gt;refined_bounds_across_modules&lt;/code&gt;; reject
&lt;code&gt;refined_own_bounds&lt;/code&gt;, &lt;code&gt;refined_own_bounds_scope&lt;/code&gt;, &lt;code&gt;refined_own_bounds_parts&lt;/code&gt;, the program
&lt;code&gt;refined_bounds_across_modules&lt;/code&gt;. The plan as written: checked where a value is made; held in the
arm; gained by an enclosing type parameter equated with a bounded one; a copy at a type without
the bound leaves the arm out. &lt;em&gt;Tests:&lt;/em&gt; run: &lt;code&gt;Sorted[A: Ord]&lt;/code&gt; and &lt;code&gt;smallest&lt;/code&gt;; reject: a method of
a bound the variant does not give, through the equated parameter.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tooling and pages.&lt;/strong&gt; &lt;em&gt;Done (branch &lt;code&gt;gadt-7&lt;/code&gt;):&lt;/em&gt; hover and completion show a refined variant’s
signature with its own type parameters and its result (&lt;code&gt;definition_index.sysl&lt;/code&gt;, which both read
through &lt;code&gt;render_target&lt;/code&gt;; tests in &lt;code&gt;lsp_tests.sysl&lt;/code&gt;); the TextMate grammar already scopes the
&lt;code&gt;-&amp;gt;&lt;/code&gt; and result type of a variant, now pinned by &lt;code&gt;editors/grammar-tests/samples/refined.avin&lt;/code&gt;
(the IntelliJ plugin copies that grammar at build time); the chapter’s two complete programs are
&lt;code&gt;run&lt;/code&gt; fences with &lt;code&gt;output&lt;/code&gt; fences, so the corpus test compiles them. The chapter’s other
examples are fragments or show errors, so stay &lt;code&gt;text&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Stage 10’s incremental builds are designed in the &lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;pipeline&lt;/a&gt;, their
choices proposed in &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;decisions&lt;/a&gt;. The plan follows a measurement.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where the time goes (2026-11-10).&lt;/strong&gt; marshal (7,400 lines, with &lt;code&gt;json&lt;/code&gt;, &lt;code&gt;tui&lt;/code&gt; and the library it
reads) at &lt;code&gt;-O2&lt;/code&gt;, phases timed by a temporary instrument on a machine shared with other builds (load
average 30 to 55, so each figure is a range over runs):&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Phase&lt;/th&gt;&lt;th&gt;Cold&lt;/th&gt;&lt;th&gt;One-line edit (a string literal)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Load and parse&lt;/td&gt;&lt;td&gt;0.1 s&lt;/td&gt;&lt;td&gt;0.1 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Check (bodies 90% of it)&lt;/td&gt;&lt;td&gt;3.9 to 5.9 s&lt;/td&gt;&lt;td&gt;4.3 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Lower: instances&lt;/td&gt;&lt;td&gt;31 to 86 s&lt;/td&gt;&lt;td&gt;31 to 54 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Lower: devirtualize&lt;/td&gt;&lt;td&gt;10 to 40 s&lt;/td&gt;&lt;td&gt;10 to 40 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Lower: scalar replacement&lt;/td&gt;&lt;td&gt;12 to 31 s&lt;/td&gt;&lt;td&gt;12 to 22 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Shims&lt;/td&gt;&lt;td&gt;7.5 s (cached after)&lt;/td&gt;&lt;td&gt;0 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Emit&lt;/td&gt;&lt;td&gt;6 to 9 s&lt;/td&gt;&lt;td&gt;6 to 9 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Split into units&lt;/td&gt;&lt;td&gt;1.2 to 1.7 s&lt;/td&gt;&lt;td&gt;1.2 to 1.7 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;clang, units&lt;/td&gt;&lt;td&gt;13.5 s (8 units at once)&lt;/td&gt;&lt;td&gt;13 to 17 s (1 unit of 8)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Link&lt;/td&gt;&lt;td&gt;0.1 s&lt;/td&gt;&lt;td&gt;0.1 s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;91 s&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;65 s to 149 s&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The edit’s columns combine the edited build (149 s at a load average of 55) with an unedited one
that did the same work (65 s): &lt;code&gt;avin build&lt;/code&gt; lowers and emits the whole program every time.&lt;/p&gt;
&lt;p&gt;The program lowers to 71,646 functions and 237 MB of LLVM text. The edit changed one line of that
text and the unit cache recompiled one unit, so clang’s part is already incremental; &lt;strong&gt;lowering is
75 to 80% of an edit’s rebuild&lt;/strong&gt;. Most of it is one defect: a tuple type’s record lists as ancestors
every tuple its parts may be seen as, one part’s ancestor at a time, which is the product of each
part’s traits and itself, and every such record gets its own equality, hash and rendering entries,
each an instance of the tuple’s impl at trait types. &lt;code&gt;(Some(1), Some(2), Some(3))&lt;/code&gt; shown once makes
125 instances of the triple’s &lt;code&gt;display&lt;/code&gt;; a sextuple of options makes 28,433 functions and 162 MB of
text (hello is 303 and 1 MB). In marshal, 33,858 functions and about 100 MB of text are these
entries. Withholding the entries from tuple records with a trait part (a probe, not the fix) took
marshal to 39,879 functions and 126 MB and clang’s cold part to 8.2 s, but the sextuple still took
2.5 s and 13 MB in the ancestor lists themselves. A sampling profile of what lowering then spends
names copying and dropping a whole &lt;code&gt;FunctionSymbol&lt;/code&gt; by value in &lt;code&gt;lower_function&lt;/code&gt; (about a fifth of
its samples), &lt;code&gt;conformance_holds&lt;/code&gt;, &lt;code&gt;same_type&lt;/code&gt; and &lt;code&gt;collect_ancestors&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The items&lt;/strong&gt;, each one agent, gated on its own, in this order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tuple records.&lt;/strong&gt; No record for a tuple type no object has, and no entries for one: a tuple’s
ancestors are tested by its parts at run time rather than listed as the product. Tests: the
instance count of the triple and the sextuple bounded (the emitted text compared with a limit);
&lt;code&gt;is&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt; and equality on tuples seen as tuples of traits, &lt;code&gt;(Display, int)&lt;/code&gt; made directly and
shown, a tuple in &lt;code&gt;Any&lt;/code&gt; shown, compared and hashed, nested tuples, at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;. The
largest win, separable, and first. &lt;strong&gt;Done:&lt;/strong&gt; a tuple’s record holds its parts’ records and the
runtime tests a tuple target part by part; only a record some object has gets equality and
rendering entries. The sextuple of options shown once went from 47,181 functions and 273 MB to
309 and 1.1 MB (hello is 304); marshal from 71,663 functions and 237 MB to 40,478 and 126 MB,
its &lt;code&gt;emit-llvm&lt;/code&gt; from 165 s to 49 s and its &lt;code&gt;-O2&lt;/code&gt; build from 195 s to 55 s (load averages 107
and about 45, so the times are rough).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lowering’s constant factors&lt;/strong&gt;, led by a fresh profile after item 1: symbols read in place
rather than copied, and the conformance and type-equality hot spots memoized where the profile
says. Its tests are the existing suite; the report gives marshal’s before and after. &lt;strong&gt;Done:&lt;/strong&gt;
the fresh profile named loops whose work grew with the square of the program rather than
copying alone. Scalar replacement’s test that no two objects of a group are in use at once
(&lt;code&gt;overlapping&lt;/code&gt;) copied a vector of booleans per block per pass and repeated whole passes; it now
keeps 64 bits to a word and revisits only a block whose entry changed. Finding a function’s
boxed locals read, and copied, every symbol of the program for every instance; an index of each
function’s local functions, built once, replaced it. Recording a slot call searched every call
at its position; variant ancestors asked whether each record holds each tested class once per
tested type rather than once per class; and the dispatch sites asked the same questions again
for every call at one position on one receiver type. marshal’s lowering went from 24.3 s to
7.6 s, by the build log, at load averages of about 10 before and 20 after, with the emitted
text byte for byte the same. What remains of lowering is spread out: conformance questions
asked for the first time, devirtualization, method tables and scalar replacement, none above a
tenth.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Build log.&lt;/strong&gt; &lt;code&gt;AVIN_BUILD_LOG=&amp;lt;file&amp;gt;&lt;/code&gt;: each phase’s time and the counts of instances, units
compiled and units reused, with a test of its form on a small program. Every later item asserts
through it. Built: &lt;code&gt;AVIN_BUILD_LOG&lt;/code&gt; is a file or &lt;code&gt;-&lt;/code&gt;, one &lt;code&gt;phase=&amp;lt;name&amp;gt; ms=&amp;lt;n&amp;gt; rss=&amp;lt;n&amp;gt; inuse=&amp;lt;n&amp;gt; maxrss=&amp;lt;n&amp;gt; key=&amp;lt;n&amp;gt;&lt;/code&gt; line per phase, documented in the &lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;pipeline&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Stable names.&lt;/strong&gt; Types in instance keys and symbols spelled by qualified names; strings named by
content, descriptors and records by type, closures and trap sites by function and place; the
module-level tables in a codegen unit of their own. Test: adding a function or a string early in a
program changes no other function’s emitted text, and the unit counts in the log say one unit
plus the tables’ recompiled. &lt;strong&gt;Done:&lt;/strong&gt; every table is &lt;code&gt;@&amp;quot;avin.&amp;lt;kind&amp;gt;:&amp;lt;name&amp;gt;&amp;quot;&lt;/code&gt;, named as the
&lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;pipeline&lt;/a&gt; lists, and the tables are the last unit. A function, a
string, a class, a data type, a module-level value or blank lines added first in a program change
no other function’s text, and a function or string added recompiles 2 of 4 units at &lt;code&gt;-O0&lt;/code&gt; and
&lt;code&gt;-O2&lt;/code&gt;. marshal’s longest
symbol is 319 bytes, with no hash suffix; its text grew from 126 MB to 140 MB. Its edit of one
string in a leaf function rebuilds in 19.1 s against 19.0 s before (load average about 7), 3 units
of 8 compiled against 2: lowering, checking and emission are still most of it, which items 5 to 7
address, and the edited function, small enough to be copied into its callers’ units at &lt;code&gt;-O2&lt;/code&gt;,
reaches a third. The C unit’s glue is still named by the checker’s indices
(&lt;code&gt;avin_c_call_&amp;lt;symbol&amp;gt;&lt;/code&gt;, &lt;code&gt;avin_c_retain_&amp;lt;class&amp;gt;&lt;/code&gt;, and the handles’ finalizers), so a declaration
added before a C binding renames the binding’s calls.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Instance keys.&lt;/strong&gt; The canonical typed-tree fingerprint, the interfaces read and the world facts,
computed and logged but not yet used. Test: an edit matrix (a body, a signature, a field, a new
implementing class, a new impl, a changed default argument, an inferred type changed by a callee’s
result, a moved line) changes exactly the keys it must. &lt;strong&gt;Done:&lt;/strong&gt; every instance gets a key after
lowering, as the &lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;pipeline&lt;/a&gt; defines it, logged as &lt;code&gt;phase=keys&lt;/code&gt; with
&lt;code&gt;instances&lt;/code&gt;, &lt;code&gt;bodies&lt;/code&gt; and &lt;code&gt;distinct&lt;/code&gt;. Devirtualization and scalar replacement report what they
decided and read for each function, and lowering the slots it gave methods with type parameters of
their own (still numbered past the largest table in the order found, so a larger table anywhere
changes the keys of the calls through them, as it changes their text). The matrix builds a program
of three modules and edits a body, a signature, a constant and a computed default argument, adds an
overload, an implementing class, an impl for a data type and a class field, renames a data field,
changes a callee’s inferred result, a lambda, a lambda’s captures and a generic function, and adds
comments between declarations and inside one and moves a function; each changes exactly the keys
listed, the library’s included, and every function whose emitted text changed has a changed key.
Keys are the same across two builds and from another directory. On marshal at &lt;code&gt;-O2&lt;/code&gt;, 41,583
instances from 6,596 bodies, all keys different: the keys take 0.59 to 0.63 s against lowering’s
6.9 to 7.9 s (load average about 12).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The instance cache.&lt;/strong&gt; Store and reuse each instance’s text, requests and summary in
&lt;code&gt;.avin/build/incremental/&amp;lt;kind&amp;gt;&amp;lt;level&amp;gt;/&lt;/code&gt;, the worklist replaying requests, the passes rerun only
where facts changed; &lt;code&gt;AVIN_INCREMENTAL=verify&lt;/code&gt;. Tests: the edit matrix’s counts; the oracle
(incremental text equals a clean build’s) for every edit; two builds of one program at once both
correct; a truncated entry treated as a miss; trimming sparing the other level. &lt;strong&gt;Done:&lt;/strong&gt; with
&lt;code&gt;AVIN_INCREMENTAL=on&lt;/code&gt; (or &lt;code&gt;verify&lt;/code&gt;), &lt;code&gt;avin build&lt;/code&gt; and &lt;code&gt;avin emit-llvm&lt;/code&gt; keep, per module, a lowered
entry under each instance’s own key (the requests lowering it made, replayed through the
worklist, and its code by stable names) and a text entry under its finished key and the emission
facts, in CRC-checked module files named by their keys, a manifest written last and no lock, as
the &lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;pipeline&lt;/a&gt; defines; the passes still run over every instance.
The tests hold an edit matrix (a body, a default argument, a signature, a constant, a class field,
a renamed data field, an overload, an implementing class, an impl for a data type, a generic
function, a callee’s inferred result, a lambda’s body and captures, lines added above and inside
a function, a moved function, a call removed) to lowering exactly the instances with new own keys
and to a clean build’s text, and cover truncated, damaged and missing files, another compiler’s
entries, trimming, two builds at once, &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;, and a corpus sample built warm. On marshal
at &lt;code&gt;-O2&lt;/code&gt; (load average 30 to 70), a one-line leaf edit rebuilds in 21.1 s against 27.0 s without
the cache (cold 26.7 s against 26.9 s): emission 5.8 s to 1.5 s and the keys 0.8 s to 0.13 s, but
lowering only 11.0 s to 9.1 s with 24,246 of 41,583 instances’ code from the cache, since the
passes still run everywhere and checking (7 s) is untouched; &lt;code&gt;verify&lt;/code&gt; passes on the edit and back.
The cache is 22 module files, 185 MB.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The commands.&lt;/strong&gt; &lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; and the language server’s builds through it, the
corpus run with the cache warm as well as cold (each corpus program edited by a script and checked
against a clean build). &lt;strong&gt;Done:&lt;/strong&gt; the cache is on by default for &lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and
&lt;code&gt;emit-llvm&lt;/code&gt;, &lt;code&gt;off&lt;/code&gt; and &lt;code&gt;verify&lt;/code&gt; kept; &lt;code&gt;check&lt;/code&gt; keeps none, and the language server only checks, so
it builds nothing to cache. A program of one file names its directories after itself
(&lt;code&gt;hello-program-O2&lt;/code&gt;), and a manifest may name only module files of its own directory. With
&lt;code&gt;AVIN_INCREMENTAL=verify&lt;/code&gt; in the tests’ environment the corpus builds each program cold with the
cache, adds a function nothing calls to its first file, and builds it again in &lt;code&gt;verify&lt;/code&gt; mode, the
warm build being the one run; &lt;code&gt;avin test&lt;/code&gt; of the library and the packages runs in &lt;code&gt;verify&lt;/code&gt; too.
Its first run failed 10 of the 202 programs of many files, all with C bindings: the C unit’s glue
is named by the checker’s indices (&lt;code&gt;avin_c_call_&amp;lt;n&amp;gt;&lt;/code&gt;, &lt;code&gt;avin_c_field_get_&amp;lt;n&amp;gt;&lt;/code&gt;), which the edit
renumbered and no key held, and every C callback’s body had one key, so one binding’s took
another’s text. Code calling the glue is now lowered every build and the glue it calls is in its
text’s key, and a callback’s body is keyed by its binding and trampoline. The second run passed
whole: the 1,221 programs of &lt;code&gt;tests/run&lt;/code&gt;, the 202 of &lt;code&gt;tests/programs/run&lt;/code&gt;, the examples, the example
packages, the library’s and the packages’ tests, 25 tests. The commands’ tests build, run and test
a program, edit it and hold each rebuild to a clean build’s program and text; hold &lt;code&gt;off&lt;/code&gt; to reading
and writing nothing; survive damaged files, a manifest of nonsense, another compiler’s cache and
trimming; and run two &lt;code&gt;avin test&lt;/code&gt;, and a &lt;code&gt;run&lt;/code&gt; beside a &lt;code&gt;test&lt;/code&gt;, of one program at once.
On marshal’s 138 modules (one &lt;code&gt;avin build&lt;/code&gt;, the whole machine reserved, load average 4 to 6 at the
start and end; the object-unit cache emptied before each cold build and the edit new to it on every
edit build; median of 3 runs, spread in brackets; &lt;code&gt;emit&lt;/code&gt; from the build log):&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Build&lt;/th&gt;&lt;th&gt;&lt;code&gt;-O0&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;-O2&lt;/code&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Cold, no cache&lt;/td&gt;&lt;td&gt;6.06 s [5.99 to 6.09]&lt;/td&gt;&lt;td&gt;8.79 s [8.75 to 8.84]&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Cold, with the cache&lt;/td&gt;&lt;td&gt;6.54 s [6.52 to 6.66]&lt;/td&gt;&lt;td&gt;9.33 s [9.32 to 9.39]&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Warm, no edit&lt;/td&gt;&lt;td&gt;4.88 s [4.86 to 4.92]&lt;/td&gt;&lt;td&gt;4.93 s [4.92 to 4.96]&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;One-line edit, no cache&lt;/td&gt;&lt;td&gt;5.81 s [5.77 to 5.85] (emit 1.21 s)&lt;/td&gt;&lt;td&gt;7.47 s [7.41 to 7.95] (emit 1.32 s)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;One-line edit, with the cache&lt;/td&gt;&lt;td&gt;5.02 s [5.01 to 5.09] (emit 0.30 s)&lt;/td&gt;&lt;td&gt;6.72 s [6.69 to 6.80] (emit 0.30 s)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;An edit’s rebuild is 14% faster at &lt;code&gt;-O0&lt;/code&gt; and 10% at &lt;code&gt;-O2&lt;/code&gt; with the cache: the cache read (0.23 s)
and write (0.04 s) cost less than the 0.9 s of emission it saves, and what remains is loading
(0.06 s), checking (1.4 s), lowering (2.0 s, 11,902 of 15,447 instances reused, the rest lowered
again), splitting and linking, which the cache does not touch; at &lt;code&gt;-O2&lt;/code&gt; clang’s compile of the
changed units (2.1 s) is the other part. A cold build with the cache costs 0.5 s more than
without it (the store). A level’s directory is 185 MB in 22 module files.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Only if measured after 7:&lt;/strong&gt; the front end. If checking becomes the larger part of an edit’s
rebuild, a design for checked interfaces per module (today one checker holds the whole program by
index, so this is a rewrite of how symbols are numbered, not a cache).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;contextual-parameters-build-plan&quot;&gt;Contextual parameters: build plan&lt;/h3&gt;
&lt;p&gt;Designed in &lt;a href=&quot;/spec/contextual-parameters/&quot;&gt;contextual parameters&lt;/a&gt;, its choices
&lt;a href=&quot;/spec/decisions/#settled&quot;&gt;settled&lt;/a&gt;. Steps 1 and 2 are done (branch &lt;code&gt;given-1&lt;/code&gt;), step 3 too (branch
&lt;code&gt;given-3&lt;/code&gt;), step 4 (branch &lt;code&gt;given-4&lt;/code&gt;), step 5 (branch &lt;code&gt;given-5&lt;/code&gt;) and step 6 (branch &lt;code&gt;given-6&lt;/code&gt;). A filled argument becomes an ordinary
argument in the checker’s output, so lowering, emission and the runtime change nothing; every step
is in the front end and tooling. Each step is one agent, gated on its own with the files it names.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Syntax.&lt;/strong&gt; &lt;code&gt;given name [: Type] = value&lt;/code&gt; in blocks, at a module’s top level and in object
bodies, with &lt;code&gt;given&lt;/code&gt; a keyword only there at a statement’s or declaration’s start; a trailing
&lt;code&gt;using&lt;/code&gt; section in the parameter lists of functions, methods, static members, class constructors,
actors and lambdas, &lt;code&gt;using&lt;/code&gt; a keyword only before a parameter’s name; the syntax tree, &lt;code&gt;avin fmt&lt;/code&gt;
(a long list breaks before &lt;code&gt;using&lt;/code&gt; as before any parameter), &lt;code&gt;syntax_show&lt;/code&gt;. Files: &lt;code&gt;parser.sysl&lt;/code&gt;,
&lt;code&gt;parse_decl.sysl&lt;/code&gt;, &lt;code&gt;parse_block.sysl&lt;/code&gt;, &lt;code&gt;parse_actor.sysl&lt;/code&gt;, &lt;code&gt;syntax.sysl&lt;/code&gt;, &lt;code&gt;formatter.sysl&lt;/code&gt;,
&lt;code&gt;syntax_show.sysl&lt;/code&gt;; tests in &lt;code&gt;parse_tests.sysl&lt;/code&gt; and &lt;code&gt;formatter_tests.sysl&lt;/code&gt;. Proof that nothing
existing changes meaning: &lt;code&gt;git grep -n -E &amp;quot;^\s*given\b&amp;quot;&lt;/code&gt; over &lt;code&gt;library/&lt;/code&gt;, &lt;code&gt;tests/&lt;/code&gt;, &lt;code&gt;examples/&lt;/code&gt;
and marshal’s and tui’s sources prints nothing, and the corpus is unchanged (&lt;code&gt;args.given(…)&lt;/code&gt;,
&lt;code&gt;iterable.avin&lt;/code&gt;‘s field &lt;code&gt;given&lt;/code&gt;). &lt;strong&gt;Done&lt;/strong&gt; (branch &lt;code&gt;given-1&lt;/code&gt;): &lt;code&gt;given&lt;/code&gt; begins a given where a
name and its &lt;code&gt;:&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt; follow it, or &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; or a capitalized name (reported); &lt;code&gt;using&lt;/code&gt;
begins the section where a name follows it, also in a parenthesized lambda’s list and as
&lt;code&gt;using tx -&amp;gt;&lt;/code&gt;, alone or trailing a call. The syntax tree carries &lt;code&gt;Param.contextual&lt;/code&gt;,
&lt;code&gt;LambdaParam.contextual&lt;/code&gt;, &lt;code&gt;FieldDecl.given&lt;/code&gt; and the block’s &lt;code&gt;GivenBinding&lt;/code&gt;. Tests:
&lt;code&gt;parse_tests.sysl&lt;/code&gt; (&lt;code&gt;given_*&lt;/code&gt;, &lt;code&gt;using_*&lt;/code&gt;), &lt;code&gt;formatter_tests.sysl&lt;/code&gt; (&lt;code&gt;fmt_contextual_parameters&lt;/code&gt;),
&lt;code&gt;tests/reject/given_syntax.avin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Declarations.&lt;/strong&gt; Given symbols as module values, object members and block locals; &lt;code&gt;using&lt;/code&gt;
parameters on function symbols; the refusals with their messages (a type parameter in a
contextual type, a built-in, tuple, function or union type, a trait that is only a bound, a
second given of one type in a scope, &lt;code&gt;given&lt;/code&gt; in a class/trait/data body, a section on a variant,
&lt;code&gt;main&lt;/code&gt;, &lt;code&gt;@test&lt;/code&gt;, a hook, &lt;code&gt;@sysl&lt;/code&gt;/&lt;code&gt;@c&lt;/code&gt;, an unnamed given, an implementation whose section differs
from its trait method’s). Files: &lt;code&gt;check.sysl&lt;/code&gt;, &lt;code&gt;names.sysl&lt;/code&gt;. Tests: &lt;code&gt;tests/reject/given_*.avin&lt;/code&gt;,
one refusal per file group of at most five errors. &lt;strong&gt;Done&lt;/strong&gt; (branch &lt;code&gt;given-1&lt;/code&gt;): a block’s given
is a &lt;code&gt;val&lt;/code&gt; recorded in &lt;code&gt;BodyState.givens&lt;/code&gt;; a module’s is a &lt;code&gt;GlobalSymbol&lt;/code&gt; with &lt;code&gt;given&lt;/code&gt; set; an
object’s is a field its declaration marks; each is held to its type and to one of a type per
scope (&lt;code&gt;check_givens&lt;/code&gt;, &lt;code&gt;given_binding_expr&lt;/code&gt;). A function’s clauses match the parameters before
its section. Calls are untouched: a contextual parameter is still an ordinary one at a call, so
explicit &lt;code&gt;tx = …&lt;/code&gt; works and a missing one is the missing-argument error until step 3, which
also owes a call to a function whose repeated parameter is followed by a section (today the
repeated parameter is taken as last). Tests: &lt;code&gt;tests/reject/given_{block_types,second_of_type, bodies,using_types,using_types_more,using_positions,using_implementations,using_names}.avin&lt;/code&gt;,
&lt;code&gt;tests/run/given_{declarations,using_declared}.avin&lt;/code&gt;, &lt;code&gt;tests/programs/run/given_module_files&lt;/code&gt;,
&lt;code&gt;tests/programs/reject/given_module_second&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resolution at calls.&lt;/strong&gt; After an overload is chosen, fill each contextual parameter: a named
argument, then the levels of the chapter’s scope walk, then the default; the errors for none,
two, and a positional argument; defaults seeing the section; class constructors, &lt;code&gt;super&lt;/code&gt;
arguments, companions’ &lt;code&gt;apply&lt;/code&gt;, infix calls, clauses, static members through a bound, trait
methods through a trait type and through a bound, extensions. Files: &lt;code&gt;check.sysl&lt;/code&gt;. Tests:
&lt;code&gt;tests/run/given_*.avin&lt;/code&gt; and &lt;code&gt;tests/reject/given_*.avin&lt;/code&gt;. &lt;strong&gt;Done&lt;/strong&gt; (branch &lt;code&gt;given-3&lt;/code&gt;):
&lt;code&gt;fill_contextual&lt;/code&gt; runs in &lt;code&gt;apply&lt;/code&gt; after the written arguments bind, so every call shape that
reaches &lt;code&gt;apply&lt;/code&gt; fills its section; &lt;code&gt;fitting_givens&lt;/code&gt; walks the levels (block givens and local
functions’ and lambdas’ contextual parameters by their scope in &lt;code&gt;visible&lt;/code&gt;, then the checked
function’s parameters, the class’s constructor fields, the object’s given fields, the module’s
givens of every file) and a filled argument is a by-name argument already checked, so lowering is
untouched. Positional arguments and a trailing block reach only the parameters before the section;
a repeated parameter followed by a section binds and packs at its own position; the section’s
defaults are computed first, each seeing the section before it, and an ordinary default takes the
whole section after its earlier parameters (&lt;code&gt;default_inputs&lt;/code&gt;). A &lt;code&gt;using&lt;/code&gt; lambda’s parameters are
givens in its body already. Givens imported from another module fill nothing yet (step 4); a
function value’s section is step 5’s. Tests:
&lt;code&gt;tests/run/given_calls_{levels,shapes,edges}.avin&lt;/code&gt;, &lt;code&gt;tests/reject/given_calls_{none,scope,two, positional,values}.avin&lt;/code&gt;, &lt;code&gt;tests/programs/run/given_module_files&lt;/code&gt;,
&lt;code&gt;tests/programs/reject/given_import_{whole,named}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modules and imports.&lt;/strong&gt; A named import (direct, braced, &lt;code&gt;as&lt;/code&gt;, through an export) brings a given
in; a whole import does not, with the hint naming the import to write; &lt;code&gt;private&lt;/code&gt;; module and
object givens made in initialization order; a module of several files sharing its givens.
Files: &lt;code&gt;check.sysl&lt;/code&gt;, &lt;code&gt;names.sysl&lt;/code&gt;, &lt;code&gt;incremental.sysl&lt;/code&gt; (a module’s givens are part of what an
importing file depends on). Tests: &lt;code&gt;tests/programs/run/given_*&lt;/code&gt; and &lt;code&gt;tests/programs/reject/given_*&lt;/code&gt;.
&lt;strong&gt;Done&lt;/strong&gt; (branch &lt;code&gt;given-4&lt;/code&gt;): &lt;code&gt;given_module_level&lt;/code&gt; takes, beside the module’s own givens, the givens
another module declares that the module exports by name and those the call’s file imports by name
(each under the name its export or import binds, one given however many names reach it); the “no
given” error adds, for each public fitting given of a module the file imports whole, the import to
write (&lt;code&gt;given_import_hint&lt;/code&gt;). Imported givens need nothing of the instance cache: a filled argument
reads the module-level value, whose interface a key already holds. Initialization order needed no
change, a given being a module-level value. Tests: &lt;code&gt;tests/programs/run/given_import_{forms,named}&lt;/code&gt;,
&lt;code&gt;tests/programs/reject/given_import_{whole,per_file,private,two}&lt;/code&gt;, &lt;code&gt;given_import_tests.sysl&lt;/code&gt;,
&lt;code&gt;instance_cache_tests.sysl&lt;/code&gt; (&lt;code&gt;imported_given_*&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lambdas, function values, threads and actors.&lt;/strong&gt; &lt;code&gt;using&lt;/code&gt; lambda parameters as givens in the
body; a function or method taken as a value filled where taken; captures of givens through the
existing capture analysis; the &lt;code&gt;@sendable&lt;/code&gt;, &lt;code&gt;spawn&lt;/code&gt;, executor-task and actor checks naming a
captured given; actor constructors’ sections. Files: &lt;code&gt;check.sysl&lt;/code&gt;. Tests: run and reject files as
above. &lt;strong&gt;Done&lt;/strong&gt; (branch &lt;code&gt;given-5&lt;/code&gt;): &lt;code&gt;function_value&lt;/code&gt; and &lt;code&gt;method_value&lt;/code&gt; take the parameters before
the section, and with a section make the value a closure (&lt;code&gt;value_closure&lt;/code&gt;) whose body is the call a
call written there would be, checked with the closure as the current function and its parameters
passed as checked arguments (&lt;code&gt;passed_on&lt;/code&gt;, a repeated one spliced), so &lt;code&gt;apply&lt;/code&gt; fills the section
from the givens in scope where the value is taken or from its defaults, and each given read is
recorded as the closure’s capture. Overloads, an object’s &lt;code&gt;apply&lt;/code&gt; and constructors are chosen by
the parameters before the section. The &lt;code&gt;spawn&lt;/code&gt;, &lt;code&gt;@sendable&lt;/code&gt;, executor and actor checks name a
captured given through the existing capture analysis; an actor’s section is held to &lt;code&gt;Sendable&lt;/code&gt; as
any actor parameter. Tests: &lt;code&gt;tests/run/given_{values,captures,threads}.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/given_calls_values.avin&lt;/code&gt;, &lt;code&gt;tests/reject/given_values_{more,threads}.avin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tooling.&lt;/strong&gt; Hover on a call shows each filled argument and the given it came from; go to
definition from a call to the given it used; completion offers &lt;code&gt;given&lt;/code&gt; and &lt;code&gt;using&lt;/code&gt;. Files:
&lt;code&gt;lsp.sysl&lt;/code&gt;, &lt;code&gt;completion.sysl&lt;/code&gt;, &lt;code&gt;definition_index.sysl&lt;/code&gt;; tests in &lt;code&gt;lsp_tests.sysl&lt;/code&gt;. The
IntelliJ plugin’s grammar (&lt;code&gt;avin-intellij&lt;/code&gt;) is its own item, shipped with the release that
carries step 1. &lt;strong&gt;Done&lt;/strong&gt; (branch &lt;code&gt;given-6&lt;/code&gt;): &lt;code&gt;fill_contextual&lt;/code&gt; records each call’s givens
(&lt;code&gt;index_filled_call&lt;/code&gt;), and when the call is indexed each becomes a reference at the call’s name
marked &lt;code&gt;filled&lt;/code&gt; with its parameter (&lt;code&gt;index_fills&lt;/code&gt;). Hover adds “Filled from givens:” with
&lt;code&gt;tx = current  // val current: Tx&lt;/code&gt; per parameter; definition answers the function, then each
given; a given’s references and highlights include the calls it filled; rename and semantic
tokens leave them out. Signatures write &lt;code&gt;using&lt;/code&gt; once before the section, and a completed call’s
snippet leaves the section out. &lt;code&gt;completion_keywords&lt;/code&gt; offers &lt;code&gt;given&lt;/code&gt; and &lt;code&gt;using&lt;/code&gt; where a form may
begin with them. Tests: &lt;code&gt;lsp_tests.sysl&lt;/code&gt; (&lt;code&gt;lsp_hover_filled_call&lt;/code&gt;, &lt;code&gt;lsp_definition_filled_call&lt;/code&gt;,
&lt;code&gt;lsp_references_filled_call&lt;/code&gt;, &lt;code&gt;lsp_semantic_tokens_filled_call&lt;/code&gt;, &lt;code&gt;lsp_definition_given_levels&lt;/code&gt;,
&lt;code&gt;lsp_definition_given_other_file&lt;/code&gt;, &lt;code&gt;lsp_signature_using_section&lt;/code&gt;, &lt;code&gt;lsp_completion_given_using&lt;/code&gt;,
&lt;code&gt;lsp_completion_keywords_of_sites&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;The test matrix.&lt;/strong&gt; Each claim of the chapter is a test; these are the cases the steps owe.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Declaring&lt;/em&gt;: givens of a class, an object, a trait type, a &lt;code&gt;data&lt;/code&gt; type with one and several
variants, a generic instance (&lt;code&gt;Pool[Conn]&lt;/code&gt;), a value type &lt;code&gt;data Retries(count: int)&lt;/code&gt;; a given with
a declared wider type; scope from the declaration on (a call before it sees the outer one); a given
not in its own value; a nested block’s given hiding an outer one; a Unicode-named given; &lt;code&gt;given&lt;/code&gt;
still an ordinary name after &lt;code&gt;.&lt;/code&gt;, in a class body, as a field and after &lt;code&gt;then&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Calls&lt;/em&gt;: a given filling a supertype’s parameter; a subtype parameter not filled by a supertype
given; explicit &lt;code&gt;tx = …&lt;/code&gt; beating a given; the default with no given and not with one; a default
seeing the section; forwarding through recursion, mutual recursion and a tail call (still a tail
call at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;); local functions; overloads where the written arguments choose and a
missing given does not fall back; infix calls; clauses; a static member through &lt;code&gt;T.m()&lt;/code&gt;; a trait
method through a trait-typed value (dynamic dispatch) and through a bound; an extension’s method.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Classes and actors&lt;/em&gt;: a constructor’s section used in field initializers and methods; a subclass
passing its own given to its superclass; a companion’s &lt;code&gt;apply&lt;/code&gt;; an actor taking a sendable given.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Generics&lt;/em&gt;: a generic function calling a contextual one at many type arguments, one given for all;
&lt;code&gt;[T: Ord]&lt;/code&gt; code with an unrelated given in scope ordering by &lt;code&gt;T&lt;/code&gt;‘s impl (the coherence claim: a
&lt;code&gt;TreeSet&lt;/code&gt; built in one file and searched in another with givens around keeps its order).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Lambdas&lt;/em&gt;: a closure capturing a given and called after its block ends, under GC stress; a &lt;code&gt;using&lt;/code&gt;
lambda parameter; a method value filled where taken; the error where none is in scope.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Imports&lt;/em&gt;: named, braced, renamed and exported imports bring a given; a whole import does not
(reject, with the hint); a private given not importable; a module given beside an imported one of
a fitting type (reject, both named).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Refusals&lt;/em&gt;: each message of the chapter’s diagnostics list, and each refused type and position.&lt;/li&gt;
&lt;li&gt;Every run test at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; and under GC stress, as the corpus runs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;sound-initialization-build-plan&quot;&gt;Sound initialization: build plan&lt;/h3&gt;
&lt;p&gt;Designed in &lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;Initialization&lt;/a&gt;, its choices proposed in
&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;decisions&lt;/a&gt;: no field, module-level value or &lt;code&gt;lazy val&lt;/code&gt; is read before it
is set, proved when the program is compiled.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What 0.0.21 does (probed 2026-11-13).&lt;/strong&gt; The class-body rule, the open-class rule, trait fields,
the module order (within and across modules, through calls, dispatch, operators, iterators,
default arguments and lambdas made) and locals are all checked at compile time, and every probe of
them was refused with the error the chapter gives or ran correctly. What is not:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Probe&lt;/th&gt;&lt;th&gt;What happens&lt;/th&gt;&lt;th&gt;Kind&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;A lambda in a superclass’s arguments reading a field, &lt;code&gt;class Late: Base(() -&amp;gt; late)&lt;/code&gt;, the superclass calling it in its body&lt;/td&gt;&lt;td&gt;a &lt;code&gt;long&lt;/code&gt; field read &lt;code&gt;0&lt;/code&gt;; a &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt; or generic field crashed (exit 139)&lt;/td&gt;&lt;td&gt;closed by item 1: refused&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The same with a method value, &lt;code&gt;Base(name)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;crashed (exit 139)&lt;/td&gt;&lt;td&gt;closed by item 1: refused&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The same with an argument passed by name, &lt;code&gt;Base(pick(true, s * 2))&lt;/code&gt;&lt;/td&gt;&lt;td&gt;read &lt;code&gt;0&lt;/code&gt;&lt;/td&gt;&lt;td&gt;closed by item 1: refused&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The same for an inherited field, &lt;code&gt;Leaf: Mid(() -&amp;gt; m)&lt;/code&gt; with &lt;code&gt;m&lt;/code&gt; Mid’s&lt;/td&gt;&lt;td&gt;read &lt;code&gt;0&lt;/code&gt;&lt;/td&gt;&lt;td&gt;closed by item 1: refused&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The same from an &lt;code&gt;object&lt;/code&gt; extending a class&lt;/td&gt;&lt;td&gt;read &lt;code&gt;0&lt;/code&gt;&lt;/td&gt;&lt;td&gt;closed by item 1: refused&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lazy val first = second + 1&lt;/code&gt;, &lt;code&gt;lazy val second = first + 1&lt;/code&gt;; a field &lt;code&gt;lazy val l = l + 1&lt;/code&gt;&lt;/td&gt;&lt;td&gt;trap at run time, although the cycle is in the code&lt;/td&gt;&lt;td&gt;module-level closed by item 3, fields and locals by item 4: refused&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A lazy’s initializer joining a thread that reads the same lazy&lt;/td&gt;&lt;td&gt;waits for ever&lt;/td&gt;&lt;td&gt;liveness&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;object O&lt;/code&gt; whose &lt;code&gt;lazy val&lt;/code&gt; or a lambda made after its last field names &lt;code&gt;O.k&lt;/code&gt;&lt;/td&gt;&lt;td&gt;refused: &lt;code&gt;O&lt;/code&gt; is needed by its own initializer (bare &lt;code&gt;k&lt;/code&gt; is accepted)&lt;/td&gt;&lt;td&gt;closed by item 2: accepted&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The holes have one cause: &lt;code&gt;field_read&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt; refuses a field read only when the
constructor is the current function, and the superclass’s arguments are never scanned by
&lt;code&gt;check_class_initialization&lt;/code&gt;, so a function made there (a lambda, a by-name thunk, a method value)
reads the object unchecked. Nothing in &lt;code&gt;library/&lt;/code&gt;, &lt;code&gt;examples/&lt;/code&gt; or &lt;code&gt;packages/&lt;/code&gt; passes such a
function (grep of every class header with a superclass call for &lt;code&gt;-&amp;gt;&lt;/code&gt;: none), so closing it changes
no code there. The &lt;code&gt;lazy&lt;/code&gt; change turns &lt;code&gt;tests/run/lazy_cycle.avin&lt;/code&gt; and
&lt;code&gt;tests/run/lazy_threads_cycle.avin&lt;/code&gt; into reject tests; the library’s own self-referring lazy values
(the &lt;code&gt;LazyList&lt;/code&gt; knots in &lt;code&gt;lazy_list.avin&lt;/code&gt;) read themselves by name inside an argument passed by
name, which stays legal.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;All four items are done&lt;/strong&gt;: every probe above is refused at compile time or runs correctly, but
the liveness case, which the chapter leaves to the threads rule. The items, each one agent, gated
on its own, in this order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Done: superclass arguments use nothing of the object.&lt;/strong&gt; &lt;code&gt;check_class_initialization&lt;/code&gt; scans the
superclass-initialization item with an &lt;code&gt;InitScan&lt;/code&gt; for the superclass’s arguments (no field
ready, inherited or own), so a lambda, a by-name argument, a local function or a method value
that uses &lt;code&gt;self&lt;/code&gt;, a field or a method is an error with the chapter’s wording; objects extending a
class go through the same path. Files: &lt;code&gt;compiler/dev/avinlang/compiler/check.sysl&lt;/code&gt;
(&lt;code&gt;check_class_initialization&lt;/code&gt;, &lt;code&gt;init_violation&lt;/code&gt;‘s wording, the method-value case near
&lt;code&gt;check.sysl:15773&lt;/code&gt;). Tests: &lt;code&gt;tests/reject/initialization_super_args.avin&lt;/code&gt; (a lambda reading an own
field, one reading an inherited field, a method value, a by-name argument, an object’s
arguments) and &lt;code&gt;tests/reject/initialization_super_args_more.avin&lt;/code&gt; (a generic superclass, a lambda
inside a lambda, a lambda calling a method, one in a tuple or a collection argument, a lambda
through two levels of superclass); &lt;code&gt;tests/run/initialization_super_args.avin&lt;/code&gt;, the legal cases
(functions capturing class parameters, module values and another object, a by-name argument
reading a parameter, the superclass calling each in its body), at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; under GC
stress. Every 2026-11-13 hole above is one of these cases. Also
&lt;code&gt;tests/reject/initialization_super_args_shapes.avin&lt;/code&gt; (a collection argument, a &lt;code&gt;lazy val&lt;/code&gt;, a
closure in an argument object’s field, a &lt;code&gt;with&lt;/code&gt; copy, a conditional argument),
&lt;code&gt;tests/reject/initialization_super_args_values.avin&lt;/code&gt; (a method value inside a lambda, a lambda
assigning a field, a by-name argument making a lambda, a trait’s &lt;code&gt;val&lt;/code&gt; the class supplies, a
generic subclass) and &lt;code&gt;tests/programs/reject/initialization_super_args&lt;/code&gt; (the superclass in
another module). A method of the object named as a value there is refused where it is written,
as a call of one already was. A local function cannot be written in a superclass’s arguments,
which take no block, so the scan’s case for one is reached by no source today.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Done: an object’s name is &lt;code&gt;self&lt;/code&gt; in its own body.&lt;/strong&gt; &lt;code&gt;global_read&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;, where every
read of a module-level value is made (a bare name, a call of the object’s &lt;code&gt;apply&lt;/code&gt;, its constructor
by the companion’s name, a pattern naming it), reads the object’s own name as &lt;code&gt;self&lt;/code&gt; inside its
body, methods, overrides, lambdas and lazy initializers, so the object rules apply to it and the
module order counts only what the body runs while the object is made; the editor still shows the
name as the object’s declaration. Tests: &lt;code&gt;tests/run/initialization_object_self_name.avin&lt;/code&gt; (a lazy
field reading &lt;code&gt;O.k&lt;/code&gt;, a lambda made after the last field stored and called later and one called at
once, a method, an override calling &lt;code&gt;super&lt;/code&gt;, an object extending a class and a generic class, the
field it inherits read before its own, a field assigned through the name, a companion’s
constructor and &lt;code&gt;apply&lt;/code&gt;, a pattern naming the object, two objects naming each other, a thread
and a future in a method of an object with no &lt;code&gt;var&lt;/code&gt;, a module value declared above the object
reading it), &lt;code&gt;tests/reject/initialization_object_self_name.avin&lt;/code&gt; (&lt;code&gt;O.y&lt;/code&gt; above &lt;code&gt;y&lt;/code&gt;, &lt;code&gt;O&lt;/code&gt; passed
before the last field, &lt;code&gt;O.m()&lt;/code&gt; before the last field, &lt;code&gt;O&lt;/code&gt; read in its superclass’s arguments
directly and in a lambda), &lt;code&gt;tests/reject/initialization_object_self_name_more.avin&lt;/code&gt; (a lambda, a
method value, a &lt;code&gt;lazy val&lt;/code&gt; read and a by-name argument through the name before the last field;
a function outside the body reading the object, called while it is made, still a cycle),
&lt;code&gt;tests/programs/run/initialization_object_self_name&lt;/code&gt; and
&lt;code&gt;tests/programs/reject/initialization_object_self_name&lt;/code&gt; (the object in another module), and an
&lt;code&gt;lsp_tests.sysl&lt;/code&gt; case for definition from the name in the body. A field &lt;code&gt;lazy val l = O.l + 1&lt;/code&gt;
in an object, a run-time trap here as a bare &lt;code&gt;l&lt;/code&gt; was, is refused by item 4.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Done: module-level lazy cycles at compile time.&lt;/strong&gt; &lt;code&gt;Uses&lt;/code&gt; (&lt;code&gt;globals.sysl&lt;/code&gt;) keeps the functions
a body calls (&lt;code&gt;calls&lt;/code&gt;) apart from those it makes (&lt;code&gt;made&lt;/code&gt;: lambdas, by-name thunks, method
values); &lt;code&gt;check_lazy_cycles&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt; follows only calls and the lazy values read
(&lt;code&gt;lazies_reached&lt;/code&gt;), stopping at another lazy value’s initializer, and a module-level &lt;code&gt;lazy val&lt;/code&gt;
that reaches itself is an error naming the chain of lazy values, reported from its
earliest-declared member as module cycles are. The module order follows both, except a &lt;code&gt;lazy val&lt;/code&gt; field’s initializer where a constructor makes it (only a read runs it, and a read is a
call), which removed the false cycle of two objects whose lazy fields read each other. The
run-time trap stays for reads through handed-on functions. Tests: &lt;code&gt;tests/reject/lazy_cycles.avin&lt;/code&gt;
(itself, through another lazy, through a function, through a trait’s implementation, through an
operator), &lt;code&gt;tests/reject/lazy_cycles_more.avin&lt;/code&gt; (an &lt;code&gt;open&lt;/code&gt; class’s override, a generic function,
a generic class’s method, a default argument, a comparison operator),
&lt;code&gt;tests/reject/lazy_cycles_reach.avin&lt;/code&gt; (a chain of three named from its earliest member when the
check meets it from outside, a lazy field’s initializer, an iterator’s &lt;code&gt;next&lt;/code&gt; in a &lt;code&gt;for&lt;/code&gt;, a local
&lt;code&gt;lazy val&lt;/code&gt; in a called function, two values read by two threads),
&lt;code&gt;tests/reject/lazy_field_made_order.avin&lt;/code&gt; (a body reading its own lazy field, a lambda made and
called while the object is made: still module cycles), &lt;code&gt;tests/reject/lazy_cycle.avin&lt;/code&gt; (moved
from &lt;code&gt;tests/run&lt;/code&gt;), &lt;code&gt;tests/programs/reject/lazy_cycle_modules/&lt;/code&gt; (across two modules),
&lt;code&gt;tests/run/lazy_self_deferred.avin&lt;/code&gt; (&lt;code&gt;ones&lt;/code&gt;, the Fibonacci knot, &lt;code&gt;#::&lt;/code&gt;, a handler naming its own
value, a method value stored, self-recursive and mutually recursive lambdas, a generic cell, a
chain with no cycle, the two objects, a value holding a class and a generic class whose lazy
field reads it, threads), &lt;code&gt;tests/programs/run/lazy_objects_modules&lt;/code&gt; (the objects across two
modules), &lt;code&gt;tests/run/lazy_deferred_trap.avin&lt;/code&gt; (a lambda the initializer makes and calls at once:
still the trap, &lt;code&gt;.err&lt;/code&gt;) and &lt;code&gt;tests/run/lazy_deferred_trap_passed.avin&lt;/code&gt; (one passed to a function
that calls it).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Done: field and local lazy cycles at compile time.&lt;/strong&gt; &lt;code&gt;check_lazy_field_cycles&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;
follows each lazy field’s initializer (&lt;code&gt;reach_function&lt;/code&gt;, &lt;code&gt;LazyReach&lt;/code&gt;) with the places its code
holds the object (&lt;code&gt;SelfAt&lt;/code&gt;: the captured &lt;code&gt;self&lt;/code&gt;, a local given it, the parameter a called function
receives it in, and an object’s name anywhere), through calls, the overrides a call through a
slot on the object may reach in classes descending from the field’s, operators and local
functions; a read of another instance is not followed. &lt;code&gt;check_local_lazy_cycles&lt;/code&gt; follows each
local &lt;code&gt;lazy val&lt;/code&gt;‘s lambda through its block and the local functions it calls. Both report
through &lt;code&gt;report_lazy_cycle&lt;/code&gt;, worded as the module-level check. Tests:
&lt;code&gt;tests/reject/lazy_field_cycles.avin&lt;/code&gt; (direct, through another lazy field, a method, &lt;code&gt;self.x&lt;/code&gt;, a
subclass’s override), &lt;code&gt;lazy_field_cycles_generic.avin&lt;/code&gt; (a generic class, a chain, a generic
method, a generic subclass’s override, a generic function given &lt;code&gt;self&lt;/code&gt;),
&lt;code&gt;lazy_field_cycles_object.avin&lt;/code&gt; (bare name, the object’s name, a function outside the body, a
module-level lazy between), &lt;code&gt;lazy_field_cycles_more.avin&lt;/code&gt; (an object extending a class, an
actor, an operator, &lt;code&gt;val me = self&lt;/code&gt;, a local function), &lt;code&gt;lazy_field_cycles_reach.avin&lt;/code&gt; (a chain
of three from its earliest member, a trait’s default method, a local lazy in the initializer, a
default argument, a superclass’s field and the subclass’s override),
&lt;code&gt;tests/programs/reject/lazy_field_cycle_modules&lt;/code&gt; (a subclass and a function in another module),
&lt;code&gt;tests/reject/lazy_local_cycles.avin&lt;/code&gt; and &lt;code&gt;lazy_local_cycles_more.avin&lt;/code&gt; (direct, nested, a local
function, a method, a loop body, a lambda’s body, a field’s initializer, a generic function, two
local functions, a match arm), &lt;code&gt;tests/reject/lazy_threads_cycle.avin&lt;/code&gt; and
&lt;code&gt;lazy_local_self_direct.avin&lt;/code&gt; (moved from &lt;code&gt;tests/run&lt;/code&gt;); &lt;code&gt;tests/run/lazy_field_other_instance.avin&lt;/code&gt;
(a node’s depth, a tree’s size, another instance’s field through a method, a generic chain, an
object over instances, a chain with no cycle, an override reading another field, a handed-on
lambda, threads), &lt;code&gt;tests/run/lazy_local_no_cycle.avin&lt;/code&gt;, and
&lt;code&gt;tests/run/lazy_threads_handed_trap.avin&lt;/code&gt; (a handed-on read on a second thread: still the trap).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The test matrix every item fills, each cell a test that would fail if the rule were false:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Rule&lt;/th&gt;&lt;th&gt;Refused shapes&lt;/th&gt;&lt;th&gt;Accepted shapes&lt;/th&gt;&lt;th&gt;Neighbours&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Class body&lt;/td&gt;&lt;td&gt;read below; method; &lt;code&gt;self&lt;/code&gt; passed; lambda, by-name, local fn, method value&lt;/td&gt;&lt;td&gt;read above; after the last field anything&lt;/td&gt;&lt;td&gt;generic class, actor class, &lt;code&gt;with&lt;/code&gt;-free data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Open/abstract body&lt;/td&gt;&lt;td&gt;override reachable; trait &lt;code&gt;val&lt;/code&gt; a subclass supplies; unsafe private&lt;/td&gt;&lt;td&gt;safe private method&lt;/td&gt;&lt;td&gt;trait default method&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Superclass arguments&lt;/td&gt;&lt;td&gt;every function using the object&lt;/td&gt;&lt;td&gt;parameters, module values&lt;/td&gt;&lt;td&gt;object extending a class, generic superclass&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Trait fields&lt;/td&gt;&lt;td&gt;method call; lambda; field below&lt;/td&gt;&lt;td&gt;fields above, parameters&lt;/td&gt;&lt;td&gt;two traits, required traits&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Object name&lt;/td&gt;&lt;td&gt;above its field; passed early&lt;/td&gt;&lt;td&gt;lazy, lambda after last field, method&lt;/td&gt;&lt;td&gt;object extending a class&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Module values&lt;/td&gt;&lt;td&gt;cycles in one module, across modules, through dispatch, operators, defaults, iterators&lt;/td&gt;&lt;td&gt;declaration order kept&lt;/td&gt;&lt;td&gt;object, &lt;code&gt;var&lt;/code&gt; written by another initializer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lazy val&lt;/code&gt;&lt;/td&gt;&lt;td&gt;self, chain, function, dispatch, field via &lt;code&gt;self&lt;/code&gt;&lt;/td&gt;&lt;td&gt;other instance, handed-on read after return&lt;/td&gt;&lt;td&gt;threads, actors, generic class&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;higher-kinded-types-build-plan&quot;&gt;Higher-kinded types: build plan&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;/spec/generics/#higher-kinded-types&quot;&gt;Higher-kinded types&lt;/a&gt; and the
&lt;a href=&quot;/spec/generics/#functor-applicative-monad-traverse&quot;&gt;standard constructor traits&lt;/a&gt; are designed in
generics, their choices proposed in &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;decisions&lt;/a&gt;. All nine steps are
done. Each step
is one agent’s item, gated on its own (targeted files plus the corpus), and lands the tests listed;
no step builds a path a later one removes. The spec’s examples are plain &lt;code&gt;text&lt;/code&gt; fences, which no
test reads; step 7 makes the finished ones &lt;code&gt;text run&lt;/code&gt; programs with &lt;code&gt;text output&lt;/code&gt; fences, which
&lt;code&gt;corpus_tests.sysl&lt;/code&gt; then builds and runs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Representation.&lt;/strong&gt; &lt;code&gt;TypeParam&lt;/code&gt; (&lt;code&gt;syntax.sysl&lt;/code&gt;) gains its holes, each a variance and bounds;
&lt;code&gt;TypeExprKind&lt;/code&gt; gains &lt;code&gt;Hole&lt;/code&gt; for a &lt;code&gt;_&lt;/code&gt; argument. &lt;code&gt;Type&lt;/code&gt; (&lt;code&gt;types.sysl&lt;/code&gt;) gains &lt;code&gt;Constructor(body, arity)&lt;/code&gt;, whose body is a data type, class or trait with &lt;code&gt;Hole(i)&lt;/code&gt; among its direct arguments (the
normal form, so &lt;code&gt;same_type&lt;/code&gt; on constructors is structural), and &lt;code&gt;Applied(head, args)&lt;/code&gt;, an application
of a constructor parameter. &lt;code&gt;substitute&lt;/code&gt; reduces &lt;code&gt;Applied(Constructor …)&lt;/code&gt; to the body with the
holes filled, so after monomorphization no &lt;code&gt;Applied&lt;/code&gt; or &lt;code&gt;Constructor&lt;/code&gt; is left, and lowering, layout
and emission see only the types they see today; &lt;code&gt;type_key&lt;/code&gt; names a constructor
(&lt;code&gt;Result[_,ParseError]&lt;/code&gt;) so instance keys and the incremental store keep one copy per constructor.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Kinds and constructor parameters, written.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; Parse &lt;code&gt;F[_]&lt;/code&gt;, &lt;code&gt;F[_, _]&lt;/code&gt;, &lt;code&gt;F[+_]&lt;/code&gt; in every type
parameter list and &lt;code&gt;_&lt;/code&gt; in type arguments (&lt;code&gt;parse_decl.sysl&lt;/code&gt;, &lt;code&gt;formatter.sysl&lt;/code&gt;); the two &lt;code&gt;Type&lt;/code&gt;
forms, &lt;code&gt;substitute&lt;/code&gt;, &lt;code&gt;solve&lt;/code&gt;, &lt;code&gt;same_type&lt;/code&gt;, &lt;code&gt;type_key&lt;/code&gt;; kind checking wherever a type is resolved
(&lt;code&gt;check.sysl&lt;/code&gt;‘s type resolution); constructor arguments written at calls and in types: a bare
generic type, a partial application, an alias that is a constructor, another constructor
parameter; instance keys (&lt;code&gt;lower.sysl&lt;/code&gt; &lt;code&gt;instance_key&lt;/code&gt;, &lt;code&gt;keys.sysl&lt;/code&gt;). Tests: &lt;code&gt;tests/run/&lt;/code&gt;
constructor parameters on a function, a method, a data type and a class, at one and two holes,
with value-type arguments (&lt;code&gt;F[int]&lt;/code&gt; unboxed at &lt;code&gt;Vector&lt;/code&gt;), &lt;code&gt;-O0&lt;/code&gt;/&lt;code&gt;-O2&lt;/code&gt;, under GC stress;
&lt;code&gt;Parsed&lt;/code&gt; and &lt;code&gt;Result[_, E]&lt;/code&gt; one instance (a counter in a module value); &lt;code&gt;tests/reject/&lt;/code&gt; one file
per kind error the spec names (constructor as a type, type as a constructor, wrong arity, nested
&lt;code&gt;_&lt;/code&gt;, &lt;code&gt;F[_[_]]&lt;/code&gt;, an alias that is no constructor); &lt;code&gt;parse_tests.sysl&lt;/code&gt; and &lt;code&gt;formatter_tests.sysl&lt;/code&gt;
for the forms.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inference without bounds, hole variance and hole bounds.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; &lt;code&gt;F&lt;/code&gt; inferred from a type of as many
parameters as it takes holes, and the error asking for it otherwise; &lt;code&gt;F[+_]&lt;/code&gt; subtyping inside the
declaration and the check on the constructor passed; &lt;code&gt;F[_: B]&lt;/code&gt; checked at every &lt;code&gt;F[X]&lt;/code&gt; written
and against the constructor’s own bounds. Tests: inference from arguments and from the expected
type; &lt;code&gt;F[+_]&lt;/code&gt; accepting &lt;code&gt;Option&lt;/code&gt; and refusing &lt;code&gt;Array&lt;/code&gt;; &lt;code&gt;F[_: Ord]&lt;/code&gt; taking &lt;code&gt;TreeSet&lt;/code&gt; and plain
&lt;code&gt;_&lt;/code&gt; refusing it; &lt;code&gt;F[X]&lt;/code&gt; at an &lt;code&gt;X&lt;/code&gt; missing the hole’s bound reported at the definition;
polymorphic recursion through a growing constructor (&lt;code&gt;expansion.sysl&lt;/code&gt;) rejected and a
non-growing one accepted.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constructor traits and their impls.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; &lt;code&gt;Self[X]&lt;/code&gt; in a trait’s methods, its arity and the
requirement chain; impls naming the holes and the bare form; coherence (once per type, the
module rule, no inherited conformance); the meeting rule, recording per trait method the type’s
method in its table and the type arguments the meeting decided (&lt;code&gt;meet_method&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;,
&lt;code&gt;TProgram.meetings&lt;/code&gt;), so a call through the bound lowers to a direct call of it; a value of
&lt;code&gt;F[X]&lt;/code&gt; has the bound’s members; constructor arguments written explicitly at calls, held to the
bound’s conformance; default bodies compiled per implementing constructor, &lt;code&gt;Self&lt;/code&gt; the
constructor in each copy. Tests: &lt;code&gt;tests/run/constructor_traits*.avin&lt;/code&gt; (a data type, a class by
its header and by an impl, two-parameter types at each hole, &lt;code&gt;List&lt;/code&gt;‘s overloaded &lt;code&gt;flatMap&lt;/code&gt; and
&lt;code&gt;Result&lt;/code&gt;‘s lower-bounded one meeting, defaults at several constructors, two-hole traits, a
bounded trait parameter, a conditional impl, &lt;code&gt;-O0&lt;/code&gt;/&lt;code&gt;-O2&lt;/code&gt; and GC stress),
&lt;code&gt;tests/programs/run/constructor_trait_modules&lt;/code&gt;; reject files for each refusal
(&lt;code&gt;tests/reject/constructor_trait_*.avin&lt;/code&gt;, &lt;code&gt;tests/programs/reject/constructor_trait_module_rule&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inferring a constructor through its bound.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; Matching &lt;code&gt;F[X]&lt;/code&gt; through the conformance
and the nearest superclass (&lt;code&gt;bound_constructor&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;; the “one trait” case is
unreachable while no impl is for a trait, see decisions); the written-out arguments joined by
variance (&lt;code&gt;widened_constructor&lt;/code&gt;: a &lt;code&gt;Result[int, Dog]&lt;/code&gt; beside a &lt;code&gt;Result[int, Cat]&lt;/code&gt;), the head
required to agree; the expected type; a lambda’s result deciding &lt;code&gt;G&lt;/code&gt;; two bounds disagreeing on
the holes an error naming both. Inference no longer sees a subclass as its superclass off a read
position (&lt;code&gt;held_as&lt;/code&gt;), a soundness fix the superclass matching met. Tests:
&lt;code&gt;tests/run/constructor_bound_inference{,_more,_gc}.avin&lt;/code&gt;, &lt;code&gt;tests/run/inference_subtype_reads.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/constructor_bound_infer_failures.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/inference_no_subtype_off_read.avin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static members on constructors and per-constructor defaults.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; &lt;code&gt;F.pure&lt;/code&gt; and a
constructor trait’s &lt;code&gt;Self.pure&lt;/code&gt; in its default bodies (the parameter itself as the receiver, its
bounds’ static members); &lt;code&gt;Option.pure&lt;/code&gt;, &lt;code&gt;Result[_, E].pure&lt;/code&gt;, &lt;code&gt;Box[_].pure&lt;/code&gt; and an alias that is
a constructor (&lt;code&gt;constructor_receiver&lt;/code&gt;, &lt;code&gt;constructor_statics&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;: the static members
of the constructor traits it implements at exactly its holes); each a &lt;code&gt;BoundCall&lt;/code&gt; that lowering
(&lt;code&gt;bound_call&lt;/code&gt;) makes a direct call of the constructor’s own member, at &lt;code&gt;Nothing&lt;/code&gt; for the holes,
so one instance per constructor; function values of both; a default overriding a required
trait’s method (&lt;code&gt;Monad&lt;/code&gt;‘s &lt;code&gt;map&lt;/code&gt;), its &lt;code&gt;Self&lt;/code&gt; seen from the trait itself. Tests:
&lt;code&gt;tests/run/constructor_statics{,_defaults,_gc}.avin&lt;/code&gt; (&lt;code&gt;F.pure&lt;/code&gt; at data types, a class,
partial applications and an alias, through two bounds, in closures and a generic class; the default &lt;code&gt;map&lt;/code&gt;
at four constructors and the types’ own meeting &lt;code&gt;map&lt;/code&gt; still called; GC stress),
&lt;code&gt;tests/reject/constructor_static_{refusals,receivers,bounds}.avin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Impls over constructor parameters.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; &lt;code&gt;impl[F[_]: B, A] F[A]&lt;/code&gt; and &lt;code&gt;F[G[A]]&lt;/code&gt;: receiver
matching through the conformance (&lt;code&gt;match_applied&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;, by &lt;code&gt;bound_constructor&lt;/code&gt;, a
subclass as the superclass that conforms, an &lt;code&gt;F[X]&lt;/code&gt; in generic code where its bounds include the
impl’s); the own-methods-first rule, as for an impl adding to a trait (&lt;code&gt;adds_to_constructor&lt;/code&gt;);
the impl the bound trait’s own in its module and an extension elsewhere (&lt;code&gt;in_bound_module&lt;/code&gt;);
extensions seen by import, their method values reported as calls are; two matching impls an
error; a receiver that matches none told why. Tests:
&lt;code&gt;tests/run/constructor_param_impls{,_gc}.avin&lt;/code&gt;, &lt;code&gt;tests/programs/run/constructor_param_extensions&lt;/code&gt;
(an extension module adding to every &lt;code&gt;Pointed&lt;/code&gt;, seen only where imported),
&lt;code&gt;tests/reject/constructor_param_impl_{calls,decls}.avin&lt;/code&gt;,
&lt;code&gt;tests/programs/reject/constructor_param_extension_{unseen,clash}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The library.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; &lt;code&gt;library/avin/functor.avin&lt;/code&gt;: &lt;code&gt;Functor&lt;/code&gt;, &lt;code&gt;Foldable&lt;/code&gt;, &lt;code&gt;Applicative&lt;/code&gt;,
&lt;code&gt;Monad&lt;/code&gt;, &lt;code&gt;Filter&lt;/code&gt;, &lt;code&gt;Traverse&lt;/code&gt;, &lt;code&gt;sequence&lt;/code&gt;, &lt;code&gt;SendableFunctor&lt;/code&gt;, &lt;code&gt;SendableMonad&lt;/code&gt;; the impls of the
spec’s table, for concrete types only, each giving only what the type lacks (&lt;code&gt;pure&lt;/code&gt;,
&lt;code&gt;traverse&lt;/code&gt;, &lt;code&gt;foldLeft&lt;/code&gt; on &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt;), and &lt;code&gt;impl SendableMonad for Future&lt;/code&gt;.
&lt;code&gt;Foldable&lt;/code&gt; is a trait for types that bounds constructors at its holes (&lt;code&gt;bounds_constructors&lt;/code&gt;
in &lt;code&gt;check.sysl&lt;/code&gt;: bounds, a constructor trait’s requirements, impls over constructor
parameters, inference), and &lt;code&gt;Iterable&lt;/code&gt; requires it, so every collection folds through
&lt;code&gt;[F[_]: Foldable]&lt;/code&gt;; a constructor trait’s parameter bounds no longer demand anything of the
conforming type’s parameters (&lt;code&gt;conforming_type_param&lt;/code&gt;). Tests: &lt;code&gt;library/tests/functors.avin&lt;/code&gt;
(the functor and monad laws through the bounds for every type in the table, &lt;code&gt;traverse&lt;/code&gt; and
&lt;code&gt;sequence&lt;/code&gt; answering the first failure with every element given to &lt;code&gt;f&lt;/code&gt;, cartesian &lt;code&gt;map2&lt;/code&gt;
beside &lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;Future&lt;/code&gt;‘s &lt;code&gt;pure&lt;/code&gt;), &lt;code&gt;tests/run/functor_own_methods.avin&lt;/code&gt; (own methods’ result
types by type patterns), &lt;code&gt;tests/run/foldable_constructor_bounds{,_gc}.avin&lt;/code&gt;,
&lt;code&gt;tests/run/sendable_monad_conformance.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/foldable_constructor_bound_{refusals,inference}.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/sendable_monad_conformance.avin&lt;/code&gt;; the spec’s &lt;code&gt;pairUp&lt;/code&gt;, &lt;code&gt;Parser&lt;/code&gt; and &lt;code&gt;traverse&lt;/code&gt;
examples are &lt;code&gt;run&lt;/code&gt; fences.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Comprehensions by conformance.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; &lt;code&gt;for_yield_expr&lt;/code&gt; (&lt;code&gt;check.sysl&lt;/code&gt;) admits each source
by its roles (&lt;code&gt;admitted_source&lt;/code&gt;, &lt;code&gt;implements_role&lt;/code&gt;: an &lt;code&gt;Iterable&lt;/code&gt;, or &lt;code&gt;Functor&lt;/code&gt;/&lt;code&gt;Monad&lt;/code&gt;/&lt;code&gt;Filter&lt;/code&gt;
or the sendable pair, through bounds in generic code) before checking its calls as before; the
guard on a non-&lt;code&gt;Iterable&lt;/code&gt; source calls &lt;code&gt;filter&lt;/code&gt;; the library’s &lt;code&gt;withFilter&lt;/code&gt; views conform to
&lt;code&gt;Iterable&lt;/code&gt;. The generator-mismatch diagnostic naming the later generator (&lt;code&gt;yield_frames&lt;/code&gt;,
&lt;code&gt;taken_by_frame&lt;/code&gt;) is taken from the parked branch &lt;code&gt;monadic-for&lt;/code&gt;. A bound of two traits reaching
one method through an override (&lt;code&gt;F[_]: Monad &amp;amp; Filter&lt;/code&gt;‘s &lt;code&gt;map&lt;/code&gt;) has the override alone
(&lt;code&gt;bound_methods&lt;/code&gt;), a bug the comprehensions met. Migration: the &lt;code&gt;Maybe&lt;/code&gt; of
&lt;code&gt;tests/run/for_yield_forms.avin&lt;/code&gt; and &lt;code&gt;for_yield_definitions.avin&lt;/code&gt; and the &lt;code&gt;Box&lt;/code&gt; of
&lt;code&gt;spec_collections_comprehensions.avin&lt;/code&gt; gain their impls; &lt;code&gt;futures_for_yield.avin&lt;/code&gt; is unchanged,
through &lt;code&gt;SendableMonad&lt;/code&gt;. Tests: &lt;code&gt;tests/run/for_yield_conformance{,_gc}.avin&lt;/code&gt; (every role at a
class, a data type, two parameters, a subclass, &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt;, mixed with
collections and through bounds, with the order of evaluation logged),
&lt;code&gt;tests/run/filtered_views_iterable.avin&lt;/code&gt;, &lt;code&gt;tests/run/bound_override_diamond.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/for_yield_roles{,_more}.avin&lt;/code&gt;, &lt;code&gt;tests/reject/for_yield_generator_mismatch.avin&lt;/code&gt;,
and the updated &lt;code&gt;tests/reject/for_yield_{sources,definitions}.avin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tooling.&lt;/strong&gt; &lt;em&gt;Done.&lt;/em&gt; Hover and completion of a constructor’s members: a value of &lt;code&gt;F[X]&lt;/code&gt; offers
and shows its bounds’ methods, &lt;code&gt;F.&lt;/code&gt; and &lt;code&gt;Self.&lt;/code&gt; their static members, &lt;code&gt;Option.&lt;/code&gt;,
&lt;code&gt;Result[_, E].&lt;/code&gt; and an alias that is a constructor the static members of the constructor traits
it implements (&lt;code&gt;constructor_static_members&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;; a partial application offered
nothing before), and a conforming type the methods an impl over a constructor
parameter adds; a signature, a declaration and a type parameter are shown with their holes
(&lt;code&gt;show_type_param&lt;/code&gt; in &lt;code&gt;syntax_show.sysl&lt;/code&gt;, used by &lt;code&gt;definition_index.sysl&lt;/code&gt;‘s headers and the
type parameter’s own hover, &lt;code&gt;type parameter F[_]: Monad&lt;/code&gt;). &lt;code&gt;avin fmt&lt;/code&gt; of every form: constructor
traits, their impls by name and by holes, impls over constructor parameters, &lt;code&gt;F.pure&lt;/code&gt; and the
static members of a partial application and an alias, hole variance and bounds. A method or a
local function whose constructor parameter opens with &lt;code&gt;-_&lt;/code&gt; was read as an expression
(&lt;code&gt;local_function_ahead&lt;/code&gt; in &lt;code&gt;parse_decl.sysl&lt;/code&gt;), a bug the formatter met. The editor grammar
(&lt;code&gt;editors/vscode/syntaxes/avin.tmLanguage.json&lt;/code&gt;, which the IntelliJ plugin bundles) reads the
brackets after a name as types: a hole and its variance, a type parameter’s variance, and
declarations and calls whose type brackets nest. Diagnostics give a letter standing alone its
letter’s article (&lt;code&gt;an F[int]&lt;/code&gt;, &lt;code&gt;a T&lt;/code&gt;, &lt;code&gt;a unit&lt;/code&gt;; &lt;code&gt;article&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;). Tests:
&lt;code&gt;lsp_tests.sysl&lt;/code&gt; (&lt;code&gt;lsp_hover_constructor_members&lt;/code&gt;, &lt;code&gt;lsp_completion_constructor_members&lt;/code&gt;),
&lt;code&gt;formatter_tests.sysl&lt;/code&gt; (&lt;code&gt;fmt_constructor_traits&lt;/code&gt;, &lt;code&gt;fmt_constructor_param_impls&lt;/code&gt;,
&lt;code&gt;fmt_constructor_statics&lt;/code&gt;), &lt;code&gt;parse_tests.sysl&lt;/code&gt; (&lt;code&gt;constructor_param_contravariant_members&lt;/code&gt;),
&lt;code&gt;editors/grammar-tests/samples/constructors.avin&lt;/code&gt;, the plugin’s &lt;code&gt;AvinEditorTest&lt;/code&gt;, and
&lt;code&gt;tests/reject/article_letter_{names,types,sendable}.avin&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;releases&quot;&gt;Releases&lt;/h2&gt;
&lt;p&gt;Releases are cut from &lt;code&gt;dev&lt;/code&gt; at any stage, as the language stands, by &lt;code&gt;scripts/release.sh&lt;/code&gt;
(&lt;a href=&quot;/compiler/releasing/&quot;&gt;Releasing&lt;/a&gt;). The first, 0.0.1, is the first installable compiler: a Homebrew
formula and a macOS arm64 tarball.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Releasing</title>
    <link href="https://avinlang.dev/compiler/releasing/"/>
    <id>https://avinlang.dev/compiler/releasing/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>How a release of the compiler is cut, what its tarball holds, and what is left to publish it.</summary>
    <content type="html">&lt;p&gt;A release is cut on the Mac that builds it, by one script that publishes nothing:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;scripts/release.sh 0.0.1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It refuses unless the tree is clean and &lt;code&gt;HEAD&lt;/code&gt; is &lt;code&gt;origin/dev&lt;/code&gt; (&lt;code&gt;--expect &amp;lt;sha&amp;gt;&lt;/code&gt; names another
commit, which is how a branch is put through a dry run, and &lt;code&gt;--repo &amp;lt;dir&amp;gt;&lt;/code&gt; another checkout). Then,
each step timed into &lt;code&gt;release-out/&amp;lt;version&amp;gt;/release.log&lt;/code&gt; with its output beside it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The version.&lt;/strong&gt; It stamps &lt;code&gt;const Version&lt;/code&gt; in &lt;code&gt;compiler/dev/avinlang/compiler/cli.sysl&lt;/code&gt; and
&lt;code&gt;package.version&lt;/code&gt; in &lt;code&gt;compiler/sysl.hocon&lt;/code&gt;, which a test holds in step, and in
&lt;code&gt;library/library.hocon&lt;/code&gt;, which the compiler checks against its own version and refuses a library
that differs from, and commits the stamp as
&lt;code&gt;avin &amp;lt;version&amp;gt;&lt;/code&gt; on the local branch, unless the tree carries that version already.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The compiler&lt;/strong&gt;, built at &lt;code&gt;-O2&lt;/code&gt; by the &lt;code&gt;sysl&lt;/code&gt; on &lt;code&gt;PATH&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The prefix.&lt;/strong&gt; &lt;code&gt;bin/avin&lt;/code&gt;; &lt;code&gt;share/avin/library&lt;/code&gt; and &lt;code&gt;share/avin/runtime&lt;/code&gt; as git tracks them;
&lt;code&gt;share/avin/editors&lt;/code&gt;, the TextMate grammars of &lt;code&gt;.avin&lt;/code&gt; and &lt;code&gt;.lavin&lt;/code&gt;; and
&lt;code&gt;share/avin/lib/&amp;lt;target&amp;gt;/libavinrt-&amp;lt;target&amp;gt;-&amp;lt;key&amp;gt;.a&lt;/code&gt;, the runtime’s archive for the machine the
release is built on. The archive is built by the staged compiler from the staged runtime, so its
key, a hash of the compiler’s version, the target and the runtime’s sources, is the one an
installed compiler computes, and an installed compiler links it without
running Sysl.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The tarball&lt;/strong&gt;, &lt;code&gt;avin-&amp;lt;version&amp;gt;-darwin-arm64.tar.gz&lt;/code&gt;, and its sha256.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The proof, from the tarball.&lt;/strong&gt; It unpacks the tarball outside the repository, makes the prefix
read-only as a Homebrew keg is, and from a scratch directory, with &lt;code&gt;AVIN_ROOT&lt;/code&gt; unset and a fresh
&lt;code&gt;AVIN_CACHE&lt;/code&gt;, runs &lt;code&gt;avin --version&lt;/code&gt;; builds and runs a hello program with only &lt;code&gt;/usr/bin&lt;/code&gt; and
&lt;code&gt;/bin&lt;/code&gt; on &lt;code&gt;PATH&lt;/code&gt;, which must link the shipped archive; runs a program that reaches a Sysl binding,
whose shims Sysl builds into the cache; makes a package with &lt;code&gt;avin new&lt;/code&gt; and runs &lt;code&gt;avin test&lt;/code&gt; on
it; and has &lt;code&gt;avin lsp&lt;/code&gt; answer &lt;code&gt;initialize&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The formula&lt;/strong&gt;, &lt;code&gt;packaging/homebrew/avin.rb&lt;/code&gt; with the version and sha256 filled in, written to
&lt;code&gt;release-out/&amp;lt;version&amp;gt;/avin.rb&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;AVIN_RELEASE_SLOT=&amp;lt;script&amp;gt;&lt;/code&gt; runs the build through a wrapper, as &lt;code&gt;zsh &amp;lt;script&amp;gt; &amp;lt;dir&amp;gt; &amp;lt;command...&amp;gt;&lt;/code&gt;,
so a release waits its turn behind a test run.&lt;/p&gt;
&lt;h2 id=&quot;what-is-left&quot;&gt;What is left&lt;/h2&gt;
&lt;p&gt;The script ends by printing the steps it does not take, each of which other people see:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;push the stamp to &lt;code&gt;dev&lt;/code&gt;, then tag the release commit &lt;code&gt;v&amp;lt;version&amp;gt;&lt;/code&gt; and push the tag;&lt;/li&gt;
&lt;li&gt;create the GitHub release &lt;code&gt;v&amp;lt;version&amp;gt;&lt;/code&gt; in &lt;code&gt;avin-lang/avin&lt;/code&gt; with the tarball;&lt;/li&gt;
&lt;li&gt;download the asset the release serves and check its sha256 is the one the script printed;&lt;/li&gt;
&lt;li&gt;copy the filled formula into &lt;code&gt;Formula/avin.rb&lt;/code&gt; of &lt;code&gt;avin-lang/homebrew-tap&lt;/code&gt; and push the tap;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;brew install avin-lang/tap/avin&lt;/code&gt; and &lt;code&gt;brew test avin&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;what-an-installed-compiler-needs&quot;&gt;What an installed compiler needs&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;clang&lt;/code&gt;, which links every program, from Xcode’s command-line tools; and &lt;code&gt;sysl&lt;/code&gt;, which builds the
shims of the Sysl bindings a program reaches, and which the formula depends on. A program that
reaches no binding is built with clang alone. The runtime archives and shims the compiler builds go
to the user’s cache, &lt;code&gt;~/Library/Caches/avin/&amp;lt;version&amp;gt;&lt;/code&gt;, never into the installed prefix.&lt;/p&gt;
&lt;p&gt;The repository has no license file yet, so the tarball carries none.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Regular expressions</title>
    <link href="https://avinlang.dev/spec/regex/"/>
    <id>https://avinlang.dev/spec/regex/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>`avin.regex`: the pattern language, backtracking matching with leftmost-first results, `Regex`, `Match` and `MatchIterator`, replacing and splitting, and a regex as an extractor pattern.</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;avin.regex&lt;/code&gt; is a regular-expression library written in Avin: a pattern is read into a syntax tree,
compiled into a program of matching operations, and run by a backtracking matcher over the text’s
characters. It is imported like any module: &lt;code&gt;import avin.regex.{Regex, Match}&lt;/code&gt; for the types, and
&lt;code&gt;import avin.regex&lt;/code&gt; for the string method &lt;code&gt;r&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.regex
import avin.regex.Regex

main()
  val date = Regex(&amp;quot;(?&amp;lt;year&amp;gt;\\d{4})-(?&amp;lt;month&amp;gt;\\d\\d)&amp;quot;)
  date.findFirstMatchIn(&amp;quot;due 2024-06&amp;quot;) match
    Some(m) -&amp;gt; println(m.group(&amp;quot;month&amp;quot;)) // Some(06)
    None -&amp;gt; println(&amp;quot;no date&amp;quot;)
  println(&amp;quot;[a-z]+&amp;quot;.r().findAllIn(&amp;quot;one, two&amp;quot;).toList) // [one, two]
  println(Regex(&amp;quot;a+b&amp;quot;).matches(&amp;quot;aab&amp;quot;)) // true
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;text-characters-and-offsets&quot;&gt;Text, characters and offsets&lt;/h2&gt;
&lt;p&gt;Matching goes &lt;strong&gt;character by character&lt;/strong&gt;: &lt;code&gt;.&lt;/code&gt; matches one Unicode scalar value however many bytes
encode it, a class tests a whole character, and a lookbehind’s lengths count characters. Every
offset the API answers with is a &lt;strong&gt;byte offset&lt;/strong&gt; into the text, as every string offset is, so
&lt;code&gt;m.start()&lt;/code&gt; and &lt;code&gt;m.end()&lt;/code&gt; slice the text directly. An empty match moves the next search of
&lt;code&gt;findAllIn&lt;/code&gt; on by one character. A &lt;code&gt;PatternError&lt;/code&gt;‘s index counts the pattern’s characters from 0.&lt;/p&gt;
&lt;h2 id=&quot;the-pattern-language&quot;&gt;The pattern language&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Construct&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;\\&lt;/code&gt;, &lt;code&gt;\.&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A literal character; a backslash before any character that is not a letter or digit makes it literal&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\t&lt;/code&gt; &lt;code&gt;\n&lt;/code&gt; &lt;code&gt;\r&lt;/code&gt; &lt;code&gt;\f&lt;/code&gt; &lt;code&gt;\a&lt;/code&gt; &lt;code&gt;\e&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Tab, newline, return, form feed, bell, escape&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\0n&lt;/code&gt; &lt;code&gt;\0nn&lt;/code&gt; &lt;code&gt;\0mnn&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An octal character, &lt;code&gt;m&lt;/code&gt; at most 3&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\xhh&lt;/code&gt; &lt;code&gt;\x{h…}&lt;/code&gt; &lt;code&gt;\uhhhh&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A character by its code in hexadecimal; &lt;code&gt;😀&lt;/code&gt; is the one character the pair encodes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\cX&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The control character of &lt;code&gt;X&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\Q…\E&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every character between taken literally; without &lt;code&gt;\E&lt;/code&gt; the quotation runs to the end&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Any character but a line terminator; with &lt;code&gt;s&lt;/code&gt;, any character; with &lt;code&gt;d&lt;/code&gt;, any but &lt;code&gt;\n&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;[abc]&lt;/code&gt; &lt;code&gt;[^abc]&lt;/code&gt; &lt;code&gt;[a-z]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A class, its negation, a range; &lt;code&gt;]&lt;/code&gt; first and &lt;code&gt;-&lt;/code&gt; first or last are literal&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;[a[bc]]&lt;/code&gt; &lt;code&gt;[a-z&amp;amp;&amp;amp;[^aeiou]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The union of nested classes, and an intersection&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\d&lt;/code&gt; &lt;code&gt;\D&lt;/code&gt; &lt;code&gt;\s&lt;/code&gt; &lt;code&gt;\S&lt;/code&gt; &lt;code&gt;\w&lt;/code&gt; &lt;code&gt;\W&lt;/code&gt;&lt;/td&gt;&lt;td&gt;ASCII digits &lt;code&gt;[0-9]&lt;/code&gt;, white space &lt;code&gt;[ \t\n\x0B\f\r]&lt;/code&gt;, word characters &lt;code&gt;[a-zA-Z_0-9]&lt;/code&gt;, and their negations; under &lt;code&gt;U&lt;/code&gt;, decimal digits (&lt;code&gt;Nd&lt;/code&gt;), &lt;code&gt;White_Space&lt;/code&gt; and Unicode word characters&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\h&lt;/code&gt; &lt;code&gt;\H&lt;/code&gt; &lt;code&gt;\v&lt;/code&gt; &lt;code&gt;\V&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Horizontal and vertical white space, and their negations&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\p{Lu}&lt;/code&gt; &lt;code&gt;\p{L}&lt;/code&gt; &lt;code&gt;\pL&lt;/code&gt; &lt;code&gt;\p{gc=Lu}&lt;/code&gt; &lt;code&gt;\p{IsLu}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A Unicode general category or a group of them (&lt;code&gt;L&lt;/code&gt;, &lt;code&gt;M&lt;/code&gt;, &lt;code&gt;N&lt;/code&gt;, &lt;code&gt;P&lt;/code&gt;, &lt;code&gt;S&lt;/code&gt;, &lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt;, &lt;code&gt;LC&lt;/code&gt;, &lt;code&gt;LD&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\p{IsAlphabetic}&lt;/code&gt; &lt;code&gt;\p{IsWhite_Space}&lt;/code&gt; &lt;code&gt;\p{IsEmoji}&lt;/code&gt; …&lt;/td&gt;&lt;td&gt;A Unicode binary property, or a POSIX class over Unicode (&lt;code&gt;\p{IsAlpha}&lt;/code&gt;); the name after &lt;code&gt;Is&lt;/code&gt; ignores case&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\p{IsGreek}&lt;/code&gt; &lt;code&gt;\p{sc=Grek}&lt;/code&gt; &lt;code&gt;\p{script=Greek}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A script, by name or four-letter code, ignoring case&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\p{InGreek}&lt;/code&gt; &lt;code&gt;\p{blk=Greek and Coptic}&lt;/code&gt; &lt;code&gt;\p{block=…}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A block, ignoring case&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\p{Alpha}&lt;/code&gt; &lt;code&gt;\p{Digit}&lt;/code&gt; &lt;code&gt;\p{Punct}&lt;/code&gt; …&lt;/td&gt;&lt;td&gt;A POSIX class, over ASCII unless &lt;code&gt;U&lt;/code&gt; is on: &lt;code&gt;Lower&lt;/code&gt;, &lt;code&gt;Upper&lt;/code&gt;, &lt;code&gt;ASCII&lt;/code&gt;, &lt;code&gt;Alpha&lt;/code&gt;, &lt;code&gt;Digit&lt;/code&gt;, &lt;code&gt;Alnum&lt;/code&gt;, &lt;code&gt;Punct&lt;/code&gt;, &lt;code&gt;Graph&lt;/code&gt;, &lt;code&gt;Print&lt;/code&gt;, &lt;code&gt;Blank&lt;/code&gt;, &lt;code&gt;Cntrl&lt;/code&gt;, &lt;code&gt;XDigit&lt;/code&gt;, &lt;code&gt;Space&lt;/code&gt;; also &lt;code&gt;L1&lt;/code&gt; (Latin-1) and &lt;code&gt;all&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\P{…}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The negation of a property&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;X?&lt;/code&gt; &lt;code&gt;X*&lt;/code&gt; &lt;code&gt;X+&lt;/code&gt; &lt;code&gt;X{n}&lt;/code&gt; &lt;code&gt;X{n,}&lt;/code&gt; &lt;code&gt;X{n,m}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Repetition, greedy; followed by &lt;code&gt;?&lt;/code&gt; reluctant, by &lt;code&gt;+&lt;/code&gt; possessive&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;(X)&lt;/code&gt; &lt;code&gt;(?&amp;lt;name&amp;gt;X)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A capturing group, numbered from 1 by its opening parenthesis; a named one, whose name is a Latin letter then letters and digits&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;(?:X)&lt;/code&gt; &lt;code&gt;(?&amp;gt;X)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A group that only groups; an atomic group, matched once and never tried another way&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;(?=X)&lt;/code&gt; &lt;code&gt;(?!X)&lt;/code&gt; &lt;code&gt;(?&amp;lt;=X)&lt;/code&gt; &lt;code&gt;(?&amp;lt;!X)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Lookahead and lookbehind, each positive or negative&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\1&lt;/code&gt; … &lt;code&gt;\k&amp;lt;name&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text a group matched, again&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;^&lt;/code&gt; &lt;code&gt;$&lt;/code&gt; &lt;code&gt;\A&lt;/code&gt; &lt;code&gt;\z&lt;/code&gt; &lt;code&gt;\Z&lt;/code&gt; &lt;code&gt;\G&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Start; end, or before a line terminator ending the input; start of input; end of input; end or before a final line terminator; where the previous match ended&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\b&lt;/code&gt; &lt;code&gt;\B&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A word boundary, and anywhere else&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\b{g}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A boundary between grapheme clusters&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\X&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One extended grapheme cluster: a user-perceived character such as &lt;code&gt;e&lt;/code&gt; and a combining accent, a flag, or an emoji sequence&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;\R&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A line break: &lt;code&gt;\r\n&lt;/code&gt;, or one of &lt;code&gt;\n&lt;/code&gt;, &lt;code&gt;\x0B&lt;/code&gt;, &lt;code&gt;\f&lt;/code&gt;, &lt;code&gt;\r&lt;/code&gt;, &lt;code&gt;\u0085&lt;/code&gt;, &lt;code&gt; &lt;/code&gt;, &lt;code&gt; &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;X\|Y&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Alternatives, tried left to right&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;(?imsxduU-imsxduU)&lt;/code&gt; &lt;code&gt;(?i:X)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Flags turned on and off from here to the end of the enclosing group, or for &lt;code&gt;X&lt;/code&gt; alone&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Flags.&lt;/strong&gt; &lt;code&gt;i&lt;/code&gt; ignores case, for ASCII letters only unless &lt;code&gt;u&lt;/code&gt; is on too, when it is Unicode’s
simple case mapping; &lt;code&gt;m&lt;/code&gt; makes &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;$&lt;/code&gt; match at each line; &lt;code&gt;s&lt;/code&gt; makes &lt;code&gt;.&lt;/code&gt; match a line terminator;
&lt;code&gt;d&lt;/code&gt; makes &lt;code&gt;\n&lt;/code&gt; the only line terminator for &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;$&lt;/code&gt;; &lt;code&gt;x&lt;/code&gt; ignores white space and &lt;code&gt;#&lt;/code&gt;
comments to the end of the line, outside &lt;code&gt;\Q…\E&lt;/code&gt; and escapes, inside classes too; &lt;code&gt;U&lt;/code&gt; makes &lt;code&gt;\d&lt;/code&gt;,
&lt;code&gt;\s&lt;/code&gt;, &lt;code&gt;\w&lt;/code&gt;, &lt;code&gt;\b&lt;/code&gt; and the POSIX classes Unicode’s and turns &lt;code&gt;u&lt;/code&gt; on with it, and &lt;code&gt;(?-U)&lt;/code&gt; turns both
off. A flag set by
&lt;code&gt;(?i)&lt;/code&gt; lasts to the end of the group it is written in, across later alternatives.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Line terminators&lt;/strong&gt; are &lt;code&gt;\n&lt;/code&gt;, &lt;code&gt;\r&lt;/code&gt;, &lt;code&gt;\r\n&lt;/code&gt;, &lt;code&gt;\u0085&lt;/code&gt;, &lt;code&gt; &lt;/code&gt; and &lt;code&gt; &lt;/code&gt;. In multiline mode &lt;code&gt;^&lt;/code&gt;
matches at the start and after a line terminator but never at the very end of the input, and never
between the &lt;code&gt;\r&lt;/code&gt; and &lt;code&gt;\n&lt;/code&gt; of a pair; &lt;code&gt;$&lt;/code&gt; matches before a line terminator and at the end.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Word boundaries.&lt;/strong&gt; A word character for &lt;code&gt;\b&lt;/code&gt; is one &lt;code&gt;\w&lt;/code&gt; matches, under &lt;code&gt;U&lt;/code&gt; too, or a
non-spacing mark that follows letters or digits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Back references.&lt;/strong&gt; &lt;code&gt;\n&lt;/code&gt; with more digits takes them while the number names a group already opened;
&lt;code&gt;\11&lt;/code&gt; after one group is &lt;code&gt;\1&lt;/code&gt; and then &lt;code&gt;1&lt;/code&gt;. A reference to a group that does not exist, or that has
not matched, matches nothing. Under &lt;code&gt;i&lt;/code&gt; a reference matches the text in any case.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lookbehind&lt;/strong&gt; is bounded: its body must have a greatest length, so every repetition in it has an
upper bound, no group in it whose body has alternatives or a repetition of varying count is
repeated by a greedy or reluctant &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;+&lt;/code&gt; or &lt;code&gt;{…}&lt;/code&gt;, and it holds no back reference. It tries its body from the nearest
start first.&lt;/p&gt;
&lt;h2 id=&quot;unicode-properties&quot;&gt;Unicode properties&lt;/h2&gt;
&lt;p&gt;The properties beyond the general category answer from tables generated from the Unicode Character
Database 17.0.0, the version the general categories come from, by &lt;code&gt;scripts/unicode_tables.avin&lt;/code&gt;;
a table is read the first time a pattern names it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Scripts&lt;/strong&gt; are those &lt;code&gt;Scripts.txt&lt;/code&gt; lists, and &lt;code&gt;Unknown&lt;/code&gt; for every other code point. A script is
named by its name or its four-letter code, as &lt;code&gt;PropertyValueAliases.txt&lt;/code&gt; gives them, with &lt;code&gt;_&lt;/code&gt; for
a space and case ignored: &lt;code&gt;\p{IsOld_Italic}&lt;/code&gt;, &lt;code&gt;\p{sc=ital}&lt;/code&gt;. Where the name after &lt;code&gt;Is&lt;/code&gt; is also a
binary property or a general category, that is what it names.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Blocks&lt;/strong&gt; are those of &lt;code&gt;Blocks.txt&lt;/code&gt;. A block is named by its name there, that name without its
spaces, or one of its names in &lt;code&gt;PropertyValueAliases.txt&lt;/code&gt;, case ignored: &lt;code&gt;\p{InGreek and Coptic}&lt;/code&gt;,
&lt;code&gt;\p{InGreekandCoptic}&lt;/code&gt;, &lt;code&gt;\p{InGreek}&lt;/code&gt;, &lt;code&gt;\p{blk=Latin_1_Sup}&lt;/code&gt;. A code point in no block is in none
of them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Binary properties&lt;/strong&gt; after &lt;code&gt;Is&lt;/code&gt;: &lt;code&gt;Alphabetic&lt;/code&gt;, &lt;code&gt;Ideographic&lt;/code&gt;, &lt;code&gt;Letter&lt;/code&gt;, &lt;code&gt;Lowercase&lt;/code&gt;, &lt;code&gt;Uppercase&lt;/code&gt;,
&lt;code&gt;Titlecase&lt;/code&gt;, &lt;code&gt;Punctuation&lt;/code&gt;, &lt;code&gt;Control&lt;/code&gt;, &lt;code&gt;White_Space&lt;/code&gt;, &lt;code&gt;Digit&lt;/code&gt;, &lt;code&gt;Hex_Digit&lt;/code&gt;, &lt;code&gt;Join_Control&lt;/code&gt;,
&lt;code&gt;Noncharacter_Code_Point&lt;/code&gt;, &lt;code&gt;Assigned&lt;/code&gt;, &lt;code&gt;Emoji&lt;/code&gt;, &lt;code&gt;Emoji_Presentation&lt;/code&gt;, &lt;code&gt;Emoji_Modifier&lt;/code&gt;,
&lt;code&gt;Emoji_Modifier_Base&lt;/code&gt;, &lt;code&gt;Emoji_Component&lt;/code&gt;, &lt;code&gt;Extended_Pictographic&lt;/code&gt;, and &lt;code&gt;Word&lt;/code&gt; (alphabetic
characters, marks, decimal digits, connector punctuation and the two joiners); &lt;code&gt;Hex_Digit&lt;/code&gt;,
&lt;code&gt;Join_Control&lt;/code&gt;, &lt;code&gt;White_Space&lt;/code&gt; and &lt;code&gt;Noncharacter_Code_Point&lt;/code&gt; are also written without their &lt;code&gt;_&lt;/code&gt;. After them come the POSIX classes over Unicode, which &lt;code&gt;U&lt;/code&gt; gives the
names without &lt;code&gt;Is&lt;/code&gt; too: &lt;code&gt;Alpha&lt;/code&gt; is &lt;code&gt;Alphabetic&lt;/code&gt;, &lt;code&gt;Lower&lt;/code&gt; and &lt;code&gt;Upper&lt;/code&gt; are &lt;code&gt;Lowercase&lt;/code&gt; and
&lt;code&gt;Uppercase&lt;/code&gt;, &lt;code&gt;Space&lt;/code&gt; is &lt;code&gt;White_Space&lt;/code&gt;, &lt;code&gt;Punct&lt;/code&gt; is &lt;code&gt;Punctuation&lt;/code&gt;, &lt;code&gt;XDigit&lt;/code&gt; is &lt;code&gt;Hex_Digit&lt;/code&gt;, &lt;code&gt;Alnum&lt;/code&gt; is
&lt;code&gt;Alphabetic&lt;/code&gt; or &lt;code&gt;Nd&lt;/code&gt;, &lt;code&gt;Cntrl&lt;/code&gt; is &lt;code&gt;Cc&lt;/code&gt;, &lt;code&gt;Digit&lt;/code&gt; is &lt;code&gt;Nd&lt;/code&gt;, &lt;code&gt;Blank&lt;/code&gt; is a tab or &lt;code&gt;Zs&lt;/code&gt;, &lt;code&gt;Graph&lt;/code&gt; is
neither a separator, &lt;code&gt;Cc&lt;/code&gt;, &lt;code&gt;Cs&lt;/code&gt; nor &lt;code&gt;Cn&lt;/code&gt;, and &lt;code&gt;Print&lt;/code&gt; is &lt;code&gt;Graph&lt;/code&gt; or &lt;code&gt;Blank&lt;/code&gt; without &lt;code&gt;Cc&lt;/code&gt;. Under &lt;code&gt;i&lt;/code&gt;,
&lt;code&gt;Lowercase&lt;/code&gt;, &lt;code&gt;Uppercase&lt;/code&gt;, &lt;code&gt;Titlecase&lt;/code&gt;, &lt;code&gt;Lower&lt;/code&gt; and &lt;code&gt;Upper&lt;/code&gt; each take every cased character. Under
&lt;code&gt;U&lt;/code&gt; the names of the POSIX classes ignore case; any other name keeps it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Grapheme clusters&lt;/strong&gt; follow the extended grapheme cluster rules of Unicode’s text segmentation
annex, with the &lt;code&gt;Grapheme_Cluster_Break&lt;/code&gt;, &lt;code&gt;Extended_Pictographic&lt;/code&gt; and &lt;code&gt;Indic_Conjunct_Break&lt;/code&gt;
properties. &lt;code&gt;\X&lt;/code&gt; matches the cluster that starts where it stands, as long as the rules make it,
and is never matched shorter, so &lt;code&gt;\X\x{301}&lt;/code&gt; does not match &lt;code&gt;e&lt;/code&gt; and a combining acute. It has no
greatest length, so a lookbehind may not hold it. &lt;code&gt;\b{g}&lt;/code&gt; matches at the start and end of the
text and wherever the rules, applied to the text before it, break: never between the regional
indicators of one flag, nor inside an emoji sequence joined by a zero width joiner.&lt;/p&gt;
&lt;h2 id=&quot;matching&quot;&gt;Matching&lt;/h2&gt;
&lt;p&gt;Matching is &lt;strong&gt;backtracking, leftmost-first&lt;/strong&gt;. The search tries each start from the left; at a start,
alternatives are tried in order, a greedy repetition takes as many repetitions as it can and gives
them back one at a time, a reluctant one takes as few as it can, and a possessive one and an atomic
group never give back. The first way the whole pattern matches is the match.&lt;/p&gt;
&lt;p&gt;The matcher keeps its own backtrack stack, so however many times a group repeats, a match takes no
deeper a call stack: &lt;code&gt;(?:a|b)*&lt;/code&gt; over a million characters matches as &lt;code&gt;[ab]*&lt;/code&gt; does. A greedy,
unbounded repetition of a group, in a pattern with no back reference, remembers the indices where a
further repetition has already failed and does not try one there again, so &lt;code&gt;(a+)+$&lt;/code&gt; and &lt;code&gt;(a|aa)+$&lt;/code&gt;
fail in polynomial time, not exponential.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Each attempt at a start has a step budget&lt;/strong&gt;: an operation of the pattern run, or a choice gone
back to, is a step, and an attempt may take 1000 steps for each character of the input and each
operation of the compiled pattern, and never fewer than 10,000,000. The budget is per attempt, so a
search over a long text may take far more steps in all. &lt;code&gt;withStepLimit(n)&lt;/code&gt; gives each attempt &lt;code&gt;n&lt;/code&gt;
steps instead.&lt;/p&gt;
&lt;p&gt;An attempt that spends its budget ends the search. A plain search (&lt;code&gt;matches&lt;/code&gt;, &lt;code&gt;findFirstIn&lt;/code&gt;,
&lt;code&gt;findAllIn&lt;/code&gt;, &lt;code&gt;replaceAllIn&lt;/code&gt;, &lt;code&gt;split&lt;/code&gt;, the extractor, …) then traps, naming the pattern, the input’s
length in characters and the budget: &lt;code&gt;pattern `(a+)+?$` backtracked too far on a 40-character input, past its budget of 10000000 steps; make a repetition possessive or atomic, or search with a `try` method to handle it&lt;/code&gt;. Each search has a &lt;strong&gt;checked&lt;/strong&gt; form, its name with &lt;code&gt;try&lt;/code&gt; before it, that
answers a &lt;code&gt;Result&lt;/code&gt; instead: &lt;code&gt;Ok&lt;/code&gt; with what the plain search gives, or &lt;code&gt;Err&lt;/code&gt; with a &lt;code&gt;MatchError&lt;/code&gt;. A
program searching text or with patterns from outside it uses the checked forms, and goes on:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;grep(r: Regex, lines: Vector[string]) -&amp;gt; Result[int, MatchError]
  var n = 0
  for line in lines
    if r.tryMatches(line)? then n += 1
  Ok(n)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The error ends the whole search wherever in the text it is met: &lt;code&gt;tryFindAllIn&lt;/code&gt; and the replacing and
splitting forms give none of the matches found before it, and a replacer has been called for each of
those matches by then. A search that stops before the start where the budget is spent, as
&lt;code&gt;tryFindFirstIn&lt;/code&gt; does at its first match, answers &lt;code&gt;Ok&lt;/code&gt;. A budget spent inside a lookaround or an
atomic group ends the search too; it is never read as the body’s failing, so &lt;code&gt;(?!…)&lt;/code&gt; does not turn it
into a match. The regex is unchanged by an error, and its next search starts with a full budget.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MatchError(pattern, inputLength, budget)&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type of &lt;code&gt;avin.regex&lt;/code&gt;: the pattern as written,
the number of characters in the text searched, and the steps each attempt had. It is an
&lt;a href=&quot;/spec/errors/#the-error-trait&quot;&gt;&lt;code&gt;Error&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;message&lt;/code&gt; and its &lt;code&gt;Display&lt;/code&gt; give &lt;code&gt;pattern `p` backtracked too far on a N-character input, past its budget of B steps&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What a group captured is what it matched on the path that succeeded, with these rules where a group
is repeated or tried more than once:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A repeated group holds its &lt;strong&gt;last repetition&lt;/strong&gt;. A group inside a repeated group that did not take
part in a later repetition keeps what it matched in an earlier one: &lt;code&gt;(a|(b))+&lt;/code&gt; on &lt;code&gt;ba&lt;/code&gt; leaves
group 2 &lt;code&gt;b&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A repetition that matched nothing ends the repetition.&lt;/li&gt;
&lt;li&gt;A group in a repeated group whose body has one length is not restored when a repetition is given
back: &lt;code&gt;((a)b){0,2}abc&lt;/code&gt; on &lt;code&gt;ababc&lt;/code&gt; matches with group 1 &lt;code&gt;ab&lt;/code&gt; at 0 and group 2 the &lt;code&gt;a&lt;/code&gt; at 2.&lt;/li&gt;
&lt;li&gt;A group captured inside a lookahead keeps its capture once the lookahead has matched, whatever
happens after it.&lt;/li&gt;
&lt;li&gt;A repetition of a lookaround or of an atomic group with &lt;code&gt;?&lt;/code&gt; or &lt;code&gt;*&lt;/code&gt; may skip it: &lt;code&gt;(?&amp;gt;a)?a&lt;/code&gt; matches
&lt;code&gt;a&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;regex&quot;&gt;&lt;code&gt;Regex&lt;/code&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;What it does&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Regex(pattern)&lt;/code&gt;, &lt;code&gt;Regex(pattern, names*)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Compiles; traps with the error’s message on a pattern that is not valid. The names, given, name the groups 1, 2, … for &lt;code&gt;group(name)&lt;/code&gt; in place of the pattern’s own&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Regex.compile(pattern, names*)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Compiles, answering &lt;code&gt;Result[Regex, PatternError]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&amp;quot;pattern&amp;quot;.r()&lt;/code&gt;, &lt;code&gt;.r(names*)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Regex(pattern, names*)&lt;/code&gt;, where &lt;code&gt;avin.regex&lt;/code&gt; is imported&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;matches(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whether all of &lt;code&gt;s&lt;/code&gt; matches; for an unanchored regex, whether any part does&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;findFirstIn(s)&lt;/code&gt;, &lt;code&gt;findFirstMatchIn(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The first match, as &lt;code&gt;Option[string]&lt;/code&gt; and &lt;code&gt;Option[Match]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;findPrefixOf(s)&lt;/code&gt;, &lt;code&gt;findPrefixMatchOf(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A match starting at the start of &lt;code&gt;s&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;findAllIn(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;MatchIterator&lt;/code&gt;: every match, left to right, not overlapping&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;findAllMatchIn(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same, as an &lt;code&gt;Iterator[Match]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;replaceAllIn(s, replacement)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt; with every match replaced by the replacement, its group references filled in&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;replaceAllIn(s, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt; with every match &lt;code&gt;m&lt;/code&gt; replaced by &lt;code&gt;f(m)&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; a &lt;code&gt;(Match) -&amp;gt; string&lt;/code&gt;; its result is read as a replacement&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;replaceFirstIn(s, replacement)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt; with its first match replaced&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;replaceSomeIn(s, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt; with each match &lt;code&gt;m&lt;/code&gt; replaced where &lt;code&gt;f(m)&lt;/code&gt;, an &lt;code&gt;Option[string]&lt;/code&gt;, is &lt;code&gt;Some&lt;/code&gt;, and kept where it is &lt;code&gt;None&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;split(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;pattern.split(s)&lt;/code&gt;: the pieces of &lt;code&gt;s&lt;/code&gt; between the matches, as an &lt;code&gt;Array[string]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unapplySeq(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The groups’ texts, an &lt;code&gt;Option[List[string]]&lt;/code&gt;, where &lt;code&gt;s&lt;/code&gt; matches as &lt;code&gt;matches&lt;/code&gt; asks; &lt;code&gt;Regex&lt;/code&gt; implements it from &lt;code&gt;SeqExtractor&lt;/code&gt;, which makes the regex an &lt;a href=&quot;/spec/operators-and-control-flow/#extractor-patterns&quot;&gt;extractor&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unanchored&lt;/code&gt;, &lt;code&gt;anchored&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same regex with &lt;code&gt;matches&lt;/code&gt; and the extractor asking about any part, or the whole&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;withStepLimit(n)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same regex, each attempt at a start allowed &lt;code&gt;n&lt;/code&gt; steps in place of the &lt;a href=&quot;#matching&quot;&gt;default budget&lt;/a&gt;; &lt;code&gt;n&lt;/code&gt; must be above 0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tryMatches(s)&lt;/code&gt;, &lt;code&gt;tryFindFirstIn(s)&lt;/code&gt;, &lt;code&gt;tryFindFirstMatchIn(s)&lt;/code&gt;, &lt;code&gt;tryFindPrefixOf(s)&lt;/code&gt;, &lt;code&gt;tryFindPrefixMatchOf(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The &lt;a href=&quot;#matching&quot;&gt;checked&lt;/a&gt; searches: &lt;code&gt;Result[T, MatchError]&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt; what the plain search answers&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tryFindAllIn(s)&lt;/code&gt;, &lt;code&gt;tryFindAllMatchIn(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every match, gathered: &lt;code&gt;Result[Vector[string], MatchError]&lt;/code&gt; and &lt;code&gt;Result[Vector[Match], MatchError]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tryReplaceAllIn(s, …)&lt;/code&gt;, &lt;code&gt;tryReplaceFirstIn(s, r)&lt;/code&gt;, &lt;code&gt;tryReplaceSomeIn(s, f)&lt;/code&gt;, &lt;code&gt;trySplit(s)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The replacing and splitting searches, checked: &lt;code&gt;Result[string, MatchError]&lt;/code&gt; and &lt;code&gt;Result[Array[string], MatchError]&lt;/code&gt;; &lt;code&gt;Pattern&lt;/code&gt; has &lt;code&gt;trySplit(s, limit = 0)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;regex&lt;/code&gt;, &lt;code&gt;toString()&lt;/code&gt;, &lt;code&gt;pattern&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The pattern as written; &lt;code&gt;pattern&lt;/code&gt; is a &lt;code&gt;Pattern&lt;/code&gt;, with &lt;code&gt;pattern&lt;/code&gt;, &lt;code&gt;groupCount&lt;/code&gt; and &lt;code&gt;split&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Regex.quote(text)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A pattern matching &lt;code&gt;text&lt;/code&gt; literally: &lt;code&gt;\Q&lt;/code&gt;, the text, &lt;code&gt;\E&lt;/code&gt;, each &lt;code&gt;\E&lt;/code&gt; in the text written so it does not end the quotation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Regex.quoteReplacement(text)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A replacement writing &lt;code&gt;text&lt;/code&gt; literally: each &lt;code&gt;\&lt;/code&gt; and &lt;code&gt;$&lt;/code&gt; with a backslash before it&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;Regex&lt;/code&gt; is &lt;a href=&quot;/spec/threads/&quot;&gt;sendable&lt;/a&gt;.&lt;/strong&gt; Compiling makes everything the regex holds, and nothing
changes it after: each search keeps its own state. So one regex, a module’s &lt;code&gt;val&lt;/code&gt; among them, is
captured by a &lt;code&gt;spawn&lt;/code&gt; body or sent on a channel as it is, and any number of threads match with it at
once. A &lt;code&gt;Pattern&lt;/code&gt; is sendable too.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.regex.Regex
import avin.threads.spawn

val word = Regex(&amp;quot;[a-z]+&amp;quot;)

main()
  val t = spawn(() -&amp;gt; word.findFirstIn(&amp;quot;42 apples&amp;quot;))
  println(t.join())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extractors.&lt;/strong&gt; A regex is an &lt;a href=&quot;/spec/operators-and-control-flow/#extractor-patterns&quot;&gt;extractor&lt;/a&gt;, a
&lt;code&gt;SeqExtractor[string, List[string]]&lt;/code&gt;, whose patterns match its groups’ texts in order: &lt;code&gt;date(y, m, d)&lt;/code&gt; matches a text the whole of
which the regex matches (any part of it, for a regex made by &lt;code&gt;unanchored&lt;/code&gt;), and needs one pattern
for each group, or &lt;code&gt;rest*&lt;/code&gt; for those left. A group that took no part gives the empty string. A
regex with no groups is a test, written &lt;code&gt;word()&lt;/code&gt;. &lt;code&gt;Groups&lt;/code&gt;, imported from &lt;code&gt;avin.regex&lt;/code&gt;, a
&lt;code&gt;SeqExtractor[Match, List[string]]&lt;/code&gt;, takes apart a &lt;code&gt;Match&lt;/code&gt; found by any regex the same way, and does not match a match of a pattern with no groups.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val date = Regex(&amp;quot;(\\d{4})-(\\d\\d)-(\\d\\d)&amp;quot;)

describe(s: string) -&amp;gt; string = s match
  date(year, month, day) -&amp;gt; s&amp;quot;day $day of month $month in $year&amp;quot;
  _ -&amp;gt; &amp;quot;not a date&amp;quot;

for m in &amp;quot;(\\d+)x(\\d+)&amp;quot;.r().findAllMatchIn(&amp;quot;3x4 and 10x20&amp;quot;)
  if m is Groups(w, h) then println(s&amp;quot;$w by $h&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Replacements.&lt;/strong&gt; In a replacement, &lt;code&gt;$&lt;/code&gt; followed by digits is what a group matched: the first digit
always counts, and each digit after it is taken while the number still names a group the pattern
has, so &lt;code&gt;$10&lt;/code&gt; with one group is group 1 and then &lt;code&gt;0&lt;/code&gt;. &lt;code&gt;${name}&lt;/code&gt; is the group the pattern names
&lt;code&gt;name&lt;/code&gt; (the names given to the &lt;code&gt;Regex&lt;/code&gt; do not count here). A group that took no part writes nothing.
A backslash makes the character after it literal, so &lt;code&gt;\$&lt;/code&gt; writes &lt;code&gt;$&lt;/code&gt; and &lt;code&gt;\\&lt;/code&gt; one backslash. A
replacement computed by &lt;code&gt;f&lt;/code&gt; is read the same way; &lt;code&gt;Regex.quoteReplacement&lt;/code&gt; makes any text safe to
use. A reference that cannot be resolved traps, with these messages: &lt;code&gt;No group 2&lt;/code&gt; for a number the
pattern does not have, &lt;code&gt;No group with name {n}&lt;/code&gt;, &lt;code&gt;Illegal group reference&lt;/code&gt; for &lt;code&gt;$&lt;/code&gt; followed by
anything else, &lt;code&gt;Illegal group reference: group index is missing&lt;/code&gt; for a &lt;code&gt;$&lt;/code&gt; at the end, &lt;code&gt;named capturing group has 0 length name&lt;/code&gt;, &lt;code&gt;named capturing group is missing trailing &apos;}&apos;&lt;/code&gt;, &lt;code&gt;capturing group name {1n} starts with digit character&lt;/code&gt;, and &lt;code&gt;character to be escaped is missing&lt;/code&gt; for a
backslash at the end.&lt;/p&gt;
&lt;p&gt;Matches are found as by &lt;code&gt;findAllIn&lt;/code&gt;, so an empty match is replaced at each position between
characters: &lt;code&gt;Regex(&amp;quot;&amp;quot;).replaceAllIn(&amp;quot;é😀&amp;quot;, &amp;quot;-&amp;quot;)&lt;/code&gt; is &lt;code&gt;-é-😀-&lt;/code&gt;, and &lt;code&gt;Regex(&amp;quot;a*&amp;quot;).replaceAllIn(&amp;quot;baaac&amp;quot;, &amp;quot;-&amp;quot;)&lt;/code&gt; is &lt;code&gt;-b--c-&lt;/code&gt;. Text with no match comes back unchanged.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Splitting.&lt;/strong&gt; &lt;code&gt;Pattern.split(s, limit = 0)&lt;/code&gt; gives the pieces of &lt;code&gt;s&lt;/code&gt; between the matches, left to
right. An empty match at the very start makes no empty first piece, while a match of some length
there does (&lt;code&gt;Regex(&amp;quot;,&amp;quot;).split(&amp;quot;,a&amp;quot;)&lt;/code&gt; is &lt;code&gt;[&amp;quot;&amp;quot;, &amp;quot;a&amp;quot;]&lt;/code&gt;); a text the pattern does not match is one piece,
the empty text included. With &lt;code&gt;limit&lt;/code&gt; above 0 there are at most &lt;code&gt;limit&lt;/code&gt; pieces, the last the rest of
the text; with 0, the empty pieces at the end are dropped, so &lt;code&gt;Regex(&amp;quot;,&amp;quot;).split(&amp;quot;a,,b,,&amp;quot;)&lt;/code&gt; is
&lt;code&gt;[&amp;quot;a&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;b&amp;quot;]&lt;/code&gt; and &lt;code&gt;Regex(&amp;quot;,&amp;quot;).split(&amp;quot;,,&amp;quot;)&lt;/code&gt; has none; below 0 every piece is kept.
A &lt;code&gt;PatternError&lt;/code&gt; has a &lt;code&gt;description&lt;/code&gt;, the &lt;code&gt;pattern&lt;/code&gt; and the &lt;code&gt;index&lt;/code&gt; of the character the error was
found at (-1 where no one character is to blame); &lt;code&gt;message&lt;/code&gt; (it is an &lt;code&gt;Error&lt;/code&gt;) writes the description, &lt;code&gt; near index&lt;/code&gt;
and the index, then the pattern on a line of its own and, where the index is inside it, a caret
under that character. The descriptions are those of the table below, among others:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Unclosed group near index 3
(ab
Dangling meta character &apos;*&apos; near index 0
*a
^
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Unclosed group&lt;/code&gt;, &lt;code&gt;Unmatched closing &apos;)&apos;&lt;/code&gt;, &lt;code&gt;Unclosed character class&lt;/code&gt;, &lt;code&gt;Illegal character range&lt;/code&gt;,
&lt;code&gt;Dangling meta character &apos;*&apos;&lt;/code&gt;, &lt;code&gt;Illegal repetition&lt;/code&gt;, &lt;code&gt;Illegal repetition range&lt;/code&gt;, &lt;code&gt;Unclosed counted closure&lt;/code&gt;, &lt;code&gt;Illegal/unsupported escape sequence&lt;/code&gt;, &lt;code&gt;Illegal octal escape sequence&lt;/code&gt;, &lt;code&gt;Illegal hexadecimal escape sequence&lt;/code&gt;, &lt;code&gt;Hexadecimal codepoint is too big&lt;/code&gt;, &lt;code&gt;Illegal Unicode escape sequence&lt;/code&gt;, &lt;code&gt;Illegal control escape sequence&lt;/code&gt;, &lt;code&gt;Unknown inline modifier&lt;/code&gt;, &lt;code&gt;Unknown group type&lt;/code&gt;,
&lt;code&gt;Look-behind group does not have an obvious maximum length&lt;/code&gt;, &lt;code&gt;Named capturing group &amp;lt;n&amp;gt; is already defined&lt;/code&gt;, &lt;code&gt;named capturing group &amp;lt;n&amp;gt; does not exist&lt;/code&gt;, &lt;code&gt;capturing group name does not start with a Latin letter&lt;/code&gt;, &lt;code&gt;named capturing group is missing trailing &apos;&amp;gt;&apos;&lt;/code&gt;, &lt;code&gt;\k is not followed by &apos;&amp;lt;&apos; for named capturing group&lt;/code&gt;, &lt;code&gt;Unknown character property name {X}&lt;/code&gt;, &lt;code&gt;Unclosed character family&lt;/code&gt;, &lt;code&gt;Empty character family&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Not supported&lt;/strong&gt;, each reported as a &lt;code&gt;PatternError&lt;/code&gt; whose description begins &lt;code&gt;Unsupported&lt;/code&gt;: the
flag &lt;code&gt;c&lt;/code&gt;, canonical equivalence, and &lt;code&gt;\N{…}&lt;/code&gt;, a character by its name.&lt;/p&gt;
&lt;h2 id=&quot;match-and-matchiterator&quot;&gt;&lt;code&gt;Match&lt;/code&gt; and &lt;code&gt;MatchIterator&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;Match&lt;/code&gt; holds its &lt;code&gt;source&lt;/code&gt; text and where the match and each group start and end.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;What it answers&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;matched&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text matched&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;start()&lt;/code&gt;, &lt;code&gt;end()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Where the match starts and ends&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;start(i)&lt;/code&gt;, &lt;code&gt;end(i)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Where group &lt;code&gt;i&lt;/code&gt; starts and ends, -1 when it took no part; group 0 is the whole match&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;group(i)&lt;/code&gt;, &lt;code&gt;group(name)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[string]&lt;/code&gt;: the group’s text, &lt;code&gt;None&lt;/code&gt; when it took no part&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupCount&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The number of capturing groups&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;subgroups&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;List[Option[string]]&lt;/code&gt;, groups 1 on&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;before()&lt;/code&gt;, &lt;code&gt;after()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text before and after the match&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;before(i)&lt;/code&gt;, &lt;code&gt;after(i)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The text before and after group &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; when it took no part&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupNames&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The names given to the &lt;code&gt;Regex&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A group number outside &lt;code&gt;0..groupCount&lt;/code&gt; traps, and so does a name no group has: by the names given
to the &lt;code&gt;Regex&lt;/code&gt; where there are any (&lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; is group 0), otherwise by the pattern’s own.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Match&lt;/code&gt; is sendable: nothing in it changes once it is found, so a thread may answer one
(&lt;code&gt;spawn(() -&amp;gt; r.findFirstMatchIn(s))&lt;/code&gt;) or send it on a channel. A &lt;code&gt;MatchIterator&lt;/code&gt; is not: it is
the state of a search in progress.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;MatchIterator&lt;/code&gt; is an &lt;code&gt;Iterator[string]&lt;/code&gt; of the matched texts. After &lt;code&gt;next()&lt;/code&gt;, until the following
&lt;code&gt;hasNext()&lt;/code&gt;, its &lt;code&gt;start()&lt;/code&gt;, &lt;code&gt;end()&lt;/code&gt;, &lt;code&gt;start(i)&lt;/code&gt;, &lt;code&gt;end(i)&lt;/code&gt;, &lt;code&gt;group(i)&lt;/code&gt;, &lt;code&gt;groupCount&lt;/code&gt; and &lt;code&gt;matched&lt;/code&gt;
answer for that match, and before the first &lt;code&gt;next()&lt;/code&gt; for the first match; asked when no match is
left, they trap. &lt;code&gt;matchData()&lt;/code&gt; turns
it into an &lt;code&gt;Iterator[Match]&lt;/code&gt;.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Refined variants</title>
    <link href="https://avinlang.dev/spec/refined-variants/"/>
    <id>https://avinlang.dev/spec/refined-variants/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Data variants that fix their type&apos;s arguments, and match arms that learn those arguments, so a typed interpreter, a typed protocol or a typed plan of transitions checks at compile time.</summary>
    <content type="html">&lt;p&gt;A variant of a generic &lt;code&gt;data&lt;/code&gt; type may say which instance of the type it makes. A &lt;code&gt;match&lt;/code&gt; arm that
takes such a variant apart then knows the instance, and the code in the arm is checked with that
knowledge:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Expr[T]
  IntLit(value: int) -&amp;gt; Expr[int]
  BoolLit(value: bool) -&amp;gt; Expr[bool]
  Add(a: Expr[int], b: Expr[int]) -&amp;gt; Expr[int]
  Eq(a: Expr[int], b: Expr[int]) -&amp;gt; Expr[bool]
  If(cond: Expr[bool], yes: Expr[T], no: Expr[T])
  Pair[A, B](first: Expr[A], second: Expr[B]) -&amp;gt; Expr[(A, B)]
  First[A, B](pair: Expr[(A, B)]) -&amp;gt; Expr[A]

eval[T](e: Expr[T]) -&amp;gt; T
eval(IntLit(n)) = n
eval(BoolLit(b)) = b
eval(Add(a, b)) = eval(a) + eval(b)
eval(Eq(a, b)) = eval(a) == eval(b)
eval(If(c, yes, no)) = if eval(c) then eval(yes) else eval(no)
eval(Pair(a, b)) = (eval(a), eval(b))
eval(First(p)) =
  val (a, _) = eval(p)
  a

main()
  val e = If(Eq(IntLit(2), Add(IntLit(1), IntLit(1))), Pair(IntLit(7), BoolLit(true)), Pair(IntLit(0), BoolLit(false)))
  println(eval(e)) // (7, true)
  println(eval(First(e)) + 1) // 8
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;(7, true)
8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;IntLit(n)&lt;/code&gt; is an &lt;code&gt;Expr[int]&lt;/code&gt;, so in the clause that takes it apart &lt;code&gt;T&lt;/code&gt; is &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt; is a &lt;code&gt;T&lt;/code&gt;
there, and &lt;code&gt;n&lt;/code&gt; is a well-typed result. &lt;code&gt;Add(IntLit(1), BoolLit(true))&lt;/code&gt; is a type error where it is
written, so &lt;code&gt;eval&lt;/code&gt; never meets one. Nothing is tested at run time beyond the variant itself.&lt;/p&gt;
&lt;p&gt;A variant written as before, &lt;code&gt;If(…)&lt;/code&gt;, makes the type at its own parameters, &lt;code&gt;Expr[T]&lt;/code&gt;, as every
variant of every &lt;code&gt;data&lt;/code&gt; type does; a type none of whose variants fixes anything is an ordinary
&lt;code&gt;data&lt;/code&gt; type, and everything in &lt;a href=&quot;/spec/declarations/#data&quot;&gt;data&lt;/a&gt; holds of these types unchanged.&lt;/p&gt;
&lt;h2 id=&quot;declaring-a-refined-variant&quot;&gt;Declaring a refined variant&lt;/h2&gt;
&lt;p&gt;A variant’s &lt;strong&gt;result&lt;/strong&gt; follows its fields after &lt;code&gt;-&amp;gt;&lt;/code&gt;: &lt;code&gt;IntLit(value: int) -&amp;gt; Expr[int]&lt;/code&gt;, and with no
fields, &lt;code&gt;Balance -&amp;gt; Query[long]&lt;/code&gt;. A variant may declare &lt;strong&gt;type parameters of its own&lt;/strong&gt; after its
name, &lt;code&gt;Pair[A, B](…)&lt;/code&gt;, with bounds as any type parameter takes (&lt;code&gt;Ask[R: Sendable](…)&lt;/code&gt;). In a variant,
the data type’s own parameter names are the variant’s parameters too, so &lt;code&gt;If&lt;/code&gt;‘s &lt;code&gt;T&lt;/code&gt;, and &lt;code&gt;T&lt;/code&gt; in a
result &lt;code&gt;-&amp;gt; Expr[T]&lt;/code&gt;, need no declaring; a variant parameter may not reuse one of those names, and
takes no variance and no lower bound, as a function’s parameters take none. A result written as the
type at its own parameters, &lt;code&gt;If(…) -&amp;gt; Expr[T]&lt;/code&gt;, is the plain variant spelled out. In a refined
variant the type’s names are the variant’s like any other: &lt;code&gt;IntLit(value: T) -&amp;gt; Expr[int]&lt;/code&gt; hides
&lt;code&gt;T&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The declaration is checked as follows.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The result is an instance of the type being declared.&lt;/strong&gt; &lt;code&gt;IntLit(value: int) -&amp;gt; Option[int]&lt;/code&gt; in
&lt;code&gt;data Expr[T]&lt;/code&gt; is refused. Its arguments are any types built from the variant’s parameters and
the program’s types: &lt;code&gt;Expr[int]&lt;/code&gt;, &lt;code&gt;Expr[(A, B)]&lt;/code&gt;, &lt;code&gt;Expr[Vector[A]]&lt;/code&gt;, &lt;code&gt;Expr[(A) -&amp;gt; B]&lt;/code&gt;. They are
built of data types, classes, tuples and function types only: a constructor parameter applied in
a result (&lt;code&gt;-&amp;gt; D[F, F[A]]&lt;/code&gt;) is refused, and a variant fixes no constructor parameter
(&lt;a href=&quot;/spec/generics/#higher-kinded-types&quot;&gt;higher-kinded types&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A parameter declared with a variance is never fixed.&lt;/strong&gt; Where the type’s parameter is &lt;code&gt;+T&lt;/code&gt; or
&lt;code&gt;-T&lt;/code&gt;, the result’s argument in that place is &lt;code&gt;T&lt;/code&gt; itself. A variant fixes only invariant
parameters (&lt;a href=&quot;#variance&quot;&gt;Variance&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union in a result’s argument names no variant parameter.&lt;/strong&gt; &lt;code&gt;-&amp;gt; Expr[int | string]&lt;/code&gt; is
allowed; &lt;code&gt;-&amp;gt; Expr[A | string]&lt;/code&gt; is refused, since a value of &lt;code&gt;Expr[int | string]&lt;/code&gt; would not say
which part &lt;code&gt;A&lt;/code&gt; is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every declared variant parameter is used&lt;/strong&gt;, in a field or in the result. A parameter named in
the fields and not in the result is a &lt;a href=&quot;#hidden-type-parameters&quot;&gt;hidden parameter&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The field types are checked for variance against the data type’s parameters&lt;/strong&gt;, as any
variant’s are, for each parameter the variant leaves unfixed. A fixed or hidden parameter has no
variance: the variant’s fields are read only through a &lt;code&gt;match&lt;/code&gt; that knows them exactly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field does not name the type at a larger instance than the variant makes&lt;/strong&gt;, unless the larger
part comes from a hidden parameter. &lt;code&gt;Lift[A](x: Expr[Vector[A]]) -&amp;gt; Expr[A]&lt;/code&gt; is refused as a
&lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;nested data type&lt;/a&gt; is: &lt;code&gt;Expr[int]&lt;/code&gt; would hold an
&lt;code&gt;Expr[Vector[int]]&lt;/code&gt;, which would hold an &lt;code&gt;Expr[Vector[Vector[int]]]&lt;/code&gt;, and every instance needs its
own compiled copy. &lt;code&gt;First[A, B](pair: Expr[(A, B)]) -&amp;gt; Expr[A]&lt;/code&gt; is allowed: its larger part
holds &lt;code&gt;B&lt;/code&gt;, which a value has only where the program made one
(&lt;a href=&quot;#compilation&quot;&gt;Compilation&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;why-it-is-sound&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;A variant is a constructor, and its result is the constructor’s signature: &lt;code&gt;Pair&lt;/code&gt; is a generic
function &lt;code&gt;[A, B](first: Expr[A], second: Expr[B]) -&amp;gt; Expr[(A, B)]&lt;/code&gt;. A value can only come from a
call of it, so its type at run time is the result at the arguments the call chose, and the header of
the object says so, as every object’s &lt;a href=&quot;/spec/generics/#reification&quot;&gt;header names its exact type&lt;/a&gt;.
Rules 1 and 3 make that type something a &lt;code&gt;match&lt;/code&gt; can read back: every parameter in the result sits
under constructors that the type’s name and arguments determine (a tuple, a generic type, a function
type), so a known instance gives exactly one answer for each. Rule 2 keeps an instance’s arguments
exact where the result fixes them. Rules 5 and 6 are the checks every data type already passes,
stated for a variant whose result is not the plain instance.&lt;/p&gt;
&lt;h2 id=&quot;making-a-value&quot;&gt;Making a value&lt;/h2&gt;
&lt;p&gt;A variant is called as a generic function is, its type arguments inferred from its fields and from
the type expected, or written: &lt;code&gt;Pair[int, bool](IntLit(1), BoolLit(true))&lt;/code&gt;, and for a variant of
the data type’s own parameters, on the type as before (&lt;code&gt;Expr[int].If(…)&lt;/code&gt;). The value has the result’s
type at those arguments. Written on a variant, the type arguments are the parameters its fields and
result name, in order: a parameter of the type a refined variant names nowhere, as &lt;code&gt;T&lt;/code&gt; in &lt;code&gt;IntLit&lt;/code&gt;,
is none of them, so &lt;code&gt;IntLit&lt;/code&gt; takes no type argument. Written on the type, &lt;code&gt;Expr[(int, bool)].Pair(…)&lt;/code&gt;,
they are the instance the value makes, and the variant’s own parameters are inferred from it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val ok: Expr[bool] = Eq(IntLit(1), IntLit(2))
val bad: Expr[bool] = IntLit(1)
// error: `IntLit(1)` is an `Expr[int]`, and an `Expr[bool]` is expected here
val worse = Add(IntLit(1), BoolLit(true))
// error: `BoolLit(true)` is an `Expr[bool]`, and the field `b` of `Add` is an `Expr[int]`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A bare variant name is decided by the type expected, as &lt;a href=&quot;/spec/declarations/#data&quot;&gt;any shared name is&lt;/a&gt;;
a refined variant whose result cannot be the expected instance is reported as above.&lt;/p&gt;
&lt;h2 id=&quot;refinement-in-a-match&quot;&gt;Refinement in a match&lt;/h2&gt;
&lt;p&gt;Matching a value of type &lt;code&gt;D[X1, …, Xn]&lt;/code&gt; against a variant whose result is &lt;code&gt;D[R1, …, Rn]&lt;/code&gt; gives the
arm &lt;strong&gt;local type equalities&lt;/strong&gt;: for each fixed place, &lt;code&gt;Xi = Ri&lt;/code&gt;, with the variant’s own parameters
standing for fresh types known only by these equalities. The equalities are solved at once, by
taking both sides apart: &lt;code&gt;(A, B) = (int, bool)&lt;/code&gt; is &lt;code&gt;A = int&lt;/code&gt; and &lt;code&gt;B = bool&lt;/code&gt;, &lt;code&gt;Vector[A] = Vector[T]&lt;/code&gt;
is &lt;code&gt;A = T&lt;/code&gt;, and two different type constructors or two different types (&lt;code&gt;int = bool&lt;/code&gt;,
&lt;code&gt;Vector[A] = Option[T]&lt;/code&gt;) are a contradiction. A type parameter may be equated with a type that does
not contain it; &lt;code&gt;T = Vector[T]&lt;/code&gt; is a contradiction too.&lt;/p&gt;
&lt;p&gt;The solution is a &lt;strong&gt;most general substitution&lt;/strong&gt; of the type parameters in scope, the enclosing
function’s and class’s and the variant’s own, and it holds in the arm:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;in the arm’s guard and body, and in the patterns inside the variant’s, which may refine further:
&lt;code&gt;Add(IntLit(n), b)&lt;/code&gt; learns nothing more, and &lt;code&gt;If(BoolLit(b), x, y)&lt;/code&gt; learns &lt;code&gt;T&lt;/code&gt;‘s equalities from
&lt;code&gt;If&lt;/code&gt; only;&lt;/li&gt;
&lt;li&gt;in a function’s &lt;a href=&quot;/spec/declarations/#clauses&quot;&gt;clause&lt;/a&gt;, for the clause’s guard and body, each
argument’s pattern contributing;&lt;/li&gt;
&lt;li&gt;for &lt;a href=&quot;/spec/operators-and-control-flow/#is&quot;&gt;&lt;code&gt;is&lt;/code&gt;&lt;/a&gt;, exactly where the names the pattern binds are in
scope: the &lt;code&gt;then&lt;/code&gt; branch of &lt;code&gt;if e is IntLit(n)&lt;/code&gt;, the rest of the block after
&lt;code&gt;if e is not IntLit(n) then return …&lt;/code&gt;, the right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;for a destructuring binding, &lt;code&gt;val Refl = proof&lt;/code&gt;, in the rest of the block, the binding’s pattern
covering every value of its type as it must;&lt;/li&gt;
&lt;li&gt;in a &lt;a href=&quot;/spec/operators-and-control-flow/#match-functions&quot;&gt;match function&lt;/a&gt; and in an actor’s or a
machine’s arms, as in any &lt;code&gt;match&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Inside the arm a type and anything it equals are one type: &lt;code&gt;n: int&lt;/code&gt; is a &lt;code&gt;T&lt;/code&gt;, a &lt;code&gt;T&lt;/code&gt; takes &lt;code&gt;int&lt;/code&gt;‘s
operators and methods, and a &lt;code&gt;Vector[A]&lt;/code&gt; is a &lt;code&gt;Vector[int]&lt;/code&gt;. Outside it nothing is known:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An arm’s result is checked against the type expected of the &lt;code&gt;match&lt;/code&gt;&lt;/strong&gt; under the arm’s
equalities: in &lt;code&gt;eval&lt;/code&gt;, each clause’s body is checked against &lt;code&gt;T&lt;/code&gt;. Where no type is expected, an
arm yields its own type as written, without equalities, so arms yielding &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;T&lt;/code&gt; agree on no
type and the result is to be declared. A non-recursive function whose result is inferred from
such a &lt;code&gt;match&lt;/code&gt; is reported with the suggestion to declare it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An inference variable settled inside an arm&lt;/strong&gt; settles to the type as written there: &lt;code&gt;best = Some(n)&lt;/code&gt; with &lt;code&gt;n: int&lt;/code&gt; makes &lt;code&gt;best&lt;/code&gt; an &lt;code&gt;Option[int]&lt;/code&gt;, and not an &lt;code&gt;Option[T]&lt;/code&gt;, so a store of a &lt;code&gt;T&lt;/code&gt;
elsewhere is an error there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A variable declared outside the arm keeps its declared type&lt;/strong&gt;, and the arm may store into it any
value of that type under the equalities: &lt;code&gt;var out: T&lt;/code&gt; takes &lt;code&gt;n&lt;/code&gt; in the &lt;code&gt;IntLit&lt;/code&gt; arm.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A fresh type the equalities leave unsolved never leaves its arm&lt;/strong&gt;: matching an &lt;code&gt;Expr[T]&lt;/code&gt;,
&lt;code&gt;Pair&lt;/code&gt;‘s &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; are known only as the parts of &lt;code&gt;T&lt;/code&gt;, so with no type expected an arm whose
result names &lt;code&gt;A&lt;/code&gt;, and a local declared outside settled to a type naming it, are errors, as for a
&lt;a href=&quot;#hidden-type-parameters&quot;&gt;hidden parameter&lt;/a&gt;. Matching an &lt;code&gt;Expr[(int, bool)]&lt;/code&gt;, &lt;code&gt;A&lt;/code&gt; is &lt;code&gt;int&lt;/code&gt;, and
the fields read as &lt;code&gt;Expr[int]&lt;/code&gt; and &lt;code&gt;Expr[bool]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A binding names a variant of its value’s type to take the value apart: &lt;code&gt;val Refl = proof&lt;/code&gt;, where
the type has refined variants, holds &lt;code&gt;Refl&lt;/code&gt;‘s equalities in the rest of the block. A field of a
refined type’s one variant is read by name, &lt;code&gt;o.value&lt;/code&gt;, where the instance says the field’s type:
every value of the instance is that variant’s. An instance the variant cannot make has no values,
and a field whose type keeps a parameter the instance does not say is reached through a &lt;code&gt;match&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An arm learns equalities from variants only. An extractor pattern does not refine, since an
extractor’s result is the type its trait’s instance declares, and neither does a type pattern:
&lt;code&gt;x: Expr[int]&lt;/code&gt; on
an &lt;code&gt;Any&lt;/code&gt; binds an &lt;code&gt;Expr[int]&lt;/code&gt; and learns nothing of any type parameter.&lt;/p&gt;
&lt;h3 id=&quot;why-it-is-sound-1&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;Avin compiles a copy of each generic function for each list of type arguments the program uses, so
in any copy that runs, &lt;code&gt;T&lt;/code&gt; is one particular type, the same for the whole call. A value reaching the
arm was made by the variant at some arguments, its type is the variant’s result at them, and that
type is the value matched’s type at every fixed place (&lt;a href=&quot;#variance&quot;&gt;Variance&lt;/a&gt;). So the equalities hold
of the copy’s types, every time the arm runs, and the most general substitution is implied by them:
whatever the body is checked to do under the substitution, it does in that copy. They are facts
about types, which never change while the program runs, so a lambda made in the arm and called later
still sees them true, and a variable stored in the arm holds a value of its declared type.&lt;/p&gt;
&lt;p&gt;A contradiction means no copy and no value can reach the arm, which is why such an arm is an error
(&lt;a href=&quot;#coverage&quot;&gt;Coverage&lt;/a&gt;). Settling inference variables as written, and checking each arm’s result
against the expected type rather than letting its type out, keep every equality inside the code it
is true for: a type that leaves the arm is one the code outside can rely on without the arm’s facts.&lt;/p&gt;
&lt;h2 id=&quot;variance&quot;&gt;Variance&lt;/h2&gt;
&lt;p&gt;A type parameter declared &lt;code&gt;+T&lt;/code&gt; or &lt;code&gt;-T&lt;/code&gt; cannot be fixed by a variant, so a covariant or a
contravariant data type is refined only in its invariant places. The reason is what a value’s static
type promises. An instance’s invariant argument is exact: a value of &lt;code&gt;Expr[T]&lt;/code&gt; was made as an
&lt;code&gt;Expr[T]&lt;/code&gt;, since an invariant instance is an instance only of itself. A covariant argument is an
upper bound: a value of &lt;code&gt;Box[Animal]&lt;/code&gt; may have been made as a &lt;code&gt;Box[Dog]&lt;/code&gt;. An equality learned from a
covariant place would be false. With&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Box[+T]
  Holds(value: T)
  DogBox(dog: Dog) -&amp;gt; Box[Dog] // error: `Box` is covariant in `T`, so a variant cannot fix `T`:
  // `DogBox` makes a `Box[Dog]`; declare the parameter invariant, `data Box[T]`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;a function &lt;code&gt;asDog[T](b: Box[T], x: T) -&amp;gt; Dog = b match DogBox(_) -&amp;gt; x&lt;/code&gt; would be checked under
&lt;code&gt;T = Dog&lt;/code&gt;, and &lt;code&gt;asDog(DogBox(rex), cat)&lt;/code&gt; is a legal call at &lt;code&gt;T = Animal&lt;/code&gt; (a &lt;code&gt;Box[Dog]&lt;/code&gt; is a
&lt;code&gt;Box[Animal]&lt;/code&gt;, a cat is an &lt;code&gt;Animal&lt;/code&gt;), which would answer the cat as a &lt;code&gt;Dog&lt;/code&gt;. What the arm truly
learns there is &lt;code&gt;Dog&lt;/code&gt; is a subtype of &lt;code&gt;T&lt;/code&gt;, a bound in one direction; Avin does not refine by bounds,
and keeps the rule a single one: a variant fixes invariant parameters, and the parameters it leaves
alone keep their variance, checked as before.&lt;/p&gt;
&lt;h3 id=&quot;why-it-is-sound-2&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;Invariant subtyping is equality, and type equality in Avin is identity once aliases are expanded and
unions are in &lt;a href=&quot;/spec/unions/#normal-form&quot;&gt;normal form&lt;/a&gt;. So at a fixed place the static argument and
the argument the value was made with are the same type, which is the premise of the equalities.
The places a variant leaves unfixed take the data type’s own parameter, so a value seen through a
wider instance there is read through fields whose variance the declaration already checked.&lt;/p&gt;
&lt;h2 id=&quot;hidden-type-parameters&quot;&gt;Hidden type parameters&lt;/h2&gt;
&lt;p&gt;A variant parameter that its fields name and its result does not is &lt;strong&gt;hidden&lt;/strong&gt;: the instance does not
say what it is, so each value carries its own. A typed protocol needs one, since a request and the
address of its reply must agree on a type that the message type does not mention:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.actors.{ActorRef, AskError, spawn}
import avin.threads.Future
import avin.time

data Query[R]
  Balance -&amp;gt; Query[long]
  Owner -&amp;gt; Query[string]
  Deposit(amount: long) -&amp;gt; Query[unit]

data AccountMsg
  Ask[R: Sendable](query: Query[R], replyTo: ActorRef[R])

actor Account(owner: string) receives AccountMsg
  var balance = long(0)

  answer[R](q: Query[R]) -&amp;gt; R
  answer(Balance) = balance
  answer(Owner) = owner
  answer(Deposit(amount)) = balance += amount

  receive
    Ask(query, replyTo) -&amp;gt; replyTo.tell(answer(query))

request[R: Sendable](account: ActorRef[AccountMsg], q: Query[R]) -&amp;gt; Future[Result[R, AskError]] =
  account.ask(r -&amp;gt; Ask(q, r), timeout = time.seconds(1))

main()
  val account = spawn(Account(&amp;quot;ada&amp;quot;))
  _ = request(account, Deposit(40)).await()
  println(request(account, Balance).await()) // Ok(40)
  println(request(account, Owner).await()) // Ok(ada)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run, it prints:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Ok(40)
Ok(ada)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;request(account, Balance)&lt;/code&gt; is a &lt;code&gt;Future[Result[long, AskError]]&lt;/code&gt;, and a reply of any other type is
an error in &lt;code&gt;Account&lt;/code&gt;, not a surprise in its caller: in the &lt;code&gt;Ask&lt;/code&gt; arm &lt;code&gt;R&lt;/code&gt; is a fresh type, the same
for &lt;code&gt;query&lt;/code&gt; and &lt;code&gt;replyTo&lt;/code&gt;, so &lt;code&gt;replyTo.tell(answer(query))&lt;/code&gt; is well typed and &lt;code&gt;replyTo.tell(balance)&lt;/code&gt;
is not (&lt;code&gt;expected R, found long&lt;/code&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;In the arm a hidden parameter is a fresh type&lt;/strong&gt;, with the bounds its declaration gives it and no
other knowledge, distinct from every other type; nested patterns may refine it, as &lt;code&gt;answer&lt;/code&gt;‘s
clauses refine &lt;code&gt;R&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A hidden parameter never leaves its arm.&lt;/strong&gt; The arm’s result, checked against the type expected,
must not need it; with no expected type, an arm whose type names it is an error. A local declared
outside the arm cannot be settled to a type naming it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Making a value&lt;/strong&gt; chooses the hidden parameter at the call, inferred or written
(&lt;code&gt;Ask[long](Balance, r)&lt;/code&gt;), and its bounds are checked there, as a call’s are.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait the type derives holds of a hidden parameter only by its bounds&lt;/strong&gt;, &lt;code&gt;Sendable&lt;/code&gt; included:
each value may hold another type there. &lt;code&gt;Ask&lt;/code&gt;‘s &lt;code&gt;R: Sendable&lt;/code&gt; is what makes &lt;code&gt;AccountMsg&lt;/code&gt; an
actor’s message type; &lt;code&gt;data Box&lt;/code&gt; with &lt;code&gt;Hold[A](value: A)&lt;/code&gt; has no automatic &lt;code&gt;Display&lt;/code&gt;, and with
&lt;code&gt;Hold[A: Display](value: A)&lt;/code&gt; it has one. A parameter of the type that a refined variant hides,
as &lt;code&gt;T&lt;/code&gt; in &lt;code&gt;Hide(value: T) -&amp;gt; Tagged[int]&lt;/code&gt;, is the value’s own, not the instance’s, and is held
the same way.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;is&lt;/code&gt; test or a binding takes apart no field of a hidden type&lt;/strong&gt;: the code its names reach is
not one arm. &lt;code&gt;if m is Ask(_, _)&lt;/code&gt; tests the variant, and a field whose type every value of the
variant shares may be matched and bound; &lt;code&gt;if m is Ask(q, _)&lt;/code&gt; is an error, which says to take the
value apart with &lt;code&gt;match&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;why-it-is-sound-3&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;The value was made by a call at one type for &lt;code&gt;R&lt;/code&gt;, so its &lt;code&gt;query&lt;/code&gt; and its &lt;code&gt;replyTo&lt;/code&gt; agree on it, and
that is all the arm assumes. A fresh type equal to no other cannot be confused with a type outside
the arm, and since the arm’s result cannot name it, no value of it is seen as anything else after
the arm. Each value carries its own, so two values matched one after the other give two unrelated
fresh types, and a program cannot pass one’s query to the other’s reply.&lt;/p&gt;
&lt;h2 id=&quot;bounds-on-a-variant-s-parameters&quot;&gt;Bounds on a variant’s parameters&lt;/h2&gt;
&lt;p&gt;A variant parameter’s bounds are checked where a value is made, as a call’s are: &lt;code&gt;Ask&lt;/code&gt; with a reply
type that is not &lt;code&gt;Sendable&lt;/code&gt; is an error at the call. In the arm the parameter has its bounds, so
&lt;code&gt;Sendable&lt;/code&gt; holds of &lt;code&gt;R&lt;/code&gt; and &lt;code&gt;ActorRef[R]&lt;/code&gt; is a type there. Where a fixed parameter is equated with a
type parameter of the enclosing code, that type gains the bound in the arm: with
&lt;code&gt;Sorted[A: Ord](items: Vector[A]) -&amp;gt; Coll[A]&lt;/code&gt;, a function &lt;code&gt;smallest[T](c: Coll[T])&lt;/code&gt; may call
&lt;code&gt;c.items.min&lt;/code&gt; in the &lt;code&gt;Sorted&lt;/code&gt; arm, where &lt;code&gt;T&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The bound is gained where the arm’s equalities hold&lt;/strong&gt;, and only by a parameter equated with the
bounded one as a whole: &lt;code&gt;U&lt;/code&gt; of a &lt;code&gt;Coll[Vector[U]]&lt;/code&gt; gains nothing in the &lt;code&gt;Sorted&lt;/code&gt; arm, and neither
does &lt;code&gt;T&lt;/code&gt; among alternatives, after the arm, or in the other branch of an &lt;code&gt;is&lt;/code&gt; test.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bounds do not change coverage&lt;/strong&gt;: on a &lt;code&gt;Coll[Thing]&lt;/code&gt;, with &lt;code&gt;Thing&lt;/code&gt; not &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Sorted&lt;/code&gt; is still a
case to cover, and its arm’s code is checked at &lt;code&gt;Thing&lt;/code&gt;, without the bound.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Whether a refined type is &lt;code&gt;Sendable&lt;/code&gt; is decided at its instance&lt;/strong&gt;: a variant’s own parameters are
what the instance’s arguments make them, so &lt;code&gt;Coll[string]&lt;/code&gt; is sendable though &lt;code&gt;Sorted&lt;/code&gt; bounds &lt;code&gt;A&lt;/code&gt;
by &lt;code&gt;Ord&lt;/code&gt; alone, and a variant that cannot make the instance holds nothing in it. A hidden
parameter is sendable only by its bounds (&lt;a href=&quot;#hidden-type-parameters&quot;&gt;Hidden type parameters&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;why-it-is-sound-4&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;No value of the variant exists at arguments that break its bounds, so wherever the arm runs, the
arguments meet them. A copy at a type without the bound reaches the arm with no value, so the arm is
not compiled there (&lt;a href=&quot;#compilation&quot;&gt;Compilation&lt;/a&gt;) and the bound is never needed of that type.&lt;/p&gt;
&lt;h2 id=&quot;coverage&quot;&gt;Coverage&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; is checked for coverage over the variants &lt;strong&gt;possible at the type matched&lt;/strong&gt;: those whose
result’s equalities with that instance have a solution. On an &lt;code&gt;Expr[int]&lt;/code&gt; that is &lt;code&gt;IntLit&lt;/code&gt;, &lt;code&gt;Add&lt;/code&gt;,
&lt;code&gt;If&lt;/code&gt; and &lt;code&gt;First&lt;/code&gt;, so&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;total(e: Expr[int]) -&amp;gt; int = e match
  IntLit(n) -&amp;gt; n
  Add(a, b) -&amp;gt; total(a) + total(b)
  If(c, a, b) -&amp;gt; if eval(c) then total(a) else total(b)
  First(p) -&amp;gt;
    val (n, _) = eval(p)
    n
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;covers every value with no arm for &lt;code&gt;BoolLit&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt; or &lt;code&gt;Pair&lt;/code&gt;. In generic code each type parameter is
a type of its own, so on an &lt;code&gt;Expr[T]&lt;/code&gt; every variant is possible, and on an &lt;code&gt;Expr[(A, B)]&lt;/code&gt; every
variant but &lt;code&gt;IntLit&lt;/code&gt;, &lt;code&gt;BoolLit&lt;/code&gt;, &lt;code&gt;Add&lt;/code&gt; and &lt;code&gt;Eq&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The equalities of a row travel along it.&lt;/strong&gt; Matching a tuple of two &lt;code&gt;Expr[T]&lt;/code&gt;s,
&lt;code&gt;(IntLit(_), BoolLit(_))&lt;/code&gt; is impossible, since the first part needs &lt;code&gt;T = int&lt;/code&gt; and the second
&lt;code&gt;T = bool&lt;/code&gt;; the arms need not cover it, and an arm written for it is an error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The equalities of an enclosing arm hold in a nested &lt;code&gt;match&lt;/code&gt;&lt;/strong&gt;: inside &lt;code&gt;eval&lt;/code&gt;‘s &lt;code&gt;IntLit&lt;/code&gt; clause a
&lt;code&gt;match&lt;/code&gt; on another &lt;code&gt;Expr[T]&lt;/code&gt; is a match on an &lt;code&gt;Expr[int]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An arm no value can reach because its equalities contradict is an error&lt;/strong&gt;, as every unreachable
arm is, and the message says which equality fails:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;isZero(e: Expr[int]) -&amp;gt; bool = e match
  IntLit(n) -&amp;gt; n == 0
  Eq(_, _) -&amp;gt; false
  // error: this arm is never reached: `Eq` makes an `Expr[bool]`, and the value matched is an
  // `Expr[int]`
  _ -&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A clause whose argument patterns contradict each other is reported the same way (&lt;code&gt;this clause is never reached: … in the same clause …&lt;/code&gt;), and so is a pattern in an &lt;code&gt;is&lt;/code&gt; test, in a binding or
among alternatives, which no value matches (&lt;code&gt;this pattern never matches: …&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Each of a set of alternatives matches on its own.&lt;/strong&gt; &lt;code&gt;IntLit(_) | BoolLit(_)&lt;/code&gt; on an &lt;code&gt;Expr[T]&lt;/code&gt; is
an arm both values reach, so neither alternative’s equalities hold in the arm, nor in the
alternatives after it; an alternative no value of the matched type can be is an error, as an arm
is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An instance at which no variant is possible has no values.&lt;/strong&gt; With
&lt;code&gt;data Same[A, B]&lt;/code&gt; and its one variant &lt;code&gt;Refl -&amp;gt; Same[A, A]&lt;/code&gt;, a &lt;code&gt;Same[int, string]&lt;/code&gt; cannot be made,
and a &lt;code&gt;match&lt;/code&gt; on one is an error (&lt;code&gt;`Same[int, string]` has no values: no variant of `Same` makes one&lt;/code&gt;), whatever its arms, as is a binding taking one apart.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Guards, extractors and the rest count as they do in &lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;match&lt;/a&gt;.
The value a missing case is named by is one of a possible variant.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;why-it-is-sound-5&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;A variant left out is one no value of the matched type can be: a value of &lt;code&gt;Expr[int]&lt;/code&gt; was made by a
variant whose result is &lt;code&gt;Expr[int]&lt;/code&gt; at some arguments, and one whose result cannot be is not it.
Along a row, all the row’s patterns match the same value at the same types, so their equalities hold
together or the row matches nothing. Pruning removes only cases that have no values, so a &lt;code&gt;match&lt;/code&gt;
judged to cover its type covers every value that reaches it.&lt;/p&gt;
&lt;h2 id=&quot;compilation&quot;&gt;Compilation&lt;/h2&gt;
&lt;p&gt;Refinement costs nothing at run time. Generics are &lt;a href=&quot;/spec/generics/#reification&quot;&gt;monomorphized&lt;/a&gt;:
each copy of a generic function has concrete type arguments, and at them every equality is decided
when the copy is made.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An arm whose equalities fail at the copy is not compiled&lt;/strong&gt;: no test, no body. In &lt;code&gt;eval[bool]&lt;/code&gt;
the &lt;code&gt;IntLit&lt;/code&gt; clause is gone, and in &lt;code&gt;eval[int]&lt;/code&gt; the &lt;code&gt;IntLit&lt;/code&gt; clause’s body is &lt;code&gt;n&lt;/code&gt;, an &lt;code&gt;int&lt;/code&gt;
answered as the &lt;code&gt;int&lt;/code&gt; it is. The tests that remain are the variant tests every &lt;code&gt;match&lt;/code&gt; makes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An instance’s layout holds the variants possible at it.&lt;/strong&gt; &lt;code&gt;Expr[bool]&lt;/code&gt; has descriptors for
&lt;code&gt;BoolLit&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;If&lt;/code&gt; and &lt;code&gt;First&lt;/code&gt;, none for &lt;code&gt;IntLit&lt;/code&gt;. A variant keeps its declared position as its
tag at every instance, so equality, hashing and the derived &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; are compiled per
instance over the variants it has.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A variant with hidden parameters has a descriptor for each list of them the program makes it
with&lt;/strong&gt; (a &lt;strong&gt;pack&lt;/strong&gt;): &lt;code&gt;Ask[long]&lt;/code&gt;, &lt;code&gt;Ask[string]&lt;/code&gt; and &lt;code&gt;Ask[unit]&lt;/code&gt; above, all of tag 0. The program is
compiled whole, so the packs are known, as the types implementing a trait are for
&lt;a href=&quot;/spec/generics/#reification&quot;&gt;generic trait methods&lt;/a&gt;. A field of a hidden type is laid out at the
pack’s type, unboxed where it is a value type. An arm on such a variant is compiled once per pack
reaching it, at the hidden types, and the &lt;code&gt;match&lt;/code&gt; runs the one whose pack the value’s
descriptor names. Equality compares the descriptors before the fields: two values of one variant
in different packs are unequal, and they hash apart.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A cycle that makes packs from ever larger hidden types&lt;/strong&gt; is
&lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;polymorphic recursion&lt;/a&gt; and is reported as one; recursion
through an arm that passes a part of the value matched, as &lt;code&gt;eval(a)&lt;/code&gt; passes &lt;code&gt;Expr[A]&lt;/code&gt; taken from
an &lt;code&gt;Expr[(A, B)]&lt;/code&gt;, shrinks and is ordinary.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;why-it-is-sound-6&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;The checker accepted the body under the most general substitution; a copy is that body at one
instance of it, so it is well typed at the copy whenever the copy’s arguments satisfy the
equalities, and when they do not, no value reaches the arm and leaving it out changes nothing. A
pack’s descriptor records the hidden types the value was made with, so the arm compiled for that
pack is the one whose types are the value’s. The descriptors and packs are finite because the
copies are, which the polymorphic-recursion check guarantees.&lt;/p&gt;
&lt;h2 id=&quot;a-typed-plan-of-transitions&quot;&gt;A typed plan of transitions&lt;/h2&gt;
&lt;p&gt;A &lt;a href=&quot;/spec/actors/#state-machines&quot;&gt;state machine&lt;/a&gt; accepts any event in any state and handles it there.
Where the order of events is itself the contract, a refined type states it, and a plan that breaks
it is a type error before the machine sees an event:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data DoorShut()
data DoorOpen()
data DoorLocked()

data Step[From, To]
  OpenIt -&amp;gt; Step[DoorShut, DoorOpen]
  CloseIt -&amp;gt; Step[DoorOpen, DoorShut]
  LockIt(code: int) -&amp;gt; Step[DoorShut, DoorLocked]
  UnlockIt(code: int) -&amp;gt; Step[DoorLocked, DoorShut]

data Plan[From, To]
  Done -&amp;gt; Plan[From, From]
  Then[Mid](step: Step[From, Mid], rest: Plan[Mid, To])

event[From, To](s: Step[From, To]) -&amp;gt; DoorEvent
event(OpenIt) = Open
event(CloseIt) = Close
event(LockIt(code)) = Lock(code)
event(UnlockIt(code)) = Unlock(code)

perform[From, To](door: Door, plan: Plan[From, To]) -&amp;gt; unit
perform(door, Done) = ()
perform(door, Then(step, rest)) =
  door.handle(event(step))
  perform(door, rest)

main()
  val night: Plan[DoorShut, DoorShut] = Then(LockIt(42), Then(UnlockIt(42), Done))
  perform(Door(), night)
  val wrong: Plan[DoorShut, DoorShut] = Then(OpenIt, Then(LockIt(1), Done))
  // error: `LockIt(1)` is a `Step[DoorShut, DoorLocked]`, and a `Step[DoorOpen, _]` is expected
  // here
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Done&lt;/code&gt;‘s result, &lt;code&gt;Plan[From, From]&lt;/code&gt;, fixes &lt;code&gt;To&lt;/code&gt; to &lt;code&gt;From&lt;/code&gt;, so a plan ends where it began only through
the steps between; &lt;code&gt;Then&lt;/code&gt;‘s &lt;code&gt;Mid&lt;/code&gt; is hidden, chained from one step to the next. &lt;code&gt;perform&lt;/code&gt; recurses at
&lt;code&gt;Plan[Mid, To]&lt;/code&gt;, a pack each, with one copy per state type the program’s plans pass through.&lt;/p&gt;
&lt;p&gt;The same shape gives a type equality a value can carry: &lt;code&gt;data Same[A, B]&lt;/code&gt; with &lt;code&gt;Refl -&amp;gt; Same[A, A]&lt;/code&gt;,
and a function that turns an &lt;code&gt;A&lt;/code&gt; into a &lt;code&gt;B&lt;/code&gt; given a proof:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;cast[A, B](proof: Same[A, B], x: A) -&amp;gt; B
cast(Refl, x) = x
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;well typed because the clause learns &lt;code&gt;A = B&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;diagnostics&quot;&gt;Diagnostics&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Where&lt;/th&gt;&lt;th&gt;Message&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;A result of another type&lt;/td&gt;&lt;td&gt;&lt;code&gt;the result of a variant is an instance of its own type: `IntLit` of `Expr` declares `Option[int]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A fixed variance parameter&lt;/td&gt;&lt;td&gt;&lt;code&gt;`Box` is covariant in `T`, so a variant cannot fix `T`: `DogBox` makes a `Box[Dog]`; declare the parameter invariant, `data Box[T]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A union naming a parameter&lt;/td&gt;&lt;td&gt;&lt;code&gt;`A` is inside a union in the result of `V`, so a value of the type does not say what `A` is&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An unused variant parameter&lt;/td&gt;&lt;td&gt;&lt;code&gt;`A` is declared by `V` but named by none of its fields and not by its result&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A reused name&lt;/td&gt;&lt;td&gt;&lt;code&gt;`T` is already a parameter of `Expr`, and stands for the same type in each of its variants&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A variance on a variant’s parameter&lt;/td&gt;&lt;td&gt;&lt;code&gt;variance is written on the parameters of a type, not on a variant&apos;s own: write `A` in `V`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A constructor parameter fixed&lt;/td&gt;&lt;td&gt;&lt;code&gt;a variant fixes no constructor parameter: `W` makes `D[Vector, T]`, and `F` of `D` is a constructor parameter, so its place holds `F`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A constructor parameter of a variant’s own&lt;/td&gt;&lt;td&gt;&lt;code&gt;a variant&apos;s own type parameters stand for types, not type constructors: `G` of `V` takes type arguments; declare a constructor parameter on the type, as in `data D[G[_]]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A result no &lt;code&gt;match&lt;/code&gt; takes apart&lt;/td&gt;&lt;td&gt;&lt;code&gt;`F[A]` in the result of `V` is no type a `match` can take apart: the result&apos;s arguments are built of data types, classes, tuples and function types&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A larger instance&lt;/td&gt;&lt;td&gt;the &lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;nested data type&lt;/a&gt; error, naming the field and the variant’s result: &lt;code&gt;…: the field `x` of `Lift` has type `Expr[Vector[A]]`, and `Lift` makes `Expr[A]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Making a value&lt;/td&gt;&lt;td&gt;&lt;code&gt;`IntLit(1)` is an `Expr[int]`, and an `Expr[bool]` is expected here&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Making a field’s value&lt;/td&gt;&lt;td&gt;&lt;code&gt;`BoolLit(true)` is an `Expr[bool]`, and the field `b` of `Add` is an `Expr[int]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An impossible arm&lt;/td&gt;&lt;td&gt;&lt;code&gt;this arm is never reached: `Eq` makes an `Expr[bool]`, and the value matched is an `Expr[int]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A contradiction in a row&lt;/td&gt;&lt;td&gt;&lt;code&gt;this arm is never reached: `IntLit` needs `T` to be `int`, and `BoolLit` in the same pattern needs it to be `bool`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A cyclic equality&lt;/td&gt;&lt;td&gt;&lt;code&gt;this arm is never reached: `Wrap` needs `T` to be `Vector[T]`, which no type is&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A contradiction in a clause&lt;/td&gt;&lt;td&gt;&lt;code&gt;this clause is never reached: `ILit` needs `T` to be `int`, and `BLit` in the same clause needs it to be `bool`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An impossible test, binding or alternative&lt;/td&gt;&lt;td&gt;&lt;code&gt;this pattern never matches: `BoolLit` makes an `Expr[bool]`, and the value matched is an `Expr[int]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Two types a refining pattern takes, reading the same&lt;/td&gt;&lt;td&gt;each named with its pattern: &lt;code&gt;expected Expr[A of `Pair` on line 4], found Expr[A of `Pair` on line 5]&lt;/code&gt;, with the column too where both are on one line&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An empty instance&lt;/td&gt;&lt;td&gt;&lt;code&gt;`Same[int, string]` has no values: no variant of `Same` makes one&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An unknown type matched&lt;/td&gt;&lt;td&gt;&lt;code&gt;the type of the value matched must be known to match `IntLit`, which fixes the type&apos;s argument; write the type where the value is declared&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A hidden type leaving its arm&lt;/td&gt;&lt;td&gt;&lt;code&gt;this arm&apos;s result is an `R`, a type `Ask` hides in the value matched, which is not known outside the arm&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Arms needing an expected type&lt;/td&gt;&lt;td&gt;&lt;code&gt;the arms of this `match` agree on no type: `IntLit`&apos;s yields an `int`, which is `T` only inside that arm; declare the result type&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Clauses needing a declared result&lt;/td&gt;&lt;td&gt;&lt;code&gt;the clauses of `f` agree on no type: `IntLit`&apos;s yields an `int`, which is `T` only inside that clause; declare the result type&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An arm not the expected type&lt;/td&gt;&lt;td&gt;&lt;code&gt;this arm yields int, not the T expected of the `match`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A fresh type leaving its arm&lt;/td&gt;&lt;td&gt;&lt;code&gt;this arm&apos;s result is an `Expr[A]`, and `A` is a type `Pair` takes from the value it matches, which is not known outside its arm&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A fresh type settling a type outside&lt;/td&gt;&lt;td&gt;&lt;code&gt;a type declared outside this arm cannot be settled to an `Expr[A]`: `A` is a type `Pair` takes from the value it matches, which is not known outside its arm&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A field the instance does not determine&lt;/td&gt;&lt;td&gt;&lt;code&gt;the field `items` of `Hold` has a type a `Holder[T]` does not determine; take the value apart with `match`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A missing case&lt;/td&gt;&lt;td&gt;the usual message, naming a possible variant: &lt;code&gt;this `match` does not cover every Expr[int] value, such as `If(_, _, _)`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Growing packs&lt;/td&gt;&lt;td&gt;the &lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;polymorphic recursion&lt;/a&gt; error, naming the variant whose hidden type grows&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A hidden field in a test&lt;/td&gt;&lt;td&gt;&lt;code&gt;`Hold` hides `A`, and its field `value` names it: an `is` test or a binding takes apart no field of a hidden type; take the value apart with `match`, whose arm is compiled for each type the value hides&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A trait a hidden parameter lacks&lt;/td&gt;&lt;td&gt;&lt;code&gt;`Tagged` has no `Display` because its field `Hide.value` names `T`, which the variant hides and a value may hold at any type; bound it, as in `[T: Display]`&lt;/code&gt;; with &lt;code&gt;derives&lt;/code&gt;, &lt;code&gt;`Loud` cannot derive `Display`: its variant `Yell` hides `A` in its field `value`, which a value may hold at any type; bound the parameter, as in `[A: Display]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Sending a hidden type&lt;/td&gt;&lt;td&gt;&lt;code&gt;its variant `Keep` hides `A`, which a value may hold at any type; bound it, as in `[A: Sendable]`&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</content>
  </entry>
  <entry>
    <title>The AVIN philosophy</title>
    <link href="https://avinlang.dev/spec/philosophy/"/>
    <id>https://avinlang.dev/spec/philosophy/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Abstraction, Versatility, Intuition and Naturalness — the four principles that guide Avin&apos;s design.</summary>
    <content type="html">&lt;p&gt;&lt;strong&gt;AVIN&lt;/strong&gt; stands for &lt;strong&gt;Abstraction, Versatility, Intuition and Naturalness&lt;/strong&gt;: four principles that
guide the design of the language.&lt;/p&gt;
&lt;p&gt;Avin is designed to make sophisticated programming techniques accessible through a simple,
expressive and coherent language. Its philosophy is rooted in the belief that powerful software
should be possible to write without unnecessary complexity.&lt;/p&gt;
&lt;h2 id=&quot;a-abstraction&quot;&gt;A — Abstraction&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Express complex ideas simply.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Abstraction lets programmers focus on what a program does rather than how every detail is
implemented.&lt;/p&gt;
&lt;p&gt;Avin provides powerful abstraction mechanisms through classes, traits, generics, higher-order
functions and pattern matching.&lt;/p&gt;
&lt;p&gt;The goal is not abstraction for its own sake, but abstractions that reduce complexity, encourage
reuse and make programs easier to understand.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Principle:&lt;/strong&gt; Powerful abstractions should simplify code, not complicate it.&lt;/p&gt;
&lt;h2 id=&quot;v-versatility&quot;&gt;V — Versatility&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;One language, many possibilities.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Avin supports several programming paradigms without forcing programmers into any single style.&lt;/p&gt;
&lt;p&gt;Object-oriented, functional, imperative and generic programming coexist naturally, so developers
can choose the approach best suited to each problem.&lt;/p&gt;
&lt;p&gt;Compiled to native code, with threads, futures and the system’s libraries within reach, Avin is
intended for applications ranging from command-line utilities to sophisticated desktop software.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Principle:&lt;/strong&gt; The language should adapt to the problem, not the other way around.&lt;/p&gt;
&lt;h2 id=&quot;i-intuition&quot;&gt;I — Intuition&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Code should behave as you expect.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A language becomes easier to learn and use when its features follow consistent, predictable rules.&lt;/p&gt;
&lt;p&gt;Avin emphasizes a coherent type system, straightforward semantics, helpful type inference and
minimal syntactic surprises.&lt;/p&gt;
&lt;p&gt;Common operations should require little ceremony, while advanced features should build naturally
on simpler ones.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Principle:&lt;/strong&gt; The obvious way to express something should usually be the correct way.&lt;/p&gt;
&lt;h2 id=&quot;n-naturalness&quot;&gt;N — Naturalness&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Code that flows naturally.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Naturalness is about making programs pleasant to write, read and maintain.&lt;/p&gt;
&lt;p&gt;Avin favours concise, expressive syntax that resembles the way programmers think about problems.&lt;/p&gt;
&lt;p&gt;Unnecessary punctuation, repetitive declarations, boilerplate and artificial distinctions should
be eliminated wherever possible.&lt;/p&gt;
&lt;p&gt;The result should be code that communicates intent clearly, without obscuring its meaning behind
language machinery.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Principle:&lt;/strong&gt; Writing code should feel like expressing an idea, not negotiating with a compiler.&lt;/p&gt;
&lt;h2 id=&quot;four-principles-one-language&quot;&gt;Four principles, one language&lt;/h2&gt;
&lt;p&gt;These principles reinforce one another:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Abstraction&lt;/strong&gt; provides expressive power.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Versatility&lt;/strong&gt; provides freedom of approach.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intuition&lt;/strong&gt; provides predictability.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Naturalness&lt;/strong&gt; provides elegance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Together they define Avin’s central ambition: &lt;strong&gt;a powerful, expressive programming language in
which sophisticated ideas can be expressed simply and naturally.&lt;/strong&gt; The &lt;a href=&quot;/spec/design/&quot;&gt;design choices&lt;/a&gt;
are how those principles become a type system, a runtime and a library.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Packages</title>
    <link href="https://avinlang.dev/spec/packages/"/>
    <id>https://avinlang.dev/spec/packages/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>avin.hocon, dependencies by git, path and workspace, version selection, avin.sum, workspaces, features, machines and files for one machine, members of a repository, vendoring, a program of one file&apos;s dependencies header, the standard library&apos;s modules, and the commands that make and keep them.</summary>
    <content type="html">&lt;p&gt;A &lt;strong&gt;package&lt;/strong&gt; is a directory holding an &lt;code&gt;avin.hocon&lt;/code&gt; manifest. The directory is the package’s program
root, exactly as for a &lt;a href=&quot;/spec/declarations/#visibility-and-modules&quot;&gt;program without one&lt;/a&gt;: each
directory under it is a module named by its path, and the root directory’s own files are the root
module, which holds &lt;code&gt;main&lt;/code&gt;. A package with &lt;code&gt;main&lt;/code&gt; is a program; one without is a library. A
&lt;strong&gt;project&lt;/strong&gt; is either one package or a &lt;a href=&quot;#workspaces&quot;&gt;workspace&lt;/a&gt; of several.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;package {
  name = &amp;quot;shapes&amp;quot;
  version = &amp;quot;0.3.1&amp;quot;
  description = &amp;quot;Plane shapes and their areas&amp;quot;
  avin = &amp;quot;0.0.18&amp;quot;
}

dependencies {
  json     { git = &amp;quot;github.com/owner/json&amp;quot;, version = &amp;quot;1.4.0&amp;quot; }
  geometry { path = &amp;quot;../geometry&amp;quot; }
  testkit  { workspace = true }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;shapes/avin.hocon
shapes/avin.sum            what each fetched dependency hashed to
shapes/main.avin           the root module, with main
shapes/shapes/area.avin    module shapes
shapes/shapes/solid/*.avin module shapes.solid
shapes/tests/*.avin        module tests, the package&apos;s own tests
shapes/.avin/              builds, only on a machine with no cache directory; not source
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The manifest is optional: a directory or a single file with none above it is a program as it always
was, and needs no ceremony.&lt;/p&gt;
&lt;h2 id=&quot;the-manifest&quot;&gt;The manifest&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;package&lt;/code&gt; names the package and gives its version; both are required, and &lt;code&gt;description&lt;/code&gt;, &lt;code&gt;avin&lt;/code&gt;
and &lt;a href=&quot;#which-machines-a-package-builds-for&quot;&gt;&lt;code&gt;targets&lt;/code&gt;&lt;/a&gt; are optional. Beside it a manifest holds
&lt;code&gt;dependencies&lt;/code&gt;, &lt;a href=&quot;#features&quot;&gt;&lt;code&gt;features&lt;/code&gt;&lt;/a&gt;,
&lt;a href=&quot;#workspaces&quot;&gt;&lt;code&gt;workspace&lt;/code&gt;&lt;/a&gt;, and for its C bindings &lt;a href=&quot;#c-libraries&quot;&gt;&lt;code&gt;c-libraries&lt;/code&gt;&lt;/a&gt;,
&lt;a href=&quot;/spec/c-bindings/#how-a-program-links-its-c-libraries&quot;&gt;&lt;code&gt;c-linking&lt;/code&gt;&lt;/a&gt; and its shorthand
&lt;a href=&quot;/spec/c-bindings/#linking-statically&quot;&gt;&lt;code&gt;static-c-libraries&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A name&lt;/strong&gt; begins with a lowercase letter and holds lowercase letters, digits, &lt;code&gt;_&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;
(&lt;code&gt;geom-tools&lt;/code&gt;). It names the package, not a module: modules are named by their directories.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A version&lt;/strong&gt; is three numbers, &lt;code&gt;major.minor.patch&lt;/code&gt;, with no leading zeros (&lt;code&gt;0.3.1&lt;/code&gt;, not &lt;code&gt;0.3&lt;/code&gt; or
&lt;code&gt;0.03.1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin&lt;/code&gt;&lt;/strong&gt; is the least Avin the package builds with, a version: &lt;code&gt;avin = &amp;quot;0.0.18&amp;quot;&lt;/code&gt; is met by Avin
0.0.18 and by every later one. Versions are compared number by number, so 0.0.9 comes before
0.0.18. It is a minimum and nothing else: no range, no upper bound. With no &lt;code&gt;avin&lt;/code&gt; the package
asks for no particular Avin. &lt;code&gt;avin new&lt;/code&gt; writes the version of the Avin that made the package.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-avin-a-package-needs&quot;&gt;The Avin a package needs&lt;/h3&gt;
&lt;p&gt;Every package a program is made of is held to its &lt;code&gt;avin&lt;/code&gt;: the root package, and every dependency,
directly or through another, fetched or by path. Building, running, testing or checking the program,
&lt;code&gt;avin add&lt;/code&gt;, &lt;code&gt;avin tidy&lt;/code&gt; and &lt;code&gt;avin vendor&lt;/code&gt; all refuse a package that needs a later Avin than the one
running, at its &lt;code&gt;avin&lt;/code&gt; value, naming the package, what it needs and what is running:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `cairo` 0.2.0 needs Avin 0.0.19 or later, and this is Avin 0.0.18: upgrade Avin to 0.0.19 or later to build it
 --&amp;gt; cairo/avin.hocon:4:10
  |
4 |   avin = &amp;quot;0.0.19&amp;quot;
  |          ^^^^^^^^
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That error comes before anything else wrong in the manifest: one written for a later Avin may hold a
key this one does not know, and the upgrade is what it needs. An &lt;code&gt;avin&lt;/code&gt; that is not a version is an
error at its value, like any other. The version compared is the running Avin’s own, three numbers: a
tree between releases is the last release, so a package naming one not yet cut is refused by it. A
program that imports a standard-library module this Avin lacks is told, with the modules it has, that
it may have been written for a later Avin, and that its package says which it needs with &lt;code&gt;avin&lt;/code&gt;.
&lt;code&gt;avin lsp&lt;/code&gt; reports both on the manifest: on &lt;code&gt;avin.hocon&lt;/code&gt; itself
when the editor opens it, and on the manifest of the package a file being edited belongs to.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every key is known.&lt;/strong&gt; A key the manifest does not hold (&lt;code&gt;author&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;tag&lt;/code&gt;) is an error at
the key, as are a value of the wrong kind and a block missing what it needs. Each error points at
its line:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `1.0` is not a version: a version is three numbers, `major.minor.patch`, such as `0.1.0`
 --&amp;gt; shapes/avin.hocon:3:13
  |
3 |   version = &amp;quot;1.0&amp;quot;
  |             ^^^^^
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;dependencies&quot;&gt;Dependencies&lt;/h2&gt;
&lt;p&gt;A dependency is named in &lt;code&gt;dependencies&lt;/code&gt; and says once where it comes from:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git&lt;/code&gt; and &lt;code&gt;version&lt;/code&gt;&lt;/strong&gt;: a git repository by its &lt;strong&gt;coordinate&lt;/strong&gt;, &lt;code&gt;host/owner/name&lt;/code&gt;, read at the tag
&lt;code&gt;v&lt;/code&gt; and the version. A coordinate is identity, not a URL: &lt;code&gt;https://&lt;/code&gt; and &lt;code&gt;.git&lt;/code&gt; are refused rather
than stripped, since two spellings of one package would be two packages. The repository is cloned
from &lt;code&gt;https://&lt;/code&gt; and the coordinate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git&lt;/code&gt; and &lt;code&gt;rev&lt;/code&gt;&lt;/strong&gt;: the same repository read at one commit, &lt;code&gt;{ git = &amp;quot;github.com/owner/json&amp;quot;, rev = &amp;quot;3f9a2c1&amp;quot; }&lt;/code&gt;, for a package that has no release or a fix not yet released. A &lt;code&gt;rev&lt;/code&gt; is a commit’s id
in lowercase hexadecimal, seven to forty digits, so an abbreviation and the full id name one
package: it is cached and recorded in &lt;code&gt;avin.sum&lt;/code&gt; under the full id. A commit that no branch or tag
reaches is found by its full id alone. A dependency has a &lt;code&gt;version&lt;/code&gt; or a &lt;code&gt;rev&lt;/code&gt;, never both.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;path&lt;/code&gt;&lt;/strong&gt;: a directory holding a package, relative to the manifest that names it, for a package
developed beside the one using it. A path dependency may name paths of its own, each relative to its
own manifest. A fetched package’s path names another package of
&lt;a href=&quot;#members-of-a-repository&quot;&gt;its own repository&lt;/a&gt;, read at the same version; a path leaving the
repository is refused, since it exists only on the machine that published it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;workspace = true&lt;/code&gt;&lt;/strong&gt;: the member of the package’s &lt;a href=&quot;#workspaces&quot;&gt;workspace&lt;/a&gt; whose package has the
dependency’s name.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A &lt;code&gt;git&lt;/code&gt; entry may also name a &lt;a href=&quot;#members-of-a-repository&quot;&gt;member of the repository&lt;/a&gt; with &lt;code&gt;member&lt;/code&gt;, and
any entry may say which of the package’s &lt;a href=&quot;#features&quot;&gt;features&lt;/a&gt; it wants (&lt;code&gt;features&lt;/code&gt;,
&lt;code&gt;default_features&lt;/code&gt;) and whether it is taken only when a feature of this package turns it on
(&lt;code&gt;optional&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;A dependency that cannot be found is reported at the manifest line naming it: a path that is not a
directory, a directory holding no manifest, a workspace dependency outside a workspace or naming no
member, a tag the repository does not have.&lt;/p&gt;
&lt;h3 id=&quot;sysl-dependencies&quot;&gt;Sysl dependencies&lt;/h3&gt;
&lt;p&gt;A package whose &lt;a href=&quot;/spec/sysl-bindings/&quot;&gt;bindings&lt;/a&gt; reach a Sysl package other than Sysl’s standard
library names it in &lt;code&gt;sysl-dependencies&lt;/code&gt;, written exactly as an Avin dependency is, by &lt;code&gt;git&lt;/code&gt; with a
&lt;code&gt;version&lt;/code&gt; or a &lt;code&gt;rev&lt;/code&gt;, or by &lt;code&gt;path&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;sysl-dependencies {
  regex  { git = &amp;quot;github.com/sysl-lang/regex&amp;quot;, version = &amp;quot;0.2.0&amp;quot; }
  digits { path = &amp;quot;../digits&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are Sysl packages, not Avin ones: Sysl fetches, selects and checks them when it builds the
bindings’ shims, so they get no line in &lt;code&gt;avin.sum&lt;/code&gt; and &lt;code&gt;avin add&lt;/code&gt; and &lt;code&gt;avin tidy&lt;/code&gt; leave them alone.
A &lt;code&gt;path&lt;/code&gt; names a directory holding a &lt;code&gt;sysl.hocon&lt;/code&gt;, relative to the manifest that names it, and a
fetched package may not name one. A workspace holds no Sysl package, so &lt;code&gt;workspace = true&lt;/code&gt; is refused
here.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A program builds with the Sysl dependencies of every package in it&lt;/strong&gt;, so a library binding a Sysl
package works in every program that uses the library, which need not name the Sysl package itself.
Two packages naming one Sysl dependency at two releases of one repository take the higher; one name
given any two other origins is refused at the manifest line, naming both:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the Sysl dependency `digits` is github.com/o/digits v0.1.0 here and the directory /work/digits in `app`: one name is one Sysl package, so make them agree
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The C libraries a Sysl package needs are linked into the program.&lt;/strong&gt; A Sysl package that binds a
library the machine supplies says so in its own files, and Avin links what it says, as Sysl links
its own programs: each library a module names with &lt;code&gt;@link&lt;/code&gt; is passed as &lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt;, and each module
its manifest requires under &lt;code&gt;requires { pkg_config { … } }&lt;/code&gt; is linked with the flags &lt;code&gt;pkg-config --libs&lt;/code&gt; answers on the machine at that link. A program binding the &lt;code&gt;sqlite3&lt;/code&gt; package therefore needs
nothing more in its own manifest than the package:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;sysl-dependencies {
  sqlite3 { git = &amp;quot;github.com/sysl-lang/sqlite3&amp;quot;, version = &amp;quot;0.7.1&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The libraries are kept beside the shims’ cached archive, so a cached build links them too; the
&lt;code&gt;pkg-config&lt;/code&gt; question is asked again at every link, so a library that moved is still found. A
&lt;code&gt;pkg_config&lt;/code&gt; module the machine does not know stops the link with the command that failed. The C a
package carries in its own tree is compiled into the shims’ archive and needs nothing at the link.&lt;/p&gt;
&lt;h3 id=&quot;c-libraries&quot;&gt;C libraries&lt;/h3&gt;
&lt;p&gt;A package whose &lt;a href=&quot;/spec/c-bindings/&quot;&gt;C bindings&lt;/a&gt; call a C library names it in &lt;code&gt;c-libraries&lt;/code&gt;: the
&lt;code&gt;pkg-config&lt;/code&gt; module (or the &lt;code&gt;link&lt;/code&gt; names) that finds and links it, the &lt;code&gt;headers&lt;/code&gt; its bindings are
checked against, and an &lt;code&gt;install&lt;/code&gt; sentence for a build that cannot find it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-libraries {
  mlt { pkg-config = &amp;quot;mlt-framework-7&amp;quot;, headers = [&amp;quot;framework/mlt.h&amp;quot;], install = &amp;quot;brew install mlt&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A program links the C libraries of every package in it, asking &lt;code&gt;pkg-config&lt;/code&gt; at every build. They are
the machine’s, not fetched, unless a package vendors one by its path: they get no line in
&lt;code&gt;avin.sum&lt;/code&gt;. A program whose manifest says &lt;code&gt;static-c-libraries = true&lt;/code&gt; links them from their static
archives, so the machine it runs on needs none of them, and its &lt;code&gt;c-linking&lt;/code&gt; block chooses library by
library; only the root package’s keys are read (&lt;a href=&quot;/spec/c-bindings/#how-a-program-links-its-c-libraries&quot;&gt;C
bindings&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;what-a-dependency-brings-in&quot;&gt;What a dependency brings in&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A dependency’s modules come in under their own names.&lt;/strong&gt; A package &lt;code&gt;geometry&lt;/code&gt; whose directory holds
&lt;code&gt;geometry/&lt;/code&gt; and &lt;code&gt;geometry/solid/&lt;/code&gt; gives its users the modules &lt;code&gt;geometry&lt;/code&gt; and &lt;code&gt;geometry.solid&lt;/code&gt;, imported
exactly as the package’s own documentation shows them. Nothing in an import names a package.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Its root directory’s files and its &lt;code&gt;tests&lt;/code&gt; directory stay its own.&lt;/strong&gt; Its root module and its &lt;code&gt;main&lt;/code&gt;
are what it runs as a program, and its tests are what &lt;code&gt;avin test&lt;/code&gt; runs in it; neither is compiled into
a package that uses it, so a program can be depended on for its modules. &lt;code&gt;avin test&lt;/code&gt; runs the tests
of the package it is given and of no other.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A module belongs to one package.&lt;/strong&gt; Two packages holding one module, the package’s own included, is
refused naming both:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: the module `geometry` is in two packages, `geometry` and `shapes`: a module belongs to one package
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A directory holding its own &lt;code&gt;avin.hocon&lt;/code&gt; is another package&lt;/strong&gt; wherever it sits under a root, and is
not one of the root’s modules. This is what lets a repository hold several packages side by side.&lt;/p&gt;
&lt;h3 id=&quot;which-version-is-chosen&quot;&gt;Which version is chosen&lt;/h3&gt;
&lt;p&gt;The version of a git dependency is &lt;strong&gt;the highest that any manifest in the graph asks for&lt;/strong&gt;, never a
newer one nobody named:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;shapes         depends on json 1.2.0 and on table 0.4.0
table 0.4.0    depends on json 1.4.0
                               ------
               json resolves to 1.4.0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A commit is never chosen among.&lt;/strong&gt; Every manifest in the graph that pins a package to a &lt;code&gt;rev&lt;/code&gt; must
name one commit, and a package pinned to a commit is not also asked for at a release; either
disagreement is refused at the manifest line, naming both:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: `b` pins example.com/avin/pinned to the commit 4c1e…, and another dependency pins it to 9a07…: a package is read at one commit, so make them agree
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Selection is a function of the manifests, so builds are reproducible without a lockfile, adding a
dependency cannot silently upgrade an unrelated one, and upgrading is an edit to a number.&lt;/p&gt;
&lt;h2 id=&quot;fetched-packages-and-avin-sum&quot;&gt;Fetched packages, and &lt;code&gt;avin.sum&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A fetched package is cloned at its tag into the machine’s cache,
&lt;code&gt;&amp;lt;cache&amp;gt;/avin/pkg/&amp;lt;coordinate&amp;gt;/@v&amp;lt;version&amp;gt;/&lt;/code&gt;, shared by every project on the machine, with its history
removed. A build fetches what the cache has not got; the language server never fetches.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;avin.sum&lt;/code&gt; sits beside the manifest and &lt;strong&gt;should be committed&lt;/strong&gt;. It has a line for every fetched
package and version the project has read:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;github.com/owner/json v1.4.0 sha256:6f1b…
github.com/owner/table r3f9a2c1d5e8b4a6f7c0d1e2f3a4b5c6d7e8f9a0b sha256:41c0…
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A package pinned to a commit is kept in the cache at &lt;code&gt;&amp;lt;cache&amp;gt;/avin/pkg/&amp;lt;coordinate&amp;gt;/@r&amp;lt;commit&amp;gt;/&lt;/code&gt;, and
its line gives &lt;code&gt;r&lt;/code&gt; and the commit’s full id where a release gives &lt;code&gt;v&lt;/code&gt; and its version.&lt;/p&gt;
&lt;p&gt;The hash is SHA-256 over a listing of the package’s files, one line each: the file’s own SHA-256 in
lowercase hexadecimal, two spaces, and its path from the package’s root, sorted by path. A &lt;code&gt;.git&lt;/code&gt;
anywhere and the root’s &lt;code&gt;.avin/&lt;/code&gt; are left out. The hash is recorded beside the cache entry when it is
fetched, so a package another project fetched first is checked too.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A package whose hash differs from its line is refused.&lt;/strong&gt; What that catches is what a version number
cannot describe: a tag moved, a repository rewritten, a mirror serving something else. The first
time a package is seen it is trusted and recorded; reviewing the line that appears is a person’s
part. A path or workspace dependency gets no line, since a directory beside you is expected to change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A build only adds lines.&lt;/strong&gt; &lt;code&gt;avin tidy&lt;/code&gt; rewrites the file to exactly the packages the project’s
resolution reads, keeping each line that stays where it was and saying what it removed, and
&lt;code&gt;avin tidy --check&lt;/code&gt; writes nothing and fails while the file is not that. A version read on the way to a
higher one keeps its line, since every build reads it again. A project fetching nothing is tidy with
no &lt;code&gt;avin.sum&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;workspaces&quot;&gt;Workspaces&lt;/h2&gt;
&lt;p&gt;A &lt;strong&gt;workspace&lt;/strong&gt; is several packages resolved as one. Its root manifest lists the members’
directories, each relative to it; &lt;code&gt;*&lt;/code&gt; stands for part of one directory’s name:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;workspace = [&amp;quot;app&amp;quot;, &amp;quot;libs/*&amp;quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each member is an ordinary package with its own manifest. The workspace adds three things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;one version selection&lt;/strong&gt; over every member’s dependencies, so no two members are built against two
versions of one package;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;one &lt;code&gt;avin.sum&lt;/code&gt;&lt;/strong&gt;, at the workspace’s root;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;members depending on each other by name&lt;/strong&gt;, &lt;code&gt;geometry { workspace = true }&lt;/code&gt;, with no fetch and no
line in &lt;code&gt;avin.sum&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A root with a &lt;code&gt;package&lt;/code&gt; block is a member too, the first. A root without one compiles nothing of its
own and so takes no dependencies; a command given it is refused, listing its members. An entry with
no &lt;code&gt;*&lt;/code&gt; must name a directory holding a manifest.&lt;/p&gt;
&lt;h2 id=&quot;features&quot;&gt;Features&lt;/h2&gt;
&lt;p&gt;A package often has a part not every user wants: a server, a desktop window, a second codec. The
cost of that part is its modules, which every build compiles, and its dependencies, which every build
fetches. &lt;strong&gt;A feature is a name for one such part&lt;/strong&gt;: what it turns on is a set of the package’s own
modules, its optional dependencies, and other features.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;features {
  server {
    doc     = &amp;quot;an HTTP server&amp;quot;
    default = true
    modules = [shapes.server]
    enables = [http, &amp;quot;tls/client&amp;quot;]
  }
  desktop = [webview]
}

dependencies {
  http    { git = &amp;quot;github.com/owner/http&amp;quot;,    version = &amp;quot;0.2.0&amp;quot;, optional = true }
  tls     { git = &amp;quot;github.com/owner/tls&amp;quot;,     version = &amp;quot;0.3.0&amp;quot;, optional = true }
  webview { git = &amp;quot;github.com/owner/webview&amp;quot;, version = &amp;quot;0.1.0&amp;quot;, optional = true }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;declaring-one&quot;&gt;Declaring one&lt;/h3&gt;
&lt;p&gt;A feature is a block, named as a package is. &lt;code&gt;desktop = [webview]&lt;/code&gt; is the short form of
&lt;code&gt;desktop { enables = [webview] }&lt;/code&gt;. The block’s keys:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;key&lt;/th&gt;&lt;th&gt;meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;doc&lt;/code&gt;&lt;/td&gt;&lt;td&gt;what the feature is, shown in errors and by the language server&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;default&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;true&lt;/code&gt; makes the feature part of what a user gets when it asks for nothing else&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;modules&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the package’s modules that exist only while the feature is on, each with the modules under it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;enables&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the optional dependencies and the other features it turns on&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;requires&lt;/code&gt;&lt;/td&gt;&lt;td&gt;features that must be on whenever this one is; a build with one of them off is refused&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A member of &lt;code&gt;enables&lt;/code&gt; names a feature of this package where one of that name is declared, and
otherwise a dependency.&lt;/strong&gt; The one exception is the feature’s own name: &lt;code&gt;json = [json]&lt;/code&gt; is the ordinary
way to say “the &lt;code&gt;json&lt;/code&gt; feature takes the &lt;code&gt;json&lt;/code&gt; package”, since a feature cannot enable itself.
&lt;code&gt;&amp;quot;dep:json&amp;quot;&lt;/code&gt; names the dependency anywhere else; &lt;code&gt;&amp;quot;tls/client&amp;quot;&lt;/code&gt; turns on the feature &lt;code&gt;client&lt;/code&gt; of the
dependency labelled &lt;code&gt;tls&lt;/code&gt;, and the dependency itself where it is optional. Both are quoted, since
HOCON reads a bare &lt;code&gt;:&lt;/code&gt; or &lt;code&gt;/&lt;/code&gt; otherwise.&lt;/p&gt;
&lt;p&gt;No feature is named &lt;code&gt;default&lt;/code&gt;. A dependency marked &lt;code&gt;optional = true&lt;/code&gt; is taken only while some feature
that is on names it; one that no feature names is refused, as is a feature naming a dependency that is
not optional, a member that is neither a feature nor a dependency, a &lt;code&gt;dep:&lt;/code&gt; or &lt;code&gt;/&lt;/code&gt; member naming a
dependency the manifest does not declare, and features that turn each other on in a cycle. &lt;strong&gt;All of
these are reported when the manifest is read&lt;/strong&gt;, at the line, before anything is fetched.&lt;/p&gt;
&lt;h3 id=&quot;how-a-feature-gates-modules&quot;&gt;How a feature gates modules&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;The module is the unit a feature gates&lt;/strong&gt;; there is no conditional compilation inside a file. A
module listed in a feature’s &lt;code&gt;modules&lt;/code&gt;, and every module under it, is part of the package only while
the feature is on: its files are not read, checked or compiled otherwise. A module is listed by one
feature at most, and the root module and &lt;code&gt;tests&lt;/code&gt; cannot be listed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What a module may import follows from the gates, and is checked whichever features are on.&lt;/strong&gt; A
module may import a gated module only where its own gate implies the other’s: it is gated by the same
feature, or by one whose &lt;code&gt;enables&lt;/code&gt; reach that feature. The same holds for an optional dependency: only
a module whose gate turns that dependency on may import its modules. An ungated module importing
&lt;code&gt;shapes.server&lt;/code&gt; is an error at the import, naming the feature it would need:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `shapes.server` exists only while the feature `server` is on, and `shapes` is always compiled: list `shapes` under a feature that enables `server`, or import it from a module that is
 --&amp;gt; shapes/shapes/area.avin:3:8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because the check is made against the manifest and not against one build’s selection, a package that
checks with every feature on also builds with any set of them off.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The package’s tests may import any of its modules, whatever its gate, and any of its optional
dependencies.&lt;/strong&gt; &lt;code&gt;avin test&lt;/code&gt; turns every feature on, so a test of &lt;code&gt;shapes.server&lt;/code&gt; can sit in &lt;code&gt;tests&lt;/code&gt;
beside the rest. A test module is read only while every module it imports is: one importing a module
that is off, or importing a test module that is not read, is passed over by that build as a gated
module is, so the package still builds, checks and tests with any set of features off, running the
tests that remain. The module is still the unit: a file of &lt;code&gt;tests&lt;/code&gt; importing &lt;code&gt;shapes.server&lt;/code&gt; takes
the whole of &lt;code&gt;tests&lt;/code&gt; with it when &lt;code&gt;server&lt;/code&gt; is off, so tests that should run without a feature go in a
module of their own, &lt;code&gt;tests/plain/&lt;/code&gt;, which nothing gated reaches.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;module tests

import shapes.server.{serve, port}

@test
servesOnItsPort()
  assertEq(serve() + port(), 284)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An import refused for the module it names is refused once for the whole import, however many names
it brings in: &lt;code&gt;import shapes.server.{serve, port}&lt;/code&gt; in an ungated module is one error.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A feature only adds.&lt;/strong&gt; It adds modules and dependencies; it cannot remove or change a declaration,
because nothing in a file depends on which features are on. A gated module’s conformances are about
its own types and traits, and its extensions are seen only by the modules that import it, which are
gated too. So a package shared by two users, each asking for different features, can be given the
union of both requests without either seeing anything change.&lt;/p&gt;
&lt;h3 id=&quot;what-a-user-asks-for&quot;&gt;What a user asks for&lt;/h3&gt;
&lt;p&gt;A dependency entry says which of the package’s features it wants:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;dependencies {
  shapes { git = &amp;quot;github.com/owner/shapes&amp;quot;, version = &amp;quot;0.3.1&amp;quot;, features = [desktop] }
  json   { git = &amp;quot;github.com/owner/json&amp;quot;,   version = &amp;quot;1.4.0&amp;quot;, default_features = false }
  table  { git = &amp;quot;github.com/owner/table&amp;quot;,  version = &amp;quot;0.4.0&amp;quot;, features = [-colour] }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;features&lt;/code&gt; adds to the package’s defaults; &lt;code&gt;default_features = false&lt;/code&gt; leaves them off; a &lt;code&gt;-&lt;/code&gt; member
takes one default away for this entry. A feature the package does not declare, a &lt;code&gt;-&lt;/code&gt; member that is
not a default, and a &lt;code&gt;-&lt;/code&gt; member beside &lt;code&gt;default_features = false&lt;/code&gt; are refused, naming who asked.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Every request for one package is added together.&lt;/strong&gt; A package reached from several manifests gets
every feature any of them asked for, its defaults included unless every request left them off. A
feature that turns on an optional dependency brings that dependency’s own requests in, so the
selection is repeated until it adds nothing; it can only grow, so it ends.&lt;/p&gt;
&lt;h3 id=&quot;on-the-command-line&quot;&gt;On the command line&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;vendor&lt;/code&gt; take three flags, which choose the &lt;strong&gt;root
package’s&lt;/strong&gt; features; a dependency’s are chosen by the manifests that depend on it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--features a,b&lt;/code&gt;&lt;/td&gt;&lt;td&gt;turn these on beside the defaults; may be given more than once&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--no-default-features&lt;/code&gt;&lt;/td&gt;&lt;td&gt;leave the defaults off&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;--all-features&lt;/code&gt;&lt;/td&gt;&lt;td&gt;turn on every feature the package declares&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A name the package does not declare is refused, listing those it does. &lt;strong&gt;&lt;code&gt;avin test&lt;/code&gt;, &lt;code&gt;avin check&lt;/code&gt;
and the language server turn every feature on unless a flag says otherwise&lt;/strong&gt;, since a module no build
compiles is a module nothing checks. &lt;code&gt;avin tidy&lt;/code&gt; resolves with every feature on, so &lt;code&gt;avin.sum&lt;/code&gt; does not
depend on which flags the last build was given. A build’s reuse of an executable is keyed by the
features it was built with.&lt;/p&gt;
&lt;h3 id=&quot;what-a-feature-does-not-do&quot;&gt;What a feature does not do&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A feature has no value a function can test.&lt;/strong&gt; There is no &lt;code&gt;feature(&amp;quot;server&amp;quot;)&lt;/code&gt; constant and no
line-level gate: the module stays the only unit a feature turns on. The parts a feature turns on are
modules and optional dependencies, which are &lt;em&gt;absent&lt;/em&gt; from a build with the feature off, so a branch
testing a constant would have to type-check against modules that are not there; folding the branch
away after checking cannot help, since the check is what fails. A function that behaves differently
with a feature on is two functions: the plain one in an ungated module, and the other in the
feature’s module, which the program reaches through the feature’s own entry point.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A module is listed by one feature only.&lt;/strong&gt; A part two features share is a feature of its own, which
both &lt;code&gt;enables&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;features {
  codec  { modules = [media.codec] }
  record { modules = [media.record], enables = [codec] }
  play   { modules = [media.play],   enables = [codec] }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That keeps every gate a single feature, so whether a module may import another is one question –
does this module’s feature turn that one on – answered the same way however many features a package
has.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A feature may exist only on some machines.&lt;/strong&gt; &lt;code&gt;if&lt;/code&gt; on a feature, in the condition language of
&lt;a href=&quot;#machines&quot;&gt;machines&lt;/a&gt;, says where the feature exists; it never turns the feature on. Asking for it on
a machine where it does not exist is refused, naming the machine; a &lt;code&gt;default&lt;/code&gt; feature that does not
exist on the machine is simply not part of the default there, and &lt;code&gt;--all-features&lt;/code&gt;, &lt;code&gt;avin test&lt;/code&gt; and
&lt;code&gt;avin check&lt;/code&gt; turn on every feature that exists on the machine being built for.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;features {
  journal { doc = &amp;quot;logging to the systemd journal&amp;quot;, modules = [probe.journal], if = &amp;quot;linux&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;machines&quot;&gt;Machines&lt;/h2&gt;
&lt;p&gt;A program is built &lt;strong&gt;for a machine&lt;/strong&gt;: an operating system and a processor. Avin builds for three:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;target&lt;/th&gt;&lt;th&gt;the machine&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;aarch64-macos&lt;/code&gt;&lt;/td&gt;&lt;td&gt;macOS on Apple silicon&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;x86_64-linux&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Linux on 64-bit Intel and AMD, with glibc&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;aarch64-linux&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Linux on 64-bit Arm, with glibc&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;The machine is the one being built for&lt;/strong&gt;: &lt;code&gt;--target &amp;lt;name&amp;gt;&lt;/code&gt; where a command takes it, and
otherwise the machine the compiler runs on. Most packages never say anything about it: the standard
library answers the same way everywhere, and a package written against it builds for every target.
What follows is for the package that cannot, because it reaches something only one system has.&lt;/p&gt;
&lt;h3 id=&quot;which-machines-a-package-builds-for&quot;&gt;Which machines a package builds for&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;package.targets&lt;/code&gt; lists the targets a package supports. Left out, it is every target Avin builds for.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;package {
  name    = &amp;quot;probe&amp;quot;
  version = &amp;quot;0.2.0&amp;quot;
  targets = [&amp;quot;x86_64-linux&amp;quot;, &amp;quot;aarch64-linux&amp;quot;, &amp;quot;aarch64-macos&amp;quot;]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Building a package for a target its manifest leaves out is refused, naming the package and the
targets it lists; so is depending on it from a package whose own &lt;code&gt;targets&lt;/code&gt; reach further. A target
name Avin does not know is an error at its value, listing the ones it does.&lt;/p&gt;
&lt;h3 id=&quot;the-condition-language&quot;&gt;The condition language&lt;/h3&gt;
&lt;p&gt;A condition is a string naming machines: &lt;strong&gt;symbols&lt;/strong&gt; joined by &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt; and parentheses. The
symbols are a closed set:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;symbol&lt;/th&gt;&lt;th&gt;holds on&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;macos&lt;/code&gt;&lt;/td&gt;&lt;td&gt;macOS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;linux&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Linux&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;posix&lt;/code&gt;&lt;/td&gt;&lt;td&gt;every system Avin builds for, today &lt;code&gt;macos&lt;/code&gt; or &lt;code&gt;linux&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;aarch64&lt;/code&gt;&lt;/td&gt;&lt;td&gt;64-bit Arm&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;x86_64&lt;/code&gt;&lt;/td&gt;&lt;td&gt;64-bit Intel and AMD&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;if = &amp;quot;linux&amp;quot;
if = &amp;quot;linux &amp;amp;&amp;amp; x86_64&amp;quot;
if = &amp;quot;!macos&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A condition is checked when the manifest is read&lt;/strong&gt;, every symbol of it, whichever machine the
build is for, so a misspelling cannot read as false and quietly leave something out of every
build:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `lunix` is not something a condition can ask about the machine: the symbols are macos, linux, posix, aarch64 and x86_64
 --&amp;gt; probe/avin.hocon:9:68
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A target’s name is refused with the condition it means (&lt;code&gt;&amp;quot;x86_64-linux&amp;quot;&lt;/code&gt; is written
&lt;code&gt;&amp;quot;x86_64 &amp;amp;&amp;amp; linux&amp;quot;&lt;/code&gt;), and so is an empty condition, which is an entry every machine takes, written
without &lt;code&gt;if&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;conditions-in-the-manifest&quot;&gt;Conditions in the manifest&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;if&lt;/code&gt; may sit on an entry of &lt;code&gt;dependencies&lt;/code&gt;, &lt;code&gt;sysl-dependencies&lt;/code&gt; and &lt;code&gt;c-libraries&lt;/code&gt;, and on a
feature. The entry is part of a build only on a machine where its condition holds:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;package { name = &amp;quot;probe&amp;quot;, version = &amp;quot;0.2.0&amp;quot;, targets = [&amp;quot;x86_64-linux&amp;quot;, &amp;quot;aarch64-linux&amp;quot;, &amp;quot;aarch64-macos&amp;quot;] }

dependencies {
  inotify { git = &amp;quot;github.com/owner/inotify&amp;quot;, version = &amp;quot;0.1.0&amp;quot;, if = &amp;quot;linux&amp;quot; }
  fsevent { git = &amp;quot;github.com/owner/fsevent&amp;quot;, version = &amp;quot;0.1.0&amp;quot;, if = &amp;quot;macos&amp;quot; }
}

sysl-dependencies {
  seccomp { git = &amp;quot;github.com/owner/seccomp&amp;quot;, version = &amp;quot;0.3.0&amp;quot;, if = &amp;quot;linux&amp;quot; }
}

c-libraries {
  ssh {
    pkg-config = &amp;quot;libssh2&amp;quot;
    headers    = [&amp;quot;libssh2.h&amp;quot;]
    install { macos = &amp;quot;brew install libssh2&amp;quot;, linux = &amp;quot;apt install libssh2-1-dev&amp;quot; }
  }
  security {
    link-flags = [&amp;quot;-framework&amp;quot;, &amp;quot;Security&amp;quot;]
    headers    = [&amp;quot;&amp;lt;Security/Security.h&amp;gt;&amp;quot;]
    if         = &amp;quot;macos&amp;quot;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A dependency left out by its condition is not in the build at all&lt;/strong&gt;: not fetched, not resolved,
not linked. A dependency’s own conditional dependencies are handed on with it, so what a program
is made of on a machine is what every manifest in it takes there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin tidy&lt;/code&gt; and &lt;code&gt;avin vendor&lt;/code&gt; answer for every machine&lt;/strong&gt; in the root’s &lt;code&gt;targets&lt;/code&gt;, as they answer
for every feature, so &lt;code&gt;avin.sum&lt;/code&gt; and &lt;code&gt;vendor/&lt;/code&gt; do not depend on the machine the last command ran
on.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;if&lt;/code&gt; and &lt;code&gt;optional = true&lt;/code&gt; compose&lt;/strong&gt;: such a dependency is taken where a feature turns it on
&lt;em&gt;and&lt;/em&gt; the condition holds. A condition cannot name a feature, and a feature cannot name a machine
except through its own &lt;code&gt;if&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;install&lt;/code&gt; is a sentence or a block of them by condition&lt;/strong&gt;, so a library is installed by the words
each system uses. The first condition that holds is the one shown; a machine none of them holds
for is shown none.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;link-flags&lt;/code&gt;&lt;/strong&gt; passes flags to the link exactly as written, for what is not a library &lt;code&gt;-l&lt;/code&gt; names:
a macOS framework (&lt;code&gt;[&amp;quot;-framework&amp;quot;, &amp;quot;Security&amp;quot;]&lt;/code&gt;), a linker option. It sits beside &lt;code&gt;pkg-config&lt;/code&gt; or
&lt;code&gt;link&lt;/code&gt;, or alone.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;files-for-one-machine&quot;&gt;Files for one machine&lt;/h3&gt;
&lt;p&gt;Inside a module, &lt;strong&gt;a file whose name carries a condition symbol between its name and &lt;code&gt;.avin&lt;/code&gt; is read
only on the machines the symbol holds on&lt;/strong&gt;: &lt;code&gt;watch.linux.avin&lt;/code&gt; on Linux, &lt;code&gt;watch.macos.avin&lt;/code&gt; on macOS,
&lt;code&gt;stack.aarch64.avin&lt;/code&gt; on 64-bit Arm. A file with no such part is read everywhere, and so is a file
named as a symbol alone (&lt;code&gt;linux.avin&lt;/code&gt;). A literate file is selected the same way
(&lt;code&gt;watch.linux.lavin&lt;/code&gt;). The part is one symbol from the table above; a name whose part is not one
(&lt;code&gt;watch.lunix.avin&lt;/code&gt;, &lt;code&gt;watch.Linux.avin&lt;/code&gt;), or that carries two (&lt;code&gt;watch.linux.x86_64.avin&lt;/code&gt;), is an error
on every machine, naming the symbols:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: probe/probe/watch/watch.lunix.avin: `watch.lunix.avin`: `lunix` is not something a file&apos;s name can ask about the machine: a file read only on some machines is named `&amp;lt;name&amp;gt;.&amp;lt;symbol&amp;gt;.avin`, and the symbols are macos, linux, posix, aarch64 and x86_64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Code for one system and one processor at once is that system’s file asking &lt;code&gt;avin.target.arch&lt;/code&gt;
(below). A program of one file is the file it names, whatever its name: &lt;code&gt;avin run tool.linux.avin&lt;/code&gt;
runs it on any machine.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;probe/probe/watch/watch.avin          module probe.watch, on every machine
probe/probe/watch/watch.linux.avin    module probe.watch, on Linux
probe/probe/watch/watch.macos.avin    module probe.watch, on macOS
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;// probe/probe/watch/watch.avin
module probe.watch

// Reports each file that changes under `dir`, as the system tells of it.
changes(dir: string, report: (string) -&amp;gt; unit) -&amp;gt; unit = start(dir, report)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;// probe/probe/watch/watch.linux.avin
module probe.watch

import inotify.{Inotify, Mask}

private start(dir: string, report: (string) -&amp;gt; unit) -&amp;gt; unit =
  Inotify.open().add(dir, Mask.Modify | Mask.Create, report)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The module is the same module on every machine; its files on one machine are the ones read there.
So a private helper in one machine’s file is seen by the module’s other files on that machine, and
the shared file above calls &lt;code&gt;start&lt;/code&gt;, which each machine’s file supplies.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A module exists on a machine where at least one of its files is read.&lt;/strong&gt; A module whose every file
carries &lt;code&gt;linux&lt;/code&gt; exists only on Linux, and that is how a whole module belongs to one system.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Every file is checked on every machine it is read on.&lt;/strong&gt; &lt;code&gt;avin check&lt;/code&gt; type-checks the package once
for each of its &lt;code&gt;targets&lt;/code&gt; on which anything differs: a file with a condition, an entry with an &lt;code&gt;if&lt;/code&gt;.
A shared file calling &lt;code&gt;start&lt;/code&gt; on a machine whose file does not supply it is an error there, naming
the machine:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: no function `start` is declared in `probe.watch` on `aarch64-macos`: `watch.linux.avin` supplies it on Linux, and no file read on this machine does -- add it to a file read there, or leave the machine out of `targets`
 --&amp;gt; probe/probe/watch/watch.avin:4:67
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Machines that read the package alike, the same files from the same packages, are checked once
together, so a package whose only difference is a Linux file is checked twice, for macOS and for
Linux. A diagnostic every check reports is told once, as it is; one that only some report is told
once, with the machines it is for:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: string has no field `length`; a string counts its characters with `charCount` and its bytes with `byteLength` (on `x86_64-linux` and `aarch64-linux`)
 --&amp;gt; probe/probe/watch/watch.linux.avin:3:41
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A machine whose package cannot be read at all (a Linux-only dependency that cannot be fetched) is
reported with its machines, &lt;code&gt;on &lt;/code&gt;x86_64-linux&lt;code&gt;and&lt;/code&gt;aarch64-linux&lt;code&gt;:&lt;/code&gt;, and the others are still
checked. &lt;code&gt;avin check --target &amp;lt;name&amp;gt;&lt;/code&gt; checks that machine alone, and names none. A package in which
nothing differs is checked once, for the machine being built for, as before.&lt;/p&gt;
&lt;p&gt;That check needs no other machine’s tools: it reads and type-checks, and builds nothing; the C unit of
the package’s C bindings is built only for the machine the compiler runs on. &lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;avin run&lt;/code&gt;
and &lt;code&gt;avin test&lt;/code&gt; read and check only the files of the machine they build for, and the language server
checks the machine it runs on.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;An import of a module that does not exist everywhere is allowed only from a file that exists no
more widely.&lt;/strong&gt; &lt;code&gt;import inotify&lt;/code&gt; in &lt;code&gt;watch.linux.avin&lt;/code&gt; is allowed, since &lt;code&gt;inotify&lt;/code&gt; is taken on Linux
and the file is read only there; the same import in &lt;code&gt;watch.avin&lt;/code&gt; is an error at the import, naming
the files and the machines where the module is missing:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `inotify`, a module of the package `inotify`, exists only on x86_64-linux and aarch64-linux, where `inotify.avin` is read, and `watch.avin` is read on aarch64-macos too: import it from a file read no more widely, or make `inotify` exist on aarch64-macos
 --&amp;gt; probe/probe/watch/watch.avin:3:8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The check is made for every machine in &lt;code&gt;targets&lt;/code&gt;, whichever one is being built: where anything in the
package differs by machine, the build reads the package, with its dependencies, for each of its
targets too. “No more widely” is by machine, not by symbol: a file for &lt;code&gt;x86_64&lt;/code&gt; may import a module
of Linux’s, since every machine reading it is Linux, and a file for &lt;code&gt;aarch64&lt;/code&gt; may not, since
&lt;code&gt;aarch64-macos&lt;/code&gt; reads it. A module that exists on every machine through a different file on each is
imported from anywhere.&lt;/p&gt;
&lt;h3 id=&quot;the-machine-in-an-expression&quot;&gt;The machine in an expression&lt;/h3&gt;
&lt;p&gt;Where the difference between machines is a value rather than a call only one system has, it is
written as an ordinary &lt;code&gt;if&lt;/code&gt; over &lt;strong&gt;&lt;code&gt;avin.target&lt;/code&gt;&lt;/strong&gt;, whose two values are compile-time constants:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.target
import avin.process.MacOS

configDir(home: string) -&amp;gt; string = target.os match
  MacOS -&amp;gt; s&amp;quot;$home/Library/Application Support/probe&amp;quot;
  _     -&amp;gt; s&amp;quot;$home/.config/probe&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;target.os&lt;/code&gt; is an &lt;code&gt;avin.process.Os&lt;/code&gt; and &lt;code&gt;target.arch&lt;/code&gt; an &lt;code&gt;avin.target.Arch&lt;/code&gt; (&lt;code&gt;Aarch64&lt;/code&gt;, &lt;code&gt;X86_64&lt;/code&gt;).
Both are known when the program is compiled, so the branches not taken are folded away, at every
optimization level; and both branches are type-checked on every machine, so one cannot rot unseen
on the machine that does not take it. A branch may therefore call only what exists everywhere; a
call only one system has belongs in that system’s file. &lt;code&gt;avin.process.os()&lt;/code&gt; answers the same value
at run time.&lt;/p&gt;
&lt;p&gt;What is decided as the program is compiled is a &lt;code&gt;match&lt;/code&gt; on either value whose arms are variants,
alternatives of them, &lt;code&gt;_&lt;/code&gt; or a name (the first arm that takes the machine’s variant is the only one
compiled, a guard before it keeping the whole &lt;code&gt;match&lt;/code&gt;), an &lt;code&gt;is&lt;/code&gt; test of either against a variant, and
&lt;code&gt;==&lt;/code&gt; or &lt;code&gt;!=&lt;/code&gt; between either and a variant or the other; an &lt;code&gt;if&lt;/code&gt; over such a test, alone or as the left
of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or &lt;code&gt;||&lt;/code&gt; that decides the whole, compiles only the branch taken. The values themselves are
declared, each in &lt;code&gt;avin.target&lt;/code&gt;‘s file for the machines it is true of (&lt;code&gt;target.linux.avin&lt;/code&gt;,
&lt;code&gt;target.aarch64.avin&lt;/code&gt;), as a package would declare them.&lt;/p&gt;
&lt;h3 id=&quot;what-a-manifest-does-not-say-about-machines&quot;&gt;What a manifest does not say about machines&lt;/h3&gt;
&lt;p&gt;There is no per-machine linker, linker script, entry point or layout: an Avin program is linked by
the platform’s own linker, started at &lt;code&gt;main&lt;/code&gt; by its C runtime, on a hosted system. There is no
&lt;code&gt;choices&lt;/code&gt; block (exactly one of a set of features): the cases it serves are a machine’s, and a
machine is already exactly one. And there is no line-level gate inside a file; the file is the
smallest thing a machine selects, as the module is the smallest thing a feature selects.&lt;/p&gt;
&lt;h2 id=&quot;members-of-a-repository&quot;&gt;Members of a repository&lt;/h2&gt;
&lt;p&gt;A coordinate names a repository and the package at its root. &lt;strong&gt;A repository that is a workspace holds
other packages too, and &lt;code&gt;member&lt;/code&gt; names one of them by its directory&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;dependencies {
  geometry-solid { git = &amp;quot;github.com/owner/geometry&amp;quot;, member = &amp;quot;solid&amp;quot;, version = &amp;quot;0.5.0&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;member&lt;/code&gt; is a directory relative to the repository’s root, as the workspace’s own list writes it, and
may be nested (&lt;code&gt;&amp;quot;tools/probe&amp;quot;&lt;/code&gt;). It is read at the tag the repository is fetched at, &lt;code&gt;v0.5.0&lt;/code&gt; here,
or at a &lt;code&gt;rev&lt;/code&gt;, and must hold an &lt;code&gt;avin.hocon&lt;/code&gt; with a &lt;code&gt;package&lt;/code&gt; block there. &lt;code&gt;member&lt;/code&gt; is only a &lt;code&gt;git&lt;/code&gt;
entry’s: beside &lt;code&gt;path&lt;/code&gt; or &lt;code&gt;workspace = true&lt;/code&gt;, or naming a directory outside the repository, it is
refused at the line.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A member is a package of its own, named by the coordinate, &lt;code&gt;//&lt;/code&gt;, and its directory&lt;/strong&gt;:
&lt;code&gt;github.com/owner/geometry//solid&lt;/code&gt;. That is what &lt;code&gt;avin.sum&lt;/code&gt; records it under and what version
selection goes by, so the root package and each member are selected separately. Its modules come in
under their own names, as every dependency’s do; the name only identifies the package.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Members of one repository at one version are one fetch.&lt;/strong&gt; The repository is cloned once into
&lt;code&gt;&amp;lt;cache&amp;gt;/avin/pkg/&amp;lt;coordinate&amp;gt;/@v&amp;lt;version&amp;gt;/&lt;/code&gt; and each member is read from its directory there. Each
member’s &lt;code&gt;avin.sum&lt;/code&gt; line holds the hash of the whole clone, which is what was fetched, so the root’s
line and a member’s at one version carry the same hash and each is checked:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;github.com/owner/geometry v0.5.0 sha256:6f1b…
github.com/owner/geometry//solid v0.5.0 sha256:6f1b…
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A fetched member’s siblings come from the same repository.&lt;/strong&gt; Inside its workspace a member names
another with &lt;code&gt;{ workspace = true }&lt;/code&gt; or a &lt;code&gt;path&lt;/code&gt; such as &lt;code&gt;&amp;quot;../core&amp;quot;&lt;/code&gt;; fetched, each of those is the
sibling’s own coordinate at the version the member was fetched at, the root package’s being the bare
coordinate. It is then an ordinary dependency: a user asking for a higher version of the sibling gets
it, by the usual rule. A &lt;code&gt;path&lt;/code&gt; leaving the repository is refused, as any fetched package’s path is.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;avin add github.com/owner/geometry//solid@0.5.0&lt;/code&gt; writes the entry with &lt;code&gt;git&lt;/code&gt; and &lt;code&gt;member&lt;/code&gt;, under the
name the member’s manifest gives it. A member that is not in the repository at that version, or a
directory there without a manifest, is refused when it is fetched, naming the coordinate and version.&lt;/p&gt;
&lt;h2 id=&quot;vendoring&quot;&gt;Vendoring&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;avin vendor&lt;/code&gt; copies every package the project resolves to into a &lt;strong&gt;&lt;code&gt;vendor/&lt;/code&gt; directory beside the
project’s manifest&lt;/strong&gt;, the workspace root’s in a workspace:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin vendor
fetching github.com/owner/json v1.4.0
vendored 3 packages into vendor/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;vendor/&lt;/code&gt; is the machine’s cache placed inside the project&lt;/strong&gt;, with its layout:
&lt;code&gt;vendor/&amp;lt;coordinate&amp;gt;/@v&amp;lt;version&amp;gt;/&lt;/code&gt; and &lt;code&gt;@r&amp;lt;commit&amp;gt;/&lt;/code&gt;, each with the hash recorded beside it. A
project that has a &lt;code&gt;vendor/&lt;/code&gt; resolves from it instead of the cache, and &lt;strong&gt;never fetches&lt;/strong&gt;: a package
the build needs and &lt;code&gt;vendor/&lt;/code&gt; lacks is refused, naming &lt;code&gt;avin vendor&lt;/code&gt; as the way to add it. Nothing has
to be configured: the directory being there is the whole of what turns it on, so a clone of a
project with a committed &lt;code&gt;vendor/&lt;/code&gt; builds with the network off.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is copied is what the project’s tests resolve&lt;/strong&gt;: every feature the package declares is on
unless the feature flags say otherwise, so &lt;code&gt;avin test&lt;/code&gt; on a vendored project fetches nothing either.
Each package is fetched into the machine’s cache first if it is not there, gets an &lt;code&gt;avin.sum&lt;/code&gt; line
if it has none, and &lt;strong&gt;its copy is hashed and checked against that line&lt;/strong&gt; before it is put in place,
so a cache entry edited since it was fetched is refused rather than frozen into the project. A clone’s
&lt;code&gt;.git&lt;/code&gt; is not copied. A package already vendored as recorded is left alone, and one the resolution no
longer reads is removed, the command saying which. Path and workspace dependencies are not vendored:
they are directories being edited beside the project, as &lt;code&gt;avin.sum&lt;/code&gt; already treats them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;vendor/&lt;/code&gt; is not source.&lt;/strong&gt; At the project’s root it is never read as a module, as &lt;code&gt;.avin/&lt;/code&gt; is not,
and nothing in it is compiled as one of the project’s own modules; its packages are dependencies like
any fetched one. &lt;code&gt;avin.sum&lt;/code&gt; is unchanged by vendoring: it is still the record each vendored package is
checked against, and &lt;code&gt;avin tidy&lt;/code&gt; still rewrites it to the resolution, independently of what &lt;code&gt;vendor/&lt;/code&gt;
holds. &lt;code&gt;avin tidy&lt;/code&gt; and &lt;code&gt;avin add&lt;/code&gt; read the machine’s cache, fetching into it, whether or not there is
a &lt;code&gt;vendor/&lt;/code&gt;; after &lt;code&gt;avin add&lt;/code&gt;, the build refuses the new package until &lt;code&gt;avin vendor&lt;/code&gt; copies it in.&lt;/p&gt;
&lt;h2 id=&quot;programs-of-one-file&quot;&gt;Programs of one file&lt;/h2&gt;
&lt;p&gt;A program of one file has no manifest, and &lt;strong&gt;names its dependencies in a header at its top&lt;/strong&gt;: the
line &lt;code&gt;// avin.hocon&lt;/code&gt;, then comment lines holding exactly what a manifest’s &lt;code&gt;dependencies&lt;/code&gt; block
holds:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;#!/usr/bin/env avin
// avin.hocon
// dependencies {
//   json  { git = &amp;quot;github.com/avin-lang/json&amp;quot;, version = &amp;quot;0.1.0&amp;quot; }
//   table { path = &amp;quot;../table&amp;quot; }
// }

import dev.avinlang.json

main(args: Vector[string])
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The header is comments&lt;/strong&gt;, so it is Avin to every tool that reads the file, and the file stays a
file: no directory, no manifest beside it. &lt;code&gt;avin run&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; and the
language server read it; nothing else needs to.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It begins on the first line&lt;/strong&gt;, or on the second after a &lt;code&gt;#!&lt;/code&gt; line, with &lt;code&gt;// avin.hocon&lt;/code&gt; and
nothing else (blanks aside). It runs to the first line that is not a &lt;code&gt;//&lt;/code&gt; comment, so a blank line
ends it, and a comment about the program goes after that. Its text is each line after its &lt;code&gt;//&lt;/code&gt;,
read as HOCON. A &lt;code&gt;// avin.hocon&lt;/code&gt; line anywhere else in the file is an error at that line, since a
header that is not read would be a dependency silently missing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It holds &lt;code&gt;dependencies&lt;/code&gt; and nothing else.&lt;/strong&gt; A dependency is written as in a manifest, by &lt;code&gt;git&lt;/code&gt;
with &lt;code&gt;version&lt;/code&gt; or &lt;code&gt;rev&lt;/code&gt;, with &lt;code&gt;member&lt;/code&gt; for a &lt;a href=&quot;#members-of-a-repository&quot;&gt;member of a repository&lt;/a&gt;,
or by &lt;code&gt;path&lt;/code&gt;, relative to the file’s directory; &lt;code&gt;features&lt;/code&gt; and &lt;code&gt;default_features&lt;/code&gt; ask for a
dependency’s features as they do in a manifest. &lt;code&gt;workspace = true&lt;/code&gt; and &lt;code&gt;optional&lt;/code&gt; are refused: a
program of one file is in no workspace and has no features of its own to turn a dependency on.
Another key (&lt;code&gt;package&lt;/code&gt;, &lt;code&gt;features&lt;/code&gt;, &lt;code&gt;sysl-dependencies&lt;/code&gt;, &lt;code&gt;c-libraries&lt;/code&gt;) is refused at the key: a
program that needs one is a package.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The dependencies resolve exactly as a manifest’s do&lt;/strong&gt;: the same version selection, the same
cache, the same errors at the header’s line in the file:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `gone` is a path dependency, and `../gone` is not a directory
 --&amp;gt; tool.avin:4:6
  |
4 | //   gone { path = &amp;quot;../gone&amp;quot; }
  |      ^^^^
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Its sum file is beside it, named after it&lt;/strong&gt;: &lt;code&gt;tool.avin.sum&lt;/code&gt; for &lt;code&gt;tool.avin&lt;/code&gt;, written as
&lt;code&gt;avin.sum&lt;/code&gt; is, a line for every fetched package and version it reads, and committed with the file.
A program of one file with only path dependencies, or none, has none. &lt;code&gt;avin tidy tool.avin&lt;/code&gt;
rewrites it, and removes it from a file whose header is gone.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is not vendored.&lt;/strong&gt; &lt;code&gt;vendor/&lt;/code&gt; belongs to one project, and a directory of programs of one file
would share one; &lt;code&gt;avin vendor tool.avin&lt;/code&gt; is refused, naming a package as the way to build with the
network off. &lt;code&gt;avin add&lt;/code&gt; writes into a manifest, so it is refused too: the header is edited by hand.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A file of a package, or of a program of many files, may not have one.&lt;/strong&gt; A package’s
dependencies are its manifest’s, and a header in one of its files is refused at the header rather
than merged with it or passed over; so is one in a file of a directory program, which has no
manifest to put them in until it becomes a package.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;A first line beginning &lt;code&gt;#!&lt;/code&gt; is not Avin&lt;/strong&gt;, in any file: it names the program that runs the file, so
a program of one file can be run as a command (&lt;code&gt;chmod +x tool.avin&lt;/code&gt;, then &lt;code&gt;./tool.avin a b&lt;/code&gt;). The
line is written &lt;code&gt;#!/usr/bin/env avin&lt;/code&gt;, so &lt;code&gt;./tool.avin a b&lt;/code&gt; runs &lt;code&gt;avin ./tool.avin a b&lt;/code&gt;, and
&lt;strong&gt;&lt;code&gt;avin &amp;lt;file&amp;gt; ...&lt;/code&gt; for a file whose first line begins &lt;code&gt;#!&lt;/code&gt; gives every argument after the file to
the program&lt;/strong&gt;: &lt;code&gt;./tool.avin -O0 x&lt;/code&gt; passes &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt;, as an interpreter passes its script’s
arguments, since a command’s caller does not know it is written in Avin. Every other form keeps the
rule of the command line: &lt;code&gt;avin run tool.avin -O0 -- x&lt;/code&gt;, and &lt;code&gt;avin -O2 tool.avin -- x&lt;/code&gt;, take &lt;code&gt;-O0&lt;/code&gt;
and &lt;code&gt;-O2&lt;/code&gt; as avin’s own and pass only what follows &lt;code&gt;--&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;the-standard-library-s-modules&quot;&gt;The standard library’s modules&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The standard library is the module &lt;code&gt;avin&lt;/code&gt; and the modules under it&lt;/strong&gt;, written in Avin and shipped
with the compiler: &lt;code&gt;share/avin/library&lt;/code&gt; beside &lt;code&gt;bin/avin&lt;/code&gt;, or &lt;code&gt;library/&lt;/code&gt; under &lt;code&gt;AVIN_ROOT&lt;/code&gt; for a
source checkout. Its version is the compiler’s. It is never a dependency: no manifest names it, no
&lt;code&gt;avin.sum&lt;/code&gt; line records it, and no package may declare a module named &lt;code&gt;avin&lt;/code&gt; or under it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin&lt;/code&gt; itself is the prelude.&lt;/strong&gt; Its public declarations are seen by every file without an import,
after the file’s own module and its imports.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every other module of it is imported by name&lt;/strong&gt;, as any module is: &lt;code&gt;import avin.fs&lt;/code&gt;,
&lt;code&gt;import avin.collections.mutable.{Map, Set}&lt;/code&gt;, &lt;code&gt;import avin.threads as t&lt;/code&gt;. Nothing beyond the prelude
is seen without an import. A module of the library is found by its path under the library’s
directory, exactly as a program’s module is found under its root; one that is not there is an
error at the import, listing the modules under the deepest prefix that exists:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the standard library has no module `avin.regx`; the modules under `avin` are `avin.actors`, `avin.c`, `avin.cli`, `avin.collections`, `avin.crypto`, `avin.fs`, `avin.io`, `avin.math`, `avin.net`, `avin.process`, `avin.random`, `avin.regex`, `avin.signal`, `avin.target`, `avin.threads`, `avin.time`
 --&amp;gt; app/main.avin:1:8
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A compilation reads the prelude and only the library modules something imports&lt;/strong&gt;: the prelude’s
own imports, then every library module the program, its dependencies and those modules import, to
the end. A library module nothing imports is not read, so the standard library can grow without
every program parsing and checking all of it. Within what is read, a function is compiled only as
a program reaches it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What belongs in it&lt;/strong&gt; is what every program’s types are built from (the core traits, collections,
strings, formatting) and what talks to the operating system (&lt;code&gt;avin.io&lt;/code&gt;, &lt;code&gt;avin.fs&lt;/code&gt;, &lt;code&gt;avin.process&lt;/code&gt;,
&lt;code&gt;avin.time&lt;/code&gt;, &lt;code&gt;avin.threads&lt;/code&gt;), so a script of one file with no manifest has them. A library for one
format or domain is a package of its own, fetched like any other: JSON is the package
&lt;code&gt;dev.avinlang.json&lt;/code&gt; (see &lt;a href=&quot;/spec/json/&quot;&gt;JSON&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An import that leaves out &lt;code&gt;avin.&lt;/code&gt;&lt;/strong&gt; is an error that writes out the import meant, where the
library has a module of that name and the program has no module or declaration of its own by it:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: there is no module `fs`; the standard library&apos;s is `avin.fs`, imported as `import avin.fs`
 --&amp;gt; script.avin:1:8
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An import of &lt;code&gt;avin.json&lt;/code&gt;&lt;/strong&gt;, or of &lt;code&gt;json&lt;/code&gt; in a program with no module or declaration of that name
and no dependency on the package, is an error naming the package:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: JSON is the package `dev.avinlang.json`; add it to your dependencies
 --&amp;gt; script.avin:1:8
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It has no features.&lt;/strong&gt; A standard module is either imported or not, which already costs a program
nothing it does not use.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The language server completes &lt;code&gt;import avin.&lt;/code&gt; from the library’s directories, and its go-to-definition
opens the library’s own source, which is read-only to a rename.&lt;/p&gt;
&lt;h2 id=&quot;commands&quot;&gt;Commands&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Every command finds the package from any path in it&lt;/strong&gt;, walking up from the file or directory it is
given to the nearest &lt;code&gt;avin.hocon&lt;/code&gt; with a &lt;code&gt;package&lt;/code&gt; block: &lt;code&gt;avin run shapes/main.avin&lt;/code&gt; and
&lt;code&gt;avin check shapes/tests&lt;/code&gt; both mean &lt;code&gt;shapes&lt;/code&gt;. A path with no such manifest above it is a program
without one, as before: a file being a &lt;a href=&quot;#programs-of-one-file&quot;&gt;program of one file&lt;/a&gt;, whose header
names its dependencies.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt;, &lt;code&gt;emit-llvm&lt;/code&gt; and &lt;code&gt;parse&lt;/code&gt; compile the whole package with its
dependencies. &lt;code&gt;avin build&lt;/code&gt; names the executable after the package. A package without &lt;code&gt;main&lt;/code&gt; is a
library: &lt;code&gt;avin check&lt;/code&gt; checks it, its tests included, and &lt;code&gt;avin run&lt;/code&gt; and &lt;code&gt;avin build&lt;/code&gt;, having no
&lt;code&gt;main&lt;/code&gt; to start from, refuse it.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin new &amp;lt;dir&amp;gt;&lt;/code&gt; writes a program package named by the directory’s last segment: its manifest,
whose &lt;code&gt;avin&lt;/code&gt; is the version of the Avin that wrote it, a module of that name (with &lt;code&gt;-&lt;/code&gt; written &lt;code&gt;_&lt;/code&gt;) holding one function, &lt;code&gt;main.avin&lt;/code&gt; using it, a test of it in
&lt;code&gt;tests/&lt;/code&gt;, and a &lt;code&gt;.gitignore&lt;/code&gt; naming the executable &lt;code&gt;avin build&lt;/code&gt; writes at the root (&lt;code&gt;/shapes&lt;/code&gt;) and
&lt;code&gt;.avin/&lt;/code&gt;. &lt;code&gt;avin new &amp;lt;dir&amp;gt; --lib&lt;/code&gt; writes a library, the same without &lt;code&gt;main.avin&lt;/code&gt;, its &lt;code&gt;.gitignore&lt;/code&gt;
naming &lt;code&gt;.avin/&lt;/code&gt; alone. It refuses a directory that exists and a name that is not a package’s.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin clean [&amp;lt;path&amp;gt;]&lt;/code&gt; removes the builds &lt;code&gt;avin run&lt;/code&gt; and &lt;code&gt;avin test&lt;/code&gt; keep for the package, which are
in the user’s cache directory, a directory per package and keyed by where the package is, so two
checkouts of it never share one (&lt;a href=&quot;/compiler/#running-and-testing&quot;&gt;running and testing&lt;/a&gt;).
&lt;code&gt;avin clean --all&lt;/code&gt; removes every program’s builds this version of Avin keeps; fetched packages stay.&lt;/li&gt;
&lt;li&gt;Fetched packages are not counted against the build cache’s limit and a sweep of the cache never
evicts one (&lt;a href=&quot;/compiler/#running-and-testing&quot;&gt;running and testing&lt;/a&gt;); &lt;code&gt;avin cache clean --packages&lt;/code&gt;
removes them, with &lt;code&gt;--older-than&lt;/code&gt; only those no build has read for that long, and the next build
that needs one fetches it again.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin add &amp;lt;coordinate&amp;gt;[@&amp;lt;version&amp;gt;|@&amp;lt;rev&amp;gt;] [&amp;lt;package&amp;gt;]&lt;/code&gt; adds a git dependency to the package’s
manifest: the version given, the commit given (written to the manifest as its full id), or the
highest release the repository has tagged. It fetches the package, lists
it under the name its own manifest gives it, and adds its hash to &lt;code&gt;avin.sum&lt;/code&gt;. Adding a dependency
already listed changes its version, to a lower one as well as a higher. A coordinate followed by
&lt;code&gt;//&lt;/code&gt; and a directory adds that &lt;a href=&quot;#members-of-a-repository&quot;&gt;member&lt;/a&gt;. The rest of the manifest,
comments and layout included, is left as written, and a dependency that cannot be fetched, is
not an Avin package, or needs a later Avin than the one running, itself or through a package it
depends on, changes nothing.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin tidy [--check] [&amp;lt;package&amp;gt;]&lt;/code&gt; rewrites &lt;code&gt;avin.sum&lt;/code&gt;, given a package, a path in one, or a
workspace’s root, which it tidies whole.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin vendor [&amp;lt;package&amp;gt;]&lt;/code&gt; copies what the project resolves to into its
&lt;a href=&quot;#vendoring&quot;&gt;&lt;code&gt;vendor/&lt;/code&gt;&lt;/a&gt;. It and &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; take the
&lt;a href=&quot;#on-the-command-line&quot;&gt;feature flags&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin doc [&amp;lt;package&amp;gt;]&lt;/code&gt; writes the package’s &lt;a href=&quot;/getting-started/#api-documentation&quot;&gt;API documentation&lt;/a&gt;,
its dependencies’ and the standard library’s modules it reads written beside its own so every
link stays inside the site, with every feature on.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin lsp&lt;/code&gt; analyzes a file in a package as the package, with its dependencies as the cache holds
them, and an &lt;code&gt;avin.hocon&lt;/code&gt; as a manifest, telling it what is wrong with it at its place.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>Operators and control flow</title>
    <link href="https://avinlang.dev/spec/operators-and-control-flow/"/>
    <id>https://avinlang.dev/spec/operators-and-control-flow/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Sysl&apos;s operator set and precedence, comparison chains, blocks that yield values, if, while, match and return.</summary>
    <content type="html">&lt;h2 id=&quot;operators&quot;&gt;Operators&lt;/h2&gt;
&lt;p&gt;Avin has Sysl’s operator set and precedence. Operators are trait methods (&lt;code&gt;+&lt;/code&gt; is &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt;,
&lt;code&gt;==&lt;/code&gt; is &lt;code&gt;Eq&lt;/code&gt;), so a generic needs the bound that supplies one, and a user type gains one through an
&lt;code&gt;impl&lt;/code&gt;. A data type or a class may also define the arithmetic and ordering operators as
&lt;a href=&quot;#operator-methods&quot;&gt;ordinary methods&lt;/a&gt;, with any operand and result types: &lt;code&gt;start + delay&lt;/code&gt; with an
&lt;code&gt;Instant&lt;/code&gt; and a &lt;code&gt;Duration&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Operator&lt;/th&gt;&lt;th&gt;Trait&lt;/th&gt;&lt;th&gt;Method&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+&lt;/code&gt; &lt;code&gt;-&lt;/code&gt; &lt;code&gt;*&lt;/code&gt; &lt;code&gt;/&lt;/code&gt; &lt;code&gt;%&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Add&lt;/code&gt; &lt;code&gt;Sub&lt;/code&gt; &lt;code&gt;Mul&lt;/code&gt; &lt;code&gt;Div&lt;/code&gt; &lt;code&gt;Rem&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;add&lt;/code&gt; &lt;code&gt;subtract&lt;/code&gt; &lt;code&gt;multiply&lt;/code&gt; &lt;code&gt;divide&lt;/code&gt; &lt;code&gt;remainder&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;unary &lt;code&gt;-&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Neg&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;negate&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;==&lt;/code&gt; &lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Eq&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;equals&lt;/code&gt;, and its negation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;lt;=&lt;/code&gt; &lt;code&gt;&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Ord&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;less&lt;/code&gt; &lt;code&gt;lessOrEqual&lt;/code&gt; &lt;code&gt;greater&lt;/code&gt; &lt;code&gt;greaterOrEqual&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Each method takes and yields the implementing type: &lt;code&gt;add(other: Self) -&amp;gt; Self&lt;/code&gt;. &lt;code&gt;Ord&lt;/code&gt; requires &lt;code&gt;Eq&lt;/code&gt;;
a type implements its &lt;code&gt;compare(other: Self) -&amp;gt; int&lt;/code&gt;, negative, zero or positive, and inherits the
four comparisons from it, implementing any of them as well where it can answer more directly. The
built-in types implement the traits their operators have, so &lt;code&gt;int&lt;/code&gt; is an &lt;code&gt;Add&lt;/code&gt; and an &lt;code&gt;Ord&lt;/code&gt;, and
&lt;code&gt;string&lt;/code&gt; is an &lt;code&gt;Add&lt;/code&gt; (joining) and an &lt;code&gt;Ord&lt;/code&gt;. Both operands of an operator reached through its trait
are of one type, with one conversion: an integer beside a value of a type that implements
&lt;code&gt;FromInteger&lt;/code&gt;, such as &lt;code&gt;BigInt&lt;/code&gt;, is converted to that type, on either side, so &lt;code&gt;big * i&lt;/code&gt;, &lt;code&gt;1 + big&lt;/code&gt;
and &lt;code&gt;big &amp;lt; n&lt;/code&gt; read as they would on integers (&lt;a href=&quot;/spec/types/#integers-meet-a-type-that-takes-them&quot;&gt;types&lt;/a&gt;). The wrapping, saturating and shift operators belong to the built-in types alone;
&lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;|&lt;/code&gt; are the integers’ and bytes’ bitwise operators, and on any other type the
&lt;a href=&quot;#methods-named-by-symbols&quot;&gt;methods&lt;/a&gt; of those names.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Add&lt;/code&gt; and &lt;code&gt;Mul&lt;/code&gt; also name their identities, as &lt;a href=&quot;/spec/declarations/#static-members&quot;&gt;static members&lt;/a&gt; of
the implementing type: &lt;code&gt;static zero() -&amp;gt; Self&lt;/code&gt;, which &lt;code&gt;add&lt;/code&gt; leaves a value unchanged by, and
&lt;code&gt;static one() -&amp;gt; Self&lt;/code&gt;, which &lt;code&gt;multiply&lt;/code&gt; does. Every implementation gives them: the integers’ are &lt;code&gt;0&lt;/code&gt;
and &lt;code&gt;1&lt;/code&gt; at each width but &lt;code&gt;i1&lt;/code&gt;, which holds 0 and -1 and has no &lt;code&gt;1&lt;/code&gt;: &lt;code&gt;i1.one()&lt;/code&gt; is a compile error, and
&lt;code&gt;one()&lt;/code&gt; reached at &lt;code&gt;i1&lt;/code&gt; through a generic traps; &lt;code&gt;real&lt;/code&gt;‘s &lt;code&gt;0.0&lt;/code&gt; and &lt;code&gt;1.0&lt;/code&gt;, and &lt;code&gt;string&lt;/code&gt;‘s &lt;code&gt;zero&lt;/code&gt; is the empty string. Generic
code reaches them through the bound:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;total[T: Add](items: Vector[T]) -&amp;gt; T
  var sum = T.zero()
  for x in items
    sum = sum + x
  sum

data Point(x: int, y: int)

impl Add for Point
  add(other: Point) -&amp;gt; Point = Point(x + other.x, y + other.y)
  static zero() -&amp;gt; Point = Point(0, 0)
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Family&lt;/th&gt;&lt;th&gt;Operators&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Arithmetic&lt;/td&gt;&lt;td&gt;unary &lt;code&gt;+&lt;/code&gt; &lt;code&gt;-&lt;/code&gt;; &lt;code&gt;+&lt;/code&gt; &lt;code&gt;-&lt;/code&gt; &lt;code&gt;*&lt;/code&gt; &lt;code&gt;/&lt;/code&gt; &lt;code&gt;%&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Explicit wrapping&lt;/td&gt;&lt;td&gt;&lt;code&gt;+%&lt;/code&gt; &lt;code&gt;-%&lt;/code&gt; &lt;code&gt;*%&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Explicit saturation&lt;/td&gt;&lt;td&gt;&lt;code&gt;+\|&lt;/code&gt; &lt;code&gt;-\|&lt;/code&gt; &lt;code&gt;*\|&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Bitwise&lt;/td&gt;&lt;td&gt;&lt;code&gt;~&lt;/code&gt; &lt;code&gt;&amp;amp;&lt;/code&gt; &lt;code&gt;^&lt;/code&gt; &lt;code&gt;\|&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Shifts&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; (shifts bind like multiplication)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Logical&lt;/td&gt;&lt;td&gt;&lt;code&gt;!&lt;/code&gt;, short-circuit &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; &lt;code&gt;\|\|&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Comparison&lt;/td&gt;&lt;td&gt;&lt;code&gt;==&lt;/code&gt; &lt;code&gt;!=&lt;/code&gt; &lt;code&gt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;lt;=&lt;/code&gt; &lt;code&gt;&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;gt;=&lt;/code&gt;, chained&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Identity&lt;/td&gt;&lt;td&gt;&lt;code&gt;===&lt;/code&gt; &lt;code&gt;!==&lt;/code&gt; (one side a reference type; see &lt;a href=&quot;/spec/equality-and-memory/#identity&quot;&gt;identity&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Range&lt;/td&gt;&lt;td&gt;&lt;code&gt;..&lt;/code&gt; &lt;code&gt;..&amp;lt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Cons&lt;/td&gt;&lt;td&gt;&lt;code&gt;::&lt;/code&gt;, prepending to a &lt;code&gt;List&lt;/code&gt; (right-associative)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Pattern test&lt;/td&gt;&lt;td&gt;&lt;code&gt;is&lt;/code&gt;, &lt;code&gt;is not&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Propagation&lt;/td&gt;&lt;td&gt;postfix &lt;code&gt;?&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Assignment&lt;/td&gt;&lt;td&gt;&lt;code&gt;=&lt;/code&gt; and compound forms (&lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;+%=&lt;/code&gt;, …)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Yielding assignment&lt;/td&gt;&lt;td&gt;&lt;code&gt;:=&lt;/code&gt; and compound forms, which return the stored value&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Update&lt;/td&gt;&lt;td&gt;prefix and postfix &lt;code&gt;++&lt;/code&gt; &lt;code&gt;--&lt;/code&gt;; prefix yields the new value, postfix the old&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Symbol methods&lt;/td&gt;&lt;td&gt;any other run of operator characters names a method, called infix at the level of its first character, or tightest when it has a &lt;code&gt;~&lt;/code&gt; in it: &lt;code&gt;xs ++ ys&lt;/code&gt;, &lt;code&gt;x +: xs&lt;/code&gt;, &lt;code&gt;a &amp;lt;~ b&lt;/code&gt;, &lt;code&gt;x #:: rest&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;An operator is the longest run of the characters &lt;code&gt;+ - * / % &amp;lt; &amp;gt; = ! &amp;amp; | ^ ~ : ? #&lt;/code&gt;, so a prefix
operator written directly after another operator needs a space: &lt;code&gt;a = -1&lt;/code&gt;, &lt;code&gt;x * -y&lt;/code&gt;. A run stops
before &lt;code&gt;//&lt;/code&gt;, which begins a comment. The range operators &lt;code&gt;..&lt;/code&gt; and &lt;code&gt;..&amp;lt;&lt;/code&gt; are spelled with dots, which
are not operator characters.&lt;/p&gt;
&lt;p&gt;Bitwise operators bind more tightly than comparisons: &lt;code&gt;x &amp;amp; mask == 0&lt;/code&gt; tests the masked value.
Within the bitwise family, &lt;code&gt;&amp;amp;&lt;/code&gt; binds tightest, then &lt;code&gt;^&lt;/code&gt;, then &lt;code&gt;|&lt;/code&gt;. Shifts bind at the multiplicative
level, so &lt;code&gt;1 + 2 &amp;lt;&amp;lt; 3&lt;/code&gt; is &lt;code&gt;17&lt;/code&gt;. A shift count at least as large as the width shifts everything out.
It is not masked.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;::&lt;/code&gt; binds more loosely than every arithmetic and bitwise operator and more tightly than ranges and
comparisons (the full table, with the methods named by symbols, is under
&lt;a href=&quot;#methods-named-by-symbols&quot;&gt;methods named by symbols&lt;/a&gt;), and it groups to the right: &lt;code&gt;n + 1 :: rest&lt;/code&gt; is &lt;code&gt;(n + 1) :: rest&lt;/code&gt;, and &lt;code&gt;1 :: 2 :: []&lt;/code&gt; is
&lt;code&gt;1 :: (2 :: [])&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Sysl’s pointer operators (prefix &lt;code&gt;*&lt;/code&gt; and &lt;code&gt;&amp;amp;&lt;/code&gt;) and &lt;code&gt;await&lt;/code&gt; are not part of Avin.&lt;/p&gt;
&lt;h3 id=&quot;infix-method-calls&quot;&gt;Infix method calls&lt;/h3&gt;
&lt;p&gt;Any method that takes one argument can be called as an infix operator, without the dot and the
parentheses: &lt;code&gt;a max b&lt;/code&gt; is &lt;code&gt;a.max(b)&lt;/code&gt;, and &lt;code&gt;xs zip ys&lt;/code&gt; is &lt;code&gt;xs.zip(ys)&lt;/code&gt;. The caller chooses the form;
the method’s author does not mark it. &lt;code&gt;a m (b, c)&lt;/code&gt; passes the tuple &lt;code&gt;(b, c)&lt;/code&gt; as the one argument.&lt;/p&gt;
&lt;p&gt;An infix call by a word groups to the left and binds more loosely than the arithmetic, bitwise,
shift, cons and range operators, and more tightly than comparisons, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; (a method
named by a symbol binds by &lt;a href=&quot;#methods-named-by-symbols&quot;&gt;its first character&lt;/a&gt;): &lt;code&gt;a max b + 1&lt;/code&gt; is
&lt;code&gt;a max (b + 1)&lt;/code&gt;, &lt;code&gt;a max b max c&lt;/code&gt; is &lt;code&gt;(a max b) max c&lt;/code&gt;, and &lt;code&gt;xs contains x &amp;amp;&amp;amp; ok&lt;/code&gt; is
&lt;code&gt;(xs contains x) &amp;amp;&amp;amp; ok&lt;/code&gt;. There is no postfix form: &lt;code&gt;xs size&lt;/code&gt; is an error, written &lt;code&gt;xs.size&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An infix call stays on one line. A line that ends with the method’s name continues it: the argument
is the indented block on the lines that follow.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val widest = current max
  measure(header) + padding
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A name that starts a line never continues the line above, inside brackets too: end the line with the
name instead. A method named by a symbol is an operator and may start a
&lt;a href=&quot;#continuation-lines&quot;&gt;continuation line&lt;/a&gt;. An indented block after a call is the call’s &lt;a href=&quot;#trailing-blocks&quot;&gt;trailing block&lt;/a&gt;, except
that one holding only a name and an operand is reported as this mistake.&lt;/p&gt;
&lt;p&gt;The call is resolved exactly as &lt;code&gt;a.m(b)&lt;/code&gt; is: overloads are chosen by the argument’s type, a trait or
&lt;code&gt;open&lt;/code&gt; method dispatches on the receiver’s class, an &lt;code&gt;impl&lt;/code&gt; adds methods that can be called this way,
and a generic method’s type arguments are inferred. The name must be a method of the receiver’s type
that can take one argument, which a method with a &lt;a href=&quot;/spec/declarations/#repeated-parameters&quot;&gt;repeated&lt;/a&gt;
last parameter can: &lt;code&gt;w surround &amp;quot;!&amp;quot;&lt;/code&gt; gives &lt;code&gt;surround(marks: string*)&lt;/code&gt; one mark. A field holding a
function is not called infix, and neither is a
function &lt;code&gt;m(a, b)&lt;/code&gt; declared outside the type: &lt;code&gt;a m b&lt;/code&gt; never means &lt;code&gt;m(a, b)&lt;/code&gt;. A method of two
parameters is not called infix even with a tuple after its name: &lt;code&gt;a put (1, 2)&lt;/code&gt; against
&lt;code&gt;put(i: int, j: int)&lt;/code&gt; is an error that says to write &lt;code&gt;a.put(1, 2)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A word that keeps its meaning after an operand, such as &lt;code&gt;then&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt; or
&lt;code&gt;match&lt;/code&gt;, is never read as a method’s name, so &lt;code&gt;if a max b then c&lt;/code&gt; and &lt;code&gt;n is int&lt;/code&gt; read as before.&lt;/p&gt;
&lt;h3 id=&quot;methods-named-by-symbols&quot;&gt;Methods named by symbols&lt;/h3&gt;
&lt;p&gt;A method may be named by a run of operator characters, declared like any other method in a class,
trait, object or impl, and called infix or dotted:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Bag(val items: Vector[int])
  ++(other: Bag) -&amp;gt; Bag = Bag(items ++ other.items)
  +:(x: int) -&amp;gt; Bag = Bag(x +: items)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;a ++ b&lt;/code&gt; is &lt;code&gt;a.++(b)&lt;/code&gt;, and &lt;code&gt;a.++(b)&lt;/code&gt; may be written as such. A function outside a type cannot be
named by a symbol. Some of the language’s own operators are not method names: declaring a method
named &lt;code&gt;==&lt;/code&gt; is an error that says to implement &lt;code&gt;Eq&lt;/code&gt;. The reserved spellings are the wrapping and
saturating &lt;code&gt;+%&lt;/code&gt; &lt;code&gt;-%&lt;/code&gt; &lt;code&gt;*%&lt;/code&gt; &lt;code&gt;+|&lt;/code&gt; &lt;code&gt;-|&lt;/code&gt; &lt;code&gt;*|&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt; &lt;code&gt;!=&lt;/code&gt; &lt;code&gt;===&lt;/code&gt; &lt;code&gt;!==&lt;/code&gt;, &lt;code&gt;::&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt; &lt;code&gt;:=&lt;/code&gt;
&lt;code&gt;:&lt;/code&gt; &lt;code&gt;?&lt;/code&gt; &lt;code&gt;-&amp;gt;&lt;/code&gt; &lt;code&gt;=&amp;gt;&lt;/code&gt;, and each yielding compound form such as &lt;code&gt;+:=&lt;/code&gt; and &lt;code&gt;&amp;lt;&amp;lt;:=&lt;/code&gt;. Every other run is
free, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;--&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; and the plain compound spellings &lt;code&gt;+=&lt;/code&gt; and &lt;code&gt;-=&lt;/code&gt; among them.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; between two operands, and the shifts &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, are free too, on every type
but the integers and bytes, whose bitwise and shift operators are the machine’s: a method of one of
these names on &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;byte&lt;/code&gt;, in an extension too, is an error. On any other type, &lt;code&gt;a | b&lt;/code&gt; calls
&lt;code&gt;a&lt;/code&gt;‘s method &lt;code&gt;|&lt;/code&gt; and &lt;code&gt;a &amp;gt;&amp;gt; b&lt;/code&gt; its method &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, each at its operator’s own level, so a parser
combinator (&lt;code&gt;p &amp;gt;&amp;gt; f&lt;/code&gt;), a set of flags, a stream or a query builder can be written with them. Prefix
&lt;code&gt;~&lt;/code&gt; stays the integers’ and bytes’ complement, and &lt;code&gt;~a&lt;/code&gt; on another type calls its method &lt;code&gt;~&lt;/code&gt; taking
no argument, an &lt;a href=&quot;#operator-methods&quot;&gt;operator method&lt;/a&gt;, and is an error where it has none.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Flags(bits: int)

impl Flags
  |(other: Flags) -&amp;gt; Flags = Flags(bits | other.bits)
  &amp;amp;(other: Flags) -&amp;gt; Flags = Flags(bits &amp;amp; other.bits)

val rw = Flags(1) | Flags(2)
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;operator-methods&quot;&gt;Operator methods&lt;/h4&gt;
&lt;p&gt;The arithmetic operators &lt;code&gt;+&lt;/code&gt; &lt;code&gt;-&lt;/code&gt; &lt;code&gt;*&lt;/code&gt; &lt;code&gt;/&lt;/code&gt; &lt;code&gt;%&lt;/code&gt; and the orderings &lt;code&gt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;lt;=&lt;/code&gt; &lt;code&gt;&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;gt;=&lt;/code&gt; are free method
names on a data type, a class or a trait, with any operand and result types, and overloaded by the
operand’s type like any method. &lt;code&gt;a + b&lt;/code&gt; calls &lt;code&gt;a&lt;/code&gt;‘s method &lt;code&gt;+&lt;/code&gt; where &lt;code&gt;a&lt;/code&gt;‘s type, or a type
parameter’s bound, has one taking one argument, at the built-in &lt;code&gt;+&lt;/code&gt;‘s own precedence, so
&lt;code&gt;a + b * k&lt;/code&gt; is &lt;code&gt;a + (b * k)&lt;/code&gt; whichever of them are methods:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Instant(epochMicros: long)

impl Instant
  +(d: Duration) -&amp;gt; Instant = Instant(epochMicros + d.micros)
  -(d: Duration) -&amp;gt; Instant = Instant(epochMicros - d.micros)
  -(earlier: Instant) -&amp;gt; Duration = Duration(epochMicros - earlier.epochMicros)

class Vec(val x: real, val y: real)
  *(k: real) -&amp;gt; Vec = Vec(x * k, y * k)
  *(other: Vec) -&amp;gt; real = x * other.x + y * other.y
  -() -&amp;gt; Vec = Vec(-x, -y)

val deadline = start + timeout
val waited = now - start
val scaled = v * 2.0
val flipped = -v
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A prefix &lt;code&gt;-a&lt;/code&gt; calls a method &lt;code&gt;-&lt;/code&gt; taking no argument, and so do the other prefix operators: &lt;code&gt;!a&lt;/code&gt; calls
a method &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;~a&lt;/code&gt; a method &lt;code&gt;~&lt;/code&gt; and &lt;code&gt;+a&lt;/code&gt; a method &lt;code&gt;+&lt;/code&gt;, each taking no argument and yielding whatever
it is declared to, at the prefix level, so &lt;code&gt;!a.b&lt;/code&gt; is &lt;code&gt;!(a.b)&lt;/code&gt; and &lt;code&gt;~a + b&lt;/code&gt; is &lt;code&gt;(~a) + b&lt;/code&gt;. A method
&lt;code&gt;!&lt;/code&gt; takes no argument at all, since &lt;code&gt;!&lt;/code&gt; has no binary form; &lt;code&gt;~&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; may also be overloaded with
one argument for &lt;code&gt;a ~ b&lt;/code&gt; and &lt;code&gt;a + b&lt;/code&gt;, which a prefix operator never calls. A query builder’s &lt;code&gt;!cond&lt;/code&gt;
builds the negated condition and a bit set’s &lt;code&gt;~bits&lt;/code&gt; its complement:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Cond(sql: string)

impl Cond
  !() -&amp;gt; Cond = Cond(s&amp;quot;NOT ($sql)&amp;quot;)

class Bits(val word: int)
  ~() -&amp;gt; Bits = Bits(~word &amp;amp; 255)
  +() -&amp;gt; int = word

trait Flip
  !() -&amp;gt; Self

twice[T: Flip](x: T) -&amp;gt; T = ! !x
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A trait may declare them, so a type parameter bounded by it has them, and a value of the trait
dispatches on its class. Two prefix operators written together are one name, so nested ones are
written apart: &lt;code&gt;! !x&lt;/code&gt;, &lt;code&gt;- ~x&lt;/code&gt;. In an &lt;code&gt;if&lt;/code&gt;, a &lt;code&gt;while&lt;/code&gt; or an operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;!a&lt;/code&gt; is a
condition only where it is a &lt;code&gt;bool&lt;/code&gt;: &lt;code&gt;if !stack&lt;/code&gt; reads where the method &lt;code&gt;!&lt;/code&gt; yields &lt;code&gt;bool&lt;/code&gt;, and is an
error where it yields a &lt;code&gt;Cond&lt;/code&gt;. A prefix &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt; on a type with no method of its name keeps
its own meaning, so it is an error on a data type or a class: &lt;code&gt;!&lt;/code&gt; needs a &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; an integer or a
byte, and &lt;code&gt;+&lt;/code&gt; a number. No core trait stands behind them, as &lt;code&gt;Neg&lt;/code&gt; stands behind &lt;code&gt;-&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Where a type has no method of an operator’s
name, the operator is its core trait’s, &lt;code&gt;Add&lt;/code&gt;‘s &lt;code&gt;add&lt;/code&gt; for &lt;code&gt;+&lt;/code&gt;, as it always is in generic code: a
type with both a method &lt;code&gt;+&lt;/code&gt; and an &lt;code&gt;impl Add&lt;/code&gt; has its method called by &lt;code&gt;a + b&lt;/code&gt; and &lt;code&gt;add&lt;/code&gt; called
by a function bounded by &lt;code&gt;Add&lt;/code&gt;. &lt;code&gt;a &amp;lt; b&lt;/code&gt; alone calls the method &lt;code&gt;&amp;lt;&lt;/code&gt;, whatever it yields, so a query
builder’s &lt;code&gt;age &amp;lt; 30&lt;/code&gt; can build a condition. A comparison by a method chains when it yields &lt;code&gt;bool&lt;/code&gt;:
&lt;code&gt;lo &amp;lt;= x &amp;lt; hi&lt;/code&gt; through methods &lt;code&gt;&amp;lt;=&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; is a &lt;a href=&quot;#comparison-chains&quot;&gt;comparison chain&lt;/a&gt;, and a link
whose method yields anything else makes the chain an error. &lt;code&gt;x += y&lt;/code&gt; and
the other compound forms assign through the method: &lt;code&gt;deadline += grace&lt;/code&gt; is
&lt;code&gt;deadline = deadline + grace&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The built-in types keep their operators: a method of one of these names on &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;,
&lt;code&gt;char&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; or a tuple, in an extension or a trait implementation, is an error, so &lt;code&gt;+&lt;/code&gt;
on two &lt;code&gt;int&lt;/code&gt;s is always the machine’s addition, and so is a method &lt;code&gt;!&lt;/code&gt;, or &lt;code&gt;~&lt;/code&gt; taking no argument,
there: &lt;code&gt;!&lt;/code&gt; on a &lt;code&gt;bool&lt;/code&gt; is always its negation. &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; stay &lt;code&gt;Eq&lt;/code&gt;‘s.&lt;/p&gt;
&lt;p&gt;One exception puts a built-in value on an operator’s left. An impl adding methods to &lt;code&gt;int&lt;/code&gt;,
&lt;code&gt;long&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt; or &lt;code&gt;bool&lt;/code&gt;, in the type’s module or as an extension, may add
a binary operator method, an arithmetic, ordering, bitwise or shift one, whose one parameter is of a
type the program declares: a data type, a class, a trait or an opaque type, of any type arguments.
Its operand is never built-in, so an operator between two built-in values still never reaches a
method. &lt;code&gt;k * v&lt;/code&gt; with &lt;code&gt;k&lt;/code&gt; a &lt;code&gt;real&lt;/code&gt; calls &lt;code&gt;real&lt;/code&gt;‘s method &lt;code&gt;*&lt;/code&gt; taking &lt;code&gt;v&lt;/code&gt;‘s type, chosen statically by
that type like any overload; where the left type has no method of the name the operator keeps its
own meaning. An integer literal on the left is an &lt;code&gt;int&lt;/code&gt; where &lt;code&gt;int&lt;/code&gt; has a method taking the right
operand, and otherwise the &lt;code&gt;long&lt;/code&gt;, then the &lt;code&gt;real&lt;/code&gt;, that has one, so &lt;code&gt;2 * v&lt;/code&gt; reads as it is written.
A trait implementation cannot add one, and a method of this kind taking a built-in type, a tuple, a
function, a union or a type parameter is an error. An extension’s is seen where its module is
imported, as every extension method is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Vec(x: real, y: real)

impl Vec
  *(k: real) -&amp;gt; Vec = Vec(x * k, y * k)

impl real
  *(v: Vec) -&amp;gt; Vec = v * self

val doubled = 2.0 * v
val tripled = 3 * v
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A symbol method’s call binds at the level of the language’s operator its name’s first character
belongs to, so a name reads with the operator it resembles, unless the method declares another
(&lt;a href=&quot;#a-declared-precedence&quot;&gt;below&lt;/a&gt;). One character overrides the first: a
name with &lt;code&gt;~&lt;/code&gt; anywhere in it binds at the tightest symbol level, so &lt;code&gt;~&lt;/code&gt;, &lt;code&gt;~&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;~&lt;/code&gt;, &lt;code&gt;&amp;lt;~&amp;gt;&lt;/code&gt;, &lt;code&gt;~!&lt;/code&gt; and
&lt;code&gt;^~&lt;/code&gt; all bind together, the way a grammar’s sequencing operators are read. A leading &lt;code&gt;#&lt;/code&gt; is passed
over, so a name starting with &lt;code&gt;#&lt;/code&gt; binds at the level of its first other character: &lt;code&gt;#::&lt;/code&gt; binds as
&lt;code&gt;::&lt;/code&gt; does and &lt;code&gt;#+&lt;/code&gt; as &lt;code&gt;+&lt;/code&gt;. A name of &lt;code&gt;#&lt;/code&gt; alone, &lt;code&gt;##&lt;/code&gt;, binds at the tightest symbol level, and a
single &lt;code&gt;#&lt;/code&gt; is no operator. The levels, tightest first:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Level&lt;/th&gt;&lt;th&gt;Operators&lt;/th&gt;&lt;th&gt;Symbol methods whose name starts with&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Prefix&lt;/td&gt;&lt;td&gt;unary &lt;code&gt;-&lt;/code&gt; &lt;code&gt;+&lt;/code&gt; &lt;code&gt;!&lt;/code&gt; &lt;code&gt;~&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Other symbols&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;~&lt;/code&gt; &lt;code&gt;?&lt;/code&gt;, and any character no lower level takes: &lt;code&gt;~&amp;gt;&lt;/code&gt;, &lt;code&gt;??&lt;/code&gt;; and every name with a &lt;code&gt;~&lt;/code&gt; in it: &lt;code&gt;&amp;lt;~&lt;/code&gt;, &lt;code&gt;^~&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Multiplicative&lt;/td&gt;&lt;td&gt;&lt;code&gt;*&lt;/code&gt; &lt;code&gt;/&lt;/code&gt; &lt;code&gt;%&lt;/code&gt; &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; &lt;code&gt;*%&lt;/code&gt; &lt;code&gt;*\|&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;*&lt;/code&gt; &lt;code&gt;/&lt;/code&gt; &lt;code&gt;%&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;: &lt;code&gt;*:&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Additive&lt;/td&gt;&lt;td&gt;&lt;code&gt;+&lt;/code&gt; &lt;code&gt;-&lt;/code&gt; &lt;code&gt;+%&lt;/code&gt; &lt;code&gt;-%&lt;/code&gt; &lt;code&gt;+\|&lt;/code&gt; &lt;code&gt;-\|&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;+&lt;/code&gt; &lt;code&gt;-&lt;/code&gt;: &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;--&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Bitwise and&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;: &lt;code&gt;&amp;amp;&amp;amp;&amp;amp;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Bitwise exclusive or&lt;/td&gt;&lt;td&gt;&lt;code&gt;^&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;^&lt;/code&gt;: &lt;code&gt;^^&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Bitwise or&lt;/td&gt;&lt;td&gt;&lt;code&gt;\|&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;\|&lt;/code&gt;: &lt;code&gt;\|&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Cons&lt;/td&gt;&lt;td&gt;&lt;code&gt;::&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;:&lt;/code&gt;: &lt;code&gt;:+&lt;/code&gt;, &lt;code&gt;:::&lt;/code&gt;, &lt;code&gt;#::&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Range&lt;/td&gt;&lt;td&gt;&lt;code&gt;..&lt;/code&gt; &lt;code&gt;..&amp;lt;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Named calls&lt;/td&gt;&lt;td&gt;&lt;code&gt;a max b&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Comparison&lt;/td&gt;&lt;td&gt;&lt;code&gt;==&lt;/code&gt; &lt;code&gt;!=&lt;/code&gt; &lt;code&gt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;lt;=&lt;/code&gt; &lt;code&gt;&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;gt;=&lt;/code&gt; &lt;code&gt;===&lt;/code&gt; &lt;code&gt;!==&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; &lt;code&gt;&amp;gt;&lt;/code&gt; &lt;code&gt;=&lt;/code&gt; &lt;code&gt;!&lt;/code&gt;: &lt;code&gt;&amp;lt;=&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;, &lt;code&gt;!!&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Logical and&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;none; a method declared &lt;code&gt;@precedence(&amp;quot;&amp;amp;&amp;amp;&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Logical or&lt;/td&gt;&lt;td&gt;&lt;code&gt;\|\|&lt;/code&gt;&lt;/td&gt;&lt;td&gt;none; a method declared &lt;code&gt;@precedence(&amp;quot;\|\|&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Assignment&lt;/td&gt;&lt;td&gt;&lt;code&gt;=&lt;/code&gt; &lt;code&gt;:=&lt;/code&gt; and compound forms&lt;/td&gt;&lt;td&gt;a name ending in &lt;code&gt;=&lt;/code&gt; that is not a comparison: &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt;, &lt;code&gt;\|=&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;So &lt;code&gt;a ++ b + c&lt;/code&gt; is &lt;code&gt;(a ++ b) + c&lt;/code&gt;, &lt;code&gt;a ++ b * c&lt;/code&gt; is &lt;code&gt;a ++ (b * c)&lt;/code&gt;, &lt;code&gt;xs ++ ys :+ z&lt;/code&gt; is
&lt;code&gt;(xs ++ ys) :+ z&lt;/code&gt;, and &lt;code&gt;xs ++ ys == zs&lt;/code&gt; compares the joined sequence. A grammar written with
combinators reads as it would on paper: &lt;code&gt;a ~ b ^^ f | c ~ d&lt;/code&gt; is &lt;code&gt;((a ~ b) ^^ f) | (c ~ d)&lt;/code&gt;,
&lt;code&gt;&amp;quot;[&amp;quot; ~&amp;gt; items &amp;lt;~ &amp;quot;]&amp;quot; ^^ f&lt;/code&gt; is &lt;code&gt;((&amp;quot;[&amp;quot; ~&amp;gt; items) &amp;lt;~ &amp;quot;]&amp;quot;) ^^ f&lt;/code&gt;, and &lt;code&gt;a &amp;lt;~ b ~ c&lt;/code&gt; is &lt;code&gt;(a &amp;lt;~ b) ~ c&lt;/code&gt;.
A &lt;code&gt;~&lt;/code&gt; name ending in &lt;code&gt;=&lt;/code&gt; is still a compound assignment: &lt;code&gt;p ~= q&lt;/code&gt; is &lt;code&gt;p = p ~ q&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A symbol call groups to the left, except that a name ending in &lt;code&gt;:&lt;/code&gt; groups to the right and takes its
receiver on the right: &lt;code&gt;x +: xs&lt;/code&gt; is &lt;code&gt;xs.+:(x)&lt;/code&gt;, and &lt;code&gt;a +: b +: xs&lt;/code&gt; is &lt;code&gt;a +: (b +: xs)&lt;/code&gt;. The operands
are still evaluated in the order written, &lt;code&gt;x&lt;/code&gt; before &lt;code&gt;xs&lt;/code&gt;. Operators of one level that group in
opposite directions, whether symbol methods or the language’s own, do not mix without parentheses:
&lt;code&gt;a ++ b +: c&lt;/code&gt;, &lt;code&gt;a + b +: c&lt;/code&gt; and &lt;code&gt;1 :: xs :+ 2&lt;/code&gt; are errors, and &lt;code&gt;(a ++ b) :+ c&lt;/code&gt; and &lt;code&gt;1 :: (xs :+ 2)&lt;/code&gt;
are not. Operators of different levels need none: &lt;code&gt;1 +: xs :+ 2&lt;/code&gt; is &lt;code&gt;(1 +: xs) :+ 2&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&quot;a-declared-precedence&quot;&gt;A declared precedence&lt;/h4&gt;
&lt;p&gt;A method named by a symbol may declare the level its calls bind at, by naming the language’s
operator of that level in &lt;code&gt;@precedence&lt;/code&gt;, and that its calls group to the right with &lt;code&gt;@groupsRight&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Parser(val name: string)
  ~(next: Parser) -&amp;gt; Parser = Parser(s&amp;quot;$name ~ ${next.name}&amp;quot;)
  @precedence(&amp;quot;|&amp;quot;)
  &amp;lt;|&amp;gt;(other: Parser) -&amp;gt; Parser = Parser(s&amp;quot;$name | ${other.name}&amp;quot;)

class Num(val n: int)
  @groupsRight
  ^^(e: Num) -&amp;gt; Num = Num(power(n, e.n))

data Cond(sql: string)

class Column(val name: string)
  &amp;gt;=(v: int) -&amp;gt; Cond = Cond(s&amp;quot;$name &amp;gt;= $v&amp;quot;)

class Rows(val sql: string)
  @precedence(&amp;quot;||&amp;quot;)
  |&amp;gt;(c: Cond) -&amp;gt; Rows = Rows(s&amp;quot;$sql WHERE ${c.sql}&amp;quot;)

val p = a ~ b &amp;lt;|&amp;gt; c ~ d             // (a ~ b) &amp;lt;|&amp;gt; (c ~ d), where `&amp;lt;|&amp;gt;` would bind as `&amp;lt;` does
val big = two ^^ three ^^ two       // two ^^ (three ^^ two)
val adults = people |&amp;gt; age &amp;gt;= 18    // people |&amp;gt; (age &amp;gt;= 18)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The level is one row of the table, named by any operator of it: &lt;code&gt;&amp;quot;~&amp;quot;&lt;/code&gt; for the tightest symbol
level, &lt;code&gt;&amp;quot;*&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;+&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;&amp;amp;&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;^&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;|&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;::&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;==&amp;quot;&lt;/code&gt;, and the two only a declaration reaches,
&lt;code&gt;&amp;quot;&amp;amp;&amp;amp;&amp;quot;&lt;/code&gt; and &lt;code&gt;&amp;quot;||&amp;quot;&lt;/code&gt;; &lt;code&gt;&amp;quot;-&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;&amp;lt;&amp;lt;&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;!=&amp;quot;&lt;/code&gt; name their rows as well. No level is added, so the table
stays the whole account of how an expression reads, and a declared call binds exactly as the
operator its declaration names does. A range, an assignment or the named-call level is not one a
method may take. &lt;code&gt;@groupsRight&lt;/code&gt; keeps the receiver on the left, &lt;code&gt;a ^^ b ^^ c&lt;/code&gt; being
&lt;code&gt;a.^^(b.^^(c))&lt;/code&gt;; only a name ending in &lt;code&gt;:&lt;/code&gt; takes its receiver on the right. A name ending in &lt;code&gt;:&lt;/code&gt;
groups right already, and &lt;code&gt;@groupsRight&lt;/code&gt; on one is an error; &lt;code&gt;@precedence&lt;/code&gt; on one moves its level
and keeps its grouping. A declared grouping follows the rule against mixing: &lt;code&gt;a ^^ b ^ c&lt;/code&gt; is an
error, as is &lt;code&gt;a &amp;lt;=&amp;lt; b &amp;lt; c&lt;/code&gt; where &lt;code&gt;&amp;lt;=&amp;lt;&lt;/code&gt; is declared at &lt;code&gt;&amp;quot;==&amp;quot;&lt;/code&gt; grouping right.&lt;/p&gt;
&lt;p&gt;A declaration belongs to the method’s &lt;strong&gt;name&lt;/strong&gt;, across the whole program, because a program is
parsed before any type is known: &lt;code&gt;a &amp;lt;|&amp;gt; b&lt;/code&gt; is read the same way whatever &lt;code&gt;a&lt;/code&gt; turns out to be, in
the declaring module, in every module that imports it, and in any module holding a value of the
type without naming it. So every method of one name in a program binds alike. An overload, another
type’s method, a trait’s declaration and each of its implementations either carry the same
declaration or one that reads the same, and a method of the name declaring nothing agrees only
where the declaration restates what the name gives. Any other is an error naming both methods,
reported at the program’s method where the other is the standard library’s: a program cannot
declare &lt;code&gt;:+&lt;/code&gt; at &lt;code&gt;*&lt;/code&gt;‘s level, since the library’s sequences already read it as &lt;code&gt;::&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Only a method named by a symbol the language does not use may declare: &lt;code&gt;@precedence&lt;/code&gt; on &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;,
&lt;code&gt;&amp;lt;&lt;/code&gt; or &lt;code&gt;==&lt;/code&gt;, which keep their levels, on an assignment such as &lt;code&gt;++=&lt;/code&gt;, on a method named by a word,
which binds as every named call does, and on a function is an error.&lt;/p&gt;
&lt;h4 id=&quot;a-right-operand-taken-by-name&quot;&gt;A right operand taken by name&lt;/h4&gt;
&lt;p&gt;A companion object may declare an operator whose name ends in &lt;code&gt;:&lt;/code&gt; as a function of two parameters,
the left operand and then the right, with the right &lt;a href=&quot;/spec/by-name/&quot;&gt;by name&lt;/a&gt;. Then &lt;code&gt;x op: r&lt;/code&gt;, where
&lt;code&gt;r&lt;/code&gt;‘s type is the companion’s class or data type, calls the companion’s &lt;code&gt;op:(x, r)&lt;/code&gt;: &lt;code&gt;x&lt;/code&gt; is evaluated
where it is written and &lt;code&gt;r&lt;/code&gt; is passed unevaluated, as any by-name argument is. The library’s lazy
list is built this way, so &lt;code&gt;0 #:: 1 #:: rest&lt;/code&gt; evaluates &lt;code&gt;rest&lt;/code&gt; only when the list’s third cell is
read:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Chain(val label: string, private val after: () -&amp;gt; Chain)
  next() -&amp;gt; Chain = after()

object Chain
  #::(label: string, rest: -&amp;gt; Chain) -&amp;gt; Chain = Chain(label, () -&amp;gt; rest)

endless(n: int) -&amp;gt; Chain = s&amp;quot;c$n&amp;quot; #:: endless(n + 1) // returns; each next() makes one more
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The right operand’s type decides&lt;/strong&gt;, and it is known without evaluating it: where that type’s
companion declares such an &lt;code&gt;op:&lt;/code&gt;, it is called, and it may be called dotted too,
&lt;code&gt;Chain.#::(&amp;quot;a&amp;quot;, rest)&lt;/code&gt;. A type with a method &lt;code&gt;op:&lt;/code&gt; of its own, or one from an impl, whose
companion also declares one, makes &lt;code&gt;x op: r&lt;/code&gt; an error naming both.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Wherever some companion declares &lt;code&gt;op:&lt;/code&gt; so, the right operand of every &lt;code&gt;x op: r&lt;/code&gt; is checked as a
delayed expression&lt;/strong&gt;, since its type is known only once it is checked. On a type whose &lt;code&gt;op:&lt;/code&gt; is an
ordinary method, the right operand is then evaluated once, at the call, after &lt;code&gt;x&lt;/code&gt;, as a strict
receiver is; a &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; leaving it is an error, as in any delayed
expression. Operators no companion declares so, &lt;code&gt;+:&lt;/code&gt; and &lt;code&gt;::&lt;/code&gt; among them, are unaffected.&lt;/li&gt;
&lt;li&gt;A companion’s &lt;code&gt;op:&lt;/code&gt; with a strict second parameter is not called infix; it is an ordinary function
of the object.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are no prefix or postfix symbol methods, beyond the &lt;a href=&quot;#operator-methods&quot;&gt;methods &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; and
&lt;code&gt;+&lt;/code&gt;&lt;/a&gt; taking no argument that the prefix operators call. &lt;code&gt;++&lt;/code&gt; and &lt;code&gt;--&lt;/code&gt; keep their update meaning when no
operand follows them on the line: &lt;code&gt;i++&lt;/code&gt; and &lt;code&gt;++i&lt;/code&gt; update &lt;code&gt;i&lt;/code&gt;, and &lt;code&gt;xs ++ ys&lt;/code&gt; calls &lt;code&gt;++&lt;/code&gt;. An operand
here is a name, a literal or an opening bracket on the same line, or an indented block on the next;
so &lt;code&gt;a ++ -b&lt;/code&gt;, with a prefix operator after &lt;code&gt;++&lt;/code&gt;, is &lt;code&gt;(a++) - b&lt;/code&gt;, written &lt;code&gt;a ++ (-b)&lt;/code&gt; to join.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;x op= y&lt;/code&gt; calls &lt;code&gt;x&lt;/code&gt;‘s method named &lt;code&gt;op=&lt;/code&gt; when the type of &lt;code&gt;x&lt;/code&gt; has one: &lt;code&gt;buffer += 3&lt;/code&gt; appends, and
the buffer need not be a &lt;code&gt;var&lt;/code&gt;. Otherwise &lt;code&gt;op=&lt;/code&gt; assigns. Where &lt;code&gt;op&lt;/code&gt; is one of the language’s
arithmetic, wrapping, saturating, shift or bitwise operators, it is the compound assignment it has
always been; where &lt;code&gt;op&lt;/code&gt; is a symbol method, or &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; or an
&lt;a href=&quot;#operator-methods&quot;&gt;operator method&lt;/a&gt; on a type that has a method of that name, &lt;code&gt;x op= y&lt;/code&gt; is
&lt;code&gt;x = x op y&lt;/code&gt;, so &lt;code&gt;flags |= Flags(4)&lt;/code&gt; combines flags into a &lt;code&gt;var&lt;/code&gt;, and &lt;code&gt;xs ++= ys&lt;/code&gt; joins onto a
&lt;code&gt;var&lt;/code&gt; vector and &lt;code&gt;xs :+= 4&lt;/code&gt; appends to it. The target is a &lt;code&gt;var&lt;/code&gt; local, a &lt;code&gt;var&lt;/code&gt; field, a module
value or an element &lt;code&gt;xs(i)&lt;/code&gt;, and its object and indices are evaluated once. A right-grouping name
has no compound form, and the yielding forms (&lt;code&gt;+:=&lt;/code&gt;) belong to the language’s operators alone. A
multiple assignment uses only the language’s compound forms.&lt;/p&gt;
&lt;h3 id=&quot;continuation-lines&quot;&gt;Continuation lines&lt;/h3&gt;
&lt;p&gt;A line that starts with a binary operator or a member’s &lt;code&gt;.&lt;/code&gt;, indented deeper than the line above
it, continues the expression that line left open:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val atom = number
  | symbol(&amp;quot;(&amp;quot;) ~&amp;gt; later(expr) &amp;lt;~ symbol(&amp;quot;)&amp;quot;)
  | ident ^^ Var

val total = a
  + b * c
  - d

val names = people
  .filter(_.age &amp;gt;= 18)
  .map(_.name)
  .sorted
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The line break means nothing to precedence: the operators group exactly as they would on one line,
so &lt;code&gt;total&lt;/code&gt; is &lt;code&gt;(a + (b * c)) - d&lt;/code&gt;, &lt;code&gt;atom&lt;/code&gt; has three alternatives, and &lt;code&gt;a + b&lt;/code&gt; with &lt;code&gt;* c&lt;/code&gt; on the
next line is &lt;code&gt;a + (b * c)&lt;/code&gt;. A comparison chain goes on across the lines too. A &lt;code&gt;.&lt;/code&gt; binds as it does
on one line, to the operand right before it, so &lt;code&gt;names&lt;/code&gt; is &lt;code&gt;people.filter(…).map(…).sorted&lt;/code&gt;, and
&lt;code&gt;a + b&lt;/code&gt; with &lt;code&gt;.toString&lt;/code&gt; on the next line is &lt;code&gt;a + b.toString&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;What starts one.&lt;/strong&gt; Every operator that stands between two operands: the arithmetic, wrapping,
saturating, shift, bitwise, comparison, logical, range and cons operators, a method named by a
symbol, &lt;code&gt;~&lt;/code&gt;, and &lt;code&gt;++&lt;/code&gt; or &lt;code&gt;--&lt;/code&gt; with an operand after it. &lt;code&gt;-&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; there are binary, written
&lt;code&gt;- d&lt;/code&gt; or &lt;code&gt;-d&lt;/code&gt;. And the &lt;code&gt;.&lt;/code&gt; of a member, a method call or a field read, after which the line goes
on as any line does: with &lt;code&gt;?&lt;/code&gt; (&lt;code&gt;.get(&amp;quot;a&amp;quot;)?&lt;/code&gt;), more members, calls and operators. A word never
starts one (a named infix call ends its line instead, as &lt;a href=&quot;#infix-method-calls&quot;&gt;above&lt;/a&gt;), and
neither do &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, a bracket, &lt;code&gt;=&lt;/code&gt; and the compound assignments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Where.&lt;/strong&gt; Wherever an expression ends a line and has a complete operand: a binding’s value, an
assignment, a &lt;code&gt;return&lt;/code&gt; value, a call’s argument, a &lt;code&gt;match&lt;/code&gt; arm’s or a lambda’s body, a branch of a
one-line &lt;code&gt;if&lt;/code&gt;, an expression statement.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How far.&lt;/strong&gt; Each following line that starts with such an operator or a &lt;code&gt;.&lt;/code&gt; and is still deeper than the
line the expression began on continues it, at the depth of a continuation line above it or deeper
(indentation that matches no line above is an error, as in any block); the depth means nothing
beyond that. The expression ends at the first line back at the depth it began
on, or shallower, so a &lt;code&gt;.&lt;/code&gt; line at the depth the expression began on is a new statement and an
error. A line inside the continuation that does not start with an operator or a &lt;code&gt;.&lt;/code&gt; is an error,
except a call’s trailing block or an infix call’s argument, indented under its own line as usual.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blank lines and comments&lt;/strong&gt; between continuation lines are skipped, as they are everywhere.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Not after a header.&lt;/strong&gt; The indented lines after the test of &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; and
&lt;code&gt;do … while&lt;/code&gt;, a &lt;code&gt;for&lt;/code&gt; source and a class’s parents are the form’s body. There, and wherever else
an indented block follows a word or a symbol that is not a complete operand (&lt;code&gt;=&lt;/code&gt;, &lt;code&gt;-&amp;gt;&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;,
&lt;code&gt;do&lt;/code&gt;, &lt;code&gt;then&lt;/code&gt;, a declaration’s signature), a line that starts with &lt;code&gt;-x&lt;/code&gt; is a block’s line:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;negate(x: int) -&amp;gt; int
  -x

sign(x: int) -&amp;gt; int
  if x &amp;lt; 0
    -1
  else
    1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inside brackets a line break is not significant, so a line in a call’s arguments may start with any
operator at any depth, a method named by a symbol included. A block opened inside the brackets, a
lambda’s body, starts its own lines again, where a comma list is a tuple, until its last line: a
line that closes a bracket opened before the block ends the block at its first comma, and the
items after that comma are the bracket’s own. So &lt;code&gt;spawn(() -&amp;gt;&lt;/code&gt; … &lt;code&gt;a + f(n), 67108864)&lt;/code&gt; passes the
lambda yielding &lt;code&gt;a + f(n)&lt;/code&gt; and &lt;code&gt;67108864&lt;/code&gt;, as &lt;code&gt;spawn(() -&amp;gt; a + f(n), 67108864)&lt;/code&gt; does; a tuple the
block yields there is written in parentheses, &lt;code&gt;(a, b))&lt;/code&gt;, and a closing bracket on a line of its own
leaves the line above a tuple. Blocks nested in the same brackets, an &lt;code&gt;if&lt;/code&gt;‘s, a &lt;code&gt;match&lt;/code&gt;‘s or an
inner lambda’s, all end at that comma.&lt;/p&gt;
&lt;h3 id=&quot;trailing-blocks&quot;&gt;Trailing blocks&lt;/h3&gt;
&lt;p&gt;An indented block on the lines after a call is the call’s last argument. The call’s line ends right
after its &lt;code&gt;)&lt;/code&gt;, and the block is given to the callee’s &lt;strong&gt;last parameter&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;retry(3)
  fetch(url)

withFile(&amp;quot;data.txt&amp;quot;) f -&amp;gt;
  process(f)

zipWith(xs, ys) (x, y) -&amp;gt;
  x * y
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;a href=&quot;/spec/by-name/&quot;&gt;by-name&lt;/a&gt; parameter (&lt;code&gt;body: -&amp;gt; T&lt;/code&gt;) takes the block as its delayed expression,
evaluated at each read of the parameter and not at the call, so &lt;code&gt;retry(3)&lt;/code&gt; runs &lt;code&gt;fetch(url)&lt;/code&gt; as many
times as &lt;code&gt;retry&lt;/code&gt; reads &lt;code&gt;body&lt;/code&gt;. A function parameter takes a lambda whose body is the block: its
parameters end the call’s line before &lt;code&gt;-&amp;gt;&lt;/code&gt;, one name (&lt;code&gt;f -&amp;gt;&lt;/code&gt;) or a parenthesized list
(&lt;code&gt;(x, y) -&amp;gt;&lt;/code&gt;, &lt;code&gt;(x: int) -&amp;gt;&lt;/code&gt;), as an ordinary lambda’s would be written.&lt;/p&gt;
&lt;p&gt;A callee with no other arguments is written without parentheses: a name, a member or a type
application, then the block, or one parameter name and &lt;code&gt;-&amp;gt;&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;scope s -&amp;gt;
  s.spawn
    part(1)

xs.foreach x -&amp;gt;
  println(x)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A lambda of several parameters needs the call’s parentheses before it, &lt;code&gt;run() (x, y) -&amp;gt;&lt;/code&gt;: the
parentheses right after a callee’s name always hold its arguments.&lt;/p&gt;
&lt;p&gt;The block’s position does not depend on the written arguments. With parentheses it comes after them,
and it still goes to the last parameter, past any defaulted one in between: against
&lt;code&gt;labelled(label: string, width: int = 4, body: -&amp;gt; string)&lt;/code&gt;, &lt;code&gt;labelled(&amp;quot;box&amp;quot;)&lt;/code&gt; and a block gives
&lt;code&gt;width&lt;/code&gt; its default. Positional and named arguments bind as they would without the block, and
overloads are chosen with it: a candidate whose last parameter cannot take a block does not fit.&lt;/p&gt;
&lt;p&gt;A trailing block applies wherever an expression ends a line: a statement, a binding’s value
(&lt;code&gt;val r = retry(3)&lt;/code&gt; and a block), an assignment, a &lt;code&gt;return&lt;/code&gt; value, a lambda’s or a &lt;code&gt;match&lt;/code&gt; arm’s
body, the argument of an infix call, the operand of an operator. Inside brackets a line break is
not significant, so a call written inside another call’s parentheses takes no block. The forms that
already put an indented block after their line keep it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The test of &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; and &lt;code&gt;do … while&lt;/code&gt;, a &lt;code&gt;for&lt;/code&gt; source and its &lt;code&gt;if&lt;/code&gt; guards, and a
class’s or object’s parents: the block is the form’s body, so &lt;code&gt;if ready(x)&lt;/code&gt; and a block tests
&lt;code&gt;ready(x)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A local function’s header: &lt;code&gt;helper()&lt;/code&gt; or &lt;code&gt;helper(n: int)&lt;/code&gt; and an indented block declare a local
function. A header’s parameters are typed, so &lt;code&gt;retry(3)&lt;/code&gt; and &lt;code&gt;retry(n)&lt;/code&gt; are calls. A call with
no arguments and a block is written without parentheses.&lt;/li&gt;
&lt;li&gt;A line that ends with an infix call’s method name, &lt;code&gt;current max&lt;/code&gt;: the block is its argument.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x match&lt;/code&gt; and the bare &lt;code&gt;match&lt;/code&gt; function: the block holds the arms.&lt;/li&gt;
&lt;li&gt;A block whose one line is a name and a single operand, &lt;code&gt;add 2&lt;/code&gt;, reads as the method and argument
of an infix call that should have ended the line above, and is reported as that.&lt;/li&gt;
&lt;li&gt;A block whose first line starts with a binary operator is a
&lt;a href=&quot;#continuation-lines&quot;&gt;continuation line&lt;/a&gt;: &lt;code&gt;f(1)&lt;/code&gt; and &lt;code&gt;    - x&lt;/code&gt; is &lt;code&gt;f(1) - x&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is an error to write a trailing block for a call whose last parameter is neither by-name nor a
function (the message names the parameter and its type), whose last parameter is already given, or
whose callee takes no arguments. A lambda on the call’s own line, &lt;code&gt;f(1) x -&amp;gt; x&lt;/code&gt;, is not a trailing
form; it is written inside the parentheses.&lt;/p&gt;
&lt;h2 id=&quot;comparison-chains&quot;&gt;Comparison chains&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;a &amp;lt; b &amp;lt;= c&lt;/code&gt; is one expression. Operands are evaluated left to right, each middle operand exactly
once, and evaluation stops at the first failing link. Parenthesizing a comparison makes it an
ordinary &lt;code&gt;bool&lt;/code&gt; operand: &lt;code&gt;(a &amp;lt; b) == flag&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A link may call its left operand’s &lt;a href=&quot;#methods-named-by-symbols&quot;&gt;operator method&lt;/a&gt; &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt; or
&lt;code&gt;&amp;gt;=&lt;/code&gt;, and links of methods mix with built-in links, &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; among them. Each link chooses its
own method among the overloads, by its two operands, so &lt;code&gt;start &amp;lt; t &amp;lt;= limit&lt;/code&gt; may call
&lt;code&gt;Instant &amp;lt; Instant&lt;/code&gt; and then &lt;code&gt;Instant &amp;lt;= Duration&lt;/code&gt;. A chain is allowed when every link yields
&lt;code&gt;bool&lt;/code&gt;; a link whose method yields anything else, as a query builder’s &lt;code&gt;age &amp;lt; 30&lt;/code&gt; yielding a
condition, makes the chain an error that names the link, its method and the type it yields, and says
to join the comparisons with &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or to parenthesize one. The same comparison alone yields whatever
its method yields.&lt;/p&gt;
&lt;h2 id=&quot;blocks&quot;&gt;Blocks&lt;/h2&gt;
&lt;p&gt;A block yields its last expression. &lt;code&gt;val&lt;/code&gt; bindings are immutable and &lt;code&gt;var&lt;/code&gt; bindings mutable; both are
scoped to their block. A block whose last item is a declaration yields &lt;code&gt;unit&lt;/code&gt;. In statement position a
value is discarded, and the branches of an unused &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; need not agree on a type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;answer() -&amp;gt; int
  val result =
    val base = 21
    base * 2
  result
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A binding may take a value apart by a pattern that cannot fail: &lt;code&gt;val q, r = divmod(17, 5)&lt;/code&gt;, or
&lt;code&gt;var (lo, hi) = 0, 10&lt;/code&gt;, in which every name is a &lt;code&gt;var&lt;/code&gt;. A pattern that could fail, such as a literal
or a variant of a type with several, belongs in a &lt;code&gt;match&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;multiple-assignment&quot;&gt;Multiple assignment&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;a, b = b, a&lt;/code&gt; assigns several places at once. The whole right side is made before any place changes,
so this swaps &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; with no temporary. The right side is a tuple, written out or computed
(&lt;code&gt;q, r = divmod(n, 10)&lt;/code&gt;), with one part per place; a place &lt;code&gt;_&lt;/code&gt; discards its part. The places may be
parenthesized: &lt;code&gt;(a, b) = (b, a)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A place is a &lt;code&gt;var&lt;/code&gt; local or a &lt;code&gt;var&lt;/code&gt; field, written &lt;code&gt;obj.field&lt;/code&gt;, &lt;code&gt;self.field&lt;/code&gt;, or by its bare name
inside its class: &lt;code&gt;self.lo, self.hi = hi, lo&lt;/code&gt;, or a module-level &lt;code&gt;var&lt;/code&gt;, by its bare name or another
module’s through that module’s name: &lt;code&gt;low, store.high = high, low&lt;/code&gt;. The object a field belongs to is evaluated first, left
to right across the places, before anything else; then the right side is made, then every place is
stored.&lt;/p&gt;
&lt;p&gt;The compound forms read every place first, then make the right side, then combine and store:
&lt;code&gt;a, b += b, a&lt;/code&gt; adds each to the other using the values the statement started with.&lt;/p&gt;
&lt;p&gt;A multiple assignment is a statement, not an expression: it has no &lt;code&gt;:=&lt;/code&gt; form, and it fills a whole
line, so it is not the body of a one-line &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;while&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;extendedGcd(a: int, b: int) -&amp;gt; (int, int, int)
  var r0, r1 = a, b
  var s0, s1 = 1, 0
  var t0, t1 = 0, 1
  while r1 != 0
    val q = r0 / r1
    r0, r1 = r1, r0 - q * r1
    s0, s1 = s1, s0 - q * s1
    t0, t1 = t1, t0 - q * t1
  r0, s0, t0
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;if&quot;&gt;if&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;label(n: int) -&amp;gt; string
  if n &amp;lt; 0 then &amp;quot;negative&amp;quot;
  elif n == 0 then &amp;quot;zero&amp;quot;
  else &amp;quot;positive&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A one-line branch needs &lt;code&gt;then&lt;/code&gt;; an indented branch may omit it. The condition must be a &lt;code&gt;bool&lt;/code&gt;.
Without an &lt;code&gt;else&lt;/code&gt;, an &lt;code&gt;if&lt;/code&gt; yields &lt;code&gt;unit&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;while&quot;&gt;while&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val found = while n &amp;lt; 10 do
  n += 1
  if n == 5 then break n
else -1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The condition is tested before each iteration, and &lt;code&gt;continue&lt;/code&gt; returns to that test. &lt;code&gt;break&lt;/code&gt; exits the
nearest loop and may carry a value, in which case every &lt;code&gt;break&lt;/code&gt; value and the loop’s &lt;code&gt;else&lt;/code&gt; must
agree. The &lt;code&gt;else&lt;/code&gt; runs on normal completion. Without an &lt;code&gt;else&lt;/code&gt;, normal completion yields &lt;code&gt;unit&lt;/code&gt;.
A &lt;code&gt;while true&lt;/code&gt; loop that no &lt;code&gt;break&lt;/code&gt; leaves never finishes, so its type is &lt;code&gt;Nothing&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;loop&quot;&gt;loop&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;var k = 0

val found = loop
  k += 5
  if k &amp;gt; 12 then break k * 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;loop&lt;/code&gt; repeats its body until a &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;return&lt;/code&gt; leaves it; &lt;code&gt;continue&lt;/code&gt; starts the body again. A
one-line loop is written &lt;code&gt;loop do step()&lt;/code&gt;. Only a &lt;code&gt;break&lt;/code&gt; ends a &lt;code&gt;loop&lt;/code&gt;, so there is no &lt;code&gt;else&lt;/code&gt;: with
&lt;code&gt;break value&lt;/code&gt;, every &lt;code&gt;break&lt;/code&gt; value must agree and is the value of the loop, and a &lt;code&gt;break&lt;/code&gt; without
one makes the loop &lt;code&gt;unit&lt;/code&gt;. A &lt;code&gt;loop&lt;/code&gt; that no &lt;code&gt;break&lt;/code&gt; leaves never finishes, so its type is
&lt;code&gt;Nothing&lt;/code&gt;, and a function may end in one. &lt;code&gt;loop&lt;/code&gt; is a keyword and cannot be used as a name.&lt;/p&gt;
&lt;h2 id=&quot;do-while&quot;&gt;do … while&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;digits(n: int) -&amp;gt; string
    var rest = n
    var s = &amp;quot;&amp;quot;

    do
        s = s&amp;quot;${rest % 10}&amp;quot; + s
        rest /= 10
    while rest &amp;gt; 0

    s

var i = 0
do i += 1 while i &amp;lt; 4
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The test comes at the end, so the body runs at least once. The body is an indented block with
&lt;code&gt;while test&lt;/code&gt; on the line that closes it, or a single statement on one line. The value rules are
&lt;code&gt;while&lt;/code&gt;‘s: a &lt;code&gt;break&lt;/code&gt; carries the loop’s value, and an &lt;code&gt;else&lt;/code&gt; after the test runs when the test fails,
so every &lt;code&gt;break&lt;/code&gt; value and the &lt;code&gt;else&lt;/code&gt; must agree.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;continue&lt;/code&gt; runs the test, not the body again. The test cannot read names the body declared, since the
body’s scope has ended. A &lt;code&gt;do&lt;/code&gt; that starts a line always opens this form; the &lt;code&gt;do&lt;/code&gt; of a one-line
&lt;code&gt;while&lt;/code&gt; body follows its header, so the two never meet.&lt;/p&gt;
&lt;h2 id=&quot;match&quot;&gt;match&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;subject match&lt;/code&gt; is followed by indented &lt;code&gt;pattern -&amp;gt; body&lt;/code&gt; arms and an optional &lt;code&gt;else&lt;/code&gt;. It is an
expression, checked for exhaustiveness. An arm’s body written on its own line fills that line, so a
comma list there is a tuple without parentheses (&lt;code&gt;_ -&amp;gt; 0, 1&lt;/code&gt;). Inside brackets whose commas
separate items (call arguments, tuple and collection literals, a &lt;code&gt;with&lt;/code&gt; change) a comma after a
one-line arm’s body ends the arm, the &lt;code&gt;match&lt;/code&gt; and the item, as it ends a &lt;code&gt;return&lt;/code&gt; value: in
&lt;code&gt;f(x match&lt;/code&gt; … &lt;code&gt;_ -&amp;gt; 0, &amp;quot;a&amp;quot;)&lt;/code&gt; the &lt;code&gt;match&lt;/code&gt; is the first argument and &lt;code&gt;&amp;quot;a&amp;quot;&lt;/code&gt; the second, which may also
stand on the line after the arms. A tuple body there is written in parentheses, &lt;code&gt;_ -&amp;gt; (0, 1)&lt;/code&gt;; a
comma after an arm that more arms follow is an error that says so. An arm’s indented body is a
block and starts a line again, up to a last line that closes the brackets, which
&lt;a href=&quot;#continuation-lines&quot;&gt;ends at its comma&lt;/a&gt; as any block’s does. Patterns include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;literals, including negative numbers;&lt;/li&gt;
&lt;li&gt;inclusive and exclusive literal ranges (&lt;code&gt;&apos;a&apos;..&apos;z&apos;&lt;/code&gt;, &lt;code&gt;0..&amp;lt;10&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;comparison patterns, which bind the value to a name or &lt;code&gt;_&lt;/code&gt; beside one literal bound or between
two: &lt;code&gt;n &amp;lt; 0&lt;/code&gt;, &lt;code&gt;n &amp;gt;= 100&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= n &amp;lt; 10&lt;/code&gt;, &lt;code&gt;&apos;a&apos; &amp;lt;= c &amp;lt;= &apos;z&apos;&lt;/code&gt;. Between two bounds the comparisons
are &lt;code&gt;&amp;lt;&lt;/code&gt; or &lt;code&gt;&amp;lt;=&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;n + k&lt;/code&gt;, where &lt;code&gt;k&lt;/code&gt; is a positive integer literal: it matches an integer of at least &lt;code&gt;k&lt;/code&gt; and binds
&lt;code&gt;n&lt;/code&gt; to the value minus &lt;code&gt;k&lt;/code&gt;, which never overflows;&lt;/li&gt;
&lt;li&gt;constructors with nested patterns, tuples and &lt;code&gt;()&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;a variant with fields named alone, bare or qualified (&lt;code&gt;Shipped&lt;/code&gt;, &lt;code&gt;Status.Shipped&lt;/code&gt;), which tests
for the variant and binds none of its fields, as &lt;code&gt;Shipped(_, _)&lt;/code&gt; does with one &lt;code&gt;_&lt;/code&gt; per field;
&lt;code&gt;Shipped()&lt;/code&gt;, with parentheses, is matched against the fields by number;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#extractor-patterns&quot;&gt;extractor patterns&lt;/a&gt;, &lt;code&gt;Name(p1, p2)&lt;/code&gt; where &lt;code&gt;Name&lt;/code&gt; is a value implementing
&lt;code&gt;Extractor&lt;/code&gt;, &lt;code&gt;BoolExtractor&lt;/code&gt; or &lt;code&gt;SeqExtractor&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;list patterns: &lt;code&gt;head :: tail&lt;/code&gt; matches a non-empty &lt;code&gt;List&lt;/code&gt;, grouping to the right
(&lt;code&gt;first :: second :: rest&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/spec/collections/#sequence-patterns&quot;&gt;sequence patterns&lt;/a&gt;: &lt;code&gt;[]&lt;/code&gt; matches an empty sequence and
&lt;code&gt;[a, b]&lt;/code&gt; a sequence of exactly two elements;&lt;/li&gt;
&lt;li&gt;type patterns (&lt;code&gt;d: Dog&lt;/code&gt;, &lt;code&gt;_: Dog&lt;/code&gt;), which also take a &lt;a href=&quot;/spec/unions/#match&quot;&gt;union&lt;/a&gt; apart, member
by member; a union in a type pattern is parenthesized, &lt;code&gt;x: (int | string)&lt;/code&gt;. A built-in type’s name
alone, &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;string&lt;/code&gt;, is the type pattern &lt;code&gt;_: int&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;alternatives (&lt;code&gt;1 | 2 | 3&lt;/code&gt;), which bind no names and may continue across lines with a leading or
trailing &lt;code&gt;|&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;named patterns (&lt;code&gt;whole @ Some(x)&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;&lt;code&gt;_&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ranges and comparison patterns match integers, bytes and chars; &lt;code&gt;n + k&lt;/code&gt; matches integers. Every
pattern form may appear wherever a pattern does, nested inside a constructor (&lt;code&gt;Some(n &amp;gt; 0)&lt;/code&gt;) or in a
function’s &lt;a href=&quot;/spec/declarations/#clauses&quot;&gt;clauses&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A guard (&lt;code&gt;n if n &amp;gt; 0 -&amp;gt;&lt;/code&gt;) is evaluated at most once per arm. Literals, ranges, comparison patterns
and &lt;code&gt;n + k&lt;/code&gt; count toward exhaustiveness by the values they leave out, so arms that together reach
every integer need no catch-all:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;bucket(n: int) -&amp;gt; string = n match
  n &amp;lt; 0 -&amp;gt; &amp;quot;negative&amp;quot;
  0 &amp;lt;= n &amp;lt; 10 -&amp;gt; &amp;quot;digit&amp;quot;
  n &amp;gt;= 10 -&amp;gt; &amp;quot;large&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Guards do not count, since a guard may fail.&lt;/p&gt;
&lt;p&gt;An arm on a &lt;a href=&quot;/spec/refined-variants/#refinement-in-a-match&quot;&gt;refined variant&lt;/a&gt; learns the type
equalities its result gives, and coverage counts only the variants possible at the type matched.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;type pattern&lt;/strong&gt;, &lt;code&gt;x: T&lt;/code&gt;, matches a value whose type at run time is &lt;code&gt;T&lt;/code&gt; and binds it to &lt;code&gt;x&lt;/code&gt; as a
&lt;code&gt;T&lt;/code&gt;; &lt;code&gt;_: T&lt;/code&gt; tests without binding. For a class or a trait it matches an instance of any subclass or
conforming class, and for a generic type it compares the type arguments exactly (&lt;code&gt;Box[int]&lt;/code&gt; is not a
&lt;code&gt;Box[string]&lt;/code&gt;). The value matched may be an &lt;code&gt;Any&lt;/code&gt;, or of a trait’s or an open class’s type, to be
taken down to a class. A downcast is written this way, never as a cast:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;legs(a: Animal) -&amp;gt; int = a match
  d: Dog -&amp;gt; d.legs
  b: Bird -&amp;gt; b.legs
  _ -&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A tuple’s type at run time is the one it was &lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;made with&lt;/a&gt;, so a tuple
type pattern compares that type, not the classes of the objects inside it: &lt;code&gt;t: (Animal, int)&lt;/code&gt; holding
a &lt;code&gt;Dog&lt;/code&gt; does not match &lt;code&gt;_: (Dog, int)&lt;/code&gt;, nor does &lt;code&gt;(a, 1)&lt;/code&gt; with &lt;code&gt;a: Animal&lt;/code&gt; as an &lt;code&gt;Any&lt;/code&gt;, while a
tuple made as a &lt;code&gt;(Dog, int)&lt;/code&gt; matches it wherever it is held. A tuple’s type is seen as another where
each part &lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;converts with no box&lt;/a&gt;: a part that is an object is its own
&lt;code&gt;Any&lt;/code&gt;, so &lt;code&gt;(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;)&lt;/code&gt; matches &lt;code&gt;_: (Any, string)&lt;/code&gt;, while &lt;code&gt;(1, &amp;quot;b&amp;quot;)&lt;/code&gt; does not, its &lt;code&gt;int&lt;/code&gt; being no
object, and an &lt;code&gt;(int, bool)&lt;/code&gt; matches &lt;code&gt;_: (int | string, bool)&lt;/code&gt; only when made with that union there.
A part naming a union of objects, &lt;code&gt;_: (Dog | Cat, int)&lt;/code&gt;, takes the object the tuple holds there when
it is one of the union’s members, whatever the part was made as. A pattern on a tuple of known type
that no tuple of that type could match is an error, as any such type pattern is. Each part is tested
on its own by a tuple pattern with a type pattern inside it, &lt;code&gt;(d: Dog, n) -&amp;gt; …&lt;/code&gt;, on a value of a tuple
type; an &lt;code&gt;Any&lt;/code&gt; is first matched by its tuple type, &lt;code&gt;p: (Animal, int)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A type pattern that can never match, such as &lt;code&gt;s: string&lt;/code&gt; on an &lt;code&gt;int&lt;/code&gt;, is an error.&lt;/p&gt;
&lt;h3 id=&quot;type-names-in-patterns&quot;&gt;Type names in patterns&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A type’s name is a type pattern by itself.&lt;/strong&gt; Each name in the
&lt;a href=&quot;/spec/types/#built-in-types&quot;&gt;table of built-in types&lt;/a&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;,
&lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt; and every sized integer &lt;code&gt;iN&lt;/code&gt;, stands for &lt;code&gt;_: T&lt;/code&gt; wherever a pattern does:
&lt;code&gt;x is int&lt;/code&gt; tests that &lt;code&gt;x&lt;/code&gt; holds an int, and &lt;code&gt;x is not string&lt;/code&gt; that it holds no string. So does the
name of any other type in scope that is no variant: a class, a trait, an &lt;code&gt;object&lt;/code&gt;, a &lt;code&gt;data&lt;/code&gt; type, an
alias, &lt;code&gt;Any&lt;/code&gt; and a type parameter, so &lt;code&gt;a is Dog&lt;/code&gt; tests for a &lt;code&gt;Dog&lt;/code&gt;. A variant’s name is still the
variant, so &lt;code&gt;data Cell(value: int)&lt;/code&gt; makes &lt;code&gt;Cell&lt;/code&gt; the variant’s pattern, and &lt;code&gt;Circle&lt;/code&gt; matches the
variant &lt;code&gt;Circle&lt;/code&gt;. It keeps a type test short where one is wanted most:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;kind(x: Any) -&amp;gt; string = x match
  int | long -&amp;gt; &amp;quot;an integer&amp;quot;
  string -&amp;gt; &amp;quot;text&amp;quot;
  _ -&amp;gt; &amp;quot;something else&amp;quot;

size(v: int | string) -&amp;gt; int = v match
  int -&amp;gt; 1
  string -&amp;gt; 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The name tests and binds nothing, so the value is bound beside its type as &lt;code&gt;n: int&lt;/code&gt;, or whole as
&lt;code&gt;n @ int&lt;/code&gt;, and &lt;code&gt;_: int | string&lt;/code&gt; and &lt;code&gt;_: Dog | Bird&lt;/code&gt; are two such alternatives. A generic type’s
name alone is an error, since a type pattern compares the type arguments: &lt;code&gt;x is Box&lt;/code&gt; asks for
&lt;code&gt;_: Box[int]&lt;/code&gt; or whichever arguments are meant, and &lt;code&gt;_: Vector[int]&lt;/code&gt; and &lt;code&gt;v: Vector[int]&lt;/code&gt; stay as
they are.&lt;/p&gt;
&lt;p&gt;Because a type’s name in a pattern always tests the type, it never names a value. A local, a
parameter or a lambda’s parameter named after a type in scope (&lt;code&gt;val Cell = 3&lt;/code&gt;, &lt;code&gt;f(Dog: int)&lt;/code&gt;) is an
error, and so is a pattern binding it (&lt;code&gt;Dog: Animal&lt;/code&gt;, &lt;code&gt;Count @ Some(_)&lt;/code&gt;). A built-in type’s name is
refused as a field’s name too, and in every binding position of a pattern (&lt;code&gt;int: T&lt;/code&gt;, &lt;code&gt;int @ p&lt;/code&gt;,
&lt;code&gt;int + 1&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= int &amp;lt; 9&lt;/code&gt;, &lt;code&gt;int*&lt;/code&gt;). It reaches coverage and reachability as the type pattern it is:
&lt;code&gt;int&lt;/code&gt; covers the &lt;code&gt;int&lt;/code&gt; member of a union, and an arm after &lt;code&gt;_&lt;/code&gt;, after another &lt;code&gt;int&lt;/code&gt; or after a
supertype’s name is never reached. A type pattern
covers every value only when its type is one the matched value already has, so a &lt;code&gt;match&lt;/code&gt; on an &lt;code&gt;Any&lt;/code&gt;
needs a &lt;code&gt;_&lt;/code&gt; arm. A literal does not match an &lt;code&gt;Any&lt;/code&gt;; match its type first (&lt;code&gt;n: int if n == 5&lt;/code&gt;). In a
function’s clauses a type pattern takes an argument apart like any other (&lt;code&gt;size(s: string) = …&lt;/code&gt;),
but one naming the parameter’s own type is an error, since the signature already says it. In a
destructuring binding, whose &lt;code&gt;:&lt;/code&gt; begins the binding’s type, a type pattern is in parentheses. A
function type in a type pattern is written in parentheses, because an arm’s &lt;code&gt;-&amp;gt;&lt;/code&gt; follows it:
&lt;code&gt;f: ((int) -&amp;gt; int) -&amp;gt; …&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; that does not cover every value names one it leaves out, written as a pattern:
&lt;code&gt;this `match` does not cover every Shape value, such as `Rect(_, _)`&lt;/code&gt;. A value is named only
where no arm can match it whatever its extractors answer; where only extractors stand between the
arms and every value, the message says so instead:
&lt;code&gt;this `match` does not cover every int value, since an extractor may answer that it does not match; add an arm for the rest, such as `_`&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An arm no value can reach is an error: one after &lt;code&gt;_&lt;/code&gt; or a binding, one after a pattern that covers
the whole type, and one whose values earlier arms already match, alone or together. The message
names the earlier arm that covers it, by its pattern and line. A guard never hides the arms after
it, since it may fail; an extractor and a type test are taken to match every value in the arm
judged and none in the arms above it, so an arm is called unreachable only when it is, whatever
the extractors answer.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Phase
  Open
  Closing

code(p: Phase) -&amp;gt; int = p match
  Open -&amp;gt; 1
  Live -&amp;gt; 2 // binds a new name, matching every Phase
  Closing -&amp;gt; 3 // error: this arm is never reached: the arm `Live` on line 7 already matches
  // every value it would; `Live` binds a new value there, since no variant
  // `Live` is in scope
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A bare name that is neither a variant nor a &lt;a href=&quot;#type-names-in-patterns&quot;&gt;type&lt;/a&gt; in scope binds, so a
variant’s name misspelled or not imported matches everything; the message says so when the covering
arm’s name starts with a capital letter.&lt;/p&gt;
&lt;h3 id=&quot;extractor-patterns&quot;&gt;Extractor patterns&lt;/h3&gt;
&lt;p&gt;A pattern &lt;code&gt;Name(p1, p2)&lt;/code&gt; whose &lt;code&gt;Name&lt;/code&gt; is not a variant is an &lt;strong&gt;extractor&lt;/strong&gt;: a value, such as an
object, a class’s companion, a local or a parameter, whose type implements one of the core
library’s extractor traits. The conformance makes the extractor; a method merely named &lt;code&gt;unapply&lt;/code&gt;
does not. The matched value is passed to the trait’s method, and its answer decides the match:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;BoolExtractor[A]&lt;/code&gt;, with &lt;code&gt;unapply(value: A) -&amp;gt; bool&lt;/code&gt;, matches where it answers &lt;code&gt;true&lt;/code&gt;, and is
written with no patterns, &lt;code&gt;Even()&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Extractor[A, B]&lt;/code&gt;, with &lt;code&gt;unapply(value: A) -&amp;gt; Option[B]&lt;/code&gt;, matches its &lt;code&gt;Some&lt;/code&gt;: one pattern
matches the value whole, and several match the parts of a tuple of as many,
&lt;code&gt;Split(key, value)&lt;/code&gt; for an &lt;code&gt;Extractor[string, (string, string)]&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SeqExtractor[A, S]&lt;/code&gt;, with &lt;code&gt;unapplySeq(value: A) -&amp;gt; Option[S]&lt;/code&gt;, &lt;code&gt;S&lt;/code&gt; a sequence, matches its
&lt;code&gt;Some&lt;/code&gt; as a &lt;a href=&quot;/spec/collections/#sequence-patterns&quot;&gt;sequence pattern&lt;/a&gt; does, so
&lt;code&gt;Words(first, second)&lt;/code&gt; needs exactly two elements and &lt;code&gt;Words(first, rest*)&lt;/code&gt; one or more.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object Twice: Extractor[int, int]
  override unapply(n: int) -&amp;gt; Option[int] = if n % 2 == 0 then Some(n / 2) else None

object Even: BoolExtractor[int]
  override unapply(n: int) -&amp;gt; bool = n % 2 == 0

describe(n: int) -&amp;gt; string = n match
  Twice(Twice(q)) -&amp;gt; s&amp;quot;four times $q&amp;quot;
  Twice(h) if h &amp;gt; 100 -&amp;gt; &amp;quot;a large double&amp;quot;
  Even() -&amp;gt; &amp;quot;even&amp;quot;
  _ -&amp;gt; &amp;quot;odd&amp;quot;

val date = Regex(&amp;quot;(\\d{4})-(\\d\\d)-(\\d\\d)&amp;quot;)
&amp;quot;2024-06-30&amp;quot; match
  date(year, month, day) -&amp;gt; …
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The traits are ordinary ones: &lt;code&gt;A&lt;/code&gt; is contravariant and &lt;code&gt;B&lt;/code&gt; and &lt;code&gt;S&lt;/code&gt; covariant, so an
&lt;code&gt;Extractor[Animal, string]&lt;/code&gt; takes a &lt;code&gt;Dog&lt;/code&gt;; an extractor may be held in a value of the trait’s type,
passed as a parameter, &lt;code&gt;e: Extractor[string, int]&lt;/code&gt;, or bound on a type parameter,
&lt;code&gt;[E: BoolExtractor[int]]&lt;/code&gt;; a data type implements one through an &lt;code&gt;impl&lt;/code&gt;; and a subclass keeps its
superclass’s conformance. A generic extractor is a value of a generic class,
&lt;code&gt;class Pair[A]: Extractor[List[A], (A, A)]&lt;/code&gt; matched as &lt;code&gt;pair(a, b)&lt;/code&gt; with &lt;code&gt;val pair = Pair[A]()&lt;/code&gt;. A
type implements each trait at one type argument; the trait whose &lt;code&gt;A&lt;/code&gt; takes the matched value
serves, and where an &lt;code&gt;unapply&lt;/code&gt; trait and &lt;code&gt;SeqExtractor&lt;/code&gt; both take it, the &lt;code&gt;unapply&lt;/code&gt; one does. A
type’s name is no value, so it is no extractor whatever static members it has. A pattern naming a
value whose type implements no extractor trait is an error that names the trait to implement, from
the type’s own &lt;code&gt;unapply&lt;/code&gt; or &lt;code&gt;unapplySeq&lt;/code&gt; where it has one.&lt;/p&gt;
&lt;p&gt;A variant of the name is always the variant, so a data type’s companion implements an extractor
trait to be matched by name, not to change what its variant’s pattern means. The method’s parameter
accepts the matched value’s type, as any call’s argument would. The method is called once
each time the pattern is tested, the patterns inside it are matched against its answer, and its
names are bound like any pattern’s; extractors nest, take guards, and appear in &lt;code&gt;is&lt;/code&gt;, alternatives,
clauses and match functions. An extractor may answer that it does not match, so it never counts
toward exhaustiveness: a &lt;code&gt;match&lt;/code&gt; relying on one needs a catch-all, and a binding’s or a &lt;code&gt;for&lt;/code&gt;‘s
pattern, which must cover every value, cannot hold one.&lt;/p&gt;
&lt;h3 id=&quot;match-functions&quot;&gt;Match functions&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; with nothing before it is a function of one value, which its arms match. The arms are
exactly those of a &lt;code&gt;match&lt;/code&gt;: patterns, &lt;code&gt;if&lt;/code&gt; guards, &lt;code&gt;-&amp;gt;&lt;/code&gt; and block bodies. One arm may stand on the
&lt;code&gt;match&lt;/code&gt; line; several go in an indented block, which may open inside parentheses or after an infix
method’s name at the end of a line:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val radii = shapes.collect(match Circle(r) -&amp;gt; r)

val sizes = shapes.map(match
  Circle(r) -&amp;gt; r * r * 3.14
  Rect(w, h) -&amp;gt; w * h)

val firstBig = shapes collectFirst match
  Circle(r) if r &amp;gt; 10.0 -&amp;gt; r
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The type of the value it matches comes from the type expected where it is written, as a lambda’s
parameter type does; a &lt;code&gt;match&lt;/code&gt; function with no expected type is an error asking for one. Where a
function type &lt;code&gt;A -&amp;gt; B&lt;/code&gt; is expected, the function is &lt;code&gt;x -&amp;gt; x match …&lt;/code&gt; and its arms must cover every
&lt;code&gt;A&lt;/code&gt;, as any &lt;code&gt;match&lt;/code&gt;‘s do: &lt;code&gt;pairs.map(match (k, v) -&amp;gt; s&amp;quot;$k=$v&amp;quot;)&lt;/code&gt;. A function of two or more
parameters is not a &lt;code&gt;match&lt;/code&gt; function’s type.&lt;/p&gt;
&lt;p&gt;Where a &lt;a href=&quot;/spec/types/#partial-functions&quot;&gt;&lt;code&gt;PartialFunction[A, B]&lt;/code&gt;&lt;/a&gt; is expected, the arms need not
cover every &lt;code&gt;A&lt;/code&gt;: the function is defined at the values some arm matches. A partial function made
this way tests its patterns and guards once each time it is called, lifted or given to
&lt;code&gt;applyOrElse&lt;/code&gt;; &lt;code&gt;isDefinedAt&lt;/code&gt; tests them without running an arm’s body.&lt;/p&gt;
&lt;h2 id=&quot;is&quot;&gt;is&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;x is P&lt;/code&gt; tests a value against any pattern a &lt;code&gt;match&lt;/code&gt; arm takes and yields a &lt;code&gt;bool&lt;/code&gt;; &lt;code&gt;x is not P&lt;/code&gt; is
its negation. &lt;code&gt;order.status is Shipped&lt;/code&gt; asks only which variant it is, whatever fields &lt;code&gt;Shipped&lt;/code&gt;
has, and &lt;code&gt;x is int&lt;/code&gt; which type it holds, since a built-in type’s name is a
&lt;a href=&quot;#match&quot;&gt;type pattern&lt;/a&gt; by itself. &lt;code&gt;not&lt;/code&gt; is a keyword only there, directly after &lt;code&gt;is&lt;/code&gt;, where it always negates: &lt;code&gt;x is not(y)&lt;/code&gt; tests the pattern &lt;code&gt;(y)&lt;/code&gt;. Everywhere else &lt;code&gt;not&lt;/code&gt; is an ordinary name, so a function, method,
parameter or local may be called &lt;code&gt;not&lt;/code&gt; and &lt;code&gt;not(p)&lt;/code&gt; calls it. The names &lt;code&gt;P&lt;/code&gt; binds are in scope only
where the test is known to have matched:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;area(shape: Option[Shape]) -&amp;gt; int
  if shape is not Some(Rect(w, h)) then return 0
  w * h

total(xs: List[int]) -&amp;gt; int
  var rest = xs
  var sum = 0
  while rest is head :: more
    sum += head
    rest = more
  sum
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;if x is P&lt;/code&gt; binds them in the &lt;code&gt;then&lt;/code&gt; branch, &lt;code&gt;while x is P&lt;/code&gt; in the body, and &lt;code&gt;a &amp;amp;&amp;amp; b&lt;/code&gt; in &lt;code&gt;b&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x is not P&lt;/code&gt; binds them where the test failed: the &lt;code&gt;else&lt;/code&gt; of an &lt;code&gt;if&lt;/code&gt;, the &lt;code&gt;else&lt;/code&gt; of a &lt;code&gt;while&lt;/code&gt;, and
the right operand of &lt;code&gt;||&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!&lt;/code&gt; swaps the two: &lt;code&gt;!(x is P)&lt;/code&gt; binds like &lt;code&gt;x is not P&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A condition binds its operands’ names where it holds, for &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, or where it fails, for &lt;code&gt;||&lt;/code&gt;. Neither
side of &lt;code&gt;a is P(v) || b is Q(v)&lt;/code&gt; holds wherever the whole does, so the &lt;code&gt;then&lt;/code&gt; branch sees no &lt;code&gt;v&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;After an &lt;code&gt;if&lt;/code&gt; whose one branch never finishes (a &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; or trap), the rest of
the block sees the names bound for the other branch, as &lt;code&gt;w&lt;/code&gt; and &lt;code&gt;h&lt;/code&gt; above.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Nowhere else: not in the other branch, not after an &lt;code&gt;if&lt;/code&gt; both of whose branches finish, not in the
test of &lt;code&gt;do … while&lt;/code&gt;, and not after an &lt;code&gt;is&lt;/code&gt; used as a value (&lt;code&gt;val big = o is Some(n) &amp;amp;&amp;amp; n &amp;gt; 100&lt;/code&gt;).
Using a name outside its scope is an error that says so. A condition binds a name once; its names
may shadow the enclosing block’s, as an arm’s may, except those the block keeps after an &lt;code&gt;if&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;return-and-end-markers&quot;&gt;return and end markers&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;return expr&lt;/code&gt; exits the enclosing function. Inside a lambda it exits the lambda. Where a &lt;code&gt;return&lt;/code&gt; or
&lt;code&gt;break&lt;/code&gt; value fills a line, a comma list is a tuple without parentheses (&lt;code&gt;return a, b&lt;/code&gt;); inside
brackets whose commas separate items (call arguments, tuple and collection literals) the value stops
at the comma, so &lt;code&gt;f(a = return 1, b = 2)&lt;/code&gt; has two arguments and a tuple is written &lt;code&gt;return (1, 2)&lt;/code&gt;.
An indented block inside the brackets starts a line again. Optional end markers
(&lt;code&gt;end if&lt;/code&gt;, &lt;code&gt;end while&lt;/code&gt;, &lt;code&gt;end match&lt;/code&gt;, &lt;code&gt;end val&lt;/code&gt;, &lt;code&gt;end name&lt;/code&gt;) are checked against the construct they
close.&lt;/p&gt;
&lt;h2 id=&quot;defer&quot;&gt;defer&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;defer stmt&lt;/code&gt; runs &lt;code&gt;stmt&lt;/code&gt; when control leaves the block the &lt;code&gt;defer&lt;/code&gt; is written in. What a program takes
from outside itself, a file, a connection, a temporary directory, a started command, is given back by
a &lt;code&gt;defer&lt;/code&gt; written beside the code that took it, rather than at every way out:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;copy(from: string, to: string) -&amp;gt; Result[unit, IoError]
  val source = fs.open(from)?
  defer source.close()
  val target = fs.create(to)?
  defer target.close()
  target.write(source.readAll()?)?
  target.close()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;It runs on every ordinary way out of its block&lt;/strong&gt;: falling off the end, &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt; taking its
failure arm, and &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; leaving a loop the block is in. The statement is a single
statement on the &lt;code&gt;defer&lt;/code&gt; line, or an indented block below it (&lt;code&gt;end defer&lt;/code&gt; may close that block).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A deferred statement belongs to its block&lt;/strong&gt;: a function’s or a lambda’s body, a branch of &lt;code&gt;if&lt;/code&gt;, an
arm of &lt;code&gt;match&lt;/code&gt;, a loop’s body, a turn of an actor, or any indented block. A loop body’s statements run
at the end of every turn, so each turn’s resource is given back before the next is taken; a
&lt;code&gt;continue&lt;/code&gt; or &lt;code&gt;break&lt;/code&gt; runs them too, and a &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; of an outer loop runs the inner
loops’ as well. A nested block’s run at its own end, before the code after it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Several run in the reverse of the order they were written&lt;/strong&gt;, so resources are given back in the
reverse of the order they were taken, and a later one may use what an earlier one guards.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Only a &lt;code&gt;defer&lt;/code&gt; that was reached runs.&lt;/strong&gt; It is a statement, not a declaration: one after a &lt;code&gt;return&lt;/code&gt;
that left, or in a branch not taken, never runs, and one a call reached is not carried into the next
call.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A deferred statement reads its names when it runs.&lt;/strong&gt; Nothing is evaluated where the &lt;code&gt;defer&lt;/code&gt; is
written; a &lt;code&gt;var&lt;/code&gt; changed after it is seen changed. The value a block yields, and the value of a
&lt;code&gt;return&lt;/code&gt; or a &lt;code&gt;break&lt;/code&gt;, are computed first, then the deferred statements run, so a statement that
changes a &lt;code&gt;var&lt;/code&gt; does not change a value already computed:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;next() -&amp;gt; int
  var n = 1
  defer n = 100
  n // 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;No jump may leave a deferred statement&lt;/strong&gt;, at any depth: no &lt;code&gt;return&lt;/code&gt;, no &lt;code&gt;?&lt;/code&gt;, and no &lt;code&gt;break&lt;/code&gt; or
&lt;code&gt;continue&lt;/code&gt; of a loop outside it, since it runs while its block is already being left. A loop written
inside it is its own, and a lambda or a local function written inside it may return from itself.
A &lt;code&gt;defer&lt;/code&gt; inside a deferred statement belongs to that statement’s block and runs at its end.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;defer&lt;/code&gt; is a statement of a block.&lt;/strong&gt; As a value (a binding’s value, an argument, a one-line
function’s body), as a one-line branch (&lt;code&gt;if c then defer f()&lt;/code&gt;), or in a class body, it is refused. Its
statement’s value is discarded, so &lt;code&gt;defer f.close()&lt;/code&gt; on a &lt;code&gt;close&lt;/code&gt; that answers a &lt;code&gt;Result&lt;/code&gt; gives the
&lt;code&gt;Result&lt;/code&gt; up; a program that wants the &lt;code&gt;Err&lt;/code&gt; closes on its success path first, which a resource’s
&lt;code&gt;close&lt;/code&gt; allows, since &lt;a href=&quot;/spec/system-library/#avin-io&quot;&gt;closing twice&lt;/a&gt; does nothing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A deferred statement takes a call out of tail position.&lt;/strong&gt; A self-call while one is waiting to run,
the value of a &lt;code&gt;return&lt;/code&gt; included, is a real call, and &lt;code&gt;@tailrec&lt;/code&gt; refuses it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A trap runs nothing.&lt;/strong&gt; A trap stops the program, or the actor’s turn, where it happens, without
running the deferred statements of the functions it stops: the program’s state is already wrong, and
cleanup run against it could do harm. An actor’s &lt;code&gt;stopping&lt;/code&gt; block still runs, as for any failed turn.
A program ended by &lt;code&gt;process.exit&lt;/code&gt; runs none either; a file or a connection left open then is closed
when the collector frees it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A cancelled thread runs them all.&lt;/strong&gt; &lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;Cancellation&lt;/a&gt; stops a thread at
a known point, a wait or a loop’s poll, where nothing is in doubt, so the deferred statements of
every frame it drops run there, innermost first, as leaving their blocks any other way would run
them: a cancelled query can still tell its server, a transaction roll back, a lease go back to its
pool. A deferred statement runs to its end once begun: the cancellation does not stop it inside one,
even where it waits, and the thread stops at its next cancellation point after. One that traps stops
the program.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;fetch(pool: Pool[Conn, IoError]) -&amp;gt; Result[Rows, PoolError[IoError]] = pool.use(c -&amp;gt;
  defer c.cancelIfBusy() // runs if the thread is cancelled while the query waits
  c.query(&amp;quot;select ...&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;</content>
  </entry>
  <entry>
    <title>Linux</title>
    <link href="https://avinlang.dev/compiler/linux/"/>
    <id>https://avinlang.dev/compiler/linux/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>How Avin comes to build and run on x86_64 and aarch64 Linux - what in the toolchain assumes macOS, what it needs from Sysl, how Linux is built, tested and shipped, and the items that do it, in order.</summary>
    <content type="html">&lt;p&gt;Avin’s targets are &lt;code&gt;aarch64-macos&lt;/code&gt;, &lt;code&gt;x86_64-linux&lt;/code&gt; and &lt;code&gt;aarch64-linux&lt;/code&gt; (glibc), as
&lt;a href=&quot;/spec/decisions/&quot;&gt;decided&lt;/a&gt;. This page is the plan for the two Linux targets: the places the
toolchain assumes macOS, what it needs from Sysl, how it is built, tested and shipped, and the items
that do the work, each one agent’s. What a package says about machines is in
&lt;a href=&quot;/spec/packages/#machines&quot;&gt;packages&lt;/a&gt;. Which items are done is in the &lt;a href=&quot;/compiler/roadmap/&quot;&gt;roadmap&lt;/a&gt;
and nowhere else.&lt;/p&gt;
&lt;h2 id=&quot;what-assumes-macos&quot;&gt;What assumes macOS&lt;/h2&gt;
&lt;p&gt;Most of the toolchain is already written for both systems: the runtime’s Sysl gates its error
numbers, socket constants and &lt;code&gt;errno&lt;/code&gt; location on &lt;code&gt;#if bsd&lt;/code&gt;; its C keeps a Linux branch beside each
macOS one; the collector is precise and touches no system interface; the standard library reaches
the system only through Sysl bindings, and Sysl’s library implements each for Linux (epoll for the
poller, &lt;code&gt;/proc&lt;/code&gt; for process memory and children, glibc’s numbers for signals). The table lists each
place that assumes macOS, and each Linux branch the items below have to prove on Linux.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;where&lt;/th&gt;&lt;th&gt;the assumption&lt;/th&gt;&lt;th&gt;on Linux&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Compiler: code and link&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;emit.sysl&lt;/code&gt; module header; &lt;code&gt;codegen_units.sysl:623&lt;/code&gt;; &lt;code&gt;driver.sysl:819&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The IR carries no &lt;code&gt;target triple&lt;/code&gt; or &lt;code&gt;datalayout&lt;/code&gt;; clang compiles it for its own default target&lt;/td&gt;&lt;td&gt;Right for a native build. A cross build passes &lt;code&gt;--target=&amp;lt;triple&amp;gt;&lt;/code&gt; to every clang line&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:780-834&lt;/code&gt; (&lt;code&gt;link&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;The link line is objects, the runtime or shims archive, the C unit, the libraries, &lt;code&gt;-lm&lt;/code&gt;; ld64 resolves archives whatever their order&lt;/td&gt;&lt;td&gt;GNU ld reads an archive once, left to right: link with &lt;code&gt;-fuse-ld=lld&lt;/code&gt;, which resolves as ld64 does, or group the archives (&lt;code&gt;-Wl,--start-group … --end-group&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:826&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;-lm&lt;/code&gt; is the only system library named&lt;/td&gt;&lt;td&gt;glibc 2.34 and later hold &lt;code&gt;pthread&lt;/code&gt;, &lt;code&gt;dl&lt;/code&gt; and &lt;code&gt;rt&lt;/code&gt; in libc; older ones need &lt;code&gt;-pthread&lt;/code&gt;. Name &lt;code&gt;-pthread&lt;/code&gt; on Linux&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:836-844,864&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;-g&lt;/code&gt; runs &lt;code&gt;dsymutil&lt;/code&gt; to gather DWARF into &lt;code&gt;&amp;lt;exe&amp;gt;.dSYM&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Already gated on &lt;code&gt;MacOS&lt;/code&gt;. The ELF linker copies DWARF into the executable, so nothing replaces it; gdb and lldb read it in place&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:62&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The tools are &lt;code&gt;clang&lt;/code&gt;, &lt;code&gt;sysl&lt;/code&gt; and &lt;code&gt;pkg-config&lt;/code&gt; by those names&lt;/td&gt;&lt;td&gt;Distributions install &lt;code&gt;clang-18&lt;/code&gt; and the like beside or instead of &lt;code&gt;clang&lt;/code&gt;: an &lt;code&gt;AVIN_CC&lt;/code&gt; variable (and Sysl’s &lt;code&gt;--cc&lt;/code&gt;) names it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:128-129&lt;/code&gt;, &lt;code&gt;:841&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A missing tool is answered with &lt;code&gt;brew install sysl-lang/tap/sysl&lt;/code&gt; and &lt;code&gt;xcode-select --install&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Name the install script and the distribution’s packages (&lt;code&gt;apt install clang lld llvm pkg-config&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:757&lt;/code&gt;; &lt;code&gt;shim.sysl:1422,1443&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;sysl build-c&lt;/code&gt; is run with no &lt;code&gt;--target&lt;/code&gt; and no &lt;code&gt;--cc&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Right natively; a cross build passes both&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;driver.sysl:764&lt;/code&gt; (&lt;code&gt;runtime_key&lt;/code&gt;); &lt;code&gt;keys.sysl&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Cache keys name the compiler and the sources, not the target&lt;/td&gt;&lt;td&gt;One machine per cache is right natively; a cross build, or a prefix shipping archives for two targets, keys by target&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cunit.sysl:655-685&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Static linking keeps &lt;code&gt;-framework&lt;/code&gt; pairs and treats libSystem, libz and libm as the system’s&lt;/td&gt;&lt;td&gt;&lt;code&gt;-framework&lt;/code&gt; never appears on Linux. The system’s libraries are glibc’s (&lt;code&gt;c&lt;/code&gt;, &lt;code&gt;m&lt;/code&gt;, &lt;code&gt;pthread&lt;/code&gt;, &lt;code&gt;dl&lt;/code&gt;, &lt;code&gt;rt&lt;/code&gt;), never taken from an archive&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cunit.sysl:712&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A shared library is &lt;code&gt;.dylib&lt;/code&gt;, &lt;code&gt;.tbd&lt;/code&gt; or &lt;code&gt;.so&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Also versioned names, &lt;code&gt;libssl.so.3&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;shim.sysl:1570&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;-lc&lt;/code&gt; and &lt;code&gt;-lm&lt;/code&gt; from a Sysl package’s needs are dropped as always linked&lt;/td&gt;&lt;td&gt;The same on Linux; &lt;code&gt;-lpthread&lt;/code&gt;, &lt;code&gt;-ldl&lt;/code&gt; are harmless and kept&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Runtime&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;runtime/avin/rt/lookup.sysl:56,110-111&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The lookup’s pipe sets descriptor flag &lt;code&gt;2&lt;/code&gt; for close-on-exec&lt;/td&gt;&lt;td&gt;&lt;code&gt;FD_CLOEXEC&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; on both systems, so this is a bug on both; macOS hides it by starting children with every other descriptor closed, and Linux does not&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;__posix__/runner_watch.c:14,28,63&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The runner’s exit is awaited on a kqueue; elsewhere it is asked about every tenth of a second&lt;/td&gt;&lt;td&gt;Linux’s branch polls. &lt;code&gt;prctl(PR_SET_PDEATHSIG)&lt;/code&gt; or a &lt;code&gt;pidfd&lt;/code&gt; answers at once&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;__posix__/stack_guard.c:78-88&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The stack’s low end from &lt;code&gt;pthread_get_stackaddr_np&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The &lt;code&gt;pthread_getattr_np&lt;/code&gt; branch&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;__posix__/stack_guard.c:131-133&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An overflow arrives as &lt;code&gt;SIGSEGV&lt;/code&gt; or &lt;code&gt;SIGBUS&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Linux raises &lt;code&gt;SIGSEGV&lt;/code&gt;; both are caught&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cpu.sysl:12-24&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;struct timeval&lt;/code&gt; read as &lt;code&gt;i64&lt;/code&gt; then a low &lt;code&gt;i32&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Linux’s &lt;code&gt;suseconds_t&lt;/code&gt; is 64 bits; the low half is the count on a little-endian machine&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;recovery.sysl:13,17,24&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;_setjmp&lt;/code&gt;/&lt;code&gt;_longjmp&lt;/code&gt; into 64 words&lt;/td&gt;&lt;td&gt;glibc has both; its &lt;code&gt;jmp_buf&lt;/code&gt; is 25 words on x86_64 and 39 on aarch64, within 64&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sockets.sysl:45-58&lt;/code&gt;; &lt;code&gt;lookup.sysl:51-54,65-70&lt;/code&gt;; &lt;code&gt;cpu.sysl:29-35&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Error numbers and &lt;code&gt;SOL_SOCKET&lt;/code&gt;/&lt;code&gt;SO_ERROR&lt;/code&gt; by &lt;code&gt;#if bsd&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Linux’s numbers, in the &lt;code&gt;#else&lt;/code&gt; branch&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Standard library&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;library/avin/process/process.avin:243-254&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;os()&lt;/code&gt; is Sysl’s &lt;code&gt;os()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Answers &lt;code&gt;Linux&lt;/code&gt;; the tests already branch on it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;library/avin/time/zone.avin:487-520&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The tz database at &lt;code&gt;TZDIR&lt;/code&gt; or &lt;code&gt;/usr/share/zoneinfo&lt;/code&gt;, the host’s zone at &lt;code&gt;/etc/localtime&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same paths; a minimal container has no tz database, so the Linux image installs &lt;code&gt;tzdata&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;library/avin/net/tls&lt;/code&gt;&lt;/td&gt;&lt;td&gt;OpenSSL found by &lt;code&gt;pkg-config&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;libssl-dev&lt;/code&gt;; the certificate store is the distribution’s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;library/avin/signal/signal.avin:16-37&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Eight signals by number&lt;/td&gt;&lt;td&gt;The eight are the same numbers on Linux&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Tests&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;static_link_tests.sysl&lt;/code&gt; (24 lines)&lt;/td&gt;&lt;td&gt;&lt;code&gt;.dylib&lt;/code&gt;, &lt;code&gt;-dynamiclib&lt;/code&gt;, &lt;code&gt;-install_name&lt;/code&gt;, &lt;code&gt;otool -L&lt;/code&gt;; the end-to-end cases return early off macOS&lt;/td&gt;&lt;td&gt;The same cases on Linux with &lt;code&gt;.so&lt;/code&gt;, &lt;code&gt;-shared&lt;/code&gt;, &lt;code&gt;-Wl,-soname&lt;/code&gt; and &lt;code&gt;readelf -d&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;debug_info_tests.sysl:326,378&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;.dSYM&lt;/code&gt; beside the executable&lt;/td&gt;&lt;td&gt;Already gated; Linux asserts the DWARF sections are in the executable&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toolchain_tests.sysl:68-69,103,127&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;~/Library/Caches&lt;/code&gt;, the Homebrew and Xcode words&lt;/td&gt;&lt;td&gt;The XDG cache case, the Linux words&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tests/programs/run/c_void_pointer_libc.out:11&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;uname&lt;/code&gt; answers &lt;code&gt;Darwin&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A per-system expected output&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tests/programs/run/c_rusage&lt;/code&gt;&lt;/td&gt;&lt;td&gt;macOS’s &lt;code&gt;proc_pid_rusage&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Read on macOS only: a &lt;code&gt;.macos.avin&lt;/code&gt; file, or a case the corpus runs only on macOS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Release&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scripts/release.sh:33,87&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The asset is &lt;code&gt;avin-&amp;lt;v&amp;gt;-darwin-arm64.tar.gz&lt;/code&gt;&lt;/td&gt;&lt;td&gt;One asset per target&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scripts/release.sh:211&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;otool -L&lt;/code&gt; lists what the compiler links&lt;/td&gt;&lt;td&gt;&lt;code&gt;ldd&lt;/code&gt; / &lt;code&gt;readelf -d&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scripts/release.sh:262,269&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;shasum -a 256&lt;/code&gt;, &lt;code&gt;stat -f %z&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;sha256sum&lt;/code&gt;, &lt;code&gt;stat -c %s&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scripts/release.sh:274,311&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;mktemp -t&lt;/code&gt;; “Apple’s clang” on &lt;code&gt;/usr/bin&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;mktemp -d&lt;/code&gt;; the distribution’s clang&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scripts/release.sh:409-411&lt;/code&gt;; &lt;code&gt;packaging/homebrew/avin.rb:8-25&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The formula is &lt;code&gt;depends_on :macos&lt;/code&gt; and &lt;code&gt;arch: :arm64&lt;/code&gt;, over Sysl’s macOS-only formula and &lt;code&gt;openssl@3&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;on_linux&lt;/code&gt; with the two Linux tarballs, once Sysl’s formula has them&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;what-avin-needs-from-sysl&quot;&gt;What Avin needs from Sysl&lt;/h2&gt;
&lt;p&gt;An installed Avin runs Sysl at users’ builds (&lt;code&gt;sysl build-c&lt;/code&gt; for the runtime when no archive
shipped, and for every program’s binding shims), so &lt;strong&gt;Linux Avin needs Linux Sysl on every user’s
machine&lt;/strong&gt;, not only at release. Sysl’s docs list &lt;code&gt;linux-x86_64&lt;/code&gt; and &lt;code&gt;linux-arm64&lt;/code&gt; among its release
platforms, implement its library for Linux, and have &lt;code&gt;x86_64-linux&lt;/code&gt; and &lt;code&gt;aarch64-linux&lt;/code&gt; in its target
registry; what it does not yet have:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A Sysl for Linux to install.&lt;/strong&gt; Sysl 0.11 ships &lt;code&gt;darwin-arm64&lt;/code&gt; only, and building it from source
needs a Sysl already installed (the seed), which Linux has no way to get. Avin needs release
tarballs &lt;code&gt;sysl-&amp;lt;v&amp;gt;-linux-x86_64.tar.gz&lt;/code&gt; and &lt;code&gt;sysl-&amp;lt;v&amp;gt;-linux-arm64.tar.gz&lt;/code&gt; in the macOS
tarball’s layout (or a documented way to make the first Linux seed).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sysl tested on Linux.&lt;/strong&gt; Sysl’s CI builds only its documentation on Ubuntu. Avin needs Sysl’s
own gate green on both Linux targets each release, &lt;code&gt;sysl.fiber&lt;/code&gt;, &lt;code&gt;sysl.io.poll&lt;/code&gt; (epoll),
&lt;code&gt;sysl.process&lt;/code&gt; (&lt;code&gt;/proc&lt;/code&gt;), &lt;code&gt;sysl.signal&lt;/code&gt; and &lt;code&gt;sysl.threads&lt;/code&gt; (futex) above all, since the runtime
stands on them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cross builds for Linux from macOS.&lt;/strong&gt; &lt;code&gt;sysl build --target x86_64-linux hello.sysl&lt;/code&gt; on the Mac
(Sysl 0.11.12, Apple clang 21) stops building the standard module: &lt;code&gt;stdio.h&lt;/code&gt; not found. There is
no way to name a Linux sysroot (the docs reach a sysroot only through the Android NDK’s and
wasi-sdk’s clang). For &lt;code&gt;avin build --target&lt;/code&gt;, a later item, Avin needs a sysroot named per target
(a flag, a &lt;code&gt;targets.&amp;lt;t&amp;gt;&lt;/code&gt; key or an environment variable) honoured by &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;build-c&lt;/code&gt; and
&lt;code&gt;build-lib&lt;/code&gt; and by the link, which takes &lt;code&gt;-fuse-ld=lld&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sysl’s Homebrew formula on Linux&lt;/strong&gt; (&lt;code&gt;on_linux&lt;/code&gt; with the two tarballs), for Avin’s formula to
depend on, once item 1 exists.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Sysl’s items 1 and 2 hold Avin’s items 4 to 8, 10 and 11 below; its item 3 holds only item 12, cross
builds.&lt;/p&gt;
&lt;h2 id=&quot;how-linux-is-built-tested-and-shipped&quot;&gt;How Linux is built, tested and shipped&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Built natively.&lt;/strong&gt; Avin is built on Linux by the Sysl on Linux, exactly as on the Mac; nothing is
cross-compiled. An installed Avin needs Sysl and clang on the machine anyway, so a native build is
the one users run.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tested locally in a colima VM&lt;/strong&gt;, aarch64 Linux at native speed on Apple silicon, at most 4 CPUs
and 6 GB: an image (&lt;code&gt;scripts/linux/Dockerfile&lt;/code&gt;) with clang, lld, llvm, pkg-config, libssl-dev,
tzdata, git, zsh and the Linux Sysl; &lt;code&gt;scripts/linux/run.zsh &amp;lt;command&amp;gt;&lt;/code&gt; runs a command in it over
the worktree. Every such run goes through marshal as &lt;code&gt;marshal submit --external --mem 6G&lt;/code&gt; with a
deadline, since the work runs in the VM and not in marshal’s own processes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tested in CI&lt;/strong&gt; on GitHub’s &lt;code&gt;ubuntu-24.04&lt;/code&gt; (x86_64) and &lt;code&gt;ubuntu-24.04-arm&lt;/code&gt; runners, on every push
to &lt;code&gt;dev&lt;/code&gt; and on every tag: install the Linux Sysl, build Avin, run the compiler’s tests and the
corpus. x86_64 is reached here and nowhere locally (an emulated x86_64 VM is too slow for a gate).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shipped&lt;/strong&gt; as a tarball per target beside the macOS one, plus &lt;code&gt;install.sh&lt;/code&gt;, which puts Avin and
the Sysl it needs into a prefix (&lt;code&gt;~/.local&lt;/code&gt; by default) and names the distribution’s packages for
what is missing. The Linux tarballs are built by the release workflow on the two native runners
from the tag the release script made; the formula gains &lt;code&gt;on_linux&lt;/code&gt; when Sysl’s has it. No &lt;code&gt;.deb&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-items&quot;&gt;The items&lt;/h2&gt;
&lt;p&gt;Each is one agent’s, in its own worktree, in this order; an item lists what it waits for. Items 1, 2,
3 and 9 need no Linux machine.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;lookup-cloexec&lt;/code&gt;&lt;/strong&gt;: the lookup’s pipe set close-on-exec with &lt;code&gt;FD_CLOEXEC&lt;/code&gt; (1). Test: a runtime
test that reads &lt;code&gt;fcntl(F_GETFD)&lt;/code&gt; of both ends while a lookup is held; and a run test that starts a
child during a held lookup and finds only its three streams open (holds on Linux; on macOS it
passes either way). Waits for nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;machine-conditions&lt;/code&gt;&lt;/strong&gt;: the manifest’s machines as &lt;a href=&quot;/spec/packages/#machines&quot;&gt;packages&lt;/a&gt; gives
them: &lt;code&gt;package.targets&lt;/code&gt;, the condition parser and its errors, &lt;code&gt;if&lt;/code&gt; on dependencies, Sysl
dependencies, C libraries and features, &lt;code&gt;install&lt;/code&gt; by condition, &lt;code&gt;link-flags&lt;/code&gt;, &lt;code&gt;--target&lt;/code&gt; on
&lt;code&gt;check&lt;/code&gt;, and &lt;code&gt;avin tidy&lt;/code&gt;/&lt;code&gt;avin vendor&lt;/code&gt; over every target. Test: &lt;code&gt;package_tests&lt;/code&gt; for every key,
every error and every composition (&lt;code&gt;if&lt;/code&gt; with &lt;code&gt;optional&lt;/code&gt;, a dependency’s conditional dependency, a
feature that does not exist on the machine); &lt;code&gt;avin check --target x86_64-linux&lt;/code&gt; on the Mac
resolving the Linux set. Waits for nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;machine-files&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;name.&amp;lt;symbol&amp;gt;.avin&lt;/code&gt;, a module existing where any file is read, the import
rule, &lt;code&gt;avin check&lt;/code&gt; once per differing target, and the &lt;code&gt;avin.target&lt;/code&gt; module (&lt;code&gt;os&lt;/code&gt;, &lt;code&gt;arch&lt;/code&gt;, &lt;code&gt;Arch&lt;/code&gt;)
as compile-time constants folded at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;. Test: &lt;code&gt;tests/programs/run&lt;/code&gt; and &lt;code&gt;reject&lt;/code&gt; for
each rule and diagnostic, checked for &lt;code&gt;x86_64-linux&lt;/code&gt; and &lt;code&gt;aarch64-linux&lt;/code&gt; from the Mac (checking
builds nothing); an IR test that an untaken branch is absent at &lt;code&gt;-O0&lt;/code&gt;. Waits for 2.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-image&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;scripts/linux/Dockerfile&lt;/code&gt; and &lt;code&gt;scripts/linux/run.zsh&lt;/code&gt;, and the colima
recipe in &lt;a href=&quot;/compiler/releasing/&quot;&gt;releasing&lt;/a&gt;. Test: &lt;code&gt;sysl --version&lt;/code&gt; and &lt;code&gt;sysl test&lt;/code&gt; of a
one-file Sysl program inside it, through marshal. Waits for Sysl’s item 1.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-build&lt;/code&gt;&lt;/strong&gt;: the compiler built on Linux, and its link made right there: &lt;code&gt;-fuse-ld=lld&lt;/code&gt; (or
grouped archives), &lt;code&gt;-pthread&lt;/code&gt;, &lt;code&gt;AVIN_CC&lt;/code&gt;, the Linux words for missing tools. Test: the compiler’s
unit tests (&lt;code&gt;sysl test compiler&lt;/code&gt; without the corpus) green in the image; &lt;code&gt;toolchain_tests&lt;/code&gt; for the
new words and &lt;code&gt;AVIN_CC&lt;/code&gt;. Waits for 4.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-runtime&lt;/code&gt;&lt;/strong&gt;: the runtime’s tests green on Linux: the stack guard, &lt;code&gt;getrusage&lt;/code&gt;, the error
numbers, the poller under the scheduler, signals, thread dumps; the runner watch made immediate
with &lt;code&gt;PR_SET_PDEATHSIG&lt;/code&gt;. Test: the runtime suite in the image; a run test that kills the runner
and finds the program gone at once. Waits for 5.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-corpus&lt;/code&gt;&lt;/strong&gt;: the execution corpus on Linux at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; under GC stress: per-system
expectations in the corpus driver (&lt;code&gt;NAME.linux.out&lt;/code&gt; beside &lt;code&gt;NAME.out&lt;/code&gt;), the macOS-only programs
given machine files, every Linux difference found fixed. Test: the whole gate in the image, through
marshal. Waits for 3 and 6.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-native-tests&lt;/code&gt;&lt;/strong&gt;: the macOS-only cases given Linux twins: static linking (&lt;code&gt;.so&lt;/code&gt;, &lt;code&gt;-shared&lt;/code&gt;,
&lt;code&gt;readelf -d&lt;/code&gt;), &lt;code&gt;-g&lt;/code&gt; (DWARF in the executable, a gdb backtrace naming the Avin source), the XDG
cache. Test: they are the tests. Waits for 5.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;target-keys&lt;/code&gt;&lt;/strong&gt;: the target in every cache key (runtime archive, shims, C unit, codegen units,
the run cache) and a shipped archive under &lt;code&gt;share/avin/lib/&amp;lt;target&amp;gt;/&lt;/code&gt;. Test: &lt;code&gt;toolchain_tests&lt;/code&gt;
that two targets never share an entry, and that an installed prefix finds its own target’s
archive. Waits for nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-ci&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;.github/workflows/linux.yml&lt;/code&gt; on both runners. Test: the workflow green on a
branch push. Waits for 7 and 8.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;linux-release&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;scripts/release.sh&lt;/code&gt; per target with the portable commands above, the
release workflow building the Linux tarballs from the tag and running step 6 of the release
(verify from the tarball) on each runner, &lt;code&gt;install.sh&lt;/code&gt;, and the formula’s &lt;code&gt;on_linux&lt;/code&gt;. Test: a
dry release on a branch producing and verifying all three tarballs; &lt;code&gt;install.sh&lt;/code&gt; into a fresh
image. Waits for 9, 10 and Sysl’s items 1 and 4.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;cross-build&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;avin build --target &amp;lt;t&amp;gt;&lt;/code&gt; from the Mac, with a sysroot. Test: a hello and a
program with bindings built for &lt;code&gt;x86_64-linux&lt;/code&gt; on the Mac and run in the image. Waits for 9 and
Sysl’s item 3.&lt;/li&gt;
&lt;/ol&gt;</content>
  </entry>
  <entry>
    <title>JSON</title>
    <link href="https://avinlang.dev/spec/json/"/>
    <id>https://avinlang.dev/spec/json/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>JSON is the package dev.avinlang.json, not a module of the standard library: depending on it, and what an import of avin.json says.</summary>
    <content type="html">&lt;p&gt;JSON is &lt;strong&gt;the package &lt;code&gt;dev.avinlang.json&lt;/code&gt;&lt;/strong&gt;, written in Avin in its own repository,
&lt;code&gt;github.com/avin-lang/json&lt;/code&gt;, and not a module of the standard library. A program adds it to its
dependencies, and its module’s import binds &lt;code&gt;json&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;dependencies {
  json { git = &amp;quot;github.com/avin-lang/json&amp;quot;, version = &amp;quot;0.0.1&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import dev.avinlang.json
import dev.avinlang.json.{Json, JsonEncoder, JsonDecoder}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The package’s README is its reference: &lt;code&gt;Json&lt;/code&gt; values, reading text with the line and column of any
error, writing compact, indented or ASCII text, the accessors that take a value apart, the streaming
&lt;code&gt;JsonReader&lt;/code&gt; over any &lt;code&gt;avin.io.Reader&lt;/code&gt;, and a program’s own types through &lt;code&gt;derives JsonEncoder, JsonDecoder&lt;/code&gt;. Those derivations are ordinary &lt;code&gt;derive&lt;/code&gt; templates in the package’s own module, found
as any library’s are (&lt;a href=&quot;/spec/derivation/&quot;&gt;derivation&lt;/a&gt;); the compiler knows nothing of JSON.&lt;/p&gt;
&lt;h2 id=&quot;import-avin-json&quot;&gt;&lt;code&gt;import avin.json&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;An import of &lt;code&gt;avin.json&lt;/code&gt;, whole, of a declaration in it, of a group or under another name, is an
error naming the package:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: JSON is the package `dev.avinlang.json`; add it to your dependencies
 --&amp;gt; script.avin:1:8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So is &lt;code&gt;import json&lt;/code&gt; in a program that has no module or declaration of its own named &lt;code&gt;json&lt;/code&gt; and does
not depend on the package:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: there is no module `json`; JSON is the package `dev.avinlang.json`; add it to your dependencies
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A program that does depend on it and writes &lt;code&gt;import json&lt;/code&gt; is told the module is missing, as for any
other name; one with a module of its own named &lt;code&gt;json&lt;/code&gt; imports that module as &lt;code&gt;json&lt;/code&gt; and may reach the
package beside it under another name, &lt;code&gt;import dev.avinlang.json as lib&lt;/code&gt;.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Generics and inference</title>
    <link href="https://avinlang.dev/spec/generics/"/>
    <id>https://avinlang.dev/spec/generics/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Reified, monomorphized generics with bounds and declaration-site variance; constructor parameters and the standard Functor and Monad traits; local type inference with subtyping.</summary>
    <content type="html">&lt;h2 id=&quot;generic-declarations&quot;&gt;Generic declarations&lt;/h2&gt;
&lt;p&gt;Functions, &lt;code&gt;data&lt;/code&gt;, classes, traits and &lt;code&gt;impl&lt;/code&gt;s take type parameters in square brackets:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;largest[T: Ord](xs: List[T]) -&amp;gt; Option[T] = …

class Cache[K: Hash, V](capacity: int)

data Result[+T, +E]
  Ok(value: T)
  Err(error: E)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;bounds&quot;&gt;Bounds&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;[T: Bound]&lt;/code&gt; requires &lt;code&gt;T&lt;/code&gt; to conform to &lt;code&gt;Bound&lt;/code&gt;, which may be a trait or a class; &lt;code&gt;[T: A &amp;amp; B]&lt;/code&gt; requires
both, and &lt;code&gt;[T: A &amp;amp; B &amp;amp; C]&lt;/code&gt; all three. A bound declared on a type applies everywhere that type’s parameters appear. An unbounded &lt;code&gt;T&lt;/code&gt;
may be stored, passed and returned; using an operator, a method or a field on it needs the bound that
provides it. Errors are reported at the generic definition, not at an instantiation.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Ordered
  less(other: Self) -&amp;gt; bool
  greater(other: Self) -&amp;gt; bool = other.less(self)

max[T: Ordered](a: T, b: T) -&amp;gt; T = if a.less(b) then b else a

class SortedPair[T: Ordered](first: T, second: T)
  high() -&amp;gt; T = max(first, second)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A value of a bounded &lt;code&gt;T&lt;/code&gt; has the members of its bounds&lt;/strong&gt;: their methods, those of the traits
they require, a trait’s &lt;code&gt;val&lt;/code&gt;s and a class bound’s visible fields, which are read as on an
instance of the class and, where &lt;code&gt;var&lt;/code&gt;, assigned the same way. A call on it is checked against
the bound’s signature with the bound’s &lt;code&gt;Self&lt;/code&gt; as &lt;code&gt;T&lt;/code&gt;, and takes every form a method call takes:
overloads, default and named arguments, infix calls, the method’s own type arguments, and the
method as a value. A member no bound has is an error naming the bounds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value of &lt;code&gt;T&lt;/code&gt; is a value of each of its bounds’ types&lt;/strong&gt;, where that type is a type: it passes
where a &lt;code&gt;Shape&lt;/code&gt; is expected when &lt;code&gt;T: Shape&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each type argument conforms to its parameter’s bounds&lt;/strong&gt;, whether written or inferred, and on
types written in declarations as at calls: a class or object through its header, its superclass
and impls, a &lt;code&gt;data&lt;/code&gt; type through its impls, a trait type to itself and the traits it requires, and
a type parameter through its own bounds. The error names the argument, the bound and the
parameter. A bound’s type arguments are inferred from the argument, as &lt;code&gt;A&lt;/code&gt; in
&lt;code&gt;drain[S: Source[A], A](s: S)&lt;/code&gt; is from the source passed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A bound is a trait or a class&lt;/strong&gt;, and may name the declaration’s other parameters. A trait whose
methods mention &lt;code&gt;Self&lt;/code&gt; is named only here, and in an impl’s header. A function’s or a method’s own
type parameter may also be bounded by a &lt;a href=&quot;#bounds-by-a-type-parameter&quot;&gt;type parameter&lt;/a&gt; declared
before it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Several bounds are joined with &lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/strong&gt;, the one spelling, wherever type parameters are declared:
on functions, methods, classes, data types, traits, actors and impl headers
(&lt;code&gt;impl[T: Ord &amp;amp; Display] Display for Box[T]&lt;/code&gt;), after a lower bound too (&lt;code&gt;[W &amp;gt;: T: Display &amp;amp; Ord]&lt;/code&gt;).
&lt;code&gt;+&lt;/code&gt; between bounds is an error that says to write &lt;code&gt;&amp;amp;&lt;/code&gt;. Each operand is a trait or a class, an
instance of a generic trait among them (&lt;code&gt;[S: Source[A] &amp;amp; Named, A]&lt;/code&gt;); &lt;strong&gt;at most one is a class&lt;/strong&gt;,
the others traits, since a class extends one superclass, so a second class is an error naming
both, even a subclass of the first, whose bound alone says the same. &lt;strong&gt;Each is written once&lt;/strong&gt;: the
same trait at the same type arguments twice is an error, and &lt;code&gt;Make[int] &amp;amp; Make[long]&lt;/code&gt; are two
bounds. The order of the operands means nothing: &lt;code&gt;[T: A &amp;amp; B]&lt;/code&gt; and &lt;code&gt;[T: B &amp;amp; A]&lt;/code&gt; admit the same
arguments and give &lt;code&gt;T&lt;/code&gt; the same members.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The members of every operand are the parameter’s&lt;/strong&gt;, as if each were its only bound. Methods of
one name from two bounds are overloads of each other, chosen by parameter types as any overloads
are: with &lt;code&gt;say(n: int)&lt;/code&gt; from one and &lt;code&gt;say(s: string)&lt;/code&gt; from the other, &lt;code&gt;x.say(1)&lt;/code&gt; and &lt;code&gt;x.say(&amp;quot;a&amp;quot;)&lt;/code&gt;
each call one. Two of the same parameter types make a call that both accept ambiguous, an error
at the generic definition naming both methods; it is not an error to write the bounds, only to
make the call. A type argument meets every operand, and the error for one that misses names the
bound it misses.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;A &amp;amp; B&lt;/code&gt; is not a type&lt;/strong&gt;: an intersection is written only as a type parameter’s bounds, so a
parameter, a field, a &lt;code&gt;val&lt;/code&gt;, a result, a type argument or a lower bound written &lt;code&gt;Named &amp;amp; Sized&lt;/code&gt; is
an error, which shows the form to write instead, &lt;code&gt;[T: Named &amp;amp; Sized](x: T)&lt;/code&gt;. A value that is both
is reached through such a parameter, whose instances call each type’s methods directly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl’s parameters are its type’s&lt;/strong&gt; where it names them as the type’s arguments, in order
(&lt;code&gt;impl[T] Ord for Box[T]&lt;/code&gt;), and have the bounds the type declares. &lt;strong&gt;An impl of a
trait may bound them further&lt;/strong&gt;, making the type conform only for the type arguments that meet the
bounds: with &lt;code&gt;impl[T: Ord] Ord for Box[T]&lt;/code&gt;, a &lt;code&gt;Box[int]&lt;/code&gt; is an &lt;code&gt;Ord&lt;/code&gt; and a &lt;code&gt;Box[Plain]&lt;/code&gt; is not. Each
type argument written or inferred for a bound is held to them, and the impl’s methods have the
bounds’ members. Such an impl is of a data type or a class, and of any trait. Where the trait is
also a type, a &lt;code&gt;Box[int]&lt;/code&gt; converts to &lt;code&gt;Display&lt;/code&gt; and a &lt;code&gt;Box[Plain]&lt;/code&gt; does not, also as a covariant
type argument (&lt;code&gt;List[Box[Plain]]&lt;/code&gt; is no &lt;code&gt;List[Display]&lt;/code&gt;); a &lt;code&gt;d: Display&lt;/code&gt; type pattern on an &lt;code&gt;Any&lt;/code&gt;
matches only an instance that conforms; and the trait’s methods, the impl’s included, are called
on an instance only where it conforms, in the type’s own methods too, where its parameters have
only the bounds the type declares. Inside generic code, &lt;code&gt;Box[T]&lt;/code&gt; conforms where &lt;code&gt;T&lt;/code&gt;‘s bounds meet
the impl’s. An impl of &lt;code&gt;Eq&lt;/code&gt; or &lt;code&gt;Hash&lt;/code&gt; may be bounded only by them, since every type meets them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl of a trait may be for an instance of a generic type&lt;/strong&gt; rather than for the type at its
own parameters: &lt;code&gt;impl FromPg for Vector[byte]&lt;/code&gt;, or a partly applied one, &lt;code&gt;impl[K] Show for Map[K, int]&lt;/code&gt;, &lt;code&gt;impl[T] Show for Box[Option[T]]&lt;/code&gt;. The type conforms to the trait where it is such
an instance, seen through its superclasses, with its parts exactly the impl’s (a &lt;code&gt;Vector[Nothing]&lt;/code&gt;
is not a &lt;code&gt;Vector[byte]&lt;/code&gt; here); each of the impl’s parameters is part of the type, takes the part at
its place and is held to its bounds. The impl’s members, static ones included, are the type’s at
those instances, wherever an impl is found: called on a value or on the type
(&lt;code&gt;Vector[byte].fromPg(text)&lt;/code&gt;), through a bound, in a bound held where a type argument is written,
on a trait value, by a type pattern, and by a template walking a field. It belongs in the module of
the type or of the trait, as any impl of a trait does. &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Sendable&lt;/code&gt; and &lt;code&gt;Boundary&lt;/code&gt;
are a type’s at every instance alike, so their impls are for the type at its own parameters. An
impl of &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; for an instance of a data type is an impl of the trait like any
other, so the type has no automatic one at its other instances.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two impls of one trait never both hold of a type&lt;/strong&gt;: there is no “more specific wins”. An
instance impl beside the type’s own impl of the trait is allowed only where the instance misses
that impl’s bounds, and two instance impls only where no instance matches both. A missed bound
counts only if it is missed for good: where some module other than the impl’s own and the core
library could still write the impl meeting it (one able to name the bound and the type without
importing a module that imports it), the two impls overlap. The error names both impls, and the
module where one could arise.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;trait FromPg
  static fromPg(text: string) -&amp;gt; Option[Self]

impl FromPg for int
  static fromPg(text: string) -&amp;gt; Option[int] = text.toIntOption()

// `bytea`: the bytes themselves.
impl FromPg for Vector[byte]
  static fromPg(text: string) -&amp;gt; Option[Vector[byte]] = Some(text.bytes)

// An array: comma-separated elements. `byte` is no `FromPg`, so this impl never holds of a
// `Vector[byte]`, and the two do not overlap.
impl[T: FromPg] FromPg for Vector[T]
  static fromPg(text: string) -&amp;gt; Option[Vector[T]]
    var out: Vector[T] = []
    for part in text.split(&apos;,&apos;)
      T.fromPg(part) match
        Some(v) -&amp;gt; out = out :+ v
        None -&amp;gt; return None
    Some(out)

decode[T: FromPg](text: string) -&amp;gt; Option[T] = T.fromPg(text)

main()
  println(decode[Vector[byte]](&amp;quot;hi&amp;quot;).map(v -&amp;gt; v.length))
  println(decode[Vector[int]](&amp;quot;1,2,3&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Some(2)
Some([1, 2, 3])
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An impl without a trait may bound its parameters too&lt;/strong&gt;, adding its methods only for the type
arguments that meet the bounds: with &lt;code&gt;impl[T: Display] List[T]&lt;/code&gt;, a &lt;code&gt;List[int]&lt;/code&gt; has &lt;code&gt;mkString&lt;/code&gt; and a
&lt;code&gt;List[Plain]&lt;/code&gt; does not. Calling such a method, or taking it as a value, on an instance that misses
a bound is an error naming the bound; a subclass has the methods at the type arguments it gives
its superclass; in generic code, &lt;code&gt;List[U]&lt;/code&gt; has them where &lt;code&gt;U&lt;/code&gt;‘s bounds meet the impl’s. Inside the
impl its parameters have the bounds’ members. Its methods overload the type’s other methods by
parameter types, as any method does, so two of the same parameter types are an error even where
their bounds could never both hold.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl without a trait may add to a type built from its parameters&lt;/strong&gt;, as
&lt;code&gt;impl[T] Option[Option[T]]&lt;/code&gt; or &lt;code&gt;impl[A: Ord, B] Seq[(A, B)]&lt;/code&gt;. Its parameters are not the type’s
but its own, learned at each call by matching the receiver’s static type against the type it
names, then held to their bounds; &lt;a href=&quot;/spec/declarations/#impl&quot;&gt;declarations&lt;/a&gt; has the matching rule.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call through a bound is direct&lt;/strong&gt;: each instance calls the implementation of its own type
argument. Where the argument is a trait type or an open class, any conforming object may arrive,
and the call goes through the object’s method table as a call on that type does.&lt;/li&gt;
&lt;li&gt;The bounds of a method’s own type parameters are contravariant positions for its class’s
parameters, as its parameter types are.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operators on a bounded &lt;code&gt;T&lt;/code&gt; come from its bounds&lt;/strong&gt;: &lt;code&gt;a + b&lt;/code&gt; needs a bound that is &lt;code&gt;Add&lt;/code&gt; or
requires it, &lt;code&gt;a &amp;lt; b&lt;/code&gt; one that is &lt;code&gt;Ord&lt;/code&gt;, and &lt;code&gt;a == b&lt;/code&gt; one that is &lt;code&gt;Eq&lt;/code&gt; (&lt;code&gt;Ord&lt;/code&gt; requires &lt;code&gt;Eq&lt;/code&gt;). Every
type meets &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt;, so any type argument passes those bounds. In an instance at a built-in
type the operator is the machine’s operation, as written outside generic code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Integer&lt;/code&gt; is a closed bound&lt;/strong&gt;: its members are the integer types, every width, which the
compiler decides; no type implements it and no declaration names it after &lt;code&gt;:&lt;/code&gt;. It requires &lt;code&gt;Add&lt;/code&gt;,
&lt;code&gt;Sub&lt;/code&gt;, &lt;code&gt;Mul&lt;/code&gt;, &lt;code&gt;Div&lt;/code&gt;, &lt;code&gt;Rem&lt;/code&gt;, &lt;code&gt;Neg&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;, so &lt;code&gt;[T: Integer]&lt;/code&gt; has every
operator and both text forms. A value of such a &lt;code&gt;T&lt;/code&gt; converts to the other integer types and to
&lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt; and &lt;code&gt;char&lt;/code&gt; as an integer does (&lt;code&gt;long(x)&lt;/code&gt;), and a call of &lt;code&gt;T&lt;/code&gt; converts to it
(&lt;code&gt;T(n)&lt;/code&gt;, trapping when &lt;code&gt;n&lt;/code&gt; does not fit, as integers do; &lt;code&gt;T.wrap(n)&lt;/code&gt; keeps the low bits); each instance converts
at its width. &lt;code&gt;T.MinValue&lt;/code&gt; and &lt;code&gt;T.MaxValue&lt;/code&gt; are the limits of the instance’s width, of type &lt;code&gt;T&lt;/code&gt; and
folded to a constant in each instance (&lt;code&gt;-128&lt;/code&gt; and &lt;code&gt;127&lt;/code&gt; at &lt;code&gt;i8&lt;/code&gt;); they read wherever &lt;code&gt;T&lt;/code&gt; is in
scope, a default argument’s value included, and a type parameter without the &lt;code&gt;Integer&lt;/code&gt; bound has
no limits. The bitwise operators &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; also work on such a &lt;code&gt;T&lt;/code&gt;, both
operands of type &lt;code&gt;T&lt;/code&gt; (&lt;code&gt;x &amp;gt;&amp;gt; T(1)&lt;/code&gt;), as the machine’s operators at each instance’s width; a &lt;code&gt;T&lt;/code&gt;
with any other bound has them only as methods of those names. So do the wrapping operators &lt;code&gt;+%&lt;/code&gt;,
&lt;code&gt;-%&lt;/code&gt;, &lt;code&gt;*%&lt;/code&gt; and the saturating &lt;code&gt;+|&lt;/code&gt;, &lt;code&gt;-|&lt;/code&gt;, &lt;code&gt;*|&lt;/code&gt; (and their compound forms), which a &lt;code&gt;T&lt;/code&gt; with any other
bound lacks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Numeric&lt;/code&gt; is the numbers’ bound&lt;/strong&gt;: every integer width and &lt;code&gt;real&lt;/code&gt; meet it, the integers
because &lt;code&gt;Integer&lt;/code&gt; requires it. It requires &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Sub&lt;/code&gt;, &lt;code&gt;Mul&lt;/code&gt;, &lt;code&gt;Div&lt;/code&gt;, &lt;code&gt;Rem&lt;/code&gt;, &lt;code&gt;Neg&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;,
&lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;, so &lt;code&gt;[T: Numeric]&lt;/code&gt; has the five arithmetic operators, negation, the
comparisons, both text forms and the identities &lt;code&gt;T.zero()&lt;/code&gt; and &lt;code&gt;T.one()&lt;/code&gt;; and it declares
&lt;code&gt;toReal -&amp;gt; real&lt;/code&gt;, the value as a &lt;code&gt;real&lt;/code&gt; (exact for an integer up to 2⁵³ in magnitude, the nearest
&lt;code&gt;real&lt;/code&gt; beyond). In each instance an operator is the instance’s own: integer overflow and integer
division by zero trap, a &lt;code&gt;real&lt;/code&gt; divides by zero to an infinity. A &lt;code&gt;T&lt;/code&gt; bounded only by &lt;code&gt;Numeric&lt;/code&gt; has
nothing integer-only: no conversion by a call (&lt;code&gt;T(n)&lt;/code&gt;, &lt;code&gt;real(x)&lt;/code&gt;; &lt;code&gt;x.toReal&lt;/code&gt; converts), no limits,
no bitwise or wrapping operators and no integer methods, and it does not meet &lt;code&gt;Integer&lt;/code&gt;. Unlike
&lt;code&gt;Integer&lt;/code&gt; it is open: a type of a program’s own that implements the traits it requires and
&lt;code&gt;toReal&lt;/code&gt; is a number too, as a rational type is.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;mean[T: Numeric](xs: Vector[T]) -&amp;gt; real = xs.sum.toReal / real(xs.length)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;digits[T: Integer](x: T) -&amp;gt; int
  var n = 1
  var rest = x / T(10)
  while rest != T(0)
    rest = rest / T(10)
    n += 1
  n
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The core library implements a trait for every integer width at once&lt;/strong&gt; with an impl over a
type parameter bounded by &lt;code&gt;Integer&lt;/code&gt; alone: &lt;code&gt;impl[T: Integer] Display for T&lt;/code&gt;. Only the core library
writes such an impl, and only with &lt;code&gt;Integer&lt;/code&gt;; a trait it implements this way has no other impl for
any width, and a program implements none of the core library’s traits for an integer type, since
neither is declared in its module. A program’s own trait may be implemented for one width
(&lt;code&gt;impl Sized for i5&lt;/code&gt;), and that width then has both.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;lower-bounds&quot;&gt;Lower bounds&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;[W &amp;gt;: T]&lt;/code&gt; requires every type argument for &lt;code&gt;W&lt;/code&gt; to be a supertype of &lt;code&gt;T&lt;/code&gt;. It is how a covariant type
takes a value of its own parameter in: a &lt;code&gt;Map[K, +V]&lt;/code&gt; cannot have &lt;code&gt;updated(key: K, value: V)&lt;/code&gt;, since
&lt;code&gt;V&lt;/code&gt; would sit where a value is passed in, but it can have&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Bag[K, +V]
  put[W &amp;gt;: V](key: K, value: W) -&amp;gt; Bag[K, W]

data Chain[+A]
  Link(head: A, tail: Chain[A])
  End

impl[A] Chain[A]
  prepended[W &amp;gt;: A](x: W) -&amp;gt; Chain[W] = Link(x, self)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Only a function’s or a method’s own type parameters have a lower bound&lt;/strong&gt;: those of a function,
of a trait’s, class’s or impl’s method, and of an extension’s method. A type’s parameters and an
impl’s take none. A lower bound is any type, and may name the declaration’s other parameters; a
chain of lower bounds may not lead back to the parameter it starts from.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is written first, then any bounds&lt;/strong&gt;: &lt;code&gt;[W &amp;gt;: T: Display]&lt;/code&gt; is a supertype of &lt;code&gt;T&lt;/code&gt; that conforms
to &lt;code&gt;Display&lt;/code&gt;. A value of &lt;code&gt;W&lt;/code&gt; has the bounds’ members, as any bounded parameter’s does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value of the lower bound is a value of the parameter, with no conversion&lt;/strong&gt;: inside
&lt;code&gt;prepended&lt;/code&gt;, &lt;code&gt;self&lt;/code&gt; is a &lt;code&gt;Chain[A]&lt;/code&gt; and so a &lt;code&gt;Chain[W]&lt;/code&gt;, and an &lt;code&gt;A&lt;/code&gt; is a &lt;code&gt;W&lt;/code&gt;. Each type argument
is held to it at the call: the bound must be the argument, or be seen as it as a covariant part is
(both references, as &lt;a href=&quot;#variance&quot;&gt;variance&lt;/a&gt; requires). So a &lt;code&gt;long&lt;/code&gt; bound admits &lt;code&gt;long&lt;/code&gt; and no
&lt;code&gt;Any&lt;/code&gt;, and &lt;code&gt;longs.prepended[Any](3)&lt;/code&gt; is an error naming the bound.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inference starts from the bound&lt;/strong&gt;: the type argument is the join of the lower bound and the
arguments a value is read from, so &lt;code&gt;cats.prepended(dog)&lt;/code&gt; is a &lt;code&gt;Chain[Animal]&lt;/code&gt;, &lt;code&gt;cats.prepended(cat)&lt;/code&gt;
stays a &lt;code&gt;Chain[Cat]&lt;/code&gt;, and a literal takes the bound’s type (&lt;code&gt;longs.prepended(3)&lt;/code&gt; is a
&lt;code&gt;Chain[long]&lt;/code&gt;). Where the bound and the arguments are references with no nearer common type, the
join is &lt;code&gt;Any&lt;/code&gt;, the top: &lt;code&gt;cats.prepended(&amp;quot;hello&amp;quot;)&lt;/code&gt; is a &lt;code&gt;Chain[Any]&lt;/code&gt;. Two value types still have no
join. A delayed (by-name) argument widens it as any other argument does, so on a map of cats
&lt;code&gt;getOrElse(key, dog)&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;. A written type argument is held to the bound. The expected
type decides a type argument only where it admits the bound; otherwise the argument is inferred as
if nothing were expected and the result then passed as any value is, so &lt;code&gt;m.getOrElse(k, &amp;quot;none&amp;quot;)&lt;/code&gt;
on a map of strings, passed where a &lt;code&gt;Display&lt;/code&gt; is expected, takes &lt;code&gt;W&lt;/code&gt; as &lt;code&gt;string&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An override writes the overridden method’s lower bound, or none&lt;/strong&gt;: it may assume no more of its
type arguments than the method it overrides does. Calls through a trait dispatch as any generic
trait method’s do.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;bounds-by-a-type-parameter&quot;&gt;Bounds by a type parameter&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;[J: I]&lt;/code&gt;, where &lt;code&gt;I&lt;/code&gt; is a type parameter in scope, requires every type argument for &lt;code&gt;J&lt;/code&gt; to be a subtype
of the one for &lt;code&gt;I&lt;/code&gt;. It is the twin of the &lt;a href=&quot;#lower-bounds&quot;&gt;lower bound&lt;/a&gt;: where &lt;code&gt;[W &amp;gt;: T]&lt;/code&gt; lets a
covariant type take a value of its parameter in, &lt;code&gt;[J: I]&lt;/code&gt; lets a contravariant one narrow the values
it reads. A &lt;code&gt;Rule[-I: Reader, +T]&lt;/code&gt; reads any &lt;code&gt;I&lt;/code&gt;; joined with a rule that reads only an &lt;code&gt;Input&lt;/code&gt;, the
join reads an &lt;code&gt;Input&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;abstract class Reader(val length: int)
  var offset = 0

class Input(val source: string): Reader(source.byteLength)

class Rule[-I: Reader, +T](val run: I -&amp;gt; Option[T])

impl[I: Reader, T] Rule[I, T]
  |[J: I](other: -&amp;gt; Rule[J, T]) -&amp;gt; Rule[J, T] = Rule(input -&amp;gt;
    val start = input.offset
    run(input) match
      Some(a) -&amp;gt; Some(a)
      None -&amp;gt;
        input.offset = start
        other.run(input))
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Only a function’s or a method’s own type parameters are bounded by a type parameter&lt;/strong&gt;, as only
they have a lower bound. The bounding one is the enclosing type’s or impl’s, or one declared
earlier in the same list (&lt;code&gt;[A: Named, B: A]&lt;/code&gt;); a later one is an error that shows the order to
write, so a chain of such bounds never leads back to where it starts, and &lt;code&gt;[A: B, B: A]&lt;/code&gt; is refused
at its first bound. A parameter has one at most, and may have trait and class bounds beside it
(&lt;code&gt;[B: A &amp;amp; Loud]&lt;/code&gt;). A constructor parameter, &lt;code&gt;F[_]&lt;/code&gt;, bounds nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value of the parameter is a value of the bounding one, with no conversion&lt;/strong&gt;: inside &lt;code&gt;|&lt;/code&gt;, an
&lt;code&gt;input&lt;/code&gt; of type &lt;code&gt;J&lt;/code&gt; is passed to &lt;code&gt;run&lt;/code&gt;, which takes an &lt;code&gt;I&lt;/code&gt;, and &lt;code&gt;self&lt;/code&gt;, a &lt;code&gt;Rule[I, T]&lt;/code&gt;, is a
&lt;code&gt;Rule[J, T]&lt;/code&gt;. It has the bounding parameter’s bounds and their members (&lt;code&gt;input.offset&lt;/code&gt;, through
&lt;code&gt;Reader&lt;/code&gt;), and through a chain, each one’s further along: in &lt;code&gt;[A: Named, B: A, C: B]&lt;/code&gt; a &lt;code&gt;C&lt;/code&gt; is a &lt;code&gt;B&lt;/code&gt;
and an &lt;code&gt;A&lt;/code&gt;, and has &lt;code&gt;Named&lt;/code&gt;‘s methods. Two branches yielding a &lt;code&gt;J&lt;/code&gt; and an &lt;code&gt;I&lt;/code&gt; agree on &lt;code&gt;I&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each type argument is held to it at the call&lt;/strong&gt;: the argument must be the bounding argument, or
be seen as it as a covariant part is (both references, as &lt;a href=&quot;#variance&quot;&gt;variance&lt;/a&gt; requires). So a
&lt;code&gt;Pen[Dog]&lt;/code&gt;‘s &lt;code&gt;swap[U: T]&lt;/code&gt; refuses a &lt;code&gt;Cat&lt;/code&gt;, a &lt;code&gt;Pen[Animal]&lt;/code&gt;‘s refuses an &lt;code&gt;int&lt;/code&gt;, and the error names
the argument, the type the bounding parameter is and both parameters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inference takes the narrower&lt;/strong&gt;: a type argument decided where a value is passed in, as &lt;code&gt;J&lt;/code&gt; is
by the &lt;code&gt;Rule[J, T]&lt;/code&gt; given for &lt;code&gt;other&lt;/code&gt;, is decided as the type given; where that type is not a
subtype of the bounding argument but the bounding argument is a subtype of it, the bounding argument
is taken instead, which the given value is also an instance of there. So &lt;code&gt;err[long](&amp;quot;no&amp;quot;) | digit()&lt;/code&gt;
(&lt;code&gt;I&lt;/code&gt; a &lt;code&gt;Reader&lt;/code&gt;, &lt;code&gt;other&lt;/code&gt; reading an &lt;code&gt;Input&lt;/code&gt;) and &lt;code&gt;digit() | success(4)&lt;/code&gt; (&lt;code&gt;I&lt;/code&gt; an &lt;code&gt;Input&lt;/code&gt;, &lt;code&gt;other&lt;/code&gt;
reading any &lt;code&gt;Reader&lt;/code&gt;) are both &lt;code&gt;Rule[Input, long]&lt;/code&gt;s. A bounding parameter nothing else decides is
decided as the argument of the parameter it bounds: &lt;code&gt;describe[A: Named, B: A](b: B)&lt;/code&gt; called with a
&lt;code&gt;Dog&lt;/code&gt; takes &lt;code&gt;A&lt;/code&gt; as &lt;code&gt;Dog&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is a position where a value is passed in&lt;/strong&gt;, as every bound of a method’s own parameter is
(&lt;a href=&quot;#variance&quot;&gt;variance&lt;/a&gt;): a &lt;code&gt;-I&lt;/code&gt; may bound one and a &lt;code&gt;+T&lt;/code&gt; may not. That mirrors the lower bound’s
rule, and for the same reason: a &lt;code&gt;Rule[Reader, T]&lt;/code&gt; seen as a &lt;code&gt;Rule[Input, T]&lt;/code&gt; is called with a &lt;code&gt;J&lt;/code&gt;
that is an &lt;code&gt;Input&lt;/code&gt;, which is a &lt;code&gt;Reader&lt;/code&gt;, so the bound the method was written against still holds;
a &lt;code&gt;Box[Dog]&lt;/code&gt; seen as a &lt;code&gt;Box[Animal]&lt;/code&gt; could be called with a &lt;code&gt;J&lt;/code&gt; that is a &lt;code&gt;Cat&lt;/code&gt;, which is no &lt;code&gt;Dog&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An override writes the overridden method’s bound, or none&lt;/strong&gt;, as for a lower bound: it may assume
no more of its type arguments than the method it overrides does.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reification&quot;&gt;Reification&lt;/h2&gt;
&lt;p&gt;Generics are monomorphized: each distinct set of type arguments produces its own code and layout.
&lt;code&gt;List[int]&lt;/code&gt; stores unboxed &lt;code&gt;int&lt;/code&gt;s. Every heap object’s header names its exact type, including type
arguments, so:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a type pattern such as &lt;code&gt;xs: List[string] -&amp;gt; …&lt;/code&gt; is checked against the object’s exact type: it
matches when that type is the pattern’s or a subtype of it, through &lt;a href=&quot;#variance&quot;&gt;variance&lt;/a&gt; too, so
a &lt;code&gt;List[Dog]&lt;/code&gt; held as an &lt;code&gt;Any&lt;/code&gt; matches &lt;code&gt;xs: List[Animal]&lt;/code&gt; and a &lt;code&gt;List[int]&lt;/code&gt; does not match
&lt;code&gt;xs: List[Any]&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;a function value’s header names its function type, so &lt;code&gt;f: ((Dog) -&amp;gt; Animal) -&amp;gt; …&lt;/code&gt; matches a
&lt;code&gt;(Animal) -&amp;gt; Dog&lt;/code&gt; held as an &lt;code&gt;Any&lt;/code&gt;, and a value of a class extending a function type, a &lt;code&gt;Vector[int]&lt;/code&gt;
among them, matches that function type;&lt;/li&gt;
&lt;li&gt;generic code can create an &lt;code&gt;Array[T]&lt;/code&gt; without any evidence parameter;&lt;/li&gt;
&lt;li&gt;there are no unchecked casts. A downcast is a &lt;code&gt;match&lt;/code&gt; with a type pattern.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Avin compiles the whole program at once. That is what makes this possible for &lt;strong&gt;generic methods on
traits&lt;/strong&gt; used dynamically (&lt;code&gt;it.map[B](f)&lt;/code&gt; where &lt;code&gt;it: Iterable[A]&lt;/code&gt;): the compiler knows every type
that implements the trait and every &lt;code&gt;B&lt;/code&gt; the program uses, and generates the dispatch for each.&lt;/p&gt;
&lt;p&gt;Trait-typed values give one shared copy of code where monomorphizing would be wasteful.&lt;/p&gt;
&lt;h3 id=&quot;polymorphic-recursion&quot;&gt;Polymorphic recursion&lt;/h3&gt;
&lt;p&gt;Because every list of type arguments gets its own copy, a program must need only finitely many of
them. &lt;strong&gt;Polymorphic recursion&lt;/strong&gt;, a cycle of generic code whose type arguments grow on every round,
needs infinitely many, and is a compile-time error naming the cycle:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;data Nest[T](x: T)

depth[T](x: T, n: int) -&amp;gt; int = if n == 0 then 0 else depth(Nest(x), n - 1)
// error: polymorphic recursion: each round of the cycle `depth` -&amp;gt; `depth` passes `Nest[T]`
// for `T`, so its type arguments grow without end and the code has no finite set of copies
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The cycle may run through any generic code: functions, methods, generic local functions, lambdas,
and calls through a trait or a bound, where a class’s implementation is reached with a larger
instance of the class. A type argument grows when it is built from the cycle’s own type parameter,
as &lt;code&gt;Nest[T]&lt;/code&gt;, &lt;code&gt;(T, T)&lt;/code&gt;, &lt;code&gt;Vector[T]&lt;/code&gt; or &lt;code&gt;(T) -&amp;gt; int&lt;/code&gt; are from &lt;code&gt;T&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Recursion whose type arguments do not grow is ordinary: &lt;code&gt;f[T]&lt;/code&gt; calling &lt;code&gt;f[T]&lt;/code&gt;, &lt;code&gt;f[A, B]&lt;/code&gt; calling
&lt;code&gt;f[B, A]&lt;/code&gt;, a call at a fixed type such as &lt;code&gt;f[int]&lt;/code&gt;, and a type that grows once outside any cycle all
have finitely many copies.&lt;/p&gt;
&lt;p&gt;A method an impl with bounds of its own adds, &lt;code&gt;impl[T: Ord] Ord for Box[T]&lt;/code&gt;, has copies only at the
type arguments that meet them. A cycle through it counts only the type arguments that may: a
&lt;code&gt;compare&lt;/code&gt; that builds a &lt;code&gt;Box[Plain[T]]&lt;/code&gt;, where &lt;code&gt;Plain&lt;/code&gt; has no &lt;code&gt;Ord&lt;/code&gt;, needs no &lt;code&gt;compare&lt;/code&gt; of that box
and compiles, while one building a &lt;code&gt;Box[Wide[T]]&lt;/code&gt; of an ordered &lt;code&gt;Wide&lt;/code&gt; grows without end and is
rejected. A type argument whose outermost type is not known where it reaches the impl, such as a
part taken apart from a larger type, is counted as one that may.&lt;/p&gt;
&lt;p&gt;A data type naming itself at a larger instance in its fields, a &lt;strong&gt;nested data type&lt;/strong&gt; such as&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;data Tree[T]
  Leaf(value: T)
  Deeper(inner: Tree[Nest[T]])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;is rejected the same way, at the type: every data type compares, hashes and shows its values field
by field, and each of those needs a copy for every depth. The larger instance may sit inside another
type, as &lt;code&gt;inner: Option[Tree[List[T]]]&lt;/code&gt; does, or reach back through a second data type; the error
names the cycle of types. A type naming itself at its own type arguments, however wrapped, as
&lt;code&gt;rest: Option[Chain[T]]&lt;/code&gt;, &lt;code&gt;kids: Vector[Rose[T]]&lt;/code&gt; or a pair of types naming each other at &lt;code&gt;T&lt;/code&gt;, is
ordinary recursion: it compiles, and its derived and structural methods have one copy per instance.&lt;/p&gt;
&lt;h2 id=&quot;subtyping&quot;&gt;Subtyping&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;S &amp;lt;: T&lt;/code&gt; holds when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;S&lt;/code&gt; is a class whose superclass chain or declared traits include &lt;code&gt;T&lt;/code&gt;, or an &lt;code&gt;impl T for S&lt;/code&gt; exists;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;T&lt;/code&gt; is &lt;code&gt;Any&lt;/code&gt;, or &lt;code&gt;S&lt;/code&gt; is &lt;code&gt;Nothing&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;both are function types, with parameters contravariant and results covariant;&lt;/li&gt;
&lt;li&gt;both are instances of one generic type and each argument follows its declared variance (below);&lt;/li&gt;
&lt;li&gt;&lt;code&gt;T&lt;/code&gt; is a type parameter with a &lt;a href=&quot;#lower-bounds&quot;&gt;lower bound&lt;/a&gt; that &lt;code&gt;S&lt;/code&gt; is, or is a subtype of as a
covariant part is;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;S&lt;/code&gt; is a type parameter &lt;a href=&quot;#bounds-by-a-type-parameter&quot;&gt;bounded by&lt;/a&gt; the type parameter &lt;code&gt;T&lt;/code&gt;, or by
one that is;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;T&lt;/code&gt; is a &lt;a href=&quot;/spec/unions/#subtyping&quot;&gt;union&lt;/a&gt; with a member &lt;code&gt;S&lt;/code&gt; is a subtype of, or &lt;code&gt;S&lt;/code&gt; is a union
each of whose members is a subtype of &lt;code&gt;T&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A value type is never a subtype of a trait or of &lt;code&gt;Any&lt;/code&gt; without conversion. A value converts to a trait
type or &lt;code&gt;Any&lt;/code&gt; by &lt;strong&gt;boxing at a single site&lt;/strong&gt;, such as an argument or an assignment. Boxing never
happens inside a container: &lt;code&gt;List[int]&lt;/code&gt; is not a &lt;code&gt;List[Display]&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;variance&quot;&gt;Variance&lt;/h2&gt;
&lt;p&gt;Type parameters of &lt;code&gt;data&lt;/code&gt; types, classes and traits declare variance: &lt;code&gt;+T&lt;/code&gt; covariant, &lt;code&gt;-T&lt;/code&gt;
contravariant, plain &lt;code&gt;T&lt;/code&gt; invariant. A function’s or an &lt;code&gt;impl&lt;/code&gt;‘s type parameters take none; the
mark on a &lt;a href=&quot;#constructor-parameters&quot;&gt;constructor parameter’s hole&lt;/a&gt;, &lt;code&gt;F[+_]&lt;/code&gt;, is a demand on the
constructor passed, not a variance of the parameter.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Immutable collections are covariant: &lt;code&gt;List[+A]&lt;/code&gt;, &lt;code&gt;Map[K, +V]&lt;/code&gt;, &lt;code&gt;Option[+T]&lt;/code&gt;, &lt;code&gt;Either[+L, +R]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Mutable collections are invariant: &lt;code&gt;Array[T]&lt;/code&gt;, &lt;code&gt;Buffer[T]&lt;/code&gt;. A covariant mutable collection would
accept a store that is only checkable at run time.&lt;/li&gt;
&lt;li&gt;Variance applies where the arguments are reference types: &lt;code&gt;Any&lt;/code&gt;, strings, tuples, functions,
&lt;code&gt;data&lt;/code&gt; types, classes and traits. Because reference types share one representation (a pointer to
an object whose header carries its type), &lt;code&gt;List[Dog]&lt;/code&gt; is a &lt;code&gt;List[Animal]&lt;/code&gt; with no conversion at
all, and &lt;code&gt;List[string]&lt;/code&gt; is a &lt;code&gt;List[Any]&lt;/code&gt;. A value of a value type becomes an &lt;code&gt;Any&lt;/code&gt; or a trait only
by boxing, which never happens inside a container, so &lt;code&gt;List[int]&lt;/code&gt; is not a &lt;code&gt;List[Any]&lt;/code&gt;.
&lt;code&gt;Nothing&lt;/code&gt; is the exception: no value has it, so a covariant &lt;code&gt;Nothing&lt;/code&gt; argument is any type, and
&lt;code&gt;List[Nothing]&lt;/code&gt; is a &lt;code&gt;List[int]&lt;/code&gt; too.&lt;/li&gt;
&lt;li&gt;Tuple parts are covariant and function types take contravariant parameters and covariant
results, on the same terms: &lt;code&gt;(Animal) -&amp;gt; int&lt;/code&gt; is a &lt;code&gt;(Dog) -&amp;gt; int&lt;/code&gt;, and &lt;code&gt;() -&amp;gt; string&lt;/code&gt; is a
&lt;code&gt;() -&amp;gt; Any&lt;/code&gt;, but &lt;code&gt;() -&amp;gt; int&lt;/code&gt; is not. A lambda may declare its parameter that wide where the
narrower function is expected, &lt;code&gt;dogs.map((a: Animal) -&amp;gt; a.name)&lt;/code&gt;, and its body sees an &lt;code&gt;Animal&lt;/code&gt;;
&lt;code&gt;(x: Any) -&amp;gt; …&lt;/code&gt; where an &lt;code&gt;(int) -&amp;gt; …&lt;/code&gt; is expected is still an error.&lt;/li&gt;
&lt;li&gt;Where two branches yield instances of one generic type, they agree on the instance whose
covariant arguments are their arguments’ agreement and whose contravariant arguments are their
arguments’ meet, the one of the two that is a subtype of the other: &lt;code&gt;if c then Some(dog) else Some(cat)&lt;/code&gt; is an &lt;code&gt;Option[Animal]&lt;/code&gt;, and for &lt;code&gt;Sink[-T]&lt;/code&gt;, &lt;code&gt;if c then sinkOfAnimals else sinkOfDogs&lt;/code&gt; is a &lt;code&gt;Sink[Dog]&lt;/code&gt;, whichever is written first, and so is the &lt;code&gt;match&lt;/code&gt; or the loop
that yields them. &lt;code&gt;Nothing&lt;/code&gt; is below every type, so a &lt;code&gt;Sink[Nothing]&lt;/code&gt; and a &lt;code&gt;Sink[Dog]&lt;/code&gt; agree
on &lt;code&gt;Sink[Nothing]&lt;/code&gt;. Two arguments neither of which is a subtype of the other (a &lt;code&gt;Sink[Dog]&lt;/code&gt; and
a &lt;code&gt;Sink[string]&lt;/code&gt;) have a meet no type names, so their instances agree on no instance and fall
back as two classes do (below): to the trait they share, or to none. An invariant argument that
differs has no agreement either. A function type’s parameters follow the same rule as
contravariant arguments, its result as a covariant one: &lt;code&gt;(Animal) -&amp;gt; int&lt;/code&gt; and &lt;code&gt;(Dog) -&amp;gt; int&lt;/code&gt;
agree on &lt;code&gt;(Dog) -&amp;gt; int&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Branches that agree on a type that is not an instance of the fully known type expected of them
agree on the expected type when both are instances of it: a &lt;code&gt;Dog&lt;/code&gt; and a &lt;code&gt;Cat&lt;/code&gt; that are both
&lt;code&gt;Animal&lt;/code&gt;s and &lt;code&gt;Pet&lt;/code&gt;s agree on &lt;code&gt;Pet&lt;/code&gt; where a &lt;code&gt;Pet&lt;/code&gt; is expected. Where a branch is not an instance
of the expected type and neither is what they agree on, that branch is the error, named as the
one that misses it.&lt;/li&gt;
&lt;li&gt;Branches that agree on no type of their own agree on the type expected of them when both are
instances of it, also while its type arguments are still being inferred: in
&lt;code&gt;v.flatMap(n -&amp;gt; if n == 2 then List.empty[int]() else v)&lt;/code&gt; the lambda is expected to yield an
&lt;code&gt;Iterable[U]&lt;/code&gt;, so its branches agree on &lt;code&gt;Iterable[int]&lt;/code&gt;, and &lt;code&gt;U&lt;/code&gt; is &lt;code&gt;int&lt;/code&gt;. The same holds for
the arms of a &lt;code&gt;match&lt;/code&gt; and for a loop’s &lt;code&gt;else&lt;/code&gt; and its &lt;code&gt;break&lt;/code&gt;s.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The checker verifies each declared parameter’s positions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;+T&lt;/code&gt; may appear where a value is read out: a method’s result, an immutable field (every field
of a &lt;code&gt;data&lt;/code&gt; type, a &lt;code&gt;val&lt;/code&gt; or plain parameter of a class), the covariant arguments of a superclass
or trait the type conforms to.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;-T&lt;/code&gt; may appear where a value is passed in: a method’s parameter.&lt;/li&gt;
&lt;li&gt;The bounds of a method’s own type parameter are positions where a value is passed in; its
&lt;a href=&quot;#lower-bounds&quot;&gt;lower bound&lt;/a&gt; is one where a value is read out, so a &lt;code&gt;+T&lt;/code&gt; may be the lower bound
of a method’s parameter, &lt;code&gt;put[W &amp;gt;: V](key: K, value: W)&lt;/code&gt;, and a &lt;code&gt;-T&lt;/code&gt; may not. A &lt;code&gt;+V&lt;/code&gt; in the
parameter itself, &lt;code&gt;put(key: K, value: V)&lt;/code&gt;, is still an error. A &lt;a href=&quot;#bounds-by-a-type-parameter&quot;&gt;type parameter bounding
it&lt;/a&gt; is a bound like any other: a &lt;code&gt;-I&lt;/code&gt; may bound a method’s own
parameter, &lt;code&gt;|[J: I](other: -&amp;gt; Rule[J, T])&lt;/code&gt;, and a &lt;code&gt;+T&lt;/code&gt; may not.&lt;/li&gt;
&lt;li&gt;A mutable field is both, so neither may appear in a &lt;code&gt;var&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A function type’s parameters flip the position and its result keeps it; an argument of another
generic type takes the position as that type’s parameter’s variance turns it, and an invariant
parameter’s argument is a position where neither may appear. So a &lt;code&gt;+T&lt;/code&gt; may appear in a method
parameter &lt;code&gt;f: (T) -&amp;gt; int&lt;/code&gt;, and a &lt;code&gt;-T&lt;/code&gt; in a result &lt;code&gt;() -&amp;gt; (T) -&amp;gt; unit&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Private members are checked like public ones: an instance seen through a wider type still runs
them.&lt;/li&gt;
&lt;li&gt;The traits a &lt;code&gt;data&lt;/code&gt; type’s &lt;code&gt;impl&lt;/code&gt;s make it conform to are parents, like a class’s. The methods an
&lt;code&gt;impl&lt;/code&gt; adds to a &lt;code&gt;data&lt;/code&gt; type are not positions: they receive the value as whichever instance of
the type it is seen as, and data is immutable. The same holds for the methods an &lt;code&gt;impl&lt;/code&gt; adds to a
final class whose fields are all immutable, which are called directly at the type the receiver is
seen as; a class with a &lt;code&gt;var&lt;/code&gt; field keeps every method a position. So, too, for the methods an
&lt;code&gt;impl&lt;/code&gt; adds to a trait (&lt;code&gt;impl[T] Seq[T]&lt;/code&gt;), which reach the value only through the trait’s own
methods.&lt;/li&gt;
&lt;li&gt;The methods an &lt;code&gt;impl&lt;/code&gt; adds to an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class are positions like its own: they are
in its method table, so a call through a wider view runs the copy for the object’s own type
arguments, and an &lt;code&gt;abstract class Box[+T]&lt;/code&gt; adding &lt;code&gt;with(y: T) -&amp;gt; Box[T]&lt;/code&gt; would let a &lt;code&gt;Box[Dog]&lt;/code&gt;
seen as a &lt;code&gt;Box[Animal]&lt;/code&gt; make a &lt;code&gt;Box[Dog]&lt;/code&gt; holding a cat. Such a method takes an element through a
lower bound instead: &lt;code&gt;Vector[+T]&lt;/code&gt; declares &lt;code&gt;:+[W &amp;gt;: T](element: W) -&amp;gt; Vector[W]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static members are not positions of a class or a &lt;code&gt;data&lt;/code&gt; type, and neither is a conformance to a
trait whose members are all static&lt;/strong&gt; (with those of the traits it requires). A static member is
reached through a type, never through a value: on the type at the arguments the call names
(&lt;code&gt;Vector[Animal].newBuilder()&lt;/code&gt;, its own instance), or through a bound at the type argument’s own.
No value of such a trait exists (a trait with a static member is a bound and not a type), so
&lt;code&gt;abstract class Vector[+T]&lt;/code&gt; may state &lt;code&gt;impl[T] Buildable[T] for Vector[T]&lt;/code&gt; with
&lt;code&gt;static newBuilder() -&amp;gt; Builder[T, Vector[T]]&lt;/code&gt;. That a &lt;code&gt;Vector[Cat]&lt;/code&gt; is a &lt;code&gt;Vector[Animal]&lt;/code&gt; lets
one do nothing through &lt;code&gt;Buildable&lt;/code&gt;: a &lt;code&gt;Vector[Cat]&lt;/code&gt; is a &lt;code&gt;Buildable[Cat]&lt;/code&gt; and not a
&lt;code&gt;Buildable[Animal]&lt;/code&gt;, so &lt;code&gt;build[Vector[Cat], Animal](dog)&lt;/code&gt; is refused, and a bound &lt;code&gt;C: Buildable[A]&lt;/code&gt; calls &lt;code&gt;C&lt;/code&gt;‘s own impl at &lt;code&gt;C&lt;/code&gt;‘s own arguments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A bound whose type has a covariant or contravariant parameter does not reach the type’s static
members&lt;/strong&gt;, nor its conformances to traits whose members are all static: an argument meeting
&lt;code&gt;U: Box[Animal]&lt;/code&gt; may be a &lt;code&gt;Box[Cat]&lt;/code&gt;, whose &lt;code&gt;make&lt;/code&gt; takes cats, so &lt;code&gt;U.make(dog)&lt;/code&gt; is an error, and
&lt;code&gt;U&lt;/code&gt; is no &lt;code&gt;Make[Animal]&lt;/code&gt;. Bound &lt;code&gt;U&lt;/code&gt; by the trait declaring the member instead.&lt;/li&gt;
&lt;li&gt;A trait keeps both as positions. A trait’s own static member is a position of the trait’s
parameters, since a type conforming to &lt;code&gt;Take[Cat]&lt;/code&gt; conforms to &lt;code&gt;Take[Animal]&lt;/code&gt; through the trait’s
variance: &lt;code&gt;trait Take[+A]&lt;/code&gt; with &lt;code&gt;static take(x: A) -&amp;gt; Self&lt;/code&gt; is an error. A trait requiring a
trait whose members are all static keeps its arguments a position, and a conformance to a trait
with any member of a value (&lt;code&gt;static make(x: T) -&amp;gt; Self&lt;/code&gt; beside &lt;code&gt;size() -&amp;gt; int&lt;/code&gt;) is a position as
before.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An error names the parameter, its variance and the position: a &lt;code&gt;+T&lt;/code&gt; in the parameter &lt;code&gt;x&lt;/code&gt; of &lt;code&gt;put&lt;/code&gt;
is reported as a covariant type parameter appearing in a contravariant position.&lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;/spec/refined-variants/#variance&quot;&gt;refined variant&lt;/a&gt; may fix only an invariant parameter of its
type; a parameter it fixes or hides has no variance in its fields.&lt;/p&gt;
&lt;p&gt;Use-site variance (wildcards, existentials) is not part of Avin.&lt;/p&gt;
&lt;h2 id=&quot;inference&quot;&gt;Inference&lt;/h2&gt;
&lt;p&gt;Inference is a &lt;strong&gt;practical approximation of Hindley–Milner&lt;/strong&gt;: within a function body, types flow
both from arguments and from the expected type, and unknowns are solved by constraint, as in HM.
Declared signatures at function boundaries keep it predictable, fast and its errors local. Full HM,
with principal types and implicit generalization, is not the goal; inferring what a reader would
infer is.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Function parameter types are declared. Result types are inferred from the body, except in
recursive functions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Local &lt;code&gt;val&lt;/code&gt;/&lt;code&gt;var&lt;/code&gt; types, lambda parameter and result types, and type arguments at calls and
constructors are inferred from arguments &lt;strong&gt;and&lt;/strong&gt; from the expected type. Within one function body,
an inference variable may be settled by a later use.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A type argument of a call that neither its arguments nor its expected type decide stays unknown
until the end of the enclosing function body (a lambda’s body is part of it), and the first use
that needs it settles it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a branch it joins: &lt;code&gt;if c then Some(x) else None&lt;/code&gt; is an &lt;code&gt;Option[int]&lt;/code&gt;, as is a &lt;code&gt;match&lt;/code&gt; whose
other arms are, and a lambda’s &lt;code&gt;None&lt;/code&gt; takes the type of its other return paths;&lt;/li&gt;
&lt;li&gt;a store: &lt;code&gt;var best = None&lt;/code&gt; then &lt;code&gt;best = Some(3)&lt;/code&gt; makes &lt;code&gt;best&lt;/code&gt; an &lt;code&gt;Option[int]&lt;/code&gt;, from the body
or from a local function or lambda that assigns it;&lt;/li&gt;
&lt;li&gt;a use as a value of a known type: an argument, a value stored where its type is declared, an
operand of an arithmetic or comparison operator, or a value matched against a literal pattern.
&lt;code&gt;best match Some(b) if b &amp;gt;= i -&amp;gt; …&lt;/code&gt; settles &lt;code&gt;b&lt;/code&gt;, and with it &lt;code&gt;best&lt;/code&gt;, as &lt;code&gt;i&lt;/code&gt;‘s type.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A later use that disagrees with an earlier one is an error at the later use. An unknown still open
at the end of the body that the call’s parameters and result name only where a value is read out
(the whole type, a covariant argument, a tuple part, a function’s result) is &lt;code&gt;Nothing&lt;/code&gt;, the least
type: &lt;code&gt;val none = None&lt;/code&gt; alone is an &lt;code&gt;Option[Nothing]&lt;/code&gt;, &lt;code&gt;Left(1)&lt;/code&gt; an &lt;code&gt;Either[int, Nothing]&lt;/code&gt;, &lt;code&gt;Ok(1)&lt;/code&gt;
a &lt;code&gt;Result[int, Nothing]&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt; a &lt;code&gt;Vector[Nothing]&lt;/code&gt;, and &lt;code&gt;show(None)&lt;/code&gt; for &lt;code&gt;show[T](o: Option[T])&lt;/code&gt;
takes &lt;code&gt;T&lt;/code&gt; as &lt;code&gt;Nothing&lt;/code&gt;. Any other unknown still open is an error at the call that made it, asking
for the type to be written: &lt;code&gt;Buffer()&lt;/code&gt;, &lt;code&gt;Map.empty()&lt;/code&gt; (its &lt;code&gt;K&lt;/code&gt; is invariant), &lt;code&gt;{}&lt;/code&gt; (a &lt;code&gt;Set&lt;/code&gt;), and a
type argument nothing at the call names. A field or module value declared without a type has its
initializer’s type at once, since any function may read it, so &lt;code&gt;val none = None&lt;/code&gt; there is an
&lt;code&gt;Option[Nothing]&lt;/code&gt;.
A type argument held to a bound is decided at its call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Constraints are subtype constraints. A type variable collects lower and upper bounds and is solved
to the least type that satisfies them, so &lt;code&gt;if c then dog else cat&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;, and the branches
of a &lt;code&gt;match&lt;/code&gt; agree on their least upper bound.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A type argument of a call given several arguments takes their join, as branches do; the first
argument does not decide it alone. Each argument whose type mentions it where a value is read out
(the whole parameter, a covariant argument of a generic type, a tuple part, a function’s result)
is a lower bound, so with nothing expected &lt;code&gt;cat :: dogs&lt;/code&gt; is a &lt;code&gt;List[Animal]&lt;/code&gt;, &lt;code&gt;pair(cat, dog)&lt;/code&gt;
for &lt;code&gt;pair[T](a: T, b: T)&lt;/code&gt; takes &lt;code&gt;Animal&lt;/code&gt;, and &lt;code&gt;firstOf(Some(cat), Some(dog))&lt;/code&gt; takes it too. An
expected type decides the type argument before the arguments do, except where the result names it
as a contravariant argument of a generic type: there the expected type bounds it only from below
(a &lt;code&gt;Sink[T]&lt;/code&gt; is a &lt;code&gt;Sink[Nothing]&lt;/code&gt; whatever &lt;code&gt;T&lt;/code&gt; is), so the arguments decide it, and the expected
type only where they leave it open. &lt;code&gt;watch(spawn(Worker()), …)&lt;/code&gt;, whose parameter is an
&lt;code&gt;ActorRef[Nothing]&lt;/code&gt;, takes &lt;code&gt;M&lt;/code&gt; from the &lt;code&gt;Behaviour&lt;/code&gt; passed to &lt;code&gt;spawn&lt;/code&gt;. An invariant or contravariant
use (an argument of &lt;code&gt;Box[T]&lt;/code&gt; for an invariant &lt;code&gt;T&lt;/code&gt;, a lambda’s parameter) decides it for good, as
the type the lower bounds so far fit, and a later argument must be an instance of that. An argument
is held to its parameter by each type argument’s variance: at a contravariant argument of a
generic type or a function type’s parameter it may name a supertype of what the parameter names,
so &lt;code&gt;take(x)&lt;/code&gt; for &lt;code&gt;take[T](b: Box[B, T])&lt;/code&gt;, &lt;code&gt;Box[-I, +T]&lt;/code&gt;, accepts an &lt;code&gt;x: Box[A, int]&lt;/code&gt; where &lt;code&gt;B&lt;/code&gt; is an
&lt;code&gt;A&lt;/code&gt;, and takes &lt;code&gt;T&lt;/code&gt; as &lt;code&gt;int&lt;/code&gt;; a type argument named there is decided as the type the argument
gives, the most it may be. A number
literal takes the type the other arguments decide, and so does one inside a value built around
it, a collection literal, a tuple or a call such as &lt;code&gt;Some(1)&lt;/code&gt;, wherever it is written: with
&lt;code&gt;f() -&amp;gt; Vector[long]&lt;/code&gt;, &lt;code&gt;assertEq(f(), [1, 2])&lt;/code&gt; and &lt;code&gt;assertEq(Some(1), someLong())&lt;/code&gt; are well typed.
Only the numbers are taken; the classes in the decided type are still widened by such an argument,
so &lt;code&gt;same(dogs, [Cat(2)])&lt;/code&gt; is a &lt;code&gt;Vector[Animal]&lt;/code&gt;; an invariant part of it, such as an &lt;code&gt;Array&lt;/code&gt;‘s
element, is taken whole. An expression of literals alone (&lt;code&gt;1_000_000_000_000 + 2001&lt;/code&gt;, &lt;code&gt;-(4 * 5)&lt;/code&gt;,
&lt;code&gt;if c then 0 else 6&lt;/code&gt;) takes the type the other arguments decide, the values built around literals
among them. Of two arguments that both hold literals, the
first written decides for the second, so &lt;code&gt;same((1, x), (x, 2))&lt;/code&gt; with &lt;code&gt;x: long&lt;/code&gt; is an error. Two value types have no join, so
&lt;code&gt;pair(1, &amp;quot;one&amp;quot;)&lt;/code&gt; is an error naming both, unless &lt;code&gt;Any&lt;/code&gt; is expected.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The lambdas and &lt;code&gt;match&lt;/code&gt; functions of a call take their parameter types from what the other
arguments decide, so they are checked after them, and in turn among themselves: each time, the
first one in the call whose parameter types are known, declared by it or decided by the arguments
checked so far. So what a typed lambda decides reaches one written before it:
&lt;code&gt;both(match n -&amp;gt; n + 1, (x: int) -&amp;gt; x * 10)&lt;/code&gt; for &lt;code&gt;both[A, B](g: (A) -&amp;gt; B, f: (A) -&amp;gt; B)&lt;/code&gt;,
and &lt;code&gt;back(match s -&amp;gt; s.byteLength, (x: int) -&amp;gt; s&amp;quot;&amp;lt;$x&amp;gt;&amp;quot;)&lt;/code&gt; for &lt;code&gt;back[A, B](g: (B) -&amp;gt; A, f: (A) -&amp;gt; B)&lt;/code&gt;,
whose &lt;code&gt;match&lt;/code&gt; takes &lt;code&gt;B&lt;/code&gt; from the lambda’s result. Where none is known, the first one left is
checked and reports what it cannot infer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A lambda whose parameter types are known takes part in the tiers above by what it yields, as any
other argument does: one yielding a value with a type of its own is checked with the arguments
that hold no literal, after them, so a number literal beside it takes the type it decides. For
&lt;code&gt;pick[T](read: (string) -&amp;gt; Option[T], absent: T)&lt;/code&gt;, &lt;code&gt;pick(s -&amp;gt; s.toLongOption(), 0)&lt;/code&gt; takes
&lt;code&gt;T = long&lt;/code&gt;, whichever argument is written first, and &lt;code&gt;pick(s -&amp;gt; s.toRealOption(), 0)&lt;/code&gt; takes
&lt;code&gt;real&lt;/code&gt;. A lambda yielding a value built around a literal (&lt;code&gt;s -&amp;gt; Some(1)&lt;/code&gt;) or a literal alone
(&lt;code&gt;s -&amp;gt; 1&lt;/code&gt;) is checked in that tier, after the other arguments of it, and takes their numbers:
&lt;code&gt;yielding(s -&amp;gt; 1, long(5))&lt;/code&gt; is a &lt;code&gt;long&lt;/code&gt;. The value a lambda yields is the last item of its block,
and an &lt;code&gt;if&lt;/code&gt; or a &lt;code&gt;match&lt;/code&gt; yields in the lowest tier of its branches. A lambda that leaves its body
by &lt;code&gt;return&lt;/code&gt; or &lt;code&gt;?&lt;/code&gt;, and a &lt;code&gt;match&lt;/code&gt; function, are still checked after every other argument, since
such a body needs its result type known before it is checked.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Two classes join to their nearest common superclass. Where they have none, they join to the trait
they both conform to that every other trait they share is a parent of: a &lt;code&gt;Parrot&lt;/code&gt; and a
&lt;code&gt;Goldfish&lt;/code&gt; that are both &lt;code&gt;Pet: Named&lt;/code&gt; join to &lt;code&gt;Pet&lt;/code&gt;. Where they share several unrelated traits,
no one of them is chosen: the join is an error that names them, and the type is written, or
given by the expected type. Two instances of one generic type join at a contravariant argument
to the meet of the two arguments, where one is a subtype of the other (&lt;a href=&quot;#variance&quot;&gt;Variance&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Two tuples of as many parts join part by part, since a tuple’s parts are read out: with &lt;code&gt;x: long&lt;/code&gt;,
&lt;code&gt;same((dog, x), (cat, x))&lt;/code&gt; takes &lt;code&gt;(Animal, long)&lt;/code&gt;, as do &lt;code&gt;if c then (dog, x) else (cat, x)&lt;/code&gt; and
&lt;code&gt;[(dog, x), (cat, x)]&lt;/code&gt;, and so does a tuple inside a covariant argument (&lt;code&gt;Some((dog, x))&lt;/code&gt; and
&lt;code&gt;Some((cat, x))&lt;/code&gt; join to &lt;code&gt;Option[(Animal, long)]&lt;/code&gt;). A part joins only where its types do: an
invariant &lt;code&gt;(Array[Dog], long)&lt;/code&gt; and &lt;code&gt;(Array[Cat], long)&lt;/code&gt; have no join, nor have &lt;code&gt;(Dog, long)&lt;/code&gt; and
&lt;code&gt;(Cat, int)&lt;/code&gt;, nor tuples of different sizes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A number literal among values that agree on one type (the branches of an &lt;code&gt;if&lt;/code&gt;, the arms of a
&lt;code&gt;match&lt;/code&gt;, the elements of a collection literal, the keys or the values of a map literal) takes the
type the others decide, wherever it is written, as an argument’s literal does: &lt;code&gt;[long(1), 2]&lt;/code&gt; and
&lt;code&gt;[2, long(1)]&lt;/code&gt; are &lt;code&gt;Vector[long]&lt;/code&gt;, &lt;code&gt;[1.5, 2]&lt;/code&gt; is a &lt;code&gt;Vector[real]&lt;/code&gt;, &lt;code&gt;if c then 2 else big&lt;/code&gt; a &lt;code&gt;long&lt;/code&gt;
for &lt;code&gt;big: long&lt;/code&gt;, and &lt;code&gt;[Some(long(1)), Some(2)]&lt;/code&gt; a &lt;code&gt;Vector[Option[long]]&lt;/code&gt;. A value built around a
literal (&lt;code&gt;Some(2)&lt;/code&gt;, &lt;code&gt;(2, &amp;quot;b&amp;quot;)&lt;/code&gt;, &lt;code&gt;[2]&lt;/code&gt;) and an expression of literals alone (&lt;code&gt;2 * 3&lt;/code&gt;, &lt;code&gt;-5&lt;/code&gt;) do the
same; a &lt;code&gt;match&lt;/code&gt; arm does so where it is an expression of literals alone. A literal that does not
fit the type decided is an error (&lt;code&gt;[i8(1), 128]&lt;/code&gt;), and literals with no other value beside them
take the first one’s type, so &lt;code&gt;[1, 5000000000]&lt;/code&gt; is an error, as the &lt;code&gt;int&lt;/code&gt; decided by &lt;code&gt;1&lt;/code&gt; cannot
hold the second. Values that agree on no type are reported in the order they are written.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An argument of type &lt;code&gt;Nothing&lt;/code&gt; (a &lt;code&gt;break&lt;/code&gt;, a &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;fail(…)&lt;/code&gt;) decides no type argument, since
the call is never made: the other arguments and the expected type decide them as they would
alone, and one that only such an argument names is &lt;code&gt;Nothing&lt;/code&gt;. So &lt;code&gt;identity(break 42)&lt;/code&gt; and
&lt;code&gt;println(fail(&amp;quot;unreachable&amp;quot;))&lt;/code&gt; are well typed, while a &lt;code&gt;Nothing&lt;/code&gt; argument beside &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;&amp;quot;one&amp;quot;&lt;/code&gt;
reconciles neither with the other, nor answers for a bound they break.
Likewise a tuple or a collection literal with a part of type &lt;code&gt;Nothing&lt;/code&gt; is never made, and has
type &lt;code&gt;Nothing&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;None&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt;, &lt;code&gt;{}&lt;/code&gt; and &lt;code&gt;Map.empty&lt;/code&gt; take their type arguments from context. Where nothing determines
a type, the result is &lt;code&gt;Nothing&lt;/code&gt; where the type argument is only read out, as above, and otherwise
an error asking for an annotation; never a silent default to &lt;code&gt;Any&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;No value has type &lt;code&gt;Nothing&lt;/code&gt;, so an instance whose covariant argument is &lt;code&gt;Nothing&lt;/code&gt; is an instance
with any type there, a value type’s too: an &lt;code&gt;Option[Nothing]&lt;/code&gt; is an &lt;code&gt;Option[int]&lt;/code&gt; and an
&lt;code&gt;Either[int, Nothing]&lt;/code&gt; an &lt;code&gt;Either[int, string]&lt;/code&gt;, with no conversion, in a declared type, an
argument, a branch, and a type pattern alike.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Nothing is generalized implicitly: a local &lt;code&gt;val f = (x) -&amp;gt; x&lt;/code&gt; with no use that settles &lt;code&gt;x&lt;/code&gt; is an
error. Polymorphic functions are declared with type parameters.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Explicit type arguments may always be given: &lt;code&gt;parse[int](text)&lt;/code&gt;, &lt;code&gt;Map.empty[string, int]&lt;/code&gt;, or a
leading prefix with the rest inferred.&lt;/p&gt;
&lt;h2 id=&quot;higher-kinded-types&quot;&gt;Higher-kinded types&lt;/h2&gt;
&lt;p&gt;A type parameter may stand for a &lt;strong&gt;type constructor&lt;/strong&gt;: a generic type not yet given its arguments.
&lt;code&gt;F[_]&lt;/code&gt; is a parameter that takes one type argument, so &lt;code&gt;F[int]&lt;/code&gt; and &lt;code&gt;F[(A, B)]&lt;/code&gt; are types wherever
&lt;code&gt;F&lt;/code&gt; is in scope. Bounded by one of the &lt;a href=&quot;#functor-applicative-monad-traverse&quot;&gt;standard traits&lt;/a&gt;, one
function serves options, results, sequences and a program’s own types alike:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;pairUp[F[_]: Monad, A, B](fa: F[A], fb: F[B]) -&amp;gt; F[(A, B)] =
  for a in fa, b in fb yield (a, b)

data AgeError(text: string)

age(text: string) -&amp;gt; Result[int, AgeError] = text.toIntOption() match
  Some(n) -&amp;gt; Ok(n)
  None -&amp;gt; Err(AgeError(text))

main()
  println(pairUp(Some(1), Some(&amp;quot;one&amp;quot;)))
  println(pairUp([1, 2], [&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;]))
  println(pairUp(age(&amp;quot;30&amp;quot;), age(&amp;quot;41&amp;quot;)))
  println(pairUp(age(&amp;quot;30&amp;quot;), age(&amp;quot;old&amp;quot;)))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Some((1, one))
[(1, a), (1, b), (2, a), (2, b)]
Ok((30, 41))
Err(AgeError(old))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each call compiles its own copy, at &lt;code&gt;Option&lt;/code&gt;, at &lt;code&gt;Vector&lt;/code&gt; and at &lt;code&gt;Result[_, AgeError]&lt;/code&gt;, as any
generic call does.&lt;/p&gt;
&lt;h3 id=&quot;constructor-parameters&quot;&gt;Constructor parameters&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;F[_]&lt;/code&gt; declares a constructor parameter of one argument&lt;/strong&gt;, &lt;code&gt;F[_, _]&lt;/code&gt; one of two. It is declared
wherever a type parameter is: on a function, a method, a &lt;code&gt;data&lt;/code&gt; type, a class, a trait and an impl,
so &lt;code&gt;data Nested[F[_], A](inner: F[Option[A]])&lt;/code&gt; is a type. Its arguments are types, never
constructors: &lt;code&gt;F[_[_]]&lt;/code&gt; is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;F&lt;/code&gt; is written with exactly its number of arguments&lt;/strong&gt;, and is then a type: &lt;code&gt;F[A]&lt;/code&gt;,
&lt;code&gt;F[Vector[int]]&lt;/code&gt;. Written bare it is a constructor, which stands only where a constructor is taken:
a type argument for another constructor parameter of its arity (&lt;code&gt;pairUp[F, A, B](…)&lt;/code&gt;), and the
receiver of a static member (&lt;code&gt;F.pure(x)&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A hole may declare a variance&lt;/strong&gt;: &lt;code&gt;F[+_]&lt;/code&gt; takes only constructors covariant at that argument, and
in return an &lt;code&gt;F[Dog]&lt;/code&gt; is an &lt;code&gt;F[Animal]&lt;/code&gt; inside the declaration. A plain &lt;code&gt;_&lt;/code&gt; is invariant: &lt;code&gt;F[Dog]&lt;/code&gt;
and &lt;code&gt;F[Animal]&lt;/code&gt; are unrelated where nothing more is known of &lt;code&gt;F&lt;/code&gt;. The mark is a demand on the
argument, not a variance of the parameter, so a function’s and an impl’s constructor parameters
write it too; the parameter itself is invariant.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A hole may carry bounds&lt;/strong&gt;: &lt;code&gt;F[_: Sendable]&lt;/code&gt; is applied only to types that meet them, which is
checked wherever the declaration writes &lt;code&gt;F[X]&lt;/code&gt;, and in return it takes constructors whose
parameter at that hole has those bounds, &lt;code&gt;Future&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt; (&lt;code&gt;F[_: Ord]&lt;/code&gt;) among them. A
variance comes first, as for any parameter: &lt;code&gt;F[+_: Ord]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A constructor parameter’s bounds are &lt;a href=&quot;#constructor-traits&quot;&gt;constructor traits&lt;/a&gt;&lt;/strong&gt;:
&lt;code&gt;[F[_]: Monad]&lt;/code&gt;, &lt;code&gt;[F[_]: Traverse &amp;amp; Monad]&lt;/code&gt;. &lt;code&gt;[F[_]: Ord]&lt;/code&gt; is an error (“&lt;code&gt;Ord&lt;/code&gt; is a bound for a
type, and &lt;code&gt;F&lt;/code&gt; is a constructor”), as is &lt;code&gt;[T: Monad]&lt;/code&gt; (“&lt;code&gt;Monad&lt;/code&gt; is a bound for a constructor of one
argument; declare &lt;code&gt;T[_]&lt;/code&gt;“).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;constructor-arguments&quot;&gt;Constructor arguments&lt;/h3&gt;
&lt;p&gt;What a parameter &lt;code&gt;F[_]&lt;/code&gt; takes, written or inferred:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A generic type named bare&lt;/strong&gt; that has as many type parameters as &lt;code&gt;F&lt;/code&gt; takes holes: a data type, a
class or a trait, &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Seq&lt;/code&gt;. A tuple or a function type is no constructor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A partial application&lt;/strong&gt;: the type named with &lt;code&gt;_&lt;/code&gt; in place of the arguments left open, as many as
&lt;code&gt;F&lt;/code&gt; takes, the others written out: &lt;code&gt;Result[_, ParseError]&lt;/code&gt;, &lt;code&gt;Either[string, _]&lt;/code&gt;,
&lt;code&gt;Map[string, _]&lt;/code&gt;. The holes are filled in order, so &lt;code&gt;Result[_, ParseError]&lt;/code&gt; applied to &lt;code&gt;int&lt;/code&gt; is
&lt;code&gt;Result[int, ParseError]&lt;/code&gt;. A &lt;code&gt;_&lt;/code&gt; is a direct argument of the type named: &lt;code&gt;Option[List[_]]&lt;/code&gt; is an
error, since only the type’s own arguments are left open.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A generic alias&lt;/strong&gt; of as many parameters, whose expansion is a type with each parameter as one of
its direct arguments: with &lt;code&gt;type Parsed[T] = Result[T, ParseError]&lt;/code&gt;, &lt;code&gt;Parsed&lt;/code&gt; is the constructor
&lt;code&gt;Result[_, ParseError]&lt;/code&gt;. An alias whose parameter sits deeper, or twice, is no constructor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Another constructor parameter&lt;/strong&gt; of that arity, or a partial application of one with more
(&lt;code&gt;G[int, _]&lt;/code&gt; for a &lt;code&gt;G[_, _]&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A constructor is not a type.&lt;/strong&gt; A value, a field, a parameter, a result or a type pattern of type
&lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Result[_, string]&lt;/code&gt; is an error saying the type takes arguments; a type where a
constructor is taken is an error too (&lt;code&gt;pairUp[int, …]&lt;/code&gt;: “&lt;code&gt;int&lt;/code&gt; is a type; &lt;code&gt;F[_]&lt;/code&gt; takes a
constructor of one argument, such as &lt;code&gt;Option&lt;/code&gt;“), and so is one of the wrong arity (&lt;code&gt;Result&lt;/code&gt; for
&lt;code&gt;F[_]&lt;/code&gt;: “&lt;code&gt;Result&lt;/code&gt; takes two arguments and &lt;code&gt;F&lt;/code&gt; one; leave one open, as &lt;code&gt;Result[_, E]&lt;/code&gt;“).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Two constructors are one&lt;/strong&gt; when they name one type with the same arguments written out at the
same places: &lt;code&gt;Parsed&lt;/code&gt; and &lt;code&gt;Result[_, ParseError]&lt;/code&gt; are one constructor, and so one instance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A type’s bounds at a hole must be the hole’s&lt;/strong&gt;: a type whose parameter there is bounded, as
&lt;code&gt;TreeSet[A: Ord]&lt;/code&gt;‘s is, is a constructor only for a hole whose bounds imply that one (&lt;code&gt;F[_: Ord]&lt;/code&gt;),
never for a plain &lt;code&gt;_&lt;/code&gt;, which generic code may apply to any type. &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; are no obstacle,
since every type meets them. The arguments written out are held to the type’s bounds where they
are written, as any type argument is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An application of a constructor is a reference type&lt;/strong&gt;: its head is a data type, a class or a
trait, so an &lt;code&gt;F[A]&lt;/code&gt; passes as an &lt;code&gt;Any&lt;/code&gt; with no boxing in every instance.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;constructor-traits&quot;&gt;Constructor traits&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Functor[A]
  map[B](f: (A) -&amp;gt; B) -&amp;gt; Self[B]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A trait whose methods write &lt;code&gt;Self&lt;/code&gt; with type arguments is a constructor trait&lt;/strong&gt;: what implements it
is a constructor, and &lt;code&gt;Self[B]&lt;/code&gt; is that constructor applied to &lt;code&gt;B&lt;/code&gt;. The trait’s parameters are the
holes: &lt;code&gt;Self&lt;/code&gt; takes as many arguments as the trait has parameters, and a value of a conforming type
is a &lt;code&gt;Self[A]&lt;/code&gt;, &lt;code&gt;self&lt;/code&gt; among them.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Its parameters take no variance&lt;/strong&gt;, and bare &lt;code&gt;Self&lt;/code&gt; is an error in it. Like any trait whose
methods mention &lt;code&gt;Self&lt;/code&gt;, it is a bound and never a type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A bound on one of its parameters is the bound of that hole&lt;/strong&gt;: &lt;code&gt;trait SendableMonad[A: Sendable]&lt;/code&gt;
is the bound of an &lt;code&gt;F[_: Sendable]&lt;/code&gt;, and is implemented by constructors whose parameter there is
bounded by no more than &lt;code&gt;Sendable&lt;/code&gt;, an unbounded one among them (&lt;code&gt;Future[T]&lt;/code&gt;): the trait applies
the constructor only to types meeting the bound, so the conformance asks nothing of the type’s
parameter. A trait requiring it bounds its own parameter as it does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait requiring a constructor trait is one&lt;/strong&gt;, and names it at its own parameters, in order:
&lt;code&gt;trait Monad[A]: Applicative[A]&lt;/code&gt;. It may require a trait for types that bounds constructors, the
same way: &lt;code&gt;trait Traverse[A]: Functor[A], Foldable[A]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait for types whose members never name &lt;code&gt;Self&lt;/code&gt; beyond the receiver bounds constructors
too&lt;/strong&gt;, where it has parameters, no static member, and requires only such traits: &lt;code&gt;Foldable[A]&lt;/code&gt;
is one. A constructor conforms to it where each of its applications does with the trait’s
parameters at the holes, so &lt;code&gt;impl Foldable for Option&lt;/code&gt;, or any conformance stating
&lt;code&gt;Foldable[T]&lt;/code&gt; for an &lt;code&gt;Option[T]&lt;/code&gt;, makes &lt;code&gt;Option&lt;/code&gt; a constructor for &lt;code&gt;[F[_]: Foldable]&lt;/code&gt;, and a
value of &lt;code&gt;F[X]&lt;/code&gt; there has its members with &lt;code&gt;X&lt;/code&gt; for the trait’s parameters. It stays a trait for
types in every other place, so a &lt;code&gt;Foldable[int]&lt;/code&gt; is a type, and a type conforming to it at no
parameter of its own (&lt;code&gt;impl Foldable[int] for Ints&lt;/code&gt;) is no constructor of it. A trait naming
&lt;code&gt;Self&lt;/code&gt; otherwise (&lt;code&gt;same(other: Self)&lt;/code&gt;) or declaring a static member bounds types only, and one
writing &lt;code&gt;Self[X]&lt;/code&gt; is a constructor trait and bounds constructors only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A static member names no parameter of the trait&lt;/strong&gt;, since a call of it names only the
constructor: &lt;code&gt;static pure[X](value: X) -&amp;gt; Self[X]&lt;/code&gt;. It is called on a constructor, a bounded
parameter (&lt;code&gt;F.pure(1)&lt;/code&gt;), a type named bare (&lt;code&gt;Option.pure(1)&lt;/code&gt;) or a partial application
(&lt;code&gt;Result[_, string].pure(1)&lt;/code&gt;), each call direct. A constructor has the static members of the
constructor traits it implements at exactly the holes it leaves open, so &lt;code&gt;Result[int, _].pure&lt;/code&gt;
is an error, as is &lt;code&gt;F.pure&lt;/code&gt; where no bound of &lt;code&gt;F&lt;/code&gt; declares &lt;code&gt;pure&lt;/code&gt;; a value of &lt;code&gt;F[X]&lt;/code&gt; has none,
its static members being its constructor’s. Named without a call, &lt;code&gt;F.pure&lt;/code&gt; and &lt;code&gt;Option.pure&lt;/code&gt; are
function values.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its default bodies are compiled for each constructor that implements it&lt;/strong&gt;, as a call through a
bound is, so unlike other traits’ defaults they may call a static member on &lt;code&gt;Self&lt;/code&gt;:
&lt;code&gt;override map[B](f: (A) -&amp;gt; B) -&amp;gt; Self[B] = flatMap(a -&amp;gt; Self.pure(f(a)))&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value of &lt;code&gt;F[X]&lt;/code&gt;, for &lt;code&gt;F[_]&lt;/code&gt; bounded by the trait, has the trait’s members&lt;/strong&gt; with &lt;code&gt;Self&lt;/code&gt; as &lt;code&gt;F&lt;/code&gt;
and the trait’s parameters as &lt;code&gt;X&lt;/code&gt;, so &lt;code&gt;fa.map(f)&lt;/code&gt; is an &lt;code&gt;F[B]&lt;/code&gt;. A &lt;code&gt;for&lt;/code&gt; comprehension draws from
it by its bounds, &lt;a href=&quot;/spec/collections/#for-comprehensions&quot;&gt;nominally&lt;/a&gt;: the last generator needs
&lt;code&gt;Functor&lt;/code&gt;, an earlier one &lt;code&gt;Monad&lt;/code&gt; and a guard &lt;code&gt;Filter&lt;/code&gt;, so with &lt;code&gt;F[_]: Functor&lt;/code&gt; alone a second
generator is an error naming the bound it needs.&lt;/li&gt;
&lt;li&gt;A constructor trait of more parameters works the same way: &lt;code&gt;trait Bifunctor[A, B]&lt;/code&gt; writes
&lt;code&gt;Self[C, D]&lt;/code&gt;, is the bound of an &lt;code&gt;F[_, _]&lt;/code&gt;, and is implemented with two holes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;implementing-a-constructor-trait&quot;&gt;Implementing a constructor trait&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;impl[T, E] Monad[T] for Result[T, E]
  static pure[X](value: X) -&amp;gt; Result[X, E] = Ok(value)

impl Monad for Option
  static pure[X](value: X) -&amp;gt; Option[X] = Some(value)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The impl names the type’s parameters, in order, as an impl of a trait always does, and gives
the trait the ones it leaves open&lt;/strong&gt;: each trait argument is a different parameter of the type, and
those are the holes, the others written out. &lt;code&gt;impl[T, E] Monad[T] for Result[T, E]&lt;/code&gt; makes &lt;code&gt;Self&lt;/code&gt;
the constructor &lt;code&gt;Result[_, E]&lt;/code&gt;, and &lt;code&gt;impl[L, R] Monad[R] for Either[L, R]&lt;/code&gt; makes it
&lt;code&gt;Either[L, _]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Where the trait’s arguments are all the type’s parameters, in order, both may be left off&lt;/strong&gt;:
&lt;code&gt;impl Monad for Option&lt;/code&gt;, &lt;code&gt;impl Traverse for List&lt;/code&gt;. The type’s parameters are then in scope by the
names its declaration gives them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The written-out parameters may be bounded further&lt;/strong&gt;, making the constructor conform only where
they meet the bounds, as any impl may (&lt;code&gt;impl[T, E: Display] Monad[T] for Report[T, E]&lt;/code&gt;); the holes
take no bounds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A type implements a constructor trait once&lt;/strong&gt;, at one choice of holes: an &lt;code&gt;Either&lt;/code&gt; that is a
&lt;code&gt;Functor&lt;/code&gt; on its right is not one on its left. The conformance is the constructor’s own: a
subclass, or a type conforming to a trait that has one, does not inherit it, and is matched as the
type that does (&lt;a href=&quot;#inferring-a-constructor&quot;&gt;inference&lt;/a&gt;). It lives in the module of the trait or of
the type, as every conformance does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The type’s own methods implement the trait’s wherever the trait’s call is a call of them.&lt;/strong&gt; A
trait method is met by the type’s method of its name whose parameters take the trait method’s
parameter types with no conversion, whose own type parameters that call decides (a lower bound by
its bound, so &lt;code&gt;Result&lt;/code&gt;‘s &lt;code&gt;flatMap[U, F &amp;gt;: E]&lt;/code&gt; meets &lt;code&gt;Monad&lt;/code&gt;‘s &lt;code&gt;flatMap&lt;/code&gt; with &lt;code&gt;F&lt;/code&gt; as &lt;code&gt;E&lt;/code&gt;), whose
result is the trait’s or conforms to it, and which has no bound the trait’s method lacks. So
&lt;code&gt;List&lt;/code&gt;‘s &lt;code&gt;flatMap(f: (T) -&amp;gt; Iterable[U]) -&amp;gt; List[U]&lt;/code&gt; meets &lt;code&gt;flatMap[B](f: (A) -&amp;gt; List[B]) -&amp;gt; List[B]&lt;/code&gt;, and &lt;code&gt;impl Monad for List&lt;/code&gt; gives only &lt;code&gt;pure&lt;/code&gt;. A method of that name that does not meet it
is an error naming what it lacks (&lt;code&gt;TreeSet&lt;/code&gt;‘s &lt;code&gt;map&lt;/code&gt; bounds &lt;code&gt;B&lt;/code&gt; by &lt;code&gt;Ord&lt;/code&gt;), and so are two
overloads that both meet it; a method the type does not have is written in the impl, and is then
the type’s own (&lt;code&gt;Option&lt;/code&gt; gains &lt;code&gt;foldLeft&lt;/code&gt;). The methods that meet are the type’s own, never a
superclass’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call through the bound calls the meeting method directly&lt;/strong&gt; in each instance, at the type
arguments the meeting decided.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A program’s own type implements the family by giving &lt;code&gt;pure&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt;; &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;map2&lt;/code&gt; come
from &lt;code&gt;Monad&lt;/code&gt;‘s defaults:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Parser[A](run: (string) -&amp;gt; Option[(A, string)])

impl Monad for Parser
  static pure[X](value: X) -&amp;gt; Parser[X] = Parser(s -&amp;gt; Some((value, s)))

  flatMap[B](f: (A) -&amp;gt; Parser[B]) -&amp;gt; Parser[B] =
    Parser(s -&amp;gt; run(s).flatMap(match (a, rest) -&amp;gt; f(a).run(rest)))

pairUp[F[_]: Monad, A, B](fa: F[A], fb: F[B]) -&amp;gt; F[(A, B)] =
  for a in fa, b in fb yield (a, b)

val digit = Parser(s -&amp;gt; s.headOption.filter(c -&amp;gt; &apos;0&apos; &amp;lt;= c &amp;lt;= &apos;9&apos;).map(c -&amp;gt; (int(c) - int(&apos;0&apos;), s.drop(1))))

val twoDigits = pairUp(digit, digit).map(match (a, b) -&amp;gt; a * 10 + b)

main()
  println(twoDigits.run(&amp;quot;42!&amp;quot;))
  println(twoDigits.run(&amp;quot;4x&amp;quot;))
  println(Parser.pure(7).run(&amp;quot;rest&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Some((42, !))
None
Some((7, rest))
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;inferring-a-constructor&quot;&gt;Inferring a constructor&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A constructor parameter is inferred where an argument’s type or the expected type is an
application of it&lt;/strong&gt;, by matching &lt;code&gt;F[X]&lt;/code&gt; against that type, alongside the call’s other type
arguments and in the same tiers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;With a constructor-trait bound, the type’s conformance says which arguments are the holes&lt;/strong&gt;:
&lt;code&gt;Result&lt;/code&gt;‘s &lt;code&gt;Monad&lt;/code&gt; leaves &lt;code&gt;T&lt;/code&gt; open, so a &lt;code&gt;Result[int, AgeError]&lt;/code&gt; makes &lt;code&gt;F&lt;/code&gt; &lt;code&gt;Result[_, AgeError]&lt;/code&gt;
and &lt;code&gt;X&lt;/code&gt; &lt;code&gt;int&lt;/code&gt;. A type with no conformance of its own is matched as the nearest superclass that
has one, a &lt;code&gt;TallShelf[int]&lt;/code&gt; as a &lt;code&gt;Shelf[int]&lt;/code&gt;. A type with none is an error naming the bound and
the type. With several bounds, the conformances must leave the same arguments open; a type that
implements one bound at one hole and another at another is an error naming both.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A subclass passes as its superclass only where a value is read out&lt;/strong&gt;, as for any type
argument: a &lt;code&gt;Box[TallShelf[int]]&lt;/code&gt; given for a &lt;code&gt;Box[F[int]]&lt;/code&gt; is refused where &lt;code&gt;Box&lt;/code&gt; is invariant,
since the generic code may store a &lt;code&gt;Shelf&lt;/code&gt; in it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Without a bound&lt;/strong&gt;, a type of exactly as many parameters as &lt;code&gt;F&lt;/code&gt; takes holes gives &lt;code&gt;F&lt;/code&gt; that type
bare; a type of more is an error asking for &lt;code&gt;F&lt;/code&gt; to be written, since nothing says which arguments
are open.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The arguments written out are inferred as type arguments are&lt;/strong&gt;: each argument naming &lt;code&gt;F&lt;/code&gt;
contributes, and where the type’s parameter is covariant they join, so &lt;code&gt;Ok(1)&lt;/code&gt;, a
&lt;code&gt;Result[int, Nothing]&lt;/code&gt;, beside a &lt;code&gt;Result[int, AgeError]&lt;/code&gt; makes &lt;code&gt;F&lt;/code&gt; &lt;code&gt;Result[_, AgeError]&lt;/code&gt;, and a
&lt;code&gt;Result[int, Dog]&lt;/code&gt; beside a &lt;code&gt;Result[int, Cat]&lt;/code&gt; makes it &lt;code&gt;Result[_, Animal]&lt;/code&gt;; at an invariant
parameter the first decides. An expected type decides them first, as it decides any type
argument. The type named must agree: an &lt;code&gt;Option&lt;/code&gt; and a &lt;code&gt;List&lt;/code&gt; for
one &lt;code&gt;F&lt;/code&gt; is an error naming both, never a join to a trait they share, which a written argument
asks for where that trait conforms to the bound: &lt;code&gt;both[Seq]([1, 2], List(3))&lt;/code&gt; for a
&lt;code&gt;both[F[_]: Foldable](a: F[int], b: F[int])&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The expected type decides &lt;code&gt;F&lt;/code&gt; as an argument does&lt;/strong&gt;: with
&lt;code&gt;wrap[F[_]: Applicative, A](a: A) -&amp;gt; F[A] = F.pure(a)&lt;/code&gt;, &lt;code&gt;val o: Option[int] = wrap(3)&lt;/code&gt; takes
&lt;code&gt;F&lt;/code&gt; as &lt;code&gt;Option&lt;/code&gt;; with nothing expected and no argument naming &lt;code&gt;F&lt;/code&gt;, the call is an error asking for
it, &lt;code&gt;wrap[Option](3)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A lambda’s result decides a constructor as any type argument it yields does: in
&lt;code&gt;words.traverse(_.toIntOption())&lt;/code&gt; the lambda yields an &lt;code&gt;Option[int]&lt;/code&gt;, so &lt;code&gt;G&lt;/code&gt; is &lt;code&gt;Option&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;impls-over-a-constructor-parameter&quot;&gt;Impls over a constructor parameter&lt;/h3&gt;
&lt;p&gt;An impl without &lt;code&gt;for&lt;/code&gt; may add methods to the applications of a bounded constructor parameter,
&lt;code&gt;impl[F[_]: Monad, A] F[A]&lt;/code&gt;, or to a type built from them,
&lt;code&gt;impl[F[_]: Traverse, G[_]: Applicative, A] F[G[A]]&lt;/code&gt;. The receiver’s static type is matched against
it as for any &lt;a href=&quot;/spec/declarations/#impl&quot;&gt;type built from parameters&lt;/a&gt;, each constructor found through its
bound’s conformance as &lt;a href=&quot;#inferring-a-constructor&quot;&gt;inference&lt;/a&gt; finds it, so a &lt;code&gt;List[Option[int]]&lt;/code&gt;
matches &lt;code&gt;F[G[A]]&lt;/code&gt; with &lt;code&gt;F&lt;/code&gt; as &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;G&lt;/code&gt; as &lt;code&gt;Option&lt;/code&gt; and &lt;code&gt;A&lt;/code&gt; as &lt;code&gt;int&lt;/code&gt;. Every rule of impls adding to
a type built from parameters holds: the type’s own methods are found first, such an impl in another
module is an &lt;a href=&quot;/spec/declarations/#extensions&quot;&gt;extension&lt;/a&gt;, seen where its module is imported, and two
that add one name and parameter types to a receiver both match make a call of it an error.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It belongs to the trait bounding the constructor it applies&lt;/strong&gt;: written in the module of one of
&lt;code&gt;F&lt;/code&gt;‘s bounds it is seen everywhere, as an impl adding to that trait is, and elsewhere it is an
extension. Like an impl adding to a trait, it never hides or clashes with a method the type has:
the type’s own method, or the bound’s, of the name and parameter types is called, and generic code
that sees only the bound calls the added one. An extension adding a method the bound declares is
an error where it is declared.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A value of &lt;code&gt;F[X]&lt;/code&gt; in generic code has the methods&lt;/strong&gt; where &lt;code&gt;F&lt;/code&gt;‘s bounds include the impl’s: in
&lt;code&gt;go[F[_]: Monad](x: F[int]) = x.twice(f)&lt;/code&gt; each instance calls the impl’s &lt;code&gt;twice&lt;/code&gt; at its constructor.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A receiver no such impl matches is told why&lt;/strong&gt;: &lt;code&gt;twice&lt;/code&gt; on a &lt;code&gt;Vector[int]&lt;/code&gt;, where &lt;code&gt;Vector&lt;/code&gt;
implements no &lt;code&gt;Monad&lt;/code&gt;, says so; on an &lt;code&gt;F[int]&lt;/code&gt; whose &lt;code&gt;F&lt;/code&gt; lacks the bound, that it is bounded by no
&lt;code&gt;Monad&lt;/code&gt;. A further bound on the element (&lt;code&gt;impl[F[_]: Monad, A: Display] F[A]&lt;/code&gt;) is reported as any
impl’s is.&lt;/li&gt;
&lt;li&gt;An unbounded constructor parameter matches as &lt;a href=&quot;#inferring-a-constructor&quot;&gt;inference&lt;/a&gt; matches one: a
type of exactly as many arguments as it has holes, named bare. Such an impl states no conformance
(&lt;code&gt;impl[F[_]: Monad, A] Display for F[A]&lt;/code&gt; is an error) and declares no static member.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;constructors-and-reification&quot;&gt;Constructors and reification&lt;/h3&gt;
&lt;p&gt;Each instance of generic code knows every constructor argument, so &lt;code&gt;F[A]&lt;/code&gt; in it is the type written
out, laid out and reified as that type is: an &lt;code&gt;F[int]&lt;/code&gt; at &lt;code&gt;List&lt;/code&gt; stores unboxed &lt;code&gt;int&lt;/code&gt;s, its header
names &lt;code&gt;List[int]&lt;/code&gt;, and a type pattern &lt;code&gt;x: F[int]&lt;/code&gt; is checked against the object’s exact type. The
copies are one per list of type arguments, constructors included: &lt;code&gt;pairUp&lt;/code&gt; at &lt;code&gt;Option&lt;/code&gt; and at
&lt;code&gt;Result[_, AgeError]&lt;/code&gt; are two, and at &lt;code&gt;Parsed&lt;/code&gt; and &lt;code&gt;Result[_, ParseError]&lt;/code&gt; one.
&lt;a href=&quot;#polymorphic-recursion&quot;&gt;Polymorphic recursion&lt;/a&gt; counts constructors too: a cycle that passes
&lt;code&gt;Result[_, Nest[E]]&lt;/code&gt; for a constructor parameter where it received &lt;code&gt;Result[_, E]&lt;/code&gt; grows without end
and is rejected.&lt;/p&gt;
&lt;h3 id=&quot;why-it-is-sound&quot;&gt;Why it is sound&lt;/h3&gt;
&lt;p&gt;Every rule above is there so that generic code checked once is correct at every instance, with no
check left for run time and no unchecked conversion anywhere:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Kinds.&lt;/strong&gt; Every type written is checked for its kind where it is written, so a constructor never
reaches a place a value’s type is taken, and every application has exactly its arity. Substituting
a constructor for &lt;code&gt;F&lt;/code&gt; therefore turns each &lt;code&gt;F[X]&lt;/code&gt; into a type that is well formed by the rules for
types without constructors, and nothing else changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Holes are direct arguments.&lt;/strong&gt; A constructor is one nominal type with some of its own arguments
left open, so applying it is substitution, two constructors are equal exactly when they look
equal, and inference has at most one answer. There is no computation at the type level to
diverge or to disagree between the checker and the instances.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hole variance.&lt;/strong&gt; &lt;code&gt;F[Dog]&lt;/code&gt; is an &lt;code&gt;F[Animal]&lt;/code&gt; only where the hole is &lt;code&gt;+_&lt;/code&gt;, and only a constructor
covariant at that argument is accepted for it, so the subtyping assumed inside the declaration is
the subtyping the &lt;a href=&quot;#variance&quot;&gt;variance&lt;/a&gt; rules grant each instance. A plain &lt;code&gt;_&lt;/code&gt; assumes none. The
arguments written out of a partial application keep their own type’s variance, as in any type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bounded holes.&lt;/strong&gt; Every &lt;code&gt;F[X]&lt;/code&gt; a declaration writes is checked against the hole’s bounds where it
is written, and a constructor is accepted for the hole only where the hole’s bounds imply its own
parameter’s, so no instance applies a type to an argument its declaration refuses, and a generic
definition’s errors are still reported at the definition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coherence.&lt;/strong&gt; A type implements a constructor trait once, at one choice of holes, in the module
of the trait or the type, so the constructor inferred for an argument is unique and the same in
every file, and each instance’s calls through the bound reach one implementation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Meeting.&lt;/strong&gt; An existing method implements a trait’s only where the trait’s call, at every type
argument, is an ordinary well-typed call of it with no conversion and no bound the trait does not
give. The call each instance makes is one the checker could have written out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No inherited conformance.&lt;/strong&gt; A subclass’s inherited &lt;code&gt;map&lt;/code&gt; answers the superclass’s type, so if it
inherited the conformance, &lt;code&gt;Self[B]&lt;/code&gt; would claim a subclass instance the method never makes; it is
matched as the superclass instead, which is exactly what it is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static members and defaults per constructor.&lt;/strong&gt; A static member is reached only through a
constructor that is known in each instance, and a default body is compiled once per implementing
constructor, so &lt;code&gt;Self.pure&lt;/code&gt; always names one implementation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Traits for types at holes.&lt;/strong&gt; A trait for types that bounds constructors names no &lt;code&gt;Self&lt;/code&gt; beyond
the receiver and has no static member, so its members read the same from every application, and
a constructor conforms to it only where a conformance states the trait’s parameters as the
type’s own. Every &lt;code&gt;F[X]&lt;/code&gt; an instance makes is then a &lt;code&gt;Foldable[X]&lt;/code&gt; by an ordinary conformance, and
a call through the bound is the ordinary call on that type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A bound, never a type.&lt;/strong&gt; No value has a constructor trait as its type, so there is no object
whose &lt;code&gt;Self&lt;/code&gt; is unknown, no dynamic dispatch over constructors and no existential to open. Each
instance is monomorphized, its values reified at their exact types, and a downcast stays a
type-checked &lt;code&gt;match&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;functor-applicative-monad-traverse&quot;&gt;Functor, Applicative, Monad, Traverse&lt;/h2&gt;
&lt;p&gt;The core library declares the standard constructor traits, in module &lt;code&gt;avin&lt;/code&gt;, and &lt;code&gt;Foldable&lt;/code&gt;, a
trait for types that bounds constructors as well, since its method never writes &lt;code&gt;Self&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Functor[A]
  map[B](f: (A) -&amp;gt; B) -&amp;gt; Self[B]

trait Foldable[+A]
  foldLeft[B](initial: B, f: (B, A) -&amp;gt; B) -&amp;gt; B

trait Applicative[A]: Functor[A]
  static pure[X](value: X) -&amp;gt; Self[X]
  map2[B, C](other: Self[B], f: (A, B) -&amp;gt; C) -&amp;gt; Self[C]

trait Monad[A]: Applicative[A]
  flatMap[B](f: (A) -&amp;gt; Self[B]) -&amp;gt; Self[B]
  override map[B](f: (A) -&amp;gt; B) -&amp;gt; Self[B] = flatMap(a -&amp;gt; Self.pure(f(a)))
  override map2[B, C](other: Self[B], f: (A, B) -&amp;gt; C) -&amp;gt; Self[C] =
    flatMap(a -&amp;gt; other.map(b -&amp;gt; f(a, b)))

trait Filter[A]: Functor[A]
  filter(p: (A) -&amp;gt; bool) -&amp;gt; Self[A]

trait Traverse[A]: Functor[A], Foldable[A]
  traverse[G[_]: Applicative, B](f: (A) -&amp;gt; G[B]) -&amp;gt; G[Self[B]]

impl[F[_]: Traverse, G[_]: Applicative, A] F[G[A]]
  sequence() -&amp;gt; G[F[A]] = traverse(x -&amp;gt; x)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value that crosses to another thread is &lt;code&gt;Sendable&lt;/code&gt;, and a function run on another thread is
&lt;code&gt;@sendable&lt;/code&gt;, so a constructor whose combinators run on a pool thread, as &lt;code&gt;Future&lt;/code&gt;‘s do, meets the
sendable pair instead, whose holes and functions carry those marks:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait SendableFunctor[A: Sendable]
  map[B: Sendable](@sendable f: (A) -&amp;gt; B) -&amp;gt; Self[B]

trait SendableMonad[A: Sendable]: SendableFunctor[A]
  static pure[X: Sendable](value: X) -&amp;gt; Self[X]
  flatMap[B: Sendable](@sendable f: (A) -&amp;gt; Self[B]) -&amp;gt; Self[B]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;impl SendableMonad for Future&lt;/code&gt; gives only &lt;code&gt;pure&lt;/code&gt; (&lt;code&gt;Future.successful&lt;/code&gt;); &lt;code&gt;Future&lt;/code&gt;‘s own &lt;code&gt;map&lt;/code&gt; and
&lt;code&gt;flatMap&lt;/code&gt; meet the rest.&lt;/p&gt;
&lt;p&gt;The impls are for concrete types only, one per row; code generic over sequences takes an
&lt;code&gt;F[_]: Monad&lt;/code&gt; (or the trait it needs) rather than a &lt;code&gt;Seq&lt;/code&gt;, which as a trait for types has no impl of
a constructor trait:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Constructor&lt;/th&gt;&lt;th&gt;&lt;code&gt;Functor&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;Foldable&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;Applicative&lt;/code&gt;, &lt;code&gt;Monad&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;Filter&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;Traverse&lt;/code&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Option&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes (&lt;code&gt;pure&lt;/code&gt; is &lt;code&gt;Some&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Result[_, E]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes (&lt;code&gt;Ok&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;no: no error to give&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Either[L, _]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes (&lt;code&gt;Right&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;no&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes (one element)&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;LazyList&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;no: an infinite list never finishes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;no: mutable&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;no&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;HashSet&lt;/code&gt;, &lt;code&gt;OrderedSet&lt;/code&gt;, &lt;code&gt;TreeSet&lt;/code&gt;&lt;/td&gt;&lt;td&gt;no: &lt;code&gt;map&lt;/code&gt; makes a &lt;code&gt;Set&lt;/code&gt;&lt;/td&gt;&lt;td&gt;yes&lt;/td&gt;&lt;td&gt;no&lt;/td&gt;&lt;td&gt;no&lt;/td&gt;&lt;td&gt;no&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The traits are nominal.&lt;/strong&gt; A type is a &lt;code&gt;Functor&lt;/code&gt; because an impl says so, and only then: a type
with a &lt;code&gt;map&lt;/code&gt; of the right shape and no &lt;code&gt;impl Functor&lt;/code&gt; is no &lt;code&gt;Functor&lt;/code&gt;, cannot be passed for an
&lt;code&gt;F[_]: Functor&lt;/code&gt;, and is no source of a &lt;a href=&quot;/spec/collections/#for-comprehensions&quot;&gt;&lt;code&gt;for&lt;/code&gt; comprehension&lt;/a&gt;
unless it is an &lt;code&gt;Iterable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every &lt;code&gt;Iterable[A]&lt;/code&gt; is a &lt;code&gt;Foldable[A]&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Iterable&lt;/code&gt; requires it and gives &lt;code&gt;foldLeft&lt;/code&gt;, so every
collection of one parameter is a constructor for &lt;code&gt;[F[_]: Foldable]&lt;/code&gt; with no impl of its own, the
sets and the sorted collections too, where the hole promises their bound (&lt;code&gt;TreeSet&lt;/code&gt; for an
&lt;code&gt;F[_: Ord]&lt;/code&gt;). &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt; gain &lt;code&gt;foldLeft&lt;/code&gt; in their impls of &lt;code&gt;Traverse&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The traits add no method a collection already has and change none.&lt;/strong&gt; &lt;code&gt;List&lt;/code&gt;‘s own &lt;code&gt;map&lt;/code&gt;,
&lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;foldLeft&lt;/code&gt; implement them, so &lt;code&gt;xs.map(f)&lt;/code&gt; on a &lt;code&gt;List&lt;/code&gt; is the call it always was, with
the result it always had; the impls write only what the types lack: &lt;code&gt;pure&lt;/code&gt;, &lt;code&gt;traverse&lt;/code&gt;, and
&lt;code&gt;foldLeft&lt;/code&gt; on &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt;. &lt;code&gt;map2&lt;/code&gt; is &lt;code&gt;Monad&lt;/code&gt;‘s, from &lt;code&gt;flatMap&lt;/code&gt;, and &lt;code&gt;sequence&lt;/code&gt;
is added to every traversable of applicatives.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A sequence’s &lt;code&gt;map2&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; pair every element with every element&lt;/strong&gt;, as a two-generator
&lt;code&gt;for&lt;/code&gt; does; &lt;code&gt;zip&lt;/code&gt; still pairs them by position, and is no trait’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;traverse&lt;/code&gt; and &lt;code&gt;sequence&lt;/code&gt; answer the first &lt;code&gt;None&lt;/code&gt;, &lt;code&gt;Err&lt;/code&gt; or &lt;code&gt;Left&lt;/code&gt;&lt;/strong&gt; where there is one, and
otherwise the applicative of all the results. A sequence’s &lt;code&gt;traverse&lt;/code&gt; gathers through &lt;code&gt;map2&lt;/code&gt;, so
&lt;code&gt;f&lt;/code&gt; is applied to every element, in order, and the first failure decides the result; it is the
result that stops at the first failure, never the evaluation. &lt;code&gt;flatten&lt;/code&gt; keeps the values that are
present and drops the rest:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Line(name: string, size: int)

data ParseError(line: string)

parseLine(text: string) -&amp;gt; Result[Line, ParseError] = text.split(&amp;quot; &amp;quot;) match
  [name, size] -&amp;gt; size.toIntOption().map(n -&amp;gt; Line(name, n)).okOr(ParseError(text))
  _ -&amp;gt; Err(ParseError(text))

main()
  println([&amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;].traverse(_.toIntOption()))
  println([&amp;quot;1&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;x&amp;quot;].traverse(_.toIntOption()))
  println([Some(1), None].sequence())
  println([Some(1), None].flatten)
  println([&amp;quot;a 1&amp;quot;, &amp;quot;b 2&amp;quot;].traverse(parseLine))
  println([&amp;quot;a 1&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c x&amp;quot;].traverse(parseLine))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Some([1, 2])
None
None
[1]
Ok([Line(a, 1), Line(b, 2)])
Err(ParseError(b))
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Not implemented, each for a reason a reader can see in its signature: &lt;code&gt;Map&lt;/code&gt; (its &lt;code&gt;map&lt;/code&gt; takes the
entries, so it folds them as an &lt;code&gt;Iterable[(K, V)]&lt;/code&gt; and is no constructor), the sets and the sorted
collections as functors (their &lt;code&gt;map&lt;/code&gt; makes a &lt;code&gt;Set&lt;/code&gt; and needs &lt;code&gt;Eq &amp;amp; Hash&lt;/code&gt; or &lt;code&gt;Ord&lt;/code&gt; of its result),
&lt;code&gt;Iterator&lt;/code&gt; as a functor (single-pass), &lt;code&gt;Range&lt;/code&gt; (its &lt;code&gt;map&lt;/code&gt; makes a &lt;code&gt;Vector&lt;/code&gt;, not a range), &lt;code&gt;Seq&lt;/code&gt;
and &lt;code&gt;Set&lt;/code&gt; (traits for types, which no impl of a constructor trait is for) and &lt;code&gt;Future&lt;/code&gt; (its &lt;code&gt;map&lt;/code&gt;
needs a &lt;code&gt;Sendable&lt;/code&gt; result and a &lt;code&gt;@sendable&lt;/code&gt; function, so it is a &lt;code&gt;SendableMonad&lt;/code&gt; instead);
&lt;code&gt;Future.traverse&lt;/code&gt;, a static member taking a collection, is unrelated and stays.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each implementation keeps the laws&lt;/strong&gt;, which the library’s tests check for every type in the
table: &lt;code&gt;map(x -&amp;gt; x)&lt;/code&gt; is the value, &lt;code&gt;map(f).map(g)&lt;/code&gt; is &lt;code&gt;map(x -&amp;gt; g(f(x)))&lt;/code&gt;; &lt;code&gt;pure(a).flatMap(f)&lt;/code&gt; is
&lt;code&gt;f(a)&lt;/code&gt;, &lt;code&gt;m.flatMap(Self.pure)&lt;/code&gt; is &lt;code&gt;m&lt;/code&gt;, and &lt;code&gt;flatMap&lt;/code&gt; is associative.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;scope-of-the-type-system&quot;&gt;Scope of the type system&lt;/h2&gt;
&lt;p&gt;The type system stays small: generics with bounds, constructor parameters bounded by constructor
traits, subtyping with declaration-site variance, traits implemented through &lt;code&gt;impl&lt;/code&gt;,
&lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt; written in annotations,
&lt;a href=&quot;/spec/declarations/#opaque-types&quot;&gt;opaque types&lt;/a&gt;, new types laid out as an existing one, and
&lt;a href=&quot;/spec/refined-variants/&quot;&gt;refined variants&lt;/a&gt;, whose &lt;code&gt;match&lt;/code&gt; arms learn type equalities. It has no type lambdas beyond the partial
application of one type’s own arguments, no constructors of constructors, and no type members,
inferred unions, implicit conversions or macros. Intersections exist only as
&lt;a href=&quot;#bounds&quot;&gt;bounds&lt;/a&gt;, &lt;code&gt;[T: A &amp;amp; B]&lt;/code&gt;: there is no intersection type to annotate a value with, so a value
of two traits at once is always a bounded parameter’s, monomorphized at its type argument. A
context a call needs (a transaction, a logger) may be passed as a
&lt;a href=&quot;/spec/contextual-parameters/&quot;&gt;contextual parameter&lt;/a&gt;, filled from a &lt;code&gt;given&lt;/code&gt; in scope; that is a value
and never a conformance: a bound is met only by the type’s &lt;code&gt;impl&lt;/code&gt;, whatever givens are in scope, and
a contextual parameter’s type names no type parameter. The
&lt;a href=&quot;/spec/collections/&quot;&gt;collections chapter&lt;/a&gt; shows how the library gets precise result types without
constructor parameters; the standard constructor traits stand beside those methods rather than
replacing them.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Errors</title>
    <link href="https://avinlang.dev/spec/errors/"/>
    <id>https://avinlang.dev/spec/errors/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Recoverable failure is a value; a bug is a trap. No exceptions, no null.</summary>
    <content type="html">&lt;p&gt;Avin uses Sysl’s model. There are no exceptions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A failure that correct calling code can meet is a value.&lt;/strong&gt; A function that can fail returns
&lt;code&gt;Result[T, E]&lt;/code&gt;, or &lt;code&gt;Option[T]&lt;/code&gt; when there is no reason to report. The failure is part of the
signature, and the caller must deal with it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A bug is a trap.&lt;/strong&gt; An index out of bounds, division by zero, an invalid conversion, &lt;code&gt;next()&lt;/code&gt; on an
exhausted iterator or a failed assertion stops the program with a message and the source location.
A trap is not a value and cannot be caught. What the program needs put back however it ends, a
terminal’s mode, goes in an &lt;a href=&quot;/spec/system-library/#exit-hooks&quot;&gt;exit hook&lt;/a&gt;, which runs after the
trap’s report.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;fail(message)&lt;/code&gt; is how a program says “this cannot happen”.&lt;/strong&gt; It is in the prelude, stops the
program with &lt;code&gt;message&lt;/code&gt; at the place it is called, and has type &lt;code&gt;Nothing&lt;/code&gt;, so it stands where a value
of any type is expected:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val n: int = if ok then 1 else fail(&amp;quot;no&amp;quot;) // avin: trap: no at main.avin:2:36
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Beside it the prelude has two more that stop the program, each at its own call:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;require(condition)&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;require(condition, message)&lt;/code&gt;&lt;/strong&gt; check what a function was given:
where &lt;code&gt;condition&lt;/code&gt; is false they trap with &lt;code&gt;requirement failed&lt;/code&gt;, or &lt;code&gt;requirement failed: &lt;/code&gt; and the
message. The message is passed &lt;a href=&quot;/spec/by-name/&quot;&gt;by name&lt;/a&gt;, so it is built only when the requirement
fails. &lt;code&gt;assert&lt;/code&gt; (see &lt;a href=&quot;/spec/declarations/#tests&quot;&gt;tests&lt;/a&gt;) states what the program itself
guarantees; &lt;code&gt;require&lt;/code&gt; states what its caller owes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;todo()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;todo(message)&lt;/code&gt;&lt;/strong&gt; stand for code not yet written. They have type &lt;code&gt;Nothing&lt;/code&gt;, as
&lt;code&gt;fail&lt;/code&gt; has, so a branch of any type may be one; reached, they trap with &lt;code&gt;not implemented&lt;/code&gt;, or
&lt;code&gt;not implemented: &lt;/code&gt; and the message.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;half(n: int) -&amp;gt; int
  require(n % 2 == 0, s&amp;quot;$n is even&amp;quot;) // avin: trap: requirement failed: 3 is even at main.avin:2:3
  n / 2

area(s: Shape) -&amp;gt; real = s match
  Circle(r) -&amp;gt; r * r * 3.14159
  Polygon(_) -&amp;gt; todo(&amp;quot;polygons&amp;quot;) // avin: trap: not implemented: polygons at main.avin:7:17
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The location is in the program’s own code.&lt;/strong&gt; A trap reached inside the core library, whether the
library asked for it, as &lt;code&gt;m(k)&lt;/code&gt; on a missing key does, or a check failed there, such as an overflow,
reports the place where the program last called into the library, with the library’s reason:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;main()
  val b = Buffer[int]()
  b.remove(0) // avin: trap: index out of range at main.avin:3:3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That holds however deep in the library the trap is, and whether the program called the library
directly, through a trait or through a function value. When the library calls back into the
program, as &lt;code&gt;Array.tabulate&lt;/code&gt; calls the function it is given, a trap the program’s code reaches in
the library again reports that inner call, the nearest one the program wrote.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Running out of stack is a trap.&lt;/strong&gt; Recursion that never reaches a base case stops the program with
&lt;code&gt;avin: trap: stack overflow&lt;/code&gt;, after the output it had already written. The message names no place, and no exit hook runs: the report comes from a handler on a stack of
its own, where no Avin code can run.
It holds on the main thread, whose stack is the operating system’s to size, and on every thread
&lt;code&gt;spawn&lt;/code&gt; starts, whose stack is 8 MiB unless &lt;code&gt;spawn&lt;/code&gt; is asked for another size.&lt;/p&gt;
&lt;h2 id=&quot;the-operator&quot;&gt;The ? operator&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;expr?&lt;/code&gt; unwraps &lt;code&gt;Ok(v)&lt;/code&gt; or &lt;code&gt;Some(v)&lt;/code&gt; to &lt;code&gt;v&lt;/code&gt;. On &lt;code&gt;Err(e)&lt;/code&gt; or &lt;code&gt;None&lt;/code&gt; it returns from the enclosing
function immediately. On a &lt;code&gt;Result&lt;/code&gt;, the error is converted through &lt;code&gt;From&lt;/code&gt; when the caller’s error
type differs:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data ConfigError
  Unreadable(cause: IoError)
  Malformed(cause: ParseError)
  Invalid(key: string)

impl From[IoError] for ConfigError
  static from(value: IoError) -&amp;gt; ConfigError = Unreadable(value)

impl From[ParseError] for ConfigError
  static from(value: ParseError) -&amp;gt; ConfigError = Malformed(value)

loadConfig(path: string) -&amp;gt; Result[Config, ConfigError]
  val text = readText(path)?
  val doc = parseDocument(text)?
  configOf(doc)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;From[E]&lt;/code&gt; is a core trait with one static member, &lt;code&gt;static from(value: E) -&amp;gt; Self&lt;/code&gt;, so an error type
implements it once for each error it wraps. On &lt;code&gt;Err(e)&lt;/code&gt;, with &lt;code&gt;e&lt;/code&gt; of type &lt;code&gt;E&lt;/code&gt; and the enclosing
function yielding errors of &lt;code&gt;F&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Where &lt;code&gt;E&lt;/code&gt; is an &lt;code&gt;F&lt;/code&gt;&lt;/strong&gt;, &lt;code&gt;e&lt;/code&gt; is passed on unchanged.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Otherwise &lt;code&gt;F.from(e)&lt;/code&gt;&lt;/strong&gt; makes the error passed on, through &lt;code&gt;F&lt;/code&gt;‘s conformance to &lt;code&gt;From[E]&lt;/code&gt;. Where
&lt;code&gt;F&lt;/code&gt; has none, a conformance &lt;code&gt;From[X]&lt;/code&gt; with &lt;code&gt;E&lt;/code&gt; an &lt;code&gt;X&lt;/code&gt; serves, if exactly one is more specific
than every other: an error of a subclass converts through its superclass’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No conformance is an error&lt;/strong&gt; naming the one missing, &lt;code&gt;From[E]&lt;/code&gt;; several equally specific are an
error naming them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union of errors needs no wrapper type.&lt;/strong&gt; “&lt;code&gt;E&lt;/code&gt; is an &lt;code&gt;F&lt;/code&gt;“ includes &lt;code&gt;E&lt;/code&gt; being a member of a
union &lt;code&gt;F&lt;/code&gt;, or a union whose members are all members of &lt;code&gt;F&lt;/code&gt;; where &lt;code&gt;F&lt;/code&gt; is a union, the one member
implementing &lt;code&gt;From[E]&lt;/code&gt; converts it; where &lt;code&gt;E&lt;/code&gt; is a union and &lt;code&gt;F&lt;/code&gt; is not, each member converts on
its own. So &lt;code&gt;load(path) -&amp;gt; Result[Config, IoError | ParseError]&lt;/code&gt; may &lt;code&gt;?&lt;/code&gt; a &lt;code&gt;Result[_, IoError]&lt;/code&gt; and a
&lt;code&gt;Result[_, ParseError]&lt;/code&gt;. The full rule is in &lt;a href=&quot;/spec/unions/#errors-and&quot;&gt;union types&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A type parameter converts through its bounds&lt;/strong&gt;: in
&lt;code&gt;load[F: From[IoError] &amp;amp; From[ParseError]](path: string) -&amp;gt; Result[Doc, F]&lt;/code&gt;, both errors convert,
and each instance calls its type argument’s &lt;code&gt;from&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An &lt;code&gt;Option&lt;/code&gt; &lt;code&gt;?&lt;/code&gt; cannot exit a function returning &lt;code&gt;Result&lt;/code&gt;, and the enclosing function’s result type
must be able to carry the failure. &lt;code&gt;main&lt;/code&gt; may answer with &lt;code&gt;Result[unit, E]&lt;/code&gt; or &lt;code&gt;Result[int, E]&lt;/code&gt;,
so a whole program can use &lt;code&gt;?&lt;/code&gt;: an &lt;code&gt;Err&lt;/code&gt; reaching the end of &lt;code&gt;main&lt;/code&gt; is written to standard error as
&lt;code&gt;error: &lt;/code&gt; and its &lt;code&gt;Display&lt;/code&gt;, and the program exits with 1 (see &lt;a href=&quot;/spec/declarations/#main&quot;&gt;&lt;code&gt;main&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;?&lt;/code&gt; returns from the function it is written in; inside a lambda, from the lambda. That function’s
result type must be declared, or for a lambda known where it is written, as in
&lt;code&gt;val f: (string) -&amp;gt; Option[int] = s -&amp;gt; Some(parse(s)? + 1)&lt;/code&gt;. For a lambda, known in shape is
enough: where the function expected yields an &lt;code&gt;Option&lt;/code&gt;, or a &lt;code&gt;Result&lt;/code&gt; whose error type is known,
and the value’s type is still to be inferred, as in a generic
&lt;code&gt;transaction[T](f: (Tx) -&amp;gt; Result[T, DbError]) -&amp;gt; Result[T, DbError]&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt; checks against that
shape and the body decides the value’s type, so &lt;code&gt;db.transaction(tx -&amp;gt; Ok(tx.execute(sql)? + 1))&lt;/code&gt;
takes &lt;code&gt;T = int&lt;/code&gt;. &lt;code&gt;return&lt;/code&gt; in such a lambda checks against the same shape. A &lt;code&gt;Result&lt;/code&gt; whose error
type is itself still unknown, and a result of any other shape, are not enough. A delayed argument
and a class body cannot be left by &lt;code&gt;?&lt;/code&gt;, as they cannot by &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;a-result-is-not-dropped&quot;&gt;A Result is not dropped&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;Result&lt;/code&gt; whose value is thrown away is an error&lt;/strong&gt;, so a failure cannot pass unseen. A &lt;code&gt;Future&lt;/code&gt;
is held to the same rule, since dropping one leaves its computation’s answer, a &lt;code&gt;Result&lt;/code&gt; as often as
not, with nobody to read it. A value is thrown away where it is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a statement of a block, other than the value the block yields;&lt;/li&gt;
&lt;li&gt;the last line of a function that yields &lt;code&gt;unit&lt;/code&gt;, or of a lambda whose function type yields &lt;code&gt;unit&lt;/code&gt;,
as in &lt;code&gt;xs.foreach(x -&amp;gt; fs.remove(x))&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;a branch of an &lt;code&gt;if&lt;/code&gt; without &lt;code&gt;else&lt;/code&gt;, or of an &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; written as a statement;&lt;/li&gt;
&lt;li&gt;the body of a loop.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;save(text: string)
  fs.writeText(&amp;quot;out.txt&amp;quot;, text) // error: a `Result` is discarded here
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A failure is handled with &lt;code&gt;?&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt;, or one of &lt;code&gt;Result&lt;/code&gt;‘s methods (&lt;code&gt;getOrElse&lt;/code&gt;, &lt;code&gt;isOk&lt;/code&gt;, …).
&lt;strong&gt;&lt;code&gt;_ = e&lt;/code&gt; drops a value on purpose&lt;/strong&gt;: it evaluates &lt;code&gt;e&lt;/code&gt; and keeps nothing, which says to a reader that
the failure was considered and does not matter, as with a socket closed after its answer was read:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;_ = fs.remove(scratch)
if closed then _ = conn.close() else _ = conn.held()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A deferred statement may drop its &lt;code&gt;Result&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;defer f.close()&lt;/code&gt; runs while its block is being left,
where no &lt;code&gt;?&lt;/code&gt; or &lt;code&gt;return&lt;/code&gt; could pass a failure on. A lambda written inside one is a function of its
own and follows the rule. Values of every other type are dropped freely: a statement such as
&lt;code&gt;buffer.append(x)&lt;/code&gt; that answers the buffer needs no &lt;code&gt;_ =&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;the-error-trait&quot;&gt;The Error trait&lt;/h2&gt;
&lt;p&gt;An error meant for a person to read is an &lt;code&gt;Error&lt;/code&gt;, a core trait in the prelude:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Error: Display
  message -&amp;gt; string
  cause -&amp;gt; Option[Error] = None
  override display(out: Writer, spec: FormatSpec) // message, then &amp;quot;: &amp;quot; and the cause
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;message&lt;/code&gt; is the error’s own sentence&lt;/strong&gt;, without its cause’s; &lt;code&gt;cause&lt;/code&gt; is the failure that led to
it, &lt;code&gt;None&lt;/code&gt; by default. Both are &lt;a href=&quot;/spec/declarations/#parameterless-methods&quot;&gt;parameterless&lt;/a&gt;: they
read what the error holds, so &lt;code&gt;e.message&lt;/code&gt; and &lt;code&gt;e.cause&lt;/code&gt; take no parentheses. A data type’s field
named &lt;code&gt;message&lt;/code&gt; implements the first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An error shows as its whole chain.&lt;/strong&gt; The display is the message, then &lt;code&gt;: &lt;/code&gt; and the cause as
it shows, so each level adds its sentence in front: &lt;code&gt;loading config: cannot read app.conf: no such file or directory&lt;/code&gt;. A message that is empty is left out with its &lt;code&gt;: &lt;/code&gt;. A data type implementing
&lt;code&gt;Error&lt;/code&gt; takes this display in place of the one it would have by its fields; one with a &lt;code&gt;Display&lt;/code&gt;
of its own keeps it, and its cause, if any, is then its own to show.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every error type of the standard library is an &lt;code&gt;Error&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;IoError&lt;/code&gt;, &lt;code&gt;CommandError&lt;/code&gt;,
&lt;code&gt;HttpError&lt;/code&gt;, &lt;code&gt;UrlError&lt;/code&gt;, &lt;code&gt;TlsError&lt;/code&gt;, &lt;code&gt;TimeParseError&lt;/code&gt;, &lt;code&gt;ZoneError&lt;/code&gt;, &lt;code&gt;PatternError&lt;/code&gt;,
&lt;code&gt;MatchError&lt;/code&gt;, &lt;code&gt;AskError&lt;/code&gt;, &lt;code&gt;SendError&lt;/code&gt; and &lt;code&gt;Utf8Error&lt;/code&gt;, and the json package’s &lt;code&gt;JsonError&lt;/code&gt;.
An error that only wraps another one, as &lt;code&gt;CommandError.Io(e)&lt;/code&gt; does, has &lt;code&gt;e&lt;/code&gt;‘s message and no
cause of its own, so it shows once.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A type of the program’s own becomes one&lt;/strong&gt; by giving it a message:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data ParseError(line: int, text: string)

impl Error for ParseError
  message -&amp;gt; string = s&amp;quot;line $line: cannot read \&amp;quot;$text\&amp;quot;&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;context&lt;/code&gt; puts an error in context.&lt;/strong&gt; On a &lt;code&gt;Result[T, E]&lt;/code&gt; whose &lt;code&gt;E&lt;/code&gt; is an &lt;code&gt;Error&lt;/code&gt;,
&lt;code&gt;context(text)&lt;/code&gt; keeps an &lt;code&gt;Ok&lt;/code&gt; and wraps an &lt;code&gt;Err(e)&lt;/code&gt; as &lt;code&gt;Err(ContextError(text, e))&lt;/code&gt;, an error whose
message is &lt;code&gt;text&lt;/code&gt; and whose cause is &lt;code&gt;e&lt;/code&gt;. The text is passed &lt;a href=&quot;/spec/by-name/&quot;&gt;by name&lt;/a&gt;, so it is
built only for an &lt;code&gt;Err&lt;/code&gt;. Contexts nest, the outermost first when shown:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;loadConfig(path: string) -&amp;gt; Result[Config, ContextError]
  val text = fs.readText(path).context(s&amp;quot;loading $path&amp;quot;)?
  parseConfig(text).context(&amp;quot;reading the settings&amp;quot;)
// Err(loading app.conf: cannot read app.conf: no such file or directory)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;ContextError(message: string, inner: Error)&lt;/code&gt; is a data type of the prelude; a program reaches the
error it wraps by &lt;code&gt;inner&lt;/code&gt;, or through &lt;code&gt;cause&lt;/code&gt;, and takes it apart by a type pattern, &lt;code&gt;io: IoError&lt;/code&gt;
in a &lt;code&gt;match&lt;/code&gt; arm or &lt;code&gt;e.inner is _: IoError&lt;/code&gt;, since its static type is the trait.
&lt;code&gt;context&lt;/code&gt; takes any error that is an &lt;code&gt;Error&lt;/code&gt;: a type parameter bounded by &lt;code&gt;Error&lt;/code&gt;, and a
&lt;a href=&quot;/spec/unions/&quot;&gt;union&lt;/a&gt; of error types each of which is one, so &lt;code&gt;load(path).context(&amp;quot;loading&amp;quot;)&lt;/code&gt; works
on a &lt;code&gt;Result[Config, IoError | ParseError]&lt;/code&gt;. And &lt;code&gt;Error&lt;/code&gt; is a type like any trait: a function
answering &lt;code&gt;Result[T, Error]&lt;/code&gt; can &lt;code&gt;?&lt;/code&gt; every error type, each passed on unchanged, which is what a
&lt;code&gt;main&lt;/code&gt; that answers a &lt;code&gt;Result&lt;/code&gt; wants.&lt;/p&gt;
&lt;h2 id=&quot;option-and-result&quot;&gt;Option and Result&lt;/h2&gt;
&lt;p&gt;Both are &lt;code&gt;data&lt;/code&gt; types of the core library, written in Avin:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Option[+T]
  Some(value: T)
  None

data Result[+T, +E]
  Ok(value: T)
  Err(error: E)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Their methods:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;&lt;code&gt;Option[T]&lt;/code&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;Result[T, E]&lt;/code&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isDefined&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;isOk&lt;/code&gt;, &lt;code&gt;isErr&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;getOrElse[B &amp;gt;: T](default: -&amp;gt; B) -&amp;gt; B&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;getOrElse[U &amp;gt;: T](default: -&amp;gt; U) -&amp;gt; U&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;orElse[B &amp;gt;: T](other: -&amp;gt; Option[B]) -&amp;gt; Option[B]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;ok -&amp;gt; Option[T]&lt;/code&gt;, &lt;code&gt;err -&amp;gt; Option[E]&lt;/code&gt;; &lt;code&gt;toOption -&amp;gt; Option[T]&lt;/code&gt;, the same as &lt;code&gt;ok&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;map[U](f: (T) -&amp;gt; U) -&amp;gt; Option[U]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;map[U](f: (T) -&amp;gt; U) -&amp;gt; Result[U, E]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flatMap[U](f: (T) -&amp;gt; Option[U]) -&amp;gt; Option[U]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;mapErr[F](f: (E) -&amp;gt; F) -&amp;gt; Result[T, F]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;filter(p: (T) -&amp;gt; bool) -&amp;gt; Option[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;flatMap[U, F &amp;gt;: E](f: (T) -&amp;gt; Result[U, F]) -&amp;gt; Result[U, F]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fold[U](ifNone: -&amp;gt; U, f: (T) -&amp;gt; U) -&amp;gt; U&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;fold[U](onErr: (E) -&amp;gt; U, onOk: (T) -&amp;gt; U) -&amp;gt; U&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;foreach(f: (T) -&amp;gt; unit)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;foreach(f: (T) -&amp;gt; unit)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exists(p: (T) -&amp;gt; bool) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;exists(p: (T) -&amp;gt; bool) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;forall(p: (T) -&amp;gt; bool) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;forall(p: (T) -&amp;gt; bool) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;contains[T1 &amp;gt;: T](x: T1) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;orElse[U &amp;gt;: T, F](f: (E) -&amp;gt; Result[U, F]) -&amp;gt; Result[U, F]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toList -&amp;gt; List[T]&lt;/code&gt;, &lt;code&gt;toVector -&amp;gt; Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;toList -&amp;gt; List[T]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zip[T1 &amp;gt;: T, U](other: Option[U]) -&amp;gt; Option[(T1, U)]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;get -&amp;gt; T&lt;/code&gt;, trapping on &lt;code&gt;None&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;filterNot(p: (T) -&amp;gt; bool) -&amp;gt; Option[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;An &lt;code&gt;Option&lt;/code&gt; also has &lt;code&gt;toRight[L](left: -&amp;gt; L) -&amp;gt; Either[L, T]&lt;/code&gt; and &lt;code&gt;toLeft[R](right: -&amp;gt; R) -&amp;gt; Either[T, R]&lt;/code&gt;, which put its value on one side of an &lt;a href=&quot;#either&quot;&gt;&lt;code&gt;Either&lt;/code&gt;&lt;/a&gt; and the argument, evaluated
only for &lt;code&gt;None&lt;/code&gt;, on the other. It also has &lt;code&gt;okOr[E](error: E) -&amp;gt; Result[T, E]&lt;/code&gt; and
&lt;code&gt;okOrElse[E](f: () -&amp;gt; E) -&amp;gt; Result[T, E]&lt;/code&gt;, giving &lt;code&gt;Ok&lt;/code&gt; of the value or &lt;code&gt;Err&lt;/code&gt; of the error, which
&lt;code&gt;okOrElse&lt;/code&gt; calls only for &lt;code&gt;None&lt;/code&gt; (&lt;code&gt;Result&lt;/code&gt;‘s &lt;code&gt;ok&lt;/code&gt; and &lt;code&gt;err&lt;/code&gt; go the other way). It also has &lt;code&gt;iterator()&lt;/code&gt; (one element or none) and &lt;code&gt;knownSize&lt;/code&gt; (1 or 0), and a second &lt;code&gt;flatMap&lt;/code&gt; taking a function that answers a collection, which answers a &lt;code&gt;Vector&lt;/code&gt; (empty for &lt;code&gt;None&lt;/code&gt;); every collection’s &lt;code&gt;flatMap&lt;/code&gt; takes a function answering an option, so &lt;code&gt;xs.flatMap(_.toIntOption())&lt;/code&gt; keeps the numbers and a &lt;code&gt;for&lt;/code&gt; comprehension draws from options and collections alike (&lt;a href=&quot;/spec/collections/#operations-without-higher-kinded-types&quot;&gt;collections&lt;/a&gt;). An
&lt;code&gt;Option[(A, B)]&lt;/code&gt; has &lt;code&gt;unzip&lt;/code&gt; giving the two options, an &lt;code&gt;Option[Option[T]]&lt;/code&gt; also has &lt;code&gt;flatten&lt;/code&gt;, and an &lt;code&gt;Option&lt;/code&gt; has &lt;code&gt;nonEmpty&lt;/code&gt; beside &lt;code&gt;isDefined&lt;/code&gt; and
&lt;code&gt;isEmpty&lt;/code&gt;. There is no &lt;code&gt;orNull&lt;/code&gt;, since Avin has no null.&lt;/p&gt;
&lt;p&gt;The companion makes an option from a condition: &lt;code&gt;Option.when(condition, value)&lt;/code&gt; is &lt;code&gt;Some(value)&lt;/code&gt;
where &lt;code&gt;condition&lt;/code&gt; holds and &lt;code&gt;None&lt;/code&gt; where it does not, and &lt;code&gt;Option.unless(condition, value)&lt;/code&gt; the other
way round. The value is passed by name, so it is evaluated only for &lt;code&gt;Some&lt;/code&gt;, and once:
&lt;code&gt;Option.when(n &amp;gt; 0, expensive(n))&lt;/code&gt; calls &lt;code&gt;expensive&lt;/code&gt; only for a positive &lt;code&gt;n&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An &lt;code&gt;Option[T]&lt;/code&gt; is an &lt;code&gt;Ord&lt;/code&gt; when &lt;code&gt;T&lt;/code&gt; is: &lt;code&gt;None&lt;/code&gt; orders before every &lt;code&gt;Some&lt;/code&gt;, and two &lt;code&gt;Some&lt;/code&gt;s order as
their values. So &lt;code&gt;derives Ord&lt;/code&gt; works on a data type with an &lt;code&gt;Option&lt;/code&gt; field, a &lt;code&gt;Vector[Option[int]]&lt;/code&gt;
sorts and has a &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt;, and &lt;code&gt;None &amp;lt; Some(0)&lt;/code&gt;. The order nests (&lt;code&gt;None&lt;/code&gt;, &lt;code&gt;Some(None)&lt;/code&gt;,
&lt;code&gt;Some(Some(1))&lt;/code&gt;), and an option of a type without &lt;code&gt;Ord&lt;/code&gt; has none.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;exists&lt;/code&gt; is false and &lt;code&gt;forall&lt;/code&gt; true for &lt;code&gt;None&lt;/code&gt; and for &lt;code&gt;Err&lt;/code&gt;, which hold no value. &lt;code&gt;toList&lt;/code&gt; and
&lt;code&gt;toVector&lt;/code&gt; give one element or none.&lt;/p&gt;
&lt;p&gt;A default or an alternative is passed by name, so it is evaluated only when it is used. A method
that takes in a value which may be wider than the one held takes it as a type with &lt;code&gt;T&lt;/code&gt; (or &lt;code&gt;E&lt;/code&gt;) as
its &lt;a href=&quot;/spec/generics/#lower-bounds&quot;&gt;lower bound&lt;/a&gt;, and the result widens to it: on an &lt;code&gt;Option[Cat]&lt;/code&gt;,
&lt;code&gt;getOrElse(dog)&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;orElse(Some(dog))&lt;/code&gt; an &lt;code&gt;Option[Animal]&lt;/code&gt;, and &lt;code&gt;contains(animal)&lt;/code&gt;
compares the cat with an &lt;code&gt;Animal&lt;/code&gt;. On an &lt;code&gt;Option[int]&lt;/code&gt; the bound admits only &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;None&lt;/code&gt; with nothing to settle its type is an &lt;code&gt;Option[Nothing]&lt;/code&gt;, and &lt;code&gt;Ok(1)&lt;/code&gt; a &lt;code&gt;Result[int, Nothing]&lt;/code&gt; (see &lt;a href=&quot;/spec/generics/#inference&quot;&gt;inference&lt;/a&gt;). No value has type &lt;code&gt;Nothing&lt;/code&gt;, so either is an
instance of any &lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Result&lt;/code&gt; with the other arguments: a module’s &lt;code&gt;val none = None&lt;/code&gt; is an
&lt;code&gt;Option[int]&lt;/code&gt; where one is wanted.&lt;/p&gt;
&lt;h2 id=&quot;either&quot;&gt;Either&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Either&lt;/code&gt; holds a value of one of two types. It is a &lt;code&gt;data&lt;/code&gt; type of the core library, written in Avin,
covariant in both sides:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Either[+L, +R]
  Left(value: L)
  Right(value: R)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Result&lt;/code&gt; is the type for something that can fail, and it is what &lt;code&gt;?&lt;/code&gt; takes apart; &lt;code&gt;Either&lt;/code&gt; is the
plain choice of two, with no &lt;code&gt;?&lt;/code&gt; and no &lt;code&gt;From&lt;/code&gt;. Its methods are right-biased: those that look at a
value look at a &lt;code&gt;Right&lt;/code&gt;‘s and pass a &lt;code&gt;Left&lt;/code&gt; through unchanged, so a &lt;code&gt;Left&lt;/code&gt; is where a reason goes.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;On a &lt;code&gt;Right(b)&lt;/code&gt;&lt;/th&gt;&lt;th&gt;On a &lt;code&gt;Left(a)&lt;/code&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isLeft&lt;/code&gt;, &lt;code&gt;isRight&lt;/code&gt;&lt;/td&gt;&lt;td&gt;false, true&lt;/td&gt;&lt;td&gt;true, false&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;fold[C](fa: (L) -&amp;gt; C, fb: (R) -&amp;gt; C) -&amp;gt; C&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;fb(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;fa(a)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;swap -&amp;gt; Either[R, L]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Left(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Right(a)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;map[R2](f: (R) -&amp;gt; R2) -&amp;gt; Either[L, R2]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Right(f(b))&lt;/code&gt;&lt;/td&gt;&lt;td&gt;itself&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flatMap[L1 &amp;gt;: L, R2](f: (R) -&amp;gt; Either[L1, R2]) -&amp;gt; Either[L1, R2]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;f(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;itself&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;getOrElse[R1 &amp;gt;: R](default: -&amp;gt; R1) -&amp;gt; R1&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;b&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;default&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;orElse[L1 &amp;gt;: L, R1 &amp;gt;: R](other: -&amp;gt; Either[L1, R1]) -&amp;gt; Either[L1, R1]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;itself&lt;/td&gt;&lt;td&gt;&lt;code&gt;other&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;contains[R1 &amp;gt;: R](x: R1) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;b == x&lt;/code&gt;&lt;/td&gt;&lt;td&gt;false&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exists(p: (R) -&amp;gt; bool) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;p(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;false&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;forall(p: (R) -&amp;gt; bool) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;p(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;true&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;filterOrElse[L1 &amp;gt;: L](p: (R) -&amp;gt; bool, zero: -&amp;gt; L1) -&amp;gt; Either[L1, R]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;itself if &lt;code&gt;p(b)&lt;/code&gt;, else &lt;code&gt;Left(zero)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;itself&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toOption -&amp;gt; Option[R]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Some(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;None&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toList -&amp;gt; List[R]&lt;/code&gt;, &lt;code&gt;toVector -&amp;gt; Vector[R]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;one element&lt;/td&gt;&lt;td&gt;empty&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;foreach(f: (R) -&amp;gt; unit)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;calls &lt;code&gt;f(b)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;nothing&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;iterator() -&amp;gt; Iterator[R]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;one element&lt;/td&gt;&lt;td&gt;empty&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Some methods are for an &lt;code&gt;Either&lt;/code&gt; of a particular shape, added by an &lt;code&gt;impl&lt;/code&gt; on it as &lt;code&gt;Option&lt;/code&gt;‘s
&lt;code&gt;flatten&lt;/code&gt; is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;merge&lt;/code&gt; on an &lt;code&gt;Either[A, A]&lt;/code&gt; gives the value from whichever side holds it.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;joinLeft&lt;/code&gt; on an &lt;code&gt;Either[Either[C, R], R]&lt;/code&gt; gives the inner either of a &lt;code&gt;Left&lt;/code&gt;, and keeps a &lt;code&gt;Right&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;joinRight&lt;/code&gt; on an &lt;code&gt;Either[L, Either[L, C]]&lt;/code&gt; gives the inner either of a &lt;code&gt;Right&lt;/code&gt;, and keeps a &lt;code&gt;Left&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;Either.cond[L, R](test: bool, right: -&amp;gt; R, left: -&amp;gt; L) -&amp;gt; Either[L, R]&lt;/code&gt; is &lt;code&gt;Right(right)&lt;/code&gt; when
&lt;code&gt;test&lt;/code&gt; holds and &lt;code&gt;Left(left)&lt;/code&gt; otherwise, evaluating only the side it uses. Defaults and alternatives
are passed by name, and a value taken in may be wider than its side, through a lower bound, as for
&lt;code&gt;Option&lt;/code&gt;: on an &lt;code&gt;Either[string, Cat]&lt;/code&gt;, &lt;code&gt;getOrElse(dog)&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;. &lt;code&gt;Left(1)&lt;/code&gt; with nothing to
settle its right side is an &lt;code&gt;Either[int, Nothing]&lt;/code&gt;, an instance of any &lt;code&gt;Either[int, R]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; covers an &lt;code&gt;Either&lt;/code&gt; with a &lt;code&gt;Left&lt;/code&gt; and a &lt;code&gt;Right&lt;/code&gt; arm that each cover their value. Eithers are
equal, hash and show by side and value: &lt;code&gt;Right(4)&lt;/code&gt;, &lt;code&gt;Left(no)&lt;/code&gt;, and under &lt;code&gt;debug&lt;/code&gt; &lt;code&gt;Left(&amp;quot;no&amp;quot;)&lt;/code&gt;.
There is no left projection: &lt;code&gt;swap&lt;/code&gt; turns the left side into the one the methods work on.&lt;/p&gt;
&lt;p&gt;An &lt;code&gt;Either[L, R]&lt;/code&gt; is an &lt;code&gt;Ord&lt;/code&gt; when &lt;code&gt;L&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt; are: every &lt;code&gt;Left&lt;/code&gt; orders before every &lt;code&gt;Right&lt;/code&gt;, and two
on the same side order as their values. A &lt;code&gt;Result[T, E]&lt;/code&gt; is ordered the same way with &lt;code&gt;Err&lt;/code&gt; in the
place of &lt;code&gt;Left&lt;/code&gt; and &lt;code&gt;Ok&lt;/code&gt; in the place of &lt;code&gt;Right&lt;/code&gt;: every &lt;code&gt;Err&lt;/code&gt; before every &lt;code&gt;Ok&lt;/code&gt;, so a failure sorts
before a success exactly as a &lt;code&gt;Left&lt;/code&gt; sorts before a &lt;code&gt;Right&lt;/code&gt;. Both sort, have &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt;, key a
&lt;code&gt;TreeMap&lt;/code&gt; or &lt;code&gt;TreeSet&lt;/code&gt;, and may be a field of a type that &lt;code&gt;derives Ord&lt;/code&gt;; they nest with &lt;code&gt;Option&lt;/code&gt; and
tuples, and one with a part of a type that has no &lt;code&gt;Ord&lt;/code&gt; has none.&lt;/p&gt;
&lt;h2 id=&quot;not-in-avin&quot;&gt;Not in Avin&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;throw&lt;/code&gt;, &lt;code&gt;try&lt;/code&gt;/&lt;code&gt;catch&lt;/code&gt;/&lt;code&gt;finally&lt;/code&gt;, &lt;code&gt;Try&lt;/code&gt;, checked or unchecked exceptions, and &lt;code&gt;null&lt;/code&gt;. A resource is
given back on every path, the early &lt;code&gt;return&lt;/code&gt;s and &lt;code&gt;?&lt;/code&gt;s included, by a
&lt;a href=&quot;/spec/operators-and-control-flow/#defer&quot;&gt;&lt;code&gt;defer&lt;/code&gt;&lt;/a&gt; written beside the code that took it.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Equality, identity and memory</title>
    <link href="https://avinlang.dev/spec/equality-and-memory/"/>
    <id>https://avinlang.dev/spec/equality-and-memory/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Typed equality, identity only where it exists, Display and Debug, and the garbage-collected heap.</summary>
    <content type="html">&lt;h2 id=&quot;equality&quot;&gt;Equality&lt;/h2&gt;
&lt;p&gt;Every value can be compared with &lt;code&gt;==&lt;/code&gt; and hashed, so any value can be a key in a &lt;code&gt;Map&lt;/code&gt; or an
element of a &lt;code&gt;Set&lt;/code&gt;. &lt;code&gt;!=&lt;/code&gt; is the negation.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Built-in types, strings, tuples and &lt;code&gt;data&lt;/code&gt; types compare and hash by value, structurally.&lt;/li&gt;
&lt;li&gt;Collections compare by contents when their elements do. This includes &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;Buffer&lt;/code&gt;: two
arrays are equal when they have the same length and equal elements in order, and &lt;code&gt;===&lt;/code&gt; compares
their identities.&lt;/li&gt;
&lt;li&gt;Class instances, &lt;code&gt;object&lt;/code&gt;s and closures compare and hash by identity, which always agree, unless
the class implements or derives &lt;code&gt;Eq&lt;/code&gt;. &lt;code&gt;class Point(x: int, y: int) derives Eq, Hash&lt;/code&gt; compares and
hashes by its fields.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;a == b&lt;/code&gt; requires &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; to have a common type: comparing an &lt;code&gt;int&lt;/code&gt; with a &lt;code&gt;string&lt;/code&gt; is a compile
error, not &lt;code&gt;false&lt;/code&gt;. Where the common type is &lt;code&gt;Any&lt;/code&gt; or a trait, the comparison is decided at run time
by the values’ own types, and values of different types are unequal, except that sequences are
equal when their elements are equal in order whatever their classes (&lt;code&gt;Any&lt;/code&gt; holding &lt;code&gt;[1, 2]&lt;/code&gt; equals a
&lt;code&gt;List(1, 2)&lt;/code&gt;), with hashes that agree. An array compares as a sequence, by its contents, as
elsewhere in Avin.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;==&lt;/code&gt; is &lt;code&gt;Eq&lt;/code&gt;‘s &lt;code&gt;equals(other: Self) -&amp;gt; bool&lt;/code&gt; and the hash is &lt;code&gt;Hash&lt;/code&gt;‘s &lt;code&gt;hash() -&amp;gt; long&lt;/code&gt;. Every type
conforms to both without declaring it, so &lt;code&gt;[K: Eq &amp;amp; Hash]&lt;/code&gt; admits any key type, and &lt;code&gt;x.equals(y)&lt;/code&gt;
and &lt;code&gt;x.hash()&lt;/code&gt; may be called on any value. A type that implements &lt;code&gt;Eq&lt;/code&gt; in an impl, or in a class’s
header, compares by its own &lt;code&gt;equals&lt;/code&gt; wherever it is compared: written directly, through a bound, as a
field of a data value or a part of a tuple, and as an &lt;code&gt;Any&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Equal values must have equal hashes. &lt;code&gt;derives Eq, Hash&lt;/code&gt; gives both from the same fields, so they
agree. A class that implements one of &lt;code&gt;==&lt;/code&gt; and the hash by hand must implement the other, and keeping
the two consistent is then its author’s responsibility. &lt;code&gt;Ord&lt;/code&gt; is never derived implicitly;
&lt;code&gt;derives Ord&lt;/code&gt; orders lexicographically by field, and by variant declaration order; its &lt;code&gt;compare&lt;/code&gt; is
-1, 0 or 1.&lt;/p&gt;
&lt;p&gt;A class derives from its constructor parameters, whether plain, &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt;, in the order they are
written; fields its body declares take no part. It derives &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; together, and &lt;code&gt;Ord&lt;/code&gt; only
beside an &lt;code&gt;Eq&lt;/code&gt; by the same fields. A data type derives from each variant’s fields, and already
compares and hashes by them, so &lt;code&gt;derives Eq, Hash&lt;/code&gt; on it changes nothing. Each field’s type must
implement what is derived from it: &lt;code&gt;class Ranked(p: Plain) derives Eq, Hash, Ord&lt;/code&gt; is an error naming
&lt;code&gt;p&lt;/code&gt; when &lt;code&gt;Plain&lt;/code&gt; has no &lt;code&gt;Ord&lt;/code&gt;. A generic type’s derived &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;, a data type’s
or a class’s, hold for the type arguments that implement the trait: &lt;code&gt;data Pair[A, B](a: A, b: B) derives Display&lt;/code&gt; displays a &lt;code&gt;Pair[int, string]&lt;/code&gt;, and a &lt;code&gt;Pair[Plain, int]&lt;/code&gt; is still made but does not
display.&lt;/p&gt;
&lt;p&gt;All five derivations are &lt;a href=&quot;/derivation#the-built-in-derivations&quot;&gt;derive templates&lt;/a&gt; in the core
library, written against the type’s shape as any library’s are; what is the language’s own is only
when they apply.&lt;/p&gt;
&lt;h2 id=&quot;identity&quot;&gt;Identity&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;a === b&lt;/code&gt; is reference identity, and &lt;code&gt;!==&lt;/code&gt; its negation. It is defined only where its answer is: at
least one side’s type must be a reference type that cannot hold a value type, that is a class (an
&lt;code&gt;object&lt;/code&gt;, an array and a buffer among them), a function type, or a type parameter bounded by a
class. The other side may then be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the same type, or a sub- or superclass of the class;&lt;/li&gt;
&lt;li&gt;a trait the class conforms to: &lt;code&gt;elements === self&lt;/code&gt;, with &lt;code&gt;elements: Iterable[T]&lt;/code&gt;, asks whether a
buffer was given itself;&lt;/li&gt;
&lt;li&gt;an &lt;code&gt;Any&lt;/code&gt;, or a type parameter with no class bound.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A value type on the other side, boxed as an &lt;code&gt;Any&lt;/code&gt; or a trait’s value, is never the object of a class,
so the answer is &lt;code&gt;false&lt;/code&gt; whatever the compiler did with the value: &lt;code&gt;x === obj&lt;/code&gt; with &lt;code&gt;x: Any&lt;/code&gt; holding
&lt;code&gt;4&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;===&lt;/code&gt; is a compile error on a value type (a built-in type, a string, a tuple, a &lt;code&gt;data&lt;/code&gt; type, an
&lt;code&gt;Option&lt;/code&gt; among them), since a value type has no identity to compare. It is also an error when
neither side is such a reference, with both sides traits, &lt;code&gt;Any&lt;/code&gt;s or type parameters that may hold a
value type: whether two equal values are one object is the compiler’s choice, so &lt;code&gt;f(Tile(2), Tile(2))&lt;/code&gt; and &lt;code&gt;f(3, 3)&lt;/code&gt; with &lt;code&gt;f(a: Shape, b: Shape) = a === b&lt;/code&gt; would answer differently for no
reason the program can see. The message suggests &lt;code&gt;==&lt;/code&gt;, or a class type for one side.&lt;/p&gt;
&lt;h2 id=&quot;display-and-debug&quot;&gt;Display and Debug&lt;/h2&gt;
&lt;p&gt;Text rendering comes from two traits. &lt;code&gt;Display&lt;/code&gt; is the human form, used by &lt;code&gt;println&lt;/code&gt;,
interpolation and &lt;code&gt;toString()&lt;/code&gt;. &lt;code&gt;Debug&lt;/code&gt; is the diagnostic form, used by &lt;code&gt;debug(x)&lt;/code&gt;, where strings are
quoted and escaped. Both render into a &lt;code&gt;Writer&lt;/code&gt; with a &lt;code&gt;FormatSpec&lt;/code&gt;, so formatting a value needs no
intermediate string. &lt;code&gt;data&lt;/code&gt; types and tuples derive both; classes declare them. Nothing has a default
that prints an address.&lt;/p&gt;
&lt;p&gt;A tuple is also an &lt;code&gt;Ord&lt;/code&gt; where each of its parts is, at every arity: part by part, the first part
that differs deciding, so later parts break ties. &lt;code&gt;(1, &amp;quot;b&amp;quot;) &amp;lt; (2, &amp;quot;a&amp;quot;)&lt;/code&gt;, and &lt;code&gt;(1, 2) &amp;lt; (1, 3)&lt;/code&gt;.
&lt;code&gt;bool&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt; with &lt;code&gt;false&lt;/code&gt; before &lt;code&gt;true&lt;/code&gt;, operators included, so &lt;code&gt;tasks.sortBy(t -&amp;gt; (t.done, t.id))&lt;/code&gt; puts the open tasks first; &lt;code&gt;unit&lt;/code&gt; has no order, so a tuple holding one has none. &lt;code&gt;List&lt;/code&gt; and &lt;code&gt;ArraySeq&lt;/code&gt; are &lt;code&gt;Ord&lt;/code&gt;
where their elements are, element by element with a prefix before the longer sequence, and
&lt;code&gt;Reverse[T]&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt; with the order of &lt;code&gt;T&lt;/code&gt; turned round (&lt;a href=&quot;/spec/collections/#sorting&quot;&gt;collections&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;data&lt;/code&gt; type has both without asking, wherever its fields have them: &lt;code&gt;println(Some(3))&lt;/code&gt; writes
&lt;code&gt;Some(3)&lt;/code&gt;, and &lt;code&gt;assertEq(Some(3), Some(3))&lt;/code&gt; needs nothing written. &lt;code&gt;derives Display, Debug&lt;/code&gt; on a data
type is allowed and means the same. An impl of the type’s own replaces the automatic one: &lt;code&gt;impl Display for Money&lt;/code&gt; gives &lt;code&gt;Money&lt;/code&gt; its own &lt;code&gt;Display&lt;/code&gt; while its &lt;code&gt;Debug&lt;/code&gt; stays the derived one, and &lt;code&gt;List&lt;/code&gt;,
&lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; keep their literal forms this way. A field without the trait leaves the type without
it rather than being an error: &lt;code&gt;data Wrapper(p: Plain)&lt;/code&gt; is made, compared and matched, and only a use
that needs its &lt;code&gt;Display&lt;/code&gt; is rejected, naming the field. A program that never shows a value compiles
none of this code; it makes only each type’s shape, before &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A derived &lt;code&gt;Display&lt;/code&gt; writes the type’s or variant’s name and its fields in parentheses, separated by
&lt;code&gt;, &lt;/code&gt;, each in its own &lt;code&gt;Display&lt;/code&gt; form: &lt;code&gt;Point(1, 2)&lt;/code&gt;, &lt;code&gt;Named(ada, Point(1, 2))&lt;/code&gt;. A variant without
fields is its bare name, &lt;code&gt;Empty&lt;/code&gt;, and so is a class without constructor parameters. A derived &lt;code&gt;Debug&lt;/code&gt; has the same shape with each field’s &lt;code&gt;Debug&lt;/code&gt;
form, so strings and chars inside are quoted and escaped: &lt;code&gt;Named(&amp;quot;ada&amp;quot;, Point(1, 2))&lt;/code&gt;. A field width
in the &lt;code&gt;FormatSpec&lt;/code&gt; pads the whole rendering; the fields themselves are written without one. Derived
on a generic type, either holds for the type arguments that implement the trait: &lt;code&gt;data Box[T](item: T)&lt;/code&gt; displays a &lt;code&gt;Box[int]&lt;/code&gt;, and a &lt;code&gt;Box&lt;/code&gt; of a type without &lt;code&gt;Display&lt;/code&gt; does not display.&lt;/p&gt;
&lt;p&gt;A collection displays as its elements in brackets, separated by &lt;code&gt;, &lt;/code&gt;, each in its own &lt;code&gt;Display&lt;/code&gt; form:
an &lt;code&gt;Array[int]&lt;/code&gt; or a &lt;code&gt;List[int]&lt;/code&gt; as &lt;code&gt;[1, 2, 3]&lt;/code&gt;, an empty one as &lt;code&gt;[]&lt;/code&gt;, nested ones as &lt;code&gt;[[1], [2, 3]]&lt;/code&gt;. Its &lt;code&gt;Debug&lt;/code&gt; has the same shape with each element’s &lt;code&gt;Debug&lt;/code&gt; form, &lt;code&gt;[&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;]&lt;/code&gt;. A field width
pads the whole. A collection displays only when its elements do.&lt;/p&gt;
&lt;h2 id=&quot;values-and-references&quot;&gt;Values and references&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Kind&lt;/th&gt;&lt;th&gt;Examples&lt;/th&gt;&lt;th&gt;Identity&lt;/th&gt;&lt;th&gt;Representation&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, tuples, &lt;code&gt;data&lt;/code&gt;&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Chosen by the compiler: in registers or inline, or on the heap for recursive or large &lt;code&gt;data&lt;/code&gt;. The program cannot tell which.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Reference&lt;/td&gt;&lt;td&gt;class instances, &lt;code&gt;object&lt;/code&gt;s, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, closures, boxes&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;td&gt;A pointer to a heap object whose header names its exact type&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Because &lt;code&gt;data&lt;/code&gt; values are immutable and have no identity, sharing, copying, inlining and boxing them
all give the same observable behaviour, so the compiler is free to choose among them.&lt;/p&gt;
&lt;h2 id=&quot;the-heap&quot;&gt;The heap&lt;/h2&gt;
&lt;p&gt;Reference types, and value types the compiler places on the heap, are managed by a precise, nonmoving
tracing collector: Sysl’s &lt;code&gt;sh.sysl.gc&lt;/code&gt;, shared with Slate. There is no manual freeing and no
reference counting in Avin code.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The compiler emits precise roots for every live reference, including temporaries and captured
variables, through a shadow stack. A conservative scan is never needed.&lt;/li&gt;
&lt;li&gt;Collection happens at allocation when the heap is under pressure. The heap grows within a
configured limit.&lt;/li&gt;
&lt;li&gt;Garbage collection is never the only way a scarce resource is released. Files, sockets and Sysl
handles have an explicit &lt;code&gt;close()&lt;/code&gt;, and a finalizer is only a safety net.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;closures&quot;&gt;Closures&lt;/h2&gt;
&lt;p&gt;A lambda or local function that captures variables is a heap object holding its environment.
Immutable captures are copied in; a captured &lt;code&gt;var&lt;/code&gt; is shared, so the closure and the enclosing scope
see the same variable. A closure that does not escape may be allocated on the stack. That is an
optimization with no visible difference.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Editors</title>
    <link href="https://avinlang.dev/getting-started/editors/"/>
    <id>https://avinlang.dev/getting-started/editors/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>The language server, `avin lsp`, and what it answers.</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;avin lsp&lt;/code&gt; is a language server: it speaks the Language Server Protocol over standard input and
output, so any editor with a protocol client can show Avin’s diagnostics, types and declarations as
you type. The answers come from the compiler itself, from the same parse and the same checking that
&lt;code&gt;avin check&lt;/code&gt; does, so the server and the build never disagree about a program.&lt;/p&gt;
&lt;h2 id=&quot;running-it&quot;&gt;Running it&lt;/h2&gt;
&lt;p&gt;An editor starts the server as a command and talks to it over its standard input and output:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;avin lsp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;avin lsp --stdio&lt;/code&gt; is the same command; the flag is what many protocol clients pass to say which
transport they use, and standard input and output is the one there is. The server finds the
library as the other commands do: in &lt;code&gt;share/avin&lt;/code&gt; beside an installed compiler, in a source
checkout beside its &lt;code&gt;compiler/avin&lt;/code&gt;, or through &lt;code&gt;AVIN_ROOT&lt;/code&gt;. It runs until the
editor sends &lt;code&gt;shutdown&lt;/code&gt; and then &lt;code&gt;exit&lt;/code&gt;, and ends with status 0; an editor that closes the input
without them, or a message whose framing cannot be read, ends it with status 1.&lt;/p&gt;
&lt;p&gt;Unsaved text is analyzed as it stands in the editor: the server reads an open document’s text in
place of the file on disk, for every file of the program, and writes nothing anywhere.&lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;/spec/declarations/#literate-source&quot;&gt;literate&lt;/a&gt; &lt;code&gt;.lavin&lt;/code&gt; document is answered like an &lt;code&gt;.avin&lt;/code&gt;
file: its program is the lines indented four columns, and every position the server reports or
reads, a diagnostic’s range, a hover’s, a definition’s place and the outline’s, is the document’s
own line and column. The VS Code extension in &lt;code&gt;editors/vscode&lt;/code&gt; registers &lt;code&gt;.lavin&lt;/code&gt; files as
&lt;em&gt;Literate Avin&lt;/em&gt;, highlights their program blocks as Avin and their prose as Markdown, and starts the
same server for them.&lt;/p&gt;
&lt;h2 id=&quot;which-program-a-file-belongs-to&quot;&gt;Which program a file belongs to&lt;/h2&gt;
&lt;p&gt;Every change is answered by checking the whole program the file belongs to, together with the
library, as &lt;code&gt;avin check&lt;/code&gt; would check it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A file under the library’s &lt;code&gt;library/&lt;/code&gt; directory is checked as the library, module &lt;code&gt;avin&lt;/code&gt; and
the modules under it.&lt;/li&gt;
&lt;li&gt;A file whose &lt;code&gt;module a.b&lt;/code&gt; header matches where it sits, &lt;code&gt;&amp;lt;root&amp;gt;/a/b/file.avin&lt;/code&gt;, is checked with
the program rooted at &lt;code&gt;&amp;lt;root&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A file with no header is a root file of the program in its directory when that directory has
modules in directories below it.&lt;/li&gt;
&lt;li&gt;Any other file is a program by itself.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-it-answers&quot;&gt;What it answers&lt;/h2&gt;
&lt;p&gt;The server announces exactly these capabilities in its answer to &lt;code&gt;initialize&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Request&lt;/th&gt;&lt;th&gt;Answer&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/didOpen&lt;/code&gt;, &lt;code&gt;didChange&lt;/code&gt;, &lt;code&gt;didSave&lt;/code&gt;, &lt;code&gt;didClose&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Full-text synchronization: each change carries the document’s whole text&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/publishDiagnostics&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Syntax errors, the first on each line, and the checker’s errors, for every file of the program, the library’s included, with an empty list for a file that has become clean. A syntax error stops the analysis at the parse, as it stops a build&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/hover&lt;/code&gt;&lt;/td&gt;&lt;td&gt;For the name under the cursor, what the checker knew about it, as Avin code: a local’s, a parameter’s, a field’s or a module value’s type (&lt;code&gt;val p: Point&lt;/code&gt;), a function’s or a method’s signature (&lt;code&gt;Point.norm() -&amp;gt; int&lt;/code&gt;), a type’s declaration, a variant with its fields. The &lt;code&gt;//&lt;/code&gt; or &lt;code&gt;/** … */&lt;/code&gt; comment directly above the declaration follows it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/definition&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Where the name under the cursor was declared: a local, a parameter, a function, a method, a field, a type, a variant, a module-level value, an imported name or module, in the same file, another file of the program or the library&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/documentSymbol&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The document’s outline: classes, traits and objects with their fields and methods, data types with their variants, impls with their methods, functions and module values. A function’s local functions are its children, at any depth, and a &lt;code&gt;@test&lt;/code&gt; function carries the test’s description as its detail, or &lt;code&gt;@test&lt;/code&gt; where it has none. It is read from the parse, so it is there while the program has mistakes in it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;workspace/symbol&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The declarations of every program an open document belongs to, every file of it whether open or not (a dependency’s files are left out): types, variants, classes, traits and objects, functions, module values, actors, machines with their states, and methods. Each names its module as its container, or for a method, a variant or a state its type (&lt;code&gt;geo.Point&lt;/code&gt;), and its location is its name. A name matches when it holds the query’s characters in order, not necessarily together, an ASCII letter matching either case (&lt;code&gt;pnt&lt;/code&gt; finds &lt;code&gt;Point&lt;/code&gt;); an empty query matches everything. At most 500 are listed&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/foldingRange&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Whole lines: each indented block from the line that opens it to its last line of code (a declaration’s body; a class, impl, actor, machine or state body; a match’s arms and an arm’s body; any other block), a text block, a run of two or more comment lines (kind &lt;code&gt;comment&lt;/code&gt;), the run of &lt;code&gt;import&lt;/code&gt; lines (kind &lt;code&gt;imports&lt;/code&gt;), and in a literate file each run of program text, its prose left out (kind &lt;code&gt;region&lt;/code&gt;). Regions nest; none is one line&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/references&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every place the program names what the name under the cursor names, in every file of the program and the library, in the order of their files; the declaration’s own name with them when the request’s &lt;code&gt;includeDeclaration&lt;/code&gt; asks for it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/documentHighlight&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The places in the document that name the same thing, the declaration marked as a write and each use as a read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/prepareRename&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The name under the cursor and where it is written, or the reason it cannot be renamed. &lt;a href=&quot;#rename&quot;&gt;Rename&lt;/a&gt; below says which names may be&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/rename&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The edit that gives the name under the cursor a new name everywhere the program names it, in every file of the program&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/semanticTokens/full&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Every name the checker resolved in the document, classified by what it names; the legend is below&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/completion&lt;/code&gt;&lt;/td&gt;&lt;td&gt;What may be written at the cursor, as the checker sees the scope there; triggered by &lt;code&gt;.&lt;/code&gt; as well as by typing a name. &lt;a href=&quot;#completion&quot;&gt;Completion&lt;/a&gt; below says what each place offers&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/formatting&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The document in the style &lt;code&gt;avin fmt&lt;/code&gt; writes, as one edit over the whole text; no edit when it is in the style already, and none while it does not parse. The request’s options are not read: the style has no settings&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;textDocument/rangeFormatting&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The top-level declarations the range touches, formatted as one edit over their whole lines; nothing outside them changes, text blocks keep every byte, and in a literate file only program lines are edited. No edit when they are in the style already, when the range holds no declaration, and none while the file does not parse&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A call through a method table goes to the method the receiver’s static type declares, and a call of
an overloaded function to the overload the checker chose. References follow the same choice: the
references of a trait’s method are the calls made through the trait, and those of a class’s
override are the calls on that class, so asking from &lt;code&gt;Shape.area&lt;/code&gt; does not list a call the checker
resolved to &lt;code&gt;Circle.area&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;rename&quot;&gt;Rename&lt;/h3&gt;
&lt;p&gt;Rename is built on the same references. It renames locals, parameters, fields, methods, types, a
module’s functions and values, pattern bindings and type parameters, with the names a call writes
for a parameter or a record’s field (&lt;code&gt;scale(width = 3)&lt;/code&gt;), in &lt;code&gt;.avin&lt;/code&gt; and &lt;code&gt;.lavin&lt;/code&gt; files alike. A
method is renamed together with the methods it overrides or implements and those that override or
implement it, so renaming &lt;code&gt;Shape.area&lt;/code&gt; renames &lt;code&gt;Circle.area&lt;/code&gt; too, from either end. A name written
with its module (&lt;code&gt;geo.area&lt;/code&gt;) is replaced after the last dot, and an import’s alias, which is a name
of its own, is left alone.&lt;/p&gt;
&lt;p&gt;A rename is refused, with the reason as the error’s message, when it would change what the program
means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the name is declared in the core library or a dependency, or a method of the family implements or
overrides one that is (an &lt;code&gt;impl Add for Point&lt;/code&gt;‘s &lt;code&gt;add&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;the name is a module or an operator;&lt;/li&gt;
&lt;li&gt;the new name is a reserved word, or is not a name (a letter or &lt;code&gt;_&lt;/code&gt;, then letters, digits and &lt;code&gt;_&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;the new name would clash with one in scope where the old one is used. The server checks the
program as the edit would leave it: every name must still mean what it meant, and no new
diagnostic may appear;&lt;/li&gt;
&lt;li&gt;the program has a syntax error, since the places of its names are not known.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;completion&quot;&gt;Completion&lt;/h3&gt;
&lt;p&gt;Completion is answered by the checker, at the place the cursor is, so what it offers is exactly
what would compile there:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Where&lt;/th&gt;&lt;th&gt;What it offers&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;After &lt;code&gt;.&lt;/code&gt; on a value&lt;/td&gt;&lt;td&gt;Its static type’s members: fields, methods, inherited ones and those of the traits it conforms to, the methods impls add to it or to its traits, and an extension’s where the file sees it; a private member only where the code may use it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;After a module’s name, &lt;code&gt;io.&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The module’s public declarations&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;After a type’s name, &lt;code&gt;Map.&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Its static members, and the members of its companion object&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A name in an expression&lt;/td&gt;&lt;td&gt;The locals and parameters in scope at the cursor, then the enclosing class’s members, then the module’s declarations, then the file’s imports, then the core library’s, then the keywords that begin an expression or a local declaration: &lt;code&gt;def&lt;/code&gt;, &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;loop&lt;/code&gt;, &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt;, &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Where a type is written: after &lt;code&gt;:&lt;/code&gt;, after &lt;code&gt;-&amp;gt;&lt;/code&gt;, in &lt;code&gt;[…]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Types only: type parameters, the module’s types, imported ones, the core library’s and the built-in types&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;In an import, &lt;code&gt;import a.&lt;/code&gt; or &lt;code&gt;import a.b.{…}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The modules below the one named and its public declarations; inside braces, the declarations only&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Each item carries what hover would show for it, a signature or a type, and the comment above its
declaration, and is sorted by how near its scope is. The editor filters the list as you type. Where
the editor says at &lt;code&gt;initialize&lt;/code&gt; that it expands snippets, a call is completed with a placeholder for
each argument without a default: &lt;code&gt;fetch(${1:thing}, ${2:times})&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The line being typed rarely parses, so the server completes in a copy of the document: the word at
the cursor is replaced by a stand-in name, and where that still does not parse, the rest of the line
is replaced by the brackets that close it, then the lines after the cursor’s declaration are blanked.
The first copy that parses is checked with the program, and what the checker found at the stand-in
is the answer. Nothing else is kept: the document’s diagnostics, hover and references stay those of
its last change. In a literate document only the program is completed; the prose, comments and
strings offer nothing. A completion in the largest file of the library takes about 130 ms.&lt;/p&gt;
&lt;h3 id=&quot;semantic-tokens&quot;&gt;Semantic tokens&lt;/h3&gt;
&lt;p&gt;Names are coloured by what the checker resolved them to, so a field and a local of the same name,
or a function and a variable, are told apart wherever they are written. Keywords, literals,
operators and comments are left to the editor’s grammar.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Token type&lt;/th&gt;&lt;th&gt;Names&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;namespace&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A module, in an import and before a member read through it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;class&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A class or an object&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;struct&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A data type with one variant, and that variant constructing it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A data type with several variants&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;interface&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A trait&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;typeParameter&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A type parameter&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;enumMember&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A variant of a data type with several&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;function&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A top-level or local function&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;method&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A method of a class, a trait or an impl&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;property&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A field&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parameter&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A parameter&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;variable&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A local or a module-level value&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Modifier&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;declaration&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The name where it is declared&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;readonly&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;val&lt;/code&gt;: a local, a field or a module value that cannot be assigned&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;static&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A static member, a member of the type rather than of its values&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;defaultLibrary&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Declared in the standard library&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A name the checker reached no declaration for has no token, so while a syntax error stops the
analysis the editor’s grammar alone colours the file.&lt;/p&gt;
&lt;p&gt;Positions are the protocol’s: a line counted from zero and a character counted in UTF-16 code
units, so a column after a non-ASCII character is the one the editor shows.&lt;/p&gt;
&lt;p&gt;A program with &lt;a href=&quot;/spec/sysl-bindings/&quot;&gt;Sysl bindings&lt;/a&gt; has their shims checked by Sysl when it is
built; the server reports what the Avin parser and checker find.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Design choices</title>
    <link href="https://avinlang.dev/spec/design/"/>
    <id>https://avinlang.dev/spec/design/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>The choices that shape Avin&apos;s type system, runtime and library, and what each one means for a program.</summary>
    <content type="html">&lt;p&gt;Avin compiles whole programs to native code and owns its runtime, so its types, values and library
are designed together. These are the choices that shape it, each with what it means for a program.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Choice&lt;/th&gt;&lt;th&gt;What it means&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Types are real at run time&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Every generic is monomorphized, and every heap object’s header names its exact type, type arguments included. A type pattern on a generic type is checked and sound, and generic code creates an &lt;code&gt;Array[T]&lt;/code&gt; as easily as any other value.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Values stay unboxed&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;List[int]&lt;/code&gt; stores &lt;code&gt;int&lt;/code&gt;s directly. A value is boxed only where it becomes a trait or &lt;code&gt;Any&lt;/code&gt; value, at that one site.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Absence is explicit&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A value that may be missing has type &lt;code&gt;Option[T]&lt;/code&gt;. Every reference refers to an object, and every field is initialized before the object can be observed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Equality is typed&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;==&lt;/code&gt; compares two values of one type; comparing unrelated types is a compile error. Every value has &lt;code&gt;==&lt;/code&gt; and a hash, so any value can be a map key: &lt;code&gt;data&lt;/code&gt; types, tuples and built-ins by value, class instances by identity unless the class implements or derives &lt;code&gt;Eq&lt;/code&gt;. Identity is also the separate &lt;code&gt;===&lt;/code&gt;, for types that have identity.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Printing is a trait&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A type is printable because it implements &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;; &lt;code&gt;data&lt;/code&gt; derives both. Output always shows the value.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;code&gt;string&lt;/code&gt; is built in&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;string&lt;/code&gt; is a type of the language: UTF-8, immutable, and named simply &lt;code&gt;string&lt;/code&gt;. Its methods live in Avin’s own core library.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;code&gt;char&lt;/code&gt; is a Unicode scalar value&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;One &lt;code&gt;char&lt;/code&gt; is one character of text, whatever its code point.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;code&gt;Array[T]&lt;/code&gt; is an ordinary collection&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Invariant, contiguous, fixed length and mutable; elements are stored unboxed; &lt;code&gt;==&lt;/code&gt; compares contents, and printing shows them.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Integers keep their width, and overflow traps&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Fixed-width integers keep their width through arithmetic (&lt;code&gt;i8 + i8&lt;/code&gt; is &lt;code&gt;i8&lt;/code&gt;), and a result that does not fit stops the program. Wrapping and saturating arithmetic are written with their own operators.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Binary data is &lt;code&gt;byte&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Integers are signed and are for counting; &lt;code&gt;byte&lt;/code&gt; is the octet that files, sockets and encodings are made of.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Failures are values; bugs are traps&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A failure a correct caller can meet is a &lt;code&gt;Result&lt;/code&gt; or &lt;code&gt;Option&lt;/code&gt;, propagated with &lt;code&gt;?&lt;/code&gt;. A bug stops the program with a trap.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Overloading is resolved statically&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Functions and methods may share a name when their parameter types differ. The compiler chooses the most specific overload from the arguments at compile time, and an ambiguous call is an error rather than a guess.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;code&gt;object&lt;/code&gt; holds module-wide state&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;An &lt;code&gt;object&lt;/code&gt; is an ordinary value, and the one place for state and functions that belong to a type rather than an instance.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Initialization is checked&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A constructor assigns every field before &lt;code&gt;self&lt;/code&gt; is used. Traits carry behaviour, not state. Module-level values and &lt;code&gt;object&lt;/code&gt;s initialize before &lt;code&gt;main&lt;/code&gt;, in dependency order, and the compiler rejects a cycle.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Objects are just data&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;An object’s header holds its type and what the collector needs, nothing more: there is no lock in every object. Threads share the heap; synchronization is library code, and actors are built into the language.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Tuples and functions of any arity&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A tuple or function type may have as many elements or parameters as the program needs.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;code&gt;unit&lt;/code&gt; is an ordinary type&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;It has one value, &lt;code&gt;()&lt;/code&gt;, and works as a type argument at no cost.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;One top type, &lt;code&gt;Any&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Every type conforms to &lt;code&gt;Any&lt;/code&gt;; value types reach it by boxing at that one site.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;code&gt;data&lt;/code&gt; is pure value&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A &lt;code&gt;data&lt;/code&gt; value has no identity, so the compiler chooses to store it inline or on the heap, and the program sees the same behaviour either way.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Conversions are written&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;+&lt;/code&gt; on strings joins two strings; numeric conversions are explicit (&lt;code&gt;long(x)&lt;/code&gt;); interpolation formats any value.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Generic programming at compile time&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Derivation (&lt;code&gt;derives&lt;/code&gt;) and reified type tests give generic code what it needs, checked by the compiler.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Whole-program compilation&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;The program, its libraries and the standard library are compiled together. That is what makes reification, monomorphized generic methods and devirtualization possible.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</content>
  </entry>
  <entry>
    <title>Derivation through shapes</title>
    <link href="https://avinlang.dev/spec/derivation/"/>
    <id>https://avinlang.dev/spec/derivation/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Library-defined derivation, where the compiler describes each data type and class as a shape, and a trait&apos;s own module says once how to derive it, checked at compile time and compiled per type.</summary>
    <content type="html">&lt;p&gt;Any trait can be derived. Besides the core library’s &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;, a
trait’s module writes a &lt;strong&gt;derive template&lt;/strong&gt; once, against the &lt;strong&gt;shape&lt;/strong&gt; the compiler gives every
data type and class: its variants, their fields, each field’s name, position, default and
annotations. A type that says &lt;code&gt;derives JsonEncoder&lt;/code&gt; gets an ordinary impl, compiled for that type
alone, whose calls on the type’s fields are written for each field’s own type and look nothing up
at run time.&lt;/p&gt;
&lt;p&gt;The aim is that a library such as a JSON codec is as complete written this way as written by hand:
encoder and decoder traits, derivation for data types and classes, renamed and omitted fields,
defaults, a discriminator for sum types, errors that name the path to the bad value, and a decoder
that streams. The &lt;a href=&quot;#a-json-library&quot;&gt;worked example&lt;/a&gt; below is that library’s core.&lt;/p&gt;
&lt;h2 id=&quot;the-approach&quot;&gt;The approach&lt;/h2&gt;
&lt;p&gt;Generic code over a type’s fields needs, for each field, a call at that field’s own type, so that
&lt;code&gt;string&lt;/code&gt; fields encode as strings and &lt;code&gt;int&lt;/code&gt; fields as numbers, each call direct. Avin has no
type-level lists, and macros are deferred, so the question is who writes
those calls.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;What it needs&lt;/th&gt;&lt;th&gt;Verdict&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;The compiler walks the fields, calling the library’s hooks&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;A hook method generic over one type parameter; the compiler calls it once per field, at the field’s type&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Chosen&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A type is converted to a tuple of its fields, and the library writes instances over tuples&lt;/td&gt;&lt;td&gt;Code generic over a tuple’s arity, which Avin does not have: one instance per arity, names and annotations carried beside, an intermediate tuple per conversion&lt;/td&gt;&lt;td&gt;Rejected&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The template loops over the fields, the loop unrolled per type&lt;/td&gt;&lt;td&gt;A name for “this field’s type” inside the loop (a path-dependent type) and a body checked anew at every expansion: a macro by another name&lt;/td&gt;&lt;td&gt;Rejected&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Descriptions read at run time&lt;/td&gt;&lt;td&gt;Lookups by name and boxing on every call&lt;/td&gt;&lt;td&gt;Rejected: cost the call site does not show&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The template is checked once, generically, like any generic code. What is checked for each deriving
type is the hook: it is found on the visitor type the template names, and each field’s type must
meet the bound it declares, a failure reported at the &lt;code&gt;derives&lt;/code&gt; entry, naming the field.&lt;/p&gt;
&lt;h2 id=&quot;shapes&quot;&gt;Shapes&lt;/h2&gt;
&lt;p&gt;The core library declares the descriptions, as plain data:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data TypeShape(name: string, variantCount: int, variants: Vector[VariantShape], annotations: Vector[Annotation])

data VariantShape(
    name: string,
    index: int,
    fieldCount: int,
    fields: Vector[FieldShape],
    annotations: Vector[Annotation]
)

data FieldShape(name: string, index: int, hasDefault: bool, annotations: Vector[Annotation])

trait Annotation

impl FieldShape // and the same on TypeShape and VariantShape
  annotation[A: Annotation]() -&amp;gt; Option[A] // the first annotation of type A
  has(a: Annotation) -&amp;gt; bool // whether a is among them, by ==
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A data type’s shape&lt;/strong&gt; has one variant per variant, in declaration order, each with its fields.
The single-line form has one variant, of the type’s name.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A class’s shape&lt;/strong&gt; has one variant, of the class’s name, whose fields are its constructor
parameters, plain, &lt;code&gt;val&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt; alike, in order: what the built-in derivations read. Fields
its body declares take no part. A repeated parameter is a field of type &lt;code&gt;Vector[T]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A shape is constant data.&lt;/strong&gt; The shapes of a type, its variants and its fields are module values
private to the type’s module, built only of literals, so the compiler makes them itself and writes
them as read-only data: nothing runs before &lt;code&gt;main&lt;/code&gt; to make them, and code reading a field of one
is compiled to the field’s value. A type
has them where it derives a trait through a template or carries annotations, and no other does;
every data type derives &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; through the core library’s templates unless it
implements both itself, so every other data type has its shape.&lt;/li&gt;
&lt;li&gt;The core library declares &lt;code&gt;TypeShape&lt;/code&gt;, &lt;code&gt;VariantShape&lt;/code&gt;, &lt;code&gt;FieldShape&lt;/code&gt;, &lt;code&gt;Annotation&lt;/code&gt;, &lt;code&gt;Shaped&lt;/code&gt;, and
the visitor and builder traits below, in the prelude’s module.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;derive-templates&quot;&gt;Derive templates&lt;/h2&gt;
&lt;p&gt;A trait’s module says how to derive it with a &lt;code&gt;derive&lt;/code&gt; declaration: the trait’s methods and static
members, written once for a type named after &lt;code&gt;for&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;derive JsonEncoder for T
  encode(out: JsonWriter) =
    T.walk(self, FieldWriter(out, T.shape()))
    out.endObject()
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;One template per trait, in the trait’s module&lt;/strong&gt;, as a conformance lives in the trait’s or the
type’s module. A second template for a trait, or one in another module, is an error. A trait
without one cannot be derived: &lt;code&gt;derives X&lt;/code&gt; is then an error saying that X has no derivation. A
&lt;code&gt;derives&lt;/code&gt; entry finds the template in its own module, in a module its file imports from, or in
the core library.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The body is an impl’s body&lt;/strong&gt;: every abstract method and static member of the trait, defaults left
alone or replaced, each checked against the trait’s as an impl’s is. &lt;code&gt;T&lt;/code&gt; stands where an impl names
its type, and &lt;code&gt;self&lt;/code&gt; is a &lt;code&gt;T&lt;/code&gt;. &lt;code&gt;T&lt;/code&gt; is any name the header gives.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;T&lt;/code&gt; conforms to the trait and to the core’s &lt;code&gt;Shaped&lt;/code&gt;&lt;/strong&gt;, and to nothing else. &lt;code&gt;Shaped&lt;/code&gt; gives the
template the static members below. &lt;code&gt;Shaped&lt;/code&gt; is named nowhere else: written as a bound anywhere but
a template, it is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The template is checked once&lt;/strong&gt;, where it is declared, like any generic code; errors in it are
the template author’s and are reported there, and nowhere else: a type deriving a trait whose
template has errors reports nothing more.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each deriving type gets the template’s body as its impl&lt;/strong&gt;, with &lt;code&gt;T&lt;/code&gt; the type. Its names resolve
as the template’s do, in the trait’s module, and each call of a member of &lt;code&gt;Shaped&lt;/code&gt; on &lt;code&gt;T&lt;/code&gt; is
replaced by code written for the type’s own variants and fields, which follows.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Shaped
  static shape() -&amp;gt; TypeShape
  static variantOf(value: Self) -&amp;gt; VariantShape
  static walk[V: ShapeVisitor](value: Self, visitor: V) -&amp;gt; V
  static walkPair[V: ShapePairVisitor](a: Self, b: Self, visitor: V) -&amp;gt; V
  static build[B: ShapeBuilder[E], E](builder: B) -&amp;gt; Result[Self, E]
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;walking-a-value&quot;&gt;Walking a value&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;T.walk(value, v)&lt;/code&gt; calls &lt;code&gt;v.variant&lt;/code&gt; with the value’s variant, then &lt;code&gt;v.field&lt;/code&gt; once per field of that
variant, in order, then &lt;code&gt;v.finish&lt;/code&gt; with the variant, each call taking the visitor the one before
returned. &lt;code&gt;finish&lt;/code&gt; does nothing unless the visitor’s type says otherwise:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait ShapeVisitor
  variant(v: VariantShape) -&amp;gt; Self
  finish(v: VariantShape) -&amp;gt; Self = self

// for data Shape = Circle(radius: real) | Rect(width: real, height: real), the compiler writes:
value match
  Circle(r) -&amp;gt; visitor.variant(CIRCLE).field[real](CIRCLE_RADIUS, r).finish(CIRCLE)
  Rect(w, h) -&amp;gt; visitor.variant(RECT).field[real](RECT_WIDTH, w).field[real](RECT_HEIGHT, h).finish(RECT)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each arm passes its own variant’s shape, so what a hook reads of it is known where the arm is
compiled: &lt;code&gt;v.fieldCount &amp;gt; 0&lt;/code&gt; in &lt;code&gt;Rect&lt;/code&gt;‘s &lt;code&gt;finish&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The field hook is not in the trait&lt;/strong&gt;, because its bound is the deriving library’s own: a visitor
type declares one method &lt;code&gt;field&lt;/code&gt; with exactly one type parameter of its own, &lt;code&gt;field[F: Bound](f: FieldShape, value: F) -&amp;gt; Self&lt;/code&gt;. The hook is resolved for each deriving type, on the visitor type the
template passes to &lt;code&gt;walk&lt;/code&gt;: the code written there calls it once per field, at the field’s type. A
visitor type without such a method, and a field whose type misses any of &lt;code&gt;Bound&lt;/code&gt;‘s traits, are
errors at the &lt;code&gt;derives&lt;/code&gt; entry, the second naming the field (&lt;code&gt;Variant.field&lt;/code&gt; in a type of several
variants). A class’s fields are read from the object, plain private parameters included.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;T.walkPair(a, b, v)&lt;/code&gt; is the same over two values, for equality and ordering: it calls
&lt;code&gt;v.variants(T.variantOf(a), T.variantOf(b))&lt;/code&gt;, and, where the two are the same variant, &lt;code&gt;v.field(f, x, y)&lt;/code&gt; per field with both values’ fields; where they differ, the visitor &lt;code&gt;variants&lt;/code&gt; returned is the
result. &lt;code&gt;T.variantOf(x)&lt;/code&gt; is the shape of the variant &lt;code&gt;x&lt;/code&gt; is, a class’s one variant for a class, and
&lt;code&gt;T.shape()&lt;/code&gt; the type’s.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait ShapePairVisitor
  variants(a: VariantShape, b: VariantShape) -&amp;gt; Self
  // and field[F: Bound](f: FieldShape, a: F, b: F) -&amp;gt; Self
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;building-a-value&quot;&gt;Building a value&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;T.build(b)&lt;/code&gt; makes a &lt;code&gt;T&lt;/code&gt; from what a builder supplies. The builder chooses the variant, then names
the fields &lt;strong&gt;in any order&lt;/strong&gt;, so a decoder reads its input as it comes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait ShapeBuilder[E]
  variant(t: TypeShape) -&amp;gt; Result[int, E] // the variant&apos;s index
  next(v: VariantShape) -&amp;gt; Result[Option[int], E] // the next field&apos;s index; None when done
  duplicate(f: FieldShape) -&amp;gt; E
  // and field[F: Bound](f: FieldShape) -&amp;gt; Result[F, E]
  //     missing[F: Bound](f: FieldShape) -&amp;gt; Result[F, E]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What the compiler writes, for each variant, is equivalent to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;var slot0: Option[F0] = None // one slot per field, each at its own type
var slot1: Option[F1] = None
while b.next(VARIANT)? is Some(i)
  i match
    0 -&amp;gt; if slot0.isDefined then return Err(b.duplicate(FIELD_0))
         else slot0 = Some(b.field[F0](FIELD_0)?)
    1 -&amp;gt; …
val x0 = slot0 or else field 0&apos;s default or else b.missing[F0](FIELD_0)?
val x1 = …
Ok(Variant(x0, x1))
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The builder’s &lt;code&gt;field&lt;/code&gt; and &lt;code&gt;missing&lt;/code&gt; are its hooks, found and held to the fields as a visitor’s
&lt;code&gt;field&lt;/code&gt; is; &lt;code&gt;E&lt;/code&gt; is what the builder’s type gives &lt;code&gt;ShapeBuilder&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;variant&lt;/code&gt; is asked even of a type with one variant, so a builder can read what opens a value
there.&lt;/li&gt;
&lt;li&gt;A field never supplied takes its &lt;strong&gt;default&lt;/strong&gt; where its declaration has one, evaluated as the
constructor would, seeing the fields before it; otherwise the builder’s &lt;code&gt;missing&lt;/code&gt; decides, so a
library can let an absent &lt;code&gt;Option&lt;/code&gt; be &lt;code&gt;None&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;An index out of range from &lt;code&gt;variant&lt;/code&gt; or &lt;code&gt;next&lt;/code&gt; is a bug in the builder, and traps with a message
naming the type or the variant.&lt;/li&gt;
&lt;li&gt;A class is built through its constructor, a repeated parameter passed as its vector. An abstract
class cannot be built, nor an open one, whose value could be any subclass: a template that calls
&lt;code&gt;build&lt;/code&gt; cannot derive for either, an error at the &lt;code&gt;derives&lt;/code&gt; entry naming the reason. &lt;code&gt;walk&lt;/code&gt;,
&lt;code&gt;walkPair&lt;/code&gt; and &lt;code&gt;variantOf&lt;/code&gt; are allowed on both, and a subclass inherits the conformance, so it
walks as its superclass.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;annotations&quot;&gt;Annotations&lt;/h2&gt;
&lt;p&gt;An annotation is a &lt;strong&gt;value of a type implementing &lt;code&gt;Annotation&lt;/code&gt;&lt;/strong&gt;: a data value or an &lt;code&gt;object&lt;/code&gt;,
written with &lt;code&gt;@&lt;/code&gt; before a type or a class (on the line before it), or a variant, a field or a class
parameter (on the same line). Its arguments are those of a call of its name, evaluated once, before
&lt;code&gt;main&lt;/code&gt;, when the shape is made, and stored there. Traits, objects and functions take no annotations
of this kind, nor do a function’s parameters.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data JsonKey(name: string)
impl Annotation for JsonKey

object JsonOmit: Annotation

@JsonTag(&amp;quot;kind&amp;quot;)
data Shape derives JsonEncoder
  @JsonKey(&amp;quot;circle&amp;quot;) Circle(radius: real)
  Rect(width: real, height: real)

data Person(@JsonKey(&amp;quot;full_name&amp;quot;) name: string, age: int, @JsonOmit score: int = 0)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A template reads them from the shape: &lt;code&gt;f.annotation[JsonKey]()&lt;/code&gt; is the field’s &lt;code&gt;JsonKey&lt;/code&gt;, if any;
&lt;code&gt;f.has(JsonOmit)&lt;/code&gt; whether it carries the object. An annotation no template reads is allowed; one
whose name resolves to no type or object, or to one not implementing &lt;code&gt;Annotation&lt;/code&gt;, is an error. A
misused annotation, such as &lt;code&gt;@JsonOmit&lt;/code&gt; on a field with no default, is not rejected while compiling:
it fails when a value is decoded. The compiler’s own annotations, &lt;code&gt;@test&lt;/code&gt;, &lt;code&gt;@tests&lt;/code&gt;, &lt;code&gt;@intrinsic&lt;/code&gt;
and &lt;code&gt;@sysl&lt;/code&gt;, stay its own and are not in shapes.&lt;/p&gt;
&lt;h2 id=&quot;derives-with-a-library-trait&quot;&gt;&lt;code&gt;derives&lt;/code&gt; with a library trait&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;data Order(id: long, lines: List[Line]) derives JsonEncoder&lt;/code&gt; makes the compiler declare, in the
type’s module, &lt;code&gt;impl JsonEncoder for Order&lt;/code&gt; whose body is the template’s with &lt;code&gt;T&lt;/code&gt; as &lt;code&gt;Order&lt;/code&gt;, and
whose &lt;code&gt;walk&lt;/code&gt; and &lt;code&gt;build&lt;/code&gt; are written for &lt;code&gt;Order&lt;/code&gt;‘s shape.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Errors name the field.&lt;/strong&gt; Where a field’s type misses the hook’s bound, the error is at the
&lt;code&gt;derives&lt;/code&gt; entry: &lt;em&gt;&lt;code&gt;Order&lt;/code&gt; cannot derive &lt;code&gt;JsonEncoder&lt;/code&gt;: field &lt;code&gt;lines&lt;/code&gt; has type &lt;code&gt;List[Line]&lt;/code&gt;, which
does not implement &lt;code&gt;JsonEncoder&lt;/code&gt;&lt;/em&gt; (here because &lt;code&gt;Line&lt;/code&gt; does not). Deriving a trait the type also
implements is an error, a conformance stated twice.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recursion needs nothing.&lt;/strong&gt; The derived impl is a conformance, declared before any body is
checked, so &lt;code&gt;data Tree(label: string, children: List[Tree]) derives JsonEncoder&lt;/code&gt; holds through
&lt;code&gt;List&lt;/code&gt;‘s bounded impl and its own; the calls recurse at run time as hand-written ones would.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generic types derive conditionally&lt;/strong&gt;, as the derived &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; do: &lt;code&gt;data Box[A](item: A) derives JsonEncoder&lt;/code&gt; is &lt;code&gt;impl[A: JsonEncoder] JsonEncoder for Box[A]&lt;/code&gt;, each
parameter bounded by the trait, so a &lt;code&gt;Box[int]&lt;/code&gt; encodes and a &lt;code&gt;Box&lt;/code&gt; of a type without an encoder
does not. Where the hook’s bound is another trait, the type bounds its parameter by it itself,
&lt;code&gt;data Labelled[A: FromText](value: A) derives FromPairs&lt;/code&gt;, and the error at the &lt;code&gt;derives&lt;/code&gt; entry says
so.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static members are derived too.&lt;/strong&gt; A template’s &lt;code&gt;static decode&lt;/code&gt; becomes &lt;code&gt;Order.decode&lt;/code&gt;, called
through a bound as &lt;code&gt;A.decode(r)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;cost&quot;&gt;Cost&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Person(name: string, age: int) derives JsonEncoder
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The derived &lt;code&gt;encode&lt;/code&gt; is &lt;code&gt;Person.walk(self, FieldWriter(out, PERSON))&lt;/code&gt; then &lt;code&gt;out.endObject()&lt;/code&gt;, and the
walk is &lt;code&gt;FieldWriter(…).variant(PERSON_0).field[string](NAME, name).field[int](AGE, age)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What holds now.&lt;/strong&gt; Every call is direct: the visitor’s type is known and each hook is compiled for
one field type, so there is no call through a method table, no lookup by name and no boxing. A shape
is constant data, and what a hook reads of it is a constant in the compiled code:
&lt;code&gt;shape.variantCount &amp;gt; 1&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;f.has(JsonOmit)&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt; and the key is &lt;code&gt;&amp;quot;name&amp;quot;&lt;/code&gt;. The
visitor costs nothing: &lt;code&gt;FieldWriter&lt;/code&gt; is data that never
leaves &lt;code&gt;encode&lt;/code&gt;, so the walk and the hooks are inlined into it and the visitor is kept as its
fields, with no allocation. The compiler’s tests hold a derived encoder to exactly this: it
allocates no more than a hand-written one, and calls each field’s own method directly. What remains
is the hand-written encoder:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;encode(out: JsonWriter) =
  out.beginObject()
  out.key(&amp;quot;name&amp;quot;)
  out.string(name)
  out.key(&amp;quot;age&amp;quot;)
  out.long(long(age))
  out.endObject()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The hooks are inlined at &lt;code&gt;-O0&lt;/code&gt; too, since the compiler inlines them to keep the visitor as its
fields; there are no lookups by name and no boxing either way. A program
that never encodes a &lt;code&gt;Person&lt;/code&gt; compiles none of the encoder.&lt;/p&gt;
&lt;h2 id=&quot;a-json-library&quot;&gt;A JSON library&lt;/h2&gt;
&lt;p&gt;The core of a &lt;code&gt;json&lt;/code&gt; library written with templates. &lt;code&gt;JsonWriter&lt;/code&gt; writes text and places the
commas; &lt;code&gt;JsonReader&lt;/code&gt; is the &lt;a href=&quot;/spec/json/&quot;&gt;JSON package&lt;/a&gt;‘s streaming reader, which
reads events from text in hand or from any &lt;code&gt;Reader&lt;/code&gt;, one at a time.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data PathStep
  Key(name: string)
  Index(at: int)

data JsonError(message: string, line: long, column: long, offset: long, path: List[PathStep] = [])

impl JsonError
  inField(name: string) -&amp;gt; JsonError = JsonError(message, line, column, offset, Key(name) :: path)
  atIndex(i: int) -&amp;gt; JsonError = JsonError(message, line, column, offset, Index(i) :: path)

trait JsonEncoder
  encode(out: JsonWriter)

trait JsonDecoder
  static decode(r: JsonReader) -&amp;gt; Result[Self, JsonError]
  static whenMissing() -&amp;gt; Option[Self] // a value for a field absent from the input

data JsonKey(name: string) // a field&apos;s or variant&apos;s name in JSON
impl Annotation for JsonKey
data JsonTag(key: string) // a sum type&apos;s discriminator key
impl Annotation for JsonTag
object JsonOmit: Annotation // never written; read only from its default

keyOf(f: FieldShape) -&amp;gt; string = f.annotation[JsonKey]().map(k -&amp;gt; k.name).getOrElse(f.name)
nameOf(v: VariantShape) -&amp;gt; string = v.annotation[JsonKey]().map(k -&amp;gt; k.name).getOrElse(v.name)
tagOf(t: TypeShape) -&amp;gt; string = t.annotation[JsonTag]().map(t -&amp;gt; t.key).getOrElse(&amp;quot;type&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instances for the built-in types and collections are written by hand, the path growing at each
element:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;impl JsonEncoder for string
  encode(out: JsonWriter) = out.string(self)

impl JsonDecoder for string
  static decode(r: JsonReader) -&amp;gt; Result[string, JsonError] = r.readString()
  static whenMissing() -&amp;gt; Option[string] = None

impl[A: JsonDecoder] JsonDecoder for Option[A]
  static decode(r: JsonReader) -&amp;gt; Result[Option[A], JsonError] =
    if r.takeNull() then Ok(None) else A.decode(r).map(a -&amp;gt; Some(a))
  static whenMissing() -&amp;gt; Option[Option[A]] = Some(None)

impl[A: JsonDecoder] JsonDecoder for Vector[A]
  static decode(r: JsonReader) -&amp;gt; Result[Vector[A], JsonError] =
    r.beginArray()?
    val items = Buffer[A]()
    while r.nextElement()?
      items.addOne(A.decode(r).mapErr(e -&amp;gt; e.atIndex(items.length))?)
    Ok(items.toVector)
  static whenMissing() -&amp;gt; Option[Vector[A]] = None
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The encoder’s derivation. A sum type writes its discriminator first:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;derive JsonEncoder for T
  encode(out: JsonWriter) =
    T.walk(self, FieldWriter(out, T.shape()))
    out.endObject()

data FieldWriter(out: JsonWriter, shape: TypeShape)

impl ShapeVisitor for FieldWriter
  variant(v: VariantShape) -&amp;gt; FieldWriter =
    out.beginObject()
    if shape.variantCount &amp;gt; 1
      out.key(tagOf(shape))
      out.string(nameOf(v))
    self

impl FieldWriter
  field[F: JsonEncoder](f: FieldShape, value: F) -&amp;gt; FieldWriter =
    if !f.has(JsonOmit)
      out.key(keyOf(f))
      value.encode(out)
    self
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The decoder’s derivation streams: it reads the discriminator, then each key as it comes, decoding
the value at that field’s type, skipping keys it does not know:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;derive JsonDecoder for T
  static decode(r: JsonReader) -&amp;gt; Result[T, JsonError] = T.build(FieldReader(r))
  static whenMissing() -&amp;gt; Option[T] = None

data FieldReader(r: JsonReader)

impl ShapeBuilder[JsonError] for FieldReader
  variant(t: TypeShape) -&amp;gt; Result[int, JsonError] =
    r.beginObject()?
    if t.variantCount == 1 then return Ok(0)
    if r.nextKey()? != Some(tagOf(t))
      return Err(r.error(s&amp;quot;expected \&amp;quot;${tagOf(t)}\&amp;quot; first, naming the variant&amp;quot;))
    val name = r.readString().mapErr(e -&amp;gt; e.inField(tagOf(t)))?
    t.variants.find(v -&amp;gt; nameOf(v) == name) match
      Some(v) -&amp;gt; Ok(v.index)
      None -&amp;gt; Err(r.error(s&amp;quot;unknown variant \&amp;quot;$name\&amp;quot;&amp;quot;).inField(tagOf(t)))

  next(v: VariantShape) -&amp;gt; Result[Option[int], JsonError]
    while r.nextKey()? is Some(key)
      if v.fields.find(f -&amp;gt; !f.has(JsonOmit) &amp;amp;&amp;amp; keyOf(f) == key) is Some(f) then return Ok(Some(f.index))
      r.skipValue()?
    Ok(None)

  duplicate(f: FieldShape) -&amp;gt; JsonError = r.error(s&amp;quot;duplicate field \&amp;quot;${keyOf(f)}\&amp;quot;&amp;quot;)

impl FieldReader
  field[F: JsonDecoder](f: FieldShape) -&amp;gt; Result[F, JsonError] =
    F.decode(r).mapErr(e -&amp;gt; e.inField(keyOf(f)))

  missing[F: JsonDecoder](f: FieldShape) -&amp;gt; Result[F, JsonError] =
    F.whenMissing() match
      Some(v) -&amp;gt; Ok(v)
      None -&amp;gt; Err(r.error(s&amp;quot;missing field \&amp;quot;${keyOf(f)}\&amp;quot;&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Address(street: string, city: string) derives JsonEncoder, JsonDecoder

data Person(
    @JsonKey(&amp;quot;full_name&amp;quot;) name: string,
    age: int,
    home: Option[Address],
    @JsonOmit visits: int = 0
) derives JsonEncoder, JsonDecoder

@JsonTag(&amp;quot;kind&amp;quot;)
data Shape derives JsonEncoder, JsonDecoder
  @JsonKey(&amp;quot;circle&amp;quot;) Circle(radius: real)
  @JsonKey(&amp;quot;rect&amp;quot;) Rect(width: real, height: real)
  Empty
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Person(&amp;quot;Ada&amp;quot;, 36, None)&lt;/code&gt; encodes as &lt;code&gt;{&amp;quot;full_name&amp;quot;:&amp;quot;Ada&amp;quot;,&amp;quot;age&amp;quot;:36,&amp;quot;home&amp;quot;:null}&lt;/code&gt;; decoding that, or
the same without &lt;code&gt;&amp;quot;home&amp;quot;&lt;/code&gt;, gives it back with &lt;code&gt;visits&lt;/code&gt; at &lt;code&gt;0&lt;/code&gt;. &lt;code&gt;Rect(2.0, 3.0)&lt;/code&gt; is
&lt;code&gt;{&amp;quot;kind&amp;quot;:&amp;quot;rect&amp;quot;,&amp;quot;width&amp;quot;:2.0,&amp;quot;height&amp;quot;:3.0}&lt;/code&gt;. Decoding &lt;code&gt;{&amp;quot;full_name&amp;quot;:&amp;quot;Ada&amp;quot;,&amp;quot;age&amp;quot;:36,&amp;quot;home&amp;quot;:{&amp;quot;street&amp;quot;: 1}}&lt;/code&gt; fails with the path &lt;code&gt;home.street&lt;/code&gt; and the position of the &lt;code&gt;1&lt;/code&gt;. A discriminator that is not the
object’s first key is refused by this decoder; a library that wants to accept it reads that object
into a tree first and decodes from the tree, with nothing new from the language.&lt;/p&gt;
&lt;h2 id=&quot;the-built-in-derivations&quot;&gt;The built-in derivations&lt;/h2&gt;
&lt;p&gt;The six traits the core library derives, &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt; and &lt;code&gt;Enumerable&lt;/code&gt;
(below), are templates in the same mould, each a few lines in the
trait’s own file of the core library, compiled for each deriving type as any library’s are:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;derive Hash for T
  hash() -&amp;gt; long = T.walk(self, hashFrom).h

private data HashFields(h: long)
private val hashFrom = HashFields(0)

impl ShapeVisitor for HashFields
  variant(v: VariantShape) -&amp;gt; HashFields = if v.index == 0 then self else HashFields(long(v.index))

impl HashFields
  field[F: Hash](f: FieldShape, value: F) -&amp;gt; HashFields = HashFields(h *% 31 +% value.hash())

derive Ord for T
  compare(other: T) -&amp;gt; int = T.walkPair(self, other, orderedSoFar).result

private data OrderFields(result: int)
private val orderedSoFar = OrderFields(0)
private val orderedBefore = OrderFields(-1)
private val orderedAfter = OrderFields(1)

impl ShapePairVisitor for OrderFields
  variants(a: VariantShape, b: VariantShape) -&amp;gt; OrderFields =
    if a.index == b.index then self elif a.index &amp;lt; b.index then orderedBefore else orderedAfter

impl OrderFields
  field[F: Ord](f: FieldShape, a: F, b: F) -&amp;gt; OrderFields =
    if result != 0 then return self
    val c = a.compare(b)
    if c == 0 then self elif c &amp;lt; 0 then orderedBefore else orderedAfter

derive Display for T
  display(out: Writer, spec: FormatSpec)
    if spec.width &amp;gt; 0
      val text = StringWriter()
      display(text, FormatSpec())
      out.writeField(text.text, spec)
    else
      T.walk(self, DisplayFields(out))

private data DisplayFields(out: Writer)

impl ShapeVisitor for DisplayFields
  variant(v: VariantShape) -&amp;gt; DisplayFields =
    out.write(v.name)
    self

  finish(v: VariantShape) -&amp;gt; DisplayFields =
    if v.fieldCount &amp;gt; 0 then out.write(&amp;quot;)&amp;quot;)
    self

impl DisplayFields
  field[F: Display](f: FieldShape, value: F) -&amp;gt; DisplayFields =
    out.write(if f.index == 0 then &amp;quot;(&amp;quot; else &amp;quot;, &amp;quot;)
    value.display(out, FormatSpec())
    self
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Eq&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt;‘s shape with &lt;code&gt;equals&lt;/code&gt;, and &lt;code&gt;Debug&lt;/code&gt; is &lt;code&gt;Display&lt;/code&gt;‘s with &lt;code&gt;debug&lt;/code&gt;. The visitors of &lt;code&gt;Eq&lt;/code&gt;
and &lt;code&gt;Ord&lt;/code&gt; take only a few values, each a module value made at compile time, so comparing allocates
nothing and each step of a comparison compiles to integers, and a derived &lt;code&gt;compare&lt;/code&gt; is -1, 0 or 1. A derived &lt;code&gt;Display&lt;/code&gt;‘s visitor never leaves the method that makes it, so it
is kept as its field and allocates nothing either. A class without constructor parameters has a variant without fields, so it displays as its bare name, as such a
variant does.&lt;/p&gt;
&lt;p&gt;What stays the compiler’s is when the templates apply. A class derives &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; together,
and &lt;code&gt;Ord&lt;/code&gt; only beside an &lt;code&gt;Eq&lt;/code&gt; by the same fields; a data type’s &lt;code&gt;==&lt;/code&gt; and hash stay the language’s
own, by value, as they are for tuples, so &lt;code&gt;derives Eq, Hash&lt;/code&gt; there adds nothing; and the automatic
&lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; of every data type are these templates applied without asking, where a field
missing the hook’s bound leaves the type without the trait instead of being an error. A field
missing &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; where the type derives it is reported before any body is
checked: &lt;em&gt;&lt;code&gt;Ranked&lt;/code&gt; cannot derive &lt;code&gt;Ord&lt;/code&gt;: its field &lt;code&gt;plain&lt;/code&gt; has type &lt;code&gt;Plain&lt;/code&gt;, which does not implement
&lt;code&gt;Ord&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;enumerations&quot;&gt;Enumerations&lt;/h3&gt;
&lt;p&gt;A data type whose variants have no fields is an &lt;strong&gt;enumeration&lt;/strong&gt;, and &lt;code&gt;derives Enumerable&lt;/code&gt; gives it
its variants as values:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;data Color derives Enumerable
  Red
  Green
  Blue

main()
  for c in Color.values
    println(s&amp;quot;${c.ordinal} ${c.name}&amp;quot;) // 0 Red, 1 Green, 2 Blue
  println(Color.valueOf(&amp;quot;Green&amp;quot;)) // Some(Green)
  println(Color.valueOf(&amp;quot;green&amp;quot;)) // None
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Enumerable
  static values() -&amp;gt; Vector[Self]
  ordinal() -&amp;gt; int
  name() -&amp;gt; string
  static valueOf(name: string) -&amp;gt; Option[Self]

derive Enumerable for T
  static values() -&amp;gt; Vector[T] = Vector.tabulate(T.shape().variantCount, i -&amp;gt; T.build(ChooseVariant(i)).ok.get)
  ordinal() -&amp;gt; int = T.variantOf(self).index
  name() -&amp;gt; string = T.variantOf(self).name
  static valueOf(name: string) -&amp;gt; Option[T] =
    for v in T.shape().variants
      if v.name == name then return T.build(ChooseVariant(v.index)).ok
    None
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;T.values&lt;/code&gt;&lt;/strong&gt; is every variant in declaration order, as a new &lt;code&gt;Vector&lt;/code&gt; each call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;ordinal&lt;/code&gt;&lt;/strong&gt; is the variant’s 0-based position in the declaration, an &lt;code&gt;int&lt;/code&gt;; a derived &lt;code&gt;Ord&lt;/code&gt;
orders variants the same way, so &lt;code&gt;a &amp;lt; b&lt;/code&gt; exactly when &lt;code&gt;a.ordinal &amp;lt; b.ordinal&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;name&lt;/code&gt;&lt;/strong&gt; is the variant’s name as declared. It is not its &lt;code&gt;Display&lt;/code&gt;: an impl of &lt;code&gt;Display&lt;/code&gt;
changes what the variant prints, never its name, so &lt;code&gt;T.valueOf(x.name)&lt;/code&gt; is always &lt;code&gt;Some(x)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;T.valueOf(name)&lt;/code&gt;&lt;/strong&gt; is the variant of exactly that name, compared byte for byte, so another
case, surrounding white space and the empty string are &lt;code&gt;None&lt;/code&gt;. It never traps.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ChooseVariant&lt;/code&gt; is the template’s builder, which picks the variant at an index and supplies no
fields, so every build succeeds.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What stays the compiler’s is who may derive it: only a data type of no type parameters whose every
variant has no fields, the single-line form included when it has none (&lt;code&gt;data Marker()&lt;/code&gt;). A variant
with fields, a type parameter and a class are each reported at the &lt;code&gt;derives&lt;/code&gt; entry:
&lt;em&gt;&lt;code&gt;Shape&lt;/code&gt; cannot derive &lt;code&gt;Enumerable&lt;/code&gt;: its variant &lt;code&gt;Circle&lt;/code&gt; has fields, and an enumeration’s values
are variants without fields&lt;/em&gt;; &lt;em&gt;&lt;code&gt;Tag&lt;/code&gt; cannot derive &lt;code&gt;Enumerable&lt;/code&gt;: it has type parameters, and an
enumeration’s values are one fixed set of variants&lt;/em&gt;; &lt;em&gt;&lt;code&gt;Word&lt;/code&gt; cannot derive &lt;code&gt;Enumerable&lt;/code&gt;: it is a
class, and an enumeration is a data type whose variants have no fields&lt;/em&gt;. A trait named &lt;code&gt;Enumerable&lt;/code&gt;
that a program declares with a template of its own follows that template’s rules instead. A method
of the type’s own named &lt;code&gt;ordinal&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt; or &lt;code&gt;valueOf&lt;/code&gt; is a second method of that name,
reported as any such pair is.&lt;/p&gt;
&lt;h2 id=&quot;what-this-does-not-do&quot;&gt;What this does not do&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No code is generated from a library’s text.&lt;/strong&gt; A template is ordinary Avin, checked once; the
compiler writes only the walk and the build, whose shape it already knows.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No reading of types at run time.&lt;/strong&gt; A shape is constant data about one type; nothing looks a type
up by name or enumerates the program’s types.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No compile-time evaluation of library code.&lt;/strong&gt; A template cannot reject a misuse of its
annotations while compiling, such as &lt;code&gt;@JsonOmit&lt;/code&gt; on a field with no default; that failure shows
when a value is decoded.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>Declarations</title>
    <link href="https://avinlang.dev/spec/declarations/"/>
    <id>https://avinlang.dev/spec/declarations/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Names, data, class, trait, object, impl, members, modules and initialization.</summary>
    <content type="html">&lt;h2 id=&quot;names&quot;&gt;Names&lt;/h2&gt;
&lt;p&gt;A name may be written in any script. It begins with a letter or &lt;code&gt;_&lt;/code&gt; and continues with letters,
digits, combining marks and connecting punctuation such as &lt;code&gt;_&lt;/code&gt;; exactly, its first character has
Unicode’s &lt;code&gt;XID_Start&lt;/code&gt; property or is &lt;code&gt;_&lt;/code&gt;, and each later one has &lt;code&gt;XID_Continue&lt;/code&gt; (the identifier
rule of Unicode Standard Annex #31).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Ärger
  Δelta(größe: int)
  Ωmega

fläche(breite: int, höhe: int) -&amp;gt; int = breite * höhe

main()
  val 名前 = &amp;quot;名&amp;quot;
  val x٣ = 3
  println(s&amp;quot;$名前 ${fläche(x٣, 2)}&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;A digit of any script continues a name and none begins one: &lt;code&gt;x٣&lt;/code&gt; is a name and &lt;code&gt;٣x&lt;/code&gt; is refused.
Number literals are written with ASCII digits only.&lt;/li&gt;
&lt;li&gt;A combining mark continues a name and cannot begin one.&lt;/li&gt;
&lt;li&gt;An emoji, a symbol, an operator character of another script and a space other than the ASCII
space are no part of any name; each is reported with its code point (&lt;code&gt;U+1F600&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A name is written in Unicode Normalization Form C.&lt;/strong&gt; A name spelled in another form (an &lt;code&gt;e&lt;/code&gt;
followed by a combining acute, where &lt;code&gt;é&lt;/code&gt; is one character in NFC) is reported, with the NFC
spelling to write instead. So two names that look the same are always the same name: nothing is
normalized behind the programmer’s back, and nothing that looks alike can differ invisibly in
how it was composed. Names in different scripts that merely look alike (Latin &lt;code&gt;a&lt;/code&gt;, Cyrillic &lt;code&gt;а&lt;/code&gt;)
are different names.&lt;/li&gt;
&lt;li&gt;A module’s name is a path of names, so each directory of a program is named by the same rule.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The reserved words name no value, type or parameter&lt;/strong&gt;: &lt;code&gt;as&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt;, &lt;code&gt;def&lt;/code&gt;,
&lt;code&gt;defer&lt;/code&gt;, &lt;code&gt;derives&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;loop&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt;,
&lt;code&gt;override&lt;/code&gt;, &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt;, &lt;code&gt;super&lt;/code&gt;, &lt;code&gt;then&lt;/code&gt;, &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; and
&lt;code&gt;yield&lt;/code&gt;. Each either follows a complete operand on its line (&lt;code&gt;x as T&lt;/code&gt;, &lt;code&gt;Base(x) derives Eq&lt;/code&gt;), or
begins a statement, a binding or a member where a line could also be an expression, or is a
value. &lt;code&gt;end&lt;/code&gt; and &lt;code&gt;self&lt;/code&gt; have rules of their own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The words that begin a top-level declaration are keywords only there, before the name it
declares&lt;/strong&gt;, and ordinary names everywhere else: &lt;code&gt;data&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;trait&lt;/code&gt;, &lt;code&gt;impl&lt;/code&gt;,
&lt;code&gt;import&lt;/code&gt;, &lt;code&gt;module&lt;/code&gt;, &lt;code&gt;type&lt;/code&gt;, &lt;code&gt;opaque&lt;/code&gt; (before &lt;code&gt;type&lt;/code&gt;), &lt;code&gt;export&lt;/code&gt; and &lt;code&gt;derive&lt;/code&gt;, with &lt;code&gt;open&lt;/code&gt; and
&lt;code&gt;abstract&lt;/code&gt; before &lt;code&gt;class&lt;/code&gt;. A top-level line holds only declarations, so such a word followed by a
name can mean nothing else, and none of them begins anything inside a block or a class body. So
&lt;code&gt;val data = readFile(p)&lt;/code&gt;, a field &lt;code&gt;class&lt;/code&gt;, a method &lt;code&gt;object()&lt;/code&gt;, a named argument &lt;code&gt;import = 1&lt;/code&gt;, a
variant &lt;code&gt;trait&lt;/code&gt;, a module &lt;code&gt;data&lt;/code&gt; and &lt;code&gt;r.type&lt;/code&gt; are all legal; &lt;code&gt;data(x: int) -&amp;gt; int&lt;/code&gt;, &lt;code&gt;impl[T](x: T)&lt;/code&gt; and &lt;code&gt;def class -&amp;gt; int&lt;/code&gt; at the top level declare functions; and &lt;code&gt;impl&lt;/code&gt; begins an impl before a
type, before type parameters and a type (&lt;code&gt;impl[A, B] (A, B)&lt;/code&gt;), or before a function type with
&lt;code&gt;for&lt;/code&gt;. The words of actors and machines are keywords only where they &lt;a href=&quot;/spec/actors/#keywords&quot;&gt;begin their
forms&lt;/a&gt;, as
&lt;code&gt;select&lt;/code&gt; is only where it ends its line to open a &lt;a href=&quot;/spec/threads/#select&quot;&gt;select block&lt;/a&gt;, and
&lt;code&gt;given&lt;/code&gt; and &lt;code&gt;using&lt;/code&gt; are keywords only where they &lt;a href=&quot;/spec/contextual-parameters/&quot;&gt;begin their
forms&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Capitalized&lt;/strong&gt; means the first character is an uppercase or titlecase letter (Unicode &lt;code&gt;Lu&lt;/code&gt; or
&lt;code&gt;Lt&lt;/code&gt;): &lt;code&gt;Ärger&lt;/code&gt;, &lt;code&gt;Δelta&lt;/code&gt; and &lt;code&gt;ǅemal&lt;/code&gt; are capitalized. A letter with no case, as in Chinese,
Japanese or Arabic, is not, so such a name is written where a lowercase one is. Types and
variants are capitalized by convention, values and functions are lowerCamelCase, and where the
language reads a name’s case (&lt;code&gt;T.V&lt;/code&gt; naming a variant, &lt;code&gt;int.MaxValue&lt;/code&gt;) this is the test. A bare
name in a pattern is a variant when a variant of that name is in scope, and otherwise binds,
whatever its case.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;functions&quot;&gt;Functions&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;area(width: int, height: int) -&amp;gt; int = width * height

greet(name: string)
  println(s&amp;quot;hello, $name&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every parameter has a declared type. The result type may be inferred, except for recursive functions.
An indented body with no &lt;code&gt;=&lt;/code&gt; and no result type returns &lt;code&gt;unit&lt;/code&gt;; with &lt;code&gt;=&lt;/code&gt; or a result type it yields
its last expression. Default arguments (&lt;code&gt;size: int = 16&lt;/code&gt;) and named arguments (&lt;code&gt;open(path, create = true)&lt;/code&gt;)
are supported, as described next.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;def&lt;/code&gt; may begin any function or method declaration&lt;/strong&gt;, and changes nothing about it: &lt;code&gt;def area(width: int, height: int) -&amp;gt; int = …&lt;/code&gt; is &lt;code&gt;area(width: int, height: int) -&amp;gt; int = …&lt;/code&gt;. It is written only where
it is needed, which is a top-level or local function with no parameter list (see
&lt;a href=&quot;#parameterless-methods&quot;&gt;parameterless methods&lt;/a&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;def now -&amp;gt; int = clock.millis()

class Rect(w: real, h: real): Shape
  override def area() -&amp;gt; real = w * h
  private def half() -&amp;gt; real = w * h / 2.0
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;def&lt;/code&gt; comes after the modifiers (&lt;code&gt;private&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt;, &lt;code&gt;override&lt;/code&gt;) and after the annotations, as in
&lt;code&gt;@tailrec&lt;/code&gt; then &lt;code&gt;private def go(…)&lt;/code&gt;. It is written once; before the modifiers, or before a &lt;code&gt;val&lt;/code&gt;,
&lt;code&gt;var&lt;/code&gt; or &lt;code&gt;lazy val&lt;/code&gt;, it is refused.&lt;/li&gt;
&lt;li&gt;A function defined by clauses takes &lt;code&gt;def&lt;/code&gt; on its signature, never on its clauses.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;def&lt;/code&gt; is a keyword: it names no function, type, value or parameter.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;default-and-named-arguments&quot;&gt;Default and named arguments&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;area(width: int, height: int = width, scale: int = 1) -&amp;gt; int = width * height * scale

area(2)                                 // 4
area(2, scale = 10)                     // 40
area(height = 3, width = 2)             // 6
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A parameter’s &lt;strong&gt;default&lt;/strong&gt; is evaluated at each call that omits its argument, never once for all
calls. It is evaluated where the function is declared, not where it is called: it sees what is in
scope at the declaration, including what a local function captures, and the parameters before its
own, but not the ones after it. A default does not decide a type argument of a generic function:
&lt;code&gt;f[T](x: T = 1)&lt;/code&gt; is an error, because &lt;code&gt;1&lt;/code&gt; is not a &lt;code&gt;T&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A call writes its &lt;strong&gt;positional&lt;/strong&gt; arguments first, then any &lt;strong&gt;named&lt;/strong&gt; ones, &lt;code&gt;name = value&lt;/code&gt;, in any
order; a positional argument after a named one is an error. Each parameter is given at most once,
by position or by name, and one given nothing must have a default. A name that is no parameter’s is
an error. A named argument is checked against its parameter’s type exactly as a positional one is,
so it takes part in inferring a generic call’s type arguments, and a lambda written as one takes its
parameter types from the parameter.&lt;/p&gt;
&lt;p&gt;The arguments written at a call are &lt;strong&gt;evaluated in the order written&lt;/strong&gt;, whatever parameters they
are given to; then the defaults of the omitted parameters are evaluated in parameter order, each
from the values before it. An argument that never finishes, such as a &lt;code&gt;return&lt;/code&gt;, ends the call there.&lt;/p&gt;
&lt;p&gt;Names and defaults belong to a function’s declaration, not to its type. A function value, such as a
lambda or a function passed as an argument, is called with positional arguments only, all of them.
A variant is called the same way as a function, so its fields may be given by name:
&lt;code&gt;Point(y = 2, x = 1)&lt;/code&gt;, and its fields may have defaults, each a function of the fields before it:
&lt;code&gt;data Range(low: int = 0, high: int = low + 10)&lt;/code&gt;. A function defined by &lt;a href=&quot;#clauses&quot;&gt;clauses&lt;/a&gt; writes its defaults on its
signature line, and its clauses match every parameter, defaulted or not. The default of a
&lt;a href=&quot;/spec/by-name/&quot;&gt;by-name&lt;/a&gt; parameter is delayed like any argument to it.&lt;/p&gt;
&lt;p&gt;Methods and class constructors take defaults and named arguments the same way:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Account(owner: string, var balance: int = 0)
  deposit(amount: int, note: string = s&amp;quot;$owner +$amount&amp;quot;) -&amp;gt; string
    balance += amount
    note

Account(&amp;quot;ann&amp;quot;).deposit(5) // &amp;quot;ann +5&amp;quot;
Account(balance = 3, owner = &amp;quot;bo&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A method’s default is evaluated as the method’s body is, so it sees &lt;code&gt;self&lt;/code&gt; and the receiver’s
members as well as the parameters before it; the receiver is the one the call is made on. A
constructor’s default sees the parameters before it, but no &lt;code&gt;self&lt;/code&gt;: the object does not exist yet.
A subclass passing its superclass’s constructor arguments may omit those with defaults.&lt;/p&gt;
&lt;p&gt;Defaults belong to the method that introduces a parameter. An &lt;code&gt;override&lt;/code&gt;, and a method that
implements a trait’s method, takes that method’s defaults and cannot declare its own, so a call
omits the same arguments and gets the same values whichever class’s method then runs. A trait’s
method declares its defaults in the trait, and they apply through the trait’s type and on every
type implementing it. A method a type inherits, from its superclass or as a trait’s default body,
keeps its own defaults, so where it also implements another trait’s method, that method must
declare no defaults or the very same ones; otherwise the type is an error. A method of one required parameter whose others have defaults can be
&lt;a href=&quot;/spec/operators-and-control-flow/#infix-method-calls&quot;&gt;called infix&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Functions and methods may be &lt;strong&gt;overloaded&lt;/strong&gt;: several functions in one scope may share a name when
their parameter types differ. A call chooses among them by its arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The candidates are the overloads that accept the call’s arguments: their number, their names and
their types. Inference runs for each candidate separately, so a literal argument fits any overload
whose parameter it can become.&lt;/li&gt;
&lt;li&gt;When more than one candidate remains, the most specific wins: the one whose every parameter type
conforms to the corresponding parameter type of each other. A call with no candidate, or with no
single most specific one, is an error that lists the overloads, except that an integer literal
breaks a tie in favour of its own type (below).&lt;/li&gt;
&lt;li&gt;Overloads must differ in their parameter types; differing only in result type or parameter names
is an error. A default argument that makes two overloads accept the same call makes that call
ambiguous.&lt;/li&gt;
&lt;li&gt;A function used as a value takes its overload from the expected function type.&lt;/li&gt;
&lt;li&gt;Where candidates differ only in what a function argument returns, &lt;code&gt;flatMap&lt;/code&gt; taking &lt;code&gt;(T) -&amp;gt; Iterable[U]&lt;/code&gt; or &lt;code&gt;(T) -&amp;gt; Option[U]&lt;/code&gt;, a lambda’s body decides its result first. An argument that
cannot be checked that way, a lambda whose branches join only at the result a candidate expects
(&lt;code&gt;if … then aList else aVector&lt;/code&gt;) or a generic function named as a value (&lt;code&gt;flatMap(identity)&lt;/code&gt;), is
checked against each candidate in turn, and the one candidate that takes it is chosen. A lambda
that never returns fits every candidate alike, and the first declared is chosen.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;describe(n: int) -&amp;gt; string = s&amp;quot;int $n&amp;quot;
describe(s: string) -&amp;gt; string = s&amp;quot;string $s&amp;quot;
which[T](x: T) -&amp;gt; string = &amp;quot;any&amp;quot;
which(x: int) -&amp;gt; string = &amp;quot;int&amp;quot;

describe(1)                             // int 1
which(1)                                // int: the generic one accepts an int, but not the reverse
which(&amp;quot;x&amp;quot;)                              // any
val f: (string) -&amp;gt; string = describe    // the string overload
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Choosing an overload works as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Which arguments decide.&lt;/strong&gt; An integer literal and a lambda take their types from their
parameter, so each candidate tries them against its own: the literal fits a parameter whose type
can hold its value (&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, the other widths, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;), and the lambda a parameter
that is a function of as many parameters, or a function of one tuple of as many elements, which
the lambda &lt;a href=&quot;/spec/types/#tuples&quot;&gt;takes apart&lt;/a&gt;. A candidate that has a lambda take a tuple apart is
chosen only where no candidate takes it as written. Where the candidates left all give a lambda
the same parameter types, known without their own type arguments, and differ only in the result
they need of it, the lambda is checked once, with those parameter types and its result left to its
body, and then fits a candidate as any other argument’s type does: a map’s
&lt;code&gt;map((k, v) -&amp;gt; Summary(k, v))&lt;/code&gt; takes the overload whose function may answer anything, and
&lt;code&gt;map((k, v) -&amp;gt; (v, k))&lt;/code&gt; the one that needs a pair, as the more specific. Every other argument is checked once, on its own, and
only its type is tried against each candidate; when every candidate gives it the same parameter
type it is checked against that type. Neither &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; nor &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt; conforms to the
other, so where no overload is the most specific an integer literal prefers its own type, &lt;code&gt;int&lt;/code&gt;,
or &lt;code&gt;long&lt;/code&gt; for a literal too large for &lt;code&gt;int&lt;/code&gt;: &lt;code&gt;measure(1)&lt;/code&gt; calls &lt;code&gt;measure(n: int)&lt;/code&gt; beside
&lt;code&gt;measure(r: real)&lt;/code&gt;, and &lt;code&gt;wide(1)&lt;/code&gt; calls &lt;code&gt;wide(n: int)&lt;/code&gt; beside &lt;code&gt;wide(n: long)&lt;/code&gt;. The overload must
also be the most specific by the arguments that are not literals. With &lt;code&gt;wide(n: long)&lt;/code&gt; and
&lt;code&gt;wide(r: real)&lt;/code&gt;, &lt;code&gt;wide(1)&lt;/code&gt; is ambiguous, since neither takes the literal’s own type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generic overloads.&lt;/strong&gt; A generic overload is compared by the same rule: &lt;code&gt;which(x: int)&lt;/code&gt; is more
specific than &lt;code&gt;which[T](x: T)&lt;/code&gt;, because &lt;code&gt;which[T]&lt;/code&gt; accepts an &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;which(int)&lt;/code&gt; does not
accept a &lt;code&gt;T&lt;/code&gt;. Of &lt;code&gt;f[T](x: T)&lt;/code&gt; and &lt;code&gt;f[T](x: Maybe[T])&lt;/code&gt;, the second is the more specific. Written
type arguments, as in &lt;code&gt;which[int](1)&lt;/code&gt;, leave only the overloads with at least that many type
parameters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Defaults.&lt;/strong&gt; The most specific is compared over the parameters the call’s arguments are given
to, so &lt;code&gt;sized(n: int)&lt;/code&gt; and &lt;code&gt;sized(n: int, scale: int = 2)&lt;/code&gt; both accept &lt;code&gt;sized(1)&lt;/code&gt; and neither is
more specific: the call is ambiguous. &lt;code&gt;sized(1, 3)&lt;/code&gt; is not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;By-name parameters.&lt;/strong&gt; Whether a parameter is by-name does not tell two overloads apart:
&lt;code&gt;f(x: -&amp;gt; int)&lt;/code&gt; and &lt;code&gt;f(x: int)&lt;/code&gt; are the same parameter types. An argument that some candidate takes
by name is delayed, as that candidate needs it; when the chosen overload takes it strictly, it is
evaluated once, at the call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Repeated parameters.&lt;/strong&gt; An overload with a &lt;a href=&quot;#repeated-parameters&quot;&gt;repeated parameter&lt;/a&gt; is a
candidate only where no overload without one accepts the call: &lt;code&gt;describe(n: int)&lt;/code&gt; beside
&lt;code&gt;describe(ns: int*)&lt;/code&gt; takes &lt;code&gt;describe(1)&lt;/code&gt;, and &lt;code&gt;pick(x: long)&lt;/code&gt; beside &lt;code&gt;pick(xs: int*)&lt;/code&gt; takes
&lt;code&gt;pick(1)&lt;/code&gt;, though the repeated one would take the literal as its own type. Among the candidates
with one, each argument given to it is compared by the element type, so &lt;code&gt;kind(xs: int*)&lt;/code&gt; and
&lt;code&gt;kind(xs: string*)&lt;/code&gt; are told apart by &lt;code&gt;kind(1, 2)&lt;/code&gt; and &lt;code&gt;kind(&amp;quot;a&amp;quot;)&lt;/code&gt;; &lt;code&gt;kind()&lt;/code&gt; is ambiguous. Inside
the function the parameter is a vector, so &lt;code&gt;f(xs: int*)&lt;/code&gt; and &lt;code&gt;f(xs: Vector[int])&lt;/code&gt; have the same
parameter types.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scopes.&lt;/strong&gt; Overloads are the functions of one name in one scope: the top-level functions of one
module, in whichever of its files each is declared, or the local functions of one block. A block’s local functions of a name hide every outer
function of that name, whatever their parameter types, and a program’s own top-level functions of
a name hide the prelude’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Function values.&lt;/strong&gt; An overloaded name used as a value with no expected function type is an
error, as is one whose expected type no overload’s parameters accept. &lt;code&gt;main&lt;/code&gt; cannot be
overloaded, and a variant’s name is not overloaded by a function of the same name.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Two declarations with the same name and the &lt;strong&gt;same&lt;/strong&gt; parameter types are an error: a function that
chooses by its arguments’ values is written with clauses, described next.&lt;/p&gt;
&lt;h3 id=&quot;repeated-parameters&quot;&gt;Repeated parameters&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;total(values: int*) -&amp;gt; int
  var sum = 0
  for v in values do sum += v
  sum

total() // 0
total(1, 2, 3) // 6
val xs = [4, 5]
total(xs*) // 9
total((1 .. 10)*) // 55
max(0, xs*) // 5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A parameter written &lt;code&gt;values: T*&lt;/code&gt; is &lt;strong&gt;repeated&lt;/strong&gt; (variadic): a call gives it zero or more &lt;code&gt;T&lt;/code&gt;s, and
inside the function it is a &lt;code&gt;Vector[T]&lt;/code&gt; of them, in the order written. The rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It is the last parameter&lt;/strong&gt;, and there is at most one. It has a name, no default (a call that
gives it nothing passes an empty vector), and is not &lt;a href=&quot;/spec/by-name/&quot;&gt;by-name&lt;/a&gt;. The parameters
before it may have defaults: &lt;code&gt;framed(left: string = &amp;quot;[&amp;quot;, right: string = &amp;quot;]&amp;quot;, items: int*)&lt;/code&gt; is
called &lt;code&gt;framed()&lt;/code&gt;, &lt;code&gt;framed(&amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;gt;&amp;quot;, 1, 2)&lt;/code&gt; or &lt;code&gt;framed(right = &amp;quot;)&amp;quot;)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its arguments are positional.&lt;/strong&gt; Every positional argument from its position on is one element,
checked against &lt;code&gt;T&lt;/code&gt; like any argument, so a literal takes &lt;code&gt;T&lt;/code&gt; and a lambda its parameter types
from it, and a generic &lt;code&gt;T&lt;/code&gt; is inferred from them as from any arguments:
&lt;code&gt;max[T: Ord](first: T, rest: T*)&lt;/code&gt; is called &lt;code&gt;max(3, 9, 4)&lt;/code&gt;. A repeated parameter cannot be named
at a call, and the call’s named arguments, which follow its positional ones, name only the
parameters before it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;xs*&lt;/code&gt; splices a sequence&lt;/strong&gt;: written as the call’s last argument, in the repeated parameter’s
position, it passes the elements of &lt;code&gt;xs&lt;/code&gt;, which is any &lt;code&gt;Iterable[T]&lt;/code&gt;: a vector, a list, an array,
a range, a set. A &lt;code&gt;Vector[T]&lt;/code&gt; is passed as it is; any other sequence is copied into a new vector.
The spliced sequence is the parameter’s only argument: &lt;code&gt;f(1, 2, xs*)&lt;/code&gt; gives the parameter both
&lt;code&gt;1, 2&lt;/code&gt; and &lt;code&gt;xs&lt;/code&gt;, and is an error, as is &lt;code&gt;xs*&lt;/code&gt; given to a parameter that is not repeated, written
before another argument, named, or anywhere but a call’s argument list. Writing the other
elements into the sequence, &lt;code&gt;f(([1, 2] ++ xs)*)&lt;/code&gt;, says the same thing. The &lt;code&gt;*&lt;/code&gt; binds as
multiplication does, so a spliced expression of a looser operator is parenthesized.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The arguments are evaluated in the order written&lt;/strong&gt;, as any call’s are, and the vector is made
from them before the call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Methods and constructors&lt;/strong&gt; take one the same way: a method of a class, a trait or an impl, a
method of an object, a local function, a function defined by clauses (whose clauses match the
vector: &lt;code&gt;f([]) = …&lt;/code&gt;, &lt;code&gt;f([x]) = …&lt;/code&gt;), and a class’s constructor, whose field is then a vector:
&lt;code&gt;class Path(val parts: string*)&lt;/code&gt; is made by &lt;code&gt;Path(&amp;quot;usr&amp;quot;, &amp;quot;bin&amp;quot;)&lt;/code&gt;, and a subclass passes its
superclass’s repeated argument on with &lt;code&gt;: Path(parts*)&lt;/code&gt;. A &lt;code&gt;data&lt;/code&gt; field cannot be repeated. An
override, and a method implementing a trait’s, repeats the same last parameter as the method it
overrides, or neither does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;As a value&lt;/strong&gt;, a function with a repeated parameter takes the vector itself:
&lt;code&gt;val f: (Vector[int]) -&amp;gt; int = total&lt;/code&gt; is called &lt;code&gt;f([1, 2])&lt;/code&gt;, since a function value is called with
all of its arguments by position.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Called infix&lt;/strong&gt;, a method whose parameters are a repeated one, or one required parameter and a
repeated one, takes the one argument: &lt;code&gt;w surround &amp;quot;!&amp;quot;&lt;/code&gt; calls &lt;code&gt;w.surround(&amp;quot;!&amp;quot;)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;main&lt;/code&gt;&lt;/strong&gt; takes no repeated parameter: its one parameter is &lt;code&gt;args: Vector[string]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;clauses&quot;&gt;Clauses&lt;/h3&gt;
&lt;p&gt;A function may be defined by &lt;strong&gt;clauses&lt;/strong&gt;: its signature on one line with no body, then one clause
per line, each the function’s name applied to a pattern per parameter:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;classify(n: int) -&amp;gt; string
classify(0) = &amp;quot;zero&amp;quot;
classify(n)
  | n &amp;lt; 0 = &amp;quot;negative&amp;quot;
  | n &amp;lt; 10 = &amp;quot;small&amp;quot;
  | _ = &amp;quot;large&amp;quot;

fib(n: int) -&amp;gt; int
fib(n &amp;lt; 2) = n
fib(n) = fib(n - 1) + fib(n - 2)

area(s: Shape) -&amp;gt; real
area(Circle(r)) = 3.14159 * r * r
area(Rect(w, h)) = w * h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A clause’s arguments are followed by &lt;code&gt;=&lt;/code&gt;, a guard or an indented block of guards; a line of the same
name followed by &lt;code&gt;-&amp;gt;&lt;/code&gt; or by nothing is another declaration, as two abstract overloads of a method
are. The signature carries the types, the result type and any type parameters; a clause’s patterns
carry none. A call tries the clauses in order and runs the first whose patterns match the arguments. The
names a clause’s patterns bind are its own.&lt;/p&gt;
&lt;p&gt;A clause may be guarded:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;f(patterns) | condition = body&lt;/code&gt; is taken only when the condition holds.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;f(patterns)&lt;/code&gt; followed by an indented block of &lt;code&gt;| condition = body&lt;/code&gt; lines tries each guard in
order; &lt;code&gt;| _ = body&lt;/code&gt; always holds and ends the block.&lt;/li&gt;
&lt;li&gt;When the patterns match but every guard fails, the next clause is tried.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;|&lt;/code&gt; that starts a line continues the expression above it, so a second guard written on its own
line after a one-line guard is not a guard; it is reported, and the guards belong in the
indented block.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A body after &lt;code&gt;=&lt;/code&gt; is one expression on the same line or an indented block. Without a declared result
type, the result is inferred from the clauses’ bodies, which must agree; a recursive function
declares it.&lt;/p&gt;
&lt;p&gt;The clauses must cover every combination of arguments, as the arms of a &lt;code&gt;match&lt;/code&gt; must. A guarded
clause counts toward that only when one of its bodies has no guard, or &lt;code&gt;| _&lt;/code&gt;, so the clauses above
end with one that matches anything. A local function may be defined by clauses too.&lt;/p&gt;
&lt;p&gt;A clause no argument can reach is an error, as an &lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;unreachable arm&lt;/a&gt;
is: one whose arguments the clauses before it already match, counting a clause only when one of its
bodies has no guard. Within a clause, a body after one with no guard (or &lt;code&gt;| _&lt;/code&gt;) is never tried, and
is an error too.&lt;/p&gt;
&lt;p&gt;A function declared inside a block is a &lt;strong&gt;local function&lt;/strong&gt;. It can be called from anywhere in its
block, including before its declaration, and it sees the locals declared before it, the enclosing
function’s parameters, and the enclosing local functions. It reads and assigns those locals
themselves, not copies, so a &lt;code&gt;var&lt;/code&gt; it changes is changed for the code around it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;counter() -&amp;gt; int
  var count = 0
  bump(by: int)
    count += by
  bump(2)
  bump(3)
  count // 5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A call made before the local function’s declaration must not reach a local that is not yet
initialized there, directly or through the local functions it calls, and the function needs a
declared result type for such a call, as it does for recursion.&lt;/p&gt;
&lt;p&gt;A local function’s name is its block’s: a &lt;code&gt;val&lt;/code&gt;, a &lt;code&gt;var&lt;/code&gt; or a pattern binding of the same name in
the same block is an error, whether it is written before or after the function, because the
function is visible across the whole block. A block nested inside, a lambda’s body and the enclosing
function’s parameters are other scopes, and a local there may hide the function as any local hides
an outer name; likewise a local function declared in a nested block or a lambda’s body hides an
enclosing value, parameter or local function of its name there, so the innermost declaration wins
whichever kind each is. The block’s own local functions of one name are overloads of each other.&lt;/p&gt;
&lt;p&gt;A local function may declare type parameters of its own, with bounds, exactly as a top-level
function does. Its calls write its type arguments or leave them to be inferred, and used as a value
it takes them from the expected function type. Inside a generic function it also sees the enclosing
type parameters, which every call shares and none writes. A type parameter of a local function may
not reuse the name of one already in scope:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;pairs[T: Display](first: T) -&amp;gt; string
  pair[U](x: U) -&amp;gt; (T, U) = (first, x)
  s&amp;quot;${pair(1)} ${pair(&amp;quot;a&amp;quot;)} ${pair[real](2.5)}&amp;quot;

pairs(&amp;quot;p&amp;quot;) // &amp;quot;(p, 1) (p, a) (p, 2.5)&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;tail-calls&quot;&gt;Tail calls&lt;/h3&gt;
&lt;p&gt;A call is in &lt;strong&gt;tail position&lt;/strong&gt; when its result is the function’s result and nothing is left to do
after it: the body itself, the last item of a block in tail position, a branch of an &lt;code&gt;if&lt;/code&gt;, an arm of
a &lt;code&gt;match&lt;/code&gt; or a clause body in tail position, the right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or &lt;code&gt;||&lt;/code&gt; in tail position, and
the value of a &lt;code&gt;return&lt;/code&gt;, wherever it is written. A call whose result is used is not: by an operator,
a conversion, another call, a store, a pattern, a guard or a condition; nor is one inside a loop, a
lambda, a by-name argument or a local function, which runs later or from somewhere else.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A function that calls itself in tail position runs as a loop.&lt;/strong&gt; The arguments are evaluated, every
one before any parameter changes, then become the parameters, and the body starts again, so the
stack does not grow however deep the recursion goes. This holds at every optimization level, of a
call that names the function itself at its own type arguments, for every function no other body can
replace: a top-level or local function, a method of a final class, of an object or of a data type,
and a private method of any class. A call of a method on another receiver of the same type is a loop
too, with that receiver as &lt;code&gt;self&lt;/code&gt;. Each pass has parameters of its own: a lambda made in one pass
keeps that pass’s values, and a &lt;code&gt;var&lt;/code&gt; its body declares is a new one each pass.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;sum(n: long, acc: long) -&amp;gt; long = if n == 0 then acc else sum(n - 1, acc + n)

sum(10000000, 0)         // 50000005000000, in constant stack
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;@tailrec&lt;/code&gt; makes it a guarantee.&lt;/strong&gt; Written before a function, a method or a local function, it
asks the compiler to prove that every call of the function in its own body is such a loop, and each
failure is an error at the call, saying why:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;@tailrec
factorial(n: long) -&amp;gt; long = if n == 0 then 1 else n * factorial(n - 1)
// error: this recursive call of `factorial` is not in tail position: its result is used by `*`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is an error for the function to have no recursive call; for it to be a method that can be
overridden, a trait’s or a public method of an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class, since a call of it may run
an override; and for a recursive call to give a generic function other type arguments, which calls
another instance rather than looping. A function defined by clauses may be &lt;code&gt;@tailrec&lt;/code&gt;, written before
its signature.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Every other call in tail position replaces the caller’s frame.&lt;/strong&gt; A call of another function, a
method, a local function, a method through a trait or an open class, or a function value, made in tail
position, does not keep the caller waiting on the stack: the callee runs in the caller’s place and
returns straight to the caller’s caller. So functions that call each other, state machines written as
functions, and continuation passing run in constant stack however deep they go, at every
optimization level, with no annotation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;isEven(n: long) -&amp;gt; bool = if n == 0 then true else isOdd(n - 1)
isOdd(n: long) -&amp;gt; bool = n != 0 &amp;amp;&amp;amp; isEven(n - 1)

isEven(10000000) // true, in constant stack

sumTo(n: long, k: (long) -&amp;gt; long) -&amp;gt; long =
  if n == 0 then k(0) else sumTo(n - 1, s -&amp;gt; k(s + n))

sumTo(1000000, s -&amp;gt; s) // 500000500000: a million continuations, each calling the next
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A call in tail position keeps its frame in a few places, where something of the caller is still
needed once the callee has started:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a call of a local function that is given the place of a local it captures, which lives in the
caller’s frame;&lt;/li&gt;
&lt;li&gt;a call into the program’s code from the core library, which puts back the place a trap in the
library reports once the call returns;&lt;/li&gt;
&lt;li&gt;a call in a class’s body, which completes the object after the body;&lt;/li&gt;
&lt;li&gt;a call of a function whose arguments do not all travel in registers: one with more than five
parameters that are integers, bools or references (a method’s receiver and the values a local
function captures count), more than eight &lt;code&gt;real&lt;/code&gt;s, or an integer wider than &lt;code&gt;long&lt;/code&gt; among its
parameters or as its result; the call is made in its own frame, and so is a tail call such a
function makes;&lt;/li&gt;
&lt;li&gt;a call of a lambda or local function value that captures a local of the function it is written in
(not only its parameters): the closure’s entry holds the local where the code can reach it, so each
such call adds the entry’s frame.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A trap reports the place it happened as always, but the frames a tail call replaced are gone: a
program stopped after a million tail calls was not a million calls deep.&lt;/p&gt;
&lt;h3 id=&quot;main&quot;&gt;&lt;code&gt;main&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A program starts at &lt;code&gt;main&lt;/code&gt;, a function of the root module written &lt;code&gt;main()&lt;/code&gt; or
&lt;code&gt;main(args: Vector[string])&lt;/code&gt;, whose &lt;code&gt;args&lt;/code&gt; are the program’s arguments after its name. It is not
generic, overloaded, or given a default or a repeated parameter. What it yields decides how the
program exits:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.fs
import avin.io.IoError

main(args: Vector[string]) -&amp;gt; Result[unit, IoError | ParseError]
  for file in args
    val settings = parse(fs.readText(file)?)?
    println(s&amp;quot;$file: ${settings.size} settings&amp;quot;)
  Ok(())
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;unit&lt;/strong&gt;: the program exits with status 0.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An integer type&lt;/strong&gt;: the program exits with that integer as its status (its low 8 bits are what
the operating system keeps).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Nothing&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;main&lt;/code&gt; never returns, so whatever ends it, &lt;code&gt;exit&lt;/code&gt; or a trap, sets the status.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Result[unit, E]&lt;/code&gt; or &lt;code&gt;Result[int, E]&lt;/code&gt;&lt;/strong&gt;, so that &lt;code&gt;?&lt;/code&gt; can be used in &lt;code&gt;main&lt;/code&gt;. &lt;code&gt;Ok(())&lt;/code&gt; exits with 0, and
&lt;code&gt;Ok(n)&lt;/code&gt; exits with &lt;code&gt;n&lt;/code&gt;. &lt;code&gt;Ok&lt;/code&gt; may hold any integer type, and &lt;code&gt;Nothing&lt;/code&gt; for a &lt;code&gt;main&lt;/code&gt; that only
answers &lt;code&gt;Err&lt;/code&gt;, such as &lt;code&gt;main() = Err(&amp;quot;nothing to do&amp;quot;)&lt;/code&gt;. &lt;strong&gt;&lt;code&gt;Err(e)&lt;/code&gt; writes &lt;code&gt;error: &lt;/code&gt; and &lt;code&gt;e&lt;/code&gt;‘s
&lt;code&gt;Display&lt;/code&gt; to standard error as one line, and exits with status 1.&lt;/strong&gt; It does this after whatever
&lt;code&gt;main&lt;/code&gt; wrote to standard output and before the exit hooks run. &lt;code&gt;E&lt;/code&gt; must implement &lt;code&gt;Display&lt;/code&gt;;
an error type with no &lt;code&gt;Display&lt;/code&gt;, even one with &lt;code&gt;Debug&lt;/code&gt;, is refused. A union of errors, &lt;code&gt;IoError | ParseError&lt;/code&gt;, is shown by the &lt;code&gt;Display&lt;/code&gt; of the member it holds, so every member must have one. An
&lt;code&gt;Ok&lt;/code&gt; of any other type, such as &lt;code&gt;Result[string, E]&lt;/code&gt;, is refused, since there is no status to read
from it.&lt;/li&gt;
&lt;li&gt;Any other type is refused.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Returning from &lt;code&gt;main&lt;/code&gt;, with any of these, ends the program the same way: standard output is flushed,
the exit hooks run on the main thread, and the process exits, ending the
&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt; and actors still running. A trap in &lt;code&gt;main&lt;/code&gt;, or in the error’s &lt;code&gt;Display&lt;/code&gt;
while it is written, stops the program as a trap does anywhere, so no &lt;code&gt;error: &lt;/code&gt; line is written.
A program built by &lt;code&gt;avin test&lt;/code&gt; runs its tests and not &lt;code&gt;main&lt;/code&gt;, so &lt;code&gt;main&lt;/code&gt; is checked but not run.&lt;/p&gt;
&lt;h2 id=&quot;data&quot;&gt;data&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;data&lt;/code&gt; declares an algebraic data type: an immutable value with one or more variants.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Shape
  Circle(radius: real)
  Rect(width: real, height: real)

data Point(x: int, y: int)

data Option[+T]
  Some(value: T)
  None
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The single-line form declares a one-variant type whose variant has the type’s name. Variants are
constructors, not types: &lt;code&gt;Some(1)&lt;/code&gt; has type &lt;code&gt;Option[int]&lt;/code&gt;. A variant without fields is a value
(&lt;code&gt;None&lt;/code&gt;); one with fields, named and not called, is its constructor as a function value, as a
class’s name is: a function of all its fields, in order, to its data type or a refined variant’s
declared instance, so &lt;code&gt;[1, 2].map(Some)&lt;/code&gt; is &lt;code&gt;[Some(1), Some(2)]&lt;/code&gt; and &lt;code&gt;val f = Circle&lt;/code&gt; is a
&lt;code&gt;(real) -&amp;gt; Shape&lt;/code&gt;. A generic variant takes its instance from the function type expected there, whose
result also decides between variants sharing a name, or from written type arguments, &lt;code&gt;Some[int]&lt;/code&gt;;
where a value of the variant’s own type is expected, the variant is to be called. A variant is a name of its module, and
several data types of one module, in one file or in several, may each have a variant of one name:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Slant
    Normal
    Italic

data Weight
    Normal
    Bold

heavy(w: Weight) -&amp;gt; bool = w match
    Normal -&amp;gt; false
    Bold -&amp;gt; true

val s: Slant = Normal
println(heavy(Normal))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A bare use of a shared name is the variant of the type expected where it is written: a parameter’s
type, an annotated binding’s, a function’s result, a field’s, a collection’s element, the other
operand of a comparison (&lt;code&gt;w == Normal&lt;/code&gt;), and in a pattern the type of the value matched, so a nested
pattern decides each name by its field’s type. Where the parameter’s type is a type argument of a
generic function, what the call’s other arguments decide of it decides the name, on whichever side
of them it is written: with &lt;code&gt;same[T](a: T, b: T)&lt;/code&gt;, both &lt;code&gt;same(w, Normal)&lt;/code&gt; and &lt;code&gt;same(Normal, w)&lt;/code&gt; take
&lt;code&gt;Weight&lt;/code&gt;‘s. The elements of a collection literal (&lt;code&gt;[Normal, w]&lt;/code&gt;) and the branches of an &lt;code&gt;if&lt;/code&gt; agree
the same way. A &lt;code&gt;match&lt;/code&gt; is checked for coverage over the matched type’s own variants. Where nothing expected decides it, the use is an error that names the types and
the qualified forms:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val a = Normal
error: `Normal` is a variant of `Slant` and `Weight`, and nothing here expects one of those types: write `Slant.Normal` or `Weight.Normal`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within one type each variant has its own name. A shared name is still one name of the module, so no
function, module-level value or object of the module may have it, and a type’s companion object may
not have a name another type’s variant has. From another module a shared name is reached as any
variant is, &lt;code&gt;fonts.Normal&lt;/code&gt; or by &lt;code&gt;import fonts.Normal&lt;/code&gt;, and decided the same way; a private type’s
variant is not seen there, so where only one of the types is public its variant needs no deciding.&lt;/p&gt;
&lt;p&gt;The same expected type also reaches past a nearer declaration to the core library’s variants, which
a module’s own variant or an imported one of the same name hides (&lt;code&gt;None&lt;/code&gt;, &lt;code&gt;Some&lt;/code&gt;, &lt;code&gt;Ok&lt;/code&gt;, &lt;code&gt;Err&lt;/code&gt;,
&lt;code&gt;Left&lt;/code&gt;, &lt;code&gt;Right&lt;/code&gt;). A mirror of a C enum with an enumerator &lt;code&gt;NONE&lt;/code&gt; declares a variant &lt;code&gt;None&lt;/code&gt;, and
wherever an &lt;code&gt;Option&lt;/code&gt; is expected the bare &lt;code&gt;None&lt;/code&gt; is still &lt;code&gt;Option&lt;/code&gt;‘s; everywhere else it is the
module’s own, as the &lt;a href=&quot;#visibility-and-modules&quot;&gt;scoping order&lt;/a&gt; says:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;data ImageFormat
  None
  Png

find(n: int) -&amp;gt; Option[int] = if n &amp;gt; 0 then Some(n) else None // Option&apos;s

val f = None // ImageFormat&apos;s: nothing expects an Option
val o: Option[ImageFormat] = Some(None) // Option&apos;s Some, ImageFormat&apos;s None
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Only the hidden variant’s own type chooses it: an expected &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;Any&lt;/code&gt; or a trait leaves the
nearer variant, which is then reported against what was expected.&lt;/p&gt;
&lt;p&gt;A variant is also reached through its type, &lt;code&gt;Type.Variant&lt;/code&gt;: &lt;code&gt;Shape.Circle(1.0)&lt;/code&gt;, &lt;code&gt;Option.None&lt;/code&gt;,
and in patterns &lt;code&gt;case Shape.Circle(r)&lt;/code&gt;. The qualified name is the same constructor as the bare one,
so the two forms mix freely in one expression or one &lt;code&gt;match&lt;/code&gt;, and a &lt;code&gt;match&lt;/code&gt; over both is checked for
coverage as one over either. A generic type’s arguments are inferred as for the bare name, or written
once, on the type (&lt;code&gt;Option[int].None&lt;/code&gt;) or on the variant (&lt;code&gt;Option.None[int]&lt;/code&gt;,
&lt;code&gt;Option.Some[long](9)&lt;/code&gt;), all of them or a leading prefix with the rest inferred. A pattern writes
none, &lt;code&gt;case Option.Some(x)&lt;/code&gt;: the value matched decides them. Another module’s
type is reached through the module, &lt;code&gt;palette.Color.Red&lt;/code&gt;, or by its own name where it is imported,
&lt;code&gt;Color.Red&lt;/code&gt;, and only where the type is public. A local, a parameter or a member named like the type
hides it, so &lt;code&gt;Color.Red&lt;/code&gt; is then that value’s member. &lt;code&gt;Type.Name&lt;/code&gt;, with &lt;code&gt;Name&lt;/code&gt; capitalized and
neither a variant of the type nor a member of its companion or a static member of the type, is
reported with the variants the type has; on a class it is reported as a class having none. A
companion object cannot declare a method or field named after one of its type’s variants, since
&lt;code&gt;Type.Variant&lt;/code&gt; names the variant.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;area(s: Shape) -&amp;gt; real = s match
  Shape.Circle(r) -&amp;gt; 3.0 * r * r
  Rect(w, h) -&amp;gt; w * h

main()
  println(area(Shape.Rect(2.0, 3.0))) // 6
  val none: Option[string] = Option.None
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A variant of a generic type may say which instance it makes, &lt;code&gt;IntLit(value: int) -&amp;gt; Expr[int]&lt;/code&gt;, and
take type parameters of its own; a &lt;code&gt;match&lt;/code&gt; arm on it then knows that instance. These are
&lt;a href=&quot;/spec/refined-variants/&quot;&gt;refined variants&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;data&lt;/code&gt; values have no identity, derive
&lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; when their fields do, without &lt;code&gt;derives&lt;/code&gt;, and are matched
exhaustively. Methods are added in an &lt;code&gt;impl&lt;/code&gt; block; an impl of &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; replaces the
derived one (&lt;a href=&quot;/spec/equality-and-memory/#display-and-debug&quot;&gt;Display and Debug&lt;/a&gt;). A data type whose
variants have no fields is an enumeration, and &lt;code&gt;derives Enumerable&lt;/code&gt; gives it &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;ordinal&lt;/code&gt;,
&lt;code&gt;name&lt;/code&gt; and &lt;code&gt;valueOf(name)&lt;/code&gt; (&lt;a href=&quot;/spec/derivation/#enumerations&quot;&gt;Enumerations&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;changing-fields-with&quot;&gt;Changing fields: &lt;code&gt;with&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A data value never changes, so a changed one is a new value: &lt;code&gt;base with { f = v, … }&lt;/code&gt; is a value of
the base’s type with each named field replaced and every other field the base’s. The left of each
&lt;code&gt;=&lt;/code&gt; is a field’s name or a &lt;strong&gt;path&lt;/strong&gt; of field names, &lt;code&gt;pos.x&lt;/code&gt;, reaching a field inside a field at any
depth; the base is left as it was.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;data Point(x: int, y: int)
data Sprite(pos: Point, name: string)

main()
  val s = Sprite(Point(1, 2), &amp;quot;ship&amp;quot;)
  val t = s with {pos.x = 3, name = &amp;quot;ghost&amp;quot;}
  println(s) // Sprite(Point(1, 2), ship)
  println(t) // Sprite(Point(3, 2), ghost)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A path makes again only the values along it.&lt;/strong&gt; &lt;code&gt;s with { pos.x = 3 }&lt;/code&gt; is a new &lt;code&gt;Sprite&lt;/code&gt; holding
a new &lt;code&gt;Point&lt;/code&gt;; every field no path reaches is the base’s own value, shared, so a class object or an
array a field holds is the same object in both. Paths with a common prefix make that prefix’s value
once: &lt;code&gt;s with { pos.x = 1, pos.y = 2 }&lt;/code&gt; makes one &lt;code&gt;Point&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each value is read against the type of the field its path ends at&lt;/strong&gt;, so a literal takes that
type, as an argument does: &lt;code&gt;{ ratio = 1 }&lt;/code&gt; into a &lt;code&gt;real&lt;/code&gt; field, &lt;code&gt;{ items = [4, 5] }&lt;/code&gt; into a &lt;code&gt;List&lt;/code&gt;,
&lt;code&gt;{ next = None }&lt;/code&gt; into an &lt;code&gt;Option&lt;/code&gt;, a lambda into a function field.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The result has the base’s type.&lt;/strong&gt; A generic data value keeps its type arguments, so
&lt;code&gt;Box(1, &amp;quot;a&amp;quot;) with { v = 2 }&lt;/code&gt; is a &lt;code&gt;Box[int]&lt;/code&gt; and &lt;code&gt;with { v = &amp;quot;s&amp;quot; }&lt;/code&gt; on it is a type error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order.&lt;/strong&gt; The base is evaluated once, first, then the values in the order written, and the new
value is made after the last of them. A value that leaves the function (&lt;code&gt;return&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;) leaves
before anything is made.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The base is a data type with one variant.&lt;/strong&gt; On a type with several the fields a value has are
decided at run time, so &lt;code&gt;with&lt;/code&gt; is refused there, and a &lt;code&gt;match&lt;/code&gt; makes the new variant. A class, a
type parameter or any other type is refused too: a class’s object is changed through its &lt;code&gt;var&lt;/code&gt;
fields.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A path goes through data fields only&lt;/strong&gt;: each name before the last must hold a data type with one
variant. A field holding a class, a type with several variants (&lt;code&gt;Option&lt;/code&gt; among them), a type
parameter or a built-in type is refused, with the suggestion to replace that field whole.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only fields are named.&lt;/strong&gt; A method of the type, even one taking no arguments, is refused; a name
the type does not have is reported with the type’s name and its nearest field.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No two changes overlap&lt;/strong&gt;: a path named twice is an error (&lt;code&gt;`pos.x` is changed twice in one `with`&lt;/code&gt;), and so is a field changed whole beside a path inside it, &lt;code&gt;pos = q, pos.x = 1&lt;/code&gt;, in either
order.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An element is not a field.&lt;/strong&gt; &lt;code&gt;with { xs(0) = 1 }&lt;/code&gt; is a syntax error that suggests replacing the
whole field, &lt;code&gt;xs = …&lt;/code&gt;. Compound assignments (&lt;code&gt;+=&lt;/code&gt;) are not written there, and &lt;code&gt;with { }&lt;/code&gt; names
nothing and is an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;with&lt;/code&gt; is a postfix tail like a call’s parentheses: it binds to the operand before it (&lt;code&gt;-p with { … }&lt;/code&gt;
is &lt;code&gt;-(p with { … })&lt;/code&gt;, &lt;code&gt;a + p with { … }&lt;/code&gt; changes &lt;code&gt;p&lt;/code&gt;), its base may be any expression, a call, a
field or another &lt;code&gt;with&lt;/code&gt;, and a member read may follow the brace (&lt;code&gt;s with { pos.x = 3 }.pos&lt;/code&gt;). A brace
suspends the off-side rule, so the changes may stand one per line, and the last may carry a comma.
&lt;code&gt;with&lt;/code&gt; is a keyword only after an operand and before &lt;code&gt;{&lt;/code&gt;; everywhere else it is a name, so a field,
a method or a local may be called &lt;code&gt;with&lt;/code&gt;, and &lt;code&gt;a with b&lt;/code&gt; stays an infix call of a method &lt;code&gt;with&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;class&quot;&gt;class&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;open class Account(owner: string, var balance: int)
  if balance &amp;lt; 0 then panic(&amp;quot;an account cannot open overdrawn&amp;quot;)
  val opened = clock.now()
  println(s&amp;quot;opened an account for $owner&amp;quot;)

  deposit(amount: int)
    balance += amount

  describe() -&amp;gt; string = s&amp;quot;$owner: $balance&amp;quot;

class Savings(owner: string, balance: int, rate: real): Account(owner, balance), Display
  override describe() -&amp;gt; string = &amp;quot;savings &amp;quot; + super.describe()
  override display(out: Writer, spec: FormatSpec) = out.write(describe())
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The class is its constructor.&lt;/strong&gt; The parameter list after the name is the constructor’s
parameter list, and there is no other constructor; a factory belongs in the companion &lt;code&gt;object&lt;/code&gt;,
whose &lt;code&gt;apply&lt;/code&gt; methods the class’s name also calls, as “A companion’s &lt;code&gt;apply&lt;/code&gt;“ below describes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class parameters are fields.&lt;/strong&gt; A plain parameter (&lt;code&gt;owner&lt;/code&gt;) is a private, immutable field: every
method of the class can read it, and nothing outside can. &lt;code&gt;val&lt;/code&gt; makes it a public read-only field
and &lt;code&gt;var&lt;/code&gt; a public mutable one (&lt;code&gt;balance&lt;/code&gt; above); &lt;code&gt;private var&lt;/code&gt; keeps a mutable one private.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The class body is the constructor’s body.&lt;/strong&gt; Everything in it that is not a member declaration —
expressions, &lt;code&gt;if&lt;/code&gt;, loops, calls — runs when an instance is created, top to bottom, together with
the initializers of the &lt;code&gt;val&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt; fields declared in the body (&lt;code&gt;opened&lt;/code&gt;). Methods are
declarations and do not run.&lt;/li&gt;
&lt;li&gt;The receiver is implicit. Members are in scope by their bare names, and &lt;code&gt;self&lt;/code&gt; names the instance.&lt;/li&gt;
&lt;li&gt;After &lt;code&gt;:&lt;/code&gt; comes at most one superclass, with its constructor arguments, followed by any number of
traits.&lt;/li&gt;
&lt;li&gt;Classes are &lt;strong&gt;final unless declared &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt;&lt;/strong&gt;. Overriding requires &lt;code&gt;override&lt;/code&gt;.
An &lt;code&gt;abstract class&lt;/code&gt; may leave members without bodies and cannot be instantiated. &lt;code&gt;open&lt;/code&gt; and
&lt;code&gt;abstract&lt;/code&gt; mark a class only: a method takes neither, since every public method of such a class
may be overridden and one without a body is abstract already; nor does a trait, a data type, an
object or a top-level function. &lt;code&gt;override&lt;/code&gt; marks a method alone. Each misplaced
word is an error that says to remove it.&lt;/li&gt;
&lt;li&gt;Instances are heap objects with identity. Unless the class implements or derives &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt; and
the hash are by identity, like &lt;code&gt;===&lt;/code&gt;; &lt;code&gt;class Point(x: int, y: int) derives Eq, Hash, Display&lt;/code&gt;
compares and hashes by its fields, which for &lt;code&gt;derives&lt;/code&gt; are its constructor parameters. Display
exists only if the class implements or derives it. See
&lt;a href=&quot;/spec/equality-and-memory/#equality&quot;&gt;equality&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A class is created by calling it, &lt;code&gt;Account(&amp;quot;ada&amp;quot;, 10)&lt;/code&gt;, as a function is called; a generic class’s
type arguments are inferred from the arguments and the expected type, or written,
&lt;code&gt;Box[string](&amp;quot;x&amp;quot;)&lt;/code&gt;. The class’s name is also its constructor as a function value.&lt;/li&gt;
&lt;li&gt;Outside the class, &lt;code&gt;obj.field&lt;/code&gt; reads a public field, &lt;code&gt;obj.field = value&lt;/code&gt; assigns a public &lt;code&gt;var&lt;/code&gt;
one, and &lt;code&gt;obj.method(args)&lt;/code&gt; calls a method. A method or a field declared &lt;code&gt;private&lt;/code&gt; in the body,
and a plain class parameter, are private to the class: its constructor and methods, and the
lambdas and local functions in them, may use them on any instance of the class.&lt;/li&gt;
&lt;li&gt;Inside the class, names resolve innermost first: a local, a parameter or a local function hides
a member of the same name, and a member hides a top-level declaration. &lt;code&gt;self.balance&lt;/code&gt; always
reaches the field, so a method’s parameter may share a field’s name. In the class body, a class
parameter’s name is its field, so it reads what an assignment to a &lt;code&gt;var&lt;/code&gt; stored.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field may share its name with a trait’s method that takes a parameter list&lt;/strong&gt;, so a field of
any name leaves a type its &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Iterable&lt;/code&gt; and every other
trait’s methods, written or derived: &lt;code&gt;data Config(host: string, debug: bool)&lt;/code&gt; prints, compares
and hashes. &lt;code&gt;x.name&lt;/code&gt; and a bare &lt;code&gt;name&lt;/code&gt; read the field; &lt;code&gt;x.name(args)&lt;/code&gt; and a bare &lt;code&gt;name(args)&lt;/code&gt; call
the method, so a field holding a function is called by reading it first, &lt;code&gt;val f = x.name&lt;/code&gt;;
through the trait, or a type parameter it bounds, only the method is seen. Every
other method of a field’s name is an error at its declaration: a method of no trait, and a
method of no parameter list, which the field implements instead.&lt;/li&gt;
&lt;li&gt;Methods take the forms top-level functions take: a body after &lt;code&gt;=&lt;/code&gt;, an indented body, or clauses,
which match the arguments and not the receiver. A method may have type parameters of its own,
after its class’s.&lt;/li&gt;
&lt;li&gt;A method declared with a parameter list, &lt;code&gt;()&lt;/code&gt; included, and named without a call is a function
value bound to its receiver: &lt;code&gt;val f = acct.deposit&lt;/code&gt; is an &lt;code&gt;(int) -&amp;gt; unit&lt;/code&gt; that deposits into
&lt;code&gt;acct&lt;/code&gt;, which is evaluated once, where the value is made. Inside the class a bare method name is
the same over &lt;code&gt;self&lt;/code&gt;. Through a superclass’s or a trait’s type the value calls the implementation
the object’s class has. A method’s own type parameters are written, &lt;code&gt;box.pair[bool]&lt;/code&gt;, or come
from the expected function type. The same holds for the methods an &lt;code&gt;impl&lt;/code&gt; adds to any type,
&lt;code&gt;&amp;quot;hey&amp;quot;.repeat&lt;/code&gt; included. A method declared with no parameter list has no such value; see below.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A method declared with an empty parameter list is a value only where a function type is
expected.&lt;/strong&gt; &lt;code&gt;val f: () -&amp;gt; int = c.bump&lt;/code&gt;, &lt;code&gt;apply(c.bump)&lt;/code&gt; with &lt;code&gt;apply(f: () -&amp;gt; int)&lt;/code&gt;, and an
element of a &lt;code&gt;Vector[() -&amp;gt; int]&lt;/code&gt; make the value; anywhere else, &lt;code&gt;println(c.bump)&lt;/code&gt;,
&lt;code&gt;s&amp;quot;${c.bump}&amp;quot;&lt;/code&gt;, &lt;code&gt;c.bump == 0&lt;/code&gt;, &lt;code&gt;val v = c.bump&lt;/code&gt; with no type, &lt;code&gt;xs.iterator.next()&lt;/code&gt;, or an
argument whose parameter is a type parameter or &lt;code&gt;Any&lt;/code&gt;, naming it without a call is an error
naming both fixes: “&lt;code&gt;bump&lt;/code&gt; is called with &lt;code&gt;()&lt;/code&gt;: write &lt;code&gt;c.bump()&lt;/code&gt;, or &lt;code&gt;() -&amp;gt; c.bump()&lt;/code&gt; for a
function value”. The fix is written on the receiver as the program named it: a local or a
parameter by its name, &lt;code&gt;self&lt;/code&gt;, a type for a static member, and nothing for the implicit &lt;code&gt;self&lt;/code&gt; of
a bare name. A placeholder’s is &lt;code&gt;_.toInt()&lt;/code&gt; alone, since a &lt;code&gt;_&lt;/code&gt; cannot stand in a lambda of its
own; any other receiver, &lt;code&gt;Some(1).iterator&lt;/code&gt;, is not repeated, and the fix is &lt;code&gt;.iterator()&lt;/code&gt;. Among overloads that include one of no
parameters, a bare name with no expected function type gets the same error. A missing &lt;code&gt;()&lt;/code&gt; is
far likelier there than a wanted function, which would otherwise surface only as wrong output.
A method with parameters, &lt;code&gt;acct.deposit&lt;/code&gt;, is a value wherever it is named.&lt;/li&gt;
&lt;li&gt;A field declared in the body without a type has its initializer’s type. The body cannot
&lt;code&gt;return&lt;/code&gt;: it runs to its end to make the object.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;parameterless-methods&quot;&gt;Parameterless methods&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Chain(items: Vector[int])
  head -&amp;gt; int = items(0)
  tail -&amp;gt; Chain = Chain(items.slice(1, items.length))
  second -&amp;gt; int = tail.head
  clear() -&amp;gt; Chain = Chain([])

val c = Chain([1, 2, 3])
c.tail.head // 2
c.clear() // `()`: declared with a parameter list
val f = () -&amp;gt; c.head
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A method declared with no parameter list is called by its name alone.&lt;/strong&gt; &lt;code&gt;head -&amp;gt; int = …&lt;/code&gt;
declares a method that &lt;code&gt;c.head&lt;/code&gt; calls, with no parentheses; inside the class &lt;code&gt;head&lt;/code&gt; and
&lt;code&gt;self.head&lt;/code&gt; call it too. Each read runs the method again, on a receiver evaluated once for that
read, so &lt;code&gt;c.tail.head&lt;/code&gt; and &lt;code&gt;s&amp;quot;${c.head}&amp;quot;&lt;/code&gt; read as a field would and compute as a call does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A method declared with &lt;code&gt;()&lt;/code&gt; keeps them at the call&lt;/strong&gt;: &lt;code&gt;buf.clear()&lt;/code&gt;, &lt;code&gt;iter.next()&lt;/code&gt;. The
parentheses say the call does something, so a method with an effect is declared with them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A parameterless method has no function value.&lt;/strong&gt; Naming it calls it; where a function is
wanted, a lambda says so, &lt;code&gt;() -&amp;gt; c.head&lt;/code&gt;. Where a function type is expected and the method yields
something else, the error names the lambda.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parentheses after one call what it yields.&lt;/strong&gt; &lt;code&gt;t.adder(4)&lt;/code&gt;, where &lt;code&gt;adder -&amp;gt; (int) -&amp;gt; int&lt;/code&gt;, calls
the function &lt;code&gt;adder&lt;/code&gt; yields, and &lt;code&gt;t.items(2)&lt;/code&gt; indexes the sequence &lt;code&gt;items&lt;/code&gt; yields. Where the
result is neither a function nor a sequence given an index, &lt;code&gt;c.head&lt;/code&gt; is an error naming the fix,
&lt;code&gt;head&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is the only method of its name&lt;/strong&gt;: a class, a trait or the impls of a type cannot also have a
method of that name with a parameter list, in the type itself or inherited, since &lt;code&gt;x.head&lt;/code&gt; would
leave no call to choose between them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The shape is part of the signature.&lt;/strong&gt; An override, or an implementation of a trait’s method, is
declared without a parameter list exactly where the method it replaces is: overriding &lt;code&gt;head&lt;/code&gt; with
&lt;code&gt;head()&lt;/code&gt;, or the reverse, is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A public field implements an abstract one.&lt;/strong&gt; A trait’s or an abstract class’s &lt;code&gt;size -&amp;gt; int&lt;/code&gt;
with no body is implemented by a method of the name, or by a public &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; field of the
name — a class parameter declared &lt;code&gt;val&lt;/code&gt; among them — or, for a data type, by a field of its one
variant. The field’s type is the method’s result. A private field does not implement it, and a
field cannot share its name with a method that has a body.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A member is declared without a parameter list as it is; a function at the top level or in a
block, with &lt;code&gt;def&lt;/code&gt;&lt;/strong&gt; (below). A parameterless method takes no type parameters of its own,
since &lt;code&gt;x.first[int]&lt;/code&gt; would read as indexing its result; its class’s type parameters it has.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A static one is read on its type the same way&lt;/strong&gt;: &lt;code&gt;Color.values&lt;/code&gt;, and through a type parameter
bounded by its trait, &lt;code&gt;T.values&lt;/code&gt;, the type argument’s own in each instance; &lt;code&gt;T.values()&lt;/code&gt; is the
error naming the fix.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The standard library declares every pure accessor without a parameter list&lt;/strong&gt;: a method of no
parameters that answers from its receiver, or a static one from its type, changing nothing and
handing out nothing to change or use up. &lt;code&gt;opt.isDefined&lt;/code&gt;, &lt;code&gt;opt.get&lt;/code&gt;, &lt;code&gt;r.isOk&lt;/code&gt;, &lt;code&gt;e.swap&lt;/code&gt;,
&lt;code&gt;s.trim&lt;/code&gt;, &lt;code&gt;s.headOption&lt;/code&gt;, &lt;code&gt;c.isDigit&lt;/code&gt;, &lt;code&gt;n.abs&lt;/code&gt;, &lt;code&gt;x.isNaN&lt;/code&gt;, &lt;code&gt;d.toSeconds&lt;/code&gt;, &lt;code&gt;date.year&lt;/code&gt;,
&lt;code&gt;5.seconds&lt;/code&gt;, &lt;code&gt;m.groupCount&lt;/code&gt;, &lt;code&gt;err.message&lt;/code&gt;, &lt;code&gt;json.keys&lt;/code&gt;. What keeps &lt;code&gt;()&lt;/code&gt; is what has an effect or
hands out a fresh mutable object or an iterator (&lt;code&gt;next()&lt;/code&gt;, &lt;code&gt;iterator()&lt;/code&gt;, &lt;code&gt;toBuffer()&lt;/code&gt;,
&lt;code&gt;charIterator()&lt;/code&gt;); what reaches a resource outside the program (a file, a socket, a child process,
a lock, a future, a signal); a constructor or factory (&lt;code&gt;Vector.empty[int]()&lt;/code&gt;, &lt;code&gt;newBuilder()&lt;/code&gt;); a
name that also has an overload with parameters (&lt;code&gt;s.toInt()&lt;/code&gt; beside &lt;code&gt;s.toInt(16)&lt;/code&gt;, and with it the
whole family &lt;code&gt;toLong()&lt;/code&gt;, &lt;code&gt;toReal()&lt;/code&gt;, &lt;code&gt;toBool()&lt;/code&gt; and their &lt;code&gt;…Option()&lt;/code&gt;; &lt;code&gt;stripMargin()&lt;/code&gt; beside
&lt;code&gt;stripMargin(&apos;#&apos;)&lt;/code&gt;); and the methods of the traits every type implements and derives produce,
&lt;code&gt;toString()&lt;/code&gt;, &lt;code&gt;hash()&lt;/code&gt;, &lt;code&gt;zero()&lt;/code&gt;, &lt;code&gt;one()&lt;/code&gt;, &lt;code&gt;negate()&lt;/code&gt; and &lt;code&gt;shape()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;With &lt;code&gt;def&lt;/code&gt;, the result type may be left to inference&lt;/strong&gt;: &lt;code&gt;def perimeter = 2.0 * (w + h)&lt;/code&gt;. Without
&lt;code&gt;def&lt;/code&gt;, a name followed by &lt;code&gt;=&lt;/code&gt; is an assignment.&lt;/li&gt;
&lt;li&gt;It is not a field: &lt;code&gt;c.head = 3&lt;/code&gt; is an error, and a class cannot declare a field and a method of
one name. &lt;code&gt;super.head&lt;/code&gt; reads the superclass’s implementation of one, where &lt;code&gt;super.describe&lt;/code&gt; names
no function value of a method with a parameter list.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;functions-with-no-parameter-list&quot;&gt;Functions with no parameter list&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;var ticks = 0

def now -&amp;gt; int
  ticks += 1
  ticks

def adder -&amp;gt; (int) -&amp;gt; int = x -&amp;gt; x + now

main()
  println(s&amp;quot;$now $now&amp;quot;) // 1 2
  def step -&amp;gt; int = now * 10
  println(step) // 30
  println(adder(100)) // 104
  val f = () -&amp;gt; now
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A function at the top level or in a block is declared without a parameter list with &lt;code&gt;def&lt;/code&gt;&lt;/strong&gt;:
&lt;code&gt;def now -&amp;gt; int = …&lt;/code&gt;. It follows the rules of a parameterless method: it is called by its bare
name, &lt;code&gt;now&lt;/code&gt;, its body running again at every read; parentheses after it call what it yields, a
function or a sequence given an index, and are otherwise an error naming the fix, &lt;code&gt;now&lt;/code&gt;; it has
no function value, so where a function is wanted a lambda names it, &lt;code&gt;() -&amp;gt; now&lt;/code&gt;, and the error
where one is missing says so; it takes no type parameters of its own; and it is no variable, so
&lt;code&gt;now = 3&lt;/code&gt; is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Without &lt;code&gt;def&lt;/code&gt;, &lt;code&gt;now -&amp;gt; int = …&lt;/code&gt; at the top level or in a block is an error&lt;/strong&gt; that names &lt;code&gt;def now -&amp;gt; int = …&lt;/code&gt;, &lt;code&gt;val now = …&lt;/code&gt; for a value computed once, and &lt;code&gt;now() -&amp;gt; …&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is the only function of its name in its scope&lt;/strong&gt;, and shares the scope’s one namespace: a
&lt;code&gt;val&lt;/code&gt; and a &lt;code&gt;def&lt;/code&gt; of one name in one module or one block, or a &lt;code&gt;def now&lt;/code&gt; beside a &lt;code&gt;now(x: int)&lt;/code&gt;,
is an error.&lt;/li&gt;
&lt;li&gt;A local one captures what is in scope where it is declared, as a local function does, and may be
read before its declaration in its block. A public one is read from another module as
&lt;code&gt;clock.now&lt;/code&gt;, or by its imported name.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;inheritance&quot;&gt;Inheritance&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;abstract class Shape(val label: string)
  area() -&amp;gt; int
  describe() -&amp;gt; string = s&amp;quot;$label: ${area()}&amp;quot;

open class Rect(label: string, val w: int, val h: int): Shape(label)
  override area() -&amp;gt; int = w * h

class Square(label: string, side: int): Rect(label, side, side)
  override describe() -&amp;gt; string = &amp;quot;square &amp;quot; + super.describe()
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Only an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class can be extended&lt;/strong&gt;; extending a final class is an error. A
generic superclass is written with its type arguments, &lt;code&gt;class IntBox(x: int): Box[int](x)&lt;/code&gt;.
A superclass or trait from another module is named as an import makes it visible, bare or
through its module: &lt;code&gt;class Body: shapes.Base(&amp;quot;b&amp;quot;), io.Reader&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Construction runs from the top down.&lt;/strong&gt; A subclass’s constructor first evaluates the arguments
written after the superclass and runs the superclass’s constructor body on the new object, then
stores its own parameters and runs its own body. Those arguments run before the object is ready:
a parameter’s name in them reads the argument itself, and they cannot call a method or use
&lt;code&gt;self&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A subclass has every field of its superclass&lt;/strong&gt;, first and in the superclass’s order, then its
own. A field cannot be overridden: a public field may not share the name of an inherited public
field or method. A private member stays private to the class that declares it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A method a subclass may override&lt;/strong&gt; is a public method of an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class. An
override is marked &lt;code&gt;override&lt;/code&gt;, takes the same parameter types (with the superclass’s type
arguments substituted) and yields the same result type or one seen as it with no conversion, since
a result is a covariant position: a subclass, a tuple whose parts are (&lt;code&gt;(Dog, Dog)&lt;/code&gt; for
&lt;code&gt;(Animal, Animal)&lt;/code&gt;), an instance of a covariant generic type at narrower arguments
(&lt;code&gt;HashMap[K, V]&lt;/code&gt; for &lt;code&gt;Map[K, V]&lt;/code&gt;, &lt;code&gt;Option[Dog]&lt;/code&gt; for &lt;code&gt;Option[Animal]&lt;/code&gt;), a function with a narrower
result, or a string or object for &lt;code&gt;Any&lt;/code&gt;. A result that would need a box is not one: &lt;code&gt;-&amp;gt; int&lt;/code&gt;
does not override &lt;code&gt;-&amp;gt; Any&lt;/code&gt;, nor &lt;code&gt;-&amp;gt; (int, int)&lt;/code&gt; &lt;code&gt;-&amp;gt; (Any, int)&lt;/code&gt;. The same holds for a method
implementing a trait’s. A method
with type parameters of its own is overridden by one declaring as many, matched by position:
&lt;code&gt;override tag[V](item: V)&lt;/code&gt; overrides &lt;code&gt;tag[U](item: U)&lt;/code&gt;. An override assumes no more of its type
arguments than the method it overrides, since a call through the base type passes any type the
base’s bounds admit: each bound it writes is implied by the overridden method’s bounds on the same
parameter, being one of them, a trait or class one of them conforms to (&lt;code&gt;[U: Shape]&lt;/code&gt; over
&lt;code&gt;[U: Named]&lt;/code&gt; where &lt;code&gt;trait Named: Shape&lt;/code&gt;), or &lt;code&gt;Eq&lt;/code&gt; or &lt;code&gt;Hash&lt;/code&gt;, which every type has. It may keep the
bounds, weaken them or drop them; &lt;code&gt;override tag[V: Ord](item: V)&lt;/code&gt; over &lt;code&gt;tag[U](item: U)&lt;/code&gt; is an
error naming the bound and the method. The same holds of a class’s or an impl’s method
implementing a trait’s, for a data type or a built-in type, of a static member, and of a trait’s
override. A method sharing an inherited method’s name and parameter types without
&lt;code&gt;override&lt;/code&gt;, and &lt;code&gt;override&lt;/code&gt; on a method that overrides nothing, are errors. An override cannot be
private.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Methods overload as functions do.&lt;/strong&gt; A class, object, trait or impl may declare several methods
of one name with different parameter types, and a call chooses among the methods of that name its
receiver’s static type has, its own and inherited ones together, by the rules for functions above.
Each overload is a method of its own: a subclass overrides one by its parameter types and inherits
the others, and may add an overload of an inherited name without &lt;code&gt;override&lt;/code&gt;. A call through an
&lt;code&gt;open&lt;/code&gt; class or a trait reaches the override of the overload it chose. &lt;code&gt;override&lt;/code&gt; that matches no
inherited method’s parameter types is an error naming the inherited overloads of that name, or,
where there is one, how its parameters differ. An overloaded method used as a value takes its
overload from the expected function type, and without one it is ambiguous.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An abstract method&lt;/strong&gt; is one without a body, allowed only in an &lt;code&gt;abstract&lt;/code&gt; class. A class that is
not abstract implements every abstract method it inherits. An abstract class cannot be
instantiated, but its constructor runs as part of each subclass’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call reaches the override of the object’s own class&lt;/strong&gt;, whatever the receiver’s static type,
when that type is an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class. &lt;code&gt;super.name(args)&lt;/code&gt; calls the superclass’s
implementation directly; it cannot name an abstract method.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A subclass instance conforms to its superclasses.&lt;/strong&gt; It passes wherever a superclass is expected,
and the branches of an &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; that yield different subclasses join to their nearest
common superclass. &lt;code&gt;===&lt;/code&gt; compares an instance of a class with one of its sub- or superclasses.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;exporting-members&quot;&gt;Exporting members&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Stack[T](private var items: Vector[T]): Sized
  export items.{length as size, isEmpty, map}
  push(x: T) = items = items :+ x

class Logged(inner: Account)
  export inner.*
  describe() -&amp;gt; string = &amp;quot;logged &amp;quot; + inner.describe()

val s = Stack([1, 2])
s.size // 2: `s.items.length`
s.map(x -&amp;gt; x * 10) // Vector(10, 20)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;export f.m&lt;/code&gt; in a type’s body presents a member of what &lt;code&gt;f&lt;/code&gt; holds as the type’s own.&lt;/strong&gt; A use of
&lt;code&gt;m&lt;/code&gt; on a value &lt;code&gt;x&lt;/code&gt; of the type is the use of &lt;code&gt;x.f.m&lt;/code&gt;: a call &lt;code&gt;x.m(args)&lt;/code&gt; is &lt;code&gt;x.f.m(args)&lt;/code&gt;, with
every overload of &lt;code&gt;m&lt;/code&gt;, its defaults, named arguments, repeated parameters and type arguments, and
&lt;code&gt;f&lt;/code&gt;‘s type arguments in place (&lt;code&gt;items&lt;/code&gt; above is a &lt;code&gt;Vector[T]&lt;/code&gt;, so &lt;code&gt;s.map&lt;/code&gt; on a &lt;code&gt;Stack[int]&lt;/code&gt; maps
&lt;code&gt;int&lt;/code&gt;s). A read &lt;code&gt;x.m&lt;/code&gt; reads the field &lt;code&gt;m&lt;/code&gt; or calls the method of no parameter list; &lt;code&gt;x.m = v&lt;/code&gt; and
&lt;code&gt;x.m += v&lt;/code&gt; assign a &lt;code&gt;var&lt;/code&gt; field &lt;code&gt;m&lt;/code&gt;; &lt;code&gt;x.m&lt;/code&gt; naming a method with parameters is its function value,
bound to &lt;code&gt;x.f&lt;/code&gt; as read then; and an operator method is exported by its spelling, &lt;code&gt;export n.+&lt;/code&gt; or
&lt;code&gt;export n.&amp;lt;&lt;/code&gt;, so &lt;code&gt;a + b&lt;/code&gt; is &lt;code&gt;a.n + b&lt;/code&gt;. The export is written as an import is: one member, a &lt;code&gt;{…}&lt;/code&gt;
group, &lt;code&gt;as&lt;/code&gt; presenting one under another name, and &lt;code&gt;export f.*&lt;/code&gt; for every public member of what
&lt;code&gt;f&lt;/code&gt; holds that the type does not have itself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;f&lt;/code&gt; is a field or a method of no parameter list&lt;/strong&gt;, read again at every use: a &lt;code&gt;var&lt;/code&gt; field
reassigned between two calls sends each to the value it holds then, and a method &lt;code&gt;f&lt;/code&gt; runs at each
use. It is the type’s own or inherited, of any privacy its code may read, so a private field is
the usual one: the export presents what it holds without presenting it. Its type is declared, as a
class parameter’s is: the members it presents are the type’s surface, known before any body is
checked. A class, an object and a data type export members; a data type writes its exports in a
plain &lt;code&gt;impl&lt;/code&gt; of it in its own module, and &lt;code&gt;f&lt;/code&gt; is a field of its one variant or a method of no
parameter list its impls declare.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An export presents public members only&lt;/strong&gt;: a field, a method that is not static, a trait’s
&lt;code&gt;val&lt;/code&gt;, or a member &lt;code&gt;f&lt;/code&gt;‘s type exports in turn, so exports chain. A private member is never
presented, by name or by &lt;code&gt;*&lt;/code&gt;, and neither is &lt;code&gt;equals&lt;/code&gt; or &lt;code&gt;hash&lt;/code&gt;, which every value has of its own.
Exports by name that lead round to one another without reaching a member are an error at each of
them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The type’s own members come first.&lt;/strong&gt; A use is forwarded only where the type, its superclasses,
its traits and its impls have no member of the name: &lt;code&gt;Logged&lt;/code&gt; above keeps its own &lt;code&gt;describe&lt;/code&gt;
beside &lt;code&gt;export inner.*&lt;/code&gt;. An export by name of a member the type has itself, or inherits from a
superclass, is an error, and so is a member a subclass declares under a name its superclass
exports by name. Two exports of one type presenting one name by name are an error naming both;
an export by name comes before a wildcard, and two wildcards both reaching a name make a use of it
an error naming both, which naming it in one export settles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A public export by name implements a trait’s method of its name&lt;/strong&gt; that the class does not
declare: the class has a method with the trait’s signature whose body is &lt;code&gt;self.f.m(params)&lt;/code&gt;,
standing where an &lt;code&gt;override&lt;/code&gt; would, so a call through the trait and a call through the class reach
the same member. &lt;code&gt;class Stack[T](…): Sized&lt;/code&gt; above meets &lt;code&gt;Sized&lt;/code&gt;‘s &lt;code&gt;size -&amp;gt; int&lt;/code&gt; this way. A
wildcard implements nothing; nor does a private export, which is an error where it names a trait’s
method, nor a method with type parameters of its own, nor an export of a data type, whose trait
impls write their methods. A member that does not fit the trait’s method is one error at the
export, naming the export, both signatures and the mismatch: “&lt;code&gt;t.size&lt;/code&gt; (&lt;code&gt;Text.size -&amp;gt; string&lt;/code&gt;),
exported as &lt;code&gt;size&lt;/code&gt;, implements &lt;code&gt;Sized.size -&amp;gt; int&lt;/code&gt; but yields string, not int”; a member that
does not take the method’s parameters, or is a field where the method takes some, is told the
same way, and a generic member is judged by what it yields at the method’s arguments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;private export&lt;/code&gt; presents the members to the type’s own code alone&lt;/strong&gt;, as a private method is;
elsewhere a use of one is an error saying so.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An export is reached through a value&lt;/strong&gt;, &lt;code&gt;x.m&lt;/code&gt; and &lt;code&gt;self.m&lt;/code&gt;. Inside the type a bare &lt;code&gt;m&lt;/code&gt; is not
the export, so a wildcard never hides a top-level declaration from the type’s own code: there the
field itself is in scope, &lt;code&gt;items.length&lt;/code&gt;. An export is not static, and &lt;code&gt;Type.m&lt;/code&gt; does not reach one.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;export&lt;/code&gt; begins an export only at the start of a line of a type’s body and before a name and a
dot; everywhere else it is an ordinary name. An editor completes the presented names after a dot,
and a use, or the name on the export line, leads to the member’s declaration.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;trait&quot;&gt;trait&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Shape
  area() -&amp;gt; real
  describe() -&amp;gt; string = s&amp;quot;area ${area()}&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A trait declares methods, which may have default bodies, abstract &lt;code&gt;val&lt;/code&gt; members a class supplies
with a field, and fields with values, which every class conforming to it stores (below). A trait may
require others: &lt;code&gt;trait Iterator[+A]: Iterable[A]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A trait is both a type and a bound. Used as a type, a value of it is a reference and calls dispatch
dynamically. Used as a bound (&lt;code&gt;[T: Shape]&lt;/code&gt;), calls are direct, because the code is monomorphized.
A trait whose methods mention &lt;code&gt;Self&lt;/code&gt; other than as the receiver (&lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt;) can only be used
as a bound.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Self&lt;/code&gt; in a trait’s methods is the type implementing the trait.&lt;/strong&gt; A method &lt;code&gt;less(other: Self)&lt;/code&gt;
is implemented by &lt;code&gt;Money&lt;/code&gt; as &lt;code&gt;less(other: Money)&lt;/code&gt;; a call substitutes the receiver’s type, so
through &lt;code&gt;[T: Ordered]&lt;/code&gt; it takes a &lt;code&gt;T&lt;/code&gt;. &lt;code&gt;Self&lt;/code&gt; is written only in a trait’s methods.&lt;/li&gt;
&lt;li&gt;A trait mentions &lt;code&gt;Self&lt;/code&gt; when its methods or &lt;code&gt;val&lt;/code&gt;s do, or a trait it requires does. Naming it as a
type (a parameter, a field, a type pattern) is an error; it is named as a bound, after a class’s
&lt;code&gt;:&lt;/code&gt; and in an impl’s header.&lt;/li&gt;
&lt;li&gt;Inside such a trait’s default bodies &lt;code&gt;self&lt;/code&gt; is a &lt;code&gt;Self&lt;/code&gt;, so it passes where a parameter takes one:
&lt;code&gt;greater(other: Self) -&amp;gt; bool = other.less(self)&lt;/code&gt;. The body is shared by every conforming type,
and its calls on &lt;code&gt;Self&lt;/code&gt; values go through their method tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When a class inherits two implementations of one member, from its superclass or from traits, it must
override that member. There is no trait linearization.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Named
  label() -&amp;gt; string

trait Tagged: Named
  tag() -&amp;gt; string = s&amp;quot;&amp;lt;${label()}&amp;gt;&amp;quot;

class Item(text: string): Tagged
  override label() -&amp;gt; string = text

val t: Tagged = Item(&amp;quot;x&amp;quot;)
val n: Named = t
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;A class conforms to the traits after its superclass in the &lt;code&gt;:&lt;/code&gt; list, and to every trait those
require; a subclass conforms to its superclass’s traits. A trait is named there with its type
arguments and without constructor arguments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implementing a trait’s method is overriding it&lt;/strong&gt;: the class’s method is marked &lt;code&gt;override&lt;/code&gt;,
whether the trait’s method is abstract or has a default body, and takes its parameter types and
its result or a type conforming to it. A method the class inherits from its superclass implements
a trait’s method of the same name without being repeated.&lt;/li&gt;
&lt;li&gt;A trait’s default body is inherited like a superclass’s method. A class that is not abstract
implements every abstract method of its traits; an abstract class may leave them to a subclass.&lt;/li&gt;
&lt;li&gt;A trait’s body declares methods and fields, all public, and no statements: it has no constructor.
A trait cannot be instantiated.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait may override a method of a trait it requires&lt;/strong&gt;, marked &lt;code&gt;override&lt;/code&gt; and with a body:
&lt;code&gt;trait Square: Shape&lt;/code&gt; with &lt;code&gt;override describe() -&amp;gt; string = …&lt;/code&gt;. In every class and data type
conforming to the trait, its body replaces the required trait’s default, or gives an abstract
method one, so a call through either trait’s type reaches it. Like a class’s override, it takes
the defaults of the method it overrides. Declaring a required trait’s method
again without &lt;code&gt;override&lt;/code&gt; is an error. Two traits overriding one default differently are two
implementations, which a class conforming to both overrides.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait’s override may have no body&lt;/strong&gt;, re-declaring the method with a narrower result:
&lt;code&gt;trait SortedMap[K, +V]: Map[K, V]&lt;/code&gt; with &lt;code&gt;override updated[W &amp;gt;: V](key: K, value: W) -&amp;gt; SortedMap[K, W]&lt;/code&gt;, so &lt;code&gt;sorted.updated(k, v).headOption&lt;/code&gt; type-checks through the sub-trait. It takes
the overridden method’s parameters, type parameters and lower bounds, and yields its result or,
where that is a class or trait, one conforming to it; its result is checked against the trait’s
variance. It shares the overridden method’s position, so a type conforming to the sub-trait has one
implementation, reached through either trait, and that implementation yields the narrowest
result. A re-declaration without a body of a method that has a default makes it abstract again:
the default is not inherited, and each implementer of the sub-trait gives its own (or a trait
further down gives a body again). A method a class inherits from its superclass implements the
re-declaration only if it yields the narrower result.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait’s method may have type parameters of its own&lt;/strong&gt;, as &lt;code&gt;map[B](f: (A) -&amp;gt; B) -&amp;gt; Iterable[B]&lt;/code&gt;.
Its implementations declare as many, matched by position. A call through the trait’s type
reaches the implementation of the object’s class at the call’s type arguments: the whole program
is compiled at once, so every type argument list a call through the trait uses is known, and each
has its own method table slot.&lt;/li&gt;
&lt;li&gt;A class conforms to a trait once: &lt;code&gt;Source[int]&lt;/code&gt; and &lt;code&gt;Source[string]&lt;/code&gt; on one class, written or
reached through other traits, is an error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A conforming instance is an instance of the trait&lt;/strong&gt;: it passes wherever the trait, or a trait
the trait requires, is expected, with no conversion, and &lt;code&gt;===&lt;/code&gt; compares it with values of those
types. Branches of an &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; yielding two classes with no common superclass agree on the
expected type when both conform to it.&lt;/li&gt;
&lt;li&gt;Inside a default body, &lt;code&gt;self&lt;/code&gt; has the trait’s type, so its calls dispatch as any trait-typed
call does.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Named
  val name: string
  greet() -&amp;gt; string = s&amp;quot;hello, $name&amp;quot;

class Person(val name: string, age: int): Named
class Counter(var name: string): Named
data Book(name: string, pages: int)
impl Named for Book
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An abstract &lt;code&gt;val&lt;/code&gt;&lt;/strong&gt; is written &lt;code&gt;val name: T&lt;/code&gt; with no value, and only a trait declares one. A
trait’s &lt;code&gt;val&lt;/code&gt; is public, is never &lt;code&gt;var&lt;/code&gt;, and shares its name with no other member of the trait.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A conforming type supplies it with a public field of that name&lt;/strong&gt;: a class parameter marked &lt;code&gt;val&lt;/code&gt;
or &lt;code&gt;var&lt;/code&gt;, a &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; of the class body, a field inherited from the superclass, or, through an
impl, a field of a &lt;code&gt;data&lt;/code&gt; type with one variant. The field’s type is the &lt;code&gt;val&lt;/code&gt;‘s or, where that is a
class or a trait, one conforming to it. A &lt;code&gt;var&lt;/code&gt; field supplies a &lt;code&gt;val&lt;/code&gt;: the class assigns it, and a
read through the trait sees the current value. A method does not supply a &lt;code&gt;val&lt;/code&gt;, and neither does a
private field. A class that is not abstract supplies every &lt;code&gt;val&lt;/code&gt; of its traits; an abstract class
may leave one to a subclass.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is read with field syntax&lt;/strong&gt;, &lt;code&gt;x.name&lt;/code&gt;, and by bare name inside the trait’s default bodies.
Read through a class type it is the field itself; read through the trait it reaches the field of
the value’s own type through its method table. It is never assigned through the trait, and
&lt;code&gt;x.name()&lt;/code&gt; calls the value it holds, which only a function-typed &lt;code&gt;val&lt;/code&gt; can be.&lt;/li&gt;
&lt;li&gt;An abstract class’s body cannot read a trait’s &lt;code&gt;val&lt;/code&gt; it leaves to a subclass: it runs before the
subclass’s fields are set.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;fields&quot;&gt;Fields&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Position(line: int, column: int)

trait Positional
    var pos: Option[Position] = None
    at(line: int, column: int) = pos = Some(Position(line, column))

class Token(val text: string): Positional

val t = Token(&amp;quot;x&amp;quot;)
t.at(3, 4)
val p: Positional = t
p.pos = None
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A trait may declare fields with values&lt;/strong&gt;, &lt;code&gt;val name: T = expr&lt;/code&gt; and &lt;code&gt;var name: T = expr&lt;/code&gt;. Each
declares its type, and is public. A field without a value is the abstract &lt;code&gt;val&lt;/code&gt; above, and is
never &lt;code&gt;var&lt;/code&gt;. A conforming type supplies an abstract &lt;code&gt;val&lt;/code&gt; only with a field; an abstract
&lt;a href=&quot;#parameterless-methods&quot;&gt;parameterless method&lt;/a&gt;, &lt;code&gt;size -&amp;gt; int&lt;/code&gt;, is implemented by a method or by a
public field.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every class and object conforming to the trait stores the trait’s fields&lt;/strong&gt;, each of its own. A
subclass of a class that conforms stores them once, in the superclass; a generic trait’s fields
take the type arguments the class names it with, &lt;code&gt;class Ints: Box[int]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;They are read and assigned as fields&lt;/strong&gt;: by bare name and through &lt;code&gt;self&lt;/code&gt; in the trait’s methods,
and as &lt;code&gt;x.name&lt;/code&gt; outside. Through a class type, &lt;code&gt;x.name&lt;/code&gt; is the class’s field; through the trait,
or a type parameter the trait bounds, it reaches the field of the object’s own class through its
method table, for reading and, for a &lt;code&gt;var&lt;/code&gt;, for assigning. A trait’s field supplies the abstract
&lt;code&gt;val&lt;/code&gt; of its name of any other trait the class conforms to.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Construction runs from the top down&lt;/strong&gt;: the superclass’s constructor, then the class’s
parameters are stored, then the fields of the traits the superclass does not already conform to
are computed, then the class body runs. The traits come in the order of the &lt;code&gt;:&lt;/code&gt; list, each after
the traits it requires and each once, and each trait’s fields in the order it declares them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field’s value is computed with &lt;code&gt;self&lt;/code&gt; as the trait’s receiver&lt;/strong&gt;, in the trait’s module. It may
read the fields initialized before it: those of a superclass, the class’s parameters (as the
trait’s &lt;code&gt;val&lt;/code&gt;s they supply), and the trait fields computed earlier. It uses &lt;code&gt;self&lt;/code&gt; for nothing
else: it calls no method of the object and does not pass it, as a class body before its last field
does not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only a class or an object conforms to a trait with fields&lt;/strong&gt;, or to one requiring such a trait: an
impl of it for a &lt;code&gt;data&lt;/code&gt; type, a built-in type or a tuple is an error. A trait’s field is never
overridden: a class declaring a field or a method of its name is an error, and so is a class
conforming to two traits that declare fields of one name.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;var&lt;/code&gt; field makes it an invariant position: a covariant trait’s type parameter cannot appear in
its type, as in a class’s.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;static-members&quot;&gt;Static members&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;trait Add
  add(other: Self) -&amp;gt; Self
  static zero() -&amp;gt; Self

impl Add for Point
  add(other: Point) -&amp;gt; Point = Point(x + other.x, y + other.y)
  static zero() -&amp;gt; Point = Point(0, 0)

total[T: Add](a: T, b: T) -&amp;gt; T = T.zero() + a + b

val origin = Point.zero()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A trait may declare &lt;strong&gt;&lt;code&gt;static&lt;/code&gt; members&lt;/strong&gt;, which belong to the implementing type rather than to a
value: &lt;code&gt;Add&lt;/code&gt;‘s &lt;code&gt;zero&lt;/code&gt; and &lt;code&gt;Mul&lt;/code&gt;‘s &lt;code&gt;one&lt;/code&gt; are the identities of their operators.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A static member is called on a type&lt;/strong&gt;: a type’s name (&lt;code&gt;int.zero()&lt;/code&gt;, &lt;code&gt;Point.zero()&lt;/code&gt;,
&lt;code&gt;Pair[int, string].zero()&lt;/code&gt;) or a type parameter whose bounds have it (&lt;code&gt;T.zero()&lt;/code&gt; with &lt;code&gt;T: Add&lt;/code&gt;).
Through a bound each instance calls its type argument’s own directly, an open class’s included,
since no object is involved. Calling one on a value is an error, and so is calling a value’s method
on a type. A local, a parameter, a member or a module value of the name hides the type; a built-in
type’s name &lt;a href=&quot;/spec/operators-and-control-flow/#match&quot;&gt;names no value&lt;/a&gt;, so its type is never hidden. A
companion object does not: &lt;code&gt;BigInt.zero()&lt;/code&gt; calls the type’s static member beside
&lt;code&gt;object BigInt&lt;/code&gt;‘s &lt;code&gt;apply&lt;/code&gt;, unless the companion declares a member of that name itself, which
&lt;code&gt;Name.member&lt;/code&gt; then means.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The name of a data type whose variant of its own name has no fields is also a value&lt;/strong&gt;, so
&lt;code&gt;Lone.hi()&lt;/code&gt; of &lt;code&gt;data Lone()&lt;/code&gt; calls the method &lt;code&gt;hi&lt;/code&gt; of that value, as &lt;code&gt;val l = Lone; l.hi()&lt;/code&gt; does,
and &lt;code&gt;Lone.hi&lt;/code&gt; without a call is a function value bound to it. Where the type has a static member
of the name, &lt;code&gt;Lone.unit()&lt;/code&gt;, the name is the type’s and calls the static member; a value’s method
of that name is then called on a value.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In a trait a static member has no body&lt;/strong&gt;: a trait’s default bodies are shared by every
conforming type, and a static member is each type’s own. &lt;code&gt;Self&lt;/code&gt; in its signature is the
implementing type, as in a method’s. A trait never overrides a static member, and its default
bodies cannot call one on &lt;code&gt;Self&lt;/code&gt;, which there is no one type; a
&lt;a href=&quot;/spec/generics/#constructor-traits&quot;&gt;constructor trait&lt;/a&gt;‘s defaults, compiled for each implementing
constructor, can.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every implementation gives it, with a body&lt;/strong&gt;, marked &lt;code&gt;static&lt;/code&gt; as the trait’s member is: an impl,
and a class’s body with &lt;code&gt;override static&lt;/code&gt;. An abstract class gives it too, since it belongs to the
type and not to a subclass’s objects. A static member is static exactly where the trait’s member
is, and is a trait’s member, an implementation of one, or a
&lt;a href=&quot;#static-members-of-built-in-types&quot;&gt;built-in type’s own&lt;/a&gt;. A class or &lt;code&gt;data&lt;/code&gt; type keeps what belongs
to the type in its companion object.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A static member’s body has no &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt;: neither &lt;code&gt;self&lt;/code&gt; nor the members of a value by bare name.
It may have parameters, defaults and type parameters as a method does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait with a static member is a bound and not a type&lt;/strong&gt;, as one mentioning &lt;code&gt;Self&lt;/code&gt; is: a value of
the trait’s type would have no type to give the member.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait has no static members of its own&lt;/strong&gt;, except those of an impl stating its own conformance
to a trait whose members are all static (&lt;a href=&quot;#impl&quot;&gt;impl&lt;/a&gt;): &lt;code&gt;Set[int].newBuilder()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A static member named without a call is a function value&lt;/strong&gt; of its parameters, as a method of a
value is: &lt;code&gt;xs.map(string.fromUtf8Lossy)&lt;/code&gt;, &lt;code&gt;val zero = Point.zero&lt;/code&gt;. Where the member is overloaded,
the function type expected says which, and without one the value is an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;static-members-of-built-in-types&quot;&gt;Static members of built-in types&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;impl string
  static fromUtf8(bytes: Array[byte]) -&amp;gt; Result[string, Utf8Error] = …
  static fromUtf8Lossy(bytes: Array[byte]) -&amp;gt; string = …

impl int
  static parity(n: int) -&amp;gt; string = if n % 2 == 0 then &amp;quot;even&amp;quot; else &amp;quot;odd&amp;quot;

val text = string.fromUtf8Lossy(bytes)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A built-in type has no companion object, since it cannot be declared, so what belongs to the type
itself is declared as a &lt;strong&gt;&lt;code&gt;static&lt;/code&gt; member in an impl of the type without a trait&lt;/strong&gt;: &lt;code&gt;string&lt;/code&gt;,
&lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt; and each integer type. The core library declares the built-in types’
own (&lt;code&gt;string.fromUtf8&lt;/code&gt;); a program adds one as it adds a method, in an &lt;a href=&quot;#extensions&quot;&gt;extension&lt;/a&gt;, seen
where its module is imported. Settled by the user 2026-11-04.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It is called on the type’s name&lt;/strong&gt;, &lt;code&gt;string.fromUtf8(bytes)&lt;/code&gt;, and is a value without a call, as
any static member is; calling it on a value is an error, and so is calling a value’s method on the
type. Its body has no &lt;code&gt;self&lt;/code&gt;, and calls the type’s other static members on the type,
&lt;code&gt;string.other()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A name is a static member or a method of the type’s values, not both&lt;/strong&gt;, so &lt;code&gt;string.name&lt;/code&gt; and
&lt;code&gt;s.name&lt;/code&gt; never mean two different functions. Static members of one name overload one another by
parameter types, as methods do.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What the language gives a built-in type cannot be redeclared&lt;/strong&gt;: &lt;code&gt;wrap&lt;/code&gt; on every built-in type,
which &lt;code&gt;i8.wrap(x)&lt;/code&gt; reads, and the limits of the numeric types and &lt;code&gt;char&lt;/code&gt; (&lt;code&gt;MaxValue&lt;/code&gt;, &lt;code&gt;MinValue&lt;/code&gt;,
and &lt;code&gt;real&lt;/code&gt;‘s &lt;code&gt;MinPositiveValue&lt;/code&gt;, &lt;code&gt;PositiveInfinity&lt;/code&gt;, &lt;code&gt;NegativeInfinity&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;An extension’s static member with the parameter types of one the type has is an error where it is
declared, as an extension’s method is; a &lt;code&gt;private&lt;/code&gt; one is its module’s.&lt;/li&gt;
&lt;li&gt;A generic impl, an impl adding to a trait and an impl of a class or &lt;code&gt;data&lt;/code&gt; type declare no static
member of their own.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;impl&quot;&gt;impl&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;impl Trait for Type&lt;/code&gt; makes an existing type conform to a trait after the fact, including the
built-in types:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;impl Display for Shape
  display(out: Writer, spec: FormatSpec) = …

impl Shape
  perimeter() -&amp;gt; real = …
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;impl Type&lt;/code&gt; without a trait adds methods to a type, and may be written in any module: in the type’s
own module its methods are the type’s, and in another module the impl is an &lt;strong&gt;extension&lt;/strong&gt;, whose
methods are seen where that module is imported (below). A conformance, &lt;code&gt;impl Trait for Type&lt;/code&gt;, lives in
the module of the trait or of the type, so a type has one answer to it everywhere; the built-in types
belong to the core library’s module, &lt;code&gt;avin&lt;/code&gt;. Declaring a trait in a class’s header and writing a
separate &lt;code&gt;impl&lt;/code&gt; for it are the same conformance; it may be stated once.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;impl&lt;/code&gt; is how Avin expresses type classes (&lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt;) and adds methods to types you
do not own. Resolution is coherent: one implementation per trait and type, found without search.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A generic trait whose members are all static, and which requires no other trait, may be
implemented by one type at several type arguments&lt;/strong&gt;, once at each: &lt;code&gt;impl From[IoError] for AppError&lt;/code&gt; beside &lt;code&gt;impl From[ParseError] for AppError&lt;/code&gt;, or &lt;code&gt;class Note : Make[int], Make[string]&lt;/code&gt;.
No value of such a trait exists, so each call names a type, and the member called is the one taking
the arguments’ types: &lt;code&gt;AppError.from(e)&lt;/code&gt; as any overloaded method, and on a type parameter bounded
by several instances, &lt;code&gt;T: Make[int] &amp;amp; Make[string]&lt;/code&gt;, the instance whose member the arguments fit.
Each conformance gives every member of the trait at its own type arguments. Any other trait is
implemented once, at one list of type arguments.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A trait type may implement a trait whose members are all static&lt;/strong&gt; (with those of the traits it
requires), as its &lt;strong&gt;own&lt;/strong&gt; conformance: &lt;code&gt;impl[A] Buildable[A] for Set[A]&lt;/code&gt;, with &lt;code&gt;static newBuilder() -&amp;gt; Builder[A, Set[A]]&lt;/code&gt;. It holds of the trait type itself, where &lt;code&gt;Set[A]&lt;/code&gt; is the type
a call names (&lt;code&gt;Set[int].newBuilder()&lt;/code&gt;) or a bound’s argument (&lt;code&gt;build[Set[int], int](…)&lt;/code&gt;), and of no
type implementing the trait: a &lt;code&gt;HashSet[A]&lt;/code&gt; does not get &lt;code&gt;Set&lt;/code&gt;‘s impl, but has its own or none, and
a type parameter bounded by &lt;code&gt;Set[A]&lt;/code&gt; does not reach it, since its argument may be any set. It lives
in the module of the trait type or of the static trait, as any conformance does. An impl of a trait
with a member of a value for a trait type is an error: every value of the trait type is of some
implementing type, whose methods the trait’s are. A conformance to such a trait is also no
&lt;a href=&quot;/spec/generics/#variance&quot;&gt;variance&lt;/a&gt; position of a class or &lt;code&gt;data&lt;/code&gt; type.&lt;/p&gt;
&lt;p&gt;A built-in type conforms to a trait only through an impl, and meets the trait as a bound: each
instance of generic code calls the impl’s method directly. A built-in value is not an object, so a
trait’s default bodies, which every conforming object shares, do not reach it: an impl for a
built-in type implements every method of the trait, defaults included.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An impl adds methods, never state.&lt;/strong&gt; Its body declares methods only: no fields and no
statements. A method an impl in a class’s or an object’s module adds to it is one of its methods,
as if the class’s body declared it: it sees the private fields, is inherited by a subclass, and a
subclass may override it. A method with the name and parameter types of one the type already has
is an error; one with other parameter types overloads it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inside an impl’s methods the receiver is implicit&lt;/strong&gt;, as in a class: &lt;code&gt;self&lt;/code&gt; is the value, the
type’s methods are in scope by bare name, and so are the fields of a &lt;code&gt;data&lt;/code&gt; type with one variant,
the fields &lt;code&gt;self.name&lt;/code&gt; reaches. A type with several variants takes &lt;code&gt;self&lt;/code&gt; apart with &lt;code&gt;match&lt;/code&gt;.
A &lt;code&gt;private&lt;/code&gt; method of an impl is callable only from the methods of that type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The methods of &lt;code&gt;impl Trait for Type&lt;/code&gt; implement the trait’s methods&lt;/strong&gt;, so they are not marked
&lt;code&gt;override&lt;/code&gt;, and each must be a method of the trait or of a trait it requires. A default body the
impl leaves alone stays, and every abstract method must be implemented. One method of a name and
parameter types implements every trait method of that name and parameter types the type conforms
to, as a class’s does; a &lt;code&gt;data&lt;/code&gt;
type’s method implementing a trait’s method is declared in an impl of that trait. An impl of a
trait with no body states a conformance the type’s methods already satisfy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;data&lt;/code&gt; value of a type that conforms to a trait is a value of the trait’s type.&lt;/strong&gt; Its calls
through the trait dispatch as a class instance’s do, a variant without fields included; a call on
the data type itself is direct.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A generic impl names the type’s parameters&lt;/strong&gt;, in order: &lt;code&gt;impl[T] Show for Box[T]&lt;/code&gt;,
&lt;code&gt;impl[K, V] Map[K, V]&lt;/code&gt;. The names are the impl’s own and need not be the declaration’s. An impl
of a trait always does: a conformance holds for every instance of a type, so an impl of a trait
for particular type arguments (&lt;code&gt;impl Show for Box[int]&lt;/code&gt;) or for a type built from its parameters
(&lt;code&gt;impl[T] Show for Box[List[T]]&lt;/code&gt;) is an error, and no two conformances of one type can overlap.
An impl of a &lt;a href=&quot;/spec/generics/#implementing-a-constructor-trait&quot;&gt;constructor trait&lt;/a&gt; names them too,
and gives the trait the ones it leaves open (&lt;code&gt;impl[T, E] Monad[T] for Result[T, E]&lt;/code&gt;), or leaves
both off where they are all open, in order (&lt;code&gt;impl Monad for Option&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl without &lt;code&gt;for&lt;/code&gt; may add methods to any type built from its parameters&lt;/strong&gt;:
&lt;code&gt;impl[T] Option[Option[T]]&lt;/code&gt;, &lt;code&gt;impl[A, B] Pair[A, List[B]]&lt;/code&gt;, and, adding to a trait,
&lt;code&gt;impl[T] Seq[Seq[T]]&lt;/code&gt; and &lt;code&gt;impl[K, V] Iterable[(K, V)]&lt;/code&gt;. Each of its parameters is part of that
type, so a call learns them from the receiver; one that is not is an error. The type is matched
against the receiver’s static type: &lt;code&gt;Option[Option[int]]&lt;/code&gt; matches &lt;code&gt;Option[Option[T]]&lt;/code&gt; with &lt;code&gt;T&lt;/code&gt; as
&lt;code&gt;int&lt;/code&gt;, and &lt;code&gt;flatten&lt;/code&gt; on an &lt;code&gt;Option[int]&lt;/code&gt; is an error saying what the receiver would need to be
(“&lt;code&gt;flatten&lt;/code&gt; is for an &lt;code&gt;Option&lt;/code&gt; of an &lt;code&gt;Option&lt;/code&gt;; this is &lt;code&gt;Option[int]&lt;/code&gt;“). Where a part of the type is
covariant, a reference matches through its traits and superclasses, as it would be passed:
a &lt;code&gt;Vector[List[int]]&lt;/code&gt; is a &lt;code&gt;Seq[Seq[int]]&lt;/code&gt;, with &lt;code&gt;T&lt;/code&gt; as &lt;code&gt;int&lt;/code&gt;. Elsewhere a part matches only its
own type, and a parameter written twice (&lt;code&gt;impl[T] Pair[T, T]&lt;/code&gt;, &lt;code&gt;impl[T, E] Result[Result[T, E], E]&lt;/code&gt;) takes one type. The impl’s bounds apply as for any impl: with &lt;code&gt;impl[A: Ord, B] Seq[(A, B)]&lt;/code&gt;,
a sequence of pairs whose first parts are not ordered lacks its methods. Inside the methods &lt;code&gt;self&lt;/code&gt;
has the type the impl names (or, adding to a trait, is a &lt;code&gt;Self&lt;/code&gt; of it), and the methods are
called directly, as other added methods are.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two impls whose types both match a receiver&lt;/strong&gt; and that add a method of one name and parameter
types make a call of it an error, as two traits’ added methods do; so does a method of the type’s
own with the name and parameter types of one an impl adds to a type built from its parameters.
Impls whose types no receiver matches both, as &lt;code&gt;Box[List[T]]&lt;/code&gt; and &lt;code&gt;Box[Option[T]]&lt;/code&gt;, may add
methods of one name and parameter types, and the receiver says which is called.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl may bound the type’s parameters further&lt;/strong&gt; (&lt;code&gt;impl[T: Display] List[T]&lt;/code&gt;,
&lt;code&gt;impl[T: Ord] Ord for Box[T]&lt;/code&gt;), and then holds only for the type arguments that meet the bounds:
the trait’s conformance, or the methods it adds. Calling one of those methods on an instance that
misses a bound is an error naming the bound. &lt;a href=&quot;/spec/generics/&quot;&gt;Generics&lt;/a&gt; has the rules.&lt;/li&gt;
&lt;li&gt;A method added to a built-in type (&lt;code&gt;impl string&lt;/code&gt;, &lt;code&gt;impl int&lt;/code&gt;) is called on a value of that type,
&lt;code&gt;&amp;quot;hi&amp;quot;.shout()&lt;/code&gt;, &lt;code&gt;7.squared()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl without &lt;code&gt;for&lt;/code&gt; may add methods to tuples and to functions&lt;/strong&gt;, naming a tuple or a function
type built from its parameters: &lt;code&gt;impl[A, B] (A, B)&lt;/code&gt; adds to every pair, &lt;code&gt;impl[A] (A, A)&lt;/code&gt; to the
pairs whose parts are of one type, &lt;code&gt;impl[A, B] (A) -&amp;gt; B&lt;/code&gt; to every function of one parameter. The
tuple and function types are the core library’s, so such an impl elsewhere is an extension. The
receiver matches as for any type built from parameters, and a call on a tuple or a function of
another shape says what it would need to be (“&lt;code&gt;swap&lt;/code&gt; is for a pair; this is &lt;code&gt;(int, int, int)&lt;/code&gt;“).
A function type is a trait, so its methods reach a value of a type naming that function type, a
sequence or a map among them, and the type’s own method of the same name and parameter types is
found first; a &lt;code&gt;@sendable&lt;/code&gt; function type adds only to &lt;code&gt;@sendable&lt;/code&gt; functions. Neither form has
static members, and a tuple’s operators stay the language’s. An impl of a trait is never for a
function type, and one for tuples is the core library’s alone. The impl has at least one type
parameter, since &lt;code&gt;impl (&lt;/code&gt;… with none begins a function named &lt;code&gt;impl&lt;/code&gt;; a part may still be written
out, as &lt;code&gt;impl[A] (A, int)&lt;/code&gt; adds to the pairs whose second part is an &lt;code&gt;int&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An impl without &lt;code&gt;for&lt;/code&gt; whose type is a trait adds methods to the trait&lt;/strong&gt; (&lt;code&gt;impl[T] Seq[T]&lt;/code&gt;,
&lt;code&gt;impl[T: Display] Seq[T]&lt;/code&gt;). Every value whose type conforms to the trait has
them: a class or &lt;code&gt;data&lt;/code&gt; type implementing it, the trait’s own type, a type parameter it bounds.
Inside them &lt;code&gt;self&lt;/code&gt; is the value and &lt;code&gt;Self&lt;/code&gt; its type; the trait’s methods, and those other impls add
to it, are in scope by bare name. They reach the value only through the trait’s methods, so they
are not variance positions: &lt;code&gt;contains(element: T)&lt;/code&gt; is written on &lt;code&gt;Seq[+T]&lt;/code&gt;. The methods an impl
adds to an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class are, by contrast, in the class’s method table, and so are
variance positions like the class’s own (&lt;a href=&quot;/spec/generics/&quot;&gt;generics&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call of an added method is compiled for the receiver’s static type.&lt;/strong&gt; Where that is a class or
a &lt;code&gt;data&lt;/code&gt; type, the trait’s methods the added one calls are that type’s, called directly; where it
is the trait, they go through the object’s method table. An added method is in no method table and
nothing overrides it; it may not take the name of a method the trait declares.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A type’s own methods are found before those added to its traits.&lt;/strong&gt; An added method with the name
and parameter types of a method the receiver’s type has (its own, an inherited one, or one of a trait
it conforms to) is passed over, so a type keeps a faster version of its own wherever its static type
is known; code that sees only the trait calls the added one. An added method with other parameter
types overloads the type’s. Where impls add a method of one name and parameter types to two traits
a type conforms to, the one added to the nearer trait is the type’s when that trait requires the
other: &lt;code&gt;impl[T] Seq[T]&lt;/code&gt;‘s &lt;code&gt;map&lt;/code&gt; hides &lt;code&gt;impl[T] Iterable[T]&lt;/code&gt;‘s on every sequence. Where neither
trait requires the other, a call of it on that type is an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;impl[T] Seq[T]
  contains(element: T) -&amp;gt; bool = exists(x -&amp;gt; x.equals(element))

present[T](xs: Seq[T], x: T) -&amp;gt; bool = xs.contains(x)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;extensions&quot;&gt;Extensions&lt;/h3&gt;
&lt;p&gt;An impl without &lt;code&gt;for&lt;/code&gt; written outside the module of the type or trait it adds to is an
&lt;strong&gt;extension&lt;/strong&gt;. Every form above may be one: &lt;code&gt;impl string&lt;/code&gt;, &lt;code&gt;impl[T: Ord] Seq[T]&lt;/code&gt;,
&lt;code&gt;impl[T] Option[Option[T]]&lt;/code&gt;, &lt;code&gt;impl Box&lt;/code&gt; for a class another module declares.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;// words/words.avin
module words

impl string
  shout() -&amp;gt; string = s&amp;quot;${self}!&amp;quot;

impl[T: Ord] Seq[T]
  median() -&amp;gt; T = sorted().apply(length / 2)

// main.avin
import words

main() = println(&amp;quot;hey&amp;quot;.shout()) // hey!
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An extension’s methods are seen by its own module and by every file that imports the module&lt;/strong&gt;:
whole (&lt;code&gt;import a.b&lt;/code&gt;, &lt;code&gt;import a.b as c&lt;/code&gt;), or any declaration of it (&lt;code&gt;import a.b.X&lt;/code&gt;,
&lt;code&gt;import a.b.{X, y}&lt;/code&gt;), directly or through a module that exports a declaration of it
(&lt;a href=&quot;#visibility-and-modules&quot;&gt;modules&lt;/a&gt;). Nothing else is needed, and a file that imports neither does not see them:
a call there is an error naming the module that adds the method and saying the file does not
import it. The core library’s impls are seen everywhere. Importing is per file, as for names.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An extension adds methods, never meaning.&lt;/strong&gt; Its methods are not the type’s: they reach no private
field or method of a type of another module, are in no method table, are not inherited as the
type’s and are not overridden; a call is compiled for the receiver’s static type, as the methods
added to a trait are. Inside them &lt;code&gt;self&lt;/code&gt; is the receiver, and the type’s public fields and methods
are in scope by bare name.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A type’s own methods are found first.&lt;/strong&gt; An extension’s method with the name and parameter types
of a method the type has, its own or an inherited one, could never be called, and is an error where
it is declared; one with other parameter types overloads the type’s. A method an extension adds to
a trait is passed over for a type that has one of its name and parameter types, as other methods
added to a trait are, so an extension never changes what an existing call means.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two extensions a file sees, from different modules&lt;/strong&gt;, that add a method of one name and
parameter types to types a receiver matches make a call of it on that receiver an error naming both
modules. Within one module the second is an error where it is declared.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;private&lt;/code&gt; method of an extension is private to its module&lt;/strong&gt;: the module’s other code calls it,
and a file importing the module does not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Infix calls, method values and calls through a bound see extensions as dotted calls do.&lt;/strong&gt; In
&lt;code&gt;middle[S: Seq[int]](xs: S) -&amp;gt; int = xs.median()&lt;/code&gt;, &lt;code&gt;median&lt;/code&gt; is found where &lt;code&gt;middle&lt;/code&gt; is written,
so &lt;code&gt;middle&lt;/code&gt;‘s own file must see the extension; each instance calls it at its type arguments.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;object&quot;&gt;object&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object Config
  val defaultPort = 8080
  var verbose = false
  port(env: Map[string, string]) -&amp;gt; int = …
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An &lt;code&gt;object&lt;/code&gt; is a singleton value. An &lt;code&gt;object&lt;/code&gt; with the same name as a class or &lt;code&gt;data&lt;/code&gt; type in the same
module is its companion and may access its private members. &lt;code&gt;object&lt;/code&gt;s may extend a class and traits.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object Default: Account(&amp;quot;none&amp;quot;, 0), Display
  override describe() -&amp;gt; string = &amp;quot;default &amp;quot; + super.describe()
  override display(out: Writer, spec: FormatSpec) = out.write(describe())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An object extending a class is made as a subclass’s instance is: the superclass’s constructor runs
first with the arguments written after &lt;code&gt;:&lt;/code&gt;, then the object’s own body. The object overrides methods
with &lt;code&gt;override&lt;/code&gt;, implements every abstract method it inherits (it cannot be left abstract), and
passes wherever the superclass is expected. The superclass is &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt;, as for any
subclass. What the superclass’s arguments and constructor read counts toward the order in which
module values and objects are made.&lt;/p&gt;
&lt;p&gt;An object’s body is written like a class body with no parameters: its fields and statements run
once, before &lt;code&gt;main&lt;/code&gt;, to make the one instance, and its methods have the same implicit receiver and
&lt;code&gt;self&lt;/code&gt;. The object’s name is a value of the object’s own type, so it can be stored and passed like
any other. There is no second instance to make, so calling the object’s name, &lt;code&gt;Name(…)&lt;/code&gt;, calls the
&lt;code&gt;apply&lt;/code&gt; methods it declares; an object without one cannot be called.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object Twice
  apply(n: int) -&amp;gt; int = n * 2
  apply(s: string) -&amp;gt; string = s + s

main()
  println(Twice(21)) // 42
  println(Twice(&amp;quot;ab&amp;quot;)) // abab
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An object shares its name only with its companion class or &lt;code&gt;data&lt;/code&gt; type. Where both exist, the name in
call position, &lt;code&gt;Account(…)&lt;/code&gt;, is the class’s constructor, and the bare name &lt;code&gt;Account&lt;/code&gt; or a member
&lt;code&gt;Account.open(…)&lt;/code&gt; is the companion. The class and its companion each use the other’s private
members.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Account(owner: string, private var balance: int)
  private val id = Account.issue()

object Account
  private var next = 0
  open(owner: string) -&amp;gt; Account = Account(owner, 0)
  balanceOf(a: Account) -&amp;gt; int = a.balance
  private issue() -&amp;gt; int
    next++
    next
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;code&gt;data&lt;/code&gt; type has a companion the same way: an object of its name in its module. A variant of the
type’s own name stays its constructor in call position, so &lt;code&gt;Point(1, 2)&lt;/code&gt; makes a point while
&lt;code&gt;Point.origin()&lt;/code&gt; is the companion’s; a type with no variant of its name, such as &lt;code&gt;List&lt;/code&gt;, has
nothing of that name to call but its companion’s &lt;code&gt;apply&lt;/code&gt;. The methods the type’s impls add and the
companion’s methods each use the other’s private members. A companion cannot share its name with a
variant of another type, nor with a variant of its own type’s name that has no fields, whose bare
name is already a value.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Point(x: int, y: int)

object Point
  origin() -&amp;gt; Point = Point(0, 0)

object List
  newBuilder[T]() -&amp;gt; ListBuilder[T] = ListBuilder()
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;a-companion-s-apply&quot;&gt;A companion’s &lt;code&gt;apply&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A companion’s &lt;code&gt;apply&lt;/code&gt; methods overload the constructor its name has in call position: the class’s,
or the data type’s variant of the type’s name. &lt;code&gt;Name(…)&lt;/code&gt; chooses among the constructor and every
&lt;code&gt;apply&lt;/code&gt; by the rules of any overloaded call: the candidates the arguments fit, by number, name and
type, and of those the most specific by parameter types, a candidate with a repeated parameter only
where none without one fits. By-name parameters, defaults, repeated parameters, generic inference and
a trailing block all work as for any call, so a by-name &lt;code&gt;apply&lt;/code&gt; takes an indented block after the
name.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Future[T](private val cell: Cell[T])

object Future
  apply[T](body: -&amp;gt; T) -&amp;gt; Future[T] = Future(Cell(body))

main()
  val direct = Future(Cell(1)) // the constructor: a `Cell` fits only it
  val page = Future(fetch(url)) // `apply`: the body runs inside it
  val sum = Future
    val a = 20
    a + 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inside the &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;Future(Cell(body))&lt;/code&gt; is the constructor: both candidates accept a &lt;code&gt;Cell[T]&lt;/code&gt;, and
the constructor’s parameter type is the more specific.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Type arguments&lt;/strong&gt; written at the call, &lt;code&gt;Future[int](…)&lt;/code&gt;, are the chosen candidate’s own: the
class’s or the data type’s type parameters for the constructor, the method’s for an &lt;code&gt;apply&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Same parameter types.&lt;/strong&gt; An &lt;code&gt;apply&lt;/code&gt; taking the same parameter types as the constructor, up to the
names of type parameters, is refused where it is declared, since no call could choose between
them; whether a parameter is by-name does not tell two apart.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No constructor of the name.&lt;/strong&gt; Where the name has no constructor in call position (a data type
with no variant of its name, such as &lt;code&gt;List&lt;/code&gt;, or an abstract class), &lt;code&gt;Name(…)&lt;/code&gt; calls the
companion’s &lt;code&gt;apply&lt;/code&gt; alone. The library gives &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; one taking their elements:
&lt;code&gt;List(1, 2, 3)&lt;/code&gt;, &lt;code&gt;Set(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;)&lt;/code&gt;, &lt;code&gt;Map((1, &amp;quot;one&amp;quot;), (2, &amp;quot;two&amp;quot;))&lt;/code&gt;. A plain object’s &lt;code&gt;apply&lt;/code&gt; is
called by the object’s name the same way.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;As a function value.&lt;/strong&gt; Where a function type is expected, the name of an object that declares
&lt;code&gt;apply&lt;/code&gt; is its companion class’s constructor or the &lt;code&gt;apply&lt;/code&gt; whose parameters accept that type’s,
chosen as for any overloaded function used as a value: &lt;code&gt;[1, 2].map(Pair)&lt;/code&gt;. For a data type’s
companion, a variant of the object’s name is one of those choices, as it is at a call. Elsewhere
the bare name is the object.
An object that is itself of a function type stays that value.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Name.apply(…)&lt;/code&gt; is an ordinary member call, and chooses among the &lt;code&gt;apply&lt;/code&gt; methods alone.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A file may also declare &lt;code&gt;val&lt;/code&gt;s and &lt;code&gt;var&lt;/code&gt;s at module level, beside its functions. Each is a value of
the program, read and (for a &lt;code&gt;var&lt;/code&gt;) assigned from any function by its name. Another module reaches a
public one as it reaches any declaration, by the name an import brings in or through the module’s
name, and assigns a &lt;code&gt;var&lt;/code&gt; the same way: &lt;code&gt;store.latest = b&lt;/code&gt;, &lt;code&gt;s.latest += 1&lt;/code&gt; after &lt;code&gt;import app.store as s&lt;/code&gt;, or &lt;code&gt;latest = b&lt;/code&gt; after &lt;code&gt;import app.store.latest&lt;/code&gt;. A private one is reached by neither, and only
a &lt;code&gt;var&lt;/code&gt; is assigned; a field of a module’s object is assigned as any field is, &lt;code&gt;store.Tally.count = 1&lt;/code&gt;. Each of these is also a place of a multiple assignment: &lt;code&gt;store.latest, n = n, store.latest&lt;/code&gt;.
Writing module state from a thread’s body is refused as reading it is
(&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&quot;type&quot;&gt;type&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;type Name = T&lt;/code&gt; declares a &lt;strong&gt;type alias&lt;/strong&gt;: another name for the type &lt;code&gt;T&lt;/code&gt;, declared at the top level
of a file beside data types and classes. A generic alias takes type parameters, and each use gives
it type arguments. An alias earns its place where a type is long or repeated: a function type, a
nested generic, a generic with some of its arguments fixed:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;type Handler = (Request) -&amp;gt; Result[Response, HttpError]
type Index = Map[string, Vector[(int, string)]]
type Parsed[T] = Result[T, ParseError]
type Lookup = (Index, string) -&amp;gt; Parsed[int]

serve(path: string, h: Handler) -&amp;gt; unit = …
val log: (string) -&amp;gt; unit = println(_)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A short type needs no alias, and a value with its own identity and named fields is a &lt;code&gt;data&lt;/code&gt; type
rather than an alias of a tuple: &lt;code&gt;data Point(x: int, y: int)&lt;/code&gt;, not &lt;code&gt;type Point = (int, int)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An alias is &lt;strong&gt;transparent&lt;/strong&gt;: a use of it is its expansion, the body with each type argument in place
of its parameter, and nothing else. It makes no new type and needs no conversion: a &lt;code&gt;Parsed[int]&lt;/code&gt; is a
&lt;code&gt;Result[int, ParseError]&lt;/code&gt; and the other way round, two overloads whose parameters differ only by an alias take
the same parameter types, and a diagnostic names the expansion, the type compared. An alias may be
written wherever a type is: a parameter, a result, a binding, a data or class field, a type
argument, a tuple, a function type, a type pattern (&lt;code&gt;r: Parsed[int]&lt;/code&gt;), and another alias’s body, which may
name an alias declared after it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A generic alias takes exactly as many type arguments as it has parameters, and one without
parameters takes none.&lt;/li&gt;
&lt;li&gt;Its parameters are plain names: no variance, no bounds, no lower bound. The types its body names
hold each type argument to their own bounds wherever the alias is used, as the expansion written
out would be: with &lt;code&gt;type Sorted[T] = TreeSet[T]&lt;/code&gt;, &lt;code&gt;Sorted[Opaque]&lt;/code&gt; is refused where &lt;code&gt;Opaque&lt;/code&gt; is not
&lt;code&gt;Ord&lt;/code&gt;, and &lt;code&gt;f[T: Ord](s: Sorted[T])&lt;/code&gt; is accepted. A body naming no parameter is held to its bounds
where the alias is declared.&lt;/li&gt;
&lt;li&gt;Every parameter appears in the body: one that does not would make &lt;code&gt;A[int]&lt;/code&gt; and &lt;code&gt;A[string]&lt;/code&gt; one
type.&lt;/li&gt;
&lt;li&gt;The body sees the alias’s own parameters and the file’s types, and no function’s type parameters
and no &lt;code&gt;Self&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;An alias cannot name itself, directly (&lt;code&gt;type A = Vector[A]&lt;/code&gt;) or through other aliases: its
expansion would never end. A recursive type is a &lt;code&gt;data&lt;/code&gt; type.&lt;/li&gt;
&lt;li&gt;An alias’s name is a type’s: it may not be the name of another type of its module (a data type,
a class, an object or an alias), of a built-in type, or &lt;code&gt;Self&lt;/code&gt;. It names no value, so a function
or a module value of the same name is no clash.&lt;/li&gt;
&lt;li&gt;An alias names only a type. It is not a value, a constructor or a pattern: &lt;code&gt;type P = Point&lt;/code&gt; does not
make &lt;code&gt;P(1, 2)&lt;/code&gt; or match &lt;code&gt;P(x, y)&lt;/code&gt;, and the diagnostic names &lt;code&gt;Point&lt;/code&gt;, which does. An &lt;code&gt;impl&lt;/code&gt; names the
type itself rather than an alias of it, and so does a class’s list of its superclass and traits.&lt;/li&gt;
&lt;li&gt;An alias takes no annotations.&lt;/li&gt;
&lt;li&gt;An alias is public unless marked &lt;code&gt;private&lt;/code&gt;, imported by name (&lt;code&gt;import geometry.{Point}&lt;/code&gt;) or reached
through its module (&lt;code&gt;geometry.Point&lt;/code&gt;) as any type is; a private one is seen only in its module, its
expansion reaching others through the signatures that use it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;type&lt;/code&gt; declares an alias only where a name follows it; anywhere else it is an ordinary name, so a
function, a parameter, a field or a local may be called &lt;code&gt;type&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;opaque-types&quot;&gt;Opaque types&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;opaque type Name = Repr&lt;/code&gt; declares an &lt;strong&gt;opaque type&lt;/strong&gt;: a new type whose values are laid out exactly
as values of its &lt;strong&gt;representation&lt;/strong&gt; &lt;code&gt;Repr&lt;/code&gt;, and which is otherwise a type apart. A &lt;code&gt;UserId&lt;/code&gt; and an
&lt;code&gt;OrderId&lt;/code&gt; that are both &lt;code&gt;long&lt;/code&gt; underneath cannot be mixed up, and neither can be passed where a
&lt;code&gt;long&lt;/code&gt; is expected, while each costs what a &lt;code&gt;long&lt;/code&gt; costs:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;module ids

opaque type UserId = long
opaque type Email = string
opaque type Id[T] = long

impl UserId
  next() -&amp;gt; UserId = UserId(repr + 1)
  def id -&amp;gt; long = repr

impl Ord for UserId
  compare(other: UserId) -&amp;gt; int = repr.compare(other.repr)

impl Display for Email
  display(out: Writer, spec: FormatSpec) = out.write(s&amp;quot;&amp;lt;$repr&amp;gt;&amp;quot;)

user(n: long) -&amp;gt; UserId = UserId(n)
email(s: string) -&amp;gt; Email = Email(s.toLower)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Only the module that declares an opaque type sees its representation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In that module, &lt;code&gt;Name(r)&lt;/code&gt; makes a value of the opaque type from a value &lt;code&gt;r&lt;/code&gt; of its
representation, and &lt;code&gt;x.repr&lt;/code&gt; is the representation of a value &lt;code&gt;x&lt;/code&gt;. In a method an impl adds to
the type, &lt;code&gt;repr&lt;/code&gt; alone is &lt;code&gt;self.repr&lt;/code&gt;. A generic opaque type’s type arguments are written,
&lt;code&gt;Id[User](1)&lt;/code&gt;, or inferred from the representation and the expected type, as a function’s are.&lt;/li&gt;
&lt;li&gt;Outside it, &lt;code&gt;Name(r)&lt;/code&gt;, &lt;code&gt;x.repr&lt;/code&gt; and a bare &lt;code&gt;repr&lt;/code&gt; are refused, with a diagnostic saying that the
representation is seen only in the declaring module. Code there names the type, passes, stores
and compares its values, calls its methods, and makes and takes apart values through the functions
the module offers.&lt;/li&gt;
&lt;li&gt;No conversion is implicit in either direction, in the module or outside it: a &lt;code&gt;long&lt;/code&gt; is not a
&lt;code&gt;UserId&lt;/code&gt;, and a &lt;code&gt;UserId&lt;/code&gt; is not a &lt;code&gt;long&lt;/code&gt;. Two instances of a generic opaque type at different type
arguments are different types, &lt;code&gt;Id[User]&lt;/code&gt; and &lt;code&gt;Id[Order]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The name is a type’s and nothing else: it is not a value, and it is not a pattern, so a &lt;code&gt;match&lt;/code&gt;
takes a value apart with &lt;code&gt;x.repr&lt;/code&gt;, in the module, rather than with &lt;code&gt;Name(r)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An opaque type has the traits and methods its impls give it, and no others; the representation’s
are not inherited. An impl of a trait takes the trait’s default bodies, so &lt;code&gt;compare&lt;/code&gt; alone gives
&lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;less&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; and sorting, and &lt;code&gt;display&lt;/code&gt; gives interpolation. An impl that only adds
methods may be written in any module, as an extension, and there it uses only what the type offers;
a trait’s impl is written in the module of the type or of the trait. Equality and hashing are the
representation’s: two values are equal when their representations are, so an opaque type is a key
of a &lt;code&gt;Map&lt;/code&gt; and an element of a &lt;code&gt;Set&lt;/code&gt;. A value with no &lt;code&gt;Display&lt;/code&gt; prints as the type’s name, which
shows nothing of the representation. An opaque type derives nothing.&lt;/p&gt;
&lt;p&gt;A value of an opaque type becomes an &lt;code&gt;Any&lt;/code&gt; or a trait’s value in a box that names the opaque type,
whatever the representation, a reference included. A type pattern for the opaque type finds it
there, one for the representation does not, and a value of the representation is never taken for
the opaque type:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;describe(x: Any) -&amp;gt; string = x match
  u: UserId -&amp;gt; s&amp;quot;user ${u.id}&amp;quot;
  n: long -&amp;gt; s&amp;quot;long $n&amp;quot;
  _ -&amp;gt; &amp;quot;other&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;describe(user(1))&lt;/code&gt; is &lt;code&gt;&amp;quot;user 1&amp;quot;&lt;/code&gt; and &lt;code&gt;describe(long(1))&lt;/code&gt; is &lt;code&gt;&amp;quot;long 1&amp;quot;&lt;/code&gt;; a union &lt;code&gt;UserId | long&lt;/code&gt;
tells its members apart the same way. A value of an opaque type is sendable where its
representation is.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The representation is any type with values to lay out: a number, a &lt;code&gt;string&lt;/code&gt;, a data value, an
object (the very object, shared), a tuple, a function, an &lt;code&gt;Option&lt;/code&gt;, a collection, another opaque
type. It may not be &lt;code&gt;Nothing&lt;/code&gt; or &lt;code&gt;unit&lt;/code&gt;, a union, or a type parameter alone, which could be
either; and it may not name the opaque type, directly or through aliases, since the type is laid
out as it. A recursive type is a &lt;code&gt;data&lt;/code&gt; type.&lt;/li&gt;
&lt;li&gt;A generic opaque type’s parameters are plain names: invariant, with no bounds. The types its
representation names hold each type argument to their own bounds where the opaque type is used,
as an alias’s do. A parameter the representation does not name is allowed, and tells values apart
by type alone: &lt;code&gt;Id[User]&lt;/code&gt; and &lt;code&gt;Id[Order]&lt;/code&gt; are both a &lt;code&gt;long&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;An opaque type is no type constructor. A generic one is not passed for a constructor parameter
&lt;code&gt;F[_]&lt;/code&gt;, whose instances are each an object, and an opaque type takes no constructor parameter of
its own, which would leave its layout undecided. It is a type argument of a constructor
parameter’s application like any type: &lt;code&gt;F[UserId]&lt;/code&gt; at &lt;code&gt;Vector&lt;/code&gt; is a &lt;code&gt;Vector[UserId]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A refined variant’s result does not name an opaque type, alone or inside another type
(&lt;code&gt;Newest -&amp;gt; Query[UserId]&lt;/code&gt; is refused); its fields may be of opaque types, and a type with refined
variants takes one as its type argument like any type.&lt;/li&gt;
&lt;li&gt;A union of an opaque type and its representation keeps its members apart; only a union naming
one type twice, the opaque type or the representation, collapses to it.&lt;/li&gt;
&lt;li&gt;An opaque type has no supertype (&lt;code&gt;opaque type X &amp;lt;: Y&lt;/code&gt; is refused), no annotations and no
&lt;code&gt;derives&lt;/code&gt; clause.&lt;/li&gt;
&lt;li&gt;Its name is a type’s, under the rules for an alias’s name; it is public unless marked &lt;code&gt;private&lt;/code&gt;,
and imported or reached through its module as any type is.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;opaque&lt;/code&gt; declares an opaque type only before &lt;code&gt;type&lt;/code&gt; and a name; anywhere else it is an ordinary
name.&lt;/p&gt;
&lt;h2 id=&quot;visibility-and-modules&quot;&gt;Visibility and modules&lt;/h2&gt;
&lt;p&gt;Declarations are public unless marked &lt;code&gt;private&lt;/code&gt; (visible in the module). A directory is a module;
&lt;code&gt;module a.b&lt;/code&gt; heads each file. A &lt;strong&gt;package&lt;/strong&gt; is a build unit with an &lt;code&gt;avin.hocon&lt;/code&gt; manifest; a
&lt;strong&gt;project&lt;/strong&gt; lists packages (&lt;a href=&quot;/spec/packages/&quot;&gt;packages&lt;/a&gt;). &lt;code&gt;import a.b.{X, y as z}&lt;/code&gt; brings names into a file, and &lt;code&gt;export a.b.{X}&lt;/code&gt; makes another module’s
declaration one of the module’s own names. The root module &lt;code&gt;avin&lt;/code&gt;
is reserved for the standard library.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;// shapes/circle.avin
module shapes

import geometry.Point

class Circle(val r: int)
  center() -&amp;gt; Point = Point(r, 0)

area(c: Circle) -&amp;gt; int = scale() * c.r * c.r

private scale() -&amp;gt; int = 3 // seen by every file of `shapes`, and nowhere else

// main.avin, in the program&apos;s root directory
import shapes.{Circle, area as circleArea}

main() = println(s&amp;quot;${circleArea(Circle(2))}&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A program is a directory tree.&lt;/strong&gt; Each directory under the program’s root is a module named by
its path from the root, &lt;code&gt;geometry/shapes&lt;/code&gt; being &lt;code&gt;geometry.shapes&lt;/code&gt;, so a directory is named as a
declaration is: letters, digits and &lt;code&gt;_&lt;/code&gt;. Every file of a module begins with &lt;code&gt;module&lt;/code&gt; and the
module’s name, which must agree with its directory. The root directory’s own files are the &lt;strong&gt;root
module&lt;/strong&gt;, which has no name, holds &lt;code&gt;main&lt;/code&gt; (&lt;code&gt;main()&lt;/code&gt; or &lt;code&gt;main(args: Vector[string])&lt;/code&gt;) and takes no header. A program of a single file is
compiled alone; its header, if any, names its module.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A module’s files are one namespace.&lt;/strong&gt; Each sees every declaration of every other file of its
module by its bare name, private ones included, and they may not declare one name twice, except
as overloads of a function. A class’s companion object may be in another file of the class’s
module, never in another module. A name declared twice, whether in one file or in two, is
reported once, at the second declaration, with the place of the first; types, functions of the
same parameter types, values, objects and variants clash with one another. The program’s other
diagnostics follow from a clash between two files, so while one is unresolved only duplicates
are reported. The same name in different modules is no clash.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Another module’s declarations are imported, per file.&lt;/strong&gt; &lt;code&gt;import a.b.X&lt;/code&gt; brings &lt;code&gt;X&lt;/code&gt; into the file;
&lt;code&gt;import a.b.{X, y as z}&lt;/code&gt; brings several, and &lt;code&gt;as&lt;/code&gt; names one differently. There is no wildcard
import. Importing a name the module does not declare, a private declaration, a name the file’s own
module declares or one another import already brings in is an error; an import the file does not
use is not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A module may be imported whole.&lt;/strong&gt; &lt;code&gt;import a.b&lt;/code&gt; binds the module under its last segment and
&lt;code&gt;import a.b as c&lt;/code&gt; under &lt;code&gt;c&lt;/code&gt;; &lt;code&gt;b.X&lt;/code&gt; then reaches &lt;code&gt;a.b&lt;/code&gt;‘s public &lt;code&gt;X&lt;/code&gt;, whatever it is: a type
(&lt;code&gt;b.Point&lt;/code&gt;, in type position too), function, value, object or variant (&lt;code&gt;b.Some(x)&lt;/code&gt;, in patterns
as well). A private &lt;code&gt;X&lt;/code&gt; or one the module does not declare is an error. The name is the module’s
alone: a declaration of the file’s module or another import under the same name is an error at the
import, and a local, parameter or member of the enclosing class named like the module hides it.
Importing &lt;code&gt;a.b&lt;/code&gt; makes only &lt;code&gt;a.b&lt;/code&gt; reachable, not its submodules; each module named in code is
imported.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Importing a module, or any declaration of it, also brings in the methods its
&lt;a href=&quot;#extensions&quot;&gt;extensions&lt;/a&gt; add&lt;/strong&gt;, so &lt;code&gt;&amp;quot;hey&amp;quot;.shout()&lt;/code&gt; works in every file that imports &lt;code&gt;words&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A module may export declarations of other modules&lt;/strong&gt;, presenting one surface over modules it
keeps internal:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;// shapes/shapes.avin
module shapes

export shapes.geometry.{Point, distance}
export shapes.color.{Color, Red, Blue as Navy}

// main.avin
import shapes.{Point, Color, Navy}
import shapes

main() = println(shapes.distance(Point(0, 0), Point(3, 4)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An export is written as an import is, at the top of any file of the module: one name, a &lt;code&gt;{…}&lt;/code&gt;
group, &lt;code&gt;as&lt;/code&gt; naming one differently; there is no wildcard. &lt;code&gt;export&lt;/code&gt; means this only at the start
of a top-level line and before a name; everywhere else it is an ordinary name.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An export is a name of its module, for the very declaration it names&lt;/strong&gt;: no copy and no wrapper.
Every file of the exporting module sees it by its bare name without an import, and other modules
reach it as any declaration of the module, imported by name (&lt;code&gt;import shapes.Point&lt;/code&gt;) or through the
module imported whole (&lt;code&gt;shapes.Point&lt;/code&gt;, in types and patterns too). A value made through it is of
the declaring module’s type, so &lt;code&gt;shapes.Point&lt;/code&gt; and &lt;code&gt;shapes.geometry.Point&lt;/code&gt; are one type, and a
&lt;code&gt;with&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt;, an impl or a conformance sees no difference. Exporting a function’s name exports
every public overload of it; a type’s variants are exported by their own names, and are reached
through an exported type as &lt;code&gt;Color.Red&lt;/code&gt; either way. Types, aliases, classes and their companion
objects, objects, traits, machines, functions, module-level values and variants may all be
exported; a &lt;code&gt;var&lt;/code&gt; is assigned through any name of it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An export names another module’s public declaration&lt;/strong&gt;, directly or through that module’s own
export, so exports chain: a module exporting &lt;code&gt;mid.Token&lt;/code&gt;, which &lt;code&gt;mid&lt;/code&gt; exports from &lt;code&gt;base&lt;/code&gt;, presents
&lt;code&gt;base.Token&lt;/code&gt;. Exporting a private declaration, one the module does not have, a whole module, a
name of the exporting module itself, or anything from the root module, which nothing imports, is
an error; so is marking an export &lt;code&gt;private&lt;/code&gt;. Two modules may export each other’s declarations;
exports that lead round to one another without reaching a declaration are an error at each of
them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An exported name clashes as a declaration does&lt;/strong&gt;: with a declaration of its module, with an
import of a different declaration by a file of the module, with a module imported under its name,
and with another export of the name reaching a different declaration. Two paths to one declaration
are never a clash: a module may export a name and import the same declaration, export it from two
files, and a file may import it both directly and through an export.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A module that exports a declaration of another presents that module’s extensions too&lt;/strong&gt;: a file
importing the exporting module, whole or any name of it, and the exporting module’s own files, see
the methods the other module’s extensions add, as a file importing the other module would. Only
the modules whose declarations it exports are presented; one it merely imports is not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What a name means&lt;/strong&gt; is decided in that order: the file’s module, its declarations and then its
exports, then the file’s imports, then the
public declarations of the standard library’s module &lt;code&gt;avin&lt;/code&gt;, which every file sees without an
import. The nearer hides the farther, whatever kind each declaration is, except that a core
library variant a nearer one hides is still chosen where its own type is expected
(&lt;a href=&quot;#data&quot;&gt;&lt;code&gt;data&lt;/code&gt;&lt;/a&gt;). A program’s own modules
may not be &lt;code&gt;avin&lt;/code&gt; or under it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Modules may import one another&lt;/strong&gt;, in a cycle if need be: the program is compiled whole. Its
module-level values initialize before &lt;code&gt;main&lt;/code&gt;, each after the values its initializer needs, across
modules as within one.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;doc-comments&quot;&gt;Doc comments&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The comment directly above a declaration documents it&lt;/strong&gt;: the run of &lt;code&gt;//&lt;/code&gt; lines with no blank line
between them and the declaration, any annotations between skipped. The comment above a file’s
&lt;code&gt;module&lt;/code&gt; line documents the module. Nothing else marks a doc comment: the language server’s hover
shows it under the declaration’s header, and &lt;a href=&quot;/getting-started/#api-documentation&quot;&gt;&lt;code&gt;avin doc&lt;/code&gt;&lt;/a&gt;
writes it into the program’s pages.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;// A shape in the plane; [area] measures one.
//
// ```
// val s = Circle(1.0)
// println(area(s))
// ```
data Shape
  // A circle of the given radius.
  Circle(radius: real)
  Rect(width: real, height: real)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It is Markdown&lt;/strong&gt;, with GitHub’s extensions. Each line loses its &lt;code&gt;//&lt;/code&gt; and one space after it;
what is left keeps its indentation, so a code block indented in the comment stays one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A block with no language, or marked &lt;code&gt;avin&lt;/code&gt;, is Avin code&lt;/strong&gt;, coloured as Avin; &lt;code&gt;avin doc --check&lt;/code&gt;
fails on one that parses neither as declarations nor as the statements of a function’s body. A
block of anything else names its language (&lt;code&gt;text&lt;/code&gt;, &lt;code&gt;sh&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A link to a declaration&lt;/strong&gt; is written with its path as the destination, &lt;code&gt;[the map](Vector.map)&lt;/code&gt;,
or as &lt;code&gt;[Name]&lt;/code&gt; or &lt;code&gt;[`Name`]&lt;/code&gt; alone. The path is found from the declaration the comment
documents: a member of its type, then a declaration of its module, then a full path such as
&lt;code&gt;avin.fs.File&lt;/code&gt; or a module’s name, then the prelude, then the one declaration of the program with
that name. &lt;code&gt;[Name]&lt;/code&gt; that names nothing is left as the text it is; &lt;code&gt;[`Name`]&lt;/code&gt; that names nothing,
and a destination that names neither a declaration nor a page of the documentation, are what
&lt;code&gt;avin doc --check&lt;/code&gt; fails on.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;literate-source&quot;&gt;Literate source&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;A file named &lt;code&gt;.lavin&lt;/code&gt; is a Markdown document, and the part of it indented four columns is the
program.&lt;/strong&gt; Everything else is prose and is not compiled. The file’s &lt;strong&gt;name&lt;/strong&gt; alone decides which
kind of file it is: an &lt;code&gt;.avin&lt;/code&gt; file is never read this way, whatever its indentation, and a &lt;code&gt;.lavin&lt;/code&gt;
file with no prose in it is an &lt;code&gt;.avin&lt;/code&gt; file indented four spaces. There is no other marker: no name
on a block, no directive that opens one, and no way to say that a block ends.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;# Halving

This program explains itself. Everything at the margin is prose, and the compiler never
sees it.

    half(n: int) -&amp;gt; int = n / 2

    main()
        val h = half(9)

A paragraph between two indented blocks ends nothing, so a body can be explained a step
at a time and picked up again where it left off.

        println(h)

What a reader should *not* run gets a fence instead of an indent:

~~~
half(n) = n / 2      // the wrong version, with no types
~~~
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The program that file holds is the indented lines, and it is an ordinary Avin program:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;half(n: int) -&amp;gt; int = n / 2

main()
  val h = half(9)
  println(h)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The code appears in the order it runs and nothing reorders it, so the file reads correctly as it
is: to a person, to a Markdown renderer, and to &lt;code&gt;grep&lt;/code&gt;. What it adds over comments is room for a
full explanation between two functions, or between two lines of one.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;.lavin&lt;/code&gt; file is accepted wherever an &lt;code&gt;.avin&lt;/code&gt; file is: as a program of one file, as a file of a
module in a directory program (a module may mix the two), in the standard library’s directory, and
by &lt;code&gt;avin test&lt;/code&gt;, which finds its &lt;code&gt;@test&lt;/code&gt; functions as it finds an ordinary file’s. The language
server reads it the same way.&lt;/p&gt;
&lt;h3 id=&quot;the-rules&quot;&gt;The rules&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Four columns is the threshold&lt;/strong&gt;, which is Markdown’s own, so what a renderer shows as a code
block is exactly what the compiler reads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The program’s indentation starts after the four columns.&lt;/strong&gt; A declaration is written four
columns in, its body eight, and so on; the program’s blocks open and close by its own
indentation, measured from there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consecutive indented blocks are one program, and prose between them is blank lines.&lt;/strong&gt; A
paragraph between two blocks ends nothing: the next block’s lines carry on at whatever depth the
program had reached, so a function body may be explained a step at a time, its later lines
indented as deep as its earlier ones. A program line less deep than the block it is in closes
that block, as it would in an &lt;code&gt;.avin&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A fenced block is an illustration.&lt;/strong&gt; Both &lt;code&gt;```&lt;/code&gt; and &lt;code&gt;~~~&lt;/code&gt; mark code that is to be read rather
than run (a wrong version beside the right one, a shell transcript, a fragment of another
language) and none of it is compiled, however it is indented. Code that runs is indented; code
that is only shown is fenced. A fence closes at a line of the same character, at least as long,
and nothing else.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What is under a list item is prose.&lt;/strong&gt; An indented block inside a list item belongs to that
item, so a list may hold examples without any of them entering the program. An executable block
therefore never sits directly under a list; a line of prose at the margin separates the two.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;positions-are-the-document-s&quot;&gt;Positions are the document’s&lt;/h3&gt;
&lt;p&gt;Every line of program text stays where it was written, so every position the compiler reports, in
a diagnostic, a trap’s report, a failed test, the language server or the debug information a
debugger reads, is the line and column of the
document the reader has open, the four columns included:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `nope` is not defined
 --&amp;gt; doubling.lavin:8:16
  |
8 |         double(nope)
  |                ^^^^
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;two-forms-markdown-accepts-are-refused&quot;&gt;Two forms Markdown accepts are refused&lt;/h3&gt;
&lt;p&gt;Both would silently drop part of the program, and neither could be diagnosed later, because what
reaches the compiler is simply a smaller program than the author wrote.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A tab in the indentation.&lt;/strong&gt; A tab is as wide as whatever displays it, so a tab-indented line could
be program text in one editor and prose in another. It is refused &lt;em&gt;before&lt;/em&gt; the four-column test,
because failing that test would silently turn the line into prose and drop a statement from a
function.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: a tab in the indentation of a literate file — what makes a line program text is four columns of indent, and a tab is as wide as whatever happens to be displaying it, so this line is code in one editor and prose in another
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A fence that is never closed.&lt;/strong&gt; Markdown runs an unclosed fence to the end of the document. In a
literate file that would turn every declaration below it into an illustration, and the resulting
diagnostic would point somewhere far below the cause. The fence is refused at the line that opened
it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: this fence is never closed, so everything below it is an illustration and none of it is compiled — close it, or indent the lines that are meant to run
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;tangle-and-weave&quot;&gt;&lt;code&gt;tangle&lt;/code&gt; and &lt;code&gt;weave&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The two halves of a literate system are named for what they do to the source. Every build of a
&lt;code&gt;.lavin&lt;/code&gt; file tangles it; &lt;code&gt;avin tangle&lt;/code&gt; prints the program with the prose stripped, line for line
with the document, and &lt;code&gt;avin weave&lt;/code&gt; renders the document as HTML with its program coloured. Both
read the file as a build does, so a file the compiler refuses is refused with the same diagnostic.
&lt;a href=&quot;/getting-started/#literate-programs&quot;&gt;Getting started&lt;/a&gt; shows them.&lt;/p&gt;
&lt;h2 id=&quot;tests&quot;&gt;Tests&lt;/h2&gt;
&lt;p&gt;A test is a top-level function marked &lt;code&gt;@test&lt;/code&gt;. &lt;code&gt;avin test&lt;/code&gt; calls it with nothing, so it takes no
parameters and has no type parameters; it passes by returning, and fails by stopping, which a failed
assertion does. It yields unit, or a &lt;code&gt;Result[unit, E]&lt;/code&gt; whose error has &lt;code&gt;Display&lt;/code&gt;: an &lt;code&gt;Ok&lt;/code&gt; passes, and
an &lt;code&gt;Err&lt;/code&gt; fails the test with the error shown as the reason (&lt;code&gt;test answered Err: empty input&lt;/code&gt;,
reported at the test’s name).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;parse(text: string) -&amp;gt; Result[int, string] = if text == &amp;quot;&amp;quot; then Err(&amp;quot;empty input&amp;quot;) else Ok(text.byteLength)

@test(&amp;quot;reads a word&amp;quot;)
readsAWord() -&amp;gt; Result[unit, string]
  val n = parse(&amp;quot;word&amp;quot;)?
  assertEq(n, 4)
  Ok(())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;@test&lt;/code&gt; names the test after its function, or after a description written first, a string that is
not empty. After it come, each at most once:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;written&lt;/th&gt;&lt;th&gt;means&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@test(should_trap)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the test &lt;strong&gt;passes&lt;/strong&gt; by trapping, and fails by returning&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@test(should_trap: &amp;quot;index out of range&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;…and what the run printed contains the text&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@test(timeout: 30)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the test may run for 30 seconds, in place of the run’s limit of 60; &lt;code&gt;0&lt;/code&gt; is no limit&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@test(ignore: &amp;quot;why&amp;quot;)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the test is compiled and checked, and &lt;strong&gt;not run&lt;/strong&gt;; the reason is required&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;So &lt;code&gt;@test(&amp;quot;keeps both arms&amp;quot;, should_trap: &amp;quot;index out of range&amp;quot;, timeout: 5, ignore: &amp;quot;the parser drops the second arm&amp;quot;)&lt;/code&gt; is one annotation. A timeout is a whole number of seconds from 0 to 2147483. A test
past its limit is stopped and fails, reading &lt;code&gt;timed out after Ns&lt;/code&gt;. An ignored test is reported with
its reason, &lt;code&gt;skip  name  ignored: why&lt;/code&gt;, starts no process, runs none of its module’s hooks and fails
nothing; the summary counts it, &lt;code&gt;3 passed, 1 failed, 1 ignored&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;hooks&quot;&gt;Hooks&lt;/h3&gt;
&lt;p&gt;Four more annotations each mark a top-level function &lt;code&gt;avin test&lt;/code&gt; calls around a module’s tests:
&lt;code&gt;@setup&lt;/code&gt; before each test and &lt;code&gt;@teardown&lt;/code&gt; after it, &lt;code&gt;@setup_all&lt;/code&gt; once before the module’s first test
and &lt;code&gt;@teardown_all&lt;/code&gt; once after its last. A hook takes nothing, yields unit and takes no arguments in
its annotation, and a module declares at most one of each. Each test runs in a process of its own,
which decides what a hook can share:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@setup&lt;/code&gt; runs in the test’s own process, immediately before the test, so what it stores in a
module-level &lt;code&gt;var&lt;/code&gt; is there when the test reads it.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@teardown&lt;/code&gt; runs in the test’s own process after a test that returned, and in a process of its own
after a test that trapped or was stopped, so it can rely on releasing only what outlives a process:
a file, a directory, a path. It runs after a failed test too.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@setup_all&lt;/code&gt; and &lt;code&gt;@teardown_all&lt;/code&gt; each run in a process of their own, sharing nothing with the tests
but what outlives a process.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A &lt;code&gt;@setup&lt;/code&gt; that fails fails the test without running it, reading &lt;code&gt;not run: `@setup` `name` failed:&lt;/code&gt;
and the reason; neither the test nor the teardown runs. A &lt;code&gt;@setup_all&lt;/code&gt; that fails is a failure of its
own, and each of the module’s tests fails without running; its &lt;code&gt;@teardown_all&lt;/code&gt; does not run. A
&lt;code&gt;@teardown&lt;/code&gt; or &lt;code&gt;@teardown_all&lt;/code&gt; that fails is a failure of its own, on a row naming the hook, beside
the verdict the test already had.&lt;/p&gt;
&lt;h3 id=&quot;tests-files&quot;&gt;&lt;code&gt;@tests&lt;/code&gt; files&lt;/h3&gt;
&lt;p&gt;A file whose header says &lt;code&gt;@tests&lt;/code&gt; holds what the tests need and the program does not: fixtures,
helpers, types made for the tests, and tests themselves.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;module shapes

@tests

unitSquare() -&amp;gt; Square = Square(1)

@test
perimeterOfTheUnitSquare()
  assertEq(unitSquare().perimeter(), 4)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every command checks it with the rest of the program, and only &lt;code&gt;avin test&lt;/code&gt; builds it: a program that
runs leaves out what it declares, and its module-level values are never computed. So nothing else may
name what it declares, and the restriction is on the code that names it: a &lt;code&gt;@test&lt;/code&gt; function or a hook
in any file may, and so may another &lt;code&gt;@tests&lt;/code&gt; file; a lambda counts as the function it is written in.
Anything else is refused where the name is written:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;`unitSquare` is declared in a `@tests` file, so only `avin test` builds it: a `@test` function, a test hook or another `@tests` file may name it, and nothing else
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An impl in a &lt;code&gt;@tests&lt;/code&gt; file is for a type or of a trait that file declares: an impl of anything else
would make a type behave one way while the tests run and another in the program that ships. And a
program does not start in a &lt;code&gt;@tests&lt;/code&gt; file: &lt;code&gt;main&lt;/code&gt; is declared in an ordinary one.&lt;/p&gt;
&lt;h3 id=&quot;the-core-library-s-tests&quot;&gt;The core library’s tests&lt;/h3&gt;
&lt;p&gt;The core library’s own tests are in &lt;code&gt;library/tests&lt;/code&gt;, beside its modules, as a package’s are in its
&lt;code&gt;tests&lt;/code&gt; directory: a program of &lt;code&gt;@test&lt;/code&gt; functions that uses the library through its public names, as
any program does, and that &lt;code&gt;avin test library/tests&lt;/code&gt; runs. That directory is no part of the library
every program is compiled with, and &lt;code&gt;avin test&lt;/code&gt; on a program runs that program’s tests only, never a
test the core library or a dependency declares.&lt;/p&gt;
&lt;h2 id=&quot;initialization&quot;&gt;Initialization&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;No field, module-level value or &lt;code&gt;lazy val&lt;/code&gt; is ever read before it is set, and the compiler proves
it.&lt;/strong&gt; Each rule below is checked when the program is compiled and costs nothing when it runs; Avin
has no default value a field holds before its initializer, so a read the rules let through could
only be a wrong value or a crash, and there is none. One check is left to run time, for a &lt;code&gt;lazy val&lt;/code&gt;
that reaches its own value through code it hands to something else to run (a lambda, an argument
passed by name, a method value), and it traps at that read rather than read what is not there.&lt;/p&gt;
&lt;h3 id=&quot;objects-under-construction&quot;&gt;Objects under construction&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Creating an instance runs the superclass’s constructor first, then stores the class parameters,
then runs the class body top to bottom. Until every field is assigned, &lt;code&gt;self&lt;/code&gt; may not be passed,
stored, captured, or used to call a method, and a body statement may not read a field declared
below it. This is checked at compile time, so no field is ever observed uninitialized:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Counter(start: int)
  var count = start
  println(describe()) // error: `describe` is called before `label` is initialized
  register(self) // error: `self` is passed, stored or returned before `label` is initialized
  val reader = () -&amp;gt; count // error: a lambda that captures `self` is made before `label` is initialized
  val label = s&amp;quot;counter $start&amp;quot;
  register(self) // every field is set: the body may use `self` freely
  describe() -&amp;gt; string = s&amp;quot;$label: $count&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Up to and including the initializer of its last field, a body uses &lt;code&gt;self&lt;/code&gt; only to read a field
already set and to assign a field. Calling a method is an error however it is spelled — a bare
name, &lt;code&gt;self.describe()&lt;/code&gt;, &lt;code&gt;super.describe()&lt;/code&gt; — and so are passing, storing or returning &lt;code&gt;self&lt;/code&gt; and
making a lambda, a by-name argument or a local function that uses a field or &lt;code&gt;self&lt;/code&gt;, or a method
value of &lt;code&gt;self&lt;/code&gt; (&lt;code&gt;describe&lt;/code&gt; named without a call), since each can read a field before it is set.
An object’s body follows the same rule.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; the body is straight-line code that sets the fields in the order written, so
“declared above” is “already set” at every point of it. Everything that could read a field later
than it is written (a method, a lambda, an argument passed by name, a local function, a method
value, another object holding &lt;code&gt;self&lt;/code&gt;) needs &lt;code&gt;self&lt;/code&gt; to do it, and none of those uses of &lt;code&gt;self&lt;/code&gt; is
allowed until the last field is set, after which every read finds a value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class’s body runs before any subclass’s fields are set, so the object is
never complete while it runs: the limits above hold for the whole of it. After its own last field
it may call only a method that cannot be overridden (a private one) and that is itself safe: one
that uses &lt;code&gt;self&lt;/code&gt; only to read and assign fields and to call other safe methods. A call that could
reach an override, directly or through such a method, is an error, as is passing, storing or
capturing &lt;code&gt;self&lt;/code&gt;, a method value of &lt;code&gt;self&lt;/code&gt; included. A trait’s abstract &lt;code&gt;val&lt;/code&gt; that the class
does not supply itself is a subclass’s field, and is not read in the body either.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; a subclass’s fields are set only after this body has returned, and the only
code that can read them is an override, a trait’s &lt;code&gt;val&lt;/code&gt; a subclass supplies, or code that holds
&lt;code&gt;self&lt;/code&gt;. A safe method is one whose every path stays inside the class’s own fields, decided over
the methods it calls until nothing changes, so calling one cannot reach an override.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A superclass’s arguments run before any field of the object is set&lt;/strong&gt;, the superclass’s own
included, so they use nothing of the object: no field, no method and no &lt;code&gt;self&lt;/code&gt;, and no lambda,
argument passed by name, local function or method value that uses one of them, since the
superclass’s constructor may call such a function before the field it reads is set. A class
parameter’s name in them reads the argument itself, so a function capturing a parameter is fine.
The same holds for the arguments an &lt;code&gt;object&lt;/code&gt; passes to the class it extends.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;open class Base(f: () -&amp;gt; int)
  val got: int = f()

class Next(start: int): Base(() -&amp;gt; start + 1) // reads the argument `start`
class Late: Base(() -&amp;gt; late) // error: a lambda that captures `self` is made in a superclass&apos;s arguments, which run before the object is initialized
  val late: int = 41
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The errors read &lt;code&gt;a lambda that captures `self` is made in a superclass&apos;s arguments, which run before the object is initialized&lt;/code&gt;, &lt;code&gt;an argument passed by name uses `self` in a superclass&apos;s arguments, …&lt;/code&gt;, &lt;code&gt;a local function that uses `self` is made in a superclass&apos;s arguments, …&lt;/code&gt;, and
for a method value &lt;code&gt;`name` is a method of the object, which a superclass&apos;s arguments cannot use as a value: …&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; the arguments are evaluated before the superclass’s constructor starts, and
that constructor may run any function it is given, at once or from its body; at that moment no
field of the object, inherited or its own, has been set. A parameter is a value the caller has
already computed, so it is the one thing of the new object’s that a function made there can read.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A trait’s fields&lt;/strong&gt; are computed after the superclass’s constructor and the class’s parameters
and before the class body, by the rule in &lt;a href=&quot;#fields&quot;&gt;Fields&lt;/a&gt;: each reads only the fields set
before it and uses &lt;code&gt;self&lt;/code&gt; for nothing else, by the same reasoning as a body before its last field.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;In an &lt;code&gt;object&lt;/code&gt;‘s own body, the object’s name is &lt;code&gt;self&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;Config.port&lt;/code&gt; in a statement before
the last field is a read of a field declared above it or an error, as &lt;code&gt;port&lt;/code&gt; is; in a method, a
lambda or a &lt;code&gt;lazy val&lt;/code&gt;‘s initializer it is the object itself, and it makes the object need
nothing it does not need already, since that code runs only once the object is complete:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object Counter
  val start: int = 1
  lazy val next: int = Counter.start + 1 // runs once `Counter` is complete
  register(() -&amp;gt; Counter.start) // after the last field: `self` may be captured
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; the name and &lt;code&gt;self&lt;/code&gt; are the same object, so they obey the same rule; the
module order needs only what the body runs while the object is made.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;module-level-values&quot;&gt;Module-level values&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Module-level &lt;code&gt;val&lt;/code&gt;s, &lt;code&gt;var&lt;/code&gt;s and &lt;code&gt;object&lt;/code&gt;s initialize before &lt;code&gt;main&lt;/code&gt;, in the order their
initializers depend on one another. An initializer depends on every module value and object it
reads, directly or through the functions it calls and the lambdas it makes; values that need
nothing of one another initialize in declaration order. A dependency cycle is a compile error that
names the chain, not a runtime surprise:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val a = b + 1
val b = readA() * 2 // error: module-level values need one another to initialize: `a` → `b` → `a`
readA() -&amp;gt; int = a
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The order is the program’s, across modules as within one: modules may import one another in a
cycle, and only a cycle of values is an error. A call through a trait or an &lt;code&gt;open&lt;/code&gt; class depends on
every implementation it may reach, and an operator on every method it may call. An object that
extends a class depends on what its superclass’s arguments and constructor read. Making an
object with a &lt;code&gt;lazy val&lt;/code&gt; field depends on nothing its initializer reads, since only a read of
the field runs it; a read does, wherever it is. So two objects whose lazy fields read each other
are no cycle, while one whose body reads its own lazy field depends on what that field reads.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; each value is computed after everything its initializer can read while it
runs, so every such read finds a value. The functions a call reaches are known, since the whole
program is compiled; where a call may reach several, all count. A function value is the one thing
the analysis does not follow to its target, and it need not: a function value exists only once the
initializer that made it has run, and that initializer depends on everything the function reads,
so it ran after all of them, and whatever calls the function later finds them set. The values
&lt;code&gt;main&lt;/code&gt; and the code after it see are all set, since every one is computed before &lt;code&gt;main&lt;/code&gt; starts.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;lazy-val&quot;&gt;lazy val&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;lazy val name = expr&lt;/code&gt;&lt;/strong&gt; (its type optional, as for &lt;code&gt;val&lt;/code&gt;) is computed on its first read instead,
exactly once, and every later read gives the value kept. One that is never read is never
computed. It is declared at module level, in a class or object body, where each instance has its
own, or in a block, as a local; &lt;code&gt;lazy&lt;/code&gt; is a modifier only before &lt;code&gt;val&lt;/code&gt;, and elsewhere an ordinary
name. A &lt;code&gt;lazy var&lt;/code&gt; is an error, since the value is never assigned, and so is one without an
initializer, and &lt;code&gt;lazy&lt;/code&gt; on a parameter, a class parameter or a data field, each of which is given
its value where it is made.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;lazy val table: Vector[string] = loadTable() // read the file when something first needs it

class Report(title: string)
  lazy val heading = s&amp;quot;== $title ==&amp;quot; // per instance, on the instance&apos;s first read

summary(rows: Vector[Row], verbose: bool) -&amp;gt; string
  lazy val detail = rows.map(describe).mkString(&amp;quot;\n&amp;quot;) // only if the branch below reads it
  if verbose then detail else s&amp;quot;${rows.length} rows&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A local &lt;code&gt;lazy val&lt;/code&gt;&lt;/strong&gt; names one value (a pattern that takes a value apart is an error) and is in
scope from its declaration to the end of its block, its own initializer included. Each time the
declaration runs it makes a new value not yet computed, so one in a loop body is a fresh one on
every pass. Its initializer sees the locals around it as they are when it runs, on the first
read, not where it is declared, and its type is its declared one or its initializer’s, which must
be known where it is declared. It is never assigned: an assignment, a compound one or a step is
refused. A closure that reads it captures it and shares it with the code around it: whichever
reads it first computes it, and every other read, in the closure or outside it, gives the value
kept, even after the block that declared it has finished. A closure carried to another thread
carries the initializer with it, so a &lt;code&gt;@sendable&lt;/code&gt; closure may capture a local &lt;code&gt;lazy val&lt;/code&gt; only
where its type is &lt;a href=&quot;/spec/threads/&quot;&gt;sendable&lt;/a&gt; and what its initializer captures and reaches is what
such a closure itself may capture and reach, through every lazy value it reads in turn.&lt;/p&gt;
&lt;p&gt;A module-level &lt;code&gt;lazy val&lt;/code&gt; takes no place in the initialization order: its initializer runs where
it is first read, and an eager value that reads it depends on what that initializer reads. Its
initializer may read every other module-level value. A field’s initializer may read every field
and call every method, since it runs once the object is complete; the class body reads the field
only where it could call a method, after its last field and not at all in an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt;
class. A trap inside an initializer stops the program as any trap does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;lazy val&lt;/code&gt; whose initializer needs its own value is a compile error&lt;/strong&gt; when its own code reaches
the read: directly, through the functions and methods it calls (every implementation a call may
reach, as for module values), or through the initializers of other lazy values it reads. The
error names the chain of lazy values:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;lazy val first: int = second + 1 // error: the `lazy val` `first` needs its own value to initialize: `first` → `second` → `first`
lazy val second: int = later()
later() -&amp;gt; int = first * 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The chain is reported at its earliest-declared member, by module and then by position, and may
run through several modules, as a cycle of module values may. A value that only reaches a chain
without being on it is not named.&lt;/p&gt;
&lt;p&gt;A field’s value is its object’s, so for a field only a read of the same object counts: by bare
name, through &lt;code&gt;self&lt;/code&gt; or a local holding it, in a method called on &lt;code&gt;self&lt;/code&gt; (every override of it a
class descending from the field’s may have), in a function &lt;code&gt;self&lt;/code&gt; is passed to, or through an
operator applied to it. An object has one instance, so for an object’s field every read through
the object’s name counts, wherever the code is. A read of another instance’s field is a
different value, and recursion through a structure is fine:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;class Node(next: Option[Node])
  lazy val depth: int = next match // each node&apos;s own depth
    Some(n) -&amp;gt; n.depth + 1
    None -&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A local &lt;code&gt;lazy val&lt;/code&gt; is held to the same rule, its initializer’s own code being the block’s code
that it runs, the local functions that code calls and the initializers of the other local lazy
values it reads:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;count() -&amp;gt; int
  lazy val n: int = twice() // error: the `lazy val` `n` needs its own value to initialize: `n` → `n`
  twice() -&amp;gt; int = n * 2
  n
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Code the initializer makes and hands on without running it itself (a lambda, an argument passed by
name, a method value) may read the value: that is how a value refers to itself, as a lazy list
whose tail is itself, &lt;code&gt;lazy val ones = LazyList.cons(1, ones)&lt;/code&gt;, or a button whose handler names the
button, do. Such a read finds the value when it runs after the initializer has returned. If it runs
while the initializer is still running, on the thread running it, it traps there:
&lt;code&gt;avin: trap: `first` is read while it is being initialized&lt;/code&gt;. This is initialization’s one check
at run time, and it is made only on the slow path of a first read.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; a lazy value is read only through its initializer’s gate, which either finds the
value stored or runs the initializer, so it is never read unset; the one way it could be needed
before it is stored is a read made while its own initializer runs. Every such read the initializer’s
own code can reach is found by the same reach the module order uses, and is an error; a read made
through a function the initializer handed on is one the compiler cannot place in time, since the
function may run at once or never, and the gate traps on it instead of waiting for itself.&lt;/p&gt;
&lt;p&gt;The first read is safe between threads: when several threads read the value first at once,
exactly one runs the initializer and the others wait for it, &lt;a href=&quot;/spec/threads/&quot;&gt;safe for the collector&lt;/a&gt;,
then all see the same, whole value. A read after the value is stored is one atomic load and a
branch. A trap in the initializer stops the program while the others still wait, so none of them
goes on without the value. The read that traps as needing its own value is one made by the thread
running the initializer, whichever thread that is; a read by any other thread waits. So an
initializer that waits for another thread which reads the same value, through a lambda it handed
that thread, waits for ever, as any threads waiting for each other do (&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;).
Two lazy values whose initializers’ own code needs each other, run on two threads, are a cycle the
compile-time rule reports, so they cannot wait for each other that way.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;locals&quot;&gt;Locals&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A local is in scope from its declaration on, and is given its value there: a lambda or a local
function above it cannot name it, its own initializer included
(&lt;code&gt;val f: () -&amp;gt; int = () -&amp;gt; f()&lt;/code&gt; is an error that &lt;code&gt;f&lt;/code&gt; is not defined).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Local helper functions may call one another in any order, but a call that would read a captured
local before its initialization is rejected.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Why it is sound:&lt;/em&gt; a name that is not in scope cannot be read, and a local function’s captures
are checked at each call against the locals set at that point.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>Settled decisions</title>
    <link href="https://avinlang.dev/spec/decisions/"/>
    <id>https://avinlang.dev/spec/decisions/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Every language and project decision made so far, in one terse list — settled and open.</summary>
    <content type="html">&lt;p&gt;This page is the single record of decisions. A chapter of this specification elaborates each one; when
a decision changes, this page and the chapter change together.&lt;/p&gt;
&lt;h2 id=&quot;settled&quot;&gt;Settled&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Identity and direction&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Avin is a natively compiled, garbage-collected application language with a deliberately small
type system, a rich standard library and ergonomic syntax.&lt;/li&gt;
&lt;li&gt;Its type system, runtime and library are designed together: see &lt;a href=&quot;/spec/design/&quot;&gt;design choices&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Syntax stays very close to Sysl. Where Sysl has no form, this specification defines one in the
same style.&lt;/li&gt;
&lt;li&gt;Execution speed is a primary goal.&lt;/li&gt;
&lt;li&gt;Programs are multi-threaded: threads run in parallel and share one garbage-collected heap.&lt;/li&gt;
&lt;li&gt;Typing is nominal. Classes instantiate objects; there are no duck-typed objects.&lt;/li&gt;
&lt;li&gt;Inference is a useful approximation of Hindley–Milner, not full HM: see
&lt;a href=&quot;/spec/generics/#inference&quot;&gt;inference&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A call’s type argument that nothing at the call decides stays open until the end of the
enclosing function body, settled by the first later use that needs it (a branch it joins, a
store, a use as a value of a known type). If nothing settles it, it is &lt;code&gt;Nothing&lt;/code&gt; where the call
names it only where a value is read out (settled 2026-11-04, below), and an error at the call
otherwise.&lt;/li&gt;
&lt;li&gt;The compiler is written in Sysl. Self-hosting is optional.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The standard library is written in Avin.&lt;/strong&gt; Sysl is reached through
&lt;a href=&quot;/spec/sysl-bindings/&quot;&gt;bindings written in Avin&lt;/a&gt;, which the compiler turns into shims that Sysl
checks. The runtime is written in Sysl.&lt;/li&gt;
&lt;li&gt;The domain is &lt;code&gt;avinlang.dev&lt;/code&gt;. Compiler modules use &lt;code&gt;dev.avinlang.compiler&lt;/code&gt;, and the standard
library uses the reserved root &lt;code&gt;avin&lt;/code&gt;. A library the project publishes outside the core library is
a package in its own repository of the &lt;code&gt;avin-lang&lt;/code&gt; organization, with modules under
&lt;code&gt;dev.avinlang&lt;/code&gt;: parser combinators are &lt;code&gt;github.com/avin-lang/parsing&lt;/code&gt;, module
&lt;code&gt;dev.avinlang.parsing&lt;/code&gt;, written as literate Avin.&lt;/li&gt;
&lt;li&gt;Building the Kutter video editor natively is a long-term application goal.&lt;/li&gt;
&lt;li&gt;Sysl’s Ada-inspired features (contracts and the like) are a long-term direction.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Functions and function types use &lt;code&gt;-&amp;gt;&lt;/code&gt;, never &lt;code&gt;=&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;match&lt;/code&gt; is postfix, with indented &lt;code&gt;pattern -&amp;gt; body&lt;/code&gt; arms.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;data&lt;/code&gt; declares algebraic data types.&lt;/li&gt;
&lt;li&gt;Classes are final unless declared &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt;; overriding requires &lt;code&gt;override&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Inheritance is written with &lt;code&gt;:&lt;/code&gt;: &lt;code&gt;class C(…): Base(…), Trait&lt;/code&gt;, one superclass with its
constructor arguments and then traits, as in &lt;code&gt;trait A: B&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The receiver is implicit: members are in scope by their bare names, and &lt;code&gt;self&lt;/code&gt; names the instance.&lt;/li&gt;
&lt;li&gt;Any method taking one argument can be called infix, &lt;code&gt;a max b&lt;/code&gt; for &lt;code&gt;a.max(b)&lt;/code&gt;, at the caller’s
choice: there is no annotation that permits or forbids it. There is no postfix form.&lt;/li&gt;
&lt;li&gt;An infix call names a method of its receiver’s type, resolved as the dotted call is; it never
falls back to a function &lt;code&gt;m(a, b)&lt;/code&gt;, and a method of two parameters is not called infix with a
tuple. It stays on one line unless the line ends with the method’s name, and then the argument is
the indented block below. Keywords such as &lt;code&gt;then&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt; never name the method.&lt;/li&gt;
&lt;li&gt;A subclass’s constructor evaluates the superclass’s arguments, runs the superclass’s body on the
object, then stores its own parameters and runs its own body. The superclass’s arguments cannot
call a method or use &lt;code&gt;self&lt;/code&gt;; a parameter’s name in them reads the argument.&lt;/li&gt;
&lt;li&gt;A subclass’s fields are its superclass’s, in order, then its own. Fields are never overridden.&lt;/li&gt;
&lt;li&gt;Only public methods can be overridden. An override takes the same parameter types and yields the
same result or a type seen as it with no conversion (covariant results; see the Proposed entry
on override results below). An override cannot be
private. A method with type parameters of its own is overridden by one declaring as many, matched
by position (bounds, once they exist, must match too).&lt;/li&gt;
&lt;li&gt;An abstract method is a method without a body, allowed only in an &lt;code&gt;abstract&lt;/code&gt; class; an abstract
class cannot be instantiated, and every concrete subclass implements each abstract method.&lt;/li&gt;
&lt;li&gt;A call through a receiver whose static type is an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class reaches the override
of the object’s class; a call through a final class’s type, and &lt;code&gt;super.m()&lt;/code&gt;, are direct.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;if&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt; branches yielding different classes join to their nearest common superclass;
where they have none, to the expected type when both conform to it, such as a trait.&lt;/li&gt;
&lt;li&gt;A class implementing a trait’s method marks it &lt;code&gt;override&lt;/code&gt;, whether the trait’s method is abstract
or has a default body, as an override of a superclass’s method is marked. A trait’s methods are
public. A trait may override a default of a trait it requires, marked &lt;code&gt;override&lt;/code&gt; and with a body;
in every type conforming to it, its body replaces the default. Redeclaring a required trait’s
method without &lt;code&gt;override&lt;/code&gt; is an error.&lt;/li&gt;
&lt;li&gt;A class conforms to a trait once: two different type argument lists for one trait, reached by any
paths, are an error. A trait’s own default bodies count as inherited implementations, so a
superclass’s method and a trait’s default of one name, or two traits’ defaults, must be overridden.&lt;/li&gt;
&lt;li&gt;A trait-typed call reaches the implementation through the class’s method table, at a position the
trait has in every conforming class’s table (the whole program is known), so it costs one virtual
call.&lt;/li&gt;
&lt;li&gt;A trait’s abstract &lt;code&gt;val name: T&lt;/code&gt; is supplied by a public field of that name of each conforming
type: a class’s &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; field, own or inherited, or a one-variant &lt;code&gt;data&lt;/code&gt; type’s field through
an impl. A &lt;code&gt;var&lt;/code&gt; field satisfies a &lt;code&gt;val&lt;/code&gt;; a method or a private field does not. Read through the
trait it is a method table entry the compiler fills with a method that loads the field; read
through a class type it is the field. It is never assigned through the trait.&lt;/li&gt;
&lt;li&gt;Traits may hold state (settled, user, 2026-11-04). A trait declares a field with a value,
&lt;code&gt;val name: T = expr&lt;/code&gt; or &lt;code&gt;var name: T = expr&lt;/code&gt;, and every class and object conforming to it stores
one of its own. Through the class’s type it is the class’s field; through the trait, or a type
parameter the trait bounds, it is read and assigned through method table entries the compiler
fills with a method that loads or stores the class’s field. Construction runs the superclass
first, then stores the class’s parameters, then computes the fields of the traits the superclass
does not already conform to, a trait’s required traits before it and each trait once, in the order
of the &lt;code&gt;:&lt;/code&gt; list, then runs the class body. A trait’s field’s value may read the fields initialized
before it and uses &lt;code&gt;self&lt;/code&gt; for nothing else. Only a class or an object conforms to a trait holding
state, or requiring one that does: an impl of it for a &lt;code&gt;data&lt;/code&gt; type, a built-in type or a tuple is an
error. A class declaring a field of a trait field’s name, or conforming to two traits that declare
fields of one name, is an error.&lt;/li&gt;
&lt;li&gt;A trait may re-declare a method of a trait it requires without a body, marked &lt;code&gt;override&lt;/code&gt;, with a
narrower result (settled, user, 2026-11-04): &lt;code&gt;trait SortedMap[K, +V]: Map[K, V]&lt;/code&gt; re-declares
&lt;code&gt;override updated[W &amp;gt;: V](key: K, value: W) -&amp;gt; SortedMap[K, W]&lt;/code&gt;, so a call through the sub-trait
yields the sub-trait. The re-declaration takes the same parameters, type parameters and lower
bounds and yields a result conforming to the overridden one, and shares its position in the method
table, so one implementation serves both traits and must yield the narrowest result. Re-declaring a
method that has a default makes it abstract again in the sub-trait: its implementers give their own.
&lt;a href=&quot;/spec/declarations/#trait&quot;&gt;Declarations&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;An &lt;code&gt;object&lt;/code&gt; may extend an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class, constructed from the top down as a subclass
is, overriding its methods and conforming to it; it implements every abstract member it inherits.&lt;/li&gt;
&lt;li&gt;A trait’s method, or an overridable class method, may have type parameters of its own and be
called dynamically. The whole program is known, so each list of its own type arguments that a call
through a table uses gets a slot of its own in the table of every type implementing the method,
filled with that type’s implementation instantiated at those arguments; such a call also costs one
virtual call.&lt;/li&gt;
&lt;li&gt;An &lt;code&gt;impl&lt;/code&gt; adds methods and conformances, never state. Written in a class’s or an object’s module,
its methods are the class’s own; for a &lt;code&gt;data&lt;/code&gt; or built-in type, or written elsewhere, they are
called directly. Inside them the receiver is
implicit, as in a class, with a one-variant &lt;code&gt;data&lt;/code&gt; type’s fields in scope by bare name.&lt;/li&gt;
&lt;li&gt;The methods of &lt;code&gt;impl Trait for Type&lt;/code&gt; implement the trait’s methods without &lt;code&gt;override&lt;/code&gt;, and each is
a method of the trait or of one it requires. A &lt;code&gt;data&lt;/code&gt; type’s method implementing a trait method is
declared in an impl of that trait.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;data&lt;/code&gt; type conforming to a trait gives every variant’s descriptor the same method table, at the
trait positions classes use, so a trait-typed call costs the same whatever the value is.&lt;/li&gt;
&lt;li&gt;A generic impl of a trait writes the type’s parameters, in order, as its own:
&lt;code&gt;impl[T] Show for Box[T]&lt;/code&gt;. An impl without &lt;code&gt;for&lt;/code&gt; may also name a type built from its parameters
(settled 2026-11-04, below).&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: &lt;a href=&quot;/spec/generics/#bounds&quot;&gt;bounds&lt;/a&gt; are traits or classes, written &lt;code&gt;[T: A &amp;amp; B]&lt;/code&gt;
(spelled &lt;code&gt;+&lt;/code&gt; until the intersection-bounds entry under &lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt; made &lt;code&gt;&amp;amp;&lt;/code&gt; the one
spelling).
A value of a bounded &lt;code&gt;T&lt;/code&gt; has its bounds’ methods, &lt;code&gt;val&lt;/code&gt;s and visible fields, and is a value of
each bound’s type; type arguments are held to their bounds where written and where inferred, and
a bound’s own type arguments are inferred from the argument. A call through a bound is direct in
each instance, and goes through the method table only where the type argument is a trait type or
an open class. An impl’s type parameters take its type’s bounds and write none of their own.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: &lt;code&gt;Self&lt;/code&gt; is written only in a trait’s methods and names the implementing type;
a trait mentioning it, itself or through a trait it requires, is only a bound. In its default
bodies &lt;code&gt;self&lt;/code&gt; is a &lt;code&gt;Self&lt;/code&gt;. A trait type is a type argument for its own bound when it does not
mention &lt;code&gt;Self&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-04 (user): &lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;polymorphic recursion&lt;/a&gt;, a
cycle of generic code whose type arguments grow on every round, is a compile-time error naming
the cycle, through functions, methods, local functions, lambdas and calls through traits and
bounds alike; recursion whose type arguments do not grow is legal. Checking never runs without
end on it.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/spec/generics/#variance&quot;&gt;Variance&lt;/a&gt; applies only where both type arguments are reference types,
so it never converts: &lt;code&gt;List[string]&lt;/code&gt; is a &lt;code&gt;List[Any]&lt;/code&gt;, &lt;code&gt;List[int]&lt;/code&gt; is not. Tuple parts and
function results are covariant and function parameters contravariant on the same terms.&lt;/li&gt;
&lt;li&gt;A variance error is reported in private members as in public ones; there is no escape for a
private &lt;code&gt;var&lt;/code&gt;. The methods an impl adds to a &lt;code&gt;data&lt;/code&gt; type are not variance positions; the traits
its impls name are, except a trait whose members are all static (revised 2026-11-19, below).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;static-traits&lt;/code&gt;): &lt;strong&gt;static members are not
variance positions of a class or &lt;code&gt;data&lt;/code&gt; type, and neither is a conformance to a trait whose
members are all static&lt;/strong&gt; (with those of the traits it requires, at least one); the entry above
read “the traits its impls name are” without exception, which refused &lt;code&gt;abstract class Vector[+T]&lt;/code&gt;
stating &lt;code&gt;impl[T] Buildable[T] for Vector[T]&lt;/code&gt; with &lt;code&gt;static newBuilder() -&amp;gt; Builder[T, Vector[T]]&lt;/code&gt;.
Why it is sound: a static member is reached through a type, never a value. On the type, the call
names the arguments (&lt;code&gt;Vector[Animal].newBuilder()&lt;/code&gt; is that instance’s own impl); through a bound
&lt;code&gt;C: Buildable[A]&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt;‘s own impl at &lt;code&gt;C&lt;/code&gt;‘s own arguments runs, and a &lt;code&gt;Vector[Cat]&lt;/code&gt; is a
&lt;code&gt;Buildable[Cat]&lt;/code&gt;, not a &lt;code&gt;Buildable[Animal]&lt;/code&gt;, so &lt;code&gt;build[Vector[Cat], Animal](dog)&lt;/code&gt; is refused. No
value of the trait exists (a trait with a static member is a bound, not a type), so no value path
from &lt;code&gt;Vector[Cat]&lt;/code&gt; to &lt;code&gt;Buildable[Animal]&lt;/code&gt; exists either. The one path left is a type parameter
bounded by a widened instance, &lt;code&gt;U: Box[Animal]&lt;/code&gt; with &lt;code&gt;U = Box[Cat]&lt;/code&gt;: &lt;strong&gt;a bound whose class or
&lt;code&gt;data&lt;/code&gt; type has a covariant or contravariant parameter reaches neither the type’s static members
nor its conformances to all-static traits&lt;/strong&gt; (&lt;code&gt;U.make(dog)&lt;/code&gt; is an error saying to bound &lt;code&gt;U&lt;/code&gt; by the
trait). Kept as positions: a trait’s own static members (a type conforming to &lt;code&gt;Take[Cat]&lt;/code&gt;
conforms to &lt;code&gt;Take[Animal]&lt;/code&gt; through the trait’s variance, so &lt;code&gt;trait Take[+A]&lt;/code&gt; with &lt;code&gt;static take(x: A)&lt;/code&gt; is refused), a trait requiring an all-static trait, and a conformance to a trait with any
member of a value. Alternatives: exempting every trait’s statics (unsound as shown); exempting
only &lt;code&gt;impl&lt;/code&gt; statics and not the trait argument (still refuses &lt;code&gt;Buildable[T]&lt;/code&gt; on &lt;code&gt;Vector[+T]&lt;/code&gt;);
refusing static calls through every class bound (narrower than needed: an invariant class’s
bound widens nothing). Tests: &lt;code&gt;static_trait_variance&lt;/code&gt;, &lt;code&gt;static_trait_variance_attacks&lt;/code&gt;,
&lt;code&gt;static_trait_variance_kept&lt;/code&gt;, &lt;code&gt;programs/run/static_trait_modules&lt;/code&gt;. Review with the user: the
widening-bound rule is new and visible (“bound &lt;code&gt;U&lt;/code&gt; by the trait declaring &lt;code&gt;make&lt;/code&gt;“).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;static-traits&lt;/code&gt;): &lt;strong&gt;a trait type may implement
a trait whose members are all static, as its own conformance&lt;/strong&gt;: &lt;code&gt;impl[A] Buildable[A] for Set[A]&lt;/code&gt;. It holds of the trait type itself, as the type a call names (&lt;code&gt;Set[int].newBuilder()&lt;/code&gt;) or
a bound’s argument, and is not inherited by the trait’s implementers (a &lt;code&gt;HashSet[A]&lt;/code&gt; has its own
or none) nor reached through a type parameter bounded by the trait type, whose argument may be
any implementer. An impl of a trait with a member of a value for a trait type is still refused
with the old message. Why: a collection literal typed by a trait (&lt;code&gt;val s: Set[int] = {1, 2}&lt;/code&gt;)
needs a builder the trait type names, and a trait’s conformance cannot be its implementers’
(each builds its own collection). It is built on the impls for instances of a type, matched
against the trait type exactly rather than through its subtypes. Alternatives: inheriting it
(wrong: &lt;code&gt;HashSet&lt;/code&gt;‘s literal would build through &lt;code&gt;Set&lt;/code&gt;‘s builder); a companion object’s
&lt;code&gt;newBuilder&lt;/code&gt; reached by name (the convention &lt;code&gt;Buildable&lt;/code&gt; replaces). Tests:
&lt;code&gt;trait_own_static_conformance&lt;/code&gt;, &lt;code&gt;trait_own_static_refusals&lt;/code&gt;, &lt;code&gt;programs/run/static_trait_modules&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A type pattern matches an object whose type conforms to the pattern’s type through variance, as
the checker’s subtyping does: a &lt;code&gt;List[Dog]&lt;/code&gt; held as an &lt;code&gt;Any&lt;/code&gt; matches &lt;code&gt;List[Animal]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04: &lt;a href=&quot;/spec/generics/#lower-bounds&quot;&gt;lower bounds&lt;/a&gt; on a function’s or a
method’s own type parameters, written first: &lt;code&gt;[W &amp;gt;: T]&lt;/code&gt;, &lt;code&gt;[W &amp;gt;: T: Display]&lt;/code&gt;. A lower bound is a
covariant position, so a covariant trait declares &lt;code&gt;put[W &amp;gt;: V](key: K, value: W) -&amp;gt; Bag[K, W]&lt;/code&gt; as
a virtual method; impl methods that are not variance positions are no longer the only way a
covariant type takes its parameter in. A value of the bound is one of the parameter with no
conversion, so a type argument is the bound or a reference type it is seen as. A call infers the
join of the bound and the arguments, &lt;code&gt;Any&lt;/code&gt; where they are references with no nearer common type;
a written or expected type argument is held to the bound (the expected type’s part is refined,
proposed below). An override writes its method’s lower
bound or none. A type’s and an impl’s parameters take none.&lt;/li&gt;
&lt;li&gt;The built-in types belong to the core library’s module, &lt;code&gt;avin&lt;/code&gt;; a conformance of one is written
there or in the trait’s module. An impl that only adds methods may be written in any module
(settled 2026-11-04, below).&lt;/li&gt;
&lt;li&gt;Functions and methods may be overloaded by parameter types. A call takes the most specific
overload that accepts its arguments, chosen at compile time; an ambiguous call is an error.
Same-named declarations with the same parameter types are an error.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/spec/declarations/#functions&quot;&gt;Overloads&lt;/a&gt; are the functions of one name in one scope. A block’s
local functions of a name hide every outer function of that name, whatever their parameter types,
and a program’s own top-level functions hide the prelude’s of the same name.&lt;/li&gt;
&lt;li&gt;A local value (&lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; or a pattern binding) and a local function of the same block may not
share a name, whichever is written first (settled, user, 2026-11-04). In a nested block, a lambda
or as a parameter of the enclosing function, a local may hide an outer local function like any
outer name (settled, user, 2026-11-04).&lt;/li&gt;
&lt;li&gt;Generic local functions (&lt;a href=&quot;/spec/declarations/#functions&quot;&gt;declarations&lt;/a&gt;): a local function’s type
parameters follow the enclosing ones it shares, which its calls never write, so &lt;code&gt;pair[int](1)&lt;/code&gt;
writes only &lt;code&gt;pair&lt;/code&gt;‘s own. A local function’s type parameter may not take the name of one already
in scope rather than hiding it. Written type arguments and those an expected type gives a generic
function used as a value are held to its bounds, as a call’s are (settled, user, 2026-11-04).&lt;/li&gt;
&lt;li&gt;Choosing an overload tries integer literals and lambdas against each candidate’s parameter; every
other argument is checked once on its own, and only its type is tried. A literal fits any
parameter that can hold it.&lt;/li&gt;
&lt;li&gt;An integer literal prefers its own type, &lt;code&gt;int&lt;/code&gt; (or &lt;code&gt;long&lt;/code&gt; for a literal too large for &lt;code&gt;int&lt;/code&gt;), when
that is all that separates the overloads: &lt;code&gt;f(1)&lt;/code&gt; with &lt;code&gt;f(int)&lt;/code&gt; and &lt;code&gt;f(long)&lt;/code&gt;, or with &lt;code&gt;f(int)&lt;/code&gt; and
&lt;code&gt;f(real)&lt;/code&gt;, calls &lt;code&gt;f(int)&lt;/code&gt;. This applies only where no overload is the most specific, and only to an
overload that is also the most specific by the arguments that are not literals; &lt;code&gt;f(1)&lt;/code&gt; with
&lt;code&gt;f(long)&lt;/code&gt; and &lt;code&gt;f(real)&lt;/code&gt; stays ambiguous, and a generic &lt;code&gt;f[T](x: T)&lt;/code&gt; loses to &lt;code&gt;f(x: long)&lt;/code&gt; by
specificity before any literal rule applies.&lt;/li&gt;
&lt;li&gt;A method named without a call, &lt;code&gt;account.deposit&lt;/code&gt;, is a function value bound to its receiver: a
closure holding &lt;code&gt;account&lt;/code&gt;, of the method’s type without the receiver. Inside the class, a bare
method name is the same closure over &lt;code&gt;self&lt;/code&gt;. This holds for a method declared with a parameter
list, &lt;code&gt;()&lt;/code&gt; included; a method declared with none (settled by the user 2026-11-12, below) is called
by its name and has no method value. One declared with an empty list &lt;code&gt;()&lt;/code&gt; is a value only where a
function type is expected (Proposed 2026-11-12, below).&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: a method value evaluates its receiver once, where the value is made. Through a
trait-typed or open-class receiver it calls the implementation the object’s class has, through
the object’s method table at each call; the object is fixed, so this is the implementation it had
when the value was made. The class’s type arguments come from the receiver’s type; a method’s own
are written (&lt;code&gt;box.pair[bool]&lt;/code&gt;) or decided by the expected function type, and one left undecided
is an error. A method value takes every parameter, by-name ones still by name, and private
methods are values only where they could be called. Two values of one method on one object are
two closures, so &lt;code&gt;===&lt;/code&gt; tells them apart.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: &lt;code&gt;loop&lt;/code&gt; is a statement that repeats its indented body (or &lt;code&gt;loop do body&lt;/code&gt; on one
line) until a &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;return&lt;/code&gt; leaves it. &lt;code&gt;loop&lt;/code&gt; is a keyword.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: &lt;code&gt;do … while&lt;/code&gt; tests at the end, so its body runs at least once. The body is an
indented block closed by a line starting &lt;code&gt;while test&lt;/code&gt;, or one statement written &lt;code&gt;do stmt while test&lt;/code&gt;; an optional &lt;code&gt;else&lt;/code&gt; runs when the test fails. &lt;code&gt;break&lt;/code&gt; carries the loop’s value as in
&lt;code&gt;while&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; runs the test, and the test cannot read names the body declared.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;string&lt;/code&gt; is a built-in type, not a class: it is final, has its own representation, gets its
methods from the library through &lt;code&gt;impl string&lt;/code&gt;, conforms to traits through &lt;code&gt;impl&lt;/code&gt;, and is matched
by the type pattern &lt;code&gt;s: string&lt;/code&gt; like any other type.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: the library’s &lt;a href=&quot;/spec/types/#string&quot;&gt;string methods&lt;/a&gt; are &lt;code&gt;byteLength&lt;/code&gt;,
&lt;code&gt;charCount&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;startsWith&lt;/code&gt;, &lt;code&gt;endsWith&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;,
&lt;code&gt;toUpper&lt;/code&gt;, &lt;code&gt;toLower&lt;/code&gt; (named &lt;code&gt;toUpperCase&lt;/code&gt; and &lt;code&gt;toLowerCase&lt;/code&gt; until the Proposed entry on one
family of case names), &lt;code&gt;trim&lt;/code&gt;, &lt;code&gt;strip&lt;/code&gt;, &lt;code&gt;stripLeading&lt;/code&gt;, &lt;code&gt;stripTrailing&lt;/code&gt;, &lt;code&gt;repeat&lt;/code&gt;,
&lt;code&gt;replace&lt;/code&gt; and &lt;code&gt;padTo&lt;/code&gt; beside &lt;code&gt;padStart&lt;/code&gt; and &lt;code&gt;padEnd&lt;/code&gt;, with the reference library’s names (user,
2026-11-04), and, with the reference’s names and behaviour (user, 2026-11-04), &lt;code&gt;stripPrefix&lt;/code&gt;,
&lt;code&gt;stripSuffix&lt;/code&gt;, &lt;code&gt;capitalize&lt;/code&gt; (only a lower-case first character changes), &lt;code&gt;stripMargin&lt;/code&gt; with the
bar or a given margin character (the characters up to U+0020 and the margin removed from each
line’s start, the terminators kept), and &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt; and &lt;code&gt;lastOption&lt;/code&gt; of the
characters, &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; trapping on the empty string. A slice traps at its call when its offsets are out of order or outside the string, or
either falls inside a character; &lt;code&gt;repeat&lt;/code&gt; traps on a negative count. Casing is the simple mapping,
one character for one; stripping removes Unicode &lt;code&gt;White_Space&lt;/code&gt;, and &lt;code&gt;trim&lt;/code&gt;, as the reference’s,
the characters up to U+0020; &lt;code&gt;replace&lt;/code&gt; replaces every occurrence, left to right and not
overlapping, and an empty pattern occurs nowhere. Methods yielding a collection or iterator
(&lt;code&gt;split&lt;/code&gt;, &lt;code&gt;chars&lt;/code&gt;, &lt;code&gt;bytes&lt;/code&gt;) wait for the collections.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: a built-in type’s impl in the core library may declare a method as an
&lt;code&gt;@intrinsic&lt;/code&gt;, whose type takes the receiver first.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03, the searches revised 2026-11-04 by the user: &lt;code&gt;indexOf&lt;/code&gt; (with an optional
starting offset), &lt;code&gt;lastIndexOf&lt;/code&gt; (with an optional last offset), &lt;code&gt;indexWhere&lt;/code&gt; (with an optional
starting offset) and &lt;code&gt;lastIndexWhere&lt;/code&gt; answer a byte offset, -1 when there is none, as the reference
library’s do, and so do a sequence’s &lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;indexWhere&lt;/code&gt;, &lt;code&gt;lastIndexOf&lt;/code&gt; and &lt;code&gt;lastIndexWhere&lt;/code&gt;,
each with the same optional bound; a string’s &lt;code&gt;indexOf&lt;/code&gt; and &lt;code&gt;lastIndexOf&lt;/code&gt; take a &lt;code&gt;char&lt;/code&gt; as well
as a string. Offsets are bytes. A number is read
whole: &lt;code&gt;toInt&lt;/code&gt; and &lt;code&gt;toLong&lt;/code&gt; take an optional &lt;code&gt;+&lt;/code&gt; or &lt;code&gt;-&lt;/code&gt; and ASCII digits, so &lt;code&gt;&amp;quot;+3&amp;quot;&lt;/code&gt; is 3 and
&lt;code&gt;&amp;quot;-0&amp;quot;&lt;/code&gt; is 0, and refuse white space, separators and overflow (&lt;code&gt;&amp;quot;-9223372036854775808&amp;quot;&lt;/code&gt; is a
&lt;code&gt;long&lt;/code&gt;); &lt;code&gt;toReal&lt;/code&gt; is correctly rounded, takes decimal only, and refuses white space, &lt;code&gt;nan&lt;/code&gt;, &lt;code&gt;inf&lt;/code&gt;,
hexadecimal and a value too large to be finite. Revised 2026-11-04 by the user to the reference
library’s: &lt;code&gt;toInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toReal&lt;/code&gt; answer the number and trap on a refusal with
&lt;code&gt;For input string: &amp;quot;…&amp;quot;&lt;/code&gt;, and &lt;code&gt;toIntOption&lt;/code&gt;, &lt;code&gt;toLongOption&lt;/code&gt; and &lt;code&gt;toRealOption&lt;/code&gt; answer &lt;code&gt;None&lt;/code&gt; for it.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-04: the core library follows the reference language’s library in names and
behaviour unless it genuinely improves on it. &lt;code&gt;Option&lt;/code&gt; has &lt;code&gt;isDefined&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt; and &lt;code&gt;nonEmpty&lt;/code&gt;
(not &lt;code&gt;isSome&lt;/code&gt;/&lt;code&gt;isNone&lt;/code&gt;), &lt;code&gt;get&lt;/code&gt; (trapping on &lt;code&gt;None&lt;/code&gt;) and &lt;code&gt;filterNot&lt;/code&gt;; there is no &lt;code&gt;orNull&lt;/code&gt;, since
there is no null. &lt;code&gt;char&lt;/code&gt; has &lt;code&gt;isDigit&lt;/code&gt;, &lt;code&gt;isLetter&lt;/code&gt;, &lt;code&gt;isLetterOrDigit&lt;/code&gt;, &lt;code&gt;isWhitespace&lt;/code&gt;,
&lt;code&gt;isSpaceChar&lt;/code&gt;, &lt;code&gt;isUpper&lt;/code&gt;, &lt;code&gt;isLower&lt;/code&gt;, &lt;code&gt;isControl&lt;/code&gt;, &lt;code&gt;toUpper&lt;/code&gt;, &lt;code&gt;toLower&lt;/code&gt; and &lt;code&gt;asDigit&lt;/code&gt;,
classifying by the Unicode Character Database. &lt;code&gt;isWhitespace&lt;/code&gt; is true for the space separators
except the non-breaking ones (U+00A0, U+2007, U+202F) and for U+0009 to U+000D and U+001C to
U+001F, so it differs from &lt;code&gt;strip&lt;/code&gt;‘s &lt;code&gt;White_Space&lt;/code&gt;; &lt;code&gt;isSpaceChar&lt;/code&gt; is the categories &lt;code&gt;Zs&lt;/code&gt;, &lt;code&gt;Zl&lt;/code&gt; and &lt;code&gt;Zp&lt;/code&gt;.
&lt;code&gt;asDigit&lt;/code&gt; is the digit’s value in radix 36 (Unicode decimal digits give their value, ASCII and
fullwidth letters give 10 to 35) and is -1 for any other character, never a trap.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04 (&lt;a href=&quot;/spec/collections/#maps-and-sets&quot;&gt;collections&lt;/a&gt;): &lt;code&gt;Map[K, +V]&lt;/code&gt; and
&lt;code&gt;Set[A]&lt;/code&gt; are traits, as in the reference library. The hash-based collections are &lt;code&gt;HashMap&lt;/code&gt; and
&lt;code&gt;HashSet&lt;/code&gt;; &lt;code&gt;TreeMap&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt; conform to &lt;code&gt;SortedMap[K, +V]&lt;/code&gt; and &lt;code&gt;SortedSet[A]&lt;/code&gt;, which require
&lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; and re-declare the updating methods with the sorted result. Map and set literals,
&lt;code&gt;Map(…)&lt;/code&gt;, &lt;code&gt;Set(…)&lt;/code&gt;, &lt;code&gt;Map.empty&lt;/code&gt;, &lt;code&gt;Set.empty&lt;/code&gt; and the two builders make the hash-based ones, typed as
the traits; &lt;code&gt;SortedMap&lt;/code&gt; and &lt;code&gt;SortedSet&lt;/code&gt; companions, and a literal where one is expected, make tree
ones. A method putting a value in takes &lt;code&gt;[W &amp;gt;: V]&lt;/code&gt;. An update through a trait answers the same
kind; &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; through the trait answer a hash-based collection. Maps and sets
of different kinds with equal contents are equal, through the traits and &lt;code&gt;Any&lt;/code&gt;, and hash alike. A
map has no &lt;code&gt;mkString&lt;/code&gt; of its own: it joins its entries as pairs, &lt;code&gt;(a, 1)&lt;/code&gt;, through &lt;code&gt;Iterable&lt;/code&gt;‘s.
The ordered operations take the reference library’s names (user, 2026-11-04): &lt;code&gt;headOption&lt;/code&gt; and
&lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;firstKey&lt;/code&gt; and &lt;code&gt;lastKey&lt;/code&gt; (trapping when empty), &lt;code&gt;minAfter(k)&lt;/code&gt; (the
least at least &lt;code&gt;k&lt;/code&gt;), &lt;code&gt;maxBefore(k)&lt;/code&gt; (the greatest less than &lt;code&gt;k&lt;/code&gt;), &lt;code&gt;rangeFrom&lt;/code&gt; and &lt;code&gt;rangeTo&lt;/code&gt;
(inclusive), &lt;code&gt;rangeUntil&lt;/code&gt; (exclusive), &lt;code&gt;range&lt;/code&gt; (from inclusive, until exclusive), &lt;code&gt;iteratorFrom&lt;/code&gt;
(and a map’s &lt;code&gt;keysIteratorFrom&lt;/code&gt; and &lt;code&gt;valuesIteratorFrom&lt;/code&gt;), and &lt;code&gt;reverseIterator&lt;/code&gt;, which the
reference’s sorted collections lack and which is kept; the tree is balanced by weight, each side
at most three times the other.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04: the elementary functions are a module, &lt;code&gt;avin.math&lt;/code&gt; (&lt;a href=&quot;/spec/system-library/#avin-math&quot;&gt;system library&lt;/a&gt;),
with the reference library’s names, called as &lt;code&gt;math.sqrt(x)&lt;/code&gt; after &lt;code&gt;import avin.math&lt;/code&gt; or imported
by name: &lt;code&gt;Pi&lt;/code&gt; and &lt;code&gt;E&lt;/code&gt;; &lt;code&gt;sqrt&lt;/code&gt;, &lt;code&gt;cbrt&lt;/code&gt;, &lt;code&gt;exp&lt;/code&gt;, &lt;code&gt;expm1&lt;/code&gt;, &lt;code&gt;log&lt;/code&gt; (natural), &lt;code&gt;log10&lt;/code&gt;, &lt;code&gt;log1p&lt;/code&gt;, &lt;code&gt;pow&lt;/code&gt;,
&lt;code&gt;hypot&lt;/code&gt;; &lt;code&gt;sin&lt;/code&gt;, &lt;code&gt;cos&lt;/code&gt;, &lt;code&gt;tan&lt;/code&gt;, &lt;code&gt;asin&lt;/code&gt;, &lt;code&gt;acos&lt;/code&gt;, &lt;code&gt;atan&lt;/code&gt;, &lt;code&gt;atan2(y, x)&lt;/code&gt;, &lt;code&gt;sinh&lt;/code&gt;, &lt;code&gt;cosh&lt;/code&gt;, &lt;code&gt;tanh&lt;/code&gt;;
&lt;code&gt;floor&lt;/code&gt;, &lt;code&gt;ceil&lt;/code&gt;, &lt;code&gt;rint&lt;/code&gt; (ties to even), &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt; (NaN when either is, &lt;code&gt;-0.0&lt;/code&gt; below
&lt;code&gt;0.0&lt;/code&gt;), &lt;code&gt;signum&lt;/code&gt;, &lt;code&gt;toRadians&lt;/code&gt; and &lt;code&gt;toDegrees&lt;/code&gt;. All take and give &lt;code&gt;real&lt;/code&gt;, follow IEEE 754 and
never trap: &lt;code&gt;sqrt(-1.0)&lt;/code&gt; is NaN, &lt;code&gt;log(0.0)&lt;/code&gt; negative infinity. Not methods on &lt;code&gt;real&lt;/code&gt;. Settled on
the user’s delegation 2026-11-19: &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;signum&lt;/code&gt; also have &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;
overloads (the only functions here with an integer meaning; &lt;code&gt;math.abs(int.MinValue)&lt;/code&gt; traps as a
negation does, and &lt;code&gt;math.max(1, n)&lt;/code&gt; on an &lt;code&gt;int&lt;/code&gt; &lt;code&gt;n&lt;/code&gt; calls the &lt;code&gt;int&lt;/code&gt; one), written in Avin; the
generic &lt;code&gt;max&lt;/code&gt;/&lt;code&gt;min&lt;/code&gt;/&lt;code&gt;clamp&lt;/code&gt; of &lt;code&gt;ordering&lt;/code&gt; stay for other types and the several-argument form. A
call no overload accepts already names every overload (&lt;code&gt;no overload of &lt;/code&gt;math.max&lt;code&gt; accepts these arguments; the overloads are …&lt;/code&gt;); the two contradictory “expected” errors came from &lt;code&gt;real&lt;/code&gt; being
the only candidate. Branch &lt;code&gt;math-int-overloads&lt;/code&gt;. The reference’s &lt;code&gt;round&lt;/code&gt;, which answers a &lt;code&gt;long&lt;/code&gt;,
is left out until real-to-integer rounding is decided with the conversions. Bindings: one
runtime function per function, over the methods of Sysl’s &lt;code&gt;Float&lt;/code&gt; on &lt;code&gt;real&lt;/code&gt;, since a binding names
a function and these are methods.&lt;/li&gt;
&lt;li&gt;A generic overload is compared by the same rule as any other: &lt;code&gt;f(x: int)&lt;/code&gt; is more specific than
&lt;code&gt;f[T](x: T)&lt;/code&gt;, which accepts an &lt;code&gt;int&lt;/code&gt; while &lt;code&gt;f(int)&lt;/code&gt; does not accept a &lt;code&gt;T&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Whether a parameter is by-name does not distinguish overloads. An argument some candidate takes by
name is delayed; an overload that takes it strictly evaluates it once, at the call.&lt;/li&gt;
&lt;li&gt;An overloaded function used as a value needs an expected function type, which chooses the
overload. &lt;code&gt;main&lt;/code&gt; cannot be overloaded.&lt;/li&gt;
&lt;li&gt;Methods overload by the same rules, among the methods of a name the receiver’s static type has,
inherited ones included. A method is identified by its name and parameter types: an override, a
trait implementation and a method table position each match by both, so a subclass overrides one
overload and inherits the others. &lt;code&gt;override&lt;/code&gt; matching no inherited parameter types is an error.&lt;/li&gt;
&lt;li&gt;A clause is a line of the function’s name and arguments followed by &lt;code&gt;=&lt;/code&gt;, a guard or indented
guards; a line of the same name followed by &lt;code&gt;-&amp;gt;&lt;/code&gt; or nothing is another declaration, so two
abstract overloads may follow each other.&lt;/li&gt;
&lt;li&gt;A class’s parameter list is its one constructor. Class parameters are private immutable fields
(&lt;code&gt;val&lt;/code&gt; makes one public and read-only, &lt;code&gt;var&lt;/code&gt; public and mutable), and the statements in the class
body are the constructor’s code, run top to bottom when an instance is created.&lt;/li&gt;
&lt;li&gt;Inside a class, a local, a parameter or a local function hides a member of the same name, and a
member hides a top-level declaration; &lt;code&gt;self.name&lt;/code&gt; always reaches the member. In the class body,
a class parameter’s name is its field, so it reads what an assignment to a &lt;code&gt;var&lt;/code&gt; stored.&lt;/li&gt;
&lt;li&gt;A private member is private to its class, not to one instance: the class’s constructor and
methods, with the lambdas and local functions in them, may use it on any instance of the class.&lt;/li&gt;
&lt;li&gt;A class body cannot &lt;code&gt;return&lt;/code&gt;. A field declared in the body without a type has its initializer’s.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;Initialization&lt;/a&gt; is checked at compile time. Through the last
field’s initializer, a class or object body uses &lt;code&gt;self&lt;/code&gt; only to read a field already set and to
assign a field: a method call in any spelling (bare name, &lt;code&gt;self.m()&lt;/code&gt;, &lt;code&gt;super.m()&lt;/code&gt;), passing,
storing or returning &lt;code&gt;self&lt;/code&gt;, a method value of &lt;code&gt;self&lt;/code&gt;, and a lambda or local function using a
field or &lt;code&gt;self&lt;/code&gt; are errors.
An &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class’s body runs before its subclasses’ fields are set, so the limits
hold for the whole of it, and it never calls a method a subclass may override.&lt;/li&gt;
&lt;li&gt;An &lt;a href=&quot;/spec/declarations/#object&quot;&gt;object&lt;/a&gt; is made once, before &lt;code&gt;main&lt;/code&gt;; its name is a value of its own
type and cannot be called. It shares its name only with its companion class, whose constructor
the name is in call position, while the bare name and &lt;code&gt;Name.member&lt;/code&gt; are the companion.&lt;/li&gt;
&lt;li&gt;Module-level &lt;code&gt;val&lt;/code&gt;s, &lt;code&gt;var&lt;/code&gt;s and &lt;code&gt;object&lt;/code&gt;s initialize before &lt;code&gt;main&lt;/code&gt;, each after the values its
initializer reads directly or through the functions it calls, the rest in declaration order; a
cycle is a compile error naming the chain.&lt;/li&gt;
&lt;li&gt;Every function declaration parameter has an explicit type.&lt;/li&gt;
&lt;li&gt;A &lt;a href=&quot;/spec/declarations/#default-and-named-arguments&quot;&gt;default argument&lt;/a&gt; is evaluated at each call
that omits it, in the declaring function’s scope, and may use the parameters before it. Named
arguments follow the positional ones, in any order; the arguments written at a call are evaluated
in the order written, then the omitted ones’ defaults in parameter order. Names and defaults belong
to a declaration: a function value is called by position. A variant takes its fields by name too.
The default of a by-name parameter is delayed like any argument to it.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: methods and class constructors take defaults as functions do. A method’s
default sees &lt;code&gt;self&lt;/code&gt;, the receiver’s members and the parameters before it; a constructor’s sees the
parameters before it and no &lt;code&gt;self&lt;/code&gt;. Defaults belong to the method that introduces the parameter:
an override, and a method implementing a trait’s, takes them and may not declare its own, so a
call’s defaults are the same whichever class’s method runs. A trait method’s defaults apply through
the trait’s type. A method of one required parameter and defaults may be called infix.&lt;/li&gt;
&lt;li&gt;A function may be defined by &lt;a href=&quot;/spec/declarations/#clauses&quot;&gt;clauses&lt;/a&gt;: its signature with no body,
then lines &lt;code&gt;f(patterns) = body&lt;/code&gt;, tried in order. A clause is guarded inline,
&lt;code&gt;f(n) | n &amp;gt; 0 = body&lt;/code&gt;, or by an indented block of &lt;code&gt;| condition = body&lt;/code&gt; lines in which &lt;code&gt;| _&lt;/code&gt; always
holds; when every guard fails, the next clause is tried. Clauses must cover every argument, and a
clause counts toward that only through an unguarded body.&lt;/li&gt;
&lt;li&gt;Comparison patterns bind a name or &lt;code&gt;_&lt;/code&gt; beside one literal bound or between two (&lt;code&gt;n &amp;lt; 0&lt;/code&gt;,
&lt;code&gt;0 &amp;lt;= n &amp;lt; 10&lt;/code&gt;), and &lt;code&gt;n + k&lt;/code&gt; matches an integer of at least the positive literal &lt;code&gt;k&lt;/code&gt;, binding the
value minus &lt;code&gt;k&lt;/code&gt;. Both go wherever a pattern does, on integers (comparisons also on bytes and
chars), and they count toward exhaustiveness, as literals and ranges do.&lt;/li&gt;
&lt;li&gt;Variadic parameters are written &lt;code&gt;values: T*&lt;/code&gt;; by-name parameters are written &lt;code&gt;value: -&amp;gt; T&lt;/code&gt;, with no
memoization.&lt;/li&gt;
&lt;li&gt;Blocks yield their last expression. &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; and loop values follow Sysl.&lt;/li&gt;
&lt;li&gt;All of Sysl’s operators are supported, including comparison chains.&lt;/li&gt;
&lt;li&gt;Built-in types are lowercase (&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;iN&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;);
other types are PascalCase; functions and methods are lowerCamelCase. These are conventions, not
syntax rules.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int&lt;/code&gt; is &lt;code&gt;i32&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; is &lt;code&gt;i64&lt;/code&gt;; they are the only integer aliases. Signed integers of any fixed width are available.
There are no unsigned integer types. &lt;code&gt;real&lt;/code&gt; is binary64, and there is no single-precision type.
&lt;code&gt;char&lt;/code&gt; is a Unicode scalar.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;byte&lt;/code&gt; is an octet (0–255) for binary data, with bitwise operations and no arithmetic.&lt;/li&gt;
&lt;li&gt;Integer overflow traps. &lt;code&gt;+%&lt;/code&gt;, &lt;code&gt;-%&lt;/code&gt;, &lt;code&gt;*%&lt;/code&gt; wrap and &lt;code&gt;+|&lt;/code&gt;, &lt;code&gt;-|&lt;/code&gt;, &lt;code&gt;*|&lt;/code&gt; saturate, explicitly.&lt;/li&gt;
&lt;li&gt;A sequence is indexed by calling it: &lt;code&gt;xs(i)&lt;/code&gt;, and &lt;code&gt;xs(i) = v&lt;/code&gt; to assign. Sequences implement
function types, and any library type can implement a function type through &lt;code&gt;apply&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[1, 2]&lt;/code&gt; is an immutable &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;{1, 2}&lt;/code&gt; a &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt; a &lt;code&gt;Map&lt;/code&gt;, unless the expected
type asks for another collection (&lt;code&gt;val b: Buffer[int] = [1, 2]&lt;/code&gt;), which the literal then builds.
&lt;code&gt;{a: 1}&lt;/code&gt; means &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;. &lt;code&gt;{}&lt;/code&gt; is the empty Set and &lt;code&gt;Map.empty&lt;/code&gt; the empty Map.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x :: xs&lt;/code&gt; prepends to an immutable &lt;code&gt;List&lt;/code&gt;, and &lt;code&gt;head :: tail&lt;/code&gt; is a list pattern, for recursive
list code. &lt;code&gt;::&lt;/code&gt; is right-associative.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: &lt;code&gt;List[+T]&lt;/code&gt; is the core library’s &lt;code&gt;data&lt;/code&gt; type with variants &lt;code&gt;Cons(first, rest)&lt;/code&gt;
and &lt;code&gt;Nil&lt;/code&gt;. &lt;code&gt;::&lt;/code&gt; and list patterns always mean the core library’s &lt;code&gt;List&lt;/code&gt;, whatever &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Cons&lt;/code&gt;
or &lt;code&gt;Nil&lt;/code&gt; name where they are written. Every &lt;code&gt;List&lt;/code&gt; method loops rather than recursing, so no
length deepens the stack, and lists compare and hash by contents and order lexicographically when
their elements are ordered.&lt;/li&gt;
&lt;li&gt;Sequences are matched with the brackets that build them: &lt;code&gt;[]&lt;/code&gt; matches any empty sequence and
&lt;code&gt;[a, b]&lt;/code&gt; any sequence of exactly two elements.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Buffer&lt;/code&gt; is the only growable mutable sequence, and &lt;code&gt;Deque&lt;/code&gt; the mutable sequence for both ends.
There is no mutable list type: every collection has a builder, through one library trait, and
&lt;code&gt;List&lt;/code&gt;‘s builder appends in constant time and yields an immutable &lt;code&gt;List&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;..&lt;/code&gt; and &lt;code&gt;..&amp;lt;&lt;/code&gt; expressions construct iterable &lt;code&gt;Range&lt;/code&gt; values.&lt;/li&gt;
&lt;li&gt;An array is made with every element set, by &lt;code&gt;Array.fill(n, value)&lt;/code&gt;, &lt;code&gt;Array.tabulate(n, f)&lt;/code&gt;,
&lt;code&gt;Array.empty()&lt;/code&gt; or &lt;code&gt;Array(a, b, c)&lt;/code&gt; (see “A collection is made by naming its type and listing its
elements” below); Avin has no null, so no array holds an unset element.
&lt;code&gt;xs(i)&lt;/code&gt; calls &lt;code&gt;xs.apply(i)&lt;/code&gt;, &lt;code&gt;xs(i) = v&lt;/code&gt; calls &lt;code&gt;xs.update(i, v)&lt;/code&gt;, and the compound, &lt;code&gt;:=&lt;/code&gt; and &lt;code&gt;++&lt;/code&gt;
forms evaluate &lt;code&gt;xs&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; once. A call with untyped arguments before &lt;code&gt;=&lt;/code&gt; is an assignment, so a
local function’s declaration types its parameters or has none.&lt;/li&gt;
&lt;li&gt;A range’s step is set with &lt;code&gt;by&lt;/code&gt;; a step of zero traps, and iteration never steps past the limit or
the type’s largest or smallest value.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;for&lt;/code&gt; with &lt;code&gt;yield&lt;/code&gt; is comprehension sugar over &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and filtering; a &lt;code&gt;for&lt;/code&gt; without
&lt;code&gt;yield&lt;/code&gt; loops over the source’s iterator.&lt;/li&gt;
&lt;li&gt;The collection hierarchy is rooted at &lt;code&gt;Iterable&lt;/code&gt;, and &lt;code&gt;Iterator&lt;/code&gt; is itself &lt;code&gt;Iterable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;print&lt;/code&gt; and &lt;code&gt;println&lt;/code&gt; are ordinary library functions (settled 2026-11-04). Both take any values, shown as
interpolation shows an &lt;code&gt;Any&lt;/code&gt; (below), and separate several with &lt;code&gt;, &lt;/code&gt;, which is not a tuple; &lt;code&gt;println&lt;/code&gt; ends with a newline and &lt;code&gt;print&lt;/code&gt;
does not. &lt;code&gt;print()&lt;/code&gt; writes nothing and &lt;code&gt;println()&lt;/code&gt; writes a bare newline; &lt;code&gt;eprint&lt;/code&gt; and &lt;code&gt;eprintln&lt;/code&gt; are
the same for standard error. &lt;code&gt;println(debug(x))&lt;/code&gt; selects &lt;code&gt;Debug&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;debug(x)&lt;/code&gt; yields &lt;code&gt;x&lt;/code&gt;‘s &lt;code&gt;Debug&lt;/code&gt; form as a string. &lt;code&gt;Writer&lt;/code&gt; writes strings (with &lt;code&gt;writeChar&lt;/code&gt;,
&lt;code&gt;writeInt&lt;/code&gt;, &lt;code&gt;writeField&lt;/code&gt; and &lt;code&gt;writeSpaces&lt;/code&gt; beside &lt;code&gt;write&lt;/code&gt;); &lt;code&gt;FormatSpec&lt;/code&gt; is &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;precision&lt;/code&gt;
and &lt;code&gt;left&lt;/code&gt;; &lt;code&gt;toString()&lt;/code&gt; is a default body of &lt;code&gt;Display&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-04 (user): a value of &lt;code&gt;Any&lt;/code&gt; or of any trait is shown by the type it has at run time.
&lt;code&gt;Any&lt;/code&gt; and every trait meet &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; whatever they declare, as every type meets &lt;code&gt;Eq&lt;/code&gt;:
such a value meets those bounds, has &lt;code&gt;display&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt; and &lt;code&gt;toString()&lt;/code&gt; and is interpolated, and
renders through its own type’s implementation, found through its type record, so &lt;code&gt;Seq[int]&lt;/code&gt; prints
as the vector it holds. It does not convert to &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; as a value, so a value of either
trait holds only objects that implement it, and is still shown through its method table. A type with no implementation of its own renders as its name (&lt;code&gt;Cat&lt;/code&gt;,
&lt;code&gt;Box[int]&lt;/code&gt;; a function value &lt;code&gt;&amp;lt;function&amp;gt;&lt;/code&gt;), never an address. Static types keep their rule: a
class or data type needs its own &lt;code&gt;Display&lt;/code&gt; to meet the bound or be interpolated, a type parameter
its bound’s. A trait takes no impl of &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt;: its values are shown by their own types,
which keeps one rule.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-04 (user): &lt;code&gt;print&lt;/code&gt;, &lt;code&gt;println&lt;/code&gt;, &lt;code&gt;eprint&lt;/code&gt; and &lt;code&gt;eprintln&lt;/code&gt; are each ONE ordinary
library function taking &lt;code&gt;values: Any*&lt;/code&gt;, with no other overloads, and the compiler treats them as
it treats any function: none, one or several values, several separated by &lt;code&gt;, &lt;/code&gt;. &lt;code&gt;println(1, pet, xs)&lt;/code&gt; with &lt;code&gt;pet: Pet&lt;/code&gt; and &lt;code&gt;xs: Seq[int]&lt;/code&gt;, a function value and a class with no &lt;code&gt;Display&lt;/code&gt; all print,
each shown as that &lt;code&gt;Any&lt;/code&gt; is in an interpolated string (by its type’s own &lt;code&gt;Display&lt;/code&gt;, or its name). A
sequence is one value; only &lt;code&gt;xs*&lt;/code&gt; spreads it, as for any repeated parameter, and then only a
sequence of &lt;code&gt;Any&lt;/code&gt; or of references. As a value &lt;code&gt;println&lt;/code&gt; is a &lt;code&gt;(Vector[Any]) -&amp;gt; unit&lt;/code&gt;. &lt;strong&gt;The cost
is stated plainly: a program that prints through them boxes every number, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; and &lt;code&gt;unit&lt;/code&gt;
argument, makes a vector of the arguments, and gives every type record its rendering entry&lt;/strong&gt;, since
any value may reach &lt;code&gt;Any&lt;/code&gt;‘s rendering; a string or an object is passed as it is. A program that
wants none of that writes to &lt;code&gt;StandardOutput&lt;/code&gt; through a &lt;code&gt;Display&lt;/code&gt; bound.&lt;/li&gt;
&lt;li&gt;A built-in type conforms to a trait through an impl and implements every method of the trait,
since a trait’s default bodies are shared by objects and a built-in value is not one.&lt;/li&gt;
&lt;li&gt;A variant’s fields take defaults, each a function of the fields before it, as a constructor’s
parameters do.&lt;/li&gt;
&lt;li&gt;Avin has Sysl’s full string interpolation and formatting.&lt;/li&gt;
&lt;li&gt;An interpolated string is a method call on &lt;code&gt;StringContext&lt;/code&gt;: &lt;code&gt;p&amp;quot;a $x b&amp;quot;&lt;/code&gt; is
&lt;code&gt;StringContext([&amp;quot;a &amp;quot;, &amp;quot; b&amp;quot;]).p(x)&lt;/code&gt;. &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;raw&lt;/code&gt; are library methods, and a program defines
its own interpolator by implementing a trait for &lt;code&gt;StringContext&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A user-defined interpolator is visible where it is imported (settled by the user, 2026-11-04): in
the module that declares it, in a file importing that module whole, and in a file importing one of
its declarations by name. &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;raw&lt;/code&gt; need no import. A module that merely imports another
does not pass its interpolators on, and using one that is not in scope is an error naming the
module to import.&lt;/li&gt;
&lt;li&gt;Interpolated literals follow Scala’s lexing (settled 2026-11-04). A backslash and a &lt;code&gt;&amp;quot;&lt;/code&gt; or
&lt;code&gt;\&lt;/code&gt; after it are skipped as a pair, so &lt;code&gt;raw&amp;quot;a\&amp;quot;b&amp;quot;&lt;/code&gt; holds &lt;code&gt;a\&amp;quot;b&lt;/code&gt;, &lt;code&gt;raw&amp;quot;a\&amp;quot;&lt;/code&gt; is unterminated and
&lt;code&gt;raw&amp;quot;a\\&amp;quot;&lt;/code&gt; ends, holding two backslashes; &lt;code&gt;$&amp;quot;&lt;/code&gt; is a double quote and &lt;code&gt;$$&lt;/code&gt; a dollar sign in every interpolator. The lexer reads
no escape: a part reaches &lt;code&gt;StringContext&lt;/code&gt; as written, and only &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;f&lt;/code&gt; process escapes, so
&lt;code&gt;p&amp;quot;\d&amp;quot;&lt;/code&gt; is fine and &lt;code&gt;s&amp;quot;\d&amp;quot;&lt;/code&gt; is an error. A backslash is otherwise an ordinary character
(&lt;code&gt;raw&amp;quot;C:\dir&amp;quot;&lt;/code&gt;, &lt;code&gt;\$name&lt;/code&gt; still interpolates).&lt;/li&gt;
&lt;li&gt;Nested helper functions see their enclosing scope. Closures are full closures, and &lt;code&gt;return&lt;/code&gt; inside a
lambda is local to the lambda.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;match&lt;/code&gt; is a value-producing expression with full destructuring.&lt;/li&gt;
&lt;li&gt;A tuple needs no parentheses where it fills the rest of a line: &lt;code&gt;= a, b&lt;/code&gt;, &lt;code&gt;return a, b&lt;/code&gt;, a
block’s line. Bindings take tuples apart (&lt;code&gt;val q, r = divmod(n, d)&lt;/code&gt;), and &lt;code&gt;a, b = b, a&lt;/code&gt; is a
multiple assignment: a statement that makes the whole right side before storing anything, with
compound forms that read every place first. Its places are &lt;code&gt;var&lt;/code&gt; locals, &lt;code&gt;var&lt;/code&gt; fields and module-level
&lt;code&gt;var&lt;/code&gt;s, each field’s object evaluated before anything else.&lt;/li&gt;
&lt;li&gt;Inside brackets whose commas separate items (call arguments, tuple and collection literals), a
&lt;code&gt;return&lt;/code&gt; or &lt;code&gt;break&lt;/code&gt; value stops at the comma, so &lt;code&gt;f(a = return 1, b = 2)&lt;/code&gt; has two arguments; a
parenthesised &lt;code&gt;return 1, 2&lt;/code&gt; is two tuple items, and &lt;code&gt;return (1, 2)&lt;/code&gt; returns a tuple. An indented
block inside the brackets starts a line again, up to a last line that closes the brackets, whose
comma ends the block; a one-line lambda body never takes a comma list.&lt;/li&gt;
&lt;li&gt;Actors are built into the language: &lt;code&gt;actor&lt;/code&gt; declares one.&lt;/li&gt;
&lt;li&gt;State machines are built into the language: &lt;code&gt;machine&lt;/code&gt; declares one, and &lt;code&gt;state&lt;/code&gt; declares each of
its states.&lt;/li&gt;
&lt;li&gt;Slate’s &lt;code&gt;dal&lt;/code&gt; is not part of Avin.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Any&lt;/code&gt; holds a value of any type. A value converts to it at a single site (an argument, a binding,
an assignment, a field, a result, a tuple part written out, a branch expected to yield one), never
inside a container. A string, a tuple and a &lt;code&gt;data&lt;/code&gt; value need no box, being objects whose header
names their type; numbers, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; and &lt;code&gt;unit&lt;/code&gt; are boxed.&lt;/li&gt;
&lt;li&gt;A type pattern &lt;code&gt;x: T&lt;/code&gt; matches a value whose run-time type is &lt;code&gt;T&lt;/code&gt;, a subclass of it or a class
conforming to it, with type arguments compared exactly. One that can never match is an error; one
covers only where the matched value’s type already conforms to &lt;code&gt;T&lt;/code&gt;. In a clause a type pattern
naming the parameter’s own type is an error.&lt;/li&gt;
&lt;li&gt;Every type has &lt;code&gt;==&lt;/code&gt; and a hash. Built-in types, strings, tuples and &lt;code&gt;data&lt;/code&gt; compare and hash by
value; class instances, &lt;code&gt;object&lt;/code&gt;s and closures by identity, which always agree, until the class
implements or derives &lt;code&gt;Eq&lt;/code&gt;. &lt;code&gt;derives Eq, Hash&lt;/code&gt; gives both from the same fields; implementing one
of &lt;code&gt;==&lt;/code&gt; and the hash without the other is an error. Keeping a hand-written pair consistent is the
programmer’s responsibility.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;==&lt;/code&gt; between two values whose static types share no common type is a compile error. On &lt;code&gt;Any&lt;/code&gt; and
on trait-typed values &lt;code&gt;==&lt;/code&gt; is decided at run time through the type’s entries: values of different
run-time types are unequal. &lt;code&gt;===&lt;/code&gt; stays defined only on reference types; where it meets an &lt;code&gt;Any&lt;/code&gt;,
a trait or a type parameter, see the identity entry settled on 2026-11-05.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: the operator traits are the core library’s &lt;code&gt;Eq&lt;/code&gt; (&lt;code&gt;equals(other: Self) -&amp;gt; bool&lt;/code&gt;), &lt;code&gt;Hash&lt;/code&gt; (&lt;code&gt;hash() -&amp;gt; long&lt;/code&gt;), &lt;code&gt;Ord: Eq&lt;/code&gt; (&lt;code&gt;compare(other: Self) -&amp;gt; int&lt;/code&gt;, with &lt;code&gt;less&lt;/code&gt;,
&lt;code&gt;lessOrEqual&lt;/code&gt;, &lt;code&gt;greater&lt;/code&gt; and &lt;code&gt;greaterOrEqual&lt;/code&gt; defaulting from it), and &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Sub&lt;/code&gt;, &lt;code&gt;Mul&lt;/code&gt;, &lt;code&gt;Div&lt;/code&gt;,
&lt;code&gt;Rem&lt;/code&gt; (&lt;code&gt;add&lt;/code&gt;, &lt;code&gt;subtract&lt;/code&gt;, &lt;code&gt;multiply&lt;/code&gt;, &lt;code&gt;divide&lt;/code&gt;, &lt;code&gt;remainder&lt;/code&gt;, each &lt;code&gt;(other: Self) -&amp;gt; Self&lt;/code&gt;) and &lt;code&gt;Neg&lt;/code&gt;
(&lt;code&gt;negate() -&amp;gt; Self&lt;/code&gt;). Every type conforms to &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; implicitly; &lt;code&gt;==&lt;/code&gt; on a type parameter
still needs a bound that is or requires &lt;code&gt;Eq&lt;/code&gt;. The built-in types implement the traits their
operators have, in the core library, and an operator on a built-in type is the machine’s
operation, in generic instances too.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: an impl of a trait may bound the type’s parameters further (&lt;code&gt;impl[T: Ord] Ord for Box[T]&lt;/code&gt;), making the type conform only for type arguments meeting them; on data types and
classes, for any trait.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: a conformance through such an impl to a trait that is also a type holds
wherever one is decided: at conversions (as a covariant type argument too), in type patterns, and
for calls of the trait’s methods, which an instance missing the bounds does not have.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: a generic type’s derived &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; are impls bounding each
parameter by the trait, so they hold where the type arguments implement it.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: arrays compare and hash by contents (&lt;code&gt;===&lt;/code&gt; stays identity); arrays and lists
display as &lt;code&gt;[1, 2, 3]&lt;/code&gt;, their &lt;code&gt;Debug&lt;/code&gt; as &lt;code&gt;[&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;]&lt;/code&gt;, each only when the elements do.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: &lt;code&gt;derives&lt;/code&gt; takes &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;. A class derives
from its constructor parameters, plain, &lt;code&gt;val&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt; alike, and not from fields its body
declares; a data type from each variant’s fields. A class derives &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; together, and
&lt;code&gt;Ord&lt;/code&gt; only with an &lt;code&gt;Eq&lt;/code&gt; by the same fields, derived or its own; a data type has both already, so
deriving them there changes nothing. &lt;code&gt;Display&lt;/code&gt; writes &lt;code&gt;Name(a, b)&lt;/code&gt;, each field in its own &lt;code&gt;Display&lt;/code&gt;
form, and a variant without fields as its name; &lt;code&gt;Debug&lt;/code&gt; writes the same shape with each field’s
&lt;code&gt;Debug&lt;/code&gt;, so strings inside are quoted. A width pads the whole. Deriving a trait the type also
implements, or one a field’s type does not implement, is an error naming the field. A generic data
type’s derived &lt;code&gt;Ord&lt;/code&gt; holds for the type arguments that are ordered; deriving &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt;
on a generic type, and &lt;code&gt;Ord&lt;/code&gt; on a generic class, needs the parameters bounded by the trait where
the type declares them.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: every data type has &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; without &lt;code&gt;derives&lt;/code&gt;, where its fields
have them, conditional on its type arguments as a derived one is; &lt;code&gt;derives Display, Debug&lt;/code&gt; on a
data type means the same. An impl of the type’s own replaces the automatic one, with no conflict.
A field without the trait leaves the type without it, which is an error only where a use needs it,
naming the field. A program that never shows a value compiles none of this code. What &lt;code&gt;derives&lt;/code&gt;
and the automatic impls name are the core library’s traits, whatever the module declares or
imports under the same names.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x.equals(y)&lt;/code&gt; and &lt;code&gt;x.hash()&lt;/code&gt; may be called on a value of any type parameter, bounded or not.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: a type argument a call’s arguments decide is the
&lt;a href=&quot;/spec/generics/#inference&quot;&gt;join&lt;/a&gt; of the types they give it where a value is read out, as two
branches’ types are joined; the first argument does not decide it alone, so &lt;code&gt;cat :: dogs&lt;/code&gt; is a
&lt;code&gt;List[Animal]&lt;/code&gt; with nothing expected. An expected type decides it first; an invariant or
contravariant use decides it for good. Two classes with no common superclass join to the one trait
they share that every other trait they share is a parent of; sharing several unrelated traits is
no join, an error naming them, rather than a choice among them. The same holds for branches.&lt;/li&gt;
&lt;li&gt;Settled 2026-11-03: the names an &lt;a href=&quot;/spec/operators-and-control-flow/#is&quot;&gt;&lt;code&gt;is&lt;/code&gt; pattern&lt;/a&gt; binds are in
scope where its test is known to have matched: the &lt;code&gt;then&lt;/code&gt; branch of an &lt;code&gt;if&lt;/code&gt;, the body of a
&lt;code&gt;while&lt;/code&gt;, the right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, and for &lt;code&gt;is not&lt;/code&gt; the &lt;code&gt;else&lt;/code&gt; branches and the right operand of
&lt;code&gt;||&lt;/code&gt;, with &lt;code&gt;!&lt;/code&gt; swapping the two. After an &lt;code&gt;if&lt;/code&gt; whose one branch never finishes, the rest of the
block sees the other branch’s names. &lt;code&gt;a is P(v) || b is P(v)&lt;/code&gt; binds no &lt;code&gt;v&lt;/code&gt; for the whole. A
condition binds a name once, and its names may shadow the enclosing block’s.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-09: &lt;strong&gt;data updates are written &lt;code&gt;with { … }&lt;/code&gt; with field paths&lt;/strong&gt;
(&lt;a href=&quot;/spec/declarations/#changing-fields-with&quot;&gt;Changing fields&lt;/a&gt;): &lt;code&gt;p with { pos.x = 3, name = &amp;quot;a&amp;quot; }&lt;/code&gt;
is a new value of &lt;code&gt;p&lt;/code&gt;‘s type, each named field replaced and every other one &lt;code&gt;p&lt;/code&gt;‘s; a path rebuilds
only the values along it, a shared prefix once. Paths go through data fields only; a method is
never named; a path named twice, or a field beside a path inside it, is an error; an index is a
syntax error suggesting the whole field; values are read against the leaf field’s type; the base
is evaluated first, then the values left to right; an unknown field is reported with the nearest
one. &lt;code&gt;with&lt;/code&gt; is a keyword only after an operand and before &lt;code&gt;{&lt;/code&gt;, binding as a postfix tail.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-09 (“union types are great”): &lt;strong&gt;limited union types&lt;/strong&gt;
(&lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt;). (1) A union &lt;code&gt;A | B&lt;/code&gt; is written only in annotations: parameters,
results, &lt;code&gt;val&lt;/code&gt;s, fields, type arguments and aliases (&lt;code&gt;type Num = int | long&lt;/code&gt;). (2) It is never
inferred: the branches of an &lt;code&gt;if&lt;/code&gt; or a &lt;code&gt;match&lt;/code&gt; join as before. (3) It compiles to an anonymous
tagged sum. (4) &lt;code&gt;match&lt;/code&gt; takes it apart by type pattern, exhaustively: a member left uncovered is an
error, and &lt;code&gt;_&lt;/code&gt; is allowed. (5) &lt;code&gt;?&lt;/code&gt; combines distinct error types into a union: a function returning
&lt;code&gt;Result[T, IoError | ParseError]&lt;/code&gt; may &lt;code&gt;?&lt;/code&gt; a &lt;code&gt;Result[_, IoError]&lt;/code&gt; and a &lt;code&gt;Result[_, ParseError]&lt;/code&gt;.
Intersection types stay deferred. The further rules are under &lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Project and tooling&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A project lists packages; a package has an &lt;code&gt;avin.hocon&lt;/code&gt; manifest; a module is a directory.&lt;/li&gt;
&lt;li&gt;A program’s root is a directory, and each directory under it is a module named by its path from
the root (&lt;code&gt;a/b&lt;/code&gt; is &lt;code&gt;a.b&lt;/code&gt;). The root directory’s own files are the root module, which has no name
and holds &lt;code&gt;main&lt;/code&gt;; they take no header. Every other file begins with &lt;code&gt;module a.b&lt;/code&gt;, naming the module
its directory makes it part of. A program of one file is compiled alone, and its header, if any,
names its module.&lt;/li&gt;
&lt;li&gt;A module’s files share one namespace: what one declares, every other sees by its bare name, its
&lt;code&gt;private&lt;/code&gt; declarations included. Another module’s declarations are reached only by importing them,
per file: &lt;code&gt;import a.b.X&lt;/code&gt;, &lt;code&gt;import a.b.{X, y as z}&lt;/code&gt;. There is no wildcard import. An unknown
import, an import of a private
declaration and an import of a name the file’s module declares or another import already binds are
errors; an unused import is not.&lt;/li&gt;
&lt;li&gt;A file sees its own module’s declarations, then its imports, then the standard library’s public
declarations in module &lt;code&gt;avin&lt;/code&gt;, which need no import; the nearer hides the farther. Program modules
may not be &lt;code&gt;avin&lt;/code&gt; or under it.&lt;/li&gt;
&lt;li&gt;Modules may import one another in a cycle; module-level values initialize in the order their uses
need across the whole program.&lt;/li&gt;
&lt;li&gt;A class and its companion object are in one module, in any of its files.&lt;/li&gt;
&lt;li&gt;One &lt;code&gt;avin&lt;/code&gt; command does everything: build, run, test, deps and config.&lt;/li&gt;
&lt;li&gt;Testing is built in: &lt;code&gt;@test&lt;/code&gt;, &lt;code&gt;@tests&lt;/code&gt;, setup and teardown, and the built-in runner.
Every feature ships with tests.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin build file.avin&lt;/code&gt; writes &lt;code&gt;./file&lt;/code&gt; by default; &lt;code&gt;-o&lt;/code&gt; overrides it. A failed build leaves
existing output untouched.&lt;/li&gt;
&lt;li&gt;The collector is Sysl’s &lt;code&gt;sh.sysl.gc&lt;/code&gt;, shared with Slate. Its API may change if Slate changes with
it.&lt;/li&gt;
&lt;li&gt;The compiler’s untyped AST, typed HIR, lowered IR and LLVM output are kept as distinct stages.&lt;/li&gt;
&lt;li&gt;A class and its companion object use each other’s private members, in both directions.&lt;/li&gt;
&lt;li&gt;An initializer’s dependencies count every lambda it makes as if it were called, and every function
it calls in full, whatever branch is taken, so a cycle that no run could follow is still rejected.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;concrete-impls&lt;/code&gt;; replaces the
earlier rule that an impl covers every instance of its type): &lt;strong&gt;An impl of a trait may be for an
instance of a generic data type or class&lt;/strong&gt;, &lt;code&gt;impl FromPg for Vector[byte]&lt;/code&gt;, or for a partly applied
one, &lt;code&gt;impl[K] Show for Map[K, int]&lt;/code&gt; or &lt;code&gt;impl[T] Show for Box[Option[T]]&lt;/code&gt;, since the rule for the
concrete case covers those unchanged: the type conforms where it is such an instance, its parts
matched exactly (no variance: a &lt;code&gt;Vector[Nothing]&lt;/code&gt; is not a &lt;code&gt;Vector[byte]&lt;/code&gt; here) and seen through
its superclasses, the impl’s parameters taking the parts and then held to their bounds. Its
members, static ones included, are the type’s at those instances, found by every path that finds
an impl: a call on the value or the type, a call through a bound, a bound held where a type
argument is written, a trait value and its method table, a type pattern on an &lt;code&gt;Any&lt;/code&gt;, and a
template walking a field of that type; a member of the type’s own of the same parameter types is
hidden there. The impl belongs in the module of the type or of the trait, as any impl of a trait
does (the core library’s &lt;code&gt;Vector&lt;/code&gt; takes one in the trait’s module). &lt;strong&gt;No overlap&lt;/strong&gt;: two impls of
one trait may not both hold of any instance, so an instance impl beside the type’s own impl of the
trait is allowed only where the instance misses that impl’s bounds (&lt;code&gt;byte&lt;/code&gt; is no &lt;code&gt;FromPg&lt;/code&gt;), and two
instance impls only where no instance matches both; there is no specialization, no “more specific
wins”. A missed bound keeps the two apart only if it is missed for good: where a module other than
the impl’s own and the core library could still write the impl meeting it, one that names both
the bound and the type without importing a module that imports it, the two overlap and the
diagnostic names that module. A parameter of a partly applied instance may be any type, so it
meets every bound. &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Sendable&lt;/code&gt; and &lt;code&gt;Boundary&lt;/code&gt; are a type’s at every instance alike and
take no instance impl. An instance impl of &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt; for a data type is an impl of the
trait of its own, so the type has no automatic one at its other instances, as with any impl of
the trait. Why: a PostgreSQL client needs &lt;code&gt;bytea&lt;/code&gt; as &lt;code&gt;Vector[byte]&lt;/code&gt; beside a generic
impl for arrays, and every domain with a byte string, a matrix of reals or a map of strings meets
the same need; refusing overlap keeps a conformance one answer everywhere, decided where the impls
are written. Alternatives weighed: specialization, the most specific impl winning (complex, with
unsound corners where a generic body relies on the general impl); a library byte-string type for
&lt;code&gt;bytea&lt;/code&gt; (does not help the next domain); leaving it (forces &lt;code&gt;bytea&lt;/code&gt; through &lt;code&gt;byte: FromPg&lt;/code&gt;, element
by element). Review with the user: whether the core library should stay fixed in the overlap
rule (it could in principle add a conformance later, but it changes with the compiler), and
whether a module of the instance’s arguments should also be allowed to declare such an impl.&lt;/li&gt;
&lt;li&gt;The singleton declaration keeps the keyword &lt;code&gt;object&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A program’s binding shims are one Sysl package that depends on the runtime’s, built into one
archive the program links in place of the runtime’s, so all of a program’s Sysl code shares one
copy of Sysl’s library. The archive is cached by a hash of the shims, the Sysl version and the
runtime’s source.&lt;/li&gt;
&lt;li&gt;A binding is a top-level function. Across the boundary a &lt;code&gt;bool&lt;/code&gt; is a byte and a &lt;code&gt;char&lt;/code&gt; its code
point; &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;Array[byte]&lt;/code&gt; are copied each way.&lt;/li&gt;
&lt;li&gt;A data type mirrors a Sysl enum or struct with &lt;code&gt;@sysl(&amp;quot;module.Name&amp;quot;)&lt;/code&gt; on its declaration. An
enum’s variants are matched by name and their fields by position; a struct is mirrored by one
variant named as the type, whose fields are matched by name. A mirror has no type parameters and
never holds itself. An integer field takes any Sysl integer, converted with a check in each
direction, so a Sysl &lt;code&gt;usize&lt;/code&gt; is mirrored by a &lt;code&gt;long&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-03: &lt;strong&gt;Sysl collections cross the binding boundary as copies.&lt;/strong&gt; A Sysl
slice or &lt;code&gt;Buf&lt;/code&gt; of a boundary type in a result becomes a fresh Avin &lt;code&gt;Vector[T]&lt;/code&gt; (or a fresh
&lt;code&gt;Array[T]&lt;/code&gt;, where the binding declares one); an Avin &lt;code&gt;Array[T]&lt;/code&gt; or &lt;code&gt;Vector[T]&lt;/code&gt; parameter of a
boundary type is copied into a Sysl slice. Collections nest, inside one another, &lt;code&gt;Option&lt;/code&gt;,
&lt;code&gt;Result&lt;/code&gt; and mirrors’ fields. &lt;code&gt;Array[byte]&lt;/code&gt; stays a bulk copy to and from &lt;code&gt;[]u8&lt;/code&gt;. No other Avin
collection crosses.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04: &lt;strong&gt;A Sysl function may fill an Avin array&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#filled-arrays&quot;&gt;Sysl
bindings&lt;/a&gt;). An &lt;code&gt;Array&lt;/code&gt; of &lt;code&gt;byte&lt;/code&gt;, an integer type, &lt;code&gt;real&lt;/code&gt;,
&lt;code&gt;bool&lt;/code&gt; or &lt;code&gt;char&lt;/code&gt; that is a binding’s own parameter (a handle method’s too) is copied into a &lt;code&gt;[]T&lt;/code&gt;
the Sysl function may write, and copied back into the array element by element when it returns;
the shim keeps the array as a root of the thread’s stack from before the call until the copy
back, which runs after the result is made. The representation is a copy, not a view of the
array’s own elements: the collector never moves an object, but a Sysl slice of memory it does
not own has no owner, so a Sysl function that kept it would read freed memory once the call
returned; a copy keeps Avin memory out of Sysl. Every other array crossing into Sysl (of other
elements, or inside an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a collection or a mirror’s field) goes in as a
&lt;code&gt;[]const T&lt;/code&gt;, so a Sysl type that could write into it is refused at the binding instead of
silently losing the writes. A &lt;code&gt;Vector&lt;/code&gt; stays a &lt;code&gt;[]T&lt;/code&gt; copy: it never changes, so nothing is lost.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Option[+T]&lt;/code&gt; and &lt;code&gt;Result[+T, +E]&lt;/code&gt; are &lt;code&gt;data&lt;/code&gt; types of the core library, written in Avin, with
their methods in an &lt;code&gt;impl&lt;/code&gt;. See &lt;a href=&quot;/spec/errors/#option-and-result&quot;&gt;errors&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04 (“follow the reference library”): &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt; and &lt;code&gt;Result&lt;/code&gt;
take lower bounds where the reference library’s methods have them, so a value taken in may be
wider than the one held and the result widens to it: &lt;code&gt;getOrElse[B &amp;gt;: T](default: -&amp;gt; B) -&amp;gt; B&lt;/code&gt;,
&lt;code&gt;orElse[B &amp;gt;: T](other: -&amp;gt; Option[B])&lt;/code&gt;, &lt;code&gt;contains[T1 &amp;gt;: T](x: T1)&lt;/code&gt; and
&lt;code&gt;zip[T1 &amp;gt;: T, U](other: Option[U]) -&amp;gt; Option[(T1, U)]&lt;/code&gt; on &lt;code&gt;Option&lt;/code&gt;; &lt;code&gt;getOrElse[R1 &amp;gt;: R]&lt;/code&gt;,
&lt;code&gt;orElse[L1 &amp;gt;: L, R1 &amp;gt;: R]&lt;/code&gt;, &lt;code&gt;contains[R1 &amp;gt;: R]&lt;/code&gt;, &lt;code&gt;flatMap[L1 &amp;gt;: L, R2]&lt;/code&gt; and
&lt;code&gt;filterOrElse[L1 &amp;gt;: L]&lt;/code&gt; on &lt;code&gt;Either&lt;/code&gt;; &lt;code&gt;getOrElse[U &amp;gt;: T]&lt;/code&gt;, &lt;code&gt;flatMap[U, F &amp;gt;: E]&lt;/code&gt; and
&lt;code&gt;orElse[U &amp;gt;: T, F]&lt;/code&gt; on &lt;code&gt;Result&lt;/code&gt;. On an &lt;code&gt;Option[Cat]&lt;/code&gt;, &lt;code&gt;getOrElse(dog)&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;. This
replaces the earlier reading that the impl’s parameters, not being variance positions, needed no
bound: they still are not, but only a lower bound widens the result. &lt;code&gt;==&lt;/code&gt; compares a value of a
type parameter with one of a parameter it is the lower bound of. &lt;code&gt;joinLeft&lt;/code&gt; and &lt;code&gt;joinRight&lt;/code&gt; keep
their shapes, &lt;code&gt;Either[Either[C, R], R]&lt;/code&gt; and &lt;code&gt;Either[L, Either[L, C]]&lt;/code&gt;, since a method takes one
lower bound per parameter and the reference’s evidence form has no counterpart.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04 (“follow the reference library”): an unknown type argument still
open at the end of its body, that the call’s parameters and result name only where a value is read
out, is &lt;code&gt;Nothing&lt;/code&gt;: &lt;code&gt;None&lt;/code&gt; alone is an &lt;code&gt;Option[Nothing]&lt;/code&gt;, &lt;code&gt;Left(1)&lt;/code&gt; an &lt;code&gt;Either[int, Nothing]&lt;/code&gt;,
&lt;code&gt;Ok(1)&lt;/code&gt; a &lt;code&gt;Result[int, Nothing]&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;Vector.empty()&lt;/code&gt; a &lt;code&gt;Vector[Nothing]&lt;/code&gt;. A later use in the
body still settles it first. A covariant &lt;code&gt;Nothing&lt;/code&gt; argument is any type, a value type’s too, since
no value has it: an &lt;code&gt;Option[Nothing]&lt;/code&gt; is an &lt;code&gt;Option[int]&lt;/code&gt;, in a declared type, an argument and a
type pattern. An unknown named anywhere else (an invariant or contravariant argument, a lambda’s
parameter) or nowhere stays an error asking for the type: &lt;code&gt;Buffer()&lt;/code&gt;, &lt;code&gt;Map.empty()&lt;/code&gt;, &lt;code&gt;{}&lt;/code&gt;. A
&lt;code&gt;Buffer[Nothing]&lt;/code&gt; could hold nothing, and a module’s &lt;code&gt;val b = Buffer()&lt;/code&gt; would only fail later, at
the first store, so the error stays where the type is missing.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04: the core library has &lt;code&gt;Either[+L, +R]&lt;/code&gt;, with &lt;code&gt;Left(value)&lt;/code&gt; and
&lt;code&gt;Right(value)&lt;/code&gt;, because the reference library has it. It follows that library’s &lt;code&gt;Either&lt;/code&gt; in names
and meaning and is right-biased: &lt;code&gt;isLeft&lt;/code&gt;, &lt;code&gt;isRight&lt;/code&gt;, &lt;code&gt;fold&lt;/code&gt;, &lt;code&gt;swap&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;,
&lt;code&gt;getOrElse&lt;/code&gt;, &lt;code&gt;orElse&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;filterOrElse&lt;/code&gt;, &lt;code&gt;toOption&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;,
&lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;iterator&lt;/code&gt;; &lt;code&gt;merge&lt;/code&gt; on &lt;code&gt;Either[A, A]&lt;/code&gt;, &lt;code&gt;joinLeft&lt;/code&gt; and &lt;code&gt;joinRight&lt;/code&gt; on the
nested shapes; &lt;code&gt;Either.cond(test, right, left)&lt;/code&gt;. &lt;code&gt;Option&lt;/code&gt; gains &lt;code&gt;toRight(left)&lt;/code&gt; and
&lt;code&gt;toLeft(right)&lt;/code&gt;. Defaults are by name and take lower bounds as &lt;code&gt;Option&lt;/code&gt;‘s do (above). There is
no left projection (&lt;code&gt;swap&lt;/code&gt; serves), no &lt;code&gt;?&lt;/code&gt; on an &lt;code&gt;Either&lt;/code&gt;, and no conversion between &lt;code&gt;Either&lt;/code&gt; and
&lt;code&gt;Result&lt;/code&gt;, which stays the type for failure. See &lt;a href=&quot;/spec/errors/#either&quot;&gt;errors&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;?&lt;/code&gt; returns from the function or lambda it is written in, so that one’s result type must be
declared or, for a lambda, known where it is written, at least in shape (an &lt;code&gt;Option&lt;/code&gt;, or a &lt;code&gt;Result&lt;/code&gt;
with its error type known; see the &lt;code&gt;lambda-question-shape&lt;/code&gt; entry). It cannot leave a delayed
argument or a class body.&lt;/li&gt;
&lt;li&gt;Builders are the trait &lt;code&gt;Builder[-A, +C]&lt;/code&gt; (&lt;code&gt;addOne&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;, &lt;code&gt;result&lt;/code&gt;, and, as the reference
library’s, &lt;code&gt;clear&lt;/code&gt;, which every builder defines and which readies a spent one for a new
collection, &lt;code&gt;sizeHint&lt;/code&gt;, a hint that changes no result, and &lt;code&gt;knownSize&lt;/code&gt;, -1 where a builder does not
know it cheaply); a collection’s companion
object makes one with &lt;code&gt;newBuilder[T]()&lt;/code&gt; (the reference library’s names, user 2026-11-04), and a sequence literal is built through the expected
collection’s, so a program’s own class with such a companion is written as a literal too. A &lt;code&gt;List&lt;/code&gt;
literal is built from the back with &lt;code&gt;::&lt;/code&gt;, since &lt;code&gt;List&lt;/code&gt; is a data type.&lt;/li&gt;
&lt;li&gt;A collection literal compared with &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt; or an ordering takes the other operand’s type.&lt;/li&gt;
&lt;li&gt;A trap inside the core library, a &lt;code&gt;fail&lt;/code&gt; or a failed check such as an overflow alike, reports the
place where the program last entered the library: the program’s own call, however many library
calls deep the trap is and whether the program reached the library directly, through a method
table or through a function value. No annotation asks for it and no function of the program pays
for it. See &lt;a href=&quot;/spec/errors/&quot;&gt;errors&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Settled by the user on 2026-11-03:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A mirror’s fields are written in Avin’s lowerCamelCase; the compiler matches each to the Sysl
field of the same words in snake_case.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fail(message)&lt;/code&gt; is public in the prelude: it traps with the message at the caller’s place and has
type &lt;code&gt;Nothing&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The methods an &lt;code&gt;impl&lt;/code&gt; adds to a final class whose fields are all immutable are not variance
positions, as a &lt;code&gt;data&lt;/code&gt; type’s are not: such an instance holds nothing a method could store a value
into. A class with a &lt;code&gt;var&lt;/code&gt; field keeps every method a position, and so does an &lt;code&gt;open&lt;/code&gt; or
&lt;code&gt;abstract&lt;/code&gt; class (settled 2026-11-05, below).&lt;/li&gt;
&lt;li&gt;A one-variant &lt;code&gt;data&lt;/code&gt; type may have a companion &lt;code&gt;object&lt;/code&gt;, as a class may: the name in call position
is the constructor and &lt;code&gt;Name.member&lt;/code&gt; the companion (&lt;code&gt;Map.empty&lt;/code&gt;, &lt;code&gt;Map.newBuilder&lt;/code&gt;, &lt;code&gt;List.newBuilder&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;An &lt;code&gt;impl&lt;/code&gt; may add methods for some type arguments only: &lt;code&gt;impl[T: Display] List[T]&lt;/code&gt; gives
&lt;code&gt;mkString&lt;/code&gt; to lists of displayable elements, and calling it on any other list is an error.&lt;/li&gt;
&lt;li&gt;The integers are one family: a closed core trait &lt;code&gt;Integer&lt;/code&gt;, whose members the compiler decides (every
&lt;code&gt;iN&lt;/code&gt;), lets the core library implement a trait once for every width (&lt;code&gt;impl[T: Integer] Display for T&lt;/code&gt;). Such an impl over a bare type parameter is allowed only for closed core traits, in the core
library.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-03: any run of the operator characters &lt;code&gt;+ - * / % &amp;lt; &amp;gt; = ! &amp;amp; | ^ ~ : ?&lt;/code&gt;
that is not one of the language’s operators names a method, declared like any method and called
infix (&lt;code&gt;xs ++ ys&lt;/code&gt;) or dotted (&lt;code&gt;xs.++(ys)&lt;/code&gt;). The language’s operators, including the yielding
compound forms, are not method names: a type has them through their traits, and a method named
&lt;code&gt;+&lt;/code&gt; is an error saying to implement &lt;code&gt;Add&lt;/code&gt;. A symbol call groups left, except that a name ending in
&lt;code&gt;:&lt;/code&gt; groups right with its receiver on the right (&lt;code&gt;x +: xs&lt;/code&gt; is &lt;code&gt;xs.+:(x)&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt; evaluated first).
The level it binds at, and the bitwise operators a type may define, are settled on 2026-11-04.
There are no prefix or postfix symbol methods; &lt;code&gt;++&lt;/code&gt; and &lt;code&gt;--&lt;/code&gt; update when no operand follows on the
line. &lt;code&gt;x op= y&lt;/code&gt; calls the method &lt;code&gt;op=&lt;/code&gt; where &lt;code&gt;x&lt;/code&gt;‘s type has one, and otherwise is the language’s
compound assignment or, for a symbol method &lt;code&gt;op&lt;/code&gt;, &lt;code&gt;x = x op y&lt;/code&gt;. The library uses symbols:
&lt;code&gt;Vector&lt;/code&gt;‘s &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;:+&lt;/code&gt; and &lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;‘s and &lt;code&gt;Map&lt;/code&gt;‘s &lt;code&gt;++&lt;/code&gt;, and a buffer’s &lt;code&gt;+=&lt;/code&gt; and &lt;code&gt;++=&lt;/code&gt; beside
&lt;code&gt;addOne&lt;/code&gt; and &lt;code&gt;addAll&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A module may be named in code through an import of the module itself: &lt;code&gt;import a.b&lt;/code&gt;, then &lt;code&gt;b.X&lt;/code&gt;
reaches &lt;code&gt;a.b&lt;/code&gt;‘s public &lt;code&gt;X&lt;/code&gt;, alongside imports of single declarations.&lt;/li&gt;
&lt;li&gt;An infix method call binds more loosely than arithmetic, bitwise, shift, cons and range operators
and more tightly than comparisons, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt;, and groups to the left, so
&lt;code&gt;xs contains x &amp;amp;&amp;amp; ok&lt;/code&gt; is &lt;code&gt;(xs contains x) &amp;amp;&amp;amp; ok&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A literal pattern does not match an &lt;code&gt;Any&lt;/code&gt; (&lt;code&gt;5 -&amp;gt; …&lt;/code&gt; on an &lt;code&gt;Any&lt;/code&gt; is an error); &lt;code&gt;n: int if n == 5&lt;/code&gt;
says it.&lt;/li&gt;
&lt;li&gt;A tuple’s type at run time is the type it was made with: &lt;code&gt;(animal, 1)&lt;/code&gt; with &lt;code&gt;animal: Animal&lt;/code&gt; is an
&lt;code&gt;(Animal, int)&lt;/code&gt; whatever its class, and a type pattern &lt;code&gt;(Dog, int)&lt;/code&gt; does not match it.&lt;/li&gt;
&lt;li&gt;After its own last field, an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class’s body may call a private method that is
safe: it uses &lt;code&gt;self&lt;/code&gt; only to read and assign fields and to call other safe methods.&lt;/li&gt;
&lt;li&gt;A string’s byte offsets and lengths are &lt;code&gt;int&lt;/code&gt;, and a string holds at most the largest &lt;code&gt;int&lt;/code&gt; bytes.&lt;/li&gt;
&lt;li&gt;A trait’s &lt;code&gt;override&lt;/code&gt; may give an abstract method of a trait it requires a body, not only replace a
default.&lt;/li&gt;
&lt;li&gt;An iterator is &lt;code&gt;hasNext()&lt;/code&gt; and &lt;code&gt;next()&lt;/code&gt;, and &lt;code&gt;next()&lt;/code&gt; on an exhausted iterator traps.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;for&lt;/code&gt; without &lt;code&gt;yield&lt;/code&gt; traverses its source through &lt;code&gt;iterator()&lt;/code&gt; (a range written in place is
counted and an array indexed); &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; leave the body directly. A type
with &lt;code&gt;foreach&lt;/code&gt; and no iterator is not a &lt;code&gt;for&lt;/code&gt; source.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Array.fill(n, value)&lt;/code&gt; evaluates &lt;code&gt;value&lt;/code&gt; once and shares it between the elements; per-element
values come from &lt;code&gt;Array.tabulate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The hash-based maps and sets iterate in an order the program cannot rely on: the immutable ones in
an order fixed by the keys’ hashes alone, so equal maps iterate alike, and the mutable ones in
table order.&lt;/li&gt;
&lt;li&gt;Maps and sets display in the shape of their literals: &lt;code&gt;{a: 1, b: 2}&lt;/code&gt;, &lt;code&gt;{1, 2, 3}&lt;/code&gt;, and &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;
with each part’s &lt;code&gt;Debug&lt;/code&gt;. Mutable maps and sets compare and hash by contents, as arrays do.&lt;/li&gt;
&lt;li&gt;Every &lt;code&gt;data&lt;/code&gt; type may have a companion, not only one-variant ones: an &lt;code&gt;object&lt;/code&gt; named after a data
type of its module is its companion. A variant of the type’s own name stays the constructor in call
position; a type with no such variant (&lt;code&gt;List&lt;/code&gt;) has nothing of its name to call. An object cannot
share its name with a variant of another type, nor with a fieldless variant of its own type’s name.&lt;/li&gt;
&lt;li&gt;A collection literal builds whatever collection is expected through the type’s own conformance to
the core trait &lt;code&gt;Buildable&lt;/code&gt; (the entry of 2026-11-19 on branch &lt;code&gt;builder-trait&lt;/code&gt;): a
sequence literal a sequence, a set literal &lt;code&gt;{a, b}&lt;/code&gt; a set and a map literal &lt;code&gt;{k: v}&lt;/code&gt; a map, giving
the builder each entry as a &lt;code&gt;(key, value)&lt;/code&gt; pair; with no expected collection they are a &lt;code&gt;Vector&lt;/code&gt;, a
&lt;code&gt;Set&lt;/code&gt; and a &lt;code&gt;Map&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The arithmetic traits carry their identities: &lt;code&gt;Add&lt;/code&gt; has &lt;code&gt;zero&lt;/code&gt; and &lt;code&gt;Mul&lt;/code&gt; has &lt;code&gt;one&lt;/code&gt;, so &lt;code&gt;sum&lt;/code&gt; and
&lt;code&gt;product&lt;/code&gt; of an empty collection are those values rather than an &lt;code&gt;Option&lt;/code&gt;. They are written once,
by impls on &lt;code&gt;Iterable&lt;/code&gt; (&lt;code&gt;impl[T: Add] Iterable[T]&lt;/code&gt;, &lt;code&gt;impl[T: Mul] Iterable[T]&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Seq[+T]&lt;/code&gt; is a core trait over &lt;code&gt;Iterable[T]&lt;/code&gt; with two abstract methods, &lt;code&gt;length()&lt;/code&gt; and
&lt;code&gt;apply(index)&lt;/code&gt;; its other methods (&lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;,
the folds, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;indexWhere&lt;/code&gt;, &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;, an
iterator and &lt;code&gt;reverseIterator&lt;/code&gt;) are default bodies written once over those two. &lt;code&gt;head&lt;/code&gt;,
&lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt; and &lt;code&gt;lastOption&lt;/code&gt; are &lt;code&gt;Iterable&lt;/code&gt;‘s own, written over &lt;code&gt;iterator()&lt;/code&gt; for every
collection (user, 2026-11-04, as the reference library has them), and a sequence and a sorted
collection override them to reach the end at once. &lt;code&gt;lift(i)&lt;/code&gt; is the element as an &lt;code&gt;Option&lt;/code&gt;. &lt;code&gt;List&lt;/code&gt; is a &lt;code&gt;Seq&lt;/code&gt;
and overrides every one that would index into it, so none takes more than linear time on a list.
&lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;indexOf&lt;/code&gt;, which take an element, and &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt;, which need
something of the elements, are added to &lt;code&gt;Seq&lt;/code&gt; by impls (&lt;code&gt;impl[T] Seq[T]&lt;/code&gt;, &lt;code&gt;impl[T: Display] Seq[T]&lt;/code&gt;, &lt;code&gt;impl[T: Ord] Seq[T]&lt;/code&gt;), written once for every sequence; &lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;indexOf&lt;/code&gt; are
&lt;code&gt;exists&lt;/code&gt; and &lt;code&gt;indexWhere&lt;/code&gt;, so on a list they walk it once.&lt;/li&gt;
&lt;li&gt;A sequence pattern on a sequence other than a list asks &lt;code&gt;length()&lt;/code&gt; once and then reads, with
&lt;code&gt;apply&lt;/code&gt;, each element whose pattern is not &lt;code&gt;_&lt;/code&gt;, in order, stopping at the first that fails.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Deque[T]&lt;/code&gt; is a ring over an array, doubling when full as a buffer does, its spare places zero
bytes. &lt;code&gt;removeHead()&lt;/code&gt; and &lt;code&gt;removeLast()&lt;/code&gt; return the element and trap on an empty deque, as
&lt;code&gt;Buffer.remove&lt;/code&gt; traps outside the buffer; &lt;code&gt;isEmpty()&lt;/code&gt; is the test before them. Settled 2026-11-04
by the user: a buffer and a deque take the reference library’s names for adding, &lt;code&gt;addOne&lt;/code&gt;,
&lt;code&gt;append&lt;/code&gt;, &lt;code&gt;prepend&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;, &lt;code&gt;appendAll&lt;/code&gt;, &lt;code&gt;prependAll&lt;/code&gt;, &lt;code&gt;insert&lt;/code&gt; and &lt;code&gt;insertAll&lt;/code&gt;, and a deque’s
ends are &lt;code&gt;prepend&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt;, &lt;code&gt;removeHead&lt;/code&gt; and &lt;code&gt;removeLast&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A trait may declare &lt;code&gt;static&lt;/code&gt; members, which belong to the implementing type rather than to a
value: &lt;code&gt;static zero() -&amp;gt; Self&lt;/code&gt; in &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;static one() -&amp;gt; Self&lt;/code&gt; in &lt;code&gt;Mul&lt;/code&gt;. Every impl gives them,
and they are called on a type, &lt;code&gt;int.zero()&lt;/code&gt;, or on a bounded type parameter, &lt;code&gt;T.zero()&lt;/code&gt;. &lt;code&gt;sum()&lt;/code&gt;
and &lt;code&gt;product()&lt;/code&gt; on the collections are written with them. The details of
&lt;a href=&quot;/spec/declarations/#static-members&quot;&gt;static members&lt;/a&gt;: &lt;code&gt;static&lt;/code&gt; is a keyword, written after
&lt;code&gt;private&lt;/code&gt; and before or after &lt;code&gt;override&lt;/code&gt;; a static member is a trait’s, an implementation of one,
or a built-in type’s own (below), and a class or &lt;code&gt;data&lt;/code&gt; type keeps what belongs to the type in its
companion object; in a trait it has no default body, and no trait
overrides one; an implementation is &lt;code&gt;static&lt;/code&gt; exactly where the trait’s member is, an abstract class
giving it too; its body has no &lt;code&gt;self&lt;/code&gt;; a trait’s default body cannot call one on &lt;code&gt;Self&lt;/code&gt;; a trait
with one is a bound and not a type; and a local, parameter, member or module value of a type’s
name hides the type as a receiver.&lt;/li&gt;
&lt;li&gt;Settled by the user 2026-11-04: a built-in type declares
&lt;a href=&quot;/spec/declarations/#static-members-of-built-in-types&quot;&gt;static members of its own&lt;/a&gt;, as &lt;code&gt;static&lt;/code&gt;
members of an impl of the type without a trait (&lt;code&gt;impl string&lt;/code&gt; with
&lt;code&gt;static fromUtf8(bytes: Array[byte]) -&amp;gt; Result[string, Utf8Error]&lt;/code&gt;), for &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;,
&lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt; and each integer type, since a built-in type has no companion object. The
core library declares the built-in types’ own; a program adds them in an extension, as it adds
methods, seen where the module is imported and private to it where marked so. They are called on
the type’s name, never on a value, and their bodies have no &lt;code&gt;self&lt;/code&gt;. A name is a static member or
a method of the type’s values, never both; static members of one name overload by parameter
types; &lt;code&gt;wrap&lt;/code&gt; and the numeric limits (&lt;code&gt;MaxValue&lt;/code&gt;, &lt;code&gt;MinValue&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;‘s &lt;code&gt;NaN&lt;/code&gt; and the rest) are the
language’s and cannot be redeclared. A generic impl, an impl adding to a trait and an impl of a
class or &lt;code&gt;data&lt;/code&gt; type declare no static member of their own. Any static member named on a known
type without a call (&lt;code&gt;string.fromUtf8Lossy&lt;/code&gt;, &lt;code&gt;int.zero&lt;/code&gt;, &lt;code&gt;Point.zero&lt;/code&gt;) is a function value of its
parameters; an overloaded one takes the expected function type’s overload, and without one is an
error. The first use is &lt;code&gt;string.fromUtf8&lt;/code&gt; and &lt;code&gt;string.fromUtf8Lossy&lt;/code&gt;
(&lt;a href=&quot;/spec/types/#strings-from-bytes&quot;&gt;strings from bytes&lt;/a&gt;), bound to Sysl’s UTF-8 decoders, with
&lt;code&gt;Utf8Error(offset: long, truncated: bool)&lt;/code&gt; mirroring Sysl’s error.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;i1&lt;/code&gt; has no &lt;code&gt;1&lt;/code&gt;: &lt;code&gt;i1.one()&lt;/code&gt; is a compile error, and &lt;code&gt;one()&lt;/code&gt; reached at &lt;code&gt;i1&lt;/code&gt; through a generic
traps with “i1 has no 1” at the place the program called, so a generic that passes its bounds
compiles for every type meeting them.&lt;/li&gt;
&lt;li&gt;An &lt;code&gt;impl&lt;/code&gt; may add methods to a trait (&lt;code&gt;impl[T] Seq[T]&lt;/code&gt;, &lt;code&gt;impl[T: Display] Seq[T]&lt;/code&gt;). Its methods
reach the value only through the trait’s own methods, which are variance-checked, so, like the
methods an impl adds to a &lt;code&gt;data&lt;/code&gt; type, they are not variance positions: &lt;code&gt;contains(element: T)&lt;/code&gt;,
&lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; are written once on &lt;code&gt;Seq&lt;/code&gt;, and generic code over &lt;code&gt;Seq[T]&lt;/code&gt;
has them. A call is compiled for the receiver’s static type, so the trait’s methods the added one
calls are that type’s, called directly, and go through the method table only where the receiver
is seen as the trait. Lookup takes the receiver’s type’s own methods first: an added method with
the name and parameter types of one the type has is passed over, so a type keeps a faster version
of its own where its static type is known. Two impls of different traits adding a method of one
name and parameter types to a type conforming to both make a call of it on that type an error; an
impl may not add a method the trait declares.&lt;/li&gt;
&lt;li&gt;The form of a &lt;code&gt;for&lt;/code&gt; with &lt;code&gt;yield&lt;/code&gt; (&lt;a href=&quot;/spec/collections/#generators-guards-and-yield&quot;&gt;for comprehensions&lt;/a&gt;):
generators &lt;code&gt;pattern in source&lt;/code&gt; separated by commas, each followed by any number of &lt;code&gt;if&lt;/code&gt; guards,
then &lt;code&gt;yield&lt;/code&gt; and the value on the rest of the line or in an indented block; or the generators one
to a line in a block after &lt;code&gt;for&lt;/code&gt;, a line starting with &lt;code&gt;if&lt;/code&gt; guarding the generator above, with
&lt;code&gt;yield&lt;/code&gt; on the line after the block. &lt;code&gt;yield&lt;/code&gt; is a keyword. A &lt;code&gt;for&lt;/code&gt; without &lt;code&gt;yield&lt;/code&gt; once kept one
generator and no guards; the entry on loops of several generators below replaces that.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Settled on the user’s delegation 2026-11-19: a &lt;code&gt;for&lt;/code&gt; without &lt;code&gt;yield&lt;/code&gt; takes every clause a
comprehension takes&lt;/strong&gt; (several generators, &lt;code&gt;if&lt;/code&gt; guards after each, value definitions between
them) &lt;strong&gt;and runs as the loops they nest into&lt;/strong&gt; (branch &lt;code&gt;for-forms&lt;/code&gt;). The parser writes it out:
each generator a &lt;code&gt;for&lt;/code&gt; inside the one before, each guard an &lt;code&gt;if&lt;/code&gt; around the rest, each definition
a &lt;code&gt;val&lt;/code&gt; before the rest; so &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; act on the innermost generator’s loop and
&lt;code&gt;return&lt;/code&gt; leaves the function, exactly as the hand-nested form does, and each generator is counted,
indexed or iterated as a loop of its own (no allocation over ranges and arrays). Why: porting
numeric programs hit the one-generator rule five times in four programs, each time with an
obvious meaning; the nested form is the one reading that adds no new semantics. Avin has no loop
labels, so a &lt;code&gt;break&lt;/code&gt; out of every generator is a &lt;code&gt;return&lt;/code&gt; from a local function or a flag, as for
hand-nested loops. Alternatives: keep the rule (pushes the nesting onto every grid and pair loop);
&lt;code&gt;break&lt;/code&gt; leaving the whole &lt;code&gt;for&lt;/code&gt; (a meaning the nested form cannot show, and a &lt;code&gt;continue&lt;/code&gt; would then
want the same, making the two forms differ); a loop over a lazy product (allocates, and loses
per-generator counting). The one-to-a-line block form after &lt;code&gt;for&lt;/code&gt; stays a comprehension’s: &lt;code&gt;do&lt;/code&gt;
on the line after the block would read as a &lt;code&gt;do … while&lt;/code&gt; statement. Review with the user: it
reverses a settled rule, and &lt;code&gt;break&lt;/code&gt; acting on the innermost generator only is the choice to look
at.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Settled on the user’s delegation 2026-11-19: &lt;code&gt;yield&lt;/code&gt; may start a line indented under a
one-line &lt;code&gt;for&lt;/code&gt;‘s clauses&lt;/strong&gt; (branch &lt;code&gt;for-forms&lt;/code&gt;), with its value on the rest of the line or in a
block under it; nothing else may follow it inside that indentation. Why: a function body whose
comprehension’s header fills the line wants its &lt;code&gt;yield&lt;/code&gt; below it, as a continuation line holds an
operator below its expression. &lt;code&gt;do&lt;/code&gt; is not accepted there, since an indented line starting with
&lt;code&gt;do&lt;/code&gt; is already a &lt;code&gt;do … while&lt;/code&gt; statement in a loop’s body, and an indented body needs no &lt;code&gt;do&lt;/code&gt;.
Alternatives: the block form only (&lt;code&gt;for&lt;/code&gt; + clauses one to a line + &lt;code&gt;yield&lt;/code&gt; at &lt;code&gt;for&lt;/code&gt;‘s depth, which
reads poorly for one generator); a general rule continuing any keyword-led line (wider than the
need, and ambiguous with bodies).&lt;/li&gt;
&lt;li&gt;A guard is &lt;code&gt;withFilter&lt;/code&gt;, a lazy view each collection provides; on a source that is no &lt;code&gt;Iterable&lt;/code&gt;
it is &lt;code&gt;Filter&lt;/code&gt;‘s &lt;code&gt;filter&lt;/code&gt; (see the entry on comprehensions by conformance). &lt;code&gt;flatMap&lt;/code&gt; on
the library’s collections takes any &lt;code&gt;Iterable&lt;/code&gt; from its function, or an &lt;code&gt;Option&lt;/code&gt; (see the
entry on &lt;code&gt;flatMap&lt;/code&gt; with options, branch &lt;code&gt;map-flatmap&lt;/code&gt;); a &lt;code&gt;Range&lt;/code&gt; maps to a &lt;code&gt;Vector&lt;/code&gt;;
a &lt;code&gt;Map&lt;/code&gt;‘s entries reach a comprehension as pairs, through &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; overloads taking
a function of one pair, and yield a &lt;code&gt;Map&lt;/code&gt; where they yield pairs, a collection otherwise.&lt;/li&gt;
&lt;li&gt;A generator’s pattern must match every element, as in a &lt;code&gt;for&lt;/code&gt; loop, rather than filtering out the
elements it does not match. &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and &lt;code&gt;?&lt;/code&gt; cannot leave a comprehension’s
guards or yielded value.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Settled by the user on 2026-11-04:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;From[E]&lt;/code&gt; is one generic trait, implemented once per source error type&lt;/strong&gt; by the type the
errors convert to: &lt;code&gt;impl From[IoError] for ConfigError&lt;/code&gt; beside &lt;code&gt;impl From[ParseError] for ConfigError&lt;/code&gt;. A type may implement one generic trait at several type arguments where the trait’s
members are all static and it requires no other trait, as &lt;code&gt;From&lt;/code&gt;‘s one member,
&lt;code&gt;static from(value: E) -&amp;gt; Self&lt;/code&gt;, is; any other trait is implemented once. &lt;code&gt;?&lt;/code&gt; on a &lt;code&gt;Result[U, E]&lt;/code&gt;
in a function yielding &lt;code&gt;Result[T, F]&lt;/code&gt; passes the error on unchanged where &lt;code&gt;E&lt;/code&gt; is an &lt;code&gt;F&lt;/code&gt;, and
otherwise through &lt;code&gt;F.from&lt;/code&gt;: at &lt;code&gt;From[E]&lt;/code&gt;, or else at the one conformance &lt;code&gt;From[X]&lt;/code&gt; with &lt;code&gt;E&lt;/code&gt; an &lt;code&gt;X&lt;/code&gt;
that is more specific than every other such. Neither is an error naming &lt;code&gt;From[E]&lt;/code&gt;; several equally
specific ones are an error naming them. On a type parameter the conformances are its bounds’,
&lt;code&gt;F: From[IoError] &amp;amp; From[ParseError]&lt;/code&gt;. See &lt;a href=&quot;/spec/errors/&quot;&gt;errors&lt;/a&gt; and
&lt;a href=&quot;/spec/declarations/#impl&quot;&gt;declarations&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;One formatting style, applied by &lt;code&gt;avin fmt [--check] [&amp;lt;path&amp;gt;...]&lt;/code&gt; and the language server’s
&lt;code&gt;textDocument/formatting&lt;/code&gt;.&lt;/strong&gt; Each block level is indented two spaces; a literate file keeps its
four-column code-block margin and indents two a level inside it, and only its program is
formatted. Spaces go around binary operators (ranges included, &lt;code&gt;0 ..&amp;lt; n&lt;/code&gt;), &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;-&amp;gt;&lt;/code&gt;, after
&lt;code&gt;,&lt;/code&gt; and &lt;code&gt;:&lt;/code&gt;, and nowhere inside brackets; a prefix operator stays against its operand. At most
one blank line in a row, none at either end of the file, and one between two top-level
declarations unless both are one line; a declaration’s comments and annotations stay with it,
and a function’s clauses are one declaration with its signature, no blank line among them
(Proposed, under &lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt;).
Comments are kept exactly, a trailing one a space after the code. A line longer than 120
characters has a list broken one item per line, a call’s or a literal’s items two columns in and
a parameter list’s four, the closing bracket on its own line; a list the source wrote one item
per line stays so, except that a broken sequence or set literal of short, simple items is filled
as many to a line as fit (Proposed, under &lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt;); a binding’s value with no list to break is broken before its loosest operators
as continuation lines, though only after the last &lt;code&gt;then&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt; of a one-line &lt;code&gt;if&lt;/code&gt;
(a line after an &lt;code&gt;if&lt;/code&gt;‘s test is its block, so a test and an earlier branch stay whole). No trailing commas are added. The formatter keeps every token and
refuses a file that does not parse; its result parses to the same syntax tree.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;compareAndSet&lt;/code&gt; on a value without identity&lt;/strong&gt; — a data value, tuple, string, &lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Any&lt;/code&gt; —
&lt;strong&gt;compares with &lt;code&gt;==&lt;/code&gt;; on scalars and references it compares the word.&lt;/strong&gt; A class instance (even of
a class that derives &lt;code&gt;Eq&lt;/code&gt;) and a function value keep identity. See
&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;Vector[+T]&lt;/code&gt; is a persistent, radix-balanced tree of arrays of 32&lt;/strong&gt;, with a prefix and a suffix
beside a balanced middle at every level, and stays the default sequence (&lt;code&gt;[1, 2]&lt;/code&gt;, &lt;code&gt;[]T&lt;/code&gt;,
&lt;code&gt;main(args)&lt;/code&gt;). Indexing and &lt;code&gt;updated&lt;/code&gt; take one array per level, at most six; &lt;code&gt;:+&lt;/code&gt; and &lt;code&gt;+:&lt;/code&gt; take
amortized constant time; slicing, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt; and their kin take time in the depth and share
every array they do not cut; &lt;code&gt;++&lt;/code&gt; takes time in the shorter operand. A vector’s arrays are
exactly sized and never written once they are in a tree. The one-array immutable sequence
remains as &lt;strong&gt;&lt;code&gt;ArraySeq[+T]&lt;/code&gt;&lt;/strong&gt;, for elements built once and then read, with no level between an
index and its element; every changed &lt;code&gt;ArraySeq&lt;/code&gt; is a copy. Every collection has &lt;code&gt;toArraySeq()&lt;/code&gt;.
See &lt;a href=&quot;/spec/collections/#vector&quot;&gt;collections&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An impl that only adds methods may be written in any module&lt;/strong&gt; (a relaxed impl); in another module
than its type’s or trait’s it is an &lt;a href=&quot;/spec/declarations/#extensions&quot;&gt;extension&lt;/a&gt;: &lt;code&gt;impl string&lt;/code&gt;,
&lt;code&gt;impl[T: Ord] Seq[T]&lt;/code&gt;, &lt;code&gt;impl[T] Option[Option[T]]&lt;/code&gt;, &lt;code&gt;impl Box&lt;/code&gt; for another module’s class. Its
methods are seen in its own module and in every file importing that module, whole or any
declaration of it, with no further step; a file importing neither does not see them, and the
core library’s are seen everywhere. A type’s own methods are found first: an extension method a
type’s own or inherited method of the same name and parameter types always hides is an error at
its declaration, and one added to a trait is passed over for a type that has such a method. Two
seen extensions of different modules adding one name and parameter types to a receiver make the
call an error naming both modules. An extension’s &lt;code&gt;private&lt;/code&gt; methods are private to its module. Its
methods reach no private member of another module’s type, are in no method table and are not
overridden; &lt;code&gt;self&lt;/code&gt; is the receiver and the type’s public fields and methods are in scope by bare
name. Infix calls, method values and calls through a bound see extensions as dotted calls do,
a bound’s where the generic function is written. Conformances, &lt;code&gt;impl Trait for Type&lt;/code&gt;, stay in the
module of the type or of the trait.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sequences, sets and maps are functions, by subtyping.&lt;/strong&gt; &lt;code&gt;Seq[+T]&lt;/code&gt; is a subtype of &lt;code&gt;(int) -&amp;gt; T&lt;/code&gt;,
through its &lt;code&gt;apply(index)&lt;/code&gt;; &lt;code&gt;Set[A]&lt;/code&gt;, immutable and mutable, of &lt;code&gt;(A) -&amp;gt; bool&lt;/code&gt;; &lt;code&gt;Map[K, V]&lt;/code&gt;,
immutable and mutable, of &lt;code&gt;(K) -&amp;gt; V&lt;/code&gt;, whose &lt;code&gt;apply&lt;/code&gt; traps on a missing key as &lt;code&gt;m(k)&lt;/code&gt; does. A
collection is passed, stored and called where its function type is expected with no conversion,
and variance holds through it: a &lt;code&gt;Vector[Dog]&lt;/code&gt; is an &lt;code&gt;(int) -&amp;gt; Animal&lt;/code&gt;. For a set &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;s(x)&lt;/code&gt; is
legal: &lt;code&gt;true&lt;/code&gt; when &lt;code&gt;x&lt;/code&gt; is an element of &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; otherwise, the set’s &lt;code&gt;apply(x) -&amp;gt; bool&lt;/code&gt;,
which is &lt;code&gt;contains&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A class or trait names a function type among its parents after &lt;code&gt;:&lt;/code&gt; (&lt;code&gt;trait Seq[+T]: Iterable[T], (int) -&amp;gt; T&lt;/code&gt;), and a data type or class through an impl with no bounds of its own (&lt;code&gt;impl[K, V] (K) -&amp;gt; V for Map[K, V]&lt;/code&gt;), in the type’s own module. The type then has an &lt;code&gt;apply&lt;/code&gt; taking exactly that
type’s parameters and yielding its result or a subtype; &lt;code&gt;apply&lt;/code&gt; implements no trait method, so it
is not marked &lt;code&gt;override&lt;/code&gt; for it. A type is at most one function type, counting those of its
superclass and its traits, and its parameters keep their variance there. A built-in type is no
function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A function type with one parameter is written without parentheses: &lt;code&gt;int -&amp;gt; string&lt;/code&gt;,
&lt;code&gt;Option[T] -&amp;gt; bool&lt;/code&gt;. &lt;code&gt;-&amp;gt;&lt;/code&gt; in a type groups to the right, so &lt;code&gt;int -&amp;gt; int -&amp;gt; int&lt;/code&gt; is
&lt;code&gt;int -&amp;gt; (int -&amp;gt; int)&lt;/code&gt;; &lt;code&gt;(A) -&amp;gt; B&lt;/code&gt; is the same type as &lt;code&gt;A -&amp;gt; B&lt;/code&gt;, &lt;code&gt;(A, B) -&amp;gt; C&lt;/code&gt; takes two
parameters, a function taking one tuple is &lt;code&gt;((A, B)) -&amp;gt; C&lt;/code&gt;, and a function taking a function is
&lt;code&gt;(int -&amp;gt; int) -&amp;gt; int&lt;/code&gt;. A function type needs no parentheses in a parameter, field, result,
type argument, tuple part or &lt;code&gt;val&lt;/code&gt; annotation, nor as a supertype; a type pattern in a &lt;code&gt;match&lt;/code&gt;
arm still writes it in parentheses, since the arm’s own &lt;code&gt;-&amp;gt;&lt;/code&gt; follows it. Error messages print
every function type with a parameter list, &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;main&lt;/code&gt; is &lt;code&gt;main()&lt;/code&gt; or &lt;code&gt;main(args: Vector[string])&lt;/code&gt;, the arguments after the program’s name, the
same as &lt;code&gt;avin.process.args()&lt;/code&gt;. The parameter is exactly &lt;code&gt;Vector[string]&lt;/code&gt; (a name for that type
is the same type; &lt;code&gt;Seq[string]&lt;/code&gt; and &lt;code&gt;Array[string]&lt;/code&gt; are errors), it has no default, and any other
parameter list is an error naming the two forms. The result rules are unchanged. A program built
for its tests does not run &lt;code&gt;main&lt;/code&gt;, so tests see no arguments.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A &lt;code&gt;match&lt;/code&gt; with nothing before it is a &lt;a href=&quot;/spec/operators-and-control-flow/#match-functions&quot;&gt;function literal&lt;/a&gt;
of one value, whose arms are ordinary &lt;code&gt;match&lt;/code&gt; arms: &lt;code&gt;xs.collect(match Some(n) -&amp;gt; n)&lt;/code&gt;, one arm on
the &lt;code&gt;match&lt;/code&gt; line, or an indented block of them, inside parentheses or after an infix method’s
name. Its parameter type comes from the expected type, as a lambda’s does, and with none it is an
error. Where &lt;code&gt;A -&amp;gt; B&lt;/code&gt; is expected its arms must cover every &lt;code&gt;A&lt;/code&gt;; where &lt;code&gt;PartialFunction[A, B]&lt;/code&gt; is
expected they need not. &lt;code&gt;PartialFunction[-A, +B]&lt;/code&gt; is a core-library trait with &lt;code&gt;isDefinedAt&lt;/code&gt;, a
call that traps at the program’s call site outside its domain, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;orElse&lt;/code&gt; and
&lt;code&gt;applyOrElse&lt;/code&gt;; a literal tests its patterns and guards once per call, &lt;code&gt;lift&lt;/code&gt; or &lt;code&gt;applyOrElse&lt;/code&gt;.
Every collection with &lt;code&gt;map&lt;/code&gt; has &lt;code&gt;collect&lt;/code&gt;, every &lt;code&gt;Iterable&lt;/code&gt; has &lt;code&gt;collectFirst&lt;/code&gt;, and &lt;code&gt;Option&lt;/code&gt; has
&lt;code&gt;collect&lt;/code&gt;. A &lt;code&gt;PartialFunction[A, B]&lt;/code&gt; is a subtype of &lt;code&gt;A -&amp;gt; B&lt;/code&gt;, through its &lt;code&gt;apply&lt;/code&gt;, so it passes
wherever one is expected and traps there outside its domain.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;[]T&lt;/code&gt; in a type position means exactly &lt;code&gt;Vector[T]&lt;/code&gt;: &lt;code&gt;xs: []int&lt;/code&gt;, &lt;code&gt;[][]int&lt;/code&gt;, &lt;code&gt;Option[[]string]&lt;/code&gt;,
&lt;code&gt;main(args: []string)&lt;/code&gt;. Its element is a name or a parenthesized type, so &lt;code&gt;[]int -&amp;gt; int&lt;/code&gt; is a
function from a vector and &lt;code&gt;[](int -&amp;gt; int)&lt;/code&gt; a vector of functions. A type pattern takes it
without parentheses, &lt;code&gt;v: []int -&amp;gt; body&lt;/code&gt;. There is no fixed-length &lt;code&gt;[N]T&lt;/code&gt; (an error); error
messages print &lt;code&gt;Vector[int]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The thread model (&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;): &lt;code&gt;avin.threads.spawn(body)&lt;/code&gt; starts a closure on a
new thread with an 8 MiB stack and &lt;code&gt;join()&lt;/code&gt; gives back its result; a structured &lt;code&gt;scope&lt;/code&gt; joins
every thread started in it; a trap in any thread stops the program, and the program ends when
&lt;code&gt;main&lt;/code&gt; returns. The heap, module-level values and captured &lt;code&gt;var&lt;/code&gt;s are shared. The library offers
&lt;code&gt;Mutex[T]&lt;/code&gt; owning its value, &lt;code&gt;Condition&lt;/code&gt;, sequentially consistent &lt;code&gt;Atomic[T]&lt;/code&gt;, &lt;code&gt;Channel[T]&lt;/code&gt; and
&lt;code&gt;Once&lt;/code&gt;, and every wait marks its thread safe for the collector. A data race is not undefined
behaviour: heap fields and module-level variables are accessed with LLVM’s &lt;code&gt;unordered&lt;/code&gt; ordering,
so a racing read sees some value written to that word, and a constructor ends with a release
fence, so no thread sees an object without its header and constructor-set fields. Actors are
scheduled onto a pool of these threads.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Details of starting and joining: &lt;code&gt;spawn&lt;/code&gt; gives back a &lt;code&gt;Thread[T]&lt;/code&gt; whose &lt;code&gt;join()&lt;/code&gt; any thread may
call, any number of times and at once; one waits for the thread and the others for that wait. A
thread’s handle is collected like any object once nothing reaches it; a thread never joined keeps
its stack until the program ends. &lt;code&gt;s.spawn&lt;/code&gt; is called by the thread running the scope’s body
while the scope is open, and anything else traps, so the scope sees every thread it has to join;
a thread the scope started starts more through a scope of its own. When several threads trap at
once, or one traps while another calls &lt;code&gt;exit&lt;/code&gt;, only the first stops the program: its output is
flushed once and its reason is the one reported.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/spec/declarations/#repeated-parameters&quot;&gt;Repeated parameters&lt;/a&gt;: &lt;code&gt;values: T*&lt;/code&gt; is the last
parameter, at most one, named, with no default and not by-name; inside the function it is a
&lt;code&gt;Vector[T]&lt;/code&gt;. A call gives it every positional argument from its position on, each checked
against &lt;code&gt;T&lt;/code&gt; (so generic &lt;code&gt;T&lt;/code&gt; is inferred from them), or splices one &lt;code&gt;Iterable[T]&lt;/code&gt; with &lt;code&gt;xs*&lt;/code&gt; as
its only argument, written last: a &lt;code&gt;Vector[T]&lt;/code&gt; is passed as it is, any other sequence copied.
&lt;code&gt;f(1, xs*)&lt;/code&gt; into the one parameter, &lt;code&gt;xs*&lt;/code&gt; anywhere else, and naming the repeated parameter are
errors. A function with one, used as a value, has the type &lt;code&gt;(…, Vector[T]) -&amp;gt; R&lt;/code&gt;. A method
overriding or implementing another repeats the same parameter or neither does; &lt;code&gt;main&lt;/code&gt; takes
none; &lt;code&gt;data&lt;/code&gt; fields cannot be repeated. A method whose only required parameter precedes a
repeated one is called infix with one argument.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An impl without &lt;code&gt;for&lt;/code&gt; adds methods to any type built from its parameters
(&lt;a href=&quot;/spec/declarations/#impl&quot;&gt;declarations&lt;/a&gt;): &lt;code&gt;impl[T] Option[Option[T]]&lt;/code&gt;,
&lt;code&gt;impl[A, B] Pair[A, List[B]]&lt;/code&gt;, &lt;code&gt;impl[T] Seq[Seq[T]]&lt;/code&gt;, &lt;code&gt;impl[K, V] Iterable[(K, V)]&lt;/code&gt;. Every
parameter must appear in the type. A call matches the receiver’s static type against it,
seeing a reference through its traits and superclasses only at covariant parts, and holds the
learned parameters to the impl’s bounds; a receiver that does not match is an error saying what
it would need to be. Two impls that both match a receiver and add a method of one name and
parameter types make the call an error, as does such a method clashing with the type’s own. An
impl of a trait for such a type is an impl for instances of it, whose overlap with another impl of
the trait is an error (see the impl for instances of a generic type, 2026-11-15). The
core library adds &lt;code&gt;flatten&lt;/code&gt; to &lt;code&gt;Option[Option[T]]&lt;/code&gt;, &lt;code&gt;Result[Result[T, E], E]&lt;/code&gt; and &lt;code&gt;Seq[Seq[T]]&lt;/code&gt;
(a &lt;code&gt;Vector[T]&lt;/code&gt;), &lt;code&gt;toMap()&lt;/code&gt; to &lt;code&gt;Iterable[(K, V)]&lt;/code&gt; (keys bounded as a map’s) and &lt;code&gt;unzip()&lt;/code&gt; to
&lt;code&gt;Seq[(A, B)]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A heap field or module variable wider than 64 bits is accessed as untorn 64-bit words: a racing
read of it may combine words of different writes (&lt;a href=&quot;/spec/threads/#the-memory-model&quot;&gt;threads&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Details of &lt;a href=&quot;/spec/threads/#synchronization&quot;&gt;synchronization&lt;/a&gt;: &lt;code&gt;Mutex[T].with&lt;/code&gt; hands its body the
value itself, and an immutable value is read with &lt;code&gt;get&lt;/code&gt;, replaced with &lt;code&gt;set&lt;/code&gt; and changed with
&lt;code&gt;update(f)&lt;/code&gt; under the lock. A mutex is not reentrant, and a thread taking one it already holds
traps rather than waiting for ever; otherwise only a deadlock of the whole program is detected
(&lt;a href=&quot;/spec/threads/#deadlock&quot;&gt;diagnostics&lt;/a&gt;). A &lt;code&gt;Condition&lt;/code&gt; is made by its
mutex’s &lt;code&gt;condition()&lt;/code&gt;, so it is waited for with that mutex only, and &lt;code&gt;wait()&lt;/code&gt; from a thread not
holding it traps. &lt;code&gt;Atomic[T]&lt;/code&gt; holds any type: a value of one word lock-free, an integer wider
than 64 bits under one runtime lock; &lt;code&gt;compareAndSet&lt;/code&gt; compares identity for a reference and the
bits for a real; &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; give back the new value and trap on overflow before storing, and
&lt;code&gt;update(f)&lt;/code&gt; retries &lt;code&gt;f&lt;/code&gt; until its compare-and-set succeeds. &lt;code&gt;Channel[T](capacity = unbounded)&lt;/code&gt; is
unbounded with no capacity, a rendezvous at zero (Proposed below, which replaced unbounded at
zero), and a negative capacity traps; a send to a closed channel traps, closing twice
does nothing, and a channel is &lt;code&gt;Iterable&lt;/code&gt;, receiving until it is closed and drained. &lt;code&gt;Once.run&lt;/code&gt;
makes every other caller wait for the running body; a body running its own &lt;code&gt;Once&lt;/code&gt; again traps.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/spec/operators-and-control-flow/#trailing-blocks&quot;&gt;Trailing blocks&lt;/a&gt;: an indented block on the
lines after a call is the call’s last argument, given to the callee’s last parameter. A by-name
parameter takes the block as its delayed expression (&lt;code&gt;retry(3)&lt;/code&gt; + block); a function parameter
takes a lambda whose parameters end the call’s line, one name or a parenthesized list after
the call’s parentheses (&lt;code&gt;withFile(path) f -&amp;gt;&lt;/code&gt;, &lt;code&gt;zipWith(a, b) (x, y) -&amp;gt;&lt;/code&gt;). A callee with no
other arguments is written without parentheses (&lt;code&gt;scope s -&amp;gt;&lt;/code&gt;, &lt;code&gt;s.spawn&lt;/code&gt; + block). It applies
wherever an expression ends a line (&lt;code&gt;val r = retry(3)&lt;/code&gt; + block, a method call, a match arm’s
body), and never in the test of &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; or &lt;code&gt;do … while&lt;/code&gt;, a &lt;code&gt;for&lt;/code&gt; source or guard,
or a class’s parents, where the block is the form’s body. A local function’s header keeps its
meaning: &lt;code&gt;name()&lt;/code&gt; or &lt;code&gt;name(x: T)&lt;/code&gt; before a block declares one. A block whose only line is a name
and an operand stays the infix-continuation error. A block for a last parameter that is neither
by-name nor a function, already given, or absent is an error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/spec/threads/#futures&quot;&gt;Futures&lt;/a&gt; in &lt;code&gt;avin.threads&lt;/code&gt;: &lt;code&gt;Future(body)&lt;/code&gt;, the companion’s
&lt;code&gt;apply[T](body: -&amp;gt; T)&lt;/code&gt;, runs a by-name body on a shared pool and gives back a &lt;code&gt;Future[T]&lt;/code&gt; at once;
&lt;code&gt;await()&lt;/code&gt; waits safe for the collector, &lt;code&gt;await(timeoutMillis: long)&lt;/code&gt; gives an &lt;code&gt;Option&lt;/code&gt;, and times
are milliseconds as a &lt;code&gt;long&lt;/code&gt;, as in a condition’s &lt;code&gt;waitFor(timeoutMillis) -&amp;gt; bool&lt;/code&gt;. &lt;code&gt;map&lt;/code&gt;,
&lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;onComplete&lt;/code&gt;, &lt;code&gt;Future.all&lt;/code&gt; (a &lt;code&gt;Vector&lt;/code&gt; in the order given), &lt;code&gt;Future.first&lt;/code&gt;
(trapping on no futures) and &lt;code&gt;Future.successful&lt;/code&gt; never wait, and every function given to one
runs on a pool thread. A future carries no failure: a computation that can fail is a
&lt;code&gt;Future[Result[T, E]]&lt;/code&gt;, which also has &lt;code&gt;mapOk&lt;/code&gt; and &lt;code&gt;flatMapOk&lt;/code&gt;, and a trap in a body stops the
program. &lt;code&gt;Promise[T]()&lt;/code&gt; has a &lt;code&gt;future&lt;/code&gt; field; &lt;code&gt;complete(x)&lt;/code&gt; a second time traps, and
&lt;code&gt;tryComplete(x) -&amp;gt; bool&lt;/code&gt; completes only where nothing has. The pool starts workers as work comes,
up to one per processor (&lt;code&gt;sysl.platform.cpu_count&lt;/code&gt;), never joins them, and starts one more in the
place of each worker waiting in &lt;code&gt;await&lt;/code&gt; while work is queued, so nested waits never deadlock it;
&lt;code&gt;await&lt;/code&gt; inside a body is allowed. The pool is a module’s &lt;code&gt;lazy val&lt;/code&gt;, so a program that makes no
future never makes it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;&lt;code&gt;lazy val&lt;/code&gt;&lt;/a&gt;, at module level and in class and object bodies
(each instance its own), and in blocks (each declaration’s run its own, see the entry for branch
&lt;code&gt;lazy-local&lt;/code&gt;), is computed on its first read, exactly once, and kept; never read, never
computed. &lt;code&gt;lazy&lt;/code&gt; is a modifier only before &lt;code&gt;val&lt;/code&gt;, an ordinary name elsewhere; &lt;code&gt;lazy var&lt;/code&gt; and
&lt;code&gt;lazy&lt;/code&gt; on parameters, class parameters and data fields are errors. A module-level one
takes no place in the eager initialization order, its readers depending on what its initializer
reads; an initializer whose own code needs its own value, directly, through the functions it
calls or through other lazy values, is a compile error naming the chain (module-level, field and
local ones alike; see the initialization entries), and one that reaches it through a function it hands on traps
at that read, naming the value. A field’s initializer may use every field and method; the class
body reads the field only where it could call a method. Concurrent first reads run the
initializer once, the others waiting safe for the collector; the value is published with a
release store paired with the readers’ acquire load, a stored value read with one atomic load
and a branch.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;/spec/declarations/&quot;&gt;A companion’s &lt;code&gt;apply&lt;/code&gt;&lt;/a&gt; overloads the constructor its name has in call
position. Where an object declares &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;Name(…)&lt;/code&gt; chooses among the class’s constructor (or
the data type’s variant of its name) and every &lt;code&gt;apply&lt;/code&gt; by the ordinary static overloading rules:
most specific by parameter types, with by-name parameters, defaults, repeated parameters, generic
inference and trailing blocks as for any call (&lt;code&gt;Future(fetch(url))&lt;/code&gt;, &lt;code&gt;Future&lt;/code&gt; + block). Type
arguments written at the call are the chosen candidate’s: the class’s or data type’s for the
constructor, the method’s for an &lt;code&gt;apply&lt;/code&gt;. An &lt;code&gt;apply&lt;/code&gt; with the constructor’s parameter types, up to
type parameter names, is an error at its declaration. A name with no constructor in call position
(a data type with no variant of its name, an abstract class, a plain object) calls its &lt;code&gt;apply&lt;/code&gt;
alone, and the library’s &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; companions take their elements that way:
&lt;code&gt;List(1, 2, 3)&lt;/code&gt;, &lt;code&gt;Set(…)&lt;/code&gt;, &lt;code&gt;Map((k, v), …)&lt;/code&gt;. Where a function type is expected, the name is the
constructor or &lt;code&gt;apply&lt;/code&gt; that type chooses, as for an overloaded function value; elsewhere the bare
name stays the object. This amends the earlier rule that the name in call position is only the
constructor and that an object cannot be called.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A method named by a symbol binds at the level of the language’s operator its first character
belongs to&lt;/strong&gt;, on Avin’s own table, tightest first: a name starting with any character that starts
no operator below (&lt;code&gt;~&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;) binds above multiplication; &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;%&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; names with
the multiplicative operators and shifts; &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt; names with the additive operators; &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;
and &lt;code&gt;|&lt;/code&gt; names with those bitwise operators, &lt;code&gt;&amp;amp;&lt;/code&gt; tightest; &lt;code&gt;:&lt;/code&gt; names with &lt;code&gt;::&lt;/code&gt;; then ranges and
methods called by a word (&lt;code&gt;a max b&lt;/code&gt;); &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;!&lt;/code&gt; names with the comparisons; and a name
ending in &lt;code&gt;=&lt;/code&gt; that is not a comparison (&lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt;, &lt;code&gt;|=&lt;/code&gt;) is an assignment. A name ending in &lt;code&gt;:&lt;/code&gt;
still groups right with its receiver on the right, and left- and right-grouping operators at one
level, symbol, word or the language’s own, do not mix without parentheses (&lt;code&gt;1 :: xs :+ 2&lt;/code&gt; is an
error; &lt;code&gt;1 +: xs :+ 2&lt;/code&gt; is &lt;code&gt;(1 +: xs) :+ 2&lt;/code&gt;). So &lt;code&gt;xs ++ ys :+ z&lt;/code&gt; is &lt;code&gt;(xs ++ ys) :+ z&lt;/code&gt;, and the
combinators &lt;code&gt;a ~ b ^^ f | c ~ d&lt;/code&gt; read &lt;code&gt;((a ~ b) ^^ f) | (c ~ d)&lt;/code&gt;. &lt;strong&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt;
between two operands are free method names&lt;/strong&gt; for every type but the integers and bytes, whose
bitwise operators stay the machine’s and cannot be redefined, by an extension either; &lt;code&gt;a | b&lt;/code&gt; on
such a type calls its method &lt;code&gt;|&lt;/code&gt;, and &lt;code&gt;x |= y&lt;/code&gt; calls &lt;code&gt;|=&lt;/code&gt; where the type has one and is otherwise
&lt;code&gt;x = x | y&lt;/code&gt;. Prefix &lt;code&gt;~&lt;/code&gt; stays the integers’ and bytes’ complement. &lt;code&gt;+ - * / %&lt;/code&gt; and the
comparisons still come only through their traits, and &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;===&lt;/code&gt;, &lt;code&gt;!==&lt;/code&gt;, &lt;code&gt;::&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;,
&lt;code&gt;:=&lt;/code&gt;, &lt;code&gt;-&amp;gt;&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, &lt;code&gt;..&lt;/code&gt; and &lt;code&gt;..&amp;lt;&lt;/code&gt; stay reserved. This replaces the earlier rule that every symbol
call binds at the level of &lt;code&gt;a max b&lt;/code&gt;. See &lt;a href=&quot;/spec/operators-and-control-flow/#methods-named-by-symbols&quot;&gt;methods named by
symbols&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The shifts &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; are free method names on the same terms as &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;|&lt;/code&gt;&lt;/strong&gt; (user,
2026-11-04), so a parser combinator library can spell sequencing-then-map &lt;code&gt;p &amp;gt;&amp;gt; f&lt;/code&gt;. On every type
but the integers and bytes, &lt;code&gt;a &amp;lt;&amp;lt; b&lt;/code&gt; and &lt;code&gt;a &amp;gt;&amp;gt; b&lt;/code&gt; call the methods of those names, at the shifts’
own level, that of multiplication (&lt;code&gt;a ++ b &amp;gt;&amp;gt; f&lt;/code&gt; is &lt;code&gt;a ++ (b &amp;gt;&amp;gt; f)&lt;/code&gt;, &lt;code&gt;a &amp;gt;&amp;gt; f | b&lt;/code&gt; is
&lt;code&gt;(a &amp;gt;&amp;gt; f) | b&lt;/code&gt;); &lt;code&gt;x &amp;lt;&amp;lt;= y&lt;/code&gt; calls &lt;code&gt;&amp;lt;&amp;lt;=&lt;/code&gt; where the type has one and is otherwise &lt;code&gt;x = x &amp;lt;&amp;lt; y&lt;/code&gt;. The
integers’ and bytes’ shifts stay the machine’s and cannot be redefined, by an extension either,
and the yielding forms &lt;code&gt;&amp;lt;&amp;lt;:=&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;:=&lt;/code&gt; stay reserved. Avin has no &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; operator, so &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; was
already a free name. This amends the rule above. See &lt;a href=&quot;/spec/operators-and-control-flow/#methods-named-by-symbols&quot;&gt;methods named by
symbols&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The arithmetic operators &lt;code&gt;+ - * / %&lt;/code&gt; and the orderings &lt;code&gt;&amp;lt; &amp;lt;= &amp;gt; &amp;gt;=&lt;/code&gt; are free method names on
data types, classes and traits, with any operand and result types&lt;/strong&gt; (user, 2026-11-04), beside
the operator traits, which stay for generic code: &lt;code&gt;Instant + Duration -&amp;gt; Instant&lt;/code&gt;,
&lt;code&gt;Instant - Instant -&amp;gt; Duration&lt;/code&gt;, &lt;code&gt;Vec * real&lt;/code&gt;. Such methods overload by the operand’s type like
any other. &lt;code&gt;a + b&lt;/code&gt; calls &lt;code&gt;a&lt;/code&gt;‘s method &lt;code&gt;+&lt;/code&gt; where &lt;code&gt;a&lt;/code&gt;‘s type (a data type, a class, or a type
parameter through its bounds) has one taking one argument, at the built-in operator’s own
precedence; where it has none, the operator is the core trait’s (&lt;code&gt;Add&lt;/code&gt;‘s &lt;code&gt;add&lt;/code&gt;), as before. The
method is just a method: on a type with both, the operator calls the method and code bounded by
&lt;code&gt;Add&lt;/code&gt; calls &lt;code&gt;add&lt;/code&gt;. Prefix &lt;code&gt;-a&lt;/code&gt; calls a method &lt;code&gt;-&lt;/code&gt; taking no argument (&lt;code&gt;-() -&amp;gt; Vec&lt;/code&gt;), and otherwise
is &lt;code&gt;Neg&lt;/code&gt;‘s &lt;code&gt;negate&lt;/code&gt;. &lt;code&gt;a &amp;lt; b&lt;/code&gt; alone calls the method &lt;code&gt;&amp;lt;&lt;/code&gt;, whatever it yields; a comparison by a
method chains when every link yields &lt;code&gt;bool&lt;/code&gt; (amended 2026-11-19; see “a comparison chain’s links
may call operator methods” below, among the decisions settled on the user’s delegation).
&lt;code&gt;x += y&lt;/code&gt; calls &lt;code&gt;+=&lt;/code&gt; where the type has one and is otherwise &lt;code&gt;x = x + y&lt;/code&gt;, the method &lt;code&gt;+&lt;/code&gt;
included. The built-in types keep their operators: a method of one of these names on &lt;code&gt;int&lt;/code&gt;,
&lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; or a tuple, by an extension or a trait implementation, is
an error. &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; stay &lt;code&gt;Eq&lt;/code&gt;‘s, and the wrapping, saturating and yielding forms stay
reserved. &lt;code&gt;avin.time&lt;/code&gt; spells its reading arithmetic with them. This amends the two rules above.
See &lt;a href=&quot;/spec/operators-and-control-flow/#methods-named-by-symbols&quot;&gt;methods named by symbols&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;not&lt;/code&gt; is a soft keyword: a keyword only directly after &lt;code&gt;is&lt;/code&gt;&lt;/strong&gt; (user, 2026-11-04), so the parsing
library can name its negative lookahead &lt;code&gt;not(p)&lt;/code&gt;. After &lt;code&gt;is&lt;/code&gt; it is always the keyword, so &lt;code&gt;x is not(y)&lt;/code&gt; negates the pattern &lt;code&gt;(y)&lt;/code&gt;; everywhere else it is an ordinary name, and a function, method,
parameter or local may be called &lt;code&gt;not&lt;/code&gt;. See &lt;a href=&quot;/spec/operators-and-control-flow/#is&quot;&gt;is&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A method named by a symbol with &lt;code&gt;~&lt;/code&gt; anywhere in its name binds at the tightest symbol level&lt;/strong&gt;,
whatever its first character: &lt;code&gt;~&lt;/code&gt;, &lt;code&gt;~&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;~&lt;/code&gt;, &lt;code&gt;~!&lt;/code&gt;, &lt;code&gt;&amp;lt;~&amp;gt;&lt;/code&gt; and &lt;code&gt;^~&lt;/code&gt; bind together there and group
left, so &lt;code&gt;num | symbol(&amp;quot;(&amp;quot;) ~&amp;gt; expr &amp;lt;~ symbol(&amp;quot;)&amp;quot;)&lt;/code&gt; is &lt;code&gt;num | ((symbol(&amp;quot;(&amp;quot;) ~&amp;gt; expr) &amp;lt;~ symbol(&amp;quot;)&amp;quot;))&lt;/code&gt;, &lt;code&gt;&amp;quot;[&amp;quot; ~&amp;gt; items &amp;lt;~ &amp;quot;]&amp;quot; ^^ f&lt;/code&gt; is &lt;code&gt;((&amp;quot;[&amp;quot; ~&amp;gt; items) &amp;lt;~ &amp;quot;]&amp;quot;) ^^ f&lt;/code&gt;, and &lt;code&gt;a &amp;lt;~ b ~ c&lt;/code&gt; is
&lt;code&gt;(a &amp;lt;~ b) ~ c&lt;/code&gt;. Every other name keeps the first-character rule; a &lt;code&gt;~&lt;/code&gt; name ending in &lt;code&gt;=&lt;/code&gt; (&lt;code&gt;~=&lt;/code&gt;)
is still a compound assignment, and prefix &lt;code&gt;~&lt;/code&gt; is unchanged. This amends the rule above, under
which &lt;code&gt;&amp;lt;~&lt;/code&gt; bound with the comparisons.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A line that starts with a binary operator, indented deeper than the line where its expression
began, continues that expression&lt;/strong&gt;, with the operator’s own precedence: the line break means
nothing. Every binary operator of the language, every method named by a symbol, &lt;code&gt;~&lt;/code&gt;, and &lt;code&gt;++&lt;/code&gt; or
&lt;code&gt;--&lt;/code&gt; with an operand after it start one, and so does a member’s &lt;code&gt;.&lt;/code&gt; (see the Proposed entry on &lt;code&gt;.&lt;/code&gt;
lines); a word, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, a bracket and the assignments do not. It applies wherever an expression with a complete operand ends a line (a binding’s value, an
assignment, a &lt;code&gt;return&lt;/code&gt; value, an infix call’s argument, a &lt;code&gt;match&lt;/code&gt; arm’s or a lambda’s body, an
expression statement) and ends at the first line back at the depth the expression began on; a
line inside it that does not start with an operator is an error. Blank lines and comments between
continuation lines are skipped. After an operand &lt;code&gt;-x&lt;/code&gt; and &lt;code&gt;+x&lt;/code&gt; there are binary; after the test of
&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt; or &lt;code&gt;while&lt;/code&gt;, a &lt;code&gt;for&lt;/code&gt; source, a class’s parents, and after anything that is not a
complete operand (&lt;code&gt;=&lt;/code&gt;, &lt;code&gt;-&amp;gt;&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;, a signature), an indented line is a block’s line, so
&lt;code&gt;if c&lt;/code&gt; over &lt;code&gt;-1&lt;/code&gt; is a block yielding &lt;code&gt;-1&lt;/code&gt;. An indented line starting with an operator after a call
is a continuation, not the call’s trailing block. See &lt;a href=&quot;/spec/operators-and-control-flow/#continuation-lines&quot;&gt;continuation
lines&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;.lavin&lt;/code&gt; file is literate source: a Markdown document whose lines indented four columns are
the program&lt;/strong&gt;, and the name alone decides it (an &lt;code&gt;.avin&lt;/code&gt; file never reads this way). It is
accepted wherever an &lt;code&gt;.avin&lt;/code&gt; file is: a program of one file, a file of any module of a directory
program or of the library, &lt;code&gt;avin test&lt;/code&gt;, and the language server. The program’s own indentation
starts after the four columns; prose between two blocks ends nothing and reads as blank lines; a
fenced block (&lt;code&gt;```&lt;/code&gt; or &lt;code&gt;~~~&lt;/code&gt;) is an illustration and is not compiled; an indented block under a
list item is prose. Prose is blanked, not removed, so every position reported is the document’s
own line and column. A tab in a line’s indentation and a fence that is never closed are refused
where they are. &lt;code&gt;avin tangle&lt;/code&gt; prints the program with the prose stripped, line for line; &lt;code&gt;avin weave&lt;/code&gt; renders the document as one HTML page, the prose as GitHub-flavoured Markdown and the
program coloured by the compiler’s own lexer. See &lt;a href=&quot;/spec/declarations/#literate-source&quot;&gt;literate
source&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Derivation through shapes&lt;/strong&gt; (&lt;a href=&quot;/spec/derivation/&quot;&gt;derivation&lt;/a&gt;): &lt;code&gt;derives&lt;/code&gt; takes any trait whose
module declares a &lt;code&gt;derive X for T&lt;/code&gt; template, written once like an impl. Every data type and class
(its constructor parameters) has a shape, made once before &lt;code&gt;main&lt;/code&gt;: variants, fields, names,
positions, defaults and annotations. Inside a template, &lt;code&gt;T.walk(value, visitor)&lt;/code&gt; and &lt;code&gt;T.walkPair(a, b, visitor)&lt;/code&gt; call the visitor’s &lt;code&gt;field[F: Bound]&lt;/code&gt; hook once per field at that field’s type, and
&lt;code&gt;T.build(builder)&lt;/code&gt; makes a value from fields supplied in any order, using defaults and the
builder’s &lt;code&gt;missing&lt;/code&gt; for absent ones. The template is checked once; the visitor’s hook is found for
each deriving type, and that each field meets its bound is reported at the &lt;code&gt;derives&lt;/code&gt; entry naming
the field. Annotations are values of types implementing &lt;code&gt;Annotation&lt;/code&gt;, written &lt;code&gt;@JsonKey(&amp;quot;name&amp;quot;)&lt;/code&gt;
on a type, variant or field. The user resolved the proposal’s open questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Shaped&lt;/code&gt; is a bound only a template’s &lt;code&gt;T&lt;/code&gt; has; a program cannot write it elsewhere.&lt;/li&gt;
&lt;li&gt;The built-in &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt; and class &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; derivations are to be
re-expressed as core-library templates. A data type’s own &lt;code&gt;==&lt;/code&gt; and hash stay the language’s.&lt;/li&gt;
&lt;li&gt;A misused annotation is not rejected while compiling; it fails when a value is decoded.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;build&lt;/code&gt; is refused for open and abstract classes, an error at the &lt;code&gt;derives&lt;/code&gt; entry; &lt;code&gt;walk&lt;/code&gt; is
allowed.&lt;/li&gt;
&lt;li&gt;Every type parameter of a generic deriving type is bounded by the derived trait.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Packages beyond the manifest, settled by the user (2026-11-04) as proposed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Features&lt;/strong&gt; (&lt;a href=&quot;/spec/packages/#features&quot;&gt;features&lt;/a&gt;), Sysl’s model with the module as the unit
gated: a feature block has &lt;code&gt;doc&lt;/code&gt;, &lt;code&gt;default&lt;/code&gt;, &lt;code&gt;modules&lt;/code&gt;, &lt;code&gt;enables&lt;/code&gt; and &lt;code&gt;requires&lt;/code&gt;, and
&lt;code&gt;name = [x]&lt;/code&gt; is its short form; optional dependencies, &lt;code&gt;&amp;quot;dep:x&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;dep/feature&amp;quot;&lt;/code&gt;, users’
&lt;code&gt;features&lt;/code&gt;, &lt;code&gt;default_features = false&lt;/code&gt; and &lt;code&gt;-x&lt;/code&gt;, unification by union and the
&lt;code&gt;--features&lt;/code&gt;/&lt;code&gt;--no-default-features&lt;/code&gt;/&lt;code&gt;--all-features&lt;/code&gt; flags are Sysl’s. Where Sysl gates lines
with &lt;code&gt;#if feature_x&lt;/code&gt;, Avin has no conditional compilation: a feature lists whole &lt;strong&gt;modules&lt;/strong&gt;
(with those under them), read only while it is on, and an import of a gated module or of an
optional dependency’s module is allowed only from a module whose own gate implies it, checked
against the manifest whatever is selected, so features are additive by construction. &lt;code&gt;avin test&lt;/code&gt;,
&lt;code&gt;avin check&lt;/code&gt;, the language server and &lt;code&gt;avin tidy&lt;/code&gt; turn every feature on. Not carried over: Sysl’s
&lt;code&gt;choices&lt;/code&gt;, a feature’s &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;targets&lt;/code&gt;, and options, which are about machines and C
configuration Avin’s manifest does not describe.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Members of a repository&lt;/strong&gt; (&lt;a href=&quot;/spec/packages/#members-of-a-repository&quot;&gt;members&lt;/a&gt;), Sysl’s:
&lt;code&gt;{ git, member = &amp;quot;dir&amp;quot;, version | rev }&lt;/code&gt;, the member a package named &lt;code&gt;&amp;lt;coordinate&amp;gt;//&amp;lt;dir&amp;gt;&lt;/code&gt; for
selection and &lt;code&gt;avin.sum&lt;/code&gt;, every member at one version one clone whose hash each member’s line
carries, a fetched member’s &lt;code&gt;workspace = true&lt;/code&gt; and in-repository &lt;code&gt;path&lt;/code&gt; siblings read as their
own coordinates at the member’s version, and &lt;code&gt;avin add &amp;lt;coordinate&amp;gt;//&amp;lt;dir&amp;gt;@&amp;lt;version&amp;gt;&lt;/code&gt;. Its modules
keep their own names, as every dependency’s do, so Avin needs no &lt;code&gt;package.repository&lt;/code&gt; key.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vendoring&lt;/strong&gt; (&lt;a href=&quot;/spec/packages/#vendoring&quot;&gt;vendoring&lt;/a&gt;), Sysl’s: &lt;code&gt;avin vendor&lt;/code&gt; copies the
resolution with every feature on into &lt;code&gt;vendor/&lt;/code&gt; at the project (workspace) root in the cache’s
layout, each copy hashed against its &lt;code&gt;avin.sum&lt;/code&gt; line first, &lt;code&gt;.git&lt;/code&gt; and path dependencies left out;
a &lt;code&gt;vendor/&lt;/code&gt; present is the cache, and the root’s &lt;code&gt;vendor/&lt;/code&gt; is never a module. Two choices of
Avin’s own: a package missing from &lt;code&gt;vendor/&lt;/code&gt; is &lt;strong&gt;refused&lt;/strong&gt; rather than fetched into it, so a
vendored build never touches the network; and &lt;code&gt;avin vendor&lt;/code&gt; &lt;strong&gt;removes&lt;/strong&gt; packages the resolution
no longer reads, as &lt;code&gt;avin tidy&lt;/code&gt; does for lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The standard library’s modules&lt;/strong&gt; (&lt;a href=&quot;/spec/packages/#the-standard-library-s-modules&quot;&gt;standard library&lt;/a&gt;):
the &lt;code&gt;avin&lt;/code&gt; tree shipped with the compiler (&lt;code&gt;share/avin/library&lt;/code&gt;, or &lt;code&gt;AVIN_ROOT/library&lt;/code&gt;),
versioned with it, never a dependency and never in &lt;code&gt;avin.sum&lt;/code&gt;; &lt;code&gt;avin&lt;/code&gt; is the prelude, seen
without an import, and every module under it is imported by name like any module. A
compilation reads the prelude and then only the library modules something imports,
transitively, so the library can grow without every program parsing all of it. Domain libraries
are packages (as settled for &lt;code&gt;dev.avinlang&lt;/code&gt;). The standard library has no features.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Integer limits and narrowing&lt;/strong&gt; (user, 2026-11-04). &lt;code&gt;MinValue&lt;/code&gt; and &lt;code&gt;MaxValue&lt;/code&gt; on every integer type
(&lt;code&gt;int.MaxValue&lt;/code&gt;, &lt;code&gt;long.MinValue&lt;/code&gt;, &lt;code&gt;i8.MaxValue&lt;/code&gt;, any &lt;code&gt;iN&lt;/code&gt;), on &lt;code&gt;byte&lt;/code&gt; and on &lt;code&gt;char&lt;/code&gt;, and on &lt;code&gt;real&lt;/code&gt;
&lt;code&gt;MaxValue&lt;/code&gt;, &lt;code&gt;MinValue&lt;/code&gt;, &lt;code&gt;MinPositiveValue&lt;/code&gt;, &lt;code&gt;PositiveInfinity&lt;/code&gt;, &lt;code&gt;NegativeInfinity&lt;/code&gt; and &lt;code&gt;NaN&lt;/code&gt;, all
compile-time constants. Narrowing integer conversions (&lt;code&gt;i8(x)&lt;/code&gt;, &lt;code&gt;int(l)&lt;/code&gt;, &lt;code&gt;T(n)&lt;/code&gt;, and a byte or char to
a narrower integer) trap when the value does not fit; real-to-integer still saturates. The wrapping
form, &lt;code&gt;i8.wrap(x)&lt;/code&gt; (spelling proposed below), keeps the low bits. A type parameter bounded by &lt;code&gt;Integer&lt;/code&gt; has the limits too, &lt;code&gt;T.MaxValue&lt;/code&gt; and
&lt;code&gt;T.MinValue&lt;/code&gt;, each instance’s own (&lt;a href=&quot;/spec/generics/&quot;&gt;generics&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Nested data types (&lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;generics&lt;/a&gt;): a data type naming itself
at a larger instance in its fields (&lt;code&gt;Deeper(inner: Tree[Nest[T]])&lt;/code&gt; in &lt;code&gt;Tree[T]&lt;/code&gt;) is rejected at
the type as polymorphic recursion, even where no code compares, hashes or shows it, since every
data type’s structural equality, hash and &lt;code&gt;Display&lt;/code&gt; would need a copy for every depth. A class
naming itself so in a field is not rejected for that alone; only code that grows with it is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Which growth counts (&lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;generics&lt;/a&gt;): growth is measured as
nesting depth, and a cycle is rejected when a round of it nests its type arguments deeper in
total. A call through a bound on a value of a type parameter takes that type’s arguments apart
(a &lt;code&gt;Box[U]&lt;/code&gt; reaching &lt;code&gt;Box&lt;/code&gt;‘s method at &lt;code&gt;U&lt;/code&gt; is one level less); an implementation reached through
a method table whose static type names every type parameter of the receiver’s class (an
&lt;code&gt;Iterator[(A, int)]&lt;/code&gt; for an &lt;code&gt;IndexedIterator[A]&lt;/code&gt;) takes them apart from the receiver’s, while one
reached through a trait that leaves some unnamed (a trait with no type parameters) continues the
cycle from wherever the class’s larger instance was made.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Literal shapes (&lt;a href=&quot;/spec/collections/#literals&quot;&gt;collections&lt;/a&gt;): each of the library’s collections is
built only by the literal of its own shape: every &lt;code&gt;Seq&lt;/code&gt; by &lt;code&gt;[a, b]&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;TreeSet&lt;/code&gt; and the
mutable &lt;code&gt;Set&lt;/code&gt; by &lt;code&gt;{a, b}&lt;/code&gt;, and &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;TreeMap&lt;/code&gt; and the mutable &lt;code&gt;Map&lt;/code&gt; by &lt;code&gt;{k: v}&lt;/code&gt;, so
&lt;code&gt;val s: Set[int] = [1, 2]&lt;/code&gt; is an error naming the literal to write; &lt;code&gt;{}&lt;/code&gt; is the empty set or the
empty map, whichever is expected. A program’s own collection with a builder is built by any
literal whose elements its builder takes, a map literal only by a builder of pairs. A map literal’s
keys agree on one type and its values on another, each as &lt;code&gt;if&lt;/code&gt; branches do. The mutable &lt;code&gt;Set&lt;/code&gt; and
&lt;code&gt;Map&lt;/code&gt; gain companions with &lt;code&gt;empty&lt;/code&gt; and &lt;code&gt;newBuilder&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Packages (&lt;a href=&quot;/spec/packages/&quot;&gt;packages&lt;/a&gt;), modelled on Sysl’s package system:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The manifest&lt;/strong&gt;: &lt;code&gt;package { name, version, description }&lt;/code&gt;, &lt;code&gt;dependencies { … }&lt;/code&gt; and &lt;code&gt;workspace = [ … ]&lt;/code&gt;, and no other key; an unknown key is an error, not a warning. A name is a lowercase
letter then lowercase letters, digits, &lt;code&gt;_&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;; a version is &lt;code&gt;major.minor.patch&lt;/code&gt; with no
leading zeros. A manifest is optional: a directory or file with none above it is a program as
before.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dependencies&lt;/strong&gt;: &lt;code&gt;{ git = &amp;quot;host/owner/name&amp;quot;, version = &amp;quot;x.y.z&amp;quot; }&lt;/code&gt; read at the tag &lt;code&gt;vx.y.z&lt;/code&gt;
and cloned from &lt;code&gt;https://&lt;/code&gt;; &lt;code&gt;{ path = &amp;quot;../dir&amp;quot; }&lt;/code&gt;, relative to the manifest naming it, and in a
fetched package naming another package of its repository at its version (refused when it leaves
the repository); &lt;code&gt;{ workspace = true }&lt;/code&gt;. A coordinate with &lt;code&gt;https://&lt;/code&gt; or &lt;code&gt;.git&lt;/code&gt; is refused.
Features and members of a repository are settled above.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Members, as built&lt;/strong&gt;: a fetched package’s in-repository &lt;code&gt;path&lt;/code&gt; and &lt;code&gt;workspace = true&lt;/code&gt;
dependencies are read as the repository’s own packages at its version whether the package is a
member or the repository’s root package, since the root of a workspace with a &lt;code&gt;package&lt;/code&gt; block is
its first member. A member’s directory may hold no &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;..&lt;/code&gt; or &lt;code&gt;*&lt;/code&gt;. The clone is filed once per
repository and version; a repository whose root has no manifest is still filed when a member of
it is what was asked for.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vendoring, as built&lt;/strong&gt;: &lt;code&gt;avin tidy&lt;/code&gt; and &lt;code&gt;avin add&lt;/code&gt; read the machine’s cache, fetching into it,
whether or not the project has a &lt;code&gt;vendor/&lt;/code&gt;, so a dependency is added to a vendored project and
then copied in by &lt;code&gt;avin vendor&lt;/code&gt;. &lt;code&gt;avin vendor&lt;/code&gt; checks every cache copy before writing anything, so
a refusal leaves &lt;code&gt;vendor/&lt;/code&gt; as it was (and a project with none still has none); a vendored copy is
left alone only when its recorded hash and its files both match its line, so an edited copy is
replaced; directories left empty by a removal are removed; and it ends &lt;code&gt;vendored N packages into vendor/&lt;/code&gt;, the packages being &lt;code&gt;avin.sum&lt;/code&gt;‘s lines (a member and its repository’s root package at
one version are two packages and one copy). The cache’s &lt;code&gt;.hash&lt;/code&gt; beside a vendored entry is trusted
by a build, as the cache’s is: a build does not re-hash &lt;code&gt;vendor/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;rev&lt;/code&gt; pins&lt;/strong&gt;: &lt;code&gt;{ git = &amp;quot;…&amp;quot;, rev = &amp;quot;&amp;lt;hex&amp;gt;&amp;quot; }&lt;/code&gt;, seven to forty lowercase hexadecimal digits,
refused with a &lt;code&gt;version&lt;/code&gt; or without &lt;code&gt;git&lt;/code&gt;. The repository is cloned whole and the commit
resolved to its full id, fetched by that id when no branch or tag reaches it (only a full id
can); the cache entry is &lt;code&gt;@r&amp;lt;full id&amp;gt;&lt;/code&gt; and the &lt;code&gt;avin.sum&lt;/code&gt; line &lt;code&gt;&amp;lt;coordinate&amp;gt; r&amp;lt;full id&amp;gt; sha256:…&lt;/code&gt;, so an abbreviation and the full id are one package. A cached commit an abbreviation
begins is found without the network. A package pinned at two commits, or at a commit and a
release, anywhere in the graph is refused naming both: a commit is not chosen among, since
none is higher. &lt;code&gt;avin add &amp;lt;coordinate&amp;gt;@&amp;lt;rev&amp;gt;&lt;/code&gt; writes the full id.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What a dependency brings in&lt;/strong&gt;: its modules, under their own names; not its root directory’s
files (its &lt;code&gt;main&lt;/code&gt;) nor its &lt;code&gt;tests&lt;/code&gt; directory, so a program can be depended on and &lt;code&gt;avin test&lt;/code&gt;
runs only the package’s own tests. One module in two packages is refused. A directory holding its
own manifest is another package and never a module of the tree above it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version selection&lt;/strong&gt;: the highest version any manifest in the graph asks for, over every member
of a workspace.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The cache&lt;/strong&gt; is the machine’s, &lt;code&gt;&amp;lt;cache&amp;gt;/avin/pkg/&amp;lt;coordinate&amp;gt;/@v&amp;lt;version&amp;gt;/&lt;/code&gt;, the clone’s
&lt;code&gt;.git&lt;/code&gt; removed and the tree’s hash written beside it. Builds fetch; the language server does not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin.sum&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;&amp;lt;coordinate&amp;gt; v&amp;lt;version&amp;gt; sha256:&amp;lt;hex&amp;gt;&lt;/code&gt; per fetched package and version read,
one file per project (the workspace root’s); the hash is Sysl’s tree hash (SHA-256 of a sorted
listing of each file’s SHA-256 and path, &lt;code&gt;.git&lt;/code&gt; and the root’s &lt;code&gt;.avin/&lt;/code&gt; left out). A mismatch is
refused; a build only adds lines; &lt;code&gt;avin tidy [--check]&lt;/code&gt; rewrites it to what the whole resolution
reads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workspaces&lt;/strong&gt;: Sysl’s: members listed by directory with &lt;code&gt;*&lt;/code&gt; within a name, a root with a
&lt;code&gt;package&lt;/code&gt; block a member, a root without one taking no dependencies and refused as a program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Finding the package&lt;/strong&gt;: every command walks up from the path it is given to the nearest
manifest with a &lt;code&gt;package&lt;/code&gt; block, a workspace root without one being passed over. Sysl looks only
beside the path; walking up is what lets a file, a test directory or an editor’s open file name
its package.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin new &amp;lt;dir&amp;gt; [--lib]&lt;/code&gt;&lt;/strong&gt; names the package by the directory, writes a module of that name
(&lt;code&gt;-&lt;/code&gt; written &lt;code&gt;_&lt;/code&gt;), &lt;code&gt;main.avin&lt;/code&gt; unless &lt;code&gt;--lib&lt;/code&gt;, a test in &lt;code&gt;tests/&lt;/code&gt; and a &lt;code&gt;.gitignore&lt;/code&gt; of &lt;code&gt;.avin/&lt;/code&gt;;
the names &lt;code&gt;avin&lt;/code&gt; and &lt;code&gt;tests&lt;/code&gt; are refused. &lt;code&gt;avin build&lt;/code&gt; names the executable after the package.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin add &amp;lt;coordinate&amp;gt;[@&amp;lt;version&amp;gt;] [&amp;lt;package&amp;gt;]&lt;/code&gt;&lt;/strong&gt; records a git dependency: the version is the
one given, or the highest release tag the host lists (&lt;code&gt;v&lt;/code&gt; and three numbers; no release is an
error naming the way to give one). The package is fetched first and listed under the name its own
manifest gives it; a dependency already listed, under that coordinate or that name, has its entry
replaced in place, to a lower version too. The edit is made in the manifest’s text, so comments
and layout stay: the entry goes last in the &lt;code&gt;dependencies&lt;/code&gt; block, a block being made at the end
of the file when there is none. The result is resolved and &lt;code&gt;avin.sum&lt;/code&gt; gains its lines (a
version that is no longer chosen keeps its line until &lt;code&gt;avin tidy&lt;/code&gt;); where fetching or resolving
fails, the manifest is put back as it was. It adds only git dependencies: a path dependency is
written by hand.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Repeated parameters beside overloads and constructors
(&lt;a href=&quot;/spec/declarations/#repeated-parameters&quot;&gt;declarations&lt;/a&gt;): an overload with a repeated parameter
is a candidate only where no overload without one accepts the call, so &lt;code&gt;pick(x: long)&lt;/code&gt; takes
&lt;code&gt;pick(1)&lt;/code&gt; beside &lt;code&gt;pick(xs: int*)&lt;/code&gt;; among those with one, the arguments are compared by the
element type. A class’s constructor may end with a repeated parameter, whose field is a
&lt;code&gt;Vector[T]&lt;/code&gt; (&lt;code&gt;class Path(val parts: string*)&lt;/code&gt;), and a subclass passes it on with &lt;code&gt;: Path(parts*)&lt;/code&gt;.
The core library gains &lt;code&gt;max(first, rest*)&lt;/code&gt; and &lt;code&gt;min(first, rest*)&lt;/code&gt; on &lt;code&gt;T: Ord&lt;/code&gt;, answering the
greatest or least of one value or more, the first of equal ones.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Option, Result and string methods (&lt;a href=&quot;/spec/errors/&quot;&gt;errors&lt;/a&gt;, &lt;a href=&quot;/spec/types/#string&quot;&gt;types&lt;/a&gt;):
&lt;code&gt;Option&lt;/code&gt; gains &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt; (on &lt;code&gt;T: Eq&lt;/code&gt;, which every type meets), &lt;code&gt;toList&lt;/code&gt;,
&lt;code&gt;toVector&lt;/code&gt; and &lt;code&gt;zip&lt;/code&gt;; &lt;code&gt;Result&lt;/code&gt; gains &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;forall&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt; and &lt;code&gt;orElse(f)&lt;/code&gt;, where &lt;code&gt;f&lt;/code&gt;
takes the error and answers a &lt;code&gt;Result&lt;/code&gt; that may have another error type. &lt;code&gt;forall&lt;/code&gt; is true of
&lt;code&gt;None&lt;/code&gt; and of an &lt;code&gt;Err&lt;/code&gt;. &lt;code&gt;string&lt;/code&gt; gains &lt;code&gt;chars&lt;/code&gt;, &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;split&lt;/code&gt;, &lt;code&gt;lines&lt;/code&gt;, &lt;code&gt;isBlank&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;,
&lt;code&gt;padStart&lt;/code&gt;, &lt;code&gt;padEnd&lt;/code&gt;, &lt;code&gt;equalsIgnoreCase&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeRight&lt;/code&gt; and &lt;code&gt;dropRight&lt;/code&gt;, which count
characters where the older methods count bytes. &lt;code&gt;split&lt;/code&gt; keeps every empty piece and traps on an
empty separator (no piece boundary is defined there). &lt;code&gt;lines&lt;/code&gt; ends a line at &lt;code&gt;\n&lt;/code&gt; or &lt;code&gt;\r\n&lt;/code&gt;; a
terminator at the end starts no further line, the empty string has no lines, and a lone &lt;code&gt;\r&lt;/code&gt;
stays in its line. &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeRight&lt;/code&gt;, &lt;code&gt;dropRight&lt;/code&gt; and the padding widths clamp rather
than trap.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: The methods every &lt;code&gt;Iterable&lt;/code&gt; has (&lt;a href=&quot;/spec/collections/#methods-every-iterable-has&quot;&gt;collections&lt;/a&gt;):
folds, &lt;code&gt;reduce&lt;/code&gt; (trapping when empty) and &lt;code&gt;reduceOption&lt;/code&gt;, searches, &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;minBy&lt;/code&gt;/&lt;code&gt;maxBy&lt;/code&gt; and
&lt;code&gt;min&lt;/code&gt;/&lt;code&gt;max&lt;/code&gt; (trapping when empty) with &lt;code&gt;minByOption&lt;/code&gt;/&lt;code&gt;maxByOption&lt;/code&gt; and &lt;code&gt;minOption&lt;/code&gt;/&lt;code&gt;maxOption&lt;/code&gt;
(answering &lt;code&gt;Option&lt;/code&gt;), the reference library’s names, &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;partition&lt;/code&gt;, &lt;code&gt;groupBy&lt;/code&gt;, &lt;code&gt;groupMap&lt;/code&gt;,
&lt;code&gt;groupMapReduce&lt;/code&gt;, the conversions and &lt;code&gt;zipWithIndex&lt;/code&gt; are written once on &lt;code&gt;Iterable&lt;/code&gt; and replace
the copies &lt;code&gt;Seq&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; had. A collection they make is a &lt;code&gt;Vector&lt;/code&gt;, whatever the receiver:
&lt;code&gt;partition&lt;/code&gt; answers &lt;code&gt;(Vector[T], Vector[T])&lt;/code&gt;, &lt;code&gt;groupBy&lt;/code&gt; a &lt;code&gt;Map[K, Vector[T]]&lt;/code&gt;, &lt;code&gt;zipWithIndex&lt;/code&gt; a
&lt;code&gt;Vector[(T, int)]&lt;/code&gt;, so a set’s or a map’s partition keeps every element, equal results included,
and a list’s comes back indexed. A type’s own method of the same signature still answers where the
type is known (&lt;code&gt;List.toList&lt;/code&gt; is the list itself). &lt;code&gt;Iterator&lt;/code&gt; has lazy &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;,
&lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt;, &lt;code&gt;dropWhile&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt; and &lt;code&gt;zipWithIndex&lt;/code&gt; answering iterators; its
&lt;code&gt;zipWithIndex&lt;/code&gt; is the trait’s own method and so is found before &lt;code&gt;Iterable&lt;/code&gt;‘s. To compile these, a
method table holds a method at a position only for the types a call through that position can
reach, by the receiver’s static type, so a trait method that makes an instance at a larger type
argument (&lt;code&gt;zipWithIndex&lt;/code&gt; on an &lt;code&gt;Iterator[(T, int)]&lt;/code&gt;) is not compiled for every type it makes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Set and map methods (&lt;a href=&quot;/spec/collections/#maps-and-sets&quot;&gt;collections&lt;/a&gt;): an immutable &lt;code&gt;Set&lt;/code&gt; has
&lt;code&gt;++&lt;/code&gt; and &lt;code&gt;--&lt;/code&gt; taking any &lt;code&gt;Iterable[A]&lt;/code&gt; beside &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt; and &lt;code&gt;subsetOf&lt;/code&gt;, which
keep their names and their &lt;code&gt;Set&lt;/code&gt; parameter; &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt; stay reserved for &lt;code&gt;Add&lt;/code&gt; and &lt;code&gt;Sub&lt;/code&gt;, so one
element goes in with &lt;code&gt;incl&lt;/code&gt; and out with &lt;code&gt;excl&lt;/code&gt;, the reference library’s names. An immutable &lt;code&gt;Map&lt;/code&gt;‘s &lt;code&gt;++&lt;/code&gt; takes any &lt;code&gt;Iterable[(K, V)]&lt;/code&gt; and &lt;code&gt;--&lt;/code&gt; any
&lt;code&gt;Iterable[K]&lt;/code&gt;. &lt;code&gt;Map.keys()&lt;/code&gt; and &lt;code&gt;values()&lt;/code&gt; answer a &lt;code&gt;Vector&lt;/code&gt; in iteration order, so the two
line up by index, rather than one-shot iterators; &lt;code&gt;keysIterator()&lt;/code&gt; and &lt;code&gt;valuesIterator()&lt;/code&gt; are the
lazy forms, and &lt;code&gt;keySet()&lt;/code&gt; answers a &lt;code&gt;Set&lt;/code&gt;. A mutable map’s &lt;code&gt;keys()&lt;/code&gt; and &lt;code&gt;values()&lt;/code&gt; are likewise
vector snapshots and its &lt;code&gt;keySet()&lt;/code&gt; an immutable &lt;code&gt;Set&lt;/code&gt; snapshot. &lt;code&gt;transform&lt;/code&gt; is the new-map form
taking the key and the value (&lt;code&gt;mapValues&lt;/code&gt; takes the value alone) on both maps, and a mutable map
has no in-place &lt;code&gt;transform&lt;/code&gt;. Everything that builds a collection from a mutable set or map
(&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;mapValues&lt;/code&gt;, &lt;code&gt;transform&lt;/code&gt;, &lt;code&gt;filterKeys&lt;/code&gt;) answers a
new mutable one; &lt;code&gt;filterInPlace(p)&lt;/code&gt; and &lt;code&gt;updateWith(k, f)&lt;/code&gt; change in place, &lt;code&gt;updateWith&lt;/code&gt; answering the
new binding as an &lt;code&gt;Option&lt;/code&gt;. &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt; and &lt;code&gt;--=&lt;/code&gt; are methods on the mutable collections
(a map’s &lt;code&gt;+=&lt;/code&gt; takes a &lt;code&gt;(key, value)&lt;/code&gt; pair), so they work on a &lt;code&gt;val&lt;/code&gt;; removing an absent element
or key is not an error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Sorting (&lt;a href=&quot;/spec/collections/#sorting&quot;&gt;collections&lt;/a&gt;): every &lt;code&gt;Seq&lt;/code&gt; has &lt;code&gt;sorted()&lt;/code&gt; (elements &lt;code&gt;Ord&lt;/code&gt;),
&lt;code&gt;sortBy[K: Ord](key)&lt;/code&gt; and &lt;code&gt;sortWith(compare: (T, T) -&amp;gt; int)&lt;/code&gt;, answering a &lt;code&gt;Vector&lt;/code&gt;; &lt;code&gt;List&lt;/code&gt;
has its own three answering a &lt;code&gt;List&lt;/code&gt;. &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt; and &lt;code&gt;Deque&lt;/code&gt; sort in place with
&lt;code&gt;sortInPlace()&lt;/code&gt;, &lt;code&gt;sortInPlaceBy(key)&lt;/code&gt; and &lt;code&gt;sortInPlaceWith(compare)&lt;/code&gt;, the reference library’s
names. Every sort is a stable merge sort, O(n log n) comparisons in the worst case with one
scratch copy of the elements; &lt;code&gt;sortBy&lt;/code&gt; and &lt;code&gt;sortInPlaceBy&lt;/code&gt; compute &lt;code&gt;key&lt;/code&gt; once per element. &lt;code&gt;avin.fs.listDir&lt;/code&gt; answers its names sorted by code point rather than in the file
system’s order.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: The methods every &lt;code&gt;Seq&lt;/code&gt; has (&lt;a href=&quot;/spec/collections/#methods-every-seq-has&quot;&gt;collections&lt;/a&gt;): &lt;code&gt;map&lt;/code&gt;,
&lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterNot&lt;/code&gt;, &lt;code&gt;withFilter&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt;,
&lt;code&gt;dropWhile&lt;/code&gt;, &lt;code&gt;takeRight&lt;/code&gt;, &lt;code&gt;dropRight&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;splitAt&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;,
&lt;code&gt;++&lt;/code&gt;, &lt;code&gt;:+&lt;/code&gt;, &lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;updated&lt;/code&gt;, &lt;code&gt;padTo&lt;/code&gt;, &lt;code&gt;indices&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;zipAll&lt;/code&gt;, &lt;code&gt;scanLeft&lt;/code&gt;, &lt;code&gt;distinct&lt;/code&gt;,
&lt;code&gt;distinctBy&lt;/code&gt;, &lt;code&gt;grouped&lt;/code&gt;, &lt;code&gt;sliding&lt;/code&gt;, &lt;code&gt;lastIndexOf&lt;/code&gt;, &lt;code&gt;lastIndexWhere&lt;/code&gt;, &lt;code&gt;startsWith&lt;/code&gt;, &lt;code&gt;endsWith&lt;/code&gt;,
&lt;code&gt;sameElements&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt; are written once on &lt;code&gt;Seq&lt;/code&gt;, answering a &lt;code&gt;Vector&lt;/code&gt; (&lt;code&gt;indices&lt;/code&gt;
a &lt;code&gt;Range&lt;/code&gt;, &lt;code&gt;grouped&lt;/code&gt; and &lt;code&gt;sliding&lt;/code&gt; an &lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;). &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt; and &lt;code&gt;ArraySeq&lt;/code&gt;
keep or gain their own versions answering their own kind. The mutable &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt; and
&lt;code&gt;Deque&lt;/code&gt; answer the element-wise &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt; and &lt;code&gt;filterNot&lt;/code&gt; with a new
collection of their own kind and the structural methods with a &lt;code&gt;Vector&lt;/code&gt;, so a structural method
never shares or aliases a mutable receiver; &lt;code&gt;Array.slice&lt;/code&gt; stays an &lt;code&gt;Array&lt;/code&gt;. A count is clamped to
&lt;code&gt;0 .. length()&lt;/code&gt;; &lt;code&gt;slice&lt;/code&gt; traps unless its indices are in order within the sequence, as it does on
strings and arrays. &lt;code&gt;intersect&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt; are multiset operations: each occurrence in the
argument matches the first unmatched equal element, and the receiver’s order is kept. &lt;code&gt;Range&lt;/code&gt; is
a &lt;code&gt;Seq[int]&lt;/code&gt; with constant-time &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;contains&lt;/code&gt;, and so an &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt;.
Overload resolution accepts an argument of a subtype of a parameter’s type, as a single
function’s call does, and compares candidates by the same conformance, so a type’s own
&lt;code&gt;++(other: List[T])&lt;/code&gt; and &lt;code&gt;Seq&lt;/code&gt;‘s &lt;code&gt;++(other: Iterable[T])&lt;/code&gt; are overloads of which the first is
more specific.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Two sequences are equal when they have the same elements in order, whichever kinds they are&lt;/strong&gt;:
a &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt; and &lt;code&gt;Range&lt;/code&gt; of equal elements compare
equal with &lt;code&gt;==&lt;/code&gt; and hash alike, with one comparison and one hash written once on &lt;code&gt;Seq&lt;/code&gt; for them
all. &lt;code&gt;==&lt;/code&gt; between two sequence types needs the same element type on both sides (a &lt;code&gt;Vector[int]&lt;/code&gt;
and a &lt;code&gt;List[string]&lt;/code&gt; are a compile-time error, as any two types with no common type are); a
value typed as &lt;code&gt;Seq[T]&lt;/code&gt; compares with any sequence. A class that implements &lt;code&gt;Eq&lt;/code&gt; itself keeps its
own equality between two of its instances. Settled (user, 2026-11-04): through &lt;code&gt;Any&lt;/code&gt; and
trait-typed values sequences of equal elements in order are equal whatever their class, with
hashes that agree (&lt;code&gt;val a: Any = [1, 2]; a == List(1, 2)&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;); the elements are compared
as &lt;code&gt;Any&lt;/code&gt; values are, so &lt;code&gt;[1] == [&amp;quot;a&amp;quot;]&lt;/code&gt; held as &lt;code&gt;Any&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;. An &lt;code&gt;Array&lt;/code&gt; is a &lt;code&gt;Seq&lt;/code&gt; here and
compares by contents, as it already did. The mutable &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt; and &lt;code&gt;Deque&lt;/code&gt; compare
as they are when the comparison runs, so a hash held across a change is stale, as it was before.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Ranges of other integer types are &lt;code&gt;NumericRange[T: Integer]&lt;/code&gt;&lt;/strong&gt;.
&lt;code&gt;Range&lt;/code&gt; stays the &lt;code&gt;int&lt;/code&gt; range, and a bare &lt;code&gt;Range&lt;/code&gt; in a signature means it. &lt;code&gt;a..b&lt;/code&gt; and &lt;code&gt;a..&amp;lt;b&lt;/code&gt;
written as values make a &lt;code&gt;NumericRange[T]&lt;/code&gt; where the bounds are integers of any type other than
&lt;code&gt;int&lt;/code&gt; (&lt;code&gt;long&lt;/code&gt;, &lt;code&gt;i8&lt;/code&gt;, &lt;code&gt;i16&lt;/code&gt;, …); an integer literal bound takes its type from the other bound, and
bounds of two types are an error. &lt;code&gt;by&lt;/code&gt; takes a step of the same type, &lt;code&gt;T&lt;/code&gt;. It is a &lt;code&gt;Seq[T]&lt;/code&gt;
with the &lt;code&gt;Range&lt;/code&gt; rules: a zero step traps, a range is empty when its start lies past its limit in
the step’s direction, and iteration stops without stepping past the limit, so it never passes
either end of &lt;code&gt;T&lt;/code&gt;. &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;isEmpty&lt;/code&gt; are answered from the bounds
and never wrap, at any width; &lt;code&gt;length()&lt;/code&gt; traps beyond &lt;code&gt;int&lt;/code&gt;, and &lt;code&gt;last()&lt;/code&gt; and the other
questions that count the values trap for a range whose ends are more than the largest &lt;code&gt;long&lt;/code&gt;
apart (the smallest &lt;code&gt;long&lt;/code&gt; to the largest), which only a range of &lt;code&gt;long&lt;/code&gt;s can be. &lt;code&gt;for&lt;/code&gt; over a range
written in place already counted any integer type, and still does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Value definitions in a &lt;code&gt;for&lt;/code&gt; with &lt;code&gt;yield&lt;/code&gt; (&lt;a href=&quot;/spec/collections/#generators-guards-and-yield&quot;&gt;for comprehensions&lt;/a&gt;):
&lt;code&gt;pattern = value&lt;/code&gt; after a generator, each with its own &lt;code&gt;if&lt;/code&gt; guards, written with no &lt;code&gt;val&lt;/code&gt;, and
never first. It is evaluated once per element that reaches it and binds in what follows. Where no
guard follows, it is a &lt;code&gt;val&lt;/code&gt; in the function passed to its generator’s source; where a guard
follows, it and the definitions before it after the same generator pair each element with its
value through the source’s &lt;code&gt;map&lt;/code&gt;, so it is evaluated for every element before that guard tests
any, and over a set or map the pair has to be hashable. A definition may not rebind a name its
generator or an earlier definition after it binds; a later generator may. Settled on the user’s
delegation 2026-11-11 as no longer open: built and pinned at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; by
&lt;code&gt;tests/run/for_yield_definitions.avin&lt;/code&gt; and &lt;code&gt;tests/run/spec_collections_comprehensions.avin&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Comprehensions over the mutable collections (&lt;a href=&quot;/spec/collections/#generators-guards-and-yield&quot;&gt;for comprehensions&lt;/a&gt;):
a mutable &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; have &lt;code&gt;withFilter&lt;/code&gt;, a lazy view as the immutable ones have, and a
mutable &lt;code&gt;Map&lt;/code&gt; a &lt;code&gt;map&lt;/code&gt; over its entries as pairs, so the first source’s kind decides the result as
elsewhere: a new mutable set or map, as an &lt;code&gt;Array&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt; or a &lt;code&gt;Deque&lt;/code&gt; gives a new one of its
own kind, the source unchanged.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;code&gt;avin.process&lt;/code&gt; (&lt;a href=&quot;/spec/system-library/&quot;&gt;system library&lt;/a&gt;): &lt;code&gt;args() -&amp;gt; Vector[string]&lt;/code&gt; holds the
arguments after the program’s name, and &lt;code&gt;programName()&lt;/code&gt; gives the name separately; &lt;code&gt;env(name)&lt;/code&gt; is
an &lt;code&gt;Option[string]&lt;/code&gt;; &lt;code&gt;exit(code: int) -&amp;gt; Nothing&lt;/code&gt; flushes standard output first, as a trap does.
Arguments are checked as UTF-8 at startup. A test run by &lt;code&gt;avin test&lt;/code&gt; sees no arguments. &lt;code&gt;main&lt;/code&gt;
may take the same vector: &lt;code&gt;main(args: Vector[string])&lt;/code&gt; (settled above).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;code&gt;avin.fs&lt;/code&gt; and &lt;code&gt;avin.io&lt;/code&gt; (&lt;a href=&quot;/spec/system-library/&quot;&gt;system library&lt;/a&gt;): &lt;code&gt;IoError&lt;/code&gt;, shared by every
module that does input or output, lives in &lt;code&gt;avin.io&lt;/code&gt; as a plain &lt;code&gt;data&lt;/code&gt; type with the variants
&lt;code&gt;NotFound&lt;/code&gt;, &lt;code&gt;PermissionDenied&lt;/code&gt;, &lt;code&gt;AlreadyExists&lt;/code&gt;, &lt;code&gt;IsADirectory&lt;/code&gt;, &lt;code&gt;NotADirectory&lt;/code&gt;,
&lt;code&gt;DirectoryNotEmpty&lt;/code&gt;, &lt;code&gt;InvalidUtf8(offset: long)&lt;/code&gt; and &lt;code&gt;Other(text: string)&lt;/code&gt;, and a &lt;code&gt;message()&lt;/code&gt;
sentence. &lt;code&gt;avin.fs&lt;/code&gt; reads and writes whole files (&lt;code&gt;readText&lt;/code&gt;, &lt;code&gt;readBytes&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;,
&lt;code&gt;appendText&lt;/code&gt;, &lt;code&gt;writeBytes&lt;/code&gt;, &lt;code&gt;appendBytes&lt;/code&gt;), asks &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;isDir&lt;/code&gt; and &lt;code&gt;isFile&lt;/code&gt;, and makes and
removes (&lt;code&gt;createDir&lt;/code&gt;, &lt;code&gt;createDirAll&lt;/code&gt;, &lt;code&gt;createTempDir&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;removeDir&lt;/code&gt;, &lt;code&gt;removeDirAll&lt;/code&gt;),
each failure an &lt;code&gt;IoError&lt;/code&gt; in a &lt;code&gt;Result&lt;/code&gt;. Writing replaces a file and appending creates one;
&lt;code&gt;createDirAll&lt;/code&gt; accepts a directory already there and &lt;code&gt;removeDirAll&lt;/code&gt; a path already gone.
&lt;code&gt;listDir(dir) -&amp;gt; Result[Vector[string], IoError]&lt;/code&gt; answers the entries’ names, without the
directory and without &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;..&lt;/code&gt;, sorted by code point, so two listings of an unchanged
directory agree.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Standard input and error, in &lt;code&gt;avin.io&lt;/code&gt; beside &lt;code&gt;IoError&lt;/code&gt; (&lt;a href=&quot;/spec/system-library/&quot;&gt;system library&lt;/a&gt;):
standard input as text through &lt;code&gt;readLine() -&amp;gt; Option[string]&lt;/code&gt;, &lt;code&gt;lines() -&amp;gt; Iterator[string]&lt;/code&gt; and
&lt;code&gt;readAll() -&amp;gt; string&lt;/code&gt;, sharing one runtime-held buffer. A line ends at &lt;code&gt;\n&lt;/code&gt; with a &lt;code&gt;\r&lt;/code&gt; before it
trimmed; the last line needs no terminator. Ill-formed UTF-8 becomes U+FFFD and a failed read ends
the input, so reading standard input answers no &lt;code&gt;IoError&lt;/code&gt;, where &lt;code&gt;fs.readText&lt;/code&gt; answers
&lt;code&gt;InvalidUtf8&lt;/code&gt;. &lt;code&gt;eprintln(x)&lt;/code&gt; mirrors &lt;code&gt;println&lt;/code&gt; on standard error and is in the prelude with
&lt;code&gt;StandardError&lt;/code&gt;, an unbuffered &lt;code&gt;Writer&lt;/code&gt;; every write to standard error flushes standard output
first. A test run by &lt;code&gt;avin test&lt;/code&gt; reads empty input.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Running and testing (stage 10): &lt;code&gt;avin run &amp;lt;program&amp;gt; [-O0 | -O2] [-- args]&lt;/code&gt; builds into
&lt;code&gt;.avin/build/&lt;/code&gt; in the program’s directory, reuses the executable while nothing it was built from
has changed, and exits with the program’s status, or 128 and the signal’s number for a trap. Its
arguments reach the process; reading them is &lt;code&gt;avin.process&lt;/code&gt;‘s, in the system library. A test is a
top-level &lt;code&gt;@test&lt;/code&gt; function of the program, in any module, taking nothing and yielding unit, named
by the function or by &lt;code&gt;@test(&amp;quot;a sentence&amp;quot;)&lt;/code&gt;; a program built for its tests need not have &lt;code&gt;main&lt;/code&gt;.
&lt;code&gt;run&lt;/code&gt; is the default command and the current directory the default program: &lt;code&gt;avin&lt;/code&gt; is &lt;code&gt;avin run .&lt;/code&gt;,
&lt;code&gt;avin &amp;lt;path&amp;gt; ...&lt;/code&gt; is &lt;code&gt;avin run &amp;lt;path&amp;gt; ...&lt;/code&gt; when the first argument is not a command name, and the
commands taking a program default it to &lt;code&gt;.&lt;/code&gt;. A command name is always the command; a path that
spells one is reached as &lt;code&gt;./test&lt;/code&gt;. &lt;code&gt;avin test&lt;/code&gt;‘s first argument is the program when it names an
existing path and the filter otherwise.
&lt;code&gt;avin test [&amp;lt;program&amp;gt;] [filter]&lt;/code&gt; builds one executable and runs each test in a process of its own, so
a trap stops only that test, reporting &lt;code&gt;ok&lt;/code&gt; or &lt;code&gt;FAIL&lt;/code&gt; per test grouped by file, the reason and the
test’s output under a failure, and &lt;code&gt;N passed, M failed&lt;/code&gt;; it exits 1 when any failed. The core
library’s &lt;code&gt;assert(condition)&lt;/code&gt;, &lt;code&gt;assert(condition, message)&lt;/code&gt; and &lt;code&gt;assertEq(actual, expected)&lt;/code&gt; (with
&lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; bounds, showing both values’ &lt;code&gt;Debug&lt;/code&gt; forms) trap at the assertion’s place.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Test attributes, hooks and &lt;code&gt;@tests&lt;/code&gt; files (&lt;a href=&quot;/spec/declarations/#tests&quot;&gt;declarations&lt;/a&gt;), following
Sysl’s model:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A test yields unit or a &lt;code&gt;Result[unit, E]&lt;/code&gt;&lt;/strong&gt; with &lt;code&gt;E: Display&lt;/code&gt;; an &lt;code&gt;Err&lt;/code&gt; fails it, reading
&lt;code&gt;test answered Err: &amp;lt;error&amp;gt;&lt;/code&gt; at the test’s name.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;@test&lt;/code&gt;‘s arguments&lt;/strong&gt;: a description first, then &lt;code&gt;should_trap&lt;/code&gt; (alone, or with text the run’s
output must contain), &lt;code&gt;timeout: N&lt;/code&gt; (whole seconds, 0 to 2147483, 0 for none, in place of the
run’s 60) and &lt;code&gt;ignore: &amp;quot;reason&amp;quot;&lt;/code&gt; (required and not empty), each at most once. &lt;code&gt;should_trap&lt;/code&gt; is
satisfied by a trap, not by a non-zero exit. An ignored test starts no process and runs no hook,
and the summary adds &lt;code&gt;, K ignored&lt;/code&gt; when K is not 0.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hooks&lt;/strong&gt; &lt;code&gt;@setup&lt;/code&gt;, &lt;code&gt;@teardown&lt;/code&gt;, &lt;code&gt;@setup_all&lt;/code&gt;, &lt;code&gt;@teardown_all&lt;/code&gt;, at most one of each per module,
top-level, taking and yielding nothing. &lt;code&gt;@setup&lt;/code&gt; runs in the test’s process; &lt;code&gt;@teardown&lt;/code&gt; there
after a test that returned and in a process of its own after one that trapped or timed out (not
after a failed &lt;code&gt;@setup&lt;/code&gt;); the &lt;code&gt;_all&lt;/code&gt; pair each in a process of their own, around the module’s
selected tests that are not ignored. A failed &lt;code&gt;@setup&lt;/code&gt; fails its test unrun; a failed
&lt;code&gt;@setup_all&lt;/code&gt; is a failure of its own and fails each of the module’s tests unrun, and skips
&lt;code&gt;@teardown_all&lt;/code&gt;; a failed &lt;code&gt;@teardown&lt;/code&gt; or &lt;code&gt;@teardown_all&lt;/code&gt; is a failure of its own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;@tests&lt;/code&gt; files&lt;/strong&gt; are checked by every command and built only by &lt;code&gt;avin test&lt;/code&gt;: their
module-level values are not computed in a program that runs. Only a &lt;code&gt;@test&lt;/code&gt; function, a hook
(a lambda in either counting as it) or another &lt;code&gt;@tests&lt;/code&gt; file may name what one declares; an impl
in one is for a type or of a trait it declares; &lt;code&gt;main&lt;/code&gt; is not declared in one.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Format specifiers (&lt;a href=&quot;/spec/strings-and-formatting/#format-specifiers&quot;&gt;strings and formatting&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Integers are signed in every base&lt;/strong&gt;: &lt;code&gt;%x&lt;/code&gt;, &lt;code&gt;%X&lt;/code&gt;, &lt;code&gt;%o&lt;/code&gt; and &lt;code&gt;%b&lt;/code&gt; write a negative value as &lt;code&gt;-&lt;/code&gt;
and its magnitude’s digits (&lt;code&gt;${-42}%x&lt;/code&gt; is &lt;code&gt;-2a&lt;/code&gt;), so the text does not depend on the value’s
width, and &lt;code&gt;+&lt;/code&gt; and the space flag apply to them as to &lt;code&gt;%d&lt;/code&gt;. There is no &lt;code&gt;%u&lt;/code&gt;; it is refused
with a pointer to &lt;code&gt;%d&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A flag that changes nothing under its conversion is an error&lt;/strong&gt;, as is a precision under &lt;code&gt;%c&lt;/code&gt;.
&lt;code&gt;%s&lt;/code&gt; refuses the numbers (integers, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;), which have conversions of their own; it
takes every other &lt;code&gt;Display&lt;/code&gt; value.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;%s&lt;/code&gt; counts characters&lt;/strong&gt;: its width and precision are characters, not bytes, as every
&lt;code&gt;Display&lt;/code&gt; width is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only a &lt;code&gt;%&lt;/code&gt; right after a hole is special&lt;/strong&gt;: there is no &lt;code&gt;%%&lt;/code&gt; escape; &lt;code&gt;%&lt;/code&gt; anywhere else, doubled
or not, is text.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A count written as a hole is an integer of any width&lt;/strong&gt;, not a &lt;code&gt;byte&lt;/code&gt;; a negative width pads on
the right, a negative precision is none, and a count beyond &lt;code&gt;int&lt;/code&gt; is the largest &lt;code&gt;int&lt;/code&gt;
(&lt;code&gt;FormatSpec.withWidth&lt;/code&gt;, &lt;code&gt;withPrecision&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;StringContext.f&lt;/code&gt;, called directly&lt;/strong&gt;, reads its specifiers as it runs: a malformed one, &lt;code&gt;%?&lt;/code&gt;
(its arguments are &lt;code&gt;Display&lt;/code&gt; values) and a count that is not an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt; trap; a value
under a conversion its type does not take renders in its own form.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: The core library’s own tests (&lt;a href=&quot;/spec/declarations/#tests&quot;&gt;tests&lt;/a&gt;): they live in &lt;code&gt;library/tests&lt;/code&gt;,
as a package’s live in its &lt;code&gt;tests&lt;/code&gt; directory, and are an ordinary program of &lt;code&gt;@test&lt;/code&gt; functions in
its root module, which &lt;code&gt;avin test library/tests&lt;/code&gt; runs and the compiler’s gate runs at &lt;code&gt;-O0&lt;/code&gt; and
&lt;code&gt;-O2&lt;/code&gt;. They test the library through its public names, as a program sees it. The directory is no
part of the core library every program is compiled with, and a &lt;code&gt;@test&lt;/code&gt; in the core library’s own
modules, like one in a dependency, is never a program’s test.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: A collection added to itself (&lt;a href=&quot;/spec/collections/#buffer&quot;&gt;collections&lt;/a&gt;): &lt;code&gt;b.addAll(b)&lt;/code&gt; and
&lt;code&gt;b ++= b&lt;/code&gt; on a &lt;code&gt;Buffer&lt;/code&gt; or a &lt;code&gt;Deque&lt;/code&gt; append the elements it held when the call began, once, and
&lt;code&gt;s --= s&lt;/code&gt; on a mutable &lt;code&gt;Set&lt;/code&gt; empties it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Superseded 2026-11-05&lt;/strong&gt; by the &lt;a href=&quot;/spec/time/&quot;&gt;dates and times&lt;/a&gt; entry that follows; kept as it
was. Settled by the user 2026-11-04: &lt;a href=&quot;/spec/system-library/#avin-time&quot;&gt;&lt;code&gt;avin.time&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;Duration&lt;/code&gt;, &lt;code&gt;Instant&lt;/code&gt; (monotonic) and &lt;code&gt;WallTime&lt;/code&gt;
(wall clock, a &lt;code&gt;Duration&lt;/code&gt; since the 1970 epoch) are data types counting whole microseconds in a
&lt;code&gt;long&lt;/code&gt;, overflow trapping; the two clocks are distinct types so their readings never mix. A
duration implements &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Sub&lt;/code&gt;, &lt;code&gt;Neg&lt;/code&gt;, and scales by a &lt;code&gt;long&lt;/code&gt; with its methods &lt;code&gt;*&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;; a
reading combines with a duration through its methods &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;, and two readings of one clock
through &lt;code&gt;-&lt;/code&gt; (or &lt;code&gt;since&lt;/code&gt;), which yields their &lt;code&gt;Duration&lt;/code&gt;. The
text forms are a duration’s largest-unit form (&lt;code&gt;1.5ms&lt;/code&gt;) and an ISO 8601 UTC timestamp. Sleeping
and calendar fields beyond the timestamp text are not part of it yet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-05: &lt;a href=&quot;/spec/time/&quot;&gt;dates and times&lt;/a&gt; (&lt;code&gt;avin.time&lt;/code&gt;) follow slate’s
date/time design with Avin’s spellings (types PascalCase, functions lowerCamelCase). Eight types:
&lt;code&gt;Instant&lt;/code&gt; (a point on the timeline, microseconds since 1970 UTC, displayed as ISO 8601 with &lt;code&gt;Z&lt;/code&gt;;
it replaces &lt;code&gt;WallTime&lt;/code&gt;), &lt;code&gt;Duration&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt; (a calendar date with no zone; no &lt;code&gt;Local&lt;/code&gt; prefix
anywhere), &lt;code&gt;Time&lt;/code&gt; (a time of day), &lt;code&gt;DateTime&lt;/code&gt; (a date and a time, no zone), &lt;code&gt;Zone&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt; (a
date-time in a zone, the only zoned type) and &lt;code&gt;Period&lt;/code&gt; (months and years). There is no monotonic
&lt;code&gt;Instant&lt;/code&gt;: &lt;code&gt;monotonic()&lt;/code&gt; answers a &lt;code&gt;Duration&lt;/code&gt;, a monotonic reading naming no point in time, and an
elapsed time is &lt;code&gt;monotonic() - start&lt;/code&gt;. Makers: &lt;code&gt;now()&lt;/code&gt;, &lt;code&gt;monotonic()&lt;/code&gt;, &lt;code&gt;date(y, m, d)&lt;/code&gt;,
&lt;code&gt;time(h, m, s)&lt;/code&gt;, &lt;code&gt;dateTime(…)&lt;/code&gt;, &lt;code&gt;zone(&amp;quot;America/Toronto&amp;quot;)&lt;/code&gt;, &lt;code&gt;localZone()&lt;/code&gt;, and &lt;code&gt;utc&lt;/code&gt;, a value
rather than a call; &lt;code&gt;epochSeconds&lt;/code&gt;, &lt;code&gt;epochMillis&lt;/code&gt; and &lt;code&gt;epochMicros&lt;/code&gt; to and from counts; the
durations &lt;code&gt;micros millis seconds minutes hours days weeks&lt;/code&gt;, also as methods (&lt;code&gt;2.hours&lt;/code&gt;); the
periods &lt;code&gt;months&lt;/code&gt; and &lt;code&gt;years&lt;/code&gt;. The implementation binds with &lt;code&gt;@sysl&lt;/code&gt; over Sysl 0.10.0’s &lt;code&gt;sysl.time&lt;/code&gt;
(&lt;code&gt;Date&lt;/code&gt;, &lt;code&gt;Time&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, &lt;code&gt;YearMonthDay&lt;/code&gt;, &lt;code&gt;Offset&lt;/code&gt;, &lt;code&gt;Weekday&lt;/code&gt;, &lt;code&gt;Resolution&lt;/code&gt;, &lt;code&gt;Zone&lt;/code&gt; over
&lt;code&gt;sysl.time.tzif&lt;/code&gt; with &lt;code&gt;offset_at&lt;/code&gt; and &lt;code&gt;resolve&lt;/code&gt;, &lt;code&gt;Zoned&lt;/code&gt;, &lt;code&gt;Period&lt;/code&gt;), with the system clock and the
local zone from &lt;code&gt;sysl.posix.time&lt;/code&gt;, and no new C. The choices the design makes beyond these are
under &lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Bindings to Sysl packages (&lt;a href=&quot;/spec/packages/#sysl-dependencies&quot;&gt;packages&lt;/a&gt;,
&lt;a href=&quot;/spec/sysl-bindings/#sysl-packages&quot;&gt;bindings&lt;/a&gt;): a manifest names the Sysl packages its bindings
reach in a block of its own, &lt;code&gt;sysl-dependencies&lt;/code&gt;, beside &lt;code&gt;dependencies&lt;/code&gt;, each entry written as an
Avin dependency is (&lt;code&gt;git&lt;/code&gt; with &lt;code&gt;version&lt;/code&gt; or &lt;code&gt;rev&lt;/code&gt;, or &lt;code&gt;path&lt;/code&gt;; never &lt;code&gt;workspace&lt;/code&gt;). The block is
separate because Sysl, not Avin, resolves, fetches and verifies those packages: they are not
Avin packages, so they take no part in Avin’s version selection, &lt;code&gt;avin.sum&lt;/code&gt;, &lt;code&gt;avin add&lt;/code&gt; or
&lt;code&gt;avin tidy&lt;/code&gt;. The shim package’s manifest lists every Sysl dependency of every package in the
program, so a library’s bindings build in any program that uses it; one name at two releases of
one coordinate takes the higher, and one name with any other two origins is refused naming both.
A fetched package may not name a Sysl directory. The shim archive and the cached executable are
keyed by these entries and by the sources of each Sysl package named by directory. Sysl’s other
dependency keys (&lt;code&gt;mount&lt;/code&gt;, &lt;code&gt;features&lt;/code&gt;, &lt;code&gt;options&lt;/code&gt;) are not offered yet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: The rest of the system library (&lt;a href=&quot;/spec/system-library/&quot;&gt;system library&lt;/a&gt;), each module following
the reference standard library’s names and shapes where Avin’s rules allow:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/spec/system-library/#the-environment-and-the-platform&quot;&gt;The environment and the platform&lt;/a&gt;&lt;/strong&gt;
are functions of &lt;code&gt;avin.process&lt;/code&gt;, beside &lt;code&gt;env&lt;/code&gt;, not a module of their own: &lt;code&gt;environment()&lt;/code&gt; as a
&lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;currentDir&lt;/code&gt;, &lt;code&gt;homeDir&lt;/code&gt;, &lt;code&gt;executable&lt;/code&gt;, &lt;code&gt;processors&lt;/code&gt;, &lt;code&gt;pid&lt;/code&gt; and &lt;code&gt;os()&lt;/code&gt;. There is no
property store and nothing sets a variable; a child’s variables are set on its command. Bindings:
&lt;code&gt;sysl.fs.current_dir&lt;/code&gt; and &lt;code&gt;home_dir&lt;/code&gt;, &lt;code&gt;sysl.env.current_exe&lt;/code&gt;, &lt;code&gt;sysl.process.pid&lt;/code&gt; (a &lt;code&gt;u32&lt;/code&gt;, which
fits a &lt;code&gt;long&lt;/code&gt;), &lt;code&gt;sysl.os&lt;/code&gt; through a mirror of &lt;code&gt;sysl.Os&lt;/code&gt;, and the runtime’s processor count.
&lt;code&gt;environment()&lt;/code&gt; needs &lt;code&gt;sysl.env.vars&lt;/code&gt;, which answers a &lt;code&gt;Buf&lt;/code&gt; of pairs: it waits for tuples as a
boundary type, a stage-7 addition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;Commands&lt;/a&gt;&lt;/strong&gt; in &lt;code&gt;avin.process&lt;/code&gt;: a &lt;code&gt;Command&lt;/code&gt; value, combined
with &lt;code&gt;|&lt;/code&gt; (a pipeline), &lt;code&gt;andThen&lt;/code&gt;, &lt;code&gt;orElse&lt;/code&gt; and &lt;code&gt;followedBy&lt;/code&gt;, redirected with &lt;code&gt;toFile&lt;/code&gt;,
&lt;code&gt;appendTo&lt;/code&gt;, &lt;code&gt;fromFile&lt;/code&gt; and &lt;code&gt;withInput&lt;/code&gt;, and run by &lt;code&gt;run()&lt;/code&gt; (the exit status), &lt;code&gt;output()&lt;/code&gt; (the
text, any status but success an &lt;code&gt;Err&lt;/code&gt;), &lt;code&gt;lines()&lt;/code&gt; (an iterator as output arrives) and &lt;code&gt;start()&lt;/code&gt;
(a &lt;code&gt;Child&lt;/code&gt;). Importing the module adds &lt;code&gt;run()&lt;/code&gt; and &lt;code&gt;output()&lt;/code&gt; to &lt;code&gt;string&lt;/code&gt;. &lt;strong&gt;Operators Avin cannot
define&lt;/strong&gt;: postfix &lt;code&gt;!&lt;/code&gt; and &lt;code&gt;!!&lt;/code&gt; (no method is called postfix, and &lt;code&gt;!&lt;/code&gt; is the language’s), and
the spellings with &lt;code&gt;#&lt;/code&gt; (&lt;code&gt;#&lt;/code&gt; was no operator character when this was built; it is one since
branch &lt;code&gt;lazy-cons-operator&lt;/code&gt;, and the words stay), so &lt;code&gt;#|&lt;/code&gt; is &lt;code&gt;|&lt;/code&gt;, and &lt;code&gt;#&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;#||&lt;/code&gt;, &lt;code&gt;###&lt;/code&gt;,
&lt;code&gt;#&amp;gt;&lt;/code&gt;, &lt;code&gt;#&amp;gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;#&amp;lt;&lt;/code&gt; are words; &lt;code&gt;run()&lt;/code&gt; is the status, where the reference’s &lt;code&gt;run()&lt;/code&gt; starts the
process, which here is &lt;code&gt;start()&lt;/code&gt;. Bindings: &lt;code&gt;sysl.process.spawn&lt;/code&gt; and &lt;code&gt;pipe&lt;/code&gt;, with a mirror of
&lt;code&gt;Stdio&lt;/code&gt; holding a &lt;code&gt;sysl.fs.File&lt;/code&gt; handle, &lt;code&gt;Spawned&lt;/code&gt; a handle waited for &lt;code&gt;blocking&lt;/code&gt;, &lt;code&gt;Status&lt;/code&gt;
mirrored as &lt;code&gt;ExitStatus&lt;/code&gt; itself, &lt;code&gt;Var&lt;/code&gt;, &lt;code&gt;sysl.fs.create&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt; and &lt;code&gt;open&lt;/code&gt; for the
redirections, and &lt;code&gt;sysl.io.FdReader&lt;/code&gt; for &lt;code&gt;lines()&lt;/code&gt;, which answers bytes as they arrive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/spec/system-library/#source&quot;&gt;&lt;code&gt;Source&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; in &lt;code&gt;avin.io&lt;/code&gt;: &lt;code&gt;fromFile&lt;/code&gt; (read whole, every failure
up front), &lt;code&gt;fromString&lt;/code&gt;, &lt;code&gt;stdin()&lt;/code&gt;, and &lt;code&gt;lines()&lt;/code&gt;, &lt;code&gt;chars()&lt;/code&gt; and &lt;code&gt;readAll()&lt;/code&gt;, each consuming. The
reference’s &lt;code&gt;getLines&lt;/code&gt; and &lt;code&gt;mkString&lt;/code&gt; are &lt;code&gt;lines&lt;/code&gt; and &lt;code&gt;readAll&lt;/code&gt;, the names &lt;code&gt;avin.io&lt;/code&gt; already uses.
No new binding: it is written over &lt;code&gt;fs.readText&lt;/code&gt; and standard input’s buffer, with one runtime
entry taking a character from that buffer for &lt;code&gt;chars()&lt;/code&gt;. Not blocked.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/spec/system-library/#avin-random&quot;&gt;&lt;code&gt;avin.random&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;: a &lt;code&gt;Random&lt;/code&gt; class (&lt;code&gt;Random(seed)&lt;/code&gt;
reproducible, &lt;code&gt;Random()&lt;/code&gt; seeded by the platform) with &lt;code&gt;nextInt&lt;/code&gt;, &lt;code&gt;nextLong&lt;/code&gt;, bounded forms,
&lt;code&gt;between&lt;/code&gt;, &lt;code&gt;nextReal&lt;/code&gt;, &lt;code&gt;nextBoolean&lt;/code&gt;, &lt;code&gt;nextGaussian&lt;/code&gt;, &lt;code&gt;nextBytes&lt;/code&gt;, &lt;code&gt;alphanumeric&lt;/code&gt;, &lt;code&gt;shuffle&lt;/code&gt; and
&lt;code&gt;setSeed&lt;/code&gt;; the companion’s methods use one shared, locked generator. PCG32, written in Avin with
the wrapping operators, so a seed gives the same sequence everywhere. Binding: one runtime
function for the platform’s seed over &lt;code&gt;sysl.posix.rand.seed_from_os&lt;/code&gt;, since a &lt;code&gt;u64&lt;/code&gt; above
&lt;code&gt;long.MaxValue&lt;/code&gt; traps at a binding’s result; it answers the entropy’s top 63 bits.
&lt;code&gt;nextGaussian&lt;/code&gt; uses &lt;code&gt;avin.math&lt;/code&gt;‘s &lt;code&gt;sqrt&lt;/code&gt; and &lt;code&gt;log&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/spec/system-library/#avin-net&quot;&gt;&lt;code&gt;avin.net&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;: &lt;code&gt;TcpStream&lt;/code&gt; and &lt;code&gt;TcpListener&lt;/code&gt;; &lt;code&gt;Url&lt;/code&gt;, parsed
and percent-encoded, written in Avin; an HTTP/1.1 client (&lt;code&gt;get&lt;/code&gt;, &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;send&lt;/code&gt; with a &lt;code&gt;Request&lt;/code&gt;)
written in Avin over the TCP stream, a status never an error. &lt;code&gt;IoError&lt;/code&gt; gains
&lt;code&gt;ConnectionRefused&lt;/code&gt;, &lt;code&gt;ConnectionReset&lt;/code&gt; and &lt;code&gt;TimedOut&lt;/code&gt;. Bindings: &lt;code&gt;sysl.net.resolve&lt;/code&gt;, &lt;code&gt;socket&lt;/code&gt;
and the &lt;code&gt;Socket&lt;/code&gt; methods, held as an opaque handle (a &lt;code&gt;Socket&lt;/code&gt;, and the &lt;code&gt;Address&lt;/code&gt; it connects
to, are not boundary types). &lt;code&gt;Url&lt;/code&gt; needs neither. &lt;code&gt;https&lt;/code&gt; takes a Sysl TLS package, named in
the library’s &lt;code&gt;sysl-dependencies&lt;/code&gt; and bound as any package is; opaque handles and bindings to
Sysl packages beyond the standard library are both in the compiler.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/spec/system-library/#concurrency&quot;&gt;Concurrency&lt;/a&gt;&lt;/strong&gt; stays in &lt;code&gt;avin.threads&lt;/code&gt;; there is no
separate concurrency module. The reference’s futures map onto what is there (&lt;code&gt;successful&lt;/code&gt;, &lt;code&gt;all&lt;/code&gt;
for &lt;code&gt;sequence&lt;/code&gt;, &lt;code&gt;first&lt;/code&gt; for &lt;code&gt;firstCompletedOf&lt;/code&gt;, &lt;code&gt;await&lt;/code&gt; for waiting with a time limit); added are
&lt;code&gt;Future.traverse&lt;/code&gt;, &lt;code&gt;mapErr&lt;/code&gt; and &lt;code&gt;orElse&lt;/code&gt; on a future of a &lt;code&gt;Result&lt;/code&gt; (its &lt;code&gt;recover&lt;/code&gt; and
&lt;code&gt;fallbackTo&lt;/code&gt;), an &lt;code&gt;Executor&lt;/code&gt; for pools of one’s own (its execution context, chosen explicitly),
&lt;code&gt;threads.blocking(body)&lt;/code&gt; and &lt;code&gt;threads.sleep(d)&lt;/code&gt;. There is no &lt;code&gt;failed&lt;/code&gt; or &lt;code&gt;filter&lt;/code&gt;, since a future
carries no failure. Bindings: none beyond a runtime timed wait for &lt;code&gt;sleep&lt;/code&gt;. Not blocked.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JSON&lt;/strong&gt; is a package of its own, not part of the system library: the package
&lt;code&gt;dev.avinlang.json&lt;/code&gt; (settled by the user 2026-11-13; see that entry).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Lower bounds and the expected type (&lt;a href=&quot;/spec/generics/#lower-bounds&quot;&gt;generics&lt;/a&gt;): the expected type
decides a lower-bounded type argument only where it admits the bound; otherwise the argument is
inferred from the bound and the arguments, and the result is passed as any value is. So
&lt;code&gt;println(m.getOrElse(k, &amp;quot;none&amp;quot;), n)&lt;/code&gt; on a &lt;code&gt;Map[string, string]&lt;/code&gt;, where each argument expects a
&lt;code&gt;Display&lt;/code&gt;, takes &lt;code&gt;W&lt;/code&gt; as &lt;code&gt;string&lt;/code&gt; rather than reporting &lt;code&gt;Display&lt;/code&gt; as no supertype of &lt;code&gt;string&lt;/code&gt;. A
delayed (by-name) argument widens an open lower-bounded type argument as any other argument does:
&lt;code&gt;cats.getOrElse(k, dog)&lt;/code&gt; is an &lt;code&gt;Animal&lt;/code&gt;. Both keep programs working that called the methods before
they took &lt;code&gt;[W &amp;gt;: V]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Trait fields (&lt;a href=&quot;/spec/declarations/#trait&quot;&gt;declarations&lt;/a&gt;): a trait’s field declares its type, since
each conforming class’s layout and the trait’s &lt;code&gt;val&lt;/code&gt; are known before any body is checked; it is
public, as every member of a trait is, and is never &lt;code&gt;lazy&lt;/code&gt;. A class never overrides a trait’s
field, &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt;: declaring a field of its name is an error rather than an override. A trait
never redeclares, with a value, a &lt;code&gt;val&lt;/code&gt; of a trait it requires.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: The wrapping conversion is spelled &lt;code&gt;i8.wrap(x)&lt;/code&gt;, as the wrapping operators are spelled &lt;code&gt;+%&lt;/code&gt;: the
integer type’s name, &lt;code&gt;.wrap&lt;/code&gt;, one operand, any integer target (a bounded type parameter included,
&lt;code&gt;T.wrap(n)&lt;/code&gt;). The core library needs it to test whether a value fits a narrower width (the formatter
converts a generic integer to &lt;code&gt;long&lt;/code&gt; and back).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;a href=&quot;/spec/regex/&quot;&gt;&lt;code&gt;avin.regex&lt;/code&gt;&lt;/a&gt;: the pattern language and its matching follow the established
backtracking dialect exactly: leftmost-first alternation, greedy, reluctant and possessive
repetition, atomic groups, bounded lookbehind (a repetition without an upper bound in one is an
error), and the same rules for what a repeated group captures; &lt;code&gt;\d&lt;/code&gt;, &lt;code&gt;\s&lt;/code&gt;, &lt;code&gt;\w&lt;/code&gt;, &lt;code&gt;\b&lt;/code&gt; and the
POSIX classes are ASCII unless &lt;code&gt;U&lt;/code&gt; makes them Unicode’s, and &lt;code&gt;i&lt;/code&gt; folds only ASCII without &lt;code&gt;u&lt;/code&gt;. Matching walks characters (scalar
values); every offset in the API is a byte offset, and a &lt;code&gt;PatternError&lt;/code&gt;‘s index counts the
pattern’s characters. There is no null: &lt;code&gt;group(i)&lt;/code&gt;, &lt;code&gt;group(name)&lt;/code&gt;, &lt;code&gt;before(i)&lt;/code&gt;, &lt;code&gt;after(i)&lt;/code&gt; answer
&lt;code&gt;Option[string]&lt;/code&gt;, &lt;code&gt;subgroups()&lt;/code&gt; a &lt;code&gt;List[Option[string]]&lt;/code&gt;, and &lt;code&gt;start(i)&lt;/code&gt;/&lt;code&gt;end(i)&lt;/code&gt; -1 for a group
that took no part. Members without arguments are methods (&lt;code&gt;&amp;quot;a+&amp;quot;.r()&lt;/code&gt;, &lt;code&gt;m.start()&lt;/code&gt;). &lt;code&gt;Regex(p)&lt;/code&gt;
traps on an invalid pattern with the error’s message and &lt;code&gt;Regex.compile(p)&lt;/code&gt; answers a
&lt;code&gt;Result[Regex, PatternError]&lt;/code&gt;; a group number or name the match does not have traps. Scripts,
blocks, the binary properties beyond the general category (&lt;code&gt;Alphabetic&lt;/code&gt;, &lt;code&gt;Uppercase&lt;/code&gt;,
&lt;code&gt;Lowercase&lt;/code&gt;, &lt;code&gt;Ideographic&lt;/code&gt;, &lt;code&gt;Word&lt;/code&gt;, &lt;code&gt;Alnum&lt;/code&gt;, emoji), the flag &lt;code&gt;U&lt;/code&gt;, &lt;code&gt;\X&lt;/code&gt; and &lt;code&gt;\b{g}&lt;/code&gt; answer from
tables generated from the Unicode Character Database, of the version the general categories come
from; the flag &lt;code&gt;c&lt;/code&gt; and &lt;code&gt;\N{…}&lt;/code&gt; are refused with an &lt;code&gt;Unsupported&lt;/code&gt; error. Replacing and splitting
follow the same dialect: &lt;code&gt;replaceAllIn&lt;/code&gt; (a replacement, or a &lt;code&gt;(Match) -&amp;gt; string&lt;/code&gt; whose result is
read as one), &lt;code&gt;replaceFirstIn&lt;/code&gt;, &lt;code&gt;replaceSomeIn&lt;/code&gt;, &lt;code&gt;split&lt;/code&gt; answering an &lt;code&gt;Array[string]&lt;/code&gt; with the
empty pieces at the end dropped, &lt;code&gt;Pattern.split(s, limit = 0)&lt;/code&gt;, &lt;code&gt;Regex.quote&lt;/code&gt; and
&lt;code&gt;Regex.quoteReplacement&lt;/code&gt;; &lt;code&gt;$n&lt;/code&gt; takes digits while they name a group, &lt;code&gt;${name}&lt;/code&gt; is the pattern’s
own name only, and a reference that cannot be resolved traps with the dialect’s message.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Extractor patterns (&lt;a href=&quot;/spec/operators-and-control-flow/#extractor-patterns&quot;&gt;control flow&lt;/a&gt;):
&lt;code&gt;Name(p…)&lt;/code&gt; names a variant wherever one of that name is in scope, and only otherwise a value (an
object, a companion, a local) whose type has &lt;code&gt;unapply&lt;/code&gt; or &lt;code&gt;unapplySeq&lt;/code&gt;; where it has both,
&lt;code&gt;unapply&lt;/code&gt; is used (the methods are now found through the extractor traits, settled 2026-11-19
below). &lt;code&gt;unapply&lt;/code&gt; answers a &lt;code&gt;bool&lt;/code&gt;, matched with no patterns (&lt;code&gt;Even()&lt;/code&gt;), or an
&lt;code&gt;Option&lt;/code&gt;, one pattern matching its value whole and several a tuple’s parts. &lt;code&gt;unapplySeq&lt;/code&gt; answers
an &lt;code&gt;Option&lt;/code&gt; of a sequence, matched as a sequence pattern; the prefix-and-sequence form is not
taken. The matched value is passed to the method as it is, with no type test first, so the
method’s parameter accepts the matched value’s type. An extractor pattern never counts toward
exhaustiveness, and since a binding’s or a &lt;code&gt;for&lt;/code&gt;‘s pattern must cover every value, extractors
appear in &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;, clauses and match functions only.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Rest patterns (&lt;a href=&quot;/spec/collections/#sequence-patterns&quot;&gt;collections&lt;/a&gt;): &lt;code&gt;rest*&lt;/code&gt; or &lt;code&gt;_*&lt;/code&gt;, last in a
sequence pattern or an &lt;code&gt;unapplySeq&lt;/code&gt; extractor’s patterns, binds what the patterns before it leave:
on a list the tail, so &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;[head, tail*]&lt;/code&gt; cover every list; on another sequence what
&lt;code&gt;drop(n)&lt;/code&gt; answers, a &lt;code&gt;Vector&lt;/code&gt;, and there too sequence patterns count lengths, so &lt;code&gt;[]&lt;/code&gt; and
&lt;code&gt;[head, tail*]&lt;/code&gt; cover every sequence. &lt;code&gt;[rest*]&lt;/code&gt; alone is the whole sequence, of its own type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: A regex as an extractor (&lt;a href=&quot;/spec/regex/#regex&quot;&gt;regular expressions&lt;/a&gt;): &lt;code&gt;Regex.unapplySeq(s)&lt;/code&gt;
answers the groups’ texts as a &lt;code&gt;List[string]&lt;/code&gt; where &lt;code&gt;s&lt;/code&gt; matches as &lt;code&gt;matches&lt;/code&gt; asks, the whole of it
or, unanchored, any part. A group that took no part gives the empty string, since a &lt;code&gt;string&lt;/code&gt; has
no null. &lt;code&gt;Groups&lt;/code&gt;, a top-level object of &lt;code&gt;avin.regex&lt;/code&gt;, takes apart any &lt;code&gt;Match&lt;/code&gt;‘s groups, &lt;code&gt;None&lt;/code&gt;
for a pattern with none. There is no &lt;code&gt;unapplySeq&lt;/code&gt; taking a &lt;code&gt;Match&lt;/code&gt; on &lt;code&gt;Regex&lt;/code&gt; itself, which
would need a match to know the regex that found it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: Sysl handles (&lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl bindings&lt;/a&gt;): a &lt;code&gt;class&lt;/code&gt; declared with &lt;code&gt;@sysl&lt;/code&gt;
naming a Sysl type has no parameters, fields or constructor and is made only by a binding that
returns it, directly or as the value of an &lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Result&lt;/code&gt;. A method without a body is bound
to the Sysl method of its name’s words in snake_case, or to the one its own &lt;code&gt;@sysl(&amp;quot;name&amp;quot;)&lt;/code&gt;
names. Every handle has &lt;code&gt;close()&lt;/code&gt;, which gives its counted reference back and does nothing a
second time; a bound method on a closed handle traps at the call with “&lt;code&gt;Name&lt;/code&gt; is closed”; a
handle never closed is given back by a finalizer when the collector frees it. A handle compares
by identity, and has no &lt;code&gt;Display&lt;/code&gt;.
Settled by the user 2026-11-04, replacing “a collection of handles does not cross” and “a handle
crosses back into Sysl only as the receiver of its own methods”: a binding’s result may also be
an &lt;code&gt;Array&lt;/code&gt; or &lt;code&gt;Vector&lt;/code&gt; of handles, also inside an &lt;code&gt;Option&lt;/code&gt; or &lt;code&gt;Result&lt;/code&gt;, made from a Sysl slice or
&lt;code&gt;Buf&lt;/code&gt;, each element a handle of its own with its own reference and finalizer. A handle by itself
goes into Sysl as the receiver of its own methods or as a parameter of any binding or bound
method; a closed one passed traps at the call as a bound method on one does. A handle inside an
&lt;code&gt;Option&lt;/code&gt; or a collection still does not go into Sysl.
Settled by the user 2026-11-04: &lt;strong&gt;how a handle is passed to a Sysl parameter&lt;/strong&gt;. The shim cannot
see the Sysl parameter’s type, so it lets Sysl choose: a trait, always held by a counted
reference, is passed as the handle’s reference, which the parameter shares; any other type is
passed as the parameter’s type asks of a generic helper, by value (a copy), as a pointer to the
handle’s own value, or at a &lt;code&gt;&amp;amp;T&lt;/code&gt; as the handle’s own counted reference, which the parameter
shares. A &lt;code&gt;*T&lt;/code&gt; parameter of a type with a destructor is refused by Sysl at the binding. Revised
on the user’s delegation 2026-11-05 (branch &lt;code&gt;sysl-091&lt;/code&gt;): from Sysl 0.9.1 the helper settles at
the &lt;code&gt;&amp;amp;T&lt;/code&gt;, so a type with a destructor needs no arm of its own and the shim tells only a trait
apart; under 0.9.0 a &lt;code&gt;&amp;amp;T&lt;/code&gt; parameter of a type without a destructor received a reference to a copy.
Since Sysl now checks the helper’s body against the parameter’s type, each handle parameter of a
binding and each handle field of a mirror has helpers of its own, written among that binding’s or
mirror’s lines of the shim, so a handle Sysl does not take there is reported as the binding or the
mirror not matching, in the handle’s and the place’s Sysl types, and no diagnostic names the
shim’s functions (the reject corpus checks that none does). Alternatives weighed: one helper per
handle type, reported at the handle class (which names neither the binding nor the parameter at
fault); explicit type arguments at each call (the shim cannot see the Sysl parameter’s type).
Settled by the user 2026-11-04: &lt;strong&gt;a handle is never used by two threads at once&lt;/strong&gt;, since its
counted reference’s count is not atomic. Each handle records an owner, and every use (a bound
method, the handle passed as a parameter, &lt;code&gt;close()&lt;/code&gt;) compares it with the running code’s and traps
with “&lt;code&gt;Name&lt;/code&gt; belongs to another thread” where they differ. The owner is an execution context the
runtime can hand over, not an operating system thread: a thread’s body, a pool task whichever
worker runs it, and later an actor, re-pointed to whichever thread runs it, so an actor’s handles
never trap between its messages; the check is one compare with a word of the running thread’s
context, which the runtime sets. Ownership moves: what a thread’s or a future’s body reaches that
the caller owns becomes the body’s at its start, and the caller’s later use traps; when the body
returns, what it was given and what it returns are in transit, as are a future’s value and what a
callback registered on one reaches, and the first code to use a handle in transit takes it. The
finalizer never checks: it runs only on an unreachable handle, on the collecting thread while the
others are stopped.
Settled by the user 2026-11-04, replacing “no mirror holds a handle”: &lt;strong&gt;a Sysl mirror’s field may
be a handle&lt;/strong&gt;, by itself (not in an &lt;code&gt;Option&lt;/code&gt;, a collection or a tuple), so that Sysl’s
&lt;code&gt;sysl.process.Stdio&lt;/code&gt; reaches Avin with its &lt;code&gt;ToFile(file: File)&lt;/code&gt; and &lt;code&gt;FromFile(file: File)&lt;/code&gt;. Into
Sysl the field is passed exactly as a handle parameter is, its reference shared for a type with a
destructor and otherwise a copy or a pointer as the Sysl field asks, with the same traps at the
call: “&lt;code&gt;Name&lt;/code&gt; is closed” and “&lt;code&gt;Name&lt;/code&gt; belongs to another thread”. Out of Sysl, which needed nothing
more, each such field becomes a handle of its own, as a handle result does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Tuples cross the Sysl boundary&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#boundary-types&quot;&gt;Sysl bindings&lt;/a&gt;).
A tuple of boundary types is a Sysl tuple of the same arity, in each direction, each part converted
as it would be alone: an integer part out of Sysl takes any Sysl integer with the range check, and
tuples nest in one another, in &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;Vector&lt;/code&gt;, and in a mirror’s fields.
A handle may be a part of a tuple that is a binding’s result or the value of its &lt;code&gt;Option&lt;/code&gt; or
&lt;code&gt;Result&lt;/code&gt;, so &lt;code&gt;accept&lt;/code&gt; answers &lt;code&gt;Result[(Socket, Address), IoError]&lt;/code&gt;; a tuple holding a handle does
not go into Sysl or sit in a collection. &lt;code&gt;avin.process&lt;/code&gt; has &lt;code&gt;environment()&lt;/code&gt; over &lt;code&gt;sysl.env.vars&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Text blocks under an interpolator that reads no escapes&lt;/strong&gt; (&lt;a href=&quot;/spec/strings-and-formatting/#text-blocks&quot;&gt;text
blocks&lt;/a&gt;). The parts &lt;code&gt;raw&amp;quot;&amp;quot;&amp;quot;…&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; and a program’s own
interpolators are given have the block’s indentation and trailing blanks dropped but no escape
read, and since joining a line with &lt;code&gt;\&lt;/code&gt; is an escape, no line joined: the &lt;code&gt;\&lt;/code&gt; and the line break
after it reach the interpolator as written. &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;f&lt;/code&gt; join lines in the lexer. A backslash
directly before a quote or a backslash is taken with it under every prefix, so &lt;code&gt;\&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; does not end
a &lt;code&gt;raw&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; block and &lt;code&gt;\\&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; does, as &lt;code&gt;raw&amp;quot;…&amp;quot;&lt;/code&gt; does not end at &lt;code&gt;\&amp;quot;&lt;/code&gt; and does at &lt;code&gt;\\&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;A block’s first &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; closes it&lt;/strong&gt; (&lt;a href=&quot;/spec/strings-and-formatting/#text-blocks&quot;&gt;text blocks&lt;/a&gt;),
so &lt;code&gt;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&lt;/code&gt; is the end of the block and a stray quote; a block ending in a quote writes it &lt;code&gt;\&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;&lt;code&gt;avin.random&lt;/code&gt;‘s details&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#avin-random&quot;&gt;system library&lt;/a&gt;), where the
chapter left them open, so that a seed’s numbers are fixed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Every generator uses PCG32’s stream 54 (increment 109), the reference implementation’s
demonstration stream, so &lt;code&gt;Random(42).nextInt()&lt;/code&gt; gives its published first output, &lt;code&gt;0xa15c02b7&lt;/code&gt;
(as an &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;-1587805513&lt;/code&gt;). Seeding is the reference’s: one step from zero, the seed added,
one step more.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nextLong&lt;/code&gt; is two draws, the first the high half; &lt;code&gt;nextBoolean&lt;/code&gt; is a draw’s top bit; &lt;code&gt;nextReal&lt;/code&gt;
is a 64-bit draw’s top 53 bits over 2^53; &lt;code&gt;nextInt(n)&lt;/code&gt; rejects 32-bit draws below &lt;code&gt;2^32 % n&lt;/code&gt;,
and &lt;code&gt;nextLong(n)&lt;/code&gt; and &lt;code&gt;between&lt;/code&gt; on &lt;code&gt;long&lt;/code&gt; reject 64-bit draws below &lt;code&gt;2^64 % n&lt;/code&gt;; &lt;code&gt;between&lt;/code&gt; on &lt;code&gt;int&lt;/code&gt;
is &lt;code&gt;nextInt&lt;/code&gt; of the span where it fits an &lt;code&gt;int&lt;/code&gt;, and &lt;code&gt;nextLong&lt;/code&gt; of it otherwise.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;between&lt;/code&gt; on &lt;code&gt;real&lt;/code&gt; draws &lt;code&gt;min + nextReal() * (max - min)&lt;/code&gt; again while it rounds up to &lt;code&gt;max&lt;/code&gt;,
and traps on a NaN bound and where &lt;code&gt;max - min&lt;/code&gt; is infinite, besides &lt;code&gt;min &amp;gt;= max&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nextGaussian&lt;/code&gt; is the polar method, keeping the second value of each pair for the next call;
&lt;code&gt;setSeed&lt;/code&gt; drops it. &lt;code&gt;nextBytes&lt;/code&gt; takes four bytes from each draw, lowest first; a negative count
traps. &lt;code&gt;alphanumeric&lt;/code&gt; draws &lt;code&gt;nextInt(62)&lt;/code&gt; per character, digits, then upper, then lower case.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;a href=&quot;/spec/regex/#unicode-properties&quot;&gt;&lt;code&gt;avin.regex&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;\b{g}&lt;/code&gt; decides a boundary by the grapheme
cluster rules over the whole text before it, so it is never inside a cluster: not between the
two regional indicators of a flag, nor inside an emoji joined by a zero width joiner or an Indic
conjunct. &lt;code&gt;\X&lt;/code&gt; matches the cluster starting where it stands, one way only, and has no bounded
length, so a lookbehind may not hold it. A script is named by any of its names in
&lt;code&gt;PropertyValueAliases.txt&lt;/code&gt;, ignoring case, and only the scripts &lt;code&gt;Scripts.txt&lt;/code&gt; lists, with
&lt;code&gt;Unknown&lt;/code&gt;, exist; a block by its name in &lt;code&gt;Blocks.txt&lt;/code&gt;, that name without spaces, or any of its
names in &lt;code&gt;PropertyValueAliases.txt&lt;/code&gt;, short ones included, ignoring case.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;blocking bindings&lt;/a&gt;: a
binding whose Sysl call may wait is written &lt;code&gt;@sysl(&amp;quot;module.name&amp;quot;, blocking)&lt;/code&gt;, and a handle’s
method bound by its own name &lt;code&gt;@sysl(blocking)&lt;/code&gt;; &lt;code&gt;blocking&lt;/code&gt; is a bare word, written once, and
nothing else follows the name. The shim converts every argument and takes a handle method’s own
share of the Sysl value, then marks the thread safe for the collector, makes the call, marks it
running again (waiting out a collection in progress) and only then converts the result; bytes a
handle’s method answers are copied into Sysl memory before the thread leaves the safe region. A
blocking call therefore never reads or writes the Avin heap, and an argument that is a pointer
into it, such as a buffer Sysl fills, would need its object held by a frame for the whole call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;a href=&quot;/spec/system-library/#url&quot;&gt;&lt;code&gt;Url&lt;/code&gt;&lt;/a&gt; follows RFC 3986 as the
established library’s URI does, beyond the first design: user information; IPv6 hosts in
brackets, with a zone; &lt;code&gt;base.resolve(ref)&lt;/code&gt; by section 5.2, dot-segment removal included;
&lt;code&gt;withScheme&lt;/code&gt;, &lt;code&gt;withUserInfo&lt;/code&gt;, &lt;code&gt;withHost&lt;/code&gt;, &lt;code&gt;withPort&lt;/code&gt;, &lt;code&gt;withPath&lt;/code&gt;, &lt;code&gt;withQuery&lt;/code&gt; and &lt;code&gt;withFragment&lt;/code&gt;;
and a trapping &lt;code&gt;Url(text)&lt;/code&gt; beside &lt;code&gt;Url.parse(text)&lt;/code&gt;, as &lt;code&gt;Regex(p)&lt;/code&gt; beside &lt;code&gt;Regex.compile(p)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Actors and state machines (&lt;a href=&quot;/spec/actors/&quot;&gt;actors and state machines&lt;/a&gt;), settled by the user
2026-11-04 as written. They answer the open questions on how actors and machines work and whether
their words are reserved.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Messages are checked by &lt;code&gt;Sendable&lt;/code&gt;&lt;/strong&gt;, a trait the compiler decides for each type from its
structure and that is written as a bound; &lt;code&gt;ActorRef[-M: Sendable]&lt;/code&gt; makes the check once, where a
message type is named, never at a send. An actor’s parameters and every type &lt;code&gt;ask&lt;/code&gt; and &lt;code&gt;adapter&lt;/code&gt;
carry are sendable too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;What is sendable&lt;/strong&gt;: the scalars, &lt;code&gt;unit&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt;; tuples and &lt;code&gt;data&lt;/code&gt; of sendable fields; the
immutable collections of sendable elements; a final class or an &lt;code&gt;object&lt;/code&gt; with no &lt;code&gt;var&lt;/code&gt; field and
only sendable fields; a trait declared &lt;code&gt;: Sendable&lt;/code&gt;, each implementor checked; &lt;code&gt;ActorRef&lt;/code&gt;,
&lt;code&gt;Behaviour&lt;/code&gt;, and &lt;code&gt;Future&lt;/code&gt;, &lt;code&gt;Promise&lt;/code&gt;, &lt;code&gt;Channel&lt;/code&gt; and &lt;code&gt;Atomic&lt;/code&gt; of a sendable type; &lt;code&gt;Mutex&lt;/code&gt; of any
type (the one deliberate door to shared mutable state); &lt;code&gt;Once&lt;/code&gt;; Sysl handles; &lt;code&gt;Isolated[T]&lt;/code&gt;. Not:
arrays, buffers, deques, mutable maps and sets, classes with a &lt;code&gt;var&lt;/code&gt; or an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt;
class, machines, function values (their captures are not in their type) and &lt;code&gt;Any&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Ownership transfer.&lt;/strong&gt; A Sysl handle in a message is put in transit by the send and taken by its
first user, the receiver; the sender’s later use traps, through the handle’s owner check. A mutable
object graph moves as an &lt;code&gt;Isolated[T]&lt;/code&gt;, made by &lt;code&gt;isolate(body)&lt;/code&gt;: the compiler checks the body reads
only sendable values from around it and that nothing it calls, transitively, reaches module-level
mutable state; &lt;code&gt;take()&lt;/code&gt; gets it out once (a second take traps) and &lt;code&gt;with(f)&lt;/code&gt; works on it in place
under the same check.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Declaring an actor&lt;/strong&gt;: &lt;code&gt;actor Name[T](params) receives M&lt;/code&gt;; the body runs once at the actor’s start
and holds its fields; &lt;code&gt;receive&lt;/code&gt; holds &lt;code&gt;match&lt;/code&gt; arms over &lt;code&gt;M&lt;/code&gt;, checked for exhaustiveness; methods
are private helpers; &lt;code&gt;self&lt;/code&gt; is the actor’s &lt;code&gt;ActorRef[M]&lt;/code&gt;, and the object holding its state is
never a value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Behaviours and &lt;code&gt;spawn&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Counter(0)&lt;/code&gt; is an immutable &lt;code&gt;Behaviour[M]&lt;/code&gt;, and
&lt;code&gt;spawn(behaviour, onFailure = Escalate, executor = Executor.shared())&lt;/code&gt; starts it and answers an
&lt;code&gt;ActorRef[M]&lt;/code&gt;, in &lt;code&gt;avin.actors&lt;/code&gt;. Code an actor runs starts a child; code elsewhere a top-level actor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;&lt;code&gt;tell&lt;/code&gt; and the mailbox&lt;/strong&gt;: &lt;code&gt;tell(message)&lt;/code&gt; never waits and never fails (no &lt;code&gt;!&lt;/code&gt;, which is
reserved); the mailbox is unbounded; one sender’s messages to one actor arrive in order; a message
to an ended actor is dropped. (Revised 2026-11-19, branch &lt;code&gt;bounded-mailbox&lt;/code&gt;: unbounded unless the
actor is spawned with a &lt;code&gt;Bounded&lt;/code&gt; mailbox, a full one’s &lt;code&gt;tell&lt;/code&gt; dropping by its overflow policy, and
&lt;code&gt;AskError&lt;/code&gt; gaining &lt;code&gt;Full&lt;/code&gt;; the entry under Actor patterns.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;&lt;code&gt;ask&lt;/code&gt;&lt;/strong&gt; is &lt;code&gt;ask(make: ActorRef[R] -&amp;gt; M, timeout: Duration) -&amp;gt; Future[Result[R, AskError]]&lt;/code&gt;, the
timeout required, &lt;code&gt;AskError&lt;/code&gt; being &lt;code&gt;TimedOut&lt;/code&gt; or &lt;code&gt;Ended&lt;/code&gt;; reply addresses are ordinary
&lt;code&gt;ActorRef[R]&lt;/code&gt;s; &lt;code&gt;adapter(f)&lt;/code&gt; makes a reference translating another protocol into the actor’s own;
&lt;code&gt;pipeToSelf(future, f)&lt;/code&gt; delivers a future’s value as a message.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Supervision&lt;/strong&gt;: a trap in an actor fails only that actor, its frames unwound and the trap reported
with the actor’s name, except while it holds a &lt;code&gt;Mutex&lt;/code&gt;, runs a &lt;code&gt;Once&lt;/code&gt;, initializes a &lt;code&gt;lazy val&lt;/code&gt; or
is inside a Sysl call, where the program stops. &lt;code&gt;Supervision&lt;/code&gt; is &lt;code&gt;Escalate&lt;/code&gt; (the default: the
parent fails, and a top-level actor stops the program, so an unsupervised program behaves as one
with threads), &lt;code&gt;Stop&lt;/code&gt;, or &lt;code&gt;Restart(limit, within)&lt;/code&gt;, re-running the body from the same behaviour
with the mailbox kept. There is no resuming with the old state.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Lifecycle&lt;/strong&gt;: &lt;code&gt;stop()&lt;/code&gt; ends the actor after the current message, dropping its mailbox; &lt;code&gt;stop(child)&lt;/code&gt;
only for its own children; children end first; a &lt;code&gt;stopping&lt;/code&gt; block runs at every end and restart;
&lt;code&gt;watch(ref, message)&lt;/code&gt; and &lt;code&gt;watch(ref, f: Ending -&amp;gt; M)&lt;/code&gt; deliver the end into the watcher’s own
mailbox, &lt;code&gt;Ending&lt;/code&gt; being &lt;code&gt;Stopped&lt;/code&gt; or &lt;code&gt;Failed(reason)&lt;/code&gt;; &lt;code&gt;ref.ended()&lt;/code&gt; is a &lt;code&gt;Future[Ending]&lt;/code&gt; for code
outside actors; an actor is not collected while it runs; the program ends when &lt;code&gt;main&lt;/code&gt; returns.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Timers&lt;/strong&gt;: &lt;code&gt;after(delay, message)&lt;/code&gt; and &lt;code&gt;every(interval, message)&lt;/code&gt; answer a cancellable &lt;code&gt;Timer&lt;/code&gt;,
queued like any message and cancelled when the actor ends or restarts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Scheduling&lt;/strong&gt;: actors are tasks on an &lt;code&gt;Executor&lt;/code&gt; (the shared pool by default); an actor runs on
one thread at a time, each message’s handling happening before the next’s; a worker handles at most
16 messages of one actor before re-queuing it; the worker repoints its context’s owner word to the
actor so the actor’s handles never trap; a waiting actor is replaced in the pool as a waiting
future is; &lt;code&gt;tell&lt;/code&gt; happens before the handling of its message.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Machines&lt;/strong&gt;: &lt;code&gt;machine Name receives E&lt;/code&gt; with &lt;code&gt;state S(params)&lt;/code&gt; blocks; an arm’s value is the next
state, or &lt;code&gt;stay&lt;/code&gt;; the first state, without parameters, is the start; &lt;code&gt;enter&lt;/code&gt; and &lt;code&gt;leave&lt;/code&gt; run on
every transition (a state yielded again included) and not on &lt;code&gt;stay&lt;/code&gt;; &lt;code&gt;receive&lt;/code&gt; holds arms shared by
every state, tried after the state’s own; the compiler checks every state handles every event;
&lt;code&gt;handle(event)&lt;/code&gt; answers the new state and &lt;code&gt;state()&lt;/code&gt; the current one, of the generated &lt;code&gt;Name.State&lt;/code&gt;
data type; a machine is not sendable, and handling an event from inside its own handler traps.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;An actor’s behaviour is a machine&lt;/strong&gt;: an actor’s body takes the same &lt;code&gt;state&lt;/code&gt; blocks, its messages
being the events, with the same checks; a restart starts it again in its first state.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-04: &lt;strong&gt;Keywords are contextual&lt;/strong&gt;: &lt;code&gt;actor&lt;/code&gt; and &lt;code&gt;machine&lt;/code&gt; only where a declaration starts, &lt;code&gt;receives&lt;/code&gt; only
in their headers, and &lt;code&gt;state&lt;/code&gt;, &lt;code&gt;receive&lt;/code&gt;, &lt;code&gt;enter&lt;/code&gt;, &lt;code&gt;leave&lt;/code&gt;, &lt;code&gt;stopping&lt;/code&gt; and &lt;code&gt;stay&lt;/code&gt; only inside their
bodies at the start of a line (&lt;code&gt;stay&lt;/code&gt; as an arm’s value), so &lt;code&gt;state&lt;/code&gt; stays an ordinary name
elsewhere.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;Handing a handle over explicitly&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl bindings&lt;/a&gt;). The
spec has no spelling for it. Proposed: &lt;code&gt;handOff(value: Any)&lt;/code&gt; in &lt;code&gt;avin.threads&lt;/code&gt;, putting every
handle &lt;code&gt;value&lt;/code&gt; reaches that the running code owns in transit, for the next code to use it; and
&lt;code&gt;Channel.send&lt;/code&gt; doing the same with what it sends, which it does not do now because handing a value
over walks it, and a channel of plain values should not pay for that (the compiler would skip
the walk for a type that cannot reach a handle).
&lt;strong&gt;Review with the user:&lt;/strong&gt; &lt;code&gt;Channel.send&lt;/code&gt; walking each message to move handle ownership costs every
channel; the compiler skipping the walk for types that cannot reach a handle is the mitigation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;a href=&quot;/spec/threads/#executors&quot;&gt;Executors&lt;/a&gt; (2026-11-04): &lt;code&gt;Executor.fixed(n)&lt;/code&gt; keeps at most &lt;code&gt;n&lt;/code&gt; tasks
working at once and starts its workers as work comes, as the shared pool does, a worker waiting in
&lt;code&gt;await&lt;/code&gt; or &lt;code&gt;blocking&lt;/code&gt; leaving its place to another; &lt;code&gt;n&lt;/code&gt; below one traps. After &lt;code&gt;shutdown()&lt;/code&gt;,
&lt;code&gt;ex.future(body)&lt;/code&gt; traps, while the &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt; of futures already made on
the executor still run there, on a worker started for them where none is left, so no future made
before is stranded. &lt;code&gt;Executor.shared().shutdown()&lt;/code&gt; traps, since every &lt;code&gt;Future(body)&lt;/code&gt; runs there.
&lt;code&gt;ex.isShutdown()&lt;/code&gt; answers whether it was shut down. &lt;code&gt;Future.successful&lt;/code&gt;, &lt;code&gt;Future.all&lt;/code&gt;,
&lt;code&gt;Future.first&lt;/code&gt;, &lt;code&gt;Future.traverse&lt;/code&gt; and a promise’s future belong to the shared executor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;a href=&quot;/spec/threads/#futures&quot;&gt;&lt;code&gt;sleep&lt;/code&gt;&lt;/a&gt; (2026-11-04): a worker that sleeps keeps its place in its pool;
a body that should leave it while it sleeps writes &lt;code&gt;blocking(sleep(d))&lt;/code&gt;. Sleeping is a runtime
function bound &lt;code&gt;blocking&lt;/code&gt; over Sysl’s &lt;code&gt;sleep&lt;/code&gt;, which waits out the whole duration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;a href=&quot;/spec/threads/#futures&quot;&gt;&lt;code&gt;orElse&lt;/code&gt; on a future of a &lt;code&gt;Result&lt;/code&gt;&lt;/a&gt; (2026-11-04):
&lt;code&gt;orElse[U &amp;gt;: T, F](other: -&amp;gt; Future[Result[U, F]])&lt;/code&gt;, widening the value as &lt;code&gt;Result.orElse&lt;/code&gt; does.
&lt;code&gt;Future&lt;/code&gt; stays invariant, since its cell is a mutable field, so a fallback written in place as
&lt;code&gt;Future.successful(Ok(0))&lt;/code&gt; needs its type stated where nothing else decides its error type.
&lt;code&gt;Future&lt;/code&gt; stays invariant: exempting object-private fields from the variance check (as the user had
accepted) proved unsound here, because each set of type arguments has its own code and a method
run through a wider view could store a value of the wider type in a field the narrower view reads
(probe on branch private-variance, not landed). Sound alternatives, not taken now: dispatching a
class with object-private members by the type arguments in its header, or reading type
arguments from the object at run time. &lt;strong&gt;Review with the user:&lt;/strong&gt; this reverses an accepted
recommendation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: Weighted choice in &lt;a href=&quot;/spec/system-library/#avin-random&quot;&gt;&lt;code&gt;avin.random&lt;/code&gt;&lt;/a&gt;, approved in kind by the user
2026-11-04, the names and details proposed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;choose[T](items: Seq[T]) -&amp;gt; T&lt;/code&gt; is uniform (one &lt;code&gt;nextInt(items.length())&lt;/code&gt;) and traps on an empty
sequence. &lt;code&gt;chooseWeighted(weights: Seq[real]) -&amp;gt; int&lt;/code&gt; answers an index and
&lt;code&gt;chooseWeighted[T](pairs: Seq[(T, real)]) -&amp;gt; T&lt;/code&gt; an item, the two overloaded by parameter type.
Both are on &lt;code&gt;Random&lt;/code&gt; and on the companion’s shared generator.&lt;/li&gt;
&lt;li&gt;A draw is &lt;code&gt;nextReal()&lt;/code&gt; times the total of the weights, redrawn while it rounds up to the total,
and the answer is the first index whose running total is above it, so a zero weight is never
chosen and a seed replays. The traps: no weights, a weight that is negative or NaN, an infinite
weight, a total that overflows, a total of zero.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Weighted[T](pairs)&lt;/code&gt; holds the running totals and the items, built once; &lt;code&gt;sample(rng: Random) -&amp;gt; T&lt;/code&gt;
draws by binary search, O(log n), and &lt;code&gt;size()&lt;/code&gt; is the number of items. It draws exactly as
&lt;code&gt;chooseWeighted&lt;/code&gt; would from the same generator state. The alias method (O(1) a draw, a
different mapping of draws to items) was not taken: the cumulative table keeps one draw per
sample and a mapping a reader can follow.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;code&gt;Url&lt;/code&gt;‘s details (&lt;a href=&quot;/spec/system-library/#url&quot;&gt;system library&lt;/a&gt;), where the design left them open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Url&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type whose &lt;code&gt;host&lt;/code&gt; is an &lt;code&gt;Option[string]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; where there is no authority
(&lt;code&gt;mailto:a@b&lt;/code&gt;) and &lt;code&gt;Some(&amp;quot;&amp;quot;)&lt;/code&gt; where it is empty (&lt;code&gt;file:///etc&lt;/code&gt;); an IPv6 host keeps its brackets;
&lt;code&gt;userInfo&lt;/code&gt;, &lt;code&gt;query&lt;/code&gt; and &lt;code&gt;fragment&lt;/code&gt; are &lt;code&gt;Option&lt;/code&gt;s like &lt;code&gt;port&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Components are kept as written, escapes and all; &lt;code&gt;Url.decode&lt;/code&gt; is the way to their text.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;parse&lt;/code&gt; holds the scheme and host in lower case and a default port as &lt;code&gt;None&lt;/code&gt;, so &lt;code&gt;==&lt;/code&gt; compares
the normalized URL and display needs no work of its own. Defaults are 80 for &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;ws&lt;/code&gt;,
443 for &lt;code&gt;https&lt;/code&gt; and &lt;code&gt;wss&lt;/code&gt;, and &lt;code&gt;portOrDefault()&lt;/code&gt; answers an &lt;code&gt;Option[int]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; for a scheme
with no default.&lt;/li&gt;
&lt;li&gt;Escapes that do not decode to UTF-8 make text no URL (&lt;code&gt;InvalidUtf8&lt;/code&gt;), at &lt;code&gt;parse&lt;/code&gt; and in each
&lt;code&gt;with&lt;/code&gt; method, so &lt;code&gt;queryParams&lt;/code&gt; keeps the plain &lt;code&gt;Vector&lt;/code&gt; the design gives it; &lt;code&gt;Url.decode&lt;/code&gt;
answers a &lt;code&gt;Result&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;queryParams&lt;/code&gt; reads &lt;code&gt;+&lt;/code&gt; as a space and skips empty pieces; &lt;code&gt;decode&lt;/code&gt; keeps &lt;code&gt;+&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;UrlError&lt;/code&gt; is &lt;code&gt;MissingScheme&lt;/code&gt;, &lt;code&gt;BadScheme&lt;/code&gt;, &lt;code&gt;BadCharacter&lt;/code&gt;, &lt;code&gt;BadPercent&lt;/code&gt;, &lt;code&gt;BadHost&lt;/code&gt;, &lt;code&gt;BadPort&lt;/code&gt;
and &lt;code&gt;InvalidUtf8&lt;/code&gt;, each but the first with the byte offset &lt;code&gt;at&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A zone is accepted only as RFC 6874 writes it, after &lt;code&gt;%25&lt;/code&gt;; hosts of a later form (&lt;code&gt;[v7.x]&lt;/code&gt;)
are accepted; characters beyond ASCII other than controls and spaces are accepted in any
component and kept.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;resolve(ref: string)&lt;/code&gt; answers a &lt;code&gt;Result&lt;/code&gt;, the reference being text; &lt;code&gt;resolve(ref: Url)&lt;/code&gt; takes
one already read. The &lt;code&gt;with&lt;/code&gt; methods take components as written and trap on one the URL cannot
hold; each optional component’s method takes a value or an &lt;code&gt;Option&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;&lt;code&gt;Source&lt;/code&gt; is a trait&lt;/strong&gt;, its three readers abstract, so a program can write a source of its own
(text made as it is read, a socket later) and hand it to any function that takes one; the kinds
&lt;code&gt;avin.io&lt;/code&gt; makes are private classes reached only through &lt;code&gt;Source.fromFile&lt;/code&gt;, &lt;code&gt;fromString&lt;/code&gt; and
&lt;code&gt;stdin&lt;/code&gt;. The alternative is a final class whose kinds are fixed by the library.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;An override adds no bound to a type parameter of
its own&lt;/strong&gt; (&lt;a href=&quot;/spec/declarations/#inheritance&quot;&gt;declarations&lt;/a&gt;). Each bound an override, or a method
implementing a trait’s, writes on its own type parameters is implied by the overridden method’s
bounds on that parameter: one of them, a trait or class one of them conforms to, or &lt;code&gt;Eq&lt;/code&gt; or
&lt;code&gt;Hash&lt;/code&gt;, which every type meets; it may keep, weaken or drop bounds. Why: a call through the base
type passes any type argument the base’s bounds admit, so an added bound let a program that
type-checked run the override at a type without the bound’s methods, which trapped or crashed. The
alternatives were requiring the bounds to be exactly the same, which forbids a weakening that is
harmless; and checking the bound at each call through the base,
which a call cannot do, since it does not know which override it reaches.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;the methods an &lt;code&gt;impl&lt;/code&gt; adds to an &lt;code&gt;open&lt;/code&gt; or
&lt;code&gt;abstract&lt;/code&gt; class are &lt;a href=&quot;/spec/generics/#variance&quot;&gt;variance&lt;/a&gt; positions&lt;/strong&gt;, whatever its fields; the
exemption stays for final classes whose fields are all immutable, &lt;code&gt;data&lt;/code&gt; types and traits. Why:
such a method is in the class’s method table, so a call through a wider view runs the copy for
the object’s own type arguments, and &lt;code&gt;(b: Box[Animal]).with(cat)&lt;/code&gt; on a &lt;code&gt;Box[Dog]&lt;/code&gt; answered a
&lt;code&gt;Box[Dog]&lt;/code&gt; holding a cat, whose dog’s fields read past the object; the core library’s &lt;code&gt;Vector&lt;/code&gt; had
the hole. So &lt;code&gt;Vector&lt;/code&gt; takes an element through a lower bound, as maps do:
&lt;code&gt;:+[W &amp;gt;: T](element: W) -&amp;gt; Vector[W]&lt;/code&gt;, &lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;updated&lt;/code&gt;, and &lt;code&gt;toArray[W &amp;gt;: T]()&lt;/code&gt;, and
&lt;code&gt;Seq&lt;/code&gt;‘s added &lt;code&gt;:+&lt;/code&gt;, &lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt; and &lt;code&gt;updated&lt;/code&gt; widen alike, so a vector’s own hides them. A vector’s
&lt;code&gt;iterator()&lt;/code&gt; and &lt;code&gt;reverseIterator()&lt;/code&gt; are &lt;code&gt;Iterator[T]&lt;/code&gt;s, and its guard view is the one every
sequence has. The alternative, not taken: making an exempt impl method non-virtual, compiled for
the receiver’s static type as a trait’s added methods are, which keeps &lt;code&gt;:+(element: T)&lt;/code&gt; but would
make an added method on an open class behave unlike a method written in its body.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;avin-net&lt;/code&gt;): &lt;code&gt;avin.net&lt;/code&gt;‘s TCP and
HTTP details (&lt;a href=&quot;/spec/system-library/#avin-net&quot;&gt;system library&lt;/a&gt;),
where the chapter left them open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;write&lt;/code&gt;, &lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;shutdownOutput&lt;/code&gt; answer &lt;code&gt;Result[unit, IoError]&lt;/code&gt;, since
each can fail; &lt;code&gt;readAll()&lt;/code&gt; is added beside &lt;code&gt;read&lt;/code&gt; and &lt;code&gt;readLine&lt;/code&gt;, and &lt;code&gt;TcpListener&lt;/code&gt; has &lt;code&gt;close()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A read, write or &lt;code&gt;accept&lt;/code&gt; after &lt;code&gt;close()&lt;/code&gt; answers &lt;code&gt;Other(&amp;quot;the connection is closed&amp;quot;)&lt;/code&gt; (or “the
listener is closed”) rather than trapping, as a closed handle’s method does.&lt;/li&gt;
&lt;li&gt;A host that resolves to no address is &lt;code&gt;Other(s&amp;quot;no address found for $host&amp;quot;)&lt;/code&gt;, not &lt;code&gt;NotFound&lt;/code&gt;,
whose message speaks of files. A port outside 0 to 65535, and &lt;code&gt;read(max)&lt;/code&gt; with &lt;code&gt;max&lt;/code&gt; below one,
trap at the call, as a &lt;code&gt;Url&lt;/code&gt;‘s &lt;code&gt;withPort&lt;/code&gt; does with a port it cannot hold.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ConnectionReset&lt;/code&gt; also covers a write to a connection the other end has closed (&lt;code&gt;EPIPE&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;setTimeout&lt;/code&gt; sets the read and the write limit together, in whole milliseconds rounded up; zero
or less takes the limit away.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bind&lt;/code&gt; takes the host’s first address and lets a port a recently stopped listener used be taken
again; the backlog is the platform’s usual 128.&lt;/li&gt;
&lt;li&gt;The socket is a handle on &lt;code&gt;sysl.net&lt;/code&gt;‘s own &lt;code&gt;Socket&lt;/code&gt;, which closes its descriptor when its last
copy goes (from Sysl 0.9.1; a runtime type wrapping it with a destructor did this before, and
was removed on branch &lt;code&gt;sysl-091&lt;/code&gt;); so closing the handle, or the collector freeing a forgotten
one, closes the socket. The runtime turns &lt;code&gt;sysl.net&lt;/code&gt;‘s errors into the four a connection tells
apart (&lt;code&gt;avin.rt.net_failure&lt;/code&gt;), the error crossing as a handle so that its variants do not join
the module’s.&lt;/li&gt;
&lt;li&gt;The HTTP client: a &lt;code&gt;Response&lt;/code&gt; also has its &lt;code&gt;reason&lt;/code&gt;; &lt;code&gt;text()&lt;/code&gt; reads ill-formed UTF-8 as U+FFFD;
&lt;code&gt;Request&lt;/code&gt; is a class with &lt;code&gt;method&lt;/code&gt;, &lt;code&gt;url&lt;/code&gt;, &lt;code&gt;headers&lt;/code&gt;, &lt;code&gt;body&lt;/code&gt; and &lt;code&gt;timeout&lt;/code&gt;, the last three
defaulted; a method or header name that is not a token, and a header value with a line break,
trap; &lt;code&gt;Host&lt;/code&gt;, &lt;code&gt;Content-Length&lt;/code&gt; and &lt;code&gt;Connection: close&lt;/code&gt; are written unless the request gives
them; an interim &lt;code&gt;1xx&lt;/code&gt; is skipped; redirects are 301, 302, 303, 307 and 308, the sixth answered
as it is.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sendable&lt;/code&gt;): &lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;&lt;code&gt;Sendable&lt;/code&gt;‘s
promises&lt;/a&gt;, where the design left them open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A declaration promises &lt;code&gt;Sendable&lt;/code&gt; as it conforms to any trait: after &lt;code&gt;:&lt;/code&gt; in a class’s or a
trait’s header, or in an impl for a data type. The promise is checked against the structure,
outside the standard library, and an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class that promises it is sendable,
each subclass being checked. (Replaced by the Proposed &lt;code&gt;@trusted_sendable&lt;/code&gt; entry, branch
&lt;code&gt;fix-core-promises&lt;/code&gt;: the library’s promises are checked too, but for the classes it marks.)
The standard library’s promises are taken as made, since they are
for types whose structure cannot show it: &lt;code&gt;Future&lt;/code&gt;, &lt;code&gt;Promise&lt;/code&gt;, &lt;code&gt;Channel&lt;/code&gt; and &lt;code&gt;Atomic&lt;/code&gt; of a
sendable type (impls bounded by &lt;code&gt;Sendable&lt;/code&gt;), &lt;code&gt;Mutex&lt;/code&gt; of any type and &lt;code&gt;Once&lt;/code&gt; (in their headers),
and &lt;code&gt;Vector&lt;/code&gt; of sendable elements. &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Range&lt;/code&gt;, the hash and tree maps and sets,
&lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt; are sendable by their structure.&lt;/li&gt;
&lt;li&gt;A generic trait that promises &lt;code&gt;Sendable&lt;/code&gt; is sendable at sendable type arguments; a type
implementing it has the parameters it passes to the trait, other than contravariantly, taken as
sendable where it is checked, and is sendable at sendable arguments for them. The immutable &lt;code&gt;Map&lt;/code&gt;
and &lt;code&gt;Set&lt;/code&gt; traits promise it, so &lt;code&gt;HashMap[K, V]&lt;/code&gt; is sendable where &lt;code&gt;K&lt;/code&gt; and &lt;code&gt;V&lt;/code&gt; are, and a type
implementing either is held to it.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Sendable&lt;/code&gt; is only a bound and a promise; it is not the type of a value.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;lazy val&lt;/code&gt; field is sendable where its type is, since it is initialized by exactly one thread.
(That rests on the runtime initializing a &lt;code&gt;lazy val&lt;/code&gt; once under contention, which the tests
&lt;code&gt;lazy_threads&lt;/code&gt;, &lt;code&gt;lazy_threads_many&lt;/code&gt; and &lt;code&gt;sendable_lazy&lt;/code&gt; pin: threads and futures reading one
first together, counting a single run of each initializer.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;mirror-handle-fields&lt;/code&gt;): &lt;strong&gt;a mirror
holding a handle goes into Sysl wherever any mirror does&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#mirrors&quot;&gt;Sysl
bindings&lt;/a&gt;) — a parameter by itself, or inside an &lt;code&gt;Option&lt;/code&gt;, a
&lt;code&gt;Result&lt;/code&gt;, a collection, a tuple or another mirror — since the shim’s conversion of the mirror
checks and passes each handle field wherever it is called, though a bare handle in an &lt;code&gt;Option&lt;/code&gt; or
a collection still does not go into Sysl. The alternative is a mirror holding a handle only by
itself, as a handle is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;tailrec&lt;/code&gt;): &lt;a href=&quot;/spec/declarations/#tail-calls&quot;&gt;tail
calls&lt;/a&gt;, the choices the request left open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every self-call in tail position is a loop, with or without &lt;code&gt;@tailrec&lt;/code&gt;&lt;/strong&gt;, at &lt;code&gt;-O0&lt;/code&gt; as at
&lt;code&gt;-O2&lt;/code&gt;, so a program’s stack use does not depend on its optimization level; the annotation only
adds the proof. Alternative: loop only where &lt;code&gt;@tailrec&lt;/code&gt; asks, leaving the rest to LLVM at &lt;code&gt;-O2&lt;/code&gt;
— rejected, since the same program would overflow at &lt;code&gt;-O0&lt;/code&gt; and not at &lt;code&gt;-O2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; is in tail position&lt;/strong&gt;, as in the reference language:
&lt;code&gt;n == 0 || (ok(n) &amp;amp;&amp;amp; f(n - 1))&lt;/code&gt; is a loop. Alternative: only &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt; branches — simpler to
explain, but it refuses a common shape of predicate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A call on another receiver of the method’s own type is a loop&lt;/strong&gt;, the receiver becoming
&lt;code&gt;self&lt;/code&gt; for the next pass, as the reference language does for a method that cannot be
overridden; a call on a receiver of the class at other type arguments is another instance and
&lt;code&gt;@tailrec&lt;/code&gt; refuses it. Alternative: only calls on &lt;code&gt;self&lt;/code&gt; — it would refuse list-walking methods
such as &lt;code&gt;next.length(acc + 1)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A private method of an open or abstract class may be &lt;code&gt;@tailrec&lt;/code&gt;&lt;/strong&gt;, since nothing overrides
it; a public one may not. There is no &lt;code&gt;final&lt;/code&gt; modifier for a single method, so making a public
method of an open class a loop means making it private or the class final.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;@tailrec&lt;/code&gt; is accepted on top-level functions, methods and local functions&lt;/strong&gt;, and is the one
annotation a local function takes; a lambda cannot be annotated. It refuses a function with no
recursive call, as the reference language does, rather than accepting it silently.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A function calling itself is made a loop; mutual recursion is left to general tail calls&lt;/strong&gt;,
which need every caller and callee to agree on a calling convention and to unlink the
shadow-stack frame before the call, and have their own entry (below).&lt;/li&gt;
&lt;li&gt;The language has no &lt;code&gt;try&lt;/code&gt;, &lt;code&gt;defer&lt;/code&gt; or &lt;code&gt;finally&lt;/code&gt;, so there is no pending cleanup to take a call
out of tail position; when such a construct is added, a call inside it is not in tail position.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;&lt;code&gt;Iterable&lt;/code&gt;‘s transformations&lt;/strong&gt;
(&lt;a href=&quot;/spec/collections/#operations-without-higher-kinded-types&quot;&gt;collections&lt;/a&gt;), following the
reference collection library (branch &lt;code&gt;coll-followups&lt;/code&gt;). &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;withFilter&lt;/code&gt;,
&lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;zip&lt;/code&gt; are added to every &lt;code&gt;Iterable&lt;/code&gt; by &lt;code&gt;impl[T] Iterable[T]&lt;/code&gt;, each returning an
&lt;code&gt;Iterable&lt;/code&gt; (a &lt;code&gt;Vector&lt;/code&gt; underneath) of the results in iteration order, so a program’s own class
conforming to &lt;code&gt;Iterable&lt;/code&gt; has them; the library’s collections keep their own of the same name and
parameter types, of their own kind. To let &lt;code&gt;Seq&lt;/code&gt;‘s, &lt;code&gt;Set&lt;/code&gt;‘s and the other traits’ versions stand,
an impl adding to a trait is passed over where an impl adding the same name and parameter types to
a trait that requires it applies (&lt;a href=&quot;/spec/declarations/#impl&quot;&gt;declarations&lt;/a&gt;); impls on unrelated
traits still clash. Why: the item asked for the members the chapter already claimed, and the
impl is how every other &lt;code&gt;Iterable&lt;/code&gt; operation is written. Alternatives: methods with bodies
declared in the trait, dispatched through the object’s table, so generic code would get the
concrete collection back at run time; that would make every collection’s &lt;code&gt;map&lt;/code&gt; an &lt;code&gt;override&lt;/code&gt;,
rule out the bounded versions (&lt;code&gt;TreeSet.map[B: Ord]&lt;/code&gt; cannot override an unbounded &lt;code&gt;map[B]&lt;/code&gt;),
and dispatch every call. The chapter’s earlier claim that generic code gets the concrete
collection back is withdrawn. The review this entry carried, a &lt;code&gt;Map&lt;/code&gt; receiver offering only its
pair-making &lt;code&gt;map&lt;/code&gt;, is superseded by the Proposed entry on a map’s &lt;code&gt;map&lt;/code&gt; to other results (branch
&lt;code&gt;map-flatmap&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;map-flatmap&lt;/code&gt;): &lt;strong&gt;a map’s &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; to anything other than pairs
answer a collection&lt;/strong&gt; (&lt;a href=&quot;/spec/collections/#operations-without-higher-kinded-types&quot;&gt;collections&lt;/a&gt;),
on the user’s direction that Avin adopt the conveniences of a rich collections library that add
no complexity. &lt;code&gt;m.map((k, v) -&amp;gt; Summary(k, v))&lt;/code&gt;, &lt;code&gt;m.map(e -&amp;gt; e.0)&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt; function or a
method value making non-pairs, and a comprehension over a map yielding non-pairs, guarded or
not, answer &lt;code&gt;Iterable[B]&lt;/code&gt; (a &lt;code&gt;Vector&lt;/code&gt; underneath) in the map’s iteration order; a pair still
makes a map of the receiver’s kind (&lt;code&gt;HashMap&lt;/code&gt; through &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;TreeMap&lt;/code&gt;, the mutable ones). Every
map has a &lt;code&gt;map[B](f: (K, V) -&amp;gt; B) -&amp;gt; Iterable[B]&lt;/code&gt; overload beside its pair-making one, and the
filtered views a comprehension’s guard makes have &lt;code&gt;map[B]&lt;/code&gt; and &lt;code&gt;flatMap[B]&lt;/code&gt; of one pair; a
function of the entry as one pair reaches &lt;code&gt;Iterable&lt;/code&gt;‘s own. To choose by the lambda’s body,
overload resolution gains one rule (&lt;a href=&quot;/spec/declarations/#default-and-named-arguments&quot;&gt;declarations&lt;/a&gt;):
where the candidates left all give a lambda (or a &lt;code&gt;match&lt;/code&gt; function) the same parameter types,
known without the candidates’ own type arguments, and differ only in the result, the lambda is
checked once with those parameters and an open result, and then fits as any typed argument does;
of two that fit, the pair-making one is the more specific. WHY: one check of the body, with no
speculative re-checking or rollback, settles the common shape exactly, and the rule is
invisible where the overloads already agree. ALTERNATIVES: checking the lambda’s body against
each candidate in turn and discarding the failures (general, but every check would have to be
undone, captures and nested lambdas included); answering a &lt;code&gt;Vector&lt;/code&gt; rather than an &lt;code&gt;Iterable&lt;/code&gt;
(handier to index, but &lt;code&gt;Iterable&lt;/code&gt;‘s own &lt;code&gt;map&lt;/code&gt;, which a one-pair function reaches, answers
&lt;code&gt;Iterable&lt;/code&gt;, and the two shapes of function should agree); a diagnostic suggesting &lt;code&gt;.toVector&lt;/code&gt;
first (the audit’s stopgap). Not done: a sorted collection’s &lt;code&gt;map&lt;/code&gt; to an element or key that is
not &lt;code&gt;Ord&lt;/code&gt; is still refused naming the bound, rather than falling back to an unsorted result,
since the sorted overload hides &lt;code&gt;Iterable&lt;/code&gt;‘s of the same parameter types and the candidates are
not held to their bounds while choosing. Review with the user: whether that fallback is wanted
too, and &lt;code&gt;Iterable&lt;/code&gt; versus &lt;code&gt;Vector&lt;/code&gt; as the result.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;map-flatmap&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;flatMap&lt;/code&gt; takes an option-making function on every
collection&lt;/strong&gt;, by an overload &lt;code&gt;flatMap[U](f: (T) -&amp;gt; Option[U])&lt;/code&gt; beside each collection’s own
&lt;code&gt;flatMap&lt;/code&gt; of a collection-making function, answering the same kind: &lt;code&gt;Iterable&lt;/code&gt; (a &lt;code&gt;Vector&lt;/code&gt;),
every &lt;code&gt;Seq&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;LazyList&lt;/code&gt; (lazily),
&lt;code&gt;Iterator&lt;/code&gt; (lazily), &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;TreeSet&lt;/code&gt;, the mutable sets and bit set, and every filtered view a
comprehension’s guard makes. A map’s takes &lt;code&gt;((K, V)) -&amp;gt; Option[(L, W)]&lt;/code&gt; into a map of its kind,
and any other option into a collection (through &lt;code&gt;Iterable&lt;/code&gt;‘s, or the filtered view’s own).
&lt;code&gt;Iterable[Option[T]]&lt;/code&gt; has &lt;code&gt;flatten&lt;/code&gt; into a &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Iterator[Option[T]]&lt;/code&gt; into a lazy iterator.
&lt;code&gt;Option&lt;/code&gt; gains &lt;code&gt;flatMap[U](f: (T) -&amp;gt; Iterable[U]) -&amp;gt; Vector[U]&lt;/code&gt;, so a comprehension drawing from
an option and then a collection yields a vector; one drawing from a collection and then options
yields the collection’s kind. The lambda’s body chooses between the two &lt;code&gt;flatMap&lt;/code&gt;s by the rule of
the entry above. WHY: the overload is a library addition that every call path sees, generic code
through &lt;code&gt;Iterable&lt;/code&gt; included, and leaves options’ representation alone. ALTERNATIVES: making
&lt;code&gt;Option&lt;/code&gt; an &lt;code&gt;Iterable&lt;/code&gt; of at most one element (&lt;code&gt;impl[T] Iterable[T] for Option[T]&lt;/code&gt;), which was
built and works, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;concat&lt;/code&gt; and &lt;code&gt;Iterable&lt;/code&gt; parameters taking options included, but the
library’s &lt;code&gt;Iterator[Iterable[T]]&lt;/code&gt; impl then views a type parameter through a trait &lt;code&gt;Option&lt;/code&gt;
conforms to, so the representation plan keeps every option of every program as an object rather
than a bare pointer (an allocation per &lt;code&gt;Some&lt;/code&gt;, and &lt;code&gt;None&lt;/code&gt; read through &lt;code&gt;Any&lt;/code&gt; changes); a
conversion at the call (a mechanism Avin does not have). Not done: &lt;code&gt;xs ++ maybe&lt;/code&gt;, &lt;code&gt;concat&lt;/code&gt; and
an option given for an &lt;code&gt;Iterable&lt;/code&gt; parameter, which need the conformance; &lt;code&gt;toList&lt;/code&gt; covers them.
Review with the user: whether options as iterables are worth reworking the representation plan
for, and the &lt;code&gt;Vector&lt;/code&gt; from an option’s &lt;code&gt;flatMap&lt;/code&gt; of a collection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;&lt;code&gt;rest*&lt;/code&gt; binds what &lt;code&gt;drop(n)&lt;/code&gt; answers&lt;/strong&gt;
(&lt;a href=&quot;/spec/collections/#sequence-patterns&quot;&gt;collections&lt;/a&gt;), branch &lt;code&gt;coll-followups&lt;/code&gt;. One rule for every &lt;code&gt;n&lt;/code&gt;,
&lt;code&gt;n = 0&lt;/code&gt; included: &lt;code&gt;[rest*]&lt;/code&gt; binds &lt;code&gt;drop(0)&lt;/code&gt;, the list itself on a list and a &lt;code&gt;Vector&lt;/code&gt; on a range,
an array, a buffer or a deque, where it used to bind the scrutinee itself at its own type. Why:
one rule the reader can predict, and a binding that never aliases a mutable array or buffer
through a pattern that elsewhere copies. Alternative: &lt;code&gt;[rest*]&lt;/code&gt; as the scrutinee, as before, which
made the binding’s type depend on whether any element came before &lt;code&gt;rest*&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;An empty collection literal joins to its siblings’
type&lt;/strong&gt; (&lt;a href=&quot;/spec/collections/#literals&quot;&gt;collections&lt;/a&gt;), branch &lt;code&gt;coll-followups&lt;/code&gt;. Among the elements of
a literal, the keys or values of a map literal, the branches of an &lt;code&gt;if&lt;/code&gt; and the arms of a &lt;code&gt;match&lt;/code&gt;,
an empty literal (&lt;code&gt;[]&lt;/code&gt;, &lt;code&gt;{}&lt;/code&gt;, or a literal holding one anywhere) is checked after the others and
against the type they agree on, where nothing useful is expected (nothing, or &lt;code&gt;Any&lt;/code&gt;), and where
that type is a collection its literal shape can build. So &lt;code&gt;[{1: [2]}, {}]&lt;/code&gt; and
&lt;code&gt;if c then {1: [2]} else {}&lt;/code&gt; are maps. Why: &lt;code&gt;{}&lt;/code&gt; alone defaults to a set, and an invariant &lt;code&gt;Set&lt;/code&gt;
never joins a &lt;code&gt;Map&lt;/code&gt;, so the sibling has to settle it before it defaults; the reference language
gets the same result from inference. Alternatives: a join rule turning &lt;code&gt;Set[_]&lt;/code&gt; into the other
side’s map after the fact (the literal’s builder is already chosen by then), or asking for an
annotation, as before.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;A range displays as written&lt;/strong&gt;
(&lt;a href=&quot;/spec/collections/#ranges&quot;&gt;collections&lt;/a&gt;), branch &lt;code&gt;coll-followups&lt;/code&gt;: &lt;code&gt;1..5&lt;/code&gt;, &lt;code&gt;0..&amp;lt;10&lt;/code&gt;,
&lt;code&gt;0..&amp;lt;10 by 2&lt;/code&gt;, the bounds as given, the step only where it is not 1; &lt;code&gt;Debug&lt;/code&gt; the same, and a
&lt;code&gt;NumericRange&lt;/code&gt; the same. Why: it reads back as the expression that made it and costs nothing to
render. Alternative: the elements, &lt;code&gt;[1, 2, 3, 4, 5]&lt;/code&gt;, as a vector shows, which hides that a range
is a progression and is unbounded in size.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;Precision under &lt;code&gt;%s&lt;/code&gt; and &lt;code&gt;%?&lt;/code&gt; is the formatter’s&lt;/strong&gt;
(&lt;a href=&quot;/spec/strings-and-formatting/#rendering&quot;&gt;strings and formatting&lt;/a&gt;), branch &lt;code&gt;coll-followups&lt;/code&gt;: the
value is rendered with no width and no precision through &lt;code&gt;writeDisplayed&lt;/code&gt; or &lt;code&gt;writeDebugged&lt;/code&gt;, and
its first N code points fill the field, for every type; renderers see a precision only under the
other conversions. Why: the chapter promised it for every value and only strings honoured it; cut
once, no renderer can get it wrong. Alternative: every renderer reading the precision, which each
collection and data type would have to implement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;regex-hardening&lt;/code&gt;): &lt;a href=&quot;/spec/regex/#matching&quot;&gt;&lt;code&gt;avin.regex&lt;/code&gt;‘s
limits on matching&lt;/a&gt;, backtracking with leftmost-first results kept:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The matcher keeps its own backtrack stack&lt;/strong&gt;, an array of frames, so a repeated group over a
long input takes no deeper a call stack however many repetitions it makes; only a part matched
on its own (a repetition’s item matched one way, an atomic group, a lookaround’s body) takes a
call, so the call depth follows the pattern’s nesting, never the input. Alternative: a
linear-time engine — rejected by the request, as back references, lookarounds and
leftmost-first captures need backtracking.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each attempt at a start has a step budget, and spending it traps&lt;/strong&gt;, the message naming the
pattern and the input’s length and saying to make a repetition possessive or atomic. A step is
an operation run or a backtrack frame popped; the budget is 1000 for each character of the
input (plus one) times each operation of the program, never fewer than 10,000,000, about a
tenth of a second of steps and far beyond what a pattern that backtracks only as far as its
input asks takes. The budget is per attempt, not per search, so a search is never stopped for
the number of starts it tries. Alternatives: answering a &lt;code&gt;Result&lt;/code&gt; from every search — rejected,
as it would make every &lt;code&gt;findFirstIn&lt;/code&gt; and &lt;code&gt;matches&lt;/code&gt; a fallible call for what is a defect of the
pattern, which the trap’s message says how to fix; no limit (the earlier behaviour) — rejected,
as one bad pattern hangs its program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;withStepLimit(n)&lt;/code&gt; sets an attempt’s budget&lt;/strong&gt; (&lt;code&gt;n&lt;/code&gt; above 0, or it traps), for a program that
wants a tighter bound on untrusted text or a looser one for a pattern known to be slow; the
trap’s message then gives the limit. Alternative: a global setting — rejected, as the budget
belongs to the pattern.&lt;/li&gt;
&lt;li&gt;Review with the user: whether a search should also have a non-trapping form for untrusted
patterns (a &lt;code&gt;Result&lt;/code&gt;-answering &lt;code&gt;tryFindFirstIn&lt;/code&gt;, say), and whether the default budget’s
constants are the right ones. A greedy, unbounded repetition of a group in a pattern without a
back reference already remembers where a further repetition failed, so the textbook
&lt;code&gt;(a+)+$&lt;/code&gt;, &lt;code&gt;(a|a)*b&lt;/code&gt; and &lt;code&gt;(a|aa)+$&lt;/code&gt; finish in polynomial time and do not trap; their reluctant,
bounded and back-referencing forms are the ones that do.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;&lt;a href=&quot;/spec/declarations/#tail-calls&quot;&gt;Guaranteed tail calls&lt;/a&gt;&lt;/strong&gt;
(branch &lt;code&gt;tailcalls&lt;/code&gt;). Every call in tail position of a function of the program, by name, through
a method table or of a function value, replaces the caller’s stack frame, at &lt;code&gt;-O0&lt;/code&gt; as at &lt;code&gt;-O2&lt;/code&gt;,
so mutual recursion, state machines of functions and continuation passing run in constant stack.
A self-call is still a jump within the function, which is cheaper. &lt;code&gt;@tailrec&lt;/code&gt; stays about
self-recursion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Every compiled function has LLVM’s &lt;code&gt;tailcc&lt;/code&gt; convention, and a tail call is &lt;code&gt;musttail call tailcc&lt;/code&gt; followed at once by its &lt;code&gt;ret&lt;/code&gt;. The C convention is kept only where code outside the
program calls in: &lt;code&gt;main&lt;/code&gt;, a C-convention wrapper for each function whose address a Sysl
binding’s shim is given, and the closure runner the runtime calls to start a thread.&lt;/li&gt;
&lt;li&gt;Calls through method tables and of function values are tail calls too, since every address a
table, a type record or a closure holds is a function of the program with its convention. A call
the whole-program pass guards by the receiver’s descriptor returns from each of its branches.&lt;/li&gt;
&lt;li&gt;The caller gives its shadow-stack frame back just before the call, as a return does. The
arguments are then roots of no frame until the callee links its own, its first act, and nothing
between the two allocates, polls or stores, so no collection can see the gap.&lt;/li&gt;
&lt;li&gt;A call stays an ordinary one where an argument may point into the caller’s own stack (a local
function given the address of a local it captures), where the core library calls the program’s
code (it restores the caller site after), where the result is converted, and in a class’s
constructor, which publishes its object after its body. A lambda or local function value that
captures a local of its enclosing function is entered through an entry that keeps the local on
its own stack, so that entry’s call adds one frame per call; capturing only parameters and values
adds none.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only a function whose arguments all travel in registers has &lt;code&gt;tailcc&lt;/code&gt;&lt;/strong&gt;: the context and at
most five integers, bools or references, at most eight reals, and no integer wider than &lt;code&gt;long&lt;/code&gt;
as a parameter or the result. The rest keep the C convention and make and receive ordinary
calls. Under &lt;code&gt;tailcc&lt;/code&gt; the callee pops the arguments passed on the stack, and LLVM’s unoptimized
code generation reloads spilled values from the wrong place after such a call (seen as crashes
and wrong results at &lt;code&gt;-O0&lt;/code&gt;); with every argument in a register there is nothing to pop. The
limits are those of the smallest target (x86-64: six integer registers, eight vector ones), so a
program’s stack use is the same everywhere. &lt;strong&gt;Review with the user&lt;/strong&gt;: a function with six or more
such parameters gets no tail call; lifting the limit means passing the extra arguments in a
block the caller’s caller owns, or a fixed LLVM.&lt;/li&gt;
&lt;li&gt;Alternatives weighed: merging each group of mutually recursive functions into one function that
switches on which one is running (no convention change, but only for calls by name, and code
size grows with the group); a trampoline in the library (no compiler work, but every tail call
pays an allocation and an indirect return, and the program must be written for it).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review with the user.&lt;/strong&gt; Error backtraces lose the frames a tail call replaced; the user may
prefer this only at -O2.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;process-commands&lt;/code&gt;): &lt;strong&gt;How the parts of a command share its settings&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;).
Proposed: a directory and variables set on a pipeline or a sequence are every part’s, a part’s own
directory replacing it and its own variables added after (a name set twice has the last value).
A time limit on a command made of parts bounds the whole, from when it starts: each program is
given what is left, a part not yet started when it runs out is &lt;code&gt;TimedOut&lt;/code&gt; without being started,
and of two nested limits the earlier ends it. Output redirected on a pipeline is its last stage’s
and input its first’s; on a sequence the file is opened once and shared, so the parts write one
after the other and the second reads on where the first stopped. A part’s own redirection replaces
the enclosing one, whose file is still opened (and so emptied by &lt;code&gt;toFile&lt;/code&gt;), as a shell’s is.
Why: each reads as a shell’s &lt;code&gt;( … )&lt;/code&gt; with the setting outside it, which is what a reader expects.
Alternatives: a limit given to each program afresh (a sequence of slow parts would never end), and
a file opened per part (each part of a sequence would empty what the one before wrote).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;process-commands&lt;/code&gt;): &lt;strong&gt;Input given as text, and output captured, go through files&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;).
Proposed: &lt;code&gt;withInput(text)&lt;/code&gt; writes the text to a temporary file, opened and unlinked before the
program starts, and &lt;code&gt;output()&lt;/code&gt; has the output written to a temporary file read once the command
has ended. Why: a pipe the program feeds or drains while it waits is a deadlock once either side
outgrows the pipe’s buffer, and a file never fills. The alternative is pipes served by a thread.
&lt;code&gt;output()&lt;/code&gt; decodes the bytes as &lt;code&gt;lines()&lt;/code&gt; does, each ill-formed run replaced with U+FFFD, rather than
failing with &lt;code&gt;Io(InvalidUtf8)&lt;/code&gt;; the alternative is the failure, which would lose the whole output
over one byte. &lt;strong&gt;Review with the user&lt;/strong&gt;: the decoding.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;command-clear-env&lt;/code&gt;): &lt;strong&gt;A command’s environment: &lt;code&gt;clearEnv&lt;/code&gt;, &lt;code&gt;withoutEnv&lt;/code&gt;, &lt;code&gt;withEnvironment&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;).
A command keeps its environment changes as an ordered list (set, remove, clear), applied in the order called; on a joined command the command’s list comes before each part’s own. &lt;code&gt;clearEnv()&lt;/code&gt; starts from an empty environment, &lt;code&gt;withoutEnv(name)&lt;/code&gt; drops one inherited variable (an unset name is no error), &lt;code&gt;withEnvironment(map)&lt;/code&gt; is &lt;code&gt;clearEnv()&lt;/code&gt; then each entry. With only sets, the running program’s environment is left to Sysl’s &lt;code&gt;inherit_env&lt;/code&gt;; once a list clears or removes, the whole environment is built from &lt;code&gt;environment()&lt;/code&gt; and handed over with &lt;code&gt;inherit_env = false&lt;/code&gt;. A bare program name after a clear is looked for on the &lt;code&gt;PATH&lt;/code&gt; the command was given, or the system’s default path where none, never the running program’s: that is Sysl’s &lt;code&gt;spawn&lt;/code&gt; rule, kept so a command never finds a program through a variable it was told not to have. Variables whose name or value is not UTF-8 are not passed once a command removes or clears (&lt;code&gt;environment()&lt;/code&gt; passes them over). WHY: a daemon must start jobs from the submitter’s environment, not its own. ALTERNATIVES: a single &lt;code&gt;withEnvironment&lt;/code&gt; only (cannot remove one variable cheaply); a settings pair of a base flag and a removed set (loses the order of calls, so &lt;code&gt;clearEnv().withEnv(x)&lt;/code&gt; and &lt;code&gt;withEnv(x).clearEnv&lt;/code&gt; could not differ); looking the program up on the parent’s &lt;code&gt;PATH&lt;/code&gt; (a cleared command would still find programs by a variable it lacks). Review with the user: the &lt;code&gt;PATH&lt;/code&gt; lookup rule.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;process-commands&lt;/code&gt;), with one change: &lt;strong&gt;&lt;code&gt;kill()&lt;/code&gt; and a started sequence&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;).
Proposed: &lt;code&gt;Child.kill()&lt;/code&gt; sends signal 15 to every program of the command still running and starts
no part not yet started; &lt;code&gt;waitFor()&lt;/code&gt; then answers &lt;code&gt;Signalled(15)&lt;/code&gt; for a program it stopped. A
started sequence starts its next part when &lt;code&gt;waitFor()&lt;/code&gt; or &lt;code&gt;isAlive()&lt;/code&gt; finds the part before it has
ended, on the code that started it, which owns the processes; &lt;code&gt;lines()&lt;/code&gt; over a command holding a
sequence moves it on with a thread of its own, since its reader is waiting on the output. A
pipeline holding a sequence is polled, its processes asked without waiting at growing intervals up
to 16 ms, while a pipeline of programs alone is waited for without polling. Alternatives: signal 9,
which a program cannot clean up after, or &lt;code&gt;kill(signal: int = 15)&lt;/code&gt;; every started command on a
thread of its own, whose processes the starting code could then not stop, since a handle belongs
to one thread. Settled: signal 15 as proposed. Changed: a started sequence must move on by itself, since a sequence that
stalls until its starter asks is a surprise; a thread of its own will own the processes and drive
the sequence, and the &lt;code&gt;Child&lt;/code&gt; will ask it to wait or to kill through a channel, which keeps each
handle on one thread. Until that is built the sequence moves on only when asked, as described.
&lt;strong&gt;Review with the user&lt;/strong&gt;: the signal.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;core-followups&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;==&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; on
&lt;code&gt;Any&lt;/code&gt; are decided at run time&lt;/strong&gt;, as &lt;a href=&quot;/spec/equality-and-memory/#equality&quot;&gt;equality&lt;/a&gt; says: values of
one type compare as that type does, by value or by identity, and values of different types, a
reference and a value among them, are unequal. The sentence in
&lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;Any and Nothing&lt;/a&gt; saying an &lt;code&gt;Any&lt;/code&gt; had no equality was stale and is
corrected. Rationale: every value has &lt;code&gt;==&lt;/code&gt; and a hash, so any value can be a map key, a &lt;code&gt;Map[Any, V]&lt;/code&gt;‘s among them, and the compiler already compared &lt;code&gt;Any&lt;/code&gt;s through each value’s own entries.
Alternative weighed: no &lt;code&gt;==&lt;/code&gt; on &lt;code&gt;Any&lt;/code&gt;, so that every comparison goes through a type pattern first,
which breaks “every value can be a key”.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;core-followups&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;===&lt;/code&gt; is defined
only where its answer is&lt;/strong&gt;: at least one side’s static type is a reference type that cannot hold a
value type (a class, an &lt;code&gt;object&lt;/code&gt;, an array, a buffer, a function type, or a type parameter bounded
by a class). The other side may be the same type, a sub- or superclass, a trait the class conforms
to, an &lt;code&gt;Any&lt;/code&gt;, or a type parameter with no class bound; an &lt;code&gt;Any&lt;/code&gt; or such a parameter is compared as
an &lt;code&gt;Any&lt;/code&gt;, and a boxed value there is never the object, so the answer is &lt;code&gt;false&lt;/code&gt;. Two sides that
may each hold a value type (traits, &lt;code&gt;Any&lt;/code&gt;s, type parameters with no class bound) are an error,
“&lt;code&gt;===&lt;/code&gt; is undefined on Shape and Shape, which may hold values with no identity; compare with &lt;code&gt;==&lt;/code&gt;,
or give one side a class type”; so is a value type on either side. See
&lt;a href=&quot;/spec/equality-and-memory/#identity&quot;&gt;identity&lt;/a&gt;. Rationale: a boxed or data value may be one
object or two at the compiler’s choice, so trait-to-trait identity answered arbitrarily
(&lt;code&gt;f(Box(2), Box(2))&lt;/code&gt; true and &lt;code&gt;f(3, 3)&lt;/code&gt; false for &lt;code&gt;f(a: Shape, b: Shape) = a === b&lt;/code&gt;), while a
class instance is never a boxed value, so mixed class and trait is well defined. Alternatives
weighed: rejecting any trait or &lt;code&gt;Any&lt;/code&gt; operand, which needlessly breaks the library’s
&lt;code&gt;elements === self&lt;/code&gt; (a buffer, deque or set given itself as an &lt;code&gt;Iterable&lt;/code&gt;); and keeping
trait-to-trait identity, which is unsound. A class with a trait it does not conform to is rejected
even when the class is open and a subclass might conform. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether an
open class and a trait it does not itself conform to should compare, since a subclass may be both.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;core-followups&lt;/code&gt;): &lt;strong&gt;a tuple already
made converts to a wider tuple only where each part already is what the wider tuple holds&lt;/strong&gt;: a part
that is an object (a string, a &lt;code&gt;data&lt;/code&gt; value, a tuple, an instance of a class) is its own &lt;code&gt;Any&lt;/code&gt;, and
an instance of a subclass is one of its superclass, so &lt;code&gt;(string, int)&lt;/code&gt; is a &lt;code&gt;(Any, int)&lt;/code&gt;; a part
that would need a box (a number, a &lt;code&gt;bool&lt;/code&gt;, a &lt;code&gt;char&lt;/code&gt;) does not convert, so &lt;code&gt;(int, int)&lt;/code&gt; is not a
&lt;code&gt;(Any, int)&lt;/code&gt;. A tuple written out where the wider one is expected boxes its part there. See
&lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;Any and Nothing&lt;/a&gt;. Rationale: a conversion that changes no bits is
free, while a boxed part changes the tuple’s layout and would mean copying the tuple behind a plain
assignment. Alternatives weighed: no conversion of a tuple once made (what the chapter said, and
needlessly strict for parts that already are objects); converting every part by copying, which
hides an allocation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;core-followups&lt;/code&gt;): &lt;strong&gt;two classes with
no common superclass that share several unrelated most specific traits do not join, and the error
names the traits&lt;/strong&gt;: “the branches of this &lt;code&gt;if&lt;/code&gt; yield Duck and Goose, which share Swims and Flies but
no single most specific type; write the type you want”, and the same ending for &lt;code&gt;match&lt;/code&gt; arms,
clauses, collection and map literals and a loop’s &lt;code&gt;break&lt;/code&gt;s, as
&lt;a href=&quot;/spec/generics/#inference&quot;&gt;inference&lt;/a&gt; says. Rationale: the bare “yield Duck and Goose” did not
say why two classes that plainly share traits fail to agree. Alternative weighed: choosing the
first trait declared, which makes the type depend on declaration order.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;core-followups&lt;/code&gt;): &lt;strong&gt;a tuple type
pattern tests the type the tuple was made with&lt;/strong&gt;, as &lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;Any and Nothing&lt;/a&gt;
says, not the classes of its parts: &lt;code&gt;t: (Animal, int)&lt;/code&gt; holding a &lt;code&gt;Dog&lt;/code&gt; does not match
&lt;code&gt;_: (Dog, int)&lt;/code&gt;, and a tuple made as a &lt;code&gt;(Dog, int)&lt;/code&gt; does wherever it is held. Each part is tested
by a tuple pattern with a type pattern inside it, &lt;code&gt;(d: Dog, n)&lt;/code&gt;, and
&lt;a href=&quot;/spec/operators-and-control-flow/&quot;&gt;type patterns&lt;/a&gt; no longer say a tuple is “taken down part by
part”. Rationale: a tuple’s run-time type is one type, fixed when it is made, so the test agrees
with the static type it was made at. Alternative weighed: testing part by part, which would make a
tuple’s run-time type depend on what it holds rather than on how it was made.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;option-ord&lt;/code&gt;): &lt;a href=&quot;/spec/errors/#option-and-result&quot;&gt;&lt;code&gt;Option[T]&lt;/code&gt; is an
&lt;code&gt;Ord&lt;/code&gt; when &lt;code&gt;T&lt;/code&gt; is&lt;/a&gt;, &lt;code&gt;None&lt;/code&gt; before every &lt;code&gt;Some&lt;/code&gt; and &lt;code&gt;Some&lt;/code&gt;s as their
values, following the reference library’s ordering of options. It makes &lt;code&gt;derives Ord&lt;/code&gt; work on a
data type with an &lt;code&gt;Option&lt;/code&gt; field and lets options sort and have &lt;code&gt;max&lt;/code&gt;/&lt;code&gt;min&lt;/code&gt;. Alternative: no order
on options, leaving a field of one underivable — rejected as the cost falls on every record with
an optional field. (Tuples already had &lt;code&gt;Ord&lt;/code&gt;; &lt;code&gt;Either&lt;/code&gt; and &lt;code&gt;Result&lt;/code&gt; follow in the next entry.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sysl-handles&lt;/code&gt;): &lt;strong&gt;a handle may name a
Sysl trait, and its trait object is kept in a cell&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#handles-on-traits&quot;&gt;Sysl bindings&lt;/a&gt;).
Every handle’s object stays two words, the first naming the Sysl value and the second its owner;
where the reference is a trait object, two words itself, the first word points at a cell the shim
allocates holding it, freed when the reference is given back. The shim tells the cases apart while
Sysl compiles it, by whether a reference to the type is wider than a pointer, and treats a trait
as always held by a counted reference. Rationale: a struct handle is unchanged and reached as
directly as before, the compiled code’s owner and closed checks read the same two words for every
handle, and the compiler need not know which Sysl types are traits, which only Sysl does.
Alternatives weighed: a handle object of three words for a trait, which needs the compiler to know
the Sysl type’s kind before Sysl checks the shim, and moves the owner word of one kind of handle;
every handle boxed, which costs a struct handle an allocation and a load for nothing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sysl-handles&lt;/code&gt;): &lt;strong&gt;an &lt;code&gt;Array&lt;/code&gt; or a
&lt;code&gt;Vector&lt;/code&gt; of handles that is a parameter goes into Sysl&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#collections-of-handles&quot;&gt;Sysl bindings&lt;/a&gt;),
replacing “a handle inside a collection does not go into Sysl”: as a slice of shares of the
handles’ Sysl values, each element checked (closed, another owner) as a handle passed by itself is,
then made the elements the Sysl parameter takes; a vector as a &lt;code&gt;[]T&lt;/code&gt;, an array as a &lt;code&gt;[]const T&lt;/code&gt;,
as for every collection, and a &lt;code&gt;Buf&lt;/code&gt; parameter not reached. Only the collection itself is the
parameter: not nested, not in an &lt;code&gt;Option&lt;/code&gt;, not a &lt;code&gt;List&lt;/code&gt;, not a callback’s answer, not a mirror’s
field. Rationale: a user interface library’s containers take &lt;code&gt;[]&amp;amp;View&lt;/code&gt;; taking shares first means
a call that waits reads no Avin object, and what Sysl keeps it keeps by its own count. A slice or
&lt;code&gt;Buf&lt;/code&gt; of handles out of Sysl already became a vector of handles, so nothing changed there.
Alternatives weighed: rooting the Avin collection for the call instead of taking shares, which
leaves a pointer element reading a value the collector may free once the call returns and Sysl
keeps it; allowing &lt;code&gt;List&lt;/code&gt; and nested collections, which nothing yet needs.
&lt;strong&gt;Review with the user:&lt;/strong&gt; whether an &lt;code&gt;Array&lt;/code&gt; of handles should reach a writable &lt;code&gt;[]&amp;amp;T&lt;/code&gt;, since a
handle collection’s elements written by Sysl could never reach the array anyway; today it is
refused as for every other array, so such a parameter is bound with a &lt;code&gt;Vector&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sysl-handles&lt;/code&gt;): &lt;strong&gt;a handle may name an
instance of a generic Sysl type&lt;/strong&gt;, &lt;code&gt;@sysl(&amp;quot;module.Signal[string]&amp;quot;)&lt;/code&gt;, struct or trait
(&lt;a href=&quot;/spec/sysl-bindings/#handles-on-generic-instances&quot;&gt;Sysl bindings&lt;/a&gt;), its methods bound at that
instance. Each type argument is written as Avin writes it and is a boundary type that is one Sysl
type: an integer of 8, 16, 32 or 64 bits, &lt;code&gt;byte&lt;/code&gt; (spelled &lt;code&gt;u8&lt;/code&gt; for Sysl), &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;,
&lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, or an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt; or a tuple of these; the compiler checks the
arguments’ shape, Sysl that the type takes them. The shim imports the generic type and spells the
instance wherever it names the handle’s type, since Sysl gives no alias to a trait’s instance.
Rationale: &lt;code&gt;syslui&lt;/code&gt; hands out &lt;code&gt;&amp;amp;Signal[T]&lt;/code&gt;, and one class per instance needs no generic classes in
bindings. Alternatives weighed: mirrors and handles as type arguments, which have Sysl spellings of
their own but would make an annotation’s text name Avin types; fully generic bindings, one class
for every &lt;code&gt;T&lt;/code&gt;, which stay specified and unbuilt. A &lt;code&gt;&amp;amp;Signal[T]&lt;/code&gt; parameter shares the handle’s
own signal (from Sysl 0.9.1), so a Sysl function setting a signal is seen by the handle
(&lt;code&gt;tests/programs/run/sysl_generic_handle_sharing&lt;/code&gt;, &lt;code&gt;tests/programs/run/ui_signal_widgets&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;tuple-ord&lt;/code&gt;): &lt;a href=&quot;/spec/errors/#either&quot;&gt;&lt;code&gt;Either[L, R]&lt;/code&gt; and &lt;code&gt;Result[T, E]&lt;/code&gt; are &lt;code&gt;Ord&lt;/code&gt;&lt;/a&gt;
when both sides are. &lt;code&gt;Left&lt;/code&gt; orders before every &lt;code&gt;Right&lt;/code&gt;, following the reference library’s
ordering of eithers; &lt;code&gt;Result&lt;/code&gt; is ordered as &lt;code&gt;Either&lt;/code&gt; with &lt;code&gt;Err&lt;/code&gt; in the place of &lt;code&gt;Left&lt;/code&gt;, so every
&lt;code&gt;Err&lt;/code&gt; before every &lt;code&gt;Ok&lt;/code&gt;. Rationale: both types put the failure on the same side (&lt;code&gt;Left&lt;/code&gt; and
&lt;code&gt;Err&lt;/code&gt; are the reason, &lt;code&gt;Right&lt;/code&gt; and &lt;code&gt;Ok&lt;/code&gt; the value), so the one rule “failure before success” holds
for both, and &lt;code&gt;Err&lt;/code&gt; agrees with &lt;code&gt;Left&lt;/code&gt; under &lt;code&gt;toRight&lt;/code&gt;/&lt;code&gt;toLeft&lt;/code&gt; conversions. Alternatives weighed:
&lt;code&gt;Ok&lt;/code&gt; before &lt;code&gt;Err&lt;/code&gt;, matching the declaration order of &lt;code&gt;Result&lt;/code&gt;‘s variants (which is what
&lt;code&gt;derives Ord&lt;/code&gt; would give a data type, and what a reader of &lt;code&gt;data Result&lt;/code&gt; might expect) but
disagreeing with &lt;code&gt;Either&lt;/code&gt;; and no order on &lt;code&gt;Result&lt;/code&gt;, leaving a record with a result field
underivable. Review with the user: the &lt;code&gt;Err&lt;/code&gt;-first choice is the one a reader of the declaration
could find surprising. Tuples needed no change: their &lt;code&gt;Ord&lt;/code&gt;, lexicographic by part at every
arity, was already written by the compiler for each arity and is now covered by tests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;bool-ord&lt;/code&gt;): &lt;strong&gt;&lt;a href=&quot;/spec/equality-and-memory/#display-and-debug&quot;&gt;&lt;code&gt;bool&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt;
before &lt;code&gt;true&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;, reversing the earlier rule that
&lt;code&gt;bool&lt;/code&gt; had no order. &lt;code&gt;compare&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt;/&lt;code&gt;max&lt;/code&gt;/&lt;code&gt;clamp&lt;/code&gt;, &lt;code&gt;Reverse&lt;/code&gt;, sorting, &lt;code&gt;TreeSet&lt;/code&gt;/&lt;code&gt;TreeMap&lt;/code&gt; keys,
tuple keys and derived orders all take a bool, and &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;gt;=&lt;/code&gt; are allowed on two bools
as on every built-in &lt;code&gt;Ord&lt;/code&gt; (one unsigned machine comparison). Rationale: porting a to-do list met
&lt;code&gt;tasks.sortBy(t -&amp;gt; (t.done, t.id))&lt;/code&gt; refused, the one-line way to put open items first; without an
order a bool field also leaves a record underivable for &lt;code&gt;Ord&lt;/code&gt; and a tuple key holding a flag
unusable, and &lt;code&gt;false &amp;lt; true&lt;/code&gt; is the one order everyone already reads (0 before 1). Alternatives
weighed: keeping the refusal, so a key is written &lt;code&gt;if t.done then 1 else 0&lt;/code&gt; (noise at every sort,
and still no &lt;code&gt;derives Ord&lt;/code&gt; with a flag); an &lt;code&gt;Ord&lt;/code&gt; for &lt;code&gt;bool&lt;/code&gt; without the operators, a split no
other &lt;code&gt;Ord&lt;/code&gt; type has; a helper such as &lt;code&gt;byDone&lt;/code&gt;, too narrow for a general type. &lt;code&gt;unit&lt;/code&gt; keeps no
order. Review with the user: it reverses a settled rule, and &lt;code&gt;b1 &amp;lt; b2&lt;/code&gt; reads oddly to some.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sysl-callbacks&lt;/code&gt;): &lt;a href=&quot;/spec/sysl-bindings/#callbacks&quot;&gt;passing Avin functions to
Sysl&lt;/a&gt;, the choices the request left open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The closure’s lifetime is Sysl’s&lt;/strong&gt;: the shim’s closure captures a counted Sysl value with a
destructor that holds a root of the collector, so the root is given back when Sysl drops its
last reference to the closure. Why: Sysl closures already carry captured state and drop it, so
nothing has to be released by hand and nothing leaks while Sysl’s own ownership is right.
Alternatives: an explicit &lt;code&gt;release&lt;/code&gt; the library calls (leaks whenever it forgets, and frees a
function Sysl may still call when it releases early); a root for the program’s whole run
(leaks every callback ever given).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A callback belongs to the code that gave it by default; &lt;code&gt;@threaded&lt;/code&gt; on a binding’s parameter
lets any thread call it.&lt;/strong&gt; The default compares owners, as a handle’s use does, and traps on any
other caller. Why: a callback’s captures are ordinary Avin objects, shared without
synchronization, so a call from another thread is a data race unless the function is checked;
most UI and event callbacks run on the thread that registered them. Alternatives: a flag on the
whole binding, &lt;code&gt;@sysl(&amp;quot;name&amp;quot;, threaded)&lt;/code&gt; (coarser: one binding may take two callbacks); reading
&lt;code&gt;&amp;amp;sync Fn&lt;/code&gt; from the Sysl signature (Avin does not parse Sysl types; Sysl’s check already refuses
the unmarked case, and the refusal is reworded to name the mark). &lt;strong&gt;Review with the user&lt;/strong&gt;: the
spelling &lt;code&gt;@threaded&lt;/code&gt;, and whether the default should be the owner (as built) or the OS thread.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What a &lt;code&gt;@threaded&lt;/code&gt; parameter is given is checked by its captures&lt;/strong&gt;, since a function value is
never &lt;code&gt;Sendable&lt;/code&gt;: a top-level function, or a lambda, local function or method value whose every
capture is a &lt;code&gt;val&lt;/code&gt; or a parameter of a sendable type. A function value held in a variable or a
parameter is refused (its type does not say what it captures), and a binding with a &lt;code&gt;@threaded&lt;/code&gt;
parameter cannot be used as a value, which would hide the call from the check. Alternatives:
making function types carry a sendability mark (&lt;code&gt;Sendable&lt;/code&gt; function types; a larger language
change); no check (unsound).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A thread Sysl started itself is attached for a &lt;code&gt;@threaded&lt;/code&gt; callback’s call&lt;/strong&gt; (its own context,
a fresh owner, the stack guard installed) and detached after; a callback without the mark called
there traps without a place, since the thread never entered from Avin. Why: an audio or I/O
thread of a C library is the common case, and attaching is cheap and safe since the thread holds
no Avin references between calls. Alternative: always trap (makes such libraries unusable).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A callback made while its thread is in a blocking call makes the thread running for the call
and safe again after&lt;/strong&gt;; the place a trap in the library reports (the context’s caller site) is
restored when the call ends.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-05 (the director): &lt;strong&gt;a binding with a &lt;code&gt;@threaded&lt;/code&gt;
parameter is &lt;code&gt;blocking&lt;/code&gt; whether or not it says so&lt;/strong&gt;, since a Sysl call that may wait for another
thread to call back would otherwise hold up that thread’s first collection for ever. Why: the
deadlock cannot be detected, and the cost is two stores and two loads per call. Alternative:
documenting that such a binding is declared &lt;code&gt;blocking&lt;/code&gt; (built first; a forgotten word hangs the
program). A same-thread callback’s binding still blocks only where it says so.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trap inside a callback stops the program at the callback’s own place.&lt;/strong&gt; Avin traps report a
place rather than a backtrace, so “with the Avin backtrace” is the trap’s place; there is no
unwinding through Sysl frames, which would need Sysl to be unwind-safe.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The program defines one C-convention entry per callback parameter&lt;/strong&gt; (a bool as a byte), which
the shim declares &lt;code&gt;extern&lt;/code&gt; and calls with the closure; the shim itself is generic in the Sysl
types of the closure’s arguments, so a callback’s integer parameter takes any Sysl integer with
the check a result has. Alternative: the shim calling the closure’s code directly through a
function pointer (ties the shim to Avin’s internal convention for &lt;code&gt;bool&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The runtime offers &lt;code&gt;avin.rt.callbacks_held&lt;/code&gt;, the number of functions Sysl holds, for tests and
for libraries that want to check they release what they register.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sendable-spawn&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Sendable&lt;/code&gt; where values cross threads
today&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;what is shared&lt;/a&gt;). The actors chapter’s build order has no
step for it; it applies the rule of &lt;code&gt;isolate&lt;/code&gt;‘s body, less the whole-program half, to threads and
futures. Review with the user: it adds two annotations users can write.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The check is two marks on a parameter, &lt;code&gt;@sendable&lt;/code&gt; and &lt;code&gt;@isolated&lt;/code&gt;, which any function may
write. What is passed for &lt;code&gt;@isolated&lt;/code&gt; may use only sendable values from around it: a lambda, a
by-name argument, a local function or a method value by what it captures (its nested closures
and the local functions it calls included), any other expression by the locals and parameters it
reads; what it makes itself is its own. &lt;code&gt;@sendable&lt;/code&gt; adds that a closure captures no &lt;code&gt;var&lt;/code&gt;, whose
box it would share with the code that made it. A marked parameter holding a function may be
passed on for one with the same mark or a weaker one; an override may not add a mark or
strengthen one. &lt;em&gt;Why&lt;/em&gt;: the library’s thread entries are ordinary Avin functions, so a user’s
wrapper of &lt;code&gt;spawn&lt;/code&gt; needs the same spelling the library uses, and a mark on the parameter checks
every call where the closure is written and its captures are known. &lt;em&gt;Alternatives&lt;/em&gt;: a list of
library functions known to the compiler (no user wrapper could pass a body on); a function type
that says it is sendable (&lt;code&gt;() -&amp;gt; T&lt;/code&gt; that is &lt;code&gt;Sendable&lt;/code&gt;), which would also let a sendable function
be stored and sent, but makes function types carry a flag through unification and subtyping
(later taken up as &lt;code&gt;@sendable&lt;/code&gt; function types, under Proposed); no check, leaving the data race the
memory model already makes harmless (the user’s direction is that threads share nothing mutable
by default).&lt;/li&gt;
&lt;li&gt;The bodies of &lt;code&gt;spawn&lt;/code&gt;, &lt;code&gt;s.spawn&lt;/code&gt;, &lt;code&gt;Future(body)&lt;/code&gt; and &lt;code&gt;ex.future(body)&lt;/code&gt;, the functions of a
future’s &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;onComplete&lt;/code&gt;, and &lt;code&gt;orElse&lt;/code&gt;‘s by-name argument are &lt;code&gt;@sendable&lt;/code&gt;.
Their results are bounded by &lt;code&gt;Sendable&lt;/code&gt;, as are &lt;code&gt;Future.successful&lt;/code&gt;‘s value, a &lt;code&gt;Promise&lt;/code&gt;‘s and
the results of &lt;code&gt;mapOk&lt;/code&gt; and &lt;code&gt;mapErr&lt;/code&gt;, so every future’s value is sendable however it was made.
&lt;em&gt;Alternative&lt;/em&gt;: bounding &lt;code&gt;Future[T]&lt;/code&gt; itself, which would make every generic function naming a
future repeat the bound.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;Mutex&lt;/code&gt; is sendable of any value, so its value is &lt;code&gt;@isolating&lt;/code&gt; where it is made (a buffer the
caller keeps cannot be guarded), &lt;code&gt;with&lt;/code&gt; is &lt;code&gt;with[R: Sendable](@isolating body: (T) -&amp;gt; R) -&amp;gt; R&lt;/code&gt;
(the value cannot be returned or stored outside), and &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; exist only for a
sendable value. A &lt;code&gt;with&lt;/code&gt; body may assign the caller’s &lt;code&gt;var&lt;/code&gt;s of sendable types, since it runs at
once on the calling thread. &lt;em&gt;Why&lt;/em&gt;: without it, &lt;code&gt;Mutex(b)&lt;/code&gt; or &lt;code&gt;m.with(v -&amp;gt; v)&lt;/code&gt; hands the guarded
buffer to code that changes it without the lock, which is the shared mutable state the mutex is
the one door to. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;Mutex&lt;/code&gt; of any value unchecked, as written before; checking only
&lt;code&gt;with&lt;/code&gt;‘s result. The cost: a body cannot give back a fresh mutable value (&lt;code&gt;nextBytes&lt;/code&gt; on the
shared random generator copies through a vector), and a generic body over an unbounded &lt;code&gt;T&lt;/code&gt;
cannot take its argument in (the shared generator’s &lt;code&gt;shuffle&lt;/code&gt;, &lt;code&gt;choose&lt;/code&gt; and &lt;code&gt;chooseWeighted&lt;/code&gt;
now draw under the lock and pick outside it, with the same draws). Review with the user.&lt;/li&gt;
&lt;li&gt;The standard library promises &lt;code&gt;Sendable&lt;/code&gt; for &lt;code&gt;Thread[T]&lt;/code&gt; of a sendable &lt;code&gt;T&lt;/code&gt;, &lt;code&gt;Executor&lt;/code&gt;, a
mutex’s &lt;code&gt;Condition&lt;/code&gt;, and &lt;code&gt;TcpStream&lt;/code&gt; and &lt;code&gt;TcpListener&lt;/code&gt;, which hold a Sysl handle and are handed
over with it. A &lt;code&gt;Scope&lt;/code&gt; is not sendable, so the trap on starting a scope’s thread from another
thread is reached only through module-level state.&lt;/li&gt;
&lt;li&gt;Tests that shared mutable data across threads were changed to share it safely: a scope’s
threads write &lt;code&gt;Atomic&lt;/code&gt; slots rather than an array; a flag and a once-initialized value became
&lt;code&gt;Atomic&lt;/code&gt;s; a vector built in a &lt;code&gt;var&lt;/code&gt; is copied into a &lt;code&gt;val&lt;/code&gt;; a test’s own byte array is made by
each thread; a trait sent through futures promises &lt;code&gt;Sendable&lt;/code&gt;; the run test of the scope trap
became a rejection test; a test’s &lt;code&gt;Once&lt;/code&gt; counter became an &lt;code&gt;Atomic&lt;/code&gt;; a test helper passing a
function to its threads marks it &lt;code&gt;@sendable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Command.lines()&lt;/code&gt; on a command holding a sequence starts the command on its driver thread, so
the mutable job belongs to that thread alone, and learns through a promise whether it started;
before, the job was made on the calling thread and handed to the driver. A started &lt;code&gt;Child&lt;/code&gt; and
a lines iterator are mutable and not sendable; a thread starts and reads its own commands.
Moving one would need &lt;code&gt;Isolated&lt;/code&gt; or a promise like &lt;code&gt;TcpStream&lt;/code&gt;‘s; a started &lt;code&gt;Child&lt;/code&gt; has since
been given the promise (&lt;a href=&quot;#proposed&quot;&gt;proposed&lt;/a&gt;), and a lines iterator has not.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;fix-lone-value&lt;/code&gt;): &lt;strong&gt;A member call on the name of a data type whose variant of its own name has no fields&lt;/strong&gt;
(&lt;code&gt;Lone.m(…)&lt;/code&gt; with &lt;code&gt;data Lone()&lt;/code&gt;; branch &lt;code&gt;fix-lone-value&lt;/code&gt;). The name is both the type and a value
of it. Proposed: where the type has a static member named &lt;code&gt;m&lt;/code&gt;, the call is the type’s and chooses
among its static members alone; otherwise it is the value’s method, its trait methods and
impl-added methods included. A method value &lt;code&gt;Lone.m&lt;/code&gt; follows the same order. Why: a static member
can only be reached through the type’s name, while the value’s method is always reachable through
a value, so giving the static the name loses nothing; and it keeps &lt;code&gt;Name.m(…)&lt;/code&gt; with a static
member meaning what it means on every other type. Alternatives weighed: the value always wins
(makes a fieldless type’s static members unreachable by name); choosing among the static members
and the value’s methods together by parameter types (a call on a type name would then mix two
kinds of receiver in one overload set, which nothing else in the language does); refusing a
static member and a value method of one name on such a type (an extra rule for a rare case). The
companion object needs no rule: it cannot share the name of a fieldless variant
(&lt;a href=&quot;/spec/declarations/#object&quot;&gt;declarations&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;option-ord-fix&lt;/code&gt;): the &lt;a href=&quot;/spec/generics/#polymorphic-recursion&quot;&gt;polymorphic recursion&lt;/a&gt;
check counts a cycle through a method an impl with bounds of its own adds only along the paths
whose type argument’s outermost type may meet the bounds, that type’s own arguments taken as any
type; a type argument whose outermost type the check does not know (a tuple, a function, a part
taken apart from a larger type) counts as one that may. Why: the check must never miss a real
cycle, and the outermost type is what the flow already tracks per path; &lt;code&gt;impl[T: Ord] Ord for Option[T]&lt;/code&gt; otherwise made every program loading the threads library fail. Alternatives weighed:
connecting the impl’s methods from the parameter as a whole (what it did: false cycles through
types that never meet the bounds); tracking type arguments deeper than the outermost type (exact
for nested shapes such as a &lt;code&gt;Box[Box[Plain[T]]]&lt;/code&gt;, which is still counted, at the cost of a much
larger flow graph). Review with the user if a nested shape turns up in real code.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;option-ord-fix&lt;/code&gt;): an ordering, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, settles an unknown in one
operand’s type from the other’s, so &lt;code&gt;Some(1) &amp;lt; None&lt;/code&gt; compares two &lt;code&gt;Option[int]&lt;/code&gt;s, as &lt;code&gt;==&lt;/code&gt; already
did. Why: the two operands of an ordering are one type, so the other operand is the only evidence
and the obvious one. Alternative: requiring &lt;code&gt;None[int]&lt;/code&gt;, which &lt;code&gt;==&lt;/code&gt; does not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;qualified-variants&lt;/code&gt;): &lt;strong&gt;Qualified variant access, &lt;code&gt;Type.Variant&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;qualified-variants&lt;/code&gt;, 2026-11-05). Decided:
&lt;code&gt;T.V&lt;/code&gt; and &lt;code&gt;m.T.V&lt;/code&gt; name data type &lt;code&gt;T&lt;/code&gt;‘s variant &lt;code&gt;V&lt;/code&gt;, beside the bare &lt;code&gt;V&lt;/code&gt;, in expressions and
patterns; the variant comes before any other member of that name, and a companion object
declaring a method or a field named after one of its type’s variants is refused where it is
declared. A capitalized &lt;code&gt;T.Name&lt;/code&gt; that is no variant, companion member or static member is reported
with the type’s variants. Why: the qualified form is meant to be unambiguous, and refusing the
companion member keeps it so, at the cost of a rule that only bites on a member spelled like a
variant (members are lowerCamelCase, variants PascalCase). Alternatives weighed: the companion’s
member winning (&lt;code&gt;Shape.Circle&lt;/code&gt; would then not always be the variant, defeating the point);
choosing between them by call shape (a value and a call of one name meaning different things);
allowing both silently with the variant winning (the companion member unreachable by name). A
static trait member spelled like a variant is not refused, since the trait and the type are
declared apart: the variant wins in &lt;code&gt;T.V&lt;/code&gt;, and the member stays reachable through a type
parameter. Type arguments are written once, on the type or on the variant, not both. Review with
the user: whether the “capitalized name” test for reporting a missing variant should instead be
any name that resolves to nothing on a data type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;thread-ownership&lt;/code&gt;): &lt;strong&gt;Every operation on a connection or a listener checks its socket’s owner first&lt;/strong&gt; (branch
&lt;code&gt;thread-ownership&lt;/code&gt;). A &lt;code&gt;TcpStream&lt;/code&gt; keeps the bytes it read ahead in Avin fields, so a read served
from them alone never reached the socket, and the code that had handed the connection over read
on from them without trapping; a closed connection or listener answered an error, and a
listener’s &lt;code&gt;port()&lt;/code&gt; its field, from any thread. Now &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;,
&lt;code&gt;writeText&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;shutdownOutput&lt;/code&gt; and &lt;code&gt;close&lt;/code&gt; on a connection, and &lt;code&gt;port&lt;/code&gt;, &lt;code&gt;accept&lt;/code&gt; and
&lt;code&gt;close&lt;/code&gt; on a listener, first call a runtime method that does nothing on the open socket, or the
socket’s &lt;code&gt;close()&lt;/code&gt;, which does nothing on a closed one: both check the owner, so the previous
owner traps at every use, open or closed, and the new owner reads the bytes read ahead, which
move with the connection. The owner check comes before a read’s size check. Why: the promise is
that a connection belongs to one thread at a time, and a race on the read-ahead fields is exactly
what it rules out. Alternatives weighed: dropping the read-ahead on hand-over (loses bytes the
other end sent); a check in the compiler for every field of a class holding a handle (a language
rule for what one library type needs); an Avin owner field compared by hand (it would not move
when the runtime hands over, which moves only handles).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;thread-ownership&lt;/code&gt;): &lt;strong&gt;A started &lt;code&gt;Child&lt;/code&gt; promises &lt;code&gt;Sendable&lt;/code&gt;, and moves between threads as a connection does&lt;/strong&gt;
(branch &lt;code&gt;thread-ownership&lt;/code&gt;). It holds a runtime token, a handle holding nothing but its owner,
and &lt;code&gt;waitFor&lt;/code&gt;, &lt;code&gt;isAlive&lt;/code&gt; and &lt;code&gt;kill&lt;/code&gt; use it first, so handing a child to a thread’s or a future’s
body makes it the body’s, the code that handed it over traps at any use while the body runs
(&lt;code&gt;`Child` belongs to another thread&lt;/code&gt;), and it comes back to the next user when the body
returns. The body may wait for it, stop it and start a sequence’s later part. Why a token: a
child’s own handles come and go (a program that has ended gives its handle back, a part not yet
started has none, nor has one whose time ran out before it began), so none of them can carry the
promise. Alternatives weighed: &lt;code&gt;Isolated&lt;/code&gt; (not built yet, and a child is a resource handed over
whole, as a connection is, not an object graph being built); keeping it not sendable, so that a
thread starts and waits for its own commands (what it was; a server that starts a command and
hands it to a waiter could not). A lines iterator stays not sendable: it is consumed where it is
made, and the thread reading a command’s output can start the command itself.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;thread-ownership&lt;/code&gt;): &lt;strong&gt;A handle class’s &lt;code&gt;@sysl&lt;/code&gt; may name it for its traps: &lt;code&gt;@sysl(&amp;quot;avin.rt.Token&amp;quot;, named: &amp;quot;Child&amp;quot;)&lt;/code&gt;&lt;/strong&gt;
(branch &lt;code&gt;thread-ownership&lt;/code&gt;; the director decided that the old owner’s trap names the type the user
holds). Every trap a handle raises, belonging to another thread and being closed, in compiled code
and in the shim, uses that name rather than the class’s; the name must be a type’s (a capital
first, letters, digits and &lt;code&gt;_&lt;/code&gt;), and nothing else about the handle changes. Why: the trap is read
by the code that misused the value, which knows the &lt;code&gt;Child&lt;/code&gt;, not the private token class inside
it. Alternatives weighed: a token class of the same name in a module of its own (two types named
&lt;code&gt;Child&lt;/code&gt;, which misleads a reader of the library); the trap text computed by the runtime from a
name the token holds (the check is inline, one compare in compiled code, and its text is fixed
when the program is compiled); naming the trap after the class whose method made the call (a
rule no reader would guess). &lt;code&gt;TcpStream&lt;/code&gt; and &lt;code&gt;TcpListener&lt;/code&gt; each keep a handle class of their
own over the one Sysl type &lt;code&gt;sysl.net.Socket&lt;/code&gt;, &lt;code&gt;named:&lt;/code&gt; for the type, so their traps name
the type the user holds (branch &lt;code&gt;socket-trap-names&lt;/code&gt;); two handle classes may share one Sysl
type. The other library handles (&lt;code&gt;File&lt;/code&gt;, &lt;code&gt;FdReader&lt;/code&gt;, &lt;code&gt;Spawned&lt;/code&gt;, &lt;code&gt;Address&lt;/code&gt;) are held only inside
private library values whose own checks come first, so none is named further.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;module-var-threads&lt;/code&gt;): &lt;strong&gt;a thread’s body reaches no
module-level mutable state&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;what is shared&lt;/a&gt;). What is passed
for a &lt;code&gt;@sendable&lt;/code&gt; parameter, directly or through every function it reaches, reads and writes no
module-level &lt;code&gt;var&lt;/code&gt; and reads no module-level value, &lt;code&gt;lazy val&lt;/code&gt; or &lt;code&gt;object&lt;/code&gt; whose type is not
sendable. Reached means: the function a call names; for a call through a method table or a bound,
every method of that name in that slot of any type’s table; for an operator on a value that is not
a scalar, every implementation of the trait method it calls; every closure and function value
made along the way; and the code a pattern runs (an extractor’s method, a sequence’s length). The
error names the module-level item and the functions it is reached through, shortest path first.
&lt;em&gt;Why&lt;/em&gt;: a module-level value is reached by name, not captured, so the capture rule of &lt;code&gt;@sendable&lt;/code&gt;
never sees it, and a body that bumps a module-level counter races with &lt;code&gt;main&lt;/code&gt;. Avin compiles the
whole program, so what a call can reach is known, as &lt;code&gt;isolate&lt;/code&gt;‘s check of its body already
assumes. &lt;em&gt;Alternatives&lt;/em&gt;: no check (the memory model makes the race harmless to the collector, but
the threads chapter promises that threads share nothing mutable but the synchronized types);
rejecting only what the body names itself (misses every call, so it closes nothing); per-thread
copies of module-level &lt;code&gt;var&lt;/code&gt;s (a different meaning for one declaration depending on which thread
reads it); and treating each module-level &lt;code&gt;var&lt;/code&gt; as an implicit &lt;code&gt;Atomic&lt;/code&gt; (hides a lock in every
read and does not make a read-modify-write atomic).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The whole argument counts, not only the closure: &lt;code&gt;spawn(makeBody())&lt;/code&gt; is checked through
&lt;code&gt;makeBody&lt;/code&gt; and every closure it makes, since what runs on the thread is whatever it gives back.
The cost is a rejection where a call evaluated at once on the calling thread reads a &lt;code&gt;var&lt;/code&gt; to
choose the body. &lt;em&gt;Alternative&lt;/em&gt;: following only closures and function values, which misses a
body returned by a call.&lt;/li&gt;
&lt;li&gt;A call through a trait method or an operator counts every implementation in the program, since
which one a value has is not known where the body is checked. The cost is a rejection where one
implementation reads a module-level &lt;code&gt;var&lt;/code&gt; and the body never meets a value of that type.
&lt;em&gt;Alternative&lt;/em&gt;: following the receiver’s static type only where the class is final, which is
finer but has to agree with devirtualization.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;reach-chains&lt;/code&gt;): &lt;strong&gt;what a call through a
method table, a bound or an operator reaches follows the types its receiver may have.&lt;/strong&gt; On a data
type it is that type’s own method; on a class, that class’s and its subclasses’; on a built-in
scalar, nothing of the program’s; on a trait or a type parameter, the method of that name of every
type conforming to the trait or to the parameter’s bounds; on &lt;code&gt;Any&lt;/code&gt;, every one, as before. A
generic function or method is followed instance by instance: called at known type arguments (or
a method on a receiver of known type arguments), its operators and bound calls on its type
parameters reach only what those types implement, and a lambda runs in the instance that makes
it. An equality on a type with an &lt;code&gt;equals&lt;/code&gt; of its own reaches that; one without compares fields
and elements and still reaches every &lt;code&gt;equals&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the rule above counted every method of the
name in the program, so a program’s &lt;code&gt;impl Sub for Money&lt;/code&gt; reading a module-level &lt;code&gt;var&lt;/code&gt; made the
standard library’s &lt;code&gt;BigInt&lt;/code&gt; subtraction, and with it &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Future&lt;/code&gt; and &lt;code&gt;println&lt;/code&gt;, look as if they
reached it: a thread’s body was rejected through chains no value could follow. Every narrowing
keeps every implementation a value of the type can really have, so nothing the check closed is
reopened (&lt;code&gt;thread_module_reach_generic.avin&lt;/code&gt; pins the reachable routes). &lt;em&gt;Alternatives&lt;/em&gt;: keeping
the name-wide rule and deduplicating the chains (still rejects correct programs); a flow analysis
of which types each generic class is made with, which would also see that an &lt;code&gt;Iterator[Any]&lt;/code&gt; in
&lt;code&gt;println&lt;/code&gt; never yields a program’s type (much larger, and an instance whose arguments are not
known still stands for every instance); narrowing by bounds alone, without instances (leaves
&lt;code&gt;Map[int, …]&lt;/code&gt; reaching every &lt;code&gt;hash&lt;/code&gt;). Review with the user: a code path through a trait-typed
value whose type arguments are not known still reaches every conforming type’s method, so a
program whose own &lt;code&gt;Hash&lt;/code&gt; or &lt;code&gt;Eq&lt;/code&gt; reads a module-level &lt;code&gt;var&lt;/code&gt; still sees library code rejected in a
thread’s body (&lt;code&gt;println&lt;/code&gt; reaches &lt;code&gt;HashSet.contains&lt;/code&gt; through an &lt;code&gt;Iterator[Any]&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;What is passed for an &lt;code&gt;@isolated&lt;/code&gt; parameter is not held to this, since it runs at once on the
calling thread. A &lt;code&gt;Mutex&lt;/code&gt;‘s value and &lt;code&gt;with&lt;/code&gt; body were &lt;code&gt;@isolated&lt;/code&gt;; they are now &lt;code&gt;@isolating&lt;/code&gt;,
which is held to it (see the &lt;code&gt;mutex-isolating&lt;/code&gt; entry below).&lt;/li&gt;
&lt;li&gt;Printing stays legal with no promise: &lt;code&gt;print&lt;/code&gt;, &lt;code&gt;println&lt;/code&gt;, &lt;code&gt;eprintln&lt;/code&gt; and the &lt;code&gt;StandardOutput&lt;/code&gt;
and &lt;code&gt;StandardError&lt;/code&gt; objects reach the runtime’s streams, which keep no state in Avin, and the
objects hold no field. The standard library’s own module-level state is held to the rule like
a program’s: the futures’ worker registry, guarded by its lock, promises &lt;code&gt;Sendable&lt;/code&gt;, as do the
regex library’s Unicode run tables (arrays filled before the table is made and never written
after), and so does
the &lt;code&gt;Annotation&lt;/code&gt; trait, since a type’s shape is one module-level value every thread may read
(an annotation type holding a mutable field is now rejected where it implements the trait). A
collection’s companion object (&lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, the mutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt;) is
sendable like any object with no field; only the collections themselves are mutable.
Review with the user: whether the &lt;code&gt;Annotation&lt;/code&gt; promise is wanted, and whether the trait and
operator over-approximation rejects too much in practice.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;lambda-untupling&lt;/code&gt;): &lt;strong&gt;A lambda takes a tuple apart by its parameters&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#tuples&quot;&gt;tuples&lt;/a&gt;; branch
&lt;code&gt;lambda-untupling&lt;/code&gt;). Where a function of one parameter whose type is an &lt;em&gt;n&lt;/em&gt;-tuple (&lt;em&gt;n&lt;/em&gt; ≥ 2) is
expected, a lambda of exactly &lt;em&gt;n&lt;/em&gt; parameters binds the tuple’s elements in order, each typed from
its element; a declared parameter type must fit its element (a wider one is accepted, as for any
lambda parameter), and an element the expected type leaves unknown takes its declared type. &lt;code&gt;_&lt;/code&gt;
binds nothing; an inner tuple is one element. It applies only where the lambda’s parameter count
does not fit the expected function directly, and among overloads a candidate that needs it is
chosen only where none takes the lambda as written (&lt;code&gt;Map.map((k, v) -&amp;gt; …)&lt;/code&gt; stays the
two-parameter overload). A count fitting neither shape is an error naming both. Why:
&lt;code&gt;xs.zip(ys).forall((x, y) -&amp;gt; x == y)&lt;/code&gt; is the natural spelling and was rejected, leaving only
&lt;code&gt;match (x, y) -&amp;gt; …&lt;/code&gt;, a pattern where two names suffice; the reference language takes tuples apart
the same way. Alternatives weighed: keeping the &lt;code&gt;match&lt;/code&gt; function as the only way (no new rule,
but the common case pays for a pattern); allowing a pattern in any lambda parameter position,
&lt;code&gt;((a, b), c) -&amp;gt; …&lt;/code&gt; (more general, but a second pattern syntax beside the &lt;code&gt;match&lt;/code&gt; function, which
already covers nested and refutable shapes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;iterable-size&lt;/code&gt;): &lt;strong&gt;every &lt;code&gt;Iterable&lt;/code&gt; has &lt;code&gt;size()&lt;/code&gt;, &lt;code&gt;knownSize()&lt;/code&gt; and &lt;code&gt;sizeCompare(n)&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/collections/&quot;&gt;collections&lt;/a&gt;), following the reference library: &lt;code&gt;size()&lt;/code&gt; counts by iterating unless a collection overrides it with its own count, &lt;code&gt;knownSize()&lt;/code&gt; is the count where it is known without iterating and -1 otherwise (a &lt;code&gt;List&lt;/code&gt; other than &lt;code&gt;Nil&lt;/code&gt;, an iterator, a view), and &lt;code&gt;sizeCompare(n)&lt;/code&gt; answers -1, 0 or 1, reading at most &lt;code&gt;n&lt;/code&gt; elements when the count is unknown. Sequences have &lt;code&gt;size()&lt;/code&gt; and &lt;code&gt;length()&lt;/code&gt;, equal. They are overridable trait members rather than &lt;code&gt;impl&lt;/code&gt; methods, so a call through &lt;code&gt;Iterable[T]&lt;/code&gt; reaches the collection’s own count. Consequence: a class implementing &lt;code&gt;Iterable&lt;/code&gt; that declares its own &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt; or &lt;code&gt;sizeCompare&lt;/code&gt; must mark it &lt;code&gt;override&lt;/code&gt;. Alternatives weighed: an arbitrary-sign &lt;code&gt;sizeCompare&lt;/code&gt; (the reference library’s contract, but -1/0/1 is what every caller tests); &lt;code&gt;length()&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt; (left to sequences, whose length is their defining measure); &lt;code&gt;sizeIs&lt;/code&gt; (needs special syntax). Review with the user: the &lt;code&gt;override&lt;/code&gt; requirement on existing user classes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-binding&lt;/code&gt;): &lt;strong&gt;A callback’s integer answer goes into whatever integer the closure Sysl takes answers, with a
check&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#callbacks&quot;&gt;Sysl bindings&lt;/a&gt;). An Avin function answering a &lt;code&gt;long&lt;/code&gt; or
an &lt;code&gt;int&lt;/code&gt; reaches a Sysl closure answering any integer, &lt;code&gt;u32&lt;/code&gt;, &lt;code&gt;u64&lt;/code&gt; and &lt;code&gt;usize&lt;/code&gt; among them, and
an answer the Sysl type cannot hold stops the program where the binding Sysl is running in was
called, naming the type by sign and width (&lt;code&gt;value out of range for u32&lt;/code&gt;). Why: Avin has no
unsigned integers (settled 2026-11-02), and syslui asks for a colour by &lt;code&gt;&amp;amp;Fn() -&amp;gt; u32&lt;/code&gt;; the
answer is the mirror image of an &lt;a href=&quot;/spec/sysl-bindings/#integer-results&quot;&gt;integer result&lt;/a&gt;, which
already takes any Sysl integer, so one rule covers both directions of a value Sysl reads, and a
narrower signed answer is the same case. A closure answering a generic Sysl function’s type
parameter names no integer, and answers the binding’s own type; the compiler learns that from
Sysl’s refusal to infer one and builds the shims once more. Alternatives weighed: an &lt;code&gt;int&lt;/code&gt;
reinterpreted as the &lt;code&gt;u32&lt;/code&gt;‘s bits (a colour past &lt;code&gt;0x7FFFFFFF&lt;/code&gt; written negative, and a reader
never sure which); refusing the binding (no window could be given a colour); converting only
into unsigned types (two rules for one shape). Built on &lt;code&gt;ui-binding&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-binding&lt;/code&gt;): &lt;strong&gt;The user interface binding is the package &lt;code&gt;ui&lt;/code&gt;, in &lt;code&gt;packages/ui&lt;/code&gt; of this repository, rather
than a module of the standard library&lt;/strong&gt; (&lt;a href=&quot;/spec/ui/&quot;&gt;User interfaces&lt;/a&gt;). Why: no package may
declare a module under &lt;code&gt;avin&lt;/code&gt;, the standard library carries no Sysl dependencies, and a program
that does not draw should neither build syslui nor link SDL3; a domain library is a package of
its own (&lt;a href=&quot;/spec/packages/#the-standard-librarys-modules&quot;&gt;packages&lt;/a&gt;). Alternatives weighed: &lt;code&gt;avin.ui&lt;/code&gt;
in the standard library (needs the library to name Sysl packages and every program to link SDL3);
a repository of its own (premature while the binding and the language move together). Built on
&lt;code&gt;ui-binding&lt;/code&gt;. Review with the user: the name &lt;code&gt;avin.ui&lt;/code&gt; was the plan’s, and only the standard
library may hold it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-binding&lt;/code&gt;): &lt;strong&gt;The binding is thin and keeps syslui’s shapes&lt;/strong&gt; (&lt;a href=&quot;/spec/ui/&quot;&gt;User interfaces&lt;/a&gt;). Each syslui
function is bound under its Avin name with syslui’s defaults restated; a view is one handle class
on the trait; one signal class for each instance a control takes (&lt;code&gt;IntSignal&lt;/code&gt;, &lt;code&gt;RealSignal&lt;/code&gt;,
&lt;code&gt;BoolSignal&lt;/code&gt;, &lt;code&gt;StringSignal&lt;/code&gt;); &lt;code&gt;slider&lt;/code&gt; is one overload for &lt;code&gt;int&lt;/code&gt; and one for &lt;code&gt;real&lt;/code&gt;; &lt;code&gt;Role&lt;/code&gt;,
&lt;code&gt;Variant&lt;/code&gt;, &lt;code&gt;TextStyle&lt;/code&gt;, &lt;code&gt;MissKind&lt;/code&gt;, &lt;code&gt;Missed&lt;/code&gt; and &lt;code&gt;Rect&lt;/code&gt; are mirrors. The package’s one function of
its own is &lt;code&gt;tap(v, key, at)&lt;/code&gt;, the draw, snapshot, press and release a test of an interface makes
every time. Why: the component and signal layer, which is Avin’s, decides the shapes an
application writes; this layer only has to reach syslui. Alternatives weighed: a generic signal
class (Avin binds a handle at one instance); wrapping every binding in a private one (no name to
change yet). Built on &lt;code&gt;ui-binding&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-binding&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;run&lt;/code&gt; is &lt;code&gt;blocking&lt;/code&gt;, and no ui callback is &lt;code&gt;@threaded&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/ui/#the-application&quot;&gt;User interfaces&lt;/a&gt;).
The frame loop waits for events for most of its life, so the thread is safe for the collector
meanwhile, and syslui-sdl calls the tree, the ground and every control’s callback on the thread
that called &lt;code&gt;run&lt;/code&gt;. Alternatives weighed: an unmarked &lt;code&gt;run&lt;/code&gt;, which would hold up every other
thread’s collections for the life of the window. Built on &lt;code&gt;ui-binding&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;unicode-identifiers&lt;/code&gt;): &lt;strong&gt;Names in any script&lt;/strong&gt; (branch &lt;code&gt;unicode-identifiers&lt;/code&gt;, 2026-11-05; &lt;a href=&quot;/spec/declarations/#names&quot;&gt;names&lt;/a&gt;).
A name starts with a character of Unicode’s &lt;code&gt;XID_Start&lt;/code&gt; or &lt;code&gt;_&lt;/code&gt; and continues with &lt;code&gt;XID_Continue&lt;/code&gt;
(UAX #31, the Unicode identifier rule), at the Unicode version the compiler’s tables were cut
from (17.0.0). Why: domain vocabulary is written in the programmer’s own language, and the XID
properties are the ones designed to be stable under normalization and across Unicode versions.
Alternatives weighed: ASCII only (what the lexer had; refuses &lt;code&gt;größe&lt;/code&gt; for no reason a reader
could guess); any non-ASCII character that is not a space (admits emoji, arrows and operators
of other scripts, so &lt;code&gt;a→b&lt;/code&gt; would be one name); General_Category letters, marks and digits
(Sysl’s rule; close to XID but not stable under normalization, and admits pattern characters
such as U+2E2F).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;unicode-identifiers&lt;/code&gt;): &lt;strong&gt;A name in a normal form other than NFC is an error, with its NFC spelling&lt;/strong&gt; (branch
&lt;code&gt;unicode-identifiers&lt;/code&gt;). Why: every name stays byte for byte the text written, so spans, rename,
lookup and emitted symbols need no second spelling, and two spellings that look identical can
never be two names, which is what normalizing would also guarantee. Alternatives weighed:
normalizing to NFC silently (friendlier to an input method that writes decomposed text, but
every name then has a spelling the source does not contain); no normalization (Sysl’s choice:
&lt;code&gt;café&lt;/code&gt; and &lt;code&gt;cafe&lt;/code&gt; with U+0301 are two names that look the same); NFKC (folds &lt;code&gt;ﬁ&lt;/code&gt; into &lt;code&gt;fi&lt;/code&gt; and
full-width letters into ASCII, which changes what a name visibly is). A module’s directory name
is held to the same rule. Review with the user: whether silent normalization is preferred.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;unicode-identifiers&lt;/code&gt;): &lt;strong&gt;Capitalized means an uppercase or titlecase first letter (&lt;code&gt;Lu&lt;/code&gt;, &lt;code&gt;Lt&lt;/code&gt;); a caseless letter is
not capitalized&lt;/strong&gt; (branch &lt;code&gt;unicode-identifiers&lt;/code&gt;). Every place the compiler asks whether a name
is capitalized (a missing variant written &lt;code&gt;T.V&lt;/code&gt;, a scalar type’s &lt;code&gt;MaxValue&lt;/code&gt;-style constants, a
missing type in an import of a library module, a handle’s &lt;code&gt;named:&lt;/code&gt;, the highlighting of types)
uses this test, so &lt;code&gt;Ärger&lt;/code&gt;, &lt;code&gt;Δelta&lt;/code&gt; and &lt;code&gt;ǅemal&lt;/code&gt; read as type-like names and &lt;code&gt;名前&lt;/code&gt; as a value’s.
A bare name in a pattern is a variant when one of that name is in scope and a binding otherwise,
whatever its case, so a caseless name is a binding unless it names a variant. Why: a caseless
script has no way to write a capital, and treating its names as lowercase keeps them usable for
the commonest names (values, functions); its types are still declared and used by name.
Alternatives weighed: caseless counting as capitalized (every CJK local would read as a
constructor-like name); refusing caseless names where a capital is expected (a CJK program could
not name a type). Review with the user: this is the choice most likely to matter to a program
written wholly in a caseless script.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;unicode-identifiers&lt;/code&gt;): &lt;strong&gt;Look-alike names in different scripts are different names, with no warning&lt;/strong&gt; (branch
&lt;code&gt;unicode-identifiers&lt;/code&gt;): Latin &lt;code&gt;a&lt;/code&gt; and Cyrillic &lt;code&gt;а&lt;/code&gt; are two names. Why: confusable detection
(UTS #39) needs data the compiler does not carry and warns on legitimate mixed-script code.
Alternative: a mixed-script warning per name. Review with the user if spoofed names in shared
packages become a concern.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;unicode-identifiers&lt;/code&gt;): &lt;strong&gt;A character above ASCII that begins no token is reported with its code point and stepped over
whole&lt;/strong&gt; (branch &lt;code&gt;unicode-identifiers&lt;/code&gt;): an emoji is “not a character a name or an operator is
spelled with”, and a digit or mark of another script where a name begins “cannot begin a name”,
each naming the character and its &lt;code&gt;U+&lt;/code&gt; code point. Why: the bytes of one character used to be read as separate
symbols, which the parser then reported one at a time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sendable-functions&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;@sendable&lt;/code&gt;
function types&lt;/strong&gt;, answering the open question whether a function value can be sent, with a type
that says what it captures (&lt;a href=&quot;/spec/types/#function-types&quot;&gt;function types&lt;/a&gt;, &lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;what is
shared&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt; is a function type whose values capture only sendable values and no &lt;code&gt;var&lt;/code&gt;
and reach no module-level mutable state; it is &lt;code&gt;Sendable&lt;/code&gt;, and a plain function type is not.
Only a function type may carry the mark.&lt;/li&gt;
&lt;li&gt;A lambda, a function reference or a method value written where a &lt;code&gt;@sendable&lt;/code&gt; function type is
expected is made as one, and is checked there by exactly the checks what is passed for a
&lt;code&gt;@sendable&lt;/code&gt; parameter gets: its captures, and the whole-program reach of module-level state.
The error names the type (&lt;code&gt;a `@sendable (int) -&amp;gt; int` may use only sendable values …&lt;/code&gt;). Any
other value of a plain function type is not one, and the mismatch says why.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt; is a subtype of &lt;code&gt;(A) -&amp;gt; B&lt;/code&gt; with no conversion: in covariant positions
(a vector’s element, a result, an override’s result) too, not through an invariant one (an
array’s element). Two branches of the two types agree on the plain one.&lt;/li&gt;
&lt;li&gt;A parameter marked &lt;code&gt;@sendable&lt;/code&gt; that takes a function holds a value of the &lt;code&gt;@sendable&lt;/code&gt; function
type inside the function, so the mark and the type are one notion seen from the two sides; the
parameter’s declared type is unchanged, so an override that drops the mark still overrides.
Passing a value already of a &lt;code&gt;@sendable&lt;/code&gt; type to &lt;code&gt;spawn&lt;/code&gt; or any marked parameter is accepted as
it is.&lt;/li&gt;
&lt;li&gt;Data and classes whose fields are &lt;code&gt;@sendable&lt;/code&gt; functions are sendable by the existing structural
rules, at every type argument of a generic one (a &lt;code&gt;Parser[T]&lt;/code&gt; holding a
&lt;code&gt;@sendable (Input) -&amp;gt; Option[T]&lt;/code&gt;), so module-level parser grammars, &lt;code&gt;lazy val&lt;/code&gt;s among them, pass
the module-state check and run on spawned threads.&lt;/li&gt;
&lt;li&gt;Two overloads that differ only in whether a function parameter is &lt;code&gt;@sendable&lt;/code&gt; are one overload
(refused as declared twice), as two differing only in a by-name parameter are, since one lambda
may be passed for either and overload resolution runs before the sendability check.&lt;/li&gt;
&lt;li&gt;An override’s parameter types match its method’s exactly, the mark included; its result may be
the &lt;code&gt;@sendable&lt;/code&gt; subtype.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Why&lt;/em&gt;: the parsing library’s grammars are module-level values holding functions, and could not
be used from a thread at all; the &lt;code&gt;@sendable&lt;/code&gt; parameter mark already decides exactly what a
function value may capture and reach, so the same check at the point a value is made lets the
type carry the guarantee through storage, fields and module-level values, soundly, and the
spelling reuses the mark readers already know.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Alternatives&lt;/em&gt;: inferring capture sendability into every function type with no mark (every
lambda’s type would depend on its body, unification and overloads would see two function types
per signature, and an API could not promise it); effect-style capture sets in the type (precise,
but a large addition to the type system for one property); leaving functions never sendable
(sound, but module-level grammars, handler tables and task lists stay unusable from threads).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: the spelling &lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt; (an annotation in type position, the
only one), against a keyword or a &lt;code&gt;Sendable&lt;/code&gt;-bounded spelling; and whether two overloads
differing only in the mark should be refused or resolved to the plain one for a lambda.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;state-machines&lt;/code&gt;): &lt;strong&gt;State machines, the choices &lt;a href=&quot;/spec/actors/#state-machines&quot;&gt;the chapter&lt;/a&gt; leaves open&lt;/strong&gt; (branch
&lt;code&gt;state-machines&lt;/code&gt;, 2026-11-05). A machine is read into its &lt;code&gt;Door.State&lt;/code&gt; data type and a final class
holding the current state, so it needs no runtime. Decided:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Order inside a transition.&lt;/strong&gt; The arm runs first; then the current state’s &lt;code&gt;leave&lt;/code&gt;, in which
&lt;code&gt;state()&lt;/code&gt; still answers the state being left; then the new state is current and its &lt;code&gt;enter&lt;/code&gt;
runs, in which &lt;code&gt;state()&lt;/code&gt; answers it; &lt;code&gt;handle&lt;/code&gt; answers the state after &lt;code&gt;enter&lt;/code&gt;. Why: an arm
computes where to go, &lt;code&gt;leave&lt;/code&gt; cleans up the old state’s data, which it can still read, and
&lt;code&gt;enter&lt;/code&gt; sees the machine as it will be. Alternatives: switching the state before &lt;code&gt;leave&lt;/code&gt; (it
would then read data no longer current); running &lt;code&gt;leave&lt;/code&gt; before the arm (an arm yielding &lt;code&gt;stay&lt;/code&gt;
would have left).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A state is a variant of its module&lt;/strong&gt;, as every data type’s variant is: &lt;code&gt;Locked(code)&lt;/code&gt; and
&lt;code&gt;door.state() is Locked(_)&lt;/code&gt; name it bare. Why: it follows from &lt;code&gt;Door.State&lt;/code&gt; being an ordinary
data type matched by bare names, as the chapter writes. Alternatives: scoping state names to
their machine, written bare only inside it and &lt;code&gt;Door.State.Locked&lt;/code&gt; outside (the chapter’s own
&lt;code&gt;door.state() is Locked(_)&lt;/code&gt; would no longer read). Amended (Proposed, branch &lt;code&gt;shared-variants&lt;/code&gt;,
below): two machines of one module may now share a state’s name, and a state an event’s
variant, each bare use decided by the type expected there, as for every shared variant name;
until then a state’s name had to be one no other variant of the module had.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Door.State&lt;/code&gt; takes all of the machine’s type parameters, with their bounds&lt;/strong&gt;, so a state of a
generic machine may hold values of them: &lt;code&gt;Cell.State[string]&lt;/code&gt;. Why: the smallest rule that lets
any state hold any of them. Alternative: only the parameters the states use (the type’s
arguments would then depend on which states mention which parameter).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;stay&lt;/code&gt; is the value of an arm where it is the arm’s value&lt;/strong&gt;: the arm’s whole body, the last
line of a block, and each branch of an &lt;code&gt;if&lt;/code&gt; or a &lt;code&gt;match&lt;/code&gt; that is itself in such a place.
Elsewhere &lt;code&gt;stay&lt;/code&gt; is an ordinary name. Why: the chapter makes &lt;code&gt;stay&lt;/code&gt; a keyword only as an arm’s
value. Alternative: anywhere in an arm’s body (it would then be a value that could be stored,
with a meaning only at the end).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The trap on handling from inside a handler names the machine and is reported at its
declaration&lt;/strong&gt;: &lt;code&gt;avin: trap: `Relay` handles an event from inside one of its own arms, `enter` or `leave` blocks at file:line:col&lt;/code&gt;. The first state’s &lt;code&gt;enter&lt;/code&gt;, run as the machine is made, is
such a block too. Why: the check is in the code the declaration makes. Alternative: reporting
the &lt;code&gt;handle&lt;/code&gt; call that re-entered, as a library trap reports the program’s call (it needs the
machine’s code to count as the library’s for its traps, which its arms are not).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The coverage error lists every case left out&lt;/strong&gt;: each variant of the event type not covered in
full, written as its first uncovered value (&lt;code&gt;Lock(_)&lt;/code&gt;, &lt;code&gt;Both(true, None)&lt;/code&gt;), followed by “where
the guard is false” when a guarded arm could have taken it; for an event type without variants,
one value (&lt;code&gt;-1&lt;/code&gt;). Why: it is the chapter’s own message, extended to the shapes it does not show.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A machine takes no parents and no &lt;code&gt;derives&lt;/code&gt;&lt;/strong&gt; in its header in this step, and a state and the
&lt;code&gt;receive&lt;/code&gt; block take &lt;code&gt;else&lt;/code&gt; arms as a &lt;code&gt;match&lt;/code&gt; does. Alternative: parents after the parameters, as
a class’s; nothing in the chapter needs them yet.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handling an event from the machine’s own body&lt;/strong&gt;, before the first state’s &lt;code&gt;enter&lt;/code&gt; has run, is
allowed: the machine is in its first state then. Alternative: trapping as from inside a handler.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Not sendable, said as such&lt;/strong&gt;: a machine passed where a sendable value is needed is reported as
“a machine, a mutable object that moves between its states”, not by its hidden state field.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-int-params&lt;/code&gt;): &lt;strong&gt;A binding’s integer parameter goes into whatever integer the Sysl
parameter is, with a check&lt;/strong&gt; (&lt;a href=&quot;/spec/sysl-bindings/#integer-parameters&quot;&gt;Sysl bindings&lt;/a&gt;). An Avin
&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;i8&lt;/code&gt; or &lt;code&gt;i16&lt;/code&gt; parameter reaches a Sysl parameter of any concrete integer type, &lt;code&gt;u8&lt;/code&gt;
to &lt;code&gt;u64&lt;/code&gt;, &lt;code&gt;usize&lt;/code&gt; and the signed widths, converted in the shim; a value the Sysl type cannot hold
stops the program where the binding was called (&lt;code&gt;value out of range for u32&lt;/code&gt;). A handle’s method
converts the same way, and a blocking call converts with its thread safe for the collector,
making it running again before stopping the program. Why: syslui’s colour modifiers take a &lt;code&gt;u32&lt;/code&gt;
parameter, Avin has no unsigned integers (settled 2026-11-02), and the rule is the mirror image of
the integer result and the callback answer, so all three directions of an integer follow one
rule. Consequence: a &lt;code&gt;long&lt;/code&gt; now reaches an &lt;code&gt;i32&lt;/code&gt; parameter where its value fits, which was
rejected before. Alternatives weighed: converting only into unsigned types (two rules for one
shape); an &lt;code&gt;int&lt;/code&gt; reinterpreted as the &lt;code&gt;u32&lt;/code&gt;‘s bits (a colour past &lt;code&gt;0x7FFFFFFF&lt;/code&gt; written negative).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-int-params&lt;/code&gt;): &lt;strong&gt;An integer parameter is passed as the Avin type
itself where Sysl cannot infer a type for its conversion&lt;/strong&gt;: a parameter whose Sysl type is a type
parameter of a generic function (&lt;code&gt;same[T](x: T)&lt;/code&gt;), and every integer parameter of a binding whose
call left any type argument uninferred (syslui’s &lt;code&gt;slider[T](value: &amp;amp;Signal[T], lo: T, hi: T)&lt;/code&gt;,
where the integer bounds decide &lt;code&gt;T&lt;/code&gt;). The compiler learns this from Sysl’s refusal and builds the
shims once more, as it does for a callback’s answer. Why: a conversion needs a target type, and a
generic parameter has none until its arguments say. Alternatives weighed: converting the
parameters a generic call can still infer and passing only the stalled ones as they are (needs a
build per round of refusals); refusing such bindings (&lt;code&gt;slider&lt;/code&gt; would be unbindable). Review with
the user: a binding to a Sysl function overloaded only by integer width now reaches the overload
Sysl picks for an uninferred integer argument, rather than the one matching the Avin type
exactly; no binding does this today.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-int-params&lt;/code&gt;): &lt;strong&gt;An integer an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a tuple or a
collection parameter holds is not converted&lt;/strong&gt;, and the binding is rejected with a sentence saying
so. Why: the conversion functions for these shapes are shared between bindings and spelled with
the Avin type’s Sysl spelling; making each generic in its integers would make every nested
parameter an inference problem, for no binding that needs it yet. Alternative: converting them as
results are converted (the shape is there, the need is not).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-int-params&lt;/code&gt;): &lt;strong&gt;A colour in &lt;code&gt;ui&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt; holding
&lt;code&gt;0xRRGGBB&lt;/code&gt;&lt;/strong&gt;, as syslui draws it, with &lt;code&gt;rgb(r, g, b)&lt;/code&gt;, &lt;code&gt;mix&lt;/code&gt;, &lt;code&gt;lighten&lt;/code&gt; and &lt;code&gt;darken&lt;/code&gt;
(&lt;a href=&quot;/spec/ui/#colours&quot;&gt;User interfaces&lt;/a&gt;). Why: syslui has no alpha, so a &lt;code&gt;0xRRGGBBAA&lt;/code&gt; would carry a
channel nobody reads; every colour fits an &lt;code&gt;int&lt;/code&gt;, which is what a hex literal is by default; and a
binding’s parameter cannot take an Avin data type, so a &lt;code&gt;Color&lt;/code&gt; type would need a wrapper around
every modifier. Alternatives weighed: a &lt;code&gt;long&lt;/code&gt; (what &lt;code&gt;app&lt;/code&gt;‘s &lt;code&gt;ground&lt;/code&gt; answers, but wider than any
colour); a &lt;code&gt;Color&lt;/code&gt; data type with &lt;code&gt;rgb&lt;/code&gt;/&lt;code&gt;rgba&lt;/code&gt; (a wrapper per modifier, and an alpha syslui
ignores). Review with the user: &lt;code&gt;app&lt;/code&gt;‘s &lt;code&gt;ground&lt;/code&gt; still answers a &lt;code&gt;long&lt;/code&gt;; it could become an &lt;code&gt;int&lt;/code&gt;
to match.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-int-params&lt;/code&gt;): &lt;strong&gt;A value narrower than 32 bits crosses the
boundary widened as the C convention says&lt;/strong&gt;: Avin marks a shim’s &lt;code&gt;i8&lt;/code&gt; and &lt;code&gt;i16&lt;/code&gt; parameters and a
callback’s narrow signed answer &lt;code&gt;signext&lt;/code&gt;, and a byte or bool &lt;code&gt;zeroext&lt;/code&gt;, which Sysl relies on. This
fixes a bug: a negative &lt;code&gt;i8&lt;/code&gt; or &lt;code&gt;i16&lt;/code&gt; computed at run time reached Sysl as a large positive value
(&lt;code&gt;-5&lt;/code&gt; as &lt;code&gt;65531&lt;/code&gt;). Alternatives weighed: passing every narrow integer as an &lt;code&gt;i32&lt;/code&gt; and narrowing in
the shim (changes the type a generic Sysl parameter infers).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sendable-params&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;@sendable&lt;/code&gt; parameter is sendable
inside its function, whatever its type&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;threads&lt;/a&gt;). Found by the
parsing library, whose combinators take a &lt;code&gt;@sendable f: PartialFunction[char, U]&lt;/code&gt; and could neither
capture it in a &lt;code&gt;@sendable&lt;/code&gt; lambda nor pass it on.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Inside the function the parameter is sendable: a &lt;code&gt;@sendable&lt;/code&gt; lambda captures it and it is passed
on for another &lt;code&gt;@sendable&lt;/code&gt; parameter without a check. &lt;em&gt;Why&lt;/em&gt;: what is passed for it was checked
where it was passed, as a function-typed parameter’s already was.&lt;/li&gt;
&lt;li&gt;What is passed for one that does not take a function is itself sendable: a &lt;code&gt;match&lt;/code&gt; function
written in place (the core library’s &lt;code&gt;MatchPartialFunction&lt;/code&gt; of two lambdas, checked by what the
arms capture and the module-level state they reach), a value of a sendable type, a parameter so
marked, or a class’s marked &lt;code&gt;val&lt;/code&gt; parameter. Any other value is refused, where before a fresh
object (&lt;code&gt;what it makes itself is its own&lt;/code&gt;) passed. &lt;em&gt;Why&lt;/em&gt;: the value is now shared by whatever the
function hands it to, so a fresh object with a &lt;code&gt;var&lt;/code&gt; field would be shared between threads.&lt;/li&gt;
&lt;li&gt;The mark belongs to the parameter, not to its type (the sound minimum): a marked value copied
into a local, stored in a data field typed as the trait, combined (&lt;code&gt;f.orElse(g)&lt;/code&gt;), or passed for
an unmarked parameter bounded by &lt;code&gt;Sendable&lt;/code&gt;, is a value of the trait’s type again, which is not
sendable. A class’s &lt;code&gt;val&lt;/code&gt; parameter marked &lt;code&gt;@sendable&lt;/code&gt; is a field whose value is sendable, so it
leaves the class sendable by its structure; a &lt;code&gt;var&lt;/code&gt; one does not. &lt;em&gt;Alternatives&lt;/em&gt;: a
&lt;code&gt;@sendable&lt;/code&gt; mark on trait types (&lt;code&gt;@sendable PartialFunction[A, B]&lt;/code&gt;), which would carry the
property through locals and fields, or marked data fields; both are new type-system surface, and
can be added later without breaking what this allows. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether
&lt;code&gt;@sendable&lt;/code&gt; should become a mark on trait types, as it is on function types.&lt;/li&gt;
&lt;li&gt;A lambda or a &lt;code&gt;match&lt;/code&gt; function passed for a type argument bounded by &lt;code&gt;Sendable&lt;/code&gt;
(&lt;code&gt;^^^[U: Sendable](value: U)&lt;/code&gt;) is made as a &lt;code&gt;@sendable&lt;/code&gt; function and checked as one where it is
made; where the expected type decides that argument as a plain function type, it is taken as its
&lt;code&gt;@sendable&lt;/code&gt; form, which conforms to the plain one. &lt;em&gt;Why&lt;/em&gt;: a plain function type is never
sendable, so the call could not succeed otherwise. &lt;em&gt;Alternative&lt;/em&gt;: requiring the type written,
&lt;code&gt;^^^[@sendable (int, int) -&amp;gt; int](…)&lt;/code&gt;, which is noisy for every operator parser. A &lt;code&gt;match&lt;/code&gt;
function where a &lt;code&gt;PartialFunction&lt;/code&gt; is expected is not changed by the bound: it is a
&lt;code&gt;PartialFunction&lt;/code&gt;, which does not promise &lt;code&gt;Sendable&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;mixed-lambda-inference&lt;/code&gt;): &lt;strong&gt;the lambdas and &lt;code&gt;match&lt;/code&gt; functions of a call are
checked in turn, each the first in the call whose parameter types are known&lt;/strong&gt;
(&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;): declared by it, or decided by the arguments checked so
far; where none is, the first one left is checked and reports what it cannot infer. Found as a
bug: they were checked strictly left to right after the other arguments, so
&lt;code&gt;both(match n -&amp;gt; n + 1, (x: int) -&amp;gt; x * 10)&lt;/code&gt; for &lt;code&gt;both[A, B](g: (A) -&amp;gt; B, f: (A) -&amp;gt; B)&lt;/code&gt; failed
with “cannot infer the type of the value this &lt;code&gt;match&lt;/code&gt; matches”, as did an untyped lambda written
before the typed one, while the same arguments swapped were accepted. &lt;em&gt;Why&lt;/em&gt;: the smallest rule
under which argument order does not matter for what can be inferred, and every call accepted
before is checked in the same order as before (each lambda it checked was already the first
ready one). &lt;em&gt;Alternatives&lt;/em&gt;: keep left to right (order-sensitive, as the bug shows); check the
lambdas with declared parameters first, then the rest left to right (misses chains, where a
&lt;code&gt;match&lt;/code&gt; function’s type comes from an untyped lambda’s result); or solve all of them together
as constraints, checking each body against partly unknown parameters (a larger change, with
diagnostics harder to place). &lt;strong&gt;Review with the user&lt;/strong&gt;: the order rule is visible in which calls infer, so a later
constraint solver would be a language change.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sendable-followups&lt;/code&gt;): &lt;strong&gt;three follow-ups to &lt;code&gt;@sendable&lt;/code&gt; parameters&lt;/strong&gt;
(&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;threads&lt;/a&gt;, &lt;a href=&quot;/spec/sysl-bindings/#callbacks&quot;&gt;callbacks&lt;/a&gt;). They
amend the &lt;code&gt;sendable-params&lt;/code&gt; entry above where it says a combination, and a &lt;code&gt;match&lt;/code&gt; function where
a &lt;code&gt;PartialFunction&lt;/code&gt; is expected, are not sendable.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A binding’s &lt;code&gt;@threaded&lt;/code&gt; parameter takes a value of a &lt;code&gt;@sendable&lt;/code&gt; function type and a parameter
marked &lt;code&gt;@sendable&lt;/code&gt; as they are, and a lambda passed there may capture a marked parameter. A
plain function value, an unmarked or &lt;code&gt;@isolated&lt;/code&gt; parameter, and an unmarked parameter captured
stay refused. &lt;em&gt;Why&lt;/em&gt;: each was checked where it was made or passed to be what any thread may
run, which is all the &lt;code&gt;@threaded&lt;/code&gt; check asks. &lt;em&gt;Alternative&lt;/em&gt;: none sound is narrower; requiring
a lambda around it (&lt;code&gt;x -&amp;gt; f(x)&lt;/code&gt;) is the contortion this removes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;f.orElse(g)&lt;/code&gt; is sendable where &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;g&lt;/code&gt; are&lt;/strong&gt;, by a promise the standard library writes on
the method, &lt;code&gt;@sendable_result&lt;/code&gt;: a call of a function so marked is sendable where its receiver
and every argument are a &lt;code&gt;match&lt;/code&gt; function written in place, a value of a sendable type, a
marked parameter or class field, or another such call; chains of &lt;code&gt;orElse&lt;/code&gt; follow. The promise
is refused outside the standard library, since nothing checks it against the body, and a call
that names the method statically reaches no override. A combination held in a local is a
&lt;code&gt;PartialFunction&lt;/code&gt; again, as a marked parameter copied into one is. Only &lt;code&gt;orElse&lt;/code&gt; makes the
promise: &lt;code&gt;lift&lt;/code&gt; answers a function whose captures a program’s own &lt;code&gt;PartialFunction&lt;/code&gt;
implementation decides, and &lt;code&gt;applyOrElse&lt;/code&gt; answers a value, not a partial function.
&lt;em&gt;Alternatives weighed&lt;/em&gt;: a general rule that any call whose parts are sendable is sendable
(unsound: the call may answer a fresh object with a &lt;code&gt;var&lt;/code&gt;, or reach module-level state); a
conditional &lt;code&gt;Sendable&lt;/code&gt; impl for &lt;code&gt;OrElsePartialFunction&lt;/code&gt; (the result’s static type is the trait,
which no impl of the class reaches); hard-coding &lt;code&gt;PartialFunction.orElse&lt;/code&gt; in the checker (the
annotation says the same and names its users); a &lt;code&gt;@sendable&lt;/code&gt; mark on trait types, under review
in the entry above, which would subsume this. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether a program’s own
combinators should be able to make the promise, checked against the body (a body that only
builds an object of a final class from its parameters).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;match&lt;/code&gt; function where a &lt;code&gt;PartialFunction&lt;/code&gt; is expected, passed for a type argument bounded
by &lt;code&gt;Sendable&lt;/code&gt;, meets the bound&lt;/strong&gt;, as a lambda there does: its two lambdas are made as
&lt;code&gt;@sendable&lt;/code&gt; functions and checked where they are made, the one running its arms holding every
pattern, guard and body, so a fault is reported once. &lt;code&gt;PartialFunction&lt;/code&gt; itself does not promise
&lt;code&gt;Sendable&lt;/code&gt;, so the bound is waived at that call only where every value the call gives the
callee of the type argument is such a function: each parameter whose type could give one (any
position but what a function passed takes, a data type’s or a class’s argument counted whatever
its variance) is of exactly that type and given such a function. A written type argument is
held to the bound as written, as &lt;code&gt;take[(int) -&amp;gt; int](…)&lt;/code&gt; is. &lt;em&gt;Why&lt;/em&gt;: the callee obtains values
of its type argument only from its arguments, each of which was checked. &lt;em&gt;Alternatives
weighed&lt;/em&gt;: a sendable form of the &lt;code&gt;PartialFunction&lt;/code&gt; type (the trait-type mark under review
above); making &lt;code&gt;MatchPartialFunction&lt;/code&gt; promise &lt;code&gt;Sendable&lt;/code&gt; (it holds two plain function fields,
which are not sendable, and a &lt;code&gt;match&lt;/code&gt; function’s static type is the trait anyway).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;Interface state is a generic Avin class
&lt;code&gt;State[T]&lt;/code&gt;, with &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt; and &lt;code&gt;update(f)&lt;/code&gt;, and a set is one write: an &lt;code&gt;invalidate()&lt;/code&gt; for a
state held in Avin, or a write of its signal for one a control has linked&lt;/strong&gt;
(&lt;a href=&quot;/spec/ui/#components-and-state&quot;&gt;components&lt;/a&gt;). Why: the state lives in Avin, so it holds any
type; making the set the frame loop’s write means nothing else has to be called after one, and a
set is counted exactly as a signal’s is. Alternatives weighed: syslui’s own signals for every
state (only four instances exist, so a list or a data value could not be state); a set that skips
the write when the value is unchanged (needs &lt;code&gt;Eq&lt;/code&gt; on every &lt;code&gt;T&lt;/code&gt;, and a function or a class has
none).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;A control over a state reads and writes the
state’s own signal, made once by &lt;code&gt;State.signal(s)&lt;/code&gt;, which is from then on where the value lives&lt;/strong&gt;,
rather than a second copy kept in step. Why: one place for the value means a control’s write is
the state’s value at once, with no build in between, and no write can echo back into the other
side, so there is no loop to break. Alternatives weighed: a bridge copying both ways at each
build, comparing against the last value it saw (stale between a tap and the next build, and a
conflict to resolve when both change); a callback from syslui on each write (not in the binding).
The controls taking a &lt;code&gt;State&lt;/code&gt; are overloads of the binding’s own (&lt;code&gt;switch&lt;/code&gt;, &lt;code&gt;checkbox&lt;/code&gt;, &lt;code&gt;radio&lt;/code&gt;,
&lt;code&gt;radioGroup&lt;/code&gt;, both &lt;code&gt;slider&lt;/code&gt;s, &lt;code&gt;textField&lt;/code&gt;, &lt;code&gt;textArea&lt;/code&gt;, &lt;code&gt;tabs&lt;/code&gt;, &lt;code&gt;scroll&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;Components are functions returning &lt;code&gt;View&lt;/code&gt;, written
&lt;code&gt;component c -&amp;gt; …&lt;/code&gt; or &lt;code&gt;keyed(key) c -&amp;gt; …&lt;/code&gt;; what a component keeps across builds is asked of its
&lt;code&gt;Scope&lt;/code&gt; by order (&lt;code&gt;c.state(init)&lt;/code&gt;, &lt;code&gt;c.remember(make)&lt;/code&gt;, &lt;code&gt;c.derived(f)&lt;/code&gt;), and a component is found
again by its place among its parent’s unkeyed components, or by its key.&lt;/strong&gt; A build is a call of
the function &lt;code&gt;root(body)&lt;/code&gt; answers; a component the build of its parent leaves out is dropped with
everything inside it. Why: a component stays a plain function of its arguments, so props are
ordinary parameters and need no class; reified type tests make the positional slots sound (a slot
asked for as another type stops the program rather than being misread); the scope is a parameter,
so a request outside a component cannot be written by mistake. Alternatives weighed: a class per
component with fields as state (props would have to be copied into an instance kept from an
earlier build, and every component would need a class and a table of instances by type); a
state machine per component (fits a component with modes, not one holding a value); a scope
passed from parent to child explicitly (every call of a component would carry it). Review with
the user: the shape of the API, and whether keys should be any &lt;code&gt;Hash&lt;/code&gt; value rather than a
&lt;code&gt;string&lt;/code&gt; or an &lt;code&gt;int&lt;/code&gt;. &lt;strong&gt;Review with the user&lt;/strong&gt;: the component API’s shape, and whether keys should be any &lt;code&gt;Hash&lt;/code&gt; rather than a string or an int.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;The mistakes the order and the keys can make stop
the program&lt;/strong&gt;: a component built with no root building, two components under one parent with one
key, a slot asked for as another type than the last build’s, a scope asked after its build, and a
root built inside its own build. Why: each would otherwise give one component another’s state
silently. Alternatives weighed: starting the slot or the component afresh (hides the mistake), a
warning (Avin has no runtime warning channel).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;derived(f)&lt;/code&gt; computes again only after something
has been written since its last computation, by the counter &lt;code&gt;writes()&lt;/code&gt; answers&lt;/strong&gt;, rather than by
the states it read. Why: every state, signal and &lt;code&gt;invalidate()&lt;/code&gt; moves the counter, so it is never
stale where the frame loop would rebuild, and it needs no record of what &lt;code&gt;f&lt;/code&gt; read. Alternatives
weighed: tracking the states read during &lt;code&gt;f&lt;/code&gt; (finer, but a hidden global and a cost on every
&lt;code&gt;get&lt;/code&gt;), computing on every call (no use as a value of its own).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;The interface’s state belongs to the thread running
it, and the type system keeps it there&lt;/strong&gt;: a &lt;code&gt;State&lt;/code&gt;, a &lt;code&gt;Derived&lt;/code&gt; and a &lt;code&gt;Scope&lt;/code&gt; are mutable, so not
sendable, and a closure for another thread cannot capture one. There is no &lt;code&gt;post&lt;/code&gt; or &lt;code&gt;runOnUi&lt;/code&gt; yet.
Why: the frame loop’s write counter and syslui’s signals are not synchronized, so the only sound
cross-thread path is a queue the frame loop drains, and nothing in the binding wakes the loop from
another thread. Alternatives weighed: a sendable &lt;code&gt;post(@sendable f)&lt;/code&gt; queuing a change (its
function could not capture the state it is meant to change, so it would need a sendable handle
to a state, a design of its own). Review with the user: a worker reporting to the interface
needs that handle and a way to wake the frame loop. &lt;strong&gt;Review with the user&lt;/strong&gt;: the path from another thread, which needs a sendable handle and a way to wake the frame loop.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;ui-components&lt;/code&gt;): &lt;strong&gt;An example program is one package, so the to-do
example is &lt;code&gt;examples/ui-todo&lt;/code&gt; beside &lt;code&gt;examples/ui&lt;/code&gt;&lt;/strong&gt;, since the corpus builds each directory of
&lt;code&gt;examples&lt;/code&gt; as one program with one &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-runtime&lt;/code&gt;): &lt;strong&gt;A behaviour’s library form is
&lt;code&gt;Behaviour[M](name: string, start: @sendable (ActorRef[M]) -&amp;gt; (M) -&amp;gt; unit)&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/actors/#declaring-an-actor&quot;&gt;declaring an
actor&lt;/a&gt;). The start runs once on the actor’s first turn, is
given the actor’s own reference (&lt;code&gt;self&lt;/code&gt;), makes the actor’s state in its locals and gives back the
handler of each message; &lt;code&gt;actor&lt;/code&gt; declarations will lower to exactly this, the name being the
declaration’s. Why: it is the smallest value that holds “the declaration and its arguments” and
can be started again for a restart, and making the start a &lt;code&gt;@sendable&lt;/code&gt; function puts the existing
capture and module-level-state checks on everything an actor’s body reaches, with no new check.
Alternatives weighed: a trait with a &lt;code&gt;receive&lt;/code&gt; method implemented by a class per actor (the state
would be an object the program sees, which the spec rules out); a constructor hidden from
programs (then the runtime could not be tested before declarations exist, and a program could not
build an actor from a function).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-runtime&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Executor.execute(task)&lt;/code&gt;&lt;/strong&gt; runs a task on
the executor’s workers with no future, as an owner of its own with nothing handed to it, and runs
after &lt;code&gt;shutdown&lt;/code&gt; as a future’s functions do (&lt;a href=&quot;/spec/threads/#executors&quot;&gt;executors&lt;/a&gt;). Why: an
actor’s turns are queued on its executor again and again, and &lt;code&gt;avin.actors&lt;/code&gt; cannot reach the
pool’s module-private queue; the path &lt;code&gt;future&lt;/code&gt; takes hands over by walking everything the task
reaches, which for an actor is its whole state and mailbox at every turn. Alternatives weighed:
putting &lt;code&gt;avin.actors&lt;/code&gt; inside &lt;code&gt;avin.threads&lt;/code&gt; (the spec names the module); walking at each turn
(cost grows with the actor’s state); a compiler-known hook visible only to the library (new
machinery for one call). &lt;strong&gt;Review with the user:&lt;/strong&gt; it adds a public method whose owner rule
(handles the giver owns trap in the task) differs from &lt;code&gt;future&lt;/code&gt;‘s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-runtime&lt;/code&gt;): &lt;strong&gt;Scheduling details&lt;/strong&gt;
(&lt;a href=&quot;/spec/actors/#scheduling&quot;&gt;scheduling&lt;/a&gt;). An actor’s number is one sequence for the whole
program, from one in the order actors are spawned, not one per declaration. &lt;code&gt;spawn&lt;/code&gt; hands the Sysl
handles its behaviour reaches to the actor, as a thread’s &lt;code&gt;spawn&lt;/code&gt; does with its body. The start
runs in the first turn and is not one of the 16 messages; a turn ends early when the mailbox is
empty; an actor on an executor that has been shut down goes on handling what it is told, so
&lt;code&gt;tell&lt;/code&gt; never fails. Why: each is the smallest rule that keeps &lt;code&gt;tell&lt;/code&gt; from waiting or failing and
keeps a handle usable by whoever runs the actor. Alternatives weighed: numbers per declaration
(&lt;code&gt;Counter#1&lt;/code&gt;, &lt;code&gt;Logger#1&lt;/code&gt;; needs a registry of names); dropping messages to an actor whose executor
is shut down (a silent loss the spec does not ask for).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-declarations&lt;/code&gt;): &lt;strong&gt;An &lt;code&gt;actor&lt;/code&gt; declaration is read into
a function and a hidden class&lt;/strong&gt; (&lt;a href=&quot;/spec/actors/#declaring-an-actor&quot;&gt;declaring an actor&lt;/a&gt;).
&lt;code&gt;actor Counter(start: int) receives M&lt;/code&gt; is the function &lt;code&gt;Counter(start: int) -&amp;gt; Behaviour[M]&lt;/code&gt;,
with the parameters’ defaults, and a private class holding the actor’s reference, the parameters
and the body’s fields and methods, whose name (&lt;code&gt;actor Counter&lt;/code&gt;) no program can write. The start
of the behaviour makes one object of that class, which runs the body, and gives back the call of
its &lt;code&gt;receive&lt;/code&gt; match; inside the body &lt;code&gt;self&lt;/code&gt; reads the reference. Why: it lowers onto the library’s
&lt;code&gt;Behaviour&lt;/code&gt; with no runtime support, as the chapter says a declaration is, and the class gives the
body’s methods the implicit receiver and its fields their life across messages for free, while
the object never becomes a value the program sees. Alternatives weighed: the body’s fields as the
start lambda’s locals and its methods as local functions (no implicit receiver, and forward
references between methods break); a runtime-known actor class (machinery the runtime does not
need).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-declarations&lt;/code&gt;): &lt;strong&gt;What an actor’s parameters may be.&lt;/strong&gt;
Each parameter’s type is held to &lt;code&gt;Sendable&lt;/code&gt; where the actor is declared, not where the start
captures it, so the error names the actor and the parameter; one the program marks &lt;code&gt;@sendable&lt;/code&gt;
is exempt, as a marked parameter of a function is sendable inside it whatever its type. A &lt;code&gt;var&lt;/code&gt;
parameter is a field the actor may change, each start beginning again from the argument; a
repeated parameter is allowed; a by-name one is refused. An argument is checked only by its type,
so &lt;code&gt;Worker(s&amp;quot;$label$made&amp;quot;)&lt;/code&gt; computed from an actor’s own &lt;code&gt;var&lt;/code&gt; is accepted. Why: the chapter says
the parameters follow a class’s rules and must be sendable; this is the reading that adds no rule
of its own. Alternatives weighed: marking every parameter &lt;code&gt;@sendable&lt;/code&gt; (then an argument computed
from a &lt;code&gt;var&lt;/code&gt; is refused, since what is passed for a marked parameter is checked by what it reads);
refusing &lt;code&gt;val&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt; parameters (no gain: nothing outside the actor reaches its fields).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-declarations&lt;/code&gt;): &lt;strong&gt;An actor’s diagnostics name the
actor.&lt;/strong&gt; A message type that is not sendable is reported once where it is written after
&lt;code&gt;receives&lt;/code&gt; (&lt;code&gt;`Buffer[int]` does not conform to `Sendable`, so the actor `Buffers` cannot receive it&lt;/code&gt;), not once for the behaviour and once for the reference; a &lt;code&gt;receive&lt;/code&gt; that does not cover the
message type says &lt;code&gt;actor `Partial` does not handle `C`&lt;/code&gt; and how a message is ignored; module-level
state reached from the body, an arm or a method is &lt;code&gt;the actor `Arm` may run on another thread&lt;/code&gt;,
the path naming the actor’s methods by their own names; a method value carrying the state is &lt;code&gt;the state of the actor&lt;/code&gt;. Why: the program wrote an actor, not a behaviour and a lambda. Alternatives
weighed: the generic messages of the &lt;code&gt;@sendable&lt;/code&gt; start (they name a function type the program
never wrote). &lt;strong&gt;Review with the user&lt;/strong&gt;: the hidden class is spelled &lt;code&gt;actor Counter&lt;/code&gt;, with a
space, so it reads well where a diagnostic names it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-lifecycle&lt;/code&gt;): &lt;strong&gt;An actor’s lifecycle is the class &lt;code&gt;ActorContext[M]&lt;/code&gt;
its state extends&lt;/strong&gt; (&lt;a href=&quot;/spec/actors/#lifecycle&quot;&gt;lifecycle&lt;/a&gt;). &lt;code&gt;stop&lt;/code&gt;, &lt;code&gt;watch&lt;/code&gt;, &lt;code&gt;unwatch&lt;/code&gt;, &lt;code&gt;after&lt;/code&gt;,
&lt;code&gt;every&lt;/code&gt;, &lt;code&gt;children&lt;/code&gt;, &lt;code&gt;parent&lt;/code&gt; and &lt;code&gt;onStopping&lt;/code&gt; are methods of &lt;code&gt;avin.actors.ActorContext[M]&lt;/code&gt;, made
from the actor’s reference; the hidden class of an &lt;code&gt;actor&lt;/code&gt; declaration extends it, so the body,
arms and methods call them as their own, and a behaviour written as a library value makes one in
its start, &lt;code&gt;ActorContext(me)&lt;/code&gt;. Each finds its actor through the runtime’s table of running actors
by the owner of the code running, and traps where that is not the actor (made by &lt;code&gt;main&lt;/code&gt;, or
called from a future). A field or method of an actor with the name and parameters of one of these
is refused (&lt;code&gt;`stop` is one of every actor&apos;s own methods&lt;/code&gt;), and the body may call them before
its own fields are initialized, since they reach only the context’s. The same table gives &lt;code&gt;spawn&lt;/code&gt;
the actor whose code is running, its new child’s parent. &lt;em&gt;Why&lt;/em&gt;: the chapter writes &lt;code&gt;stop()&lt;/code&gt; and
&lt;code&gt;after(…)&lt;/code&gt; bare inside an actor, typed by the actor’s message type, and inheritance gives exactly
that with no new lookup rule, while the library form keeps working with no declaration.
&lt;em&gt;Alternatives weighed&lt;/em&gt;: changing a behaviour’s start to take the context instead of the reference
(every library-form behaviour changes, and &lt;code&gt;me&lt;/code&gt; is no longer a reference); free functions finding
the running actor (&lt;code&gt;after&lt;/code&gt; could not be typed by the actor’s messages); names the checker
resolves specially inside actors (a lookup rule of its own, and nothing for the library form).
&lt;strong&gt;Review with the user&lt;/strong&gt;: the public name &lt;code&gt;ActorContext&lt;/code&gt; and &lt;code&gt;onStopping&lt;/code&gt;, and that an actor’s
own names now include &lt;code&gt;children&lt;/code&gt; and &lt;code&gt;parent&lt;/code&gt; (a test’s field &lt;code&gt;children&lt;/code&gt; was renamed).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-lifecycle&lt;/code&gt;): &lt;strong&gt;Stopping, the cases the chapter leaves open.&lt;/strong&gt;
&lt;code&gt;stop(self)&lt;/code&gt; is &lt;code&gt;stop()&lt;/code&gt;; stopping an actor that has ended does nothing, whoever started it (there
is no actor left to protect, and the end may have raced the call); an actor asked to stop before
its first turn still runs its body first, so its &lt;code&gt;stopping&lt;/code&gt; block always has state to run on; an
actor started while its parent is ending is stopped at once and its parent does not wait for it; a
&lt;code&gt;stopping&lt;/code&gt; block is given to the context after the body’s statements, and several &lt;code&gt;onStopping&lt;/code&gt;
functions run in the order given; &lt;code&gt;children()&lt;/code&gt; omits a child once it has ended, before its end is
told to watchers. &lt;em&gt;Why&lt;/em&gt;: each is the reading that never traps on a race and never leaves a parent
waiting for ever. &lt;em&gt;Alternatives weighed&lt;/em&gt;: &lt;code&gt;stop(self)&lt;/code&gt; trapping as “not a child”; stopping an
ended non-child trapping (needs a record of every child that ever ended); a child started from
&lt;code&gt;stopping&lt;/code&gt; made a top-level actor instead.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-lifecycle&lt;/code&gt;): &lt;strong&gt;Watching, the cases the chapter leaves open.&lt;/strong&gt;
Watching an actor again replaces the earlier watch, so its end is told once; an actor watching
itself is told nothing; &lt;code&gt;watch(ref, f)&lt;/code&gt; takes a &lt;code&gt;@sendable&lt;/code&gt; &lt;code&gt;f&lt;/code&gt;, run on the pool where the end is
known, its result queued; &lt;code&gt;unwatch&lt;/code&gt; and the replacing watch drop a message already queued and not
yet handled. &lt;em&gt;Why&lt;/em&gt;: one message per watched end is what a program counting ends needs, and the
dropped message is what makes &lt;code&gt;unwatch&lt;/code&gt; mean something under a race. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a
message per &lt;code&gt;watch&lt;/code&gt; call; running &lt;code&gt;f&lt;/code&gt; in the watcher’s turn (the mailbox would hold functions
rather than messages); watching itself trapping.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-lifecycle&lt;/code&gt;): &lt;strong&gt;Timers.&lt;/strong&gt; One thread, started with the first
timer, keeps every actor’s timers and sleeps until the earliest is due; timers fire in the order
they fall due, those due together in the order they were set; a delay of zero or less is due at
once; a repeating timer is set again an interval after it fires (it does not catch up after a
stall), and an interval of zero or less traps; &lt;code&gt;cancel()&lt;/code&gt; works from any thread, since a &lt;code&gt;Timer&lt;/code&gt;
is sendable, and drops a message of it queued and not yet handled. &lt;code&gt;Timer&lt;/code&gt; has only &lt;code&gt;cancel()&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: a thread per timer would hold a worker per pending timer, and dropping queued messages
makes a cancelled timer’s count exact without timing. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a fixed rate that
catches up; &lt;code&gt;every(zero)&lt;/code&gt; sending as fast as it is handled; an &lt;code&gt;isActive()&lt;/code&gt; query (left out until a
program needs it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-lifecycle&lt;/code&gt;): &lt;strong&gt;An actor’s state is never captured by a &lt;code&gt;@sendable&lt;/code&gt;
function&lt;/strong&gt;, whatever its fields: &lt;code&gt;Future(stop())&lt;/code&gt; in an arm, or a body reading a &lt;code&gt;val&lt;/code&gt; field, is
refused with &lt;code&gt;it uses the state of the actor `Escaper`, which only the actor&apos;s own code reaches; copy what it needs into a `val` first&lt;/code&gt;. Before, only a state with a &lt;code&gt;var&lt;/code&gt; was refused. &lt;em&gt;Why&lt;/em&gt;: the
context’s methods act for the actor that is running, so a state carried to another thread is never
right to use there, and the static refusal says so where the runtime would trap. &lt;em&gt;Alternatives
weighed&lt;/em&gt;: keeping the structural rule and relying on the trap. &lt;strong&gt;Review with the user&lt;/strong&gt;: it
tightens a settled rule.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-lifecycle&lt;/code&gt;): &lt;strong&gt;The expected type bounds a contravariant type
argument of a call’s result only from below&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;). A call
whose result is &lt;code&gt;Sink[T]&lt;/code&gt; for a contravariant &lt;code&gt;T&lt;/code&gt; takes &lt;code&gt;T&lt;/code&gt; from its arguments, and from the
expected type only where they leave it open, so &lt;code&gt;watch(spawn(Worker()), …)&lt;/code&gt; and &lt;code&gt;val r: ActorRef[Nothing] = spawn(Quiet())&lt;/code&gt; check. Before, the expected &lt;code&gt;ActorRef[Nothing]&lt;/code&gt; made &lt;code&gt;M&lt;/code&gt;
&lt;code&gt;Nothing&lt;/code&gt; and the argument was refused. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;Sink[A]&lt;/code&gt; is a &lt;code&gt;Sink[B]&lt;/code&gt; for every &lt;code&gt;B&lt;/code&gt; below &lt;code&gt;A&lt;/code&gt;,
so the expected argument says nothing about &lt;code&gt;T&lt;/code&gt; beyond a lower bound. &lt;em&gt;Alternatives weighed&lt;/em&gt;:
recording a lower bound on the variable (the checker’s unknowns hold one type, not bounds).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-ask&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Ended&lt;/code&gt; means “not delivered”, decided at the send.&lt;/strong&gt; An ask completes with &lt;code&gt;Err(Ended)&lt;/code&gt; exactly
where the asked actor was ending or had ended when the question was sent, so the message was
dropped. A question that was queued and then dropped because the actor ended before handling it
times out. Why: the chapter defines &lt;code&gt;Ended&lt;/code&gt; as “the message could not be delivered”, and an actor
may legitimately forward the reply reference and end, the reply still to come from another actor;
watching the asked actor’s end for every ask would also hold a callback per ask on long-lived
actors. Alternative: complete with &lt;code&gt;Ended&lt;/code&gt; as soon as the asked actor ends before a reply (quicker
failure for a question dropped from a mailbox, wrong for forwarded replies).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-ask&lt;/code&gt;): &lt;strong&gt;An ask’s reply reference&lt;/strong&gt; is an ordinary &lt;code&gt;ActorRef[R]&lt;/code&gt; shown as &lt;code&gt;Reply#n&lt;/code&gt;, numbered from one
apart from the actors (so asks never disturb the actors’ numbering), unequal to every other
reference; its &lt;code&gt;ended()&lt;/code&gt; completes (&lt;code&gt;Stopped&lt;/code&gt;) once the ask has its answer or has timed out, and
an ask &lt;em&gt;of&lt;/em&gt; a used reply reference answers &lt;code&gt;Ended&lt;/code&gt;. Why: it is a one-shot address, so it ends
when it can accept nothing more. Alternatives: no identity of its own (sharing the asker’s, which
&lt;code&gt;main&lt;/code&gt; and threads do not have), or numbering it among the actors.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-ask&lt;/code&gt;): &lt;strong&gt;The timeout is set once the question is delivered&lt;/strong&gt;; a timeout of zero or less times out at
once unless the reply was already there. Alternative: trap on a timeout not more than zero as
&lt;code&gt;every&lt;/code&gt; does on its interval (a zero timeout is a legitimate “only if it is already answered”).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-ask&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;adapter(f)&lt;/code&gt;‘s &lt;code&gt;f&lt;/code&gt; runs where the message is sent&lt;/strong&gt;, so it is &lt;code&gt;@sendable&lt;/code&gt;, and the adapter
refers to the adapting actor: equal to its &lt;code&gt;self&lt;/code&gt;, the same hash and display, the same &lt;code&gt;ended()&lt;/code&gt;;
a message sent to it once the actor has ended is dropped, and an ask of it answers &lt;code&gt;Ended&lt;/code&gt;. Why:
the mailbox holds the actor’s own message type, so translating at the send keeps it so, and the
chapter says a reference compares by the actor it refers to. Alternative: translate in the
actor’s own turn, which would let &lt;code&gt;f&lt;/code&gt; read the actor’s state but needs a mailbox of translations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-ask&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;pipeToSelf&lt;/code&gt; of a future complete already sends at once&lt;/strong&gt;, so its message precedes any the actor
sends itself after the call, and two such pipes arrive in the order they were made; an
incomplete one sends from wherever the future completes, so &lt;code&gt;f&lt;/code&gt; is &lt;code&gt;@sendable&lt;/code&gt;. &lt;code&gt;T&lt;/code&gt; carries no
&lt;code&gt;Sendable&lt;/code&gt; bound, the value never leaving the future’s own handing-over. Alternative: always go
through &lt;code&gt;onComplete&lt;/code&gt;, leaving the order of an already-complete pipe and a later &lt;code&gt;tell&lt;/code&gt; open.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-ask&lt;/code&gt;): &lt;strong&gt;A lambda’s parameter of a known shape with an open type argument&lt;/strong&gt; (&lt;code&gt;Promise[T]&lt;/code&gt;,
&lt;code&gt;ActorRef[R]&lt;/code&gt;) takes that shape, and the body decides the argument, as &lt;code&gt;p -&amp;gt; ReadLine(p)&lt;/code&gt; decides
&lt;code&gt;T&lt;/code&gt; from &lt;code&gt;ReadLine&lt;/code&gt;‘s parameter; a body that leaves it open is reported at the parameter, once.
A wholly unknown parameter type is still an error. Why: inference fails otherwise exactly where
the explicit form succeeds, and &lt;code&gt;ask(r -&amp;gt; Get(r), …)&lt;/code&gt; is the chapter’s idiom. Alternative:
require the type argument at every request-style call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;How a trap is contained.&lt;/strong&gt; The runtime runs an
actor’s start, messages and &lt;code&gt;stopping&lt;/code&gt; blocks under a return point (&lt;code&gt;_setjmp&lt;/code&gt;), and a trap there
restores the shadow stack, caller site and owner it recorded and returns to the turn
(&lt;code&gt;_longjmp&lt;/code&gt;). A count of regions in doubt on each thread (a lock held, which covers &lt;code&gt;Mutex&lt;/code&gt; and
&lt;code&gt;Once&lt;/code&gt;; a &lt;code&gt;lazy val&lt;/code&gt; initializing; an Avin function Sysl called) makes a trap inside one stop the
program instead. &lt;em&gt;Why&lt;/em&gt;: no unwinding tables are needed and the common path costs one &lt;code&gt;_setjmp&lt;/code&gt;
per turn. &lt;em&gt;Alternatives&lt;/em&gt;: unwinding through every frame (needs landing pads in every function),
or running each actor on a thread of its own (defeats many actors on few threads).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Failed&lt;/code&gt;‘s reason is the trap’s reason without its
place&lt;/strong&gt; (&lt;code&gt;Failed(integer overflow)&lt;/code&gt;), the place being in the report. &lt;em&gt;Alternative&lt;/em&gt;: the whole
report line, which ties the value to the file layout.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;Every trap in an actor’s code is reported naming the
actor, also where it stops the program&lt;/strong&gt; (a mutex held, a &lt;code&gt;Once&lt;/code&gt;, a &lt;code&gt;lazy val&lt;/code&gt;, a Sysl call), so
the report says where the bug ran. &lt;em&gt;Alternative&lt;/em&gt;: the plain &lt;code&gt;avin: trap:&lt;/code&gt; line where the program
stops, as a thread’s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;A stack overflow in an actor stops the program&lt;/strong&gt;, as
in a thread, with &lt;code&gt;avin: trap: stack overflow&lt;/code&gt;: the stack may run out inside the runtime or the C
library holding a lock, so nothing can be said about shared state. &lt;em&gt;Alternative&lt;/em&gt;: contain it with
&lt;code&gt;siglongjmp&lt;/code&gt; from the signal handler (unsafe where the fault came from inside a lock).
&lt;strong&gt;Review with the user&lt;/strong&gt;: the chapter lists no exception for it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;An actor that escalates handles nothing more and
waits for its parent’s failure to stop it&lt;/strong&gt; (it ends &lt;code&gt;Failed&lt;/code&gt;), rather than ending at once; a
failure escalated to a parent that is already ending or restarting is dropped, since the parent
is stopping its children anyway. &lt;em&gt;Why&lt;/em&gt;: a failure escalated to the top then stops the program
with no &lt;code&gt;stopping&lt;/code&gt; block run anywhere, deterministically, and the parent’s supervision decides
the whole branch’s fate. &lt;em&gt;Alternative&lt;/em&gt;: the child ends on its own and tells the parent, which
races the program’s stop against the branch’s &lt;code&gt;stopping&lt;/code&gt; blocks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;A restart also cancels the actor’s watches&lt;/strong&gt; (its
timers are cancelled as the chapter says), since the fresh state sets its own; its reference,
number, parent and watchers stay, and a stop asked for before the restart is honoured after it.
A restart is reported as &lt;code&gt;avin: restarting Counter#3&lt;/code&gt;, after the trap’s line. &lt;em&gt;Alternative&lt;/em&gt;:
keep the watches, whose messages the fresh state may not expect.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Restart&lt;/code&gt;‘s window counts restarts made within the
last &lt;code&gt;within&lt;/code&gt;; a limit less than zero or a window not more than zero traps in &lt;code&gt;spawn&lt;/code&gt;&lt;/strong&gt;, as an
&lt;code&gt;every&lt;/code&gt; interval not more than zero does. &lt;em&gt;Alternative&lt;/em&gt;: treat them as zero (a zero window would
silently mean “restart for ever”).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;A trap in a &lt;code&gt;stopping&lt;/code&gt; block ends the actor &lt;code&gt;Failed&lt;/code&gt;&lt;/strong&gt;
with that reason, or keeps the first reason where a trap had failed it already, asks no
supervision (so a block that traps during a restart ends the actor), and runs no later
&lt;code&gt;onStopping&lt;/code&gt; function. &lt;em&gt;Alternative&lt;/em&gt;: end it &lt;code&gt;Stopped&lt;/code&gt; where it was stopping (hides the bug from
its watchers).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;pipeToSelf&lt;/code&gt; function and a watch’s function run in
the receiving actor’s own turn&lt;/strong&gt;, when it takes the message, rather than wherever the future or
the end completed, so a trap in one fails the actor that asked for it and never an unrelated
thread or the actor watched. The message of a pipe of a future complete already is still made
at once, in the actor’s code. This revises the earlier pipe decision’s “sends from wherever the
future completes”. An adapter’s function still runs at the send (its trap is the sender’s), as
settled. &lt;em&gt;Alternative&lt;/em&gt;: leave them where the value is known, where a trap stops the program from
a pool worker or fails the watched actor in the middle of ending. &lt;strong&gt;Review with the user&lt;/strong&gt;: the
adapter and the pipe now differ in where their function runs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-failure&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;spawn&lt;/code&gt;‘s parameters are &lt;code&gt;(behaviour, onFailure, executor)&lt;/code&gt;&lt;/strong&gt;, as the chapter writes them, so an executor alone is given by name
(&lt;code&gt;executor = ex&lt;/code&gt;). &lt;em&gt;Alternative&lt;/em&gt;: keep the executor second.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;C bindings&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-05: &lt;strong&gt;public C interoperability is no longer deferred.&lt;/strong&gt; The user’s
words, on how to build the MLT library: &lt;em&gt;“Doing it as a c binding would force c interoperability
and would provide a good stressor for it. The sysl MLT binding isn’t being used.”&lt;/em&gt; So Avin binds C
libraries itself (&lt;a href=&quot;/spec/c-bindings/&quot;&gt;C bindings&lt;/a&gt;), and &lt;code&gt;avin-lang/mlt&lt;/code&gt;, MLT 7 bound over them,
is the stressor that drives the work (roadmap stage 13). Until it is built, C is reached through
Sysl as before.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled 2026-11-05 on the user’s question &lt;em&gt;“Why should C interop go through Sysl since avin
generates LLVM IR?”&lt;/em&gt;: &lt;strong&gt;a C binding is a direct call&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/#how-a-c-binding-is-compiled&quot;&gt;how a C binding is
compiled&lt;/a&gt;). The emitter declares the C symbol in
the LLVM IR and Avin’s own code calls it; clang links the library with the flags &lt;code&gt;pkg-config&lt;/code&gt;
answers. What the Sysl shim does for a Sysl binding — converting arguments and results, the
&lt;code&gt;enter_safe&lt;/code&gt;/&lt;code&gt;leave_safe&lt;/code&gt; bracket of a &lt;code&gt;blocking&lt;/code&gt; call, keeping a handle’s reference, callback
trampolines and attaching a C-owned thread — is done by Avin’s lowering and the runtime. &lt;em&gt;Why&lt;/em&gt;:
the shim exists so that Sysl checks a binding against a Sysl signature, and a C binding has none,
so a shim would add a compile step, a cache and a Sysl dependency and check nothing. &lt;em&gt;Alternative
weighed&lt;/em&gt;: lowering each C binding into the Sysl shim as an &lt;code&gt;extern&lt;/code&gt; (the director’s first
recommendation), which would have had Sysl’s ABI lowering of aggregates for free but no check
against C’s header, since Sysl does not read headers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;c-interop-design&lt;/code&gt;): &lt;strong&gt;C bindings&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/&quot;&gt;chapter&lt;/a&gt;).
Each is the recommendation the chapter is written to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The binding copies the C prototype as a string&lt;/strong&gt;, &lt;code&gt;@c(&amp;quot;char *mlt_properties_get(mlt_properties self, const char *name)&amp;quot;)&lt;/code&gt;, beside an Avin signature in Avin types, matched by position. &lt;em&gt;Why&lt;/em&gt;:
C’s &lt;code&gt;unsigned&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt; and typedefs cannot be said in Avin types, the prototype is what a
reader compares with the header, and clang can check it exactly. Three marker words (&lt;code&gt;out&lt;/code&gt;,
&lt;code&gt;inout&lt;/code&gt;, &lt;code&gt;userdata&lt;/code&gt;) and &lt;code&gt;length(p)&lt;/code&gt; say what C’s types do not. &lt;em&gt;Alternatives&lt;/em&gt;: a vocabulary of C
types in Avin (&lt;code&gt;CInt&lt;/code&gt;, &lt;code&gt;CSize&lt;/code&gt;, …), a second type system in safe code; C types implied by the
Avin types, which cannot spell a &lt;code&gt;uint32_t&lt;/code&gt; or a typedef.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every binding is checked against its header, by clang, in a generated C unit&lt;/strong&gt;: a
&lt;code&gt;_Static_assert&lt;/code&gt; of &lt;code&gt;__builtin_types_compatible_p&lt;/code&gt; per binding, the kind of each typedef, every
mirror’s layout; the unit also measures typedef widths, enumerators and constants as object-file
data read without running it (cross builds measure the target). A package with bindings and no
&lt;code&gt;headers&lt;/code&gt; is refused. &lt;em&gt;Why&lt;/em&gt;: it is the one check on the trusted surface that can be automatic.
&lt;em&gt;Alternatives&lt;/em&gt;: trusting the declaration as a Sysl &lt;code&gt;extern&lt;/code&gt; does; parsing headers in the
compiler (the Sysl project refused that too).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C libraries are named in the manifest&lt;/strong&gt;, &lt;code&gt;c-libraries { mlt { pkg-config, headers, install } }&lt;/code&gt;
(or &lt;code&gt;link = [...]&lt;/code&gt;), and every program links the C libraries of all its packages. &lt;em&gt;Why&lt;/em&gt;: it is
the shape of &lt;code&gt;sysl-dependencies&lt;/code&gt;, and a library’s requirement travels with it. &lt;em&gt;Alternative&lt;/em&gt;: a
module-header &lt;code&gt;@link&lt;/code&gt;, as Sysl writes it, which cannot carry headers or the install message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Struct by value goes through clang-compiled glue&lt;/strong&gt;, which takes and answers the struct by
pointer; scalars, pointers and structs by pointer are called directly. &lt;em&gt;Why&lt;/em&gt;: clang’s ABI
classification is right on every target at once, and the C unit already exists. &lt;em&gt;Alternatives&lt;/em&gt;:
implementing AAPCS64 (Darwin first) and then System V x86-64 classification in lowering, a
per-target body of code whose bugs corrupt arguments silently; refusing by-value structs, which
MLT’s &lt;code&gt;mlt_color&lt;/code&gt; and &lt;code&gt;mlt_event_data&lt;/code&gt; need. &lt;strong&gt;Review with the user&lt;/strong&gt; if the extra call is ever
measured to matter.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handles own one C reference&lt;/strong&gt;: a pointer answered is owned unless the binding says
&lt;code&gt;borrowed&lt;/code&gt;, which needs a &lt;code&gt;retain&lt;/code&gt;; &lt;code&gt;release&lt;/code&gt;/&lt;code&gt;retain&lt;/code&gt; are a C function or a C expression in
&lt;code&gt;self&lt;/code&gt;; &lt;code&gt;as:&lt;/code&gt; lists the other C types a handle passes as (C’s first-member inheritance), each by
a C conversion that lends; &lt;code&gt;keeps:&lt;/code&gt; makes the holder keep an Avin object (MLT’s profile),
&lt;code&gt;consumes:&lt;/code&gt; closes a handle the call takes. &lt;em&gt;Why&lt;/em&gt;: the sysl MLT binding found exactly these
shapes, and every one is written once per class or binding. &lt;em&gt;Alternative&lt;/em&gt;: one Avin handle class
per C type with explicit upcast bindings, many more declarations for the same check.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C handles keep the single-owner check&lt;/strong&gt;; &lt;code&gt;shared&lt;/code&gt; exempts a thread-safe C object and makes it
sendable. &lt;em&gt;Why&lt;/em&gt;: most C objects are not thread-safe. &lt;em&gt;Alternative&lt;/em&gt;: no check for C handles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strings&lt;/strong&gt;: &lt;code&gt;const char *&lt;/code&gt; from a &lt;code&gt;string&lt;/code&gt; copied with a NUL, a held NUL trapping; a &lt;code&gt;char *&lt;/code&gt;
result copied and UTF-8-checked (trapping), &lt;code&gt;Array[byte]&lt;/code&gt; for unchecked bytes, borrowed unless
&lt;code&gt;free:&lt;/code&gt; names the freeing function. &lt;em&gt;Alternatives&lt;/em&gt;: truncating at a NUL, replacing invalid UTF-8
with U+FFFD (what standard input does), a &lt;code&gt;Result&lt;/code&gt; per string result.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Null is &lt;code&gt;Option&lt;/code&gt;; a null bound as the type itself traps.&lt;/strong&gt; A C integer bound as
&lt;code&gt;Result[unit, int]&lt;/code&gt; is &lt;code&gt;Ok&lt;/code&gt; on zero. &lt;em&gt;Alternative&lt;/em&gt;: a &lt;code&gt;Result&lt;/code&gt; for null pointers, which would need
an error the C call never gave.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Out parameters join the result&lt;/strong&gt;, as a tuple after the C result or in a status’s &lt;code&gt;Ok&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;:
Avin has no pointers to pass. &lt;em&gt;Alternative&lt;/em&gt;: filled one-element arrays, which work today but read
badly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Buffers are copied (&lt;code&gt;bytes:&lt;/code&gt;) or borrowed as an &lt;code&gt;avin.c.ByteView&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;view:&lt;/code&gt;), a read-only,
bounds-checked handle holding its owner, &lt;strong&gt;closed when its owner is next used&lt;/strong&gt;. &lt;em&gt;Why&lt;/em&gt;: MLT may
replace a frame’s image on the next call, so validity is “until the owner changes”, and the owner
check catches every use after that. &lt;em&gt;Alternatives&lt;/em&gt;: views valid only inside a block
(&lt;code&gt;frame.withImage { … }&lt;/code&gt;), which forbids keeping one at all; copy only, which costs a copy per
frame. Writable views are proposed below, from the Cairo survey.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Callbacks&lt;/strong&gt;: one C-convention trampoline per function type, the closure found through the
&lt;code&gt;userdata&lt;/code&gt;, the runtime’s Sysl-callback record and &lt;code&gt;callback_enter&lt;/code&gt; reused; &lt;code&gt;keeps:&lt;/code&gt; holds a
registered callback on its handle, whose &lt;code&gt;forget:&lt;/code&gt; unregisters each before &lt;code&gt;release&lt;/code&gt;; a
keeping class without &lt;code&gt;forget&lt;/code&gt; is refused; &lt;code&gt;@threaded&lt;/code&gt; as for Sysl, a C thread attached per call.
&lt;em&gt;Alternative&lt;/em&gt;: a registration object returned to the caller, which the user must keep alive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Varargs are refused.&lt;/strong&gt; A package needing one may carry C. &lt;em&gt;Why&lt;/em&gt;: an argument’s type cannot be
checked against &lt;code&gt;...&lt;/code&gt;, and a format string from Avin is a hole. &lt;em&gt;Alternatives&lt;/em&gt;: allowing calls
whose extra arguments the prototype fixes. Whether an Avin package may carry C sources of its
own, compiled into the C unit, is itself proposed: it is the trusted escape hatch for macros with
arguments and odd shapes, and it widens the trusted surface beyond &lt;code&gt;@c(&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No pointer type and no &lt;code&gt;unsafe&lt;/code&gt; block in Avin; the &lt;code&gt;@c&lt;/code&gt; declarations (and the glue they
generate) are the whole trusted surface.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: soundness in safe code, and one grep finds
everything to review. &lt;em&gt;Alternative&lt;/em&gt;: an &lt;code&gt;unsafe&lt;/code&gt; region with a raw pointer type, which would let
a binding’s pleasant layer be written in Avin but makes every Avin file a possible hole.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;errno&lt;/code&gt;&lt;/strong&gt; was not read by a binding at first; an &lt;code&gt;errno&lt;/code&gt; flag answering &lt;code&gt;Result[T, int]&lt;/code&gt; from a
&lt;code&gt;-1&lt;/code&gt; result was the likely form, and is what was built, with &lt;code&gt;Errno&lt;/code&gt; besides (settled 2026-11-15,
branch &lt;code&gt;c-opaque-errno&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: the prototype-string form of &lt;code&gt;@c&lt;/code&gt;, the largest syntax choice here; whether a
package may carry C sources, which widens the trusted surface beyond the &lt;code&gt;@c&lt;/code&gt; lines; the two
parser additions (&lt;code&gt;val&lt;/code&gt; with no initializer for &lt;code&gt;@c(const:)&lt;/code&gt;, list-valued annotation
arguments); and a missing &lt;code&gt;@threaded&lt;/code&gt; on a callback C calls from its own thread being caught
only by a trap at run time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;c-bindings-scalars&lt;/code&gt;): &lt;strong&gt;C bindings of scalars&lt;/strong&gt; (stage 13 step 1), the choices
building it made where the chapter is silent.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A typedef’s kind is decided by the Avin type and checked by the C unit&lt;/strong&gt; with
&lt;code&gt;__builtin_classify_type&lt;/code&gt;: an integer type for an integer, an integer one byte wide (of either
sign, as a C &lt;code&gt;char&lt;/code&gt; is) for &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; for &lt;code&gt;bool&lt;/code&gt;, a floating-point type for &lt;code&gt;real&lt;/code&gt;, its
width measured to choose &lt;code&gt;float&lt;/code&gt; or &lt;code&gt;double&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the checker cannot see the header, and the
Avin type says what the binding means. &lt;em&gt;Alternatives&lt;/em&gt;: a kind written in the prototype; measuring
every typedef’s kind and refusing in the driver, which needs an expression valid for any type
and C has none.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;unsigned char&lt;/code&gt; crosses as &lt;code&gt;byte&lt;/code&gt; or as an integer type, &lt;code&gt;char&lt;/code&gt; (and a &lt;code&gt;char&lt;/code&gt; typedef) only
as &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;signed char&lt;/code&gt; only as an integer type.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: the table lists &lt;code&gt;unsigned char&lt;/code&gt; in
both rows and &lt;code&gt;char&lt;/code&gt; only as a byte. &lt;em&gt;Alternative&lt;/em&gt;: &lt;code&gt;char&lt;/code&gt; as an integer at its measured sign,
which makes a program’s meaning depend on the machine.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An argument’s trap names the C type, &lt;code&gt;value out of range for u64 (size_t)&lt;/code&gt;; a result’s names
the Avin type, &lt;code&gt;value out of range for long&lt;/code&gt;&lt;/strong&gt;, as a Sysl binding’s do. &lt;em&gt;Alternative&lt;/em&gt;: naming
both types in both directions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A result the binding declares &lt;code&gt;unit&lt;/code&gt; is declared &lt;code&gt;void&lt;/code&gt; in the IR&lt;/strong&gt;, so a discarded pointer or
integer needs no measurement; a struct result is refused even then, since it may be returned
through memory. &lt;em&gt;Alternative&lt;/em&gt;: declaring the measured type and ignoring the value.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The measurements are found by a marker in the object’s bytes&lt;/strong&gt;, one table of two bytes per
type (width, sign), rather than by its symbol, so no object format (Mach-O, ELF, COFF) is parsed.
&lt;em&gt;Alternative&lt;/em&gt;: reading the symbol table, a reader per format.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The mismatch diagnostic takes its two types from a pointer of the prototype’s type set to
the header’s function&lt;/strong&gt;, whose clang diagnostic keeps the typedefs’ names, and the header from
the note of a redeclaration as the prototype says it; the &lt;code&gt;_Static_assert&lt;/code&gt; stays the check, so a
clang that only warns on the pointer still refuses the binding. &lt;em&gt;Alternative&lt;/em&gt;: the assertion’s
own text, which clang writes with every typedef expanded.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The toolchain names the &lt;code&gt;pkg-config&lt;/code&gt; it asks&lt;/strong&gt; (&lt;code&gt;Toolchain.pkg_config&lt;/code&gt;), so a build for
another machine can ask that machine’s, and the corpus asks one that also finds the C fixture in
&lt;code&gt;tests/c&lt;/code&gt;, which it builds. &lt;em&gt;Alternatives&lt;/em&gt;: the environment’s &lt;code&gt;PKG_CONFIG_PATH&lt;/code&gt;, which a test
cannot set for the compiler it runs in its own process; a package-relative &lt;code&gt;.pc&lt;/code&gt; path in the
manifest, which the chapter does not have. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;avin&lt;/code&gt; should read
&lt;code&gt;PKG_CONFIG&lt;/code&gt; as autotools does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A function a header declares &lt;code&gt;static inline&lt;/code&gt; is not caught by the header check&lt;/strong&gt;: C lets the
unit’s redeclaration inherit the internal linkage, so the binding fails at the link, where the
linker names the missing symbol. &lt;em&gt;Alternative&lt;/em&gt;: reading the C unit’s symbol table for a local
definition, a reader per object format.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;cairo-survey&lt;/code&gt;): &lt;strong&gt;C bindings, from the Cairo survey&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/&quot;&gt;chapter&lt;/a&gt;). The user asked for &lt;code&gt;avin-lang/cairo&lt;/code&gt;, Cairo 1.18 bound over the C bindings beside
&lt;code&gt;avin-lang/mlt&lt;/code&gt;, ported from the reference binding’s surface. Mapping it onto the chapter found these
lacks; each is the smallest addition that covers it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An integer bound as &lt;code&gt;bool&lt;/code&gt;&lt;/strong&gt; is &lt;code&gt;false&lt;/code&gt; for zero, &lt;code&gt;true&lt;/code&gt; otherwise; a &lt;code&gt;bool&lt;/code&gt; passes &lt;code&gt;0&lt;/code&gt;/&lt;code&gt;1&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;cairo_bool_t&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt;, and so is every pre-C99 library’s truth value. &lt;em&gt;Alternatives&lt;/em&gt;:
binding it as &lt;code&gt;int&lt;/code&gt; and comparing in Avin at every call site; a &lt;code&gt;truth&lt;/code&gt; marker word in the
prototype, which says what the Avin type already does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A status that is a C enum binds as &lt;code&gt;Result[unit, E]&lt;/code&gt;&lt;/strong&gt; with &lt;code&gt;E&lt;/code&gt; its mirror: &lt;code&gt;Ok&lt;/code&gt; for the zero
enumerator, &lt;code&gt;Err(variant)&lt;/code&gt; otherwise; the mirror keeps its zero variant, which a callback answers.
&lt;em&gt;Why&lt;/em&gt;: Cairo’s &lt;code&gt;cairo_status_t&lt;/code&gt; is the error type itself, and mapping an &lt;code&gt;int&lt;/code&gt; back to it by hand
repeats the enum. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;Result[unit, int]&lt;/code&gt; and a mapping function; requiring the mirror
to omit its zero variant, which a callback answering &lt;code&gt;Success&lt;/code&gt; could not then name.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Latched errors need nothing new&lt;/strong&gt;: the status query is an ordinary binding, and the library
asks it after constructors, before output (&lt;code&gt;writePng&lt;/code&gt;, &lt;code&gt;finish&lt;/code&gt;, the PNG stream) and on request,
answering &lt;code&gt;Result[_, CairoError]&lt;/code&gt; there and &lt;code&gt;unit&lt;/code&gt; from the drawing calls. &lt;em&gt;Why&lt;/em&gt;: Cairo latches
errors on the object and makes every later call a no-op, so the next query sees every failure.
&lt;em&gt;Alternatives&lt;/em&gt;: a per-class &lt;code&gt;status:&lt;/code&gt; expression the compiler checks after every call, trapping
or answering &lt;code&gt;Result&lt;/code&gt; from all ~150 drawing calls, which costs a call each and makes every line of
drawing code carry a &lt;code&gt;?&lt;/code&gt;; trapping on any latched error, which turns a bad PNG file into a crash.
&lt;strong&gt;Review with the user&lt;/strong&gt;: whether drawing calls should trap on a latched error in a debug build.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;attach:&lt;/code&gt; ties what a handle keeps to the C object’s lifetime&lt;/strong&gt;, through the library’s
destroy notification (&lt;code&gt;cairo_surface_set_user_data&lt;/code&gt;, &lt;code&gt;mlt_properties_set_data&lt;/code&gt;): the kept
objects move to a pinned runtime record that C’s &lt;code&gt;destroy&lt;/code&gt; releases; &lt;code&gt;key:&lt;/code&gt; names the static key
type the C unit defines per class. &lt;em&gt;Why&lt;/em&gt;: Cairo contexts and surface patterns reference their
surface, so the Avin &lt;code&gt;Surface&lt;/code&gt; can be collected while C still draws into the &lt;code&gt;ByteBlock&lt;/code&gt; (or font
file) it was made over — a use after free that &lt;code&gt;keeps:&lt;/code&gt; on the handle does not prevent. The same
gap reaches MLT wherever a C object that keeps a pointer (a producer keeping its profile) is held
by another C object (a playlist) after its Avin handle is collected. &lt;em&gt;Alternatives&lt;/em&gt;: keeping the
kept objects for the rest of the program, a leak per surface; refusing &lt;code&gt;keeps:&lt;/code&gt; on handles C can
reference, which refuses &lt;code&gt;create_for_data&lt;/code&gt;; making the library hold every surface in an Avin
table. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether the MLT &lt;code&gt;keeps:&lt;/code&gt; bindings should move to &lt;code&gt;attach:&lt;/code&gt; too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Field accessors take expressions and bounded indices&lt;/strong&gt;: &lt;code&gt;field:&lt;/code&gt; a C lvalue in &lt;code&gt;self&lt;/code&gt; and the
accessor’s parameters, &lt;code&gt;bound:&lt;/code&gt; the C expression an index is checked below; an index with no bound
is refused. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;cairo_path_t&lt;/code&gt; is a C-owned array of a union, which no mirror may hold, and
reading it element by element through glue keeps the union out of Avin. &lt;em&gt;Alternatives&lt;/em&gt;: an
opaque value per element, which needs by-value glue for every read; a package-carried C file
flattening the path into doubles, the trusted escape hatch proposed above, wider than one line.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Option&lt;/code&gt; of a mirror for a nullable &lt;code&gt;const T *&lt;/code&gt;.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;cairo_recording_surface_create&lt;/code&gt;
takes null for unbounded extents. &lt;em&gt;Alternative&lt;/em&gt;: two bindings, one passing a sentinel struct.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Upper-case enumerators match an upper-case prefix&lt;/strong&gt; (&lt;code&gt;CAIRO_FORMAT_&lt;/code&gt; → &lt;code&gt;Argb32&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;:
most C libraries write enumerators in upper case. &lt;em&gt;Alternative&lt;/em&gt;: &lt;code&gt;@c(&amp;quot;name&amp;quot;)&lt;/code&gt; on every variant.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;String and &lt;code&gt;real&lt;/code&gt; constants&lt;/strong&gt;: &lt;code&gt;@c(const:)&lt;/code&gt; reads a string literal’s bytes as a measurement,
checked as UTF-8. &lt;em&gt;Why&lt;/em&gt;: Cairo’s tag names (&lt;code&gt;CAIRO_TAG_DEST&lt;/code&gt;) are string macros. &lt;em&gt;Alternative&lt;/em&gt;:
copying the literals into Avin, which drifts if the header changes them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arrays of mirrors&lt;/strong&gt; go to &lt;code&gt;const T *&lt;/code&gt; converted into C memory for the call; &lt;strong&gt;arrays C
allocates&lt;/strong&gt; are copied out with &lt;code&gt;array:&lt;/code&gt;, &lt;code&gt;length:&lt;/code&gt; and &lt;code&gt;free:&lt;/code&gt; (generalizing &lt;code&gt;bytes:&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;:
Cairo’s glyph arrays, in (&lt;code&gt;cairo_show_glyphs&lt;/code&gt;) and out (&lt;code&gt;cairo_scaled_font_text_to_glyphs&lt;/code&gt;).
&lt;em&gt;Alternatives&lt;/em&gt;: a handle on &lt;code&gt;cairo_glyph_allocate&lt;/code&gt;‘s array with indexed writers, a C-shaped API
in Avin code; writing a converted array back for non-&lt;code&gt;const&lt;/code&gt; pointers, which no Cairo call needs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;view&lt;/code&gt; on the result, and writable views&lt;/strong&gt;: a bare &lt;code&gt;view&lt;/code&gt; names the C result as the memory;
&lt;code&gt;writable&lt;/code&gt; answers an &lt;code&gt;avin.c.MutByteView&lt;/code&gt; (a &lt;code&gt;ByteView&lt;/code&gt; with &lt;code&gt;update&lt;/code&gt;, &lt;code&gt;fill&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;),
closed by the owner’s next use like any view. &lt;em&gt;Why&lt;/em&gt;: Cairo’s pixel access is
&lt;code&gt;cairo_image_surface_get_data&lt;/code&gt;‘s result, and the reference program writes pixels and calls
&lt;code&gt;mark_dirty&lt;/code&gt;, which, being a use, closes the view so a write after it traps. &lt;em&gt;Alternatives&lt;/em&gt;:
copy out, edit, copy back with &lt;code&gt;create_for_data&lt;/code&gt; (a full copy per edit); a block-scoped
&lt;code&gt;withPixels { … }&lt;/code&gt;, which the chapter already weighed against for reading; one &lt;code&gt;ByteView&lt;/code&gt; type
with a run-time writable flag, which moves a type error to run time. A &lt;code&gt;stable&lt;/code&gt; marker for
owner methods that do not close views (Cairo’s &lt;code&gt;get_width&lt;/code&gt; after &lt;code&gt;get_data&lt;/code&gt;) was weighed and left
out: the library reads those first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin.c.ByteBlock&lt;/code&gt;, memory Avin gives C&lt;/strong&gt;: fixed-length, zeroed, outside the collected heap,
never copied at a call, read and written like a &lt;code&gt;MutByteView&lt;/code&gt;, freed when collected, kept by C
through &lt;code&gt;keeps:&lt;/code&gt; (and &lt;code&gt;attach:&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;cairo_image_surface_create_for_data&lt;/code&gt; keeps the pointer
and writes into it for the surface’s life, which neither a copied array nor a heap array (moved
out of the heap for &lt;code&gt;blocking&lt;/code&gt; calls) can be. &lt;em&gt;Alternatives&lt;/em&gt;: pinning an &lt;code&gt;Array[byte]&lt;/code&gt; in the
collector, which pins the collector’s design to non-moving arrays; leaving &lt;code&gt;create_for_data&lt;/code&gt;
unbound (the reference program uses it).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory lent to a callback is a view&lt;/strong&gt; closed when it returns, &lt;code&gt;const&lt;/code&gt; a &lt;code&gt;ByteView&lt;/code&gt;, otherwise a
&lt;code&gt;MutByteView&lt;/code&gt;, its length from a &lt;code&gt;length(p)&lt;/code&gt; beside it; a function-pointer typedef is written out
in the prototype. &lt;em&gt;Why&lt;/em&gt;: Cairo’s PNG write and read streams pass &lt;code&gt;(closure, data, length)&lt;/code&gt;.
&lt;em&gt;Alternatives&lt;/em&gt;: a copied &lt;code&gt;Array[byte]&lt;/code&gt; per chunk (fine for writing, impossible for reading, where
the callback must fill C’s buffer).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Steps 8 and 9 of stage 13 swap&lt;/strong&gt;: buffers before callbacks, so callbacks can take views.
&lt;em&gt;Why&lt;/em&gt;: the PNG stream needs both, and neither MLT step needs the other. &lt;em&gt;Alternative&lt;/em&gt;: callbacks
first with copied arrays, the read stream deferred.&lt;/li&gt;
&lt;li&gt;The survey’s three questions, settled with it. &lt;strong&gt;&lt;code&gt;attach:&lt;/code&gt; for MLT&lt;/strong&gt;: only where C keeps
something Avin owns that C’s own reference count does not cover (memory Avin gives C, a callback’s
closure); MLT’s playlists, tractors and services take their own reference to what they are given,
so a counted handle needs nothing more, and the MLT steps are audited for the other cases.
&lt;strong&gt;Review with the user.&lt;/strong&gt; &lt;strong&gt;No trap on a latched error in debug builds&lt;/strong&gt;: a program behaves the
same at every optimization level; the binding checks the status after constructors and before
output, as the chapter says. &lt;strong&gt;A FreeType binding&lt;/strong&gt; (&lt;code&gt;avin-lang/freetype&lt;/code&gt;) waits until Cairo’s
font-face step needs it; the toy font API and the platform’s own font backend come first.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;freetype-design&lt;/code&gt;): &lt;strong&gt;C bindings, from the FreeType survey&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/&quot;&gt;chapter&lt;/a&gt;). The user: &lt;em&gt;“Yes we’ll need a freetype binding to work with cairo.”&lt;/em&gt;
The user (2026-11-05): &lt;em&gt;“Yes we’ll need a freetype binding to work with cairo.”&lt;/em&gt; A third stressor,
&lt;code&gt;avin-lang/freetype&lt;/code&gt;, binds FreeType 2 (&lt;code&gt;pkg-config freetype2&lt;/code&gt;) to the reference binding’s surface,
and &lt;code&gt;avin-lang/cairo&lt;/code&gt; depends on it for Cairo’s FreeType font faces (&lt;code&gt;cairo-ft.h&lt;/code&gt;). This replaces
the Cairo survey’s “a FreeType binding waits until Cairo’s font-face step needs it”. Mapping the
reference surface onto the chapter found these lacks; each is the smallest addition that covers it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A binding may name a handle class of another package&lt;/strong&gt; its package depends on: the prototype
names the class’s own C type or an &lt;code&gt;as:&lt;/code&gt; type; the class’s glue is the declaring package’s,
compiled once; the package’s bindings are checked after the &lt;code&gt;headers&lt;/code&gt;, and with the &lt;code&gt;pkg-config&lt;/code&gt;
flags, of every package whose handle classes they name, in dependency order; ownership (lent,
&lt;code&gt;keeps:&lt;/code&gt;, &lt;code&gt;consumes:&lt;/code&gt;, &lt;code&gt;attach:&lt;/code&gt;, owned and &lt;code&gt;borrowed&lt;/code&gt; results) crosses unchanged. &lt;em&gt;Why&lt;/em&gt;:
&lt;code&gt;cairo_ft_font_face_create_for_ft_face&lt;/code&gt; takes FreeType’s &lt;code&gt;FT_Face&lt;/code&gt;, and a header of one library
need not include the other’s (Cairo’s happens to; most do not). &lt;em&gt;Alternatives&lt;/em&gt;: a third package
holding only the shared handle class, which the reference binding needs only to break a
dependency cycle Avin does not have; Cairo declaring its own &lt;code&gt;FT_Face&lt;/code&gt; handle, two handles with
two owners and two &lt;code&gt;release&lt;/code&gt;s on one C object, a double free; trusting each library’s header to
include the other’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A header may be named by a macro&lt;/strong&gt;: an entry of &lt;code&gt;headers&lt;/code&gt; that is a C identifier is emitted
as &lt;code&gt;#include NAME&lt;/code&gt;, defined by an earlier entry, and a macro no earlier header defines is
reported at the entry. &lt;em&gt;Why&lt;/em&gt;: FreeType documents its headers by macro (&lt;code&gt;#include &amp;lt;ft2build.h&amp;gt;&lt;/code&gt;
then &lt;code&gt;#include FT_FREETYPE_H&lt;/code&gt;), and Cairo’s own &lt;code&gt;cairo-ft.h&lt;/code&gt; includes it so. &lt;em&gt;Alternatives&lt;/em&gt;:
naming the path the macro expands to (&lt;code&gt;&amp;lt;freetype/freetype.h&amp;gt;&lt;/code&gt;), which the installed FreeType’s
own &lt;code&gt;ft2build.h&lt;/code&gt; shows and which needs nothing new, but writes into the manifest a layout that
FreeType’s macros exist to keep its users out of; a &lt;code&gt;prelude&lt;/code&gt; string of raw C lines in the manifest, wider than
one rule and the start of a C file in HOCON.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A kept handle whose class declares &lt;code&gt;retain&lt;/code&gt; is held by a C reference&lt;/strong&gt;, taken through that
&lt;code&gt;retain&lt;/code&gt; when the call succeeds and given back through its &lt;code&gt;release&lt;/code&gt; after the holder’s own
&lt;code&gt;release&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the collector finalizes the unreachable in address order, so a &lt;code&gt;Face&lt;/code&gt; and the
&lt;code&gt;Library&lt;/code&gt; it keeps, dead in one collection, may be finalized library first; freeing the library
frees every face still in it, and the face’s &lt;code&gt;FT_Done_Face&lt;/code&gt; then frees one twice. With the
reference, the library’s &lt;code&gt;release&lt;/code&gt;, &lt;code&gt;FT_Done_Library&lt;/code&gt;, only drops a count (&lt;code&gt;FT_Done_FreeType&lt;/code&gt;
also frees the memory manager whatever the count, so it is no &lt;code&gt;release&lt;/code&gt;). MLT’s &lt;code&gt;Consumer&lt;/code&gt; keeping its &lt;code&gt;Playlist&lt;/code&gt;
(&lt;code&gt;keeps: &amp;quot;source&amp;quot;&lt;/code&gt;) gains the same order. &lt;em&gt;Alternatives&lt;/em&gt;: ordered finalization in the collector
(kept before keeper), which Avin cannot change and which the collector’s address-order sweep
does not offer; holding the Avin object and taking the order on trust, a use after free whenever
a &lt;code&gt;release&lt;/code&gt; touches what it keeps; making the library’s &lt;code&gt;release&lt;/code&gt; a no-op while faces exist, a
count in Avin of what C already counts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;kept: &amp;quot;name: Class&amp;quot;&lt;/code&gt; lets a holder’s &lt;code&gt;release:&lt;/code&gt;/&lt;code&gt;retain:&lt;/code&gt; name what it keeps&lt;/strong&gt;, as that
handle’s C pointer; the class is made only by bindings keeping exactly one handle of that class,
and an unused name is refused. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;FT_Done_MM_Var(library, master)&lt;/code&gt; frees the variation
descriptor through a library the descriptor does not record; the face it came from publishes it
(&lt;code&gt;face-&amp;gt;glyph-&amp;gt;library&lt;/code&gt;), and the C reference above keeps that face valid until after the
&lt;code&gt;release&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: walking the descriptor into Avin data and freeing it inside one
binding, which needs a binding that copies a C struct holding arrays of structs (a larger
addition); a &lt;code&gt;release&lt;/code&gt; taking a second argument from a per-handle C field the runtime stores,
the same thing with a less readable spelling; leaving the variation API unbound.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;keeps:&lt;/code&gt; takes a list&lt;/strong&gt; (&lt;code&gt;keeps: [&amp;quot;library&amp;quot;, &amp;quot;base&amp;quot;]&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;FT_New_Memory_Face&lt;/code&gt; keeps its
library and its memory. &lt;em&gt;Alternative&lt;/em&gt;: repeating the key, which HOCON merges rather than lists.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;keeps:&lt;/code&gt; naming an array parameter is refused&lt;/strong&gt;, since its C copy lives for the call; memory C
keeps is a &lt;code&gt;ByteBlock&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;FT_New_Memory_Face&lt;/code&gt; reads its buffer lazily for the face’s
life. &lt;em&gt;Alternative&lt;/em&gt;: pinning the array, which the &lt;code&gt;ByteBlock&lt;/code&gt; decision already weighed against.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;length(p)&lt;/code&gt; may mark an &lt;code&gt;inout&lt;/code&gt; pointer to an integer&lt;/strong&gt;: the array’s length is written in, C’s
answer is part of the result, checked to be no more than the length; &lt;code&gt;None&lt;/code&gt; for an &lt;code&gt;Option&lt;/code&gt; of
the array passes null and zero. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;FT_Load_Sfnt_Table&lt;/code&gt; takes &lt;code&gt;FT_ULong *length&lt;/code&gt;, and is
called once with no buffer to learn a table’s size, then again to fill one. &lt;em&gt;Alternatives&lt;/em&gt;: an
&lt;code&gt;inout&lt;/code&gt; length the caller passes, which lets the length and the array disagree (a read past the
end); a &lt;code&gt;ByteBlock&lt;/code&gt; sized by a first call, the same disagreement.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field accessor may answer a &lt;code&gt;view&lt;/code&gt;&lt;/strong&gt; of a byte-pointer field, &lt;code&gt;length:&lt;/code&gt; a C expression in
&lt;code&gt;self&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the glyph bitmap is &lt;code&gt;face-&amp;gt;glyph-&amp;gt;bitmap.buffer&lt;/code&gt;, &lt;code&gt;|pitch| * rows&lt;/code&gt; bytes the next
load replaces; the view’s closing on the face’s next use is exactly FreeType’s rule.
&lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;bytes:&lt;/code&gt; on a field, a copy of every glyph before the library walks it, which the
library could still choose; a glue function per field answering the pointer, the same with more
C. The view’s bounds check catches the reference binding’s &lt;code&gt;row * pitch&lt;/code&gt; indexing, which reads
before the buffer when &lt;code&gt;pitch&lt;/code&gt; is negative.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cairo’s FreeType font face is an &lt;code&gt;attach:&lt;/code&gt; class keeping the &lt;code&gt;Face&lt;/code&gt;.&lt;/strong&gt; Cairo keeps the
&lt;code&gt;FT_Face&lt;/code&gt; without a reference, documents that it must outlive every font face made from it, and
asks for it to be given back from &lt;code&gt;cairo_font_face_set_user_data&lt;/code&gt;‘s destructor; contexts and
scaled fonts reference the font face, so &lt;code&gt;keeps:&lt;/code&gt; on the Avin handle is not enough. The destroy
unpins the record and the &lt;code&gt;Face&lt;/code&gt; is then finalized as usual. &lt;em&gt;Alternative&lt;/em&gt;: a destroy that calls
&lt;code&gt;FT_Done_Face&lt;/code&gt; itself, from whatever thread drops the last reference, while an Avin &lt;code&gt;Face&lt;/code&gt; may
still be in use: FreeType’s face count is not atomic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;FT_Error_String&lt;/code&gt; binds as &lt;code&gt;Option[string]&lt;/code&gt;&lt;/strong&gt;, and the library carries its own names for the
codes, as &lt;code&gt;@c(const:)&lt;/code&gt; values of &lt;code&gt;fterrors.h&lt;/code&gt;‘s &lt;code&gt;FT_Err_*&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: Homebrew’s FreeType is built
without &lt;code&gt;FT_CONFIG_OPTION_ERROR_STRINGS&lt;/code&gt;, so the function answers null there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The test font is Kaisei Decol Regular&lt;/strong&gt;, from the reference repository, under the SIL Open
Font License 1.1 (Copyright 2020 The Kaisei Project Authors, no Reserved Font Name), bundled
with its &lt;code&gt;OFL.txt&lt;/code&gt; in the package’s tests. &lt;em&gt;Alternative&lt;/em&gt;: a smaller OFL Latin font (4.4 MB is
large for a test fixture), at the cost of a font the reference program’s output was not made
with. &lt;strong&gt;Review with the user&lt;/strong&gt;: the fixture’s size.&lt;/li&gt;
&lt;li&gt;Left out: &lt;code&gt;cairo_ft_font_options_substitute&lt;/code&gt;, which takes a fontconfig &lt;code&gt;FcPattern *&lt;/code&gt; and waits on
a fontconfig binding; &lt;code&gt;FT_Outline_Decompose&lt;/code&gt; and the other callback APIs, which the reference
binding does not reach.&lt;/li&gt;
&lt;li&gt;The survey’s two questions, settled with it. &lt;strong&gt;The test font is a small OFL font&lt;/strong&gt;, not Kaisei
Decol Regular (OFL 1.1 and usable, but 4.4 MB): a Latin face of a few hundred kilobytes, its
licence file beside it in the package’s tests, keeps the repository light, and the reference
binding’s outputs that need Kaisei’s glyphs are reproduced with the small face’s instead.
&lt;strong&gt;&lt;code&gt;cairo_ft_font_options_substitute&lt;/code&gt; waits on a fontconfig binding&lt;/strong&gt;: it takes a fontconfig
pattern, and nothing else in &lt;code&gt;cairo&lt;/code&gt; or &lt;code&gt;freetype&lt;/code&gt; needs fontconfig. The macro-named headers and
&lt;code&gt;FT_Error_String&lt;/code&gt;, which the survey placed in step 2, ride step 3, since step 2 was already being
built.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;c-bindings-strings&lt;/code&gt;): &lt;strong&gt;C bindings of strings and truth values&lt;/strong&gt;
(stage 13 step 2), the choices building it made where the &lt;a href=&quot;/spec/c-bindings/#strings&quot;&gt;chapter&lt;/a&gt; is
silent.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A C string is exactly one pointer to a plain &lt;code&gt;char&lt;/code&gt;&lt;/strong&gt;, &lt;code&gt;const&lt;/code&gt; when the qualifier comes before
the star (&lt;code&gt;const char *&lt;/code&gt;, &lt;code&gt;char const *&lt;/code&gt;); a qualifier after it (&lt;code&gt;char *const&lt;/code&gt;) is the pointer’s
own and changes nothing. &lt;code&gt;signed char *&lt;/code&gt;, &lt;code&gt;unsigned char *&lt;/code&gt;, &lt;code&gt;void *&lt;/code&gt; and &lt;code&gt;char **&lt;/code&gt; are other
pointers. &lt;em&gt;Why&lt;/em&gt;: those are the types C’s string functions use, and the header check catches any
other spelling. &lt;em&gt;Alternative&lt;/em&gt;: taking &lt;code&gt;unsigned char *&lt;/code&gt; as a string too, which libraries use for
bytes, not text.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A typedef crossing as a string is checked by the C unit&lt;/strong&gt; to be &lt;code&gt;char *&lt;/code&gt; or &lt;code&gt;const char *&lt;/code&gt;
as a result, and &lt;code&gt;const char *&lt;/code&gt; as a parameter (&lt;code&gt;__builtin_types_compatible_p&lt;/code&gt;), and is not
measured. &lt;em&gt;Why&lt;/em&gt;: the same rule the chapter gives a spelled &lt;code&gt;char *&lt;/code&gt; parameter, which C may write.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A typedef crossing as &lt;code&gt;bool&lt;/code&gt; may be a C &lt;code&gt;bool&lt;/code&gt; or an integer type&lt;/strong&gt; (checked with
&lt;code&gt;__builtin_classify_type&lt;/code&gt;), and is passed as the integer it measures; a C &lt;code&gt;bool&lt;/code&gt; typedef is then
one byte holding 0 or 1, the same registers as an &lt;code&gt;i1&lt;/code&gt;. An integer keyword crossing as &lt;code&gt;bool&lt;/code&gt;
may be any but a plain &lt;code&gt;char&lt;/code&gt;, which crosses only as &lt;code&gt;byte&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the checker cannot tell a
&lt;code&gt;bool&lt;/code&gt; typedef from &lt;code&gt;cairo_bool_t&lt;/code&gt;, and one measured path serves both. &lt;em&gt;Alternative&lt;/em&gt;: a marker
word for a truth value, which the Cairo survey weighed and set aside.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The traps’ words&lt;/strong&gt;: &lt;code&gt;the string passed to `s` of `length` holds a NUL at byte 3&lt;/code&gt; (the
chapter’s), &lt;code&gt; `fixture_invalid` answered a string that is not UTF-8 at byte 2&lt;/code&gt; (the offset is
where the first ill-formed sequence starts, as &lt;code&gt;from_utf8&lt;/code&gt; reports it; overlong forms,
surrogates, values past U+10FFFF and a cut-off sequence are all ill-formed), and
&lt;code&gt; `fixture_maybe` answered null&lt;/code&gt; (the chapter’s). A parameter declared with a pattern rather
than a name is named &lt;code&gt;parameter N&lt;/code&gt;. &lt;em&gt;Alternative&lt;/em&gt;: naming the binding rather than the C function
in the result traps; the C function is what answered.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A string argument’s copy is freed after the result is converted&lt;/strong&gt;, not when the call
returns, since C may answer a pointer into a string it was passed (&lt;code&gt;strchr&lt;/code&gt;, &lt;code&gt;strstr&lt;/code&gt;); the
copies are made with &lt;code&gt;malloc&lt;/code&gt; by the runtime (&lt;code&gt;avin_rt_c_string_in&lt;/code&gt;) and freed by
&lt;code&gt;avin_rt_c_string_free&lt;/code&gt;. A non-&lt;code&gt;blocking&lt;/code&gt; call cannot collect, and the collector never moves an
object, but the copy is still needed for the NUL. &lt;em&gt;Alternative&lt;/em&gt;: one buffer per thread reused
across calls, which a callback calling the same binding again would overwrite.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;free:&lt;/code&gt; accepts a function the headers declare as &lt;code&gt;void (void *)&lt;/code&gt;, &lt;code&gt;void (char *)&lt;/code&gt;,
&lt;code&gt;void (const char *)&lt;/code&gt; or &lt;code&gt;void (&amp;lt;the result&apos;s type&amp;gt;)&lt;/code&gt;&lt;/strong&gt;; anything else, including one answering
a value, is refused at the binding, as is a name no header declares. It is called only for a
non-null answer, after the copy is made, and &lt;strong&gt;a binding whose result is &lt;code&gt;unit&lt;/code&gt; with &lt;code&gt;free:&lt;/code&gt;
frees what C answered and discards it&lt;/strong&gt;. &lt;code&gt;free:&lt;/code&gt; on a binding that answers no string is refused
at check. &lt;em&gt;Why&lt;/em&gt;: a free function that answers a status is not one a binding can ignore, and a
library’s own free functions are seldom safe on null. &lt;em&gt;Alternative&lt;/em&gt;: refusing &lt;code&gt;free:&lt;/code&gt; on a
&lt;code&gt;unit&lt;/code&gt; result, which would leave no way to call such a function without leaking.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;Array[byte]&lt;/code&gt; result may be an &lt;code&gt;Option&lt;/code&gt; too&lt;/strong&gt;, null being &lt;code&gt;None&lt;/code&gt;, and a null bound as a
bare &lt;code&gt;Array[byte]&lt;/code&gt; traps as a bare &lt;code&gt;string&lt;/code&gt; does. &lt;strong&gt;An &lt;code&gt;Array[byte]&lt;/code&gt; parameter is refused&lt;/strong&gt; until
&lt;a href=&quot;/spec/c-bindings/#arrays-and-out-parameters&quot;&gt;arrays&lt;/a&gt; are built. &lt;em&gt;Alternative&lt;/em&gt;: an empty array
for null, which hides the difference C makes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;free:&lt;/code&gt; on a &lt;code&gt;unit&lt;/code&gt; result should stay legal.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;c-bindings-handles&lt;/code&gt;): &lt;strong&gt;C handles&lt;/strong&gt; (stage 13 step 3), the choices
building them made where the &lt;a href=&quot;/spec/c-bindings/#handles&quot;&gt;chapter&lt;/a&gt; is silent.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;shared&lt;/code&gt; is a bare word of the class’s &lt;code&gt;@c&lt;/code&gt;&lt;/strong&gt;, &lt;code&gt;@c(type: …, release: …, shared)&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the
&lt;code&gt;@c(&lt;/code&gt; lines are the whole trusted surface, and a thread-safety claim is one of them; no class
modifier says it today. &lt;em&gt;Alternative&lt;/em&gt;: a &lt;code&gt;shared class&lt;/code&gt; modifier, a keyword for one use.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A handle’s method is bound by a prototype taking the receiver first, named &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt;, of the
class’s C type (or that type &lt;code&gt;const&lt;/code&gt;); the method’s parameters follow by position. &lt;em&gt;Why&lt;/em&gt;: the
chapter’s every example writes it so, and the name makes the receiver visible in the C text.
&lt;em&gt;Alternative&lt;/em&gt;: the receiver at any position named &lt;code&gt;self&lt;/code&gt;, which no surveyed library needs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What keeps is the handle the binding answers, else a method’s receiver&lt;/strong&gt;, and a method
answering a handle may name &lt;code&gt;self&lt;/code&gt; in &lt;code&gt;keeps:&lt;/code&gt; to have the new handle keep the receiver.
Nothing is kept unless the call succeeded: a handle answered (not null), or a zero status.
&lt;em&gt;Why&lt;/em&gt;: a library object made by a method of another usually depends on it (a face’s variation
descriptor). &lt;em&gt;Alternative&lt;/em&gt;: the receiver always keeps for a method, which leaves the made
handle unprotected.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;consumes:&lt;/code&gt; closes the handle passed whatever the call answers, and may name &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt;; the
consumed handle keeps what it kept until it is collected or closed. &lt;em&gt;Why&lt;/em&gt;: C functions that take
a reference take it unconditionally, and giving back what the consumed object keeps while C
still holds the object would be a use after free. &lt;em&gt;Alternatives&lt;/em&gt;: closing only on success,
which most taking functions do not distinguish; releasing what it keeps at once.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A holder keeping a handle by a C reference also takes one to each C object that handle so
holds&lt;/strong&gt;, after it, given back after it. &lt;em&gt;Why&lt;/em&gt;: found under the collector’s stress in the
fixture: a variation descriptor keeps a face, the face’s own handle is collected first and gives
back its reference to the library, and the library is freed under a face the descriptor’s
&lt;code&gt;release&lt;/code&gt; reaches through. &lt;em&gt;Alternatives&lt;/em&gt;: holding the kept handle as the Avin object as well,
which orders nothing within one collection; refusing chains of kept handles, which FreeType’s
API is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The class &lt;code&gt;kept:&lt;/code&gt; names declares &lt;code&gt;retain&lt;/code&gt; and no &lt;code&gt;kept:&lt;/code&gt; of its own&lt;/strong&gt;, and is found in the
holder’s module or by its module and name (&lt;code&gt;freetype.Face&lt;/code&gt;); &lt;code&gt;retain:&lt;/code&gt; sees the name only where
it takes a &lt;code&gt;borrowed&lt;/code&gt; result’s reference, as the pointer of the handle the binding keeps; a
holder keeping a handle whose class has &lt;code&gt;kept:&lt;/code&gt; holds it as the Avin object. &lt;em&gt;Why&lt;/em&gt;: the name is
a pointer only while a C reference holds it, and a class with &lt;code&gt;kept:&lt;/code&gt; cannot be given back from
its pointer alone. &lt;em&gt;Alternative&lt;/em&gt;: storing every kept name in the C reference’s record, which
then has to hold references of its own, the same chain again.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A status’s code is any integer type&lt;/strong&gt;, converted with the result’s range check
(&lt;code&gt;Result[unit, long]&lt;/code&gt; for &lt;code&gt;long long&lt;/code&gt;; a &lt;code&gt;long long&lt;/code&gt; code past &lt;code&gt;int&lt;/code&gt; traps for
&lt;code&gt;Result[unit, int]&lt;/code&gt;). &lt;em&gt;Alternative&lt;/em&gt;: &lt;code&gt;int&lt;/code&gt; only, which loses a &lt;code&gt;long&lt;/code&gt; status’s code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The C unit includes a package’s headers after those of every package whose handle classes
its bindings name&lt;/strong&gt;, and otherwise in the order the libraries are listed, the program’s own
first. &lt;em&gt;Why&lt;/em&gt;: that is the only order the header check depends on, and it is read from the
bindings themselves. &lt;em&gt;Alternative&lt;/em&gt;: a topological order of the whole package graph, which
reorders headers no binding needs reordered.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: &lt;code&gt;shared&lt;/code&gt; as a word of &lt;code&gt;@c&lt;/code&gt; rather than a modifier, and the chain of C
references a kept handle brings with it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;c-bindings-fields&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;as:&lt;/code&gt; conversions and field accessors&lt;/strong&gt; (stage 13
step 4), the choices building them made where the &lt;a href=&quot;/spec/c-bindings/#handles-and-c-s-inheritance&quot;&gt;chapter&lt;/a&gt;
is silent.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;as:&lt;/code&gt; entry’s right side is a C function’s name or an expression in &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt;, as
&lt;code&gt;release:&lt;/code&gt;‘s is, and &lt;code&gt;as:&lt;/code&gt; is one string or a list. The C unit checks with
&lt;code&gt;__builtin_types_compatible_p&lt;/code&gt; that what it makes is the entry’s type. &lt;em&gt;Why&lt;/em&gt;: one rule for every
piece of glue, and C would otherwise convert a wrong pointer silently (the C unit compiles with
warnings off). &lt;em&gt;Alternative&lt;/em&gt;: an expression only, which makes MLT’s every entry repeat &lt;code&gt;(self)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A conversion is made after the closed and owner checks, from the handle’s own pointer, and
passes null as null&lt;/strong&gt;; what a binding &lt;code&gt;keeps:&lt;/code&gt; or &lt;code&gt;consumes:&lt;/code&gt; is the handle itself, held by its
class’s own &lt;code&gt;retain&lt;/code&gt;, never the converted pointer. &lt;em&gt;Why&lt;/em&gt;: the converted pointer is lent and may
point into the object, so a reference taken through another class’s glue would be the wrong
count. &lt;em&gt;Alternative&lt;/em&gt;: holding the converted pointer, which has no &lt;code&gt;release&lt;/code&gt; of its own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field is a member path read as &lt;code&gt;self-&amp;gt;&lt;/code&gt; followed by it&lt;/strong&gt;; its type is named in the C unit by
&lt;code&gt;__typeof__&lt;/code&gt; with the indices replaced by zero, so it is measured and checked without being
read. &lt;em&gt;Why&lt;/em&gt;: every surveyed accessor (MLT’s profile, FreeType’s face and glyph slot, Cairo’s
path) is a member path, and an unevaluated operand needs no index. &lt;em&gt;Alternative&lt;/em&gt;: a full C
expression in &lt;code&gt;self&lt;/code&gt;, which nothing surveyed needs and which makes &lt;code&gt;self-&amp;gt;&lt;/code&gt; noise in each.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only scalars are written&lt;/strong&gt;; a string or handle field is read only. &lt;em&gt;Why&lt;/em&gt;: a string or a
reference stored into a C struct needs an owner that frees or gives it back, which no surveyed
library asks Avin to be. &lt;em&gt;Alternative&lt;/em&gt;: writing strings copied with &lt;code&gt;malloc&lt;/code&gt; and never freed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Indices are &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long&lt;/code&gt;, passed as &lt;code&gt;long long&lt;/code&gt;, one &lt;code&gt;bound:&lt;/code&gt; each, in order&lt;/strong&gt;, a list for
more than one; a bound may use &lt;code&gt;self&lt;/code&gt; and the indices. The check is &lt;code&gt;0 &amp;lt;= index &amp;lt; bound&lt;/code&gt;, made
in Avin before the glue reads, trapping with “index &lt;code&gt;i&lt;/code&gt; of &lt;code&gt;Class.method&lt;/code&gt; out of range”. &lt;em&gt;Why&lt;/em&gt;:
a two-dimensional field needs a bound per index, and the trap names the index that was out of
range. &lt;em&gt;Alternative&lt;/em&gt;: one bound for all indices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A handle read from a field is lent, without &lt;code&gt;borrowed&lt;/code&gt; written&lt;/strong&gt;, and its class must declare
&lt;code&gt;retain&lt;/code&gt; and no &lt;code&gt;kept:&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a struct’s pointer is never the reader’s to give back.
&lt;em&gt;Alternative&lt;/em&gt;: requiring &lt;code&gt;borrowed&lt;/code&gt;, a word that could only ever be written one way.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: writers of scalars only.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;&lt;a href=&quot;/spec/time/&quot;&gt;Dates and times&lt;/a&gt;&lt;/strong&gt; (branch
&lt;code&gt;datetime-design&lt;/code&gt;), the choices the design makes beyond the user’s settled entry. Where the slate design leaves a name open, the names follow the
widely used date/time library family of Avin’s reference standard library ecosystem (&lt;code&gt;atZone&lt;/code&gt;,
&lt;code&gt;plusDays&lt;/code&gt;, &lt;code&gt;withYear&lt;/code&gt;, &lt;code&gt;toInstant&lt;/code&gt;, &lt;code&gt;isBefore&lt;/code&gt;, &lt;code&gt;toMinutes&lt;/code&gt;), except where a slate or a simpler
spelling is better, as each entry says.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Representation and ranges.&lt;/strong&gt; Every type but &lt;code&gt;Zone&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type whose fields are its
representation (&lt;code&gt;Duration(micros)&lt;/code&gt;, &lt;code&gt;Instant(epochMicros)&lt;/code&gt;, &lt;code&gt;Date(epochDay: int)&lt;/code&gt;,
&lt;code&gt;Time(microsOfDay)&lt;/code&gt;, &lt;code&gt;DateTime(date, time)&lt;/code&gt;, &lt;code&gt;Zoned(dateTime, offset, zone)&lt;/code&gt;,
&lt;code&gt;Period(months, days)&lt;/code&gt;); the makers check and the constructors take fields as given. A &lt;code&gt;Duration&lt;/code&gt;
and an &lt;code&gt;Instant&lt;/code&gt; span a whole &lt;code&gt;long&lt;/code&gt;, a &lt;code&gt;Date&lt;/code&gt; a whole &lt;code&gt;int&lt;/code&gt; of days, and what leaves a range traps.
&lt;em&gt;Why&lt;/em&gt;: data types are unboxed values, and every field value of &lt;code&gt;Duration&lt;/code&gt;, &lt;code&gt;Instant&lt;/code&gt;, &lt;code&gt;Date&lt;/code&gt; and
&lt;code&gt;Period&lt;/code&gt; is meaningful, so those constructors are total. &lt;em&gt;Alternatives&lt;/em&gt;: one common range for every
type (±290,000 years), cleaner to state, but enforceable only with constructors the module keeps
to itself, which Avin does not have; classes with private state, boxed and with identity. A
&lt;code&gt;Time&lt;/code&gt; or &lt;code&gt;Zoned&lt;/code&gt; built through its constructor with fields no maker would give is the cost.
&lt;strong&gt;Review with the user&lt;/strong&gt;: a module-private constructor would close it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Days and weeks are exact durations; a calendar day is &lt;code&gt;plusDays(n)&lt;/code&gt; or &lt;code&gt;Period(0, n)&lt;/code&gt;.&lt;/strong&gt; The
settled list makes &lt;code&gt;days&lt;/code&gt; and &lt;code&gt;weeks&lt;/code&gt; durations, as Sysl 0.10.0’s are, so &lt;code&gt;Period&lt;/code&gt; holds months
and days (Sysl’s &lt;code&gt;Period(months, days)&lt;/code&gt;), &lt;code&gt;months&lt;/code&gt; and &lt;code&gt;years&lt;/code&gt; make it, and &lt;code&gt;Date + Duration&lt;/code&gt; does
not compile (&lt;code&gt;date.plusDays(1)&lt;/code&gt;). On a &lt;code&gt;Zoned&lt;/code&gt;, &lt;code&gt;z + days(1)&lt;/code&gt; is 24 hours and &lt;code&gt;z.plusDays(1)&lt;/code&gt; the
same wall clock a day later. &lt;em&gt;Why&lt;/em&gt;: the user’s list and Sysl agree, and the exact/calendar line
stays in the types. &lt;em&gt;Alternatives&lt;/em&gt;: slate’s implementation, where &lt;code&gt;days&lt;/code&gt; and &lt;code&gt;weeks&lt;/code&gt; make periods
so &lt;code&gt;zoned + days(1)&lt;/code&gt; keeps the wall clock, which contradicts the settled list. &lt;strong&gt;Review with the
user&lt;/strong&gt;: the two spellings answer differently across a daylight-saving change.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Names where slate leaves them open, and where slate’s are kept.&lt;/strong&gt; &lt;code&gt;t.atZone(z)&lt;/code&gt;, &lt;code&gt;d.atTime(t)&lt;/code&gt;,
&lt;code&gt;t.atDate(d)&lt;/code&gt;, &lt;code&gt;d.atStartOfDay()&lt;/code&gt;, &lt;code&gt;zt.toInstant&lt;/code&gt;, &lt;code&gt;plusYears&lt;/code&gt;/&lt;code&gt;plusMonths&lt;/code&gt;/&lt;code&gt;plusWeeks&lt;/code&gt;/
&lt;code&gt;plusDays&lt;/code&gt; (no &lt;code&gt;minus&lt;/code&gt; forms: a negative count), &lt;code&gt;withYear&lt;/code&gt;/&lt;code&gt;withMonth&lt;/code&gt;/&lt;code&gt;withDay&lt;/code&gt;/&lt;code&gt;withHour&lt;/code&gt;…,
&lt;code&gt;isBefore&lt;/code&gt;/&lt;code&gt;isAfter&lt;/code&gt;/&lt;code&gt;isSameInstant&lt;/code&gt;, a duration’s &lt;code&gt;toHours()&lt;/code&gt; (whole) and &lt;code&gt;toHoursPart()&lt;/code&gt;, a
date’s &lt;code&gt;daysUntil&lt;/code&gt;/&lt;code&gt;monthsUntil&lt;/code&gt;/&lt;code&gt;until&lt;/code&gt;. Kept from slate as better: &lt;code&gt;weekday()&lt;/code&gt; (shorter, and the
name of its type) over &lt;code&gt;dayOfWeek&lt;/code&gt;, &lt;code&gt;day()&lt;/code&gt; and so &lt;code&gt;withDay&lt;/code&gt; over &lt;code&gt;dayOfMonth&lt;/code&gt;, &lt;code&gt;onOrAfter(w)&lt;/code&gt; and
&lt;code&gt;onOrBefore(w)&lt;/code&gt; over adjuster objects, &lt;code&gt;parseTimestamp&lt;/code&gt;, the &lt;code&gt;epoch*&lt;/code&gt; makers. Slate’s single &lt;code&gt;at&lt;/code&gt;
is spelt &lt;code&gt;atZone&lt;/code&gt;/&lt;code&gt;atTime&lt;/code&gt;/&lt;code&gt;atDate&lt;/code&gt;, since one overloaded word hides which conversion is meant and
&lt;code&gt;atZone&lt;/code&gt; names what can fail. &lt;code&gt;startOf(&amp;quot;month&amp;quot;)&lt;/code&gt; becomes &lt;code&gt;startOfMonth()&lt;/code&gt; and its siblings, so a
date’s &lt;code&gt;startOfHour&lt;/code&gt; is a compile error rather than a run-time one. &lt;em&gt;Alternatives&lt;/em&gt;: slate’s
&lt;code&gt;d.minutes&lt;/code&gt; for whole minutes (the same word makes and measures), &lt;code&gt;dayOfMonth&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Choosing an instant for a skipped or repeated reading.&lt;/strong&gt; &lt;code&gt;dt.atZone(z)&lt;/code&gt; answers
&lt;code&gt;Result[Zoned, ZoneTimeError]&lt;/code&gt; (&lt;code&gt;Skipped&lt;/code&gt;, &lt;code&gt;Repeated&lt;/code&gt;), and &lt;code&gt;atZoneEarlier(z)&lt;/code&gt;/&lt;code&gt;atZoneLater(z)&lt;/code&gt;,
Sysl’s &lt;code&gt;at_earlier&lt;/code&gt;/&lt;code&gt;at_later&lt;/code&gt;, always answer: the earlier or later instant of a repeated hour, and
in a skipped hour both push the reading past the gap by its length. A period on a &lt;code&gt;Zoned&lt;/code&gt;, a
&lt;code&gt;with…&lt;/code&gt; and &lt;code&gt;startOfDay&lt;/code&gt; push past a gap and, in a repeated hour, keep the offset the reading had
where it is one of the two and otherwise take the earlier. &lt;em&gt;Why&lt;/em&gt;: what the binding gives, and the
established rule. &lt;em&gt;Alternatives&lt;/em&gt;: slate’s string choice (&lt;code&gt;&amp;quot;earlier&amp;quot; | &amp;quot;later&amp;quot; | &amp;quot;after&amp;quot;&lt;/code&gt;), a
&lt;code&gt;Pick&lt;/code&gt; enum argument.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;Zoned&lt;/code&gt;‘s equality and order.&lt;/strong&gt; &lt;code&gt;==&lt;/code&gt; needs the same instant in the same zone; &lt;code&gt;Ord&lt;/code&gt; orders by
instant, then wall reading, then zone name, so it agrees with &lt;code&gt;==&lt;/code&gt; and a &lt;code&gt;TreeMap&lt;/code&gt; keeps two
readings of one instant; &lt;code&gt;isBefore&lt;/code&gt;, &lt;code&gt;isAfter&lt;/code&gt; and &lt;code&gt;isSameInstant&lt;/code&gt; compare instants alone.
&lt;em&gt;Alternatives&lt;/em&gt;: slate’s, where &lt;code&gt;&amp;lt;&lt;/code&gt; compares only the instant and so is false both ways for two
zones’ readings of one instant, an &lt;code&gt;Ord&lt;/code&gt; that disagrees with &lt;code&gt;==&lt;/code&gt;. &lt;strong&gt;Review with the user&lt;/strong&gt;: &lt;code&gt;&amp;lt;&lt;/code&gt;
between two zones’ readings of one instant is decided by the zone names.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Text.&lt;/strong&gt; ISO 8601 with &lt;code&gt;T&lt;/code&gt;, the seconds always written, the fraction only when there is one and
without trailing zeros (slate’s), years outside &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;9999&lt;/code&gt; signed; a fixed zone’s &lt;code&gt;Zoned&lt;/code&gt; writes no
bracketed name. A duration keeps the form the user settled on 2026-11-04, its largest unit of &lt;code&gt;s&lt;/code&gt;,
&lt;code&gt;ms&lt;/code&gt; and &lt;code&gt;us&lt;/code&gt; (&lt;code&gt;90.5s&lt;/code&gt;, &lt;code&gt;1.5ms&lt;/code&gt;); a period writes as &lt;code&gt;1y 2mo 3d&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: one shape per column; the
duration form is the user’s own decision, which a delegated choice does not overturn.
&lt;em&gt;Alternatives&lt;/em&gt;: Sysl’s renderers (a space for &lt;code&gt;T&lt;/code&gt;, seconds dropped when zero), today’s &lt;code&gt;WallTime&lt;/code&gt;
form with six fraction digits always, slate’s &lt;code&gt;1h 30m&lt;/code&gt; duration form (the design agent’s
proposal). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether durations should move to slate’s &lt;code&gt;1h 30m&lt;/code&gt; form.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Parsing.&lt;/strong&gt; &lt;code&gt;parseDate&lt;/code&gt;, &lt;code&gt;parseTime&lt;/code&gt;, &lt;code&gt;parseDateTime&lt;/code&gt;, &lt;code&gt;parseTimestamp&lt;/code&gt; and &lt;code&gt;parseZoned&lt;/code&gt;, each a
&lt;code&gt;Result&lt;/code&gt; with &lt;code&gt;TimeParseError&lt;/code&gt; (&lt;code&gt;BadShape(text, at)&lt;/code&gt;, &lt;code&gt;OutOfRange(text, field)&lt;/code&gt;,
&lt;code&gt;Trailing(text, at)&lt;/code&gt;, &lt;code&gt;UnknownZone(text, name)&lt;/code&gt;, &lt;code&gt;at&lt;/code&gt; a byte offset), every display read back,
ASCII digits only, a timestamp’s offset required. &lt;em&gt;Why&lt;/em&gt;: Sysl’s error kinds, with the text a
message must quote. &lt;em&gt;Alternatives&lt;/em&gt;: a message string only (slate); reading by pattern, left out
until wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Patterns.&lt;/strong&gt; &lt;code&gt;format(pattern)&lt;/code&gt; with slate’s pattern language (&lt;code&gt;YYYY&lt;/code&gt;, &lt;code&gt;MMMM&lt;/code&gt;, &lt;code&gt;WWWW&lt;/code&gt;, &lt;code&gt;h12&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;,
&lt;code&gt;f&lt;/code&gt;…, &lt;code&gt;z&lt;/code&gt;…, &lt;code&gt;|literal|&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt; a bar), English names and no locales; an element the value lacks, a
malformed run and an unclosed bar trap, the pattern being program text. &lt;code&gt;Instant&lt;/code&gt; has no &lt;code&gt;format&lt;/code&gt;.
&lt;em&gt;Alternatives&lt;/em&gt;: a compiled pattern answering a &lt;code&gt;Result&lt;/code&gt;, as &lt;code&gt;Regex.compile&lt;/code&gt; does, for patterns read
from outside.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Zones.&lt;/strong&gt; &lt;code&gt;zone(name)&lt;/code&gt; answers &lt;code&gt;Result[Zone, ZoneError]&lt;/code&gt; (&lt;code&gt;UnknownZone&lt;/code&gt;, &lt;code&gt;NotAZoneName&lt;/code&gt; decided
before any file is read, &lt;code&gt;Malformed&lt;/code&gt;); &lt;code&gt;localZone()&lt;/code&gt; always answers, &lt;code&gt;utc&lt;/code&gt; where the host names no
zone it can read; &lt;code&gt;fixedZone(offset: Duration)&lt;/code&gt; takes whole minutes within ±23:59 and traps
otherwise. An offset is a &lt;code&gt;Duration&lt;/code&gt; and Sysl’s &lt;code&gt;Offset&lt;/code&gt; stays behind the binding.
&lt;code&gt;isDaylightSavingAt&lt;/code&gt; and &lt;code&gt;abbreviationAt&lt;/code&gt; read the zone’s table through &lt;code&gt;sysl.time.tzif&lt;/code&gt;.
&lt;em&gt;Alternatives&lt;/em&gt;: an &lt;code&gt;Offset&lt;/code&gt; type of its own (a ninth public type), &lt;code&gt;localZone()&lt;/code&gt; as a &lt;code&gt;Result&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The wall clock reads microseconds&lt;/strong&gt; as the host gives them. &lt;em&gt;Alternatives&lt;/em&gt;: whole milliseconds,
slate’s choice for agreement with a back end Avin does not have.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Smaller additions&lt;/strong&gt;: &lt;code&gt;isoWeek()&lt;/code&gt; and &lt;code&gt;isoWeekYear()&lt;/code&gt;; &lt;code&gt;endOfMonth()&lt;/code&gt;; &lt;code&gt;Date - Date&lt;/code&gt; a &lt;code&gt;Period&lt;/code&gt; of
days; &lt;code&gt;d / e&lt;/code&gt; between durations a &lt;code&gt;long&lt;/code&gt;; a &lt;code&gt;Period&lt;/code&gt; and a &lt;code&gt;Zone&lt;/code&gt; &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; but not &lt;code&gt;Ord&lt;/code&gt;; a
&lt;code&gt;Time&lt;/code&gt; with no arithmetic; &lt;code&gt;Weekday&lt;/code&gt; ordered Monday to Sunday with &lt;code&gt;isoNumber()&lt;/code&gt; and &lt;code&gt;plus(n)&lt;/code&gt;;
&lt;code&gt;months&lt;/code&gt; and &lt;code&gt;years&lt;/code&gt; as methods on &lt;code&gt;int&lt;/code&gt; as the durations are on &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;; &lt;code&gt;3 * d&lt;/code&gt; does not
compile, the built-in types’ operators gaining no methods.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Delays.&lt;/strong&gt; Every delay in the library is a &lt;code&gt;Duration&lt;/code&gt;: &lt;code&gt;Future.await&lt;/code&gt; and &lt;code&gt;Condition.waitFor&lt;/code&gt; gain
overloads taking one beside their milliseconds; a command’s deadline is a &lt;code&gt;monotonic()&lt;/code&gt; reading;
actor timers keep the runtime’s monotonic microseconds and their &lt;code&gt;Duration&lt;/code&gt; parameters.
&lt;em&gt;Alternatives&lt;/em&gt;: leaving the millisecond forms alone.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;Data types of one module may share a variant’s
name&lt;/strong&gt; (branch &lt;code&gt;shared-variants&lt;/code&gt;).
Replaces the rule that a variant’s name is unique across a module’s files, which kept a C or Sysl
binding from mirroring two enums with one variant name (&lt;code&gt;Slant.Normal&lt;/code&gt;, &lt;code&gt;Weight.Normal&lt;/code&gt;;
&lt;code&gt;sysl.process&lt;/code&gt;‘s &lt;code&gt;Stdio.Inherit&lt;/code&gt; and &lt;code&gt;Group.Inherit&lt;/code&gt;) and two machines from sharing &lt;code&gt;Idle&lt;/code&gt;.
&lt;strong&gt;Review with the user.&lt;/strong&gt; The parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The expected type decides a bare use.&lt;/strong&gt; A shared name is the variant of the type expected
where it is written: a parameter’s, an annotated binding’s, a result’s, a field’s, a
collection’s element, and in a pattern the matched value’s, so nested patterns decide each name
by its field’s type. Why: it is how the qualified form’s work is already done everywhere a type
is known, and it keeps bare names, Avin’s usual form, working in all the places a shared name is
actually used. Alternatives: refusing every bare use of a shared name (mirrors would read
&lt;code&gt;Weight.Normal&lt;/code&gt; everywhere); picking the first declared type (silent, order-dependent);
deciding also by shape, a call meaning the variant with fields (a second rule for a reader to
know; not built).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Where nothing decides it, an error names the types and the qualified forms&lt;/strong&gt;: “&lt;code&gt;Normal&lt;/code&gt; is a
variant of &lt;code&gt;Slant&lt;/code&gt; and &lt;code&gt;Weight&lt;/code&gt;, and nothing here expects one of those types: write
&lt;code&gt;Slant.Normal&lt;/code&gt; or &lt;code&gt;Weight.Normal&lt;/code&gt;“. An expected type that is none of them is not a decision, and
&lt;code&gt;Any&lt;/code&gt; or a trait expected is not either. Reached through a module, the forms keep the module:
&lt;code&gt;fonts.Slant.Normal&lt;/code&gt;. Why: the qualified form always works, so the fix is the message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A comparison’s other operand decides&lt;/strong&gt;, as it does a number literal’s type: &lt;code&gt;w == Normal&lt;/code&gt;,
&lt;code&gt;Normal != w&lt;/code&gt;. A shared name, bare or called, is checked after the other operands, with their
type expected. Why: comparing with a variant is the commonest use outside a &lt;code&gt;match&lt;/code&gt;.
Alternative: requiring &lt;code&gt;is Normal&lt;/code&gt; or &lt;code&gt;Weight.Normal&lt;/code&gt; there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coverage, derived impls and shapes are per type&lt;/strong&gt; and unchanged: a &lt;code&gt;match&lt;/code&gt; over &lt;code&gt;Weight&lt;/code&gt; is
covered by &lt;code&gt;Weight&lt;/code&gt;‘s own variants; &lt;code&gt;Display&lt;/code&gt;/&lt;code&gt;Debug&lt;/code&gt; write the name; &lt;code&gt;Eq&lt;/code&gt;/&lt;code&gt;Hash&lt;/code&gt;/&lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;walk&lt;/code&gt;
and &lt;code&gt;build&lt;/code&gt; use the type’s own declaration order; layouts and mirrors are keyed by type, and a
mirrored variant crosses into Sysl as its own enum’s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A shared name is still one name of the module&lt;/strong&gt;: a function, module-level value or object of
that name is refused (“&lt;code&gt;Normal&lt;/code&gt; is already a variant of &lt;code&gt;Slant&lt;/code&gt; and &lt;code&gt;Weight&lt;/code&gt;“), a companion object
may not have a name another type’s variant has, and the name is not a type. Within one type a
variant’s name stays its own. Why: functions and values are not chosen by expected type, so the
clash would stay unresolvable. Alternative: letting a function or value hide the variants.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Imports: &lt;code&gt;import m.Normal&lt;/code&gt; is allowed&lt;/strong&gt; where &lt;code&gt;m&lt;/code&gt;‘s types share &lt;code&gt;Normal&lt;/code&gt;; the imported name is
shared in the importing file as in &lt;code&gt;m&lt;/code&gt;, and decided the same way. Why: it costs no new rule and a
file importing one of the names for its own type’s use reads naturally. Alternative weighed:
refusing the import and asking for the type (&lt;code&gt;import m.Weight&lt;/code&gt;, then &lt;code&gt;Weight.Normal&lt;/code&gt;), which the
brief leaned to; refused because the bare form then could not be written at all in that file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Visibility&lt;/strong&gt;: a shared name is seen from another module where any of its types is public, and
a private type’s variant is left out there, so where only one type is public its variant needs
no deciding (&lt;code&gt;signals.Stop&lt;/code&gt;). Where all are private the name is private to its module.&lt;/li&gt;
&lt;li&gt;Machines: two machines’ states, and a state and an event’s variant, may share a name, by the same
rule (amending the settled machine entry above). An arm’s result is its own &lt;code&gt;State&lt;/code&gt;, &lt;code&gt;handle&lt;/code&gt;‘s
argument the event type, so machine code needs nothing written.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;actor-state&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;state&lt;/code&gt; blocks in actors&lt;/strong&gt; (stage 12 step 8), the
choices building it made where the &lt;a href=&quot;/spec/actors/#an-actors-states&quot;&gt;chapter&lt;/a&gt; is silent.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Only a transition runs &lt;code&gt;leave&lt;/code&gt;&lt;/strong&gt;: an actor that stops, fails or restarts runs its &lt;code&gt;stopping&lt;/code&gt;
block, which reads &lt;code&gt;state()&lt;/code&gt;, and not the current state’s &lt;code&gt;leave&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the chapter defines
&lt;code&gt;leave&lt;/code&gt; as running when the actor moves out of a state into another, and &lt;code&gt;stopping&lt;/code&gt; is already
the one block an ending runs; running both would run two cleanups for one ending, in an order
the program cannot see. &lt;em&gt;Alternative&lt;/em&gt;: running the current state’s &lt;code&gt;leave&lt;/code&gt; before &lt;code&gt;stopping&lt;/code&gt;,
which suits a state holding a resource (the chapter’s &lt;code&gt;Ready(socket)&lt;/code&gt;) but runs code written
for a transition when none happens.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trap in &lt;code&gt;enter&lt;/code&gt; or &lt;code&gt;leave&lt;/code&gt; fails the actor&lt;/strong&gt; as a trap in an arm does, and a trap in a
&lt;code&gt;leave&lt;/code&gt; leaves the actor in the state it was leaving; one in an &lt;code&gt;enter&lt;/code&gt; leaves it in the state
entered. The first state’s &lt;code&gt;enter&lt;/code&gt; runs as the last statement of the body, so a restart runs it
again, and a trap there fails the actor as it starts. &lt;em&gt;Why&lt;/em&gt;: the transition’s steps run in the
order the chapter gives, inside the turn, and supervision already decides what a trap in a turn
means. &lt;em&gt;Alternative&lt;/em&gt;: rolling the state back on a trap, which needs a copy of the state before
every transition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An actor’s &lt;code&gt;State&lt;/code&gt; type and its states are private to its module&lt;/strong&gt;, as the class holding its
state is, and &lt;code&gt;state()&lt;/code&gt; is one of the actor’s own methods, not its reference’s. The states are
still names of the module, and share a name with another type’s variant there, a machine’s
states included, by the rule for shared variant names above. &lt;em&gt;Why&lt;/em&gt;: nothing outside an actor reaches its state. &lt;em&gt;Alternative&lt;/em&gt;: a public &lt;code&gt;State&lt;/code&gt; type
another module could match on, which nothing could hand it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An actor with states needs no &lt;code&gt;receive&lt;/code&gt; block&lt;/strong&gt;, as a machine needs none; without states it
still needs one. A shared arm of an actor with states yields a state, as a machine’s does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No reentrancy trap&lt;/strong&gt;: only the runtime hands an actor a message, one turn at a time, so the
actor needs no busy flag of the kind a machine’s &lt;code&gt;handle&lt;/code&gt; keeps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A sendable function reading a stateful actor’s fields is refused with the advice to copy into
a &lt;code&gt;val&lt;/code&gt;&lt;/strong&gt;, not to make a field a &lt;code&gt;val&lt;/code&gt;, which cannot make an actor that moves between states
sendable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: the first choice; whether an ending should run the current state’s
&lt;code&gt;leave&lt;/code&gt; is the one a program holding a resource in a state notices.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;A variant pattern writes no type arguments&lt;/strong&gt;
(branch &lt;code&gt;qualified-variant-targs&lt;/code&gt;). In an
expression a generic type’s variant takes its type arguments on the type, &lt;code&gt;Heap[int].Leaf&lt;/code&gt;, or on
the variant, &lt;code&gt;Heap.Leaf[int]&lt;/code&gt; and &lt;code&gt;Heap.Node[int](…)&lt;/code&gt; (settled by the declarations chapter’s
&lt;code&gt;Option.Some[long](9)&lt;/code&gt;; only the fieldless form had been missing, and is now built). In a pattern
neither form is written: &lt;code&gt;case Heap.Leaf[int]&lt;/code&gt;, &lt;code&gt;case Heap[int].Node(…)&lt;/code&gt; and &lt;code&gt;case Some[int](x)&lt;/code&gt;
are reported, &lt;em&gt;“a pattern takes its type arguments from the value it matches; write &lt;code&gt;Heap.Leaf&lt;/code&gt;“&lt;/em&gt;.
Why: the scrutinee’s type already decides them, so a written list could only repeat it or be an
error, and a test of the instance is a type pattern’s job (&lt;code&gt;x: Box[int]&lt;/code&gt;). Alternatives weighed:
accepting both spellings in patterns with the arguments required to equal the scrutinee’s (more
symmetric with expressions, but adds a rule that only restates the type); accepting them and
ignoring them (silently wrong where they differ). Revisit if a pattern on an &lt;code&gt;Any&lt;/code&gt; scrutinee
should match a variant at one instance, which would give written arguments a meaning.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;C enum mirrors, constants, statuses and out
parameters, as built&lt;/strong&gt; (branch &lt;code&gt;c-bindings-enums&lt;/code&gt;,
&lt;a href=&quot;/spec/c-bindings/#enums-and-constants&quot;&gt;chapter&lt;/a&gt;). The chapter left these open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An enumerator’s words and case.&lt;/strong&gt; A word starts at each upper-case letter of the variant’s
name, a digit and &lt;code&gt;_&lt;/code&gt; staying with the word before them (&lt;code&gt;Yuv420p&lt;/code&gt; one word, &lt;code&gt;ColorDodge&lt;/code&gt; two,
&lt;code&gt;Rgb16_565&lt;/code&gt; → &lt;code&gt;RGB16_565&lt;/code&gt;); they are upper case where the prefix has an upper-case letter and no
lower-case one, and lower case otherwise, a prefix with no letter or none at all included.
&lt;em&gt;Why&lt;/em&gt;: it is the case rule the chapter already states, made total. &lt;em&gt;Alternatives&lt;/em&gt;: a &lt;code&gt;case:&lt;/code&gt;
word on the mirror; matching the header’s enumerators case-insensitively, which the C unit cannot
list. A name starting with a digit after the prefix (&lt;code&gt;CAIRO_PDF_VERSION_1_4&lt;/code&gt;) is named with the
variant’s own &lt;code&gt;@c&lt;/code&gt;, and the C unit’s refusal of the derived name says so.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A mirror crosses only where the prototype writes its C type&lt;/strong&gt; (or that type &lt;code&gt;const&lt;/code&gt;), not at
a plain &lt;code&gt;int&lt;/code&gt; that happens to carry it. &lt;em&gt;Why&lt;/em&gt;: the binding then checks that the C function means
this enum. &lt;em&gt;Alternative&lt;/em&gt;: any integer position, which loses that check.
&lt;strong&gt;Review with the user&lt;/strong&gt;: some C APIs take an enum’s values as &lt;code&gt;int&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Duplicated values&lt;/strong&gt;: a variant crosses as its enumerator’s value, and a value C answers is the
first variant in declaration order holding it. &lt;em&gt;Alternative&lt;/em&gt;: refusing a mirror listing two
enumerators of one value, which refuses aliases a header keeps for compatibility.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A status mirror is &lt;code&gt;Ok&lt;/code&gt; for zero whether or not it lists a zero variant.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: zero is
success by the binding’s form, not by the mirror. &lt;em&gt;Alternative&lt;/em&gt;: requiring the zero variant.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constants&lt;/strong&gt;: an integer type takes any integer constant expression the headers define,
enumerators, characters and a &lt;code&gt;static const&lt;/code&gt; clang folds among them; &lt;code&gt;real&lt;/code&gt; takes a floating or
an integer constant; &lt;code&gt;string&lt;/code&gt; only a string literal, its bytes checked as UTF-8. A value its Avin
type cannot hold is refused at the constant with its value. &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt; and &lt;code&gt;byte&lt;/code&gt; constants are
refused. &lt;em&gt;Why&lt;/em&gt;: the three kinds the chapter names, each checked where it is read. &lt;em&gt;Alternatives&lt;/em&gt;:
narrowing silently; a &lt;code&gt;bool&lt;/code&gt; constant from an integer (left for when a library needs one).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;out&lt;/code&gt; and &lt;code&gt;inout&lt;/code&gt; are written before the parameter’s type&lt;/strong&gt; (&lt;code&gt;out int *x&lt;/code&gt;), the parameter a
pointer to what is answered, never to &lt;code&gt;const&lt;/code&gt;; a parameter may still be named &lt;code&gt;out&lt;/code&gt;. A non-&lt;code&gt;void&lt;/code&gt;
C result is left out where the binding’s result is the out values alone (&lt;code&gt;int f(out int *a)&lt;/code&gt;
bound as &lt;code&gt;-&amp;gt; int&lt;/code&gt; answers the out value), and is the first part where the result is a tuple of
one more. &lt;em&gt;Why&lt;/em&gt;: it is the chapter’s “a C result bound as &lt;code&gt;unit&lt;/code&gt; leaves the tuple without it”
without a &lt;code&gt;unit&lt;/code&gt; part to write. &lt;em&gt;Alternative&lt;/em&gt;: requiring a tuple whose first part is &lt;code&gt;unit&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An out slot starts as zero or null&lt;/strong&gt;, so a C function that writes nothing answers zero,
&lt;code&gt;None&lt;/code&gt;, or stops where the type has no null. &lt;strong&gt;A handle is never &lt;code&gt;inout&lt;/code&gt;&lt;/strong&gt;: whether C kept the
reference it was passed or replaced it cannot be said. &lt;em&gt;Alternative&lt;/em&gt;: passing it in and treating
what comes back as a new owned handle, which double-frees where C answers the same pointer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;inout&lt;/code&gt; string&lt;/strong&gt; is passed as a NUL-terminated copy through &lt;code&gt;const char **&lt;/code&gt; and read back
where C pointed it, before the copy is freed, so C may move it into the copy; a string C answers
through an out pointer is left to C, as a borrowed result is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What &lt;code&gt;keeps:&lt;/code&gt; keeps with out handles&lt;/strong&gt;: the holder is the handle the C result is, else the
first handle answered through an out pointer, else the receiver; a status keeps only when it is
zero, and a &lt;code&gt;None&lt;/code&gt; handle keeps nothing. &lt;code&gt;borrowed&lt;/code&gt; applies to every handle the binding answers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;time-instant&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;Duration&lt;/code&gt; given to a millisecond wait is
rounded up to whole milliseconds.&lt;/strong&gt; &lt;code&gt;Future.await(d)&lt;/code&gt; and &lt;code&gt;Condition.waitFor(d)&lt;/code&gt; pass the runtime’s
millisecond wait &lt;code&gt;ceil(d / 1ms)&lt;/code&gt;, so &lt;code&gt;await(micros(1))&lt;/code&gt; waits a millisecond; a duration of zero or
less asks without waiting, as a count that is not positive does. &lt;em&gt;Why&lt;/em&gt;: a timed wait should never
end before the time it was given, the rule &lt;code&gt;setTimeout&lt;/code&gt; already follows for a socket.
&lt;em&gt;Alternatives&lt;/em&gt;: rounding down, which turns every duration under a millisecond into no wait at all;
a microsecond wait in the runtime, which the condition variable beneath does not offer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;time-instant&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;toMicrosPart()&lt;/code&gt; is the part below the second&lt;/strong&gt;
(&lt;code&gt;micros % 1_000_000&lt;/code&gt;), as the chapter’s list goes from &lt;code&gt;toSecondsPart()&lt;/code&gt; straight to it, with no
&lt;code&gt;toMillisPart()&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the four parts then cover a duration with nothing left over (hours below
the day, minutes, seconds, microseconds). &lt;em&gt;Alternatives&lt;/em&gt;: the part below the millisecond, which
would need a &lt;code&gt;toMillisPart()&lt;/code&gt; beside it to be complete.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;An expected type reaches a core library variant
that a nearer one hides&lt;/strong&gt; (branch
&lt;code&gt;none-shadowing&lt;/code&gt;). A module’s own variant &lt;code&gt;None&lt;/code&gt; (a C mirror’s &lt;code&gt;ImageFormat.None&lt;/code&gt;) hid &lt;code&gt;Option&lt;/code&gt;‘s
throughout the module, so &lt;code&gt;return None&lt;/code&gt; from a &lt;code&gt;-&amp;gt; Option[T]&lt;/code&gt; function, &lt;code&gt;val x: Option[int] = None&lt;/code&gt; and a &lt;code&gt;None&lt;/code&gt; pattern on an option were all refused. Now, where the type expected at a bare
variant name (every position of the shared-variant rule above: parameter, annotated binding,
result, field, collection element, comparison operand, pattern) is a data type that none of the
nearer variants of that name belongs to, but the core library’s variant of the name does, that
variant is meant: &lt;code&gt;None&lt;/code&gt;, &lt;code&gt;Some&lt;/code&gt;, &lt;code&gt;Ok&lt;/code&gt;, &lt;code&gt;Err&lt;/code&gt;, &lt;code&gt;Left&lt;/code&gt;, &lt;code&gt;Right&lt;/code&gt; and any later prelude variant.
&lt;strong&gt;Where nothing decides it the nearer declaration wins&lt;/strong&gt;, as the scoping order always said, so
&lt;code&gt;val f = None&lt;/code&gt; in that module is still &lt;code&gt;ImageFormat.None&lt;/code&gt;; an expected type that is neither (an
&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;Any&lt;/code&gt;, a trait) also leaves the nearer one, reported against what was expected. Only the
core library’s variants are reached this way: a file may not import a name its module declares,
so an imported variant is never the hidden one, and an imported &lt;code&gt;None&lt;/code&gt; hides &lt;code&gt;Option&lt;/code&gt;‘s exactly as
a module’s own does. &lt;strong&gt;Review with the user&lt;/strong&gt;: it makes programs valid that were refused, and
changes no valid program’s meaning (a use the rule now gives to &lt;code&gt;Option&lt;/code&gt; was a type error before).
&lt;em&gt;Why&lt;/em&gt;: the rule for shared names is the one a reader already knows, and a C mirror’s
&lt;code&gt;None&lt;/code&gt; is common enough that writing &lt;code&gt;Option.None&lt;/code&gt; in every option-returning function of a
binding module would be a tax on exactly the code the bindings chapter shows. The undecided case
keeps the nearer one because every such use was valid before and meant the module’s variant;
making it an ambiguity error would break &lt;code&gt;val f = None&lt;/code&gt; and &lt;code&gt;f == None&lt;/code&gt; in existing mirror
modules, and would make the module’s own name second-class in its own module. &lt;em&gt;Alternatives&lt;/em&gt;:
an ambiguity error naming &lt;code&gt;ImageFormat.None&lt;/code&gt; and &lt;code&gt;Option.None&lt;/code&gt; wherever nothing decides (no
silent pick, but breaks valid programs and asks for a qualified form on the module’s own type);
leaving shadowing as it was and requiring &lt;code&gt;Option.None&lt;/code&gt; (the status quo the bug report was
about); refusing a variant named like a core library variant (would rename C enumerators).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;The language server’s &lt;code&gt;workspace/symbol&lt;/code&gt; and
&lt;code&gt;textDocument/foldingRange&lt;/code&gt;&lt;/strong&gt; (branch
&lt;code&gt;lsp-symbols-folding&lt;/code&gt;). Workspace symbols are read off each file’s parse, for every program an
open document belongs to, its unopened files included and its dependencies’ left out; a name
matches a query holding its characters in order (a subsequence), ASCII letters in either case; at
most 500 symbols are listed, in file order, for any query. A symbol’s location is its name, its
container its module, or its type for a method, a variant or a machine’s state; an actor is listed
once, as its class, and compiler-written members (names with a &lt;code&gt;$&lt;/code&gt;) are not listed. Folding is by
whole lines, from the lexer’s blocks (the line before an indent to the last line of code before the
matching dedent), multi-line tokens, comment runs, the import run and, in a literate file, runs of
program text; two regions of the same lines are listed once, the block’s kind winning. WHY: the
parse is there while the program has mistakes, as the outline’s is; a subsequence is what editors’
symbol search does; 500 is more than a person reads and small enough to answer per keystroke; the
lexer’s indent and dedent tokens already know comments, text blocks and bracketed continuations,
which a reading of indentation alone would not. ALTERNATIVES: symbols from the checker’s index
(absent while the program has a syntax error, and it holds no declarations of its own); prefix or
fuzzy-scored matching ranked by score (fine to add later; the protocol leaves ranking to the
client); Unicode case folding (needs a case table the compiler does not have); no cap, or a cap
only for the empty query; folding by indentation alone. Review with the user: whether ranking by
match quality is wanted, and whether a machine’s compiler-written &lt;code&gt;state()&lt;/code&gt;/&lt;code&gt;handle()&lt;/code&gt; should be
listed (they are, at the machine’s name).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;An arm no value can reach is an error&lt;/strong&gt; (branch
&lt;code&gt;unreachable-arms&lt;/code&gt;). An arm of a &lt;code&gt;match&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt; function, an actor’s &lt;code&gt;receive&lt;/code&gt; or a machine
state, and a clause of a function, is an error when the arms before it without a guard already
match every value it would: after &lt;code&gt;_&lt;/code&gt;, after a binding, after a pattern covering the whole type,
or covered by several earlier arms together. The message names the earlier arm that alone covers
it, by pattern and line, &lt;em&gt;“this arm is never reached: the arm &lt;code&gt;_&lt;/code&gt; on line 3 already matches every
value it would”&lt;/em&gt;, or says the arms before it do together. Where the covering arm binds a name
spelled as a type or a variant is (an upper-case first letter), it adds &lt;em&gt;“&lt;code&gt;Live&lt;/code&gt; binds a new
value there, since no variant &lt;code&gt;Live&lt;/code&gt; is in scope”&lt;/em&gt;. A guard never hides the arms after it; a
clause hides the ones after it only when one of its bodies has no guard; a clause body after a body
with no guard is an error too. Reachability is decided on the coverage matrix, so it knows what
coverage knows (variants, &lt;code&gt;true&lt;/code&gt;/&lt;code&gt;false&lt;/code&gt;, literals, ranges, comparisons, &lt;code&gt;n + k&lt;/code&gt;, strings by
equality, sequences by length, nesting); an extractor or a type test is taken to match every value
in the arm judged and none in the arms above it, so an arm is called unreachable only when it is,
whatever the extractors answer. A machine state’s own arms are judged against each other; the
shared &lt;code&gt;receive&lt;/code&gt; arms, which a state may override by handling an event itself, are judged against
each other once. A match whose patterns already failed to check is not judged. WHY: an arm
&lt;code&gt;Live -&amp;gt; …&lt;/code&gt; meant as a variant that was not in scope bound a new name, matched every phase, and
hid the arms after it: the actor runtime hung and spun at 900% CPU with nothing reported. A dead
arm is always a mistake, either in the arm or in an arm above it, and it is found by a check the
compiler already makes. ALTERNATIVES: a warning (Avin has no warnings channel; every diagnostic is
an error, and a warning shown only sometimes is the one that is missed); an error only after an
irrefutable arm (catches the bug that prompted this, but not &lt;code&gt;Some(_)&lt;/code&gt; before &lt;code&gt;Some(0)&lt;/code&gt;, which is
as dead); leaving it as it was. Review with the user: whether two identical extractor arms
(&lt;code&gt;Even() -&amp;gt; …&lt;/code&gt; twice) should count as unreachable, since an extractor is a function that could
answer differently each time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: &lt;strong&gt;C arrays as pointers and &lt;code&gt;blocking&lt;/code&gt; calls, as
built&lt;/strong&gt; (branch &lt;code&gt;c-bindings-arrays&lt;/code&gt;, stage 13
step 6, &lt;a href=&quot;/spec/c-bindings/#arrays-and-out-parameters&quot;&gt;chapter&lt;/a&gt;). The chapter left these open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;Array[int]&lt;/code&gt; or &lt;code&gt;Array[long]&lt;/code&gt; goes only to a pointer to a &lt;em&gt;signed&lt;/em&gt; integer of its size;
an &lt;code&gt;Array[byte]&lt;/code&gt; to any one-byte integer; an &lt;code&gt;Array[real]&lt;/code&gt; to any eight-byte floating-point
type&lt;/strong&gt;, typedefs included, all checked by the C unit (&lt;code&gt;__builtin_classify_type&lt;/code&gt;, &lt;code&gt;sizeof&lt;/code&gt; and
&lt;code&gt;(T)-1 &amp;lt; (T)0&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: “the element types must be the same size and kind, and nothing is
converted” — an unsigned element read as an &lt;code&gt;int&lt;/code&gt; would turn its upper half negative, which Avin
has no unsigned type to hold, while a byte is an octet of no sign. &lt;em&gt;Alternatives&lt;/em&gt;: any integer
of the size (silently reinterpreting unsigned elements); only the C types the chapter lists
by name (which refuses &lt;code&gt;FT_Fixed *&lt;/code&gt;, &lt;code&gt;aa_octet *&lt;/code&gt; and every typedef). &lt;strong&gt;Review with the user&lt;/strong&gt;:
an unsigned element array (&lt;code&gt;uint32_t *&lt;/code&gt; pixels) needs a binding per element or a buffer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;length(data)&lt;/code&gt; is written first, before the parameter’s type and before &lt;code&gt;inout&lt;/code&gt;&lt;/strong&gt;
(&lt;code&gt;length(buffer) inout FT_ULong *length&lt;/code&gt;), as &lt;code&gt;out&lt;/code&gt; and &lt;code&gt;inout&lt;/code&gt; are; a parameter may still be
named &lt;code&gt;length&lt;/code&gt;. It marks an integer of C’s keywords (not &lt;code&gt;char&lt;/code&gt;, not an enumeration) or a
typedef, which the C unit checks to be an integer. &lt;em&gt;Alternative&lt;/em&gt;: after the type, which reads as
part of it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An &lt;code&gt;Option&lt;/code&gt; of an array is accepted wherever an array is&lt;/strong&gt;, not only beside an &lt;code&gt;inout&lt;/code&gt; length:
&lt;code&gt;None&lt;/code&gt; passes null and a length of zero to any binding. &lt;em&gt;Why&lt;/em&gt;: C that takes null for “no data”
is common, and the rule is the chapter’s for &lt;code&gt;inout&lt;/code&gt;. &lt;em&gt;Alternative&lt;/em&gt;: only beside an &lt;code&gt;inout&lt;/code&gt;
length.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An array’s length crosses as an &lt;code&gt;int&lt;/code&gt; converted to the length’s C type&lt;/strong&gt;, so an array too
long for an &lt;code&gt;unsigned char&lt;/code&gt; length stops the program at the call, naming the length’s type and
the array (“value out of range for u8 (unsigned char), the length of &lt;code&gt;p&lt;/code&gt;“). &lt;strong&gt;A length C writes
back through &lt;code&gt;inout&lt;/code&gt; is read as an out value, then compared with the array’s length&lt;/strong&gt;, the
program stopping where it is greater; &lt;code&gt;None&lt;/code&gt; bounds nothing, since it asks C the length it
needs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every array position crosses as a pointer in place unless the call is &lt;code&gt;blocking&lt;/code&gt;&lt;/strong&gt;: the
collector never moves an object and no collection runs while a call that is not &lt;code&gt;blocking&lt;/code&gt; holds
the thread, so nothing is copied; a &lt;code&gt;blocking&lt;/code&gt; call is passed a copy off the heap (an empty
array’s a byte long, so C is never passed null for it), copied back only where the pointer is not
&lt;code&gt;const&lt;/code&gt;, and freed once the thread is running again. &lt;em&gt;Alternative&lt;/em&gt;: copying for every call,
which costs the common case for nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;blocking&lt;/code&gt; call keeps each handle it is passed alive across the wait&lt;/strong&gt; by using its object
after &lt;code&gt;leave_safe&lt;/code&gt;, so the collector, running while the call waits, cannot give the C pointer
back under C. &lt;em&gt;Alternative&lt;/em&gt;: relying on the caller holding it, which a temporary argument does
not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arrays of mirrors, strings, handles, &lt;code&gt;bool&lt;/code&gt; and the narrower integers are refused&lt;/strong&gt; with the
four element types the chapter lists; arrays of mirrors arrive with struct mirrors (step 7).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sysl-generic-bindings&lt;/code&gt;): &lt;strong&gt;generic bindings are bounded by &lt;code&gt;Boundary&lt;/code&gt;&lt;/strong&gt;
(&lt;a href=&quot;/spec/sysl-bindings/#generics&quot;&gt;Sysl bindings&lt;/a&gt;). A binding’s type parameters, a generic handle
class’s, and a bound method’s own are each bounded by &lt;code&gt;Boundary&lt;/code&gt;, a core trait the compiler decides
from a type’s structure as it decides &lt;code&gt;Sendable&lt;/code&gt;: the integers of 8, 16, 32 and 64 bits, &lt;code&gt;byte&lt;/code&gt;,
&lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;@sysl&lt;/code&gt; mirrors, and &lt;code&gt;Option&lt;/code&gt;s, &lt;code&gt;Result&lt;/code&gt;s and tuples of
these, and a type parameter bounded by it. It is only a bound: not a type, and no impl, trait or
derivation declares it. Each call’s type arguments are held to it as to any bound, a generic
function passes its own type parameter on only where that one is bounded by it too, and every
instantiation gets a shim of its own that Sysl checks, so a Sysl bound the instance does not meet is
reported at the binding in Sysl’s words; an Avin bound beside it (&lt;code&gt;[T: Boundary &amp;amp; Ord]&lt;/code&gt;) is Avin’s to
check, with no mapping between Sysl’s traits and Avin’s. A generic handle class,
&lt;code&gt;@sysl(&amp;quot;m.Signal&amp;quot;) class Signal[T: Boundary]&lt;/code&gt;, names the generic type without arguments, its type
parameters invariant and the Sysl type’s in order; each instance the program uses is a handle of its
own on the Sysl type’s instance, with its own finalizer, spelled by the shim from the instance’s
types, so a mirror may be a type argument (the annotation-text instances keep their narrower rule).
Rationale: the declaration can be checked once and every instantiation is then sound by the bound
machinery that already exists, including through a library’s generic wrappers, with no
instantiation-time diagnostics in lowering (which reports none); “one Sysl type” is what a handle’s
instance needs and what keeps a type argument’s Sysl type the same in both directions.
Alternatives weighed: unbounded type parameters checked per call at concrete types only (refuses
every generic wrapper, or needs a closed-world pass in the checker that does not exist); an
implicit bound, never written (hides why a wrapper’s &lt;code&gt;T&lt;/code&gt; is refused); admitting collections (their
Sysl type is a slice going in and a slice or a &lt;code&gt;Buf&lt;/code&gt; coming out, so a &lt;code&gt;T&lt;/code&gt; a Sysl function stores
would not be one type) and handles (one goes into Sysl only by itself, so &lt;code&gt;Option[T]&lt;/code&gt; at a handle
could not cross in); a mapping from Sysl traits to Avin bounds (no table exists, and Sysl checks its
own bounds anyway). &lt;strong&gt;Review with the user:&lt;/strong&gt; the name &lt;code&gt;Boundary&lt;/code&gt;, and whether handles should become
type arguments of generic handles (&lt;code&gt;Signal[View]&lt;/code&gt;), which needs the shim to pass a handle inside a
generic Sysl value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;sysl-generic-bindings&lt;/code&gt;): &lt;strong&gt;a callback closure’s parameters are written
out where Sysl cannot infer them&lt;/strong&gt;. A Sysl closure taking the function’s own type parameter
(&lt;code&gt;applied[T, U](x: T, f: &amp;amp;Fn(T) -&amp;gt; U)&lt;/code&gt;) left the shim’s lambda &lt;code&gt;(q0) -&amp;gt; …&lt;/code&gt; untyped, which Sysl
refuses, for generic and non-generic bindings alike; the shim now writes each parameter as the Avin
type’s Sysl spelling on that diagnostic, and is rebuilt for as long as each build names something
more to write out (the lambda’s types first, the integer answer after), not once.
Rationale: the same retry the shim already made for integer answers and parameters, extended.
Alternatives weighed: always typing the lambda (wrong where Sysl hands a collection as a &lt;code&gt;Buf&lt;/code&gt;
rather than a slice, which only inference gets right); refusing such bindings.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;A send hands a message’s handles to the receiving actor,
not into transit&lt;/strong&gt; (&lt;a href=&quot;/spec/actors/#handing-over-ownership&quot;&gt;actors&lt;/a&gt;). The settled ownership
decision says a send puts a message’s handles in transit for their first user, the receiver, and
that the sender’s later use traps. &lt;code&gt;ActorRef.tell&lt;/code&gt; knows the actor the message goes to, so the
handles the sender owns are handed straight to that actor’s owner as the message enters its
mailbox. Why: in transit, a sender that uses a handle before the receiver does would take it
back, and the trap the decision promises would depend on a race; handed to the actor, the
sender’s next use always traps. A message dropped because the actor has ended hands nothing over,
so its handles stay the sender’s. A reply to an &lt;code&gt;ask&lt;/code&gt; completes a future, which already puts its
handles in transit for the waiting code. Alternatives weighed: in transit as written (racy, as
above); handing over when the receiver takes the message off its mailbox (too late: the sender
could have used the handle meanwhile).
&lt;strong&gt;Review with the user:&lt;/strong&gt; it refines the wording of a decision the user settled.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;Handing a value over stops at what is shared between
owners.&lt;/strong&gt; The runtime’s walk follows every object a value reaches, so a message holding an
actor’s reference walked into that actor’s state and handed its handles away (an actor that
spawned a child capturing its own reference lost its connections to the child). The standard
library marks the types shared between owners &lt;code&gt;@keeps_owners&lt;/code&gt; — &lt;code&gt;ActorRef&lt;/code&gt;, &lt;code&gt;Timer&lt;/code&gt;, &lt;code&gt;Future&lt;/code&gt;,
&lt;code&gt;Promise&lt;/code&gt;, &lt;code&gt;Executor&lt;/code&gt;, &lt;code&gt;Channel&lt;/code&gt;, &lt;code&gt;Mutex&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt;, &lt;code&gt;Once&lt;/code&gt;, &lt;code&gt;Atomic&lt;/code&gt;, &lt;code&gt;Thread&lt;/code&gt;, &lt;code&gt;Scope&lt;/code&gt; — and
their type records carry the mark, at which every walk (a send, &lt;code&gt;spawn&lt;/code&gt;, a thread’s or a future’s
body, completing a future) stops: their handles keep their owners, as a channel’s values already
do. &lt;code&gt;Behaviour&lt;/code&gt; is walked, since its start’s captures are what the new actor owns. The mark is the
standard library’s alone. Alternatives weighed: a walk the compiler writes for each type (exact,
but a collection’s nodes are untyped to it); a marker trait instead of an annotation (visible to
every program, which could then hide its own handles from a send).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;Which messages a send walks.&lt;/strong&gt; A send walks its message
where its type may hold a handle: a handle; a tuple, data type or class with a field that may; a
generic type of the standard library, its collections and &lt;code&gt;Isolated&lt;/code&gt; among them, at a type
argument that may, or that keeps a function (&lt;code&gt;Behaviour&lt;/code&gt;); a function value; and &lt;code&gt;Any&lt;/code&gt;, a trait,
or an open or abstract class, which may hold anything. A &lt;code&gt;@keeps_owners&lt;/code&gt; type and the scalars and
strings never are. Decided per type where the program is compiled (the actors’ intrinsic
&lt;code&gt;holds_handles&lt;/code&gt;), so a message of numbers, strings, actors’ references or &lt;code&gt;Vector[int]&lt;/code&gt; costs no
walk. Alternatives weighed: walking every message (pays for every send); a standard library
generic type judged by its fields too (a &lt;code&gt;Vector[int]&lt;/code&gt;‘s nodes hold &lt;code&gt;Any&lt;/code&gt;, so every vector would be
walked).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;@isolating&lt;/code&gt;, the mark of &lt;code&gt;isolate&lt;/code&gt;‘s body and &lt;code&gt;with&lt;/code&gt;‘s
function&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;what is shared&lt;/a&gt;). The rule of &lt;code&gt;isolate&lt;/code&gt;‘s body is
&lt;code&gt;@isolated&lt;/code&gt;‘s (only sendable values from around it) and the whole-program check that nothing it
runs reaches module-level mutable state; &lt;code&gt;@isolated&lt;/code&gt; deliberately leaves out the second half for a
mutex’s body. A third mark between &lt;code&gt;@isolated&lt;/code&gt; and &lt;code&gt;@sendable&lt;/code&gt; carries both, and a program’s own
function that isolates what its caller passes writes it too: a parameter so marked is passed on
for &lt;code&gt;@isolating&lt;/code&gt; or &lt;code&gt;@isolated&lt;/code&gt;, and a &lt;code&gt;@sendable&lt;/code&gt; one for &lt;code&gt;@isolating&lt;/code&gt;, but not the other way. It
allows capturing a &lt;code&gt;var&lt;/code&gt; of the code around it, since the body runs at once. Alternatives weighed:
holding every &lt;code&gt;@isolated&lt;/code&gt; argument to the module-level check (a mutex’s body was thought to have
no need of it, which the &lt;code&gt;mutex-isolating&lt;/code&gt; entry below corrects);
an annotation only the standard library may write (a program could then not wrap &lt;code&gt;isolate&lt;/code&gt;).
&lt;strong&gt;Review with the user:&lt;/strong&gt; it adds a third annotation users can write, beside &lt;code&gt;@sendable&lt;/code&gt; and
&lt;code&gt;@isolated&lt;/code&gt; (a mutex’s value and body take it too, below).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;with&lt;/code&gt; holds an &lt;code&gt;Isolated&lt;/code&gt;‘s objects while its function
runs.&lt;/strong&gt; Two &lt;code&gt;with&lt;/code&gt;s of one &lt;code&gt;Isolated&lt;/code&gt; on two threads would change one graph at once, and a &lt;code&gt;take&lt;/code&gt;
from inside &lt;code&gt;f&lt;/code&gt; would hand the objects out while &lt;code&gt;f&lt;/code&gt; still works on them. So &lt;code&gt;with&lt;/code&gt; moves the
&lt;code&gt;Isolated&lt;/code&gt; from held to in use by one atomic compare-and-set and back when &lt;code&gt;f&lt;/code&gt; returns; a &lt;code&gt;take&lt;/code&gt; or
&lt;code&gt;with&lt;/code&gt; meanwhile traps with &lt;code&gt;`Isolated` is in use by `with`&lt;/code&gt;, and a &lt;code&gt;with&lt;/code&gt; after a &lt;code&gt;take&lt;/code&gt; traps
as a second &lt;code&gt;take&lt;/code&gt; does (&lt;code&gt;`Isolated` was already taken&lt;/code&gt;). A trap inside &lt;code&gt;f&lt;/code&gt; leaves it in use.
Alternatives weighed: a lock that makes a second &lt;code&gt;with&lt;/code&gt; wait (an actor holding it would stall a
worker, and a &lt;code&gt;with&lt;/code&gt; from inside &lt;code&gt;f&lt;/code&gt; would deadlock); no check (a data race).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;Where &lt;code&gt;Isolated&lt;/code&gt; lives.&lt;/strong&gt; &lt;code&gt;Isolated&lt;/code&gt;, &lt;code&gt;isolate&lt;/code&gt; are in
&lt;code&gt;avin.actors&lt;/code&gt; (the chapter that defines them), imported as &lt;code&gt;import avin.actors.{Isolated, isolate}&lt;/code&gt;; a thread passes one through a channel the same way. &lt;code&gt;Isolated(objects)&lt;/code&gt; may be called
directly, its parameter marked &lt;code&gt;@isolating&lt;/code&gt;, as &lt;code&gt;Mutex(value)&lt;/code&gt;‘s is. Alternatives
weighed: the core module (imported everywhere, though only concurrent code wants it);
&lt;code&gt;avin.threads&lt;/code&gt; (the actors chapter names it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (branch &lt;code&gt;mutex-isolating&lt;/code&gt;; found on
&lt;code&gt;actor-isolation&lt;/code&gt;): &lt;strong&gt;a mutex’s value and its &lt;code&gt;with&lt;/code&gt; body are &lt;code&gt;@isolating&lt;/code&gt;&lt;/strong&gt;
(&lt;a href=&quot;/spec/threads/#synchronization&quot;&gt;synchronization&lt;/a&gt;). Under &lt;code&gt;@isolated&lt;/code&gt;, &lt;code&gt;m.with(b -&amp;gt; cache = b)&lt;/code&gt;
on the main thread stored the buffer in a module-level &lt;code&gt;var&lt;/code&gt;, so the main thread could change it
later without the lock while a worker changed it under the lock; &lt;code&gt;Mutex(make())&lt;/code&gt;, where &lt;code&gt;make&lt;/code&gt;
keeps the buffer it returns in a module-level &lt;code&gt;var&lt;/code&gt;, did the same at construction. Both
parameters now take the whole-program check that nothing they run reaches module-level mutable
state. The cost: a body may not read a module-level &lt;code&gt;var&lt;/code&gt; (or a module-level value of a type that
is not sendable) even where it stores nothing; it reads a local copied before the &lt;code&gt;with&lt;/code&gt; instead.
Module-level &lt;code&gt;val&lt;/code&gt;s of sendable types, another mutex among them, stay readable, so nested &lt;code&gt;with&lt;/code&gt;s
on two module-level mutexes are legal. Alternatives weighed: a narrower rule refusing only a flow
of the guarded value into module state while still allowing reads of module &lt;code&gt;var&lt;/code&gt;s (an escape
analysis through every call, field, collection and closure; the store can go through a module
&lt;code&gt;val&lt;/code&gt; of a mutable collection or an object’s method, so the rule is the same whole-program reach
with flow tracking on top, harder to make sound and to explain in one diagnostic); leaving the
constructor &lt;code&gt;@isolated&lt;/code&gt; (keeps the same hole open through the value’s maker). &lt;strong&gt;Review with the
user:&lt;/strong&gt; a &lt;code&gt;with&lt;/code&gt; body that only reads a module-level &lt;code&gt;var&lt;/code&gt; counter is now refused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05 (built on branch &lt;code&gt;c-bindings-callbacks&lt;/code&gt;, stage 13 step 9,
&lt;a href=&quot;/spec/c-bindings/#callbacks&quot;&gt;chapter&lt;/a&gt;): &lt;strong&gt;C callbacks, as built.&lt;/strong&gt; The chapter left these open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A function pointer finds its &lt;code&gt;userdata&lt;/code&gt; by name&lt;/strong&gt;: the function pointer’s own prototype marks
exactly one parameter &lt;code&gt;userdata&lt;/code&gt;, and the binding marks one of the same name, which carries it
(&lt;code&gt;void (*listener)(userdata void *data, …)&lt;/code&gt; beside &lt;code&gt;userdata void *data&lt;/code&gt;); each of the binding’s
carries exactly one function, and a parameter taking a function is named. &lt;em&gt;Why&lt;/em&gt;: MLT and Cairo
already use one name for both, and a name says unambiguously which &lt;code&gt;void *&lt;/code&gt; goes with which
function when a binding takes two. &lt;em&gt;Alternatives&lt;/em&gt;: by position (the n-th &lt;code&gt;userdata&lt;/code&gt; carries the
n-th function; silent when C’s order differs), or one function per binding (MLT and Cairo need
no more, but GLib-style APIs pass a &lt;code&gt;destroy&lt;/code&gt; beside the callback).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One trampoline per binding parameter, not per C function type.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: two bindings of one
C type may cross it as different Avin types (&lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;, a mirror and an integer), so the
conversions differ; the trampoline is a few instructions and the function it runs is the
conversion. &lt;em&gt;Alternative&lt;/em&gt;: one per C type with the conversions chosen at run time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A callback answers a scalar, a truth value or an enum mirror, and &lt;code&gt;unit&lt;/code&gt; exactly where C’s
function answers &lt;code&gt;void&lt;/code&gt;&lt;/strong&gt;; a string, a handle or a status as its answer is refused. &lt;em&gt;Why&lt;/em&gt;: a
string or a handle answered to C would have to outlive the call with nothing to free it.
&lt;em&gt;Alternative&lt;/em&gt;: answer a string copied into memory C must free, which no C API this stage binds
expects.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What C calls a function with crosses as a binding’s result does&lt;/strong&gt;, a string copied and
checked (or an &lt;code&gt;Array[byte]&lt;/code&gt;, or &lt;code&gt;None&lt;/code&gt; for null), a handle lent through its class’s &lt;code&gt;retain&lt;/code&gt; —
a handle class without &lt;code&gt;retain&lt;/code&gt; is refused there — and a value no Avin type holds stops the
program where the binding C is running was called, as the answer’s does, naming the function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;forget:&lt;/code&gt; is a C function’s name, called &lt;code&gt;name(self, userdata)&lt;/code&gt;, or a C expression in &lt;code&gt;self&lt;/code&gt;
and &lt;code&gt;userdata&lt;/code&gt;&lt;/strong&gt;, run in the handle’s glue for each callback it keeps, after its pointer is taken
and before &lt;code&gt;release&lt;/code&gt;; a handle that keeps a handle never takes the other’s callbacks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A kept function’s record roots it until the handle keeping it is given back.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: the
record must outlive any call C makes, even one racing the collector on a thread of C’s own.
&lt;em&gt;Consequence&lt;/em&gt;: a kept function that captures its own holder keeps both alive until &lt;code&gt;close()&lt;/code&gt;.
&lt;em&gt;Alternative&lt;/em&gt;: trace the function from the handle, which frees such a cycle but lets a C thread
call a function the collector has just freed. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether that cycle is
worth a weak record.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In a program that passes C a function, every call of a C library function may run the
collector&lt;/strong&gt;, and is planned as one that does: any C call may call back a function C keeps. The
C unit’s glue never does. &lt;em&gt;Alternative&lt;/em&gt;: a &lt;code&gt;calls-back&lt;/code&gt; word on the bindings that may, which is
cheaper and trusted.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;libc’s &lt;code&gt;qsort&lt;/code&gt; and &lt;code&gt;bsearch&lt;/code&gt; take no &lt;code&gt;userdata&lt;/code&gt;, so they cannot be bound&lt;/strong&gt;; the corpus binds a
C function of its own that calls &lt;code&gt;qsort_r&lt;/code&gt; and &lt;code&gt;bsearch&lt;/code&gt; through one.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-05: on branch &lt;code&gt;c-bindings-structs&lt;/code&gt; (roadmap stage 13
step 7), &lt;strong&gt;C struct mirrors, opaque values and arrays C answers.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A mirror’s layout is measured, and checked against the header’s order.&lt;/strong&gt; The C unit measures
each field’s offset, width and sign and the struct’s size, and asserts the fields come in the
header’s order, each where C’s alignment puts it after the one before, none after the last;
lowering reads and writes each field at its measured offset and width, with the traps of an
argument and a result. &lt;em&gt;Why&lt;/em&gt;: a field narrower or wider than its Avin type (&lt;code&gt;uint8_t&lt;/code&gt; as &lt;code&gt;int&lt;/code&gt;,
&lt;code&gt;float&lt;/code&gt; as &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;unsigned long&lt;/code&gt; as &lt;code&gt;long&lt;/code&gt;) crosses as a scalar parameter does, and the layout is
the target’s. &lt;em&gt;Alternatives&lt;/em&gt;: a layout implied by the Avin types alone and asserted (cannot spell
a &lt;code&gt;float&lt;/code&gt; or a &lt;code&gt;short&lt;/code&gt; field); matching fields by name in any order (hides a reordered header).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every field is named, which a positional initializer checks.&lt;/strong&gt; The unit initializes the struct
by position with one zero per mirrored field under &lt;code&gt;-Wmissing-field-initializers&lt;/code&gt; made an error,
so a field hidden in the padding between two others is found. For that the unit no longer passes
&lt;code&gt;-w&lt;/code&gt;; it ignores every warning with &lt;code&gt;#pragma clang diagnostic ignored &amp;quot;-Weverything&amp;quot;&lt;/code&gt; instead.
&lt;em&gt;Alternative&lt;/em&gt;: the layout checks alone, which miss a small field in padding.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A mirror has one variant named as the type&lt;/strong&gt;, as a Sysl struct mirror does, and its fields are
integer types, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;strong&gt;&lt;code&gt;Option[string]&lt;/code&gt;&lt;/strong&gt; (null as &lt;code&gt;None&lt;/code&gt;), enum
mirrors and other struct mirrors. &lt;em&gt;Why&lt;/em&gt;: FreeType’s and Cairo’s structs carry nullable names.
&lt;em&gt;Alternative&lt;/em&gt;: &lt;code&gt;string&lt;/code&gt; only, a stop on null.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strings in a mirror passed in are copies freed after the call; strings C writes into a mirror
are copied out and left to C&lt;/strong&gt;, as a borrowed string result is. &lt;em&gt;Alternative&lt;/em&gt;: a &lt;code&gt;free:&lt;/code&gt; per
field, which no surveyed struct needs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every out value stays in the result, the array’s length too&lt;/strong&gt;, where &lt;code&gt;array:&lt;/code&gt; names the array.
&lt;em&gt;Why&lt;/em&gt;: one rule for out values. &lt;em&gt;Alternative&lt;/em&gt;: dropping the out value &lt;code&gt;length:&lt;/code&gt; names.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An array C answers that is null&lt;/strong&gt; is &lt;code&gt;None&lt;/code&gt; for an &lt;code&gt;Option&lt;/code&gt;, an empty array where its length is
zero, and a stop otherwise; a negative length, or one past an &lt;code&gt;int&lt;/code&gt;, stops the program; the
array is freed by &lt;code&gt;free:&lt;/code&gt; (a function or an expression in the array’s name, optional for memory
C keeps) after it is copied, and unread where a status fails. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether
&lt;code&gt;free:&lt;/code&gt; should be required with &lt;code&gt;array:&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Opaque values cross by value only&lt;/strong&gt;: a parameter, a result and a method’s &lt;code&gt;self&lt;/code&gt;, never through
a pointer, &lt;code&gt;inout&lt;/code&gt; or in an &lt;code&gt;Option&lt;/code&gt;; each object is its own, compared by identity, and
sendable, since it is an immutable copy. &lt;em&gt;Alternative&lt;/em&gt;: also &lt;code&gt;out&lt;/code&gt; and &lt;code&gt;const T *&lt;/code&gt;, which no
surveyed binding needs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-06: &lt;strong&gt;concurrency that waits is written as straight-line blocking
code, run on lightweight threads; Avin has no &lt;code&gt;async&lt;/code&gt; or &lt;code&gt;await&lt;/code&gt; keywords.&lt;/strong&gt; A lightweight thread
is a runtime-scheduled thread with a stack of its own; a few operating system threads, about one
per core, run whichever are ready. A call that would wait (a socket read, &lt;code&gt;Future.await&lt;/code&gt;, a
channel, &lt;code&gt;sleep&lt;/code&gt;, a lock) parks only its lightweight thread: the runtime records what it waits
on (a socket through the runtime’s poller over kqueue or epoll, a future, a timer), and runs another on the
same operating system thread. &lt;code&gt;spawn&lt;/code&gt;, the futures’ pool and actors’ turns come to run on
lightweight threads, so the APIs that exist today keep their meaning and become cheap; a server
holds one lightweight thread or one actor per connection, and a connection that waits holds no
operating system thread. Concurrency stays explicit: &lt;code&gt;Future(body)&lt;/code&gt; to start work and &lt;code&gt;await()&lt;/code&gt;
on it, &lt;code&gt;Future.all&lt;/code&gt; and &lt;code&gt;Future.first&lt;/code&gt;, channels and &lt;code&gt;scope&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: no division of functions into those that may wait and those that may not, so one library
serves every caller and any function at any depth may wait; an ordinary call allocates nothing;
existing code needs no change. &lt;em&gt;Alternatives&lt;/em&gt;: stackless &lt;code&gt;async&lt;/code&gt; functions compiled to state
machines (smaller per waiting task, in the hundreds of bytes, but every function on the path to
a wait marked &lt;code&gt;async&lt;/code&gt;, libraries split in two, and an actor’s state open to change at each
&lt;code&gt;await&lt;/code&gt;); &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; as sugar over lightweight threads (&lt;code&gt;async def&lt;/code&gt; a &lt;code&gt;Future&lt;/code&gt;, &lt;code&gt;await e&lt;/code&gt;
&lt;code&gt;e.await()&lt;/code&gt;), declined as a second spelling of what &lt;code&gt;Future&lt;/code&gt; already says.
&lt;em&gt;Consequences&lt;/em&gt;: a stack per lightweight thread, reserved large and committed as touched (at
least a page, 16 KB on arm64, per lightweight thread), with moving parked frames to the heap a
later reduction; the collector scans parked stacks; a C call that blocks holds its operating
system thread, as &lt;code&gt;blocking&lt;/code&gt; already accounts for.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;lightweight threads are time-sliced at
safepoints.&lt;/strong&gt; A lightweight thread that has run for its slice, 10 ms to begin with and tunable,
yields at its next safepoint poll and goes to the back of the ready queue, so threads that never
wait share a core instead of starving the others. A timer in the runtime raises the yield request
on the carrier running it; compiled code already polls a flag on every back edge of its control
flow and before every call that may recur, for the collector, and the same poll answers it, so a
thread that does not overrun pays nothing more. A wait still switches at once, and an actor’s
turn still ends after 16 messages. A long C call cannot be interrupted; &lt;code&gt;blocking&lt;/code&gt; lets another
carrier run in its place. Built with the scheduler core.
&lt;em&gt;Why&lt;/em&gt;: fairness for computation-heavy threads at no cost to the rest, from a poll that exists
already, with every interruption at a point where the roots are exact.
&lt;em&gt;Alternatives&lt;/em&gt;: switching only at waits (a long computation holds its carrier until it ends);
interrupting at any instruction by a signal (needs exact roots at every instruction, which the
shadow stacks give only at safepoints).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;The allocation chunk belongs to the carrier, a runtime record per operating system thread, and
a context reaches it through a pointer&lt;/strong&gt; (branch &lt;code&gt;lwt-carrier-chunk&lt;/code&gt;). &lt;code&gt;Context.carrier&lt;/code&gt; points at
the &lt;code&gt;Carrier&lt;/code&gt; the context runs on, which holds the &lt;code&gt;gc.Chunk&lt;/code&gt;; allocation reads
&lt;code&gt;ctx.carrier.chunk&lt;/code&gt;, one load more than before, and compiled code never touches the chunk, so
lowering is unchanged. Attaching a thread makes its carrier (a record that keeps itself alive)
and links it into a list of carriers beside the list of contexts, both under the heap lock;
detaching retires the chunk, unlinks the carrier and frees it, and detaching twice changes
nothing. A collection retires the chunk of every carrier rather than of every context. A
context’s &lt;code&gt;carrier&lt;/code&gt; is stored only while the context is safe, by one store, so a later
scheduler moves a lightweight thread between carriers without moving a chunk.
&lt;em&gt;Why&lt;/em&gt;: thousands of parked lightweight threads must hold no chunk each, and the chunk is a
property of the thread that is running, not of the code it runs. &lt;em&gt;Alternatives&lt;/em&gt;: the chunk kept
in the context and handed over at each switch (a copy of the chunk’s six words per switch, and
every parked context still sized for one); a thread-local carrier found through the platform’s
thread-local storage (no pointer in the context, but a thread-local access on every allocation,
dearer than one load); the carrier embedded in the thread’s own storage beside its context (no
separate record, but a carrier would then die with the context it was made beside, which is
wrong once contexts outnumber carriers).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;the scheduler is one ready queue under one lock, run by
workers started one at a time as threads become ready, up to one per processor.&lt;/strong&gt; A thread made
ready goes to the back of the queue; an idle worker sleeps on a condition and is woken for it, and
where none is idle and fewer workers than processors are counted, another is started. A worker is
an operating system thread with a carrier of its own that runs no compiled code itself: it switches
to a lightweight thread and back, and after the switch back does what the thread asked (let a
guard go, re-queue it, give its stack back). &lt;em&gt;Why&lt;/em&gt;: the simplest correct queue, with every wake in
the order threads became ready, and the lock is held for a few instructions. &lt;em&gt;Alternatives&lt;/em&gt;: a
queue per worker with stealing (less contention on many cores; more code, and no ordering
between workers), left for when a measurement asks for it; starting every worker at once (simpler
counting, but a program with one thread would start one per processor).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;a lightweight thread’s stack keeps &lt;code&gt;spawn&lt;/code&gt;‘s 8 MiB default,
reserved through &lt;code&gt;sysl.fiber&lt;/code&gt; and committed as touched, with 64 KiB at the least; the stacks of
ended threads are kept, 64 at most, for threads asking about the same size.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: the default
costs address space only, so every program that recursed deeply in a thread before still does,
and a reused stack saves a mapping and its guard per short thread. &lt;em&gt;Alternatives&lt;/em&gt;: a smaller
default such as 1 MiB (less address space at a hundred thousand threads, but deep recursion that
fitted in a thread would overflow); no reuse (a map and an unmap per thread). Review with the
user: the default is the knob most likely to want a different value once servers hold many
thousands of threads.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;lwt-stacks&lt;/code&gt;): &lt;strong&gt;a lightweight thread’s stack
stays one fixed reservation, 8 MiB unless &lt;code&gt;spawn&lt;/code&gt;‘s &lt;code&gt;stack&lt;/code&gt; asks otherwise and 64 KiB at the
least, and the runtime gives its pages back: the monitor trims a thread it has seen parked at two
ticks with no run between, down to 16 KiB below where it parked, and a stack kept for reuse is
trimmed to its top 16 KiB as its thread ends.&lt;/strong&gt; This settles the Open item on stack size and
growth. A worker marks a parked thread settled after it has switched away and lists it; the monitor
raises the thread’s &lt;code&gt;trimming&lt;/code&gt; mark and only then looks for it parked and settled, while a worker
about to run it marks it running and unsettled and only then waits for &lt;code&gt;trimming&lt;/code&gt; to fall, so a
trim never overlaps the thread’s next run. The release is &lt;code&gt;madvise(MADV_DONTNEED)&lt;/code&gt; on Linux; on
macOS that advice leaves the pages resident, so the range is mapped afresh in place
(&lt;code&gt;MAP_FIXED&lt;/code&gt;), which frees them at once (&lt;code&gt;runtime/avin/rt/__posix__/stack_release.c&lt;/code&gt;). A release
the system refuses leaves the range as it was, mapped and committed (a failed &lt;code&gt;madvise&lt;/code&gt; changes
nothing, and a fixed mapping the kernel cannot make puts the old one back), so the runtime only
counts it (&lt;code&gt;stack_releases_refused&lt;/code&gt;) and the thread goes on untrimmed; nothing traps. The
overflow trap is untouched: the guard and the report’s low end are the stack’s own, and a trimmed
stack still overflows at its end with &lt;code&gt;stack overflow&lt;/code&gt;. &lt;em&gt;Measured&lt;/em&gt; (macOS, arm64, 16 KiB pages,
&lt;code&gt;-O2&lt;/code&gt;, resident bytes per parked thread after its recursion returned): depth 0, 17 KB before and
after; depth 1,000, 66 KB before, 34 KB after; depth 10,000, 493 KB before, 34 KB after (1,000
threads: 470 MiB before, 32 MiB after). 100,000 shallow parked threads hold 1.6 GiB either way, a
page and a record each. Deepest recursion, main thread and spawned thread alike, unchanged: about
40,000 calls at &lt;code&gt;-O0&lt;/code&gt; and 50,000 at &lt;code&gt;-O2&lt;/code&gt; of a one-argument function. A two-thread rendezvous
ping-pong (two parks a round trip) and a start-and-join churn showed no slowdown beyond the
machine’s noise (round trip 1.0–2.1 µs after against 1.8–2.9 µs before, interleaved runs). A
&lt;code&gt;madvise&lt;/code&gt; of an 8 MiB stack costs about 20 µs on macOS whether or not its pages are resident, and
the fresh mapping about 0.3 µs, which is why the release is the mapping there and why it is done
by the monitor after a tick rather than at every park. &lt;em&gt;Alternatives&lt;/em&gt;: trimming at every park (a
system call a park, a third or more of a rendezvous round trip); stamping each park with the clock
(a clock read a park, where a run count is two stores); copying or segmented stacks that grow
(refused: C frames and the native frames the collector’s shadow stack points into cannot move,
and a segment boundary in a C call has nowhere to go); a soft guard page below where a thread
parked, unprotected by the fault handler when the thread goes deeper (refused: a system call
writing into that page first gets &lt;code&gt;EFAULT&lt;/code&gt; instead of a fault); moving parked frames to the heap
(the same objection as copying). Review with the user: the 8 MiB default and the 16 KiB kept below
a parked thread, and the name &lt;code&gt;stack&lt;/code&gt; of &lt;code&gt;spawn&lt;/code&gt;‘s size parameter, which the trimming makes less
pressing to change but which a server author may still want to set lower to bound address space.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;main&lt;/code&gt; stays on the program’s first operating system thread
and is not a worker; its waits block that thread.&lt;/strong&gt; Every wait has two forms: a lightweight thread
parks, and any other thread (the main thread, a thread attached for a callback) sleeps on one
shared condition until its own waiter is woken. &lt;em&gt;Why&lt;/em&gt;: the main thread stays free for the &lt;code&gt;ui&lt;/code&gt;
package, which must run on it, and a program whose &lt;code&gt;main&lt;/code&gt; never waits keeps its whole processor
count of workers. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;main&lt;/code&gt; as a lightweight thread run by a worker, with the first
operating system thread one of the workers (one kind of wait, but the &lt;code&gt;ui&lt;/code&gt; package would then need
a way to pin a thread to it, which is the open main-thread question).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;time-slicing answers at the existing poll by a second bit of
its flag.&lt;/strong&gt; &lt;code&gt;requested&lt;/code&gt; holds &lt;code&gt;Stop&lt;/code&gt; (1), raised by a collection, and &lt;code&gt;Yield&lt;/code&gt; (2), raised by the
monitor, a runtime thread that ticks every millisecond while a worker is busy, when a worker’s
thread has run 10 ms while another is ready; it also sets that worker’s own &lt;code&gt;yield_wanted&lt;/code&gt;. A poll
still loads the word and branches on zero; &lt;code&gt;avin_rt_safepoint&lt;/code&gt; waits out a &lt;code&gt;Stop&lt;/code&gt; and then, on a
worker whose flag is set, yields to the back of the queue, and lowers &lt;code&gt;Yield&lt;/code&gt; once no worker wants
it. Any lightweight thread yields at any poll, inside a lock or a callback too. &lt;em&gt;Why&lt;/em&gt;: compiled
code is unchanged and pays nothing while nothing overruns; while one does, the others’ polls take
the slow call for at most a tick. &lt;em&gt;Alternatives&lt;/em&gt;: a flag per carrier read through the context (no
spurious slow calls, but two loads per poll and a compiler change); not yielding inside a lock
(the lock’s waiters park anyway, so it buys nothing and lets one thread hold a worker).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;a blocking call is noticed, not announced: &lt;code&gt;enter_safe&lt;/code&gt;
marks the carrier blocked and counts the call, and the monitor releases a worker that has stayed
blocked across a whole tick while threads are ready.&lt;/strong&gt; A released worker is not counted against
the target, and another is woken from the spares or started; when the call returns the thread
runs on, and its worker rejoins the count at its next switch, or rests as a spare where the count
is full. This generalizes the pools’ &lt;code&gt;blocking&lt;/code&gt; compensation to every blocking binding, &lt;code&gt;sleep&lt;/code&gt;
and a wait for a &lt;code&gt;lazy val&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a call that returns within a tick costs two stores and starts
nothing, and the generated shims and every binding stay as they are. &lt;em&gt;Alternatives&lt;/em&gt;: compensating
at every blocking call (a thread start or wake per call, however short); a pool of threads for
blocking calls only (every such call a hand-off between threads).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;every lock and condition parks: &lt;code&gt;Mutex&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt; and
&lt;code&gt;Once&lt;/code&gt; as well as channels, futures, promises and joins.&lt;/strong&gt; The runtime’s one lock and one
condition, which all of them are built on, keep a queue of waiters; a lock let go goes straight to
its oldest waiter. The brief planned &lt;code&gt;Mutex&lt;/code&gt; and &lt;code&gt;Condition&lt;/code&gt; for the next step, keeping them
blocking until then. &lt;em&gt;Why&lt;/em&gt;: channels, futures’ cells and the pools are built on the very lock and
condition &lt;code&gt;Mutex&lt;/code&gt; uses, so keeping &lt;code&gt;Mutex&lt;/code&gt; blocking meant a second, temporary implementation of
both; and a &lt;code&gt;Mutex&lt;/code&gt; whose holder parks can then never hold every worker. &lt;em&gt;Alternatives&lt;/em&gt;: a parking
lock and condition beside the blocking ones, used by channels and futures only, until the next
step (two implementations, one to remove). Review with the user: it moves part of the next step
into this one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-scheduler&lt;/code&gt;): &lt;strong&gt;a context waits as the one waiter it holds&lt;/strong&gt;, since a thread
waits on one thing at a time; a timed wait of a lightweight thread is a timer the monitor fires,
added by the worker after the thread has switched away and taken off by the thread when it runs
again. &lt;em&gt;Why&lt;/em&gt;: no waiter is ever made per wait, and no waiter is reachable once its wait has
answered. &lt;em&gt;Alternatives&lt;/em&gt;: a waiter in the waiting function’s frame (the same, but its address is
a local’s, which Sysl’s escape check refuses to queue); a heap waiter per wait (an allocation per
wait).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;views and blocks are one object layout, the runtime’s
&lt;code&gt;CMemory&lt;/code&gt;, with their operations as intrinsics of &lt;code&gt;avin.c&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;ByteView&lt;/code&gt;, &lt;code&gt;MutByteView&lt;/code&gt; (a
subclass) and &lt;code&gt;ByteBlock&lt;/code&gt; (a subclass of &lt;code&gt;MutByteView&lt;/code&gt;) are library classes the compiler lays out as
the address, owner, length, closed flag, the two reasons they trap with and the lender; each
operation is a call of the runtime that checks the code running, the closed flag and the bounds, and
stops the program at the caller. &lt;em&gt;Why&lt;/em&gt;: a class holding an address in an Avin field could be made by
its public constructor with any address, since Avin has no private constructors; a layout only the
compiler and the runtime fill keeps every address one C lent or Avin allocated. &lt;em&gt;Alternatives&lt;/em&gt;: a
Sysl handle per view (the view could not keep its lender, an Avin object, alive); inline MIR for
every operation (more compiler, and a closed view’s reason is a string the runtime reports anyway).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;a view’s lengths and indices are &lt;code&gt;int&lt;/code&gt;s&lt;/strong&gt;, and a C length
past the greatest &lt;code&gt;int&lt;/code&gt;, or negative, stops the program at the call. &lt;em&gt;Why&lt;/em&gt;: arrays’ are &lt;code&gt;int&lt;/code&gt;s, so a
copy, a slice and an index mix with them without conversions; 2 GiB is more than a frame or a glyph.
&lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;long&lt;/code&gt; lengths (every index written &lt;code&gt;long(i)&lt;/code&gt;); &lt;code&gt;long&lt;/code&gt; lengths with &lt;code&gt;int&lt;/code&gt; indices
(a view longer than any index reaches). Review with the user: a library lending more than 2 GiB at
once would need &lt;code&gt;long&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;null lends &lt;code&gt;None&lt;/code&gt; in an &lt;code&gt;Option&lt;/code&gt; whatever the length, and
otherwise an empty view where the length is zero and a stop where it is not&lt;/strong&gt;, as arrays C answers
are. &lt;em&gt;Why&lt;/em&gt;: FreeType’s empty glyph is null with no rows, and a frame with no image may answer null
with a size of zero. &lt;em&gt;Alternative&lt;/em&gt;: null always a stop outside an &lt;code&gt;Option&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;a view belongs to the code owning its lender, and is lent
only by a method of a handle that is not &lt;code&gt;shared&lt;/code&gt;.&lt;/strong&gt; A view checks its lender’s owner at each use, so
handing the lender over (a thread’s body capturing the view or its frame) takes the view with it and
any other thread traps. &lt;em&gt;Why&lt;/em&gt;: closing a view is a write the lender’s next use makes, and reading
memory the lender’s next call may free; both must happen on one owner at a time, which a &lt;code&gt;shared&lt;/code&gt;
handle does not have. &lt;em&gt;Alternatives&lt;/em&gt;: an owner of the view’s own (a view handed over without its
lender would race the lender’s next use); &lt;code&gt;shared&lt;/code&gt; views closed under a lock (a lock per byte read).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;a failed status lends nothing and copies nothing, but is a
use of its receiver&lt;/strong&gt;, which closes the view lent before it. &lt;em&gt;Why&lt;/em&gt;: the call ran, and may have freed
the memory. &lt;em&gt;Alternative&lt;/em&gt;: closing only on success (a stale view after a failed conversion).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;the record &lt;code&gt;attach:&lt;/code&gt; gives C belongs to one handle object&lt;/strong&gt;:
later keeps through the same handle add to it, the handle lets go of it when its reference goes back,
and C holds it until &lt;code&gt;destroy&lt;/code&gt;; on an &lt;code&gt;attach:&lt;/code&gt; class every kept object, handles too, is held as its
Avin object, so a kept handle’s own C reference lives as long as the record. &lt;code&gt;key:&lt;/code&gt; may be left out
(a &lt;code&gt;char&lt;/code&gt; of the class’s own keys the record), and &lt;code&gt;attach:&lt;/code&gt; with &lt;code&gt;shared&lt;/code&gt; is refused. &lt;em&gt;Why&lt;/em&gt;: the
record’s slot is reused only once neither the handle nor C holds it, so a handle never updates
another’s record; holding kept handles as objects keeps their references alive past the holder’s
&lt;code&gt;close()&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: one record per C object, found through the library’s own getter (no
getter is named, and &lt;code&gt;attach:&lt;/code&gt; would need a second expression); C references for kept handles (given
back with the holder’s handle, while C still uses them). Review with the user: two Avin handles on
one C object each attach under the same key, so the second replaces the first’s record, and C’s
destroy of the first lets go of what the first kept while the first handle still keeps it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;ByteBlock&lt;/code&gt;‘s own constructor makes a block of no bytes,
passed to C as null&lt;/strong&gt;, and &lt;code&gt;ByteBlock(length)&lt;/code&gt; is the companion’s &lt;code&gt;apply&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a class has a
constructor, and the empty block is harmless where every index is out of range. &lt;em&gt;Alternative&lt;/em&gt;: an
abstract class with a factory (a block could not be named as the type &lt;code&gt;ByteBlock(n)&lt;/code&gt; makes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;c-bindings-buffers&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;bytes:&lt;/code&gt; is &lt;code&gt;array:&lt;/code&gt; for an &lt;code&gt;Array[byte]&lt;/code&gt;&lt;/strong&gt;, with &lt;code&gt;free:&lt;/code&gt;
where C allocated the bytes. &lt;em&gt;Why&lt;/em&gt;: the spec’s copy was the one-element case of the generalized
&lt;code&gt;array:&lt;/code&gt;; one path copies both. &lt;em&gt;Alternative&lt;/em&gt;: &lt;code&gt;bytes:&lt;/code&gt; with no &lt;code&gt;free:&lt;/code&gt; (a leak per call for a library
that allocates).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lock-turn-leak&lt;/code&gt;): &lt;strong&gt;a join answers only once
the ended thread keeps nothing alive&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;).
An ending lightweight thread detaches its context (its frames, which hold its closure and its
joint, stop being roots) and then marks its joint done and wakes its joiners, both under the heap
lock, so no collection runs between the two and the joint outlives its last use even when nothing
else reaches it. &lt;em&gt;Why&lt;/em&gt;: before, the joint was marked done first, so a collection right after a join
could still find the closure and the joint through the ended thread’s frame; a program saw its
memory freed one collection late, and a runtime test asserting an empty heap after a join failed
under load. &lt;em&gt;Alternatives&lt;/em&gt;: keep the old order and promise only that an ended thread’s objects are
collected eventually (weaker, and visible to any program measuring its heap); or clear the frame’s
slots before marking the joint done (the joint, then reachable from nothing for a thread nobody
joins, could be collected while the ending thread still writes to it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-timers&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;sleep&lt;/code&gt; parks a lightweight thread on a timer, and the
monitor thread fires the timers.&lt;/strong&gt; &lt;code&gt;sleep&lt;/code&gt; in a lightweight thread parks it with no guard and a
timer at its deadline, as a timed wait parks, so its worker runs other threads; &lt;code&gt;main&lt;/code&gt; and other
threads that are not lightweight block, safe for the collector. The monitor, which already wakes
once a tick while any worker is busy and sleeps until the soonest timer while none is, fires the
timers that are due. &lt;em&gt;Why&lt;/em&gt;: the monitor exists, already fires timed waits and already sleeps until
the soonest one, so sleeps need no thread of their own and no new wake-up path; a sleep is never
more than a tick late while workers are busy. &lt;em&gt;Alternatives weighed&lt;/em&gt;: the poller’s timeout (the
poller of sockets, step 4, is not built yet; once it is, its wait could take the soonest timer as
its timeout and the monitor could hand timers over, which this choice does not preclude); a timer
thread of its own (one more operating system thread doing what the monitor does); keeping &lt;code&gt;sleep&lt;/code&gt;
a blocking call that the monitor compensates for (a worker per sleeper, which is what the
lightweight threads are for). Review with the user only if sleep precision under 1 ms matters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;lwt-timers&lt;/code&gt;): &lt;strong&gt;the timers are a binary heap of waiters keyed by deadline, ties
broken by the order they were set, each waiter keeping its place in the heap.&lt;/strong&gt; Adding, firing and
cancelling a timer each cost O(log n) under the timer lock, and reading the soonest is O(1);
threads whose time runs out together are made ready soonest first, and two due at the same
microsecond in the order they began waiting. A timed wait that its event ends first takes its own
timer off when it runs again (its place makes that one step, not a search); the timer and the
event race on the waiter’s state, and only the one that changes it from pending makes the thread
ready, so a wait answers exactly once and leaves no timer behind. &lt;em&gt;Why&lt;/em&gt;: the linear list cost a
scan per cancel and per tick, which ten thousand sleepers turn into a hundred million steps a
second; a heap of the waiters themselves needs no allocation per timer beyond the heap’s array.
&lt;em&gt;Alternatives weighed&lt;/em&gt;: a hierarchical timing wheel (O(1) add and cancel, but a tick-quantized
deadline and more machinery than a heap that is already fast at this scale); a sorted list (O(n)
insertion); a heap without places (cancel would search, O(n)).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;unix-sockets&lt;/code&gt;): Unix domain sockets in &lt;code&gt;avin.net&lt;/code&gt;: &lt;code&gt;UnixStream&lt;/code&gt; and
&lt;code&gt;UnixListener&lt;/code&gt; mirror &lt;code&gt;TcpStream&lt;/code&gt; and &lt;code&gt;TcpListener&lt;/code&gt;, sharing the read-ahead code (&lt;code&gt;read&lt;/code&gt;,
&lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;) through one private class both hold; &lt;code&gt;UnixListener.bind(path)&lt;/code&gt; fails with
&lt;code&gt;AlreadyExists&lt;/code&gt; where anything is at the path, and the separate &lt;code&gt;bindReplacing(path)&lt;/code&gt; removes a
socket file nobody listens on (a probing connection is refused) before binding, leaving a live
listener’s path and any non-socket file alone; &lt;code&gt;close()&lt;/code&gt; leaves the socket file; a path the
platform cannot carry (103 bytes on macOS, 107 on Linux) is an &lt;code&gt;Err&lt;/code&gt; with the platform’s
message, and a connect to a path with nothing at it is &lt;code&gt;NotFound&lt;/code&gt;. Waits are the TCP ones: blocking
bindings that park the lightweight thread’s carrier as TCP’s do, with no poller integration.
WHY: a daemon and its command-line client need a local socket with the API they already know from
TCP; silently deleting an existing path could remove another program’s live socket or an unrelated
file, so the safe &lt;code&gt;bind&lt;/code&gt; refuses and the replacing form is explicit. Alternatives weighed: &lt;code&gt;bind&lt;/code&gt;
always removing a stale file (a surprise on a path that is a live socket or not a socket at all);
&lt;code&gt;close()&lt;/code&gt; removing the file (wrong for a listener handed between threads, and a second program may
already have replaced it); one shared &lt;code&gt;Stream&lt;/code&gt; trait over TCP and Unix (no use yet, and the
language’s traits would add a dispatch to every read). Review with the user: &lt;code&gt;bindReplacing&lt;/code&gt;‘s probe
connection is seen by a live listener as an immediately closed connection.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Open files in &lt;code&gt;avin.fs&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;fs-file&lt;/code&gt;, for the job manager’s log following and event log; the
&lt;a href=&quot;/spec/system-library/#open-files&quot;&gt;system library&lt;/a&gt; chapter has the surface). Each choice below the
spec did not settle, each settled on the user’s delegation 2026-11-06. Review with the user: the first two (a &lt;code&gt;File&lt;/code&gt; kept to one thread, and no seek from the end).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;the type is &lt;code&gt;File&lt;/code&gt;, opened by &lt;code&gt;fs.open&lt;/code&gt;, &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt;, &lt;code&gt;openUpdate&lt;/code&gt; and
&lt;code&gt;createUpdate&lt;/code&gt;.&lt;/strong&gt; WHY: the five modes cover every combination a program asks for, named for what
happens to what is already there, as Sysl names them, and the whole-file functions keep their names.
ALTERNATIVES: an &lt;code&gt;OpenMode&lt;/code&gt; argument (one function, but a mode a program can get wrong at runtime
and a longer call for the common case); only read, create and append (no way to overwrite part of a
file).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;a &lt;code&gt;File&lt;/code&gt; is not &lt;code&gt;Sendable&lt;/code&gt;.&lt;/strong&gt; WHY: its Sysl handle belongs to the thread that opened it,
and a program that wants another thread to use a file opens it there; &lt;code&gt;TcpStream&lt;/code&gt;‘s hand-over
machinery buys nothing for a file a program can reopen. ALTERNATIVES: make it &lt;code&gt;Sendable&lt;/code&gt; with the
owner check a &lt;code&gt;TcpStream&lt;/code&gt; has. Review with the user if a file must move between actors.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;seeking is from the start only, plus &lt;code&gt;seekToEnd()&lt;/code&gt;; a negative offset is an &lt;code&gt;Err&lt;/code&gt;, a
seek past the end is allowed.&lt;/strong&gt; WHY: following a log needs “start at the end”, and a tail needs
absolute offsets, which &lt;code&gt;size()&lt;/code&gt; gives; offsets back from the end are &lt;code&gt;size() - n&lt;/code&gt;, with no second
vocabulary. ALTERNATIVES: a &lt;code&gt;Whence&lt;/code&gt; argument; a signed offset meaning from the end.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;&lt;code&gt;readLine&lt;/code&gt; answers an unterminated last line; &lt;code&gt;readCompleteLine&lt;/code&gt; does not, and leaves
the partial line unread.&lt;/strong&gt; WHY: a file followed while another program writes it shows half a line
at some moment, and a follower must not act on it; a file read to its end wants the last line even
with no &lt;code&gt;\n&lt;/code&gt;. ALTERNATIVES: one &lt;code&gt;readLine&lt;/code&gt; with the first meaning (torn lines when following), or
the second (the last line of a file with no final newline lost).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;&lt;code&gt;read(max)&lt;/code&gt; and the line calls share one buffer of the &lt;code&gt;File&lt;/code&gt;‘s own, and &lt;code&gt;position()&lt;/code&gt;
is the logical position (the file’s, minus what is buffered and unread).&lt;/strong&gt; WHY: lines need a
buffer, and &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;seek&lt;/code&gt; and &lt;code&gt;write&lt;/code&gt; have to agree with it. A &lt;code&gt;write&lt;/code&gt; or &lt;code&gt;seek&lt;/code&gt; gives the
buffered bytes back first. ALTERNATIVES: separate byte and line modes (a program mixing them gets
surprises).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;a read at the end is not sticky.&lt;/strong&gt; WHY: following a growing file is the point; the next
read asks the file again. ALTERNATIVES: a latched end that &lt;code&gt;seek&lt;/code&gt; clears (Sysl’s own flag is not
used).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;misuse is an &lt;code&gt;Err&lt;/code&gt;, not a trap: a call on a closed file, a read of a write-only file,
a write to a read-only one, a negative seek offset; a negative &lt;code&gt;max&lt;/code&gt; or &lt;code&gt;count&lt;/code&gt; or tail size traps&lt;/strong&gt;
like &lt;code&gt;TcpStream.read&lt;/code&gt;‘s, being a program mistake at the call. WHY: the first group depends on the
state the program’s files are in at runtime. The &lt;code&gt;Err&lt;/code&gt; for those is &lt;code&gt;Other&lt;/code&gt; with a plain sentence,
as &lt;code&gt;TcpStream&lt;/code&gt;‘s closed connection is. ALTERNATIVES: a dedicated &lt;code&gt;IoError&lt;/code&gt; variant for a closed file
(more to match on for a rare case).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;&lt;code&gt;readTail(file, maxBytes)&lt;/code&gt; answers text, begins at a whole character, and replaces
invalid bytes with U+FFFD; &lt;code&gt;readTailLines(file, count)&lt;/code&gt; answers lines.&lt;/strong&gt; WHY: the caller wants to
print or search the end of a log, where a cut character is garbage and an invalid byte elsewhere
should not refuse the whole tail. A start inside a UTF-8 sequence skips the rest of that sequence
(continuation bytes), never reading earlier bytes to complete it, so exactly the bytes asked for
or fewer come back. ALTERNATIVES: back up to include the whole character (more than &lt;code&gt;maxBytes&lt;/code&gt;);
answer bytes and leave decoding to the caller; &lt;code&gt;InvalidUtf8&lt;/code&gt; for a cut start.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;opening a directory for reading or updating is &lt;code&gt;IsADirectory&lt;/code&gt;.&lt;/strong&gt; WHY: the platform
opens a directory for reading and fails only at the first read, which would show up as an
unexplained failed read. ALTERNATIVES: leave it to the read.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;the calls do not park a lightweight thread.&lt;/strong&gt; WHY: the whole-file &lt;code&gt;avin.fs&lt;/code&gt; calls do
not either, and a regular file’s read does not wait for a peer. ALTERNATIVES: bind them
&lt;code&gt;blocking&lt;/code&gt; (needed only for files on a stalled network mount).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;(Superseded by the Proposed entry &lt;strong&gt;JSON is &lt;code&gt;avin.json&lt;/code&gt; in the standard library&lt;/strong&gt;.) Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;JSON is the package &lt;code&gt;json&lt;/code&gt;, in &lt;code&gt;packages/json&lt;/code&gt; of this repository,
module &lt;code&gt;json&lt;/code&gt;, rather than &lt;code&gt;avin.json&lt;/code&gt; in the standard library&lt;/strong&gt; (&lt;a href=&quot;/spec/json/&quot;&gt;JSON&lt;/a&gt;). Why: the
system library chapter already says JSON is a package of its own; the package mechanism reads a
path dependency and a git dependency on a directory of a repository (&lt;code&gt;//packages/json&lt;/code&gt;), as the
&lt;code&gt;ui&lt;/code&gt; package is reached; and a domain library outside the standard library keeps the compiler’s
library small. Alternatives weighed: &lt;code&gt;avin.json&lt;/code&gt; in the standard library (contradicts the system
library chapter, and every compiler release would carry it); a repository &lt;code&gt;avin-lang/json&lt;/code&gt; of its
own (premature while the derivation templates it is to carry are still being built in this one).
Review with the user: whether JSON should after all ship with the compiler, since marshal and most
services need it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;a JSON number is a &lt;code&gt;Long&lt;/code&gt; when the text writes a whole number that
fits a &lt;code&gt;long&lt;/code&gt;, and a &lt;code&gt;Real&lt;/code&gt; otherwise; a &lt;code&gt;Real&lt;/code&gt; is always written with a fraction or an
exponent.&lt;/strong&gt; Why: identifiers, counts and sizes stay exact past 2^53; writing &lt;code&gt;1.0&lt;/code&gt; rather than &lt;code&gt;1&lt;/code&gt;
makes &lt;code&gt;parse(render(j)) == j&lt;/code&gt; for every finite value, kind included. &lt;code&gt;-0&lt;/code&gt; is the &lt;code&gt;Long&lt;/code&gt; 0 (a whole
number, and a &lt;code&gt;long&lt;/code&gt; has no minus zero); &lt;code&gt;-0.0&lt;/code&gt; is the &lt;code&gt;Real&lt;/code&gt; minus zero. A whole number beyond a
&lt;code&gt;long&lt;/code&gt; is a &lt;code&gt;Real&lt;/code&gt;, rounded. The &lt;code&gt;Real&lt;/code&gt; form follows the usual shortest-digits rule, written out
from 1e-6 up to 1e21 and with an exponent outside. Alternatives weighed: one &lt;code&gt;Num(real)&lt;/code&gt; (loses
integers beyond 2^53); keeping a number’s text (&lt;code&gt;Num(text)&lt;/code&gt;, exact for any size but every reader
parses again); a third &lt;code&gt;Big(digits)&lt;/code&gt; variant for integers beyond a &lt;code&gt;long&lt;/code&gt; (exact, at the cost of a
case every match must handle). Review with the user: the variant names &lt;code&gt;Long&lt;/code&gt;, &lt;code&gt;Real&lt;/code&gt;, &lt;code&gt;Str&lt;/code&gt;,
&lt;code&gt;Arr&lt;/code&gt;, &lt;code&gt;Obj&lt;/code&gt; (chosen because &lt;code&gt;Array&lt;/code&gt; is a built-in type’s name and &lt;code&gt;String&lt;/code&gt;/&lt;code&gt;Object&lt;/code&gt; read as
types), and the companion’s &lt;code&gt;obj&lt;/code&gt;/&lt;code&gt;arr&lt;/code&gt;/&lt;code&gt;str&lt;/code&gt;/&lt;code&gt;num&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;a number too large to be a finite &lt;code&gt;real&lt;/code&gt; is an error, and a NaN or an
infinity is written &lt;code&gt;null&lt;/code&gt;.&lt;/strong&gt; Why: a &lt;code&gt;Real&lt;/code&gt; holding an infinity cannot be written back as JSON, so
accepting &lt;code&gt;1e400&lt;/code&gt; would break the round trip; writing &lt;code&gt;null&lt;/code&gt; keeps &lt;code&gt;render&lt;/code&gt; total, as most writers
do. Alternatives weighed: reading &lt;code&gt;1e400&lt;/code&gt; as an infinity; trapping when writing a non-finite value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;an object keeps every member, a key written twice included, and &lt;code&gt;get&lt;/code&gt;
and &lt;code&gt;apply&lt;/code&gt; answer the last.&lt;/strong&gt; Why: reading is lossless and the order is the document’s, which a
log or a configuration file shown back to a person needs; the last-wins lookup is what most
readers do. Lookup is a scan from the end, which is fast for the objects a protocol carries.
Alternatives weighed: refusing a duplicate key (strict, but RFC 8259 allows it); the first one
winning; members in a &lt;code&gt;Map&lt;/code&gt; (fast lookup, loses order or needs an ordered map).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;arrays and objects nest at most 512 deep unless &lt;code&gt;parse&lt;/code&gt; is given
another limit, a scalar being 0 deep.&lt;/strong&gt; Why: the reader is recursive, and a hostile document of a
million &lt;code&gt;[&lt;/code&gt; would otherwise end in a stack overflow trap; 512 is far beyond any real document and
far inside a lightweight thread’s 8 MiB stack. Alternatives weighed: no limit; an iterative reader
with no limit (more code, and the values built are still recursive to write); 1000 or 10000.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;a lone surrogate escape is an error.&lt;/strong&gt; Why: a &lt;code&gt;string&lt;/code&gt; holds only
characters, and U+D800 is not one. Alternatives weighed: replacing it with U+FFFD (silent loss);
carrying it as WTF-8 (a string that is not UTF-8).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;an error’s line ends at a line feed only and its column counts
characters; it also carries the byte offset.&lt;/strong&gt; Why: the line feed is the only line end JSON text
ordinarily has, a &lt;code&gt;\r\n&lt;/code&gt; counts the same, and counting characters matches what an editor shows.
The place is counted out only when an error is made, so reading pays nothing for it.
Alternatives weighed: a lone carriage return also ending a line; columns in bytes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;the accessors answer &lt;code&gt;Option&lt;/code&gt;s, &lt;code&gt;apply&lt;/code&gt; traps, and &lt;code&gt;asLong&lt;/code&gt; takes a
&lt;code&gt;Real&lt;/code&gt; that is a whole number within a &lt;code&gt;long&lt;/code&gt;.&lt;/strong&gt; Why: Options chain with &lt;code&gt;?&lt;/code&gt; in a function
answering an &lt;code&gt;Option&lt;/code&gt; (&lt;code&gt;j.get(&amp;quot;a&amp;quot;)?.get(&amp;quot;b&amp;quot;)?.asInt()&lt;/code&gt;), and &lt;code&gt;apply&lt;/code&gt; is for a member the program
knows is there, as a map’s is; a producer writing &lt;code&gt;3.0&lt;/code&gt; for a count is common. Alternatives
weighed: a missing member answering &lt;code&gt;Null&lt;/code&gt; (confuses absent with null); a cursor type with its
own errors (a later layer, which the derivation’s &lt;code&gt;JsonReader&lt;/code&gt; covers).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;(JSON’s tests have since moved to &lt;code&gt;library/tests&lt;/code&gt;; see the Proposed entry &lt;strong&gt;JSON is &lt;code&gt;avin.json&lt;/code&gt; in the standard library&lt;/strong&gt;. The rule stands for any later package with tests.) Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;json&lt;/code&gt;): &lt;strong&gt;the corpus runs every package under &lt;code&gt;packages/&lt;/code&gt; that has a &lt;code&gt;tests&lt;/code&gt;
directory, with &lt;code&gt;avin test&lt;/code&gt; at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;.&lt;/strong&gt; Why: a package’s tests are what &lt;code&gt;avin test&lt;/code&gt;
runs in it, and the repository’s own packages must be gated like the core library is. A package
whose behaviour needs a window (&lt;code&gt;ui&lt;/code&gt;) has no such directory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;process-control&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;Child&lt;/code&gt;‘s process ids are recorded, and read by
any thread&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;). &lt;code&gt;pid()&lt;/code&gt;, &lt;code&gt;group()&lt;/code&gt;, &lt;code&gt;signal&lt;/code&gt; and
&lt;code&gt;signalGroup&lt;/code&gt; read atomics the starting code writes as each program starts, never the command’s
handles, which belong to one thread, so a job manager can signal a child another thread is waiting
for. &lt;code&gt;pid()&lt;/code&gt; is the program started last (a pipeline’s last stage, a sequence’s latest part, as a
shell’s &lt;code&gt;$!&lt;/code&gt; is), and &lt;code&gt;signal&lt;/code&gt; reaches that one program; &lt;code&gt;kill&lt;/code&gt; remains the call that reaches
every program and stops a sequence. A command seen to have ended is refused with the platform’s
“No such process” rather than signalled, since its id may have been given again; one that ended
unseen is a zombie the signal reaches harmlessly. Alternatives: &lt;code&gt;signal&lt;/code&gt; through the owner, which
traps on a child another thread waits for (what the marshal survey met); a &lt;code&gt;signal&lt;/code&gt; reaching every
program, which needs every program’s id kept and the job’s handles’ state shared; &lt;code&gt;pid()&lt;/code&gt; as an
&lt;code&gt;Option&lt;/code&gt;, rather than &lt;code&gt;0&lt;/code&gt; for a command whose time ran out before it started a program.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;process-control&lt;/code&gt;): &lt;strong&gt;One group per command, and &lt;code&gt;signalGroup&lt;/code&gt; without
one is an &lt;code&gt;Err&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;). &lt;code&gt;inNewGroup()&lt;/code&gt; puts every program
of the command in one group its first program leads, the outermost setting deciding; a sequence’s
later part whose group has emptied leads a new one (joining a gone group is refused by the
platform), and &lt;code&gt;group()&lt;/code&gt; follows it. &lt;code&gt;signalGroup&lt;/code&gt; on a command with no group of its own is
&lt;code&gt;Err(Other(&amp;quot;the command has no group of its own&amp;quot;))&lt;/code&gt;, never a signal to the program’s own group,
and it still signals after the command ended, since a group outlives its leader while anything it
started is left: the case a job manager kills for. Alternatives: a trap for &lt;code&gt;signalGroup&lt;/code&gt; without a
group (a daemon would die of a missed setting); a group per part; refusing the later part.
&lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;signalGroup&lt;/code&gt; should trap.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;process-control&lt;/code&gt;): &lt;strong&gt;Standard error is redirected as output is&lt;/strong&gt;
(&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;): &lt;code&gt;errorsToFile&lt;/code&gt;, &lt;code&gt;errorsAppendTo&lt;/code&gt; and
&lt;code&gt;errorsToOutput()&lt;/code&gt;, the last sharing the output’s open file (one offset, so neither stream
truncates or overwrites the other), going into what &lt;code&gt;output()&lt;/code&gt; and &lt;code&gt;lines()&lt;/code&gt; capture, and, where
the output is the program’s own, opening &lt;code&gt;/dev/stdout&lt;/code&gt; to append. On a pipeline every stage’s
errors go to the pipeline’s redirection. The redirections apply output first whatever the order
they were called in. Alternatives: one &lt;code&gt;bothToFile(file)&lt;/code&gt; (a second name for a pair of calls);
&lt;code&gt;Stdio&lt;/code&gt;-like values passed to one &lt;code&gt;withStreams&lt;/code&gt;; &lt;code&gt;2&amp;gt;&amp;amp;1&lt;/code&gt; read as the output at the point of the call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;process-control&lt;/code&gt;): &lt;strong&gt;Signals are watched in &lt;code&gt;avin.signal&lt;/code&gt;, and a wait
looks every 20 ms&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#avinsignal&quot;&gt;&lt;code&gt;avin.signal&lt;/code&gt;&lt;/a&gt;). The platform’s facility
is a counted flag, so &lt;code&gt;wait()&lt;/code&gt; parks its lightweight thread and looks again every 20 milliseconds,
the latency bound; &lt;code&gt;take()&lt;/code&gt; asks once. Constants are &lt;code&gt;val&lt;/code&gt;s named for what they mean (&lt;code&gt;Terminate&lt;/code&gt;,
&lt;code&gt;Interrupt&lt;/code&gt;, &lt;code&gt;Hangup&lt;/code&gt;, &lt;code&gt;User1&lt;/code&gt;…), the user ones numbered by the runtime for the platform; sending
stays in &lt;code&gt;avin.process&lt;/code&gt; beside the process ids it takes. Alternatives: the POSIX short names
(&lt;code&gt;TERM&lt;/code&gt;), against Avin’s naming; a &lt;code&gt;data Signal&lt;/code&gt; (a closed set, while numbers are open, and
&lt;code&gt;ExitStatus.Signalled&lt;/code&gt; speaks &lt;code&gt;int&lt;/code&gt;); a wake from the handler through the scheduler, which needs a
runtime handler that is async-signal-safe, for a latency no program has needed yet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;nested-literal-typing&lt;/code&gt;): &lt;strong&gt;A number literal nested in an argument takes the
numbers the other arguments decide&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;). An argument that is
or holds an integer literal (a collection literal, a tuple, or a call other than a conversion
such as &lt;code&gt;long(1)&lt;/code&gt;, with such a part) is checked after the arguments that hold none, against the
type they decided so far, and an expression of literals alone (a literal, or an operation or &lt;code&gt;if&lt;/code&gt;
on such expressions) after both, so &lt;code&gt;assertEq(count(Box(1)), 1_000_000_000_000 + 1)&lt;/code&gt; with a &lt;code&gt;long&lt;/code&gt;
result is a &lt;code&gt;long&lt;/code&gt; whichever is written first. Where the decided type would otherwise be left open
so a later argument may widen it, the argument is given its shape with the value types and every
invariant type argument kept, and every class or other reference leaf at a covariant place left
open. So &lt;code&gt;assertEq(f(), [1, 2])&lt;/code&gt; with &lt;code&gt;f() -&amp;gt; Vector[long]&lt;/code&gt; is a
&lt;code&gt;Vector[long]&lt;/code&gt;, while &lt;code&gt;same(dogs, [Cat(2)])&lt;/code&gt; still joins to a &lt;code&gt;Vector[Animal]&lt;/code&gt;. Why: the chapter
already says a literal takes the type the other arguments decide, and a literal one level down is
the same literal to a reader. Two limits, chosen as the smallest rule: of two arguments that
both hold literals, the first written decides for the second (&lt;code&gt;same((1, x), (x, 2))&lt;/code&gt; for
&lt;code&gt;x: long&lt;/code&gt; is an error, where a part-by-part solution would type it); and choosing an overload
checked a nested literal once at its own type where the candidates’ parameters differ. Review
with the user: whether the first limit is worth lifting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposed (branch &lt;code&gt;fix-literal-expected&lt;/code&gt;, 2026-11-14): the second limit is lifted.&lt;/strong&gt; Choosing an
overload checks a value built around number literals by itself first, as before; where that
leaves no candidate fitting (or it does not check by itself, as &lt;code&gt;[5_000_000_000]&lt;/code&gt; does not), it is
checked against each candidate’s parameter instead, with the type arguments the receiver, the
lower bounds and the other arguments decide, as a bare literal is. So &lt;code&gt;kind(Some(1))&lt;/code&gt; beside
&lt;code&gt;kind(o: Option[long])&lt;/code&gt; and &lt;code&gt;kind(o: Option[string])&lt;/code&gt; is the &lt;code&gt;long&lt;/code&gt; one, and &lt;code&gt;longs ++ [400]&lt;/code&gt;,
which met two overloads of &lt;code&gt;++&lt;/code&gt; (&lt;code&gt;Vector[W]&lt;/code&gt; and &lt;code&gt;Iterable[W]&lt;/code&gt; with &lt;code&gt;W &amp;gt;: long&lt;/code&gt;), is a
&lt;code&gt;Vector[long]&lt;/code&gt; (found writing marshal). Where the literal fits candidates at its own type, the
choice is unchanged, so &lt;code&gt;own([1])&lt;/code&gt; beside &lt;code&gt;Vector[int]&lt;/code&gt; and &lt;code&gt;Vector[long]&lt;/code&gt; stays the &lt;code&gt;int&lt;/code&gt; one.
With it, a reference type that takes integers or decimals (&lt;code&gt;BigInt&lt;/code&gt;, &lt;code&gt;BigDecimal&lt;/code&gt;, a type
implementing &lt;code&gt;FromInteger&lt;/code&gt;) is kept in the expected type a literal argument gets, as a number is,
so &lt;code&gt;pair(cents, [3])&lt;/code&gt; for &lt;code&gt;pair[T](a: Vector[T], b: Vector[T])&lt;/code&gt; builds &lt;code&gt;Cents&lt;/code&gt; where it had built
an &lt;code&gt;int&lt;/code&gt;. Why: a literal one level down is the same literal to a reader, and an operator method
on a collection is the commonest place it meets overloads. Alternatives: checking against each
candidate first (would change which overload &lt;code&gt;own([1])&lt;/code&gt; picks, and is ambiguous where both
take it); trying candidates by the literal’s structure only (more code, same result).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;stdout-flush-isnan&lt;/code&gt;): &lt;strong&gt;standard output gets an explicit &lt;code&gt;flush()&lt;/code&gt;; reading flushes it; &lt;code&gt;real&lt;/code&gt; gets &lt;code&gt;isNaN&lt;/code&gt;, &lt;code&gt;isInfinite&lt;/code&gt; and &lt;code&gt;isFinite&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;flush()&lt;/code&gt; is a prelude function and a method on &lt;code&gt;StandardOutput&lt;/code&gt; and &lt;code&gt;StandardError&lt;/code&gt; (a no-op beyond flushing output, as error keeps no buffer); a read of standard input that must wait flushes output first. The classifiers are methods on &lt;code&gt;real&lt;/code&gt; in &lt;code&gt;avin&lt;/code&gt;, written in Avin (&lt;code&gt;self != self&lt;/code&gt;; comparison with the infinities; &lt;code&gt;self - self == 0.0&lt;/code&gt;); &lt;code&gt;real.NaN&lt;/code&gt;, &lt;code&gt;real.PositiveInfinity&lt;/code&gt; and &lt;code&gt;real.NegativeInfinity&lt;/code&gt; already existed, and &lt;code&gt;real&lt;/code&gt; is the only floating type. WHY: a drawing program must push a frame without a newline, and a prompt must be seen before the wait; the methods read as &lt;code&gt;char&lt;/code&gt;‘s do, where the &lt;code&gt;avin.math&lt;/code&gt; functions are not methods. ALTERNATIVES: a &lt;code&gt;Writer.flush&lt;/code&gt; on the trait (every writer would need a meaning); flushing only on &lt;code&gt;print&lt;/code&gt; (defeats buffering); &lt;code&gt;math.isNaN(x)&lt;/code&gt; functions (the spec keeps &lt;code&gt;avin.math&lt;/code&gt; for elementary functions). Review with the user if a &lt;code&gt;Writer&lt;/code&gt;-level &lt;code&gt;flush&lt;/code&gt; is wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;exit-hooks&lt;/code&gt;): &lt;strong&gt;Exit hooks are &lt;code&gt;process.onExit(@sendable body: () -&amp;gt; unit) -&amp;gt; ExitHook&lt;/code&gt;, with &lt;code&gt;cancel() -&amp;gt; bool&lt;/code&gt;, run newest first and once each&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#exit-hooks&quot;&gt;exit
hooks&lt;/a&gt;). Why: a library that changes the world outside the
program (tui’s raw mode and alternate screen) must put it back on every ending, and the language
has no &lt;code&gt;finally&lt;/code&gt; or &lt;code&gt;defer&lt;/code&gt;; a hook per change, cancelled when the change is undone normally, is
the smallest shape, and newest first undoes changes in the reverse of the order they were made.
Alternatives: one global handler to set (libraries would overwrite each other); a &lt;code&gt;defer&lt;/code&gt;
construct (scoped to a frame, so it cannot run on a trap or an &lt;code&gt;exit&lt;/code&gt; from another thread);
oldest first.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;exit-hooks&lt;/code&gt;): &lt;strong&gt;The thread that ends the program runs the hooks&lt;/strong&gt;: the main
thread when &lt;code&gt;main&lt;/code&gt; returns, the thread calling &lt;code&gt;exit&lt;/code&gt;, the trapping thread after its report
(an escalated actor failure and running out of memory included), a test’s process as a program.
The other threads go on running meanwhile; one that traps or calls &lt;code&gt;exit&lt;/code&gt; waits for the end
silently, the first ending being the program’s. So the body is &lt;code&gt;@sendable&lt;/code&gt;. Why: a trap on another
thread cannot hand work to the main thread, which may be blocked or be the one that trapped, and
stopping every other thread first would stop the threads a hook needs (a future’s pool) or leave
them stopped holding locks. Alternatives: always on the main thread (impossible when it is the
one waiting or trapping); stopping the other threads first; hooks free to capture anything
(a data race with the threads still running). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether a hook should
rather be allowed to capture non-sendable state from the main thread for the common case.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;exit-hooks&lt;/code&gt;): &lt;strong&gt;A hook that traps or calls &lt;code&gt;exit&lt;/code&gt; never goes on, and the hooks
after it still run&lt;/strong&gt;, on top of its stack rather than after unwinding it (the runtime’s frames
hold counted values a jump past them would leak). The trap is reported as &lt;code&gt;avin: trap in an exit hook:&lt;/code&gt; and the program then ends as a trap ends it, even where &lt;code&gt;main&lt;/code&gt; returned or &lt;code&gt;exit&lt;/code&gt; was
called; an &lt;code&gt;exit&lt;/code&gt; in a hook keeps the status of the ending that ran the hooks. A trap in a hook
while a mutex is held stops the program at once, since a later hook may need what the lock
guards. Why: one bad hook must not keep the others from putting their state back, and a failed
cleanup must not end with a status that says success. Alternatives: a trap in a hook ends the
program at once; an &lt;code&gt;exit&lt;/code&gt; in a hook replaces the status (the last word wins, which a cleanup
should not have).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;exit-hooks&lt;/code&gt;): &lt;strong&gt;A hook registered while the hooks run runs too&lt;/strong&gt;, at once after
the one that registered it; &lt;code&gt;cancel()&lt;/code&gt; answers &lt;code&gt;false&lt;/code&gt; for a hook that has run or begun. Why: the
registry is a stack the runner pops, so a hook a cleanup registers is the newest. Alternative:
ignore registrations once the program is ending (silently drops cleanup a hook asked for).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;exit-hooks&lt;/code&gt;): &lt;strong&gt;No hook runs on a stack overflow or on an unwatched signal.&lt;/strong&gt;
A stack overflow is reported by a handler on its own small stack where no Avin code can run. A
signal the program does not watch keeps its platform action; a program that wants its hooks on
&lt;code&gt;Terminate&lt;/code&gt;, &lt;code&gt;Interrupt&lt;/code&gt; or &lt;code&gt;Hangup&lt;/code&gt; watches it and calls &lt;code&gt;exit&lt;/code&gt;, as tui already watches them.
Why: running hooks on an unwatched signal needs a watcher thread in every program with a hook, and
a library watch of its own would change what the signal does for the program, which
&lt;a href=&quot;/spec/system-library/#avinsignal&quot;&gt;&lt;code&gt;avin.signal&lt;/code&gt;&lt;/a&gt; promises it does not. Alternatives: the runtime
watches &lt;code&gt;Terminate&lt;/code&gt;, &lt;code&gt;Interrupt&lt;/code&gt; and &lt;code&gt;Hangup&lt;/code&gt; whenever a hook is registered and nothing else
watches them, ending with &lt;code&gt;exit(128 + sig)&lt;/code&gt; after the hooks; running hooks from the overflow
handler on a fresh stack (the thread may have overflowed inside a lock). &lt;strong&gt;Review with the
user&lt;/strong&gt;: the signals, if a program wants cleanup on Ctrl-C without watching for it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;generic-joins&lt;/code&gt;): &lt;strong&gt;Two tuples join part by part&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;).
&lt;code&gt;(Dog, long)&lt;/code&gt; and &lt;code&gt;(Cat, long)&lt;/code&gt; agree on &lt;code&gt;(Animal, long)&lt;/code&gt; wherever two types are joined: the
arguments of one type parameter, the branches of an &lt;code&gt;if&lt;/code&gt;, the arms of a &lt;code&gt;match&lt;/code&gt;, the elements of a
literal, and a tuple inside a covariant argument (&lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;). Each part joins as two
types alone do, so a part of an invariant type (&lt;code&gt;Array[Dog]&lt;/code&gt; beside &lt;code&gt;Array[Cat]&lt;/code&gt;) or two different
value types (&lt;code&gt;long&lt;/code&gt; beside &lt;code&gt;int&lt;/code&gt;) still have no join, nor have tuples of different sizes. Why: the
chapter already lists a tuple part among the places a value is read out, and two classes alone join;
a tuple of them failing to was an omission in the checker’s join, which handled classes and generic
types but not tuples. Alternatives: requiring the tuple type to be written (a contortion the class
case does not need). Nothing here deserves a conversation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;generic-joins&lt;/code&gt;): &lt;strong&gt;A number literal among values that agree on one type takes the
type the others decide&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;, &lt;a href=&quot;/spec/collections/#literals&quot;&gt;collections&lt;/a&gt;).
Among the elements of a collection literal, the keys or values of a map literal and the branches of
an &lt;code&gt;if&lt;/code&gt;, the values are checked in tiers, as a call’s arguments are: those holding no literal first,
then values built around a literal (&lt;code&gt;Some(2)&lt;/code&gt;, &lt;code&gt;(2, &amp;quot;b&amp;quot;)&lt;/code&gt;, &lt;code&gt;[2]&lt;/code&gt;), then expressions of literals alone
(&lt;code&gt;2&lt;/code&gt;, &lt;code&gt;2 * 3&lt;/code&gt;, &lt;code&gt;-5&lt;/code&gt;), then empty literals, each later tier given the shape of what the earlier agree
on with its value types kept and its classes left open. So &lt;code&gt;[long(1), 2]&lt;/code&gt;, &lt;code&gt;[2, long(1)]&lt;/code&gt; and
&lt;code&gt;if c then 2 else big&lt;/code&gt; are &lt;code&gt;long&lt;/code&gt;, and &lt;code&gt;[1.5, 2]&lt;/code&gt; is &lt;code&gt;Vector[real]&lt;/code&gt;. A &lt;code&gt;match&lt;/code&gt; arm takes part only
where it is an expression of literals alone, since an arm checked after the others would be checked
outside its pattern’s scope, and a value built around a literal may name a pattern’s binding.
Diagnostics for values with no common type still read in written order, at the later value. Why:
&lt;code&gt;types.md&lt;/code&gt; already says a literal takes its width from the other operand, and the literal chapter
says elements agree as an &lt;code&gt;if&lt;/code&gt;‘s branches do; &lt;code&gt;[long(1), 2]&lt;/code&gt; being an error while &lt;code&gt;long(1) + 2&lt;/code&gt; is
not read as a gap to programs. Alternatives: only the collection literal (leaves &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt;
stricter than the literal that is said to agree as they do); leaving each literal an inference
variable settled at its use (the alternative weighed for nested literals too, deferred for the
same reason); deferring every &lt;code&gt;match&lt;/code&gt; arm that holds a literal by re-entering its pattern’s scope
(more machinery for a rare shape). Review with the user: whether &lt;code&gt;match&lt;/code&gt; arms such as &lt;code&gt;Some(2)&lt;/code&gt;
beside &lt;code&gt;Some(big)&lt;/code&gt; should also agree.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;okor-command-message&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Option.okOr&lt;/code&gt; / &lt;code&gt;okOrElse&lt;/code&gt; and &lt;code&gt;CommandError.message&lt;/code&gt;&lt;/strong&gt;.
&lt;code&gt;Option[T]&lt;/code&gt; gains &lt;code&gt;okOr[E](error: E) -&amp;gt; Result[T, E]&lt;/code&gt; and &lt;code&gt;okOrElse[E](f: () -&amp;gt; E)&lt;/code&gt;, the &lt;code&gt;Result&lt;/code&gt;
counterparts of &lt;code&gt;toRight&lt;/code&gt;; &lt;code&gt;Result.ok&lt;/code&gt; and &lt;code&gt;err()&lt;/code&gt; already existed. &lt;code&gt;okOr&lt;/code&gt; takes its argument
by value and &lt;code&gt;okOrElse&lt;/code&gt; a function called only for &lt;code&gt;None&lt;/code&gt;. WHY: the two names say which form
evaluates; the by-name form already exists as a lambda call, and a by-name &lt;code&gt;okOr&lt;/code&gt; would leave
&lt;code&gt;okOrElse&lt;/code&gt; redundant. Alternatives: a by-name &lt;code&gt;okOr&lt;/code&gt; only (as &lt;code&gt;toRight&lt;/code&gt; is; one method, but an
argument with effects reads as eager and is not), or &lt;code&gt;toRight&lt;/code&gt;-style names (&lt;code&gt;toOk&lt;/code&gt;). Review
with the user if &lt;code&gt;okOr&lt;/code&gt;‘s eagerness should instead match &lt;code&gt;toRight&lt;/code&gt;‘s.
&lt;code&gt;CommandError.message -&amp;gt; string&lt;/code&gt; reads &lt;code&gt;exited with status N&lt;/code&gt;, &lt;code&gt;killed by signal N (Name)&lt;/code&gt;
(&lt;code&gt;unknown&lt;/code&gt; for a signal &lt;code&gt;avin.signal&lt;/code&gt; has no name for), &lt;code&gt;timed out&lt;/code&gt;, and an &lt;code&gt;Io&lt;/code&gt; error’s own
&lt;code&gt;IoError.message&lt;/code&gt;. WHY: one sentence per variant in &lt;code&gt;IoError.message&lt;/code&gt;‘s lower-case style, the
signal’s name beside its number as &lt;code&gt;avin.signal&lt;/code&gt; names them. Alternatives: the number alone;
&lt;code&gt;ExitStatus.message&lt;/code&gt; as well (not added: nothing needs it yet).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;sysl-098&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Child.detach()&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;).
&lt;code&gt;detach() -&amp;gt; long&lt;/code&gt; lets go of every program of the command still running without stopping it
(Sysl’s &lt;code&gt;Spawned.detach&lt;/code&gt;) and answers &lt;code&gt;pid()&lt;/code&gt;, the same &lt;code&gt;long&lt;/code&gt; the &lt;code&gt;Child&lt;/code&gt; already answers it as;
a sequence’s later part not yet started is never started, and the sequence’s own redirected files
are closed, the running part holding its copies. Afterwards &lt;code&gt;waitFor&lt;/code&gt;, &lt;code&gt;isAlive&lt;/code&gt; and &lt;code&gt;kill&lt;/code&gt; trap
(&lt;code&gt;a detached &lt;/code&gt;Child&lt;code&gt; is not waited for, asked after or stopped&lt;/code&gt;), while &lt;code&gt;pid&lt;/code&gt;, &lt;code&gt;group&lt;/code&gt;, &lt;code&gt;signal&lt;/code&gt;,
&lt;code&gt;signalGroup&lt;/code&gt; and &lt;code&gt;residentBytes&lt;/code&gt; answer from the ids recorded at each start; a second &lt;code&gt;detach&lt;/code&gt;
answers the pid again, and detaching a command already waited for lets go of nothing. Nothing reaps
a detached program: one that ends while the program runs is a zombie until the program ends.
WHY: once detached the &lt;code&gt;Child&lt;/code&gt; can no longer see the command end, so an answer from &lt;code&gt;waitFor&lt;/code&gt; or
&lt;code&gt;isAlive&lt;/code&gt; would be a guess, and a trap is how the library treats a handle used against its state
(a &lt;code&gt;Child&lt;/code&gt; used from the wrong thread); keeping the id-based operations lets a program still stop
what it started. ALTERNATIVES: &lt;code&gt;waitFor&lt;/code&gt; still waiting by pid (reaping, which makes a detached
command a waited one again and races a reaper the program may run itself); &lt;code&gt;Err&lt;/code&gt; from &lt;code&gt;waitFor&lt;/code&gt;
and &lt;code&gt;false&lt;/code&gt; from &lt;code&gt;isAlive&lt;/code&gt; (an &lt;code&gt;isAlive&lt;/code&gt; of &lt;code&gt;false&lt;/code&gt; would be a lie about a running program);
answering &lt;code&gt;int&lt;/code&gt; as Sysl does (the &lt;code&gt;Child&lt;/code&gt; answers every id as a &lt;code&gt;long&lt;/code&gt;); refusing to detach a
pipeline or a sequence. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether a detached command should be reaped
by the runtime so it leaves no zombie.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;process-pipes&lt;/code&gt;): &lt;strong&gt;a started command’s
standard streams as pipes&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#pipes-to-a-started-command&quot;&gt;pipes to a started command&lt;/a&gt;).
&lt;code&gt;pipeInput()&lt;/code&gt;, &lt;code&gt;pipeOutput()&lt;/code&gt; and &lt;code&gt;pipeErrors()&lt;/code&gt; on &lt;code&gt;Command&lt;/code&gt; ask for them, each replacing an
earlier redirection of its stream as the other redirections do, and &lt;code&gt;pipeOutput().errorsToOutput()&lt;/code&gt;
merges standard error into the output’s pipe; &lt;code&gt;Child.stdin()&lt;/code&gt;, &lt;code&gt;stdout()&lt;/code&gt; and &lt;code&gt;stderr()&lt;/code&gt; answer
them, the same end every time, and trap for a stream not piped. The ends are new public classes,
&lt;code&gt;ChildInput: avin.net.StreamWriter&lt;/code&gt; and &lt;code&gt;ChildOutput: avin.net.StreamReader&lt;/code&gt;, with
&lt;code&gt;ChildOutput.readAvailable(max)&lt;/code&gt; as standard input has it. Why: the halves of a split connection
are exactly the shape (a &lt;code&gt;Reader&lt;/code&gt;/&lt;code&gt;ByteWriter&lt;/code&gt; that is also a &lt;code&gt;Readiness&lt;/code&gt;/&lt;code&gt;Writability&lt;/code&gt;, with
&lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt;, &lt;code&gt;writeSome&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;close&lt;/code&gt;), so a protocol written against a
connection’s halves (a language server’s client) runs over a child unchanged, and &lt;code&gt;select&lt;/code&gt; and
&lt;code&gt;Selector&lt;/code&gt; take them with no new arm. Each end is non-blocking and waits as a socket does
(&lt;code&gt;runtime/avin/rt/pipes.sysl&lt;/code&gt;), parking a lightweight thread on the poller; a write to a reader
that has gone answers &lt;code&gt;ConnectionReset&lt;/code&gt; (on macOS the end is marked &lt;code&gt;F_SETNOSIGPIPE&lt;/code&gt;, since that
system raises the write’s SIGPIPE on the whole process; elsewhere SIGPIPE is blocked on the writing
thread for the write and taken back). The ends are made by &lt;code&gt;sysl.process.pipe&lt;/code&gt;, closed on exec.
Choices: &lt;strong&gt;only &lt;code&gt;start()&lt;/code&gt; hands pipes over&lt;/strong&gt;: &lt;code&gt;run()&lt;/code&gt;, &lt;code&gt;output()&lt;/code&gt;, &lt;code&gt;lines()&lt;/code&gt; and a part of a
pipeline or sequence asking for one trap, since nothing could ever hold the pipe; &lt;strong&gt;the pipes do not
belong to the &lt;code&gt;Child&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;Pipes&lt;/code&gt; is &lt;code&gt;@keeps_owners&lt;/code&gt;), so handing the &lt;code&gt;Child&lt;/code&gt; to a thread that waits
for it leaves the pipes with the code using them; &lt;strong&gt;&lt;code&gt;waitFor&lt;/code&gt; and &lt;code&gt;Child.close()&lt;/code&gt; leave the pipes
alone&lt;/strong&gt; (each end closes with its own &lt;code&gt;close()&lt;/code&gt;, or when collected), because an end may belong to
another thread at the time; &lt;strong&gt;the command’s time limit bounds every wait on its pipes&lt;/strong&gt;, a wait
past it answering &lt;code&gt;TimedOut&lt;/code&gt;, so &lt;code&gt;withTimeout&lt;/code&gt; cannot be outwaited by a read nobody times; the pipes
do not keep the command running. Alternatives weighed: the ends as &lt;code&gt;io.Reader&lt;/code&gt;/&lt;code&gt;io.ByteWriter&lt;/code&gt;
classes of &lt;code&gt;avin.process&lt;/code&gt; alone (no &lt;code&gt;avin.net&lt;/code&gt; dependency, but every connection protocol would need
an adapter); socket pairs in place of pipes (all of the socket code reused, but a child sees a socket
where it expects a pipe); &lt;code&gt;Option&lt;/code&gt;-answering or take-once accessors (&lt;code&gt;takeStdout()&lt;/code&gt;), which make a
loop of &lt;code&gt;child.stdin().write(…)&lt;/code&gt; wrong; ends owned by the &lt;code&gt;Child&lt;/code&gt; and handed over with it, which
traps a program reading a child’s output while a thread waits for it; &lt;code&gt;waitFor&lt;/code&gt; closing the input
first, which reaches across threads; &lt;code&gt;run()&lt;/code&gt; with a pipe meaning an empty input. &lt;strong&gt;Review with the
user&lt;/strong&gt;: whether &lt;code&gt;Child.close()&lt;/code&gt; should also close the pipes the closing code holds, and whether the
ends should keep the command alive.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;sysl-098&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;totalMemory&lt;/code&gt; and &lt;code&gt;residentBytes&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#the-environment-and-the-platform&quot;&gt;the environment and the
platform&lt;/a&gt;). &lt;code&gt;process.totalMemory() -&amp;gt; Result[long, IoError]&lt;/code&gt; and &lt;code&gt;process.residentBytes(pid: long) -&amp;gt; Result[long, IoError]&lt;/code&gt; over Sysl’s
&lt;code&gt;total_memory&lt;/code&gt; and &lt;code&gt;resident_bytes&lt;/code&gt;, the &lt;code&gt;u64&lt;/code&gt; bound as a &lt;code&gt;long&lt;/code&gt; (machine memory and a process’s
resident pages are far below 2^63), and &lt;code&gt;Child.residentBytes()&lt;/code&gt; for the program &lt;code&gt;pid()&lt;/code&gt; names. A
process that is not there (Sysl’s &lt;code&gt;NotFound&lt;/code&gt;, which from Sysl 0.9.9 it answers for a reaped child
and an unused pid alike), a pid of zero or less and one past the largest &lt;code&gt;int&lt;/code&gt; are
&lt;code&gt;Err(NotFound)&lt;/code&gt;; Sysl’s &lt;code&gt;NotPermitted&lt;/code&gt; is &lt;code&gt;Err(PermissionDenied)&lt;/code&gt;, which macOS answers for pid 1
and Linux does not (it reads any process’s size). A &lt;code&gt;Child&lt;/code&gt; seen to have ended, or with no program
started, is &lt;code&gt;Err(NotFound)&lt;/code&gt; without asking. WHY: the pid is a &lt;code&gt;long&lt;/code&gt; everywhere else in
&lt;code&gt;avin.process&lt;/code&gt; (&lt;code&gt;pid()&lt;/code&gt;, &lt;code&gt;signal&lt;/code&gt;); &lt;code&gt;NotFound&lt;/code&gt; and &lt;code&gt;PermissionDenied&lt;/code&gt; are the &lt;code&gt;IoError&lt;/code&gt; cases a
program tells apart, where Sysl’s &lt;code&gt;NotPermitted&lt;/code&gt; would otherwise read as &lt;code&gt;Other(text)&lt;/code&gt;.
ALTERNATIVES: &lt;code&gt;pid: int&lt;/code&gt; as Sysl takes it; &lt;code&gt;Option[long]&lt;/code&gt; (loses why); passing Sysl’s
“no such process” through as &lt;code&gt;Other(...)&lt;/code&gt; as &lt;code&gt;signal&lt;/code&gt; does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06: &lt;strong&gt;A group of only ended, unreaped processes answers “No such process”&lt;/strong&gt; (branch
&lt;code&gt;group-signal-eperm&lt;/code&gt;; &lt;a href=&quot;/spec/system-library/#commands&quot;&gt;commands&lt;/a&gt;). &lt;code&gt;signalGroup&lt;/code&gt; maps the
platform’s permission refusal to &lt;code&gt;Err(Other(&amp;quot;No such process&amp;quot;))&lt;/code&gt;: on macOS &lt;code&gt;kill(-pgid)&lt;/code&gt; answers
EPERM while a group holds only zombies and ESRCH once they are reaped, so the same program saw
either answer by the timing of the reaping. Every process in a group a command made belongs to the
program’s user, so a refusal can only mean that. WHY: one answer for an empty group, however the
reaping falls. Alternatives: leave the platform’s answer and have callers wait for reaping (no way
to observe it, and the flake stays); report the permission error only for a group the program did
not start (not reachable, since &lt;code&gt;signalGroup&lt;/code&gt; only names groups of its own commands).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;parallel-codegen&lt;/code&gt;): &lt;strong&gt;A build compiles the program’s LLVM text as codegen units
at once, one clang each, at most eight, and keeps each unit’s object in the toolchain’s cache by
its text.&lt;/strong&gt; A function only one function calls goes with its caller (kept local, so still inlined
there: without this a hot single-caller function across a cut ran ~6% slower at &lt;code&gt;-O2&lt;/code&gt;); other
functions are placed by a hash of their name, globals with their first user, aliases
with their global; a local crossing units is promoted to a hidden &lt;code&gt;avin.cgu:&lt;/code&gt; name; at &lt;code&gt;-O2&lt;/code&gt; small
functions (body cost at most 32) and short constants are copied &lt;code&gt;available_externally&lt;/code&gt; into the
units that use them. Why: clang -O2 on one 34 MB module was ~10 s of a 15 s rebuild of tui’s &lt;code&gt;top&lt;/code&gt;
on one core of eighteen; the hash placement keeps an edit to one function inside one unit, so the
cache recompiles one unit. Eight: on a machine of six performance and twelve efficiency cores more
units land on the slow cores and repeat more declarations and copies (the same cap Sysl’s builds
measured). Alternatives weighed: units balanced greedily by size (better balance, but every edit
that shifts a size reshuffles the units and defeats the cache); copying small local functions as
local copies (cheaper, but a function would have one address per unit); no copies at &lt;code&gt;-O2&lt;/code&gt; (a
call across units could never be inlined); no object cache (a one-line edit recompiles every
unit); one unit per processor without a cap. &lt;code&gt;AVIN_CODEGEN_UNITS&lt;/code&gt; overrides the count. &lt;strong&gt;Review
with the user&lt;/strong&gt; only if &lt;code&gt;-O2&lt;/code&gt; run-time performance across units ever shows up in a profile: the
copy limit is the knob.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;parallel-codegen&lt;/code&gt;): &lt;strong&gt;The cache of unit objects is trimmed to 1 GiB&lt;/strong&gt;, oldest
first, after a build that compiled a unit, sparing anything used in the last hour; a reused
object’s time is refreshed. The test corpus links without keeping objects. Why: a build of &lt;code&gt;top&lt;/code&gt;
keeps ~8 objects of a few MB per level, so 1 GiB holds dozens of builds; the hour keeps a
concurrent build’s objects from being evicted under it. Alternatives: a count of objects; no
trimming.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;process-exec&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;process.exec&lt;/code&gt; and its environment&lt;/strong&gt;
(&lt;a href=&quot;/spec/system-library/#becoming-another-program&quot;&gt;becoming another program&lt;/a&gt;).
&lt;code&gt;exec(program, args) -&amp;gt; Result[Nothing, IoError]&lt;/code&gt; over Sysl 0.9.9’s &lt;code&gt;sysl.process.exec&lt;/code&gt;,
inheriting the environment, and an overload &lt;code&gt;exec(program, args, environment: Map[string, string])&lt;/code&gt; giving exactly that environment, nothing inherited, a bare name looked for on its &lt;code&gt;PATH&lt;/code&gt;.
Why: a &lt;code&gt;Result&lt;/code&gt; with &lt;code&gt;Nothing&lt;/code&gt; on its &lt;code&gt;Ok&lt;/code&gt; side lets &lt;code&gt;?&lt;/code&gt; pass the failure on and says in the type
that success never comes back; a whole &lt;code&gt;Map&lt;/code&gt; matches what &lt;code&gt;process.environment()&lt;/code&gt; answers, so
adding to the program’s own is &lt;code&gt;environment().updated(...)&lt;/code&gt;, and a self-upgrading daemon wants the
environment it was started with. Alternatives weighed: answering a bare &lt;code&gt;IoError&lt;/code&gt; as Sysl does
(no &lt;code&gt;?&lt;/code&gt;); a &lt;code&gt;Command.exec()&lt;/code&gt; carrying &lt;code&gt;withEnv&lt;/code&gt;/&lt;code&gt;clearEnv&lt;/code&gt; edits (a command’s directory, time
limit and redirections have no meaning for an &lt;code&gt;exec&lt;/code&gt;, and would need refusing); a vector of
environment edits. Standard output is flushed by the Sysl call (&lt;code&gt;fflush&lt;/code&gt; of every stream, which
is where Avin’s output is buffered). A &lt;code&gt;match&lt;/code&gt; over the answer still needs an &lt;code&gt;Ok(_)&lt;/code&gt; arm, since
exhaustiveness does not yet treat a variant holding &lt;code&gt;Nothing&lt;/code&gt; as impossible. &lt;strong&gt;Review with the
user&lt;/strong&gt; whether such arms should be dropped from exhaustiveness.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;process-exec&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;waitPid&lt;/code&gt; and &lt;code&gt;tryWaitPid&lt;/code&gt; answer &lt;code&gt;Err(NotFound)&lt;/code&gt; for
anything not there to wait for&lt;/strong&gt;: a pid that is not this program’s child or was already reaped
(Sysl’s &lt;code&gt;Other(10)&lt;/code&gt;, &lt;code&gt;ECHILD&lt;/code&gt;), and a pid of zero or less or past the largest process id (Sysl’s
&lt;code&gt;Other(22)&lt;/code&gt; for the first, refused before the call for the second). Why: it matches
&lt;code&gt;residentBytes&lt;/code&gt;, where a process that is not there, a reaped child among them, and a pid of zero
or less are &lt;code&gt;NotFound&lt;/code&gt;, and gives a caller one case to match. &lt;code&gt;waitPid&lt;/code&gt; is bound &lt;code&gt;blocking&lt;/code&gt;, as
&lt;code&gt;Child.waitFor&lt;/code&gt; is, and both answer the same mirrored &lt;code&gt;ExitStatus&lt;/code&gt;. Alternatives weighed:
&lt;code&gt;Other&lt;/code&gt; with a sentence (unmatchable by kind); a trap for a pid of zero or less (a pid read back
from saved state is data, not a programming error).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-07 (branch &lt;code&gt;fs-rename&lt;/code&gt;): &lt;code&gt;fs.rename(from, to) -&amp;gt; Result[unit, IoError]&lt;/code&gt; (&lt;a href=&quot;/spec/system-library/&quot;&gt;system
library&lt;/a&gt;) &lt;strong&gt;replaces&lt;/strong&gt; what is at &lt;code&gt;to&lt;/code&gt;, in one step, and does not refuse.
A file replaces a file; a directory replaces an empty directory; a directory that holds entries
is &lt;code&gt;DirectoryNotEmpty&lt;/code&gt;; a file onto a directory is &lt;code&gt;IsADirectory&lt;/code&gt;, a directory onto a file
&lt;code&gt;NotADirectory&lt;/code&gt;. Renaming a path to itself succeeds and changes nothing. WHY: the call exists for
the atomic write (write &lt;code&gt;state.json.new&lt;/code&gt;, rename it over &lt;code&gt;state.json&lt;/code&gt;), which is only atomic if a
reader sees the old file or the new and the replacement never fails because the old one is there;
replacing is also what the platform’s own rename does, so no extra check can race. ALTERNATIVES:
refuse with &lt;code&gt;AlreadyExists&lt;/code&gt; when &lt;code&gt;to&lt;/code&gt; exists (a separate check-then-rename is racy, and the
atomic write would need a remove first, losing atomicity); two functions, &lt;code&gt;rename&lt;/code&gt; and
&lt;code&gt;renameReplacing&lt;/code&gt;. Across file systems the call fails and moves nothing (&lt;code&gt;Other&lt;/code&gt;), never copying.
Review with the user if a refuse-by-default &lt;code&gt;rename&lt;/code&gt; is preferred.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-07: &lt;strong&gt;A &lt;code&gt;Zone&lt;/code&gt; holds its rules in Avin until Sysl’s own zone can be held&lt;/strong&gt; (branch &lt;code&gt;local-time&lt;/code&gt;).
A zone is a final class of a name and its rules: one fixed offset, or the bytes of the host
database’s file for it as an immutable &lt;code&gt;Vector[byte]&lt;/code&gt;. Each question (&lt;code&gt;offsetAt&lt;/code&gt;,
&lt;code&gt;isDaylightSavingAt&lt;/code&gt;, &lt;code&gt;abbreviationAt&lt;/code&gt;) passes the bytes to the runtime, which decodes them with
Sysl 0.9.9’s &lt;code&gt;sysl.time.tzif&lt;/code&gt; and answers. Why: that release’s decoded &lt;code&gt;tzif.Zone&lt;/code&gt; is a view of the
bytes it was decoded from, so it cannot be held as a handle past the call that made it; the bytes
can, and a zone so held is an immutable value any thread may share, as the chapter says, where a
handle belongs to one thread. Decoding a table walks its header, short beside reading it.
Alternatives weighed: a handle over the borrowed view (a dangling reference once the shim’s copy
is freed); a runtime table of decoded zones under a lock, handed out by number (global state and a
lock for what is a pure function of the bytes); waiting for Sysl 0.10.0’s owning &lt;code&gt;Zone&lt;/code&gt; (marshal
needs the local time now). When Avin moves to Sysl 0.10.0, &lt;code&gt;Zone&lt;/code&gt; becomes a handle over its zone
with no change to Avin’s API. Review with the user: the roadmap planned the handle from the start.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-07: &lt;strong&gt;The local zone is the one &lt;code&gt;TZ&lt;/code&gt; names, else the one &lt;code&gt;/etc/localtime&lt;/code&gt; is, read from the
database like any other&lt;/strong&gt; (branch &lt;code&gt;local-time&lt;/code&gt;). &lt;code&gt;TZ&lt;/code&gt; with a leading &lt;code&gt;:&lt;/code&gt; dropped is a zone’s name,
a &lt;code&gt;TZ&lt;/code&gt; that is a path is that file, named for what follows its &lt;code&gt;zoneinfo/&lt;/code&gt;; with &lt;code&gt;TZ&lt;/code&gt; unset,
&lt;code&gt;/etc/localtime&lt;/code&gt;‘s bytes are the table and its link’s target after &lt;code&gt;zoneinfo/&lt;/code&gt; the name
(&lt;code&gt;localtime&lt;/code&gt; where it is a copy). An empty &lt;code&gt;TZ&lt;/code&gt;, one naming no zone, one that is not a zone’s
name, and a file that does not decode give &lt;code&gt;utc&lt;/code&gt;. Why: one source for the offset, the abbreviation
and daylight saving, and a local zone equal to &lt;code&gt;zone(name)&lt;/code&gt; of its own name, so
&lt;code&gt;localZone() == zone(&amp;quot;America/New_York&amp;quot;)?&lt;/code&gt; where that is the host’s zone. Alternatives weighed:
the offset from &lt;code&gt;localtime_r&lt;/code&gt; (Sysl’s &lt;code&gt;local_offset&lt;/code&gt;) with the abbreviation from the table (two
sources that could disagree, and a POSIX rule &lt;code&gt;TZ&lt;/code&gt; such as &lt;code&gt;EST5EDT&lt;/code&gt; with no file would have an
offset and no abbreviation); a zone named &lt;code&gt;local&lt;/code&gt; (never equal to the named zone it is). A POSIX
rule string with no file of its name in the database is therefore &lt;code&gt;utc&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-07: &lt;strong&gt;Pattern details the chapter left open&lt;/strong&gt; (branch &lt;code&gt;local-time&lt;/code&gt;): &lt;code&gt;||&lt;/code&gt; is a bar between the bars
too (&lt;code&gt;|a||b|&lt;/code&gt; writes &lt;code&gt;a|b&lt;/code&gt;), as it is outside them, so any text can be quoted; &lt;code&gt;DDD&lt;/code&gt; pads the day of
the year to three digits, as &lt;code&gt;DD&lt;/code&gt; pads the day of the month to two; &lt;code&gt;YY&lt;/code&gt; is the last two digits of
the year’s magnitude (&lt;code&gt;01&lt;/code&gt; for year &lt;code&gt;-1&lt;/code&gt;); &lt;code&gt;YYYY&lt;/code&gt; outside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9999&lt;/code&gt; writes the year as the
display does (&lt;code&gt;+12345&lt;/code&gt;, &lt;code&gt;-0001&lt;/code&gt;); &lt;code&gt;z&lt;/code&gt; and &lt;code&gt;zz&lt;/code&gt; of UTC are &lt;code&gt;+00:00&lt;/code&gt; and &lt;code&gt;+0000&lt;/code&gt;, never &lt;code&gt;Z&lt;/code&gt;, so a
pattern writes one shape for every zone (a literal &lt;code&gt;Z&lt;/code&gt; is written as itself); &lt;code&gt;f&lt;/code&gt; … &lt;code&gt;ffffff&lt;/code&gt; cut
the fraction rather than rounding, so a reading never rounds into the next second; and the whole
pattern is read before anything is written, so a malformed pattern traps as malformed whatever
value it is given. Alternatives weighed: &lt;code&gt;DDD&lt;/code&gt; unpadded (a column of days of the year would not
line up); &lt;code&gt;Z&lt;/code&gt; for UTC’s &lt;code&gt;z&lt;/code&gt; (a pattern’s output would change shape with the zone).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Settled on the user’s delegation 2026-11-07 (branch &lt;code&gt;stop-signals&lt;/code&gt;): &lt;code&gt;avin.signal&lt;/code&gt; names &lt;code&gt;Stop&lt;/code&gt;, &lt;code&gt;Continue&lt;/code&gt;,
&lt;code&gt;TerminalStop&lt;/code&gt; and &lt;code&gt;Child&lt;/code&gt;.&lt;/strong&gt; Each is an &lt;code&gt;int&lt;/code&gt; numbered by the runtime for the platform
(&lt;code&gt;avin.rt.job_signal&lt;/code&gt;, over Sysl’s &lt;code&gt;STOP&lt;/code&gt;, &lt;code&gt;CONT&lt;/code&gt;, &lt;code&gt;TSTP&lt;/code&gt; and &lt;code&gt;CHLD&lt;/code&gt;, as &lt;code&gt;User1&lt;/code&gt; and &lt;code&gt;User2&lt;/code&gt; are
over &lt;code&gt;USR1&lt;/code&gt; and &lt;code&gt;USR2&lt;/code&gt;), since all four differ between macOS and Linux. &lt;strong&gt;&lt;code&gt;Stop&lt;/code&gt; cannot be
watched&lt;/strong&gt;: &lt;code&gt;watch(Stop)&lt;/code&gt; is &lt;code&gt;Err(Other(&amp;quot;Invalid argument&amp;quot;))&lt;/code&gt;, the refusal &lt;code&gt;Kill&lt;/code&gt; already gets,
because the platform lets nothing catch it. &lt;code&gt;Continue&lt;/code&gt;, &lt;code&gt;TerminalStop&lt;/code&gt; and &lt;code&gt;Child&lt;/code&gt; can be
watched like any other signal; a watched &lt;code&gt;TerminalStop&lt;/code&gt; no longer stops the program, and a
watched &lt;code&gt;Child&lt;/code&gt; is raised whenever a program the program started ends, is stopped or continues.
A status a signal ended also names them (&lt;code&gt;killed by signal 19 (Stop)&lt;/code&gt;), and now names &lt;code&gt;User1&lt;/code&gt; and
&lt;code&gt;User2&lt;/code&gt;, which it called “unknown”. Why: a supervisor pauses a job’s process group with &lt;code&gt;Stop&lt;/code&gt;
and &lt;code&gt;Continue&lt;/code&gt;, and needs &lt;code&gt;Child&lt;/code&gt; to see an end that races a restart; an &lt;code&gt;Err&lt;/code&gt;, not a trap, is
the existing treatment of a signal that cannot be watched, and a refusal is a value the caller
can act on. Alternatives weighed: a trap on &lt;code&gt;watch(Stop)&lt;/code&gt; (inconsistent with &lt;code&gt;Kill&lt;/code&gt;, and a
platform-dependent number would make “this one traps” a hidden fact of the platform); leaving
&lt;code&gt;Stop&lt;/code&gt; out of the library and sending a literal number (the number is not portable); spelling
&lt;code&gt;Continue&lt;/code&gt; as &lt;code&gt;Cont&lt;/code&gt; (the library spells every other name out). Review with the user: whether
&lt;code&gt;TerminalStop&lt;/code&gt; should be left unwatchable, as a program that traps Ctrl-Z rarely means to.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-07 (branch &lt;code&gt;lambda-after-literal&lt;/code&gt;): &lt;strong&gt;A lambda’s result takes part in a call’s literal tiers&lt;/strong&gt;
(&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;). A lambda whose parameter types are known is checked in
the tier of the value it yields (the last item of its block; the lowest tier among an &lt;code&gt;if&lt;/code&gt;‘s or a
&lt;code&gt;match&lt;/code&gt;‘s branches), after the other arguments of that tier, rather than after every argument. So
&lt;code&gt;pick(s -&amp;gt; s.toLongOption(), 0)&lt;/code&gt; for &lt;code&gt;pick[T](read: (string) -&amp;gt; Option[T], absent: T)&lt;/code&gt; takes
&lt;code&gt;T = long&lt;/code&gt;, as passing a named function does, and &lt;code&gt;pick(s -&amp;gt; s.toRealOption(), 0)&lt;/code&gt; takes &lt;code&gt;real&lt;/code&gt;;
a lambda yielding &lt;code&gt;Some(1)&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt; takes the numbers the other arguments decide. A lambda that
leaves its body by &lt;code&gt;return&lt;/code&gt; or &lt;code&gt;?&lt;/code&gt;, and a &lt;code&gt;match&lt;/code&gt; function, are still checked last, since such a
body needs its result type known before it is checked. Why: the settled number-literal decision
says a literal gives way to a type from a neighbour, and a lambda’s result is a neighbour; a
lambda checked last let the &lt;code&gt;0&lt;/code&gt; fix &lt;code&gt;T = int&lt;/code&gt; first, so the lambda and a named function of the
same type behaved differently (marshal met it). Alternatives: deferring the literal instead of
advancing the lambda (the same order in effect, but it reaches only literals, not the lambda’s own
literal result); checking a lambda with &lt;code&gt;?&lt;/code&gt; against a result type known only in shape, deferred
here and since built (next paragraph).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;lambda-question-shape&lt;/code&gt;): a lambda using &lt;code&gt;?&lt;/code&gt;
or &lt;code&gt;return&lt;/code&gt; checks against a result known only in shape.&lt;/strong&gt; Where the function type expected for
a lambda yields an &lt;code&gt;Option[T]&lt;/code&gt;, or a &lt;code&gt;Result[T, E]&lt;/code&gt; with &lt;code&gt;E&lt;/code&gt; known, and &lt;code&gt;T&lt;/code&gt; is still to be
inferred (wholly or in part), the lambda’s result is that shape: &lt;code&gt;?&lt;/code&gt; passes a &lt;code&gt;None&lt;/code&gt;, or an &lt;code&gt;Err&lt;/code&gt;
converted to &lt;code&gt;E&lt;/code&gt; as in any function, and the body’s value solves &lt;code&gt;T&lt;/code&gt;, so
&lt;code&gt;inside(n -&amp;gt; Ok(half(n + 1)? + 1))&lt;/code&gt; for &lt;code&gt;inside[T](f: (int) -&amp;gt; Result[T, string])&lt;/code&gt; takes
&lt;code&gt;T = int&lt;/code&gt;. A &lt;code&gt;Result&lt;/code&gt; whose &lt;code&gt;E&lt;/code&gt; is itself unknown, and any other shape, stay refused with “this
lambda uses &lt;code&gt;?&lt;/code&gt;, so its result type must be known where it is written”. WHY: the pg package
needs it for every &lt;code&gt;c.transaction(tx -&amp;gt; { tx.execute(…)?; Ok(x) })&lt;/code&gt; and &lt;code&gt;pool.use&lt;/code&gt; body, where
the transaction’s value type is the caller’s and the error type is the library’s; the error
type is what &lt;code&gt;?&lt;/code&gt; needs, and it is known. Only a lambda that exits by &lt;code&gt;?&lt;/code&gt; or &lt;code&gt;return&lt;/code&gt; takes the
shape as its declared result; any other lambda still infers from the body against the shape as a
hint, so nothing it accepted changes. ALTERNATIVES: inferring &lt;code&gt;E&lt;/code&gt; from the first &lt;code&gt;?&lt;/code&gt; too (makes a
lambda’s error type depend on which failure is written first, and a later &lt;code&gt;?&lt;/code&gt; of another error
type then fails to convert rather than widen); making a &lt;code&gt;?&lt;/code&gt; lambda take part in the literal tiers
as well (it is still checked after the other arguments, so
&lt;code&gt;pick(s -&amp;gt; Some(s.toLongOption()? + 1), 0)&lt;/code&gt; still fixes &lt;code&gt;T = int&lt;/code&gt; from the &lt;code&gt;0&lt;/code&gt; and is refused:
checking it earlier would refuse a &lt;code&gt;?&lt;/code&gt; lambda whose result is a bare &lt;code&gt;T&lt;/code&gt; that only a later
argument decides). Review with the user: whether a &lt;code&gt;?&lt;/code&gt; lambda should also join the literal tiers
when its expected result has the shape, which would make the &lt;code&gt;pick&lt;/code&gt; example a &lt;code&gt;long&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Settled on the user’s delegation 2026-11-07 (branch &lt;code&gt;hash-digest&lt;/code&gt;): &lt;code&gt;avin.crypto&lt;/code&gt;, digests over &lt;code&gt;sysl.crypto&lt;/code&gt;.&lt;/strong&gt;
The module is &lt;code&gt;avin.crypto&lt;/code&gt;; it has &lt;code&gt;sha256&lt;/code&gt;, &lt;code&gt;sha512&lt;/code&gt;, &lt;code&gt;sha1&lt;/code&gt; and &lt;code&gt;md5&lt;/code&gt; (each taking a
&lt;code&gt;Vector[byte]&lt;/code&gt; or a &lt;code&gt;string&lt;/code&gt;, hashed as UTF-8, answering a &lt;code&gt;Vector[byte]&lt;/code&gt;), &lt;code&gt;hmacSha256&lt;/code&gt; and
&lt;code&gt;hmacSha512&lt;/code&gt;, &lt;code&gt;toHex&lt;/code&gt;, and incremental &lt;code&gt;Sha256()&lt;/code&gt;, &lt;code&gt;Sha512()&lt;/code&gt;, &lt;code&gt;Sha1()&lt;/code&gt; and &lt;code&gt;Md5()&lt;/code&gt; with &lt;code&gt;update&lt;/code&gt;
and &lt;code&gt;finish&lt;/code&gt;. WHY: marshal hand-wrote FNV-1a to key a build cache because the library had no
digest, and Sysl already has SHA-2, SHA-1, MD5 and HMAC; a binding cannot disagree with Sysl.
&lt;code&gt;avin.crypto&lt;/code&gt; rather than &lt;code&gt;avin.hash&lt;/code&gt; because the module holds keyed digests, and “hash” in Avin
already means the trait behind &lt;code&gt;HashMap&lt;/code&gt;. A digest is a &lt;code&gt;Vector[byte]&lt;/code&gt;, not a string, so it
compares, keys and stores as bytes and hex is one call away. Details: &lt;code&gt;finish()&lt;/code&gt; caches its digest
and answers it again, and &lt;code&gt;update&lt;/code&gt; after &lt;code&gt;finish&lt;/code&gt; traps (a Sysl hasher cannot be finished twice);
the hashers are Avin classes over private handles because a handle has no constructor; the
one-shot digests and HMACs go through small &lt;code&gt;avin.rt&lt;/code&gt; functions (&lt;code&gt;runtime/avin/rt/digest.sysl&lt;/code&gt;)
because Sysl’s one-shot functions answer a fixed array (&lt;code&gt;[32]u8&lt;/code&gt;), which no binding result takes,
and Sysl keeps its streaming HMAC private. ALTERNATIVES: &lt;code&gt;avin.hash&lt;/code&gt; (above); digests as hex
&lt;code&gt;string&lt;/code&gt; (loses the bytes); one-shots through the Sysl hasher handle only (cannot reach HMAC);
making the boundary accept fixed &lt;code&gt;[N]u8&lt;/code&gt; results (a compiler change for a handful of functions);
an HMAC written in Avin over the hashers (a second implementation to keep correct); also offering
SHA-224, SHA-384, HMAC-SHA-1 and HMAC-MD5 (Sysl has them, nothing asks) and a constant-time
&lt;code&gt;verify&lt;/code&gt; (Sysl has one; add it when a program checks tags). Review with the user: whether &lt;code&gt;sha1&lt;/code&gt;
and &lt;code&gt;md5&lt;/code&gt; belong in the standard library at all, and whether the other SHA-2 widths and &lt;code&gt;verify&lt;/code&gt;
should be added now.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A top-level name declared twice is reported with the first declaration’s place, and a clash
between two files of a module suppresses every other diagnostic.&lt;/strong&gt; Settled on the user’s
delegation 2026-11-07. Each duplicate message ends &lt;code&gt;; first declared at FILE:LINE:COL&lt;/code&gt;. When the
clash spans files, the program’s other errors are dropped before printing, because they are almost
always cascades of the clash (two &lt;code&gt;Filter&lt;/code&gt; types in one module gave 48 conformance errors and no
word of the clash, and the CLI shows five). A clash inside one file keeps its other errors, since
existing reject cases mix a duplicate with unrelated errors and the duplicate is easy to see there.
WHY: the clash is the cause and must be the error read first. ALTERNATIVES: suppressing for
same-file clashes too (hides real unrelated errors in one file); ordering duplicates first without
suppressing (the cascade still fills the five shown). Review with the user: whether same-file
clashes should suppress the cascade too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;File metadata in &lt;code&gt;avin.fs&lt;/code&gt;&lt;/strong&gt; Settled on the user’s delegation 2026-11-07: &lt;code&gt;metadata(path)&lt;/code&gt; answers
&lt;code&gt;Result[Metadata, IoError]&lt;/code&gt; with &lt;code&gt;Metadata(size: long, modified: Instant, isDir: bool, isFile: bool)&lt;/code&gt;, from one &lt;code&gt;stat&lt;/code&gt;, so the fields describe one entry; &lt;code&gt;size(path)&lt;/code&gt; and
&lt;code&gt;modified(path)&lt;/code&gt; are shorthands for the two fields a program usually wants, and &lt;code&gt;setModified(path, instant)&lt;/code&gt; sets the modification time (and the access time with it). Every call follows symbolic
links, as &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;isDir&lt;/code&gt; and &lt;code&gt;isFile&lt;/code&gt; do; a dangling link is &lt;code&gt;NotFound&lt;/code&gt;. &lt;code&gt;modified&lt;/code&gt; is an
&lt;code&gt;avin.time.Instant&lt;/code&gt;, the type &lt;code&gt;now()&lt;/code&gt; answers, so a program compares a file’s age with
&lt;code&gt;now() - modified&lt;/code&gt;-style arithmetic and nothing else. Why: marshal’s retention kept &lt;code&gt;.used&lt;/code&gt;
sidecar files because a file’s age and size could not be read; one &lt;code&gt;stat&lt;/code&gt; is also one trip, and
a value is not three answers about three possibly different files. Alternatives weighed:
separate &lt;code&gt;size&lt;/code&gt;/&lt;code&gt;modified&lt;/code&gt; only (three trips for three facts, no directory answer); returning
Sysl’s whole &lt;code&gt;Meta&lt;/code&gt; (owner, inode and permission bits are not what Avin programs ask yet, and
they tie the type to POSIX); a &lt;code&gt;linkMetadata&lt;/code&gt; that does not follow (nothing needs it yet, and
&lt;code&gt;avin.fs&lt;/code&gt; offers no way to make a link to ask about); &lt;code&gt;setModified&lt;/code&gt; omitted (Sysl has
&lt;code&gt;set_modified&lt;/code&gt;, so it costs a line, and it lets “last used” be recorded without writing).
Times are microseconds, the library’s resolution.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Permission bits in &lt;code&gt;avin.fs&lt;/code&gt;&lt;/strong&gt; Settled on the user’s delegation 2026-11-23 (branch
&lt;code&gt;fs-permissions&lt;/code&gt;): &lt;code&gt;Metadata&lt;/code&gt; gains a fifth field, &lt;code&gt;permissions: int&lt;/code&gt;, the twelve low bits of the
mode (the nine &lt;code&gt;rwx&lt;/code&gt; with setuid, setgid and sticky; never the file type), read by the same one
&lt;code&gt;stat&lt;/code&gt;; &lt;code&gt;permissions(path)&lt;/code&gt; is its shorthand, as &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;modified&lt;/code&gt; are; &lt;code&gt;setPermissions(path, mode)&lt;/code&gt; sets exactly &lt;code&gt;mode&lt;/code&gt;, following a link. The mode is an &lt;code&gt;int&lt;/code&gt; written as an octal literal
(&lt;code&gt;0o600&lt;/code&gt;), which the lexer already reads. &lt;strong&gt;A mode outside &lt;code&gt;0o0&lt;/code&gt;..&lt;code&gt;0o7777&lt;/code&gt; is an &lt;code&gt;Err&lt;/code&gt;&lt;/strong&gt; of kind
&lt;code&gt;Other&lt;/code&gt; naming it in octal (&lt;code&gt;a mode outside 0o0 to 0o7777: 0o10000&lt;/code&gt;), raised before the path is
touched, so the file keeps its mode. Setuid, setgid and sticky are accepted, since &lt;code&gt;permissions&lt;/code&gt;
reports them and the two must round trip; where a platform refuses one (macOS: sticky on a plain
file for a non-superuser) its error comes back as the platform’s. Why: marshal’s token file must
be owner-only, and the bits belong with the other facts one &lt;code&gt;stat&lt;/code&gt; gives. Alternatives weighed:
a separate &lt;code&gt;Permissions&lt;/code&gt; type with &lt;code&gt;ownerRead&lt;/code&gt;-style accessors (more surface than one octal number,
which is how every reader already thinks of a mode; can come later over the same int); masking an
out-of-range mode silently to &lt;code&gt;0o7777&lt;/code&gt;, as Sysl’s &lt;code&gt;set_permissions&lt;/code&gt; does (a type bit passed by
mistake, &lt;code&gt;0o100644&lt;/code&gt; from a raw &lt;code&gt;st_mode&lt;/code&gt;, would succeed quietly); trapping instead of &lt;code&gt;Err&lt;/code&gt; (a mode
read from a config file is input, not a program bug; &lt;code&gt;File.seek&lt;/code&gt;‘s negative offset is the same
shape and answers &lt;code&gt;Err&lt;/code&gt;). Creating a file with a mode from the start (no moment with wider bits)
is not in this entry: Sysl 0.13.2 exposes no create-with-mode, &lt;code&gt;fchmod&lt;/code&gt; or umask call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;isFile&lt;/code&gt; means a regular file&lt;/strong&gt; Settled on the user’s delegation 2026-11-23 (branch
&lt;code&gt;fs-metadata&lt;/code&gt;): &lt;code&gt;fs.isFile(path)&lt;/code&gt; and &lt;code&gt;Metadata.isFile&lt;/code&gt; are true for a regular file alone; a FIFO,
a socket and a character or block device now answer &lt;code&gt;false&lt;/code&gt;, where before &lt;code&gt;isFile&lt;/code&gt; was “exists and
is not a directory”. Why: every caller in the library, marshal and fettle asks &lt;code&gt;isFile&lt;/code&gt; before
reading, running or sizing a file, and a FIFO there blocks the read and a socket fails it; the
&lt;code&gt;evictOlderThan&lt;/code&gt; example in the chapter would have removed another program’s socket. Alternatives
weighed: keeping “not a directory” and adding &lt;code&gt;isRegular&lt;/code&gt; (the common name would keep answering
the question no caller means). Review with the user: it changes behaviour, though no test,
example or caller found relied on the old meaning.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Complete file metadata in &lt;code&gt;avin.fs&lt;/code&gt;&lt;/strong&gt; Settled on the user’s delegation 2026-11-23 (branch
&lt;code&gt;fs-metadata&lt;/code&gt;): &lt;code&gt;Metadata&lt;/code&gt; gains &lt;code&gt;kind: FileKind&lt;/code&gt;, &lt;code&gt;accessed&lt;/code&gt;, &lt;code&gt;changed&lt;/code&gt; (both &lt;code&gt;Instant&lt;/code&gt;),
&lt;code&gt;owner&lt;/code&gt;, &lt;code&gt;group&lt;/code&gt;, &lt;code&gt;links&lt;/code&gt;, &lt;code&gt;inode&lt;/code&gt; and &lt;code&gt;device&lt;/code&gt; (all &lt;code&gt;long&lt;/code&gt;), after its five existing fields, and
an &lt;code&gt;isLink&lt;/code&gt; member; &lt;code&gt;linkMetadata(path)&lt;/code&gt; reads a link itself; &lt;code&gt;exists(path, followLinks = true)&lt;/code&gt;
asks about a dangling link with &lt;code&gt;followLinks = false&lt;/code&gt;; &lt;code&gt;isSameFile(a, b) -&amp;gt; Result[bool, IoError]&lt;/code&gt;
compares inode and device; &lt;code&gt;isReadable&lt;/code&gt;/&lt;code&gt;isWritable&lt;/code&gt; ask the platform’s &lt;code&gt;access&lt;/code&gt;; and
&lt;code&gt;avin.process&lt;/code&gt; gains &lt;code&gt;userId()&lt;/code&gt;, &lt;code&gt;groupId()&lt;/code&gt; and &lt;code&gt;userName(id)&lt;/code&gt;. &lt;code&gt;FileKind&lt;/code&gt; is &lt;code&gt;Regular | Directory | Symlink | Fifo | Socket | CharDevice | BlockDevice | UnknownKind(bits)&lt;/code&gt;, named from
the type bits Sysl’s &lt;code&gt;Meta.kind&lt;/code&gt; reports (its &lt;code&gt;Special(bits)&lt;/code&gt; split into the four POSIX kinds).
Why: walking safely, de-duplicating and copying with attributes need the kind, identity and owner
of an entry, and they come from the one &lt;code&gt;stat&lt;/code&gt; already made. Choices: &lt;strong&gt;ids are &lt;code&gt;long&lt;/code&gt;&lt;/strong&gt;, since a
user id is unsigned 32-bit and macOS’s &lt;code&gt;nobody&lt;/code&gt; is &lt;code&gt;4294967294&lt;/code&gt;; inode and device are &lt;code&gt;long&lt;/code&gt;
wrapped from 64 bits, compared, never done arithmetic on. &lt;strong&gt;&lt;code&gt;Regular&lt;/code&gt; rather than &lt;code&gt;File&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;File&lt;/code&gt;
is the open-file class of the same module, and a variant is a module-level name. &lt;strong&gt;&lt;code&gt;isSameFile&lt;/code&gt;
is a &lt;code&gt;Result&lt;/code&gt;&lt;/strong&gt;, not &lt;code&gt;false&lt;/code&gt; for a missing path, since “no such file” is not “a different file”.
&lt;strong&gt;&lt;code&gt;exists&lt;/code&gt; takes a named flag&lt;/strong&gt; rather than a second name (&lt;code&gt;existsNoFollow&lt;/code&gt;), as the copy options
will. &lt;strong&gt;&lt;code&gt;isReadable&lt;/code&gt; answers for the user who started the program&lt;/strong&gt; (&lt;code&gt;access(2)&lt;/code&gt;‘s real ids), and
the superuser is &lt;code&gt;true&lt;/code&gt; whatever the bits. &lt;strong&gt;Owner names are user names only&lt;/strong&gt;, in
&lt;code&gt;avin.process&lt;/code&gt;: Sysl 0.13.2 has &lt;code&gt;user_name&lt;/code&gt; and no group-name lookup, so &lt;code&gt;groupName&lt;/code&gt; is left out
until it does. Alternatives weighed: a separate &lt;code&gt;LinkMetadata&lt;/code&gt; type (the fields are the same); a
&lt;code&gt;Permissions&lt;/code&gt;-style object for ids (one number is what every reader thinks in); &lt;code&gt;accessed&lt;/code&gt; left
out because some file systems do not record reads (it is still right after &lt;code&gt;setModified&lt;/code&gt;, and the
chapter says which do not).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-08 (branch &lt;code&gt;runner-streaming&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin test&lt;/code&gt; pushes its report out as it goes, and on SIGTERM or
SIGINT writes out what it holds and names the work in progress.&lt;/strong&gt; The report text of a run is
unchanged. The report is pushed to its reader when a test finishes and at least half a second has
passed since the last push (the first finish always pushes), and at the end of the run, so a log
read while the run is alive shows every test but the last half second’s, and speed is unchanged.
On SIGTERM or SIGINT the runner pushes the report at once, then writes &lt;code&gt;avin test: interrupted by SIGTERM; in progress:&lt;/code&gt; (or &lt;code&gt;SIGINT&lt;/code&gt;) and one line for each piece of work still running, in the form
&lt;code&gt;run      &amp;lt;file&amp;gt;  &amp;lt;test&amp;gt;  &amp;lt;seconds&amp;gt;s&lt;/code&gt; for a test and &lt;code&gt;compile  &amp;lt;program&amp;gt;  &amp;lt;seconds&amp;gt;s&lt;/code&gt; for the build of
the program, stops the test processes it started and exits with 143 (TERM) or 130 (INT), within
about 20 ms of the signal. A watcher thread reads the signals, so a build blocked in a tool, or a
compiler pass that is busy, cannot keep the lines from being written. The new option &lt;code&gt;avin test --prefix&lt;/code&gt; puts the file’s path and a colon before every result line (&lt;code&gt;a.avin:   ok    passes  3ms&lt;/code&gt;),
for runs whose output is interleaved with other runs’ in one log; headings and the summary are not
prefixed. Why: a job stopped at its deadline left a zero-byte log because the report sat in a
buffer until the run ended, and a hung build named nothing. Alternatives weighed: flushing after
every line (cost: a write for every line of a many-test run), a prefix always on (changes every
existing report), a prefix on only when output is not a terminal (the same program would write
different text by where it was sent), and polling the signal flag between tests (a blocked test or
build would never reach the poll). Review with the user: the option’s name &lt;code&gt;--prefix&lt;/code&gt;, and the exit
codes 143 and 130 (the shell’s 128 + signal convention).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;with-update&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;with&lt;/code&gt; is refused on a data type with several variants&lt;/strong&gt;, and a
path through a field of such a type (&lt;code&gt;Option&lt;/code&gt; among them) is refused too. Why: variants are
constructors, not types, so no static type says which variant a value is and which fields it has;
the language already refuses &lt;code&gt;s.radius&lt;/code&gt; on a &lt;code&gt;Shape&lt;/code&gt; for the same reason, and a &lt;code&gt;match&lt;/code&gt; arm makes
the new variant directly (&lt;code&gt;Circle(r) -&amp;gt; Circle(r + 1)&lt;/code&gt;). Alternatives weighed: accepting it where
every variant has every named field, with the same type, and choosing the variant at run time (a
hidden &lt;code&gt;match&lt;/code&gt;), which makes the form’s cost and its errors depend on edits to other variants; and
trapping on a variant without the field, which turns a compile-time error into a run-time one.
Review with the user: whether the every-variant-has-it form is wanted for enums whose variants
share a common header.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;with-update&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;with&lt;/code&gt; keeps the base’s type arguments&lt;/strong&gt;: &lt;code&gt;Box[int] with { v = &amp;quot;s&amp;quot; }&lt;/code&gt; is a type error, not a &lt;code&gt;Box[string]&lt;/code&gt;. Why: the result is then always the base’s type,
as the desugaring to a copy says, the value of each change is read against a known field type (so
literals and &lt;code&gt;None&lt;/code&gt; take it), and a field the change does not name, which may hold a &lt;code&gt;T&lt;/code&gt;, never
has to be re-checked at a new type. Alternative weighed: re-inferring the type arguments from the
changed fields and the kept ones, which is what a call of the variant would do; it is left for an
explicit construction, &lt;code&gt;Box(&amp;quot;s&amp;quot;, b.label)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;with-update&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;with&lt;/code&gt; is read as the update only when the brace follows it on
the same line&lt;/strong&gt;, as a postfix tail binding tighter than every prefix and infix operator; before
anything else it is an ordinary name, so &lt;code&gt;a with b&lt;/code&gt; stays the infix call of a method &lt;code&gt;with&lt;/code&gt;. Why:
keywords are contextual, and &lt;code&gt;Isolated.with&lt;/code&gt; and the library’s &lt;code&gt;shared.with(f)&lt;/code&gt; keep their names.
The cost: an infix call of a method &lt;code&gt;with&lt;/code&gt; whose argument is a set or map literal must be written
&lt;code&gt;a.with({…})&lt;/code&gt;. Alternative weighed: making &lt;code&gt;with&lt;/code&gt; a reserved word, which would rename those
methods.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;with-update&lt;/code&gt;): &lt;strong&gt;a misspelt field is reported with the nearest field&lt;/strong&gt; when it is
at most two single-byte edits away and fewer edits than the name’s length (&lt;code&gt;nmae&lt;/code&gt; suggests &lt;code&gt;name&lt;/code&gt;;
a one-letter name suggests nothing). Alternative weighed: listing every field of the type, which is
long for wide types.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-09: &lt;strong&gt;placeholder lambdas &lt;code&gt;_ + 1&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#placeholder-lambdas&quot;&gt;placeholder
lambdas&lt;/a&gt;; branch &lt;code&gt;placeholder-lambdas&lt;/code&gt;). Each &lt;code&gt;_&lt;/code&gt; in a call’s
argument is a parameter of its own, in the order written, and the smallest argument holding it is
the lambda’s body: &lt;code&gt;xs.map(_ + 1)&lt;/code&gt;, &lt;code&gt;xs.map(_.name)&lt;/code&gt;, &lt;code&gt;xs.reduce(_ + _)&lt;/code&gt;, &lt;code&gt;xs.map(f(_, 2))&lt;/code&gt;. The
right side of a &lt;code&gt;val&lt;/code&gt; with a declared function type takes one too. Parameter types come from the
expected type, as for any lambda. Why: the user’s rule that Avin adopts the conveniences that add
no complexity; the short form reads as what it does and is the usual one for a one-step function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;placeholder-lambdas&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;_&lt;/code&gt; that is a whole argument belongs to the argument
around its call&lt;/strong&gt;, so &lt;code&gt;xs.map(f(_, 2))&lt;/code&gt; is &lt;code&gt;xs.map(x -&amp;gt; f(x, 2))&lt;/code&gt; and &lt;code&gt;f(_)&lt;/code&gt; is never the identity
lambda &lt;code&gt;f(x -&amp;gt; x)&lt;/code&gt;. Where a call with such a &lt;code&gt;_&lt;/code&gt; is itself no argument and no declared value’s
right side (&lt;code&gt;f(_, 2)&lt;/code&gt; as a statement), it is an error asking for the lambda to be written out.
Why: the identity is rarely what &lt;code&gt;f(_)&lt;/code&gt; means, and &lt;code&gt;x -&amp;gt; x&lt;/code&gt; is short; reading the whole call as the
lambda is what makes partial application, &lt;code&gt;f(_, 2)&lt;/code&gt;, work. Alternative weighed: the identity
lambda, which makes &lt;code&gt;f(_, 2)&lt;/code&gt; a call of &lt;code&gt;f&lt;/code&gt; with a function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;placeholder-lambdas&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;xs.map(f(_))&lt;/code&gt; is an error saying to pass &lt;code&gt;f&lt;/code&gt;&lt;/strong&gt;: a
placeholder lambda that only calls a function named in lowercase with all its parameters in order
(&lt;code&gt;f(_)&lt;/code&gt;, &lt;code&gt;add(_, _)&lt;/code&gt;) is that function, and functions are already values. A name starting in
uppercase (&lt;code&gt;Some(_)&lt;/code&gt;, &lt;code&gt;Point(_, 0)&lt;/code&gt;) is taken for a constructor and makes the lambda. Why: one
spelling for one meaning, and the error teaches that a function is passed by name. Alternatives
weighed: accepting it as &lt;code&gt;x -&amp;gt; f(x)&lt;/code&gt; (harmless, but two spellings), and deciding by what the name
resolves to rather than its case, which needs the parser to know the checker’s answer; the case
test follows the settled naming rule. Review with the user: whether the redundant form should
simply be allowed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;placeholder-lambdas&lt;/code&gt;): &lt;strong&gt;where a placeholder is searched for.&lt;/strong&gt; Through
operators of every precedence, member access and method calls, tuple parts, &lt;code&gt;is&lt;/code&gt;, ranges, &lt;code&gt;?&lt;/code&gt;,
&lt;code&gt;with&lt;/code&gt;‘s base, a call’s callee and a call’s arguments that are &lt;code&gt;_&lt;/code&gt; alone; never into a lambda, a
block, &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt;, a collection literal, an interpolation, an assignment or another call’s other
arguments. A &lt;code&gt;_&lt;/code&gt; in those is an error, not a lambda around the nearer construct. Why: the set is
the expressions that read as one step on one value, and a &lt;code&gt;_&lt;/code&gt; inside a nested lambda or a branch
would make the reader search for which lambda it belongs to. Alternatives weighed: searching
everything to the argument (makes &lt;code&gt;xs.map(n -&amp;gt; n + _)&lt;/code&gt; a lambda returning a lambda) and searching
operators only (rejects &lt;code&gt;(_, 0)&lt;/code&gt; and &lt;code&gt;_ is Some(_)&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;placeholder-lambdas&lt;/code&gt;): &lt;strong&gt;a declared value takes a placeholder lambda only by its
written type&lt;/strong&gt;: &lt;code&gt;val f: (int) -&amp;gt; int = _ + 1&lt;/code&gt; and any declared type other than a tuple; an
undeclared &lt;code&gt;val f = _ + 1&lt;/code&gt; is an error, as are a function’s body, &lt;code&gt;return&lt;/code&gt; and an assignment’s
right side, whose expected type the parser does not see. Why: the brief’s rule, kept syntactic so
the lambda’s extent never depends on type inference. Alternative weighed: any expression with an
expected function type, which makes the extent of a lambda depend on checking. (Amended
2026-11-19, branch &lt;code&gt;underscore-fn-expected&lt;/code&gt;: a function’s body with a written result type is a
place too, since its type is written as a declared value’s is; see the entries below.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;underscore-fn-expected&lt;/code&gt;): &lt;strong&gt;a branch is a
place of its own.&lt;/strong&gt; Where an &lt;code&gt;if&lt;/code&gt;, a &lt;code&gt;match&lt;/code&gt; or a block stands where a placeholder lambda may (a
call’s argument, a declared value, a function’s body with a declared result), each branch of the
&lt;code&gt;if&lt;/code&gt;, each arm of the &lt;code&gt;match&lt;/code&gt; and the block’s last line is such a place in turn, recursively, with
a call argument’s rules: &lt;code&gt;val key: (Request) -&amp;gt; string = by match &amp;quot;method&amp;quot; -&amp;gt; _.method …&lt;/code&gt; and
&lt;code&gt;xs.map(if up then _ + 1 else _ - 1)&lt;/code&gt;. The condition, subject, guards and a block’s earlier lines
keep their own &lt;code&gt;_&lt;/code&gt;, and an &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;match&lt;/code&gt; anywhere else gives no branch a place, so
&lt;code&gt;val f = if c then _ + 1 else 0&lt;/code&gt; keeps its error. Why: a choice among functions is common
(ported command-line programs met it at once), each branch’s value is the function expected, and
the rule stays syntactic, so a lambda’s extent still never depends on checking. Alternatives
weighed: searching the whole &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt; for one lambda around it (makes &lt;code&gt;if _ &amp;gt; 0 then …&lt;/code&gt; a
lambda of the condition, a different meaning per position), and deciding by the expected type the
checker finds (any position, but extent then depends on inference). Review with the user: it
widens the 2026-11-09 rule that an &lt;code&gt;if&lt;/code&gt; and a &lt;code&gt;match&lt;/code&gt; keep their own &lt;code&gt;_&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;underscore-fn-expected&lt;/code&gt;): &lt;strong&gt;a function’s
body with a declared result type, and each of its clauses’ bodies, is a placeholder’s place&lt;/strong&gt;, by
the same rule as a declared value: any written result but a tuple, so a type alias of a function
type works, &lt;code&gt;adder(n: int) -&amp;gt; (int) -&amp;gt; int = _ + n&lt;/code&gt;. A function with no declared result is not
one, and &lt;code&gt;return&lt;/code&gt;‘s value stays none (the parser does not carry the result type to it). Why: the
result type is written beside the body as a value’s type is beside its value. Alternatives
weighed: only a result written as a function type (excludes aliases, unlike values), and leaving
bodies out as before (the 2026-11-09 reason, that the parser does not see the type, holds for
&lt;code&gt;return&lt;/code&gt; but not for a body whose type is written above it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;underscore-fn-expected&lt;/code&gt;): &lt;strong&gt;a placeholder
lambda where no function is expected is reported once&lt;/strong&gt;, as “cannot infer the type of this &lt;code&gt;_&lt;/code&gt;“,
and is then of no type, so &lt;code&gt;val n: int = _ + 1&lt;/code&gt; and &lt;code&gt;count() -&amp;gt; int = if c then _ + 1 else 0&lt;/code&gt; no
longer add “expected int, found (&lt;error&gt;) -&amp;gt; &lt;error&gt;“ or “the branches agree on no type”. Why: the
second message only repeats the first in worse words. Alternative weighed: keeping the function of
errors, which is what a written lambda’s unknown parameter still gives.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;type-aliases&lt;/code&gt;): &lt;strong&gt;type aliases are transparent&lt;/strong&gt;, &lt;code&gt;type Name[T] = Body&lt;/code&gt; (&lt;a href=&quot;/spec/declarations/#type&quot;&gt;type&lt;/a&gt;): each use is the body with the type arguments
substituted, and the checker keeps no trace of the alias, so diagnostics name the expansion. Why:
an alias is shorthand for a long type, and a type a reader can see through needs no conversion and
no new rules for equality, overloading or patterns. Alternatives weighed: a nominal alias (a new
type, as &lt;code&gt;data&lt;/code&gt; makes), which would need conversions everywhere and duplicates what a one-variant
data type already does; remembering the alias for diagnostics, which needs an alias-carrying type in
every type the checker builds and is left as a later improvement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;type-aliases&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;type&lt;/code&gt; is a declaration word only before a name&lt;/strong&gt;,
and elsewhere an ordinary name, as &lt;code&gt;actor&lt;/code&gt;, &lt;code&gt;machine&lt;/code&gt;, &lt;code&gt;lazy&lt;/code&gt; and &lt;code&gt;with&lt;/code&gt; are. Why: no Avin code in
the library or the tests names anything &lt;code&gt;type&lt;/code&gt;, but a field called &lt;code&gt;type&lt;/code&gt; is common in data that
mirrors JSON or C, and keywords are contextual where they can be. Alternative weighed: a reserved
word, which would forbid those names for no gain in parsing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;type-aliases&lt;/code&gt;): &lt;strong&gt;an alias’s type parameters take no variance, no
bounds and no lower bound; the types its body names hold its type arguments to their own bounds at
each use.&lt;/strong&gt; Why: the alias is its expansion, so its uses are held exactly as the expansion written
out would be, and a bound on the alias would only repeat the body’s (or wrongly differ from it).
Alternatives weighed: bounds on alias parameters checked against the body, as a data type’s are,
which adds a second statement of the same constraint; no check at all until the expansion is used
as a value, which would accept &lt;code&gt;Sorted[Opaque]&lt;/code&gt; in a signature.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;type-aliases&lt;/code&gt;): &lt;strong&gt;an alias whose body does not use one of its type
parameters is refused.&lt;/strong&gt; Why: &lt;code&gt;A[int]&lt;/code&gt; and &lt;code&gt;A[string]&lt;/code&gt; would be one type, which reads as a
distinction the program does not make. Alternative weighed: allowing it as a phantom parameter, which
a transparent alias cannot give any meaning. Review with the user: a phantom-type idiom would need
&lt;code&gt;data&lt;/code&gt; instead.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;type-aliases&lt;/code&gt;): &lt;strong&gt;an alias names only a type: it is not a value, a
constructor, a pattern, an impl’s target or a parent in a class’s list&lt;/strong&gt;, each refused with a
message naming the expansion, and the name that makes and matches its values where there is one.
Why: one meaning for an alias’s name keeps a call and a pattern reading as what they make and
match, and the expansion may be a tuple or a function type that has no constructor at all. An
alias of a function type in a class’s parent list is refused with the rest, though the function
type itself may be written there. Alternatives weighed: allowing an alias of a data type or a class
as its constructor and in patterns (&lt;code&gt;P(1, 2)&lt;/code&gt;), which makes an alias’s use depend on what it
expands to; allowing &lt;code&gt;impl Alias&lt;/code&gt;, which would add methods to a type under a name that does not
say which. Review with the user: aliases of traits in a parent list may be wanted later.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;type-aliases&lt;/code&gt;): &lt;strong&gt;an alias’s name may be shared with a function or a
module value, but not with any other type of its module (data type, class, object, alias), a
built-in type or &lt;code&gt;Self&lt;/code&gt;.&lt;/strong&gt; Why: an alias lives only where types are written, so a function of its
name is never ambiguous, while two types of one name would be. Alternative weighed: refusing every
clash, as a class’s name clashes with a function’s because the class’s name is also its
constructor, which an alias is not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;derives-enumerable&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Enumerable&lt;/code&gt; is a core library trait derived through an
ordinary template&lt;/strong&gt; (&lt;code&gt;library/avin/enumerable.avin&lt;/code&gt;), its members &lt;code&gt;static values() -&amp;gt; Vector[Self]&lt;/code&gt;, &lt;code&gt;ordinal() -&amp;gt; int&lt;/code&gt;, &lt;code&gt;name() -&amp;gt; string&lt;/code&gt; and &lt;code&gt;static valueOf(name: string) -&amp;gt; Option[Self]&lt;/code&gt;; the compiler’s only part is who may derive it. Why: the template mechanism already
gives every member (&lt;code&gt;T.shape()&lt;/code&gt;, &lt;code&gt;T.variantOf&lt;/code&gt;, &lt;code&gt;T.build&lt;/code&gt;), so nothing new enters the compiler
but the refusal, and the trait can be a bound (&lt;code&gt;E: Enumerable&lt;/code&gt;) in generic code. Alternatives
weighed: members the compiler writes out per type (a constant vector made once, faster
&lt;code&gt;values()&lt;/code&gt;, but a second derivation path beside the templates); an &lt;code&gt;enum&lt;/code&gt; keyword (new syntax for
what a data type already is).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;derives-enumerable&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;values()&lt;/code&gt; is a &lt;code&gt;Vector&lt;/code&gt;, made anew at each call&lt;/strong&gt;.
Why: &lt;code&gt;Vector&lt;/code&gt; is the library’s default sequence, what a literal &lt;code&gt;[a, b]&lt;/code&gt; makes; a template has
no per-type storage to keep one in, and the vector is immutable, so a fresh one is
indistinguishable from a kept one except in cost (O(variants) per call). Alternatives weighed:
&lt;code&gt;Array&lt;/code&gt; (mutable, so it would have to be copied anyway); &lt;code&gt;List&lt;/code&gt;; an iterator (cannot be indexed
by &lt;code&gt;ordinal()&lt;/code&gt;). Review with the user if &lt;code&gt;values()&lt;/code&gt; turns up in a hot loop: a compiler-kept
constant would make it free.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;derives-enumerable&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;name()&lt;/code&gt; is part of &lt;code&gt;Enumerable&lt;/code&gt;, separate from
&lt;code&gt;Display&lt;/code&gt;&lt;/strong&gt;. Why: &lt;code&gt;Display&lt;/code&gt; can be replaced by an impl, so it cannot be the inverse of
&lt;code&gt;valueOf&lt;/code&gt;; &lt;code&gt;name()&lt;/code&gt; always is, &lt;code&gt;T.valueOf(x.name()) == Some(x)&lt;/code&gt;. Alternatives weighed: reusing
&lt;code&gt;toString()&lt;/code&gt;/&lt;code&gt;Display&lt;/code&gt; (breaks the round trip once &lt;code&gt;Display&lt;/code&gt; is customised); a &lt;code&gt;static names()&lt;/code&gt; (redundant with &lt;code&gt;values().map(v -&amp;gt; v.name())&lt;/code&gt;). A type’s own method named &lt;code&gt;name&lt;/code&gt;
then clashes, reported as two methods of one name; review with the user if that proves common.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;derives-enumerable&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;valueOf&lt;/code&gt; matches the declared name exactly, byte for
byte, answering &lt;code&gt;Option&lt;/code&gt;&lt;/strong&gt;. Why: exact is predictable and cheap, and a program wanting another
rule (case-insensitive, trimmed) writes it over &lt;code&gt;values()&lt;/code&gt; and &lt;code&gt;name()&lt;/code&gt;. Alternatives weighed: a
trapping &lt;code&gt;valueOf&lt;/code&gt; (the library answers input that may be wrong with &lt;code&gt;Option&lt;/code&gt;, as
&lt;code&gt;toIntOption&lt;/code&gt; does); case-insensitive matching (ambiguous where two variants differ only in case).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;derives-enumerable&lt;/code&gt;): &lt;strong&gt;a generic data type cannot derive &lt;code&gt;Enumerable&lt;/code&gt;, even
when every variant has no fields&lt;/strong&gt; (&lt;code&gt;data Tag[A]&lt;/code&gt; with &lt;code&gt;X | Y&lt;/code&gt;). Why: a derived impl of a
generic type bounds each parameter by the trait (&lt;code&gt;impl[A: Enumerable]&lt;/code&gt;), which means nothing for
a phantom parameter, and &lt;code&gt;Tag.values()&lt;/code&gt; would need a type argument nobody can infer. A
parameterless enumeration is what such code wants. Alternative weighed: allowing it with
unbounded parameters, &lt;code&gt;Tag[int].values()&lt;/code&gt;, a special case in how templates are applied.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;derives-enumerable&lt;/code&gt;): &lt;strong&gt;only data types derive it; a class (an object cannot
write &lt;code&gt;derives&lt;/code&gt;) is refused even without constructor parameters&lt;/strong&gt;. Why: a class instance has
identity, so &lt;code&gt;values()&lt;/code&gt; would make a new instance per call, unequal to the last. Alternative
weighed: allowing a class of no parameters as an enumeration of one.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Exports between modules&lt;/strong&gt; (branch &lt;code&gt;export-reexports&lt;/code&gt;; &lt;a href=&quot;/spec/declarations/#visibility-and-modules&quot;&gt;modules&lt;/a&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;&lt;code&gt;export&lt;/code&gt; is written exactly as &lt;code&gt;import&lt;/code&gt; is&lt;/strong&gt;: &lt;code&gt;export a.b.X&lt;/code&gt;, &lt;code&gt;export a.b.{X, y as z}&lt;/code&gt;, renaming with &lt;code&gt;as&lt;/code&gt;, one top-level line each, at the top of any file of the module. Why: one
syntax to learn, and every form an import has means the same thing in an export. Alternatives
weighed: an &lt;code&gt;export&lt;/code&gt; modifier on an &lt;code&gt;import&lt;/code&gt; line (&lt;code&gt;export import a.b.X&lt;/code&gt;), which ties presenting
a name to bringing it into one file; a list in the package manifest, far from the code it shapes.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;an exported name is a name of the module, seen by every file of the exporting module
without an import&lt;/strong&gt;, and found after the module’s own declarations and before the file’s imports.
Why: a module’s files are one namespace, and an export adds to that namespace exactly as a
declaration would; a module presenting &lt;code&gt;Point&lt;/code&gt; and writing &lt;code&gt;centre(p: Point)&lt;/code&gt; beside it should
not have to import what it already offers. Alternatives weighed: an export visible only to other
modules, so the exporting file also writes the matching import (two lines per name, and a file of
the module that forgets the import sees a name its importers see but it does not); an export
visible in its own file only, as an import is (breaks “a module’s files are one namespace”).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;no wildcard export&lt;/strong&gt;, as there is no wildcard import. Why: a module’s surface stays
readable from its export lines, and a declaration added to an internal module never silently
joins the public surface. Alternative weighed: &lt;code&gt;export a.b.*&lt;/code&gt;, convenient for a facade over one
module; revisit with wildcard imports if those are ever added.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;an export names a public declaration of another module, directly or through that
module’s export; private, unknown, whole-module, own-module and root-module exports and a
&lt;code&gt;private export&lt;/code&gt; are errors.&lt;/strong&gt; Why: an export presents a declaration, never widens one, and the
root module has no name to be imported by. A whole module is not a declaration: &lt;code&gt;export a.b&lt;/code&gt;
would make a module a member of another, which modules are not. Alternatives weighed: exporting
a whole module as a nested name (&lt;code&gt;shapes.geometry&lt;/code&gt; reachable as &lt;code&gt;facade.geometry&lt;/code&gt;), which needs
module members and is left for later; letting an export make a private declaration public, which
would make &lt;code&gt;private&lt;/code&gt; meaningless to the module that wrote it.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;exports chain, and two modules may export each other’s declarations; exports that
lead round without reaching a declaration are an error at each export of the cycle.&lt;/strong&gt; Exports are
resolved from the source before anything is declared, following each chain with the names it has
passed, so a cycle stops rather than loops. A link that is wrong (a private or unknown target) is
reported where it is written, and the exports chained after it are not reported again; an import
through such a chain reports the name as private to, or missing from, the module it names.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;an exported name clashes as a declaration does, but two paths to one declaration
never clash.&lt;/strong&gt; An export clashes with a declaration of its module, with another export of the
name reaching a different declaration, with an import of a different declaration in a file of the
module, and with a module imported under that name. A module exporting a name and importing the
same declaration, exporting it from two files, and a file importing it both directly and through
an export are all accepted. Why: the error exists to stop one name meaning two things; when both
mean one declaration nothing is ambiguous. Alternative weighed: refusing every duplicate, which
makes a module that both uses and presents a declaration choose between an import and an export
for no reason.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;every kind of top-level declaration can be exported&lt;/strong&gt;: data types, aliases (generic
ones too), classes with their companion objects, objects, traits, machines (with &lt;code&gt;Door.State&lt;/code&gt;),
functions (all public overloads of the name, never a private one), module-level &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; and
&lt;code&gt;lazy val&lt;/code&gt;, and variants. A type’s variants are not exported with it: each is exported by its own
name, as each is imported by its own, and &lt;code&gt;Color.Red&lt;/code&gt; reaches one through an exported type either
way. Why: an export is a name for a declaration, and every name an import can bring in is one an
export can present; variants follow imports so the two never differ. Alternative weighed:
exporting a data type’s variants with it, which an import does not do either.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;a module that exports a declaration of another presents that module’s extensions&lt;/strong&gt;:
the exporting module’s own files, and every file importing it whole or any name of it, see the
methods the other module’s extensions add; a file importing a declaration through an export sees
its declaring module’s extensions as a direct import would. Why: “importing a module or any of
its declarations brings in its extensions” should not depend on which path reached the
declaration, and a facade over a package should carry the package’s extensions with it. Only
modules whose declarations are exported are presented, not modules the exporter merely imports.
Alternatives weighed: extensions reached only by importing their module directly (a facade could
not offer a package’s extension methods at all); an explicit &lt;code&gt;export&lt;/code&gt; of an extension (an impl
has no name to export). Review with the user: this widens which extensions a file sees.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;&lt;code&gt;export&lt;/code&gt; is a contextual word&lt;/strong&gt;, meaning an export only at the start of a top-level
line before a name, and an ordinary name everywhere else (a function &lt;code&gt;export(…)&lt;/code&gt;, a field, a
parameter, a local). Why: as &lt;code&gt;type&lt;/code&gt; is; nothing in the library or tests names anything &lt;code&gt;export&lt;/code&gt;
today, but the word is a natural method name (&lt;code&gt;report.export()&lt;/code&gt;), and keeping it free costs one
token of lookahead. Alternative weighed: a reserved keyword, simpler to lex but taking a useful
name from every program.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;a diagnostic and the language server name the declaration an export reaches&lt;/strong&gt;: an
import clash reports &lt;code&gt;already imported, from \&lt;/code&gt;inner.Widget`&lt;code&gt;, the declaring module&apos;s path, and go-to-definition on an exported name (at the export line or any import of it) goes to the declaration itself. Completion after &lt;/code&gt;m.` does not yet list a module’s exports (see Open).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Member exports&lt;/strong&gt; (branch &lt;code&gt;member-export&lt;/code&gt;; &lt;a href=&quot;/spec/declarations/#exporting-members&quot;&gt;exporting members&lt;/a&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;export f.m&lt;/code&gt; in a type’s body is written as a
module export is&lt;/strong&gt;, one member, a &lt;code&gt;{…}&lt;/code&gt; group, &lt;code&gt;as&lt;/code&gt; renaming, with operators by their spelling
(&lt;code&gt;export n.+&lt;/code&gt;), in the body of a class or an object, or in a plain &lt;code&gt;impl&lt;/code&gt; of a data type of the
impl’s own module (a data type has no body of its own). Why: one form for presenting something
as one’s own, at the module and at the type. Alternatives weighed: a modifier on the field
(&lt;code&gt;delegate val items&lt;/code&gt;, all or nothing); generated wrapper methods the program writes itself
(what the feature exists to save).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;export f.*&lt;/code&gt; presents every public member of
what &lt;code&gt;f&lt;/code&gt; holds that the type does not have itself&lt;/strong&gt;, unlike module exports, which have no
wildcard. Why: the usual forwarding is a wrapper over one value’s whole surface, with a few
members of its own replacing the wrapped one’s; listing every member defeats it. The module rule
was about a declaration added to an internal module joining a public surface unseen; here the
wrapped type is named in the field’s declared type, so what joins is visible there. Spelled &lt;code&gt;*&lt;/code&gt;,
not &lt;code&gt;_&lt;/code&gt;, since &lt;code&gt;_&lt;/code&gt; is a placeholder lambda in an expression and a hole in a type. Alternatives
weighed: no wildcard, as for modules; &lt;code&gt;_&lt;/code&gt;. Review with the user: the one place the two export
forms differ.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a use is the use of &lt;code&gt;x.f.m&lt;/code&gt;, checked as that
code&lt;/strong&gt;, a fallback of the checker’s member lookup after the type’s own members, its superclasses’,
its traits’ and its impls’: calls with every overload, defaults, named and repeated arguments and
type arguments, reads, assignments of a &lt;code&gt;var&lt;/code&gt; field (&lt;code&gt;x.m = v&lt;/code&gt;, &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;), method values bound
to &lt;code&gt;x.f&lt;/code&gt; as read then, infix calls and operators (&lt;code&gt;a + b&lt;/code&gt;, a lone &lt;code&gt;a &amp;lt; b&lt;/code&gt;). Why: forwarding then
means exactly what the longer code means, with its diagnostics, and needs no copy of a member’s
signature to drift from it. Alternatives weighed: a wrapper method per overload, generated into
the type (copies defaults, repeated and by-name parameters and type parameters of each member,
and reports mistakes against the copy).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;f&lt;/code&gt; is a field (own, or a public inherited one)
or a method of no parameter list, with its type declared, read again at every use.&lt;/strong&gt; A &lt;code&gt;var&lt;/code&gt;
field reassigned between calls sends each to the value it then holds; a method &lt;code&gt;f&lt;/code&gt; runs at each
use. Why: the export is part of the type’s surface, which other declarations (trait conformance,
completion) need before any body is checked; a class parameter’s type is always written, so the
common case costs nothing. Alternatives weighed: inferring an undeclared field’s type by checking
the class body first, as a field read does (makes a declaration depend on a body); reading &lt;code&gt;f&lt;/code&gt;
once at construction (a &lt;code&gt;var&lt;/code&gt; field’s export would go stale).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;an export presents public members only&lt;/strong&gt;: never
a private one, by name or by &lt;code&gt;*&lt;/code&gt;, never a static one, never &lt;code&gt;equals&lt;/code&gt; or &lt;code&gt;hash&lt;/code&gt; (every value has
its own); a member the field’s type exports in turn counts, so exports chain. Exports by name that
lead round without reaching a member are an error at each export of the round, and wildcards that
lead round present nothing (each search stops at a depth bounded by the program’s types).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;the type’s own members win; an export by name of
a member the type has is an error.&lt;/strong&gt; A wildcard silently leaves the type’s own members (and its
superclasses’, traits’ and impls’) to them, the usual way to replace a few of a wrapped value’s
members. An export by name of a member the type declares, a field of its own or inherited, or a
superclass’s method is an error, since naming a member and declaring it says two things; so are
two exports by name of one name (naming both), and a subclass member named like an export its
superclass makes by name (a use through the superclass would reach the export and one through the
subclass the member, with no override between them). An export by name comes before a wildcard,
and two wildcards both reaching a name make a use of it an error naming both. Alternatives
weighed: the type’s own member silently winning over an export by name too (hides a mistake); an
export by name winning over the type’s own member (makes the member dead code). Review with the
user: the conflict rule.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a public export by name of a class implements the
trait’s methods of its name&lt;/strong&gt; that the class does not declare: the class gets a method with the
trait’s signature whose body is &lt;code&gt;self.f.m(params)&lt;/code&gt;, standing as an &lt;code&gt;override&lt;/code&gt; would (it replaces a
default too), so a call through the trait reaches the member; every overload of the trait’s name
is implemented. A wildcard implements nothing, a private export of a trait method’s name is an
error, a trait method with type parameters of its own is reported at the export, and a data type’s
export implements nothing (its trait impls write their methods). A member that cannot be called
with the trait method’s parameters, or yields another type, is one error at the export naming the
export, the trait’s method, both signatures and the mismatch, never the diagnostics of the method
written for it. Why:
delegation-based conformance is most of what forwarding is for; requiring the name keeps a class’s
conformance readable from its declaration, and keeps it from depending on what a wrapped type
happens to have. Alternatives weighed: forwards never counting toward a trait (every conformance
written out by hand); a wildcard counting too (a trait met by a member the class never names).
Review with the user: trait satisfaction, its restriction to exports by name and to classes, and
methods with type parameters of their own.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;an export is reached through a value&lt;/strong&gt;, &lt;code&gt;x.m&lt;/code&gt;
and &lt;code&gt;self.m&lt;/code&gt;, never by a bare &lt;code&gt;m&lt;/code&gt; inside the type nor by &lt;code&gt;Type.m&lt;/code&gt;. Why: a wildcard adding bare
names to the type’s code would hide top-level declarations whenever the wrapped type grows a
member; inside the type the field itself is in scope. Alternative weighed: bare names reaching
exports as members do.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;private export&lt;/code&gt; presents the members to the
type’s own code&lt;/strong&gt; (its class and companion, or a data type’s impls), as a private method is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;the editor follows an export&lt;/strong&gt;: completion after
a dot offers the members a value’s exports present, under the names presented, and
go-to-definition (and hover) on a use, an alias or the export line reaches the member’s
declaration, the field read included.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (built on branch &lt;code&gt;regex-budget&lt;/code&gt;, for &lt;code&gt;marshal grep&lt;/code&gt;): &lt;a href=&quot;/spec/regex/#matching&quot;&gt;&lt;code&gt;avin.regex&lt;/code&gt;‘s checked
searches&lt;/a&gt;. A spent step budget becomes a failure the caller can handle,
answering the review question left on the settled limits on matching:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A checked family beside the plain API&lt;/strong&gt;: &lt;code&gt;tryMatches&lt;/code&gt;, &lt;code&gt;tryFindFirstIn&lt;/code&gt;,
&lt;code&gt;tryFindFirstMatchIn&lt;/code&gt;, &lt;code&gt;tryFindPrefixOf&lt;/code&gt;, &lt;code&gt;tryFindPrefixMatchOf&lt;/code&gt;, &lt;code&gt;tryFindAllIn&lt;/code&gt;,
&lt;code&gt;tryFindAllMatchIn&lt;/code&gt;, &lt;code&gt;tryReplaceAllIn&lt;/code&gt; (both forms), &lt;code&gt;tryReplaceFirstIn&lt;/code&gt;, &lt;code&gt;tryReplaceSomeIn&lt;/code&gt;,
&lt;code&gt;trySplit&lt;/code&gt; and &lt;code&gt;Pattern.trySplit&lt;/code&gt;, each &lt;code&gt;Result[T, MatchError]&lt;/code&gt; with &lt;code&gt;T&lt;/code&gt; what the plain search
answers. &lt;em&gt;Why&lt;/em&gt;: a pattern written in the program that backtracks too far is a defect the trap
explains, and every &lt;code&gt;findFirstIn&lt;/code&gt; stays a plain &lt;code&gt;Option&lt;/code&gt;; a program searching outside text or
patterns (a grep) needs to go on, and says so by its choice of method. It mirrors
&lt;code&gt;Regex(p)&lt;/code&gt; beside &lt;code&gt;Regex.compile(p)&lt;/code&gt; and &lt;code&gt;Url(text)&lt;/code&gt; beside &lt;code&gt;Url.parse&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: every
search answering a &lt;code&gt;Result&lt;/code&gt; (breaking, and makes every search fallible for what is almost
always a defect); a regex-level mode (&lt;code&gt;checked()&lt;/code&gt;) changing what the plain methods do on
overflow (the result type cannot change with it, so it would need a sentinel); an
&lt;code&gt;error()&lt;/code&gt; query on the iterator after it stops (easy to forget, so a spent budget reads as “no
more matches”).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The gathered forms of every-match searches&lt;/strong&gt;: &lt;code&gt;tryFindAllIn&lt;/code&gt; answers a &lt;code&gt;Vector&lt;/code&gt;, not an
iterator, and the error discards the matches found before it; a replacer has been called for
those by then. &lt;em&gt;Why&lt;/em&gt;: an iterator of &lt;code&gt;Result&lt;/code&gt;s, or one whose end might be an error, makes the
common loop longer and is easy to read wrongly. &lt;em&gt;Alternatives&lt;/em&gt;: an &lt;code&gt;Iterator[Result[Match, MatchError]]&lt;/code&gt;; giving the matches found so far with the error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;MatchError(pattern, inputLength, budget)&lt;/code&gt;, a plain &lt;code&gt;data&lt;/code&gt; type&lt;/strong&gt; with &lt;code&gt;message()&lt;/code&gt; and
&lt;code&gt;Display&lt;/code&gt;, as &lt;code&gt;PatternError&lt;/code&gt; is; &lt;code&gt;inputLength&lt;/code&gt; counts characters. &lt;em&gt;Alternatives&lt;/em&gt;: a &lt;code&gt;RegexError&lt;/code&gt;
with variants for both kinds of failure (&lt;code&gt;compile&lt;/code&gt; would change type, breaking); a bare message
string.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The plain searches still trap&lt;/strong&gt;, the message now naming the budget and the checked
alternative: &lt;code&gt;… past its budget of N steps; make a repetition possessive or atomic, or search with a &lt;/code&gt;try&lt;code&gt; method to handle it&lt;/code&gt;. The budget stays per regex (&lt;code&gt;withStepLimit&lt;/code&gt;), its default
unchanged. &lt;em&gt;Alternatives&lt;/em&gt;: a per-call limit argument on the &lt;code&gt;try&lt;/code&gt; methods (doubles every
signature; &lt;code&gt;withStepLimit&lt;/code&gt; is cheap to call per search).&lt;/li&gt;
&lt;li&gt;The matcher learns of a spent budget by a flag every step checks, so a spent budget ends the
whole search through every nested part; a lookaround’s or atomic group’s body answering no for
it is never taken as the body failing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (built on branch &lt;code&gt;regex-sendable&lt;/code&gt;, a gap the
concurrent-program ports met): &lt;strong&gt;a compiled &lt;a href=&quot;/spec/regex/#regex&quot;&gt;&lt;code&gt;Regex&lt;/code&gt;&lt;/a&gt;, its &lt;code&gt;Pattern&lt;/code&gt; and a
&lt;code&gt;Match&lt;/code&gt; are sendable&lt;/strong&gt;, and each class declares &lt;code&gt;: Sendable&lt;/code&gt;, so a change that makes one hold
something mutable fails to compile in the library rather than in a program. A &lt;code&gt;MatchIterator&lt;/code&gt;
stays not sendable: it is a search in progress. &lt;em&gt;How&lt;/em&gt;: a compiled program’s operations, a
literal’s characters and a branch’s alternatives are &lt;code&gt;ArraySeq&lt;/code&gt;s, filled once at compile time; a
character class’s test is a &lt;code&gt;@sendable (int) -&amp;gt; bool&lt;/code&gt;, so every closure that builds one is checked
to capture only sendable values (a class’s table of the first 256 characters is copied into an
&lt;code&gt;ArraySeq&lt;/code&gt;); and a class’s answers for the characters below 128, an array of 128 &lt;code&gt;bool&lt;/code&gt;s, are two
&lt;code&gt;long&lt;/code&gt;s of bits, which is no slower and holds nothing mutable. Each search already kept its own
state (the engine’s groups, locals and backtracking stack), so no search allocates more than
before. A &lt;code&gt;Match&lt;/code&gt; holds its group offsets as &lt;code&gt;ArraySeq&lt;/code&gt;s, which costs one copy of two small arrays
per &lt;code&gt;Match&lt;/code&gt; made; &lt;code&gt;split&lt;/code&gt; no longer makes a &lt;code&gt;Match&lt;/code&gt; per piece at all. &lt;em&gt;Why&lt;/em&gt;: a pattern compiled
once at module level and used from every worker is the ordinary way to write a concurrent
scanner, crawler or server, and an immutable value that cannot be shared reads as a defect.
&lt;em&gt;Alternatives&lt;/em&gt;: compiling a regex per thread (what the port had to do; wasteful and easy to miss);
a &lt;code&gt;@sendable&lt;/code&gt; field marker trusting the library (no check would keep it true); making the core
library’s frozen array type reachable from &lt;code&gt;avin.regex&lt;/code&gt; (saves one load per operation dispatched
but widens what the core module shares; &lt;code&gt;ArraySeq&lt;/code&gt; is the public form of the same thing).
Review with the user: whether the one extra load per dispatched operation through &lt;code&gt;ArraySeq&lt;/code&gt;
is worth a library-internal way to name a frozen array outside the core module.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09: &lt;strong&gt;Union types: the rules beyond the user’s five points&lt;/strong&gt; (branch &lt;code&gt;unions-design&lt;/code&gt;;
&lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Precedence: &lt;code&gt;|&lt;/code&gt; binds tighter than &lt;code&gt;-&amp;gt;&lt;/code&gt; and looser than everything else in a type&lt;/strong&gt;, so
&lt;code&gt;(A) -&amp;gt; B | C&lt;/code&gt; returns a union and a union of functions parenthesizes each. &lt;em&gt;Why&lt;/em&gt;: a function
returning one of several results is far more common than a union with a function member, and
&lt;code&gt;-&amp;gt;&lt;/code&gt; is already the loosest type operator. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;|&lt;/code&gt; looser than &lt;code&gt;-&amp;gt;&lt;/code&gt; (makes the
common case need parentheses); refusing the unparenthesized form (noisy).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A union in a type pattern is parenthesized&lt;/strong&gt;, &lt;code&gt;x: (int | string) -&amp;gt;&lt;/code&gt;; a &lt;code&gt;|&lt;/code&gt; in a pattern is
always an alternative, and &lt;code&gt;x: int | string&lt;/code&gt; is reported with the parenthesized form. &lt;em&gt;Why&lt;/em&gt;: it
keeps one meaning for &lt;code&gt;|&lt;/code&gt; in patterns, as function types already need parentheses there.
&lt;em&gt;Alternatives&lt;/em&gt;: parsing a type after &lt;code&gt;:&lt;/code&gt; greedily (makes &lt;code&gt;_: A | _: B&lt;/code&gt; mean something else).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Normal form: flatten, order irrelevant, a member that converts to another member (by subtyping
or boxing into a trait or &lt;code&gt;Any&lt;/code&gt;) absorbed, &lt;code&gt;Nothing&lt;/code&gt; absorbed, one member is that member. Written
by hand, a duplicate, absorbed or &lt;code&gt;Nothing&lt;/code&gt; member is an error naming the type to write; arising
through an alias or type argument it is absorbed silently.&lt;/strong&gt; &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;T | int&lt;/code&gt; at &lt;code&gt;T = int&lt;/code&gt; and
&lt;code&gt;T | Animal&lt;/code&gt; at &lt;code&gt;T = Dog&lt;/code&gt; must compile, while &lt;code&gt;Dog | Animal&lt;/code&gt; written out is almost certainly a
mistake. Absorbing by conversion rather than subtyping alone keeps every injection unambiguous
(&lt;code&gt;int | Display&lt;/code&gt; would otherwise leave an &lt;code&gt;int&lt;/code&gt; two homes). &lt;em&gt;Alternatives&lt;/em&gt;: keep subsumed members
distinct (two homes for one value, an ambiguity on every injection); refuse at instantiation too
(breaks generic code); silently absorb written duplicates (hides mistakes). Review with the user:
whether written duplicates should be errors or warnings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inference carries a union it is given and never forms one&lt;/strong&gt;: &lt;code&gt;val u2 = u&lt;/code&gt; is the union; a
union and its member join to the union; &lt;code&gt;T&lt;/code&gt; in &lt;code&gt;x: T | string&lt;/code&gt; takes the members the argument
leaves over (&lt;code&gt;orText(u)&lt;/code&gt; with &lt;code&gt;u: int | bool | string&lt;/code&gt; gives &lt;code&gt;T = int | bool&lt;/code&gt;); a member argument
decides no &lt;code&gt;T&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: anything less makes unions unusable in generic code; forming one would be
the inference the user ruled out. &lt;em&gt;Alternatives&lt;/em&gt;: refusing to solve &lt;code&gt;T&lt;/code&gt; against a union (forces
explicit type arguments everywhere).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Injection at a single site, like boxing&lt;/strong&gt;: a member’s own type first, else the one member it
converts to, several an error naming them; a literal takes its default type where that is a
member, else the one numeric member it fits; &lt;code&gt;None&lt;/code&gt;/&lt;code&gt;Ok(x)&lt;/code&gt;/an empty literal go to the one member
that is an instance of their type. &lt;em&gt;Why&lt;/em&gt;: mirrors how a value becomes an &lt;code&gt;Any&lt;/code&gt;, and never guesses.
&lt;em&gt;Alternatives&lt;/em&gt;: choosing the first member written (order would then matter, contradicting the
normal form).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Overloads&lt;/strong&gt;: a member type is more specific than a union containing it; a union more specific
than a type every member converts to; a union argument never chooses among member overloads (an
error suggesting a &lt;code&gt;match&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: overloads are resolved statically (settled 2026-11-02).
&lt;em&gt;Alternatives&lt;/em&gt;: generating a dispatch &lt;code&gt;match&lt;/code&gt; over member overloads (dynamic overloading, which
the language does not have).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A named function is adapted where written&lt;/strong&gt; to a function type whose parameters inject into its
union parameters (&lt;code&gt;val f: (int) -&amp;gt; string = describe&lt;/code&gt;); a function value already made is not.
&lt;em&gt;Why&lt;/em&gt;: the same single-site rule as &lt;code&gt;@sendable&lt;/code&gt; references. &lt;em&gt;Alternatives&lt;/em&gt;: always requiring a
lambda (a contortion for the common case).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Representation: a union whose members are all types an &lt;code&gt;Any&lt;/code&gt; holds without a box is laid out
as an &lt;code&gt;Any&lt;/code&gt; (one pointer, the header as the tag); one with a scalar member is a tag, a bits slot
and, if any member is a reference, a separate pointer slot.&lt;/strong&gt; Consequently variance through
containers holds exactly where the layouts agree: &lt;code&gt;List[Dog] &amp;lt;: List[Dog | Cat]&lt;/code&gt;,
&lt;code&gt;Result[T, IoError] &amp;lt;: Result[T, IoError | ParseError]&lt;/code&gt;, but not &lt;code&gt;List[int] &amp;lt;: List[int | string]&lt;/code&gt;.
Tag numbering follows the normal form, and the layout is decided before optimization, so -O0 and
-O2 agree. &lt;em&gt;Why&lt;/em&gt;: reference unions cost nothing over &lt;code&gt;Any&lt;/code&gt; and keep &lt;code&gt;?&lt;/code&gt;‘s common case free;
scalar unions avoid an allocation per value; the separate pointer slot keeps the collector’s
roots exact. &lt;em&gt;Alternatives&lt;/em&gt;: every union boxed as an &lt;code&gt;Any&lt;/code&gt; (simplest, but &lt;code&gt;int | long&lt;/code&gt; allocates);
every union a tag-and-payload value (no variance through containers, a conversion for every
&lt;code&gt;Result&lt;/code&gt; of a wider error); one overlapping payload word (needs tag-aware root scanning).
Review with the user: the variance consequence is visible to programs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;match&lt;/code&gt;&lt;/strong&gt;: type patterns, supertypes and sub-unions cover members; any other pattern applies to
the one member it can match (&lt;code&gt;0&lt;/code&gt; and &lt;code&gt;n &amp;lt; 0&lt;/code&gt; on an &lt;code&gt;int | string&lt;/code&gt; reach the int), and one more than
one member could match is an error; a type pattern naming no member is an error; in generic code
the &lt;code&gt;match&lt;/code&gt; is checked as written and, at an instance where members come together, the first arm
in order wins. &lt;em&gt;Why&lt;/em&gt;: lets literals and constructors reach their member without a nested
&lt;code&gt;match&lt;/code&gt;, without guessing. &lt;em&gt;Alternatives&lt;/em&gt;: type patterns only, as on an &lt;code&gt;Any&lt;/code&gt; (verbose).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;is&lt;/code&gt; binds, it does not narrow&lt;/strong&gt;: &lt;code&gt;v&lt;/code&gt; keeps its union type after &lt;code&gt;if v is _: string&lt;/code&gt;; the
pattern binds a name. &lt;em&gt;Why&lt;/em&gt;: the settled &lt;code&gt;is&lt;/code&gt; scoping (2026-11-03) has no flow-sensitive typing,
and unions should not introduce it. &lt;em&gt;Alternatives&lt;/em&gt;: flow narrowing of the tested variable
(a new, language-wide mechanism). Review with the user.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What a union can do&lt;/strong&gt;: &lt;code&gt;==&lt;/code&gt; and hashing as two &lt;code&gt;Any&lt;/code&gt;s holding the values; &lt;code&gt;===&lt;/code&gt; only where every
member is a class or function type; a union conforms to a trait every member conforms to whose
methods take &lt;code&gt;Self&lt;/code&gt; only as receiver (&lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, a library &lt;code&gt;JsonEncoder&lt;/code&gt;), plus
&lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Sendable&lt;/code&gt; member-wise, never &lt;code&gt;Ord&lt;/code&gt;; a member call is looked up on the members’ join and
on those traits, ambiguity an error. &lt;em&gt;Why&lt;/em&gt;: printing, hashing and calling a shared superclass
method are what a union is used for; &lt;code&gt;Ord&lt;/code&gt; would need an order between members that order-free
unions cannot give. &lt;em&gt;Alternatives&lt;/em&gt;: refusing every member call (forces a &lt;code&gt;match&lt;/code&gt; just to call a
method every member has); any method name every member has, structurally (breaks the nominal
principle, and its result would be an inferred union). Review with the user.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;?&lt;/code&gt; with unions&lt;/strong&gt;: (1) &lt;code&gt;E&lt;/code&gt; converting to &lt;code&gt;F&lt;/code&gt; (a member, a member’s subtype, a union of members)
passes on unchanged; (2) for a union &lt;code&gt;F&lt;/code&gt;, the one member implementing &lt;code&gt;From[E]&lt;/code&gt; converts; (3) for a
union &lt;code&gt;E&lt;/code&gt; and a plain &lt;code&gt;F&lt;/code&gt;, each member converts on its own; (4) otherwise &lt;code&gt;F.from(e)&lt;/code&gt; as before.
&lt;code&gt;?&lt;/code&gt; never adds a member. &lt;em&gt;Why&lt;/em&gt;: unions replace hand-written wrapper error types without breaking
the &lt;code&gt;From&lt;/code&gt; rule existing code relies on. &lt;em&gt;Alternatives&lt;/em&gt;: a union &lt;code&gt;F&lt;/code&gt; consulting no &lt;code&gt;From&lt;/code&gt; (loses
the bridge from wrapper errors); inferring the error union from the &lt;code&gt;?&lt;/code&gt;s in the body (the
inference the user ruled out).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Refused&lt;/strong&gt;: &lt;code&gt;impl&lt;/code&gt; or extension on a union; a union as a parent or as an upper bound (a lower
bound is allowed); a union across &lt;code&gt;@sysl&lt;/code&gt;/&lt;code&gt;@c&lt;/code&gt; declarations and mirrors; a &lt;code&gt;with { … }&lt;/code&gt; field path
through a union field; casts, calls and construction of a union. &lt;em&gt;Why&lt;/em&gt;: each needs a declared
type or a C/Sysl layout a union does not have. &lt;em&gt;Alternatives&lt;/em&gt;: shims that pass a tag and payload
across a binding (no Sysl or C library takes one).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chapter&lt;/strong&gt;: a chapter of its own, &lt;code&gt;spec/unions.md&lt;/code&gt;, linked from types, generics, errors and
&lt;code&gt;match&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: a section of types.md (too long for one section).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-09 (branch &lt;code&gt;unions-core&lt;/code&gt;): &lt;strong&gt;Union types: the choices the core’s implementation
made&lt;/strong&gt; (&lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every union is laid out as an &lt;code&gt;Any&lt;/code&gt; for now, a scalar member in a box.&lt;/strong&gt; The chapter’s
tag-and-payload layout for a union with a scalar member needs values of more than one machine
word in the compiler’s intermediate code (parameters, results, fields, array elements, closure
captures), which nothing else in the language has; the core ships without it. The type rules stay
the chapter’s, so programs do not change when the layout lands: &lt;code&gt;List[int]&lt;/code&gt; is still no
&lt;code&gt;List[int | string]&lt;/code&gt;, and a union of references still nests in covariant containers. &lt;em&gt;Why&lt;/em&gt;: one
layout makes every part of the core correct now (exact roots, &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; alike, equality,
hashing and rendering through the &lt;code&gt;Any&lt;/code&gt; machinery), at the cost of a box per scalar injected.
&lt;em&gt;Alternatives&lt;/em&gt;: building the multi-word value first (holds every other part of the item); a single
tagged word (cannot hold a &lt;code&gt;long&lt;/code&gt; and a pointer apart, so roots would not be exact). Review with the
user: the allocation per scalar injection until the layout lands.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A copy of generic code at a union type argument is a copy of its own&lt;/strong&gt;, so a type pattern naming
the parameter tests the union’s members, &lt;code&gt;t: T&lt;/code&gt; at &lt;code&gt;T = int | bool&lt;/code&gt; taking neither a string nor
anything else. Through a method called by its table, the type argument is still taken as &lt;code&gt;Any&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: a function’s copies are keyed by their type arguments, and the union is one; a method’s
table slot is shared by every receiver. &lt;em&gt;Alternatives&lt;/em&gt;: erasing every union type argument to &lt;code&gt;Any&lt;/code&gt;
(a &lt;code&gt;T&lt;/code&gt; arm would take every value).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Members that come together through a type argument are merged when they are the same type, and
a member a subtype of another is kept, injection choosing the widest.&lt;/strong&gt; &lt;code&gt;T | int&lt;/code&gt; at &lt;code&gt;T = int&lt;/code&gt; is
&lt;code&gt;int&lt;/code&gt;; &lt;code&gt;T | Animal&lt;/code&gt; at &lt;code&gt;T = Dog&lt;/code&gt; keeps both members in the type, and a &lt;code&gt;Puppy&lt;/code&gt; given to it is the
&lt;code&gt;Animal&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: substitution is done where the class table is not at hand; the two forms hold the
same values and match the same way, and only a message names the difference. &lt;em&gt;Alternatives&lt;/em&gt;:
absorbing subtypes at every substitution (needs the declarations at each one).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;x: int | string&lt;/code&gt; in a pattern is recognized as a type pattern followed by bare names that are
no variants&lt;/strong&gt;, and reported with the parenthesized form; any other alternatives are checked as
written. &lt;em&gt;Why&lt;/em&gt;: a bare name is a binding, which alternatives refuse anyway, so nothing legal is
taken from the program. &lt;em&gt;Alternatives&lt;/em&gt;: deciding it in the parser (cannot tell a variant from a
type there).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;|&lt;/code&gt; after a type is a guard, not a union member, where the name after it is followed by an
operator no type is followed by&lt;/strong&gt; (a comparison, arithmetic, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;), so
&lt;code&gt;f(n: int) -&amp;gt; int | n &amp;gt; 0 = n&lt;/code&gt; is still reported as a guard on a signature. &lt;em&gt;Why&lt;/em&gt;: keeps the
existing clause diagnostics. &lt;em&gt;Alternatives&lt;/em&gt;: refusing &lt;code&gt;|&lt;/code&gt; after a result type outside brackets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Messages the chapter left open&lt;/strong&gt; are those of &lt;a href=&quot;/spec/unions/#what-is-refused&quot;&gt;what is refused&lt;/a&gt;
and these: a pattern several members could match names them and suggests a type pattern; &lt;code&gt;None&lt;/code&gt;,
&lt;code&gt;Ok(…)&lt;/code&gt;, a collection literal or a lambda with several members of its kind names them and asks for
the type meant; a literal several numeric members fit names them and suggests a conversion, as in
&lt;code&gt;byte(3)&lt;/code&gt;; two arguments of one type parameter that agree on no type add that a type argument is
never inferred as a union, with the union to write; a missing clause names the member, as in
&lt;code&gt;size(_: string)&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: each says what to write. &lt;em&gt;Alternatives&lt;/em&gt;: the generic messages, which
name no member.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10: &lt;strong&gt;Union types: the operations’ choices the chapter left open&lt;/strong&gt; (branch
&lt;code&gt;unions-ops&lt;/code&gt;; &lt;a href=&quot;/spec/unions/&quot;&gt;union types&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;?&lt;/code&gt; converts an error union member by member whatever the function’s error type is&lt;/strong&gt;, not
only where it is no union: an &lt;code&gt;IoError | ParseError&lt;/code&gt; passed on from a function yielding
&lt;code&gt;ConfigError | Invalid&lt;/code&gt;, where &lt;code&gt;ConfigError&lt;/code&gt; implements &lt;code&gt;From&lt;/code&gt; at each, converts each member by
rule 2. &lt;em&gt;Why&lt;/em&gt;: rules 1 and 2 cannot reach this case (no member implements &lt;code&gt;From&lt;/code&gt; at the union),
so rule 3 as written would leave it an error with no way to say what to do but &lt;code&gt;mapErr&lt;/code&gt;, while
each member converts on its own; the extension only turns an error into the conversion a reader
expects. &lt;em&gt;Alternatives&lt;/em&gt;: keep rule 3 for a plain &lt;code&gt;F&lt;/code&gt; only (refuses an obvious program);
implement &lt;code&gt;From&lt;/code&gt; at a union (a union has no &lt;code&gt;impl&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait with type parameters counts for a union through the one instance every member
holds&lt;/strong&gt;: &lt;code&gt;Vector[int] | List[int]&lt;/code&gt; has &lt;code&gt;Seq[int]&lt;/code&gt;‘s methods, so &lt;code&gt;u.size()&lt;/code&gt; and &lt;code&gt;u.map(…)&lt;/code&gt; work
although the two join on no type. &lt;em&gt;Why&lt;/em&gt;: the chapter’s rule (“the traits the union conforms to”)
names no restriction to traits without parameters, and the instance is unambiguous when the
members agree on it. &lt;em&gt;Alternatives&lt;/em&gt;: only traits without type parameters (refuses the common
sequence case); every instance any member holds (ambiguous).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A member of the union found through a trait or the join is called, named as a value or read
as a field with the union seen as that type&lt;/strong&gt;, with no conversion, as an &lt;code&gt;Any&lt;/code&gt; holding its
member is seen: a field of the join class is read (&lt;code&gt;p.called&lt;/code&gt; on &lt;code&gt;Puppy | Kitten&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: the
union is laid out as an &lt;code&gt;Any&lt;/code&gt;, which already is a value of every trait and class its member is;
the field is the chapter’s “looked up where it would be on the members’ join”. &lt;em&gt;Alternatives&lt;/em&gt;:
methods only (a field of the shared superclass would need a &lt;code&gt;match&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;===&lt;/code&gt; between a union with a value member and an object of a class is accepted&lt;/strong&gt;, answering
&lt;code&gt;false&lt;/code&gt; for a value member, as it is between an &lt;code&gt;Any&lt;/code&gt; and an object; it is refused where neither
side holds only objects (&lt;code&gt;Dog | int&lt;/code&gt; against an &lt;code&gt;Any&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: the identity chapter’s rule for
&lt;code&gt;Any&lt;/code&gt;, which the union chapter says the union follows. &lt;em&gt;Alternatives&lt;/em&gt;: refuse every &lt;code&gt;===&lt;/code&gt; on a
union with a value member (stricter than &lt;code&gt;Any&lt;/code&gt;, with no added safety).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The diagnostics’ wording&lt;/strong&gt;: a union argument to overloads of its members says the member is
known only while running and suggests a &lt;code&gt;match&lt;/code&gt;; a bound a union misses says why (no order;
the member that does not conform; a trait taking &lt;code&gt;Self&lt;/code&gt; other than as the receiver); a result
with a scalar error union names &lt;code&gt;mapErr(e -&amp;gt; e)&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: each names the fix. &lt;em&gt;Alternatives&lt;/em&gt;: the
general messages alone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-sockets&lt;/code&gt;): &lt;strong&gt;a socket wait parks on one poller with a thread of its own, one
readiness report per wait.&lt;/strong&gt; Every socket &lt;code&gt;avin.net&lt;/code&gt; makes is non-blocking; an operation that would
have to wait registers the descriptor with the runtime’s single &lt;code&gt;sysl.io.poll&lt;/code&gt; set as &lt;code&gt;OneShot&lt;/code&gt;,
under a token naming a slot that holds the waiter, and parks; the poller’s own operating system
thread waits on the set and makes each reported waiter ready, and the operation is tried again. A
slot is let go under one lock by whichever ends the wait, so a report arriving after a timeout
finds its slot gone or taken again under a newer token and wakes nobody. &lt;em&gt;Why&lt;/em&gt;: the monitor sleeps
on a condition, which a kernel set cannot wake, and a thread blocked in the set’s wait needs nothing
else; a one-shot registration per wait can never deliver a stale wake to a later wait on another
thing. &lt;em&gt;Alternatives&lt;/em&gt;: the monitor waiting on the poller with the soonest timer as its timeout
(the timers then move under the poller, a larger change to settled code, which this choice does not
preclude); workers polling the set between threads (no extra thread, but a worker with nothing ready
then sleeps in the kernel instead of on its condition, and wakes need a second path); a level- or
edge-triggered registration kept for the socket’s life (one system call less per wait, but a
report for a wait that has ended can reach the next one, so every wait in the runtime would have to
tolerate spurious wakes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-sockets&lt;/code&gt;): &lt;strong&gt;a connection’s timeout bounds each wait, not the whole
operation.&lt;/strong&gt; A write that waits for room several times fails with &lt;code&gt;TimedOut&lt;/code&gt; only where one wait
outlasts the limit, as the kernel’s per-call socket timeouts did before; the limit is kept in the
connection rather than in the socket, since a non-blocking socket ignores the kernel’s. &lt;em&gt;Why&lt;/em&gt;: a
large transfer to a slow but steady peer keeps going, and the meaning of &lt;code&gt;setTimeout&lt;/code&gt; does not
change. &lt;em&gt;Alternatives&lt;/em&gt;: a deadline for the whole &lt;code&gt;write&lt;/code&gt; or &lt;code&gt;readAll&lt;/code&gt; (stops a slow transfer that is
still making progress). Review with the user if a whole-operation deadline is wanted as well.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-sockets&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;connect&lt;/code&gt; parks; a Unix &lt;code&gt;connect&lt;/code&gt; does not.&lt;/strong&gt; A TCP connection
that cannot be made at once waits for the socket to become writable, then reads the socket’s
pending error (&lt;code&gt;SO_ERROR&lt;/code&gt;) for the outcome, since a second &lt;code&gt;connect&lt;/code&gt; answers “already connected”
even for a refused connection on macOS. A Unix connection is made at once by the kernel or refused,
so it stays a plain call and the socket is made non-blocking after. &lt;em&gt;Alternatives&lt;/em&gt;: a blocking
&lt;code&gt;connect&lt;/code&gt; that the monitor compensates for (holds a worker for a round trip to the peer).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-sockets&lt;/code&gt;): &lt;strong&gt;a connection or listener cannot be closed under a thread parked
on it.&lt;/strong&gt; It belongs to the parked thread, so another thread’s &lt;code&gt;close()&lt;/code&gt; traps as any other use
from there does, and the wait ends only by the peer, a timeout or readiness. &lt;em&gt;Why&lt;/em&gt;: the ownership
rule already decides it, and no wake path for a socket closed elsewhere is needed. &lt;em&gt;Alternatives&lt;/em&gt;: a
shared close that wakes the parked thread with an error (needs sockets shared between threads,
which the ownership rule excludes; cancellation by &lt;code&gt;scope&lt;/code&gt; is where an outside end of a wait
belongs).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-ui&lt;/code&gt;): &lt;strong&gt;Other threads reach the interface through inboxes and &lt;code&gt;post&lt;/code&gt;, run
by the main thread from one queue&lt;/strong&gt; (&lt;a href=&quot;/spec/ui/#threads&quot;&gt;User interfaces&lt;/a&gt;). &lt;code&gt;inbox(handle)&lt;/code&gt; is
made on the main thread; its handler, which may capture &lt;code&gt;State&lt;/code&gt;, stays there; the &lt;code&gt;Inbox[T, R]&lt;/code&gt; is
sendable, with &lt;code&gt;send(m) -&amp;gt; Future[R]&lt;/code&gt; and &lt;code&gt;ask(m) -&amp;gt; R&lt;/code&gt;. &lt;code&gt;post(@sendable work)&lt;/code&gt; queues work with
no answer. Every message and post waits in one queue, so one thread’s order holds across inboxes.
Why: the interface’s state is not sendable and must not become so, so the code that touches it
has to be made on the main thread and only a sendable message may cross; a future for the answer
reuses what already parks a lightweight thread. Alternatives weighed: &lt;code&gt;post&lt;/code&gt; alone (a sendable
closure cannot reach a &lt;code&gt;State&lt;/code&gt;, so it could not change the interface); a sendable &lt;code&gt;State&lt;/code&gt; behind a
lock (every build would lock, and a write from another thread would race the build); an actor for
the interface (the frame loop owns the thread, so a mailbox would still need this queue); a queue
for each inbox (loses one thread’s order between two inboxes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-ui&lt;/code&gt;; moved to &lt;code&gt;on_frame&lt;/code&gt; on
branch &lt;code&gt;binding-f32&lt;/code&gt;, which rests on the Proposed &lt;code&gt;f32&lt;/code&gt; entry): &lt;strong&gt;The frame loop runs the waiting
work in syslui-sdl’s &lt;code&gt;on_frame&lt;/code&gt;&lt;/strong&gt;, at the start of every frame and before the loop decides whether to build
the tree again, so work posted before a frame runs in that frame and what it writes is built in it;
&lt;code&gt;run&lt;/code&gt; runs what is left once more as it returns. The package’s binding of &lt;code&gt;app&lt;/code&gt; is &lt;code&gt;named&lt;/code&gt; (branch
&lt;code&gt;binding-defaults&lt;/code&gt;, see the Proposed &lt;code&gt;named&lt;/code&gt; entry), so it passes &lt;code&gt;on_frame&lt;/code&gt; and leaves &lt;code&gt;on_event&lt;/code&gt;,
&lt;code&gt;font&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt;, which come before it, to syslui-sdl’s own defaults; until then it copied those
defaults into Avin, since a binding passed its arguments by place. Why: &lt;code&gt;on_frame&lt;/code&gt; is the hook syslui-sdl
runs first in a frame for exactly this. Alternatives weighed: a wrapper of &lt;code&gt;ground&lt;/code&gt;, which &lt;code&gt;lwt-ui&lt;/code&gt;
used while no real could cross into an &lt;code&gt;f32&lt;/code&gt; (run after the tree, so its work was built a frame
late); &lt;code&gt;tree&lt;/code&gt; (called only when something was written, so it would never notice a post);
&lt;code&gt;on_event&lt;/code&gt; (called only when there are events).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-ui&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;handlePosted&lt;/code&gt; runs only what was waiting when it was called.&lt;/strong&gt;
Work that sends or posts waits for the next call. Why: work that posts itself again, a common
animation shape, would otherwise hold a frame for ever. Alternatives weighed: draining until the
queue is empty (simpler, but unbounded).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-ui&lt;/code&gt;): &lt;strong&gt;An ask on the main thread stops the program; a send or post there
is queued.&lt;/strong&gt; Why: the main thread handles the message, so its own wait would never end; a trap
names the mistake where a hang would not. Alternatives weighed: handling the queue up to the
message at once (re-enters a handler that asks, and runs work out of frame order).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-ui&lt;/code&gt;): &lt;strong&gt;Making an inbox, &lt;code&gt;handlePosted&lt;/code&gt; and &lt;code&gt;run&lt;/code&gt; are the main thread’s
alone&lt;/strong&gt;, refused at compile time from code for another thread because they reach the package’s
module-level state, and checked again at run time with &lt;code&gt;isMainThread()&lt;/code&gt; (a new function of
&lt;code&gt;avin.threads&lt;/code&gt;, answered by the runtime from the calling context). &lt;code&gt;run&lt;/code&gt; on another thread stops
the program before any window is opened. Why: a window on a thread other than the process’s
first never shows on macOS, and a handler made on another thread would run on the main thread
with that thread’s values. Alternatives weighed: answering &lt;code&gt;Err&lt;/code&gt; from &lt;code&gt;run&lt;/code&gt; (a mistake in the
program, not a condition it can handle); moving &lt;code&gt;run&lt;/code&gt; to the main thread silently (the caller’s
wait for its result would be the same hang).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-ui&lt;/code&gt;): &lt;strong&gt;An inbox lasts as long as the program, and work still waiting when
&lt;code&gt;main&lt;/code&gt; returns is dropped.&lt;/strong&gt; Why: inboxes are made once, as a window’s state is, and the program
ends when &lt;code&gt;main&lt;/code&gt; returns whatever its threads are doing. Alternatives weighed: closing inboxes
(needs a lifetime the interface does not have yet); running the queue at exit (runs interface code
after the interface is gone).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (built on branch &lt;code&gt;main-lwt&lt;/code&gt;): &lt;strong&gt;Threads pinned to the
main thread, on a main scheduler of its own&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#pinned-to-the-main-thread&quot;&gt;Threads&lt;/a&gt;,
&lt;a href=&quot;/spec/ui/#threads&quot;&gt;User interfaces&lt;/a&gt;). What was missing: code on the main thread could not wait
for a future, a channel or an ask without blocking the frame loop, so a handler had no way to
fetch something and then set a signal. &lt;code&gt;spawnOnMain(body)&lt;/code&gt; (and a scope’s &lt;code&gt;spawnOnMain&lt;/code&gt;) starts a
lightweight thread that runs on the main thread only; it parks as any thread does, whatever wakes
it puts it on the main scheduler’s ready queue, and it carries on on the main thread. Its body is
not checked as sendable and runs as the main thread’s owner of Sysl handles, so it reaches the
interface’s state; only the main thread starts one (a worker that tries stops the program).
&lt;code&gt;isMainThread()&lt;/code&gt; answers &lt;code&gt;true&lt;/code&gt; in it; &lt;code&gt;isPinnedToMain()&lt;/code&gt; tells it from the main thread’s own code,
so an &lt;code&gt;ask&lt;/code&gt; there parks rather than trapping, and &lt;code&gt;run&lt;/code&gt; there traps.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How the loop drives it:&lt;/strong&gt; once a frame, from &lt;code&gt;handlePosted&lt;/code&gt;, which runs &lt;code&gt;runMainThreads()&lt;/code&gt;
after the messages and posted work; and the main thread’s own waits (lock, condition, join,
channel, future, select, sleep) run pinned threads as they become ready, a ready one waking the
blocked main thread. syslui-sdl’s loop polls every frame, so no wake source is needed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;With no window:&lt;/strong&gt; the same, so a plain &lt;code&gt;main&lt;/code&gt; joining a pinned thread runs it, and a loop of
its own calls &lt;code&gt;runMainThreads()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order against posted work:&lt;/strong&gt; posted work and messages first, in the order sent, then the
pinned threads ready by then, each once, in the order they became ready. A pinned thread that
posted work makes ready runs in the same call; one another pinned thread makes ready runs at the
next, which bounds a call as &lt;code&gt;handlePosted&lt;/code&gt; already is bounded.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cancellation and deadlock:&lt;/strong&gt; a scope’s &lt;code&gt;spawnOnMain&lt;/code&gt; is cancelled with the scope, as its other
threads are; the deadlock check counts a ready pinned thread as work, and its report marks each
pinned thread &lt;code&gt;pinned to the main thread&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A pinned thread parked when &lt;code&gt;run&lt;/code&gt; ends&lt;/strong&gt; stays parked and runs whenever the main thread next
runs the main scheduler; when &lt;code&gt;main&lt;/code&gt; returns it is dropped, as every thread is.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Why&lt;/em&gt;: the interface’s state belongs to the main thread, so the code that waits and then touches
it has to run there; a lightweight thread pinned to it reuses everything that already parks and
wakes a thread, and the main thread stays the only one that ever touches the state. &lt;em&gt;Alternatives
weighed&lt;/em&gt;: &lt;code&gt;await&lt;/code&gt; inside a handler, which runs on the main thread’s own stack (it would have to
block the frame or re-enter the loop from inside the handler); running every posted piece of work
and every message as a pinned thread, which would give one order for all of it and let any handler
wait (a stack for every message, the common case paying for the rare one, and a handler’s answer
coming frames later); a wake source the loop waits on, the runtime’s poller descriptor or a
run-loop source on macOS (needed only by a loop that sleeps when idle, which syslui-sdl’s does
not); letting &lt;code&gt;runMainThreads&lt;/code&gt; from a pinned thread run the others (nested switching on the main
thread’s stack for no gain); a body checked as sendable (could not reach a &lt;code&gt;State&lt;/code&gt;, which is the
point); time-slicing pinned threads (they share the main thread with the frames, which no slice
makes fairer). Review with the user: the order of a pinned thread’s resumption against posted work
(posted first, per frame, not one interleaved order) and the name &lt;code&gt;spawnOnMain&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;binding-f32&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;real&lt;/code&gt; crosses into and out of any Sysl floating-point type
that rounds: &lt;code&gt;f32&lt;/code&gt;, &lt;code&gt;f16&lt;/code&gt;, &lt;code&gt;bf16&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt;.&lt;/strong&gt; A binding’s own &lt;code&gt;real&lt;/code&gt; parameter, a mirror’s &lt;code&gt;real&lt;/code&gt;
field going into Sysl, and a callback’s &lt;code&gt;real&lt;/code&gt; answer are rounded into the Sysl type to the nearest
value it holds, a tie to the even one, as an IEEE conversion rounds: a value past its largest
becomes an infinity of its sign, one below half its smallest subnormal a zero of its sign, a NaN
stays a NaN, and nothing stops the program. A &lt;code&gt;real&lt;/code&gt; result, a mirror’s field coming out, a
callback’s parameter, and a real an &lt;code&gt;Option&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a tuple or a collection result holds are
widened exactly. A real inside a parameter’s &lt;code&gt;Option&lt;/code&gt;, tuple or collection is passed as &lt;code&gt;real&lt;/code&gt;
only, as an integer there is passed as its declared type. A binding’s own real is passed as it is
first and rounded only where Sysl refuses a &lt;code&gt;real&lt;/code&gt; there (the shim is built again), so a Sysl
function overloaded at &lt;code&gt;real&lt;/code&gt; and &lt;code&gt;f32&lt;/code&gt; (&lt;code&gt;sysl.math.ulp&lt;/code&gt;) is called at &lt;code&gt;real&lt;/code&gt;, unrounded, and a
generic one takes the real itself. A real is not made from an &lt;code&gt;f128&lt;/code&gt; (its arithmetic is not
&lt;code&gt;sysl.math.Float&lt;/code&gt;; Sysl widens a parameter into one itself), nor from any non-floating type. Why: Avin has one floating type, and a
graphics or audio library’s &lt;code&gt;f32&lt;/code&gt; (syslui-sdl’s &lt;code&gt;size&lt;/code&gt;, a canvas’s coordinates) is what a binding
meets; rounding is what every conversion between floating widths does and the only one that keeps
every &lt;code&gt;f32&lt;/code&gt; value exact on the way back. It mirrors how an integer crosses into any Sysl integer.
Alternatives weighed: an &lt;code&gt;f32&lt;/code&gt; type in Avin (a second floating type in every arithmetic rule, for
the boundary’s sake); trapping where the value does not fit (a rounding is not an error, and an
infinity is a legal &lt;code&gt;f32&lt;/code&gt;); converting a real held inside a parameter’s option or collection too
(integers are not converted there either, and the copy would be written element by element);
rounding every real parameter at once (an overload at &lt;code&gt;f32&lt;/code&gt; would then be chosen over the one at
&lt;code&gt;real&lt;/code&gt;, losing precision silently).
&lt;strong&gt;Review with the user&lt;/strong&gt; whether a &lt;code&gt;real&lt;/code&gt; into an &lt;code&gt;f32&lt;/code&gt; should trap on overflow to infinity
rather than round to it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;binding-defaults&lt;/code&gt;): &lt;strong&gt;A binding marked &lt;code&gt;named&lt;/code&gt; (&lt;code&gt;@sysl(&amp;quot;f&amp;quot;, named)&lt;/code&gt;) passes
every argument by its parameter’s name, so a parameter it leaves out takes the Sysl function’s own
default.&lt;/strong&gt; The Avin name is spelled as Sysl spells it, each uppercase letter an underscore and its
lowercase, as a mirror’s fields are (&lt;code&gt;onFrame&lt;/code&gt; is &lt;code&gt;on_frame&lt;/code&gt;); the binding lists the parameters it
passes in any order; the receiver of a handle’s method is never named; every parameter of a
&lt;code&gt;named&lt;/code&gt; binding has a name. A binding without &lt;code&gt;named&lt;/code&gt; passes by position, as before. Sysl checks
the names and reports a missing parameter without a default, or a name it does not declare, with
its own message at the binding. Why: a binding that had to reach a parameter behind defaulted ones
copied the Sysl defaults into Avin (the ui package copied syslui-sdl’s &lt;code&gt;font&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt; and reached
a private handle for &lt;code&gt;on_event&lt;/code&gt;‘s default), and those copies go stale silently; with names, Sysl
supplies and evaluates its own defaults at each call, a non-literal one included. One word on the
annotation, decided per binding, changes no existing binding’s shim and needs no knowledge of the
Sysl signature in the Avin compiler. Alternatives weighed: caller-side omission, where an argument
an Avin caller leaves out of a binding’s call is left out of the Sysl call too (most general, but a
binding would need a shim for each set of omitted arguments its callers use, and Avin’s own
defaults on a binding would mean two things); a per-parameter mark such as &lt;code&gt;@named&lt;/code&gt; or a
&lt;code&gt;= sysl&lt;/code&gt; default on a positional list (the binding still lists every parameter up to the last one
it passes, and a mixed call needs the names anyway); naming every binding’s arguments always (would
make every existing binding’s parameter names part of its contract with Sysl); copying the
defaults (the stale copies this replaces). Review with the user: the surface word &lt;code&gt;named&lt;/code&gt;, and
whether a caller-side form should come later.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-scope&lt;/code&gt;): &lt;strong&gt;Cancellation by a scope stops a thread and drops its frames&lt;/strong&gt;
(&lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation&lt;/a&gt;). &lt;code&gt;s.cancel()&lt;/code&gt; cancels the scope’s threads, and those
it starts afterwards (which run nothing); a cancelled thread stops at its next cancellation point
with its frames dropped and ends with no result: &lt;code&gt;Thread.result() -&amp;gt; Option[T]&lt;/code&gt; (new) answers
&lt;code&gt;None&lt;/code&gt;, and &lt;code&gt;join&lt;/code&gt; traps. The cancellation points are every wait but a lock’s (sleep, join,
condition, so channels, futures and promises, and a socket’s wait for its descriptor) and every
safepoint poll. A socket’s wait is ended inside the runtime’s Sysl code, which may not drop its
own frames (they hold the socket), so it fails the operation and the library stops the thread as
soon as the operation has returned to it; no caller ever sees that failure. &lt;em&gt;Why&lt;/em&gt;: Avin has no
exceptions and a trap stops the program, so a cancellation that made each wait answer an &lt;code&gt;Err&lt;/code&gt;
would change the type of every wait in the library and leave a computing thread unreachable; the
runtime already drops an actor’s frames on a trap, and a thread shares nothing mutable outside a
lock, so dropping its frames loses nothing anyone else can see. &lt;em&gt;Alternatives weighed&lt;/em&gt;: every wait
answering an &lt;code&gt;Err&lt;/code&gt; or &lt;code&gt;Option&lt;/code&gt; (the direction first sketched; changes every signature, and a loop
that never waits is never cancelled); a cooperative flag the thread polls (a thread that forgets
to look is never cancelled, and parked threads still need waking); a trap at the next wait (stops
the program). Review with the user: &lt;code&gt;join&lt;/code&gt; trapping on a cancelled thread rather than answering an
&lt;code&gt;Option&lt;/code&gt;, which keeps every existing &lt;code&gt;join&lt;/code&gt; unchanged.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-scope&lt;/code&gt;): &lt;strong&gt;A thread is not stopped inside a region others may wait on&lt;/strong&gt;: a
lock held, a &lt;code&gt;lazy val&lt;/code&gt; being initialized, an Avin function Sysl called (the regions a trap already
treats as in doubt), and the library’s running of what waits for a future it completed. It
finishes the region and stops at its next cancellation point after. A wait on a condition is a
cancellation point when the lock it lets go is the only region the thread is in; the thread then
stops without taking the lock again. Waiting for a lock is not a cancellation point. &lt;em&gt;Why&lt;/em&gt;: a
mutex is the only door to shared mutable state, so a thread stopped outside every lock leaves
nothing half changed, and never leaves a lock held; a lock is held briefly, so making its wait a
point would buy little and race the hand-over of the lock. &lt;em&gt;Alternatives weighed&lt;/em&gt;: stopping
anywhere and releasing the locks a thread holds (leaves the state they guard half changed); making
the release of the last lock itself a cancellation point (cuts library code short after its
release, as a future’s completion is).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-scope&lt;/code&gt;): &lt;strong&gt;Cancellation reaches down through scopes, and only scopes.&lt;/strong&gt; A
cancelled thread stops first at the innermost scope it runs, which cancels its own threads and
waits for them, and the cancellation then goes on outward; a scope opened while its thread holds a
lock sets no such stop, so its threads are not cancelled with the thread. Threads started with the
plain &lt;code&gt;spawn&lt;/code&gt;, and futures’ work, are not reached by any scope’s cancellation. &lt;em&gt;Why&lt;/em&gt;: structured
joins hold only if a scope never returns before its threads, cancelled or not; unstructured threads
have no owner to be cancelled by. &lt;em&gt;Alternatives weighed&lt;/em&gt;: cancelling the thread alone and leaving
its inner scope’s threads running (breaks the scope’s promise); a &lt;code&gt;Thread.cancel()&lt;/code&gt; on any thread
(unstructured cancellation, which nothing here needs).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-scope&lt;/code&gt;): &lt;strong&gt;A failure does not cancel a scope by itself.&lt;/strong&gt; A trap stops the
program as before, so there is no failing thread to propagate; a thread reports a failure as a
&lt;code&gt;Result&lt;/code&gt;, and the scope’s body cancels and returns it. &lt;code&gt;Scope&lt;/code&gt; gains &lt;code&gt;cancel()&lt;/code&gt; and
&lt;code&gt;isCancelled()&lt;/code&gt; only, both used by the thread running the body while the scope is open. &lt;em&gt;Why&lt;/em&gt;: the
body already sees every thread’s result and decides what a failure means; a &lt;code&gt;scope&lt;/code&gt; that inspected
results would need to know their type is a &lt;code&gt;Result&lt;/code&gt;. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a &lt;code&gt;scopeTry&lt;/code&gt; whose
threads return &lt;code&gt;Result[T, E]&lt;/code&gt; and whose first &lt;code&gt;Err&lt;/code&gt; cancels the rest (a second entry point for what
a channel and a &lt;code&gt;cancel&lt;/code&gt; express); a sendable canceller a thread could call (the body can already
cancel on a message). Review with the user: whether a &lt;code&gt;Result&lt;/code&gt;-aware scope is wanted for brevity.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-scope&lt;/code&gt;): &lt;strong&gt;The scope hands back the Sysl handles a cancelled thread’s body
reached&lt;/strong&gt;, once it has waited for the thread, as a body that returns hands them back itself; they
are then in transit, for the next code to use. &lt;em&gt;Why&lt;/em&gt;: a connection given to a thread that was
cancelled is otherwise unusable by anyone, and closing it is the scope’s thread’s job. &lt;em&gt;Alternatives
weighed&lt;/em&gt;: leaving them with the ended thread’s owner (every later use traps); handing them back on
the cancelled thread as it stops (it runs no code of its own then).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10: &lt;strong&gt;Actors’ turns on lightweight threads&lt;/strong&gt; (branch &lt;code&gt;lwt-actors&lt;/code&gt;, &lt;a href=&quot;/spec/actors/#scheduling&quot;&gt;scheduling&lt;/a&gt;).
An actor on the shared executor, the default, runs each turn as a lightweight thread of its own,
started with a thread’s default stack (8 MiB reserved, committed as touched, reused from the
scheduler’s spares) and handing nothing over, the turn making the actor the owner of its code; a
turn that waits parks, and one that computes is time-sliced. An actor given an executor of its own
keeps running its turns as tasks on that executor’s workers, so &lt;code&gt;Executor.fixed(n)&lt;/code&gt; still bounds
how many work at once and the 16-message fairness among its actors stays exact. To tell the two
apart, &lt;code&gt;Executor.shared()&lt;/code&gt; now gives back the same executor every time, compared with &lt;code&gt;===&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: a turn as its own thread is what makes a sleeping or awaiting turn free its worker; the
shared pool counts a worker that sleeps or receives from a channel as working, so its few workers
could all be held by waiting turns. An explicit executor is a request for a bound, and keeping it
keeps every program that asked for one behaving as it did. &lt;em&gt;Alternatives&lt;/em&gt;: one long-lived
lightweight thread per actor, parked on an empty mailbox (a committed stack page or more for every
idle actor, and a parked thread for each of a hundred thousand actors); every turn a thread of its
own whatever the executor (drops the bound &lt;code&gt;Executor.fixed(n)&lt;/code&gt; asks for, and the
&lt;code&gt;actors_fairness&lt;/code&gt;/&lt;code&gt;actors_waiting&lt;/code&gt; behaviour on one worker); &lt;code&gt;spawn&lt;/code&gt;‘s executor as an
&lt;code&gt;Option[Executor] = None&lt;/code&gt; (breaks the positional &lt;code&gt;spawn(b, Stop, ex)&lt;/code&gt;); a public
&lt;code&gt;Executor.isShared()&lt;/code&gt; (more surface for one library’s need). Review with the user: whether an
explicit executor should still bound an actor once every turn could be a thread.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;train-2&lt;/code&gt;): &lt;strong&gt;A scope’s cancellation does not reach actors&lt;/strong&gt;
(&lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation&lt;/a&gt;, &lt;a href=&quot;/spec/actors/#scheduling&quot;&gt;scheduling&lt;/a&gt;). An actor
started by a scope’s thread is a top-level actor and runs on when that thread is cancelled; an
actor’s turn, a lightweight thread started as a plain thread is, is never cancelled by a scope,
though the scopes it runs cancel their own threads. The waits a turn makes need nothing of their
own: a turn waits only in the library’s waits (a future’s &lt;code&gt;await&lt;/code&gt;, so an &lt;code&gt;ask&lt;/code&gt;; a sleep, a
channel, a condition, a socket), every one already a cancellation point for a thread that can be
cancelled. An asker cancelled in an &lt;code&gt;ask&lt;/code&gt;‘s &lt;code&gt;await&lt;/code&gt; leaves its question in the actor’s mailbox,
handled in its place among the messages told, and the reply completes a promise nobody awaits,
which also takes the ask’s timer out. &lt;em&gt;Why&lt;/em&gt;: cancellation reaches down through scopes and only
scopes, and an actor is owned by its parent actor or by nobody, never by the thread that happened
to start it, so tying its life to that thread’s scope would make where an actor is spawned decide
when it ends; cancelling a turn would stop an actor halfway through a message, leaving its fields
half changed with no lock to guard them, and break one turn at a time. &lt;em&gt;Alternatives weighed&lt;/em&gt;:
stopping the actors a cancelled thread started (structured actors, which the actor tree already
provides through parent actors); taking a cancelled asker’s question back out of the mailbox
(needs a mailbox that removes from its middle, and the actor may already be handling it); making
a turn cancellable by the scope that told it a message (a message has no owning scope).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;the server library is in the standard library, as &lt;code&gt;TcpServer&lt;/code&gt; in
&lt;code&gt;avin.net&lt;/code&gt; and &lt;code&gt;http.serve&lt;/code&gt; in &lt;code&gt;avin.net.http&lt;/code&gt;&lt;/strong&gt;, not a package and not a module of its own. &lt;em&gt;Why&lt;/em&gt;:
the TCP connection and the HTTP client it builds on are there already, the server shares the
client’s &lt;code&gt;Response&lt;/code&gt; and token rules, and it is the first user of the runtime’s poller and, later,
of &lt;code&gt;scope&lt;/code&gt; cancellation, which tie it to the compiler’s release. &lt;em&gt;Alternatives&lt;/em&gt;: a package
&lt;code&gt;dev.avinlang.http&lt;/code&gt; (versioned apart, but it would duplicate the client’s types or depend on the
standard library’s privates); a module &lt;code&gt;avin.net.server&lt;/code&gt; (one more import for the one type).
Review with the user if a larger web framework is wanted later: that belongs in a package on top.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;each connection is served in an actor’s first turn, supervised
with &lt;code&gt;Stop&lt;/code&gt;&lt;/strong&gt;, rather than on a plain lightweight thread. &lt;em&gt;Why&lt;/em&gt;: a trap in a thread stops the
program, and an actor is the only place a trap is contained; a connection’s handler is the place
a server most needs a bug to cost one connection. The actor’s first turn runs the whole
connection and the actor stops after it; an &lt;code&gt;onStopping&lt;/code&gt; given before the connection is served
runs &lt;code&gt;failed&lt;/code&gt; (which writes the &lt;code&gt;500&lt;/code&gt;) and closes it, since a &lt;code&gt;stopping&lt;/code&gt; block is given only after
the body has run. &lt;em&gt;Alternatives&lt;/em&gt;: a lightweight thread per connection (a handler’s trap stops the
server); an actor per request (a mailbox and a turn per request, for no gain).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;the connections’ actors run on an executor of the server’s own,
&lt;code&gt;Executor.fixed(maxConnections)&lt;/code&gt;&lt;/strong&gt;. &lt;em&gt;Why&lt;/em&gt;: a connection’s turn parks on its socket for as long as
the connection lives, and on the shared pool, about one worker per processor, those parked turns
would keep every other connection waiting for a worker; the workers are lightweight threads, so a
worker per connection costs a parked stack each. Once actors’ turns run on lightweight threads of
their own (stage 14, item 5), the executor may go. &lt;em&gt;Alternatives&lt;/em&gt;: the shared pool with each wait
in &lt;code&gt;blocking&lt;/code&gt; (a trap inside &lt;code&gt;blocking&lt;/code&gt; leaves the worker counted as waiting for good).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;at the connection limit, the next connection waits unaccepted&lt;/strong&gt;
in the listener’s backlog until one ends, rather than being accepted and refused. &lt;em&gt;Why&lt;/em&gt;: the
client is served late instead of not at all, and the server spends nothing on it meanwhile.
&lt;em&gt;Alternatives&lt;/em&gt;: accept and close at once, or answer &lt;code&gt;503&lt;/code&gt; (a burst turns into failures the client
must retry).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;, reworked on &lt;code&gt;train-2&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;stop()&lt;/code&gt; cancels the acceptor’s parked
&lt;code&gt;accept&lt;/code&gt;&lt;/strong&gt;, which waits on a thread of a scope the acceptor runs; the acceptor’s own thread then
closes the listener. No connection is made to wake it. (&lt;code&gt;lwt-server&lt;/code&gt; first woke it with a
connection of its own to the listener, the one thing that could end a parked &lt;code&gt;accept&lt;/code&gt; before
&lt;code&gt;scope&lt;/code&gt; could cancel a wait.) &lt;em&gt;Why&lt;/em&gt;: a listener belongs to the thread parked on it, so no other
thread may close it, and cancellation ends a wait where it is parked without a connection the
server would accept and drop, a descriptor per stop, or a host to reach itself on (&lt;code&gt;127.0.0.1&lt;/code&gt;
for &lt;code&gt;0.0.0.0&lt;/code&gt;). The API of &lt;code&gt;stop&lt;/code&gt;, &lt;code&gt;join&lt;/code&gt; and &lt;code&gt;shutdown&lt;/code&gt; does not change. &lt;em&gt;Alternatives&lt;/em&gt;: the
waking connection (kept until cancellation landed); an &lt;code&gt;accept&lt;/code&gt; with a timeout polled for the
stop (a delay of up to the poll, and wake-ups for nothing); a listener closable from another
thread (against the ownership rule).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;train-2&lt;/code&gt;): &lt;strong&gt;a shutdown closes a connection idle between requests at once,
unanswered, and a request read once the server is stopping is answered &lt;code&gt;503&lt;/code&gt;&lt;/strong&gt;. The HTTP server
waits for each request, its first included, through &lt;code&gt;TcpServer.idle&lt;/code&gt;, so stopping cancels that
wait; a request being read or answered finishes, its response saying &lt;code&gt;Connection: close&lt;/code&gt;.
(&lt;code&gt;lwt-server&lt;/code&gt; let an idle connection run to its idle limit, answering &lt;code&gt;503&lt;/code&gt; to a request arriving
meanwhile, since nothing could end the wait from outside.) &lt;em&gt;Why&lt;/em&gt;: an idle connection has nothing
in flight, so closing it loses nothing, and &lt;code&gt;join&lt;/code&gt; no longer waits up to &lt;code&gt;idleTimeout&lt;/code&gt;, or for
ever where it is zero. &lt;em&gt;Alternatives&lt;/em&gt;: idle connections ending at their limit (a slow shutdown);
serving requests on connections already open (a chatty client keeps the server up for ever).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;train-2&lt;/code&gt;): &lt;strong&gt;a shutdown reaches a connection’s actor through &lt;code&gt;TcpServer.idle&lt;/code&gt;,
a scope the actor’s turn runs around each idle wait&lt;/strong&gt;, not a scope around the turn. &lt;code&gt;idle(wait)&lt;/code&gt;
registers the wait with the server, runs &lt;code&gt;wait&lt;/code&gt; on a thread of a scope opened by the calling
thread, and parks that thread on a promise that the wait completes &lt;code&gt;false&lt;/code&gt; once it answers and
&lt;code&gt;stop()&lt;/code&gt; completes &lt;code&gt;true&lt;/code&gt; for every registered wait; on &lt;code&gt;true&lt;/code&gt; the scope cancels the wait. Its
result is &lt;code&gt;Some&lt;/code&gt; of the wait’s answer, or &lt;code&gt;None&lt;/code&gt; where the server stopped first, and &lt;code&gt;None&lt;/code&gt; at
once, &lt;code&gt;wait&lt;/code&gt; not run, where it was already stopping. The acceptor’s &lt;code&gt;accept&lt;/code&gt; goes through the
same path, so what follows an accept (counting the connection, starting its actor) runs on a
thread nothing cancels. &lt;em&gt;Why&lt;/em&gt;: a scope’s cancellation does not reach actors, and an actor’s turn
is never cancelled (settled for &lt;code&gt;train-2&lt;/code&gt; above), so the server cannot cancel a turn; it can only
cancel a scope the turn runs, and &lt;code&gt;cancel&lt;/code&gt; must be called by the thread running that scope’s body,
which is why the turn parks on the promise and cancels itself. Only the wait is cancelled, so
code answering a request, and a trap in it (which fails the connection’s actor alone), stay on the
turn. A promise per wait and a registry keyed by number wake only the waits that exist, not every
connection on every request. &lt;em&gt;Costs&lt;/em&gt;: a scope and a lightweight thread per idle wait, and a
&lt;code&gt;Vector&lt;/code&gt; copy of each read the HTTP server makes there, since a wait’s result must be sendable;
a trap in &lt;code&gt;wait&lt;/code&gt; stops the program, as a trap in any thread does. &lt;strong&gt;Review with the user&lt;/strong&gt;: it
adds &lt;code&gt;idle&lt;/code&gt; to &lt;code&gt;TcpServer&lt;/code&gt;‘s public API, the one way a protocol on it tells the server which
waits a shutdown may end. &lt;em&gt;Alternatives&lt;/em&gt;: the connection’s whole &lt;code&gt;serve&lt;/code&gt; on a scope’s thread with
the turn watching it (a trap in &lt;code&gt;serve&lt;/code&gt; would stop the program instead of failing the actor, and
a request in flight would be cancelled with it); a server-wide condition notified when any wait
ends (wakes every idle connection per request); shutting down the read side of idle sockets from
the stopping thread (not cancellation, and a socket belongs to the thread that uses it); a
per-connection server handle carrying an idle flag (the same cancellation, plus a race between
the flag and the wait’s answer).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;HTTP limits and refusals.&lt;/strong&gt; Timeouts bound each wait, as a
connection’s do: &lt;code&gt;readTimeout&lt;/code&gt; while a request is read (&lt;code&gt;408&lt;/code&gt; once one runs out mid-request, and a
quiet close where a connection sent nothing), &lt;code&gt;writeTimeout&lt;/code&gt; while a response is written, and
&lt;code&gt;idleTimeout&lt;/code&gt; between requests; &lt;code&gt;maxHeaderBytes&lt;/code&gt; (16 KiB) bounds the request line (&lt;code&gt;414&lt;/code&gt;) and the
head and a chunked body’s trailers (&lt;code&gt;431&lt;/code&gt;); &lt;code&gt;maxBodyBytes&lt;/code&gt; (1 MiB) bounds a body by its length
before it is read, or as chunks arrive (&lt;code&gt;413&lt;/code&gt;). A request with both &lt;code&gt;Content-Length&lt;/code&gt; and
&lt;code&gt;Transfer-Encoding&lt;/code&gt;, two lengths that differ, a coding list not ending in &lt;code&gt;chunked&lt;/code&gt; or a header
folded onto a second line is &lt;code&gt;400&lt;/code&gt;, and a coding besides &lt;code&gt;chunked&lt;/code&gt; &lt;code&gt;501&lt;/code&gt;. Every refusal closes
the connection after shutting its side and reading what the client still sends for half a
second, so the answer is not lost to a reset. &lt;em&gt;Why&lt;/em&gt;: RFC 9112’s choices where it gives the server
one, and per-wait timeouts keep one meaning for “timeout” across the library. &lt;em&gt;Alternatives&lt;/em&gt;: a
deadline for the whole request (stops a slow upload still making progress; review with the user
if wanted beside the per-wait limit); decoding &lt;code&gt;gzip&lt;/code&gt; request bodies (a dependency for a rare
case).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;Response&lt;/code&gt; is the client’s class, given makers&lt;/strong&gt;
(&lt;code&gt;Response.text&lt;/code&gt;, &lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;empty&lt;/code&gt;, &lt;code&gt;withHeader&lt;/code&gt;) and &lt;code&gt;http.reasonPhrase&lt;/code&gt;; a handler is a plain
&lt;code&gt;@sendable (ServerRequest) -&amp;gt; Response&lt;/code&gt;; routes are a vector given to &lt;code&gt;Router(routes)&lt;/code&gt;, made by
&lt;code&gt;Route(method, pattern, handler)&lt;/code&gt; or &lt;code&gt;Route.get&lt;/code&gt; and its siblings, and &lt;code&gt;router.handle&lt;/code&gt; is the
handler. &lt;em&gt;Why&lt;/em&gt;: one response type for both sides; a vector literal spans lines, where a builder’s
chain of &lt;code&gt;.get(…)&lt;/code&gt; cannot, since a line starting with &lt;code&gt;.&lt;/code&gt; does not continue the one above. The
server writes &lt;code&gt;Content-Length&lt;/code&gt; and &lt;code&gt;Connection&lt;/code&gt; itself and refuses (traps on) a status outside
200 to 599. Responses are whole bodies; a streamed (chunked) response is later work.
&lt;em&gt;Alternatives&lt;/em&gt;: a builder &lt;code&gt;Router().get(…)&lt;/code&gt; (a chain on one line, or a &lt;code&gt;var&lt;/code&gt; reassigned); a
response writer handed to the handler (streaming, but a handler that forgets to finish it).
Whether a line that starts with &lt;code&gt;.&lt;/code&gt; should continue the expression above, left for review here,
is answered under &lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt;: it does, so a builder’s chain may now span lines.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-10 (built on branch &lt;code&gt;lwt-server&lt;/code&gt;): &lt;strong&gt;routing&lt;/strong&gt;: segments matched one for one with the request’s
decoded segments, &lt;code&gt;:name&lt;/code&gt; binding a non-empty one, the first matching route winning; a &lt;code&gt;GET&lt;/code&gt;
route answers &lt;code&gt;HEAD&lt;/code&gt;; &lt;code&gt;404&lt;/code&gt; for a path no route matches and &lt;code&gt;405&lt;/code&gt; with &lt;code&gt;Allow&lt;/code&gt; for one matched for
other methods. &lt;em&gt;Why&lt;/em&gt;: the smallest router that covers a service’s paths, with escaped and raw
Unicode routing alike and an escaped &lt;code&gt;/&lt;/code&gt; staying inside its segment. &lt;em&gt;Alternatives&lt;/em&gt;: wildcards
for the rest of a path and patterns in a segment (later, if programs need them).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (designed on branch &lt;code&gt;incremental-design&lt;/code&gt;): &lt;strong&gt;Lowering is made cheaper before anything is cached&lt;/strong&gt;:
the &lt;a href=&quot;/compiler/roadmap/#incremental-builds-build-plan&quot;&gt;build plan&lt;/a&gt; fixes tuple records (a
tuple’s ancestors listed as the product of its parts’ traits, each with its own entries: 33,858 of
marshal’s 71,646 functions) and lowering’s constant factors first. WHY: lowering is 75 to 80% of
an edit’s rebuild and most of it is that defect; a cache built first would key and store tens of
thousands of instances no program needs, and its measured win would be the defect’s. Alternatives:
cache first and fix after (stores the waste and measures the wrong thing); fix only (an edit still
lowers the whole program).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (designed on branch &lt;code&gt;incremental-design&lt;/code&gt;): &lt;strong&gt;The unit of reuse is the instance, grouped a file per
source module; the front end stays whole-program and uncached.&lt;/strong&gt; WHY: monomorphization makes the
instance, not the module, the thing whose code exists, and closed-world passes decide per call
site; checking marshal is about 4 s of a 65 s rebuild, and the checker numbers every symbol of the
program by index, so caching its output per module is a rewrite, deferred until a measurement says
the front end is the larger part. Alternatives: per-module object files with generic code emitted
where it is used (duplicates instances across modules and loses closed-world devirtualization); a
cache of the checked front end per module first (targets 6% of the time); whole-program LLVM text
cached by the program’s hash (only helps an unchanged program, which the executable record already
does).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (designed on branch &lt;code&gt;incremental-design&lt;/code&gt;): &lt;strong&gt;An instance’s key is its identity spelled by qualified
names, its typed body printed canonically, the layouts and records it reads, and the world facts
the whole-program passes used on it&lt;/strong&gt;, beside the compiler’s stamp, level and kind. WHY: the
printed typed tree carries every resolution and inference the checker made, so a change elsewhere
that alters what the body means alters its key without a dependency graph of the source; world
facts per call site let a new implementing class rerun the passes on its callers without lowering
them again. Alternatives: the declaration’s source text plus the hashes of the modules it imports
(misses inference changes through a callee’s result, and invalidates on every unrelated change to
an imported module); one hash of the whole program’s world for the passes (any new class reruns
every pass on every instance).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (designed on branch &lt;code&gt;incremental-design&lt;/code&gt;): &lt;strong&gt;Emitted names are stable&lt;/strong&gt;: a string by its content’s
hash, a descriptor or record by its type, a closure or trap site by its function and place, the
module-level tables in a codegen unit of their own. WHY: today’s numbering by discovery order lets
one new instance renumber the rest, which changes every unit’s text and defeats both caches.
Alternatives: keep the numbering and patch indices at emission (every reused text rewritten
anyway); number per module (still moves when a module gains a string).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (designed on branch &lt;code&gt;incremental-design&lt;/code&gt;): &lt;strong&gt;The instance cache lives in the program’s
&lt;code&gt;.avin/build/incremental/&amp;lt;kind&amp;gt;&amp;lt;level&amp;gt;/&lt;/code&gt;, content-addressed, published by rename, with no lock;
a missing, short or mismatched entry is a miss; a build trims what its manifest does not name and
was not used in the last hour.&lt;/strong&gt; WHY: the same scheme as the unit and shim caches, safe for two
builds at once because a key’s bytes are the same whoever writes them. Alternatives: a lock per
program directory (serializes &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; and the language server); the toolchain’s shared
cache for everything (instances of a program’s own types are useless to any other program; sharing
library-only instances can come later, since the keys already allow it). Review with the user:
whether library-only instances should later go to the toolchain’s cache, shared across programs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (designed on branch &lt;code&gt;incremental-design&lt;/code&gt;): &lt;strong&gt;An incremental build is tested against a clean one&lt;/strong&gt;:
every edit in the compiler’s tests checks that the incremental build’s LLVM text equals a build
with no cache, and the counts in &lt;code&gt;AVIN_BUILD_LOG&lt;/code&gt; that only the affected instances were lowered;
&lt;code&gt;AVIN_INCREMENTAL=verify&lt;/code&gt; compares every reused instance with a fresh lowering. WHY: a key missing
a dependency is the one way this design fails, and it fails silently; the clean build is an oracle
that needs no list of what each edit should touch. Alternatives: count-only tests (prove reuse,
not correctness); trusting the key (no defence against a missed dependency).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;option-nested&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Option[Nothing]&lt;/code&gt; takes the form of the options it is seen
as inside other values.&lt;/strong&gt; Its one value, &lt;code&gt;None&lt;/code&gt;, is null as a pointer and the constant &lt;code&gt;None&lt;/code&gt;
object as an object, so the program-wide plan keeps it a pointer when every view of it inside
another value (a &lt;code&gt;Vector[Option[Nothing]]&lt;/code&gt; as a &lt;code&gt;Vector[Option[Dog]]&lt;/code&gt;, a &lt;code&gt;Result&lt;/code&gt;, a function’s
result, an option, a tuple, a data field, a map value) sees it as an option kept as a pointer, and
an object when every such view sees it as one kept as an object (&lt;code&gt;Option[int]&lt;/code&gt;,
&lt;code&gt;Option[Option[Dog]]&lt;/code&gt;); a bare &lt;code&gt;Option[Nothing]&lt;/code&gt; written as an option of the other form is
converted where it is written, as before. &lt;em&gt;Why&lt;/em&gt;: options of classes and strings stay pointers in
the common program that builds a collection of &lt;code&gt;None&lt;/code&gt;s, at no cost in any other. &lt;em&gt;Left as full
objects (correct, slower)&lt;/em&gt;: a program that sees it inside other values both ways, since one
vector of it could flow to both and no single form serves; and one that sees it as an option of a
type parameter (&lt;code&gt;Vector[Option[Nothing]]&lt;/code&gt; as &lt;code&gt;Vector[Option[T]]&lt;/code&gt; in generic code), since the view
is recorded once for every instance. &lt;em&gt;Alternatives&lt;/em&gt;: (a) &lt;code&gt;None&lt;/code&gt; null in every option, objects
included, removing the conflict but adding a null test to every match, method call and table
entry on an object option; (b) copying the containing value at the view, which a view by
definition does not do and which breaks identity of mutable containers; (c) keeping
&lt;code&gt;Option[Nothing]&lt;/code&gt; always an object, the old rule, which stores every option of the program as an
object as soon as one nested view to a pointer option exists. With it, an &lt;code&gt;Option[Nothing]&lt;/code&gt;
written as another option is always that option’s own &lt;code&gt;None&lt;/code&gt; (the null, or that option’s constant
object, where an object option used to receive the &lt;code&gt;Option[Nothing]&lt;/code&gt; object itself), so as an
&lt;code&gt;Any&lt;/code&gt; it has the option’s type and equals that type’s other &lt;code&gt;None&lt;/code&gt;s, as the equality chapter’s
rule by run-time type says; one seen inside a vector as an &lt;code&gt;Option[Dog]&lt;/code&gt; and then boxed is an
&lt;code&gt;Option[Dog]&lt;/code&gt; too. A view inside an object-form value still leaves the &lt;code&gt;Option[Nothing]&lt;/code&gt; object
there, as any view leaves a value as it was made.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;https&lt;/code&gt;): &lt;strong&gt;TLS’s API&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#tls&quot;&gt;system library&lt;/a&gt;).
A module of its own, &lt;code&gt;avin.net.tls&lt;/code&gt;: &lt;code&gt;TlsStream.connect(host, port, settings)&lt;/code&gt;, and
&lt;code&gt;TlsStream.client(tcp, host, settings)&lt;/code&gt; / &lt;code&gt;TlsStream.server(tcp, settings)&lt;/code&gt; over a &lt;code&gt;TcpStream&lt;/code&gt;
the caller made; &lt;code&gt;TlsClient&lt;/code&gt; (the authorities it adds) and &lt;code&gt;TlsServer(certificate, key)&lt;/code&gt; (PEM
text, checked by &lt;code&gt;TlsServer.of&lt;/code&gt;) as immutable sendable values. In &lt;code&gt;avin.net.http&lt;/code&gt; an &lt;code&gt;https&lt;/code&gt; URL
just works (port 443 by default), &lt;code&gt;Request.withTls(client)&lt;/code&gt; choosing the settings, kept across
redirects; &lt;code&gt;http.serve(…, tls = Some(server))&lt;/code&gt; serves HTTPS. A trait &lt;code&gt;ByteStream&lt;/code&gt;, which
&lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;TlsStream&lt;/code&gt; implement, lets the HTTP code run over either, and
&lt;code&gt;ReadAhead&lt;/code&gt; became public so the TLS module shares the line reading. &lt;em&gt;Why&lt;/em&gt;: the URL decides
TLS, as a reader expects; settings are values, so a request, a thread and an actor carry them
freely; the stream over a caller’s &lt;code&gt;TcpStream&lt;/code&gt; keeps that connection’s timeout and cancellation
without a second set. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;TlsStream&lt;/code&gt; in &lt;code&gt;avin.net&lt;/code&gt; itself (every TCP program would
then build OpenSSL, since a module’s bindings come with it); a &lt;code&gt;TlsClient&lt;/code&gt; holding one OpenSSL
context for many connections (a context’s reference count is not atomic, so it could not be
shared between threads; a context is made per connection instead, which reads the machine’s
store each time, a few milliseconds); a &lt;code&gt;trust(pem)&lt;/code&gt; that checks the PEM at once (it would need
a context; a PEM that is not one is &lt;code&gt;Credentials&lt;/code&gt; at the connection instead).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;https&lt;/code&gt;): &lt;strong&gt;the trust model&lt;/strong&gt;. A client trusts the machine’s store,
through OpenSSL’s default paths, plus what &lt;code&gt;TlsClient.trust(pem)&lt;/code&gt; adds; it always checks the
host name (a name or an address), sends it for SNI, and speaks TLS 1.2 at the least, none of
which can be turned off, as the Sysl package &lt;code&gt;openssl&lt;/code&gt; decides. &lt;em&gt;Why&lt;/em&gt;: trust that only grows
cannot be misused to accept a bad certificate; a private, corporate or test authority is one
case. &lt;em&gt;Alternatives&lt;/em&gt;: a switch to skip verification (refused: it is how bad certificates get
accepted); a bundled set of roots (it goes stale). &lt;strong&gt;Gap&lt;/strong&gt;: on macOS the store is the &lt;code&gt;cert.pem&lt;/code&gt;
of Homebrew’s OpenSSL, not the Keychain, so a root added only to the Keychain is not trusted;
the &lt;code&gt;sysl&lt;/code&gt; session would queue reading the Keychain in the &lt;code&gt;openssl&lt;/code&gt; package on request.
Review with the user whether Keychain roots are wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;https&lt;/code&gt;): &lt;strong&gt;TLS errors&lt;/strong&gt;. &lt;code&gt;TlsError&lt;/code&gt; is &lt;code&gt;Transport(IoError)&lt;/code&gt;,
&lt;code&gt;Certificate(text)&lt;/code&gt;, &lt;code&gt;Handshake(text)&lt;/code&gt; and &lt;code&gt;Credentials(text)&lt;/code&gt;; an &lt;code&gt;HttpError&lt;/code&gt; gains
&lt;code&gt;Tls(TlsError)&lt;/code&gt;, a &lt;code&gt;Transport&lt;/code&gt; failure staying &lt;code&gt;Io&lt;/code&gt; as for &lt;code&gt;http&lt;/code&gt;. After the handshake a TLS
failure in a read or write is &lt;code&gt;IoError.Other(&amp;quot;TLS: …&amp;quot;)&lt;/code&gt;, so a &lt;code&gt;TlsStream&lt;/code&gt; is a &lt;code&gt;ByteStream&lt;/code&gt;.
&lt;code&gt;openssl&lt;/code&gt; 0.2.2 reports a refused certificate as one error, so &lt;code&gt;Certificate&lt;/code&gt; covers an
untrusted, self-signed or expired certificate and one for another host alike; the mapping is
the one function &lt;code&gt;handshakeError&lt;/code&gt; in &lt;code&gt;library/avin/net/tls/tls.avin&lt;/code&gt;, and &lt;code&gt;openssl&lt;/code&gt; 0.2.3’s
&lt;code&gt;Error.refusal()&lt;/code&gt; (&lt;code&gt;HostMismatch&lt;/code&gt;, &lt;code&gt;Expired&lt;/code&gt;, &lt;code&gt;Untrusted&lt;/code&gt;, &lt;code&gt;Other&lt;/code&gt;) lets it split &lt;code&gt;Certificate&lt;/code&gt;
into those kinds there alone. &lt;em&gt;Alternatives&lt;/em&gt;: one &lt;code&gt;Tls(text)&lt;/code&gt; error (a program could not tell
a refused certificate from a broken connection); typed errors for every read and write (every
&lt;code&gt;ByteStream&lt;/code&gt; user would need a second error type).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;https&lt;/code&gt;): &lt;strong&gt;a connection’s end and timeouts over TLS&lt;/strong&gt;. The end of the
stream is the peer’s &lt;code&gt;close_notify&lt;/code&gt; or the TCP connection closing, both read as the end, since
many servers close without a &lt;code&gt;close_notify&lt;/code&gt; and HTTP frames its bodies; a body read to the
connection’s end can therefore be cut short undetected, as over TCP. Every wait, the handshake’s
included, is a wait of the TCP connection beneath, under its &lt;code&gt;setTimeout&lt;/code&gt; limit and cancellable
by a scope; &lt;code&gt;http&lt;/code&gt; sets the request’s timeout before the handshake, and &lt;code&gt;http.serve&lt;/code&gt; bounds the
handshake by &lt;code&gt;readTimeout&lt;/code&gt;. A handler that traps on a TLS connection has it closed unanswered.
&lt;em&gt;Alternatives&lt;/em&gt;: an error for an end without &lt;code&gt;close_notify&lt;/code&gt; (it would refuse ordinary servers);
a handshake timeout of its own (one more limit to set). Review with the user whether a body read
to the connection’s end should require &lt;code&gt;close_notify&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;https&lt;/code&gt;): &lt;strong&gt;the standard library’s Sysl packages&lt;/strong&gt;. The library names
the Sysl packages its own bindings reach in &lt;code&gt;library/library.hocon&lt;/code&gt;, a manifest whose
&lt;code&gt;sysl-dependencies&lt;/code&gt; block is read as a package’s is. One joins a program’s shims only where a
binding or handle the program compiles names a Sysl item inside it, the package’s name being a
segment of the item’s name before its last (&lt;code&gt;sh.sysl.openssl.client&lt;/code&gt;); a program naming the same
package keeps its own, unless both are releases of one repository and the library’s is later.
So only programs that reach &lt;code&gt;avin.net.tls&lt;/code&gt; (&lt;code&gt;avin.net.http&lt;/code&gt; among them) need OpenSSL installed,
and the Homebrew formula depends on &lt;code&gt;openssl@3&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a dependency written as a package’s,
without making the library a package (an &lt;code&gt;avin.hocon&lt;/code&gt; there would make &lt;code&gt;library/tests&lt;/code&gt; a
package’s tests). &lt;em&gt;Alternatives&lt;/em&gt;: always adding the library’s packages (every program with a
binding would fetch and link OpenSSL); the runtime depending on &lt;code&gt;openssl&lt;/code&gt; (every program would
link it); a table from module to package in the compiler (a second place to keep in step).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-view-fields&lt;/code&gt;): &lt;strong&gt;Views lent by a
field and to a callback&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A field accessor lending a view says &lt;code&gt;view&lt;/code&gt;, &lt;code&gt;length:&lt;/code&gt; and perhaps &lt;code&gt;writable&lt;/code&gt;, as a binding
does&lt;/strong&gt;, and nothing else; &lt;code&gt;length:&lt;/code&gt; is a C expression in &lt;code&gt;self&lt;/code&gt; and the indices, evaluated after
the field is read, whether or not it is null. &lt;em&gt;Why&lt;/em&gt;: the words a binding lending its result
already uses, so a reader learns one form. &lt;em&gt;Alternatives&lt;/em&gt;: a separate &lt;code&gt;buffer:&lt;/code&gt; word for fields;
evaluating the length only for a non-null pointer, which would let a &lt;code&gt;length:&lt;/code&gt; that dereferences
the struct run only sometimes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The C unit, not the checker, refuses a &lt;code&gt;writable&lt;/code&gt; view of a &lt;code&gt;const&lt;/code&gt; field&lt;/strong&gt;, by glue that
assigns through the pointer, since the field’s type is the header’s and the checker never sees
it. &lt;em&gt;Why&lt;/em&gt;: a binding’s prototype says &lt;code&gt;const&lt;/code&gt; in Avin’s source, a field’s does not. &lt;em&gt;Alternative&lt;/em&gt;:
making the accessor spell the field’s C type, which repeats the header.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A view lent a callback may be an &lt;code&gt;Option&lt;/code&gt;&lt;/strong&gt;, null with any length &lt;code&gt;None&lt;/code&gt;, and otherwise null
follows a binding’s rule: an empty view for a length of zero, a stop for any other
(&lt;code&gt; C lent the function given to `f` null&lt;/code&gt;); a negative length and one past the greatest &lt;code&gt;int&lt;/code&gt;
stop the program at the binding’s call. &lt;em&gt;Why&lt;/em&gt;: one rule for every view. &lt;em&gt;Alternative&lt;/em&gt;: refusing an
&lt;code&gt;Option&lt;/code&gt; in a callback, which would make a C library that passes null for an empty chunk stop
the program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A view lent a callback has no lender and belongs to the code the callback runs in&lt;/strong&gt;: another
thread’s use stops the program, a thread the callback starts among them, since the view is not
handed over with a body that captures it as a handle’s view is with its lender. &lt;em&gt;Why&lt;/em&gt;: C frees
the memory when the callback returns, so it must not be read anywhere the closing cannot order
before the free. &lt;em&gt;Alternative&lt;/em&gt;: handing it over like a block, which lets another thread read
while the callback returns and C frees. Review with the user only if a library needs a thread to
read a chunk in place.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A callback view’s length is converted through &lt;code&gt;long&lt;/code&gt;&lt;/strong&gt; before the view’s own checks, so an
unsigned 64-bit length past a &lt;code&gt;long&lt;/code&gt;‘s range stops the program as that conversion does, and any
smaller one past the greatest &lt;code&gt;int&lt;/code&gt; as &lt;code&gt;more bytes than a view holds&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the conversions a
callback’s integer arguments already use. &lt;em&gt;Alternative&lt;/em&gt;: a dedicated 64-bit unsigned comparison,
which only changes the message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The trap texts&lt;/strong&gt; name the binding: &lt;code&gt; the `ByteView` lent to the function given to `f` was closed when it returned&lt;/code&gt; and &lt;code&gt; … belongs to another thread&lt;/code&gt;; a field’s view is a handle’s view
and says &lt;code&gt; the `ByteView` of `Face` was closed when `Face` was used again&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-derive&lt;/code&gt;): &lt;strong&gt;JSON derivation&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;One &lt;code&gt;JsonError&lt;/code&gt; for parsing and decoding&lt;/strong&gt;, the path its last field with a default:
&lt;code&gt;JsonError(message, line, column, offset, path: List[PathStep] = [])&lt;/code&gt;, &lt;code&gt;inField&lt;/code&gt;/&lt;code&gt;atIndex&lt;/code&gt;
putting a step in front, &lt;code&gt;pathText()&lt;/code&gt; writing &lt;code&gt;items[2].name&lt;/code&gt;, and &lt;code&gt;Display&lt;/code&gt; putting that text
and a colon before the message where the path is not empty. &lt;em&gt;Why&lt;/em&gt;: a program handles one error
type from the package, and every existing &lt;code&gt;JsonError(message, line, column, offset)&lt;/code&gt; keeps
compiling. &lt;em&gt;Alternatives&lt;/em&gt;: the derivation chapter’s &lt;code&gt;JsonError(path, message, line, column)&lt;/code&gt;,
which drops the offset and breaks every existing construction; a separate &lt;code&gt;DecodeError&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;JsonReader&lt;/code&gt; reads text in memory&lt;/strong&gt;, &lt;code&gt;JsonReader(text, maxDepth = 512)&lt;/code&gt;, with &lt;code&gt;beginObject&lt;/code&gt;,
&lt;code&gt;nextKey&lt;/code&gt;, &lt;code&gt;beginArray&lt;/code&gt;, &lt;code&gt;nextElement&lt;/code&gt;, &lt;code&gt;takeNull&lt;/code&gt;, &lt;code&gt;readString&lt;/code&gt;, &lt;code&gt;readBool&lt;/code&gt;, &lt;code&gt;readInt&lt;/code&gt;,
&lt;code&gt;readLong&lt;/code&gt;, &lt;code&gt;readReal&lt;/code&gt;, &lt;code&gt;readJson&lt;/code&gt;, &lt;code&gt;skipValue&lt;/code&gt;, &lt;code&gt;end&lt;/code&gt; and &lt;code&gt;error(message)&lt;/code&gt;, the last naming the
start of the last token read. &lt;em&gt;Why&lt;/em&gt;: the derivations need exactly these, and the tokenizer is the
parser’s own, so its messages are &lt;code&gt;parse&lt;/code&gt;‘s. &lt;em&gt;Alternatives&lt;/em&gt;: reading a byte stream now, which is
the streaming reader’s item; these methods are the seam it plugs into. A &lt;code&gt;JsonWriter(out: Writer)&lt;/code&gt; writes compact text only, &lt;code&gt;writeNull()&lt;/code&gt; for &lt;code&gt;null&lt;/code&gt;. (The streaming reader has since
taken this reader’s place: see the Proposed entry &lt;strong&gt;one &lt;code&gt;JsonReader&lt;/code&gt;&lt;/strong&gt; below.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Numbers&lt;/strong&gt;: an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt; reads any whole number in range, &lt;code&gt;3.0&lt;/code&gt; and &lt;code&gt;1e3&lt;/code&gt; included, as
&lt;code&gt;Json.asInt&lt;/code&gt;/&lt;code&gt;asLong&lt;/code&gt; do; a fraction or a number out of range is an error naming it. A NaN or an
infinity is written &lt;code&gt;null&lt;/code&gt; (as &lt;code&gt;render&lt;/code&gt; writes it) and &lt;code&gt;null&lt;/code&gt; does not read as a &lt;code&gt;real&lt;/code&gt;.
&lt;em&gt;Alternatives&lt;/em&gt;: integer literals only; &lt;code&gt;null&lt;/code&gt; reading back as NaN, which would make every &lt;code&gt;real&lt;/code&gt;
field silently nullable.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;Option[Option[A]]&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Some(None)&lt;/code&gt; and &lt;code&gt;None&lt;/code&gt; both write &lt;code&gt;null&lt;/code&gt; and read back as &lt;code&gt;None&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;:
JSON has one null. &lt;em&gt;Alternatives&lt;/em&gt;: refusing to derive for nested options.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Maps&lt;/strong&gt; are &lt;code&gt;HashMap[K, A]&lt;/code&gt; and &lt;code&gt;TreeMap[K, A]&lt;/code&gt; with &lt;code&gt;K: JsonMapKey&lt;/code&gt;, a trait the package
implements for &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; (the digits, read back only from what &lt;code&gt;toLongOption&lt;/code&gt;
reads); a key written twice keeps its last value. &lt;em&gt;Why&lt;/em&gt;: an impl of a trait is for a data type or
a class, not for the &lt;code&gt;Map&lt;/code&gt; trait, and must take its type’s parameters in order, so &lt;code&gt;Map[string, A]&lt;/code&gt;
cannot be named. &lt;em&gt;Alternatives&lt;/em&gt;: string keys only. &lt;strong&gt;Review with the user&lt;/strong&gt;: a field typed as the
&lt;code&gt;Map&lt;/code&gt; trait (what a map literal is typed as) cannot derive the JSON traits; covering it needs the
language to let a library trait be implemented for a trait type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unknown keys are skipped&lt;/strong&gt; and a field written twice is an error (as the chapter says); a second
discriminator key after the first is an unknown key. A missing field’s error is at the object’s
closing brace, with the object’s path. The nesting limit counts a skipped value’s containers too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Entry points&lt;/strong&gt; &lt;code&gt;json.encode(value) -&amp;gt; string&lt;/code&gt; and &lt;code&gt;json.decode[A](text, maxDepth = 512)&lt;/code&gt;, the
second refusing anything but white space after the value. &lt;em&gt;Alternatives&lt;/em&gt;: only the traits’
methods, leaving every program to make a writer and a reader.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-calendar&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;startOfYear()&lt;/code&gt;, &lt;code&gt;startOfMonth()&lt;/code&gt; and &lt;code&gt;startOfWeek()&lt;/code&gt; on a
&lt;code&gt;DateTime&lt;/code&gt; answer midnight&lt;/strong&gt; of that day, while &lt;code&gt;endOfMonth()&lt;/code&gt; keeps the time of day, as the
chapter says. &lt;em&gt;Why&lt;/em&gt;: a start is the first moment of its span, as &lt;code&gt;startOfDay&lt;/code&gt; is; keeping the
time would make &lt;code&gt;r.startOfMonth&lt;/code&gt; mean “the same time on the 1st”, which &lt;code&gt;r.withDay(1)&lt;/code&gt; already
says. &lt;em&gt;Alternatives&lt;/em&gt;: keep the time of day for all four (symmetric with &lt;code&gt;endOfMonth&lt;/code&gt;, but two
spellings of &lt;code&gt;withDay(1)&lt;/code&gt;); make &lt;code&gt;endOfMonth&lt;/code&gt; the last microsecond of the month too (a start/end
pair, but the chapter decided “at the same time of day”). Review with the user whether
&lt;code&gt;endOfMonth&lt;/code&gt; on a reading should rather be its month’s last microsecond.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-calendar&lt;/code&gt;): &lt;strong&gt;a calendar answer outside &lt;code&gt;Date.Min&lt;/code&gt; to &lt;code&gt;Date.Max&lt;/code&gt; traps
with a message naming the date&lt;/strong&gt; (&lt;code&gt;the date +5881580-07-31 is outside Date.Min to Date.Max&lt;/code&gt;), or,
where the answer is a count of days with no year to write (a weekday search, &lt;code&gt;startOfWeek&lt;/code&gt;,
&lt;code&gt;DateTime ± Duration&lt;/code&gt;), &lt;code&gt;the date N days from 1970-01-01 is outside Date.Min to Date.Max&lt;/code&gt;; the
maker &lt;code&gt;date(y, m, d)&lt;/code&gt; traps the same way, and a year far beyond the dates (&lt;code&gt;withYear(long.MaxValue)&lt;/code&gt;)
is checked before any arithmetic, so it never overflows on the way. &lt;code&gt;daysUntil&lt;/code&gt; and &lt;code&gt;DateTime - DateTime&lt;/code&gt;, whose answers are an &lt;code&gt;int&lt;/code&gt; and a &lt;code&gt;Duration&lt;/code&gt;, trap as an integer overflow does. &lt;em&gt;Why&lt;/em&gt;:
the chapter says leaving a type’s range traps “as an integer overflow does”; a message naming the
date says more than &lt;code&gt;integer overflow&lt;/code&gt; where there is a date to name. &lt;em&gt;Alternatives&lt;/em&gt;: a bare
integer overflow trap everywhere (shorter code, a less useful message); clamping to the bounds
(silently wrong).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-calendar&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;withYear&lt;/code&gt; takes a &lt;code&gt;long&lt;/code&gt;&lt;/strong&gt;, the type &lt;code&gt;year()&lt;/code&gt; answers, so
&lt;code&gt;d.withYear(d.year + 1)&lt;/code&gt; needs no conversion; the other &lt;code&gt;with…&lt;/code&gt; take an &lt;code&gt;int&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;:
&lt;code&gt;int&lt;/code&gt; like the makers (a conversion at every use of &lt;code&gt;year()&lt;/code&gt;), or changing &lt;code&gt;year()&lt;/code&gt; to &lt;code&gt;int&lt;/code&gt;
(every year of a &lt;code&gt;Date&lt;/code&gt; fits, but a change to step 1’s fields).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-calendar&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;with…&lt;/code&gt; and &lt;code&gt;startOf…&lt;/code&gt; on &lt;code&gt;Zoned&lt;/code&gt; wait for step 3&lt;/strong&gt;, which
builds &lt;code&gt;Resolution&lt;/code&gt; and the zone’s handling of a skipped or repeated reading they rely on; step 2
gives &lt;code&gt;Zoned&lt;/code&gt; only &lt;code&gt;isoWeek()&lt;/code&gt; and &lt;code&gt;isoWeekYear()&lt;/code&gt;, which need no resolution.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;generic-variant-inference&lt;/code&gt;): &lt;strong&gt;A
shared variant name takes the type its siblings decide&lt;/strong&gt;: a bare or called variant name several data types share, passed for
a generic function’s type argument, is decided by what the call’s other arguments decide of that
type argument: &lt;code&gt;assertEq(p.segments(0), MoveTo(10.0, 20.0))&lt;/code&gt; takes &lt;code&gt;T = Segment&lt;/code&gt; from the first
argument, so &lt;code&gt;MoveTo&lt;/code&gt; is &lt;code&gt;Segment&lt;/code&gt;‘s. It is checked after the arguments that are not such names,
wherever it is written, so &lt;code&gt;same(MoveTo(1.0, 2.0), segment)&lt;/code&gt; resolves too, and named arguments go
the same way. The elements of a collection literal and the two branches of an &lt;code&gt;if&lt;/code&gt; agree the same
way: &lt;code&gt;[Close, segment]&lt;/code&gt;, &lt;code&gt;if c then Close else segment&lt;/code&gt;. Only the data type is taken from the
others; its type arguments are left for the variant’s own fields to decide, so a later argument
may still widen them, as any argument’s may. Where every argument for the type argument is such a
name, or the others decide a type that is none of the name’s owners, the use is refused with the
usual message. Why: the name’s type is fixed by the call before it is chosen, exactly as with a
parameter of the data type itself, and checking the shared names last makes the result
independent of argument order, which a reader expects of &lt;code&gt;assertEq(a, b)&lt;/code&gt; and &lt;code&gt;assertEq(b, a)&lt;/code&gt;.
Alternatives: left to right only, so &lt;code&gt;same(MoveTo(…), segment)&lt;/code&gt; is refused (order-dependent, and
the expected value usually comes second); taking the decided type with its type arguments fixed
too (refuses a later argument that widens them); a second checking pass over the whole call
(the same answers here, with each argument checked twice).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps&lt;/code&gt;): &lt;strong&gt;An array C fills, its length known before the call&lt;/strong&gt;: an
&lt;code&gt;out T *&lt;/code&gt; parameter (one star, against &lt;code&gt;out T **&lt;/code&gt; for an array C allocates) named with &lt;code&gt;array:&lt;/code&gt;, its
&lt;code&gt;length:&lt;/code&gt; a C expression over the parameters evaluated in the glue before the call; the glue
&lt;code&gt;malloc&lt;/code&gt;s that many elements (at least one), C fills them, and they are copied into an &lt;code&gt;Array&lt;/code&gt; and
freed with &lt;code&gt;free&lt;/code&gt;. A negative length or one past the greatest &lt;code&gt;int&lt;/code&gt; calls nothing (the glue answers
a zeroed result) and the length stops the program when it is read; length checks now come before the
null check for every array C answers. It is never in an &lt;code&gt;Option&lt;/code&gt; and takes no &lt;code&gt;free:&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;:
Cairo’s &lt;code&gt;cairo_get_dash&lt;/code&gt; writes &lt;code&gt;cairo_get_dash_count&lt;/code&gt; doubles, a length no parameter carries; the
words &lt;code&gt;array:&lt;/code&gt;/&lt;code&gt;length:&lt;/code&gt; are the ones an array C answers already uses, the number of stars says who
allocates, and the answer is the same &lt;code&gt;Array&lt;/code&gt; in the result. &lt;em&gt;Alternatives&lt;/em&gt;: an Avin &lt;code&gt;Array&lt;/code&gt; passed
in, checked by the glue to be at least &lt;code&gt;length:&lt;/code&gt; long (the library would make and size it, and a
precondition the binding cannot see becomes the program’s); a &lt;code&gt;capacity:&lt;/code&gt; word on an in-array; the
array allocated in the collected heap (a moving or concurrent collection, and a &lt;code&gt;blocking&lt;/code&gt; call,
would need it pinned).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps&lt;/code&gt;): &lt;strong&gt;Several arrays in one call&lt;/strong&gt;: &lt;code&gt;array:&lt;/code&gt;/&lt;code&gt;bytes:&lt;/code&gt; take a list,
&lt;code&gt;length:&lt;/code&gt; and &lt;code&gt;free:&lt;/code&gt; then lists of the same length in the same order, &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; in &lt;code&gt;free:&lt;/code&gt; freeing
nothing; the glue writes each length through its own pointer and has a free function per array
(&lt;code&gt;avin_c_array_free_&amp;lt;symbol&amp;gt;_&amp;lt;j&amp;gt;&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: the existing words, with the list shape &lt;code&gt;keeps:&lt;/code&gt; already
has; one array keeps its single-string form. &lt;em&gt;Alternatives&lt;/em&gt;: repeating &lt;code&gt;array:&lt;/code&gt;/&lt;code&gt;length:&lt;/code&gt;/&lt;code&gt;free:&lt;/code&gt;
groups in order (order-dependent pairing nobody can see); marking the count in the prototype
(&lt;code&gt;length(glyphs) out int *num_glyphs&lt;/code&gt;), which would drop the count from the result and reuse a
marker that means something else for &lt;code&gt;inout&lt;/code&gt;; a &lt;code&gt;free:&lt;/code&gt; keyed by name (no map literal in an
annotation).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;null&lt;/code&gt; in a prototype passes null&lt;/strong&gt;: a word before a pointer
parameter’s type; the parameter is no Avin parameter and no out value, and a function whose caller
chooses (Cairo’s clusters, wanted or not) is bound twice, once with &lt;code&gt;out&lt;/code&gt; and once with &lt;code&gt;null&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: what is passed is fixed per binding, so the result’s type stays fixed; the prototype is where
the other per-parameter words (&lt;code&gt;out&lt;/code&gt;, &lt;code&gt;inout&lt;/code&gt;, &lt;code&gt;userdata&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;) already live. &lt;em&gt;Alternatives&lt;/em&gt;:
an Avin &lt;code&gt;bool&lt;/code&gt; or &lt;code&gt;Option&lt;/code&gt; parameter choosing at run time (the result’s shape would depend on a
value); a &lt;code&gt;skip:&lt;/code&gt; list on the annotation (a second place saying what one parameter is).
&lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;null&lt;/code&gt; should also let an Avin &lt;code&gt;Option&lt;/code&gt; parameter decide.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps&lt;/code&gt;): &lt;strong&gt;A field accessor reads and writes an enum mirror&lt;/strong&gt;: the C
unit checks the field is of an integer type (any, not only the mirrored enum) and measures it; a read
value no variant holds stops the program as an enum result does (&lt;code&gt; the field `f` of `H` held a value no variant of `M` holds&lt;/code&gt;), a write stores the enumerator’s value, and an &lt;code&gt;Option&lt;/code&gt; of a
mirror is refused. &lt;em&gt;Why&lt;/em&gt;: a struct mirror’s field already crosses this way, and Cairo’s path header
is a union member; accepting any integer type lets an &lt;code&gt;int&lt;/code&gt; field holding an enum’s values be
mirrored. &lt;em&gt;Alternatives&lt;/em&gt;: requiring the field to be exactly the mirrored enum (the field’s type is
the header’s, which the checker never sees, so the C unit would compare type names); reading it as
an &lt;code&gt;int&lt;/code&gt; and converting in Avin (the workaround cairo used).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;attach:&lt;/code&gt; failing
answers &lt;code&gt;Err&lt;/code&gt; where the binding answers &lt;code&gt;Result[H, E]&lt;/code&gt;&lt;/strong&gt;: a binding whose C result is a handle of a class with &lt;code&gt;attach:&lt;/code&gt;, which keeps
something and answers no out values, may answer &lt;code&gt;Result[H, E]&lt;/code&gt;, &lt;code&gt;E&lt;/code&gt; an integer type or an enum
mirror; when &lt;code&gt;attach:&lt;/code&gt; answers non-zero, the record is undone, the handle given back (its kept list
cleared) and &lt;code&gt;Err&lt;/code&gt; of the answer returned, converted as a status code is. Without the &lt;code&gt;Result&lt;/code&gt; the
trap stays. &lt;em&gt;Why&lt;/em&gt;: Cairo’s &lt;code&gt;cairo_surface_set_user_data&lt;/code&gt; on a surface in error answers the surface’s
own status, so the &lt;code&gt;attach:&lt;/code&gt; answer is exactly the error the program wants, and no new word is
needed; the &lt;code&gt;Result&lt;/code&gt; is the existing status shape. &lt;em&gt;Alternatives&lt;/em&gt;: a class-level &lt;code&gt;status:&lt;/code&gt; C
expression evaluated on every new handle (a new word, and a check on bindings that keep nothing);
answering &lt;code&gt;None&lt;/code&gt; for a refused attach (loses the reason); keeping the trap and the library’s
pre-checks (what cairo had to write).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;array-refmaps&lt;/code&gt;): &lt;strong&gt;An array’s descriptor carries a per-element reference map&lt;/strong&gt; (the
runtime half of the union tag-and-payload layout, under Settled → unions → Representation). An
array of elements &lt;code&gt;k&lt;/code&gt; words wide names one of three tracers: every element one reference
(&lt;code&gt;avin_rt_trace_array&lt;/code&gt;, as before), no reference word (the ordinary tracer with no offsets, as
before), or a mapped element (&lt;code&gt;avin_rt_trace_array_map&lt;/code&gt;), whose descriptor lists the byte offset
within an element of each reference word, in the same trailing offset list an object’s
descriptor uses for its fields; the tracer reads exactly those words of every element and never a
scalar word, so a union’s bits word holding something that looks like a heap address keeps
nothing alive. The compiler builds every array descriptor through &lt;code&gt;array_descriptor(…, words)&lt;/code&gt;,
which picks the fast path whenever the map fits one; a one-word element is never mapped. Handing
a value over to another thread reads the same words through the same scanners (&lt;code&gt;scan_object&lt;/code&gt;).
The two fast paths compile to the same machine code as before. &lt;em&gt;Why&lt;/em&gt;: the offset list already
exists, is what the emitter writes for objects, and costs nothing for the arrays every program has
today; elements of a union are at most three words, so a short list per element is cheap.
&lt;em&gt;Alternatives&lt;/em&gt;: a bit mask word per descriptor (one word, but a second format beside the offset
list, and a bit scan per element); a tracer per element shape generated by the compiler (fastest,
but code per instance and a new symbol per shape); keeping union elements boxed in arrays (no
runtime change, an allocation per element).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.io.Reader&lt;/code&gt;&lt;/strong&gt;, a trait of one method, &lt;code&gt;read(max) -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt;, an empty array at the end, which &lt;code&gt;fs.File&lt;/code&gt;, &lt;code&gt;net.TcpStream&lt;/code&gt; and
&lt;code&gt;net.UnixStream&lt;/code&gt; implement with the &lt;code&gt;read&lt;/code&gt; each already had. &lt;em&gt;Why&lt;/em&gt;: the streaming JSON reader
reads “a byte stream”, and the three byte sources had the same method with no common type, so a
function could take only one of them. &lt;em&gt;Alternatives&lt;/em&gt;: a read function &lt;code&gt;(int) -&amp;gt; Result[Array[byte], IoError]&lt;/code&gt; passed to the JSON reader (no library change, but every caller writes the lambda and
other byte readers gain nothing); a &lt;code&gt;ByteSource&lt;/code&gt; trait private to the json package (each source
wrapped by hand). Standard input and a command’s output are not readers yet; making them so is
later work when a program needs it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;the streaming JSON reader’s interface&lt;/strong&gt;, &lt;code&gt;JsonReader&lt;/code&gt; with the
pull events of &lt;code&gt;JsonEvent&lt;/code&gt; (&lt;code&gt;next&lt;/code&gt;, &lt;code&gt;peek&lt;/code&gt;, &lt;code&gt;depth&lt;/code&gt;) beside the calls the derivation chapter’s
decoder makes (&lt;code&gt;beginArray&lt;/code&gt;, &lt;code&gt;nextElement&lt;/code&gt;, &lt;code&gt;beginObject&lt;/code&gt;, &lt;code&gt;nextKey&lt;/code&gt;, &lt;code&gt;readString&lt;/code&gt;, &lt;code&gt;takeNull&lt;/code&gt;,
&lt;code&gt;skipValue&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt;), completed with &lt;code&gt;readBool&lt;/code&gt;, &lt;code&gt;readLong&lt;/code&gt;, &lt;code&gt;readInt&lt;/code&gt;, &lt;code&gt;readReal&lt;/code&gt;, &lt;code&gt;readValue&lt;/code&gt;,
&lt;code&gt;readDocument&lt;/code&gt; and &lt;code&gt;finish&lt;/code&gt;; made by &lt;code&gt;fromReader&lt;/code&gt;, &lt;code&gt;fromString&lt;/code&gt; and &lt;code&gt;fromBytes&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: one type
serves both a program walking a large document and a derived decoder, and the events are the
smallest set that names every token; a decoder’s calls are each a step or two over them.
&lt;em&gt;Alternatives&lt;/em&gt;: callbacks pushed per event (a decoder cannot pull a field’s value at its type);
an iterator of events (no &lt;code&gt;Result&lt;/code&gt; per step, so a fault would have to trap); a reader of several
values in a row (JSON lines), later if a program needs it, as &lt;code&gt;parse&lt;/code&gt; takes one value too.
Review with the user: the variant names (&lt;code&gt;StartObject&lt;/code&gt; … &lt;code&gt;EndOfText&lt;/code&gt;), chosen to stay apart from
&lt;code&gt;Json&lt;/code&gt;‘s own variants in the same module.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;a stream gives &lt;code&gt;parse&lt;/code&gt;‘s faults at &lt;code&gt;parse&lt;/code&gt;‘s places&lt;/strong&gt;, and a
failure to read is a &lt;code&gt;JsonError&lt;/code&gt; (&lt;code&gt;the text could not be read: &amp;lt;the IoError&apos;s message&amp;gt;&lt;/code&gt;) at the
place reading stopped, rather than a separate error type. Bytes that are not UTF-8 are found as
they are read, so a grammar fault earlier in the text is reported first, where &lt;code&gt;parse&lt;/code&gt; of bytes,
which checks the whole text first, reports the UTF-8 fault. &lt;em&gt;Why&lt;/em&gt;: one error type for the decoder
to carry, and a stream cannot look ahead to the end. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;Either[IoError, JsonError]&lt;/code&gt;
per call (every decoder’s signature grows); trapping on a read failure.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;JsonError&lt;/code&gt;‘s &lt;code&gt;line&lt;/code&gt;, &lt;code&gt;column&lt;/code&gt; and &lt;code&gt;offset&lt;/code&gt; are &lt;code&gt;long&lt;/code&gt;s&lt;/strong&gt;
(they were &lt;code&gt;int&lt;/code&gt;s). &lt;em&gt;Why&lt;/em&gt;: a stream larger than memory runs past two gibibytes, and a minified one
is on a single line, so an &lt;code&gt;int&lt;/code&gt; column or offset would trap on overflow. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;int&lt;/code&gt;s
that saturate (a wrong place, silently); a &lt;code&gt;long&lt;/code&gt; offset only (a column of a long line still
overflows).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;a parent after &lt;code&gt;:&lt;/code&gt; may be named through its module&lt;/strong&gt;,
&lt;code&gt;class Body: shapes.Base(&amp;quot;b&amp;quot;), io.Reader&lt;/code&gt;, resolved as a type written &lt;code&gt;m.T&lt;/code&gt; is. &lt;em&gt;Why&lt;/em&gt;: it was
refused with “expected a superclass” though the same name is a type everywhere else; found when
&lt;code&gt;fs.File&lt;/code&gt; was made an &lt;code&gt;io.Reader&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: none weighed; the bare name through an import
stays the common form.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;one &lt;code&gt;JsonReader&lt;/code&gt;, the streaming one, which the derived
decoders read through&lt;/strong&gt;. The in-memory reader of the derivation item is gone and so are the
token methods it added to &lt;code&gt;parse&lt;/code&gt;‘s private reader; &lt;code&gt;json.decode[A](text)&lt;/code&gt; reads through
&lt;code&gt;JsonReader.fromString&lt;/code&gt;. Where the two readers named a call differently the streaming names stay:
&lt;strong&gt;&lt;code&gt;readValue&lt;/code&gt;&lt;/strong&gt; (not &lt;code&gt;readJson&lt;/code&gt;) and &lt;strong&gt;&lt;code&gt;finish&lt;/code&gt;&lt;/strong&gt; (not &lt;code&gt;end&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: one reader means one grammar
and one set of places for a fault, whether the text is in hand or arriving; &lt;code&gt;readValue&lt;/code&gt; pairs with
&lt;code&gt;skipValue&lt;/code&gt; and &lt;code&gt;readDocument&lt;/code&gt;, and &lt;code&gt;finish&lt;/code&gt; cannot be read as the end of an object or array, as
&lt;code&gt;end&lt;/code&gt; can; the streaming names had the more users (its tests, the chapter’s example, three corpus
programs) against one test and one decoder line. A text reader is made by
&lt;code&gt;JsonReader.fromString(text)&lt;/code&gt;, since the class’s constructor takes a source; the derivation
entry’s &lt;code&gt;JsonReader(text, maxDepth)&lt;/code&gt; no longer compiles (its only users were the package’s own
test and &lt;code&gt;json.decode&lt;/code&gt;). &lt;em&gt;Alternatives&lt;/em&gt;: keeping both readers behind a trait the decoders take
(two grammars to keep in step, and a decoder call through a trait for every token); keeping both
names of each call (two words for one thing in the chapter’s table); a second constructor
&lt;code&gt;JsonReader(text)&lt;/code&gt; (the language gives a class one constructor).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;where the two readers worded an error differently, the settled
derivation wording stays&lt;/strong&gt;: &lt;code&gt;expected a boolean&lt;/code&gt; (not &lt;code&gt;expected true or false&lt;/code&gt;), &lt;code&gt;found a boolean&lt;/code&gt;
for &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; alike (not &lt;code&gt;found false&lt;/code&gt;), and &lt;code&gt;the number N is not a whole number within an int&apos;s range&lt;/code&gt; / &lt;code&gt;a long&apos;s range&lt;/code&gt; (not &lt;code&gt;does not fit an int&lt;/code&gt; / &lt;code&gt;within a long&lt;/code&gt;), &lt;code&gt;readInt&lt;/code&gt; naming the
number as written, a fraction included. A fault in the text itself is the stream’s, worded as
&lt;code&gt;parse&lt;/code&gt; words it: &lt;code&gt;tru&lt;/code&gt; read as a &lt;code&gt;bool&lt;/code&gt; is &lt;code&gt;unexpected word &apos;tru&apos; where a value was expected&lt;/code&gt;, no
longer &lt;code&gt;expected a boolean, found &apos;t&apos;&lt;/code&gt;, and text ending where a string was wanted is &lt;code&gt;unexpected end of text where a value was expected&lt;/code&gt;, since the stream tokenizes before the decoder asks for a
kind. A fault met while an array looks for its next element (&lt;code&gt;[&lt;/code&gt; and the end, &lt;code&gt;[1 2]&lt;/code&gt;) carries the
array’s path, not an element’s (&lt;code&gt;[&lt;/code&gt; decoded as a &lt;code&gt;Vector[int]&lt;/code&gt; has an empty path where it had
&lt;code&gt;[0]&lt;/code&gt;), since no element has begun. &lt;em&gt;Why&lt;/em&gt;: the derivation’s messages were settled and name kinds throughout (&lt;code&gt;a number&lt;/code&gt;, &lt;code&gt;a string&lt;/code&gt;), and a stream cannot answer “what character is next” without reading a token.
&lt;em&gt;Alternatives&lt;/em&gt;: the stream’s wordings throughout; the derivation’s character-level messages, which
would make the stream peek bytes outside its tokenizer. Review with the user: the &lt;code&gt;[0]&lt;/code&gt; path a
fault at the next element used to carry.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;json.decode[A](source: Reader, maxDepth = 512)&lt;/code&gt;&lt;/strong&gt;, an overload
of &lt;code&gt;decode&lt;/code&gt; reading a value of a derived type as its text arrives, from a file, a connection or any
&lt;code&gt;Reader&lt;/code&gt;, refusing anything but white space after it. &lt;em&gt;Why&lt;/em&gt;: the streaming reader exists so that a
document need not be held whole, and a program decoding its own type should not have to build the
reader and call &lt;code&gt;finish&lt;/code&gt; itself. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;JsonReader.fromReader&lt;/code&gt; and &lt;code&gt;A.decode(r)&lt;/code&gt; by hand;
a &lt;code&gt;decode&lt;/code&gt; taking a &lt;code&gt;JsonReader&lt;/code&gt; (which leaves the end of the text unchecked or checks it where a
caller wanted to read on).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;json-stream&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;net.ByteStream&lt;/code&gt; is an &lt;code&gt;io.Reader&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;trait ByteStream: Sendable, Reader&lt;/code&gt;, its &lt;code&gt;read&lt;/code&gt; the trait’s), so &lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;TlsStream&lt;/code&gt; are all
readers and JSON reads from a TLS connection as from a plain one. &lt;em&gt;Why&lt;/em&gt;: both sides arrived at
once, the stream item making &lt;code&gt;TcpStream&lt;/code&gt; and &lt;code&gt;UnixStream&lt;/code&gt; readers by name and the TLS item giving
the three a common &lt;code&gt;ByteStream&lt;/code&gt;; declaring it on the trait covers every connection, the TLS one
included, with one line. &lt;em&gt;Alternatives&lt;/em&gt;: naming &lt;code&gt;io.Reader&lt;/code&gt; beside &lt;code&gt;ByteStream&lt;/code&gt; on each class (TLS
left out unless named a third time).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-period&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;a.monthsUntil(b)&lt;/code&gt; counts a month whole when &lt;code&gt;b&lt;/code&gt;‘s day of the
month has reached &lt;code&gt;a&lt;/code&gt;‘s&lt;/strong&gt; (the month difference, less one where &lt;code&gt;b&lt;/code&gt;‘s day is smaller, or plus one
going backward where it is larger), and &lt;code&gt;a.until(b)&lt;/code&gt; is those months and the days from &lt;code&gt;a + months(n)&lt;/code&gt; to &lt;code&gt;b&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: it is the chapter’s “as a person counts them” (2026-01-31 to 2026-02-28
is 0, to 2026-03-01 is 1), it makes &lt;code&gt;b.monthsUntil(a) == -a.monthsUntil(b)&lt;/code&gt; always, and with
months-first addition &lt;code&gt;a + a.until(b) == b&lt;/code&gt; holds in both directions (a sweep of 21,228 pairs
tests it). &lt;code&gt;b - a.until(b) == a&lt;/code&gt; and &lt;code&gt;b.until(a) == -a.until(b)&lt;/code&gt; fail for some pairs near month
ends (2026-01-30 and 2026-03-01), and the chapter now says so. &lt;em&gt;Alternatives&lt;/em&gt;: the largest &lt;code&gt;n&lt;/code&gt;
with &lt;code&gt;a + months(n) &amp;lt;= b&lt;/code&gt; (answers 1 for 2026-01-31 to 2026-02-28, against the chapter); counting
backward periods from &lt;code&gt;b&lt;/code&gt; so the reverse is the negation (breaks &lt;code&gt;a + a.until(b) == b&lt;/code&gt; for
&lt;code&gt;a &amp;gt; b&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-period&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;p.toIsoString&lt;/code&gt; writes a period in ISO 8601’s form&lt;/strong&gt;,
&lt;code&gt;P1Y2M3D&lt;/code&gt;, the months split into years as the display splits them, &lt;code&gt;P0D&lt;/code&gt; for the empty period,
and a negative part with its own sign (&lt;code&gt;P-1Y-2M&lt;/code&gt;, &lt;code&gt;P1M-3D&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: the display &lt;code&gt;1y 2mo 3d&lt;/code&gt; is
for people; exchange formats want ISO’s, and a period’s parts may differ in sign, which a single
leading &lt;code&gt;-&lt;/code&gt; cannot write. &lt;em&gt;Alternatives&lt;/em&gt;: a leading &lt;code&gt;-&lt;/code&gt; when every part is negative and per-part
signs only otherwise (two rules for one value); no ISO text until step 5’s parsing (a writer
without a reader for a while). Review with the user whether the step 5 parser should read it
(&lt;code&gt;parsePeriod&lt;/code&gt;), which the chapter does not list.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-period&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;toYearsPart()&lt;/code&gt; and &lt;code&gt;toMonthsPart()&lt;/code&gt; carry the months’ sign&lt;/strong&gt;
(&lt;code&gt;months(-14)&lt;/code&gt; is -1 year and -2 months), as &lt;code&gt;Duration&lt;/code&gt;‘s parts do, and the display and ISO text
write each part with that sign (&lt;code&gt;-1y -2mo&lt;/code&gt;). &lt;strong&gt;&lt;code&gt;p.isZero()&lt;/code&gt;&lt;/strong&gt; asks for the empty period, as
&lt;code&gt;Duration.isZero()&lt;/code&gt; does. &lt;em&gt;Alternatives&lt;/em&gt;: floor division (-2 years and 10 months, which reads as
something else); no &lt;code&gt;isZero&lt;/code&gt; (&lt;code&gt;p == Period.Zero&lt;/code&gt; says the same, less directly).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-period&lt;/code&gt;): &lt;strong&gt;calendar steps count in a &lt;code&gt;long&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Date ± Period&lt;/code&gt;,
&lt;code&gt;plusYears(n)&lt;/code&gt; (&lt;code&gt;12 * n&lt;/code&gt; months) and &lt;code&gt;plusWeeks(n)&lt;/code&gt; (&lt;code&gt;7 * n&lt;/code&gt; days) never overflow on the way, so
an answer past the dates traps naming the date (&lt;code&gt;the date +5881580-08-11 is outside Date.Min to Date.Max&lt;/code&gt;), or the count of days where only a day step overflows, as step 2’s traps do; the
makers &lt;code&gt;years(n)&lt;/code&gt; and &lt;code&gt;Period * n&lt;/code&gt;, whose answers are periods, trap as an integer overflow.
&lt;code&gt;plusYears&lt;/code&gt;, &lt;code&gt;plusMonths&lt;/code&gt;, &lt;code&gt;plusWeeks&lt;/code&gt; and &lt;code&gt;plusDays&lt;/code&gt; take an &lt;code&gt;int&lt;/code&gt;, as the makers do.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-period&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Zoned ± Period&lt;/code&gt; and &lt;code&gt;Zoned&lt;/code&gt;‘s &lt;code&gt;plus…&lt;/code&gt; wait for step 3&lt;/strong&gt;,
whose &lt;code&gt;Resolution&lt;/code&gt; decides a period landing in a gap or an overlap.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-period&lt;/code&gt;): &lt;strong&gt;the formatter breaks a long one-line &lt;code&gt;if&lt;/code&gt; only after its last
&lt;code&gt;then&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt;&lt;/strong&gt;, keeping its tests, its earlier branches and any operators before it
on one line. &lt;em&gt;Why&lt;/em&gt;: a line after an &lt;code&gt;if&lt;/code&gt;‘s test is its block, so a break there changes the
program (the formatter refused &lt;code&gt;library/avin/time/period.avin&lt;/code&gt;); a break in an earlier branch
would put the next &lt;code&gt;elif&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt; inside a continuation line. &lt;em&gt;Alternatives&lt;/em&gt;: wrapping the
&lt;code&gt;if&lt;/code&gt; in brackets to break inside it (adds tokens, which the formatter never does); leaving any
line holding an &lt;code&gt;if&lt;/code&gt; long (also loses the safe break in the last branch).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-parse&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BadShape&lt;/code&gt; names what was expected&lt;/strong&gt;:
&lt;code&gt;BadShape(text, at, expected)&lt;/code&gt;, its message &lt;code&gt;cannot read &amp;quot;2026/03/08&amp;quot;: expected &apos;-&apos; at byte 4&lt;/code&gt;, and
&lt;code&gt;Trailing&lt;/code&gt;‘s &lt;code&gt;expected the end at byte 10&lt;/code&gt;, in place of the chapter’s earlier &lt;code&gt;not the expected shape at byte 4&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a reader fixing the text needs to know what would have been accepted
there, and the parser knows it at the point it stops. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;BadShape(text, at)&lt;/code&gt; with one
fixed message (says where but not what); a separate &lt;code&gt;expected&lt;/code&gt; method computing it again from the
text (a second parser).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-parse&lt;/code&gt;): &lt;strong&gt;a parse reads the whole shape first, then checks the
fields in the order they are written&lt;/strong&gt;, so &lt;code&gt;2026-02-30T24:00&lt;/code&gt; is refused for its day and
&lt;code&gt;2026-02-30T24:00 &lt;/code&gt; for its trailing space; a zone name is looked up last. The fields an
&lt;code&gt;OutOfRange&lt;/code&gt; names are &lt;code&gt;year&lt;/code&gt;, &lt;code&gt;month&lt;/code&gt;, &lt;code&gt;day&lt;/code&gt;, &lt;code&gt;date&lt;/code&gt; (past &lt;code&gt;Date.Min&lt;/code&gt;/&lt;code&gt;Date.Max&lt;/code&gt; inside their
own years), &lt;code&gt;hour&lt;/code&gt;, &lt;code&gt;minute&lt;/code&gt;, &lt;code&gt;second&lt;/code&gt;, &lt;code&gt;fraction&lt;/code&gt;, &lt;code&gt;offset&lt;/code&gt;, &lt;code&gt;instant&lt;/code&gt; (past
&lt;code&gt;Instant.Min&lt;/code&gt;/&lt;code&gt;Instant.Max&lt;/code&gt;), &lt;code&gt;months&lt;/code&gt; and &lt;code&gt;days&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: one rule for which error a text with
several faults gets, and a shape error never hides behind a range error further left.
&lt;em&gt;Alternatives&lt;/em&gt;: failing at the first fault left to right (a range error could then mask a
shape error after it, and the answer would depend on how far the reader had got).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-parse&lt;/code&gt;): &lt;strong&gt;a year of four digits has no sign, and a signed year has
four digits or more&lt;/strong&gt;, even inside &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9999&lt;/code&gt; (&lt;code&gt;+2026&lt;/code&gt;, &lt;code&gt;-0000&lt;/code&gt; read); an unsigned fifth digit
is a shape error at byte 4. A seventh digit of fraction is &lt;code&gt;OutOfRange(text, &amp;quot;fraction&amp;quot;)&lt;/code&gt; even
when it is &lt;code&gt;0&lt;/code&gt;. &lt;code&gt;t&lt;/code&gt;, &lt;code&gt;z&lt;/code&gt;, a comma as the decimal sign, &lt;code&gt;−&lt;/code&gt; (U+2212) and a bare &lt;code&gt;±hh&lt;/code&gt; offset are
refused. &lt;em&gt;Why&lt;/em&gt;: the display never writes them, and each accepted alternative is one more form
every other reader of the text would have to accept. &lt;em&gt;Alternatives&lt;/em&gt;: ISO 8601’s lowercase and
comma variants (wider, and nothing here writes them).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-parse&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;parseZoned&lt;/code&gt; with a zone name checks the offset against
the zone&lt;/strong&gt;: the reading minus the offset is the instant, and the zone’s clocks must show that
offset then, or the text is &lt;code&gt;OutOfRange(text, &amp;quot;offset&amp;quot;)&lt;/code&gt;; so both readings of an autumn overlap
read and a reading in a spring gap is refused. Any &lt;code&gt;ZoneError&lt;/code&gt; from looking the name up
(unknown, not a name, an undecodable file) is &lt;code&gt;UnknownZone(text, name)&lt;/code&gt;. A fixed zone’s name in
brackets (&lt;code&gt;+05:30[+05:30]&lt;/code&gt;, &lt;code&gt;Z[UTC]&lt;/code&gt;) reads as the fixed zone. Built over &lt;code&gt;zone(name)&lt;/code&gt;, which is
on dev ahead of the rest of step 3. &lt;em&gt;Why&lt;/em&gt;: the offset makes the instant unambiguous, and a text
whose offset the zone never shows names no reading of that zone. &lt;em&gt;Alternatives&lt;/em&gt;: trusting the
zone and re-reading the instant from the reading alone (needs step 3’s &lt;code&gt;Resolution&lt;/code&gt; for gaps and
overlaps, and drops the offset the text gave); trusting the offset and ignoring the zone’s (keeps
a &lt;code&gt;Zoned&lt;/code&gt; whose offset its zone contradicts). Review with the user whether a mismatch deserves a
variant of its own rather than &lt;code&gt;OutOfRange&lt;/code&gt;‘s &lt;code&gt;offset&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;time-parse&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;parsePeriod(text)&lt;/code&gt;&lt;/strong&gt;, named as the chapter’s other
readers are, reads &lt;code&gt;P&lt;/code&gt;, then a number of years &lt;code&gt;Y&lt;/code&gt;, of months &lt;code&gt;M&lt;/code&gt; and of days &lt;code&gt;D&lt;/code&gt; in that order, at
least one, each with its own &lt;code&gt;-&lt;/code&gt; where negative, so every &lt;code&gt;toIsoString()&lt;/code&gt; reads back equal. Forms
&lt;code&gt;toIsoString()&lt;/code&gt; does not write but whose numbers are plain also read (&lt;code&gt;P12M&lt;/code&gt; as &lt;code&gt;P1Y&lt;/code&gt;, &lt;code&gt;P0Y&lt;/code&gt;,
&lt;code&gt;P007D&lt;/code&gt;, &lt;code&gt;P-0D&lt;/code&gt;); a total of months or days beyond an &lt;code&gt;int&lt;/code&gt; is out of range. &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;W&lt;/code&gt;, a &lt;code&gt;T&lt;/code&gt; time
part, a fraction and lower-case letters are refused. &lt;em&gt;Why&lt;/em&gt;: a reader for the writer, settled as
the step 5 follow-up to the &lt;code&gt;toIsoString()&lt;/code&gt; entry above. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;Period.parse&lt;/code&gt; on the
companion (unlike the chapter’s other readers); accepting only the canonical form (refuses
&lt;code&gt;P12M&lt;/code&gt;, which means one exact period); ISO’s weeks (&lt;code&gt;P2W&lt;/code&gt;, fourteen days, which &lt;code&gt;toIsoString&lt;/code&gt;
never writes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;tls-refusal&lt;/code&gt;): &lt;strong&gt;why a certificate was refused&lt;/strong&gt;. &lt;code&gt;TlsError.Certificate&lt;/code&gt;
gains a second field, &lt;code&gt;why: TlsRefusal&lt;/code&gt;, and &lt;code&gt;TlsError.refusal() -&amp;gt; Option[TlsRefusal]&lt;/code&gt; answers it
(&lt;code&gt;None&lt;/code&gt; for the other errors). &lt;code&gt;TlsRefusal&lt;/code&gt; is &lt;code&gt;HostMismatch&lt;/code&gt;, &lt;code&gt;Expired&lt;/code&gt;, &lt;code&gt;NotYetValid&lt;/code&gt;,
&lt;code&gt;Untrusted&lt;/code&gt; and &lt;code&gt;Other(code: long)&lt;/code&gt;, and its &lt;code&gt;message()&lt;/code&gt; and the error’s say the reason in words.
Amended 2026-11-11 (branch &lt;code&gt;openssl-024&lt;/code&gt;): the mapping to the five kinds comes from the package
&lt;code&gt;openssl&lt;/code&gt; 0.2.4, whose &lt;code&gt;Error.refusal()&lt;/code&gt; groups the X509 verdicts (62 and 64, a certificate for
another name or another IP address, host; 10 expired; 9 not yet valid; 2, 18, 19, 20, 21
untrusted; any other &lt;code&gt;Other(code)&lt;/code&gt;). &lt;code&gt;TlsRefusal&lt;/code&gt; mirrors &lt;code&gt;openssl&lt;/code&gt;‘s &lt;code&gt;Refusal&lt;/code&gt; and the private
&lt;code&gt;TlsFailure&lt;/code&gt; binds &lt;code&gt;refusal()&lt;/code&gt; as a &lt;a href=&quot;/spec/sysl-bindings/#methods-of-a-mirror&quot;&gt;mirror’s bound method&lt;/a&gt;,
so Avin keeps no table of its own; a failure with no verdict is &lt;code&gt;Other(0)&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a program
can tell a wrong name from an untrusted issuer, which read identically before; the reason is a
value, so it is matched, not parsed out of text. The field is not an &lt;code&gt;Option&lt;/code&gt;, since a refused
certificate always has a verdict and &lt;code&gt;Other&lt;/code&gt; carries the unusual ones. The field is &lt;code&gt;why&lt;/code&gt; because
a variant field named &lt;code&gt;refusal&lt;/code&gt; would clash with the method. &lt;em&gt;Alternatives&lt;/em&gt;: an &lt;code&gt;Option&lt;/code&gt; field (a
&lt;code&gt;None&lt;/code&gt; that cannot happen); one variant per kind, &lt;code&gt;HostMismatch&lt;/code&gt; and the like as &lt;code&gt;TlsError&lt;/code&gt;
variants (every existing &lt;code&gt;Certificate(_)&lt;/code&gt; pattern would stop matching and a program that only
cares that a certificate was refused would need four arms); keeping &lt;code&gt;Certificate(text)&lt;/code&gt; and
adding a separate query (the reason would have to be stored somewhere anyway). &lt;strong&gt;Breaking&lt;/strong&gt;:
&lt;code&gt;Certificate(_)&lt;/code&gt; patterns become &lt;code&gt;Certificate(_, _)&lt;/code&gt;. Review with the user whether the
&lt;code&gt;Certificate&lt;/code&gt; arity change is wanted over a variant per kind.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps-2&lt;/code&gt;): &lt;strong&gt;A field accessor reads and writes a struct
mirror whole&lt;/strong&gt;: the C unit checks the field is the struct the mirror mirrors (any member path,
through pointers and array elements); the reader’s glue copies the field into memory Avin
allocates, read into a new value as a filled &lt;code&gt;out&lt;/code&gt; mirror is, the memory then freed; the writer
lays the value out as C’s struct and the glue assigns it. A mirror holding a string, directly or
in a mirror it holds, is refused as a writer’s value, and an &lt;code&gt;Option&lt;/code&gt; of a mirror is refused
either way. &lt;em&gt;Why&lt;/em&gt;: FreeType’s &lt;code&gt;face-&amp;gt;bbox&lt;/code&gt; and &lt;code&gt;face-&amp;gt;size-&amp;gt;metrics&lt;/code&gt; are structs read whole, and
one accessor per member (the package’s workaround, eight accessors and a tuple) loses the type;
the mirror’s layout is already checked and measured, so the copy is the struct passed by value’s
own conversion. Writing a string would leave C holding a copy no one frees, the rule for string
fields; a field is never null. &lt;em&gt;Alternatives&lt;/em&gt;: read only, no writer (writing is the scalar rule
extended and costs one glue function); a writer that leaks or keeps the string copies (C would
own Avin’s allocation); answering a handle on the struct inside the owner (lifetime tied to the
owner, and every member a call). Review with the user: a mirror holding a string is read-only.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps-2&lt;/code&gt;): &lt;strong&gt;One pointer to a typedef of &lt;code&gt;char&lt;/code&gt; is a
string&lt;/strong&gt;: where a string crosses (parameter, result, &lt;code&gt;out&lt;/code&gt; value, callback parameter), a C type
written as one pointer to a typedef (&lt;code&gt;const FT_String *&lt;/code&gt;, &lt;code&gt;FT_String const *&lt;/code&gt;, &lt;code&gt;T *const&lt;/code&gt;) is
checked by the C unit as a typedef of the whole pointer: &lt;code&gt;char *&lt;/code&gt; or &lt;code&gt;const char *&lt;/code&gt; as a result,
&lt;code&gt;const char *&lt;/code&gt; as a parameter, so a typedef chain and a &lt;code&gt;typedef const char T&lt;/code&gt; both work. A
pointer to a typedef of &lt;code&gt;unsigned char&lt;/code&gt; or &lt;code&gt;signed char&lt;/code&gt; is refused by a check of its own whose
message says those are bytes rather than text, for results, parameters, fields and struct
mirrors’ fields. &lt;em&gt;Why&lt;/em&gt;: only the headers know what &lt;code&gt;FT_String&lt;/code&gt; is, and the existing typedef rule
already defers the string check to the C unit; fields already resolved typedefs, since their
type comes from the header. &lt;em&gt;Alternatives&lt;/em&gt;: rewriting the prototype’s spelling to &lt;code&gt;char&lt;/code&gt; (loses
the header check’s typedef names); a new C type kind in the parser for a pointer to a typedef
(every handle &lt;code&gt;cairo_t *&lt;/code&gt; is one, so each position would have to tell the two apart).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;c-binding-gaps-2&lt;/code&gt;): &lt;strong&gt;The c-bindings chapter’s FreeType library is
released with &lt;code&gt;FT_Done_Library&lt;/code&gt;&lt;/strong&gt;, not &lt;code&gt;FT_Done_FreeType&lt;/code&gt;: the latter frees the library’s memory
manager whatever the reference count, so a face kept past the library’s handle would allocate
through freed memory. The chapter’s prose and both examples say so. &lt;em&gt;Why&lt;/em&gt;: a &lt;code&gt;release&lt;/code&gt; must give
back exactly one reference when the class declares &lt;code&gt;retain&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: none that keeps
&lt;code&gt;keeps:&lt;/code&gt; sound; the manager’s small record is not given back, as the freetype package notes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;openssl-024&lt;/code&gt;): &lt;strong&gt;a mirror’s methods may be bound to Sysl&lt;/strong&gt;
(&lt;a href=&quot;/spec/sysl-bindings/#methods-of-a-mirror&quot;&gt;methods of a mirror&lt;/a&gt;). A method without a body in an
&lt;code&gt;impl&lt;/code&gt; of a &lt;code&gt;@sysl&lt;/code&gt; data type that names no trait is bound to the Sysl method of its name’s words
in snake_case, or the one its own &lt;code&gt;@sysl(&amp;quot;name&amp;quot;)&lt;/code&gt; names, with &lt;code&gt;blocking&lt;/code&gt; and &lt;code&gt;named&lt;/code&gt; as on a
handle’s method; it may be overloaded by parameter types; its parameters and result cross as a
binding’s do. Each call converts the receiver into the Sysl value, puts it in a counted box of its
own and calls the method on that, so a Sysl method taking &lt;code&gt;self&lt;/code&gt;, &lt;code&gt;&amp;amp;self&lt;/code&gt; or &lt;code&gt;*self&lt;/code&gt; is bound
alike, and what a &lt;code&gt;*self&lt;/code&gt; method writes is lost with the box: the mirror is a value. A method
without a body on a plain data type, or in an &lt;code&gt;impl&lt;/code&gt; of a trait, still needs one; a method with a
body takes no &lt;code&gt;@sysl&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;openssl&lt;/code&gt;‘s &lt;code&gt;Error.refusal()&lt;/code&gt; is a method of a struct Avin
mirrors, and a mirror had no way to reach it, so Avin copied its table. The &lt;code&gt;impl&lt;/code&gt; form, because
a data type’s body holds its variants, and a handle’s body form would need a second kind of body
member for data. The box, because the shim cannot see which receiver the Sysl method takes and
&lt;code&gt;&amp;amp;self&lt;/code&gt; needs a counted reference; the cost is one allocation per call. &lt;em&gt;Alternatives&lt;/em&gt;: methods
in the data’s own body after its variants (a new body grammar for data); a top-level binding
whose first parameter is the mirror, &lt;code&gt;@sysl(&amp;quot;sh.sysl.openssl.Error.refusal&amp;quot;)&lt;/code&gt; (a path that names
a method rather than a function, read differently from every other binding’s); passing the value on the stack and
refusing &lt;code&gt;&amp;amp;self&lt;/code&gt; methods (most Sysl readers take &lt;code&gt;&amp;amp;self&lt;/code&gt;); a &lt;code&gt;*self&lt;/code&gt; method’s write copied back
(a mirror is immutable in Avin). Also chosen here: &lt;code&gt;TlsRefusal&lt;/code&gt; itself mirrors &lt;code&gt;openssl&lt;/code&gt;‘s
&lt;code&gt;Refusal&lt;/code&gt; rather than a private mirror mapped to it, since a second data type with the same
variant names cannot share the module, and the two would be the same five cases. Review with
the user whether a public library type mirroring a package’s enum is wanted: a variant &lt;code&gt;openssl&lt;/code&gt;
adds must be added to &lt;code&gt;TlsRefusal&lt;/code&gt;, which Sysl reports as not matching until it is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;Each emitted table is named &lt;code&gt;@&amp;quot;avin.&amp;lt;kind&amp;gt;:&amp;lt;name&amp;gt;&amp;quot;&lt;/code&gt;, the name
spelled by qualified names in full, with no hash suffix&lt;/strong&gt;: a type as &lt;code&gt;avin.Option[int]&lt;/code&gt;,
&lt;code&gt;class geo.Box[]&lt;/code&gt;, &lt;code&gt;object geo.Box[]&lt;/code&gt;, &lt;code&gt;(int, string)&lt;/code&gt;; a descriptor by its type, a variant after
its type’s (&lt;code&gt;avin.Option[int].Some&lt;/code&gt;); a record by its type; a constant closure by its function; a
module-level value by its qualified name (&lt;code&gt;object &lt;/code&gt; before an object’s). WHY: readable in the
emitted text and in a profile, injective by construction (two types of one module never share a
name but an object and its companion, which the prefixes tell apart), and short enough: marshal’s
longest symbol is 319 bytes, 275 of its 111,642 symbols are over 200, and every one is local to
the program, so no linker or object format limit is near. The emitted text grew 11% (126 MB to
140 MB for marshal). Alternatives: a hash of the spelling (shorter, unreadable, and a collision
is silent until the assembler reports it); the spelling cut at a length with a hash of the rest
(not needed at these lengths). Emission stops with the name where two of one kind would share
one, rather than the assembler reporting a redefinition.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;A string constant is named by the first 16 hexadecimal digits
of the SHA-256 of its bytes&lt;/strong&gt;, a later string sharing them by its index after a dot. WHY: the same
string has the same name in every program and every build; 64 bits make a shared prefix within one
program improbable past any program’s size. Alternatives: the whole digest (32 more bytes on each of
thousands of strings); the text itself (unbounded, and escaping in a symbol).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;A trap site is named by the innermost top-level function or
method declared around it, the byte offset from that declaration’s start, and 12 hexadecimal
digits of the SHA-256 of its reason&lt;/strong&gt;; a site in code the compiler wrote (an empty span) by the
instance being lowered; one in a declaration the checker copies (a derived &lt;code&gt;Display&lt;/code&gt; and its
siblings, one method name on several types sharing a declaration) or outside every function by its
file and offset. Trap sites are never copied into the units that reach them at &lt;code&gt;-O2&lt;/code&gt;. WHY: lines
added above a function move its sites’ lines, which only the tables’ unit holds, and leave every
function’s text as it was; a copy of a site, which no code reads, would carry its line into the
units that reach it. Alternatives: the instance and its sites in order (a site is shared by every
instance of a generic function, so its name would depend on which instance was lowered first);
file and line (moves with every line added above). Review with the user: a site in a library
template is named by file and offset, which an edit to that library file moves.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;A local function or lambda is numbered among its top-level
function’s local functions of its name, from 1 in declaration order&lt;/strong&gt; (&lt;code&gt;&amp;lt;program&amp;gt;.pick.lambda#2&lt;/code&gt;).
WHY: two blocks may each declare a local function of one name, and the number counts only within
the function, which an edit elsewhere never changes. Alternatives: the checker’s symbol index
(moves with every symbol declared before it); the byte offset within the function (moves with an
edit above the lambda inside the function, which changes the function’s text anyway, and is longer).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;A shared constant object is named by a hash of what it holds,
an unshared one (a vector literal’s) by its module-level value and its place among that value’s
objects; a C trampoline by its binding and place.&lt;/strong&gt; WHY: equal shared objects are one object
already, so their content is their identity; an unshared object’s identity is its value’s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;A module-level value that holds a reference keeps its slot in the
roots frame, and its name is a private alias of that slot&lt;/strong&gt;; code names the alias. WHY: the slot’s
position moves when a value is added before it, and the alias keeps that position in the tables’
unit alone; the runtime’s view of the frame is unchanged. Alternatives: a global per value and a
frame of addresses (a runtime change for the same effect).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stable-names&lt;/code&gt;): &lt;strong&gt;The module-level tables are the last codegen unit of &lt;code&gt;n&lt;/code&gt;, the
functions spread over the other &lt;code&gt;n - 1&lt;/code&gt;, and a unit holds its pieces in the order of their names.&lt;/strong&gt;
WHY: a new string, type or trap site then changes the tables’ unit and its user’s alone, and a
unit whose own pieces are unchanged is the same text whatever order lowering found them in.
Alternatives: tables in the first unit that names them (a new early user moves them, changing two
units); one unit per kind of table (more units for no fewer recompilations). Left as it was: a
function called from one function alone still lives in its caller’s unit, so a second caller in
another unit moves it; and a small function copied into its callers’ units at &lt;code&gt;-O2&lt;/code&gt; makes an edit
to it recompile those units too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;manifest-avin-version&lt;/code&gt;): &lt;strong&gt;a package names the least Avin it builds with&lt;/strong&gt;
(&lt;a href=&quot;/spec/packages/#the-manifest&quot;&gt;the manifest&lt;/a&gt;, &lt;a href=&quot;/spec/packages/#the-avin-a-package-needs&quot;&gt;the Avin a package
needs&lt;/a&gt;). &lt;code&gt;avin = &amp;quot;0.0.18&amp;quot;&lt;/code&gt; in the &lt;code&gt;package&lt;/code&gt; block, a
version, met by that Avin and every later one, compared number by number (0.0.9 before 0.0.18).
A minimum only: no ranges, no upper bound, no pre-release suffixes. Every package of the
resolved graph is held to it, the root and each dependency at any depth, fetched or by path, by
every command that reads manifests (build, run, test, check, &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;tidy&lt;/code&gt;, &lt;code&gt;vendor&lt;/code&gt;); a package
needing a later Avin is refused at its &lt;code&gt;avin&lt;/code&gt; value, naming the package, its requirement and the
running version and saying to upgrade, before anything else wrong in that manifest. A malformed
value is an error at the value. &lt;code&gt;avin new&lt;/code&gt; writes the running Avin’s version. &lt;code&gt;avin lsp&lt;/code&gt; reports
it on &lt;code&gt;avin.hocon&lt;/code&gt; when the editor opens one, and on the manifest of the package a file being
edited belongs to. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;cairo&lt;/code&gt; needed 0.0.18 and could only say so in its README, and a
package that needs a feature should fail with the upgrade named rather than with an unknown key
or a type error. The key’s spelling follows &lt;code&gt;sysl.hocon&lt;/code&gt;, which names the Sysl a package needs
as &lt;code&gt;sysl = &amp;quot;0.10.0&amp;quot;&lt;/code&gt; in its &lt;code&gt;package&lt;/code&gt; block. A minimum, because Avin’s versions only add: a
later Avin that breaks a package is a bug or a deliberate break in a release, which a range
written in advance cannot foresee, and an upper bound would refuse every upgrade until each
package re-releases. Checked when each manifest is read, so every path that reads one is held to
it without a second walk of the graph; told first, because a manifest written for a later Avin
may hold a key this one does not know. &lt;em&gt;Alternatives&lt;/em&gt;: a range (&lt;code&gt;&amp;gt;=0.0.18, &amp;lt;0.1&lt;/code&gt;), refused for
the reasons above; a top-level &lt;code&gt;avin&lt;/code&gt; key or a &lt;code&gt;requires { avin = … }&lt;/code&gt; block (Sysl puts its own in
&lt;code&gt;package&lt;/code&gt;); a warning rather than an error (the build would then fail later and less clearly);
checking only the root package (a dependency’s need is the common case, as with &lt;code&gt;cairo&lt;/code&gt;). Review
with the user whether &lt;code&gt;avin new&lt;/code&gt; should write the running version (it ties a new package to the
Avin that made it, which may be later than the package needs).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;min-avin&lt;/code&gt;; completes the entry above, which
had left the question in § Open): &lt;strong&gt;the minimum stays the whole design, the running version is the
stamped &lt;code&gt;Version&lt;/code&gt;, and a missing library module points at the upgrade.&lt;/strong&gt; The key (&lt;code&gt;package.avin&lt;/code&gt;),
its checking of every package of the graph, &lt;code&gt;avin check&lt;/code&gt; and &lt;code&gt;avin new&lt;/code&gt; were settled and built
2026-11-11; this adds only the hint: the “the standard library has no module” error ends with
“if the program was written for a later Avin than this one (X), upgrade Avin, and let its package
say which it needs with &lt;code&gt;avin = &amp;quot;…&amp;quot;&lt;/code&gt;“. It names no manifest state, because every declared
minimum has already been met by the time a module is looked up, so the error means either a typo
or a package that does not say what it needs. &lt;em&gt;Dev builds&lt;/em&gt;: the version compared is the number
&lt;code&gt;scripts/release.sh&lt;/code&gt; stamps into &lt;code&gt;const Version&lt;/code&gt;, three numbers with no pre-release suffix, so a
tree between releases is the last release; a package naming a release not yet cut is refused by it
with the usual message. &lt;em&gt;Why no exemption&lt;/em&gt;: a version has meaning only once a release stamps it,
and a pre-release rule would add a suffix to a version syntax that is three numbers. &lt;em&gt;&lt;code&gt;avin tidy&lt;/code&gt;
warning on a dependency’s minimum above the root’s&lt;/em&gt;: not added; the root’s &lt;code&gt;avin&lt;/code&gt; is what its
author tests with, and a dependency above the running Avin is already refused. &lt;em&gt;Alternatives&lt;/em&gt;: a
hint only where the manifest has no &lt;code&gt;avin&lt;/code&gt; (the driver does not see manifests, and the hint is
harmless where one is declared); an &lt;code&gt;AVIN_VERSION&lt;/code&gt; override for dev trees. Review with the user:
the key’s name (&lt;code&gt;avin&lt;/code&gt;, after &lt;code&gt;sysl&lt;/code&gt; in &lt;code&gt;sysl.hocon&lt;/code&gt;) and whether ranges are wanted (refused above,
because Avin’s versions only add).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-keys&lt;/code&gt;): &lt;strong&gt;An instance key is a content hash in two parts: a lowered
part (identity, body fingerprint, interfaces read) and the world facts the whole-program steps
decided for it, both made on every build after lowering&lt;/strong&gt; (&lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;the instance
key&lt;/a&gt;). The facts are recorded where they are decided, as each step
runs: the slots of methods with type parameters of their own, each devirtualization decision at a
call through a table (not the whole set of descriptors a receiver type admits), and each summary
scalar replacement read, with the finished key of every function it inlined (never one that may
recur, so the inlined keys form no cycle). WHY: a decision is exactly what a step’s rewriting of
a function depends on, so a new implementing class changes the keys of only the calls whose
decision it changes, and a callee’s body edit reaches a caller only through a changed summary or
an inlining; and the cache (item 6) can reuse a lowered form on the first part and rerun only the
passes on the second. Alternatives: the callee’s key for every summarized callee, as the pipeline
first wrote it (every leaf edit would reach every transitive caller); the admitted descriptors
rather than the decision (a class added past the guard limit would change keys for no change).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-keys&lt;/code&gt;): &lt;strong&gt;The body fingerprint is per function, with its family’s
captures, not per family.&lt;/strong&gt; A local function or lambda and its top-level function share one table
of locals; each fingerprint holds its own tree, the locals it owns or captures, and what every
function of the family captures (with each captured local’s type and mutability), which decides
what is kept in a box. WHY: a lambda’s body edit then changes the lambda and its closure entry and
not the function around it, unless its captures change. Alternatives: one fingerprint for the
whole family (every edit in it changes every member; simpler, and what the first build did).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-keys&lt;/code&gt;): &lt;strong&gt;Places in the fingerprint follow trap-site naming&lt;/strong&gt;: a node
inside its declaration counts from the declaration’s start; a node outside it (a constant default
argument copied into a call keeps its place in its own file) is named as &lt;code&gt;trap_name&lt;/code&gt; would name
a trap there; a derived impl’s shared template counts from the start of its file; the compiler’s
own code (an empty span) is named by the instance. A constant’s place is left out: no trap is
named by it. WHY: a trap site’s name is the only place a function’s text holds, so this is the
least that keeps the key sound; lines added between declarations change no key. A comment inside
a function changes its key whether or not a trap site follows it. Alternatives: only the places of
nodes that can trap (needs lowering’s knowledge of which do, duplicated); no places at all
(unsound: an edit moving a trap site changes the text).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-keys&lt;/code&gt;): &lt;strong&gt;What a key reads of types is conservative where the text
rarely depends on it&lt;/strong&gt;: every type argument’s supertypes and method table (they choose the method
a call on a bound runs), and a class’s or data type’s whole layout for any read of a field (its
field types in order, never the names). So a new impl for a type changes the instances at that
type that never call through a bound, and a field appended to a class changes the readers of its
earlier fields; both cost a rebuild, never a stale instance. Review with the user if the cache’s
hit rate after edits like these matters: narrowing needs the bound calls and the fields read
recorded during lowering, as the other facts are. Alternatives: record during lowering exactly
which table entries and fields each instance used (precise, more state threaded through
lowering).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-keys&lt;/code&gt;): &lt;strong&gt;The key names the compiler by its version and its
executable’s path and modification time, not the level.&lt;/strong&gt; WHY: lowering does not depend on the
level, and the pipeline keeps one instance directory per level. Alternatives: the level in the key
as well (redundant with the directory), the executable’s hash (reads 8 MB per build).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;A lowered entry is the instance’s requests and its
code by name, replayed; not a record of lowering’s state&lt;/strong&gt; (&lt;a href=&quot;/compiler/#incremental-builds&quot;&gt;the instance
cache&lt;/a&gt;). Every request lowering an instance makes of the whole
program goes through one function of lowering (seventeen of them: a layout, a record, an object’s
record, a box, a value box, a type tested, a string, a trap site, an instance, a generated
function, a slot, a slot of a method with type parameters of its own, a closure’s shape, a constant
closure, a constant object, a call through a table, a call of a function value), which records it
while the instance is lowered for the cache; the outermost request alone is recorded. The code
names what it counts by its stable name. WHY: replaying a request runs the same code a fresh
lowering runs, so the instances, tables and records grow exactly as they would, in the same order,
and an incomplete record fails to read back (an unknown name) rather than silently differing. A
binding, a C callback and a C binding’s body mark the instance as one no entry holds.
Alternatives: the difference in lowering’s state before and after each instance (state is keyed by
the checker’s indices, which an edit moves); a module’s whole lowered program (a change anywhere
in the module loses all of it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;Only the program’s functions with bodies get lowered
entries.&lt;/strong&gt; Closure entries, bindings and the functions lowering makes (equality, hashing, rendering,
adapters, C callbacks) are lowered every build; every function gets a text entry. WHY: they are
small and many of them depend on the whole set of types; on marshal they are about 17,000 of
41,583 instances and a fraction of lowering’s time. Alternatives: entries for every kind
(each kind’s requests would need recording; generated functions read tables the worklist is still
filling).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;A text entry is keyed by the finished key and the
facts emission reads of the whole program&lt;/strong&gt;: for each call, the callee’s symbol and signature,
whether it may collect and whether the call may close a cycle of the call graph, and a shim’s
extensions. WHY: these decide the frame, the polls and the calling convention of a function’s text
and are not in its finished key, which covers its code. Alternatives: emission facts in the
finished key itself (the keys would depend on emission’s call graph); a hash of the finished code
(costs an encoding of every function each build).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;The passes still run over every instance on every
build&lt;/strong&gt;; devirtualization’s fixed point runs over per-function summaries (the set of objects a
receiver or a result may be) and rewrites only functions that call through a table, and the
dispatch sites are found once per position and class or trait. Both give byte-identical text.
WHY: measured on marshal, the passes are not where lowering an unchanged instance costs most, and
running them only where facts changed needs every function’s post-pass code, scalar summary and
fence fact cached under a key over its callees’ (a key over a cone of the call graph, with
dispatch targets as edges); that is a design of its own. Review with the user: it is what stands
between the cache and a lowering phase proportional to an edit. Alternatives: build the cone keys
now.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;The cache is opt-in in this step&lt;/strong&gt;: &lt;code&gt;AVIN_INCREMENTAL&lt;/code&gt;
(&lt;code&gt;on&lt;/code&gt;, &lt;code&gt;verify&lt;/code&gt;, &lt;code&gt;off&lt;/code&gt;) for &lt;code&gt;avin build&lt;/code&gt; and &lt;code&gt;avin emit-llvm&lt;/code&gt;, in
&lt;code&gt;.avin/build/incremental/&amp;lt;kind&amp;gt;&amp;lt;level&amp;gt;/&lt;/code&gt;. WHY: item 7 of the plan makes &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and
the language server use it by default once the corpus has run warm. Alternatives: on by default now.
Superseded by the Proposed default for every command that builds (branch &lt;code&gt;incremental-default&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;The store is a file per module named by a hash of
its module and keys, with a length and CRC-32 header, a manifest written last, and no lock&lt;/strong&gt;; a
file is kept only if the build read it whole, and files neither named nor used in the last hour are
trimmed, with no size limit. WHY: a name from the keys costs nothing to compute (a content hash
would hash about 190 MB per build on marshal), the CRC catches truncation and damage, and two
builds write the same bytes for the same keys. Alternatives: an entry per file (41,000 files per
build); a SHA-256 per file; a size limit as the unit cache has (the unit cache’s hour rule already
keeps it to what recent builds used).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;instance-cache&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;verify&lt;/code&gt; compares the whole text and names the first
function that differs&lt;/strong&gt;, in the clean build’s order, or the first line where no function does.
WHY: the function’s symbol says which key missed a dependency; its key adds nothing a reader can
act on. Alternatives: compare instance by instance before emission (needs the clean build’s
instances matched to the cached build’s).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-string&lt;/code&gt;): &lt;strong&gt;String
character-wise and parsing methods.&lt;/strong&gt; Choices the spec did not settle, in &lt;a href=&quot;/spec/types/#string&quot;&gt;&lt;code&gt;types.md&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;toBool&lt;/code&gt; is exact.&lt;/strong&gt; Only &lt;code&gt;&amp;quot;true&amp;quot;&lt;/code&gt; and &lt;code&gt;&amp;quot;false&amp;quot;&lt;/code&gt;; &lt;code&gt;toBool&lt;/code&gt; traps with the number-parse
message (&lt;code&gt;For input string: &amp;quot;…&amp;quot;&lt;/code&gt;) on anything else, &lt;code&gt;toBoolOption&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;. &lt;em&gt;Why:&lt;/em&gt; a
parse that accepts &lt;code&gt;&amp;quot;True&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;1&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;yes&amp;quot;&lt;/code&gt; hides data errors, and the exact form is the one
every program can state. &lt;em&gt;Alternatives:&lt;/em&gt; case-insensitive; also &lt;code&gt;&amp;quot;1&amp;quot;&lt;/code&gt;/&lt;code&gt;&amp;quot;0&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A &lt;code&gt;radix&lt;/code&gt; outside 2 to 36 traps, in the &lt;code&gt;Option&lt;/code&gt; forms too.&lt;/strong&gt; &lt;em&gt;Why:&lt;/em&gt; a bad radix is the
caller’s bug, not bad input, so &lt;code&gt;None&lt;/code&gt; would hide it. &lt;em&gt;Alternative:&lt;/em&gt; &lt;code&gt;None&lt;/code&gt; from the &lt;code&gt;Option&lt;/code&gt;
forms.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Radix digits are ASCII &lt;code&gt;0&lt;/code&gt;–&lt;code&gt;9&lt;/code&gt; and &lt;code&gt;a&lt;/code&gt;–&lt;code&gt;z&lt;/code&gt;, either case&lt;/strong&gt;, with the optional &lt;code&gt;+&lt;/code&gt;/&lt;code&gt;-&lt;/code&gt; sign of
the decimal forms, and no prefix (&lt;code&gt;&amp;quot;0x10&amp;quot;.toInt(16)&lt;/code&gt; is not a number). &lt;em&gt;Alternatives:&lt;/em&gt; accept a
&lt;code&gt;0x&lt;/code&gt;/&lt;code&gt;0b&lt;/code&gt; prefix where it matches the radix.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;split(sep, limit)&lt;/code&gt;: &lt;code&gt;limit&lt;/code&gt; is the most pieces; the last holds the remaining text.&lt;/strong&gt; A
&lt;code&gt;limit&lt;/code&gt; of 0 or less means no limit, 1 returns the whole string as one piece. &lt;em&gt;Why:&lt;/em&gt; the
reading that needs no special negative case beyond “no limit”. &lt;em&gt;Alternatives:&lt;/em&gt; a limit of 0
dropping trailing empty pieces; a negative limit trapping.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;stripLineEnd&lt;/code&gt; removes one terminator, &lt;code&gt;\n&lt;/code&gt; or &lt;code&gt;\r\n&lt;/code&gt;, never a lone &lt;code&gt;\r&lt;/code&gt;&lt;/strong&gt;, agreeing with
&lt;code&gt;lines()&lt;/code&gt;, which does not end a line at a &lt;code&gt;\r&lt;/code&gt; either. &lt;em&gt;Alternative:&lt;/em&gt; also a lone &lt;code&gt;\r&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;compareIgnoreCase&lt;/code&gt; compares the two after &lt;code&gt;toLower&lt;/code&gt;&lt;/strong&gt;, as &lt;code&gt;equalsIgnoreCase&lt;/code&gt; equates
them, so its sign is &lt;code&gt;compare&lt;/code&gt; of the lower-cased strings. &lt;em&gt;Alternative:&lt;/em&gt; comparing character by
character after upper-casing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;charIterator()&lt;/code&gt; is a lazy &lt;code&gt;Iterator[char]&lt;/code&gt; reading the string by offset&lt;/strong&gt;, with &lt;code&gt;next()&lt;/code&gt; on
an exhausted one trapping like every iterator. &lt;code&gt;map&lt;/code&gt;/&lt;code&gt;flatMap&lt;/code&gt;/&lt;code&gt;filter&lt;/code&gt; on a string answer a
&lt;code&gt;string&lt;/code&gt;, not an iterator, and &lt;code&gt;tail&lt;/code&gt;/&lt;code&gt;init&lt;/code&gt; trap on the empty string as &lt;code&gt;Seq&lt;/code&gt;‘s do.
Review with the user: whether &lt;code&gt;toBool&lt;/code&gt; should be this strict, and whether the &lt;code&gt;Option&lt;/code&gt; forms
should answer &lt;code&gt;None&lt;/code&gt; rather than trap for a radix outside 2 to 36.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-ordering&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;clamp(x, lo, hi)&lt;/code&gt; is a free function, and &lt;code&gt;Vector&lt;/code&gt; has no &lt;code&gt;Ord&lt;/code&gt; yet.&lt;/strong&gt; A method
&lt;code&gt;x.clamp(lo, hi)&lt;/code&gt; on every &lt;code&gt;Ord&lt;/code&gt; type needs &lt;code&gt;impl[T: Ord] T&lt;/code&gt;, which the checker refuses (an impl
adds to a type parameter only where it is bounded by &lt;code&gt;Integer&lt;/code&gt; alone), so &lt;code&gt;clamp&lt;/code&gt; is a free
function beside &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt;, which are free functions too; it traps where &lt;code&gt;hi &amp;lt; lo&lt;/code&gt;. Why: it
reads like &lt;code&gt;max&lt;/code&gt;/&lt;code&gt;min&lt;/code&gt; and needs no language change. Alternatives weighed: widening the blanket
impl rule (a language change with a wide reach); a method on &lt;code&gt;Integer&lt;/code&gt; only (leaves strings,
chars and reals without). &lt;code&gt;impl[T: Ord] Ord for Vector[T]&lt;/code&gt; is refused because &lt;code&gt;Vector&lt;/code&gt; is an
abstract covariant class, whose added methods are variance positions, and &lt;code&gt;compare(other: Vector[T])&lt;/code&gt; takes &lt;code&gt;T&lt;/code&gt; in; &lt;code&gt;ArraySeq&lt;/code&gt; is a final class and has its &lt;code&gt;Ord&lt;/code&gt;. &lt;code&gt;Seq[T]&lt;/code&gt; gets no
&lt;code&gt;compare&lt;/code&gt; method. Review with the user: how &lt;code&gt;Vector&lt;/code&gt; should be &lt;code&gt;Ord&lt;/code&gt;. The recommendation is that
a method a trait impl adds, and no subclass overrides, is called through the static type rather
than the method table, which would make &lt;code&gt;compare&lt;/code&gt; on a covariant abstract class sound; that is a
language change, so it waits for the user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-ordering&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Reverse&lt;/code&gt;,
&lt;code&gt;compareBy&lt;/code&gt;, &lt;code&gt;reverseOrder&lt;/code&gt; and &lt;code&gt;thenBy&lt;/code&gt; are in &lt;code&gt;avin&lt;/code&gt; as plain names.&lt;/strong&gt;
&lt;code&gt;Reverse&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type with &lt;code&gt;Ord&lt;/code&gt; reversed and equality as &lt;code&gt;T&lt;/code&gt;‘s; descending sorts are written
with it rather than a &lt;code&gt;sortedDescending()&lt;/code&gt;. Why: it composes inside tuple keys, which a
descending method cannot. Alternatives weighed: &lt;code&gt;sortedDescending&lt;/code&gt;/&lt;code&gt;sortByDescending&lt;/code&gt; on &lt;code&gt;Seq&lt;/code&gt;
(do not combine with a second key).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-seq&lt;/code&gt;): &lt;strong&gt;Seq search, slices
and combinatorics&lt;/strong&gt;, &lt;a href=&quot;/spec/collections/&quot;&gt;collections&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;search&lt;/code&gt; answers the first of equal elements.&lt;/strong&gt; &lt;code&gt;Found(i)&lt;/code&gt; is the lowest index holding an
element equal to the one searched for, found by a lower-bound halving, so the answer is
deterministic. Why: a binary search that stops at the first hit returns whichever duplicate the
midpoints reach, which no caller can rely on and a test cannot pin; the lower bound costs the same
O(log n) comparisons and makes &lt;code&gt;Found(i)&lt;/code&gt; and &lt;code&gt;InsertionPoint(i)&lt;/code&gt; one index (&lt;code&gt;i&lt;/code&gt; is where the
element is or would go, the insertion point of an equal element being its first). Alternatives:
any equal element, unspecified (cheaper by at most one comparison, not testable); the last one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;search(x, from, until)&lt;/code&gt; holds its window to the sequence&lt;/strong&gt; (&lt;code&gt;until&lt;/code&gt; to &lt;code&gt;0 .. n&lt;/code&gt;, then &lt;code&gt;from&lt;/code&gt; to
&lt;code&gt;0 .. until&lt;/code&gt;) rather than trapping, as counts are held (&lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;) and unlike &lt;code&gt;slice&lt;/code&gt;, which
traps. Why: the window is a bound on where to look, not an index range to read, and an empty or
out-of-range one has the clear answer &lt;code&gt;InsertionPoint&lt;/code&gt; of its edge. Alternative: trap as &lt;code&gt;slice&lt;/code&gt;
does. &lt;code&gt;searchBy(key, wanted)&lt;/code&gt; is included (the plan marked it optional); it takes the key
function first, as &lt;code&gt;sortBy&lt;/code&gt;‘s sibling &lt;code&gt;distinctBy&lt;/code&gt; does, and &lt;code&gt;K: Ord&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;combinations&lt;/code&gt; and &lt;code&gt;permutations&lt;/code&gt; are distinct by &lt;code&gt;equals&lt;/code&gt; and ordered by first appearance.&lt;/strong&gt;
The classes of equal elements are found with a hash map on the elements (as &lt;code&gt;distinct&lt;/code&gt; does), so
&lt;code&gt;equals&lt;/code&gt; and &lt;code&gt;hash&lt;/code&gt; must agree, and the vectors come in dictionary order of the classes’ first
appearance. Why: the dictionary order is stepped with O(k) or O(n) work and no memory beyond the
class counts, and needs no &lt;code&gt;Ord&lt;/code&gt;. Alternatives: the order of a recursive generation, which differs
for a multiset; positions rather than values (every permutation of equal elements, n! of them).
&lt;code&gt;k &amp;lt; 0&lt;/code&gt; or &lt;code&gt;k &amp;gt; n&lt;/code&gt; gives an empty iterator, &lt;code&gt;k == 0&lt;/code&gt; and the empty sequence’s permutations one
empty vector.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;indexOfSlice&lt;/code&gt; and &lt;code&gt;lastIndexOfSlice&lt;/code&gt; find the empty slice where the edges allow&lt;/strong&gt;: at
&lt;code&gt;max(from, 0)&lt;/code&gt; while that is no further than the length, and at &lt;code&gt;min(end, n)&lt;/code&gt; while &lt;code&gt;end &amp;gt;= 0&lt;/code&gt;;
&lt;code&gt;lastIndexOfSlice(slice)&lt;/code&gt; is the form with &lt;code&gt;end&lt;/code&gt; the length, written as an overload as
&lt;code&gt;lastIndexOf&lt;/code&gt; is. &lt;code&gt;patch&lt;/code&gt; holds &lt;code&gt;from&lt;/code&gt; to &lt;code&gt;0 .. n&lt;/code&gt; and a &lt;code&gt;replaced&lt;/code&gt; below 0 to 0 rather than
trapping, and takes &lt;code&gt;other&lt;/code&gt; as an &lt;code&gt;Iterable[W]&lt;/code&gt; with &lt;code&gt;W &amp;gt;: T&lt;/code&gt;, widening as &lt;code&gt;++&lt;/code&gt; does.
&lt;code&gt;reduceRightOption&lt;/code&gt; accompanies &lt;code&gt;reduceRight&lt;/code&gt; as &lt;code&gt;reduceOption&lt;/code&gt; accompanies &lt;code&gt;reduce&lt;/code&gt;.
Alternative for all: trap on an out-of-range count, as &lt;code&gt;slice&lt;/code&gt; does for indices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;inits()&lt;/code&gt; and &lt;code&gt;tails()&lt;/code&gt; copy the elements into a vector once and slice it per step&lt;/strong&gt;, so each
step is O(log n) and the n + 1 vectors share structure; they are lazy iterators, not a vector of
vectors. &lt;code&gt;transpose()&lt;/code&gt; of rows of different lengths traps (the plan’s decision), and answers an
empty vector, not a vector of empty ones, for no rows; for rows that are all empty it answers
empty too.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-math&lt;/code&gt;): &lt;strong&gt;the integer methods are an inherent impl over &lt;code&gt;Integer&lt;/code&gt;, not
members of the trait.&lt;/strong&gt; &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;sign&lt;/code&gt;, &lt;code&gt;pow&lt;/code&gt;, &lt;code&gt;gcd&lt;/code&gt;, &lt;code&gt;lcm&lt;/code&gt;, &lt;code&gt;floorDiv&lt;/code&gt;, &lt;code&gt;floorMod&lt;/code&gt;, &lt;code&gt;bitCount&lt;/code&gt;,
&lt;code&gt;leadingZeros&lt;/code&gt;, &lt;code&gt;trailingZeros&lt;/code&gt;, &lt;code&gt;isPowerOfTwo&lt;/code&gt; and &lt;code&gt;toRadix&lt;/code&gt; are written once in
&lt;code&gt;library/avin/integer.avin&lt;/code&gt; as &lt;code&gt;impl[T: Integer] T&lt;/code&gt;, which the core library may declare. Why: it
gives every width the methods with no new trait and no change to the closed bound. The cost: a
type parameter bounded by &lt;code&gt;Integer&lt;/code&gt; sees only the trait’s members, so generic code cannot write
&lt;code&gt;x.abs()&lt;/code&gt;. Alternatives weighed: putting the methods in &lt;code&gt;Integer&lt;/code&gt; as required members (every
width implements them, but “no type implements it” then has an exception, and the arithmetic
traits would grow by a dozen); leaving them to free functions (&lt;code&gt;math.abs(x)&lt;/code&gt;, unlike
&lt;code&gt;x.compare(y)&lt;/code&gt;). Review with the user: whether generic code should reach these methods, which
means making them members of &lt;code&gt;Integer&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-math&lt;/code&gt;): &lt;strong&gt;the bitwise and shift operators work on a type parameter
bounded by &lt;code&gt;Integer&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;x &amp;amp; y&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; on a &lt;code&gt;T: Integer&lt;/code&gt; are the machine’s
operators at each instance’s width, with both operands &lt;code&gt;T&lt;/code&gt; (&lt;code&gt;x &amp;gt;&amp;gt; T(1)&lt;/code&gt;); the checker had treated
every operator on a type parameter as a call of a method of that name, so &lt;code&gt;Integer&lt;/code&gt; code had no
bit operations at all. Why: the bound is documented as having every integer operation, and the
integer methods need them. Alternatives weighed: methods &lt;code&gt;bitAnd&lt;/code&gt;, &lt;code&gt;shiftLeft&lt;/code&gt; on &lt;code&gt;Integer&lt;/code&gt; (a
second spelling of what the operators already say); doing the bit work by division and remainder
(slower, and unreadable). A &lt;code&gt;T&lt;/code&gt; with another bound still has them only as methods.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-math&lt;/code&gt;): &lt;strong&gt;choices inside the integer methods.&lt;/strong&gt; &lt;code&gt;pow(n: int)&lt;/code&gt; takes an
&lt;code&gt;int&lt;/code&gt; exponent at every width and traps on a negative one (a fraction is not an integer);
&lt;code&gt;x.pow(0)&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; for every &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;0.pow(0)&lt;/code&gt; included. &lt;code&gt;gcd&lt;/code&gt; is never negative and traps only when
its value is &lt;code&gt;MinValue&lt;/code&gt;‘s magnitude; &lt;code&gt;lcm&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt; when either side is, otherwise positive. &lt;code&gt;sign&lt;/code&gt;
is an &lt;code&gt;int&lt;/code&gt;, as are &lt;code&gt;bitCount&lt;/code&gt;, &lt;code&gt;leadingZeros&lt;/code&gt; and &lt;code&gt;trailingZeros&lt;/code&gt;, which count at the width
(&lt;code&gt;(-1).bitCount&lt;/code&gt; is &lt;code&gt;32&lt;/code&gt;, zero has &lt;code&gt;width&lt;/code&gt; leading and trailing zeros). &lt;code&gt;toRadix&lt;/code&gt; writes lower
case, a &lt;code&gt;-&lt;/code&gt; and the magnitude, as &lt;code&gt;f&amp;quot;%x&amp;quot;&lt;/code&gt; does, with no prefix, and takes &lt;code&gt;int&lt;/code&gt; from 2 to 36 and
traps outside it. Why: each is the usual meaning, the least surprising for a program moving
between widths. Alternatives weighed: a &lt;code&gt;long&lt;/code&gt; exponent (never needed; an &lt;code&gt;int&lt;/code&gt; is enough for
squaring by halves); a &lt;code&gt;gcd&lt;/code&gt; that keeps a negative sign (an unsigned-looking result is what callers
want).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-math&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.math&lt;/code&gt;
additions.&lt;/strong&gt; &lt;code&gt;round(x)&lt;/code&gt; returns a &lt;code&gt;long&lt;/code&gt;, a tie
going away from zero, and converts as &lt;code&gt;long(x)&lt;/code&gt; does for NaN and out-of-range values; &lt;code&gt;trunc(x)&lt;/code&gt;
returns a &lt;code&gt;real&lt;/code&gt;, as &lt;code&gt;floor&lt;/code&gt; and &lt;code&gt;ceil&lt;/code&gt; do, keeping a negative zero’s sign; &lt;code&gt;ulp&lt;/code&gt; at the greatest
finite value is the gap below it (a finite answer rather than infinity); &lt;code&gt;nextUp&lt;/code&gt; and &lt;code&gt;nextDown&lt;/code&gt;
leave NaN and the infinity they move towards alone. Why: &lt;code&gt;round&lt;/code&gt; is the one the program usually
wants as an integer and &lt;code&gt;rint&lt;/code&gt; is already the &lt;code&gt;real&lt;/code&gt; form; the others follow the platform’s
functions. Alternatives weighed: &lt;code&gt;round&lt;/code&gt; returning &lt;code&gt;real&lt;/code&gt; (no saturation story to tell, but the
common use then needs &lt;code&gt;long(round(x))&lt;/code&gt;); &lt;code&gt;trunc&lt;/code&gt; returning &lt;code&gt;long&lt;/code&gt; (loses negative zero and the
large values). Review with the user: the &lt;code&gt;round&lt;/code&gt; and &lt;code&gt;trunc&lt;/code&gt; result types differ, which is
unusual to read.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-iterator&lt;/code&gt;): &lt;strong&gt;The eager methods added to every &lt;code&gt;Iterable&lt;/code&gt; answer
vectors.&lt;/strong&gt; &lt;code&gt;scanLeft&lt;/code&gt; is a &lt;code&gt;Vector[B]&lt;/code&gt;, &lt;code&gt;tapEach&lt;/code&gt; and &lt;code&gt;concat&lt;/code&gt; a &lt;code&gt;Vector[T]&lt;/code&gt; (&lt;code&gt;Vector[W]&lt;/code&gt; for
&lt;code&gt;concat[W &amp;gt;: T]&lt;/code&gt;), &lt;code&gt;span&lt;/code&gt; and &lt;code&gt;partitionMap&lt;/code&gt; pairs of vectors, and &lt;code&gt;flatten()&lt;/code&gt; of a collection of
collections a &lt;code&gt;Vector[T]&lt;/code&gt;; &lt;code&gt;grouped&lt;/code&gt; and &lt;code&gt;sliding&lt;/code&gt; answer the &lt;code&gt;Iterator[Vector[T]]&lt;/code&gt; a sequence’s
do, by delegating to the iterator’s forms. WHY: one predictable kind, the one &lt;code&gt;partition&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;
and &lt;code&gt;scanLeft&lt;/code&gt; on a sequence already answer, with no higher-kinded types to name the receiver’s
own. Alternatives: &lt;code&gt;Iterable[B]&lt;/code&gt; as the &lt;code&gt;Iterable&lt;/code&gt; transformations answer (hides that it is a
vector), or each collection keeping a same-kind form (a long tail of overrides). Review with the
user: whether &lt;code&gt;tapEach&lt;/code&gt; on a list should answer a list.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-iterator&lt;/code&gt;): &lt;strong&gt;An iterator’s new lazy forms are added by
&lt;code&gt;impl[T] Iterator[T]&lt;/code&gt;, not declared in the trait.&lt;/strong&gt; So &lt;code&gt;padTo(total, element: T)&lt;/code&gt; and
&lt;code&gt;zipAll(other, thisElement: T, thatElement)&lt;/code&gt; take the element type in a parameter of the
covariant &lt;code&gt;Iterator&lt;/code&gt;, and the forms are found before the eager ones every &lt;code&gt;Iterable&lt;/code&gt; has. An
iterator whose static type is only &lt;code&gt;Iterable&lt;/code&gt; gets the eager forms, as with &lt;code&gt;map&lt;/code&gt;. Alternatives:
trait members with lower-bounded parameters (&lt;code&gt;padTo[W &amp;gt;: A]&lt;/code&gt;), which a program’s own iterator
could override, at the cost of a widened result everywhere.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-iterator&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;it ++ other&lt;/code&gt; takes &lt;code&gt;other&lt;/code&gt; as an ordinary
&lt;code&gt;Iterable&lt;/code&gt; and asks for its &lt;code&gt;iterator()&lt;/code&gt; only once &lt;code&gt;it&lt;/code&gt; is used up&lt;/strong&gt;; &lt;code&gt;concat&lt;/code&gt; on an iterator is
the same lazy join. WHY: a strict argument reads like every other call, and the iterator taken late
is what keeps a mutable &lt;code&gt;other&lt;/code&gt; read as it is when reached. Alternative: a by-name &lt;code&gt;other&lt;/code&gt;, which
would delay even evaluating the expression.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-iterator&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Iterator.from&lt;/code&gt; is two overloads over
&lt;code&gt;T: Integer&lt;/code&gt;, &lt;code&gt;from(start)&lt;/code&gt; and &lt;code&gt;from(start, step)&lt;/code&gt;,&lt;/strong&gt; not one with &lt;code&gt;step = 1&lt;/code&gt;, since the default
would have to be &lt;code&gt;T(1)&lt;/code&gt; of the caller’s type. An element is computed when it is read, so
&lt;code&gt;from(int.MaxValue)&lt;/code&gt; gives &lt;code&gt;int.MaxValue&lt;/code&gt; and overflow traps only when the element past it is read.
Alternatives: a default parameter written &lt;code&gt;T(1)&lt;/code&gt;; &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; overloads only.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-iterator&lt;/code&gt;): &lt;strong&gt;The companion iterators compute when read.&lt;/strong&gt;
&lt;code&gt;fill&lt;/code&gt; and &lt;code&gt;continually&lt;/code&gt; evaluate their by-name element at each &lt;code&gt;next()&lt;/code&gt;, &lt;code&gt;tabulate&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt; at
each &lt;code&gt;next()&lt;/code&gt;, &lt;code&gt;iterate&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt; before each element after the first, and &lt;code&gt;unfold&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt;
when &lt;code&gt;hasNext()&lt;/code&gt; is asked and holds the element it gave. WHY: an iterator does no work for an
element that is not read. Alternative: &lt;code&gt;fill&lt;/code&gt; and &lt;code&gt;tabulate&lt;/code&gt; building a vector and iterating it,
as the sequence companions do (eager, and &lt;code&gt;fill&lt;/code&gt;‘s element evaluated before any is read).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-iterator&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;grouped&lt;/code&gt; and &lt;code&gt;sliding&lt;/code&gt; on an iterator give the
windows a sequence’s give&lt;/strong&gt;, reading the next window when &lt;code&gt;hasNext()&lt;/code&gt; is asked, holding no element
beyond the current window, and trapping on a size or step below 1 at the call, with the messages a
sequence’s use. &lt;code&gt;BufferedIterator[A]&lt;/code&gt; is a public class with &lt;code&gt;peek()&lt;/code&gt; (trapping with “peek on an
exhausted iterator”) and &lt;code&gt;peekOption()&lt;/code&gt;; &lt;code&gt;buffered()&lt;/code&gt; on one wraps it again. &lt;code&gt;flatten()&lt;/code&gt; is also
on an iterator of collections, lazily, beside the eager one on every collection of collections.
Alternatives: windows read at &lt;code&gt;next()&lt;/code&gt; only (no lookahead, but &lt;code&gt;hasNext()&lt;/code&gt; could not answer for a
step that skips past the end); &lt;code&gt;buffered()&lt;/code&gt; answering a buffered iterator itself.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-predef&lt;/code&gt;): &lt;strong&gt;an impl without &lt;code&gt;for&lt;/code&gt; adds methods to tuple and function
types&lt;/strong&gt; built from its parameters (&lt;code&gt;impl[A, B] (A, B)&lt;/code&gt;, &lt;code&gt;impl[A, B] (A) -&amp;gt; B&lt;/code&gt;), as the impl chapter
already allowed for any type built from parameters and for traits, which function types are. The
checker refused both (“an impl adds to a data type, a class, an object or a built-in type”; “an
impl for every tuple of an arity implements a trait”); that was a bug against the design and is
fixed. The choices the chapter did not settle: &lt;strong&gt;a function type’s methods reach the types that
are subtypes of it&lt;/strong&gt; (a data type or class naming it, sequences, sets, maps, partial functions), as
a trait’s added methods reach its implementers, and &lt;strong&gt;the type’s own method of the same parameter
types is found first&lt;/strong&gt;, as for a trait; a tuple pattern stays exact, as other non-trait patterns
do. &lt;strong&gt;A &lt;code&gt;@sendable&lt;/code&gt; function type in the pattern matches only &lt;code&gt;@sendable&lt;/code&gt; functions.&lt;/strong&gt; Such an impl
outside the core library is an extension, since the tuple and function types are the core
library’s. Rationale: these follow the existing rules for traits and for patterns, with no new
rule. Alternatives weighed: matching only receivers whose static type is a function type (a
&lt;code&gt;Vector&lt;/code&gt; would then lack &lt;code&gt;andThen&lt;/code&gt;, though it is passed wherever an &lt;code&gt;(int) -&amp;gt; T&lt;/code&gt; is); treating a
&lt;code&gt;@sendable&lt;/code&gt; pattern as plain (its methods would reach functions that may not run on another
thread, against what the impl names).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-predef&lt;/code&gt;): &lt;strong&gt;an impl naming a tuple or function type has at least one type
parameter.&lt;/strong&gt; &lt;code&gt;impl (int, int)&lt;/code&gt; with none begins a function named &lt;code&gt;impl&lt;/code&gt;, since &lt;code&gt;impl&lt;/code&gt; is a
keyword only before a type and &lt;code&gt;impl(…)&lt;/code&gt; declares a function; &lt;code&gt;impl() -&amp;gt; int&lt;/code&gt; followed by a body
reads either way, so no rule on the tokens can tell them apart. A part may be written out
(&lt;code&gt;impl[A] (A, int)&lt;/code&gt;). Alternatives weighed: allowing &lt;code&gt;impl[]&lt;/code&gt; (an empty list says nothing and the
parser refuses it for every impl); making &lt;code&gt;impl&lt;/code&gt; a full keyword (breaks a function of that name).
Review with the user: whether an impl for one concrete tuple or function type is wanted enough to
reserve &lt;code&gt;impl (&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-predef&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;require(condition, message)&lt;/code&gt; takes the message by name&lt;/strong&gt;, so
it is built only when the requirement fails, while &lt;code&gt;assert(condition, message)&lt;/code&gt; takes a plain
string. Rationale: &lt;code&gt;require&lt;/code&gt; sits at the top of ordinary functions, called on every call, and its
message usually interpolates the arguments; building it every time would cost the common path.
Alternatives weighed: a plain string, as &lt;code&gt;assert&lt;/code&gt; (cost on every call); changing &lt;code&gt;assert&lt;/code&gt; to by-name
as well (out of this item’s scope; it would be a separate change to a settled API). &lt;code&gt;todo(message)&lt;/code&gt;
takes a plain string, since it always traps. &lt;strong&gt;&lt;code&gt;ensuring&lt;/code&gt; is not provided&lt;/strong&gt;: it needs an impl for
every type (&lt;code&gt;impl[T] T&lt;/code&gt;), which only the integer family has; a postcondition is written with
&lt;code&gt;require&lt;/code&gt;/&lt;code&gt;assert&lt;/code&gt; on the result.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-inplace&lt;/code&gt;): &lt;strong&gt;in-place operations on &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt; and &lt;code&gt;Array&lt;/code&gt;, and
&lt;code&gt;StringWriter&lt;/code&gt; length and clear.&lt;/strong&gt; Choices the spec did not settle:
(1) &lt;strong&gt;&lt;code&gt;remove(i, n)&lt;/code&gt; is an overload of &lt;code&gt;remove(i)&lt;/code&gt;&lt;/strong&gt;, and its count parameter is named &lt;code&gt;n&lt;/code&gt;, so it
never shadows the buffer’s own &lt;code&gt;count&lt;/code&gt;. A range not within the collection traps (&lt;code&gt;n&lt;/code&gt; greater than
&lt;code&gt;length() - i&lt;/code&gt; included, tested without overflow); &lt;code&gt;n = 0&lt;/code&gt; at &lt;code&gt;length()&lt;/code&gt; is allowed.
(2) &lt;strong&gt;&lt;code&gt;subtractOne(x)&lt;/code&gt; answers a &lt;code&gt;bool&lt;/code&gt;&lt;/strong&gt; (whether one was taken out) rather than the collection,
and is declared in an &lt;code&gt;impl[T: Eq]&lt;/code&gt; block, so it exists only where elements compare; it takes the
first match, from the front. Alternatives: returning &lt;code&gt;self&lt;/code&gt; for chaining (hides a miss), and a
&lt;code&gt;-=&lt;/code&gt; operator (a bool-valued compound assignment reads badly).
(3) &lt;strong&gt;&lt;code&gt;filterInPlace&lt;/code&gt; and &lt;code&gt;mapInPlace&lt;/code&gt; trap when the predicate or function changed the length&lt;/strong&gt;,
instead of leaving the outcome unspecified or silently working on a snapshot: the check is one
comparison per element and turns a corrupted result into a trap at the caller’s line. Alternatives:
iterate a snapshot (hides the bug and costs a copy), or leave it undefined.
(4) &lt;strong&gt;&lt;code&gt;mapInPlace&lt;/code&gt; takes &lt;code&gt;(T) -&amp;gt; T&lt;/code&gt;&lt;/strong&gt;, since the element type cannot change in place.
(5) &lt;strong&gt;&lt;code&gt;patchInPlace(from, other, replaced)&lt;/code&gt; reads &lt;code&gt;other&lt;/code&gt; first&lt;/strong&gt; and traps for a &lt;code&gt;from&lt;/code&gt; or
&lt;code&gt;replaced&lt;/code&gt; outside the collection, where a clamping rule would hide a wrong index.
(6) &lt;strong&gt;&lt;code&gt;fillInPlace&lt;/code&gt; is a separate name from the companion’s &lt;code&gt;Array.fill&lt;/code&gt;&lt;/strong&gt;, as &lt;code&gt;fill&lt;/code&gt; there makes a
new array; it shares the one value as &lt;code&gt;fill&lt;/code&gt; does.
(7) &lt;strong&gt;&lt;code&gt;Array.copyTo(dest, at, from = 0, count = length() - from)&lt;/code&gt;&lt;/strong&gt; gives &lt;code&gt;count&lt;/code&gt; a default that is
a function of &lt;code&gt;from&lt;/code&gt;, which the declaration rules allow; it is overlap-safe in both directions
(the copy runs backwards when &lt;code&gt;dest&lt;/code&gt; is the same array and &lt;code&gt;at &amp;gt; from&lt;/code&gt;). All ranges are checked
before the first element moves.
(8) &lt;strong&gt;&lt;code&gt;StringWriter.length()&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt; count of bytes&lt;/strong&gt;, as every offset into a string is, and
&lt;code&gt;clear()&lt;/code&gt; drops the stored text so a text already taken is unaffected. A &lt;strong&gt;&lt;code&gt;write(x: Display)&lt;/code&gt;
overload on &lt;code&gt;Writer&lt;/code&gt; is not added&lt;/strong&gt;: it would sit beside &lt;code&gt;write(text: string)&lt;/code&gt; (a &lt;code&gt;string&lt;/code&gt; is
&lt;code&gt;Display&lt;/code&gt;) and make every call a resolution by specificity for no gain, &lt;code&gt;writeDisplayed&lt;/code&gt; already
writing any &lt;code&gt;Display&lt;/code&gt; value. Revisit if a user wants &lt;code&gt;out.write(42)&lt;/code&gt;. Review with the user: the
length-change trap in (3), and leaving out &lt;code&gt;write(x: Display)&lt;/code&gt; in (8).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;neg-nan-sign&lt;/code&gt;): &lt;strong&gt;Unary minus on a
&lt;code&gt;real&lt;/code&gt; flips the sign bit of every value, NaN included&lt;/strong&gt; (the machine’s negation, not &lt;code&gt;-0.0 - x&lt;/code&gt;,
which leaves a NaN’s sign as it was), and &lt;strong&gt;&lt;code&gt;math.signBit(x: real) -&amp;gt; bool&lt;/code&gt;&lt;/strong&gt; answers whether the
sign bit is set, so the sign of a NaN or a zero can be observed. WHY: negation is the sign flip
for every value in IEEE 754, and without &lt;code&gt;signBit&lt;/code&gt; a program could tell a NaN’s sign by no means
(&lt;code&gt;hash&lt;/code&gt; makes every NaN one value and both print as &lt;code&gt;NaN&lt;/code&gt;). Alternatives: reading the sign through
&lt;code&gt;copySign(1.0, x)&lt;/code&gt; only (works, but reads as a trick).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;union-mir-words&lt;/code&gt;): &lt;strong&gt;Values of more than one machine word in the intermediate
code&lt;/strong&gt; (the first part of the union tag-and-payload layout, under Settled → unions →
Representation).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Each word is a value of its own&lt;/strong&gt; (scalar replacement): as parameters a multi-word value is one
parameter per word, in a local one slot per word, in an object or a closure one field per word,
and a merge at a join is one slot per word. Only a result needs new forms: a signature’s &lt;code&gt;rest&lt;/code&gt;
lists the types of the words after the first; a call defines the first word as its value and each
later one with &lt;code&gt;CallWord&lt;/code&gt;, a return gives the first as its value and each later one with
&lt;code&gt;ReturnWord&lt;/code&gt;; LLVM returns the words as one structure, in registers. &lt;em&gt;Why&lt;/em&gt;: every word is an
ordinary typed value, so the frame plan roots exactly the words of reference type, wherever each
is live across a collection point, and never a scalar word, with no change to how roots are
found. &lt;em&gt;Alternatives&lt;/em&gt;: an LLVM structure value carried whole (the root plan would have to look
inside it); returning the later words through slots of the caller passed by address (a slot whose
address is passed is no root the plan follows); returning them through the thread’s context (a
store and a load per word, and a window where a reference is in no frame).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proven on tuples taken apart from calls&lt;/strong&gt;: &lt;code&gt;val (a, b) = f(x)&lt;/code&gt;, where &lt;code&gt;f&lt;/code&gt; is one of the
program’s functions with a body (not a constructor, a trait’s method or a binding) and the tuple
has at least two parts with runtime values, calls a copy of &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;f#words&lt;/code&gt;, that answers with the
tuple’s parts, one word each; every return reads the parts out of the tuple, which is then made
and read in one function and kept as its parts, and a call in tail position of a function yielding
a tuple of the same words passes its words straight on. So a recursive or large function answering
with a tuple no longer allocates it for a caller that takes it apart; a caller that keeps the tuple
calls &lt;code&gt;f&lt;/code&gt; itself, which still makes it. &lt;em&gt;Why&lt;/em&gt;: a real path the existing programs run, with
references beside scalars in every combination, and with no change to any type’s representation
or to what a program sees. &lt;em&gt;Alternatives&lt;/em&gt;: a compiler-internal pair type no program could reach
(exercised only by tests); every function yielding a tuple answering with words and callers that
keep it making it again (a made-again tuple’s type record could differ from the one the function
made, which a type pattern on an &lt;code&gt;Any&lt;/code&gt; would see).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A small function answering with words is inlined where it is called&lt;/strong&gt;, each later word through a
slot of its own, so &lt;code&gt;val (q, r) = divmod(a, b)&lt;/code&gt; still makes no call and no tuple. Guarded calls
through a method table meet in one value, so devirtualization leaves a call of several words
through the table rather than guarding it. A call in tail position whose every word the block
returns at its own place is a tail call, its whole result returned, so functions answering with
words call each other in constant stack as functions yielding tuples do. &lt;em&gt;Alternatives&lt;/em&gt;: never
inlining such functions (a call where there was none at &lt;code&gt;-O0&lt;/code&gt;); no tail calls of several words
(deep mutual recursion through &lt;code&gt;val (a, b) = f(x)&lt;/code&gt; would overflow the stack).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-priority-queue&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;PriorityQueue&lt;/code&gt; gives the greatest element first&lt;/strong&gt; (branch &lt;code&gt;stdlib-priority-queue&lt;/code&gt;),
&lt;a href=&quot;/spec/collections/#priority-queues&quot;&gt;collections&lt;/a&gt;. &lt;code&gt;PriorityQueue[T]()&lt;/code&gt; orders by &lt;code&gt;T&lt;/code&gt;‘s &lt;code&gt;Ord&lt;/code&gt;, and
&lt;code&gt;PriorityQueue.withOrdering(compare)&lt;/code&gt; by a comparison; the element &lt;code&gt;compare&lt;/code&gt; finds greatest comes
out first. Why: it matches &lt;code&gt;max&lt;/code&gt;, which every &lt;code&gt;Ord&lt;/code&gt; type already answers, and &lt;code&gt;dequeue&lt;/code&gt; then takes
the same element &lt;code&gt;max()&lt;/code&gt; would; a least-first queue is one &lt;code&gt;Reverse&lt;/code&gt; or &lt;code&gt;reverseOrder&lt;/code&gt; away either
way. Alternative: least first (the order of a sorted sequence read from the front, the usual choice
for shortest-path searches); it makes &lt;code&gt;PriorityQueue[int]()&lt;/code&gt; the odd one out against &lt;code&gt;max&lt;/code&gt;.
Review with the user: it is the default every caller will meet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-priority-queue&lt;/code&gt;): &lt;strong&gt;A queue’s &lt;code&gt;iterator()&lt;/code&gt; and &lt;code&gt;toVector()&lt;/code&gt; are in heap order, and &lt;code&gt;toSortedVector()&lt;/code&gt; is the sorted
form&lt;/strong&gt; (branch &lt;code&gt;stdlib-priority-queue&lt;/code&gt;). Heap order starts with the greatest element and is
otherwise unspecified; the iterator is a snapshot taken when it is made, so enqueuing or dequeuing
while iterating neither traps nor changes what it gives. Why: heap order costs nothing, a sorted
iteration costs O(n log n) and a copy, and &lt;code&gt;Iterable&lt;/code&gt; conformance wants the cheap one; a snapshot
makes mutation during iteration defined. Alternatives: iterating in dequeue order; an iterator
over the live heap (cheaper, but what it gives after a change is arbitrary).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-priority-queue&lt;/code&gt;): &lt;strong&gt;Equal elements come out in no promised order&lt;/strong&gt; (branch &lt;code&gt;stdlib-priority-queue&lt;/code&gt;): a binary heap
is not stable. Alternative: a sequence number breaking ties first-in-first-out, at the cost of a
word per element and a wider comparison; a caller wanting it orders by &lt;code&gt;thenBy&lt;/code&gt; on its own counter.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-ordered-map&lt;/code&gt;): &lt;strong&gt;Insertion-ordered maps and sets: names, update order, equality&lt;/strong&gt; (branch &lt;code&gt;stdlib-ordered-map&lt;/code&gt;).
The concrete types are &lt;code&gt;OrderedMap[K, +V]&lt;/code&gt; and &lt;code&gt;OrderedSet[A]&lt;/code&gt;, conforming to the traits &lt;code&gt;SeqMap[K, +V]&lt;/code&gt;
and &lt;code&gt;SeqSet[A]&lt;/code&gt;. &lt;em&gt;Why:&lt;/em&gt; the concrete names say what the collection does, as &lt;code&gt;HashMap&lt;/code&gt; says how it
finds and &lt;code&gt;TreeMap&lt;/code&gt; how it sorts, and no implementation (a vector of keys) leaks into them; the
trait names follow the sequence-like “in the order added” meaning of &lt;code&gt;Seq&lt;/code&gt;. &lt;em&gt;Alternatives:&lt;/em&gt;
&lt;code&gt;VectorMap&lt;/code&gt;/&lt;code&gt;VectorSet&lt;/code&gt; (names the layout, not the behaviour), &lt;code&gt;InsertionOrderedMap&lt;/code&gt;,
&lt;code&gt;LinkedHashMap&lt;/code&gt;-style names, and &lt;code&gt;OrderedMap&lt;/code&gt; as the trait with the concrete type named for its
layout. &lt;em&gt;Update order:&lt;/em&gt; updating a key already present keeps its place and replaces its value;
removing and re-adding moves it to the end. &lt;em&gt;Why:&lt;/em&gt; an update is not a new arrival, so a map used as
a record keeps its field order. &lt;em&gt;Alternative:&lt;/em&gt; an update moves the key to the end. &lt;em&gt;Equality:&lt;/em&gt; two
maps are equal when they hold the same keys bound to equal values, and two sets when they hold the
same elements, whatever the order, and equal ones hash alike, so an &lt;code&gt;OrderedMap&lt;/code&gt; equals a
&lt;code&gt;HashMap&lt;/code&gt; of the same entries as every kind of &lt;code&gt;Map&lt;/code&gt; does. &lt;em&gt;Why:&lt;/em&gt; the existing rule makes map
equality independent of the kind, and an order-sensitive &lt;code&gt;==&lt;/code&gt; on one kind would break transitivity
through the traits. &lt;em&gt;Alternative:&lt;/em&gt; an order-sensitive &lt;code&gt;==&lt;/code&gt; between two ordered maps (reached by
comparing &lt;code&gt;iterator()&lt;/code&gt;s). &lt;em&gt;Layout:&lt;/em&gt; a hash trie from key to slot and a vector of slots, removal
leaving a gap, compacted when gaps exceed both eight and the entries. &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and
&lt;code&gt;flatMap&lt;/code&gt; through the trait answer hash-based collections, as for &lt;code&gt;TreeMap&lt;/code&gt; through &lt;code&gt;Map&lt;/code&gt;. A
&lt;code&gt;{k: v}&lt;/code&gt; or &lt;code&gt;{a, b}&lt;/code&gt; literal builds one where &lt;code&gt;SeqMap&lt;/code&gt;, &lt;code&gt;OrderedMap&lt;/code&gt;, &lt;code&gt;SeqSet&lt;/code&gt; or &lt;code&gt;OrderedSet&lt;/code&gt; is
expected. Review with the user: the names.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-ordered-map&lt;/code&gt;): &lt;strong&gt;A call through a method table or a bound reaches only methods of types that conform&lt;/strong&gt; (branch
&lt;code&gt;stdlib-ordered-map&lt;/code&gt;; a fix, recorded because it changes what the polymorphic-recursion check
reports). The type arguments of a method’s own type parameters flowed into every method of the same
name and arity of any type, so a generic method that called a sequence’s &lt;code&gt;updated&lt;/code&gt; with a type built
from its own parameter was reported as recursing into itself. They now flow only into methods of
types that have the called method’s class or trait among their ancestors. &lt;em&gt;Alternative:&lt;/em&gt; keep the
name-only approximation and rename the method (rejected: &lt;code&gt;updated&lt;/code&gt; is the name every map has).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-linked-map&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.collections.mutable.LinkedMap[K, V]&lt;/code&gt; and
&lt;code&gt;LinkedSet[A]&lt;/code&gt;, the insertion-ordered mutable map and set.&lt;/strong&gt; The choices:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;Re-binding a present key keeps its place&lt;/em&gt;; &lt;code&gt;putLast(k, v)&lt;/code&gt; and &lt;code&gt;moveToEnd(k)&lt;/code&gt; (and a set’s
&lt;code&gt;addLast&lt;/code&gt; and &lt;code&gt;moveToEnd&lt;/code&gt;) make it the newest, and a key removed and bound again is new. Why:
&lt;code&gt;m(k) = v&lt;/code&gt; is a plain update everywhere else, and an insertion-ordered map whose update reorders
it would make &lt;code&gt;m(k) += 1&lt;/code&gt; shuffle the iteration; an LRU cache that wants the move says so
with &lt;code&gt;moveToEnd&lt;/code&gt;. Alternatives: every put moves to the end (access order for caches, but
surprising for a plain map); a constructor flag selecting access order (one type with two
behaviours).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Equality and hash ignore order&lt;/em&gt;: two linked maps (or sets) are equal when they hold the same
entries, as two mutable maps are; a &lt;code&gt;LinkedMap&lt;/code&gt; is not comparable with a &lt;code&gt;Map&lt;/code&gt; of the other
kind (they are different classes). Why: &lt;code&gt;==&lt;/code&gt; on maps is about contents, and the order is
observable through iteration anyway. Alternative: order-sensitive equality, which makes
&lt;code&gt;{a: 1, b: 2}&lt;/code&gt; differ from &lt;code&gt;{b: 2, a: 1}&lt;/code&gt;, unlike every other map.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;The oldest and newest ends&lt;/em&gt;: &lt;code&gt;headOption()&lt;/code&gt; and &lt;code&gt;lastOption()&lt;/code&gt; answer the ends in constant
time (overriding &lt;code&gt;Iterable&lt;/code&gt;‘s, so &lt;code&gt;head()&lt;/code&gt; and &lt;code&gt;last()&lt;/code&gt; trap when empty), and &lt;code&gt;removeFirst()&lt;/code&gt;
and &lt;code&gt;removeLast()&lt;/code&gt; answer the removed &lt;code&gt;(key, value)&lt;/code&gt; (a set’s, the element) and trap when empty.
Why: &lt;code&gt;removeFirst&lt;/code&gt; is the eviction step of an LRU cache. Alternatives: &lt;code&gt;removeFirst&lt;/code&gt; answering
an &lt;code&gt;Option&lt;/code&gt; (an empty map is then silently ignored by a cache that expected an entry);
&lt;code&gt;pollFirst&lt;/code&gt;-style names.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Mutation during iteration&lt;/em&gt;: replacing values and removing entries are defined (a removed
entry the iterator has not reached is skipped); binding new keys never traps but whether the
iterator visits them is not defined. Why: the entries sit in a buffer, a removal leaves a gap
the iterator skips, and the buffer is squeezed only by an insertion, which hands the map a new
buffer and leaves an iterator in progress stepping through the old one. Alternative: trapping on
a structural change (a version counter), which the other mutable maps do not do either.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Representation&lt;/em&gt;: a &lt;code&gt;Map[K, int]&lt;/code&gt; from each key to its position, and a &lt;code&gt;Buffer&lt;/code&gt; of entries in
insertion order with gaps for removed ones, squeezed when gaps are half of at least 32
positions; every operation is amortized constant time. Alternative: open addressing with
order links threaded through the table, one structure instead of two but a second copy of the
table’s removal logic; it can replace this without changing the API.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-queue&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Queue[+T]&lt;/code&gt; (immutable, two lists), built by the stdlib-queue branch.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Choice:&lt;/em&gt; &lt;code&gt;Queue&lt;/code&gt; is an abstract covariant class with a private two-list implementation, so its
constructor cannot be called with a state that breaks the invariant (the front is empty only
when the back is). It has &lt;code&gt;Queue(xs*)&lt;/code&gt;, &lt;code&gt;Queue.empty[T]()&lt;/code&gt; and &lt;code&gt;Queue.newBuilder&lt;/code&gt;, but no
&lt;code&gt;tabulate&lt;/code&gt; or &lt;code&gt;fill&lt;/code&gt;, no &lt;code&gt;++&lt;/code&gt;, and no literal form. &lt;code&gt;dequeue()&lt;/code&gt; answers &lt;code&gt;(T, Queue[T])&lt;/code&gt;;
&lt;code&gt;front()&lt;/code&gt; is the name of the head read; &lt;code&gt;apply(i)&lt;/code&gt; is O(i) and &lt;code&gt;map&lt;/code&gt;/&lt;code&gt;filter&lt;/code&gt; answer queues.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Why:&lt;/em&gt; the abstract class keeps the invariant that gives constant-time &lt;code&gt;front()&lt;/code&gt; and amortized
constant &lt;code&gt;dequeue&lt;/code&gt;; a pair return keeps the type immutable; &lt;code&gt;Seq&lt;/code&gt; conformance gives equality,
hashing and the sequence methods for free, so a queue equals a vector of its elements.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Alternatives weighed:&lt;/em&gt; a &lt;code&gt;data&lt;/code&gt; type with public &lt;code&gt;Cons&lt;/code&gt;-like variants (exposes the lists and the
invariant); a banker’s queue with lazy rebalancing (worst-case bounds, but heavier and no
better for the usual single-threaded use); &lt;code&gt;dequeue&lt;/code&gt; answering &lt;code&gt;Option&lt;/code&gt; only (loses the trap
that every other &lt;code&gt;removeHead&lt;/code&gt; has); &lt;code&gt;head&lt;/code&gt;/&lt;code&gt;tail&lt;/code&gt; names only (they remain, from &lt;code&gt;Seq&lt;/code&gt;, with &lt;code&gt;tail&lt;/code&gt;
answering a &lt;code&gt;Vector&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-bitset&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BitSet&lt;/code&gt; (immutable and mutable): representation and negatives&lt;/strong&gt; (branch &lt;code&gt;stdlib-bitset&lt;/code&gt;).
Proposed: the immutable &lt;code&gt;BitSet&lt;/code&gt; is a class over a &lt;code&gt;Vector[long]&lt;/code&gt; of words, kept without empty words
at the end, so an update copies one path and &lt;code&gt;toBitMask()&lt;/code&gt; is the words; the mutable one is over a
&lt;code&gt;Buffer[long]&lt;/code&gt;. A negative element is not in any bit set: &lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;excl&lt;/code&gt;/&lt;code&gt;remove&lt;/code&gt; treat it as
absent (&lt;code&gt;false&lt;/code&gt;, set unchanged), and everything that would add one traps (&lt;code&gt;incl&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;,
the builder, &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;); the ordered queries and slices take any &lt;code&gt;int&lt;/code&gt;. Why: a
query about a number that cannot be present has the honest answer “no”, which keeps generic
code over &lt;code&gt;Set[int]&lt;/code&gt; from trapping on &lt;code&gt;s(x)&lt;/code&gt;, while storing a number the set cannot hold must not
silently succeed. Alternatives weighed: trapping in &lt;code&gt;contains&lt;/code&gt;/&lt;code&gt;remove&lt;/code&gt; too (strict, but breaks
&lt;code&gt;Set[int]&lt;/code&gt; code that probes with arbitrary ints); ignoring negatives in &lt;code&gt;incl&lt;/code&gt; (silently drops an
element, so &lt;code&gt;s.incl(x).contains(x)&lt;/code&gt; can be false); offsetting by a minimum (a different set type).
Review with the user if bit sets of negatives (a signed range) are wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-bitset&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BitSet&lt;/code&gt; method names beyond the &lt;code&gt;Set&lt;/code&gt; ones&lt;/strong&gt; (branch &lt;code&gt;stdlib-bitset&lt;/code&gt;). Proposed: the immutable
set adds &lt;code&gt;symmetricDiff&lt;/code&gt; and &lt;code&gt;toBitMask&lt;/code&gt;, with &lt;code&gt;BitSet.fromBitMask&lt;/code&gt;; the mutable one adds
&lt;code&gt;unionInPlace&lt;/code&gt;, &lt;code&gt;intersectInPlace&lt;/code&gt;, &lt;code&gt;diffInPlace&lt;/code&gt;, &lt;code&gt;symmetricDiffInPlace&lt;/code&gt; (taking a mutable bit
set), the non-mutating &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt; and &lt;code&gt;symmetricDiff&lt;/code&gt; over mutable bit sets,
&lt;code&gt;copy()&lt;/code&gt; and &lt;code&gt;toSet()&lt;/code&gt; (the immutable one), beside the mutable &lt;code&gt;Set&lt;/code&gt;‘s &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;addAll&lt;/code&gt;,
&lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt;, &lt;code&gt;--=&lt;/code&gt; and &lt;code&gt;filterInPlace&lt;/code&gt;. Why: the &lt;code&gt;…InPlace&lt;/code&gt; suffix names the in-place form of a
method the set already has (as &lt;code&gt;filterInPlace&lt;/code&gt; and &lt;code&gt;sortInPlace&lt;/code&gt; do) and spells out what the symbol
forms &lt;code&gt;|=&lt;/code&gt; and &lt;code&gt;&amp;amp;=&lt;/code&gt; would, which are free method names but carry no word for a reader. Alternatives:
&lt;code&gt;|=&lt;/code&gt;, &lt;code&gt;&amp;amp;=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt; as the in-place algebra (&lt;code&gt;-=&lt;/code&gt; is taken by removing an element); &lt;code&gt;unionWith&lt;/code&gt; and so on
(suggests a combining function); &lt;code&gt;addAll(other)&lt;/code&gt; for the union (already means adding elements of
any &lt;code&gt;Iterable&lt;/code&gt;). &lt;code&gt;symmetricDiff&lt;/code&gt; is &lt;code&gt;xor&lt;/code&gt; in some libraries; the longer name reads without
knowing bit-twiddling. The mutable bit set’s &lt;code&gt;union&lt;/code&gt;/&lt;code&gt;intersect&lt;/code&gt;/&lt;code&gt;diff&lt;/code&gt; take a mutable bit set only
rather than any &lt;code&gt;Set[int]&lt;/code&gt;, the mutable &lt;code&gt;Set&lt;/code&gt; not being a &lt;code&gt;Set&lt;/code&gt; trait member either.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-bitset&lt;/code&gt;): &lt;strong&gt;A mutable &lt;code&gt;BitSet&lt;/code&gt; iterates over a snapshot, and its ordered queries copy it&lt;/strong&gt; (branch
&lt;code&gt;stdlib-bitset&lt;/code&gt;). Proposed: &lt;code&gt;iterator()&lt;/code&gt;, &lt;code&gt;headOption()&lt;/code&gt;, &lt;code&gt;lastOption()&lt;/code&gt;, &lt;code&gt;minAfter&lt;/code&gt; and
&lt;code&gt;maxBefore&lt;/code&gt; of a mutable bit set read an immutable copy of its words, so changing the set during a
&lt;code&gt;for&lt;/code&gt; is safe and visits the elements it had when the loop began. Why: it makes the iterator the
same code as the immutable one, and a mutable hash set’s iterator has no defined behaviour under
change at all, so a stable one is the safer promise. Cost: one pass over the words per call, so a
loop calling &lt;code&gt;minAfter&lt;/code&gt; repeatedly on a large sparse set is quadratic in the words. Alternative: a
live iterator that reads the words as it goes (no copy, but sees its own changes); revisit if
&lt;code&gt;minAfter&lt;/code&gt; is used as a scan.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-mutable-tree&lt;/code&gt;): &lt;strong&gt;A mutable tree map or set holds an immutable one and
replaces it; iterating it while updating it is legal and sees the collection as it was.&lt;/strong&gt;
&lt;code&gt;avin.collections.mutable.TreeMap&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt; keep a private immutable &lt;code&gt;TreeMap&lt;/code&gt; or &lt;code&gt;TreeSet&lt;/code&gt;
and assign a new one at each update. Why: the persistent tree is already balanced and tested, its
&lt;code&gt;SortedTree&lt;/code&gt; is private to module &lt;code&gt;avin&lt;/code&gt; (so a second module could not share it without widening
it), every ordered query comes for free, and &lt;code&gt;toTreeMap()&lt;/code&gt;/&lt;code&gt;toTreeSet()&lt;/code&gt; become O(1) snapshots.
Consequence: an iterator made before an update visits the entries as they were, so a loop that
removes or adds entries cannot skip, repeat or fault, unlike the hash-based mutable collections,
whose iteration while updating is unspecified. Alternatives weighed: a mutable balanced tree with
in-place rotations (faster constants, no allocation per update, but a second tree implementation,
and iterators would need invalidation rules); a skip list (same objection). Updates allocate
O(log n) nodes, which a mutable tree would not; revisit if a profile shows it. Review with the user:
the snapshot-iteration guarantee is a promise a later in-place tree would have to keep.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-mutable-tree&lt;/code&gt;): &lt;strong&gt;Two types are named &lt;code&gt;TreeMap&lt;/code&gt; (and &lt;code&gt;TreeSet&lt;/code&gt;), one in
&lt;code&gt;avin&lt;/code&gt; and one in &lt;code&gt;avin.collections.mutable&lt;/code&gt;.&lt;/strong&gt; As &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; already are. Inside the mutable
module the bare name is the mutable one and the immutable one is imported under an alias; a program
importing the mutable one unaliased while also using the prelude’s gets the mutable one for the bare
name, and reaches the immutable one through an aliased import (both forms are tested). Alternatives:
distinct names (&lt;code&gt;MutableTreeMap&lt;/code&gt;) which would break the parallel with &lt;code&gt;Map&lt;/code&gt;/&lt;code&gt;Set&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-mutable-tree&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;removeFirst()&lt;/code&gt;/&lt;code&gt;removeLast()&lt;/code&gt; trap on an empty
collection; &lt;code&gt;removeFirstOption()&lt;/code&gt;/&lt;code&gt;removeLastOption()&lt;/code&gt; answer &lt;code&gt;None&lt;/code&gt;.&lt;/strong&gt; The immutable sorted
collections pair &lt;code&gt;head()&lt;/code&gt; (trapping) with &lt;code&gt;headOption()&lt;/code&gt;; the removal operations follow the same
split, the plain name being the trapping form. Alternatives: answering an &lt;code&gt;Option&lt;/code&gt; from the plain
name (as &lt;code&gt;remove(key)&lt;/code&gt; does), or a &lt;code&gt;pollFirst&lt;/code&gt; name.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-mutable-tree&lt;/code&gt;): &lt;strong&gt;The &lt;code&gt;range*&lt;/code&gt; forms of a mutable tree collection answer a
new mutable collection, not a view.&lt;/strong&gt; As &lt;code&gt;filter&lt;/code&gt; and &lt;code&gt;copy()&lt;/code&gt; do on the hash-based mutable
collections; a write to the slice does not reach the original. Sharing the tree makes the slice O(log
n) to make. Alternative: live views, which would need the mutable tree to be in place.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-mutable-tree&lt;/code&gt;): &lt;strong&gt;A mutable tree set’s &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt; and
&lt;code&gt;subsetOf&lt;/code&gt; take a mutable tree set&lt;/strong&gt;, as the mutable hash set’s take a mutable hash set; the
&lt;code&gt;keySet()&lt;/code&gt; of a mutable tree map is an immutable &lt;code&gt;TreeSet&lt;/code&gt; snapshot, as a mutable &lt;code&gt;Map&lt;/code&gt;‘s is an
immutable &lt;code&gt;Set&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;tuple-result-override&lt;/code&gt;): &lt;strong&gt;an override’s or an implementation’s result may be
any type seen as the declared result with no conversion&lt;/strong&gt;
(&lt;a href=&quot;/spec/declarations/&quot;&gt;declarations&lt;/a&gt;), the covariant position &lt;a href=&quot;/spec/generics/#variance&quot;&gt;generics&lt;/a&gt;
already names: &lt;code&gt;-&amp;gt; (Dog, Dog)&lt;/code&gt; overrides &lt;code&gt;-&amp;gt; (Animal, Animal)&lt;/code&gt;, &lt;code&gt;-&amp;gt; (HashMap[K, V], HashMap[K, V])&lt;/code&gt;
implements &lt;code&gt;-&amp;gt; (Map[K, V], Map[K, V])&lt;/code&gt;, &lt;code&gt;-&amp;gt; Option[Dog]&lt;/code&gt; overrides &lt;code&gt;-&amp;gt; Option[Animal]&lt;/code&gt;,
&lt;code&gt;-&amp;gt; () -&amp;gt; Dog&lt;/code&gt; overrides &lt;code&gt;-&amp;gt; () -&amp;gt; Animal&lt;/code&gt;, and &lt;code&gt;-&amp;gt; string&lt;/code&gt; overrides &lt;code&gt;-&amp;gt; Any&lt;/code&gt;. A result that
would need a box (&lt;code&gt;-&amp;gt; int&lt;/code&gt; for &lt;code&gt;-&amp;gt; Any&lt;/code&gt;, &lt;code&gt;-&amp;gt; (int, int)&lt;/code&gt; for &lt;code&gt;-&amp;gt; (Any, int)&lt;/code&gt;) or that differs at
an invariant argument (&lt;code&gt;Array[Dog]&lt;/code&gt; for &lt;code&gt;Array[Animal]&lt;/code&gt;) is still refused. Rationale: the chapter
said “for a class, a subclass”, which refused exactly the shapes the variance rules call
subtypes with one representation, so a value returned through the base needs no conversion;
the checker now asks the same no-conversion question an element of a covariant collection does.
Alternatives weighed: keeping results to classes only (tuples and covariant instances then need
a differently named method, as own-kind &lt;code&gt;partition&lt;/code&gt; met); also boxing a scalar result, which
would make an override’s call site convert behind a virtual call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;LazyList[+T]&lt;/code&gt; is a class whose cell is a
private &lt;code&gt;lazy val&lt;/code&gt;&lt;/strong&gt;, and the expression that computes the cell is dropped once it has run. The
cell is &lt;code&gt;Option[(T, LazyList[T])]&lt;/code&gt;; the class holds a function that reads the real expression out
of a captured variable and empties it, so an evaluated cell keeps nothing the expression captured.
WHY: a covariant class may hold no &lt;code&gt;var&lt;/code&gt; of its element type, and a &lt;code&gt;lazy val&lt;/code&gt; is the one immutable
field that is computed once and kept, with its trap on a read during its own evaluation. Keeping
the expression would hold everything it captured for as long as the cell lives (a &lt;code&gt;filter&lt;/code&gt; cell
would hold every source cell it skipped). ALTERNATIVES: an invariant node class with &lt;code&gt;var&lt;/code&gt;s (the
list could then not be covariant); a &lt;code&gt;var&lt;/code&gt; of type &lt;code&gt;Any&lt;/code&gt; cast back on each read (no type checking
of the cell); keeping the expression (simpler, a space leak).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;LazyList.cons(head, tail)&lt;/code&gt; takes the head
strictly and the tail by name, and the tail is evaluated when the list’s second cell is first
read&lt;/strong&gt;, not when the first is: &lt;code&gt;xs.head&lt;/code&gt; never evaluates the tail expression. WHY: the first
cell is then exactly the head, and a function building a list recursively runs one step per cell
read. ALTERNATIVES: a by-name head too (a cell would then be one more function for a value usually
at hand); evaluating the tail with the first cell (one list fewer per cell, but &lt;code&gt;head()&lt;/code&gt; runs the
next step).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;, replaced on
branch &lt;code&gt;lazy-cons-operator&lt;/code&gt;): &lt;code&gt;x +: xs&lt;/code&gt; prepends to a lazy list already made, and &lt;code&gt;LazyList.cons(x, tail)&lt;/code&gt; is the delayed form. The
user then decided (2026-11-11): &lt;em&gt;“yes, a lazy head #:: tail operator would be good to include.”&lt;/em&gt;
The operator is the entry below; &lt;code&gt;+:&lt;/code&gt; stays strict.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;lazy-cons-operator&lt;/code&gt;): &lt;strong&gt;A companion object may declare an operator
ending in &lt;code&gt;:&lt;/code&gt; with its right operand by name, and &lt;code&gt;x op: r&lt;/code&gt; calls it where &lt;code&gt;r&lt;/code&gt;‘s type is the
companion’s type.&lt;/strong&gt; &lt;code&gt;object LazyList&lt;/code&gt; declares &lt;code&gt;#::[T](head: T, tail: -&amp;gt; LazyList[T])&lt;/code&gt;, so
&lt;code&gt;0 #:: 1 #:: fibs.zip(fibs.tail).map((a, b) -&amp;gt; a + b)&lt;/code&gt; evaluates its tail only when the cell
after the head is first read. The right operand’s type decides which &lt;code&gt;op:&lt;/code&gt; is called, and that
type is known only once the operand is checked, so wherever some companion declares &lt;code&gt;op:&lt;/code&gt; this
way, the right operand of every &lt;code&gt;x op: r&lt;/code&gt; is checked as a delayed expression; a type whose &lt;code&gt;op:&lt;/code&gt;
is its own strict method evaluates it once at the call, after &lt;code&gt;x&lt;/code&gt;, as before. A type with its own
&lt;code&gt;op:&lt;/code&gt; whose companion also declares one makes the call an error naming both. Where the call is
expected to give a type whose companion declares the operator, the right operand is checked
against that type (&lt;code&gt;val xs: LazyList[long] = 1 #:: 2 #:: LazyList.empty()&lt;/code&gt; takes &lt;code&gt;long&lt;/code&gt;
literals). WHY: it reuses two rules the language already has, a companion holding what belongs
to a type and by-name parameters with all their restrictions, and adds no declaration syntax;
the operator reads as the list it builds, and nothing changes for operators no companion declares
so (&lt;code&gt;+:&lt;/code&gt;, &lt;code&gt;::&lt;/code&gt;, &lt;code&gt;:+&lt;/code&gt;). ALTERNATIVES: a by-name receiver for a method (&lt;code&gt;self&lt;/code&gt; a delayed
expression: no value to dispatch on, a new declaration form, and every bare member read in the
body would evaluate it again); a &lt;code&gt;lazy&lt;/code&gt; modifier on a method (reads as a memoized result); &lt;code&gt;::&lt;/code&gt;
building a lazy list where one is expected (overloads the language’s own &lt;code&gt;List&lt;/code&gt; operator on the
expected type); a special case for &lt;code&gt;LazyList&lt;/code&gt; in the checker (not available to other types).
&lt;strong&gt;Review with the user&lt;/strong&gt;: the cost of the rule is that a &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; inside
the right operand of &lt;code&gt;#::&lt;/code&gt; is an error on every type, since &lt;code&gt;LazyList&lt;/code&gt; declares &lt;code&gt;#::&lt;/code&gt; for the
whole program.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;lazy-cons-operator&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;#&lt;/code&gt; is an operator character&lt;/strong&gt;, and a leading
&lt;code&gt;#&lt;/code&gt; is passed over when a symbol name’s level is decided: &lt;code&gt;#::&lt;/code&gt; binds as &lt;code&gt;::&lt;/code&gt;, &lt;code&gt;#+&lt;/code&gt; as &lt;code&gt;+&lt;/code&gt;, a name
of &lt;code&gt;#&lt;/code&gt; alone (&lt;code&gt;##&lt;/code&gt;) binds tightest, and a single &lt;code&gt;#&lt;/code&gt; is no operator. WHY: &lt;code&gt;#::&lt;/code&gt; must bind more
loosely than arithmetic (&lt;code&gt;n + 1 #:: rest&lt;/code&gt;), and a &lt;code&gt;#&lt;/code&gt; prefix marks a variant of an operator
without changing how it reads. &lt;code&gt;#&lt;/code&gt; was unused in code before, so no program changes meaning.
ALTERNATIVES: &lt;code&gt;#&lt;/code&gt; at the tightest level as other unclaimed characters are (then &lt;code&gt;n + 1 #:: rest&lt;/code&gt;
would be &lt;code&gt;n + (1 #:: rest)&lt;/code&gt;); &lt;code&gt;#&lt;/code&gt; its own level. This replaces the earlier note that &lt;code&gt;#&lt;/code&gt; is no
operator character, which kept &lt;code&gt;avin.process&lt;/code&gt; from spelling &lt;code&gt;#|&lt;/code&gt;; those combinators keep their
word names.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;lazy-cons-operator&lt;/code&gt;): &lt;strong&gt;There is no &lt;code&gt;head #:: tail&lt;/code&gt; pattern.&lt;/strong&gt; A
pattern names an extractor by a word (&lt;code&gt;Name(p1, p2)&lt;/code&gt;), and the only operator written between a
pattern’s parts is &lt;code&gt;List&lt;/code&gt;‘s &lt;code&gt;::&lt;/code&gt;, so an infix extractor pattern would be a further language change.
A lazy list is taken apart with &lt;code&gt;headOption()&lt;/code&gt; and &lt;code&gt;tail()&lt;/code&gt;. &lt;strong&gt;Review with the user&lt;/strong&gt; if infix
extractor patterns are wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;lazy-cons-operator&lt;/code&gt;): &lt;strong&gt;A lazy list’s cell read while it is being
evaluated traps with &lt;code&gt;a LazyList cell is read while it is being evaluated&lt;/code&gt;&lt;/strong&gt;, checked by a flag
the list’s progress record holds while its cell’s expression runs, rather than the &lt;code&gt;lazy val&lt;/code&gt;‘s
own message, which named the private field &lt;code&gt;cell&lt;/code&gt;. ALTERNATIVES: keeping the &lt;code&gt;lazy val&lt;/code&gt;‘s
message (names an implementation detail).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;LazyList&lt;/code&gt; is an &lt;code&gt;Iterable&lt;/code&gt;, not a &lt;code&gt;Seq&lt;/code&gt;.&lt;/strong&gt; WHY:
a &lt;code&gt;Seq&lt;/code&gt; answers &lt;code&gt;length()&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt; and its hash through &lt;code&gt;length()&lt;/code&gt;, which
never returns on an endless list, and every eager method a &lt;code&gt;Seq&lt;/code&gt; adds would build a &lt;code&gt;Vector&lt;/code&gt; from
it; sequence patterns over it would call &lt;code&gt;length()&lt;/code&gt; too. As an &lt;code&gt;Iterable&lt;/code&gt; it keeps the forcing
methods every collection has, its own lazy forms found first. ALTERNATIVES: a &lt;code&gt;Seq&lt;/code&gt; overriding the
methods that would not return (most of them), or a &lt;code&gt;Seq&lt;/code&gt; whose &lt;code&gt;length()&lt;/code&gt; simply does not return
on an endless list.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;): &lt;strong&gt;A lazy list’s &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; show the
evaluated prefix and &lt;code&gt;…&lt;/code&gt;, evaluating nothing&lt;/strong&gt;: &lt;code&gt;[0, 1, 4]&lt;/code&gt;, &lt;code&gt;[0, 1, …]&lt;/code&gt;, &lt;code&gt;[…]&lt;/code&gt;, with a field
width padding the whole. WHY: displaying an endless list must return, and a display that
evaluated cells would run a program’s functions while printing. ALTERNATIVES: forcing every cell
(does not return on an endless list); a fixed prefix forced (side effects while printing);
&lt;code&gt;&amp;lt;not computed&amp;gt;&lt;/code&gt; text (longer, and not a form the other collections use). No &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt; or
&lt;code&gt;Ord&lt;/code&gt;, which could not answer for two equal endless lists.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;): &lt;strong&gt;A lazy list is not sendable&lt;/strong&gt;, so each belongs to
the thread that made it; the cells’ &lt;code&gt;lazy val&lt;/code&gt; evaluation would be safe between threads, but the
expressions not yet evaluated are functions that may capture anything. ALTERNATIVES: sendable when
every expression is a &lt;code&gt;@sendable&lt;/code&gt; function (every lazy method would need a sendable form).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-lazy-list&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;zip&lt;/code&gt; takes another &lt;code&gt;LazyList&lt;/code&gt;&lt;/strong&gt; and stays lazy;
&lt;strong&gt;&lt;code&gt;flatMap&lt;/code&gt; takes &lt;code&gt;(T) -&amp;gt; Iterable[U]&lt;/code&gt;&lt;/strong&gt;, reading each collection through its iterator as cells are
read; &lt;strong&gt;&lt;code&gt;++&lt;/code&gt; takes its right operand by name&lt;/strong&gt;, evaluated only when the cell after the left’s last
is read (the iterator’s &lt;code&gt;++&lt;/code&gt; takes a strict &lt;code&gt;Iterable&lt;/code&gt;, since an iterator is read once anyway);
&lt;code&gt;toLazyList()&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt; converts, since &lt;code&gt;from&lt;/code&gt; is the integer counter’s name as on
&lt;code&gt;Iterator&lt;/code&gt;. Also added beyond the item: &lt;code&gt;filterNot&lt;/code&gt;, &lt;code&gt;zipWithIndex&lt;/code&gt;, &lt;code&gt;fill&lt;/code&gt;, &lt;code&gt;tabulate&lt;/code&gt;, &lt;code&gt;lift&lt;/code&gt;,
&lt;code&gt;force()&lt;/code&gt; and &lt;code&gt;isEvaluated()&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-map-extras&lt;/code&gt;): &lt;strong&gt;Map defaults, own-kind &lt;code&gt;partition&lt;/code&gt; and &lt;code&gt;Set.subsets&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;stdlib-map-extras&lt;/code&gt;).
Proposed: &lt;code&gt;withDefault(f)&lt;/code&gt; and &lt;code&gt;withDefaultValue(v)&lt;/code&gt; on every map answer a &lt;code&gt;DefaultMap&lt;/code&gt;, a
wrapper whose &lt;code&gt;apply&lt;/code&gt; of an absent key answers the default and whose every other read (&lt;code&gt;get&lt;/code&gt;,
&lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;getOrElse&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt;, iteration, &lt;code&gt;keySet&lt;/code&gt;) sees only the real entries; the default is
never stored. &lt;code&gt;updated&lt;/code&gt;, &lt;code&gt;removed&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;--&lt;/code&gt;, &lt;code&gt;updatedWith&lt;/code&gt; and &lt;code&gt;filter&lt;/code&gt; keep the wrapper and
its default; &lt;code&gt;transform&lt;/code&gt; and &lt;code&gt;mapValues&lt;/code&gt; answer the wrapped map’s own kind, because a default
of the old value type cannot be carried across the function. The wrapper equals, and hashes as,
the map it wraps and every map of the same entries, ignoring the default. A default of a
supertype widens the map, as &lt;code&gt;updated&lt;/code&gt; does. Why: &lt;code&gt;get&lt;/code&gt; answering &lt;code&gt;Option&lt;/code&gt; is how a program
asks whether a key is there, and a counter wants &lt;code&gt;apply&lt;/code&gt; alone to be total. Alternatives
weighed: &lt;code&gt;get&lt;/code&gt; also answering the default (hides absence, makes &lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;get&lt;/code&gt;
disagree); the default taking part in equality (two maps of the same entries would differ by a
closure that cannot be compared); the wrapper mapping its default through &lt;code&gt;mapValues&lt;/code&gt;
(needs the value function to be applied to a default on every miss, a surprise at each read).
&lt;code&gt;partition&lt;/code&gt; of a hash, tree or ordered map and of a hash, tree, ordered or bit set is a method
of the concrete type answering that type, &lt;code&gt;p&lt;/code&gt; called once per element; it is not on &lt;code&gt;Map&lt;/code&gt;,
&lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;SortedMap&lt;/code&gt;, &lt;code&gt;SeqMap&lt;/code&gt;, &lt;code&gt;SortedSet&lt;/code&gt; or &lt;code&gt;SeqSet&lt;/code&gt;, so through a trait a set’s partition is
&lt;code&gt;Iterable&lt;/code&gt;‘s and answers vectors, as the settled &lt;code&gt;Iterable&lt;/code&gt; decision says, and a map’s
&lt;code&gt;partition&lt;/code&gt; of a pair function answers the own kind only where the type is known. Why: a
tuple of two collections is not a subtype of a tuple of two supertypes in an override’s
result, and a set’s partition over the trait cannot change &lt;code&gt;Iterable&lt;/code&gt;‘s result type.
Amended on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;partition-override&lt;/code&gt;): with an override’s result free to
narrow, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;SortedMap&lt;/code&gt; and &lt;code&gt;SeqMap&lt;/code&gt; declare &lt;code&gt;partition(p: (K, V) -&amp;gt; bool)&lt;/code&gt; answering maps
of their own trait (&lt;code&gt;Map&lt;/code&gt; carries a default built on &lt;code&gt;removed&lt;/code&gt;, so a user class implementing
&lt;code&gt;Map&lt;/code&gt; needs no change), and each concrete map overrides it with its own kind, so a call through
&lt;code&gt;Map&lt;/code&gt; answers maps of the receiver’s kind. Sets keep &lt;code&gt;Iterable&lt;/code&gt;‘s &lt;code&gt;(Vector, Vector)&lt;/code&gt; through
&lt;code&gt;Set&lt;/code&gt;, since a set is not a vector and &lt;code&gt;Set&lt;/code&gt; cannot narrow it; the own-kind set &lt;code&gt;partition&lt;/code&gt;
stays on the concrete types. Alternatives weighed: a &lt;code&gt;Set.partition&lt;/code&gt; answering &lt;code&gt;(Set, Set)&lt;/code&gt;
(conflicts with &lt;code&gt;Iterable&lt;/code&gt;‘s result, which is not a supertype of it). Alternatives weighed
originally: trait methods answering &lt;code&gt;(Map, Map)&lt;/code&gt; (the concrete type then could not
narrow the result); two &lt;code&gt;filter&lt;/code&gt; calls (calls &lt;code&gt;p&lt;/code&gt; twice, which a predicate with an effect
shows). &lt;code&gt;subsets()&lt;/code&gt; and &lt;code&gt;subsets(k)&lt;/code&gt; are iterators on &lt;code&gt;Set&lt;/code&gt; that read the elements into a
vector and generate combinations by size, so the order is by size then by position and nothing
is made ahead; every subset is a set of the receiver’s kind. Why by size: the empty set first
and the set last, the same order for every kind, and no &lt;code&gt;2^n&lt;/code&gt; counter to overflow for a set of
more than 62 elements. Alternatives weighed: bitmask order (overflows past 62 elements, and
puts the subsets in an order a reader cannot predict from the sizes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;stdlib-from&lt;/code&gt;): &lt;strong&gt;Companion &lt;code&gt;from&lt;/code&gt;, &lt;code&gt;Vector.iterate&lt;/code&gt;, &lt;code&gt;unfold&lt;/code&gt; and the sorted conversions&lt;/strong&gt; (branch
&lt;code&gt;stdlib-from&lt;/code&gt;). Proposed: &lt;code&gt;from(xs: Iterable[T])&lt;/code&gt; on every immutable collection companion and
on the mutable ones (&lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;TreeMap&lt;/code&gt;, &lt;code&gt;TreeSet&lt;/code&gt;, &lt;code&gt;LinkedMap&lt;/code&gt;, &lt;code&gt;LinkedSet&lt;/code&gt;,
&lt;code&gt;BitSet&lt;/code&gt;, &lt;code&gt;PriorityQueue&lt;/code&gt;), a map’s taking &lt;code&gt;Iterable[(K, V)]&lt;/code&gt;; for a duplicate key the later
pair’s value wins (an ordered map keeping the key’s first place), the rule &lt;code&gt;apply&lt;/code&gt; and the
builders already follow. &lt;code&gt;Vector.iterate(start, length, f)&lt;/code&gt; takes the length as its second
parameter and calls &lt;code&gt;f&lt;/code&gt; &lt;code&gt;length - 1&lt;/code&gt; times; &lt;code&gt;Vector.unfold&lt;/code&gt; and &lt;code&gt;List.unfold&lt;/code&gt; are the eager forms
of &lt;code&gt;Iterator.unfold&lt;/code&gt;. &lt;code&gt;toSortedSet()&lt;/code&gt; and &lt;code&gt;toSortedMap()&lt;/code&gt; are &lt;code&gt;impl&lt;/code&gt; blocks on &lt;code&gt;Iterable&lt;/code&gt; bounded
by &lt;code&gt;Ord&lt;/code&gt;, like &lt;code&gt;toSet()&lt;/code&gt; and &lt;code&gt;toMap()&lt;/code&gt;. Why: one spelling that works for every source and target,
where the collection-specific conversions need a method per pair. Alternatives weighed: a
&lt;code&gt;to(factory)&lt;/code&gt; conversion (needs higher-kinded types); a universal &lt;code&gt;into(builder)&lt;/code&gt; (not added:
&lt;code&gt;builder.addAll(xs)&lt;/code&gt; already reads as well, and &lt;code&gt;from&lt;/code&gt; covers the target-first reading);
&lt;code&gt;List.iterate&lt;/code&gt;/&lt;code&gt;ArraySeq.iterate&lt;/code&gt; (not added; &lt;code&gt;Vector.iterate(...).toList&lt;/code&gt; is one call);
&lt;code&gt;Array.from&lt;/code&gt; (left out as arrays are not in the item). &lt;code&gt;Iterator.from(start)&lt;/code&gt; is the unrelated
counting iterator and keeps its name.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;union-tag-payload&lt;/code&gt;): &lt;strong&gt;The words of a union with a scalar member, and
where they live&lt;/strong&gt; (the second part of Settled → unions → Representation, built on the multi-word
values above).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Three words&lt;/strong&gt;: a 32-bit tag, 64 bits for a scalar member and, where a member is a reference, the
reference. Tag 0 says the union holds a reference, whose header names its type; tag &lt;code&gt;i + 1&lt;/code&gt; says
it holds scalar member &lt;code&gt;i&lt;/code&gt;, the scalar members ordered by their type keys, so the order written
never changes the layout. A scalar is kept in the bits as its value: an integer sign-extended, a
&lt;code&gt;byte&lt;/code&gt; and a &lt;code&gt;char&lt;/code&gt; zero-extended, a &lt;code&gt;bool&lt;/code&gt; as 0 or 1, a &lt;code&gt;real&lt;/code&gt;‘s bits unchanged (so a NaN’s
payload and a zero’s sign survive), &lt;code&gt;unit&lt;/code&gt; as nothing. A union of scalars alone has two words.
&lt;em&gt;Why&lt;/em&gt;: the reference word is the only one the frame plan can root, and a separate 64-bit word
holds every scalar unchanged. &lt;em&gt;Alternatives&lt;/em&gt;: one word for the tag and the bits together (a
&lt;code&gt;long&lt;/code&gt; member needs all 64 bits); a word per scalar member (more words for nothing); numbering by
the order written (&lt;code&gt;int | string&lt;/code&gt; and &lt;code&gt;string | int&lt;/code&gt; would differ).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In lowering, the union is a reference to its cell&lt;/strong&gt;, an object of those words that is made once
and only read; a function takes and gives each union as its words (&lt;code&gt;MCell&lt;/code&gt; in a signature,
replaced by the words before anything else reads the program), and makes a cell of the words it
receives. So scalar replacement keeps every cell of a local, a parameter or a result as its
fields in slots, and none of them allocates; a call in tail position passes its callee’s words
straight on. &lt;em&gt;Why&lt;/em&gt;: every operation on a union (injection, a &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt;, the hash,
rendering) is written once, on the cell, and the existing scalar replacement makes it words
everywhere a value stays in its function. &lt;em&gt;Alternatives&lt;/em&gt;: lowering carrying several operands for
one value through every expression form (a much larger change to every join, local and call
path, for the same code after scalar replacement).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Where a union is stored&lt;/strong&gt; (a field, an element, a capture, a module-level value, a generic
type’s storage at a union argument), &lt;strong&gt;its cell stays an object&lt;/strong&gt;, traced through its reference
word, until those places lay a union out as its words too: storing a union allocates its cell as
boxing a scalar did, a string member included. &lt;em&gt;Why&lt;/em&gt;: one representation per type everywhere, so
generic code at a union type argument needs no conversion where it meets its storage.
&lt;em&gt;Alternatives&lt;/em&gt;: converting to an &lt;code&gt;Any&lt;/code&gt; at every such boundary (a box only for a scalar member, but
a conversion at every generic call and field access, each a place to get wrong). Superseded by
the next entry (branch &lt;code&gt;union-words-storage&lt;/code&gt;): storage now holds the words.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Converting to an &lt;code&gt;Any&lt;/code&gt; or a trait&lt;/strong&gt; boxes a scalar member there and passes a reference member
as it is; &lt;strong&gt;a member call&lt;/strong&gt; through a trait every member has converts the union the same way,
except &lt;code&gt;display&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt; and &lt;code&gt;toString&lt;/code&gt;, which call the member’s own implementation by the tag
with no box. &lt;code&gt;===&lt;/code&gt; with an object compares the union as an &lt;code&gt;Any&lt;/code&gt;, so a scalar member, a new box,
is never identical to it. &lt;strong&gt;&lt;code&gt;==&lt;/code&gt; and the hash&lt;/strong&gt; are decided by the tag: two values of one member
compare and hash as that member, and a reference as an &lt;code&gt;Any&lt;/code&gt;, so a union and the same value as an
&lt;code&gt;Any&lt;/code&gt; are equal and hash alike. Review with the user: storing a union with a string member now
allocates its cell where an &lt;code&gt;Any&lt;/code&gt; did not, until fields and collections take the words.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;union-tag-payload&lt;/code&gt;): &lt;strong&gt;Tuple type patterns by their parts’ layouts.&lt;/strong&gt;
&lt;code&gt;Any&lt;/code&gt; are equal and hash alike. (The review flag this entry carried, a stored union with a string
member allocating its cell, is closed by the next entry.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;union-words-storage&lt;/code&gt;): &lt;strong&gt;A union with a scalar member is stored as its
words&lt;/strong&gt; (the storage half of the entry above).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every storage place holds the words&lt;/strong&gt;: a field of a data value, a class or a tuple, an array
element (so a &lt;code&gt;Vector&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt; and a map), a closure’s capture, a captured &lt;code&gt;var&lt;/code&gt;‘s box and a
module-level value lay the union out as its tag (in an 8-byte slot), its bits and, with a
reference member, its reference, 24 bytes or 16, and only the reference word is traced (a
descriptor’s reference offsets, an array’s element map). Storing reads the words out of the
value’s cell; loading makes a cell of the words read, which scalar replacement removes, so storing
and reading allocate nothing for any member. &lt;em&gt;Why&lt;/em&gt;: it removes the allocation the entry above
flagged, and every place reuses one pair of helpers. &lt;em&gt;Alternatives&lt;/em&gt;: the cell kept as an object
in storage (an allocation per store, a string member included); converting to an &lt;code&gt;Any&lt;/code&gt; there (a
box for each scalar member, and type tests on read).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generic code at a union type argument stores the words in each instance&lt;/strong&gt; (&lt;code&gt;Vector[int | string]&lt;/code&gt; holds 24-byte elements), never boxing at a generic boundary. &lt;em&gt;Why&lt;/em&gt;: generic code is
compiled per instance already, so the instance’s storage is the union’s own; nothing converts at
a call. &lt;em&gt;Alternatives&lt;/em&gt;: boxing a union to an &lt;code&gt;Any&lt;/code&gt; where it enters generic code (an allocation
per element and a type test per read, for no gain).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A module-level union keeps its tag and bits in its own 16 bytes and its reference word in a
module-level reference of its own&lt;/strong&gt;, named &lt;code&gt;&amp;lt;value&amp;gt;#reference&lt;/code&gt;, after every value and &lt;code&gt;lazy val&lt;/code&gt;
state word. &lt;em&gt;Why&lt;/em&gt;: the program’s roots are a frame of references, so the reference word has to be
one of them; the rest is plain data. &lt;em&gt;Alternatives&lt;/em&gt;: the cell kept on the heap for module-level
values (an allocation per assignment of a &lt;code&gt;var&lt;/code&gt;); teaching the root frame a word map (a runtime
change for one case).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Atomic&lt;/code&gt; keeps a reference to a cell&lt;/strong&gt;: its value is one word that &lt;code&gt;load&lt;/code&gt;, &lt;code&gt;store&lt;/code&gt;, &lt;code&gt;swap&lt;/code&gt; and
the hardware compare-and-set access indivisibly, so an &lt;code&gt;Atomic[int | string]&lt;/code&gt; allocates the cell
on each store. &lt;em&gt;Why&lt;/em&gt;: three words cannot be swapped atomically without a lock. &lt;em&gt;Alternatives&lt;/em&gt;:
a lock for &lt;code&gt;Atomic&lt;/code&gt;s of unions (as for integers wider than 64 bits; slower for every operation).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A load from storage reads a tag of 0 (a reference) only beside a non-null reference word, and
any other zero tag as the first scalar member’s.&lt;/strong&gt; A racing read may combine a tag and a reference
from two writes, as it may an &lt;code&gt;i128&lt;/code&gt;‘s words, and an array element not yet filled is all zero;
either way the value read is one of a member, never a null taken for a reference. &lt;em&gt;Why&lt;/em&gt;: the
promise that a race never breaks memory safety; it costs two compares and two selects per load.
&lt;em&gt;Alternatives&lt;/em&gt;: no check (a racing read could dereference null); a lock per union field (a cost
on every access for a race the program should not have). Review with the user: a racing read of a
union may now combine two writes, an exception the threads chapter states beside wide integers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An integer member wider than 64 bits is kept boxed in the reference word under tag 0&lt;/strong&gt;, its
type told by its box’s record, so &lt;code&gt;i128 | int&lt;/code&gt; has a reference word and injecting an &lt;code&gt;i128&lt;/code&gt;
allocates its box. This fixes the layout above, which kept such a member in the 64 bits and lost
its high bits. &lt;em&gt;Why&lt;/em&gt;: the bits slot stays 64 bits for every union, and a wide integer, rare in a
union, costs a box as it does in an &lt;code&gt;Any&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: a bits slot as wide as the widest
member (a layout per union type, and every helper and the call words taking a width); refusing
integers wider than 64 bits as members (a gap in the language).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A tuple with a union part is not answered as words&lt;/strong&gt; by &lt;code&gt;val (a, b) = f(x)&lt;/code&gt;: the call makes the
tuple, and the parts are read from it. &lt;em&gt;Why&lt;/em&gt;: a result’s words do not nest a union’s words yet.
&lt;em&gt;Alternatives&lt;/em&gt;: flattening the union’s words into the result’s (a later optimization).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;union-tag-payload&lt;/code&gt;): &lt;strong&gt;Tuple type patterns by their parts’ layouts.&lt;/strong&gt;
A tuple type pattern matches a tuple whose type as made is seen as the target with no conversion,
part by part: a part that is an object (a string, a tuple, a data value, an object of a class, a
function, or a union of references) is seen as an &lt;code&gt;Any&lt;/code&gt; part, so a &lt;code&gt;(string, string)&lt;/code&gt; and a
&lt;code&gt;(Dog, string)&lt;/code&gt; are &lt;code&gt;(Any, string)&lt;/code&gt;s; a scalar part, or a union with a scalar member, is only that
very part, so an &lt;code&gt;(int, string)&lt;/code&gt; is no &lt;code&gt;(Any, string)&lt;/code&gt; and an &lt;code&gt;(int, bool)&lt;/code&gt; no
&lt;code&gt;(int | string, bool)&lt;/code&gt;; a part naming a &lt;strong&gt;union of references&lt;/strong&gt; takes any object there and then
tests that object’s own type against the members, so &lt;code&gt;(Dog | Cat, int)&lt;/code&gt; matches a tuple made as
&lt;code&gt;(Dog, int)&lt;/code&gt;, as &lt;code&gt;(Dog | Cat, int)&lt;/code&gt; or as &lt;code&gt;(Any, int)&lt;/code&gt; holding a &lt;code&gt;Cat&lt;/code&gt;, and not one holding a &lt;code&gt;Bird&lt;/code&gt;
or a boxed number. A pattern on a tuple of known type that could never match by this rule is the
error any such pattern is (&lt;code&gt;a value of type (int, bool) is never a (int | string, bool), so this type pattern never matches&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: the chapter’s rule that a tuple converts only where each part
keeps its layout decides which tuples a pattern can take as its type; a union of references is
laid out as an &lt;code&gt;Any&lt;/code&gt;, so a tuple made with one records an &lt;code&gt;Any&lt;/code&gt; there and only the object can say
which member it is. &lt;em&gt;Alternatives&lt;/em&gt;: matching only a tuple made with exactly the pattern’s type
(what was built: &lt;code&gt;(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;)&lt;/code&gt; was no &lt;code&gt;(Any, string)&lt;/code&gt;); testing every part by the value it holds
(rebuilding the tuple at the pattern’s layout where a scalar part would need a box, an allocation
hidden in a &lt;code&gt;match&lt;/code&gt;). Review with the user: a union-of-references part tests the object, while a
class part tests the type the tuple was made with.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;incremental-default&lt;/code&gt;): &lt;strong&gt;The instance cache is on by default&lt;/strong&gt; for
every command that builds: &lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;emit-llvm&lt;/code&gt;. &lt;code&gt;AVIN_INCREMENTAL=off&lt;/code&gt;
turns it off, &lt;code&gt;verify&lt;/code&gt; stays, and &lt;code&gt;on&lt;/code&gt;, unset or empty are the default; any other value is an
error for the commands that build, while &lt;code&gt;avin check&lt;/code&gt; (even with &lt;code&gt;--bindings&lt;/code&gt;) neither reads the
variable nor keeps a cache. The language server only checks, so it has no build to cache. WHY: the
whole corpus built warm under &lt;code&gt;verify&lt;/code&gt; matched its clean builds, the commands’ tests hold every
command to a clean build after an edit, and the cache needs no care (another compiler’s entries
are misses and trimmed after an hour; damage is a miss). Alternatives: on for &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt;
only, &lt;code&gt;build&lt;/code&gt; staying clean for release builds (a release build has the same oracle and gains as
much); an &lt;code&gt;--incremental&lt;/code&gt; flag rather than a variable (a flag every command would carry for a
setting nobody changes per build). Review with the user: the disk it takes, about the size of the
program’s text per kind and level (185 MB for marshal at &lt;code&gt;-O2&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;incremental-default&lt;/code&gt;): &lt;strong&gt;A program of one file names its cache
directories after itself&lt;/strong&gt;, &lt;code&gt;.avin/build/incremental/&amp;lt;stem&amp;gt;-&amp;lt;kind&amp;gt;&amp;lt;level&amp;gt;&lt;/code&gt;, while a directory
or package keeps &lt;code&gt;&amp;lt;kind&amp;gt;&amp;lt;level&amp;gt;&lt;/code&gt;. WHY: every file of a directory shares that directory’s
&lt;code&gt;.avin/build&lt;/code&gt;, as their executables already do (named by stem); with one directory per kind and
level, two programs built in turn would overwrite each other’s manifest and an hour later trim each
other’s entries. The suffix is one of four fixed words, so no stem makes two programs’ names meet.
Alternatives: a subdirectory per file (&lt;code&gt;incremental/&amp;lt;stem&amp;gt;/program-O2&lt;/code&gt;, which a file named
&lt;code&gt;tests-O0.avin&lt;/code&gt; would make collide with a directory program’s); one shared directory (correct,
since entries are content-addressed, but each program would lose its reuse in turn).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;incremental-default&lt;/code&gt;): &lt;strong&gt;A manifest names only module files of its own
directory&lt;/strong&gt;: a name that is not hexadecimal digits and &lt;code&gt;.mod&lt;/code&gt; is passed over as damaged and never
read. WHY: a damaged manifest could otherwise send the reader to &lt;code&gt;../&lt;/code&gt; paths outside the cache;
nothing a build writes has another form. Alternatives: trusting the manifest (only the checksum
would stand between a stray path and its contents being read as entries).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;incremental-default&lt;/code&gt;): &lt;strong&gt;Code that calls the C unit’s glue is never
taken from the cache’s lowered entries, and the glue it calls is part of its text’s key&lt;/strong&gt;; a C
callback’s body is keyed by its binding and its trampoline’s name. The warm corpus run found three
stale texts: the glue (&lt;code&gt;avin_c_call_&amp;lt;n&amp;gt;&lt;/code&gt;, &lt;code&gt;avin_c_field_get_&amp;lt;n&amp;gt;&lt;/code&gt;, &lt;code&gt;avin_c_retain_&amp;lt;n&amp;gt;&lt;/code&gt; and the
rest) is named by the checker’s indices, which a declaration added earlier renumbers, and no key
held those numbers; and every callback body had one key, so one binding’s callback took
another’s text. WHY: the functions that call glue directly are the bindings’ own bodies, fields
and handles, which are small and already mostly lowered every build, and covering the names in
the text key also covers the copies inlining makes of them. Alternatives: name the glue by what it
glues, as the stable names do for everything else (the right end state, but it changes the C unit
and every place lowering calls into it); a digest of every C declaration’s number in every key
(a declaration added anywhere would re-lower a C program whole). Review with the user: stable C
glue names would let these functions be reused too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;incremental-default&lt;/code&gt;): &lt;strong&gt;The warm corpus run is chosen by
&lt;code&gt;AVIN_INCREMENTAL=verify&lt;/code&gt; in the environment of &lt;code&gt;sysl test compiler&lt;/code&gt;&lt;/strong&gt;: each corpus program is
built cold with an empty cache, edited by adding a function nothing calls at the end of its first
non-literate file, and built again from the cache in &lt;code&gt;verify&lt;/code&gt; mode, which also builds it clean; the
warm build is the one run. Unset, the gate builds each program once with no cache. WHY: the warm run
builds every program three times, so it belongs before a release or after a change to the cache,
not in every gate; the edit changes the source and the executable’s key but no line any program
prints or traps at, so the corpus’s expectations still hold. Alternatives: the warm run in every
gate (triples the corpus’s compile time); an edit inside a function (moves trap lines the &lt;code&gt;.err&lt;/code&gt;
files record, or changes what a program does).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-11 (built on branch &lt;code&gt;site-prime-sieve&lt;/code&gt;): &lt;strong&gt;A program the website shows is run-checked from
the page itself.&lt;/strong&gt; In &lt;code&gt;docs/content/**/*.md&lt;/code&gt;, a fence whose info string carries the word &lt;code&gt;run&lt;/code&gt;
after its language (&lt;code&gt;```text run&lt;/code&gt;) holds a complete program, and the next fence, carrying
&lt;code&gt;output&lt;/code&gt; (&lt;code&gt;```text output&lt;/code&gt;), holds exactly what it prints, with prose allowed between
them. The corpus test builds every marked program at &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt;, runs it as an example is run,
and fails naming the page and line when it does not compile, ends other than with exit 0, or prints
anything but its output fence; a &lt;code&gt;run&lt;/code&gt; fence with no &lt;code&gt;output&lt;/code&gt; fence after it, an &lt;code&gt;output&lt;/code&gt; fence with
no &lt;code&gt;run&lt;/code&gt; fence and a marked fence never closed fail the same way. Unmarked fences stay
illustrations. WHY: the page is the one copy of the program, so what the reader sees is exactly
what was built; the words after the language leave the rendered page as it was (the site renders
the fence by its language alone); the run reuses the examples’ check, so a shown program meets the
same standard as &lt;code&gt;examples/&lt;/code&gt;. ALTERNATIVES: keep each program as a file under &lt;code&gt;examples/&lt;/code&gt; and
check that the page’s fence is byte-identical to it (two copies to edit, and the output on the
page would need a third check against the &lt;code&gt;.out&lt;/code&gt; file); an HTML comment before the fence as the
marker (invisible in the page but present in its source, and a second line to keep beside the
fence); a literate &lt;code&gt;.lavin&lt;/code&gt; page (the site renders indented code differently from fences).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;): &lt;strong&gt;a method declared with
no parameter list is called with no parentheses.&lt;/strong&gt; &lt;code&gt;head -&amp;gt; T = …&lt;/code&gt; in a class, trait, object or
impl is called as &lt;code&gt;xs.head&lt;/code&gt;; a method declared with &lt;code&gt;()&lt;/code&gt; keeps them at the call, &lt;code&gt;buf.clear()&lt;/code&gt;,
&lt;code&gt;iter.next()&lt;/code&gt;. &lt;code&gt;account.deposit&lt;/code&gt; stays a method value, bound to its receiver, for a method with a
parameter list. A parameterless method has no method value: the function that reads one is the
lambda &lt;code&gt;() -&amp;gt; xs.head&lt;/code&gt;, and there is no &lt;code&gt;m _&lt;/code&gt; form. REJECTED: omitting &lt;code&gt;()&lt;/code&gt; at the call of any
method of no parameters, since &lt;code&gt;x.m&lt;/code&gt; would then be both a call and a method value, and the
parentheses that mark a call with an effect would be gone.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;): &lt;strong&gt;parentheses after a parameterless method
call what it yields.&lt;/strong&gt; &lt;code&gt;t.adder(4)&lt;/code&gt;, where &lt;code&gt;adder -&amp;gt; (int) -&amp;gt; int&lt;/code&gt;, calls the function &lt;code&gt;adder&lt;/code&gt;
yields, and &lt;code&gt;t.items(2)&lt;/code&gt; indexes the sequence &lt;code&gt;items&lt;/code&gt; yields; &lt;code&gt;c.head&lt;/code&gt;, where &lt;code&gt;head&lt;/code&gt; yields
neither (or a sequence given no index), is an error naming the fix, “&lt;code&gt;head&lt;/code&gt; takes no parameter
list, so it is called without parentheses: write &lt;code&gt;head&lt;/code&gt;, not &lt;code&gt;head()&lt;/code&gt;“. The same holds inside the
class by bare name and through &lt;code&gt;super&lt;/code&gt;. WHY: &lt;code&gt;x.m(a)&lt;/code&gt; must mean one thing, and the declaration says
&lt;code&gt;m&lt;/code&gt; takes no arguments, so the only call the parentheses can make is of the result; reporting
&lt;code&gt;x.head&lt;/code&gt; instead of reading it as a call keeps the rule visible at every wrong use. ALTERNATIVES:
accepting &lt;code&gt;x.head&lt;/code&gt; as a synonym of &lt;code&gt;x.head&lt;/code&gt; (two spellings of one call, and it hides a callable
result’s call); refusing parentheses after a parameterless method altogether (then &lt;code&gt;t.adder(4)&lt;/code&gt;
would need &lt;code&gt;(t.adder)(4)&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;): &lt;strong&gt;the parameter-list shape is part of a
signature.&lt;/strong&gt; Overriding or implementing a parameterless method with a &lt;code&gt;()&lt;/code&gt; one, or the reverse, is
an error naming the shape to write; it applies to class overrides, trait implementations in
classes and in a data type’s impls. WHY: a call site written against the trait must be valid
against every implementation. ALTERNATIVE: letting the override’s shape win (a call through the
trait and through the class would be written differently).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;): &lt;strong&gt;a public field implements an abstract
parameterless method.&lt;/strong&gt; A trait’s or an abstract class’s &lt;code&gt;size -&amp;gt; int&lt;/code&gt; with no body is implemented
by a method, or by a public &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; field of the name (a &lt;code&gt;val&lt;/code&gt; class parameter included),
or for a data type by a field of its one variant; the field’s type must be the method’s result. A
private field does not, and is named in the error; a field still cannot share its name with a
method that has a body (a default is not replaced by a field). The converse is unchanged: a
trait’s abstract &lt;code&gt;val&lt;/code&gt; is supplied only by a field. WHY: a parameterless method reads like a field
at every call, so a class whose answer is stored should be able to store it; only an abstract one
is implemented this way, so a default body is never silently replaced. ALTERNATIVES: methods only
(a stored answer needs a method that returns the field); letting a field replace a default too
(a field would override silently, without &lt;code&gt;override&lt;/code&gt;). Reviewed with the user 2026-11-12 and kept: &lt;code&gt;var&lt;/code&gt; fields are
accepted, so a parameterless method may yield a different value at each read through the field.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;), then
revised by the user the same day (next entry): &lt;strong&gt;only members are declared without a
parameter list.&lt;/strong&gt; A top-level function or a local function declared &lt;code&gt;name -&amp;gt; T = …&lt;/code&gt; is an error
naming &lt;code&gt;name() -&amp;gt; …&lt;/code&gt; and &lt;code&gt;val name = …&lt;/code&gt;. WHY: the smallest choice; a module value computed once is
already a &lt;code&gt;val&lt;/code&gt;, and the call-without-parentheses reading is what a member of a value needs.
ALTERNATIVES: top-level parameterless functions called by bare name, recomputed at each read (a
second kind of module-level name that reads like a &lt;code&gt;val&lt;/code&gt; and is not one). Review with the user if
module-level computed names are wanted. It was reviewed: the user chose the alternative, written
with &lt;code&gt;def&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-12 (built on branch &lt;code&gt;def&lt;/code&gt;): &lt;strong&gt;optional &lt;code&gt;def&lt;/code&gt;; &lt;code&gt;def&lt;/code&gt; permits a
parameterless top-level/local function.&lt;/strong&gt; &lt;code&gt;def&lt;/code&gt; may begin any function or method declaration,
members of a class, trait, object or impl, statics, top-level and local functions, with or without
a parameter list and on functions defined by clauses, and means nothing more there: &lt;code&gt;def f(x: int) -&amp;gt; int = …&lt;/code&gt; is &lt;code&gt;f(x: int) -&amp;gt; int = …&lt;/code&gt;. At the top level and in a block, &lt;code&gt;def now -&amp;gt; int = …&lt;/code&gt;
declares a function with no parameter list, by the rules of a parameterless method: read by its
bare name and run again at every read, parentheses after it calling what it yields (a function or
a sequence given an index, and otherwise an error naming &lt;code&gt;now&lt;/code&gt;), no function value (the lambda
&lt;code&gt;() -&amp;gt; now&lt;/code&gt;, named by the error where a function is wanted), no type parameters of its own, never
assigned, the only function of its name in its scope and sharing that scope’s namespace with
values. Written without &lt;code&gt;def&lt;/code&gt; there, &lt;code&gt;now -&amp;gt; int = …&lt;/code&gt; is an error naming &lt;code&gt;def now -&amp;gt; …&lt;/code&gt; first,
then &lt;code&gt;val now = …&lt;/code&gt; and &lt;code&gt;now() -&amp;gt; …&lt;/code&gt;. &lt;code&gt;def&lt;/code&gt; is a keyword. Style: &lt;code&gt;def&lt;/code&gt; is written only where it is
required; the library and tests use it nowhere else, apart from the tests of the optional form.
Also built on branch &lt;code&gt;def&lt;/code&gt;: a method of a data type’s or a built-in type’s impl defined by clauses
matches its arguments and not its receiver, as a class’s method’s clauses already did (they were
refused for counting the receiver as an argument).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;): &lt;strong&gt;a parameterless method is the only method
of its name&lt;/strong&gt; in its type, inherited ones and the methods impls add included; and &lt;strong&gt;it takes no
type parameters of its own&lt;/strong&gt;, a parse error, since &lt;code&gt;x.first[int]&lt;/code&gt; would read as indexing its
result (its class’s type parameters it has). WHY: &lt;code&gt;x.head&lt;/code&gt; calls the parameterless one, which
leaves no call to choose another overload with. ALTERNATIVES: overloading resolved by whether
parentheses follow (two methods behind one name with different call shapes); type parameters
written &lt;code&gt;x.first[int]&lt;/code&gt; (indexing and type application become ambiguous after a member).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-methods&lt;/code&gt;): &lt;strong&gt;naming a parameterless method where a
function type is expected is an error naming the lambda&lt;/strong&gt;, “&lt;code&gt;head&lt;/code&gt; takes no parameter list, so it
has no function value: naming it calls it; for a function, write a lambda, as in &lt;code&gt;() -&amp;gt; x.head&lt;/code&gt;“,
unless the method yields a function, which is then the value. &lt;code&gt;super.name&lt;/code&gt; with no call reads a
superclass’s parameterless method and is refused for one with a parameter list. WHY: the plain
type mismatch (“expected () -&amp;gt; int, found int”) hides that the user meant a method value.
ALTERNATIVE: the generic type-mismatch error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-collections&lt;/code&gt;): &lt;strong&gt;the collections’ pure accessors are
parameterless methods&lt;/strong&gt;, on &lt;code&gt;Iterable&lt;/code&gt;, &lt;code&gt;Iterator&lt;/code&gt;, &lt;code&gt;Seq&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, every immutable and mutable
collection, &lt;code&gt;Builder&lt;/code&gt; and their impls: &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;,
&lt;code&gt;size&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, &lt;code&gt;minOption&lt;/code&gt;, &lt;code&gt;maxOption&lt;/code&gt;,
&lt;code&gt;sum&lt;/code&gt;, &lt;code&gt;product&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;, &lt;code&gt;distinct&lt;/code&gt;, &lt;code&gt;indices&lt;/code&gt;, &lt;code&gt;flatten&lt;/code&gt;, &lt;code&gt;transpose&lt;/code&gt;, &lt;code&gt;unzip&lt;/code&gt;,
&lt;code&gt;zipWithIndex&lt;/code&gt;, &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;keySet&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toArraySeq&lt;/code&gt;, &lt;code&gt;toSet&lt;/code&gt;, &lt;code&gt;toMap&lt;/code&gt;,
&lt;code&gt;toSortedSet&lt;/code&gt; and &lt;code&gt;toSortedMap&lt;/code&gt;. &lt;strong&gt;Kept with &lt;code&gt;()&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;iterator()&lt;/code&gt;, &lt;code&gt;toArray()&lt;/code&gt; and &lt;code&gt;toBuffer()&lt;/code&gt;
(each a fresh mutable object), &lt;code&gt;next()&lt;/code&gt;, &lt;code&gt;hasNext()&lt;/code&gt;, &lt;code&gt;buffered()&lt;/code&gt;, &lt;code&gt;view()&lt;/code&gt;, &lt;code&gt;peek()&lt;/code&gt; and every
mutating method; the internal &lt;code&gt;erasedSize()&lt;/code&gt;/&lt;code&gt;erasedLength()&lt;/code&gt;. No accessor had an overload with
parameters to give up: &lt;code&gt;min&lt;/code&gt;/&lt;code&gt;max&lt;/code&gt; with an ordering are &lt;code&gt;minBy&lt;/code&gt;/&lt;code&gt;maxBy&lt;/code&gt;, and the free &lt;code&gt;min(a, b)&lt;/code&gt;
and &lt;code&gt;max(a, b)&lt;/code&gt; are functions, not methods. WHY: these answer from the collection without changing
it, which is what a parameterless method says; one spelling across every collection, since the
shape is part of the signature and generic code over &lt;code&gt;Iterable[T]&lt;/code&gt; reads them the same way.
&lt;strong&gt;Reviewed with the user 2026-11-12 and kept: an iterator is an &lt;code&gt;Iterable&lt;/code&gt;, so &lt;code&gt;it.head&lt;/code&gt;, &lt;code&gt;it.size&lt;/code&gt;, &lt;code&gt;it.toVector&lt;/code&gt; are
parameterless too and read from it&lt;/strong&gt;, against the rule that a method with an effect keeps its
&lt;code&gt;()&lt;/code&gt;. ALTERNATIVES weighed: keep these &lt;code&gt;()&lt;/code&gt; on &lt;code&gt;Iterable&lt;/code&gt; and convert only where the receiver is a
collection (impossible while &lt;code&gt;Iterator&lt;/code&gt; conforms to &lt;code&gt;Iterable&lt;/code&gt;, the shape being part of the
signature); split a &lt;code&gt;Collection&lt;/code&gt; trait off &lt;code&gt;Iterable&lt;/code&gt; for the accessors so an iterator keeps &lt;code&gt;()&lt;/code&gt;
(a library reshaping larger than this sweep); convert only &lt;code&gt;head&lt;/code&gt;/&lt;code&gt;size&lt;/code&gt;/&lt;code&gt;isEmpty&lt;/code&gt; (a mixed
spelling a reader has to memorise). Option, Either, Result, &lt;code&gt;string&lt;/code&gt; and the numerics keep &lt;code&gt;()&lt;/code&gt;
for now (wave 2), since no trait they implement forced them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Fixed 2026-11-12 (branch &lt;code&gt;parameterless-collections&lt;/code&gt;): naming a parameterless method of a
generic class or trait where a function is expected, &lt;code&gt;val f: () -&amp;gt; int = xs.head&lt;/code&gt; on a
&lt;code&gt;Vector[int]&lt;/code&gt;, now gives the lambda error: what the call yields is read at the receiver’s type
arguments, where before the method’s own &lt;code&gt;T&lt;/code&gt; hid it and the plain type mismatch was reported.
The compiler’s own expansions (a &lt;code&gt;for&lt;/code&gt; over an array or a range, a sequence pattern) read
&lt;code&gt;length&lt;/code&gt; and &lt;code&gt;nonEmpty&lt;/code&gt; without a call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;def&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;def&lt;/code&gt; comes after the modifiers and the
annotations, once&lt;/strong&gt;: &lt;code&gt;@tailrec&lt;/code&gt; on the line before, then &lt;code&gt;private override static def f(…)&lt;/code&gt;;
&lt;code&gt;def private f&lt;/code&gt; is an error naming &lt;code&gt;private def f&lt;/code&gt;, &lt;code&gt;def def f&lt;/code&gt; an error, and &lt;code&gt;def&lt;/code&gt; before &lt;code&gt;val&lt;/code&gt;,
&lt;code&gt;var&lt;/code&gt; or &lt;code&gt;lazy val&lt;/code&gt; an error saying a value is declared without it. WHY: the modifiers describe
the declaration and &lt;code&gt;def&lt;/code&gt; begins it, so &lt;code&gt;def&lt;/code&gt; sits next to the name it introduces, as &lt;code&gt;val&lt;/code&gt; does in
&lt;code&gt;private val x&lt;/code&gt;; one place keeps declarations uniform to read and to search. ALTERNATIVES: &lt;code&gt;def&lt;/code&gt;
first and modifiers after it (&lt;code&gt;def private f&lt;/code&gt;), or either order (two spellings of one declaration).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;def&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;def name = body&lt;/code&gt; with no parameter list and no
result type is a parameterless function or method whose result is inferred&lt;/strong&gt;, at the top level, in
a block and as a member (&lt;code&gt;def perimeter = 2.0 * (w + h)&lt;/code&gt;). Without &lt;code&gt;def&lt;/code&gt; a name followed by &lt;code&gt;=&lt;/code&gt; is
an assignment, so only &lt;code&gt;def&lt;/code&gt; can say this. WHY: a parameter list’s absence is what &lt;code&gt;def&lt;/code&gt; permits,
and every other function may leave its result to inference; refusing it would make &lt;code&gt;def&lt;/code&gt; require
a written type for no reason of its own. ALTERNATIVE: requiring &lt;code&gt;-&amp;gt; T&lt;/code&gt; after a parameterless
&lt;code&gt;def&lt;/code&gt; (one shape, more to write). An indented body after &lt;code&gt;def name&lt;/code&gt; with neither &lt;code&gt;=&lt;/code&gt; nor &lt;code&gt;-&amp;gt;&lt;/code&gt; is
refused, naming &lt;code&gt;def name -&amp;gt; T = …&lt;/code&gt;, &lt;code&gt;def name = …&lt;/code&gt; and &lt;code&gt;name()&lt;/code&gt;, since a body run for its effect
is declared with &lt;code&gt;()&lt;/code&gt;. Review with the user: whether the inferred form is wanted at all.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;def&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;def&lt;/code&gt; on a clause and on a field is refused&lt;/strong&gt;:
&lt;code&gt;def&lt;/code&gt; belongs to a function’s signature, never to the clauses after it (a clause written with
&lt;code&gt;def&lt;/code&gt; is reported and then read as the clause it is), and &lt;code&gt;def val x&lt;/code&gt; is an error rather than a
field (then read as the &lt;code&gt;val&lt;/code&gt; it is). WHY: one keyword per declaration, and a field already has
its own. ALTERNATIVE: &lt;code&gt;def&lt;/code&gt; accepted and ignored before a clause (two spellings of one clause).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;def&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;override def&lt;/code&gt; and &lt;code&gt;def&lt;/code&gt; on trait members change
nothing about overriding&lt;/strong&gt;: a parameterless &lt;code&gt;def name -&amp;gt; T&lt;/code&gt; overrides or implements only a
parameterless method, exactly as without &lt;code&gt;def&lt;/code&gt;, and &lt;code&gt;override&lt;/code&gt; is still required where it was.
WHY: &lt;code&gt;def&lt;/code&gt; adds no meaning to a member. ALTERNATIVE: &lt;code&gt;def&lt;/code&gt; implying &lt;code&gt;override&lt;/code&gt; (two spellings
would mean different things).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;def&lt;/code&gt;): &lt;strong&gt;the diagnostics for a parameterless function name
it by its own name, also when it is reached through a module&lt;/strong&gt;: &lt;code&gt;val f: () -&amp;gt; int = clock.now&lt;/code&gt;
reports “&lt;code&gt;now&lt;/code&gt; takes no parameter list …, as in &lt;code&gt;() -&amp;gt; now&lt;/code&gt;“. WHY: the checker sees the resolved
function; the module-qualified spelling would need the source text. ALTERNATIVE: name the
qualified spelling, &lt;code&gt;() -&amp;gt; clock.now&lt;/code&gt; (more exact; a small later change).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;grammar-tests&lt;/code&gt;): Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;grammar-tests&lt;/code&gt;): &lt;strong&gt;the editor grammar tests run in the release flow, not in the compiler gate.&lt;/strong&gt; &lt;code&gt;sysl test editors/grammar-tests&lt;/code&gt; is a package of its own so the compiler gate does not need Oniguruma; it
broke unnoticed on a Sysl upgrade because nothing ran it. &lt;code&gt;scripts/release.sh&lt;/code&gt; runs it (step
&lt;code&gt;03b-grammar&lt;/code&gt;, through the slot wrapper) before tagging, and the director runs it after any Sysl bump or
grammar change. WHY: the grammar ships in the VS Code extension and the IntelliJ plugin, so a
release must not carry a grammar whose tests cannot build; the run takes seconds. ALTERNATIVES:
adding it to the compiler gate (couples the gate to a native Oniguruma build and to the
highlighter package’s Sysl pin); a CI-only job (no CI runs here). Review with the user if the
gate coupling is preferred.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;runner-orphans&lt;/code&gt;): &lt;strong&gt;Every program a runner starts leads a process
group of its own, and nothing in that group outlives it.&lt;/strong&gt; &lt;code&gt;avin test&lt;/code&gt; (each test and hook), the
execution corpus and the documentation-programs check start each program with a new process
group, so whatever it starts in turn is in the group too. Once the program has been waited for,
whatever is left of its group is sent &lt;code&gt;SIGTERM&lt;/code&gt;, given &lt;strong&gt;200 ms&lt;/strong&gt; to go (the same grace the
system layer gives a program that outstays its limit), then sent &lt;code&gt;SIGKILL&lt;/code&gt;: after every run, not
only after a timeout, since a test that passed but left a server’s worker running orphans it just
the same. A runner stopped by &lt;code&gt;SIGINT&lt;/code&gt;, &lt;code&gt;SIGTERM&lt;/code&gt; or now also &lt;code&gt;SIGHUP&lt;/code&gt; (exiting 130, 143, 129)
sends &lt;code&gt;SIGKILL&lt;/code&gt; at once to every group still running, with no grace, because whoever stopped it is
itself about to make it stop. WHY: the orphans found 2026-11-12 (a corpus program spinning for
8 h; two left idle for 30 h) were programs and grandchildren that the runner never reached once
the timeout had killed only the leader, or once the runner itself was stopped. ALTERNATIVES
weighed: enforcing the limit on the whole group at once (&lt;code&gt;SIGTERM&lt;/code&gt; to the group at the deadline
rather than to the leader first) needs a watchdog thread of the runner’s own in place of the
system layer’s timeout, for a difference only in the order the grandchildren hear &lt;code&gt;SIGTERM&lt;/code&gt;; a
child-side check that its parent has gone (macOS has no parent-death signal, so every Avin program
would poll); a longer grace (a test’s tidy-up has its whole limit already). Known limit: a runner
killed with &lt;code&gt;SIGKILL&lt;/code&gt; cannot act, and its programs, no longer in its group, are not reached by a
signal sent to that group; marshal and &lt;code&gt;sysl test&lt;/code&gt; both send &lt;code&gt;SIGTERM&lt;/code&gt; first. A program that
moves itself into another group or session is also beyond reach. &lt;code&gt;avin run&lt;/code&gt; is unchanged: its
program stays in the terminal’s group so that Ctrl-C and job control reach it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;field-shadow&lt;/code&gt;): &lt;strong&gt;A field may share its name with a trait’s method
that takes a parameter list.&lt;/strong&gt; &lt;code&gt;x.name&lt;/code&gt; and a bare &lt;code&gt;name&lt;/code&gt; read the field; &lt;code&gt;x.name(args)&lt;/code&gt; and a
bare &lt;code&gt;name(args)&lt;/code&gt; call the method (a bare call is &lt;code&gt;self.name(args)&lt;/code&gt;, which already put methods
first); through the trait or a type parameter it bounds only the method is seen. A method of no
trait, or of no parameter list, still may not share a field’s name, and is reported at its own
declaration; what a derived impl lacks is reported at the &lt;code&gt;derives&lt;/code&gt; entry, never in the library’s
template. WHY: &lt;code&gt;display&lt;/code&gt;, &lt;code&gt;debug&lt;/code&gt;, &lt;code&gt;compare&lt;/code&gt; and the rest are ordinary field names
(&lt;code&gt;data Config(host: string, debug: bool)&lt;/code&gt;), and every data type derives &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt;
without asking, so refusing the pair made such a type unprintable with an error inside
&lt;code&gt;format.avin&lt;/code&gt;; the read/call split is the rule member access and calls already followed, so no
program changes meaning. A field holding a function under such a name is called by reading it
first (&lt;code&gt;val f = x.name&lt;/code&gt;). ALTERNATIVES: renaming the protocol methods to reserved spellings
(breaks every hand-written impl and still leaves a name a field can take); having the library and
templates call through a qualified trait form such as &lt;code&gt;Display.display(x, …)&lt;/code&gt; (no such form exists,
and it would fix only the library’s calls, not a program’s own impl); refusing the field with a
better message (keeps &lt;code&gt;debug: bool&lt;/code&gt; illegal). Review with the user: it widens what a type may
declare.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;main-result&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;main&lt;/code&gt; may answer with &lt;code&gt;Result[unit, E]&lt;/code&gt; or
&lt;code&gt;Result[N, E]&lt;/code&gt; for any integer type &lt;code&gt;N&lt;/code&gt;, and also with &lt;code&gt;Result[Nothing, E]&lt;/code&gt;. An &lt;code&gt;Err&lt;/code&gt; is written to
standard error as &lt;code&gt;error: &lt;/code&gt; followed by its &lt;code&gt;Display&lt;/code&gt;, and the program exits with 1.&lt;/strong&gt; The line is
written before the exit hooks run. &lt;code&gt;Ok(n)&lt;/code&gt; exits with &lt;code&gt;n&lt;/code&gt;, as a plain integer &lt;code&gt;main&lt;/code&gt; does.
WHY: this lets a whole script use &lt;code&gt;?&lt;/code&gt;. The &lt;code&gt;error: &lt;/code&gt; prefix matches the compiler’s own
diagnostics and is what a command-line user expects. Status 1 is the ordinary failure status, and
it is distinct from a trap, which ends the program with a signal. Allowing any integer type matches
the plain &lt;code&gt;main&lt;/code&gt;, which may yield any integer. &lt;code&gt;Nothing&lt;/code&gt; covers &lt;code&gt;main() = Err(…)&lt;/code&gt;, whose &lt;code&gt;Ok&lt;/code&gt; type is
inferred as &lt;code&gt;Nothing&lt;/code&gt;. ALTERNATIVES: allow only &lt;code&gt;int&lt;/code&gt; in &lt;code&gt;Ok&lt;/code&gt; (narrower than plain &lt;code&gt;main&lt;/code&gt; for no
reason); give each error type its own status (there is no agreed way to choose one, and a program
that wants a particular status calls &lt;code&gt;exit&lt;/code&gt;); trap on &lt;code&gt;Err&lt;/code&gt; (a trap reports a source position
and signals, which is wrong for an expected failure such as a missing file).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;main-result&lt;/code&gt;): &lt;strong&gt;The error type of a &lt;code&gt;Result&lt;/code&gt;-answering &lt;code&gt;main&lt;/code&gt; must
implement &lt;code&gt;Display&lt;/code&gt;. There is no fallback to &lt;code&gt;Debug&lt;/code&gt;.&lt;/strong&gt; A union of errors needs &lt;code&gt;Display&lt;/code&gt; on every
member. WHY: the line is meant for the program’s user, and a &lt;code&gt;Debug&lt;/code&gt; form, such as quoted strings
or field names, reads as an accident. This is the same rule that applies to the error of a
&lt;code&gt;@test&lt;/code&gt; function answering &lt;code&gt;Result[unit, E]&lt;/code&gt;, so the two &lt;code&gt;Result&lt;/code&gt; readers agree. Data types get
&lt;code&gt;Display&lt;/code&gt; automatically wherever their fields have it, so the requirement rarely costs anything.
ALTERNATIVES: fall back to &lt;code&gt;Debug&lt;/code&gt; when there is no &lt;code&gt;Display&lt;/code&gt; (more programs compile, but some
errors would be shown in a form nobody chose); show any value at all through the runtime renderer
(same objection, and weaker). The user may want to revisit this if programs commonly hit errors
that have only &lt;code&gt;Debug&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;parameterless-wave2&lt;/code&gt;): &lt;strong&gt;the rest of the standard library’s pure
accessors are parameterless.&lt;/strong&gt; The rule applied: a public method of no parameters is declared
without a parameter list when it answers from its receiver (or, static, from its type), changes
nothing, and hands out nothing to change or use up; the same rule wave 1 applied to collections,
where &lt;code&gt;reverse&lt;/code&gt;, &lt;code&gt;distinct&lt;/code&gt; and the immutable conversions count as accessors. Converted: Option’s
&lt;code&gt;isDefined&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toArraySeq&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt;,
&lt;code&gt;flatten&lt;/code&gt;, &lt;code&gt;unzip&lt;/code&gt;; Either’s &lt;code&gt;isLeft&lt;/code&gt;, &lt;code&gt;isRight&lt;/code&gt;, &lt;code&gt;swap&lt;/code&gt;, &lt;code&gt;toOption&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;,
&lt;code&gt;merge&lt;/code&gt;, &lt;code&gt;joinLeft&lt;/code&gt;, &lt;code&gt;joinRight&lt;/code&gt;; Result’s &lt;code&gt;isOk&lt;/code&gt;, &lt;code&gt;isErr&lt;/code&gt;, &lt;code&gt;ok&lt;/code&gt;, &lt;code&gt;err&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt;, &lt;code&gt;flatten&lt;/code&gt;; a
pair’s &lt;code&gt;swap&lt;/code&gt;; string’s &lt;code&gt;byteLength&lt;/code&gt;, &lt;code&gt;charCount&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;isBlank&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;,
&lt;code&gt;last&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;, &lt;code&gt;chars&lt;/code&gt;, &lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;lines&lt;/code&gt;, &lt;code&gt;trim&lt;/code&gt;,
&lt;code&gt;strip&lt;/code&gt;, &lt;code&gt;stripLeading&lt;/code&gt;, &lt;code&gt;stripTrailing&lt;/code&gt;, &lt;code&gt;stripLineEnd&lt;/code&gt;, &lt;code&gt;capitalize&lt;/code&gt;, &lt;code&gt;toUpper&lt;/code&gt;,
&lt;code&gt;toLower&lt;/code&gt;; char’s &lt;code&gt;isDigit&lt;/code&gt;, &lt;code&gt;isLetter&lt;/code&gt;, &lt;code&gt;isLetterOrDigit&lt;/code&gt;, &lt;code&gt;isSpaceChar&lt;/code&gt;, &lt;code&gt;isWhitespace&lt;/code&gt;,
&lt;code&gt;isUpper&lt;/code&gt;, &lt;code&gt;isLower&lt;/code&gt;, &lt;code&gt;isControl&lt;/code&gt;, &lt;code&gt;toUpper&lt;/code&gt;, &lt;code&gt;toLower&lt;/code&gt;, &lt;code&gt;asDigit&lt;/code&gt;; the integers’ &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;sign&lt;/code&gt;,
&lt;code&gt;bitCount&lt;/code&gt;, &lt;code&gt;leadingZeros&lt;/code&gt;, &lt;code&gt;trailingZeros&lt;/code&gt;, &lt;code&gt;isPowerOfTwo&lt;/code&gt;; real’s &lt;code&gt;isNaN&lt;/code&gt;, &lt;code&gt;isInfinite&lt;/code&gt;,
&lt;code&gt;isFinite&lt;/code&gt;; Enumerable’s &lt;code&gt;values&lt;/code&gt; (static), &lt;code&gt;ordinal&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;; StringWriter’s &lt;code&gt;text&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;,
&lt;code&gt;isEmpty&lt;/code&gt;; ByteView’s &lt;code&gt;length&lt;/code&gt;; &lt;code&gt;sorted&lt;/code&gt;, &lt;code&gt;firstKey&lt;/code&gt;, &lt;code&gt;lastKey&lt;/code&gt;, &lt;code&gt;toTreeMap&lt;/code&gt;, &lt;code&gt;toBitMask&lt;/code&gt; and a
queue’s &lt;code&gt;front&lt;/code&gt;, &lt;code&gt;frontOption&lt;/code&gt;, &lt;code&gt;dequeue&lt;/code&gt;, &lt;code&gt;dequeueOption&lt;/code&gt;, &lt;code&gt;toQueue&lt;/code&gt;, which wave 1 missed;
regex’s &lt;code&gt;pattern&lt;/code&gt;, &lt;code&gt;regex&lt;/code&gt;, &lt;code&gt;anchored&lt;/code&gt;, &lt;code&gt;unanchored&lt;/code&gt;, &lt;code&gt;groupCount&lt;/code&gt;, &lt;code&gt;groupNames&lt;/code&gt;, &lt;code&gt;matched&lt;/code&gt;,
&lt;code&gt;start&lt;/code&gt;, &lt;code&gt;end&lt;/code&gt;, &lt;code&gt;before&lt;/code&gt;, &lt;code&gt;after&lt;/code&gt;, &lt;code&gt;subgroups&lt;/code&gt;; time’s int and long &lt;code&gt;micros&lt;/code&gt; … &lt;code&gt;weeks&lt;/code&gt;,
Duration’s &lt;code&gt;toDays&lt;/code&gt; … &lt;code&gt;toSecondsReal&lt;/code&gt;, &lt;code&gt;isNegative&lt;/code&gt;, &lt;code&gt;isZero&lt;/code&gt;, &lt;code&gt;abs&lt;/code&gt;, Instant’s and Zoned’s
&lt;code&gt;epochSeconds&lt;/code&gt;/&lt;code&gt;epochMillis&lt;/code&gt;/&lt;code&gt;epochMicros&lt;/code&gt;, every Date, Time, DateTime and Zoned field reader
(&lt;code&gt;year&lt;/code&gt;, &lt;code&gt;month&lt;/code&gt;, &lt;code&gt;day&lt;/code&gt;, &lt;code&gt;weekday&lt;/code&gt;, &lt;code&gt;hour&lt;/code&gt;, &lt;code&gt;startOfMonth&lt;/code&gt;, &lt;code&gt;date&lt;/code&gt;, &lt;code&gt;time&lt;/code&gt;, &lt;code&gt;abbreviation&lt;/code&gt;, …),
Period’s &lt;code&gt;months&lt;/code&gt;/&lt;code&gt;years&lt;/code&gt; and readers, Weekday’s &lt;code&gt;isoNumber&lt;/code&gt;, Zone’s &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;isFixed&lt;/code&gt;; every
error type’s &lt;code&gt;message&lt;/code&gt;; Url’s &lt;code&gt;portOrDefault&lt;/code&gt; and &lt;code&gt;queryParams&lt;/code&gt;, an HTTP response’s and request’s
&lt;code&gt;text&lt;/code&gt;, a request’s &lt;code&gt;queryParams&lt;/code&gt;; ExitStatus’s &lt;code&gt;isSuccess&lt;/code&gt;, Command’s &lt;code&gt;clearEnv&lt;/code&gt; and
&lt;code&gt;inNewGroup&lt;/code&gt;; Weighted’s &lt;code&gt;size&lt;/code&gt;; Json’s &lt;code&gt;isNull&lt;/code&gt;, &lt;code&gt;asBool&lt;/code&gt; … &lt;code&gt;asMembers&lt;/code&gt;, &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt;,
&lt;code&gt;render&lt;/code&gt;, &lt;code&gt;renderAscii&lt;/code&gt;. A trait’s static member declared without a parameter list is now read
through a type parameter too, &lt;code&gt;T.values&lt;/code&gt; (it was refused as “&lt;code&gt;T&lt;/code&gt; is not defined”), and the
infix-postfix diagnostic names both spellings, &lt;code&gt;xs.size&lt;/code&gt; and &lt;code&gt;xs.size()&lt;/code&gt;.
&lt;strong&gt;Kept with &lt;code&gt;()&lt;/code&gt;, the borderline calls&lt;/strong&gt;: (1) string’s &lt;code&gt;toInt()&lt;/code&gt;, &lt;code&gt;toLong()&lt;/code&gt;, &lt;code&gt;toIntOption()&lt;/code&gt;,
&lt;code&gt;toLongOption()&lt;/code&gt; have overloads taking a radix, and a parameterless method is the only one of its
name, so they keep &lt;code&gt;()&lt;/code&gt;, and &lt;code&gt;toReal()&lt;/code&gt;, &lt;code&gt;toRealOption()&lt;/code&gt;, &lt;code&gt;toBool()&lt;/code&gt;, &lt;code&gt;toBoolOption()&lt;/code&gt; keep them
with them, one spelling for the family of parsers; &lt;code&gt;stripMargin()&lt;/code&gt; likewise beside
&lt;code&gt;stripMargin(c)&lt;/code&gt;. (2) The core traits’ members every type implements or derives —
&lt;code&gt;toString()&lt;/code&gt;, &lt;code&gt;hash()&lt;/code&gt;, &lt;code&gt;zero()&lt;/code&gt;, &lt;code&gt;one()&lt;/code&gt;, &lt;code&gt;negate()&lt;/code&gt;, &lt;code&gt;shape()&lt;/code&gt;, Codec’s &lt;code&gt;whenMissing()&lt;/code&gt; and
&lt;code&gt;jsonKey()&lt;/code&gt; — and so Duration’s and Period’s &lt;code&gt;zero()&lt;/code&gt;/&lt;code&gt;negate()&lt;/code&gt;, since changing these changes
every program’s own impls and derives; &lt;strong&gt;review with the user&lt;/strong&gt;, as a wave of its own. (3)
Reads of shared or outside state: a &lt;code&gt;Mutex&lt;/code&gt;‘s and a UI state’s &lt;code&gt;get()&lt;/code&gt;, a signal’s &lt;code&gt;read()&lt;/code&gt;,
a future’s &lt;code&gt;isCompleted()&lt;/code&gt;/&lt;code&gt;value()&lt;/code&gt;/&lt;code&gt;peek()&lt;/code&gt;, an executor’s &lt;code&gt;isShutdown()&lt;/code&gt;, an actor mailbox’s
&lt;code&gt;isEmpty()&lt;/code&gt;, and every method of a file, socket, listener, child process or command’s handle
(&lt;code&gt;pid()&lt;/code&gt;, &lt;code&gt;isAlive()&lt;/code&gt;, &lt;code&gt;isClosed()&lt;/code&gt;, &lt;code&gt;port()&lt;/code&gt;), whose answer can change under the reader. (4)
Constructors and factories, &lt;code&gt;Vector.empty[T]()&lt;/code&gt;, &lt;code&gt;BitSet.empty()&lt;/code&gt;, &lt;code&gt;newBuilder()&lt;/code&gt;, &lt;code&gt;copy()&lt;/code&gt;,
&lt;code&gt;Random()&lt;/code&gt;. (5) A UI view’s modifiers &lt;code&gt;padded()&lt;/code&gt; and &lt;code&gt;panel()&lt;/code&gt;, beside &lt;code&gt;padding(n)&lt;/code&gt; and
&lt;code&gt;pad(…)&lt;/code&gt;, one spelling for the modifier chain. (6) Private helpers and binding classes.
&lt;strong&gt;Borderline converted&lt;/strong&gt;: &lt;code&gt;opt.get&lt;/code&gt; and &lt;code&gt;s.head&lt;/code&gt; trap on None and on an empty string, as &lt;code&gt;xs.head&lt;/code&gt;
does; &lt;code&gt;q.dequeue&lt;/code&gt; reads like an action but answers a new queue and changes nothing; a regex
matcher’s &lt;code&gt;matched&lt;/code&gt;, &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; read the current match of a cursor that &lt;code&gt;findNext()&lt;/code&gt;
moves, as a buffer’s &lt;code&gt;size&lt;/code&gt; reads a buffer that &lt;code&gt;push&lt;/code&gt; changes. WHY: one rule across the library,
so a reader knows a call’s spelling from what it does; the families above stay uniform.
ALTERNATIVES weighed: converting only the brief’s types (Option, Either, Result, string) and
leaving char, integer, time and regex for later (two spellings for one kind of method, read side
by side in the same expression, &lt;code&gt;s.trim.toInt()&lt;/code&gt; beside &lt;code&gt;c.isDigit()&lt;/code&gt;); renaming the radix
overloads (&lt;code&gt;toIntRadix(16)&lt;/code&gt;) so &lt;code&gt;toInt&lt;/code&gt; could lose its &lt;code&gt;()&lt;/code&gt; (a rename of a settled API for
spelling alone); converting &lt;code&gt;toString()&lt;/code&gt; and &lt;code&gt;hash()&lt;/code&gt; now (every class’s impls change with them).
A trap to know: &lt;code&gt;opt.get()&lt;/code&gt; where &lt;code&gt;opt: Option[() -&amp;gt; T]&lt;/code&gt; now calls the function the option holds;
the library’s one such site was rewritten to &lt;code&gt;opt.get&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;bare-method-ref&lt;/code&gt;): &lt;strong&gt;a method declared with an empty parameter list,
&lt;code&gt;m()&lt;/code&gt;, named without a call is a function value only where a function type is expected.&lt;/strong&gt; Anywhere
else (&lt;code&gt;println(xs.sorted)&lt;/code&gt;, &lt;code&gt;s&amp;quot;${s.isEmpty}&amp;quot;&lt;/code&gt;, &lt;code&gt;c.bump == 0&lt;/code&gt;, &lt;code&gt;val v = c.bump&lt;/code&gt; with no type, an
argument for a type parameter or &lt;code&gt;Any&lt;/code&gt;), it is an error naming the call &lt;code&gt;x.m()&lt;/code&gt; and the lambda
&lt;code&gt;() -&amp;gt; x.m()&lt;/code&gt;; among overloads with one of no parameters, a bare name with no expected function
type gets the same error rather than “ambiguous”. Instance, static and trait methods alike;
methods with parameters (&lt;code&gt;account.deposit&lt;/code&gt;) are values wherever named, as settled. WHY: with
parameterless and &lt;code&gt;()&lt;/code&gt; methods side by side, a missing &lt;code&gt;()&lt;/code&gt; is the commonest slip, and &lt;code&gt;print&lt;/code&gt;
takes &lt;code&gt;Any&lt;/code&gt;, so it compiled and printed &lt;code&gt;&amp;lt;function&amp;gt;&lt;/code&gt;; where a function type is expected the value
is wanted and type-checks. ALTERNATIVES: refusing method values of &lt;code&gt;()&lt;/code&gt; methods altogether (then
&lt;code&gt;spawn(worker.run)&lt;/code&gt; needs a lambda); a warning instead of an error (wrong output still ships);
extending the rule to top-level functions of no parameters (they are always called with &lt;code&gt;()&lt;/code&gt;, so
the slip does not arise). Review with the user: &lt;code&gt;val f = c.bump&lt;/code&gt; no longer infers a function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;bare-method-ref&lt;/code&gt;): &lt;strong&gt;a function value stays without &lt;code&gt;Display&lt;/code&gt;&lt;/strong&gt;, so
interpolating one is an error, now with the hint “a function value is never shown: to show what
it returns, call it”; &lt;code&gt;print&lt;/code&gt;/&lt;code&gt;println&lt;/code&gt; keep taking &lt;code&gt;Any&lt;/code&gt; and show a function as &lt;code&gt;&amp;lt;function&amp;gt;&lt;/code&gt;.
WHY: the empty-list rule above already stops the missing-&lt;code&gt;()&lt;/code&gt; slip at its source, and the
remaining ways to print a function (a variable or lambda, a method value of a method with
parameters) are deliberate; a special refusal inside &lt;code&gt;print&lt;/code&gt; would make it unlike every other
&lt;code&gt;Any&lt;/code&gt; parameter, against its settled “one ordinary library function”. ALTERNATIVES: refusing a
function-typed argument to &lt;code&gt;print&lt;/code&gt;/&lt;code&gt;println&lt;/code&gt; (a special case); refusing any conversion of a
function to &lt;code&gt;Any&lt;/code&gt; (breaks heterogeneous &lt;code&gt;Any&lt;/code&gt; containers holding callbacks).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;lazylist-perf&lt;/code&gt;): &lt;strong&gt;A lazy list’s cell is one object of three words,
filled in place by the one function that evaluates it.&lt;/strong&gt; &lt;code&gt;LazyList[+T]&lt;/code&gt; holds &lt;code&gt;pending&lt;/code&gt; (the
evaluating function until it has run, a constant trapping function while it runs, then &lt;code&gt;None&lt;/code&gt;),
&lt;code&gt;first&lt;/code&gt; and &lt;code&gt;rest&lt;/code&gt;; an empty cell is one whose &lt;code&gt;rest&lt;/code&gt; is itself, and a cell evaluated as another
list’s first cell whose rest would be itself points at that other cell instead (the same element,
then itself again), so a list that is its own tail still repeats. Making a cell allocates the cell
and the function that evaluates it, and evaluating it allocates only the cells after it and the
elements; a cell is read with a test of &lt;code&gt;pending&lt;/code&gt; and no lock, since a lazy list is not sendable.
To keep the element and the rest in a covariant class, the core library gains the intrinsic
&lt;strong&gt;&lt;code&gt;field_unset&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;private var x: T = fieldUnset()&lt;/code&gt; is a field the constructor leaves as the zero
bytes the object was made with (not yet a value, as an array’s spare capacity is not), which the
class’s own code writes before reading it; such a field must be a &lt;code&gt;private var&lt;/code&gt; with its type
written, is not a position for the class’s variance (it is written only with values computed for
that instance), and the intrinsic is the core library’s alone; called anywhere but as a field’s
initializer it traps (&lt;code&gt;a field is read before it is set&lt;/code&gt;). Measured at &lt;code&gt;-O2&lt;/code&gt; (&lt;code&gt;LazyList.from(0)&lt;/code&gt;
and the stages named, then &lt;code&gt;take(n)&lt;/code&gt;, the cost per element; time under a loaded machine, user
time): bytes kept per evaluated cell 256 → 48 (resident growth per held cell 304 → 96); bytes
allocated per element of &lt;code&gt;from&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt; or &lt;code&gt;take&lt;/code&gt; 304 in 7 objects → 96 in 2, and of
&lt;code&gt;#::&lt;/code&gt; 544 in 13 → 192 in 4 (two cells, each with its function); time per element of
&lt;code&gt;from.take&lt;/code&gt; 0.118 → 0.035 µs, &lt;code&gt;map&lt;/code&gt; 0.18 → 0.058, &lt;code&gt;filter&lt;/code&gt; 0.24 → 0.079, &lt;code&gt;#::&lt;/code&gt; 0.18 → 0.065, the
4000th prime by the sieve 4.8 → 1.7 s; at &lt;code&gt;-O0&lt;/code&gt; &lt;code&gt;from.take&lt;/code&gt; 0.16 → 0.06 µs. &lt;code&gt;lazy_list_deep&lt;/code&gt; runs
a million cells again. WHY: each cell was a &lt;code&gt;LazyList&lt;/code&gt; object, a progress object, the closure of
its &lt;code&gt;lazy val&lt;/code&gt;, a box and a closure to drop the pending function, the function itself, and a
tuple for the evaluated element and rest, with a lock-taking &lt;code&gt;lazy val&lt;/code&gt; read on every access; the
element and rest belong in the cell, which only a field left unset can hold, since a covariant
class may not otherwise keep a &lt;code&gt;var&lt;/code&gt; of its parameter and a field must otherwise be given a value
when the object is made. The counts are pinned by &lt;code&gt;lazy_list_cell_tests.sysl&lt;/code&gt;, which reads them
from the code each maker compiles to; no runtime allocation counter was added, since the code is
where an allocation is decided and the test holds however a run is timed. ALTERNATIVES: a cheaper
&lt;code&gt;lazy val&lt;/code&gt; (no closure per object) with the tuple kept (three objects per element, still a lock
per read); &lt;code&gt;Option[T]&lt;/code&gt; for the element (allocates a &lt;code&gt;Some&lt;/code&gt; for every scalar element); a separate
evaluated node per cell (two objects); an annotation exempting a field from variance, with an
initial value supplied some other way (two mechanisms where one does); a runtime allocation
counter exposed to programs (a hook in every allocation, for a check the code already answers).
Review with the user: &lt;code&gt;field_unset&lt;/code&gt; is a new escape from the variance and initialization rules,
though only the core library may use it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;train-c-fix&lt;/code&gt;): &lt;strong&gt;Proposed (branch &lt;code&gt;train-c-fix&lt;/code&gt;): an argument that cannot be checked before an overload is chosen
is tried against each candidate.&lt;/strong&gt; Where a lambda’s body, checked with its result left open (the
rule &lt;code&gt;map-flatmap&lt;/code&gt; added for &lt;code&gt;flatMap&lt;/code&gt;‘s &lt;code&gt;Iterable&lt;/code&gt;/&lt;code&gt;Option&lt;/code&gt; overloads), reports an error, or a
generic function named as a value cannot be checked without the parameter’s type, the argument is
checked against each remaining candidate with nothing reported and nothing it settles kept; when
exactly one candidate takes it, that one is chosen and the argument checked against it. Otherwise
the argument is checked as before and reports what is wrong. A lambda whose body never returns
(&lt;code&gt;x -&amp;gt; fail(…)&lt;/code&gt;) fits every candidate, and the first declared is chosen (an option’s own &lt;code&gt;flatMap&lt;/code&gt;
on an option). WHY: with one &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;v.flatMap(n -&amp;gt; if … then aList else aVector)&lt;/code&gt; and
&lt;code&gt;xs.flatMap(identity)&lt;/code&gt; checked against its &lt;code&gt;Iterable[U]&lt;/code&gt;; the second overload took that expected
type away, so the branches no longer joined and &lt;code&gt;identity&lt;/code&gt; could not be instantiated — a call that
compiled stopped compiling because an overload was added. ALTERNATIVES: always prefer the
&lt;code&gt;Iterable&lt;/code&gt; overload (a rule naming library types, and wrong for &lt;code&gt;[Some(1)].flatMap(identity)&lt;/code&gt;);
report such calls as ambiguous and ask for a type (breaks code that worked); join the branches to
their least common supertype without an expected type (changes &lt;code&gt;if&lt;/code&gt; typing everywhere). A trial
checks the argument once per candidate, which costs only where candidates disagree.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;train-c-fix&lt;/code&gt;): &lt;strong&gt;Proposed (branch &lt;code&gt;train-c-fix&lt;/code&gt;): a class with a field left unset by &lt;code&gt;field_unset&lt;/code&gt; is made only by
its own code and its companion’s.&lt;/strong&gt; &lt;code&gt;LazyList[int]()&lt;/code&gt; from a program made a cell whose function,
element and rest were zero bytes, and reading it crashed the program. The constructor of such a
class is refused anywhere else: &lt;code&gt; `LazyList` keeps fields its own code fills in, so only the class and its companion make one&lt;/code&gt;. WHY: Avin has no private constructors, and the unset fields are safe
only because the class’s own code writes them before reading. ALTERNATIVES: module-private
constructors in general (a language feature, reviewed separately for &lt;code&gt;Time&lt;/code&gt;/&lt;code&gt;Zoned&lt;/code&gt;); a constructor
parameter of a private type (an extra field in every cell). Review with the user: it is a special
case of private constructors, which may want to be the general feature.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;io-errors&lt;/code&gt;): &lt;strong&gt;an &lt;code&gt;IoError&lt;/code&gt; carries its kind, operation and subject:
&lt;code&gt;data IoError(kind: ErrorKind, operation: string = &amp;quot;&amp;quot;, subject: string = &amp;quot;&amp;quot;)&lt;/code&gt;&lt;/strong&gt;, the former
variants becoming &lt;code&gt;ErrorKind&lt;/code&gt;‘s, each with a &lt;code&gt;description&lt;/code&gt;. It shows as &lt;code&gt;cannot &amp;lt;operation&amp;gt; &amp;lt;subject&amp;gt;: &amp;lt;description&amp;gt;&lt;/code&gt; (&lt;code&gt;cannot read nope.txt: no such file or directory&lt;/code&gt;), leaving out what is
empty, and every error &lt;code&gt;avin.fs&lt;/code&gt;, &lt;code&gt;avin.process&lt;/code&gt;, &lt;code&gt;avin.signal&lt;/code&gt; and &lt;code&gt;avin.net&lt;/code&gt; make names both: a
path (&lt;code&gt;old to new&lt;/code&gt; for a rename), a program, &lt;code&gt;process N&lt;/code&gt;, &lt;code&gt;host:port&lt;/code&gt;, a socket’s path, &lt;code&gt;a client of &amp;lt;address&amp;gt;&lt;/code&gt; for an accepted connection. A program tells kinds apart with
&lt;code&gt;Err(IoError(NotFound, _, _))&lt;/code&gt;, a guard on &lt;code&gt;e.kind&lt;/code&gt;, or &lt;code&gt;==&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: the error a program prints
must say what failed and on what, and one type keeps &lt;code&gt;Reader&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt; and every signature as they
were. &lt;em&gt;Alternatives&lt;/em&gt;: a wrapper per module (&lt;code&gt;FileError(path, kind)&lt;/code&gt;), which would split the one
error every reader shares and change every signature; a subject field on each variant, which
repeats it eleven times; keeping the variants and adding the path only to the message, which
leaves the value unable to say what it was about. &lt;strong&gt;Review with the user&lt;/strong&gt;: matching moved from
&lt;code&gt;Err(NotFound)&lt;/code&gt; to &lt;code&gt;Err(IoError(NotFound, _, _))&lt;/code&gt;, longer at every site that tells kinds apart.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;io-errors&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;CommandError.Failed(status, command)&lt;/code&gt;&lt;/strong&gt; names the
command’s programs (&lt;code&gt;ls&lt;/code&gt;, &lt;code&gt;ls | wc&lt;/code&gt;, &lt;code&gt;make &amp;amp;&amp;amp; ./app&lt;/code&gt;, &lt;code&gt;a || b&lt;/code&gt;, &lt;code&gt;a; b&lt;/code&gt;), and its message is
&lt;code&gt;false exited with status 1&lt;/code&gt;; an empty &lt;code&gt;command&lt;/code&gt; leaves it out. &lt;em&gt;Why&lt;/em&gt;: a failed status must say
which command failed. &lt;em&gt;Alternative&lt;/em&gt;: the command only in the message, not matchable.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;io-errors&lt;/code&gt;): &lt;strong&gt;the core trait &lt;code&gt;Error: Display&lt;/code&gt;, with parameterless
&lt;code&gt;message -&amp;gt; string&lt;/code&gt; and &lt;code&gt;cause -&amp;gt; Option[Error] = None&lt;/code&gt;, and a default &lt;code&gt;display&lt;/code&gt; that shows the
message, then &lt;code&gt;: &lt;/code&gt; and the cause as it shows&lt;/strong&gt;, leaving out an empty message. &lt;em&gt;Why
parameterless&lt;/em&gt;: both read what the error holds, the parameterless rule’s case, and a data field
named &lt;code&gt;message&lt;/code&gt; then implements the first (the json package’s &lt;code&gt;JsonError&lt;/code&gt; does). &lt;em&gt;Why the
cause’s display rather than its message&lt;/em&gt;: an error with a &lt;code&gt;Display&lt;/code&gt; of its own (&lt;code&gt;JsonError&lt;/code&gt;‘s
place) keeps it inside a chain. Every standard-library error type implements it (&lt;code&gt;IoError&lt;/code&gt;,
&lt;code&gt;CommandError&lt;/code&gt;, &lt;code&gt;HttpError&lt;/code&gt;, &lt;code&gt;UrlError&lt;/code&gt;, &lt;code&gt;TlsError&lt;/code&gt;, &lt;code&gt;TimeParseError&lt;/code&gt;, &lt;code&gt;ZoneError&lt;/code&gt;,
&lt;code&gt;PatternError&lt;/code&gt;, &lt;code&gt;MatchError&lt;/code&gt;, &lt;code&gt;AskError&lt;/code&gt;, &lt;code&gt;Utf8Error&lt;/code&gt;, &lt;code&gt;JsonError&lt;/code&gt;), each &lt;code&gt;message()&lt;/code&gt; becoming
&lt;code&gt;message&lt;/code&gt;, and &lt;code&gt;TlsRefusal.message&lt;/code&gt; with them. A wrapper that only re-tags another error
(&lt;code&gt;CommandError.Io&lt;/code&gt;, &lt;code&gt;HttpError.Io&lt;/code&gt;, &lt;code&gt;TlsError.Transport&lt;/code&gt;) has that error’s message and no cause,
so it shows once. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;message()&lt;/code&gt; with parentheses, as before (against the
parameterless rule); a &lt;code&gt;source&lt;/code&gt; chain printed separately rather than in the display (a program
would have to walk it to print anything useful).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;io-errors&lt;/code&gt;): &lt;strong&gt;a data type implementing a core trait that gives
&lt;code&gt;display&lt;/code&gt; (or &lt;code&gt;debug&lt;/code&gt;) a body takes that method rather than the automatic one&lt;/strong&gt; made from its
fields, as it does where its own impl declares the method. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;impl Error for ParseError&lt;/code&gt;
must show the sentence, not &lt;code&gt;ParseError(3)&lt;/code&gt;. Only core-library traits are looked at, since the
automatic derivation is decided before names resolve. &lt;em&gt;Alternative&lt;/em&gt;: making each error type also
write &lt;code&gt;impl Display&lt;/code&gt;, which every program’s error type would have to repeat.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;io-errors&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Result[T, E].context(text: -&amp;gt; string) -&amp;gt; Result[T, ContextError]&lt;/code&gt;, for &lt;code&gt;E: Error&lt;/code&gt;, and &lt;code&gt;data ContextError(message: string, inner: Error)&lt;/code&gt;
in the prelude&lt;/strong&gt;, whose cause is &lt;code&gt;inner&lt;/code&gt;. It works on a union of &lt;code&gt;Error&lt;/code&gt; types and a type
parameter bounded by &lt;code&gt;Error&lt;/code&gt;, and &lt;code&gt;?&lt;/code&gt; passes it, and every other error type, unchanged into
&lt;code&gt;Result[T, Error]&lt;/code&gt;. &lt;em&gt;Why by name&lt;/em&gt;: the text is usually interpolated and is needed only for an
&lt;code&gt;Err&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;withContext(f: () -&amp;gt; string)&lt;/code&gt; beside an eager &lt;code&gt;context&lt;/code&gt; (two names for one
thing, which by-name already covers); a context method on &lt;code&gt;Option&lt;/code&gt; too (not added: &lt;code&gt;okOr&lt;/code&gt; makes the
error first); keeping the wrapped error’s static type (&lt;code&gt;ContextError[E]&lt;/code&gt;), which a chain of
contexts would nest in its type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-13: &lt;strong&gt;JSON is the package &lt;code&gt;dev.avinlang.json&lt;/code&gt;&lt;/strong&gt;, in its own repository
(&lt;code&gt;github.com/avin-lang/json&lt;/code&gt;, version 0.0.1), not a module of the standard library; it supersedes
the 2026-11-12 entry below. The library’s &lt;code&gt;library/avin/json&lt;/code&gt; and its tests &lt;code&gt;library/tests/jsontests&lt;/code&gt;
moved to the package, which &lt;code&gt;avin test&lt;/code&gt; runs; the tests of the README’s examples went with them.
&lt;code&gt;import avin.json&lt;/code&gt; (whole, a declaration, a group, or under another name) is an error naming the
package: &lt;em&gt;JSON is the package &lt;code&gt;dev.avinlang.json&lt;/code&gt;; add it to your dependencies&lt;/em&gt;; so is &lt;code&gt;import json&lt;/code&gt;
in a program with no module or declaration &lt;code&gt;json&lt;/code&gt; and no dependency on the package. The corpus
programs that test the compiler or runtime with JSON (derivation’s diagnostics, the collector’s
stress, traps, threads and sockets) became manifest programs in &lt;code&gt;tests/programs/{run,reject}/json_*&lt;/code&gt;
depending on the package by the path &lt;code&gt;../../../../../json&lt;/code&gt;, the sibling checkout
&lt;code&gt;~/dev/avin-lang/json&lt;/code&gt;, as the compiler reaches &lt;code&gt;~/dev/sysl-lang/parsing&lt;/code&gt;. JSON derivation needed no
compiler change: its templates are ordinary &lt;code&gt;derive&lt;/code&gt; templates found in the module a file imports
from. A single-file script that needs JSON declares the dependency in the script itself (a separate
item, &lt;code&gt;script-deps&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;(Superseded by the user’s decision of 2026-11-13, &lt;strong&gt;JSON is the package &lt;code&gt;dev.avinlang.json&lt;/code&gt;&lt;/strong&gt;.)
Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;json-stdlib&lt;/code&gt;): &lt;strong&gt;JSON is &lt;code&gt;avin.json&lt;/code&gt; in the standard library&lt;/strong&gt;, moved
from the package &lt;code&gt;packages/json&lt;/code&gt; (module &lt;code&gt;json&lt;/code&gt;); it supersedes the 2026-11-06 entry that made it
a package, and the one that had the corpus gate &lt;code&gt;packages/json&lt;/code&gt;‘s tests. Its tests are
&lt;code&gt;library/tests/json_*.avin&lt;/code&gt;, run with the core library’s own; its corpus programs are single files
in &lt;code&gt;tests/run/json_*.avin&lt;/code&gt; and &lt;code&gt;tests/reject/json_*.avin&lt;/code&gt; with no manifest. An import that leaves
out &lt;code&gt;avin.&lt;/code&gt;, &lt;code&gt;import json&lt;/code&gt; or &lt;code&gt;import fs.readText&lt;/code&gt;, is an error naming the import meant (it reads: there is
no module &lt;code&gt;json&lt;/code&gt;; the standard library’s is &lt;code&gt;avin.json&lt;/code&gt;, imported as &lt;code&gt;import avin.json&lt;/code&gt;), unless
the program has a module or a top-level declaration of that name. &lt;em&gt;Why&lt;/em&gt;: reading JSON is the first
thing many scripts do, and a script of one file has no manifest to name a dependency in; marshal
and most services need it; and the library is read only where imported, so a program that does not
import it pays nothing. The hint is general rather than a list of package names because the one
well-known package name a script reached for is now a library module, and a list in the compiler
would go stale. &lt;em&gt;Alternatives&lt;/em&gt;: a package the compiler makes available by default without a
manifest (a second, implicit dependency mechanism with its own versioning); keeping the package and
only improving the diagnostic (still no JSON for a lone script); the module name
&lt;code&gt;dev.avinlang.json&lt;/code&gt; for the package (the prefix packages take, but still a package). Programs
outside this repository change &lt;code&gt;import json&lt;/code&gt; to &lt;code&gt;import avin.json&lt;/code&gt; and drop the &lt;code&gt;json&lt;/code&gt; dependency
from their manifests. Review with the user: it reverses a settled decision, and it widens what the
standard library holds from “what talks to the operating system” to “the formats nearly every
script reads”.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;defer-use&lt;/code&gt;): &lt;strong&gt;resource cleanup is a block-scoped &lt;code&gt;defer&lt;/code&gt; statement,
and the library’s resources are each an &lt;code&gt;io.Close&lt;/code&gt;&lt;/strong&gt;
(&lt;a href=&quot;/spec/operators-and-control-flow/#defer&quot;&gt;defer&lt;/a&gt;, &lt;a href=&quot;/spec/system-library/#close&quot;&gt;&lt;code&gt;Close&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;defer stmt&lt;/code&gt;&lt;/strong&gt; (or &lt;code&gt;defer&lt;/code&gt; and an indented block) runs the statement when control leaves the
block it is written in: at the block’s end, &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;‘s failure arm, &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt;.
The reached ones run last first; one not reached never runs; names are read when it runs, and a
block’s, &lt;code&gt;return&lt;/code&gt;‘s or &lt;code&gt;break&lt;/code&gt;‘s value is computed before. No &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, or &lt;code&gt;break&lt;/code&gt;/&lt;code&gt;continue&lt;/code&gt;
of an outer loop may leave a deferred statement. It is a statement of a block only: as a value, a
one-line branch or in a class body it is refused. While one waits, nothing is in tail position,
so &lt;code&gt;@tailrec&lt;/code&gt; refuses a self-call there. &lt;code&gt;defer&lt;/code&gt; becomes a keyword (one test function named
&lt;code&gt;defer&lt;/code&gt; was renamed).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trap and &lt;code&gt;process.exit&lt;/code&gt; run no deferred statement.&lt;/strong&gt; There is no unwinding; files and
connections left open are closed by the collector’s finalizers.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;defer-on-cancel&lt;/code&gt;): &lt;strong&gt;a cancelled
thread runs its deferred statements&lt;/strong&gt;, innermost first, as at any other way out of their blocks,
wherever its cancellation stops it (a wait, a safepoint poll), and then its frames are dropped
as before. A thread running a scope stops first at that scope: the scope body’s deferred
statements run, the scope cancels its threads and waits for them (each running its own), then the
functions around the scope run theirs. &lt;strong&gt;A deferred statement runs to its end once begun&lt;/strong&gt;: the
thread’s cancellation does not stop it inside one (its own waits are not cancellation points
while it runs, as while a lock is held), and one that comes meanwhile stops the thread at its next
cancellation point after; one that traps stops the program, as any trap. &lt;strong&gt;A cancelled wait on a
mutex’s condition stops the thread holding the lock again&lt;/strong&gt;, so a &lt;code&gt;with&lt;/code&gt; body’s deferred
statements run under it and &lt;code&gt;with&lt;/code&gt;‘s own &lt;code&gt;defer&lt;/code&gt; lets it go; the library’s internal conditions
still stop without the lock, as their code expects. &lt;code&gt;Pool&lt;/code&gt;‘s putting back what a cancelled call
held is now a &lt;code&gt;defer&lt;/code&gt;.
&lt;em&gt;Why&lt;/em&gt;: cancellation stops a thread at a known point, a wait or a poll, in a consistent state,
unlike a trap. Without it no library or package can clean up after a cancelled task: found
writing a PostgreSQL client, where a cancelled query must send a CancelRequest, a cancelled
&lt;code&gt;transaction(f)&lt;/code&gt; must roll back, and a pool lease or a &lt;code&gt;Mutex.with&lt;/code&gt; must be given back.
&lt;em&gt;Alternatives weighed&lt;/em&gt;: a public &lt;code&gt;onCancel(cleanup)(body)&lt;/code&gt; in &lt;code&gt;avin.threads&lt;/code&gt; (a second mechanism
beside &lt;code&gt;defer&lt;/code&gt;, and lambdas again, with the &lt;code&gt;return&lt;/code&gt;/&lt;code&gt;?&lt;/code&gt;/&lt;code&gt;break&lt;/code&gt; problem &lt;code&gt;defer&lt;/code&gt; was chosen to
avoid); leaving it (no cleanup at all after a cancellation); running a deferred statement with
cancellation live (a cleanup that waits could itself be cut off half done).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each deferred statement is its closure, put on the thread’s list where the &lt;code&gt;defer&lt;/code&gt; is
reached&lt;/strong&gt; (&lt;code&gt;lower.sysl&lt;/code&gt;‘s &lt;code&gt;Defer&lt;/code&gt;, &lt;code&gt;runtime/avin/rt/defers.sysl&lt;/code&gt;): every way out of the block runs
the block’s own from the list, newest first, and a cancellation runs every one reached since the
cancellation point it returns to before it drops their frames; a trap in an actor’s turn drops
the ones it passes unrun. A function that defers nothing never touches the list. The checker
checks the statement as a lambda of no parameters that no jump may leave, so a &lt;code&gt;var&lt;/code&gt; it reads is
shared as a captured one is. &lt;em&gt;Why&lt;/em&gt;: the cancellation unwinds by returning to the cancellation
point past every frame between, so what those frames deferred must be reachable from the thread
itself; a list costs a closure and two runtime calls per deferred statement and nothing anywhere
else. &lt;em&gt;Alternatives weighed&lt;/em&gt;: emitting each deferred statement inline at every exit, as before,
and a landing pad per function that defers (a &lt;code&gt;setjmp&lt;/code&gt; in every such call, with the locals it
reads unreliable after the return); a frame-local record pointing at a compiled cleanup function
(no allocation, but a new kind of stack object for the collector and the code generator).
&lt;strong&gt;Review with the user&lt;/strong&gt;: deferred statements now allocate a closure where they capture
anything, a cost on the ordinary path (&lt;code&gt;Mutex.with&lt;/code&gt; among them); a later pass could emit them
inline again where no cancellation point can be reached between the &lt;code&gt;defer&lt;/code&gt; and its block’s end.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;trait io.Close { close() -&amp;gt; Result[unit, IoError] }&lt;/code&gt;&lt;/strong&gt;, closing twice answering &lt;code&gt;Ok&lt;/code&gt;:
&lt;code&gt;fs.File&lt;/code&gt; (unchanged), the new &lt;code&gt;fs.TempDir&lt;/code&gt; from &lt;code&gt;fs.tempDir(prefix)&lt;/code&gt; (&lt;code&gt;close&lt;/code&gt; removes the tree),
every &lt;code&gt;net.ByteStream&lt;/code&gt;, &lt;code&gt;TcpListener&lt;/code&gt; and &lt;code&gt;UnixListener&lt;/code&gt; (their &lt;code&gt;close&lt;/code&gt; now answers &lt;code&gt;Ok(())&lt;/code&gt;
rather than &lt;code&gt;unit&lt;/code&gt;; &lt;code&gt;TlsStream&lt;/code&gt;‘s answers the failure to send its close notice), and
&lt;code&gt;process.Child&lt;/code&gt; (new &lt;code&gt;close&lt;/code&gt;: kill if not seen to end, then wait; a detached child is let be).
&lt;code&gt;Mutex.with&lt;/code&gt;/&lt;code&gt;update&lt;/code&gt; release their lock through &lt;code&gt;defer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Why&lt;/em&gt;: the paths that leak are early &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt; and &lt;code&gt;break&lt;/code&gt;, and only a construct the
compiler places at every exit covers them; a library &lt;code&gt;use(r)(body)&lt;/code&gt; puts the body in a lambda,
where a &lt;code&gt;return&lt;/code&gt;, a &lt;code&gt;?&lt;/code&gt; of the enclosing function, a &lt;code&gt;break&lt;/code&gt; or a &lt;code&gt;continue&lt;/code&gt; cannot be written at
all. Block scope (not function scope) gives back each loop turn’s resource before the next and
needs no run-time state; reading names at the exit needs no storage. The syntax and the rules
are Sysl’s own &lt;code&gt;defer&lt;/code&gt;, so the two languages read alike. &lt;code&gt;Close&lt;/code&gt; answers a &lt;code&gt;Result&lt;/code&gt; because a
flush, a removal and a wait can fail, and &lt;code&gt;File.close&lt;/code&gt; already did.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Alternatives weighed&lt;/em&gt;: a library &lt;code&gt;use(resource)(body)&lt;/code&gt; over a &lt;code&gt;Close&lt;/code&gt; trait (cannot leave the
enclosing function from the body; nests one lambda per resource); function-scoped &lt;code&gt;defer&lt;/code&gt;
evaluating its arguments where written (holds every turn’s resource until the function returns,
needs a run-time list); &lt;code&gt;try&lt;/code&gt;/&lt;code&gt;finally&lt;/code&gt; (a second block structure for one need); running deferred
statements on a trap (unwinding through a broken state); a &lt;code&gt;Close&lt;/code&gt; whose &lt;code&gt;close&lt;/code&gt; answers &lt;code&gt;unit&lt;/code&gt;
(would drop &lt;code&gt;File.close&lt;/code&gt;‘s flush error and a &lt;code&gt;TempDir&lt;/code&gt;‘s removal error); &lt;code&gt;use x = e&lt;/code&gt; binding sugar
over &lt;code&gt;defer x.close()&lt;/code&gt; (left for later; &lt;code&gt;defer&lt;/code&gt; covers it in one more line).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: whether discarding a &lt;code&gt;close&lt;/code&gt;‘s &lt;code&gt;Result&lt;/code&gt; in &lt;code&gt;defer&lt;/code&gt; deserves a warning;
whether &lt;code&gt;use x = e&lt;/code&gt; sugar is wanted.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;numeric&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Numeric&lt;/code&gt;, the numbers’ bound.&lt;/strong&gt; A core trait
&lt;code&gt;Numeric: Add, Sub, Mul, Div, Rem, Neg, Ord, Display, Debug&lt;/code&gt; declaring &lt;code&gt;toReal -&amp;gt; real&lt;/code&gt;; &lt;code&gt;Integer&lt;/code&gt;
now requires it (&lt;code&gt;trait Integer: Numeric&lt;/code&gt;), so every width meets it through one
&lt;code&gt;impl[T: Integer] Numeric for T&lt;/code&gt;, and &lt;code&gt;real&lt;/code&gt; has its own impl. Why: a mean, a clamp or a running
total over &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt; alike had no bound to name (&lt;code&gt;[T: Add]&lt;/code&gt; cannot reach a &lt;code&gt;real&lt;/code&gt;, and
&lt;code&gt;Integer&lt;/code&gt; excludes &lt;code&gt;real&lt;/code&gt;); taking every operator the integers and &lt;code&gt;real&lt;/code&gt; share (&lt;code&gt;Div&lt;/code&gt; and &lt;code&gt;Rem&lt;/code&gt;
included, though their meaning differs: integer division truncates and traps on zero) gives the
most generic code, and &lt;code&gt;zero&lt;/code&gt;/&lt;code&gt;one&lt;/code&gt; are already &lt;code&gt;Add&lt;/code&gt;‘s and &lt;code&gt;Mul&lt;/code&gt;‘s. Alternatives: only
&lt;code&gt;Add &amp;amp; Sub &amp;amp; Mul &amp;amp; Ord&lt;/code&gt; (the audit’s sketch), which leaves &lt;code&gt;/&lt;/code&gt; out of generic numeric code; a
&lt;code&gt;Numeric&lt;/code&gt; that also offered &lt;code&gt;fromInt&lt;/code&gt;/&lt;code&gt;T(n)&lt;/code&gt; construction, left out since &lt;code&gt;zero&lt;/code&gt;/&lt;code&gt;one&lt;/code&gt; cover the
identities and a conversion from integers is lossy at narrow widths; a separate &lt;code&gt;Fractional&lt;/code&gt; for
&lt;code&gt;real&lt;/code&gt;, not needed while &lt;code&gt;real&lt;/code&gt; is the one non-integer. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;Div&lt;/code&gt;
and &lt;code&gt;Rem&lt;/code&gt; belong in it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;numeric&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Numeric&lt;/code&gt; is open.&lt;/strong&gt; Unlike &lt;code&gt;Integer&lt;/code&gt;, a program’s own
type that implements the required traits and &lt;code&gt;toReal&lt;/code&gt; is a number (a rational type is the
example in the tests). Why: a library number type (a decimal, a rational, a fixed-point) should
reach every &lt;code&gt;[T: Numeric]&lt;/code&gt; function. Alternative: closed like &lt;code&gt;Integer&lt;/code&gt;, which would keep &lt;code&gt;toReal&lt;/code&gt;
meaningful only for built-ins at the cost of every user number.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;numeric&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;average&lt;/code&gt; totals as &lt;code&gt;real&lt;/code&gt; and traps when empty.&lt;/strong&gt;
&lt;code&gt;average&lt;/code&gt; on a collection of &lt;code&gt;Numeric&lt;/code&gt; elements is a &lt;code&gt;real&lt;/code&gt; mean summed through &lt;code&gt;toReal&lt;/code&gt;, so
integers whose sum overflows their type still average (beyond 2⁵³ the total rounds);
&lt;code&gt;average&lt;/code&gt; traps on an empty collection as &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; do, and &lt;code&gt;averageOption&lt;/code&gt; answers
&lt;code&gt;None&lt;/code&gt;. Alternatives: summing in &lt;code&gt;T&lt;/code&gt; and converting once (exact for small integers, but traps
where the mean is representable); NaN for an empty collection (silent, unlike &lt;code&gt;max&lt;/code&gt;); only
&lt;code&gt;averageOption&lt;/code&gt;. &lt;code&gt;sum&lt;/code&gt;, &lt;code&gt;product&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; were already generic over &lt;code&gt;Add&lt;/code&gt;, &lt;code&gt;Mul&lt;/code&gt; and &lt;code&gt;Ord&lt;/code&gt;
and are left as they were rather than duplicated on &lt;code&gt;Numeric&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;numeric&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;real(x)&lt;/code&gt; on a &lt;code&gt;Numeric&lt;/code&gt; parameter is refused, naming
&lt;code&gt;.toReal&lt;/code&gt;.&lt;/strong&gt; A call converts only a type parameter bounded by &lt;code&gt;Integer&lt;/code&gt;; a &lt;code&gt;T: Numeric&lt;/code&gt; converts
with its own method. Why: a conversion call on a type parameter is lowered per instance by the
compiler for integers only, while &lt;code&gt;toReal&lt;/code&gt; is an ordinary trait method a program’s own number
implements. Alternative: lower &lt;code&gt;real(x)&lt;/code&gt; to &lt;code&gt;x.toReal&lt;/code&gt; for a &lt;code&gt;Numeric&lt;/code&gt; parameter, more uniform
with the integers’ &lt;code&gt;real(x)&lt;/code&gt;, at the cost of a second meaning for a conversion call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;http-verbs&lt;/code&gt;): &lt;strong&gt;the HTTP client has a function per common verb, each taking
its headers.&lt;/strong&gt; &lt;code&gt;http.get&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;delete(url, headers = [])&lt;/code&gt;; &lt;code&gt;http.post&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt; and
&lt;code&gt;patch(url, body: string, contentType, headers = [])&lt;/code&gt;, the content type sent first and the body
as UTF-8. Headers are a &lt;code&gt;Vector[(string, string)]&lt;/code&gt;, as &lt;code&gt;Request&lt;/code&gt; and &lt;code&gt;Response&lt;/code&gt; already hold
them. Why: one call for the everyday request, with the shape &lt;code&gt;post&lt;/code&gt; already had; anything rarer
(another method, a byte body, a timeout, TLS settings) stays &lt;code&gt;send(Request(...))&lt;/code&gt;. Alternatives
weighed: an options record per call (a second way to spell &lt;code&gt;Request&lt;/code&gt;); a &lt;code&gt;Map&lt;/code&gt; for headers (loses
order and repeated names, which HTTP allows); byte-body overloads of &lt;code&gt;post&lt;/code&gt;/&lt;code&gt;put&lt;/code&gt;/&lt;code&gt;patch&lt;/code&gt; (left to
&lt;code&gt;Request.withBody&lt;/code&gt;, to keep one overload per verb).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;http-verbs&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;Request&lt;/code&gt;‘s headers are checked as it is made, those given to
its constructor too.&lt;/strong&gt; The constructor traps on a header name that is not a token or a value
holding a line break, as &lt;code&gt;withHeader&lt;/code&gt; did; before, a header passed to the constructor was written
unchecked, so a value holding &lt;code&gt;\r\n&lt;/code&gt; could add a header of its own. Why: a verb’s &lt;code&gt;headers&lt;/code&gt;
reach the constructor, so this is where every path meets. Alternative weighed: checking as the
head is written (as the server does for a &lt;code&gt;Response&lt;/code&gt;), which would trap later, away from the
code that built the request. &lt;code&gt;withHeaders(more)&lt;/code&gt; adds several in order.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;http-verbs&lt;/code&gt;): &lt;strong&gt;query parameters are added one at a time by
&lt;code&gt;Request.withQueryParam(name, value)&lt;/code&gt;&lt;/strong&gt;, each encoded by &lt;code&gt;Url.encode&lt;/code&gt; (so a space is &lt;code&gt;%20&lt;/code&gt;, not
&lt;code&gt;+&lt;/code&gt;), joined with &lt;code&gt;?&lt;/code&gt; or &lt;code&gt;&amp;amp;&lt;/code&gt; and placed before any fragment, by text on the request’s URL, which is
parsed only when sent. Why: the cheapest form that reads well in a chain and needs no parse that
could fail at build time. Alternatives weighed: a &lt;code&gt;query&lt;/code&gt; parameter on every verb (a fifth
parameter on &lt;code&gt;post&lt;/code&gt;/&lt;code&gt;put&lt;/code&gt;/&lt;code&gt;patch&lt;/code&gt;); a &lt;code&gt;Url.withQueryParam&lt;/code&gt; (useful too, but not needed for a
request); form encoding with &lt;code&gt;+&lt;/code&gt; (only &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; bodies need it).
Review with the user: whether the verbs should also take a &lt;code&gt;query&lt;/code&gt; vector.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;http-verbs&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Response.json(status, text: string)&lt;/code&gt; takes JSON already
written&lt;/strong&gt; and sends it as &lt;code&gt;application/json&lt;/code&gt; without checking it. Why: JSON lives in a package
today (moving to the standard library as &lt;code&gt;avin.json&lt;/code&gt;), and &lt;code&gt;avin.net.http&lt;/code&gt; must not depend on a
package; a text overload needs nothing. (JSON stays a package, &lt;code&gt;dev.avinlang.json&lt;/code&gt;, by the user’s
decision of 2026-11-13, so the text overload is the only one; a program passes &lt;code&gt;value.render&lt;/code&gt;.)
Alternatives weighed:
leaving &lt;code&gt;Response.json&lt;/code&gt; out until then (every JSON handler spells the content type by hand);
&lt;code&gt;charset=utf-8&lt;/code&gt; in the type (RFC 8259 defines none for &lt;code&gt;application/json&lt;/code&gt;). Review with the user:
the &lt;code&gt;Json&lt;/code&gt; overload once &lt;code&gt;avin.json&lt;/code&gt; lands.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;path-helpers&lt;/code&gt;): &lt;strong&gt;Paths are strings, and the path functions live in &lt;code&gt;avin.fs&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;path-helpers&lt;/code&gt;, 2026-11-12).
Proposed: no &lt;code&gt;Path&lt;/code&gt; type; &lt;code&gt;fs.join&lt;/code&gt;, &lt;code&gt;fs.parent&lt;/code&gt;, &lt;code&gt;fs.fileName&lt;/code&gt;, &lt;code&gt;fs.extension&lt;/code&gt;, &lt;code&gt;fs.stem&lt;/code&gt;,
&lt;code&gt;fs.normalize&lt;/code&gt;, &lt;code&gt;fs.relativeTo&lt;/code&gt;, &lt;code&gt;fs.components&lt;/code&gt;, &lt;code&gt;fs.isAbsolute&lt;/code&gt;/&lt;code&gt;isRelative&lt;/code&gt; take and answer
&lt;code&gt;string&lt;/code&gt;, bound to &lt;code&gt;sysl.path&lt;/code&gt;, and sit in &lt;code&gt;avin.fs&lt;/code&gt; beside the calls they feed. Why: every call
of &lt;code&gt;avin.fs&lt;/code&gt;, &lt;code&gt;avin.process&lt;/code&gt; and the rest already takes a &lt;code&gt;string&lt;/code&gt;, so a type would mean a
conversion at every call or a second overload of each; every &lt;code&gt;string&lt;/code&gt; method applies to a path as
it is; the separators and dots the functions look at are ASCII, so working on UTF-8 text is exact
for any name. Alternatives weighed: a &lt;code&gt;Path&lt;/code&gt; class with &lt;code&gt;/&lt;/code&gt; and methods (&lt;code&gt;p.parent&lt;/code&gt;), which reads
well but splits the library in two; a separate &lt;code&gt;avin.path&lt;/code&gt; module, which a program’s own
&lt;code&gt;path&lt;/code&gt; variable shadows at once (&lt;code&gt;fs.join&lt;/code&gt; cannot be shadowed by a local of that name). Review with
the user: whether a &lt;code&gt;Path&lt;/code&gt; type is wanted after all.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;path-helpers&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;walk&lt;/code&gt; answers a sorted vector, with an unreadable directory as an entry&lt;/strong&gt; (branch
&lt;code&gt;path-helpers&lt;/code&gt;). Proposed: &lt;code&gt;fs.walk(root) -&amp;gt; Result[Vector[Entry], IoError]&lt;/code&gt;, depth first, a
directory before its contents, each directory’s names in code-point order (as &lt;code&gt;listDir&lt;/code&gt;), the root
itself left out; &lt;code&gt;Entry(path, relative, depth, isDir, isLink, error)&lt;/code&gt;. A link is listed and never
followed (&lt;code&gt;isDir&lt;/code&gt; false for it), the root is followed when it is a link, and a directory that cannot
be listed is an entry whose &lt;code&gt;error&lt;/code&gt; holds the reason, the walk going on past it; only a root that
cannot be listed makes the whole walk an &lt;code&gt;Err&lt;/code&gt;. Why: one &lt;code&gt;?&lt;/code&gt; at the call and an ordinary &lt;code&gt;for&lt;/code&gt; over
the answer, deterministic order for tests and tools, no entry silently lost and no permission
problem deep in a tree spoiling the rest. Alternatives weighed: a lazy iterator of
&lt;code&gt;Result[Entry, IoError]&lt;/code&gt; with pruning (sysl’s shape: cheaper on a huge tree, but every item needs
its own &lt;code&gt;?&lt;/code&gt; and the order is the file system’s); failing the whole walk at the first error; skipping
unreadable directories silently; following links with cycle detection. Review with the user:
whether a lazy walk with pruning is wanted for very large trees.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;path-helpers&lt;/code&gt;): &lt;strong&gt;Pattern matching is by character, and &lt;code&gt;glob&lt;/code&gt; ignores what it cannot read&lt;/strong&gt; (branch
&lt;code&gt;path-helpers&lt;/code&gt;). Proposed: &lt;code&gt;fs.matches(pattern, path)&lt;/code&gt; is written in Avin rather than bound to
&lt;code&gt;sysl.path.matches&lt;/code&gt;: &lt;code&gt;?&lt;/code&gt; and a class take one &lt;em&gt;character&lt;/em&gt;, so &lt;code&gt;?.txt&lt;/code&gt; fits &lt;code&gt;文.txt&lt;/code&gt;. Pattern and path
are compared component by component (doubled and trailing &lt;code&gt;/&lt;/code&gt; do not matter, an absolute pattern fits
only an absolute path); &lt;code&gt;**&lt;/code&gt; as a whole component is zero or more components; a name starting with &lt;code&gt;.&lt;/code&gt;
is fitted only by a component starting with a literal &lt;code&gt;.&lt;/code&gt; (not &lt;code&gt;?&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; or &lt;code&gt;[.]&lt;/code&gt;), and &lt;code&gt;**&lt;/code&gt; does not
pass through one; an unclosed &lt;code&gt;[&lt;/code&gt; is a literal &lt;code&gt;[&lt;/code&gt; and a trailing &lt;code&gt;\&lt;/code&gt; a literal &lt;code&gt;\&lt;/code&gt;, so every pattern
is valid and &lt;code&gt;matches&lt;/code&gt; never fails. &lt;code&gt;fs.glob(pattern) -&amp;gt; Vector[string]&lt;/code&gt; expands component by
component, answers sorted and without repeats, follows a link named by a literal or wildcard
component but not under &lt;code&gt;**&lt;/code&gt;, and treats a directory it cannot read as empty. Why: Avin strings are
characters, and a byte &lt;code&gt;?&lt;/code&gt; would match a third of &lt;code&gt;文&lt;/code&gt;; component-wise matching makes &lt;code&gt;glob&lt;/code&gt;‘s answers
fit &lt;code&gt;matches&lt;/code&gt; by construction; the shell’s hidden-name rule keeps &lt;code&gt;**&lt;/code&gt; out of &lt;code&gt;.git&lt;/code&gt;. Alternatives
weighed: binding sysl’s byte matcher (one third of a character per &lt;code&gt;?&lt;/code&gt;); an &lt;code&gt;Err&lt;/code&gt; for a malformed
pattern (a &lt;code&gt;Result&lt;/code&gt; on every &lt;code&gt;matches&lt;/code&gt; call for a case a literal reading answers); &lt;code&gt;glob&lt;/code&gt; answering
&lt;code&gt;Result&lt;/code&gt; (an error deep in a tree would lose the rest, as with &lt;code&gt;walk&lt;/code&gt;, and a pattern has no single
directory whose failure should be the answer). Review with the user: brace alternatives &lt;code&gt;{a,b}&lt;/code&gt;,
left out.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;path-helpers&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;isDir&lt;/code&gt; and &lt;code&gt;isFile&lt;/code&gt; ask &lt;code&gt;stat&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;path-helpers&lt;/code&gt;). Proposed: &lt;code&gt;fs.isDir&lt;/code&gt; was bound to
&lt;code&gt;sysl.fs.is_dir&lt;/code&gt;, which opens the path as a directory, so a directory the program may not read
answered &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;isFile&lt;/code&gt; (&lt;code&gt;exists &amp;amp;&amp;amp; !isDir&lt;/code&gt;) answered &lt;code&gt;true&lt;/code&gt; for it; both now read the same
&lt;code&gt;stat&lt;/code&gt; as &lt;code&gt;metadata&lt;/code&gt;. Why: the chapter says &lt;code&gt;isDir&lt;/code&gt; is whether the path names a directory, and
&lt;code&gt;walk&lt;/code&gt; needs the kind of an unreadable directory to report it. Alternatives weighed: keeping the
opening check (a permission answer dressed as a kind).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;text-papercuts&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;sortedDescending&lt;/code&gt; on every &lt;code&gt;Seq&lt;/code&gt; of &lt;code&gt;Ord&lt;/code&gt;
elements (a &lt;code&gt;List&lt;/code&gt;‘s answering a &lt;code&gt;List&lt;/code&gt;), and &lt;code&gt;sortInPlaceDescending()&lt;/code&gt; on arrays, buffers and
deques&lt;/strong&gt;, beside &lt;code&gt;Reverse&lt;/code&gt;, which stays the way to sort descending by a key. This amends the
settled &lt;code&gt;Reverse&lt;/code&gt; entry, which had chosen no &lt;code&gt;sortedDescending&lt;/code&gt;. Why: the whole-element case is the
common one (top scores, largest files), &lt;code&gt;sortBy(x -&amp;gt; Reverse(x))&lt;/code&gt; is a detour for it, and the
obvious spelling a program reaches for instead, &lt;code&gt;sorted.reverse&lt;/code&gt;, is quietly wrong for elements
that compare equal but differ, since it turns their order round; a stable descending sort keeps
it. No &lt;code&gt;sortByDescending&lt;/code&gt;: a key turned round is &lt;code&gt;Reverse(key)&lt;/code&gt;, which also composes inside a
tuple key, so a second spelling would add nothing. Alternatives weighed: keep &lt;code&gt;Reverse&lt;/code&gt; alone (the
settled choice; the gap audit’s programs did not find it); &lt;code&gt;sortByDescending(key)&lt;/code&gt; as well (two
ways to write one thing); a &lt;code&gt;descending&lt;/code&gt; flag on &lt;code&gt;sorted&lt;/code&gt; (a boolean argument reads poorly at the
call). &lt;strong&gt;Review with the user&lt;/strong&gt;: it reverses a settled choice.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;text-papercuts&lt;/code&gt;): &lt;strong&gt;the &lt;code&gt;,&lt;/code&gt; format flag groups a decimal integer’s
digits in threes with commas&lt;/strong&gt;, under &lt;code&gt;%d&lt;/code&gt; and &lt;code&gt;%i&lt;/code&gt; only; under every other conversion it is the
“has no effect” error. The zeros of a precision are grouped with the digits (&lt;code&gt;${5}%,.6d&lt;/code&gt; is
&lt;code&gt;000,005&lt;/code&gt;), but the zeros of the &lt;code&gt;0&lt;/code&gt; flag are not: they fill the width before the grouped digits,
the commas and the sign counting in it, so the field is never wider than asked unless the number
is (&lt;code&gt;${1234}%0,8d&lt;/code&gt; is &lt;code&gt;0001,234&lt;/code&gt;, &lt;code&gt;${-1234}%0,8d&lt;/code&gt; is &lt;code&gt;-001,234&lt;/code&gt;). &lt;code&gt;FormatSpec&lt;/code&gt; gains
&lt;code&gt;grouping: bool = false&lt;/code&gt; as its last field, so code that builds one by position is unchanged.
Why: a width is a column’s width, and a column that a comma can widen by one does not line up;
precision zeros are digits of the number, fill zeros are padding. Alternatives weighed: grouping
the fill zeros too, added until the field is full (&lt;code&gt;0,001,234&lt;/code&gt; for width 8: one wider than asked);
&lt;code&gt;_&lt;/code&gt; or a locale’s
separator (no locale exists; a comma is the common reading); allowing &lt;code&gt;,&lt;/code&gt; under &lt;code&gt;%f&lt;/code&gt; (a real’s
grouping is a separate item, not asked for yet). Always a comma, never locale-dependent.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;text-papercuts&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;string.utf8&lt;/code&gt; answers a new &lt;code&gt;Array[byte]&lt;/code&gt;&lt;/strong&gt;, a
parameterless member as &lt;code&gt;bytes&lt;/code&gt; is, the array the caller’s own on every call. Why: files, sockets
and request bodies take an &lt;code&gt;Array[byte]&lt;/code&gt;, and &lt;code&gt;s.bytes.toArray()&lt;/code&gt; built a vector only to copy it.
Alternatives weighed: &lt;code&gt;toUtf8()&lt;/code&gt; with parentheses (it is a pure conversion, so the parameterless
rule writes it bare); answering a frozen, shared view (an &lt;code&gt;Array&lt;/code&gt; is mutable, so sharing would let
one caller change another’s bytes).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;dot-chain&lt;/code&gt;): &lt;strong&gt;a line that starts with a member’s &lt;code&gt;.&lt;/code&gt;, indented deeper than the
line its expression began on, continues that expression&lt;/strong&gt;, exactly as a line starting with a binary
operator does: in the same places (a binding’s value, an assignment, a &lt;code&gt;return&lt;/code&gt; value, an infix
call’s argument, a &lt;code&gt;match&lt;/code&gt; arm’s or a lambda’s body, a branch of a one-line &lt;code&gt;if&lt;/code&gt;, an expression
statement, a trailing lambda’s body), never in the header of a form whose body follows, with blank
lines and comments between skipped, and ending at the first line back at the depth the expression
began on. &lt;code&gt;.&lt;/code&gt; and the binary operators may alternate line by line, and a call’s trailing block
ending inside the chain lets the next &lt;code&gt;.&lt;/code&gt; line go on after it. The line break means nothing to
binding: &lt;code&gt;.&lt;/code&gt; takes the operand right before it, so &lt;code&gt;a + b&lt;/code&gt; then &lt;code&gt;    .toString&lt;/code&gt; is
&lt;code&gt;a + b.toString&lt;/code&gt;, as on one line. An indented line after a call that starts with &lt;code&gt;.&lt;/code&gt; is a
continuation, not the call’s trailing block. The error for a line inside a continuation that
starts with neither now says “a binary operator or &lt;code&gt;.&lt;/code&gt;“. &lt;em&gt;Why&lt;/em&gt;: a pipeline of &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt; and
a builder’s &lt;code&gt;.get(…)&lt;/code&gt; calls reads one step per line, and wrapping it in parentheses to get there
was the only way before (audit item C2; the &lt;code&gt;lwt-server&lt;/code&gt; routing entry chose a vector over a
builder for this reason). Reusing the operator continuation keeps one rule for where an expression
may go on, and the line break meaning nothing keeps one rule for precedence. &lt;em&gt;Alternatives&lt;/em&gt;: a
&lt;code&gt;.&lt;/code&gt; line binding to the whole expression above (&lt;code&gt;(a + b).toString&lt;/code&gt;), which reads naturally for a
chain after an operator but makes the line break change meaning, unlike every operator line;
requiring a chain to start on its own line (&lt;code&gt;val ys =&lt;/code&gt; then the receiver and the dots on deeper
lines), which adds nothing the depth rule does not already say; a trailing &lt;code&gt;.&lt;/code&gt; at the end of the
line above, which hides the call being made. Review with the user whether &lt;code&gt;.&lt;/code&gt; after an operator
line should bind to the whole expression instead.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;nothing-conversion&lt;/code&gt;): &lt;strong&gt;A function whose result is &lt;code&gt;Nothing&lt;/code&gt; converts to one of another result where it is written, as a
lambda calling it, and not inside another type&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#any-and-nothing&quot;&gt;types&lt;/a&gt;; branch
&lt;code&gt;nothing-conversion&lt;/code&gt;). The subtyping rules already made &lt;code&gt;(A) -&amp;gt; Nothing&lt;/code&gt; a subtype of every
&lt;code&gt;(A) -&amp;gt; R&lt;/code&gt;, but no function value of it was accepted where one was expected (only a lambda whose
body never finishes, checked against the expected type), while an inferred type argument let one
through with no conversion, and the call through the wider type then called code yielding no value
as code yielding one. A call of a &lt;code&gt;Nothing&lt;/code&gt; function yields no value at all, and one of an
&lt;code&gt;(A) -&amp;gt; R&lt;/code&gt; yields an &lt;code&gt;R&lt;/code&gt;, so the two are laid out differently and one is not the other as it
stands. The choice: at a declared type, an argument (after inference too), a result, a field, and
the branches of an &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt; or elements of a collection literal, the value is evaluated once
into a local and made a lambda of the expected type calling it (a named function is called by name
and nothing is captured, so it may be &lt;code&gt;@sendable&lt;/code&gt;); nested results (&lt;code&gt;() -&amp;gt; () -&amp;gt; Nothing&lt;/code&gt;) convert
one level at a time. Parameters keep their variance; a &lt;code&gt;Vector[(int) -&amp;gt; Nothing]&lt;/code&gt; is no
&lt;code&gt;Vector[(int) -&amp;gt; int]&lt;/code&gt;, as a &lt;code&gt;Vector[int]&lt;/code&gt; is no &lt;code&gt;Vector[Any]&lt;/code&gt;. Why: it gives the subtyping rule
its meaning with no change to how functions are called, and matches how a value of a value type
becomes an &lt;code&gt;Any&lt;/code&gt; or a trait (at the site, never inside a container). Alternatives weighed: a view
with no conversion, the closure’s entry for a &lt;code&gt;Nothing&lt;/code&gt; result answering every result’s layout
(impossible in one entry: an &lt;code&gt;int&lt;/code&gt;, a &lt;code&gt;real&lt;/code&gt;, a reference and no value are returned differently);
a dedicated adapter node in lowering (the same conversion, built by hand rather than as a checked
lambda); refusing the conversion and keeping only lambdas (contradicts the subtyping rule, and the
inferred case had to be closed anyway). Review with the user: whether a function held inside a
collection should convert too, which needs a copy of the collection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;numeric-widths&lt;/code&gt;): &lt;strong&gt;numbers have &lt;code&gt;toInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toReal&lt;/code&gt; as
parameterless members, each exactly the conversion call of its type.&lt;/strong&gt; Every integer type has
&lt;code&gt;n.toInt&lt;/code&gt; and &lt;code&gt;n.toLong&lt;/code&gt; (&lt;code&gt;int(n)&lt;/code&gt;, &lt;code&gt;long(n)&lt;/code&gt;: a narrowing one traps when the value does not fit,
as the call does); &lt;code&gt;real&lt;/code&gt; has &lt;code&gt;x.toInt&lt;/code&gt; and &lt;code&gt;x.toLong&lt;/code&gt; (&lt;code&gt;int(x)&lt;/code&gt;, &lt;code&gt;long(x)&lt;/code&gt;: truncation toward zero,
saturation at the bounds, NaN to zero); &lt;code&gt;toReal&lt;/code&gt; was already &lt;code&gt;Numeric&lt;/code&gt;‘s. They are members of the
integer family’s impl and of &lt;code&gt;real&lt;/code&gt;‘s, not of &lt;code&gt;Numeric&lt;/code&gt;, so a number type of a program’s own owes
only &lt;code&gt;toReal&lt;/code&gt;. WHY: &lt;code&gt;string.toLong()&lt;/code&gt; and &lt;code&gt;xs.sum.toReal&lt;/code&gt; put conversions where a reader reaches for
them, and &lt;code&gt;n.toLong&lt;/code&gt; answering &lt;code&gt;int has no field `toLong` &lt;/code&gt; was the surprise; making the member the
call, rather than a second semantics, keeps one rule for what a conversion does. A narrowing
&lt;code&gt;toInt&lt;/code&gt; traps, as &lt;code&gt;string.toInt()&lt;/code&gt; traps on a number that does not fit and as &lt;code&gt;int(n)&lt;/code&gt; does, so the
trap/&lt;code&gt;Option&lt;/code&gt; split stays where it is (&lt;code&gt;toIntOption()&lt;/code&gt; is for text, whose failure is the input’s).
ALTERNATIVES: no members, only a hint naming &lt;code&gt;long(n)&lt;/code&gt; (leaves &lt;code&gt;toReal&lt;/code&gt; the odd one out); a
narrowing &lt;code&gt;toInt&lt;/code&gt; answering &lt;code&gt;Option[int]&lt;/code&gt; (differs from &lt;code&gt;int(n)&lt;/code&gt; and from &lt;code&gt;string.toInt()&lt;/code&gt;); no
narrowing members at all, &lt;code&gt;toLong&lt;/code&gt; only (an &lt;code&gt;int&lt;/code&gt; from a &lt;code&gt;long&lt;/code&gt; is as common as the reverse); members
on &lt;code&gt;byte&lt;/code&gt; too (a byte is not a number, and &lt;code&gt;int(b)&lt;/code&gt; reads as what it is). Review with the user:
whether &lt;code&gt;real.toInt&lt;/code&gt; should trap on NaN and out-of-range values instead of saturating, as
&lt;code&gt;string.toInt()&lt;/code&gt; traps on text that is no number.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;numeric-widths&lt;/code&gt;): &lt;strong&gt;mixed-width arithmetic stays an error, and its diagnostic
names the conversion&lt;/strong&gt;, pointing at the operand to convert: &lt;code&gt;error: `*` needs two numbers of one type, not long and int; write `long(n)` &lt;/code&gt;, the operand quoted as written (or, when it is longer
than 40 bytes or spans lines, &lt;code&gt;convert the int with a call of `long` &lt;/code&gt;). The narrower integer
converts to the wider, an integer or a byte to &lt;code&gt;real&lt;/code&gt;, a byte to an integer, an integer to a type
parameter bounded by &lt;code&gt;Integer&lt;/code&gt; (&lt;code&gt;T(n)&lt;/code&gt;), and a value of a &lt;code&gt;Numeric&lt;/code&gt; parameter to &lt;code&gt;real&lt;/code&gt; by
&lt;code&gt;x.toReal&lt;/code&gt;. Comparisons (&lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt;, …, each link of a chain) say the same. A compound
assignment’s target keeps its type, so there the value converts to it, a narrowing call included
(&lt;code&gt;n -= total&lt;/code&gt; suggests &lt;code&gt;int(total)&lt;/code&gt;). A &lt;code&gt;char&lt;/code&gt; beside a number gets no conversion hint: it is no
number, and &lt;code&gt;&apos;-&apos; * 3&lt;/code&gt; meant &lt;code&gt;repeat&lt;/code&gt;. WHY: the spec settles that integers are never widened
implicitly; the error was right and only lacked the fix. ALTERNATIVES: implicit widening (contrary
to the settled rule); pointing at the whole operation (the hint names one operand, so the caret
should too); suggesting a narrowing of the wider operand (loses values).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;diag-spans-recovery&lt;/code&gt;): &lt;strong&gt;Parse recovery and the hints for &lt;code&gt;Map(k -&amp;gt; v)&lt;/code&gt; and an argument’s type&lt;/strong&gt; (branch
&lt;code&gt;diag-spans-recovery&lt;/code&gt;). A line of a block, class, actor or machine the parser cannot read to its
end is skipped to the next line, and reported only when nothing in it was reported already; an
argument list or parenthesized group meeting a token other than &lt;code&gt;,&lt;/code&gt; or &lt;code&gt;)&lt;/code&gt; reports it once and
skips to its &lt;code&gt;)&lt;/code&gt;. &lt;code&gt;-&amp;gt;&lt;/code&gt; there says “write a map as &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;“ when the callee’s name ends in &lt;code&gt;Map&lt;/code&gt;
and “&lt;code&gt;-&amp;gt;&lt;/code&gt; does not pair two values: write a pair as &lt;code&gt;(a, b)&lt;/code&gt;, and a map as &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;“ otherwise;
and “a lambda’s parameter with a type is written in parentheses” when &lt;code&gt;: T -&amp;gt;&lt;/code&gt; follows a name.
WHY: one mistake made five to ten errors,
each naming a token rather than the mistake, and the token shows exactly which mistake it is.
ALTERNATIVES: suppressing every error after the first in a statement (panic mode), which also
hides a genuinely separate mistake on the same line; accepting &lt;code&gt;k -&amp;gt; v&lt;/code&gt; as a pair (a second
spelling of a tuple, and &lt;code&gt;x -&amp;gt; body&lt;/code&gt; is a lambda). The hints this entry first gave for &lt;code&gt;x: T&lt;/code&gt; in
an argument or a group (“give the type argument instead”, “declare the value with it”) are gone:
&lt;code&gt;x: T&lt;/code&gt; there is now a &lt;a href=&quot;#proposed&quot;&gt;type ascription&lt;/a&gt; (the user approved ascription 2026-11-13).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;diag-spans-recovery&lt;/code&gt;): &lt;strong&gt;A member’s mistake is shown at the member&lt;/strong&gt; (branch &lt;code&gt;diag-spans-recovery&lt;/code&gt;). The checker reports
a missing or private member, an argument-count mistake and &lt;code&gt;()&lt;/code&gt; on a parameterless member at the
member’s name and argument list; the call’s own span, used for a type mismatch and for traps,
stays the whole expression. WHY: in a chain written over leading-&lt;code&gt;.&lt;/code&gt; lines the whole span starts
lines above the member at fault, and the rendering shows only its first line. ALTERNATIVES:
narrowing the call’s span itself (a wrong-type value would then be shown at its last member only);
storing the name’s span in the syntax tree (every &lt;code&gt;Member&lt;/code&gt; match changes, for a span the source
already determines).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;argparse&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.cli&lt;/code&gt;: a declared parser read by name&lt;/strong&gt; (branch &lt;code&gt;argparse&lt;/code&gt;). Proposed: the standard
library’s argument parser is a &lt;code&gt;Parser&lt;/code&gt; value built by chained declarations (&lt;code&gt;flag&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;,
&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;choice&lt;/code&gt;, &lt;code&gt;positional&lt;/code&gt;, &lt;code&gt;positionals&lt;/code&gt;, each with named &lt;code&gt;short&lt;/code&gt;, &lt;code&gt;help&lt;/code&gt;, &lt;code&gt;default&lt;/code&gt;,
&lt;code&gt;required&lt;/code&gt;, &lt;code&gt;repeated&lt;/code&gt;, &lt;code&gt;value&lt;/code&gt;), and &lt;code&gt;parse(args)&lt;/code&gt; answers &lt;code&gt;Result[Args, ArgsError]&lt;/code&gt;; values are
asked for by name and type (&lt;code&gt;a.int(&amp;quot;top&amp;quot;)&lt;/code&gt;, &lt;code&gt;a.strings(&amp;quot;file&amp;quot;)&lt;/code&gt;), and asking for an undeclared
name or the wrong type traps. &lt;code&gt;parseOrExit&lt;/code&gt; covers the usual &lt;code&gt;main&lt;/code&gt;: help or version to standard
output and status 0, a mistake to standard error with the usage line and status 2. Why: it needs
no language feature, a program reads in the order its help does, and every mistake a user can
make is a value with a sentence naming what they wrote. Alternatives weighed: deriving a parser
from a &lt;code&gt;data&lt;/code&gt; type’s fields (&lt;code&gt;data Options(...) derives Args&lt;/code&gt;), which checks names at compile time
but needs a derivation and a way to attach help, short letters and defaults to fields; a
getopt-style loop the program drives, which is what &lt;code&gt;wc&lt;/code&gt; hand-rolled; one getter returning
&lt;code&gt;Option&lt;/code&gt; for everything, which makes every read a &lt;code&gt;match&lt;/code&gt;. Review with the user: whether a
derived form is wanted on top of this one.
The rules it settles, each the common command-line convention: &lt;code&gt;--name=value&lt;/code&gt; and &lt;code&gt;--name value&lt;/code&gt;
alike; bundled letters (&lt;code&gt;-lw&lt;/code&gt;, &lt;code&gt;-n5&lt;/code&gt;, &lt;code&gt;-lwn5&lt;/code&gt;); an option’s value is the next argument whatever
it starts with (&lt;code&gt;--top -1&lt;/code&gt;); &lt;code&gt;-&lt;/code&gt; alone and the empty argument are positional; &lt;code&gt;--&lt;/code&gt; ends the
options; options and arguments interleave; a single option given twice keeps the last (so an
alias’s option can be overridden), a &lt;code&gt;repeated&lt;/code&gt; one keeps all, and a flag is counted (&lt;code&gt;-vvv&lt;/code&gt;).
Every parser has &lt;code&gt;--help&lt;/code&gt;/&lt;code&gt;-h&lt;/code&gt;, and &lt;code&gt;--version&lt;/code&gt; where it has a version, unless the program
declares that name or letter itself; each acts where it stands, left to right. An option with no
&lt;code&gt;default&lt;/code&gt; reads as its type’s zero (&lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;0.0&lt;/code&gt;) and &lt;code&gt;given(name)&lt;/code&gt; tells whether it was on
the command line; the help shows a default only where it is not that zero, since a default
parameter cannot tell an explicit zero from an omitted one. Every option has a long name (the
name &lt;code&gt;Args&lt;/code&gt; looks it up by); positional arguments are strings. The reasons read &lt;code&gt;unknown option `--x` &lt;/code&gt;, &lt;code&gt;`--count` needs an int, not `abc`&lt;/code&gt; and &lt;code&gt;`--scale` needs a number, not `x`&lt;/code&gt;
(a user of the program knows “number” better than “real”). Alternatives weighed: refusing an
option given twice (catches typos, breaks overriding an alias); refusing a value that starts with
&lt;code&gt;-&lt;/code&gt; unless it is a number; typed positional arguments, left out until a program needs one;
&lt;code&gt;Option&lt;/code&gt;-typed defaults (&lt;code&gt;default = Some(3)&lt;/code&gt;), exact but noisy at every declaration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (built on branch &lt;code&gt;cli-subcommands&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.cli&lt;/code&gt;
commands are parsers of their own.&lt;/strong&gt; &lt;code&gt;Parser.command(sub)&lt;/code&gt; adds the command &lt;code&gt;sub.name&lt;/code&gt;, whose
options and arguments &lt;code&gt;sub&lt;/code&gt; declares and whose help line is &lt;code&gt;sub.about&lt;/code&gt;; a command may have
commands (&lt;code&gt;git remote add&lt;/code&gt;). The first positional argument names the command and every argument
after it is the command’s, so the program’s options come before the command word and the
command’s after it (&lt;code&gt;todo --file t.txt add -p high milk&lt;/code&gt;); a parser with commands takes no
positional arguments, and declaring both traps. &lt;code&gt;Args.command&lt;/code&gt; is the command’s name (empty where
the parser has none) and &lt;code&gt;Args.commandArgs&lt;/code&gt; the command’s own &lt;code&gt;Args&lt;/code&gt;. While a command reads its
arguments its parser is named after the program and the command, so its usage line, help and
messages say &lt;code&gt;todo add&lt;/code&gt;. Every parser with commands has the command &lt;code&gt;help&lt;/code&gt; (&lt;code&gt;todo help add&lt;/code&gt;,
&lt;code&gt;todo help remote add&lt;/code&gt;) unless the program declares one of that name, as with &lt;code&gt;--help&lt;/code&gt;; &lt;code&gt;todo add --help&lt;/code&gt; is the command’s own. No command is &lt;code&gt;missing command; the commands are `add`, …&lt;/code&gt;; an
unknown one is &lt;code&gt;unknown command `lst`; did you mean `list`?&lt;/code&gt;, the suggestion being the nearest
name within two edits (fewer than the word’s characters), else the one name the word begins,
else the list of commands. WHY: a sub-parser is the value a program already knows how to build,
so a command needs no new kind of declaration, and nesting comes free; reading only the program’s
options before the word is the convention every tool with commands follows, and keeps a
command’s options free to reuse the program’s names. Alternatives weighed:
&lt;code&gt;command(name, help, sub)&lt;/code&gt; (repeats what &lt;code&gt;sub&lt;/code&gt; already holds); a dispatch table of functions
(&lt;code&gt;command(sub, run)&lt;/code&gt;) that &lt;code&gt;parse&lt;/code&gt; would call, which hides control flow and fixes a return type
on every command; options of the program accepted after the command word too (ambiguous where
both declare a name); a missing command printing the help instead of a mistake; matching
commands by unique prefix outright (&lt;code&gt;todo l&lt;/code&gt; running &lt;code&gt;list&lt;/code&gt;), which turns a later command into a
breaking change. Review with the user: whether a missing command should show the help (git’s
way) rather than be a mistake.
&lt;strong&gt;A mistake is reportable without ending the program.&lt;/strong&gt; &lt;code&gt;ArgsError.Invalid&lt;/code&gt; gains &lt;code&gt;program&lt;/code&gt;
(the name of the parser that found it, &lt;code&gt;todo add&lt;/code&gt;) and &lt;code&gt;hint&lt;/code&gt; (&lt;code&gt;Run `todo add --help` for the options.&lt;/code&gt;, &lt;code&gt;Run `todo --help` for the commands.&lt;/code&gt;, or &lt;code&gt;help&lt;/code&gt; where &lt;code&gt;--help&lt;/code&gt; is the program’s
own, or empty), so &lt;code&gt;Invalid(reason, usage, program, hint)&lt;/code&gt;; &lt;code&gt;ArgsError.report&lt;/code&gt; is the whole
text &lt;code&gt;parseOrExit&lt;/code&gt; writes, every line ending in a newline, and &lt;code&gt;exitCode&lt;/code&gt; its status (0 for the
help or the version, 2 for a mistake). A shell or script runner calls &lt;code&gt;parse&lt;/code&gt;, writes
&lt;code&gt;e.report&lt;/code&gt; and reads the next line; &lt;code&gt;message&lt;/code&gt; and the &lt;code&gt;Display&lt;/code&gt; stay the reason alone, so an
&lt;code&gt;ArgsError&lt;/code&gt; passed on with &lt;code&gt;?&lt;/code&gt; still reads as one sentence. WHY: the error must carry the
failing command’s name, since only it knows it; a parser method &lt;code&gt;report(e)&lt;/code&gt; would name the
top program for a command’s mistake. Alternatives weighed: keeping &lt;code&gt;Invalid(reason, usage)&lt;/code&gt; and
folding the name into &lt;code&gt;usage&lt;/code&gt; (changes what the field means); making the &lt;code&gt;Display&lt;/code&gt; the whole
report (a multi-line display breaks error chaining). Review with the user: the two new fields
change &lt;code&gt;Invalid&lt;/code&gt;‘s shape, so a program matching &lt;code&gt;Invalid(reason, usage)&lt;/code&gt; must add &lt;code&gt;_, _&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;small-papercuts&lt;/code&gt;): &lt;strong&gt;one family of case names, &lt;code&gt;toUpper&lt;/code&gt; and &lt;code&gt;toLower&lt;/code&gt;, for
&lt;code&gt;char&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt; alike.&lt;/strong&gt; &lt;code&gt;string.toUpperCase&lt;/code&gt; and &lt;code&gt;toLowerCase&lt;/code&gt; are renamed to &lt;code&gt;toUpper&lt;/code&gt; and
&lt;code&gt;toLower&lt;/code&gt;, the names &lt;code&gt;char&lt;/code&gt; already had, across the library, its tests, the corpus, the scripts
and the spec; &lt;code&gt;&amp;quot;a&amp;quot;.toUpperCase&lt;/code&gt; is refused with &lt;code&gt;string has no field `toUpperCase`; a string maps its case with `toUpper` and `toLower`, as a `char` does&lt;/code&gt;. WHY: one name for one operation
on both types, and the shorter one, which conflicts with nothing on either type. There is no
deprecation mechanism to keep the old names as aliases, so the old names are gone and the error
names the new ones. ALTERNATIVES: rename &lt;code&gt;char&lt;/code&gt;‘s to &lt;code&gt;toUpperCase&lt;/code&gt; (longer, and &lt;code&gt;isUpper&lt;/code&gt;/&lt;code&gt;isLower&lt;/code&gt;
on &lt;code&gt;char&lt;/code&gt; would then disagree with it); keep both names on &lt;code&gt;string&lt;/code&gt; as plain aliases (two names for
one method forever, with no way to retire one). Review with the user: it breaks source using the
old names (marshal, tui and typing-practice use them), so their call sites change in the release
that carries it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;small-papercuts&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin&lt;/code&gt; takes its options before or after the program.&lt;/strong&gt;
The program is the first argument that is neither an option nor an option’s value, wherever it
stands before &lt;code&gt;run&lt;/code&gt;‘s &lt;code&gt;--&lt;/code&gt;; for &lt;code&gt;avin test&lt;/code&gt;, only an existing path is the program and any other
word is the filter, as before. &lt;code&gt;avin run -O2 main.avin&lt;/code&gt;, &lt;code&gt;avin run main.avin -O2&lt;/code&gt;,
&lt;code&gt;avin -O2 main.avin&lt;/code&gt; and &lt;code&gt;avin build -o out -O0 main.avin&lt;/code&gt; are all accepted, and only what follows
&lt;code&gt;--&lt;/code&gt; reaches the program. A first argument that is any option (not only &lt;code&gt;-O0&lt;/code&gt;, &lt;code&gt;-O2&lt;/code&gt; or &lt;code&gt;--&lt;/code&gt;) now
means &lt;code&gt;avin run&lt;/code&gt;, which checks the options itself. WHY: the audit’s &lt;code&gt;avin run -O2 file.avin&lt;/code&gt;
printed the whole usage; the order of avin’s own options carries no meaning, and &lt;code&gt;--&lt;/code&gt; already
separates the program’s arguments. ALTERNATIVES: options after the program only, with an error
saying so (keeps a rule nobody needs); treating words after the program as its arguments without
&lt;code&gt;--&lt;/code&gt; (makes &lt;code&gt;avin run main.avin -O2&lt;/code&gt; pass &lt;code&gt;-O2&lt;/code&gt; to the program, which surprises in the other
direction). One exception, from branch &lt;code&gt;script-deps&lt;/code&gt; (below): &lt;code&gt;avin &amp;lt;file&amp;gt; ...&lt;/code&gt;, with no command
word, for a file whose first line begins &lt;code&gt;#!&lt;/code&gt;, gives every argument after the file to the program,
since that is how a &lt;code&gt;#!/usr/bin/env avin&lt;/code&gt; line runs it as a command.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;small-papercuts&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Result.toOption&lt;/code&gt; beside &lt;code&gt;ok&lt;/code&gt;, and &lt;code&gt;StringWriter&lt;/code&gt; is
&lt;code&gt;Display&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;toOption&lt;/code&gt; answers exactly what &lt;code&gt;ok&lt;/code&gt; does, under the name &lt;code&gt;Either&lt;/code&gt; and the
collections use; &lt;code&gt;ok&lt;/code&gt; stays. &lt;code&gt;StringWriter&lt;/code&gt; implements &lt;code&gt;Display&lt;/code&gt; (its &lt;code&gt;text&lt;/code&gt;, padded to a field’s
width, as a string) and &lt;code&gt;toString()&lt;/code&gt; returns its &lt;code&gt;text&lt;/code&gt;. WHY: the names people reach for first,
and a writer that interpolates as what it holds. ALTERNATIVES: renaming &lt;code&gt;ok&lt;/code&gt; to &lt;code&gt;toOption&lt;/code&gt;
(breaks callers for no gain; &lt;code&gt;ok&lt;/code&gt;/&lt;code&gt;err&lt;/code&gt; read as a pair); a &lt;code&gt;StringWriter&lt;/code&gt; with &lt;code&gt;toString()&lt;/code&gt; only
(it would still show as its type’s name in &lt;code&gt;s&amp;quot;$w&amp;quot;&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;small-papercuts&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;t._1&lt;/code&gt; on a tuple names the part to write.&lt;/strong&gt; A member
&lt;code&gt;_&lt;/code&gt; followed by decimal digits asked of a tuple adds &lt;code&gt;; a tuple&apos;s parts are numbered from 0, so write `.n-1` &lt;/code&gt; when &lt;code&gt;1 &amp;lt;= n &amp;lt;=&lt;/code&gt; its arity, and &lt;code&gt;; a tuple&apos;s parts are numbered from 0 and read as `.0` to `.k` &lt;/code&gt; otherwise (&lt;code&gt;_0&lt;/code&gt;, a part beyond the arity, a number too large to read). WHY: the
&lt;code&gt;_1&lt;/code&gt; spelling is what readers of other notations write first, and &lt;code&gt;_n&lt;/code&gt; meaning part &lt;code&gt;n - 1&lt;/code&gt; is the
likely intent. ALTERNATIVES: accepting &lt;code&gt;_1&lt;/code&gt; as a second spelling (two ways to write one thing).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;build-dir&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin run&lt;/code&gt; and &lt;code&gt;avin test&lt;/code&gt; build into the user’s cache
directory, not into &lt;code&gt;.avin/&lt;/code&gt; beside the program.&lt;/strong&gt; A program’s executables and its instance cache
go to &lt;code&gt;build/&amp;lt;name&amp;gt;-&amp;lt;key&amp;gt;/&lt;/code&gt; in the toolchain’s cache (&lt;code&gt;~/Library/Caches/avin/&amp;lt;version&amp;gt;/&lt;/code&gt; on macOS,
&lt;code&gt;$XDG_CACHE_HOME/avin/&amp;lt;version&amp;gt;/&lt;/code&gt; or &lt;code&gt;~/.cache/avin/&amp;lt;version&amp;gt;/&lt;/code&gt; elsewhere, or &lt;code&gt;AVIN_CACHE&lt;/code&gt;), where
&lt;code&gt;&amp;lt;name&amp;gt;&lt;/code&gt; is the program’s directory’s or file’s name and &lt;code&gt;&amp;lt;key&amp;gt;&lt;/code&gt; twelve hex digits of a SHA-256 of
its absolute, canonical path. &lt;code&gt;.avin/build/&lt;/code&gt; beside the program is used only on a machine with no
cache directory (no &lt;code&gt;AVIN_CACHE&lt;/code&gt;, &lt;code&gt;HOME&lt;/code&gt; or &lt;code&gt;XDG_CACHE_HOME&lt;/code&gt;; the runtime’s archives then go to the
temporary directory, which is cleared under a long-lived cache). &lt;code&gt;avin build&lt;/code&gt; and &lt;code&gt;-o&lt;/code&gt; are
unchanged. The new &lt;code&gt;avin clean [&amp;lt;program&amp;gt;]&lt;/code&gt; removes the program’s directory and any &lt;code&gt;.avin/build/&lt;/code&gt;
beside it (on the fallback, a program of one file’s entries only, and &lt;code&gt;.avin/&lt;/code&gt; once empty);
&lt;code&gt;avin clean --all&lt;/code&gt; removes the whole &lt;code&gt;build/&lt;/code&gt; of this version and nothing else of the cache, and on
the fallback means the current program’s. &lt;code&gt;avin new&lt;/code&gt; writes &lt;code&gt;/&amp;lt;name&amp;gt;&lt;/code&gt; (the executable &lt;code&gt;avin build&lt;/code&gt;
leaves at the root) and &lt;code&gt;.avin/&lt;/code&gt; into an application’s &lt;code&gt;.gitignore&lt;/code&gt;, &lt;code&gt;.avin/&lt;/code&gt; alone into a
library’s. Why: a one-file script run from anywhere left an &lt;code&gt;.avin/&lt;/code&gt; next to it; Sysl keeps its
builds and run cache in the machine cache directory keyed by version and target and uses a
project’s &lt;code&gt;.sysl/&lt;/code&gt; only where there is none, and Avin already keeps its fetched packages, runtime
archives and shims there, so a build cache beside the source was the one exception. Keying by path
keeps two worktrees of one repository apart (each has its own sources), and the version in the
path keeps one compiler’s entries from another’s. The executables and records are still published
by rename and the instance cache is lock-free as before, so two builds of one program at once stay
safe. Alternatives weighed: keep &lt;code&gt;.avin/&lt;/code&gt; beside projects and move only one-file programs (two
rules to explain, and a repository still grows a directory to ignore); key by the program’s content
rather than its path (every edit would start a new cache, and nothing would ever trim the old);
&lt;code&gt;--all&lt;/code&gt; removing the whole &lt;code&gt;avin/&amp;lt;version&amp;gt;&lt;/code&gt; (it would also drop fetched packages, which a build
then fetches again over the network); a lock around a program’s cache (the content-addressed,
rename-published entries need none). Review with the user: whether a cache of a deleted project
should ever be trimmed on its own (answered by the cache’s limit: least recently used first, see
the Proposed entries of branch &lt;code&gt;cache-trim&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;variant-test-open&lt;/code&gt;): &lt;strong&gt;A variant with fields named alone in a pattern
tests for the variant and binds none of its fields.&lt;/strong&gt; &lt;code&gt;o.status is Shipped&lt;/code&gt;, &lt;code&gt;Shipped -&amp;gt; …&lt;/code&gt; in a
&lt;code&gt;match&lt;/code&gt; arm, &lt;code&gt;Status.Shipped&lt;/code&gt; qualified, &lt;code&gt;Some(Shipped)&lt;/code&gt; nested and &lt;code&gt;f(Shipped) = …&lt;/code&gt; in a clause
all mean &lt;code&gt;Shipped(_, _)&lt;/code&gt;, with the variant’s own number of &lt;code&gt;_&lt;/code&gt;; coverage and unreachable arms
treat it as that pattern. &lt;code&gt;Shipped()&lt;/code&gt;, written with parentheses, is still matched against the
fields by number and refused for a variant that has some. Why: the commonest test of a variant
asks only which one it is, and counting &lt;code&gt;_&lt;/code&gt;s to say so is noise that changes whenever a field is
added; the previous error suggested &lt;code&gt;Shipped(fields)&lt;/code&gt;, which is not Avin, and the bare name could
mean nothing else, since a variant in scope is never a binding. One rule for every place a
pattern goes, because &lt;code&gt;x is P&lt;/code&gt; takes exactly the patterns a &lt;code&gt;match&lt;/code&gt; arm takes. Alternatives: only
in &lt;code&gt;is&lt;/code&gt; (two pattern languages, and a &lt;code&gt;match&lt;/code&gt; arm refactored from an &lt;code&gt;if … is&lt;/code&gt; would break);
keeping the error and suggesting &lt;code&gt;Shipped(_, _)&lt;/code&gt; with the right number of &lt;code&gt;_&lt;/code&gt; (valid, but the
test still has to change with the fields). Review with the user: a reader may take &lt;code&gt;Shipped&lt;/code&gt;
for a variant without fields.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;variant-test-open&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;open&lt;/code&gt;, &lt;code&gt;abstract&lt;/code&gt; and &lt;code&gt;override&lt;/code&gt; where they
mean nothing are one error each, and the declaration then parses as written.&lt;/strong&gt; Before a method:
“a method takes no &lt;code&gt;open&lt;/code&gt;: every public method of an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class, and every
method of a trait, may be overridden already; remove &lt;code&gt;open&lt;/code&gt;“, and for &lt;code&gt;abstract&lt;/code&gt; that a method
declared without a body is abstract already; before a field, that a field cannot be overridden
or is abstract by having no value; before a top-level function, that it belongs to no class or
overrides nothing; before &lt;code&gt;trait&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt; and &lt;code&gt;object&lt;/code&gt;, why each takes none; &lt;code&gt;override class&lt;/code&gt;,
that a class replaces nothing and extends with &lt;code&gt;: Base&lt;/code&gt;. Why: the words were read as names, so
&lt;code&gt;open sound() -&amp;gt; string&lt;/code&gt; reported &lt;code&gt;open&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt; as undefined and then every override of
&lt;code&gt;sound&lt;/code&gt; as overriding nothing. The spec settles that every public method of an open class may be
overridden, so methods have no &lt;code&gt;open&lt;/code&gt; to accept. Alternatives: accepting &lt;code&gt;open&lt;/code&gt; on a method as a
harmless no-op (two spellings of one meaning); a method-level &lt;code&gt;open&lt;/code&gt; with classes’ methods
final by default (a language change the settled rules do not ask for). &lt;code&gt;open(…)&lt;/code&gt;, &lt;code&gt;open = …&lt;/code&gt;
and a method named &lt;code&gt;open&lt;/code&gt; keep their meaning: the word is a modifier only before a name or a
declaration keyword.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigint&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BigInt&lt;/code&gt; is a class of the core module &lt;code&gt;avin&lt;/code&gt;, written in Avin, its
magnitude in limbs of nine decimal digits held in &lt;code&gt;long&lt;/code&gt;s.&lt;/strong&gt; It is visible with no import, as
&lt;code&gt;BitSet&lt;/code&gt; is; its limbs are a &lt;code&gt;FrozenArray[long]&lt;/code&gt;, a type no program can name, so its constructor
cannot be called with a malformed magnitude from outside the library, and the value is immutable
and sendable. Multiplication is schoolbook and division is long division with a normalized
divisor, both quadratic. &lt;em&gt;Why&lt;/em&gt;: base 10^9 makes decimal text, by far the commonest, a limb at a
time in both directions, and keeps a limb product plus a carry inside a &lt;code&gt;long&lt;/code&gt; with no wrapping
arithmetic; living in &lt;code&gt;avin&lt;/code&gt; lets it reuse the integer formatter’s private layout code, so &lt;code&gt;%d&lt;/code&gt;
and its flags behave exactly as for &lt;code&gt;long&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: binding Sysl’s &lt;code&gt;sysl.math.bigint&lt;/code&gt;
through a handle (faster, but its behaviour, text forms and traps would be Sysl’s to change, and
the library is meant to be Avin); base 2^32 limbs (cheaper bit operations, which &lt;code&gt;BigInt&lt;/code&gt; does not
have yet, but every decimal conversion becomes a division per nine digits and products need
wrapping or 128-bit arithmetic); a module &lt;code&gt;avin.math&lt;/code&gt; needing an import (keeps the core namespace
smaller); Karatsuba multiplication (not needed at the sizes programs meet so far). Review with the
user: whether &lt;code&gt;BigInt&lt;/code&gt; should be in the core namespace, and whether it should gain the bitwise
operators and shifts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigint&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BigInt&lt;/code&gt;‘s API mirrors the integer methods: &lt;code&gt;abs&lt;/code&gt;, &lt;code&gt;sign&lt;/code&gt;, &lt;code&gt;pow&lt;/code&gt;,
&lt;code&gt;gcd&lt;/code&gt;, &lt;code&gt;lcm&lt;/code&gt;, &lt;code&gt;floorDiv&lt;/code&gt;, &lt;code&gt;floorMod&lt;/code&gt;, &lt;code&gt;toRadix(r)&lt;/code&gt;, plus &lt;code&gt;isZero&lt;/code&gt;, &lt;code&gt;divRem&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt;/&lt;code&gt;toInt&lt;/code&gt;
that trap and &lt;code&gt;toLongOption&lt;/code&gt;/&lt;code&gt;toIntOption&lt;/code&gt; that answer &lt;code&gt;None&lt;/code&gt;.&lt;/strong&gt; Made by &lt;code&gt;BigInt(n)&lt;/code&gt; from any
integer width (a non-generic &lt;code&gt;apply(n: long)&lt;/code&gt; beside the generic one, so a literal as large as a
&lt;code&gt;long&lt;/code&gt; is accepted), &lt;code&gt;BigInt(text)&lt;/code&gt;/&lt;code&gt;BigInt(text, radix)&lt;/code&gt; that trap on bad text as &lt;code&gt;toLong&lt;/code&gt; does
(&lt;code&gt;For input string: &amp;quot;…&amp;quot;&lt;/code&gt;), and &lt;code&gt;BigInt.parse(text[, radix])&lt;/code&gt; answering &lt;code&gt;Option&lt;/code&gt;. A zero divisor
traps with &lt;code&gt;division by zero&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: one vocabulary for whole numbers, so code moves between
&lt;code&gt;long&lt;/code&gt; and &lt;code&gt;BigInt&lt;/code&gt; by changing a type; the trapping and &lt;code&gt;Option&lt;/code&gt; pairs follow &lt;code&gt;string.toLong&lt;/code&gt; /
&lt;code&gt;toLongOption&lt;/code&gt;. &lt;em&gt;Alternatives&lt;/em&gt;: &lt;code&gt;toString(radix)&lt;/code&gt; instead of &lt;code&gt;toRadix&lt;/code&gt; (the integer types already
chose &lt;code&gt;toRadix&lt;/code&gt;); only &lt;code&gt;Option&lt;/code&gt; conversions (forces &lt;code&gt;.get&lt;/code&gt; at every call that knows the value
fits); a &lt;code&gt;string.toBigInt&lt;/code&gt; extension (adds to every string a method for one type).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigint&lt;/code&gt;): &lt;strong&gt;the integer format conversions &lt;code&gt;%d&lt;/code&gt;, &lt;code&gt;%i&lt;/code&gt;, &lt;code&gt;%x&lt;/code&gt;, &lt;code&gt;%X&lt;/code&gt;, &lt;code&gt;%o&lt;/code&gt; and
&lt;code&gt;%b&lt;/code&gt; take a &lt;code&gt;BigInt&lt;/code&gt;, and &lt;code&gt;%s&lt;/code&gt; refuses it as it refuses every number.&lt;/strong&gt; The checker names the core
library’s &lt;code&gt;BigInt&lt;/code&gt; beside the integer widths and &lt;code&gt;byte&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: a whole number is formatted as one,
with grouping, signs, zero padding and bases; refusing &lt;code&gt;%s&lt;/code&gt; keeps the rule that a number’s
conversion says how its digits are laid out. &lt;em&gt;Alternatives&lt;/em&gt;: a trait (say &lt;code&gt;WholeNumber&lt;/code&gt;) a type
implements to be taken by the integer conversions (general, but a new trait and a display
contract for one type); accepting &lt;code&gt;BigInt&lt;/code&gt; under &lt;code&gt;%s&lt;/code&gt; (inconsistent with every other number).
Review with the user: whether a trait should open the integer conversions to other types.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigint&lt;/code&gt;): &lt;strong&gt;a type’s static member is called on its name even where the type
has a companion object.&lt;/strong&gt; &lt;code&gt;Cup.zero()&lt;/code&gt; with &lt;code&gt;object Cup&lt;/code&gt; declared reported “&lt;code&gt;Cup&lt;/code&gt; has no member
&lt;code&gt;zero&lt;/code&gt;“ (and &lt;code&gt;Period.zero()&lt;/code&gt; the same), since the name was read as the object. Now &lt;code&gt;Name.member&lt;/code&gt;
is the companion’s where the companion declares a member of that name, and otherwise the type’s
static member where it has one, for classes and data types, written with type arguments or not,
called or named as a function value. &lt;em&gt;Why&lt;/em&gt;: the spec calls a static member on the type’s name, and
a companion is where a type keeps its factories, so a type with both is the ordinary case
(&lt;code&gt;BigInt.zero()&lt;/code&gt; beside &lt;code&gt;BigInt.apply&lt;/code&gt;). &lt;em&gt;Alternatives&lt;/em&gt;: refusing a static member and a
companion on one type (rules out the common case); the type’s static member winning over the
companion’s member of the same name (makes a companion unable to shadow it deliberately).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;json-package&lt;/code&gt;): &lt;strong&gt;the corpus programs that test the compiler with
JSON depend on the sibling checkout &lt;code&gt;~/dev/avin-lang/json&lt;/code&gt; by path&lt;/strong&gt; (&lt;code&gt;../../../../../json&lt;/code&gt; from
&lt;code&gt;tests/programs/{run,reject}/NAME/&lt;/code&gt;). &lt;em&gt;Why&lt;/em&gt;: the corpus loads packages without fetching, and a copy
of the package inside this repository would drift from the real one; the compiler already reaches
&lt;code&gt;~/dev/sysl-lang/parsing&lt;/code&gt; the same way. &lt;em&gt;Alternatives&lt;/em&gt;: a vendored copy under &lt;code&gt;tests/packages/json&lt;/code&gt;
(self-contained, but two sources of one package); a git dependency (the corpus does not fetch).
Review with the user: it makes the avin gate need the json checkout beside it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;json-package&lt;/code&gt;): &lt;strong&gt;a trap inside a package is placed in the package’s
source&lt;/strong&gt;, as before for any module that is not the core library: &lt;code&gt;j(&amp;quot;absent&amp;quot;)&lt;/code&gt; now reports
&lt;code&gt;at json.avin:98:9&lt;/code&gt; where, as &lt;code&gt;avin.json&lt;/code&gt;, it reported the program’s call. The corpus programs
&lt;code&gt;json_missing_key_trap&lt;/code&gt; and &lt;code&gt;json_missing_index_trap&lt;/code&gt; hide the package’s line and column. &lt;em&gt;Why&lt;/em&gt;: the
rule that a trap is placed where the program last called in is the core library’s (&lt;a href=&quot;/spec/errors/&quot;&gt;errors&lt;/a&gt;),
and widening it to every dependency is a design change of its own. &lt;em&gt;Alternatives&lt;/em&gt;: placing a trap
at the last call from the root package’s own code (better for a package’s users, worse for its
author debugging it); a per-package opt-in. Review with the user: a package’s user would usually
rather see their own call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;script-deps&lt;/code&gt;): &lt;strong&gt;A program of one file names its dependencies in a header of
comment lines at its top&lt;/strong&gt;: the line &lt;code&gt;// avin.hocon&lt;/code&gt;, then &lt;code&gt;//&lt;/code&gt; lines whose text after the &lt;code&gt;//&lt;/code&gt; is
exactly a manifest’s &lt;code&gt;dependencies&lt;/code&gt; block, ending at the first line that is not a &lt;code&gt;//&lt;/code&gt; comment
(&lt;a href=&quot;/spec/packages/#programs-of-one-file&quot;&gt;packages&lt;/a&gt;). Why: domain libraries are packages (JSON, CSV),
and a script must reach them without becoming a directory with a manifest; reusing the manifest’s
own HOCON means one syntax, one parser and one set of errors, shown at the header’s line in the
file. Being comments, the header needs no change to the lexer, the parser, the formatter or the
IntelliJ plugin, and a file with one is still Avin to every tool. &lt;code&gt;// avin.hocon&lt;/code&gt; reads as “this
file’s manifest”, and the editor grammar colours the block as embedded HOCON. Alternatives weighed:
a &lt;code&gt;---&lt;/code&gt; front-matter fence (a second lexical form every tool must learn, and a file no older
compiler reads); a declaration in the language, &lt;code&gt;dependencies { … }&lt;/code&gt; or an annotation on the file
(dependencies are the build’s business, not the program’s, and the checker would have to ignore
it); one &lt;code&gt;@dep(&amp;quot;github.com/…@1.0&amp;quot;)&lt;/code&gt; comment per dependency (a second syntax for what a manifest
already says, without &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;rev&lt;/code&gt;, &lt;code&gt;member&lt;/code&gt; or features); a block comment (Avin has none).
Review with the user: the marker’s spelling.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;script-deps&lt;/code&gt;): &lt;strong&gt;The header holds &lt;code&gt;dependencies&lt;/code&gt; only, and is at the top or
refused.&lt;/strong&gt; &lt;code&gt;workspace = true&lt;/code&gt; and &lt;code&gt;optional&lt;/code&gt; are refused (no workspace, no features of its own);
&lt;code&gt;package&lt;/code&gt;, &lt;code&gt;features&lt;/code&gt;, &lt;code&gt;sysl-dependencies&lt;/code&gt; and &lt;code&gt;c-libraries&lt;/code&gt; are refused at the key, a program that
needs them being a package. It begins on the first line, or the second after a &lt;code&gt;#!&lt;/code&gt; line; a
&lt;code&gt;// avin.hocon&lt;/code&gt; line anywhere else is an error, because a header silently not read is a missing
dependency reported as an unknown module. Alternatives weighed: allowing &lt;code&gt;sysl-dependencies&lt;/code&gt; and
&lt;code&gt;c-libraries&lt;/code&gt; (each works through the same resolution, and may be added when a script needs one);
allowing other comments or blank lines before it (a header that moves is harder to find, and the
rule “first line” is one a reader can check at a glance).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;script-deps&lt;/code&gt;): &lt;strong&gt;A header in a file of a package, or of a program of many files,
is refused at the header&lt;/strong&gt;, rather than merged with the manifest or passed over. Why: two places
naming a package’s dependencies would disagree, and passing it over hides a mistake; a directory
program has no manifest, and the way to give it dependencies is to make it a package. Only the
package’s own files are checked; a dependency’s files are not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;script-deps&lt;/code&gt;): &lt;strong&gt;A program of one file’s sum file is beside it, named after it&lt;/strong&gt;:
&lt;code&gt;tool.avin.sum&lt;/code&gt;, written and checked as &lt;code&gt;avin.sum&lt;/code&gt; is, absent when nothing is fetched, rewritten by
&lt;code&gt;avin tidy tool.avin&lt;/code&gt;. A program of one file is &lt;strong&gt;not vendored&lt;/strong&gt;: &lt;code&gt;avin vendor&lt;/code&gt; refuses it, and
&lt;code&gt;avin add&lt;/code&gt; (which edits a manifest) refuses it too. Why: the sum file is where a manifest’s is,
beside what names the dependencies, and naming it after the file lets several scripts share a
directory. A &lt;code&gt;vendor/&lt;/code&gt; beside the file would be shared by every script in the directory, and
vendoring one would remove the others’ packages. Alternatives weighed: no lock at all, trusting
the cache’s recorded hash (a moved tag would go unnoticed on a second machine); one &lt;code&gt;avin.sum&lt;/code&gt; per
directory (scripts would add and &lt;code&gt;tidy&lt;/code&gt; would remove each other’s lines); the hashes written into
the header (the build would rewrite the user’s source); a &lt;code&gt;vendor/&amp;lt;file&amp;gt;/&lt;/code&gt; per script. Review with
the user: whether a script’s sum file is wanted, or is clutter next to a one-file tool.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;script-deps&lt;/code&gt;): &lt;strong&gt;A
first line beginning &lt;code&gt;#!&lt;/code&gt; is not Avin&lt;/strong&gt;, in every file, and the line is written
&lt;code&gt;#!/usr/bin/env avin&lt;/code&gt;. &lt;strong&gt;&lt;code&gt;avin &amp;lt;file&amp;gt; ...&lt;/code&gt; (the form a &lt;code&gt;#!&lt;/code&gt; line runs, with no command word)
for a file whose first line begins &lt;code&gt;#!&lt;/code&gt; gives every argument after the file to the program&lt;/strong&gt;, so
&lt;code&gt;./tool.avin -O0 x&lt;/code&gt; passes &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt;. Every other form keeps the command line’s rule:
&lt;code&gt;avin run tool.avin -O0 -- x&lt;/code&gt; and &lt;code&gt;avin -O2 tool.avin -- x&lt;/code&gt; take the options as avin’s and pass
only what follows &lt;code&gt;--&lt;/code&gt;. Why: &lt;code&gt;./tool.avin a b&lt;/code&gt; runs &lt;code&gt;avin ./tool.avin a b&lt;/code&gt; through the &lt;code&gt;#!&lt;/code&gt; line,
and without the rule the program’s arguments would need a &lt;code&gt;--&lt;/code&gt; that a command’s caller cannot know
to write; while a person typing &lt;code&gt;avin run&lt;/code&gt; is using avin, and its options mean the same wherever
they stand. Alternatives weighed: every argument after any &lt;code&gt;#!&lt;/code&gt; file the program’s, &lt;code&gt;avin run&lt;/code&gt;
included (the branch’s first form; it made &lt;code&gt;avin run tool.avin -O0&lt;/code&gt; mean something different for
one kind of file); &lt;code&gt;#!/usr/bin/env -S avin run&lt;/code&gt; as the line (needs &lt;code&gt;env -S&lt;/code&gt;, and runs through
&lt;code&gt;avin run&lt;/code&gt;, where the options are avin’s); &lt;code&gt;#!&lt;/code&gt; lines needing &lt;code&gt;avin run --&lt;/code&gt; (env passes the file
after the &lt;code&gt;--&lt;/code&gt;, so it would be an argument, not the program); taking options before the first
non-option and the rest as the program’s (&lt;code&gt;./tool -O0&lt;/code&gt; would still be eaten). Review with the
user: the argument rule, which makes &lt;code&gt;-O0&lt;/code&gt; after a &lt;code&gt;#!&lt;/code&gt; file the program’s when run as a command.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;fmt-pack&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin fmt&lt;/code&gt; fills a broken literal of short, simple items, as many to a line as fit&lt;/strong&gt; (branch
&lt;code&gt;fmt-pack&lt;/code&gt;). A sequence literal &lt;code&gt;[…]&lt;/code&gt; or set literal &lt;code&gt;{…}&lt;/code&gt; (brackets not after an operand, so no
index or type arguments) whose every item is a number, a character, a plain string, &lt;code&gt;true&lt;/code&gt;,
&lt;code&gt;false&lt;/code&gt; or a name, a number with a sign against it included, and no item wider than 32
characters, is broken where any list would be (past 120 characters, or written with a line
break after its opening bracket and before its closing one), but its items are then laid out
&lt;code&gt;, &lt;/code&gt;-separated, as many to a line as fit in the 120 columns, two columns in, a trailing comma
kept after the last. Any other item (a call, a lambda, a tuple, a nested literal, an
interpolated string, a &lt;code&gt;key: value&lt;/code&gt; entry) keeps the one-item-per-line layout, and a comment
among the items keeps the lines as written, as everywhere inside brackets. Arguments of a call
are never filled. The result is idempotent: a filled literal is broken after its opening bracket,
so formatting it again fills it the same way. WHY: a generated table (tui’s &lt;code&gt;width_table.avin&lt;/code&gt;,
about 640 pairs of code points) became ~1,280 lines of one number each; filled, it is 111 lines
and reads as a table. ALTERNATIVES: keep a source that is one per line one per line (leaves the
table unreadable, and a table that has been through &lt;code&gt;fmt&lt;/code&gt; once could never recover); fill any
list of one-token items, call arguments included (a call’s arguments are each a meaning, and
one per line shows them); fill short tuples &lt;code&gt;(a, b)&lt;/code&gt; too (more rules for the reader of the style
to learn; a table of pairs is written flat, as tui’s is); align items into columns (wider diffs
for one changed entry, and no gain for numbers of one width). Review with the user: the 32-
character limit, and whether a short list deliberately written one per line should stay so.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;discarded-result&lt;/code&gt;): &lt;strong&gt;A dropped &lt;code&gt;Result&lt;/code&gt; or &lt;code&gt;Future&lt;/code&gt; is an error, and
&lt;code&gt;_ = e&lt;/code&gt; drops one on purpose&lt;/strong&gt; (&lt;a href=&quot;/spec/errors/#a-result-is-not-dropped&quot;&gt;errors&lt;/a&gt;). A value of
either type is reported where it is thrown away: a block’s statement, the last line of a function
or lambda yielding &lt;code&gt;unit&lt;/code&gt;, a branch of an &lt;code&gt;if&lt;/code&gt; without &lt;code&gt;else&lt;/code&gt; or of an &lt;code&gt;if&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt; written as a
statement, a loop’s body. &lt;code&gt;_ = e&lt;/code&gt; evaluates &lt;code&gt;e&lt;/code&gt; and keeps nothing. A deferred statement is exempt,
and so is an expression the checker reads only for its own errors after the form around it failed.
The standard library’s call sites were each handled or marked &lt;code&gt;_ =&lt;/code&gt; (a socket or pipe closed once
its exchange is over, a temporary directory removed, a signal to a program that may have ended).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;fs.writeText(&amp;quot;/nonexistent/x&amp;quot;, &amp;quot;hi&amp;quot;)&lt;/code&gt; as a statement compiled and failed silently (gap
audit C8). An error, not a warning: Avin has no warnings channel, every diagnostic is an error,
and a warning shown only sometimes is the one that is missed (as for unreachable match arms).
&lt;code&gt;_ = e&lt;/code&gt; is the spelling a reader already knows from destructuring, where &lt;code&gt;_&lt;/code&gt; drops a part. A
deferred statement is exempt because it runs while its block is being left, where no &lt;code&gt;?&lt;/code&gt; or
&lt;code&gt;return&lt;/code&gt; can carry a failure anywhere, and &lt;code&gt;defer f.close()&lt;/code&gt; is the form &lt;code&gt;defer&lt;/code&gt; exists for. A
&lt;code&gt;Future&lt;/code&gt; is included because dropping one loses its answer the same way.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Alternatives weighed&lt;/em&gt;: a warning (no channel to carry it); a &lt;code&gt;@mustUse&lt;/code&gt; annotation on types or
functions (more general, but a new attribute for two types, and a library author could forget
it); &lt;code&gt;Result&lt;/code&gt; only (a dropped &lt;code&gt;Future[Result[…]]&lt;/code&gt; loses the failure just as surely); reporting
a dropped &lt;code&gt;Result&lt;/code&gt; in &lt;code&gt;defer&lt;/code&gt; too, which would make &lt;code&gt;defer _ = f.close()&lt;/code&gt; the idiom (noise on the
one form &lt;code&gt;defer&lt;/code&gt; is for); &lt;code&gt;val _ = e&lt;/code&gt; as the only discard (it already works, but reads as a
declaration).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;defer&lt;/code&gt; should stay exempt (decisions above left “whether
discarding a &lt;code&gt;close&lt;/code&gt;‘s &lt;code&gt;Result&lt;/code&gt; in &lt;code&gt;defer&lt;/code&gt; deserves a warning” open), and whether a lambda yielding
&lt;code&gt;unit&lt;/code&gt; should be held to the rule (it is, so &lt;code&gt;xs.foreach(f -&amp;gt; fs.remove(f))&lt;/code&gt; is an error).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigint-natural&lt;/code&gt;): &lt;strong&gt;Integers meet a type that takes them, through a core trait &lt;code&gt;FromInteger&lt;/code&gt;&lt;/strong&gt; (2026-11-13, branch
&lt;code&gt;bigint-natural&lt;/code&gt;; &lt;a href=&quot;/spec/types/#integers-meet-a-type-that-takes-them&quot;&gt;types&lt;/a&gt;). &lt;code&gt;trait FromInteger&lt;/code&gt;
with one member, &lt;code&gt;static fromInteger[N: Integer](n: N) -&amp;gt; Self&lt;/code&gt;; &lt;code&gt;BigInt&lt;/code&gt; implements it. (1) An
integer literal where such a type is expected is &lt;code&gt;T.fromInteger(literal)&lt;/code&gt;, the literal typed as a
&lt;code&gt;long&lt;/code&gt; where it fits and otherwise at the narrowest width a multiple of 64 bits that holds it, so a
literal of any size and base is a &lt;code&gt;BigInt&lt;/code&gt; (&lt;code&gt;val x: BigInt = 123456789012345678901234567890&lt;/code&gt;). (2)
In &lt;code&gt;+ - * / %&lt;/code&gt;, the comparisons and &lt;code&gt;==&lt;/code&gt;/&lt;code&gt;!=&lt;/code&gt;, an operand of an integer type (or a type parameter
bounded by &lt;code&gt;Integer&lt;/code&gt;) beside an operand of such a type is converted with &lt;code&gt;fromInteger&lt;/code&gt;, on either
side and in chains; a compound assignment converts only its value, so an integer target keeps its
type. (3) Where the type has an operator method of the name and no overload of it takes an
integer, its integer argument is converted, and a converted left operand calls it. (4) An integer
literal is refused as a pattern for such a type, since its value is a call. WHY: &lt;code&gt;f * i&lt;/code&gt;,
&lt;code&gt;f == 0&lt;/code&gt; and &lt;code&gt;val f: BigInt = 1&lt;/code&gt; are what a reader writes, and &lt;code&gt;BigInt(i)&lt;/code&gt; around every integer
hid the arithmetic. One trait serves both rules and any later number type (a decimal, a rational)
joins by an impl, with no type named in the checker; the conversion is lossless by the trait’s
contract, which is why it is allowed where integer widths, which can lose, still need &lt;code&gt;long(x)&lt;/code&gt;.
A literal too large for &lt;code&gt;long&lt;/code&gt; reuses the arbitrary-width integers rather than a text form, so the
trait has one member. ALTERNATIVES: operator methods on &lt;code&gt;BigInt&lt;/code&gt; taking &lt;code&gt;[N: Integer]&lt;/code&gt; (covers
&lt;code&gt;big * i&lt;/code&gt; only; &lt;code&gt;i * big&lt;/code&gt; and &lt;code&gt;0 == big&lt;/code&gt; still need a checker rule, so two mechanisms); a general
reversed-operand lookup on the right operand’s type (larger, and it says nothing of literals or
&lt;code&gt;==&lt;/code&gt;); implicit conversion of an integer to a &lt;code&gt;FromInteger&lt;/code&gt; type at every expected type, arguments
included (wider than asked, and it makes overloads &lt;code&gt;f(BigInt)&lt;/code&gt;/&lt;code&gt;f(long)&lt;/code&gt; harder to read); a
&lt;code&gt;fromDigits(text)&lt;/code&gt; member for literals past &lt;code&gt;long&lt;/code&gt; (a second member every implementer writes, and
a parse at run time). Literal patterns for such a type (matching by &lt;code&gt;==&lt;/code&gt;) were left out: a pattern
is a constant today, and coverage reasons about constants. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether the
conversion should reach plain arguments (&lt;code&gt;gcd(7)&lt;/code&gt; already works for a literal; &lt;code&gt;gcd(i)&lt;/code&gt; does not),
and whether &lt;code&gt;BigInt.zero()&lt;/code&gt;/&lt;code&gt;one()&lt;/code&gt; should lose their &lt;code&gt;()&lt;/code&gt; with the core traits’ wave.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigint-natural&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BigInt(n)&lt;/code&gt; with a literal past &lt;code&gt;long&lt;/code&gt; stays an error&lt;/strong&gt; (2026-11-13, branch &lt;code&gt;bigint-natural&lt;/code&gt;):
&lt;code&gt;apply(n: long)&lt;/code&gt; and &lt;code&gt;apply[T: Integer](n: T)&lt;/code&gt; give the literal no wider type, and the message says
it does not fit; &lt;code&gt;val x: BigInt = …&lt;/code&gt; is the spelling. WHY: typing a literal at a free &lt;code&gt;Integer&lt;/code&gt;
bound by its size would be a second literal rule for one call. ALTERNATIVE: an &lt;code&gt;apply&lt;/code&gt; overload
the literal rule reaches.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BigDecimal&lt;/code&gt;: an immutable unscaled &lt;code&gt;BigInt&lt;/code&gt; and a scale, rounding by a &lt;code&gt;Rounding&lt;/code&gt; data type,
no context object&lt;/strong&gt; (2026-11-13, branch &lt;code&gt;bigdecimal&lt;/code&gt;; &lt;a href=&quot;/spec/types/#bigdecimal&quot;&gt;types&lt;/a&gt;). The class
is &lt;code&gt;BigDecimal(val unscaled: BigInt, val scale: int)&lt;/code&gt;; a negative scale traps in the constructor,
so a whole number is always scale 0 and a large one carries its zeros in &lt;code&gt;unscaled&lt;/code&gt;. &lt;code&gt;Rounding&lt;/code&gt;
has &lt;code&gt;HalfEven&lt;/code&gt; (the default everywhere), &lt;code&gt;HalfUp&lt;/code&gt;, &lt;code&gt;HalfDown&lt;/code&gt;, &lt;code&gt;Up&lt;/code&gt;, &lt;code&gt;Down&lt;/code&gt;, &lt;code&gt;Ceiling&lt;/code&gt; and
&lt;code&gt;Floor&lt;/code&gt;, and no mode that traps on inexactness: the exact operation is &lt;code&gt;exactDiv&lt;/code&gt;, answering an
&lt;code&gt;Option&lt;/code&gt;. Every rounding operation takes its precision positionally and its mode by name:
&lt;code&gt;round(places, rounding = …)&lt;/code&gt;, &lt;code&gt;roundSignificant(digits, rounding = …)&lt;/code&gt;, &lt;code&gt;div(o, scale, rounding = …)&lt;/code&gt;, &lt;code&gt;divSignificant(o, digits, rounding = …)&lt;/code&gt;. WHY: one value type with its precision stated at
each call reads plainly and has no hidden state; an &lt;code&gt;Option&lt;/code&gt; says “may not be exact” in the type
where a trapping mode would say it at run time. ALTERNATIVES: a context object or a thread-wide
default (hidden state, the thing the user asked to leave out); an &lt;code&gt;Unnecessary&lt;/code&gt; mode (a trap where
a type can say it); a visible negative scale (&lt;code&gt;1E+3&lt;/code&gt; as unscaled 1, scale -3: compact, but a second
spelling of every whole number and a source of surprise in &lt;code&gt;scale&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;/&lt;/code&gt; gives 34 significant digits, half to even, and an exact quotient within them at the
“preferred” scale&lt;/strong&gt; (branch &lt;code&gt;bigdecimal&lt;/code&gt;). The quotient is rounded to 34 significant digits, then
zeros after the point are dropped down to the dividend’s scale less the divisor’s (never below 0):
&lt;code&gt;1 / 4&lt;/code&gt; is &lt;code&gt;0.25&lt;/code&gt;, &lt;code&gt;6.00 / 2&lt;/code&gt; is &lt;code&gt;3.00&lt;/code&gt;, &lt;code&gt;1 / 3&lt;/code&gt; has 34 threes. So &lt;code&gt;/&lt;/code&gt; agrees with &lt;code&gt;exactDiv&lt;/code&gt;
wherever it is exact, and &lt;code&gt;divSignificant&lt;/code&gt; keeps the same rule at its own digit count. WHY: 34 is
the precision of a 128-bit decimal, enough for money and rates; padding every quotient to 34 digits
(&lt;code&gt;0.2500000…&lt;/code&gt;) would make &lt;code&gt;/&lt;/code&gt; useless for display. ALTERNATIVES: a fixed scale for &lt;code&gt;/&lt;/code&gt; (wrong for
large and small magnitudes alike); refusing &lt;code&gt;/&lt;/code&gt; and requiring &lt;code&gt;div&lt;/code&gt; (the user asked for a default);
no zero-stripping (the padded form above).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;Decimal literals reach a type through a core trait &lt;code&gt;FromDecimal: FromInteger&lt;/code&gt;, with the
literal’s text&lt;/strong&gt; (branch &lt;code&gt;bigdecimal&lt;/code&gt;; &lt;a href=&quot;/spec/types/#decimals-meet-a-type-that-takes-them&quot;&gt;types&lt;/a&gt;).
&lt;code&gt;static fromDecimal(text: string) -&amp;gt; Self&lt;/code&gt; takes the literal as written, sign and exponent kept and
separators dropped; &lt;code&gt;RealLit&lt;/code&gt; now keeps its spelling for this. The parse happens at run time, each
time the literal is evaluated. WHY: the literal is exact only if no &lt;code&gt;real&lt;/code&gt; is ever made of it, and
text is the one form every decimal type can read; the trait mirrors &lt;code&gt;FromInteger&lt;/code&gt;, so a program’s
own decimal type joins by an impl. ALTERNATIVES: emitting &lt;code&gt;BigDecimal(unscaledLiteral, scale)&lt;/code&gt;
(exact and parse-free, but names one library type in the checker and serves no other); a
compile-time constant pool (later optimization, not a language question). &lt;strong&gt;Review with the
user&lt;/strong&gt;: whether to hoist the parse once performance matters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;BigInt&lt;/code&gt; meets a type that takes decimals by &lt;code&gt;FromDecimal.fromBigInt&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;bigdecimal&lt;/code&gt;).
The trait’s second member converts a &lt;code&gt;BigInt&lt;/code&gt; operand beside a &lt;code&gt;FromDecimal&lt;/code&gt; type under the five
operators, the comparisons and &lt;code&gt;==&lt;/code&gt;, either side, chains and compound assignment included, as an
integer operand meets a &lt;code&gt;FromInteger&lt;/code&gt; type. A type that takes only integers takes no &lt;code&gt;BigInt&lt;/code&gt;.
WHY: &lt;code&gt;price * qty&lt;/code&gt; with a &lt;code&gt;BigInt&lt;/code&gt; count should read as written, and a type taking every decimal
takes every whole number losslessly. ALTERNATIVES: a &lt;code&gt;fromBigInt&lt;/code&gt; member on &lt;code&gt;FromInteger&lt;/code&gt; (every
integer-only type would have to write it, with nothing to build it from); converting through
&lt;code&gt;fromDecimal(n.toString())&lt;/code&gt; (no extra member, but a text round trip on every operation); overloads
on &lt;code&gt;BigDecimal&lt;/code&gt; and &lt;code&gt;BigInt&lt;/code&gt; (covers one pair of types, and &lt;code&gt;BigInt&lt;/code&gt; would have to know
&lt;code&gt;BigDecimal&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;A real literal waits for the other operand only beside a value that is not a literal&lt;/strong&gt;
(branch &lt;code&gt;bigdecimal&lt;/code&gt;). In &lt;code&gt;x + 0.5&lt;/code&gt;, &lt;code&gt;0.5 + x&lt;/code&gt; and &lt;code&gt;x &amp;lt; 0.5&lt;/code&gt;, the literal takes &lt;code&gt;x&lt;/code&gt;‘s type, so a
&lt;code&gt;BigDecimal&lt;/code&gt; &lt;code&gt;x&lt;/code&gt; makes it one; among literals alone (&lt;code&gt;1 + 0.5&lt;/code&gt;, &lt;code&gt;1 &amp;lt; 2.5&lt;/code&gt;) everything is a &lt;code&gt;real&lt;/code&gt;
as before. WHY: the operand order rule integer literals follow, extended without changing a
program that compiled.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;The &lt;code&gt;Rounding&lt;/code&gt; variants are core names, seen everywhere&lt;/strong&gt; (branch &lt;code&gt;bigdecimal&lt;/code&gt;). &lt;code&gt;HalfEven&lt;/code&gt;,
&lt;code&gt;Up&lt;/code&gt;, &lt;code&gt;Down&lt;/code&gt;, &lt;code&gt;Ceiling&lt;/code&gt;, &lt;code&gt;Floor&lt;/code&gt; and the rest are variants of a prelude data type, so
&lt;code&gt;rounding = Floor&lt;/code&gt; needs no import or qualifier. A program’s own &lt;code&gt;Up&lt;/code&gt; or &lt;code&gt;Down&lt;/code&gt; hides them where
nothing expects a &lt;code&gt;Rounding&lt;/code&gt;, and where one is expected the bare name is still &lt;code&gt;Rounding&lt;/code&gt;‘s, as for
&lt;code&gt;None&lt;/code&gt; and &lt;code&gt;Some&lt;/code&gt;; &lt;code&gt;Rounding.Up&lt;/code&gt; is always available. WHY: the call reads &lt;code&gt;x.round(2, rounding = HalfUp)&lt;/code&gt;, as asked. ALTERNATIVES: a module &lt;code&gt;avin.math&lt;/code&gt; for &lt;code&gt;BigDecimal&lt;/code&gt; and &lt;code&gt;Rounding&lt;/code&gt; (an import
for every program using money); prefixed names (&lt;code&gt;RoundHalfUp&lt;/code&gt;). &lt;strong&gt;Review with the user&lt;/strong&gt;: short
common words such as &lt;code&gt;Up&lt;/code&gt; and &lt;code&gt;Down&lt;/code&gt; in the prelude.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;bigdecimal&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;BigDecimal&lt;/code&gt;‘s smaller choices&lt;/strong&gt; (branch &lt;code&gt;bigdecimal&lt;/code&gt;): (1) the sign accessor is &lt;code&gt;sign&lt;/code&gt;, as on
&lt;code&gt;BigInt&lt;/code&gt; and the integers, not &lt;code&gt;signum&lt;/code&gt;; (2) &lt;code&gt;round(places)&lt;/code&gt; always answers that scale, padding
with zeros where the number has fewer places, and a negative &lt;code&gt;places&lt;/code&gt; rounds to tens, hundreds, …
answering scale 0; (3) &lt;code&gt;roundSignificant&lt;/code&gt; drops one zero a carry adds after the point (&lt;code&gt;9.99&lt;/code&gt; to 2
is &lt;code&gt;10&lt;/code&gt;), while a whole number keeps the zeros it needs; (4) &lt;code&gt;%&lt;/code&gt; and &lt;code&gt;divRem&lt;/code&gt; use the quotient cut
toward zero, the remainder taking the dividend’s sign, as on &lt;code&gt;BigInt&lt;/code&gt;; no &lt;code&gt;floorDiv&lt;/code&gt; yet; (5)
&lt;code&gt;toBigInt&lt;/code&gt;, &lt;code&gt;toLong&lt;/code&gt; and &lt;code&gt;toInt&lt;/code&gt; take the whole part toward zero, as &lt;code&gt;real&lt;/code&gt;‘s do, trapping (or
&lt;code&gt;None&lt;/code&gt;) only when it does not fit; (6) &lt;code&gt;fromRealExact&lt;/code&gt; and &lt;code&gt;fromRealShortest&lt;/code&gt; trap on NaN and the
infinities and answer the least scale that holds the value; &lt;code&gt;fromRealExact&lt;/code&gt; writes the &lt;code&gt;real&lt;/code&gt; with
1074 places through &lt;code&gt;%f&lt;/code&gt;, which every finite &lt;code&gt;real&lt;/code&gt; fits exactly; (7) &lt;code&gt;BigDecimal(text)&lt;/code&gt; and
&lt;code&gt;parse&lt;/code&gt; accept &lt;code&gt;.5&lt;/code&gt;, &lt;code&gt;5.&lt;/code&gt; and an exponent, refuse separators and white space, and answer &lt;code&gt;None&lt;/code&gt;
for a resulting scale outside &lt;code&gt;int&lt;/code&gt; (a large positive exponent within it, &lt;code&gt;1e100000000&lt;/code&gt;, is read,
at the cost of its digits); (8) &lt;code&gt;%f&lt;/code&gt; takes a &lt;code&gt;BigDecimal&lt;/code&gt; with its precision as places, half to
even, and with none keeps its own scale; &lt;code&gt;%e&lt;/code&gt;, &lt;code&gt;%g&lt;/code&gt;, &lt;code&gt;%s&lt;/code&gt;, &lt;code&gt;%d&lt;/code&gt; and &lt;code&gt;,&lt;/code&gt; are refused; (9) the hash
is the least-scale form’s, so equal values hash alike; (10) &lt;code&gt;exactDiv&lt;/code&gt; by zero traps, as every
division does, since &lt;code&gt;None&lt;/code&gt; means “never ends”; (11) &lt;code&gt;BigDecimal.zero()&lt;/code&gt; and &lt;code&gt;one()&lt;/code&gt; are at scale
0; (12) mixing a &lt;code&gt;real&lt;/code&gt; value with a &lt;code&gt;BigDecimal&lt;/code&gt; is an error that names &lt;code&gt;fromRealShortest&lt;/code&gt; and
&lt;code&gt;fromRealExact&lt;/code&gt;. ALTERNATIVES weighed for each: &lt;code&gt;signum&lt;/code&gt; (inconsistent with &lt;code&gt;BigInt&lt;/code&gt;);
&lt;code&gt;round&lt;/code&gt; never adding places (then &lt;code&gt;round(2)&lt;/code&gt; cannot be used to show cents); floor division for
&lt;code&gt;%&lt;/code&gt; (different from every other &lt;code&gt;%&lt;/code&gt; in the language); traps for fractional &lt;code&gt;toLong&lt;/code&gt; (the whole part
is what conversions take elsewhere); &lt;code&gt;Option&lt;/code&gt; from the &lt;code&gt;real&lt;/code&gt; conversions (NaN is a programming
error, not data); a &lt;code&gt;%f&lt;/code&gt; default of 6 places (loses digits a decimal holds exactly).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Deferred&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Path-dependent and intersection types; inferred unions; implicit parameters; macros.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-13: &lt;strong&gt;Avin has higher-kinded types and a standard Functor, Monad and
Traverse family&lt;/strong&gt;, reversing their deferral; the design’s choices are under
&lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt; (branch &lt;code&gt;hkt-design&lt;/code&gt;), and the guiding rule the user gave with it is that
Avin is the ultimate &lt;em&gt;sound, nominally typed&lt;/em&gt;, compiled, garbage-collected high-level language:
every rule is sound with no unchecked escape, the traits are nominal, and &lt;code&gt;for&lt;/code&gt; comprehensions
admit their sources by conformance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-12 (built on branch &lt;code&gt;library-version&lt;/code&gt;): &lt;strong&gt;the standard library carries the compiler’s version, and
the compiler refuses a library of any other.&lt;/strong&gt; &lt;code&gt;library/library.hocon&lt;/code&gt;‘s &lt;code&gt;package.version&lt;/code&gt; is
stamped by &lt;code&gt;scripts/release.sh&lt;/code&gt; in the same commit as &lt;code&gt;const Version&lt;/code&gt; and &lt;code&gt;compiler/sysl.hocon&lt;/code&gt;,
and a compiler checks it against its own before it compiles anything: &lt;code&gt;check&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;,
&lt;code&gt;test&lt;/code&gt; and &lt;code&gt;lsp&lt;/code&gt; print one error naming both versions and the library’s path, and nothing else.
A library with no version, or a &lt;code&gt;library.hocon&lt;/code&gt; that is missing or unreadable, is refused the
same way. The rule is an &lt;strong&gt;exact match&lt;/strong&gt;. A compiler built between releases carries the last
release’s version, and so does the library in its own checkout, so a development build matches
its own tree; only a library from another release, through &lt;code&gt;AVIN_ROOT&lt;/code&gt; or an install, differs.
Why: a library of another version fails as dozens of errors inside &lt;code&gt;library/avin/*.avin&lt;/code&gt;, which
points a reader at the library rather than at the mismatch. Alternatives weighed: a dev compiler
accepting a library from the same commit (needs a commit id stamped into both and a build step
that keeps them in step, to answer a case the exact rule already passes); “the library is newer
than the compiler” (a newer library declares what an older compiler cannot check, which is the
failure being fixed). Review with the user: whether a pre-release suffix should be accepted in the
library’s stamp; manifests accept three numbers only, as &lt;code&gt;sysl.hocon&lt;/code&gt;‘s version does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;c1-diagnostics&lt;/code&gt;): &lt;strong&gt;A method declared &lt;code&gt;m()&lt;/code&gt; and named bare where a
value is expected is reported as “&lt;code&gt;m&lt;/code&gt; is called with &lt;code&gt;()&lt;/code&gt;: write &lt;code&gt;c.m()&lt;/code&gt;, or &lt;code&gt;() -&amp;gt; c.m()&lt;/code&gt; for a
function value”&lt;/strong&gt;, the call first, written on the receiver as the program named it (a local or
parameter by name, &lt;code&gt;self&lt;/code&gt;, a type for a static member, nothing for a bare name’s implicit &lt;code&gt;self&lt;/code&gt;),
&lt;code&gt;_.m()&lt;/code&gt; alone for a placeholder, and &lt;code&gt;.m()&lt;/code&gt; with “a lambda calling it” for any other receiver.
Why: the error is almost always a missing &lt;code&gt;()&lt;/code&gt; now that pure accessors are declared without a
parameter list, so the fix leads, and a fix written on the program’s own receiver is what the
reader types; the old text (“is declared with an empty parameter list, so naming it without a
call makes a function value, which is allowed only where …”) put the rule before the fix and
showed &lt;code&gt;x.m()&lt;/code&gt; for every receiver. Alternatives weighed: repeating a complex receiver’s source
text (the checker holds no source text, and a long chain would crowd the message); keeping the
&lt;code&gt;x.&lt;/code&gt; placeholder (it names a variable the program does not have). The opposite message, for
&lt;code&gt;x.m()&lt;/code&gt; on a parameterless &lt;code&gt;m&lt;/code&gt;, is unchanged: it already reads well inside lambdas, placeholders
and chains.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-13 (built on branch &lt;code&gt;fmt-two-space&lt;/code&gt;):
&lt;strong&gt;&lt;code&gt;avin fmt&lt;/code&gt; keeps a function’s clauses together.&lt;/strong&gt; No blank line goes between a function’s
signature and its first clause or between two of its clauses, at the top level, in a class, an
object, a trait or a block alike, and blank lines the source wrote there are dropped, around
any comments between the clauses too (the comments stay). A clause is recognised as the parser
recognises one: the name of the signature or clause before it at its level, an argument list,
then &lt;code&gt;=&lt;/code&gt;, a guard or an indented block of guards; the signature is a line naming the function
with typed parameters, no &lt;code&gt;=&lt;/code&gt; and no indented body. The function counts as one declaration, so
the blank line between it and a different declaration before or after it stays as before, and a
blank line inside a clause’s body is the body’s own and stays. In a literate file, blank lines
beside prose are the document’s and are kept even between clauses. Why: a function written as
clauses is one declaration and the preferred form for a function that matches on its
parameters; a blank line before a multi-line clause, which the rule for top-level declarations
put there, makes it read as several declarations. Alternatives weighed: keeping the blank lines
the source wrote and only not adding any (a file would read differently by who wrote it, and the
formatter is meant to settle exactly this); a blank line between clauses only around a
multi-line one (it still splits one function in two); a blank line between every clause
(it spreads a short definition over twice its lines).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;http-stream&lt;/code&gt;): &lt;strong&gt;A streamed response is a &lt;code&gt;Response&lt;/code&gt; whose body a
function writes through a &lt;code&gt;BodyWriter&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;Response.stream(status, contentType, write)&lt;/code&gt;, with a
&lt;code&gt;length&lt;/code&gt; overload, and &lt;code&gt;Response.events&lt;/code&gt; for server-sent events through an &lt;code&gt;EventWriter&lt;/code&gt;). The
head says &lt;code&gt;Transfer-Encoding: chunked&lt;/code&gt;, or &lt;code&gt;Content-Length&lt;/code&gt; where the length is given, or to an
HTTP/1.0 client neither, the body ending with the connection. Each write answers &lt;code&gt;Result[unit, IoError]&lt;/code&gt;, &lt;code&gt;Err&lt;/code&gt; once the client has gone or the server is stopping and for every later write;
a write past a given length traps; a handler trapping once the head is sent has its connection
closed with no &lt;code&gt;500&lt;/code&gt;. Why: one &lt;code&gt;Response&lt;/code&gt; type keeps routers, middleware and error pages working
on streamed answers unchanged, and a &lt;code&gt;Result&lt;/code&gt; per write makes the end of a stream the program’s
ordinary control flow. Alternatives weighed: a separate &lt;code&gt;StreamedResponse&lt;/code&gt; type beside &lt;code&gt;Response&lt;/code&gt;
(every handler type and middleware doubled); a handler handed the connection (the server loses
its framing and keep-alive); writes that trap when the client has gone (a client leaving is not a
bug). Review with the user: whether &lt;code&gt;Response.events&lt;/code&gt;‘s fifteen-second keep-alive default suits.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;http-stream&lt;/code&gt;): &lt;strong&gt;Typed parameters through a &lt;code&gt;FromParam&lt;/code&gt; trait of
static methods&lt;/strong&gt;, &lt;code&gt;paramAs[T]&lt;/code&gt;, &lt;code&gt;queryAs[T]&lt;/code&gt; (with a default overload) and &lt;code&gt;queryOption[T]&lt;/code&gt;
answering &lt;code&gt;Result[_, ParamError]&lt;/code&gt;, &lt;code&gt;Missing&lt;/code&gt; or &lt;code&gt;Invalid&lt;/code&gt;; &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt; and
&lt;code&gt;bool&lt;/code&gt; implement it. Why: a static &lt;code&gt;parse&lt;/code&gt; makes a program’s own type a parameter type by one
&lt;code&gt;impl&lt;/code&gt;, and a &lt;code&gt;Result&lt;/code&gt; lets &lt;code&gt;?&lt;/code&gt; answer the client &lt;code&gt;400&lt;/code&gt;. Alternatives weighed: separate
&lt;code&gt;queryInt&lt;/code&gt;/&lt;code&gt;queryLong&lt;/code&gt; methods (closed to a program’s own types); trapping on bad input (a client
error is not a server bug).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;http-stream&lt;/code&gt;): &lt;strong&gt;Handlers that fail answer &lt;code&gt;Result[Response, ToResponse]&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;ToResponse&lt;/code&gt; is a trait with &lt;code&gt;toResponse()&lt;/code&gt;, implemented by &lt;code&gt;Response&lt;/code&gt; itself and
&lt;code&gt;ParamError&lt;/code&gt;, &lt;code&gt;fromResult&lt;/code&gt; turns such a function into a &lt;code&gt;Handler&lt;/code&gt;, and each &lt;code&gt;Route.get&lt;/code&gt; … &lt;code&gt;patch&lt;/code&gt;
has an overload taking one. Why: &lt;code&gt;?&lt;/code&gt; then ends a handler with any failure the program’s own error
types can render, and a plain &lt;code&gt;Response&lt;/code&gt; handler is untouched. Alternatives weighed: one
&lt;code&gt;Result&lt;/code&gt;-only handler type (every simple handler would wrap in &lt;code&gt;Ok&lt;/code&gt;); an &lt;code&gt;Error&lt;/code&gt;-bounded error
rendered as &lt;code&gt;500&lt;/code&gt; (hides the status the program meant). Making the overloads work needed two
compiler fixes: a lambda tried against several overloads is compiled only for the one chosen, and
an argument checked before the overload was chosen is made &lt;code&gt;@sendable&lt;/code&gt; where the chosen one’s
parameter is (tests &lt;code&gt;overload_lambda_return&lt;/code&gt;, &lt;code&gt;overload_sendable&lt;/code&gt;, &lt;code&gt;overload_sendable_capture&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-request-values&lt;/code&gt;): &lt;strong&gt;A middleware
hands values on through the request, keyed by their exact type&lt;/strong&gt;: &lt;code&gt;ServerRequest.withValue[T: Sendable](value: T) -&amp;gt; ServerRequest&lt;/code&gt; and &lt;code&gt;value[T: Sendable]() -&amp;gt; Option[T]&lt;/code&gt;. &lt;code&gt;withValue&lt;/code&gt;
answers a new request; a second value of one type replaces the first; the key is the type
&lt;code&gt;withValue&lt;/code&gt; was given, compared exactly as a type pattern compares a generic type’s arguments
(each value is held in an invariant private &lt;code&gt;Carried[T]&lt;/code&gt; as an &lt;code&gt;Any&lt;/code&gt;), so a value handed on as a
trait is not read as its class nor the reverse, and &lt;code&gt;int&lt;/code&gt; is not &lt;code&gt;long&lt;/code&gt;. Parameters a router
binds keep the values. Why: the type is a key no two middlewares collide on by accident and that
needs no cast to read, reified type patterns make it sound with no new language feature, and a
request id or a span from a logging middleware fits the same API as a user from an auth one.
The names follow &lt;code&gt;withParams&lt;/code&gt; and &lt;code&gt;header(name)&lt;/code&gt; beside it. Both take &lt;code&gt;Sendable&lt;/code&gt; because a
handler may move what it reads onto another thread (&lt;code&gt;untilStopped&lt;/code&gt;), and a non-sendable &lt;code&gt;T&lt;/code&gt; is
refused at &lt;code&gt;value&lt;/code&gt; too rather than silently answering &lt;code&gt;None&lt;/code&gt;. Alternatives weighed: a key
object (&lt;code&gt;RequestKey[T]&lt;/code&gt;) for two values of one type — not built, since a program wraps each in
its own &lt;code&gt;data&lt;/code&gt; type, which also names what the value is, and the library has no key-object
idiom elsewhere; subtype matching on read (&lt;code&gt;value[Role]()&lt;/code&gt; finding an &lt;code&gt;Admin&lt;/code&gt;) — refused, since
which of two values answers would depend on their order; route parameters or headers as the
carrier — strings only, and spoofable from the client; the names &lt;code&gt;with&lt;/code&gt;/&lt;code&gt;get&lt;/code&gt; — &lt;code&gt;with&lt;/code&gt; already
means running a body on a &lt;code&gt;Mutex&lt;/code&gt;, and &lt;code&gt;withX&lt;/code&gt; is the request’s and the response’s existing
form. Review with the user: whether a key-object form is wanted after all.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;http-stream&lt;/code&gt;): &lt;strong&gt;Route groups and middleware are plain functions&lt;/strong&gt;:
&lt;code&gt;type Handler&lt;/code&gt;, a middleware &lt;code&gt;(Handler) -&amp;gt; Handler&lt;/code&gt;, &lt;code&gt;Route.wrap&lt;/code&gt;, &lt;code&gt;Route.under&lt;/code&gt; and
&lt;code&gt;Route.group(prefix, routes, middleware)&lt;/code&gt; answering a &lt;code&gt;Vector[Route]&lt;/code&gt;, nesting with the inner
middleware inside the outer. A prefix must begin with &lt;code&gt;/&lt;/code&gt; and not end with one, else it traps.
Why: groups flatten into the router’s one ordered list, so matching, &lt;code&gt;405&lt;/code&gt; and &lt;code&gt;HEAD&lt;/code&gt; stay as they
were. Alternatives weighed: a nested router type (two matching rules); a prefix tolerating a
trailing &lt;code&gt;/&lt;/code&gt; (two spellings of one path, and &lt;code&gt;//&lt;/code&gt; after joining).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;http-stream&lt;/code&gt;): &lt;strong&gt;Error pages are an &lt;code&gt;ErrorPage = @sendable (int) -&amp;gt; Response&lt;/code&gt;&lt;/strong&gt;, given to &lt;code&gt;Router&lt;/code&gt; (its &lt;code&gt;404&lt;/code&gt; and &lt;code&gt;405&lt;/code&gt;) and &lt;code&gt;http.serve&lt;/code&gt; (every status it answers
itself), defaulting to &lt;code&gt;plainError&lt;/code&gt;, the reason phrase as text; the status sent is always the one
given, and a &lt;code&gt;405&lt;/code&gt; keeps its &lt;code&gt;Allow&lt;/code&gt;. Why: one function covers JSON or HTML pages without a
table of statuses. Alternatives weighed: a &lt;code&gt;Map[int, Response]&lt;/code&gt; (every status listed by hand, and
none computed); letting the page change the status (a &lt;code&gt;404&lt;/code&gt; page answering &lt;code&gt;200&lt;/code&gt; misleads clients).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;http-stream&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;isStopping()&lt;/code&gt; and &lt;code&gt;untilStopped(wait)&lt;/code&gt; on a
&lt;code&gt;ServerRequest&lt;/code&gt;, &lt;code&gt;BodyWriter&lt;/code&gt; and &lt;code&gt;EventWriter&lt;/code&gt;&lt;/strong&gt;, &lt;code&gt;untilStopped&lt;/code&gt; running &lt;code&gt;wait&lt;/code&gt; on its own thread
through &lt;code&gt;TcpServer.idle&lt;/code&gt;, so stopping cancels it and the handler gets &lt;code&gt;None&lt;/code&gt;. Why: a long poll or
an event stream otherwise holds &lt;code&gt;join()&lt;/code&gt; until its client goes. Alternatives weighed: a
cancellation token passed to every handler (every handler signature changes); leaving shutdown
to the write timeout (a quiet stream would hold it for &lt;code&gt;writeTimeout&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-websocket&lt;/code&gt;): &lt;strong&gt;An upgrade is a
&lt;code&gt;Response&lt;/code&gt; too&lt;/strong&gt;: &lt;code&gt;Response.upgrade(protocol, take)&lt;/code&gt; is a &lt;code&gt;101&lt;/code&gt; carrying an &lt;code&gt;Upgrade&lt;/code&gt;, and the
server, seeing one, writes the head with &lt;code&gt;Upgrade: protocol&lt;/code&gt; and &lt;code&gt;Connection: Upgrade&lt;/code&gt; and hands
&lt;code&gt;take&lt;/code&gt; an &lt;code&gt;Upgraded&lt;/code&gt; (the stream, the bytes it had read ahead past the request, the write limit,
and the server’s &lt;code&gt;isStopping&lt;/code&gt;/&lt;code&gt;untilStopped&lt;/code&gt;), reading no more requests and closing the connection
once &lt;code&gt;take&lt;/code&gt; returns; a trap in &lt;code&gt;take&lt;/code&gt; closes it with no &lt;code&gt;500&lt;/code&gt;. Why: routes, groups and middleware
apply to a WebSocket route unchanged, as they do to a streamed one, and the bytes read ahead are
not lost when a client sends its first frame with the handshake. Alternatives weighed: a separate
upgrade handler type on &lt;code&gt;Route&lt;/code&gt; (middleware written twice); handing the raw &lt;code&gt;ByteStream&lt;/code&gt; alone
(a frame read ahead with the request would vanish).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-websocket&lt;/code&gt;): &lt;strong&gt;WebSockets in
&lt;code&gt;avin.net.http&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;webSocket(request, session, protocols, maxMessageBytes = 1 MiB, closeTimeout = 5 s) -&amp;gt; Response&lt;/code&gt; checks the handshake and answers &lt;code&gt;101&lt;/code&gt;, &lt;code&gt;405&lt;/code&gt; (not &lt;code&gt;GET&lt;/code&gt;), &lt;code&gt;426&lt;/code&gt; with
&lt;code&gt;Upgrade: websocket&lt;/code&gt; (no upgrade to a WebSocket asked), &lt;code&gt;426&lt;/code&gt; with &lt;code&gt;Sec-WebSocket-Version: 13&lt;/code&gt;
(another version) or &lt;code&gt;400&lt;/code&gt; (HTTP/1.0, no &lt;code&gt;Connection: Upgrade&lt;/code&gt;, a key not sixteen bytes of
base64); the subprotocol chosen is the server’s first that the client offers. &lt;code&gt;WebSocket.connect(url, headers, protocols, tls, timeout, maxMessageBytes)&lt;/code&gt; is the client, &lt;code&gt;ws&lt;/code&gt; and &lt;code&gt;wss&lt;/code&gt;. Both ends share
one &lt;code&gt;WebSocket&lt;/code&gt;: &lt;code&gt;send(text)&lt;/code&gt;, &lt;code&gt;send(bytes)&lt;/code&gt;, &lt;code&gt;ping&lt;/code&gt;, &lt;code&gt;receive()&lt;/code&gt;, &lt;code&gt;receive(limit)&lt;/code&gt;, &lt;code&gt;close(code, reason)&lt;/code&gt;, &lt;code&gt;isOpen&lt;/code&gt;, &lt;code&gt;isStopping&lt;/code&gt;, &lt;code&gt;untilStopped&lt;/code&gt;, answering &lt;code&gt;Result[_, WebSocketError]&lt;/code&gt; (&lt;code&gt;Closed(code, reason)&lt;/code&gt;, &lt;code&gt;Broken&lt;/code&gt;, and for &lt;code&gt;connect&lt;/code&gt; &lt;code&gt;Refused&lt;/code&gt;, &lt;code&gt;BadHandshake&lt;/code&gt;, &lt;code&gt;Unreachable&lt;/code&gt;). Why: one module
with the HTTP server it upgrades from, and errors the program’s control flow handles, as a
&lt;code&gt;BodyWriter&lt;/code&gt;‘s are. Alternatives weighed: an &lt;code&gt;avin.net.websocket&lt;/code&gt; module (it needs the server’s
private connection loop); a callback per message (&lt;code&gt;onText&lt;/code&gt;, &lt;code&gt;onClose&lt;/code&gt;; the session’s own loop
reads more plainly and keeps its state in locals).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-websocket&lt;/code&gt;): &lt;strong&gt;What a WebSocket
does by itself&lt;/strong&gt;: a ping is answered with a pong as it arrives and a pong is passed over; a
fragmented message is put back together, control frames between its fragments answered; the size
limit is checked against a frame’s declared length before its payload is read, so an oversized
message is refused without being buffered (&lt;code&gt;1009&lt;/code&gt;); text is checked to be UTF-8 once the message
is whole (&lt;code&gt;1007&lt;/code&gt;), and so is a close reason; a frame breaking the protocol (&lt;code&gt;1002&lt;/code&gt;) — a client’s
frame not masked or a server’s masked, a reserved bit, an unknown opcode, a fragmented or long
control frame, a continuation with nothing to continue or a new message inside one, a close of
one byte or with a code no endpoint may send, a 64-bit length with its top bit set — fails the
connection: the close frame is sent and the connection closed at once. A close from the other end
is answered with its code (none for none, heard as &lt;code&gt;1005&lt;/code&gt;) and the connection closed; this end’s
&lt;code&gt;close&lt;/code&gt; waits &lt;code&gt;closeTimeout&lt;/code&gt; for the answer. A session returning with its WebSocket open closes it
with &lt;code&gt;1000&lt;/code&gt;; a server stopping closes it with &lt;code&gt;1001&lt;/code&gt; at its next receive (the wait being through
&lt;code&gt;idle&lt;/code&gt;) or send; a peer going without a close is &lt;code&gt;Closed(1006, …)&lt;/code&gt;. A frame’s length need not be
in its fewest bytes, though this end writes it so; every message is sent as one frame; a client
masks each frame with four bytes from &lt;code&gt;SecureRandom&lt;/code&gt;. Why: these are RFC 6455’s rules where it
gives them, and where it leaves a choice (validating UTF-8 at the end rather than as fragments
arrive, accepting a longer-than-needed length) the simpler one that still refuses what it must.
Alternatives weighed: surfacing pings and pongs as messages (every session would answer them by
hand); validating UTF-8 per fragment (fails a bad message sooner, at more code). &lt;strong&gt;Review with the
user:&lt;/strong&gt; a &lt;code&gt;WebSocket&lt;/code&gt; belongs to one thread, as its stream does (a TLS stream checks its owner), so
a session that must send what another thread produces while also receiving polls with
&lt;code&gt;receive(limit)&lt;/code&gt;; a &lt;code&gt;select&lt;/code&gt;-like receive over a channel, or a sendable sending half, would be the
next step if a program needs one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;lazy-local&lt;/code&gt;): &lt;strong&gt;A local &lt;code&gt;lazy val&lt;/code&gt;, in a block, is the value of a
cell made where it is declared&lt;/strong&gt;, the core library’s private &lt;code&gt;LazyCell[T]&lt;/code&gt;, holding the value, its
state word and the closure computing it, so a read is that cell’s lazy field read: once on the
first read, under the same protocol as a field’s between threads, with the same trap for a read
made while it is being computed. The choices the request left open:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Closures share it.&lt;/em&gt; A closure capturing the name captures the cell, so a first read inside
the closure computes it for the enclosing scope too, and the reverse; it outlives its block. A
declaration in a loop body makes a new cell on every pass. &lt;em&gt;Alternatives&lt;/em&gt;: copying the value
into the closure at capture (would force it where the closure is made, defeating the point);
one cell per declaration site (wrong for loops and recursion).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;The initializer sees the locals as they are at the first read&lt;/em&gt;, a captured &lt;code&gt;var&lt;/code&gt; included,
since it is a lambda run then; fields see their object at the first read in the same way.
&lt;em&gt;Alternative&lt;/em&gt;: snapshotting the locals at the declaration (would need a copy of every captured
&lt;code&gt;var&lt;/code&gt;, and differs from what a lambda written in the same place does).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Across threads, sendable where its type is and its initializer would be.&lt;/em&gt; A &lt;code&gt;@sendable&lt;/code&gt;
closure (a thread’s body, a future’s) may capture a local &lt;code&gt;lazy val&lt;/code&gt; only where the value’s
type is sendable and every local and parameter the initializer captures passes the rules that
closure is held to, a &lt;code&gt;var&lt;/code&gt; refused, through each lazy value the initializer reads in turn; what
the initializer reaches is held to the module-level state rule too. &lt;em&gt;Why&lt;/em&gt;: the initializer may
run on whichever thread reads first, so it is code the closure carries; a field’s initializer
captures only its object, which the object’s own sendability covers. &lt;em&gt;Alternatives&lt;/em&gt;: refusing
every capture of a lazy local by a &lt;code&gt;@sendable&lt;/code&gt; closure (simpler, but refuses the plain case of
a sendable value computed from sendable &lt;code&gt;val&lt;/code&gt;s); checking the value’s type alone (unsound: an
initializer capturing a &lt;code&gt;Buffer&lt;/code&gt; or a &lt;code&gt;var&lt;/code&gt; would run on another thread).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;A self-read follows the other lazy values&lt;/em&gt;: today it traps at run time, &lt;code&gt;avin: trap: `x` is read while it is being initialized&lt;/code&gt;, as a field’s and a module-level value’s do, and a lazy
list may refer to itself through its cells. The sound-initialization design (&lt;code&gt;### lazy val&lt;/code&gt; in
declarations) makes a read the initializer’s own code reaches a compile error; a local is held
to it in the same way when that is built, and its run tests &lt;code&gt;lazy_local_self_direct&lt;/code&gt; (a direct
read, which becomes a reject test) and &lt;code&gt;lazy_local_self&lt;/code&gt; (a read through a closure the
initializer calls, which stays a trap) say which side each falls on. A trap in the initializer
stops the program as any trap does.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;The type must be known where it is declared&lt;/em&gt;: an initializer whose type is not settled there
(one reading only its own value) is refused with “cannot infer the type of &lt;code&gt;x&lt;/code&gt;“, as a field’s
is, rather than settled by later uses as a plain &lt;code&gt;val&lt;/code&gt;‘s may be. An initializer that never
finishes gives the type &lt;code&gt;Nothing&lt;/code&gt;. A mismatch with a declared type is reported as “the
initializer of &lt;code&gt;x&lt;/code&gt; yields …”.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;One name per declaration&lt;/em&gt;: &lt;code&gt;lazy val (a, b) = …&lt;/code&gt; and &lt;code&gt;lazy val a, b = …&lt;/code&gt; are refused (“take
the value apart where it is read”), as is a &lt;code&gt;lazy val&lt;/code&gt; without an initializer; an assignment, a
compound assignment and a step are refused as for a module-level &lt;code&gt;lazy val&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Cost&lt;/em&gt;: a declaration allocates the cell and the initializer’s closure, both kept until the cell
is unreachable. &lt;em&gt;Alternative weighed&lt;/em&gt;: storing the value, state and closure in boxed locals
without an object (saves one allocation but needs a layout of its own in the lowering and a
separate sendability rule); clearing the closure after the first read (frees its captures early,
but fields keep theirs, and a race-free clear needs another store on the hot path).
Review with the user: the cross-thread rule (the more permissive of the two sound choices).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;sync-kit&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;WaitGroup&lt;/code&gt; counts work and has no &lt;code&gt;spawn&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;add&lt;/code&gt;,
&lt;code&gt;done&lt;/code&gt;, &lt;code&gt;wait&lt;/code&gt;, a timed &lt;code&gt;waitFor&lt;/code&gt; and &lt;code&gt;pending&lt;/code&gt;; a count below zero traps. Why: a scope already
starts threads and waits for them structurally, so a spawning wait group would be a second way to
do what &lt;code&gt;scope&lt;/code&gt; does; what a wait group adds is counting work finished by threads started
elsewhere (an executor, an actor, another scope) or by no thread at all. Alternatives weighed:
&lt;code&gt;wg.spawn(body)&lt;/code&gt; starting and counting a thread (duplicates &lt;code&gt;Scope.spawn&lt;/code&gt;, and an unscoped spawn
escapes cancellation); answering a negative count by clamping at zero (hides a double &lt;code&gt;done&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;sync-kit&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;Semaphore&lt;/code&gt; has a capacity, and a release beyond it
traps.&lt;/strong&gt; &lt;code&gt;Semaphore(permits, capacity = permits)&lt;/code&gt;; negative permits, a capacity below one or more
permits than the capacity trap too. Permits belong to no thread, and waiters are not queued (one
arriving as a permit comes back may take it first). Why: an over-release is the same bug as a
wait group’s double &lt;code&gt;done&lt;/code&gt;, a permit given back that nobody took, and a trap finds it where it
happens; the separate capacity keeps the signalling use (&lt;code&gt;Semaphore(0, capacity = 1)&lt;/code&gt;) that an
“at most the initial permits” rule would forbid. Alternatives weighed: an unbounded count (a
silent over-release grows the limit for good); permits owned by the thread that took them (rules
out a permit taken by one thread and given back by another, which hand-offs need); a FIFO queue
of waiters (a cancelled waiter would have to take its place back, for a fairness the condition’s
oldest-first wake mostly gives already). Review with the user: trap or ignore an over-release.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;sync-kit&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;withPermit&lt;/code&gt; and a &lt;code&gt;RwLock&lt;/code&gt;‘s read give back what they
hold when a cancellation stops their body; a &lt;code&gt;RwLock&lt;/code&gt;‘s write runs to its end; a trap in any of
them stops the program.&lt;/strong&gt; The share is taken under the library’s lock and held in a region in
doubt from that moment until it is given back (the runtime’s new &lt;code&gt;lock_release_holding&lt;/code&gt; and
&lt;code&gt;cancel_guarded_held&lt;/code&gt;), so no cancellation can come between taking it and the body. A read body
or a permit’s body runs at a cancellation point of its own inside that region, so a cancelled scope stops
a long download inside &lt;code&gt;withPermit&lt;/code&gt; at once and the permit goes back, while a trap there, even in
an actor, stops the program as one under a lock does, since recovering the actor’s turn would
leave the share held for ever. A write body is also uncancellable, as a &lt;code&gt;Mutex&lt;/code&gt;‘s body is, since
stopping it could leave the value half changed. Why: a semaphore guards no value, and a reader
changes nothing, so nothing is left in doubt by stopping them; a writer does change the value.
Alternatives weighed: every body uncancellable, as a mutex’s (a scope’s cancellation would wait
for every permit holder’s whole body); every body cancellable (a write could leave the value
torn); a trap in an actor’s body failing only the actor (needs a give-back chain run by the
actor’s recovery, which the runtime does not have).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;sync-kit&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;RwLock&lt;/code&gt; lets writers in first, and lets in the readers
a write kept waiting before the next writer.&lt;/strong&gt; A reader that arrives while a writer waits waits
behind it; when a write ends, every reader then waiting is admitted ahead of the writers waiting.
Why: writers do not starve under overlapping readers, and readers do not starve under back-to-back
writers, with no tuning. Alternatives weighed: pure writer preference (readers starve while
writers keep coming); reader preference (writers starve); a strict FIFO of both (serialises
readers that could share). Review with the user: a read body is trusted only to read; nothing
stops it changing a mutable value other readers share, which races with them (a race is not
undefined behaviour in Avin, but the type system does not rule it out here as it does elsewhere).
A read-only view of a value would close it and is a language feature, not a library one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;sync-kit&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;Barrier&lt;/code&gt;‘s action runs under its lock, and a party
cancelled while waiting withdraws.&lt;/strong&gt; The last arrival runs the action holding the barrier’s lock,
so the action is uncancellable and one that waits on its own barrier traps as a lock taken twice
does; &lt;code&gt;wait&lt;/code&gt; answers whether the caller arrived last. A cancelled waiter takes its arrival back
(it is not counted for the round), through the runtime’s settling condition wait, which answers a
cancellation with the lock held again rather than stopping at once. Why: a scope cancelled
mid-round leaves the barrier as if the stopped parties had never come, ready for new ones.
Alternatives weighed: a cancelled party staying counted (the round could trip with a party
missing); “breaking” the barrier for every party (a state each &lt;code&gt;wait&lt;/code&gt; would have to answer);
running the action outside the lock (waiting on its own barrier would then deadlock instead of
trapping).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled by the user 2026-11-14 (built on branch &lt;code&gt;contextual-keywords&lt;/code&gt;, from the user’s decision of 2026-11-14 that
&lt;code&gt;data&lt;/code&gt; keeps its spelling and becomes contextual): &lt;strong&gt;the words that begin a top-level declaration
are keywords only there, before the name they declare, and ordinary names everywhere else&lt;/strong&gt;:
&lt;code&gt;data&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;trait&lt;/code&gt;, &lt;code&gt;impl&lt;/code&gt;, &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;module&lt;/code&gt; join &lt;code&gt;type&lt;/code&gt;, &lt;code&gt;opaque&lt;/code&gt;, &lt;code&gt;export&lt;/code&gt;,
&lt;code&gt;derive&lt;/code&gt;, &lt;code&gt;actor&lt;/code&gt; and &lt;code&gt;machine&lt;/code&gt;, and &lt;code&gt;open&lt;/code&gt; and &lt;code&gt;abstract&lt;/code&gt; are keywords only before &lt;code&gt;class&lt;/code&gt;. So
&lt;code&gt;val data = readFile(p)&lt;/code&gt;, a field &lt;code&gt;class&lt;/code&gt;, a method &lt;code&gt;object()&lt;/code&gt;, a parameter &lt;code&gt;import&lt;/code&gt;, a named
argument &lt;code&gt;module = 2&lt;/code&gt;, a type parameter, a variant, a module named &lt;code&gt;data&lt;/code&gt; and &lt;code&gt;r.type&lt;/code&gt; are all
legal, and &lt;code&gt;data(x: int)&lt;/code&gt; at the top level declares a function called &lt;code&gt;data&lt;/code&gt;. &lt;strong&gt;The reserved
words stay&lt;/strong&gt;: &lt;code&gt;as&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;then&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;do&lt;/code&gt;, &lt;code&gt;yield&lt;/code&gt; and &lt;code&gt;derives&lt;/code&gt;, because each
follows a complete operand on its line (&lt;code&gt;x as T&lt;/code&gt;, &lt;code&gt;if c then a&lt;/code&gt;, &lt;code&gt;Base(x) derives Eq&lt;/code&gt;), where a
name is an infix call; &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;loop&lt;/code&gt;, &lt;code&gt;defer&lt;/code&gt;, &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt;, &lt;code&gt;val&lt;/code&gt;,
&lt;code&gt;var&lt;/code&gt; and &lt;code&gt;def&lt;/code&gt;, because each begins a statement or a declaration inside a block, where a line may
equally be an expression starting with a name (&lt;code&gt;loop&lt;/code&gt; and an indented block would read as a call
of &lt;code&gt;loop&lt;/code&gt; with a trailing block; &lt;code&gt;return (x)&lt;/code&gt; as a call); &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt; and &lt;code&gt;override&lt;/code&gt;,
because they begin a member of a class body, where a line may be a statement, and &lt;code&gt;private + (o: T)&lt;/code&gt; would be both a method named by a symbol and an expression on a value; &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt;,
&lt;code&gt;self&lt;/code&gt; and &lt;code&gt;super&lt;/code&gt;, which are values. &lt;code&gt;end&lt;/code&gt; keeps its rule (a keyword only before a name), and
&lt;code&gt;not&lt;/code&gt; and &lt;code&gt;with&lt;/code&gt; theirs. Why: the test is whether the keyword’s every position can be told from a
name’s by the next token alone. A top-level line holds only declarations, never a statement, so a
declaration word followed by a name can mean nothing else, and none of these words begins
anything inside a block or a class body. Alternatives weighed: renaming &lt;code&gt;data&lt;/code&gt; (the user kept the
spelling); making every word contextual by look-ahead over whole lines (&lt;code&gt;loop&lt;/code&gt;, &lt;code&gt;return&lt;/code&gt; and the
modifiers would each need a rule of their own that a reader cannot see at a glance); keeping
&lt;code&gt;class&lt;/code&gt; and &lt;code&gt;object&lt;/code&gt; reserved as the most declaration-like (they are common field names, and
nothing about them is less decidable than &lt;code&gt;data&lt;/code&gt;). The user
settled 2026-11-14 that &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt; and &lt;code&gt;override&lt;/code&gt; stay reserved: a modifier used as a
variable name would read strangely.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-7&lt;/code&gt;): &lt;strong&gt;a trait for types whose
members never write &lt;code&gt;Self&lt;/code&gt; bounds constructors too&lt;/strong&gt;
(&lt;a href=&quot;/spec/generics/#constructor-traits&quot;&gt;generics&lt;/a&gt;). A trait with parameters, no static member, no
member naming &lt;code&gt;Self&lt;/code&gt; beyond the receiver, and requiring only such traits (&lt;code&gt;Foldable[A]&lt;/code&gt;, any
&lt;code&gt;Countable[A]&lt;/code&gt; of a program’s own) is a trait for types everywhere it is one, and also a bound of
a constructor parameter of its arity: &lt;code&gt;impl Foldable for Option&lt;/code&gt; makes each &lt;code&gt;Option[T]&lt;/code&gt; a
&lt;code&gt;Foldable[T]&lt;/code&gt;, so &lt;code&gt;Option&lt;/code&gt; is a constructor for &lt;code&gt;[F[_]: Foldable]&lt;/code&gt;, and a constructor trait may
require it at its own parameters (&lt;code&gt;trait Traverse[A]: Functor[A], Foldable[A]&lt;/code&gt;). A type conforms
as a constructor only where a conformance states the trait’s parameters as its own parameters,
so &lt;code&gt;impl Foldable[int] for Ints&lt;/code&gt; makes no constructor; a type whose parameter is bounded is one
only for a hole promising that bound (&lt;code&gt;TreeSet&lt;/code&gt; for &lt;code&gt;F[_: Ord]&lt;/code&gt;), as for a constructor trait; a
trait naming &lt;code&gt;Self&lt;/code&gt; otherwise or declaring a static member bounds types only, and one writing
&lt;code&gt;Self[X]&lt;/code&gt; stays a constructor trait, never a type. Why: &lt;code&gt;Foldable&lt;/code&gt;‘s method mentions no &lt;code&gt;Self&lt;/code&gt;,
so what it promises of an &lt;code&gt;F[X]&lt;/code&gt; is exactly what the type conformance promises of that type; one
trait serves both uses, generic code over constructors reads the conformances the collections
already have, and nothing new is needed at run time (each instance’s call is the ordinary call on
its type). Alternatives weighed: a constructor trait requiring a trait for types at its holes (a
constraint on every application &lt;code&gt;Self[A]&lt;/code&gt;, a second notion with its own rules, where the dual
reading needs none); giving &lt;code&gt;Foldable&lt;/code&gt; a method that writes &lt;code&gt;Self&lt;/code&gt; (an artificial member, and it
would stop &lt;code&gt;Foldable[int]&lt;/code&gt; being a type). This supersedes the Proposed “a constructor trait
requires only constructor traits” (branch &lt;code&gt;hkt-3&lt;/code&gt;) for traits that bound constructors.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-7&lt;/code&gt;): &lt;strong&gt;every &lt;code&gt;Iterable[A]&lt;/code&gt; is a
&lt;code&gt;Foldable[A]&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;Iterable&lt;/code&gt; requires &lt;code&gt;Foldable&lt;/code&gt; and gives &lt;code&gt;foldLeft&lt;/code&gt; as its default, moved from the
impl adding methods to every &lt;code&gt;Iterable&lt;/code&gt;; &lt;code&gt;List&lt;/code&gt; gives its own walk in its impl of &lt;code&gt;Seq&lt;/code&gt; and
&lt;code&gt;Vector&lt;/code&gt; overrides it, so every collection of one parameter is a constructor for &lt;code&gt;[F[_]: Foldable]&lt;/code&gt; with no impl of its own, and &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt; gain &lt;code&gt;foldLeft&lt;/code&gt; in their
impls of &lt;code&gt;Traverse&lt;/code&gt;. A class of a program’s own conforming to &lt;code&gt;Iterable&lt;/code&gt; that declares its own
&lt;code&gt;foldLeft&lt;/code&gt; now marks it &lt;code&gt;override&lt;/code&gt;. Why: the fold is what every collection already has, and the
nominal rule needs a conformance; one in &lt;code&gt;Iterable&lt;/code&gt; gives it to all of them at once. Alternatives
weighed: &lt;code&gt;impl Foldable for&lt;/code&gt; each collection (an impl per type, each restating &lt;code&gt;foldLeft&lt;/code&gt;, since
a method an impl adds to a trait does not implement another trait’s); leaving the collections
out of &lt;code&gt;Foldable&lt;/code&gt; (generic folds would not take a &lt;code&gt;Vector&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-7&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Seq&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; leave
the table of the standard constructor traits; the impls are for concrete types only&lt;/strong&gt;
(&lt;a href=&quot;/spec/generics/#functor-applicative-monad-traverse&quot;&gt;generics&lt;/a&gt;): &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;,
&lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;LazyList&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt;, and the sets and
sorted collections as &lt;code&gt;Foldable&lt;/code&gt; only, since their &lt;code&gt;map&lt;/code&gt; answers a &lt;code&gt;Set&lt;/code&gt; and needs &lt;code&gt;Eq &amp;amp; Hash&lt;/code&gt; or
&lt;code&gt;Ord&lt;/code&gt; of its result. Generic code over sequences takes an &lt;code&gt;F[_]: Monad&lt;/code&gt; (or the trait it needs).
No impl is for a trait type. Why: an impl is for a type’s own constructor, and a trait’s &lt;code&gt;map&lt;/code&gt;
answers the trait’s type for every implementing class, so &lt;code&gt;Seq&lt;/code&gt; could meet &lt;code&gt;Functor&lt;/code&gt; only through
an impl for a trait, which the language does not have. Alternatives weighed: impls for trait
types, a future language feature, added only if a library need appears.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-7&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;traverse&lt;/code&gt; and
&lt;code&gt;sequence&lt;/code&gt; through &lt;code&gt;Applicative.map2&lt;/code&gt; apply &lt;code&gt;f&lt;/code&gt; to every element and answer the first failure.&lt;/strong&gt;
The spec’s “stops at the first failure” means the result, not evaluation: a sequence’s
&lt;code&gt;traverse&lt;/code&gt; folds through &lt;code&gt;map2&lt;/code&gt;, which runs &lt;code&gt;f&lt;/code&gt; on each element in order, and the first &lt;code&gt;None&lt;/code&gt;,
&lt;code&gt;Err&lt;/code&gt; or &lt;code&gt;Left&lt;/code&gt; decides what is answered. Why: &lt;code&gt;traverse&lt;/code&gt; is written once for every applicative,
and &lt;code&gt;map2&lt;/code&gt; is all an applicative gives; stopping early would need a short-circuiting fold the
trait does not have. Alternatives weighed: a stopping &lt;code&gt;traverse&lt;/code&gt; per constructor of the result
(&lt;code&gt;Option&lt;/code&gt;‘s, &lt;code&gt;Result&lt;/code&gt;‘s), which generic code at a program’s own applicative would not have.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-7&lt;/code&gt;): &lt;strong&gt;a constructor trait’s
parameter bounds ask nothing of the conforming type’s parameters&lt;/strong&gt;: &lt;code&gt;impl SendableMonad for Future&lt;/code&gt;, whose &lt;code&gt;T&lt;/code&gt; has no bound, conforms, since the trait applies the constructor only to
types meeting &lt;code&gt;Sendable&lt;/code&gt;; a type whose parameter is bounded by more than the trait’s parameter
promises is still refused, and a trait requiring the trait bounds its own parameter as it does.
A conformance had held &lt;code&gt;T&lt;/code&gt; to &lt;code&gt;Sendable&lt;/code&gt; as an ordinary trait argument, against the spec’s
“bounded by no more than &lt;code&gt;Sendable&lt;/code&gt;“. Alternatives: none that keep &lt;code&gt;Future&lt;/code&gt; a &lt;code&gt;SendableMonad&lt;/code&gt;
with its parameter unbounded.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-8&lt;/code&gt;): &lt;strong&gt;a value bounded by two
traits that reach one method, one of them overriding it, has the override alone&lt;/strong&gt;: with
&lt;code&gt;F[_]: Monad &amp;amp; Filter&lt;/code&gt;, &lt;code&gt;fa.map&lt;/code&gt; is &lt;code&gt;Monad&lt;/code&gt;‘s default, not also the &lt;code&gt;Functor&lt;/code&gt; method &lt;code&gt;Filter&lt;/code&gt;
requires; with &lt;code&gt;T: Loud &amp;amp; Quiet&lt;/code&gt; over &lt;code&gt;Base&lt;/code&gt;, &lt;code&gt;describe&lt;/code&gt; is &lt;code&gt;Loud&lt;/code&gt;‘s override. The calls had
been reported ambiguous, so the spec’s &lt;code&gt;F[_]: Monad &amp;amp; Filter&lt;/code&gt; took no comprehension. Why: a
type conforming to both has the override as its one method, so the bound has it too, as a type
inheriting both already did (&lt;code&gt;unreplaced&lt;/code&gt;). Alternatives: none; the ambiguity was a bug.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-8&lt;/code&gt;): &lt;strong&gt;the views
&lt;code&gt;withFilter&lt;/code&gt; makes conform to &lt;code&gt;Iterable&lt;/code&gt;&lt;/strong&gt;, each by an &lt;code&gt;iterator()&lt;/code&gt; that tests the source’s
elements as they are reached; their own &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;withFilter&lt;/code&gt; and &lt;code&gt;foreach&lt;/code&gt; are
kept, so a comprehension’s result is the collection’s as before. Why: the spec says the calls
after a guard are on an &lt;code&gt;Iterable&lt;/code&gt;; a view may now be held as one, looped over and folded.
Alternatives: leaving the views outside the hierarchy (a guard’s result could not be passed
where an &lt;code&gt;Iterable&lt;/code&gt; is wanted).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (built on branch &lt;code&gt;hkt-8&lt;/code&gt;): &lt;strong&gt;a refused
comprehension source names the fix only where the module can make it&lt;/strong&gt;: &lt;code&gt;declare impl Monad for Box&lt;/code&gt; for a type of one parameter declared in the module being checked, “declare an impl of
&lt;code&gt;Monad&lt;/code&gt; for &lt;code&gt;Pair&lt;/code&gt; at the parameter it holds its elements in” for one of more, “a type of no
parameters is a source only as an &lt;code&gt;Iterable&lt;/code&gt;“ for one of none, “add &lt;code&gt;Monad&lt;/code&gt; to the bounds of
&lt;code&gt;F&lt;/code&gt;“ in generic code, and nothing for another module’s type (&lt;code&gt;Result&lt;/code&gt;‘s missing &lt;code&gt;Filter&lt;/code&gt;), whose
impl the module rule puts out of reach. The source is named where it is a name (&lt;code&gt;`box` is a `Box[int]`&lt;/code&gt;), “this source” otherwise; a guard’s refusal is reported at the guard. A source
is checked for its roles before any call on it, and a refused one checks nothing after it.
Alternatives: always suggesting an impl (wrong advice for a library type).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-pool&lt;/code&gt;): &lt;strong&gt;a resource pool is
&lt;code&gt;avin.threads.Pool[T, E]&lt;/code&gt;, lending through a body&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#pools&quot;&gt;pools&lt;/a&gt;). &lt;code&gt;use(f)&lt;/code&gt;
and &lt;code&gt;lease(f)&lt;/code&gt; lend a resource for the call of &lt;code&gt;f&lt;/code&gt; and always take it back, answering
&lt;code&gt;Result[R, PoolError[E]]&lt;/code&gt;; there is no &lt;code&gt;acquire&lt;/code&gt;/&lt;code&gt;release&lt;/code&gt; pair. Why: the scope of the body is
what makes “always returned” true by construction, on a return, a cancellation inside it, and a
trap (which stops the program); a resource handed out by &lt;code&gt;acquire&lt;/code&gt; comes back only if every path
remembers to give it back. It sits in &lt;code&gt;avin.threads&lt;/code&gt; beside the semaphore it resembles, built on
the same lock and cancellation machinery; the executor’s private worker pool, which was also
called &lt;code&gt;Pool&lt;/code&gt;, is renamed &lt;code&gt;WorkerPool&lt;/code&gt;. Alternatives weighed: an &lt;code&gt;acquire()&lt;/code&gt; answering a lease to
&lt;code&gt;release()&lt;/code&gt; by hand (an actor holding a connection across messages would want it; it can be added
beside the body form later); a module of its own (&lt;code&gt;avin.pool&lt;/code&gt;), which would need the threads
module’s private machinery made public. &lt;strong&gt;Review with the user:&lt;/strong&gt; whether an explicit
acquire/release form is wanted for resources held across an actor’s messages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-pool&lt;/code&gt;): &lt;strong&gt;a pool’s resources
are isolated rather than sendable.&lt;/strong&gt; A &lt;code&gt;Pool&lt;/code&gt; is sendable whatever &lt;code&gt;T&lt;/code&gt; is, as a &lt;code&gt;Mutex&lt;/code&gt; is:
&lt;code&gt;create&lt;/code&gt;, &lt;code&gt;validate&lt;/code&gt; and &lt;code&gt;destroy&lt;/code&gt; are &lt;code&gt;@sendable&lt;/code&gt;, so a resource is made from sendable values
alone, and &lt;code&gt;use&lt;/code&gt;‘s and &lt;code&gt;lease&lt;/code&gt;‘s bodies are &lt;code&gt;@isolating&lt;/code&gt; and give back a sendable &lt;code&gt;R&lt;/code&gt;, so the
resource never leaves the call it is lent to. Why: the resources worth pooling are mutable
(a connection’s buffers and state), and a program’s mutable class cannot promise &lt;code&gt;Sendable&lt;/code&gt; (the
&lt;code&gt;@trusted_sendable&lt;/code&gt; mark is the standard library’s), so a pool that asked &lt;code&gt;T: Sendable&lt;/code&gt; could not
hold the database client it exists for. The cost: a body may not capture a mutable value from
around it, and two mutable resources cannot be used in one nested body (&lt;code&gt;db.use(c -&amp;gt; cache.use(r -&amp;gt; … c …))&lt;/code&gt; is refused, since the inner body captures &lt;code&gt;c&lt;/code&gt;). Alternatives weighed:
&lt;code&gt;T: Sendable&lt;/code&gt; (sound, and too narrow, as above); unrestricted bodies (a resource kept past its
call would be used by two threads at once). &lt;strong&gt;Review with the user:&lt;/strong&gt; the nested-body
restriction, which a borrow form the language does not have would lift.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-pool&lt;/code&gt;): &lt;strong&gt;a pool’s waiters
are served first come, first served, by direct hand-off.&lt;/strong&gt; A resource given back goes straight
to the call that has waited longest, and so does the place a destroyed resource or a failed make
gives up; a new call queues behind any waiter even when it comes just as a resource is given
back, so no call is overtaken. Idle resources are lent most recently used first, so the oldest
expire under &lt;code&gt;idleTimeout&lt;/code&gt;. Why: fairness the brief asks for, and an &lt;code&gt;AcquireTimedOut&lt;/code&gt; under
load then means the pool is too small rather than unlucky. Alternatives weighed: waking any
waiter and letting it race (the semaphore’s way; cheaper, and unfair); oldest idle first (keeps
every connection warm, and none ever expires on a quiet server).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-pool&lt;/code&gt;): &lt;strong&gt;every function a
pool runs for a call runs where a trap cannot be contained.&lt;/strong&gt; A trap inside &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;create&lt;/code&gt;,
&lt;code&gt;validate&lt;/code&gt; or &lt;code&gt;destroy&lt;/code&gt; stops the program even in an actor, as one inside &lt;code&gt;withPermit&lt;/code&gt; does.
Why: an actor that survived the trap would leave the pool counting a resource or a place that is
never given back, shrinking it for good. &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;create&lt;/code&gt; stay cancellable; &lt;code&gt;destroy&lt;/code&gt; runs to its
end. Alternatives weighed: containing the trap and leaking the place (a pool that slowly loses
capacity in a long-running server). &lt;strong&gt;Review with the user:&lt;/strong&gt; a server whose handlers are actors
may prefer the handler’s failure to the program’s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-pool&lt;/code&gt;): &lt;strong&gt;idle resources
expire when the pool is next used, not on a timer of their own.&lt;/strong&gt; A call looking for a resource,
and &lt;code&gt;evictIdle()&lt;/code&gt;, destroy those idle longer than &lt;code&gt;idleTimeout&lt;/code&gt;, keeping &lt;code&gt;minIdle&lt;/code&gt;; &lt;code&gt;minIdle&lt;/code&gt;
also sets what &lt;code&gt;warm()&lt;/code&gt; makes, and is not kept topped up as resources are destroyed. Why: a pool
then starts no thread and holds no timer, and a program that wants eviction on a quiet pool calls
&lt;code&gt;evictIdle&lt;/code&gt; from a &lt;code&gt;Ticker&lt;/code&gt;. Alternatives weighed: a reaper thread per pool (a thread that
outlives every call and must be stopped by &lt;code&gt;close&lt;/code&gt;); refilling to &lt;code&gt;minIdle&lt;/code&gt; after each eviction
(a &lt;code&gt;create&lt;/code&gt; failing in the background has nobody to report to).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-pool&lt;/code&gt;): &lt;strong&gt;a pool’s failure is
&lt;code&gt;PoolError[E]&lt;/code&gt;: &lt;code&gt;AcquireTimedOut&lt;/code&gt;, &lt;code&gt;PoolClosed&lt;/code&gt;, &lt;code&gt;CreateFailed(error: E)&lt;/code&gt;.&lt;/strong&gt; It is an &lt;code&gt;Error&lt;/code&gt;
where &lt;code&gt;E&lt;/code&gt; is, &lt;code&gt;CreateFailed&lt;/code&gt; having &lt;code&gt;error&lt;/code&gt; as its &lt;code&gt;cause&lt;/code&gt;, and shows the same sentence wherever
&lt;code&gt;E&lt;/code&gt; has a &lt;code&gt;Display&lt;/code&gt;. The case names carry &lt;code&gt;Acquire&lt;/code&gt;/&lt;code&gt;Pool&lt;/code&gt; so that they do not clash with
&lt;code&gt;avin.io&lt;/code&gt;‘s &lt;code&gt;TimedOut&lt;/code&gt; in a program importing both. Timeouts are &lt;code&gt;Option[Duration]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; for
waiting for ever. Alternatives weighed: a &lt;code&gt;string&lt;/code&gt; error (loses the database’s own error);
&lt;code&gt;Option[T]&lt;/code&gt; from &lt;code&gt;use&lt;/code&gt; (a caller could not tell a timeout from a closed pool).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;pool-production&lt;/code&gt;, for the PostgreSQL
driver’s pool): &lt;strong&gt;a &lt;code&gt;Pool&lt;/code&gt; takes &lt;code&gt;maxWaiting: Option[int]&lt;/code&gt;, and a call that would wait while that
many already wait fails at once with a new case, &lt;code&gt;QueueFull&lt;/code&gt;.&lt;/strong&gt; A server on lightweight threads
under overload otherwise queues every request behind the pool until each one’s timeout, holding a
thread and a socket for each; failing at once lets it answer 503. The bound is checked under the
pool’s lock where the call would join the queue, so it is exact under any number of threads; a
call that finds a resource idle or a place to make one is never refused, and a call already
queued that has to look again (its resource failed &lt;code&gt;validate&lt;/code&gt;) is not refused either. It lives in
&lt;code&gt;Pool&lt;/code&gt; rather than in a wrapper because only the lock knows the queue’s length: a count kept
outside overshoots by every caller racing past the check. Alternatives weighed: a separate
admission &lt;code&gt;Semaphore&lt;/code&gt; in front of the pool (bounds callers inside, not callers waiting, so it
refuses while resources are idle); reusing &lt;code&gt;AcquireTimedOut&lt;/code&gt; (a server cannot tell overload from
a slow database). &lt;strong&gt;Review with the user&lt;/strong&gt;: &lt;code&gt;QueueFull&lt;/code&gt; is a new case of a public &lt;code&gt;data&lt;/code&gt;, so an
exhaustive &lt;code&gt;match&lt;/code&gt; on &lt;code&gt;PoolError&lt;/code&gt; elsewhere needs an arm.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;pool-production&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;maxLifetime&lt;/code&gt; and
&lt;code&gt;jitter&lt;/code&gt; retire old resources, and &lt;code&gt;jitter&lt;/code&gt; lengthens limits, never shortens them.&lt;/strong&gt; A resource
older than &lt;code&gt;maxLifetime&lt;/code&gt; is destroyed rather than lent (looked at in the lending, before
&lt;code&gt;validate&lt;/code&gt;) or kept (looked at as it comes back), and &lt;code&gt;evictIdle&lt;/code&gt; destroys idle ones however
few that leaves, &lt;code&gt;minIdle&lt;/code&gt; being &lt;code&gt;warm&lt;/code&gt;‘s to make up, since an aged connection is replaced, not
kept. Each resource draws its part of &lt;code&gt;jitter&lt;/code&gt;, from 0 up to &lt;code&gt;jitter&lt;/code&gt;, once when it is made, and
both its lifetime and its idle limit are lengthened by it; the draw comes from a SplitMix64
generator of the pool’s own under its lock, since &lt;code&gt;avin.random&lt;/code&gt; builds on &lt;code&gt;avin.threads&lt;/code&gt;. Adding
rather than subtracting follows the PostgreSQL driver pgx (&lt;code&gt;MaxConnLifetimeJitter&lt;/code&gt;), keeps
every limit a true minimum, and needs no clamp when &lt;code&gt;jitter&lt;/code&gt; exceeds a limit. Alternatives
weighed: subtracting the jitter (a limit becomes a ceiling, which suits a server-side cutoff,
but a jitter longer than the limit would need clamping); a jitter as a fraction of each limit;
jitter on the lifetime only. &lt;strong&gt;Review with the user&lt;/strong&gt;: subtracting is the other common choice.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;pool-production&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;counters()&lt;/code&gt; answers a
&lt;code&gt;PoolCounters&lt;/code&gt; of running totals beside &lt;code&gt;stats()&lt;/code&gt;, rather than widening &lt;code&gt;PoolStats&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;acquires&lt;/code&gt;,
&lt;code&gt;waited&lt;/code&gt;, &lt;code&gt;waitTime&lt;/code&gt;, &lt;code&gt;timeouts&lt;/code&gt;, &lt;code&gt;rejected&lt;/code&gt;, &lt;code&gt;created&lt;/code&gt; and &lt;code&gt;destroyed&lt;/code&gt; are what a server exports as
metrics (pgx’s &lt;code&gt;Stat&lt;/code&gt;, a pool’s usual gauges); &lt;code&gt;PoolStats&lt;/code&gt; stays the deterministic snapshot of what
is held now, which tests and programs print, while &lt;code&gt;waitTime&lt;/code&gt; varies run to run. &lt;code&gt;waitTime&lt;/code&gt; runs
from the call to the lending, so it includes making or checking a resource, as pgx’s
&lt;code&gt;AcquireDuration&lt;/code&gt; does. Alternatives weighed: one wider &lt;code&gt;PoolStats&lt;/code&gt; (its printed form would stop
being stable); counting in each user’s wrapper (&lt;code&gt;waited&lt;/code&gt; and &lt;code&gt;timeouts&lt;/code&gt; are only known under the
lock).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;select-readable&lt;/code&gt;): &lt;strong&gt;a thread waits
for a connection’s bytes OR a channel’s value with a &lt;code&gt;select&lt;/code&gt; arm, &lt;code&gt;stream.readable() -&amp;gt; body&lt;/code&gt;,
not with a second waiting mechanism.&lt;/strong&gt; A connection belongs to one thread (its reference counts
are not atomic, and OpenSSL is single-threaded per connection), so the thread that owns a
WebSocket must do all of its reads and writes, and so must wait for “bytes arrived or another
thread queued a frame”. The arm fits the others’ shape, an operation on its operand
(&lt;code&gt;ch.receive()&lt;/code&gt;, &lt;code&gt;ch.send(x)&lt;/code&gt;), so it composes with channel arms, &lt;code&gt;after&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt;, and the
select’s one-park, wake-once token covers it: where the stream is not readable when tried, its
descriptor is registered with the runtime’s poller for one report under the select’s own waiter,
and every ending withdraws it under the poller’s lock, as channel links are withdrawn. The arm
binds nothing and reads nothing (its body reads), since a read’s size and form (&lt;code&gt;read(max)&lt;/code&gt;,
&lt;code&gt;readLine&lt;/code&gt;) are the body’s choice. Ready means a read would answer without waiting: buffered
read-ahead, TLS plaintext already decrypted or a whole record arrived (TLS’s &lt;code&gt;readable()&lt;/code&gt; hands
the engine the ciphertext already on the socket, so part of a record does not count, and keeps
any failure it meets for the next read), the end, a reset or a closed connection. Its operand is
the trait &lt;code&gt;avin.threads.Readiness&lt;/code&gt; (&lt;code&gt;readable() -&amp;gt; bool&lt;/code&gt;, &lt;code&gt;readinessDescriptor() -&amp;gt; int&lt;/code&gt;), which
&lt;code&gt;ByteStream&lt;/code&gt; extends, so &lt;code&gt;avin.threads&lt;/code&gt; needs nothing of &lt;code&gt;avin.net&lt;/code&gt;, and a source of one’s own,
with &lt;code&gt;-1&lt;/code&gt; for no descriptor, can be named too. The thread dump counts the arms as sockets (“in a
select on 1 channel and 1 socket”). Alternatives weighed: an interruptible socket wait rung by a
waker (smaller, but a second way to wait beside select, composing with neither &lt;code&gt;after&lt;/code&gt; nor several
channels); an arm that reads and binds the bytes, &lt;code&gt;conn.read(n) as bytes&lt;/code&gt; (fixes the read’s form
in the arm, and a &lt;code&gt;readLine&lt;/code&gt; could not use it); waking on socket readiness alone for TLS (a partial
record would wake a select whose read then blocks). Review with the user: the spelling
&lt;code&gt;readable()&lt;/code&gt; and the name &lt;code&gt;Readiness&lt;/code&gt;; whether the descriptor should stay a public method.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;ws-sender&lt;/code&gt;): &lt;strong&gt;a WebSocket’s other
threads send through &lt;code&gt;ws.sender()&lt;/code&gt;, a sendable &lt;code&gt;WebSocketSender&lt;/code&gt; that queues whole messages in a
bounded outbox the owning thread writes while it receives.&lt;/strong&gt; The owner’s &lt;code&gt;receive&lt;/code&gt; waits in one
&lt;code&gt;select&lt;/code&gt; on the stream’s &lt;code&gt;readable()&lt;/code&gt;, the outbox, a sender’s close request, the server’s
&lt;code&gt;stopped()&lt;/code&gt; channel and the limit, so every frame (senders’, its own, pongs, the close handshake)
is written by the thread the connection belongs to, a message at a time, never interleaved.
Alternatives weighed: a mutex around the socket shared by every writer (impossible: a TLS stream
and a socket’s handles belong to one thread); a writer thread per WebSocket (a second owner of the
connection, the same impossibility); an unbounded outbox (a slow client would hold every message
ever sent to it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;ws-sender&lt;/code&gt;): &lt;strong&gt;the outbox is bounded
in messages, &lt;code&gt;outboxSize = 64&lt;/code&gt; on &lt;code&gt;webSocket&lt;/code&gt; and &lt;code&gt;WebSocket.connect&lt;/code&gt;, not in bytes; a send to a
full one waits up to the WebSocket’s write timeout and answers &lt;code&gt;Err(Broken(IoError(TimedOut, _, _)))&lt;/code&gt;, the WebSocket left open.&lt;/strong&gt; A message bound is one bounded channel, and the owner’s write to
a client that does not read fails at the same write timeout, closing it, so a slow client holds at
most 64 messages and its senders at most one write timeout each. Zero is a hand-over: each send
waits for the owner to take it. Alternatives weighed: a byte bound (needs a second counter beside
the channel, and one huge message would still have to be admitted); failing at once when full
(a burst would lose messages a healthy client reads a moment later); closing the WebSocket when a
send times out (the owner’s write timeout already does, for a client that really stopped).
Review with the user: whether a byte bound is wanted beside the message bound, and the default 64.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;ws-sender&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Ok&lt;/code&gt; from a sender
means queued while open; the close is a request, and the senders are refused from the start of
any close.&lt;/strong&gt; A sender’s &lt;code&gt;close(code, reason)&lt;/code&gt; sets the shared state at once (every sender call
after answers &lt;code&gt;Err(Closed(code, reason))&lt;/code&gt;) and the owner carries it out while it receives, after
writing what was queued before it. The owner’s close refuses senders from the start of its
handshake, and its end (close, peer close, failure, server stopping, cancellation) drops what is
queued and wakes every sender waiting for room. A message queued in the instant the WebSocket
ends may answer &lt;code&gt;Ok&lt;/code&gt; and be dropped, as a write accepted by a socket that then breaks is.
Alternatives weighed: an &lt;code&gt;Ok&lt;/code&gt; only once written (every send would wait for the owner’s next
receive); closing from the sender’s thread (it does not own the connection).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;ws-sender&lt;/code&gt;): &lt;strong&gt;a session that only
answers what arrives loops in &lt;code&gt;ws.serve(onMessage) -&amp;gt; WebSocketError&lt;/code&gt;&lt;/strong&gt;, which receives until the
WebSocket closes and answers why, beside &lt;code&gt;receive()&lt;/code&gt;, which a session may loop on itself; it is
while the owner receives that its senders’ messages are written, so a session must be in one or
the other. Alternatives weighed: a background writer started by &lt;code&gt;sender()&lt;/code&gt; (a second owner); no
helper, documenting the &lt;code&gt;receive()&lt;/code&gt; loop (the chat server’s loop is written once in every app).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;ws-sender&lt;/code&gt;): &lt;strong&gt;data messages over
65536 bytes are sent in fragments of 65536, written back to back&lt;/strong&gt;, by the owner’s &lt;code&gt;send&lt;/code&gt; and by
senders alike, so a peer limiting frame sizes still takes large messages; a pong waits for the end
of the message being written. A thread cancelled while it receives closes the connection with no
close frame (a frame may have been half written) and ends the WebSocket with &lt;code&gt;1006&lt;/code&gt;.
&lt;code&gt;TcpServer.stopped()&lt;/code&gt; is a channel closed by &lt;code&gt;stop&lt;/code&gt;, which the owner’s select watches in place of
running each wait on a thread of its own through &lt;code&gt;idle&lt;/code&gt;. Review with the user: the fragment size,
and whether &lt;code&gt;stopped()&lt;/code&gt; should be a receive-only view rather than a &lt;code&gt;Channel[unit]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;stdio-blocking&lt;/code&gt;): &lt;strong&gt;standard input
and output wait safe for the collector.&lt;/strong&gt; Every read of standard input and every write to standard
output or standard error, a flush and a trap’s report included, marks its thread safe for the
collector while it waits, the string being written kept in a frame of the runtime’s own. A
lightweight thread reading standard input from a stream with no position (a pipe, a socket, a
terminal where the platform answers so) parks on the poller first; one reading a file or a device
reads at once, since the poller does not report a file at its end as ready. Writes do not park: the
output goes through the C library’s buffer, shared with any C code the program calls, so a thread
held up writing keeps its worker, counted as blocked, and the monitor runs another in its place.
&lt;strong&gt;The wait for standard input is not a cancellation point&lt;/strong&gt;, as it was not before: a cancelled
thread goes on waiting for its line. &lt;em&gt;Why&lt;/em&gt;: the smallest fix that keeps the behaviour the program
sees; making it one would add a failure path to &lt;code&gt;readLine&lt;/code&gt;, which answers no error. &lt;em&gt;Alternatives&lt;/em&gt;:
parking writes too (needs non-blocking standard output, which a pipe shared with the parent
process cannot be given safely); a cancellable input wait that unwinds the thread as a sleep does.
Review with the user: whether waiting for standard input should be a cancellation point.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;net-split-writable&lt;/code&gt;): &lt;strong&gt;a
connection splits into a reader and a writer for two threads at once.&lt;/strong&gt; &lt;code&gt;ByteStream.split() -&amp;gt; (StreamReader, StreamWriter)&lt;/code&gt;, for &lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt; and &lt;code&gt;TlsStream&lt;/code&gt;; both halves are
sendable traits, each half its own thread’s, so a driver pipelines a batch of any size without
stopping at windows for the send/receive buffer deadlock (found by the pg driver’s batch item).
Closing the writer half-closes (shutdown write; TLS sends its close notice first); closing the
reader only stops reading; the connection closes once both halves are closed or unreachable.
The split connection is used up (every operation answers an error naming the split; closing it
does nothing); splitting it again, or splitting a closed connection, traps. &lt;strong&gt;No &lt;code&gt;reunite&lt;/code&gt;&lt;/strong&gt;: a
protocol that wants one owner again keeps both halves on one thread, and a reunite would have to
check that the two halves are of one connection and that neither has pending state. A TCP or Unix
writer’s &lt;code&gt;close&lt;/code&gt; answers &lt;code&gt;Ok&lt;/code&gt; where the peer has gone, as a connection’s does; a TLS writer’s answers
whether the close notice went out, as &lt;code&gt;TlsStream.close&lt;/code&gt; does. Each half holds its own handle on the
socket (&lt;code&gt;avin.rt.socket_share&lt;/code&gt;), so each is owner-checked on its own. The runtime’s poller keeps,
per descriptor, the waiter of each direction and registers the union of the two
(&lt;code&gt;runtime/avin/rt/sockets.sysl&lt;/code&gt;), so a reader parked for bytes and a writer parked for room wait
on one descriptor at once; before this a second registration replaced the first under epoll. A TLS
stream’s halves share one session in a &lt;code&gt;@keeps_owners&lt;/code&gt; object: the engine and the TCP writer are
reached only holding a lock of their own, each handle taken from transit by the code holding the
lock and handed back before it goes (a cancellation included, by &lt;code&gt;defer&lt;/code&gt;), and nothing is held
while waiting for the connection, so the reader decrypts while the writer waits for room. A reader
that has ciphertext of its own to send sends it only where nobody else is sending (&lt;code&gt;tryAcquire&lt;/code&gt;),
and otherwise leaves it owed to the writer. Alternatives weighed: concurrent reads and writes on
one connection value, with no halves (no owner check could then tell a misuse from a use);
&lt;code&gt;dup&lt;/code&gt;ing the descriptor for the writer (Sysl’s &lt;code&gt;Socket&lt;/code&gt; cannot adopt one, and the poller would
still need two registrations under kqueue’s filters); a TLS writer that waits for the reader on
every record (a renegotiation alone needs that, and the writer does wait for it then).
&lt;strong&gt;Review with the user:&lt;/strong&gt; whether a reunite is wanted, and that a writer told by TLS to wait for
the peer (a renegotiation) waits for its reader to read.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;net-split-writable&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;writable()&lt;/code&gt;
is a select arm beside &lt;code&gt;readable()&lt;/code&gt;, with a partial write &lt;code&gt;writeSome(bytes) -&amp;gt; Result[int, IoError]&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;threads.Writability&lt;/code&gt; (&lt;code&gt;writable()&lt;/code&gt;, &lt;code&gt;writabilityDescriptor()&lt;/code&gt;) beside &lt;code&gt;Readiness&lt;/code&gt;;
every &lt;code&gt;ByteStream&lt;/code&gt; and every &lt;code&gt;StreamWriter&lt;/code&gt; is one, and &lt;code&gt;select&lt;/code&gt; reads &lt;code&gt;sink.writable()&lt;/code&gt; into a
&lt;code&gt;SelectWritable&lt;/code&gt; arm, watched on the poller for room. &lt;code&gt;writeSome&lt;/code&gt; is added because the arm needs
it to be useful: &lt;code&gt;write&lt;/code&gt; sends everything and so waits again after the arm said there was room.
It waits for room for the first byte only where there is none, sends what fits, and answers at
least one unless given nothing. Over TLS it hands TLS at most one record (16384 bytes of
plaintext) and sends what of the record fits; the rest is kept and goes before anything else, and
&lt;code&gt;writable()&lt;/code&gt; sends it as room comes and answers &lt;code&gt;true&lt;/code&gt; only once it has gone, so &lt;code&gt;writeSome&lt;/code&gt; after
&lt;code&gt;writable()&lt;/code&gt; never waits; a read meanwhile leaves its own ciphertext queued behind that record
rather than waiting for room. Alternatives weighed: no &lt;code&gt;writeSome&lt;/code&gt;, the arm for &lt;code&gt;write&lt;/code&gt; (waits
again on a large write, as above); a TLS &lt;code&gt;writeSome&lt;/code&gt; that sends its whole record (waits for room
for a record after the arm said there was some); a &lt;code&gt;writable()&lt;/code&gt; that ignores the kept record (a
select that finds the socket writable and the arm not, round after round, spinning).
&lt;strong&gt;Review with the user:&lt;/strong&gt; the TLS record bound of &lt;code&gt;writeSome&lt;/code&gt;, and the names &lt;code&gt;writeSome&lt;/code&gt; and
&lt;code&gt;writabilityDescriptor&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;read-secret&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;io.readSecret(prompt)&lt;/code&gt;,
&lt;code&gt;readSecretBytes&lt;/code&gt; and &lt;code&gt;readSecretOrLine&lt;/code&gt; read a line from the controlling terminal with echo
off.&lt;/strong&gt; fettle prompts for a sudo or ssh password, as does any tool asking for a passphrase, and
nothing in the library read input with echo off. The calls open &lt;code&gt;/dev/tty&lt;/code&gt; (so a piped standard
input does not matter), write the prompt to it, turn off &lt;code&gt;ECHO&lt;/code&gt; and &lt;code&gt;ECHONL&lt;/code&gt; while keeping
&lt;code&gt;ICANON&lt;/code&gt;, and restore the exact &lt;code&gt;termios&lt;/code&gt; found. Details settled: (1) &lt;strong&gt;no terminal&lt;/strong&gt; is
&lt;code&gt;Err(IoError(NoTerminal, &amp;quot;read&amp;quot;, &amp;quot;the terminal&amp;quot;))&lt;/code&gt;, a new &lt;code&gt;ErrorKind&lt;/code&gt; case, since a program
tells it apart from a failed read; &lt;code&gt;readSecretOrLine&lt;/code&gt; is the opt-in fallback, writing the prompt
to standard error and reading a line from standard input, as a tool run by a script with its
password piped in needs. (2) &lt;strong&gt;Signals&lt;/strong&gt;: &lt;code&gt;ISIG&lt;/code&gt; stays on, and for the length of the read the C
side (&lt;code&gt;runtime/avin/rt/__posix__/secret_tty.c&lt;/code&gt;) catches interrupt, hangup, terminate and quit: its
handler restores the terminal, gives the signal its previous action back and sends it again, so
the program dies or handles the signal with echo on; a program that survives sees the read fail
as &lt;code&gt;Other(&amp;quot;interrupted&amp;quot;)&lt;/code&gt;. A terminal stop (Ctrl-Z) is caught too: the handler restores the
terminal, stops the program with the default action, and on continue hides the terminal again
and the read writes its prompt again and goes on (as &lt;code&gt;sudo&lt;/code&gt; and &lt;code&gt;getpass&lt;/code&gt; do); what was typed before
the Ctrl-Z is discarded by the terminal. SIGTTIN and SIGTTOU are not caught: they stop a program before the terminal has been
changed. (3) &lt;strong&gt;Concurrency&lt;/strong&gt;: the read holds
&lt;code&gt;input_readers&lt;/code&gt;, the lock of every standard input reader, so a secret and a &lt;code&gt;readLine&lt;/code&gt; never
read the terminal at once; a lightweight thread waiting for the line is not cancellable, as one
waiting for standard input is, so a cancel takes effect once the line has been read and the
terminal is back. (4) &lt;strong&gt;Bytes&lt;/strong&gt;: &lt;code&gt;readSecretBytes&lt;/code&gt; returns an &lt;code&gt;Array[byte]&lt;/code&gt; the caller can
overwrite; &lt;code&gt;readSecret&lt;/code&gt; is a string, which has no way to be cleared, and the runtime clears its
own gathering buffers. (5) A trailing &lt;code&gt;\n&lt;/code&gt; and a &lt;code&gt;\r&lt;/code&gt; before it are dropped; the end of input
with bytes typed ends the line, with none it is &lt;code&gt;Other(&amp;quot;end of input&amp;quot;)&lt;/code&gt;. Alternatives weighed:
turning &lt;code&gt;ISIG&lt;/code&gt; off as &lt;code&gt;getpass&lt;/code&gt; does (Ctrl-C then arrives as a byte only once the line ends,
so it would not interrupt a prompt); reading standard input when there is no terminal by default
(a secret would then show on the screen, and a program that means to read one must ask by
name); a cancellable wait (the existing standard input lock holds the thread’s cancellation off,
and a read cut short would leave typed bytes half taken); a single &lt;code&gt;readSecret&lt;/code&gt; with a
fallback flag. Tests drive real programs over a pseudo-terminal (&lt;code&gt;tests/pty/pty_drive.c&lt;/code&gt;,
&lt;code&gt;secret_tests.sysl&lt;/code&gt;). &lt;strong&gt;Review with the user:&lt;/strong&gt; the name &lt;code&gt;readSecret&lt;/code&gt; (against &lt;code&gt;readPassword&lt;/code&gt;
or &lt;code&gt;promptSecret&lt;/code&gt;), and the no-terminal behaviour: an error by default with &lt;code&gt;readSecretOrLine&lt;/code&gt;
as the explicit fallback, rather than falling back to standard input on its own.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;stdio-bytes&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;io.stdin()&lt;/code&gt; is standard
input as a &lt;code&gt;Reader&lt;/code&gt; of bytes, and &lt;code&gt;io.stdout()&lt;/code&gt; and &lt;code&gt;io.stderr()&lt;/code&gt; are standard output and error
as &lt;code&gt;ByteWriter&lt;/code&gt;s&lt;/strong&gt;, answering the &lt;code&gt;Sendable&lt;/code&gt; objects &lt;code&gt;StandardInputBytes&lt;/code&gt;, &lt;code&gt;StandardOutputBytes&lt;/code&gt;
and &lt;code&gt;StandardErrorBytes&lt;/code&gt;. Source: the avin-lang/lsp package could not serve LSP over stdio, whose
&lt;code&gt;Content-Length&lt;/code&gt; counts bytes, since &lt;code&gt;avin.io&lt;/code&gt; read standard input only as text decoded with
U+FFFD and had no byte writer for standard output; the workaround would have bound Sysl’s
&lt;code&gt;FdReader&lt;/code&gt; directly, as the tui package does. Details settled: (1) &lt;strong&gt;Mixing&lt;/strong&gt;: byte reads take
from the one buffer &lt;code&gt;readLine&lt;/code&gt;, &lt;code&gt;lines()&lt;/code&gt;, &lt;code&gt;readAll&lt;/code&gt; and &lt;code&gt;Source.stdin()&lt;/code&gt; share
(&lt;code&gt;runtime/avin/rt/input.sysl&lt;/code&gt;), so a header read as a line and a body read as bytes go on from
each other with no byte lost or read twice; a read answers what the buffer holds, else one read
of the input. (2) &lt;strong&gt;Serialization&lt;/strong&gt;: byte reads hold &lt;code&gt;input_readers&lt;/code&gt;, the lock of every standard
input reader and of &lt;code&gt;readSecret&lt;/code&gt;. (3) &lt;strong&gt;Parking&lt;/strong&gt;: a lightweight thread waits on the poller, as a
line read does. (4) &lt;strong&gt;End and failure&lt;/strong&gt;: the end is an empty array, every time it is asked; a
read that fails is &lt;code&gt;Err(Other(&amp;lt;platform sentence&amp;gt;))&lt;/code&gt; for bytes, while the text readers keep seeing
the end. (5) &lt;strong&gt;Output&lt;/strong&gt;: a byte write is unbuffered and goes out whole before it returns, behind
what &lt;code&gt;print&lt;/code&gt; buffered: it holds standard output’s stdio lock while flushing that buffer and
writing to the descriptor, and &lt;code&gt;println&lt;/code&gt; writes its whole line through the same stream, so a
printed line is never split by a byte write (the println-atomic entry of 2026-11-15 still holds);
a write to standard error flushes standard output first, as &lt;code&gt;eprint&lt;/code&gt; does. (6) &lt;strong&gt;A reader that
has gone&lt;/strong&gt;: SIGPIPE is held off for the length of a byte write (on macOS by the descriptor’s own
mark, the 2026-11-20 entry below; elsewhere blocked on the writing thread, the one the write
raised taken back), so the write answers &lt;code&gt;ConnectionReset&lt;/code&gt; (&lt;code&gt;EPIPE&lt;/code&gt;, the kind a
connection’s write answers) and the program goes on; &lt;code&gt;print&lt;/code&gt; keeps its quiet death, which a
filter in a pipeline wants. (7) &lt;strong&gt;Closed descriptors&lt;/strong&gt;: a bug met on the way, a program started
with standard input closed read the runtime’s own pipe, which had taken descriptor 0; the runtime
now opens &lt;code&gt;/dev/null&lt;/code&gt; on each of 0, 1 and 2 that is missing before it opens anything. Alternatives
weighed: an error for mixing text and byte reads (two buffers or a mode switch, and a header and
body protocol could not be written at all); a buffered &lt;code&gt;stdout()&lt;/code&gt; with &lt;code&gt;flush&lt;/code&gt; (a byte write
could then be overtaken by, or split, a &lt;code&gt;println&lt;/code&gt;, and an LSP message must leave whole); ignoring
SIGPIPE for the whole program (every &lt;code&gt;print&lt;/code&gt; to a closed pipe would then have to fail somewhere,
where today it ends the program quietly); public objects alone with no functions (a module-level
function reads as &lt;code&gt;io.readLine()&lt;/code&gt; does). Tests: &lt;code&gt;stdio_tests.sysl&lt;/code&gt;, driving
&lt;code&gt;tests/stdio/stdio_bytes.avin&lt;/code&gt; through &lt;code&gt;sh&lt;/code&gt; and &lt;code&gt;tests/pty/stdio_tty.avin&lt;/code&gt; over a
pseudo-terminal, at -O0 and -O2. &lt;strong&gt;Review with the user:&lt;/strong&gt; the names &lt;code&gt;stdin()&lt;/code&gt;, &lt;code&gt;stdout()&lt;/code&gt;,
&lt;code&gt;stderr()&lt;/code&gt; and the object names &lt;code&gt;StandardInputBytes&lt;/code&gt;, &lt;code&gt;StandardOutputBytes&lt;/code&gt;,
&lt;code&gt;StandardErrorBytes&lt;/code&gt; (beside the text writers &lt;code&gt;StandardOutput&lt;/code&gt; and &lt;code&gt;StandardError&lt;/code&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-20 (branch &lt;code&gt;stdio-sigpipe&lt;/code&gt;): &lt;strong&gt;on macOS a byte write
to standard output or error marks the descriptor never to raise SIGPIPE (&lt;code&gt;F_SETNOSIGPIPE&lt;/code&gt;) for
the length of the write only&lt;/strong&gt;, and puts back the mark it found. WHY: macOS raises the SIGPIPE
of a write to a gone reader on the whole process, where any thread not blocking it takes it, so
blocking it on the writing thread (item (6) above) failed whenever the program had another
thread: four threads writing to &lt;code&gt;prog | head -c 10&lt;/code&gt;, or one writer beside busy threads, ended
with status 141 every time at -O0 and -O2 before the change. The mark belongs to the open pipe
or socket, which the shell and the program’s children share, so it is held under the stdio
locks of both standard streams and taken off before the write returns: &lt;code&gt;print&lt;/code&gt;, &lt;code&gt;eprint&lt;/code&gt; and a
child writing to the same output keep their SIGPIPE, and nothing is left changed on the shell’s
pipe after the program ends. On Linux the signal goes to the writing thread, so the thread mask
is kept there unchanged. ALTERNATIVES: marking descriptors 1 and 2 once at startup (every
&lt;code&gt;print&lt;/code&gt; to a gone reader would then fail silently and a printing loop would never end, every
child and every later process on the shell’s pipe would inherit the mark); ignoring SIGPIPE for
the whole program (the same &lt;code&gt;print&lt;/code&gt; problem, and an ignored signal survives &lt;code&gt;exec&lt;/code&gt; into every
child). Tests: &lt;code&gt;stdio_tests.sysl&lt;/code&gt; § several writing threads, a writer beside busy threads,
threads writing to standard error, &lt;code&gt;print&lt;/code&gt; without a newline after a failed byte write, and a
child (&lt;code&gt;yes&lt;/code&gt;) started after one, at -O0 and -O2.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Linux as a target, and machines in packages&lt;/strong&gt; (branch &lt;code&gt;linux-plan&lt;/code&gt;, 2026-11-19; the user,
2026-11-19: Avin is “for anyone who would enjoy using it”). The plan is
&lt;a href=&quot;/compiler/linux/&quot;&gt;Linux&lt;/a&gt;; the package surface is &lt;a href=&quot;/spec/packages/#machines&quot;&gt;machines&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;Avin’s targets are &lt;code&gt;aarch64-macos&lt;/code&gt;,
&lt;code&gt;x86_64-linux&lt;/code&gt; and &lt;code&gt;aarch64-linux&lt;/code&gt;&lt;/strong&gt;, glibc on Linux, named as Sysl’s target registry names
them. WHY: they are Sysl’s release platforms, so the toolchain Avin drives at every build
exists on each; servers and CI are overwhelmingly x86_64 Linux, and aarch64 Linux is what a
Mac’s containers run natively. ALTERNATIVES: x86_64 Linux alone (leaves out Arm servers and
makes every local Linux test an emulated one); musl (static executables, but Sysl’s registry
and its library are glibc’s); Intel macOS and Windows (Sysl ships neither).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;Avin is built natively on each target, not
cross-compiled from the Mac.&lt;/strong&gt; WHY: an installed Avin runs &lt;code&gt;sysl build-c&lt;/code&gt; and clang at every
user’s build, so Linux needs Sysl and clang on Linux whatever the release does, and a native
build is the configuration users run; cross-building would add a sysroot to manage for no
user. Local Linux work runs in a colima VM (aarch64, native speed on Apple silicon) through
marshal; CI runs GitHub’s x86_64 and arm64 Ubuntu runners. ALTERNATIVES: cross-compiling from
the Mac with a glibc sysroot (Sysl cannot yet: the probe of &lt;code&gt;sysl build --target x86_64-linux&lt;/code&gt;
fails building its standard module, &lt;code&gt;stdio.h&lt;/code&gt; not found, and Sysl has no way to name a sysroot);
both (cross kept for &lt;code&gt;avin build --target&lt;/code&gt;, a later item once Sysl has sysroots).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a Linux release ships a tarball per target&lt;/strong&gt;
(&lt;code&gt;avin-&amp;lt;v&amp;gt;-linux-x86_64.tar.gz&lt;/code&gt;, &lt;code&gt;avin-&amp;lt;v&amp;gt;-linux-arm64.tar.gz&lt;/code&gt;, the same prefix layout as the
macOS one) &lt;strong&gt;and an install script&lt;/strong&gt; that installs Avin and the Sysl it needs into a prefix
and names the distribution’s packages for clang, lld, llvm-ar and pkg-config; the Homebrew
formula gains &lt;code&gt;on_linux&lt;/code&gt; once Sysl’s formula has it. No &lt;code&gt;.deb&lt;/code&gt;. WHY: a tarball is what every
other route is built from, and an install script reaches every distribution with no
repository to host or sign. ALTERNATIVES: Linuxbrew only (needs Sysl’s formula on Linux first,
and many servers have no brew); a &lt;code&gt;.deb&lt;/code&gt; and an apt repository (hosting and signing, one
distribution family); a static single binary (Avin needs Sysl and clang beside it anyway).
&lt;strong&gt;Review with the user:&lt;/strong&gt; whether a &lt;code&gt;.deb&lt;/code&gt; is wanted later.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;machine conditions in the manifest are Sysl’s
condition language&lt;/strong&gt; (symbols, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, parentheses), over the closed set &lt;code&gt;macos&lt;/code&gt;,
&lt;code&gt;linux&lt;/code&gt;, &lt;code&gt;posix&lt;/code&gt;, &lt;code&gt;aarch64&lt;/code&gt;, &lt;code&gt;x86_64&lt;/code&gt;, as &lt;code&gt;if&lt;/code&gt; on an entry of &lt;code&gt;dependencies&lt;/code&gt;,
&lt;code&gt;sysl-dependencies&lt;/code&gt; and &lt;code&gt;c-libraries&lt;/code&gt; and on a feature (where it says only where the feature
exists), checked symbol by symbol when the manifest is read; &lt;code&gt;package.targets&lt;/code&gt; lists the
targets a package supports (all by default); &lt;code&gt;install&lt;/code&gt; may be a block of sentences by
condition; &lt;code&gt;link-flags&lt;/code&gt; passes flags such as &lt;code&gt;-framework Security&lt;/code&gt; as written. &lt;code&gt;avin tidy&lt;/code&gt; and
&lt;code&gt;avin vendor&lt;/code&gt; answer for every target. WHY: one condition language across Avin’s manifest,
Sysl’s manifests and the Sysl dependencies Avin hands to Sysl; checking every symbol at read
keeps a misspelling from silently dropping a dependency. ALTERNATIVES: per-target blocks
(&lt;code&gt;targets.x86_64-linux { dependencies { … } }&lt;/code&gt;, which repeat a dependency per target and
cannot say “every Linux”); a target name as the condition (&lt;code&gt;if = &amp;quot;x86_64-linux&amp;quot;&lt;/code&gt;, which cannot
say “every Linux” either); Sysl’s &lt;code&gt;choices&lt;/code&gt; and per-target linker keys (machine and image
configuration Avin’s hosted programs do not have).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;in source, the file is the unit a machine
selects&lt;/strong&gt;: &lt;code&gt;name.&amp;lt;symbol&amp;gt;.avin&lt;/code&gt; is read only where the symbol holds, a module exists on a
machine where any of its files is read, an import of a module that is not everywhere is allowed
only from a file that is read no more widely, and &lt;code&gt;avin check&lt;/code&gt; type-checks once per target
where anything differs. Values that differ by machine are written over &lt;code&gt;avin.target.os&lt;/code&gt; and
&lt;code&gt;avin.target.arch&lt;/code&gt;, compile-time constants whose untaken branches fold away, both branches
checked on every machine. WHY: it keeps the rule features follow (a whole unit is in or out,
nothing in a file changes with the build), so every file means one thing; a module keeps one
name and one surface on every machine, and the per-target check proves the surface is there.
ALTERNATIVES: Sysl’s &lt;code&gt;#if&lt;/code&gt; lines (a file reads differently per machine and the untaken lines
are never checked); a constant alone (cannot hold a call only one system declares, since both
branches are checked); whole modules per machine in the manifest (a &lt;code&gt;machines { linux { modules = […] } }&lt;/code&gt; block, which forces shared code to import a different module per machine);
&lt;code&gt;name_linux.avin&lt;/code&gt; with an underscore (collides with ordinary file names that end in a system’s
name). &lt;strong&gt;Review with the user:&lt;/strong&gt; the surface syntax: the &lt;code&gt;.linux.avin&lt;/code&gt; infix,
&lt;code&gt;package.targets&lt;/code&gt;, the &lt;code&gt;if&lt;/code&gt; key, the &lt;code&gt;install&lt;/code&gt; block and &lt;code&gt;avin.target&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (closing two Open items): &lt;strong&gt;a feature has no
compile-time constant&lt;/strong&gt;, the module staying the only unit a feature gates. WHY: a feature’s
modules and optional dependencies are absent with it off, so a branch on &lt;code&gt;feature(&amp;quot;x&amp;quot;)&lt;/code&gt; could
not type-check against them; a machine constant works only because every machine’s standard
library is whole. ALTERNATIVES: a &lt;code&gt;feature(&amp;quot;x&amp;quot;)&lt;/code&gt; constant folded away (fails to check, as
above); line gates (the conditional compilation the features design refused). &lt;strong&gt;A module is
listed by one feature only&lt;/strong&gt;; a part two features share becomes a feature both &lt;code&gt;enables&lt;/code&gt;.
WHY: every gate stays one feature, so the import check stays one question. ALTERNATIVES: a
module on while any of its features is on (the import check would have to reason about
disjunctions, and a module’s presence would depend on combinations).&lt;/li&gt;
&lt;li&gt;Found while surveying, not fixed here (no runtime run is allowed on this branch): the DNS
lookup’s pipe sets descriptor flag &lt;code&gt;2&lt;/code&gt; (&lt;code&gt;runtime/avin/rt/lookup.sysl&lt;/code&gt;, &lt;code&gt;CloseOnExecFlag&lt;/code&gt;), but
&lt;code&gt;FD_CLOEXEC&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; on macOS and on Linux, so the pipe is inherited by a child started during a
lookup. macOS hides it, starting children with every other descriptor closed; Linux does not.
It is the first item of the &lt;a href=&quot;/compiler/linux/&quot;&gt;plan&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (the user approved moving extractors onto a trait the
same day; branch &lt;code&gt;extractor-trait&lt;/code&gt;): &lt;strong&gt;an extractor is a value whose type implements one of three
core traits&lt;/strong&gt;, &lt;code&gt;Extractor[-A, +B]&lt;/code&gt; (&lt;code&gt;unapply(value: A) -&amp;gt; Option[B]&lt;/code&gt;), &lt;code&gt;BoolExtractor[-A]&lt;/code&gt;
(&lt;code&gt;unapply(value: A) -&amp;gt; bool&lt;/code&gt;) and &lt;code&gt;SeqExtractor[-A, +S]&lt;/code&gt; (&lt;code&gt;unapplySeq(value: A) -&amp;gt; Option[S]&lt;/code&gt;),
in &lt;code&gt;library/avin/extractor.avin&lt;/code&gt;; the pattern checker finds the conformance (&lt;code&gt;extractor_instances&lt;/code&gt;
in &lt;code&gt;check.sysl&lt;/code&gt;) and calls the trait’s method, a class’s or data type’s own implementation
directly, so a method merely named &lt;code&gt;unapply&lt;/code&gt; no longer makes an extractor. The pattern syntax, the
three result shapes, coverage (an extractor never counts) and refinement (an extractor learns no
equalities) are unchanged, and the methods keep the names &lt;code&gt;unapply&lt;/code&gt; and &lt;code&gt;unapplySeq&lt;/code&gt;. A type
implements each trait at one type argument (the rule for every trait with instance members); the
trait whose &lt;code&gt;A&lt;/code&gt; takes the matched value serves, an &lt;code&gt;unapply&lt;/code&gt; trait before &lt;code&gt;SeqExtractor&lt;/code&gt;. A
type’s name is no extractor. A value implementing none is reported with the trait to implement,
worked out from the type’s own &lt;code&gt;unapply&lt;/code&gt; or &lt;code&gt;unapplySeq&lt;/code&gt; where it has one, or with the three
traits and their methods. WHY: the user’s rule that Avin is sound and nominal, which the soundness
audit found broken here by a lookup by name; as ordinary traits, extractors also become
first-class: held in a value of the trait’s type, passed as a parameter, bounded on a type
parameter, implemented by a data type through an impl, inherited by a subclass, with the
variance a function’s argument and result have. The &lt;code&gt;S&lt;/code&gt; of &lt;code&gt;SeqExtractor&lt;/code&gt; is left open rather
than bounded by &lt;code&gt;Seq&lt;/code&gt;, so a &lt;code&gt;List&lt;/code&gt; stays a &lt;code&gt;List&lt;/code&gt; for its &lt;code&gt;rest*&lt;/code&gt; and list patterns; the pattern
asks for a sequence where it is used. ALTERNATIVES: a marker trait with no members, the method
still found by name inside it (half nominal; a value of the trait’s type could not be matched);
one trait with the result shape as a type parameter (the three shapes are different methods);
&lt;code&gt;unapply&lt;/code&gt; keeping its role by name with a modifier (not a trait, so no extractor values).
&lt;strong&gt;Review with the user:&lt;/strong&gt; two things the structural rule allowed are gone: an extractor object
with a generic method, &lt;code&gt;object Pair&lt;/code&gt; with &lt;code&gt;unapply[A](xs: List[A])&lt;/code&gt;, which no trait instance can
name, is now a generic class used through a value (&lt;code&gt;val pair = Pair[A]()&lt;/code&gt;, &lt;code&gt;pair(a, b)&lt;/code&gt;); and
one object with &lt;code&gt;unapply&lt;/code&gt;s overloaded on several input types now picks one input type per trait.
Each implementation is also written &lt;code&gt;override&lt;/code&gt;, as every trait member’s is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (built on branch &lt;code&gt;builder-trait&lt;/code&gt;; the move onto a trait
approved by the user 2026-11-19): &lt;strong&gt;a collection literal finds its builder through the core trait
&lt;code&gt;Buildable[A]&lt;/code&gt;, never by a method’s name&lt;/strong&gt; (&lt;a href=&quot;/spec/collections/#literals&quot;&gt;literals&lt;/a&gt;). The trait has
one member, &lt;code&gt;static newBuilder() -&amp;gt; Builder[A, Self]&lt;/code&gt;; &lt;code&gt;A&lt;/code&gt; is the element a literal gives the
builder, a map’s &lt;code&gt;(K, V)&lt;/code&gt; pair. A literal where a type &lt;code&gt;C&lt;/code&gt; is expected is built by &lt;code&gt;C.newBuilder()&lt;/code&gt;
where an impl of &lt;code&gt;Buildable&lt;/code&gt; targets &lt;code&gt;C&lt;/code&gt; itself, or where &lt;code&gt;C&lt;/code&gt; is a type parameter bounded by it
(&lt;code&gt;make[C: Buildable[int]]() -&amp;gt; C = [1, 2, 3]&lt;/code&gt;); otherwise it is the default &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; or
&lt;code&gt;Map&lt;/code&gt;, built through their own conformances. A companion object’s &lt;code&gt;newBuilder&lt;/code&gt; builds no literal.
Every library collection implements it, its impl calling the companion’s &lt;code&gt;newBuilder&lt;/code&gt;, which stays
the public way to get a builder (&lt;code&gt;Vector.newBuilder[int]()&lt;/code&gt;); a repeated parameter’s vector is
built through &lt;code&gt;Vector&lt;/code&gt;‘s conformance too. An expected collection (an &lt;code&gt;Iterable&lt;/code&gt;, or a type whose
companion has a &lt;code&gt;newBuilder&lt;/code&gt;) that is neither &lt;code&gt;Buildable&lt;/code&gt; nor an instance of the default is
reported by the trait it lacks: “a sequence literal cannot build &lt;code&gt;Stack[int]&lt;/code&gt;, which does not
implement &lt;code&gt;Buildable&lt;/code&gt;…”. WHY: the user’s goal is a sound, nominally typed language, and a literal
that called whatever its expected type’s companion named &lt;code&gt;newBuilder&lt;/code&gt; was the last structural
lookup the soundness audit left; a trait is a stated promise, checked where it is made. One trait
for sequences, sets and maps, parameterized by the element rather than by a type constructor,
serves every collection the library has: &lt;code&gt;BitSet&lt;/code&gt; (a &lt;code&gt;Buildable[int]&lt;/code&gt; with no parameter of its
own), &lt;code&gt;TreeSet&lt;/code&gt; (an &lt;code&gt;Ord&lt;/code&gt; bound on its impl), maps (pairs), traits (&lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;SortedMap&lt;/code&gt;, building
their default kinds), and any program’s collection, with or without a companion, from any module,
as &lt;code&gt;FromInteger&lt;/code&gt; does for integer literals. &lt;strong&gt;The conformance is the type’s own&lt;/strong&gt;: a &lt;code&gt;TreeSet&lt;/code&gt;
expected is built by &lt;code&gt;TreeSet&lt;/code&gt;‘s impl, never by &lt;code&gt;SortedSet&lt;/code&gt;‘s or &lt;code&gt;Set&lt;/code&gt;‘s, since those would make
a different collection. ALTERNATIVES: a constructor trait on the companion, &lt;code&gt;trait IterableFactory[C[_]]&lt;/code&gt; with &lt;code&gt;newBuilder[A]()&lt;/code&gt; (cannot express &lt;code&gt;BitSet&lt;/code&gt;, which takes no
parameter, nor &lt;code&gt;TreeSet&lt;/code&gt;‘s &lt;code&gt;Ord&lt;/code&gt; and &lt;code&gt;HashSet&lt;/code&gt;‘s &lt;code&gt;Eq &amp;amp; Hash&lt;/code&gt; element bounds, and needs a second
trait for maps); two traits, one for sequences and sets and one for maps (the element type already
tells a pair from an element, so the second adds nothing); removing the companions’ &lt;code&gt;newBuilder&lt;/code&gt;
and calling the static as &lt;code&gt;Vector[int].newBuilder()&lt;/code&gt; (breaks every call site in every avin-lang
repo for no gain in soundness). A trait type’s own conformance builds where the trait type is
expected (&lt;code&gt;SortedSet&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;SeqMap&lt;/code&gt;, so &lt;code&gt;{}&lt;/code&gt; where a &lt;code&gt;Map&lt;/code&gt; is expected is the empty map
through &lt;code&gt;Map&lt;/code&gt;‘s own impl), and an impl for one instance, &lt;code&gt;impl Buildable[int] for Count[int]&lt;/code&gt;,
builds that instance only; &lt;code&gt;Count[string]&lt;/code&gt; expected is the error naming the trait. &lt;strong&gt;The companion
&lt;code&gt;apply&lt;/code&gt; stays an ordinary method&lt;/strong&gt; (&lt;code&gt;Deque(1, 2, 3)&lt;/code&gt;): its repeated parameter’s &lt;code&gt;Vector&lt;/code&gt; is already
built through &lt;code&gt;Vector&lt;/code&gt;‘s conformance, so it meets the trait where a literal does, and each
collection keeps the cheapest way from that vector to itself. ALTERNATIVES for &lt;code&gt;apply&lt;/code&gt;: rewriting
every companion &lt;code&gt;apply&lt;/code&gt; over its own &lt;code&gt;newBuilder&lt;/code&gt; (no gain in soundness, and slower where &lt;code&gt;apply&lt;/code&gt;
converts the vector directly, as &lt;code&gt;Array&lt;/code&gt;‘s &lt;code&gt;toArray&lt;/code&gt; does); a &lt;code&gt;static apply(xs: A*) -&amp;gt; Self&lt;/code&gt; in
&lt;code&gt;Buildable&lt;/code&gt; with a default body (makes &lt;code&gt;C(1, 2)&lt;/code&gt; callable on a bound &lt;code&gt;C: Buildable[int]&lt;/code&gt;, but adds
a second member every program’s impl inherits, and &lt;code&gt;C.newBuilder()&lt;/code&gt; already serves that).
&lt;strong&gt;Review with the user&lt;/strong&gt;: the name &lt;code&gt;Buildable&lt;/code&gt;, and whether the companions’ &lt;code&gt;newBuilder&lt;/code&gt; should
eventually be the static member alone.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;train-ay&lt;/code&gt;, reconciling &lt;code&gt;builder-trait&lt;/code&gt; with
the comparisons of ranges and literals that predate it): &lt;strong&gt;a type only suggested to a collection
literal, by another operand of &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt; or an ordering, leaves the literal its default where no
literal builds that type&lt;/strong&gt;, so &lt;code&gt;(1 .. 3) == [1, 2, 3]&lt;/code&gt; is
a &lt;code&gt;Range&lt;/code&gt; compared with a &lt;code&gt;Vector&lt;/code&gt; by their elements, as before &lt;code&gt;Buildable&lt;/code&gt;; a type demanded of
the literal (a declaration, a parameter, a result, an ascription) still reports the trait it
lacks, &lt;code&gt;val r: Range = [1, 2]&lt;/code&gt;. WHY: the suggestion exists so a literal compares like with like
where it can (&lt;code&gt;xs == [1, 2]&lt;/code&gt; with &lt;code&gt;xs&lt;/code&gt; a &lt;code&gt;List&lt;/code&gt;); where it cannot, a literal of the default
compares the same by &lt;code&gt;Seq&lt;/code&gt; equality, and an error there would refuse a comparison that has an
obvious meaning. ALTERNATIVES: refusing the comparison and asking for &lt;code&gt;.toVector&lt;/code&gt; (breaks
established programs for no soundness gain); making &lt;code&gt;Range&lt;/code&gt; &lt;code&gt;Buildable&lt;/code&gt; (a literal cannot promise
a range’s even step, so its builder would have to fail at run time).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;train-ay&lt;/code&gt;, reconciling &lt;code&gt;bytes-sendable&lt;/code&gt;‘s
&lt;code&gt;object Isolated&lt;/code&gt; with constructors used as values): &lt;strong&gt;a class’s companion object that declares no
&lt;code&gt;apply&lt;/code&gt; leaves the name the class’s constructor where a function is expected&lt;/strong&gt;, as in call
position, so &lt;code&gt;val mi: (Vector[string]) -&amp;gt; Isolated[Vector[string]] = Isolated&lt;/code&gt; and
&lt;code&gt;[1, 2].map(Box)&lt;/code&gt; make values; elsewhere the name is the object. WHY: adding a companion with
unrelated members (&lt;code&gt;Isolated.move&lt;/code&gt;) must not take away the constructor value its class had.
ALTERNATIVES: the object always (breaks every such value when a companion is added); an error
asking to choose (nothing is ambiguous where the object is not a function).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;avin repl&lt;/code&gt;, an interactive session&lt;/strong&gt; (branch &lt;code&gt;repl&lt;/code&gt;, 2026-11-19; approved by the user the same
day). The surface is in &lt;a href=&quot;/getting-started/#the-interactive-session&quot;&gt;getting started&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a session is one growing program, built and run
whole after each input; earlier inputs run again, their output passed over.&lt;/strong&gt; Imports go to the
program’s top, type declarations below them, everything else into &lt;code&gt;main&lt;/code&gt;; the program writes a
mark before the newest input and one after it, and only what lies between is shown. WHY: Avin
compiles a closed world — one LLVM module with the library, monomorphized instances, devirtualized
calls and per-program type descriptors — so loading each input as a shared object into one live
process (keeping the heap, globals and threads) needs separate compilation across units:
instances shared or duplicated between units, type identity across them, the collector’s roots
registered per loaded unit, and the runtime moved into the host. That is a compiler architecture,
not an item. Replaying costs an input’s side effects repeating unseen, values computed afresh
(random, time) differing from the ones shown, and run time growing with the session; each input
still builds in about a second at &lt;code&gt;-O0&lt;/code&gt; through the instance cache. ALTERNATIVES: &lt;code&gt;dlopen&lt;/code&gt; per
input into a live process (the right end state, above); an interpreter over the checked program
(a second semantics to keep equal to the compiled one); replaying with the earlier inputs’
effects suppressed (not possible for effects outside the process). &lt;strong&gt;Review with the user:&lt;/strong&gt;
whether the live-process design is wanted next, and how soon.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;each code input is a block nested in the one
before it&lt;/strong&gt; (&lt;code&gt;if true&lt;/code&gt; around the rest), so &lt;code&gt;val x&lt;/code&gt; entered again hides the earlier &lt;code&gt;x&lt;/code&gt; from the
later inputs, as a block’s local does, and the earlier inputs keep the &lt;code&gt;x&lt;/code&gt; they saw; a local
function entered again does the same. WHY: Avin forbids a second &lt;code&gt;val&lt;/code&gt; of one name in one block;
nesting gives the hiding every interactive language has without renaming anything.
ALTERNATIVES: renaming earlier bindings (rewrites what the user typed, and diagnostics show other
names).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;repl-2&lt;/code&gt;; replaces “functions are local
functions of &lt;code&gt;main&lt;/code&gt;“ and “a type declared again replaces the earlier declaration”): &lt;strong&gt;each
declaration of types, and each function or &lt;code&gt;val&lt;/code&gt; that uses no local of &lt;code&gt;main&lt;/code&gt;, is a module of the
session’s own&lt;/strong&gt; (&lt;code&gt;avinrepl.c3&lt;/code&gt;), which imports, by name, the newest of each name the inputs
before it gave, and every earlier module whole (so their extensions are seen). Such a function or
&lt;code&gt;val&lt;/code&gt; is &lt;em&gt;hoisted&lt;/em&gt;: a class, trait or function entered after it calls or reads it. A hoisted
function is also written into &lt;code&gt;main&lt;/code&gt; where it was entered, and a hoisted &lt;code&gt;val&lt;/code&gt; read there under
its name (&lt;code&gt;val base = avinReplC2.base&lt;/code&gt;), so code in &lt;code&gt;main&lt;/code&gt; sees every name in the order entered,
exactly as before. A name entered again hides the earlier one from every later input, module or
code, and a module entered before keeps the one it imported: a class calling &lt;code&gt;twice&lt;/code&gt; keeps the
&lt;code&gt;twice&lt;/code&gt; it was declared after. “Uses no local” is the checker’s answer, not a guess: the input is
first checked and run as code of &lt;code&gt;main&lt;/code&gt;, and hoisted when none of its references resolve to a
local of &lt;code&gt;main&lt;/code&gt; other than a hoisted input’s. A hoisted input is written as a module only once a
declaration of types comes after it (nothing else can reach it there), so a session of code
alone checks and builds no extra files; one that does not check as a module when a declaration
first needs it stays code of &lt;code&gt;main&lt;/code&gt;, and the declaration is checked again without it. A function
or &lt;code&gt;val&lt;/code&gt; that uses a local stays in &lt;code&gt;main&lt;/code&gt;, and a &lt;code&gt;var&lt;/code&gt;, a &lt;code&gt;lazy val&lt;/code&gt;, a
destructuring &lt;code&gt;val&lt;/code&gt; and an input of several statements stay there too, out of the modules’
reach; a module never imports a name whose newest declaration is such a local. &lt;code&gt;main&lt;/code&gt; imports the
newest of each type’s name, so code there sees a type declared again in place of the old one,
and the new declaration is refused where earlier code of &lt;code&gt;main&lt;/code&gt; no longer checks against it. An
impl of a type or trait the session declared joins that declaration’s module, where a
conformance has to be and a plain impl’s methods are the type’s own; any other impl is an
extension in a module of its own. A session import binding a name a module gives is left out of
the later modules, the module’s name being the nearer. A hoisted &lt;code&gt;val&lt;/code&gt; is computed before &lt;code&gt;main&lt;/code&gt;
when the session runs again, which is not seen: an earlier input’s output is passed over.
WHY: a declaration can only reach what is declared at the top level of some module, and modules
are how Avin scopes names, so one module per input gives declarations the same hiding &lt;code&gt;main&lt;/code&gt;
has, with nothing renamed and every diagnostic in the user’s own names; and each module’s text is
fixed once entered, so its instances stay in the build cache. ALTERNATIVES: one top-level module
for every declaration (a function or &lt;code&gt;val&lt;/code&gt; entered again would replace the earlier one under the
inputs that used it, and a value computed from it would change when the session runs again);
hoisting by renaming (&lt;code&gt;twice$2&lt;/code&gt;; diagnostics and types show the other names); hoisting by a
syntactic test of the free names (a parameter named like a local would keep the function local).
&lt;strong&gt;Review with the user:&lt;/strong&gt; that code of &lt;code&gt;main&lt;/code&gt; sees a type declared again where modules keep the
old one (Avin has no local types to hide it with), and whether a &lt;code&gt;var&lt;/code&gt; should be reachable from
declarations too (a module-level &lt;code&gt;var&lt;/code&gt; changes what threads may read).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;an expression’s value is kept as &lt;code&gt;resN&lt;/code&gt; and shown
as &lt;code&gt;res0: int = 42&lt;/code&gt;, by its type’s &lt;code&gt;Debug&lt;/code&gt; through &lt;code&gt;Any&lt;/code&gt;&lt;/strong&gt; (a string quoted, a type with no
&lt;code&gt;Debug&lt;/code&gt; by its name, a function as &lt;code&gt;&amp;lt;function&amp;gt;&lt;/code&gt;); a &lt;code&gt;val&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; shows its own name, a local
function its header, a type declaration its header; an expression of type &lt;code&gt;unit&lt;/code&gt; shows nothing
and takes no number. The type is the checker’s, as hover shows it. ALTERNATIVES: &lt;code&gt;Display&lt;/code&gt;
(a string unquoted reads like output); &lt;code&gt;it&lt;/code&gt; for the last value only.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;an input ends&lt;/strong&gt; at the end of its line unless a
bracket is open, the line ends with an operator, &lt;code&gt;=&lt;/code&gt; or a comma, or the input opened a block —
a type’s declaration, a line the parser finds unfinished at its end (&lt;code&gt;if x &amp;gt; 0&lt;/code&gt;, &lt;code&gt;f(n: int) -&amp;gt; int&lt;/code&gt;), or a local function’s header with parameters (&lt;code&gt;log(m: string)&lt;/code&gt;, which alone reads as a
call) — which an empty line ends. &lt;code&gt;greet()&lt;/code&gt; alone is a call; a function of no parameters opens
its block with a result type or &lt;code&gt;=&lt;/code&gt;. ALTERNATIVES: a continuation character; always waiting for
an empty line after an indented line (one more Enter for every one-line input).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;repl-2&lt;/code&gt;, replacing &lt;code&gt;sysl.term.edit&lt;/code&gt;,
which edits one line and completes nothing): &lt;strong&gt;at a terminal an input is edited whole by the
session’s own editor&lt;/strong&gt; (&lt;code&gt;repl_editor.sysl&lt;/code&gt;, over &lt;code&gt;sysl.term.keys&lt;/code&gt;): Enter enters an input the
completeness rule above finds complete, wherever the cursor is, and otherwise breaks the line at
the cursor and goes on under a &lt;code&gt;   |&lt;/code&gt; prompt, indented as the line above and two more after a
line opening a block (&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, a header, an open bracket, a trailing operator; a trailing
comma keeps the indentation); Backspace over an indentation takes back two columns; the arrows
move through the input’s lines and, past its first or last, through the inputs entered before
(500, whole); Ctrl-A/E/B/F/P/N/K/U as usual, Ctrl-C drops the input, Ctrl-D on an empty one ends
the session. Lines wider than the terminal are drawn over as many rows as they take (its width is
asked at each drawing). Raw mode only while an input is read, so a running input gets Ctrl-C;
&lt;strong&gt;read from a pipe there are no prompts&lt;/strong&gt;, and lines are taken one at a time as before, so a
scripted session’s output is what its inputs write. An input’s standard output and error reach
the session as one stream, in the order written. No new C dependency. ALTERNATIVES: linenoise
(a C dependency); a line at a time with a continuation prompt (an earlier line cannot be
changed); entering on an empty line always (one more Enter for every one-line input).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;repl-2&lt;/code&gt;): &lt;strong&gt;Tab completes from the
language server’s completion&lt;/strong&gt; (&lt;code&gt;completion.sysl&lt;/code&gt;): the input is placed in the session’s
program as it would be entered (an import among the imports, a declaration of types as a module
of its own, other code in &lt;code&gt;main&lt;/code&gt;), the word at the cursor replaced by the stand-in, and what the
check finds there is offered: names in scope (locals of &lt;code&gt;main&lt;/code&gt;, hoisted inputs, types, imports,
the core library, and the keywords an expression may begin with), a receiver’s members after a
&lt;code&gt;.&lt;/code&gt;, modules after &lt;code&gt;import&lt;/code&gt;. The names are ordered nearest scope first, then by name; Tab writes
what all of them begin with, and when that adds nothing and there are several, lists them under
the input. Tab with only spaces before the cursor indents. The session’s own names
(&lt;code&gt;avinReplShow&lt;/code&gt;, the module aliases) are never offered. ALTERNATIVES: names collected from the
session’s text (no members, no types of expressions); a menu to choose from (a larger editor).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;in a package, or a directory holding a program,
the session’s program is that program with its root module replaced by the session&lt;/strong&gt;, so its
modules import as they do from &lt;code&gt;main&lt;/code&gt;, and its dependencies, Sysl packages and C libraries come
with it. &lt;code&gt;:load &amp;lt;file&amp;gt;&lt;/code&gt; enters a file’s imports and top-level declarations one at a time as if
typed; its &lt;code&gt;main&lt;/code&gt; becomes a local function to call. ALTERNATIVES: keeping the root module
(its &lt;code&gt;main&lt;/code&gt; collides with the session’s); &lt;code&gt;:load&lt;/code&gt; running the file’s &lt;code&gt;main&lt;/code&gt; (it can be called).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;, the
design approved by the user 2026-11-13 and its build approved 2026-11-19; built from branch
&lt;code&gt;given-1&lt;/code&gt; on): &lt;strong&gt;contextual parameters are for context values, never for
conformances&lt;/strong&gt; (&lt;a href=&quot;/spec/contextual-parameters/&quot;&gt;contextual parameters&lt;/a&gt;). A &lt;code&gt;using&lt;/code&gt; parameter is
filled from a &lt;code&gt;given&lt;/code&gt; in scope; a bound is met only by the type’s &lt;code&gt;impl&lt;/code&gt;, a given never overrides
or adds to one, a contextual parameter’s type names no type parameter, and a given has none. Why:
Avin already resolves trait instances coherently through &lt;code&gt;impl&lt;/code&gt; and bounds, so letting a given
fill a bound would be a second way to supply an instance, and an incoherent one: a &lt;code&gt;TreeSet&lt;/code&gt;
built under one ordering and searched under another. Under the principle the user set the same
day (&lt;em&gt;“the ultimate SOUND, NOMINALLY typed, compiled, garbage-collected high-level language”&lt;/em&gt;),
coherence is not negotiable, so givens carry what conformances cannot: a transaction, a logger,
a request, a clock. A non-natural order stays an argument of its call (&lt;code&gt;sortWith&lt;/code&gt;, &lt;code&gt;sortBy&lt;/code&gt; with
&lt;code&gt;Reverse&lt;/code&gt;). Alternatives weighed: a &lt;code&gt;using&lt;/code&gt; of a trait type filled by a given, falling back to the
impl (two ways to do one thing, and incoherent across values built under different scopes);
givens for bounds only with priorities (the search and ambiguity rules that cost compile time and
predictability); no contextual parameters at all (every layer threads a logger by hand).
&lt;strong&gt;Review with the user.&lt;/strong&gt; This is the central choice.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; built
on branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;every given is named; no anonymous givens.&lt;/strong&gt;
&lt;code&gt;given tx = db.begin()&lt;/code&gt;, &lt;code&gt;given log: Logger = …&lt;/code&gt;. Why: one way to declare one; the name is what a
call passes explicitly (&lt;code&gt;tx = …&lt;/code&gt;), what a diagnostic names and what another file imports.
Alternatives weighed: anonymous &lt;code&gt;given RequestContext(id)&lt;/code&gt; (a second form for the same thing, and
an import with nothing to name); &lt;code&gt;given existingName&lt;/code&gt; to make a value a given (a second way to
make a lambda’s parameter one, beside &lt;code&gt;using&lt;/code&gt;). Review with the user: anonymous givens are the
likeliest to be missed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; built
on branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;using&lt;/code&gt; is a trailing section of the one parameter
list&lt;/strong&gt;, &lt;code&gt;f(a: A, using tx: Tx, log: Logger)&lt;/code&gt;, passed explicitly only by name. Why: Avin has one
parameter list per function and named arguments already; positional passing would let an
argument meant for an ordinary parameter land on a contextual one. Alternatives weighed: a second
parameter list &lt;code&gt;f(a)(using tx)&lt;/code&gt; (Avin has no curried lists); &lt;code&gt;using&lt;/code&gt; on each parameter (repetition);
positional explicit passing (ambiguous next to defaults).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; to be
built at step 3 of the &lt;a href=&quot;/compiler/roadmap/#contextual-parameters-build-plan&quot;&gt;plan&lt;/a&gt;): &lt;strong&gt;resolution is lexical, nearest level wins, two fits
at one level are an error&lt;/strong&gt;: blocks, then enclosing functions’ and lambdas’ &lt;code&gt;using&lt;/code&gt; parameters,
the class constructor’s or actor’s, the object’s givens, then the module’s own givens with the
file’s imported ones; fit is nominal conformance; then the parameter’s default. Why: one
deterministic answer per call, decided where it is written and shown by the source; no ranking by
specificity, so no rule a reader must simulate. Alternatives weighed: exact-type matching only (a
given &lt;code&gt;FileLogger&lt;/code&gt; could not fill a &lt;code&gt;Logger&lt;/code&gt;); most-specific ranking across levels (search, and
surprising winners); one flat scope (a block could not narrow a module’s given).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; to be
built at step 4 of the plan): &lt;strong&gt;a given is seen in another file only when imported
by name&lt;/strong&gt; (directly or through an export); importing the module whole does not bring its givens.
Why: a given changes what a call receives with nothing written at the call, so the file says
which; a library adding a given then cannot change an existing call elsewhere. Alternatives
weighed: givens seen through any import of their module, as extensions are (silent changes of
meaning); a &lt;code&gt;.given&lt;/code&gt; wildcard import (Avin has no wildcard import). Review with the user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; built
on branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;a given’s type is a nominal type of the program&lt;/strong&gt;
(a class, an object’s type, a trait used as a type, a &lt;code&gt;data&lt;/code&gt; type, closed type arguments); built-in
types, tuples, function types and unions are refused, and a given is a &lt;code&gt;val&lt;/code&gt;. Why: nominal typing
— a value fills a parameter because its type declares what it is, not because a common shape such
as &lt;code&gt;int&lt;/code&gt; fits; and a &lt;code&gt;var&lt;/code&gt; given would share a box across closures and threads.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; built
on branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;givens are declared in blocks, at a module’s top
level and in object bodies; classes and actors take context as &lt;code&gt;using&lt;/code&gt; parameters of their
constructors&lt;/strong&gt; (private fields, givens in their bodies). No &lt;code&gt;given&lt;/code&gt; in class, trait or &lt;code&gt;data&lt;/code&gt;
bodies, and none of &lt;code&gt;data&lt;/code&gt; variants, &lt;code&gt;main&lt;/code&gt;, tests, hooks or bindings take a &lt;code&gt;using&lt;/code&gt; section. Why:
one place per kind of declaration; a class’s context comes from whoever makes it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; to be
built at step 5 of the plan): &lt;strong&gt;lambdas and function values.&lt;/strong&gt; A lambda resolves
where it is written and captures the givens it uses; its parameters after &lt;code&gt;using&lt;/code&gt; are givens in
its body but positional in its type; function types have no &lt;code&gt;using&lt;/code&gt; section; a function taken as a
value has its section filled where it is taken. Why: a function value is called with positional
arguments only (as for names and defaults), and lexical capture keeps one rule for every closure.
Alternatives weighed: contextual function types (&lt;code&gt;(using Tx) -&amp;gt; R&lt;/code&gt;, a new kind of type); a
&lt;code&gt;given tx&lt;/code&gt; statement in the lambda’s body (a second way). Review with the user: contextual
function types are what would make &lt;code&gt;db.transaction { insert(row) }&lt;/code&gt; need no parameter.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; to be
built at step 5 of the plan): &lt;strong&gt;a given does not cross &lt;code&gt;spawn&lt;/code&gt; by itself&lt;/strong&gt;; a
closure that uses one captures it and is checked as any capture (sendability, no &lt;code&gt;var&lt;/code&gt;). Why: a
given is a lexical value, not thread-local state, so the sharing rules see it. Alternatives
weighed: an inherited per-thread context (dynamic scoping, invisible in the source).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (proposed 2026-11-13 on branch &lt;code&gt;given-design&lt;/code&gt;; the
section built on branch &lt;code&gt;given-1&lt;/code&gt;, its filling at step 3 of the plan): &lt;strong&gt;contextual parameters may have defaults&lt;/strong&gt;, used
where no given fits, and every default of the function sees the contextual parameters, which are
filled first. The section takes no part in choosing an overload. Why: a default is the natural
fallback (&lt;code&gt;using clock: Clock = SystemClock&lt;/code&gt;), and resolving after the overload is chosen keeps
the cost of a call linear and its errors at the chosen function. No standard-library API adopts
contextual parameters in this design; adopting one (an &lt;code&gt;Executor&lt;/code&gt; for &lt;code&gt;Future(body)&lt;/code&gt;) is its own
item, since &lt;code&gt;ex.future(body)&lt;/code&gt; already exists and the two would be two ways.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;an opaque type may be a given’s
and a contextual parameter’s type&lt;/strong&gt;, beside classes, objects, traits used as types and &lt;code&gt;data&lt;/code&gt;
types. Why: the refusal of built-in types exists because a given &lt;code&gt;int&lt;/code&gt; would be given wherever
any &lt;code&gt;int&lt;/code&gt; is asked for; an opaque type is a nominal type of its own (&lt;code&gt;opaque type UserId = long&lt;/code&gt;), which only what asks for a &lt;code&gt;UserId&lt;/code&gt; receives, so it has none of that problem, and “avin is
for everyone” favours the wider rule. Alternatives weighed: refusing it as the design’s list did
(a wrapper &lt;code&gt;data&lt;/code&gt; type would be needed for a value an opaque type already names). Review with
the user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;where &lt;code&gt;given&lt;/code&gt; and &lt;code&gt;using&lt;/code&gt;
begin their forms.&lt;/strong&gt; &lt;code&gt;given&lt;/code&gt; begins a given where a name and its &lt;code&gt;:&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt; follow it; before
&lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; or a capitalized name it is read as a given and reported (a &lt;code&gt;val&lt;/code&gt; already; never a
&lt;code&gt;var&lt;/code&gt;; every given named); everywhere else it is a name. &lt;code&gt;using&lt;/code&gt; begins a section where a name
(or a class parameter’s modifier) follows it in a parameter list, also in a parenthesized lambda
and as &lt;code&gt;using tx -&amp;gt;&lt;/code&gt;, alone or as a call’s trailing lambda. Why: the smallest test that keeps
every existing use (&lt;code&gt;args.given(…)&lt;/code&gt;, &lt;code&gt;given = 3&lt;/code&gt;, &lt;code&gt;given(x)&lt;/code&gt;, a parameter &lt;code&gt;using: Mode&lt;/code&gt;) meaning
what it did; the capitalized-name case turns the likeliest mistake, an unnamed given, into its
own message rather than a parse error. Alternatives weighed: reserving both words (breaks
existing programs); reading &lt;code&gt;given&lt;/code&gt; before any name as a declaration (an infix call &lt;code&gt;given max b&lt;/code&gt; on a value named &lt;code&gt;given&lt;/code&gt; would change meaning).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-1&lt;/code&gt;): &lt;strong&gt;a contextual parameter has a
name, is neither by-name nor repeated, and a class’s is written without &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; or
&lt;code&gt;private&lt;/code&gt;; a repeated parameter may come just before the section.&lt;/strong&gt; Why: it is passed explicitly
only by name; a given is one value already made, so by-name evaluation and repetition mean
nothing for it; a class’s contextual parameter is a private field and a given by definition.
The section comes last, so a repeated parameter is last of the others (&lt;code&gt;all(xs: int*, using tx: Tx)&lt;/code&gt;). A data variant takes no section, reported where it is parsed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-3&lt;/code&gt;): &lt;strong&gt;a local function’s or a lambda’s
contextual parameters are a level of the scope walk between its body and the block it is written
in&lt;/strong&gt;, so they beat the givens of the blocks around it and lose to the givens of its own body’s
blocks. Why: the chapter listed “the enclosing blocks” before “the contextual parameters of each
enclosing function or lambda”, which read literally would let a block outside a local function hide
the function’s own &lt;code&gt;using&lt;/code&gt; parameter, the value its caller chose for it; resolving by lexical
nearness is the rule every other name follows, and it is the reading of “nearer level wins” a
reader expects. Alternatives weighed: every block first, then every function’s parameters
innermost out (the literal list, where &lt;code&gt;helper(using tx: Tx) = tag()&lt;/code&gt; written in a block with
&lt;code&gt;given t = Tx(…)&lt;/code&gt; would ignore its own &lt;code&gt;tx&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-3&lt;/code&gt;): &lt;strong&gt;the section’s defaults are
computed before the other omitted defaults, and a contextual parameter’s default sees the
section’s parameters before it, not the ordinary ones&lt;/strong&gt;; an ordinary default sees the parameters
before it and the whole section. Why: the chapter has ordinary defaults see the section, so the
section must be complete first; a section default that also saw ordinary parameters could depend
on an ordinary default that depends on it, a cycle with no order to compute it in. Alternatives
weighed: a section default seeing every parameter before it in the list (needs an order that
interleaves the two kinds, and the cycle above is then a compile error to explain); a section
default seeing nothing of the call (&lt;code&gt;using tx: Tx, clock: Clock = Clock(tx.start)&lt;/code&gt; lost).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-3&lt;/code&gt;): &lt;strong&gt;a positional argument past the
parameters before the section is the “passed by name” error when the call writes no more
positional arguments than the function has parameters, and the argument-count error otherwise&lt;/strong&gt;
(&lt;code&gt;tag(tx, tx)&lt;/code&gt; for &lt;code&gt;tag(using tx: Tx)&lt;/code&gt; says it takes 0 arguments, not 2). Where a repeated
parameter comes before the section, every positional argument is the repeated parameter’s, so a
&lt;code&gt;tx&lt;/code&gt; written last is a type error there, and the section is still filled. Why: the error names the
likeliest fix, naming the argument, where a call has one positional argument per contextual
parameter; beyond that it was not meant for the section. Alternatives weighed: always the “passed
by name” error (wrong advice for a call of too many arguments).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-4&lt;/code&gt;): &lt;strong&gt;a given a module exports by name
is a given of that module’s own files too&lt;/strong&gt;, beside the givens it declares, at the module level of
the scope walk; a given and an export of it, or two imports of one given (&lt;code&gt;current as tx&lt;/code&gt; and
&lt;code&gt;kit.{current}&lt;/code&gt;), are one given, never two that fit. Why: an export names the given as explicitly
as an import does, and a module’s files already see every name it exports as one of their own, so
the rule “a file sees another module’s given only where a name of it is written” holds for both.
Alternatives weighed: an export presents the given to importers only, its own files needing an
import as well (a second line naming the same given, with nothing the reader learns from it).
Review with the user: whether exporting a given should also bring it in for the exporting module.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-4&lt;/code&gt;): &lt;strong&gt;the “no given” error’s hint names
every public given, of the parameter’s type or one conforming to it, that a module the file imports
whole declares or exports and the file does not already import&lt;/strong&gt;, each as its own clause after
&lt;code&gt;; &lt;/code&gt; (&lt;code&gt;`kit` declares the given `kitTx`, which this file does not import: `import kit.{kitTx}`&lt;/code&gt;),
under the name that module presents it by. A private given is never offered, since it cannot be
imported. Why: the hint is there to say which import to write, so it offers exactly the imports
that would compile and fix the call. Alternatives weighed: the first such given only (hides the
choice when two modules offer one); every module of the program (suggests modules the file never
named).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-4&lt;/code&gt;): &lt;strong&gt;imported givens enter the
instance cache through the module-level value each filled call reads&lt;/strong&gt;, with no extra key input: a
filled argument is a read of that value in the typed tree, and a key already holds the interface
of every module-level value its tree reads, so an edit of an imported given’s type lowers each
caller it fills again and an edit of its value alone does not. Alternatives weighed: a key input
listing every given a file imports (re-lowers callers on edits that cannot change their text).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-5&lt;/code&gt;): &lt;strong&gt;a function, method or
constructor with a &lt;code&gt;using&lt;/code&gt; section, taken as a value, is a closure calling it as a call written
where the value is taken would: its type is the parameters before the section, the section is
filled from the givens in scope there, which the closure captures, and a contextual parameter no
given fills takes its default, computed at each call of the value.&lt;/strong&gt; &lt;code&gt;rows.map(insert)&lt;/code&gt; is exactly
&lt;code&gt;rows.map(row -&amp;gt; insert(row))&lt;/code&gt;, so a value with no given in scope is the call’s “needs a &lt;code&gt;Tx&lt;/code&gt;“
error, two that fit are the call’s “two givens” error, an overload is chosen by the parameters
before its section, and a value cannot take the section explicitly (a lambda does: &lt;code&gt;(r, t) -&amp;gt; insert(r, tx = t)&lt;/code&gt;). A method whose parameters are all in its section is called with &lt;code&gt;()&lt;/code&gt; as one of
no parameters is: &lt;code&gt;s.current&lt;/code&gt; with no function type expected is the “called with &lt;code&gt;()&lt;/code&gt;“ error, and
&lt;code&gt;val f: () -&amp;gt; int = s.current&lt;/code&gt; is its value. Why: the chapter’s own equivalence, taken literally,
gives every other answer: the given is captured as any read of it is, so the &lt;code&gt;spawn&lt;/code&gt;, &lt;code&gt;@sendable&lt;/code&gt;,
executor and &lt;code&gt;@threaded&lt;/code&gt; checks name it with no new rule, and a default is computed where an
omitted argument’s always is, at the call. Alternatives weighed: keeping the section as positional
parameters of the value (the step-3 behaviour; the given in scope would be ignored, and the value
would not fit the function types it reads as); computing the defaults once where the value is
taken (a second time at which a default runs, unlike every other default); a value of a method of
only contextual parameters made where no function type is expected (&lt;code&gt;s.current&lt;/code&gt; would then quietly
be a function where a call was almost certainly meant).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-5&lt;/code&gt;): &lt;strong&gt;an actor’s &lt;code&gt;using&lt;/code&gt; section is
held to &lt;code&gt;Sendable&lt;/code&gt; as any actor parameter is, filled where the actor is made&lt;/strong&gt;, by the given in
scope, by name, or by its default, and its parameters are givens in the actor’s body and its
&lt;code&gt;receive&lt;/code&gt;. Why: an actor’s parameters are carried to it by its behaviour, so the section is checked
where the actor is declared, once, with the message every other parameter gets. Alternatives
weighed: none that keeps one rule for actor parameters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-6&lt;/code&gt;): &lt;strong&gt;an editor sees each argument a
call’s &lt;code&gt;using&lt;/code&gt; section was filled with at the call’s name.&lt;/strong&gt; Hover on the name shows the
function’s signature, then “Filled from givens:” and one line per filled parameter as it would be
written, with the given’s declaration beside it (&lt;code&gt;tx = current  // val current: Tx&lt;/code&gt;); go to
definition answers the function first and then each given, in the section’s order (an editor
shows a list to pick from); a given’s references and highlights include the calls it filled, at
the call’s name; a rename of a given never edits a call it filled, since nothing there spells
it; and the call’s name stays one semantic token, the function’s. A signature shown by hover or
completion writes &lt;code&gt;using&lt;/code&gt; once before its section (&lt;code&gt;send(n: int, using tx: Tx, log: Log)&lt;/code&gt;), and a
completed call’s snippet leaves the section out. Why: a filled argument has no text of its own,
and the call’s name is the one place a reader looks at when asking what the call receives;
listing the givens in definition makes the jump one step from where the question arises.
Alternatives weighed: an inlay hint after the call’s parentheses (&lt;code&gt;insert(2)⟨tx = current⟩&lt;/code&gt;;
cleaner to read, but a separate request most editors show only when asked, and nothing here
serves inlay hints yet); definition going to the given alone (loses the function, the commoner
question); leaving filled calls out of references (then “where is this given used” has no
answer). Review with the user: whether inlay hints for filled arguments are wanted as well.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-6&lt;/code&gt;): &lt;strong&gt;completion offers &lt;code&gt;given&lt;/code&gt; and
&lt;code&gt;using&lt;/code&gt; where a form may begin with them&lt;/strong&gt;: both among the statement keywords where a name in an
expression is being written (a block’s given; a &lt;code&gt;using&lt;/code&gt; lambda, &lt;code&gt;using tx -&amp;gt; …&lt;/code&gt;); &lt;code&gt;given&lt;/code&gt; at the
start of a line no expression holds (a module’s or an object’s given); and &lt;code&gt;using&lt;/code&gt; at an item’s
start in a parenthesized list no expression holds (a parameter list, on its line or a line of its
own). A type, a member after a dot and an import offer neither. Why: the checker already tells an
expression’s place apart; the other two are read off the text before the cursor, which is all a
half-written declaration offers. Alternatives weighed: walking the parsed declaration for a
parameter at the cursor (exact, but a half-written parameter list rarely parses); offering both
everywhere (noise in types and imports, where neither can be written).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Guards on &lt;code&gt;select&lt;/code&gt; arms, and &lt;code&gt;Selector&lt;/code&gt; for a set of sources known at run time&lt;/strong&gt; (branch
&lt;code&gt;select-dynamic&lt;/code&gt;, 2026-11-19). The gap came from the ssh package (branch &lt;code&gt;pty-forward&lt;/code&gt;,
&lt;code&gt;Socket.waitWith&lt;/code&gt;): relaying a tunnel to a local connection, it could not leave out an arm by a
run-time condition (“watch &lt;code&gt;local.writable()&lt;/code&gt; only while bytes are pending for it”) and spelled
out twelve selects, one per combination; and nothing could wait on N connections or N tunnels,
which blocks a multi-connection &lt;code&gt;ssh -L&lt;/code&gt; and &lt;code&gt;-R&lt;/code&gt;. The surface is &lt;a href=&quot;/spec/threads/#select&quot;&gt;select&lt;/a&gt;
and &lt;a href=&quot;/spec/threads/#selectors&quot;&gt;selectors&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;any arm but &lt;code&gt;else&lt;/code&gt; may end in an &lt;code&gt;if&lt;/code&gt; guard&lt;/strong&gt;,
written as a match arm’s is, after the operation and its &lt;code&gt;as&lt;/code&gt; pattern. &lt;strong&gt;A false guard makes the
arm absent&lt;/strong&gt;: not evaluated beyond its guard, not watched, never run, its value never sent. &lt;strong&gt;The
guard is evaluated first&lt;/strong&gt;, with the arms’ other expressions, once and in written order, before
any arm is tried, so it cannot name the arm’s pattern’s bindings, which no value has yet. WHY:
evaluating the guard first lets it protect the arm’s own expressions (&lt;code&gt;conns(i).readable() if i &amp;lt; n&lt;/code&gt;) and keeps a value meant for an absent arm from being computed; an arm that is not there
should cost nothing. ALTERNATIVES: the guard after the arm’s expressions (a send’s value computed
for nothing, and a guard that cannot protect its arm); a guard that sees the received value, as
a match guard sees its bindings (it would have to receive before deciding, then put the value
back, which a channel cannot do without reordering).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a select whose every arm is guarded off, with no
&lt;code&gt;after&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt; left, traps&lt;/strong&gt;, and so does &lt;code&gt;wait&lt;/code&gt; on an empty &lt;code&gt;Selector&lt;/code&gt;. WHY: only a
cancellation could end such a wait, which is almost always a loop’s exit condition gone wrong;
the trap names it where it happens, instead of a thread that hangs or a deadlock report later.
A thread meant to wait for its cancellation says so with an &lt;code&gt;after&lt;/code&gt; or a channel. ALTERNATIVES:
waiting for cancellation (as the brief offered; silent where it is a bug); a compile-time error
(guards are run-time values, so it can only be caught at run time).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;after&lt;/code&gt; takes a guard; &lt;code&gt;else&lt;/code&gt; does not.&lt;/strong&gt; A false
guard on &lt;code&gt;after&lt;/code&gt; leaves a select that waits until an arm runs. &lt;code&gt;else&lt;/code&gt;‘s body follows it with no
arrow, so &lt;code&gt;else if c then a else b&lt;/code&gt; already means an &lt;code&gt;if&lt;/code&gt; there. WHY: a guarded &lt;code&gt;after&lt;/code&gt; is the
“time out only while something is pending” case; a guarded &lt;code&gt;else&lt;/code&gt; is &lt;code&gt;after 0&lt;/code&gt; guarded, which
already exists. ALTERNATIVES: a guard on &lt;code&gt;else&lt;/code&gt; (&lt;code&gt;else if&lt;/code&gt; would read two ways).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;the dynamic form is a library type,
&lt;code&gt;avin.threads.Selector[K: Eq]&lt;/code&gt;&lt;/strong&gt;: entries &lt;code&gt;receive(channel, key) -&amp;gt; SelectReceive[T]&lt;/code&gt; (whose
&lt;code&gt;received()&lt;/code&gt; holds what was received), &lt;code&gt;send(channel, x, key)&lt;/code&gt;, &lt;code&gt;readable(source, key)&lt;/code&gt; and
&lt;code&gt;writable(sink, key)&lt;/code&gt;; &lt;code&gt;remove(key)&lt;/code&gt;, &lt;code&gt;removeWhere(p)&lt;/code&gt;, &lt;code&gt;clear()&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;; waits
&lt;code&gt;wait() -&amp;gt; K&lt;/code&gt;, &lt;code&gt;within(timeout)&lt;/code&gt;, &lt;code&gt;until(deadline)&lt;/code&gt; and &lt;code&gt;poll() -&amp;gt; Option[K]&lt;/code&gt;. The entries stay
between waits; a send entry is taken out once its value has gone. Each entry is the arm object a
&lt;code&gt;select&lt;/code&gt; block is read into, and a wait runs the same library loop and the same runtime park on
the poller, so there is one wait path. WHY: a set of N sources needs a value the program can
build, keep and change between waits, and keys of the program’s choosing answer “which one”
without index bookkeeping; mixed kinds (channels and streams) live in one set. ALTERNATIVES: a
&lt;code&gt;for&lt;/code&gt; arm in &lt;code&gt;select&lt;/code&gt; (&lt;code&gt;for c in conns: c.readable() -&amp;gt; …&lt;/code&gt;), which reads well for one homogeneous
collection but rebuilds the set every time the select is reached, needs a second arm per kind of
source, and adds a binding form to the select grammar; both (two ways to say the same thing, the
&lt;code&gt;for&lt;/code&gt; arm being sugar the library type can carry later if programs want it); entries answered by
index (indices shift as entries are removed); a send entry that stays after it ran (it would send
the same value again at the next wait).
&lt;strong&gt;Review with the user:&lt;/strong&gt; the &lt;code&gt;Selector&lt;/code&gt; surface (its name, keys over indices, &lt;code&gt;receive&lt;/code&gt;
answering the entry, a send entry taken out once it ran), and whether &lt;code&gt;select&lt;/code&gt; should gain a
&lt;code&gt;for&lt;/code&gt; arm as sugar over it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;stdin-readiness&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;io.stdin()&lt;/code&gt; is a
&lt;code&gt;Readiness&lt;/code&gt;, any thread may wait on it, and &lt;code&gt;readAvailable(max)&lt;/code&gt; reads only what is there.&lt;/strong&gt;
Source: the &lt;code&gt;stdio-bytes&lt;/code&gt; branch found that the tui package could not move off its own Sysl
binding of descriptor 0 (&lt;code&gt;sysl.io.wait.ready&lt;/code&gt; with a time limit, then a raw read), because
&lt;code&gt;io.stdin()&lt;/code&gt; had no timed wait and bytes in the runtime’s shared buffer would never show as the
descriptor’s readiness; any interactive program (a TUI, a REPL, a language server with timers)
needs standard input in one wait with channels and timers. Details settled: (1) &lt;strong&gt;Ready&lt;/strong&gt; means
bytes are in the shared buffer (a &lt;code&gt;readLine&lt;/code&gt;‘s read-ahead among them), the input has ended or
failed, standard input is a file (whose read never waits), or descriptor 0 polls readable;
&lt;code&gt;readable()&lt;/code&gt; never waits, and answers &lt;code&gt;false&lt;/code&gt; while another thread holds the input lock.
(2) &lt;strong&gt;Ownership: none.&lt;/strong&gt; Standard input is process-global, so any thread may name it in a
select or a &lt;code&gt;Selector&lt;/code&gt;, and several at once; a connection keeps its owner rule. (3) &lt;strong&gt;The lock&lt;/strong&gt;:
a select never takes &lt;code&gt;input_readers&lt;/code&gt; to wait. Every select arm on standard input is enlisted on
a runtime queue (&lt;code&gt;input_changed&lt;/code&gt;) that every reader notifies as it lets the lock go, so bytes
another thread’s &lt;code&gt;readLine&lt;/code&gt; left in the buffer end the wait; one select at a time watches
descriptor 0 on the poller (which holds one waiter per descriptor and direction), and hands the
watch on, waking the others, when its wait ends; a reader parked on descriptor 0 takes the
watch’s place and tells the selects when it lets go. The library is unchanged: the runtime’s
&lt;code&gt;select_watch&lt;/code&gt; takes descriptor 0 by this path. (4) &lt;strong&gt;&lt;code&gt;readAvailable(max) -&amp;gt; Result[Option[Array[byte]], IoError]&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;Some&lt;/code&gt; of what &lt;code&gt;read(max)&lt;/code&gt; would answer without
waiting, an empty array at the end, &lt;code&gt;None&lt;/code&gt; where a read would wait or another thread is
reading; it is a method of &lt;code&gt;StandardInputBytes&lt;/code&gt;, not of &lt;code&gt;Reader&lt;/code&gt;. WHY: one wait path for every
source; the queue closes the one gap readiness on the descriptor alone leaves (bytes already
buffered) without polling; &lt;code&gt;Option&lt;/code&gt; keeps “nothing yet” apart from “ended”, which a TUI must
tell apart. ALTERNATIVES: only the thread that first waits on standard input may wait on it,
trapping others (a rule a program could not see, for a resource that has no owner); taking the
input lock to look (a select would then wait behind a thread parked in &lt;code&gt;readLine&lt;/code&gt;, past its
&lt;code&gt;after&lt;/code&gt;); a select re-trying standard input on a timer (&lt;code&gt;wakeAt&lt;/code&gt;) while another thread reads
(polling, and a delay); &lt;code&gt;readAvailable&lt;/code&gt; answering an empty array for both “nothing yet” and the
end (ambiguous); &lt;code&gt;readSome&lt;/code&gt;/&lt;code&gt;readAvailable&lt;/code&gt; on the &lt;code&gt;Reader&lt;/code&gt; trait (every reader would owe it,
and files and connections have no use for it yet). tui switched in its branch &lt;code&gt;stdin-api&lt;/code&gt;.
&lt;strong&gt;Review with the user:&lt;/strong&gt; the name &lt;code&gt;readAvailable&lt;/code&gt; and its &lt;code&gt;Option&lt;/code&gt; answer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (the user asked for the change, branch
&lt;code&gt;method-chain&lt;/code&gt;): &lt;strong&gt;a comparison chain’s links may call operator methods; a chain is allowed when
every link yields &lt;code&gt;bool&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;lo &amp;lt;= x &amp;lt; hi&lt;/code&gt; with &lt;code&gt;x&lt;/code&gt;‘s type defining &lt;code&gt;&amp;lt;=&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; as methods is one
chain, as it is for built-in comparisons, and links of methods mix with built-in links, &lt;code&gt;==&lt;/code&gt; and
&lt;code&gt;!=&lt;/code&gt; among them. The chain keeps its meaning: operands are evaluated left to right, each middle
operand exactly once, and evaluation stops at the first false link. Each link resolves on its own
left operand’s type, so overloads are chosen per link (&lt;code&gt;t0 &amp;lt; t &amp;lt;= d&lt;/code&gt; calls &lt;code&gt;Instant &amp;lt; Instant&lt;/code&gt;
and then &lt;code&gt;Instant &amp;lt;= Duration&lt;/code&gt;). A link whose method yields anything but &lt;code&gt;bool&lt;/code&gt; (a query builder’s
&lt;code&gt;age &amp;lt; 30&lt;/code&gt; yielding a condition) makes the chain an error naming the link, its method and the type
it yields, and saying to join the comparisons with &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or parenthesize one; &lt;code&gt;a &amp;lt; b&lt;/code&gt; alone still
yields whatever the method yields. The compiler lowers a method link through the chain’s one
lowering: the checker records the link’s resolved call on two unnamed locals, and the chain
gives them the operands’ values it already holds. Why: chains read as the mathematics they
write, and the house style asks for them wherever possible; the earlier rule’s reason, that a
method may yield anything, is kept exactly where it applies, a link that does not yield &lt;code&gt;bool&lt;/code&gt;.
Alternatives weighed: keeping the error (forces &lt;code&gt;lo &amp;lt;= x &amp;amp;&amp;amp; x &amp;lt; hi&lt;/code&gt; on types with methods only);
allowing any result type and joining links with the result’s own &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (no single meaning for
short-circuiting, and a condition builder’s &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; is a method too); desugaring method chains into
nested &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; blocks in the checker (a second lowering of chains to keep in step with the first).
Amends “the arithmetic operators … are free method names” above.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (built on branch &lt;code&gt;machine-conditions&lt;/code&gt;): &lt;strong&gt;the choices
&lt;a href=&quot;/spec/packages/#machines&quot;&gt;machines&lt;/a&gt; left open in the manifest.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A feature that does not exist on a machine turns nothing on there&lt;/strong&gt;, even when a feature that
does exist &lt;code&gt;enables&lt;/code&gt; it: the selection leaves it out, and what only it would turn on stays off.
A feature that &lt;code&gt;requires&lt;/code&gt; it is refused there as requiring a feature that is off. WHY: “does not
exist” means the same whichever way the feature is reached; turning its modules on through
another feature would make it exist after all. ALTERNATIVES: refusing a feature that enables an
absent one (makes a cross-machine package spell its enables twice); taking it through &lt;code&gt;enables&lt;/code&gt;
anyway (contradicts its &lt;code&gt;if&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;targets = []&lt;/code&gt; is refused&lt;/strong&gt;; a package builds for at least one target. WHY: an empty list is
a package nothing can build, and is more likely a slip than an intent. ALTERNATIVES: reading it
as every target (the opposite of what it says).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Whether a dependency “reaches further” is asked over the dependent’s targets where the entry’s
condition holds&lt;/strong&gt;, so &lt;code&gt;lib { …, if = &amp;quot;macos&amp;quot; }&lt;/code&gt; may name a package that builds only for
&lt;code&gt;aarch64-macos&lt;/code&gt;. The check runs whatever machine the build is for, against the manifests.
WHY: an entry the condition leaves out is not in those machines’ builds at all.
ALTERNATIVES: refusing on every target of the dependent (forces &lt;code&gt;targets&lt;/code&gt; where &lt;code&gt;if&lt;/code&gt; already says
it).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A whole workspace resolved for a machine is the members that build for it&lt;/strong&gt;, so &lt;code&gt;avin tidy&lt;/code&gt;
and &lt;code&gt;avin vendor&lt;/code&gt; of a workspace answer each target with the members that list it. A
workspace’s root, and a package listing no &lt;code&gt;targets&lt;/code&gt;, answer for every target. WHY: a member
built for Linux alone has nothing to resolve on macOS. ALTERNATIVES: refusing the workspace on
the machines some member leaves out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;link-flags&lt;/code&gt; are passed exactly as written, in order, with no flag merged with another&lt;/strong&gt;, after
the flags of &lt;code&gt;pkg-config&lt;/code&gt; or &lt;code&gt;link&lt;/code&gt;. WHY: the spec’s “as written”; &lt;code&gt;-framework&lt;/code&gt; repeated before
two frameworks must stay two pairs. ALTERNATIVES: removing repeats (breaks &lt;code&gt;-framework&lt;/code&gt; pairs).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;c-linking&lt;/code&gt;‘s &lt;code&gt;static&lt;/code&gt; and &lt;code&gt;dynamic&lt;/code&gt; may name a C library the machine leaves out&lt;/strong&gt;, which does
nothing there: a library of a package in the build whose &lt;code&gt;if&lt;/code&gt; does not hold, or,
&lt;code&gt;&amp;lt;package&amp;gt;/&amp;lt;library&amp;gt;&lt;/code&gt;, a library of a dependency whose &lt;code&gt;if&lt;/code&gt; leaves it out, named by the
dependency’s label (its libraries are not read on that machine, so an unqualified name of one is
still refused there). A name that is no library at all is refused on every machine.
&lt;code&gt;static-system&lt;/code&gt;‘s checks stay per machine. WHY: one program manifest serves every target, so a
name meant for one machine must not fail the others, while a typo still fails everywhere.
ALTERNATIVES: an &lt;code&gt;if&lt;/code&gt; on &lt;code&gt;c-linking&lt;/code&gt;‘s entries (a second place to say what the library’s own
&lt;code&gt;if&lt;/code&gt; already says); resolving every target to check each name (a build would resolve three
times).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;--target&lt;/code&gt; is taken by &lt;code&gt;avin check&lt;/code&gt; alone&lt;/strong&gt; for now, reading every manifest as that machine’s
build does; &lt;code&gt;avin build --target&lt;/code&gt; is the cross-build item. WHY: checking builds nothing, so it
needs no other machine’s tools. ALTERNATIVES: every command (a build for another machine needs
a sysroot Sysl does not have yet).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A condition’s syntax errors&lt;/strong&gt; name the condition and what is wrong at the place: a symbol,
&lt;code&gt;!&lt;/code&gt; or &lt;code&gt;(&lt;/code&gt; wanted (at the end or where a character stands), a &lt;code&gt;(&lt;/code&gt; never closed, or a word
following a whole condition; symbols are lowercase and &lt;code&gt;-&lt;/code&gt; belongs to a word, so a target’s name
is read whole and refused with the condition it means. WHY: one place and one sentence per
mistake, as the manifest’s other errors give. ALTERNATIVES: one generic “not a condition” error.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (built on branch &lt;code&gt;machine-files&lt;/code&gt;): &lt;strong&gt;the choices
&lt;a href=&quot;/spec/packages/#files-for-one-machine&quot;&gt;files for one machine&lt;/a&gt; and
&lt;a href=&quot;/spec/packages/#the-machine-in-an-expression&quot;&gt;the machine in an expression&lt;/a&gt; left open.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A literate file is selected as an ordinary one&lt;/strong&gt; (&lt;code&gt;watch.linux.lavin&lt;/code&gt;), and &lt;strong&gt;a file’s name
carries one symbol&lt;/strong&gt;: two parts (&lt;code&gt;watch.linux.x86_64.avin&lt;/code&gt;) are refused, naming each, as is a
part that is no symbol, on every machine, in a package, a program with no manifest, a dependency
and the standard library alike. A file named as a symbol alone (&lt;code&gt;linux.avin&lt;/code&gt;) is ordinary. WHY:
the spec’s “the part is one symbol”; a &lt;code&gt;.lavin&lt;/code&gt; file is a module’s file like any other.
ALTERNATIVES: a compound part as &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; of its symbols (a second condition syntax in file names);
leaving &lt;code&gt;.lavin&lt;/code&gt; unselected (a literate module could not differ by machine).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A program of one file is never selected&lt;/strong&gt;: &lt;code&gt;avin run tool.linux.avin&lt;/code&gt; runs it anywhere. WHY:
the file is named outright, so there is nothing to choose between. ALTERNATIVES: refusing it off
Linux (a script would fail for its name).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The import rule asks, for each file read on this machine, every target its root lists that
reads the file&lt;/strong&gt;, each target’s package read as its build reads it (resolving, and fetching what
the cache lacks, a dependency taken only there). A target whose package cannot be read holds no
file to anything in a build, and &lt;code&gt;avin check&lt;/code&gt; reports it. “No more widely” is by machine: a file
for &lt;code&gt;x86_64&lt;/code&gt; may import Linux’s module. A module whose files differ per machine but exist on every
machine is imported from anywhere. The rule is checked only where anything differs (a file with a
symbol, a manifest entry with &lt;code&gt;if&lt;/code&gt;), so other packages cost nothing more. Standard library modules
are not held to it, since none is missing on any machine. WHY: the spec’s “for every machine in
&lt;code&gt;targets&lt;/code&gt;, whichever one is being built”; a dependency’s module names are known only by reading
it. ALTERNATIVES: mapping an import to a dependency’s label without reading it (a module’s name
need not be its package’s); checking only in &lt;code&gt;avin check&lt;/code&gt; (a build would accept what another
machine’s build refuses). &lt;strong&gt;Review with the user:&lt;/strong&gt; whether a build may fetch a dependency only
another machine takes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The import’s error names the module, its package where it is another’s, the machines it exists
on and its files there, the importing file and the machines it is missing on&lt;/strong&gt;, and it is the only
error at that import (the “standard library’s module is meant” hint is not added beside it).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin check&lt;/code&gt; checks once per set of targets that read the package alike&lt;/strong&gt; (the same files,
from the same packages), in the order &lt;code&gt;targets&lt;/code&gt; lists them; with nothing differing it checks the
machine being built for, as before, including refusing a host the package leaves out. A diagnostic
every check reports is told once, as it is; one some report gets &lt;code&gt;(on&lt;/code&gt;x86_64-linux&lt;code&gt;and&lt;/code&gt;aarch64-linux&lt;code&gt;)&lt;/code&gt; after its message; a name that a file of the same module read on another machine
declares is told as the spec’s &lt;code&gt;no function &lt;/code&gt;start&lt;code&gt; is declared in … on …&lt;/code&gt; (also &lt;code&gt;no value&lt;/code&gt;,
&lt;code&gt;no type&lt;/code&gt;). A machine whose package cannot be read is told as &lt;code&gt;on &lt;/code&gt;…&lt;code&gt;:&lt;/code&gt; and its error. The C unit
is built only for the machine the compiler runs on. WHY: one sentence per mistake with the
machines it is for, and no other machine’s tools. ALTERNATIVES: a check per target always (the
arch-only difference of &lt;code&gt;avin.target&lt;/code&gt; would check every package three times); a prefix
&lt;code&gt;on &lt;/code&gt;…&lt;code&gt;: &lt;/code&gt; on every machine-specific diagnostic (moves the headline off what is wrong).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;avin.target&lt;/code&gt;‘s values are declared in the library by its own files&lt;/strong&gt; (&lt;code&gt;target.macos.avin&lt;/code&gt;,
&lt;code&gt;target.linux.avin&lt;/code&gt;, &lt;code&gt;target.aarch64.avin&lt;/code&gt;, &lt;code&gt;target.x86_64.avin&lt;/code&gt;), and &lt;strong&gt;folding is a lowering of a
read of a value of &lt;code&gt;avin.target&lt;/code&gt;&lt;/strong&gt;: a &lt;code&gt;match&lt;/code&gt; whose arms up to the taken one are decided by their
patterns (variants, alternatives, &lt;code&gt;_&lt;/code&gt;, names) compiles that arm alone; an &lt;code&gt;is&lt;/code&gt; test against a
variant and &lt;code&gt;==&lt;/code&gt;/&lt;code&gt;!=&lt;/code&gt; with a variant or the other value are decided and fold the &lt;code&gt;if&lt;/code&gt; or the
left of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;/&lt;code&gt;||&lt;/code&gt; over them, as an &lt;code&gt;is&lt;/code&gt; test a pattern refutes already does. A guard before the
taken arm keeps the whole &lt;code&gt;match&lt;/code&gt;. WHY: the values are ordinary declarations checked like any
other, and folding reuses the decided-condition path. ALTERNATIVES: a compiler intrinsic for
&lt;code&gt;os&lt;/code&gt; and &lt;code&gt;arch&lt;/code&gt; (a second way to make a value per machine); folding every compile-time constant
(changes the code of every program reading a constant, beyond what was decided).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The language server checks the files of the machine it runs on&lt;/strong&gt;, so a file for another machine
open in an editor is not analyzed as part of its package. A later item may check it for a machine
that reads it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;bounded-mailbox&lt;/code&gt;): &lt;strong&gt;A mailbox may be bounded,
given as &lt;code&gt;spawn(b, mailbox = Bounded(capacity, overflow))&lt;/code&gt;; a &lt;code&gt;tell&lt;/code&gt; to a full one drops by the
actor’s &lt;code&gt;Overflow&lt;/code&gt;, and senders that must know or wait use &lt;code&gt;offer&lt;/code&gt; and &lt;code&gt;send&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;data Mailbox&lt;/code&gt; is
&lt;code&gt;Unbounded&lt;/code&gt; (the default) or &lt;code&gt;Bounded(capacity: int, overflow: Overflow)&lt;/code&gt;, &lt;code&gt;Overflow&lt;/code&gt; being
&lt;code&gt;DropNewest&lt;/code&gt; or &lt;code&gt;DropOldest&lt;/code&gt;; a capacity less than one traps in &lt;code&gt;spawn&lt;/code&gt;. &lt;code&gt;tell&lt;/code&gt; keeps its settled
promise, never waiting and never failing, and drops as the policy says, counted by
&lt;code&gt;ref.dropped() -&amp;gt; long&lt;/code&gt;. &lt;code&gt;offer(m) -&amp;gt; Result[unit, SendError]&lt;/code&gt; never waits and answers &lt;code&gt;Err(Full)&lt;/code&gt;;
&lt;code&gt;send(m)&lt;/code&gt; and &lt;code&gt;send(m, timeout)&lt;/code&gt; park the sending thread until there is room (a timed one answering
&lt;code&gt;Err(TimedOut)&lt;/code&gt;, a timeout of zero or less being &lt;code&gt;offer&lt;/code&gt;), as a cancellation point that leaves
nothing in the mailbox, waking with &lt;code&gt;Err(Ended)&lt;/code&gt; where the actor ends; an actor’s &lt;code&gt;send&lt;/code&gt; to its own
full mailbox answers &lt;code&gt;Err(Full)&lt;/code&gt; at once. &lt;code&gt;SendError&lt;/code&gt; is &lt;code&gt;Full&lt;/code&gt;, &lt;code&gt;TimedOut&lt;/code&gt; or &lt;code&gt;Ended&lt;/code&gt;; &lt;code&gt;AskError&lt;/code&gt;
gains &lt;code&gt;Full&lt;/code&gt;, and an ask of a full mailbox completes with it at once under either policy, dropping
nothing to make room. What the actor arranged for itself (a watch’s notice, a timer’s message, a
piped future’s) goes in outside the bound and is never refused, and stop, restart and escalation
are not messages, so no bound holds them back; a restart keeps the mailbox and its bound; messages a
stash gives back do not count again. &lt;code&gt;Router.pool(…, mailbox)&lt;/code&gt; bounds the router’s mailbox and each
routee’s at one capacity, and the router waits for room in the routee it chose (&lt;code&gt;SmallestMailbox&lt;/code&gt;
only once every routee is full), so a full pool’s backpressure reaches the router’s own mailbox,
where the policy and &lt;code&gt;offer&lt;/code&gt;/&lt;code&gt;send&lt;/code&gt; act. A bounded mailbox is a queue under a lock, so the oldest
message may be dropped and senders may wait on a condition; unbounded actors keep the lock-free
queue and pay nothing. &lt;em&gt;Why&lt;/em&gt;: the bound is a property of the actor, chosen where it is started, as
its supervision and executor are; separating the sender’s choice (&lt;code&gt;tell&lt;/code&gt; fire-and-forget, &lt;code&gt;offer&lt;/code&gt;
to know, &lt;code&gt;send&lt;/code&gt; to wait) from the actor’s policy keeps &lt;code&gt;tell&lt;/code&gt;‘s settled meaning and gives every
program its backpressure path (marshal’s queues, a pg pool) with no new wait inside &lt;code&gt;tell&lt;/code&gt;; an ask
that cannot be delivered answering at once is what &lt;code&gt;Ended&lt;/code&gt; already does. &lt;em&gt;Alternatives weighed&lt;/em&gt;:
a capacity and policy on &lt;code&gt;Behaviour&lt;/code&gt; or the &lt;code&gt;actor&lt;/code&gt; declaration (the same actor wants different
bounds in different places); a third policy that fails the &lt;code&gt;tell&lt;/code&gt; (&lt;code&gt;tell&lt;/code&gt; answers nothing, so the
failure would be a trap in the sender for the receiver’s slowness); a &lt;code&gt;tell&lt;/code&gt; that waits (breaks the
settled rule, and deadlocks two actors telling each other); &lt;code&gt;offer&lt;/code&gt; answering a &lt;code&gt;bool&lt;/code&gt; (cannot tell
&lt;code&gt;Full&lt;/code&gt; from &lt;code&gt;Ended&lt;/code&gt;); &lt;code&gt;send&lt;/code&gt; as a &lt;code&gt;Future&lt;/code&gt; (the message would still be delivered after its awaiter
was cancelled); a dead-letters hook called with each dropped message (needs a typed callback on the
mailbox and runs user code inside the sender’s &lt;code&gt;tell&lt;/code&gt;; a counter is enough to observe overload);
counting the actor’s own notices against the bound (a full mailbox would lose a watch’s notice of
an end); each routee bounded but the router not (a full pool would make the router drop or block
with no policy of the caller’s); a bounded lock-free ring (cannot drop the oldest without the
actor’s help, and would cap the actor’s own notices too). &lt;strong&gt;Review with the user:&lt;/strong&gt; the overflow
surface (two policies, the policy always written out with no default, no failing policy), the names &lt;code&gt;offer&lt;/code&gt;,
&lt;code&gt;send&lt;/code&gt; and &lt;code&gt;dropped&lt;/code&gt;, and the router’s bound being shared by router and routees.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;lambda-trailing-arg&lt;/code&gt;): &lt;strong&gt;a block’s last line
that closes a bracket opened before the block ends the block at its first comma&lt;/strong&gt;: in
&lt;code&gt;spawn(() -&amp;gt;&lt;/code&gt; … &lt;code&gt;a + f(n), 67108864)&lt;/code&gt; the lambda yields &lt;code&gt;a + f(n)&lt;/code&gt; and &lt;code&gt;67108864&lt;/code&gt; is &lt;code&gt;spawn&lt;/code&gt;‘s
second argument, as on one line. The items after the comma are the bracket’s own (positional or
named arguments, collection elements, map entries); every block opened in the same brackets on the
way (an &lt;code&gt;if&lt;/code&gt;‘s or &lt;code&gt;match&lt;/code&gt;‘s, an inner lambda’s) ends there too, and a trailing block the line itself
opens and closes is stepped over. A tuple the block yields on that line is written in parentheses,
&lt;code&gt;(a, b))&lt;/code&gt;; a &lt;code&gt;)&lt;/code&gt; on a line of its own, a tuple on an earlier line and &lt;code&gt;a, b = b, a&lt;/code&gt; on an earlier
line are unchanged. Why: the block’s lines read the trailing items as a tuple the block yields, so
the call silently lost its argument (the thread got the default stack and yielded a tuple), and the
spec’s “a block inside brackets starts a line again” said nothing about the line that leaves the
brackets; the rule makes the multi-line form mean what the one-line form means, as the
&lt;code&gt;match&lt;/code&gt;-arm rule of 2026-11-15 (“inside brackets a comma ends a &lt;code&gt;match&lt;/code&gt; arm’s one-line body”) did
for arms. Alternatives: an error for an unparenthesized tuple on such a
line, asking for parentheses either way (safe, but rejects the natural way to write a trailing
argument); keeping the tuple (silent wrong code). It changes code that compiled before; a scan of
every &lt;code&gt;.avin&lt;/code&gt; file in the avin-lang repos found none relying on the old reading, and code that did
now fails to compile (an argument count or a lambda’s type). &lt;strong&gt;Review with the user&lt;/strong&gt;: it changes
the meaning of code that compiled before.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;link-control&lt;/code&gt;; the user: &lt;em&gt;“It should be as
flexible as possible. Avin isn’t just for me, it’s for anyone who would enjoy using it.”&lt;/em&gt;): &lt;strong&gt;a
program chooses how each C library is linked in its root manifest’s &lt;code&gt;c-linking&lt;/code&gt; block, and a C
library’s own block says what else links it&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/#how-a-program-links-its-c-libraries&quot;&gt;C
bindings&lt;/a&gt;). The program’s block holds
&lt;code&gt;default&lt;/code&gt; (&lt;code&gt;&amp;quot;static&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;dynamic&amp;quot;&lt;/code&gt;), &lt;code&gt;static&lt;/code&gt; and &lt;code&gt;dynamic&lt;/code&gt; lists of libraries (&lt;code&gt;&amp;lt;library&amp;gt;&lt;/code&gt; or
&lt;code&gt;&amp;lt;package&amp;gt;/&amp;lt;library&amp;gt;&lt;/code&gt;), &lt;code&gt;static-system&lt;/code&gt; (&lt;code&gt;-l&lt;/code&gt; names the system provides, linked from their archives)
and &lt;code&gt;search&lt;/code&gt; (where those archives are, absolute or root-relative). &lt;code&gt;static-c-libraries = true&lt;/code&gt;
keeps its meaning as the shorthand of &lt;code&gt;default = &amp;quot;static&amp;quot;&lt;/code&gt;; saying both is an error, so nothing
that builds today changes. A C library gains &lt;code&gt;files&lt;/code&gt; (archives and shared libraries by path),
&lt;code&gt;search&lt;/code&gt; (&lt;code&gt;-L&lt;/code&gt; directories, searched for archives when static), &lt;code&gt;include&lt;/code&gt; (&lt;code&gt;-I&lt;/code&gt; directories, since a
vendored library’s headers are not where &lt;code&gt;pkg-config&lt;/code&gt; would say), &lt;code&gt;frameworks&lt;/code&gt; and &lt;code&gt;link-flags&lt;/code&gt;
(raw, the escape hatch); their paths are relative to the package and may not be absolute or hold a
&lt;code&gt;..&lt;/code&gt; segment, so a fetched package builds wherever it lands. &lt;strong&gt;Static is a promise, dynamic is “as
named”&lt;/strong&gt;: a library linked statically takes no shared library from a search directory (an error
names the missing archive, as before, now for &lt;code&gt;link&lt;/code&gt; names and &lt;code&gt;files&lt;/code&gt; too), while one linked
dynamically is linked from the flags as given, so a vendored &lt;code&gt;.a&lt;/code&gt; is static either way. &lt;em&gt;Why one
block&lt;/em&gt;: one place says how the program links, and a &lt;code&gt;static&lt;/code&gt;/&lt;code&gt;dynamic&lt;/code&gt; pair reads as the program’s
sentence (“all static except mlt”). &lt;em&gt;Alternatives weighed&lt;/em&gt;: a per-library &lt;code&gt;static = true&lt;/code&gt; in the
library’s block (the author would decide for every program; refused before and still refused, its
test kept); per-library keys inside the program’s own &lt;code&gt;dependencies&lt;/code&gt; entries (a library of a
dependency’s dependency has no entry to put it in); a top-level &lt;code&gt;link&lt;/code&gt; key as Sysl writes it (reads
as one key with the &lt;code&gt;-l&lt;/code&gt; meaning of a library’s &lt;code&gt;link&lt;/code&gt;); &lt;code&gt;static-c-libraries&lt;/code&gt; taking a list (one key
with two types, and no room for &lt;code&gt;dynamic&lt;/code&gt;). &lt;strong&gt;The command line&lt;/strong&gt; (&lt;code&gt;--static-c-libraries&lt;/code&gt;,
&lt;code&gt;--dynamic-c-libraries&lt;/code&gt; on build, run, test and check) stands in for the manifest’s default only;
a library the manifest names keeps its way, since such a name usually records a reason (a licence,
a missing archive) a one-off flag should not erase. &lt;em&gt;Alternative&lt;/em&gt;: the flag overruling everything
(simpler to state, but &lt;code&gt;--static-c-libraries&lt;/code&gt; would then trip over every &lt;code&gt;dynamic-only&lt;/code&gt; library
the program had already answered for). A cached &lt;code&gt;run&lt;/code&gt;/&lt;code&gt;test&lt;/code&gt; build is keyed by how each library is
linked and by its files, which also fixed the cache reusing a static build after the manifest
changed. &lt;strong&gt;A library package may say &lt;code&gt;dynamic-only = &amp;quot;&amp;lt;why&amp;gt;&amp;quot;&lt;/code&gt;&lt;/strong&gt;, one key for both “must be dynamic”
(licence) and “has no archive”: both mean the same to a build and differ only in the reason, which
the error quotes. A program that would link it statically, by its default, the flag or its
&lt;code&gt;static&lt;/code&gt; list, is refused with that reason and told to name it in &lt;code&gt;dynamic&lt;/code&gt;; it is never made
dynamic silently, because a program asking to be static would then ship needing the library
installed. &lt;em&gt;Alternatives&lt;/em&gt;: the requirement silently winning over the program’s default (quiet,
and breaks the static promise); a requirement the program could override by &lt;code&gt;static&lt;/code&gt; (a licence
is not the program’s to waive); two keys, &lt;code&gt;dynamic-only&lt;/code&gt; and &lt;code&gt;no-archive&lt;/code&gt; (two names for one
effect). &lt;strong&gt;System libraries stay dynamic unless &lt;code&gt;static-system&lt;/code&gt; names them&lt;/strong&gt;; a named one with no
archive in the searched directories, or named but linked by no library, is an error. &lt;strong&gt;On Linux&lt;/strong&gt;
(not built yet) an archive is still linked by its path; a &lt;code&gt;-l&lt;/code&gt; kept dynamic stays &lt;code&gt;-l&lt;/code&gt;; a
&lt;code&gt;static-system&lt;/code&gt; name maps onto &lt;code&gt;-Wl,-Bstatic -l&amp;lt;name&amp;gt; -Wl,-Bdynamic&lt;/code&gt;; &lt;code&gt;frameworks&lt;/code&gt; are macOS’s.
A package’s vendored C sources are compiled by the library’s &lt;code&gt;sources&lt;/code&gt; (the next entry); &lt;code&gt;files&lt;/code&gt;
links a prebuilt archive. &lt;strong&gt;Review with the user&lt;/strong&gt;: the surface syntax (&lt;code&gt;c-linking&lt;/code&gt; and its five keys,
&lt;code&gt;&amp;lt;package&amp;gt;/&amp;lt;library&amp;gt;&lt;/code&gt; naming, the library keys &lt;code&gt;files&lt;/code&gt;/&lt;code&gt;search&lt;/code&gt;/&lt;code&gt;include&lt;/code&gt;/&lt;code&gt;frameworks&lt;/code&gt;/&lt;code&gt;link-flags&lt;/code&gt;,
the two flags’ names), and the library-requirement rule (&lt;code&gt;dynamic-only&lt;/code&gt; refusing a static program
rather than yielding to it, and the program’s &lt;code&gt;static&lt;/code&gt; list not overriding it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;c-sources&lt;/code&gt;; the gap is link-control’s report:
a package could link a prebuilt archive by &lt;code&gt;files&lt;/code&gt; but not compile the &lt;code&gt;.c&lt;/code&gt; files it ships, so a
binding of a library distributed as source, sqlite3.c, miniz or stb, needed its user to build an
archive for each machine; only a Sysl dependency’s own &lt;code&gt;.c&lt;/code&gt; was compiled, by Sysl): &lt;strong&gt;a C library
names the C files its package ships in &lt;code&gt;sources&lt;/code&gt;, and the flags they are compiled with in
&lt;code&gt;cflags&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/#c-sources-a-package-ships&quot;&gt;C bindings&lt;/a&gt;). &lt;code&gt;sources&lt;/code&gt; are paths relative
to the package, under the rules of &lt;code&gt;files&lt;/code&gt; (no absolute path, no &lt;code&gt;..&lt;/code&gt; segment), and a &lt;code&gt;*&lt;/code&gt; matches
within one directory, as a workspace’s members do; &lt;code&gt;**&lt;/code&gt; is refused, a pattern matching no file
and a path that is not there are errors, and the matches are sorted and each file taken once.
They are compiled by the clang the C unit is compiled with, for the build’s machine, with &lt;code&gt;-O2&lt;/code&gt;
unless &lt;code&gt;cflags&lt;/code&gt; names a level (whatever the program’s own &lt;code&gt;-O&lt;/code&gt;, so &lt;code&gt;-O0&lt;/code&gt; and &lt;code&gt;-O2&lt;/code&gt; builds share
the objects), the library’s &lt;code&gt;include&lt;/code&gt; directories as &lt;code&gt;-I&lt;/code&gt;, the &lt;code&gt;--cflags&lt;/code&gt; of its &lt;code&gt;pkg-config&lt;/code&gt;
module, then &lt;code&gt;cflags&lt;/code&gt;, last. &lt;strong&gt;&lt;code&gt;cflags&lt;/code&gt; holds what a package says about its C and nothing about the
build&lt;/strong&gt;: defines (&lt;code&gt;-D&lt;/code&gt;, &lt;code&gt;-U&lt;/code&gt;), an optimization level (&lt;code&gt;-O&lt;/code&gt;), warnings (&lt;code&gt;-W&lt;/code&gt;, &lt;code&gt;-w&lt;/code&gt;, &lt;code&gt;-pedantic&lt;/code&gt;), the
standard (&lt;code&gt;-std=&lt;/code&gt;) and code generation (&lt;code&gt;-f&lt;/code&gt;). &lt;code&gt;-I&lt;/code&gt; and its kin are refused with a pointer at
&lt;code&gt;include&lt;/code&gt;, &lt;code&gt;-Wl,&lt;/code&gt;/&lt;code&gt;-Wa,&lt;/code&gt;/&lt;code&gt;-Wp,&lt;/code&gt; with a pointer at &lt;code&gt;link-flags&lt;/code&gt;, and anything else (the target, the
output, &lt;code&gt;-l&lt;/code&gt;, &lt;code&gt;-g&lt;/code&gt;) as not a package’s to say; &lt;code&gt;cflags&lt;/code&gt; with no &lt;code&gt;sources&lt;/code&gt; is an error, since it
would read as flags of the C unit, which it is not. The objects are linked into the program before
the libraries’ link flags, &lt;strong&gt;statically, always&lt;/strong&gt;, whatever &lt;code&gt;c-linking&lt;/code&gt;, the command line or
&lt;code&gt;static-c-libraries&lt;/code&gt; say of the library: they are part of the program. So &lt;strong&gt;&lt;code&gt;dynamic-only&lt;/code&gt; beside
&lt;code&gt;sources&lt;/code&gt; is an error at the entry&lt;/strong&gt;, and &lt;code&gt;pkg-config&lt;/code&gt; or &lt;code&gt;link&lt;/code&gt; beside &lt;code&gt;sources&lt;/code&gt; are allowed (a
wrapper compiled against an installed library, a source calling libz). &lt;strong&gt;The cache&lt;/strong&gt;: each object
is kept in &lt;code&gt;csources/&lt;/code&gt; by a key over the source’s text, its flags (an &lt;code&gt;include&lt;/code&gt; directory read as
the package writes it, so a package keys alike wherever it is fetched), the target, the compiler’s
version and &lt;code&gt;clang --version&lt;/code&gt;, and the path (package-relative where inside it) and text of every
header it includes, which clang lists (&lt;code&gt;-MD&lt;/code&gt;) when it compiles and a record keeps; a source with no
record is scanned with &lt;code&gt;clang -M&lt;/code&gt; first, so two packages shipping the same file compile it once
and link it once. &lt;code&gt;avin run&lt;/code&gt;‘s cached executables are keyed by each source’s and recorded header’s
modification time. &lt;strong&gt;The clangs run at once, one per processor at most&lt;/strong&gt;: Avin has no job count of
its own, and this is the bound codegen units already keep. &lt;strong&gt;A source clang refuses&lt;/strong&gt; is reported
as &lt;code&gt;error: the source &lt;/code&gt;&lt;path&gt;&lt;code&gt;of the C library&lt;/code&gt;&lt;l&gt;&lt;code&gt;of package&lt;/code&gt;&lt;p&gt;&lt;code&gt; does not compile:&lt;/code&gt; followed
by clang’s own output, which names the file and the line; warnings of a source that compiles are
not shown (a vendored library’s warnings are its maintainers’; &lt;code&gt;-Werror&lt;/code&gt; makes them errors).
&lt;strong&gt;&lt;code&gt;avin check&lt;/code&gt; does not compile the sources&lt;/strong&gt;; it checks each is there and each pattern matches,
as it checks &lt;code&gt;files&lt;/code&gt;. &lt;strong&gt;Per-machine sources are entries with an &lt;code&gt;if&lt;/code&gt;&lt;/strong&gt;: a library whose sources
differ by machine is written as one entry for what is common and one per machine (&lt;code&gt;vend-macos { if = &amp;quot;macos&amp;quot;, sources = [...] }&lt;/code&gt;), using the conditions every entry already takes, rather than a
condition inside &lt;code&gt;sources&lt;/code&gt;. &lt;strong&gt;A header-only library needs nothing new&lt;/strong&gt;: its package ships the
one-line &lt;code&gt;.c&lt;/code&gt; that asks for its implementation (&lt;code&gt;#define STB_IMAGE_IMPLEMENTATION&lt;/code&gt; then the
include) and names it in &lt;code&gt;sources&lt;/code&gt;. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a top-level &lt;code&gt;c-sources&lt;/code&gt; block apart
from &lt;code&gt;c-libraries&lt;/code&gt; (the sources belong to the library whose headers and &lt;code&gt;include&lt;/code&gt; they share, and
a second block would repeat them); &lt;code&gt;cflags&lt;/code&gt; passing anything (a package could then name a target
or an output and break the build’s own choices); &lt;code&gt;-I&lt;/code&gt; allowed in &lt;code&gt;cflags&lt;/code&gt; (two ways to say
&lt;code&gt;include&lt;/code&gt;, one of them able to name an absolute path); the program’s &lt;code&gt;-O&lt;/code&gt; level (debug builds of
the program would rebuild and slow every vendored library, which is not what is being debugged);
conditions inside &lt;code&gt;sources&lt;/code&gt; (&lt;code&gt;sources { macos = [...] }&lt;/code&gt;, a second condition syntax where &lt;code&gt;if&lt;/code&gt;
already serves); keying objects by the source alone (an edited header would be missed) or by its
preprocessed text (a preprocessing on every build, even when nothing changed); a shared library
built from the sources (they are the program’s, and a static object needs no install). &lt;strong&gt;Review
with the user&lt;/strong&gt;: the key names &lt;code&gt;sources&lt;/code&gt; and &lt;code&gt;cflags&lt;/code&gt;, which flags &lt;code&gt;cflags&lt;/code&gt; allows, the default
&lt;code&gt;-O2&lt;/code&gt; independent of the program’s level, and silencing warnings of sources that compile.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;target-keys&lt;/code&gt;): &lt;strong&gt;every cache entry names the
machine it was built for, in its name and in its key&lt;/strong&gt;. A toolchain has a &lt;code&gt;target&lt;/code&gt; (the compiler’s
own machine unless a build names another). Under &lt;code&gt;units/&lt;/code&gt;, &lt;code&gt;shims/&lt;/code&gt;, &lt;code&gt;cunit/&lt;/code&gt; and &lt;code&gt;csources/&lt;/code&gt; an
entry is &lt;code&gt;&amp;lt;target&amp;gt;-&amp;lt;key&amp;gt;&lt;/code&gt;; the runtime archive is &lt;code&gt;libavinrt-&amp;lt;target&amp;gt;-&amp;lt;key&amp;gt;.a&lt;/code&gt;, in the cache and
shipped as &lt;code&gt;share/avin/lib/&amp;lt;target&amp;gt;/libavinrt-&amp;lt;target&amp;gt;-&amp;lt;key&amp;gt;.a&lt;/code&gt;; a program’s directory under
&lt;code&gt;build/&lt;/code&gt; is &lt;code&gt;&amp;lt;name&amp;gt;-&amp;lt;target&amp;gt;-&amp;lt;key&amp;gt;&lt;/code&gt;, which holds its executables and its instance cache; the key
hashed into each entry also holds the target, and an executable’s record does too. Without a cache
directory the compiler’s own machine keeps &lt;code&gt;.avin/build&lt;/code&gt; and another machine uses
&lt;code&gt;.avin/build/&amp;lt;target&amp;gt;&lt;/code&gt;. &lt;code&gt;avin cache info&lt;/code&gt; lists the entries per target and &lt;code&gt;avin cache clean --target &amp;lt;target&amp;gt;&lt;/code&gt; removes one target’s. &lt;strong&gt;Existing caches are not carried over&lt;/strong&gt;: an old entry has
no target in its name, so no build finds it (it is never misread), &lt;code&gt;avin cache info&lt;/code&gt; lists it as
&lt;code&gt;untargeted&lt;/code&gt;, and the least-recently-used sweep removes it, so the first build after the upgrade
rebuilds. &lt;em&gt;Why&lt;/em&gt;: a cross build, or a prefix shipping archives for two machines, must never reuse an
object built for the other, and the name makes the target visible to &lt;code&gt;info&lt;/code&gt; and &lt;code&gt;clean&lt;/code&gt; without
opening a file. &lt;em&gt;Alternatives weighed&lt;/em&gt;: the target in the hash alone (disjoint, but &lt;code&gt;info&lt;/code&gt; and
&lt;code&gt;clean --target&lt;/code&gt; could not tell targets apart); a subdirectory per target in each kind (the sweep
and &lt;code&gt;info&lt;/code&gt; count entries one level down, and a directory would become one entry holding every
object of its target, evicted whole); keeping old names for the compiler’s own machine (a
compatibility rule with no reader once a second machine exists, and the rebuild is one build). The
&lt;code&gt;.avin/build&lt;/code&gt; fallback keeps its path for the compiler’s own machine so existing programs’
directories do not move, which is the one place an old entry stays valid, and its executable
records carry the target so a stale one is rebuilt. &lt;code&gt;avin clean&lt;/code&gt; removes a program’s builds
for every target there, and each target’s directory once it is empty.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;prefix-ops&lt;/code&gt;; the user approved the feature
that day): &lt;strong&gt;a data type, a class or a trait may define the prefix &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; as methods
taking no argument, as it defines &lt;code&gt;-&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/operators-and-control-flow/#operator-methods&quot;&gt;operator methods&lt;/a&gt;).
&lt;code&gt;!a&lt;/code&gt;, &lt;code&gt;~a&lt;/code&gt; and &lt;code&gt;+a&lt;/code&gt; call &lt;code&gt;a&lt;/code&gt;‘s method of that name where its type, or a type parameter’s bound, has
one taking no argument; each yields any type, binds at the prefix level, and is resolved by the one
path the prefix &lt;code&gt;-&lt;/code&gt; already took. Choices this branch made: &lt;strong&gt;a &lt;code&gt;!&lt;/code&gt; yielding something other than
&lt;code&gt;bool&lt;/code&gt; is allowed&lt;/strong&gt;, as a method &lt;code&gt;&amp;lt;&lt;/code&gt; may yield a &lt;code&gt;Cond&lt;/code&gt;, so a query builder’s &lt;code&gt;!cond&lt;/code&gt; is a
condition object. &lt;strong&gt;In a condition (&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, an operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or &lt;code&gt;||&lt;/code&gt;) the &lt;code&gt;!&lt;/code&gt; call must
yield &lt;code&gt;bool&lt;/code&gt;&lt;/strong&gt;, and one that does not is “expected bool, found Cond”, the same message any
non-&lt;code&gt;bool&lt;/code&gt; condition gets; the condition then binds no names, since an &lt;code&gt;is&lt;/code&gt; test is never the
operand of a method &lt;code&gt;!&lt;/code&gt;. &lt;strong&gt;A method &lt;code&gt;!&lt;/code&gt; takes no argument at all&lt;/strong&gt;, a defaulted one included: &lt;code&gt;!&lt;/code&gt;
has no binary form, and an &lt;code&gt;a ! b&lt;/code&gt; reading would be a new infix operator nobody asked for. &lt;code&gt;~&lt;/code&gt; and
&lt;code&gt;+&lt;/code&gt; keep their one-argument overloads for &lt;code&gt;a ~ b&lt;/code&gt; and &lt;code&gt;a + b&lt;/code&gt;. &lt;strong&gt;Generic code reaches them through
a user trait that declares them&lt;/strong&gt; (&lt;code&gt;trait Flip&lt;/code&gt; with &lt;code&gt;!() -&amp;gt; Self&lt;/code&gt;); there is no core trait for
them, since no built-in type’s &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt; is anything generic code over user types needs, and
&lt;code&gt;Neg&lt;/code&gt; stays the only prefix core trait. &lt;strong&gt;Where the type has no such method the operator keeps its
meaning&lt;/strong&gt;: on a data type or a class &lt;code&gt;!a&lt;/code&gt;, &lt;code&gt;~a&lt;/code&gt; and &lt;code&gt;+a&lt;/code&gt; are the errors they were (“expected bool”,
“&lt;code&gt;~&lt;/code&gt; needs an integer or a byte”, “&lt;code&gt;+&lt;/code&gt; needs a number”). &lt;strong&gt;The built-in types stay closed&lt;/strong&gt;: a
method &lt;code&gt;!&lt;/code&gt;, or &lt;code&gt;~&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt; taking no argument, on &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; or
a tuple, in an extension or a trait’s implementation, is an error (“a prefix &lt;code&gt;!&lt;/code&gt; on bool is the
language’s own…”); &lt;code&gt;!&lt;/code&gt; is no longer among the reserved method spellings. &lt;strong&gt;Two prefix operators
written together stay one name&lt;/strong&gt; (&lt;code&gt;!!x&lt;/code&gt; and &lt;code&gt;-~x&lt;/code&gt; are the existing “a symbol method has no prefix
form” error), so nesting is written &lt;code&gt;! !x&lt;/code&gt; and &lt;code&gt;- ~x&lt;/code&gt;, as the operator-run rule already said.
&lt;em&gt;Alternatives weighed&lt;/em&gt;: requiring &lt;code&gt;bool&lt;/code&gt; from every method &lt;code&gt;!&lt;/code&gt; (rules out the query builder the
feature is for); core traits &lt;code&gt;Not&lt;/code&gt;, &lt;code&gt;Complement&lt;/code&gt; and &lt;code&gt;Positive&lt;/code&gt; (no program asks for them, and
each would need an impl for every built-in type); splitting a run of prefix characters such as
&lt;code&gt;!!&lt;/code&gt; into nested operators (it breaks the one longest-run rule the lexer and &lt;code&gt;++&lt;/code&gt;/&lt;code&gt;--&lt;/code&gt; rely on).
&lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;!!x&lt;/code&gt; should read as &lt;code&gt;! !x&lt;/code&gt; without the space.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;collection-apply&lt;/code&gt;): &lt;strong&gt;a collection is made by
naming its type and listing its elements.&lt;/strong&gt; &lt;code&gt;Array(1, 2, 3)&lt;/code&gt; was refused; it now works, as an
ordinary companion &lt;code&gt;apply[T](elements: T*)&lt;/code&gt; in the library (no compiler special case: the
repeated parameter infers &lt;code&gt;T&lt;/code&gt; from the elements, from the expected type, or from type arguments
written at the call, and &lt;code&gt;Array()&lt;/code&gt; with none is the existing “cannot infer” error). Types that
gained the form: &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;LazyList&lt;/code&gt;, the mutable &lt;code&gt;Set&lt;/code&gt; and
&lt;code&gt;LinkedSet&lt;/code&gt;, and &lt;code&gt;PriorityQueue&lt;/code&gt; (by the elements’ own order); &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;,
&lt;code&gt;HashSet&lt;/code&gt;, &lt;code&gt;SortedSet&lt;/code&gt;, &lt;code&gt;SeqSet&lt;/code&gt;, &lt;code&gt;OrderedSet&lt;/code&gt;, &lt;code&gt;TreeSet&lt;/code&gt; (immutable and mutable) and &lt;code&gt;BitSet&lt;/code&gt;
already had it. &lt;code&gt;Array(1, 2.5)&lt;/code&gt; widens to &lt;code&gt;Array[real]&lt;/code&gt;; mismatched types are the ordinary
argument error. A class that keeps fields its own code fills in (&lt;code&gt;LazyList&lt;/code&gt;) no longer offers
its constructor to a call outside that code, so &lt;code&gt;LazyList[T]()&lt;/code&gt; calls the companion’s &lt;code&gt;apply&lt;/code&gt;
and makes the empty list instead of being refused. An empty call with no element type to infer
follows the settled rule of 2026-11-04 (generics.md): the covariant collections (&lt;code&gt;Vector&lt;/code&gt;,
&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;LazyList&lt;/code&gt;) take &lt;code&gt;Nothing&lt;/code&gt;, as &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;Vector.empty()&lt;/code&gt; do, and an
invariant or bounded element type (&lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, every set, &lt;code&gt;PriorityQueue&lt;/code&gt;) is a
“cannot infer” error. The refusal of an array’s name with type arguments used as a value
(&lt;code&gt;Array[int]&lt;/code&gt;) stays, its text now naming &lt;code&gt;Array(a, b)&lt;/code&gt;. The old refusal of calling an array’s constructor is removed, and the
literal &lt;code&gt;[1, 2, 3]&lt;/code&gt; is unchanged. &lt;strong&gt;Maps are excluded&lt;/strong&gt; (settled 2026-11-09): &lt;code&gt;Map(&amp;quot;k&amp;quot; -&amp;gt; 7)&lt;/code&gt; stays
refused with its hint to write &lt;code&gt;{&amp;quot;k&amp;quot;: 7}&lt;/code&gt;, and no pair operator is added. &lt;code&gt;Map((k, v), …)&lt;/code&gt; taking
tuples already exists and stays; no other map gained a form. Alternatives weighed: a compiler
special case treating &lt;code&gt;Name(a, b)&lt;/code&gt; as a literal (rejected: the library form needs none, and a
program’s own collections get the form by declaring &lt;code&gt;apply&lt;/code&gt;). Review with the user: whether the
tuple form &lt;code&gt;Map((1, &amp;quot;one&amp;quot;), …)&lt;/code&gt; should stay beside &lt;code&gt;{1: &amp;quot;one&amp;quot;}&lt;/code&gt;, since it is a second way to write
a map that no one needs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;diff&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.diff&lt;/code&gt;, a module of the
standard library for the differences between two sequences and between two texts’ lines.&lt;/strong&gt; It is
&lt;code&gt;library/avin/diff/diff.avin&lt;/code&gt;, a module of its own beside &lt;code&gt;avin.uuid&lt;/code&gt;, not part of the prelude, so
a program names what it uses (&lt;code&gt;import avin.diff.{diff, unifiedDiff}&lt;/code&gt;). The API: &lt;code&gt;diff[T: Eq](a, b) -&amp;gt; Vector[Edit[T]]&lt;/code&gt; with &lt;code&gt;Edit[T]&lt;/code&gt; the variants &lt;code&gt;Keep(value)&lt;/code&gt;, &lt;code&gt;Insert(value)&lt;/code&gt; and
&lt;code&gt;Delete(value)&lt;/code&gt;; &lt;code&gt;apply(a, edits)&lt;/code&gt;, which checks every &lt;code&gt;Keep&lt;/code&gt; and &lt;code&gt;Delete&lt;/code&gt; against the input and
traps naming the edit; &lt;code&gt;changes&lt;/code&gt;; &lt;code&gt;Line(text, terminated)&lt;/code&gt; with &lt;code&gt;splitLines&lt;/code&gt; and &lt;code&gt;joinLines&lt;/code&gt;;
&lt;code&gt;LineOptions(ignoreTrailingSpace = false, finalNewline = true)&lt;/code&gt; and &lt;code&gt;diffLines&lt;/code&gt;; &lt;code&gt;Hunk&lt;/code&gt;, &lt;code&gt;hunks(edits, context)&lt;/code&gt;; &lt;code&gt;renderUnified&lt;/code&gt; and &lt;code&gt;unifiedDiff&lt;/code&gt;, whose output is &lt;code&gt;diff -u&lt;/code&gt;‘s byte for byte (checked
against GNU diff’s on twenty fixture pairs at context 0, 1 and 3). The algorithm is Myers’ O(ND)
with the linear-space middle-snake refinement, so memory is proportional to the inputs (three
arrays of their combined size, and the script) and never to their product; a run of changes lists
its deletes before its inserts, as &lt;code&gt;diff -u&lt;/code&gt; prints them. Choices: edits carry the elements, not
indices, so a script is self-describing and &lt;code&gt;apply&lt;/code&gt; can verify it (a &lt;code&gt;Keep&lt;/code&gt; holds the first
sequence’s element, so a line diff that ignores trailing space keeps the original text); lines
split at &lt;code&gt;\n&lt;/code&gt; only and keep a &lt;code&gt;\r&lt;/code&gt;, as &lt;code&gt;diff&lt;/code&gt; does, so CRLF is a difference unless
&lt;code&gt;ignoreTrailingSpace&lt;/code&gt; is set (which ignores a &lt;code&gt;\r&lt;/code&gt; with the rest); a last line with no &lt;code&gt;\n&lt;/code&gt; differs
from the same line with one by default, as &lt;code&gt;diff&lt;/code&gt; reports it, and &lt;code&gt;finalNewline = false&lt;/code&gt; makes them
equal; two changes share a hunk when no more than &lt;code&gt;2 * context&lt;/code&gt; unchanged lines lie between them;
an empty range is written &lt;code&gt;start,0&lt;/code&gt; with &lt;code&gt;start&lt;/code&gt; the line before, a range of one line as its
number alone, as &lt;code&gt;diff -u&lt;/code&gt; does. Alternatives weighed: edits as index ranges
(&lt;code&gt;Keep(aStart, bStart, count)&lt;/code&gt;, more compact for large inputs, but cannot be applied without the
second sequence and reads less well in a pattern match); the quadratic table of the longest common
subsequence (simplest, but 10,000 lines against 10,000 takes 10^8 cells); a patience or histogram
diff (often reads better on source code, but is not shortest and does not match &lt;code&gt;diff -u&lt;/code&gt;); a
prelude placement (every program would carry the names &lt;code&gt;Edit&lt;/code&gt;, &lt;code&gt;Keep&lt;/code&gt; and &lt;code&gt;Delete&lt;/code&gt;). Tests:
&lt;code&gt;library/tests/diff.avin&lt;/code&gt;, with every pair of sequences over three values up to four long and
random pairs checked against the quadratic table for minimality. Review with the user: the names
&lt;code&gt;Edit&lt;/code&gt;, &lt;code&gt;Keep&lt;/code&gt;, &lt;code&gt;Insert&lt;/code&gt;, &lt;code&gt;Delete&lt;/code&gt;, &lt;code&gt;diffLines&lt;/code&gt;, &lt;code&gt;unifiedDiff&lt;/code&gt; and &lt;code&gt;changes&lt;/code&gt;, and whether a
patience diff should join this one as &lt;code&gt;diffLines&lt;/code&gt;‘ option.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;io.inputs&lt;/code&gt; and &lt;code&gt;io.inputLines&lt;/code&gt;: the files named, or standard input when none.&lt;/strong&gt; Settled on the
user’s delegation 2026-11-19: &lt;code&gt;io.inputs(paths: Vector[string]) -&amp;gt; Iterator[Result[(string, string), IoError]]&lt;/code&gt; yields each input as its name and all its text, and &lt;code&gt;io.inputLines(paths)&lt;/code&gt; yields the
same shape with one line per element. No paths is one input, standard input; &lt;code&gt;-&lt;/code&gt; names standard
input wherever it stands in the list, and a name is yielded as written, so standard input is
&lt;code&gt;&amp;quot;-&amp;quot;&lt;/code&gt;. Inputs are read as the iterator reaches them; one that cannot be read is an &lt;code&gt;Err&lt;/code&gt; (the
ordinary &lt;code&gt;IoError&lt;/code&gt;, naming the file) in its place, and the iterator goes on, so a tool reports and
carries on, and &lt;code&gt;.collect&lt;/code&gt;/&lt;code&gt;?&lt;/code&gt; style stopping at the first failure is the caller’s choice. Standard
input is read to its end once, so a second &lt;code&gt;-&lt;/code&gt; is empty. A file’s lines come from its whole text
(&lt;code&gt;readText&lt;/code&gt;), standard input’s as it advances. Why: every command-line filter writes this loop,
and an element carrying its name serves the &lt;code&gt;name:line&lt;/code&gt; output of &lt;code&gt;grep&lt;/code&gt; and an error message
alike. Placed in &lt;code&gt;avin.io&lt;/code&gt; beside &lt;code&gt;readAll&lt;/code&gt; and &lt;code&gt;lines&lt;/code&gt;, named as they are. Alternatives weighed:
&lt;code&gt;Vector&lt;/code&gt; of results (reads every file before the first line is used, and cannot stream standard
input); a &lt;code&gt;Source&lt;/code&gt; of the concatenation (loses where each line came from); stopping at the first
failing file (a tool wants to report each); a name of &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; for standard input (indistinguishable
from a named empty string, and &lt;code&gt;-&lt;/code&gt; is what the tool was told). Tests: &lt;code&gt;tests/run/io_inputs_files&lt;/code&gt;,
&lt;code&gt;io_inputs_stdin&lt;/code&gt;, &lt;code&gt;io_inputs_lines_stdin&lt;/code&gt;. Review with the user: the name &lt;code&gt;&amp;quot;-&amp;quot;&lt;/code&gt; yielded for
standard input, and files being read whole rather than streamed by line.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A symbol method may declare its precedence and grouping&lt;/strong&gt; (branch &lt;code&gt;declared-precedence&lt;/code&gt;,
2026-11-19; the user approved “perhaps declared precedence” in the missing-features list,
2026-11-19). The surface is &lt;a href=&quot;/spec/operators-and-control-flow/#a-declared-precedence&quot;&gt;A declared precedence&lt;/a&gt;.
&lt;strong&gt;Review with the user:&lt;/strong&gt; the whole surface, the annotation names &lt;code&gt;@precedence&lt;/code&gt; and
&lt;code&gt;@groupsRight&lt;/code&gt;, naming a level by an operator’s string, and the program-wide rule.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;@precedence(&amp;quot;|&amp;quot;)&lt;/code&gt; names a row of the existing
level table by any operator in it, and &lt;code&gt;@groupsRight&lt;/code&gt; makes calls group to the right with the
receiver kept on the left.&lt;/strong&gt; The rows a method may take are the symbol levels plus &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;‘s and
&lt;code&gt;||&lt;/code&gt;‘s, which a pipe looser than every comparison needs. WHY: no level is added, so the table
stays the whole account of how an expression reads, and a reader who knows how &lt;code&gt;|&lt;/code&gt; binds knows
how a call declared as &lt;code&gt;|&lt;/code&gt; binds; naming the row by its operator needs no new vocabulary.
ALTERNATIVES: numeric levels (refused: a reader cannot place &lt;code&gt;infixl 6&lt;/code&gt; without a table of
every declaration in scope, and two libraries’ numbers interleave in ways neither author
saw); identifier level names such as &lt;code&gt;@precedence(additive)&lt;/code&gt; (a second set of names for rows
the operators already name); one annotation with a grouping argument,
&lt;code&gt;@precedence(&amp;quot;^&amp;quot;, right)&lt;/code&gt; (a positional flag reads worse than a word of its own); &lt;code&gt;@groups(left)&lt;/code&gt;
as well (a name ending in &lt;code&gt;:&lt;/code&gt; would then take its receiver on the right yet group left, a
combination nothing needs); nothing new, with documentation (the user approved the feature).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a declaration belongs to the method’s name
across the whole program&lt;/strong&gt;, and every method of that name in the program reads alike: an
overload, another type’s method, a trait’s declaration and each implementation either declare
the same reading or one that comes to the same (a method declaring nothing agrees only where
the declaration restates what its name gives); any other is an error naming both, reported at
the program’s method where the other is the standard library’s. WHY: the parse runs before
any type is known, so &lt;code&gt;a &amp;lt;|&amp;gt; b&lt;/code&gt; cannot be read by &lt;code&gt;a&lt;/code&gt;‘s type; a module holding a value of the
type without importing it must read its calls as the declaring module does, which only a
program-wide reading guarantees; and a module’s code cannot change meaning silently when an
unrelated library joins the program, because that is an error instead. ALTERNATIVES: by the
receiver’s type at each call (needs types at parse time, or a second parse after checking,
and makes &lt;code&gt;a op b op2 c&lt;/code&gt; unreadable without knowing every operand’s type); visible through
imports only, as some languages scope fixity (a module that reaches the type through a
function’s result, without importing its module, would read the calls differently from the
declaring module); undeclared methods silently following a declaration (another library’s
&lt;code&gt;&amp;lt;|&amp;gt;&lt;/code&gt;, written for the default reading, would be re-read by a declaration it never saw).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;the compiler reads declarations after parsing
every unit with the default levels, then parses again, at the declared levels, only the units
that write a declared name&lt;/strong&gt;, a program with no declaration that changes a reading being parsed
once as before. WHY: the declarations are on methods inside the files, so they are known only
after a first parse; re-parsing keeps the parser the one place precedence lives, with no tree
rewriting pass to keep in step with it. ALTERNATIVES: a fixity-resolution pass over the parsed
trees (a second implementation of the precedence rules over every expression form); a lexical
pre-scan for declarations (a second, partial parser of class and impl bodies).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;only a method named by a symbol the language
does not use declares&lt;/strong&gt;: &lt;code&gt;@precedence&lt;/code&gt; or &lt;code&gt;@groupsRight&lt;/code&gt; on one of the language’s operators
(&lt;code&gt;+&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;), an assignment (&lt;code&gt;++=&lt;/code&gt;), a method named by a word, or a function is an error;
&lt;code&gt;~&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt; and &lt;code&gt;--&lt;/code&gt; between two operands may declare. &lt;code&gt;@groupsRight&lt;/code&gt; on a name ending in &lt;code&gt;:&lt;/code&gt; is an
error (it groups right already). A comparison and &lt;code&gt;is&lt;/code&gt; take part in the rule against mixing
groupings now that a right-grouping method can share their level. WHY: the language’s own
operators keep one reading everywhere, and every named call binds alike.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin parse&lt;/code&gt;, &lt;code&gt;avin fmt&lt;/code&gt; and the LSP’s single-file views read one file at a time and so parse
it at the default levels; &lt;code&gt;avin check&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and the LSP’s diagnostics load
the whole program and read the declarations. &lt;code&gt;avin fmt&lt;/code&gt; keeps the file’s tokens, so a default
reading changes only where it chooses to break a long line.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;bytes-sendable&lt;/code&gt;; found by the ssh package on
&lt;code&gt;pty-forward&lt;/code&gt;, whose relay could hand read buffers to per-connection threads only by copying each
into a &lt;code&gt;Vector[byte]&lt;/code&gt;): &lt;strong&gt;an array the program holds moves to another thread with
&lt;code&gt;Isolated.move(items)&lt;/code&gt;, with no copy, and the array carries an owner that every use checks&lt;/strong&gt;
(&lt;a href=&quot;/spec/actors/#handing-over-ownership&quot;&gt;handing over ownership&lt;/a&gt;).
&lt;code&gt;move[T: Sendable](items: Array[T]) -&amp;gt; Isolated[Array[T]]&lt;/code&gt;, on &lt;code&gt;Isolated&lt;/code&gt;‘s companion in
&lt;code&gt;avin.actors&lt;/code&gt;; it covers every &lt;code&gt;Array&lt;/code&gt; of sendable elements, bytes or not, and nothing else. An
array’s header gains an owner word beside its length (eight bytes), zero for an array never moved,
which any code that reaches it may use as before, since an array is still not sendable. A move
also rewrites the length word for good: its top bit set, the length in bits 32 to 62, the low 32
bits zero. So an element use of an array never moved checks exactly what it did before, the index
against the low 32 bits, and a moved array fails that check for every index and goes on, on a
path the optimizer is told is cold, to compare its owner; &lt;code&gt;length&lt;/code&gt;, a slice, a clear and a copy
test the word’s sign as they read it. A move
gives it an owner no running code is, by one compare-and-set; &lt;code&gt;take&lt;/code&gt; claims it for the taker, &lt;code&gt;with&lt;/code&gt;
for the code running &lt;code&gt;f&lt;/code&gt; and moves it again after; every use by other code traps with
&lt;code&gt;`Array` was moved to another owner&lt;/code&gt;: an element read or write, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;, a copy into
or out of it, an iterator’s step, a C binding’s argument (checked before C sees it), a Sysl
binding’s argument (checked as its shim reads it), a &lt;code&gt;ByteBlock&lt;/code&gt; write from it, and a second move.
&lt;strong&gt;Aliases&lt;/strong&gt; (a field, a closure’s capture, an iterator) are the same object, so their uses trap
as the local’s does; a &lt;strong&gt;slice&lt;/strong&gt; taken before the move is a copy and stays the sender’s; frozen
arrays (a &lt;code&gt;Vector&lt;/code&gt;‘s or an &lt;code&gt;ArraySeq&lt;/code&gt;‘s) are the library’s own, never moved, and unchecked. Why:
an array’s elements are stored inside the object, so a move cannot hand the receiver new storage
and leave the sender an empty shell; the only sound zero-copy move of an array other references
may reach is one the array itself enforces, and an owner word read beside the length the bounds
check already reads keeps the common path to a load and a compare. Handles already move this
way, and the messages match. &lt;em&gt;Alternatives weighed&lt;/em&gt;: (a) &lt;strong&gt;transfer on send&lt;/strong&gt;, making &lt;code&gt;Array&lt;/code&gt;
sendable and moving it implicitly at every send — then an &lt;code&gt;@isolating&lt;/code&gt; body (a mutex’s value,
&lt;code&gt;isolate&lt;/code&gt;) could capture an array that was never moved and share it unchecked between threads, so
every array would need a real owner from birth and every mutex, pool and &lt;code&gt;Isolated&lt;/code&gt; a walk to
re-own what it holds; far wider and slower for the same gain. (b) &lt;strong&gt;&lt;code&gt;freeze()&lt;/code&gt;/&lt;code&gt;toBytes()&lt;/code&gt;&lt;/strong&gt;, an
immutable sendable view — still needs the array to refuse later writes (the same owner word), and
the relay wants a buffer the receiver can write and hand back. (c) &lt;strong&gt;a separate &lt;code&gt;Transfer[T]&lt;/code&gt;
type&lt;/strong&gt; — &lt;code&gt;Isolated&lt;/code&gt; already is the type of “mutable, moving, taken once”, with &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;with&lt;/code&gt; and
its place in the handover walk; a second type would duplicate it. (d) &lt;strong&gt;lifting
&lt;code&gt;@trusted_sendable&lt;/code&gt;‘s restriction&lt;/strong&gt; to the standard library — rejected: it would let any package
declare an array-holding class sendable with nothing checking the claim, which is a data race,
not a gap closed. A compile-time refusal of the sender’s later use was weighed too: it needs
uniqueness or alias analysis the checker does not have, and the runtime check covers every
alias. &lt;em&gt;The cost, measured on the build that settled it&lt;/em&gt;: memory, a million live arrays of 0 to
100 bytes take 0 or 16 more bytes each, by whether the eight cross a 16-byte allocation class
(56→56 bytes at 0, 1 and 8 elements; 56→72 at 9 and 16; 72→88 at 32; 104→120 at 64; 152→152 at
100). Time, at -O2: a read loop over an array never moved compiles to the same ten instructions
as before; a write loop bounded by &lt;code&gt;a.length&lt;/code&gt; keeps an element bounds check the optimizer used to
drop, plus a sign test, three predictable instructions an iteration. A first encoding that loaded
the owner word at every use was measured (preliminary, eleven interleaved runs, before the
benchmark was cut short) at 3% to 54% slower in tight loops, which is why the owner sits behind
the bounds check; the encoding that settled was checked in the generated code, not timed.
&lt;strong&gt;Review with the user&lt;/strong&gt;: the remaining write-loop check and the memory above, and whether
&lt;code&gt;Buffer&lt;/code&gt; should move the same way (its length is a field of its own, so it would need its own
owner).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;ports-cli&lt;/code&gt;): &lt;strong&gt;an example of many files,
&lt;code&gt;examples/NAME/&lt;/code&gt;, is run and its output checked when &lt;code&gt;examples/NAME.out&lt;/code&gt; stands beside it, and is
only built and linked when it has none&lt;/strong&gt;, as a program that opens a window has none. Its input
and expected standard error are &lt;code&gt;examples/NAME.in&lt;/code&gt; and &lt;code&gt;examples/NAME.err&lt;/code&gt;, its expectation lines
(&lt;code&gt;// args:&lt;/code&gt;, &lt;code&gt;// expect:&lt;/code&gt;) in its own files, exactly as a program in &lt;code&gt;tests/programs/run&lt;/code&gt; has them.
&lt;em&gt;Why&lt;/em&gt;: the command-line examples (&lt;code&gt;wordfreq&lt;/code&gt;, &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;logsum&lt;/code&gt;, &lt;code&gt;dusage&lt;/code&gt;, &lt;code&gt;markdown&lt;/code&gt;, &lt;code&gt;todo&lt;/code&gt;) are
directories with a README, and the sidecar beside the directory is the rule the corpus already
reads for programs of many files, so nothing new is learned to read one. &lt;em&gt;Alternatives weighed&lt;/em&gt;:
sidecars inside the directory (a second rule for the same thing); a header line marking a window
program as not run (a marker on the exception rather than on the output that makes the check); a
separate &lt;code&gt;examples/run/&lt;/code&gt; directory (splits the examples a reader browses by how they are tested).
Branches &lt;code&gt;ports-concurrent&lt;/code&gt; and &lt;code&gt;ports-numeric&lt;/code&gt; reached the same rule on their own, with the same
reasons; the corpus keeps one copy of it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;variant-fn-value&lt;/code&gt;): &lt;strong&gt;a variant with fields,
named and not called, is its constructor as a function value, as a class’s name is.&lt;/strong&gt; &lt;code&gt;Heard&lt;/code&gt;,
&lt;code&gt;Event.Heard&lt;/code&gt;, &lt;code&gt;events.Heard&lt;/code&gt; and &lt;code&gt;Some[int]&lt;/code&gt; are each a function of the variant’s fields, in
order and all of them (defaults are not dropped, as a class constructor’s value drops none), to
its data type, or to a refined variant’s declared instance: &lt;code&gt;[&amp;quot;a&amp;quot;].map(Heard)&lt;/code&gt;,
&lt;code&gt;[1, 2].map(Some)&lt;/code&gt;, &lt;code&gt;adapter(Heard)&lt;/code&gt;, &lt;code&gt;listener.ask(Stop, patience)&lt;/code&gt;. Where a function type of as
many parameters is expected, its parameters stand for the fields’ (an open one there takes the
field’s type, so &lt;code&gt;adapter(Heard)&lt;/code&gt; needs no &lt;code&gt;adapter[ChatEvent]&lt;/code&gt;) and its result is the type the
variant is made at, which also decides between variants sharing a name; elsewhere the value’s
type is the variant’s own, and a generic variant whose instance nothing decides is reported
(“cannot infer &lt;code&gt;T&lt;/code&gt; for &lt;code&gt;Some&lt;/code&gt; used as a value; write it, as in &lt;code&gt;Some[int]&lt;/code&gt;“). An expected type
the variant does not fit is reported as the whole value’s type against it. Where a value of the
variant’s own data type is expected, the call was meant, and the old error stands (“&lt;code&gt;Circle&lt;/code&gt; has
fields; call it, as in &lt;code&gt;Circle(arguments)&lt;/code&gt;“); a variant without fields is still the value it
names. A data type’s companion object of the variant’s name that declares &lt;code&gt;apply&lt;/code&gt;, where a
function type is expected, offers the variant beside its &lt;code&gt;apply&lt;/code&gt; methods, chosen as among
overloads, as the call &lt;code&gt;Name(…)&lt;/code&gt; already chose among them. The value is a lambda made at the use
that calls the variant as written, so it captures nothing and is &lt;code&gt;@sendable&lt;/code&gt; where one is wanted.
&lt;em&gt;Why&lt;/em&gt;: the smallest rule that makes a variant behave as the constructor it is, with the typing a
class constructor’s value already has; ports of concurrent programs reached for it at every
actor adapter and &lt;code&gt;ask&lt;/code&gt;. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a value only where a function type is expected
(refuses &lt;code&gt;val f = Heard&lt;/code&gt;, which a class name allows); a function value that drops defaulted
fields (a value has no defaults, and which arity would be ambiguous); keeping the variant out of
a companion’s overloads (inconsistent with the call). A lambda whose parameter type nothing but
its body decides, &lt;code&gt;adapter(e -&amp;gt; Heard(e))&lt;/code&gt;, still reports “cannot infer the type of &lt;code&gt;e&lt;/code&gt;“: the
lambda’s parameter is typed before its body is checked, and this item does not widen inference.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;scalar-left-ops&lt;/code&gt;): &lt;strong&gt;a built-in value may
stand on an operator method’s left.&lt;/strong&gt; An impl of no trait adding to &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt; (any integer
width), &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt; or &lt;code&gt;bool&lt;/code&gt;, in the type’s module or as an extension, may add
a binary arithmetic, ordering, bitwise or shift method whose one parameter is a data type, a class,
a trait or an opaque type (any type arguments): &lt;code&gt;impl real&lt;/code&gt; adding &lt;code&gt;*(v: Vec) -&amp;gt; Vec = v * self&lt;/code&gt;
makes &lt;code&gt;k * v&lt;/code&gt; legal. &lt;code&gt;l op r&lt;/code&gt; with &lt;code&gt;l&lt;/code&gt; built-in and &lt;code&gt;r&lt;/code&gt; of such a type calls &lt;code&gt;l&lt;/code&gt;‘s method when an
overload takes &lt;code&gt;r&lt;/code&gt; (or &lt;code&gt;r&lt;/code&gt;‘s type has no integer/decimal conversion, so the call reports the
overloads); resolution is static by parameter types, chains and &lt;code&gt;&amp;lt;&lt;/code&gt;-links included. An integer
literal on the left is &lt;code&gt;int&lt;/code&gt; where an &lt;code&gt;int&lt;/code&gt; overload fits, else &lt;code&gt;long&lt;/code&gt;, else &lt;code&gt;real&lt;/code&gt; (&lt;code&gt;2 * v&lt;/code&gt;). A
method of such a name on a built-in type taking a built-in type, tuple, function, union or type
parameter stays an error (a type parameter could be filled by a built-in type), as does any such
method in a trait implementation (&lt;code&gt;impl Grow for real&lt;/code&gt;) and every prefix method; an unseen
extension’s operator is reported with the module to import. WHY: &lt;code&gt;k * v&lt;/code&gt; is how scaling is
written, and code was forced into &lt;code&gt;v * k&lt;/code&gt;; since the operand is never built-in, built-in ×
built-in arithmetic can never change meaning, and the rule reuses relaxed impls and overloading,
adding no new declaration form. A type that takes integers (&lt;code&gt;BigInt&lt;/code&gt;) keeps meeting integers by
&lt;code&gt;fromInteger&lt;/code&gt; unless an overload names it. ALTERNATIVES: reflected methods on the right operand
(&lt;code&gt;*:&lt;/code&gt; or a &lt;code&gt;reverse *&lt;/code&gt;, as a second dispatch step: two places a reader must look for one operator,
and a precedence question when both sides define one); a &lt;code&gt;Scalar&lt;/code&gt; trait the right type implements
(&lt;code&gt;scale(k)&lt;/code&gt;), which serves only multiplication by numbers and not &lt;code&gt;&amp;quot;label&amp;quot; + v&lt;/code&gt; or &lt;code&gt;k &amp;lt; v&lt;/code&gt;;
widening &lt;code&gt;FromInteger&lt;/code&gt;-style conversion of the left operand to the right type (wrong for &lt;code&gt;k * v&lt;/code&gt;,
where a real is not a vector). The literal preference &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt; was chosen over
“ambiguous when several fit” so &lt;code&gt;2 * v&lt;/code&gt; works with only &lt;code&gt;real&lt;/code&gt; adding &lt;code&gt;*&lt;/code&gt;. Tests:
&lt;code&gt;tests/run/scalar_left_operators&lt;/code&gt;, &lt;code&gt;tests/reject/scalar_left_operator_{declarations,builtin_operands,calls}&lt;/code&gt;,
&lt;code&gt;tests/programs/{run,reject}/scalar_left_extensions&lt;/code&gt;. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether an operand
of a type parameter bounded by a trait (&lt;code&gt;[T: Shape] k * s&lt;/code&gt;) should also dispatch (left out: the
right operand must be a concrete program type today), and the literal preference order.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;display-width&lt;/code&gt;): &lt;strong&gt;the standard library
measures the columns of a terminal: &lt;code&gt;char.displayWidth&lt;/code&gt;, &lt;code&gt;string.displayWidth&lt;/code&gt;,
&lt;code&gt;padStartWidth(width, ch = &apos; &apos;)&lt;/code&gt;, &lt;code&gt;padEndWidth(width, ch = &apos; &apos;)&lt;/code&gt; and &lt;code&gt;truncateWidth(width, ellipsis = &amp;quot;…&amp;quot;)&lt;/code&gt;, and a formatted field’s width counts those columns.&lt;/strong&gt; The rules
(&lt;code&gt;library/avin/display_width.avin&lt;/code&gt;): a character is 2 when East Asian Wide or Fullwidth; 0 when a
nonspacing or enclosing mark, a format character (but the soft hyphen and the marks before a
number), or a Hangul vowel or final jamo; 0 when a control character; 1 otherwise, Ambiguous and
unassigned included. Text is measured by cluster: a character with the zero-width characters after
it, a skin tone after an emoji, and, after a pictograph, each pictograph a zero-width joiner joins;
a cluster is as wide as its first character, except that a variation selector 16 after an emoji, or
a skin tone, makes it 2, and two regional indicators are one flag of 2. The table is generated from
the Unicode Character Database 17.0.0 (the version &lt;code&gt;sysl.unicode&lt;/code&gt; answers with) by
&lt;code&gt;scripts/display_width_table.avin&lt;/code&gt; into &lt;code&gt;library/avin/display_width_table.avin&lt;/code&gt;, about 3 KB of
base-32 runs decoded on the first character beyond ASCII; ASCII is answered without it. Choices,
each with its rationale and the alternatives weighed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Control characters are 0&lt;/strong&gt;, not -1 as C’s &lt;code&gt;wcwidth&lt;/code&gt; answers: a width is summed, and a -1 makes
every sum wrong; where a tab or newline moves the cursor is the terminal’s business. Alternative:
1, as &lt;code&gt;tui&lt;/code&gt; draws a control as U+FFFD (a drawing choice, not a measure).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Emoji sequences are 2 per cluster&lt;/strong&gt;, as kitty, WezTerm, iTerm2, Ghostty and the other modern
terminals draw them; older terminals that measure each code point make a family 6 or more. A
variation selector 15 changes nothing, since terminals mostly keep a default-emoji character two
wide under it. A lone regional indicator is 1, its East Asian width. A zero-width joiner joins only
a pictograph to a pictograph, as the grapheme rule GB11 does, so &lt;code&gt;a&lt;/code&gt; + ZWJ + &lt;code&gt;😀&lt;/code&gt; is 3.
Alternative: full extended grapheme clusters from the break tables &lt;code&gt;avin.regex&lt;/code&gt; carries (exact for
Indic conjuncts and prepended marks, but the prelude would carry those tables and the widths come
out the same for what a terminal draws).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Separate names, &lt;code&gt;padStartWidth&lt;/code&gt;/&lt;code&gt;padEndWidth&lt;/code&gt;, beside &lt;code&gt;padStart&lt;/code&gt;/&lt;code&gt;padEnd&lt;/code&gt;&lt;/strong&gt;, which keep counting
characters. Alternative: a named parameter (&lt;code&gt;padEnd(10, byWidth = true)&lt;/code&gt;), rejected as a flag that
changes what the first argument means; or changing &lt;code&gt;padEnd&lt;/code&gt; itself, rejected because a sequence’s
&lt;code&gt;padTo&lt;/code&gt; and &lt;code&gt;take&lt;/code&gt;/&lt;code&gt;drop&lt;/code&gt; count characters and &lt;code&gt;padEnd&lt;/code&gt; pairs with them. A wide fill character fills
two columns at a time and a space fills a column left over; a fill of no width traps (&lt;code&gt;padding by width needs a fill character that takes a column&lt;/code&gt;) when padding is needed, rather than looping or
silently using a space.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;truncateWidth&lt;/code&gt; never cuts a cluster&lt;/strong&gt;, so the result may be a column short of &lt;code&gt;width&lt;/code&gt; where a
wide character does not fit, and adds no padding (pad it after when a fixed width is wanted). An
ellipsis wider than &lt;code&gt;width&lt;/code&gt; is dropped and the clusters that fit kept; a &lt;code&gt;width&lt;/code&gt; of 0 or less keeps
nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A formatted field’s width (&lt;code&gt;%8s&lt;/code&gt;, &lt;code&gt;%-6?&lt;/code&gt;, &lt;code&gt;%3c&lt;/code&gt;, and &lt;code&gt;FormatSpec.width&lt;/code&gt; in &lt;code&gt;writeField&lt;/code&gt;) counts
columns&lt;/strong&gt;: field widths exist to line columns up, and for ASCII nothing changes. The precision of
&lt;code&gt;%s&lt;/code&gt; and &lt;code&gt;%?&lt;/code&gt; still counts characters, as &lt;code&gt;take&lt;/code&gt; does. The runtime’s &lt;code&gt;text_width&lt;/code&gt; intrinsic, which
counted code points for the field, is removed. Review with the user: this changes the output of an
existing program that formats wide or combining text into a field (a CJK &lt;code&gt;%10s&lt;/code&gt; now pads four
columns less for two ideographs).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avin.cli&lt;/code&gt;‘s help measures names with &lt;code&gt;displayWidth&lt;/code&gt; and pads with &lt;code&gt;padEndWidth&lt;/code&gt;. The &lt;code&gt;tui&lt;/code&gt;
package’s own table (&lt;code&gt;width_table.avin&lt;/code&gt;, Unicode 16.0.0) and its &lt;code&gt;charWidth&lt;/code&gt;/&lt;code&gt;textWidth&lt;/code&gt; can
become calls to these.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Examples of concurrent programs, and what they asked of the library&lt;/strong&gt; (branch
&lt;code&gt;ports-concurrent&lt;/code&gt;, 2026-11-19).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Running an example of many files that has its output beside it: the &lt;code&gt;ports-cli&lt;/code&gt; entry above.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;Response.html(status, text)&lt;/code&gt;&lt;/strong&gt;, a response of
the type &lt;code&gt;text/html; charset=utf-8&lt;/code&gt; with the text sent as given, beside &lt;code&gt;Response.text&lt;/code&gt; and
&lt;code&gt;Response.json&lt;/code&gt;. WHY: a server that renders a page wrote &lt;code&gt;Response.bytes(status, text.utf8, &amp;quot;text/html; charset=utf-8&amp;quot;)&lt;/code&gt; by hand. ALTERNATIVES: none kept; escaping the text (it is markup,
already written).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;lib-papercuts&lt;/code&gt;): &lt;strong&gt;four library papercuts.&lt;/strong&gt;
(1) Every hasher of &lt;code&gt;avin.crypto&lt;/code&gt; (&lt;code&gt;Sha256&lt;/code&gt;, &lt;code&gt;Sha512&lt;/code&gt;, &lt;code&gt;Sha1&lt;/code&gt;, &lt;code&gt;Md5&lt;/code&gt;) gains &lt;code&gt;update(bytes: Array[byte])&lt;/code&gt; and the range forms &lt;code&gt;update(bytes, from, until)&lt;/code&gt; for a vector and for an array; the
array is handed to the digest in place through the &lt;code&gt;@sysl&lt;/code&gt; binding, with no copy, and a range
outside &lt;code&gt;0 ..&amp;lt; bytes.length&lt;/code&gt; or with &lt;code&gt;from &amp;gt; until&lt;/code&gt; traps. (2) &lt;code&gt;Channel.length&lt;/code&gt; answers the number
of buffered values, a snapshot under the lock that is stale at once (documented as a racy
observation); &lt;code&gt;size&lt;/code&gt; is the same number, since the inherited &lt;code&gt;size&lt;/code&gt; would consume the channel by
iterating it; &lt;code&gt;capacity&lt;/code&gt;, the constructor’s bound, is now a public &lt;code&gt;val&lt;/code&gt; (&lt;code&gt;unbounded&lt;/code&gt; for a channel
made with none, &lt;code&gt;0&lt;/code&gt; for a rendezvous). (3) &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; are methods of every integer type,
&lt;code&gt;real&lt;/code&gt; (as &lt;code&gt;math.max&lt;/code&gt;/&lt;code&gt;math.min&lt;/code&gt;: NaN when either is, &lt;code&gt;-0.0&lt;/code&gt; below &lt;code&gt;0.0&lt;/code&gt;), &lt;code&gt;char&lt;/code&gt; and &lt;code&gt;byte&lt;/code&gt;,
returning the first operand when equal; they are separate from &lt;code&gt;int.MaxValue&lt;/code&gt;/&lt;code&gt;MinValue&lt;/code&gt;, which are
static members. (4) The mutable &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;LinkedMap&lt;/code&gt; and &lt;code&gt;LinkedSet&lt;/code&gt; companions gain the
variadic &lt;code&gt;apply&lt;/code&gt;, shaped as the mutable &lt;code&gt;TreeMap&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt; have it (&lt;code&gt;Map((1, &amp;quot;a&amp;quot;), (2, &amp;quot;b&amp;quot;))&lt;/code&gt;;
later pairs replace earlier ones, a linked collection keeps first-insertion order). Why: each
closes a gap a ported program met and costs one line of surface. Alternatives weighed: a &lt;code&gt;Slice&lt;/code&gt;
type for the range form (rejected, &lt;code&gt;(bytes, from, until)&lt;/code&gt; is the shape &lt;code&gt;string.slice&lt;/code&gt; and the
collections already use); &lt;code&gt;Channel.length&lt;/code&gt; as a method with a call (kept parameterless, as
&lt;code&gt;size&lt;/code&gt;); &lt;code&gt;max&lt;/code&gt;/&lt;code&gt;min&lt;/code&gt; only through &lt;code&gt;Ord&lt;/code&gt; (rejected, &lt;code&gt;Ord&lt;/code&gt; has none, and the free functions need an
import for &lt;code&gt;real&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;end&lt;/code&gt; closes a form only when a name follows it, wherever it stands.&lt;/strong&gt; Settled on the user’s
delegation 2026-11-19 (branch &lt;code&gt;keyword-member-diag&lt;/code&gt;): &lt;code&gt;end = at&lt;/code&gt; after a statement with an
indented body is the word &lt;code&gt;end&lt;/code&gt; used as a name and gets the one error &lt;code&gt;end is not defined&lt;/code&gt;,
instead of an &lt;code&gt;end&lt;/code&gt; closer that swallowed the &lt;code&gt;=&lt;/code&gt; and cascaded into an infix-call error quoting
the whole enclosing body. The infix-call “no argument” suggestion quotes a receiver that spans
lines as &lt;code&gt;…&lt;/code&gt;, and is not reported when the receiver is itself an already-reported error.
Alternatives weighed: a dedicated “&lt;code&gt;end&lt;/code&gt; is a keyword” error (a second message for what the name
lookup already says); quoting the last line of a multi-line receiver (a fragment that is not the
receiver).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;given-grammar&lt;/code&gt;): &lt;strong&gt;the editor grammar scopes
&lt;code&gt;given&lt;/code&gt; and &lt;code&gt;using&lt;/code&gt; only where they are keywords.&lt;/strong&gt; &lt;code&gt;given&lt;/code&gt; is &lt;code&gt;keyword.declaration&lt;/code&gt; at the start
of a line (after an optional &lt;code&gt;private&lt;/code&gt;) when a name and then &lt;code&gt;:&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt; follow, and never after
&lt;code&gt;.&lt;/code&gt;, before &lt;code&gt;val&lt;/code&gt;/&lt;code&gt;var&lt;/code&gt;, or as a name (&lt;code&gt;given = 3&lt;/code&gt;, &lt;code&gt;given(x)&lt;/code&gt;). &lt;code&gt;using&lt;/code&gt; is &lt;code&gt;storage.modifier&lt;/code&gt;
when a parameter name follows and then &lt;code&gt;:&lt;/code&gt;, &lt;code&gt;,&lt;/code&gt;, &lt;code&gt;)&lt;/code&gt;, &lt;code&gt;-&amp;gt;&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt;, in a parameter list or a
lambda, and not as a name (&lt;code&gt;f(using: Mode)&lt;/code&gt;, &lt;code&gt;using -&amp;gt; using&lt;/code&gt;, &lt;code&gt;val using = 1&lt;/code&gt;, &lt;code&gt;x.using y&lt;/code&gt;). Why:
the spec makes both words keywords only in those positions, and a line-local TextMate pattern can
see exactly them. Alternatives weighed: scoping both words everywhere (colours ordinary names
wrongly); a begin/end rule for parameter lists (a parameter list can span lines and nest, which
the line-based tokenizer cannot track reliably). Review with the user: a &lt;code&gt;using&lt;/code&gt; whose parameter
name ends its line (a parameter list broken across lines) is not coloured.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;API documentation from the source&lt;/strong&gt; (branch &lt;code&gt;avin-doc&lt;/code&gt;; &lt;a href=&quot;/getting-started/#api-documentation&quot;&gt;&lt;code&gt;avin doc&lt;/code&gt;&lt;/a&gt;,
&lt;a href=&quot;/spec/declarations/#doc-comments&quot;&gt;doc comments&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a doc comment is the run of &lt;code&gt;//&lt;/code&gt; lines directly
above a declaration, past any annotations between&lt;/strong&gt;: exactly what the language server’s hover
already showed, so no second comment form exists and every comment the standard library already
wrote is its documentation. It is Markdown with GitHub’s extensions; each line loses its &lt;code&gt;//&lt;/code&gt; and
one space, and keeps the rest of its indentation. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a &lt;code&gt;///&lt;/code&gt; form of its own
(every existing comment would have to be rewritten, and a plain comment above a declaration would
silently stop being shown).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;&lt;code&gt;avin doc [&amp;lt;program&amp;gt;] [-o &amp;lt;dir&amp;gt;] [--check] [--std-url &amp;lt;url&amp;gt;] [&amp;lt;features&amp;gt;]&lt;/code&gt; and &lt;code&gt;avin doc --std&lt;/code&gt;&lt;/strong&gt;: the program is checked as &lt;code&gt;avin check&lt;/code&gt;
checks it, with every feature on, and refused with its diagnostics when it does not check; a page
per module (&lt;code&gt;&amp;lt;module&amp;gt;.html&lt;/code&gt;), the root module’s declarations on &lt;code&gt;index.html&lt;/code&gt; beside the list of
modules, a shared &lt;code&gt;style.css&lt;/code&gt; and a &lt;code&gt;search.js&lt;/code&gt; the search box reads, no fetch from anywhere else.
The default output is &lt;code&gt;.avin/doc&lt;/code&gt; beside the program (the package’s directory, the directory of a
program without a manifest, or the file’s), which a package’s &lt;code&gt;.gitignore&lt;/code&gt; already names; a
directory is written only when it is new, empty, or holds &lt;code&gt;.avin-doc&lt;/code&gt;, the marker &lt;code&gt;avin doc&lt;/code&gt; writes,
and then its old pages are removed first. &lt;em&gt;Alternatives weighed&lt;/em&gt;: &lt;code&gt;doc/&lt;/code&gt; beside the program (a
directory of hand-written docs by that name would be overwritten); &lt;code&gt;--check&lt;/code&gt; that also writes (a
check in CI wants nothing written).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;what a page shows&lt;/strong&gt;: every public declaration
of every module but a test module (&lt;code&gt;@tests&lt;/code&gt; files and a package’s &lt;code&gt;tests&lt;/code&gt; module), each with the
header hover shows (a function’s, a field’s and a value’s as the checker typed it; a type’s first
line as written), a data type’s variants and a record’s fields, a class’s public fields and methods,
a trait’s members, an object’s, a type’s public member exports as written (&lt;code&gt;export f.{m, n as k}&lt;/code&gt;),
the impls a type has with their public methods, and a module’s exports. An impl is listed with its
type when the site documents the type among modules of the same kind (the program’s, a
dependency’s, the library’s), with the module it is written in named when that is another;
otherwise under its own module’s “Implementations”. A method is shown without its type
(&lt;code&gt;map[U](…)&lt;/code&gt;, not &lt;code&gt;Option[T].map[U](…)&lt;/code&gt;). A module with nothing public and no comment has no
page. Anchors are &lt;code&gt;Type&lt;/code&gt;, &lt;code&gt;Type.member&lt;/code&gt;, &lt;code&gt;function&lt;/code&gt;, an overload’s &lt;code&gt;name-2&lt;/code&gt;, an impl’s
&lt;code&gt;Type.impl&lt;/code&gt;; a byte outside a name is written &lt;code&gt;~&lt;/code&gt; and its hex.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;a type named in a signature links to the
declaration the checker resolved it there&lt;/strong&gt;, so two types of one name in two modules are never
confused; a name the checker inferred rather than read (an alias’s body shown in its place) links
to the one type of the site with that name, and a type parameter never links. &lt;strong&gt;The standard
library’s modules the program reads, and its dependencies’ modules, are written beside its own&lt;/strong&gt;,
listed apart on the index, so every link stays inside the site; &lt;code&gt;--std-url&lt;/code&gt; names where the
library’s pages are published instead and writes none of them. &lt;em&gt;Alternatives weighed&lt;/em&gt;: always
linking to a fixed public URL (a site that breaks offline, and on a version mismatch); never
linking into the library (the commonest types of every signature would be dead text). &lt;strong&gt;Review
with the user&lt;/strong&gt;: whether the library’s pages should come with every package’s documentation by
default.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-19: &lt;strong&gt;links in a doc comment&lt;/strong&gt;: a link whose destination
is a path of names, &lt;code&gt;[the map](Vector.map)&lt;/code&gt;, and &lt;code&gt;[Name]&lt;/code&gt; or &lt;code&gt;[`Name`]&lt;/code&gt; with no destination,
link to that declaration, found as a member of the documented declaration’s type (and its
owners’), then in its module, then as a full path or a module’s name, then in the prelude, then as
the one declaration of the site with that name (&lt;code&gt;Type.member&lt;/code&gt; included). A relative destination
that names no declaration must be a page of the site. &lt;strong&gt;&lt;code&gt;--check&lt;/code&gt; fails on a destination link that
leads nowhere, a backticked &lt;code&gt;[`Name`]&lt;/code&gt; that resolves to nothing, and a fenced block with no
language or &lt;code&gt;avin&lt;/code&gt; that parses neither as declarations nor as the statements of a function body&lt;/strong&gt;;
a bare &lt;code&gt;[words]&lt;/code&gt; that names nothing stays prose, and &lt;code&gt;http:&lt;/code&gt;-style links are not fetched. Without
&lt;code&gt;--check&lt;/code&gt; the same problems are warnings and the pages are written. Only the program’s own modules
are checked, never a dependency’s or the library’s. &lt;em&gt;Alternatives weighed&lt;/em&gt;: reporting every
unresolved &lt;code&gt;[x]&lt;/code&gt; (prose in brackets is common: &lt;code&gt;[1, 2, 3]&lt;/code&gt;); fetching external links (slow, flaky,
and a fetch the command promises not to make); running the blocks as tests (a separate feature,
left for later).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-20 (branch &lt;code&gt;mem-mir-size&lt;/code&gt;): &lt;strong&gt;the mid-level
representation keeps an integer constant as a number and shares each call signature.&lt;/strong&gt; An
&lt;code&gt;Operand&lt;/code&gt; was 40 bytes because &lt;code&gt;ConstInt&lt;/code&gt; held its decimal text; it now holds a &lt;code&gt;long&lt;/code&gt;
(&lt;code&gt;ConstInt(bits, value)&lt;/code&gt;), and an integer no &lt;code&gt;long&lt;/code&gt; spells the same way (one wider than 64 bits, a
&lt;code&gt;BigInt&lt;/code&gt; literal) is &lt;code&gt;ConstWide(bits, digits: &amp;amp;string)&lt;/code&gt;, so the LLVM text stays byte for byte what
it was. A &lt;code&gt;Runtime&lt;/code&gt; or &lt;code&gt;Indirect&lt;/code&gt; callee names a &lt;code&gt;&amp;amp;MirSignature&lt;/code&gt; that lowering makes once per shape
(&lt;code&gt;MirSignatures&lt;/code&gt;, keyed by the signature’s types), so a call no longer carries its own two lists.
&lt;code&gt;Operand&lt;/code&gt; 40 → 24 bytes, &lt;code&gt;Inst&lt;/code&gt; 136 → 88, &lt;code&gt;Terminator&lt;/code&gt; 64 → 48. Measured on marshal at -O2 with a
cold cache: the lower phase’s resident memory 2.98 → 2.28 GB, its in-use heap 1.80 → 1.41 GB, the
build’s peak 5.54 → 4.66 GB; the emitted module of marshal (with and without &lt;code&gt;-g&lt;/code&gt;) and of 252
corpus programs is unchanged. The instance cache’s entry format is unchanged too: a constant is
still written as its digits and a signature in full, and reading one shares it again.
Alternatives weighed: signatures by index into a table on &lt;code&gt;MirProgram&lt;/code&gt; (as small, but every pass
that reads a call’s signature, emit, devirtualization, union words and the instance cache, would
need the table handed to it, where a shared reference needs nothing); keeping one signature per
call behind a reference (no sharing: the lists stay per call); boxing the rare large instructions
(&lt;code&gt;Variable&lt;/code&gt;, &lt;code&gt;AtomicCompareSet&lt;/code&gt;, a C call’s &lt;code&gt;CFunction&lt;/code&gt;): once operands shrank, the largest
variants, &lt;code&gt;Call&lt;/code&gt;, &lt;code&gt;Select&lt;/code&gt;, &lt;code&gt;AtomicCompareSet&lt;/code&gt; and &lt;code&gt;Variable&lt;/code&gt;, all carry 80 bytes, and &lt;code&gt;Call&lt;/code&gt; and
&lt;code&gt;Select&lt;/code&gt; are common, so boxing the rare ones shrinks no instruction and was left out.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-20 (branch &lt;code&gt;mem-clang-child&lt;/code&gt;): &lt;strong&gt;a build’s clangs and
link run in a compiler image that never compiled.&lt;/strong&gt; Once &lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;avin run&lt;/code&gt; or &lt;code&gt;avin test&lt;/code&gt;
has compiled (diagnostics already said, the instance cache already written), the compiler writes
the module’s text, the shim archive, the C flags and the tests to a temporary directory and
replaces itself with &lt;code&gt;exec&lt;/code&gt; as &lt;code&gt;avin --linking-handed &amp;lt;dir&amp;gt; &amp;lt;the same command&amp;gt;&lt;/code&gt;; the new image
carries out the same command, takes the compilation from the directory where it would compile,
removes it, and splits, compiles the units and links. Freed small allocations stay resident for a
process’s life on macOS, so only a new image drops them: marshal at &lt;code&gt;-O2&lt;/code&gt;, cold, peaked at 8.19 GB
for the process tree before and 5.48 GB after (the compile alone; the linking image held 1.10 GB
beside its 8 clangs), at the same speed. Same process id, standard streams, exit status and
signals; &lt;code&gt;AVIN_BUILD_LOG&lt;/code&gt; goes on in the same file, with &lt;code&gt;handoff&lt;/code&gt; and &lt;code&gt;restore&lt;/code&gt; lines between
the compile’s phases and the link’s. When the directory cannot be written or the image cannot be
started, the link runs in place as before; a directory that cannot be read is compiled again.
Only the compiler’s own &lt;code&gt;main&lt;/code&gt; hands off, so a compiler run in memory (its tests) links in place.
Alternatives weighed: a child that compiles and exits while the first process waits to link
(what Sysl’s &lt;code&gt;sysl test&lt;/code&gt; does; two processes, and every diagnostic and the live report passed
across); a child for the link while the compiling process waits (its retained heap stays
resident beside the clangs, so nothing is gained); returning freed memory to the system (macOS
gives none back). Review with the user: the internal &lt;code&gt;--linking-handed&lt;/code&gt; argument shows in &lt;code&gt;ps&lt;/code&gt;
while a link runs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-20 (branch &lt;code&gt;gc-release&lt;/code&gt;): &lt;strong&gt;a collection gives the whole
pages of large free runs back to the system&lt;/strong&gt; (&lt;a href=&quot;/compiler/#runtime&quot;&gt;runtime&lt;/a&gt;), through the page
release hook of gc 0.4.0, with the system’s page size (&lt;code&gt;getpagesize&lt;/code&gt;, 16 KiB on macOS arm64).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How, on macOS: the range is mapped afresh in place&lt;/strong&gt; (&lt;code&gt;mmap&lt;/code&gt; with &lt;code&gt;MAP_FIXED&lt;/code&gt;), as the
stacks’ unused pages already are. Measured on a burst of 8 million strings (932 MB at the peak)
dropped and followed by churn: the resident size the system reports (&lt;code&gt;process.residentBytes&lt;/code&gt;,
what marshal reads) stayed at 1047 MB with &lt;code&gt;MADV_FREE&lt;/code&gt; and with &lt;code&gt;MADV_FREE_REUSABLE&lt;/code&gt;, and fell
to 2 MB with the remap. &lt;code&gt;MADV_FREE_REUSABLE&lt;/code&gt; also expects &lt;code&gt;MADV_FREE_REUSE&lt;/code&gt; before the pages are
used again, and the collector hands a released run out again with no call to the client, so it
was not sound here even had it measured well. &lt;strong&gt;On Linux, &lt;code&gt;madvise(MADV_DONTNEED)&lt;/code&gt;&lt;/strong&gt;, which
drops the pages at once; written, not run on this machine.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;When: a collection releases only when the arena reaches more than twice the budget past
what the last collection left live, and at most once a second.&lt;/strong&gt; Without the first condition a
program whose live data is small churns its 8 MiB of allocation in and out of the system at
every collection; without the second, one whose live objects sit high in the arena (a buffer
made after a burst) releases and refaults the free pages below them at every collection. Both
were measured: unthrottled, the churn after the drop took 1.2 s more system time over 2000
collections; with both conditions the system time is the same as with releasing off. A
collection that does not release runs with the hook removed, so its free runs stay ordinary
blocks a later collection can release. The first release in a program is never delayed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;AVIN_GC_RELEASE=0&lt;/code&gt; turns it off&lt;/strong&gt;; unset or any other value leaves it on.&lt;/li&gt;
&lt;li&gt;Cost: binarytrees 21 at -O2, three runs each way, 7.01–7.81 s with releasing and 7.01–7.39 s
without (the same within noise); the burst reproducer’s churn 9.16–9.72 s user with and
8.78–9.56 s without, system time 0.09–0.11 s both ways.&lt;/li&gt;
&lt;li&gt;Alternatives weighed: &lt;code&gt;MADV_FREE&lt;/code&gt; and &lt;code&gt;MADV_FREE_REUSABLE&lt;/code&gt; (above); releasing at every
collection (the refault cost above); a retained cushion skipped inside the hook (unsound with
this gc: a range the hook skips is still marked released, and is never offered again until
written); a library call to release on demand (no program needs it yet). Review with the user:
whether one second is the right interval, and whether a program should be able to ask for a
release (a collection) itself, since without one a program that drops a burst and then
allocates little keeps its pages until enough allocation brings a collection.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;http-request-timeout&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;http.serve&lt;/code&gt;
bounds the whole of a request&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#servers&quot;&gt;servers&lt;/a&gt;) by &lt;code&gt;requestTimeout&lt;/code&gt;,
60 seconds unless asked, measured from the request’s first byte and covering its line, headers
and body, chunked or of a length; once spent, the next wait for bytes is answered &lt;code&gt;408&lt;/code&gt; and the
connection closed, freeing its slot among &lt;code&gt;maxConnections&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: &lt;code&gt;readTimeout&lt;/code&gt; bounds each wait
alone, so a client sending a byte every few seconds held a connection, and a slot, for ever.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Each request has its own bound&lt;/strong&gt;, begun when its first byte is read; on a connection kept
alive the idle wait before it is &lt;code&gt;idleTimeout&lt;/code&gt;‘s and no part of it, and a connection’s wait for
its first byte stays &lt;code&gt;readTimeout&lt;/code&gt;‘s. A wait is cut to what is left of the bound, so the &lt;code&gt;408&lt;/code&gt;
comes at about the bound and not at the next &lt;code&gt;readTimeout&lt;/code&gt;. Bytes already read ahead
(pipelining) are parsed without a wait, so the bound costs a clock reading per wait only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero is no limit&lt;/strong&gt;, as for the other timeouts; a negative bound traps where the server
starts, as a negative &lt;code&gt;maxBodyBytes&lt;/code&gt; does (a negative timeout is a mistake, not a wish).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The parameter comes last&lt;/strong&gt;, after &lt;code&gt;errors&lt;/code&gt;, so no call passing the earlier ones by position
changes meaning.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A refusal’s drain is bounded in time too&lt;/strong&gt;: after a refusal the server read and dropped
what the client still sent, each read waiting half a second, up to 1 MiB, so a client trickling
on after its &lt;code&gt;408&lt;/code&gt; kept the connection for as long as it liked. The drain now lasts half a
second in all.&lt;/li&gt;
&lt;li&gt;Alternatives weighed: a header bound alone (as some servers keep apart from a body’s) leaves a
trickled body open; a minimum data rate is harder to state and to test; 30 seconds (as
&lt;code&gt;readTimeout&lt;/code&gt;) or 300 seconds for the default. Review with the user: whether 60 seconds suits
as the default, since a slow client uploading the default largest body of 1 MiB needs about
17 KB/s, and a server taking larger bodies has to raise it; and whether a TLS handshake, whose
waits are each &lt;code&gt;readTimeout&lt;/code&gt;‘s, should get a total bound too.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;http-forms&lt;/code&gt;): &lt;strong&gt;form bodies in
&lt;code&gt;avin.net.http&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#http-server&quot;&gt;HTTP server&lt;/a&gt;): &lt;code&gt;ServerRequest.form()&lt;/code&gt;
and &lt;code&gt;Request.withForm&lt;/code&gt; for &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt;, &lt;code&gt;ServerRequest.multipart(limits)&lt;/code&gt;,
&lt;code&gt;Multipart.parse&lt;/code&gt;, &lt;code&gt;Multipart.encoded&lt;/code&gt; and &lt;code&gt;Request.withMultipart&lt;/code&gt; for &lt;code&gt;multipart/form-data&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;One urlencoded codec, &lt;code&gt;Url.formDecode&lt;/code&gt; and &lt;code&gt;Url.formEncode&lt;/code&gt;&lt;/strong&gt;, which &lt;code&gt;queryParams&lt;/code&gt; now reads
through, so a query and a form body decode alike (WHATWG URL’s parser and serializer). Decoding
is strict where WHATWG is lenient: a malformed &lt;code&gt;%&lt;/code&gt; escape or bytes that are not UTF-8 are an
error (&lt;code&gt;BadEncoding(UrlError)&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt;) rather than kept or replaced by U+FFFD, since a silently
altered field is worse for a server than a refusal. A &lt;code&gt;charset&lt;/code&gt; parameter is ignored; the body
is read as UTF-8, as WHATWG reads every form. The serializer escapes &lt;code&gt;~&lt;/code&gt; as WHATWG does, so
&lt;code&gt;formEncode&lt;/code&gt; differs from &lt;code&gt;Url.encode&lt;/code&gt; there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A wrong or missing &lt;code&gt;Content-Type&lt;/code&gt; is an error (&lt;code&gt;NotAForm&lt;/code&gt;, &lt;code&gt;415&lt;/code&gt;)&lt;/strong&gt;, never an empty form.
&lt;code&gt;form()&lt;/code&gt; and &lt;code&gt;multipart()&lt;/code&gt; are methods with parentheses, since each parses the body anew.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multipart is read strictly by RFC 2046 lines&lt;/strong&gt;: CRLF only (a body of bare line feeds has no
delimiter); a delimiter followed by anything but &lt;code&gt;--&lt;/code&gt; or optional spaces/tabs and CRLF is body
content, so binary bytes resembling the boundary stay in the part; a body without the closing
delimiter is &lt;code&gt;BadMultipart&lt;/code&gt;; a body of no parts (&lt;code&gt;--b--&lt;/code&gt;) is an empty &lt;code&gt;Multipart&lt;/code&gt;. Every part
needs &lt;code&gt;Content-Disposition: form-data&lt;/code&gt; with a &lt;code&gt;name&lt;/code&gt; (RFC 7578 §4.2); a part’s type defaults
to &lt;code&gt;text/plain&lt;/code&gt; (§4.4). Header lines must be &lt;code&gt;token: value&lt;/code&gt; in UTF-8; folded lines are refused.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Names and filenames are read as the WHATWG HTML standard writes them&lt;/strong&gt;: a quoted value runs
to the next &lt;code&gt;&amp;quot;&lt;/code&gt;, and &lt;code&gt;%22&lt;/code&gt;, &lt;code&gt;%0D&lt;/code&gt;, &lt;code&gt;%0A&lt;/code&gt; become &lt;code&gt;&amp;quot;&lt;/code&gt;, CR, LF; there is no backslash escaping
(browsers send Windows paths with raw backslashes). The builder writes the same way, so the
round trip is exact. A &lt;code&gt;boundary&lt;/code&gt; in the &lt;code&gt;Content-Type&lt;/code&gt; is read as an RFC 9110 parameter
(quoted-pair escapes honoured) and must be 1–70 &lt;code&gt;bchars&lt;/code&gt; not ending in a space (&lt;code&gt;NoBoundary&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;filename*&lt;/code&gt; (RFC 5987) in UTF-8 or ISO-8859-1 is preferred to &lt;code&gt;filename&lt;/code&gt;&lt;/strong&gt;, as RFC 6266
prefers it; one in another charset or malformed is ignored (falling back to &lt;code&gt;filename&lt;/code&gt;, or no
filename). RFC 7578 says senders should not use it, so the builder never writes it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filenames are untrusted and nothing writes them to disk&lt;/strong&gt;: &lt;code&gt;Part.filename&lt;/code&gt; is the sender’s
text as given, documented so; the library offers no “save upload” helper that could use it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limits, &lt;code&gt;MultipartLimits(maxParts = 1000, maxHeaderBytes = 8192, maxBytes = 10485760)&lt;/code&gt;&lt;/strong&gt;:
a part count (&lt;code&gt;TooManyParts&lt;/code&gt;), the bytes of one part’s header block (&lt;code&gt;PartHeadersTooLarge&lt;/code&gt;)
and the whole body (&lt;code&gt;FormTooLarge&lt;/code&gt;), each &lt;code&gt;413&lt;/code&gt;. The body is first bounded by the server’s own
&lt;code&gt;maxBodyBytes&lt;/code&gt; (1 MiB by default), so &lt;code&gt;maxBytes&lt;/code&gt; binds only where a program raises that; it is
there so a streaming reader can enforce the same limits. 1000 parts follows common server
defaults for form fields and files.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Streaming is a later addition, not a change&lt;/strong&gt;: request bodies are buffered today, so &lt;code&gt;parse&lt;/code&gt;
takes the whole body; a streaming reader will be a separate entry point (a reader yielding
each part’s head and then its body as a stream) beside &lt;code&gt;Multipart.parse&lt;/code&gt;, sharing
&lt;code&gt;MultipartLimits&lt;/code&gt;, &lt;code&gt;FormError&lt;/code&gt; and the header and disposition readers, so nothing here changes
shape when it comes.&lt;/li&gt;
&lt;li&gt;The client: &lt;code&gt;withMultipart(form)&lt;/code&gt; uses &lt;code&gt;Multipart.newBoundary()&lt;/code&gt; (&lt;code&gt;avin-&lt;/code&gt; and 32 hex digits
from &lt;code&gt;SecureRandom&lt;/code&gt;); &lt;code&gt;withMultipart(form, boundary)&lt;/code&gt; and &lt;code&gt;encoded(boundary)&lt;/code&gt; trap on a boundary
RFC 2046 refuses or one a part’s body holds. Both builders replace any &lt;code&gt;Content-Type&lt;/code&gt; the
request had. &lt;code&gt;Request.header(name)&lt;/code&gt; was added beside &lt;code&gt;Response.header&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Alternatives weighed: lenient urlencoded decoding as WHATWG (silent corruption); accepting LF
line ends in multipart (looser than the RFC, invites ambiguity with binary bodies); RFC 9110
backslash escapes in disposition values (mangles Windows paths browsers send); refusing a
malformed &lt;code&gt;filename*&lt;/code&gt; (one bad optional parameter failing a whole upload); a &lt;code&gt;form&lt;/code&gt; returning a
plain vector like &lt;code&gt;queryParams&lt;/code&gt; (a &lt;code&gt;Form&lt;/code&gt; with &lt;code&gt;value&lt;/code&gt;/&lt;code&gt;values&lt;/code&gt; reads better in handlers, and
&lt;code&gt;pairs&lt;/code&gt; keeps the vector). Review with the user: the default limits, and whether a &lt;code&gt;formAs[T]&lt;/code&gt;
mirroring &lt;code&gt;queryAs[T]&lt;/code&gt; is wanted.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;avin-log&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.log&lt;/code&gt;, structured logging
in the standard library&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#avinlog&quot;&gt;system library&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The central API: a &lt;code&gt;Sendable&lt;/code&gt; class &lt;code&gt;Logger&lt;/code&gt;, reached as a given.&lt;/strong&gt; The record functions
&lt;code&gt;trace&lt;/code&gt; … &lt;code&gt;error(message, fields)&lt;/code&gt; are a logger’s methods and also module functions taking
&lt;code&gt;using logger: Logger = DefaultLogger&lt;/code&gt;; a program declares a given at its module’s top level, and
a request’s handler a &lt;code&gt;child&lt;/code&gt; as a given of its own block. &lt;strong&gt;There is no global logger to set&lt;/strong&gt;:
the default is a fixed &lt;code&gt;val&lt;/code&gt; (&lt;code&gt;Info&lt;/code&gt;, text, standard error), and configuration is a given, so no
module-level mutable state exists and a test’s logger can never leak into another’s. Alternatives
weighed: a given only, with no default (every library function logging would demand one of every
caller); a settable global default (mutable shared state, and two configurations racing in a
test run); a logger passed explicitly everywhere (what contextual parameters exist to remove).
Review with the user: the central API, the name of the module functions (&lt;code&gt;log.info(…)&lt;/code&gt; reads
well, but &lt;code&gt;debug&lt;/code&gt; and &lt;code&gt;error&lt;/code&gt; imported by name hide the prelude’s &lt;code&gt;debug&lt;/code&gt; of a value and read
like the &lt;code&gt;Error&lt;/code&gt; trait), and whether a settable process-wide default is wanted after all.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Laziness by by-name parameters.&lt;/strong&gt; The message (&lt;code&gt;-&amp;gt; string&lt;/code&gt;) and the fields
(&lt;code&gt;-&amp;gt; Vector[Field]&lt;/code&gt;) are by-name, so a record below the threshold evaluates neither; the
threshold is one &lt;code&gt;Level&lt;/code&gt; comparison. Measured at &lt;code&gt;-O2&lt;/code&gt;, 10 million disabled &lt;code&gt;debug&lt;/code&gt; calls with an
interpolated message and two fields take about 17 ns each beside 0.4 ns for the bare loop, and
2.8 ns each behind &lt;code&gt;if logger.enabled(Level.Debug)&lt;/code&gt;: the difference is the two delayed
arguments’ closures being made, which the by-name chapter’s representation says live on the
caller’s stack where they cannot escape. Alternatives: a closure parameter &lt;code&gt;() -&amp;gt; string&lt;/code&gt;
(heavier to write at every call), a string built always (the cost a disabled record must not
pay), a macro (the language has none).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A field is &lt;code&gt;(string, Any)&lt;/code&gt;&lt;/strong&gt;: any value can be written without conversion, a number and a
&lt;code&gt;bool&lt;/code&gt; keep their kind in JSON and anything else is its &lt;code&gt;Display&lt;/code&gt;. An &lt;code&gt;Option&lt;/code&gt; is not unwrapped:
a type pattern cannot match an &lt;code&gt;Option&lt;/code&gt; of any element type held in an &lt;code&gt;Any&lt;/code&gt; (&lt;code&gt;Option[_]&lt;/code&gt; is
refused as an open constructor), so a field not known is left out (the access log leaves out an
unknown length or address). Alternatives: a union of the JSON kinds (every other value converted
by hand at the call); a &lt;code&gt;LogValue&lt;/code&gt; trait (an impl for every type a program logs).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A logger’s own fields are rendered when it is made&lt;/strong&gt;, in its format, and held as text, which
keeps the logger &lt;code&gt;Sendable&lt;/code&gt; (an &lt;code&gt;Any&lt;/code&gt; is not) and makes a child free per record. A key written
twice, by a child and a record, is written twice rather than replaced.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text lines&lt;/strong&gt;: RFC 3339 time (&lt;code&gt;Instant&lt;/code&gt;‘s display), the upper-case level padded to five
columns, the message with its control characters escaped, then &lt;code&gt;key=value&lt;/code&gt; with a value or key
quoted as a JSON string where it is empty or holds a space, a control character, &lt;code&gt;&amp;quot;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt; or &lt;code&gt;\&lt;/code&gt;.
Colour paints only the level’s name, only where &lt;code&gt;colour&lt;/code&gt; is asked and the sink takes it (the
standard sinks: a terminal, &lt;code&gt;NO_COLOR&lt;/code&gt; unset, &lt;code&gt;TERM&lt;/code&gt; not &lt;code&gt;dumb&lt;/code&gt;, through &lt;code&gt;sysl.posix.tty&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sinks&lt;/strong&gt; are a &lt;code&gt;Sendable&lt;/code&gt; &lt;code&gt;Sink(write, colours)&lt;/code&gt; called once a line with its &lt;code&gt;\n&lt;/code&gt;, so one call
is one write and lines never interleave, as &lt;code&gt;println&lt;/code&gt; keeps them. &lt;strong&gt;The file sink appends each
line under a lock with the file opened for that line&lt;/strong&gt; (&lt;code&gt;fs.appendText&lt;/code&gt;), rather than holding a
&lt;code&gt;File&lt;/code&gt; open: an open &lt;code&gt;File&lt;/code&gt; belongs to the thread that opened it and traps when another thread
writes it, even inside a &lt;code&gt;Mutex&lt;/code&gt;; and reopening per line also survives a log rotator moving the
file away. A line that cannot be written is dropped: logging never stops the program it reports
on. Alternatives: a writer thread owning the file behind a channel (a thread to start and stop,
and lines not yet written when the record’s call returns); a &lt;code&gt;File&lt;/code&gt; behind a &lt;code&gt;Mutex&lt;/code&gt; (refused by
the file’s thread ownership, above).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The HTTP access log&lt;/strong&gt; gains an overload &lt;code&gt;accessLog(logger, clock, ids)&lt;/code&gt;, writing an &lt;code&gt;Info&lt;/code&gt;
record &lt;code&gt;request&lt;/code&gt; with its fields; the sink form is unchanged.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;File conveniences in &lt;code&gt;avin.fs&lt;/code&gt; (branch &lt;code&gt;fs-conveniences&lt;/code&gt;).&lt;/strong&gt; Settled on the user’s delegation
2026-11-23: &lt;code&gt;readLines&lt;/code&gt;/&lt;code&gt;lines&lt;/code&gt;/&lt;code&gt;writeLines&lt;/code&gt;, &lt;code&gt;writeTextAtomic&lt;/code&gt;/&lt;code&gt;writeBytesAtomic&lt;/code&gt;, a
&lt;code&gt;createParents = false&lt;/code&gt; argument on every write, &lt;code&gt;removeAll&lt;/code&gt; and &lt;code&gt;removeIfExists&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lines end at &lt;code&gt;\n&lt;/code&gt; or &lt;code&gt;\r\n&lt;/code&gt;; the last line needs no terminator; a final terminator ends the
last line rather than starting an empty one (so an empty file has no lines). &lt;code&gt;writeLines&lt;/code&gt; always
writes &lt;code&gt;\n&lt;/code&gt;, so a file it writes ends in a newline.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lines(file)&lt;/code&gt; answers &lt;code&gt;Result[Lines, IoError]&lt;/code&gt;: an open failure is immediate, a read failure
mid-stream is the last item. &lt;code&gt;Lines&lt;/code&gt; is an iterator and an &lt;code&gt;io.Close&lt;/code&gt;. The file closes when the
iterator is exhausted or fails; an early stop is &lt;code&gt;close()&lt;/code&gt; (&lt;code&gt;defer&lt;/code&gt;), and a forgotten one is
closed by the collector like any &lt;code&gt;File&lt;/code&gt;. Alternatives weighed: closing on garbage collection
alone (descriptors held for an unbounded time); a callback form &lt;code&gt;withLines(file, f)&lt;/code&gt; (does not
compose with iterator adapters).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;createParents&lt;/code&gt; is a default argument rather than twin functions, since the language has
default arguments; the default is &lt;code&gt;false&lt;/code&gt;, so existing calls are unchanged.&lt;/li&gt;
&lt;li&gt;Atomic writes: a uniquely named file beside the target (its name from the system layer, unique
per call and per process), written, &lt;code&gt;fsync&lt;/code&gt;ed, closed, and renamed over the target; any failure
removes it and leaves the target untouched. The directory itself is not synced after the rename,
and the replacement has default permissions rather than the old file’s.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;removeAll&lt;/code&gt; removes a file, a link (never followed) or a tree, and a missing path is &lt;code&gt;NotFound&lt;/code&gt;;
&lt;code&gt;removeIfExists&lt;/code&gt; returns &lt;code&gt;Result[bool, IoError]&lt;/code&gt; (&lt;code&gt;Ok(false)&lt;/code&gt; for nothing there) rather than a
bare &lt;code&gt;bool&lt;/code&gt;, since removal can fail for other reasons and a &lt;code&gt;bool&lt;/code&gt; would hide them. Review with
the user: whether &lt;code&gt;removeAll&lt;/code&gt; of a missing path should rather succeed, as &lt;code&gt;removeDirAll&lt;/code&gt; does.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;fs-walk&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.fs&lt;/code&gt; walks lazily, with
options&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#paths&quot;&gt;system library&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;walker(root, …)&lt;/code&gt; is an &lt;code&gt;Iterator[Result[Entry, IoError]]&lt;/code&gt;&lt;/strong&gt;, the shape &lt;code&gt;io.inputs&lt;/code&gt; already
has for a lazy sequence whose steps can fail; each directory is listed (whole, as &lt;code&gt;listDir&lt;/code&gt;
sorts it) when the walk reaches it. &lt;strong&gt;&lt;code&gt;walk(root)&lt;/code&gt; keeps its name, result and behaviour&lt;/strong&gt; and
takes the same named options, gathering &lt;code&gt;walker&lt;/code&gt;; nothing is deprecated. Alternatives: changing
&lt;code&gt;walk&lt;/code&gt; to answer the iterator (breaks every caller’s &lt;code&gt;match&lt;/code&gt; on its &lt;code&gt;Result&lt;/code&gt;), and a separate
options value (named, defaulted parameters read as well at the call and need no new type).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Options: &lt;code&gt;maxDepth&lt;/code&gt; (no limit by default; 0 the root alone; negative fails at the call),
&lt;code&gt;includeRoot&lt;/code&gt;, &lt;code&gt;postOrder&lt;/code&gt;, &lt;code&gt;followLinks&lt;/code&gt;, &lt;code&gt;prune&lt;/code&gt;, &lt;code&gt;stopOnError&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;prune&lt;/code&gt; is asked about each
directory the walk is about to go into, never the root (a hidden or oddly named root would
otherwise end a walk before it starts) and never a directory at &lt;code&gt;maxDepth&lt;/code&gt; (it would not be gone
into anyway); a pruned directory is still an entry.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An unreadable directory: reported by default, failing on request.&lt;/strong&gt; By default it is an entry
with the reason in &lt;code&gt;error&lt;/code&gt; and the walk goes on, as &lt;code&gt;walk&lt;/code&gt; always did; with &lt;code&gt;stopOnError&lt;/code&gt; it is
an &lt;code&gt;Err&lt;/code&gt;, the walk’s last element. A root that cannot be listed is an &lt;code&gt;Err&lt;/code&gt; either way. A root
that is not a directory is &lt;code&gt;NotADirectory&lt;/code&gt; (as &lt;code&gt;walk&lt;/code&gt; always answered) unless &lt;code&gt;includeRoot&lt;/code&gt; asks
for it, when it is the one entry.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Following links, a loop is found by canonical path&lt;/strong&gt;: a link naming a directory whose
&lt;code&gt;canonicalize&lt;/code&gt; equals that of a directory on the walk’s own way down is an entry carrying
&lt;code&gt;Other(&amp;quot;file system loop&amp;quot;)&lt;/code&gt; and is not gone into; &lt;code&gt;stopOnError&lt;/code&gt; makes it the &lt;code&gt;Err&lt;/code&gt;. Only
ancestors count, so two links to one directory are both walked. Device and inode would avoid a
&lt;code&gt;realpath&lt;/code&gt; per directory, but &lt;code&gt;Metadata&lt;/code&gt; does not carry them yet (branch &lt;code&gt;fs-metadata&lt;/code&gt; adds
them); switching is a change inside &lt;code&gt;Walker&lt;/code&gt; with no change to what a program sees. Canonical
paths are asked only when &lt;code&gt;followLinks&lt;/code&gt; is on. Alternatives: a global visited set (would skip a
second link to a directory outside any cycle), a dedicated &lt;code&gt;ErrorKind&lt;/code&gt; (adds a variant every
exhaustive match of &lt;code&gt;ErrorKind&lt;/code&gt; would have to name).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Entry&lt;/code&gt; keeps its fields&lt;/strong&gt;; its kind is &lt;code&gt;isDir&lt;/code&gt; and &lt;code&gt;isLink&lt;/code&gt;, two calls per entry as before.
A &lt;code&gt;kind&lt;/code&gt; field joins it when &lt;code&gt;Metadata.kind&lt;/code&gt; lands. A followed link to a directory has both true.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;find(root, p, …)&lt;/code&gt; answers paths&lt;/strong&gt; (as &lt;code&gt;glob&lt;/code&gt; does), and has a pattern overload matched
against &lt;code&gt;relative&lt;/code&gt;; it takes the options but &lt;code&gt;includeRoot&lt;/code&gt; and &lt;code&gt;postOrder&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;{a,b}&lt;/code&gt; alternation in &lt;code&gt;matches&lt;/code&gt;, &lt;code&gt;matcher&lt;/code&gt; and &lt;code&gt;glob&lt;/code&gt;&lt;/strong&gt;, written out before the pattern is
split into components, so an alternative may hold &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;**&lt;/code&gt; and further braces. &lt;code&gt;{a}&lt;/code&gt; is &lt;code&gt;a&lt;/code&gt;,
&lt;code&gt;{}&lt;/code&gt; and &lt;code&gt;{,x}&lt;/code&gt; have the empty alternative, an unclosed &lt;code&gt;{&lt;/code&gt; is literal, as an unclosed &lt;code&gt;[&lt;/code&gt; is,
and braces escaped or inside a class are literal. The hidden-name rule applies to each written-out
pattern, so &lt;code&gt;{.git,src}&lt;/code&gt; fits &lt;code&gt;.git&lt;/code&gt;. Alternatives: &lt;code&gt;{a}&lt;/code&gt; kept literal (some shells do; no
pattern reads better for it), and alternation inside a component only (forbids
&lt;code&gt;{src,lib}/**&lt;/code&gt;). Review with the user: overlaps the path-helpers item, which also lists &lt;code&gt;{a,b}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;matcher(pattern)&lt;/code&gt; is a function value&lt;/strong&gt; reading the pattern once. Alternative: a &lt;code&gt;Glob&lt;/code&gt;
class; a function value is all a walk filter needs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;proposed&quot;&gt;Proposed&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;fs-handle&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;File&lt;/code&gt; has positioned
&lt;code&gt;readAt&lt;/code&gt;/&lt;code&gt;writeAt&lt;/code&gt;, &lt;code&gt;setLength&lt;/code&gt; (alias &lt;code&gt;truncate&lt;/code&gt;), &lt;code&gt;sync&lt;/code&gt;/&lt;code&gt;syncData&lt;/code&gt;/&lt;code&gt;fullSync&lt;/code&gt; and
&lt;code&gt;deleteOnClose&lt;/code&gt;.&lt;/strong&gt; Positioned calls never move the position and hand over or give up what the
handle buffered (written bytes are drained, read-ahead dropped), so they mix freely with &lt;code&gt;read&lt;/code&gt;
and &lt;code&gt;write&lt;/code&gt;. &lt;code&gt;readAt&lt;/code&gt; loops until &lt;code&gt;max&lt;/code&gt; bytes or the end, so a short answer only means the end;
&lt;code&gt;writeAt&lt;/code&gt; loops over partial writes, so it writes all or answers &lt;code&gt;Err&lt;/code&gt;. &lt;code&gt;syncData&lt;/code&gt; on macOS is
&lt;code&gt;fsync&lt;/code&gt;; &lt;code&gt;fullSync&lt;/code&gt; is the one that empties the drive’s cache. &lt;code&gt;deleteOnClose&lt;/code&gt; is a flag on the
handle that &lt;code&gt;close&lt;/code&gt; honours by removing the name (a file the collector frees is not removed),
built in Avin on &lt;code&gt;remove&lt;/code&gt;, with no new Sysl function. Why: positioned I/O is what random-access
files, stores and concurrent writers need; one handle per lightweight thread keeps the “a file
belongs to the thread that opened it” rule. Alternatives weighed: a &lt;code&gt;Result[long]&lt;/code&gt; partial
write (every caller would loop); marking at open time (&lt;code&gt;createTemp&lt;/code&gt;), which would need a new
open variant. Review with the user: whether delete-on-close should instead be an open option
once Sysl exposes &lt;code&gt;open_with&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-19 (branch &lt;code&gt;train-ax&lt;/code&gt;): &lt;strong&gt;inside brackets whose commas separate items a comma
after a &lt;code&gt;select&lt;/code&gt;‘s one-line arm ends the arm, the &lt;code&gt;select&lt;/code&gt; and the item, as it does a match’s&lt;/strong&gt;,
and a &lt;code&gt;select&lt;/code&gt; on a block’s last line that closes a bracket ends at that line’s comma. Why: the
select chapter says its arms are written as a match’s are, and with the 2026-11-19 rule that a
block’s last line ends at its comma the old reading (the comma list a tuple the arm yields) no
longer parsed at all, failing &lt;code&gt;select_readable_custom&lt;/code&gt;; the rule makes &lt;code&gt;f(select&lt;/code&gt; … &lt;code&gt;-&amp;gt; v, x)&lt;/code&gt;
mean what &lt;code&gt;f(m match&lt;/code&gt; … &lt;code&gt;-&amp;gt; v, x)&lt;/code&gt; means. Alternatives: keeping the tuple reading for &lt;code&gt;select&lt;/code&gt;
alone (one construct reading commas unlike its sibling); an error asking for parentheses either
way. It changes code that compiled before: &lt;code&gt;println(select&lt;/code&gt; … &lt;code&gt;-&amp;gt; &amp;quot;up&amp;quot;, made)&lt;/code&gt; printed a tuple and
now passes two arguments, so that test writes &lt;code&gt;println((select&lt;/code&gt; … &lt;code&gt;-&amp;gt; &amp;quot;up&amp;quot;, made))&lt;/code&gt;. Review with
the user: it changes the meaning of code that compiled before.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (built on branch &lt;code&gt;tls-strand&lt;/code&gt;): &lt;strong&gt;a read of a whole &lt;code&gt;TlsStream&lt;/code&gt; that has to
wait for input while part of a record a &lt;code&gt;writeSome&lt;/code&gt; made is still unsent waits for input OR room,
whichever comes first, and sends that rest as room comes&lt;/strong&gt;; its wait keeps the connection’s time
limit (&lt;code&gt;TimedOut&lt;/code&gt; where it runs out, the unsent rest kept in order for the next read or write).
&lt;code&gt;TcpStream&lt;/code&gt; gains &lt;code&gt;timeout -&amp;gt; Duration&lt;/code&gt;, the limit &lt;code&gt;setTimeout&lt;/code&gt; set, which that wait needs since
the limit may have been set on the TCP connection before TLS began (spec system-library.md, TCP
and TLS). This settles the review question of the &lt;code&gt;pg-flake-0032&lt;/code&gt; entry below. Why: a whole
connection’s &lt;code&gt;writeSome&lt;/code&gt; that sent part of a record left the rest for its next write,
&lt;code&gt;writable()&lt;/code&gt; or close, so a caller that ended a request with &lt;code&gt;writeSome&lt;/code&gt; and then only read left
its peer waiting for the rest while it waited for the peer’s answer, a hang until the time limit.
The one wait cannot be for room alone, since a peer that is itself sending and not reading would
then never be read from (two full connections, each end waiting to write); it cannot be for input
alone, which is the hang. A select over the TCP connection’s &lt;code&gt;readable()&lt;/code&gt; and &lt;code&gt;writable()&lt;/code&gt; waits
for both on the one thread that owns the connection; the runtime’s poller keeps one waiter per
descriptor and direction, and an unsplit connection has only this thread, so the two watches
never meet another waiter (the obstacle that ruled this out for a split connection’s reader).
Alternatives weighed: a whole connection’s &lt;code&gt;writeSome&lt;/code&gt; sending its whole record as the split
writer’s now does (it would break “after &lt;code&gt;writable()&lt;/code&gt; answered &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;writeSome&lt;/code&gt; does not wait”,
which single-threaded select loops rely on, and could deadlock one thread reading and writing a
busy peer); flushing the rest in full before a read waits (the same deadlock, the read waiting for
room while the peer waits for room too); a flush the caller must call (every caller, a generic
&lt;code&gt;StreamWriter&lt;/code&gt; one included, would have to know it). Not covered: a program that, after a
&lt;code&gt;writeSome&lt;/code&gt; left a rest, waits in a &lt;code&gt;select&lt;/code&gt; with only a &lt;code&gt;readable()&lt;/code&gt; arm on the connection; a
select watches one direction per arm, so such a loop keeps a &lt;code&gt;writable()&lt;/code&gt; arm while &lt;code&gt;writable()&lt;/code&gt;
answers &lt;code&gt;false&lt;/code&gt;, as the threads chapter’s write loop does. Review with the user: whether that
select case deserves more (a &lt;code&gt;readable()&lt;/code&gt; that also sends what room allows).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (built on branch &lt;code&gt;pg-flake-0032&lt;/code&gt;): &lt;strong&gt;the writing half of a split TLS
connection sends the whole record each &lt;code&gt;writeSome&lt;/code&gt; makes before it answers, waiting for room for
the rest where the connection has too little&lt;/strong&gt;, refining the 2026-11-15 &lt;code&gt;writeSome&lt;/code&gt; entry for that
half (spec system-library.md, TLS). Why: a &lt;code&gt;writeSome&lt;/code&gt; that kept the rest of its record for a later
call left it unsent where the writer made no later call, and its peer waited for that rest for
ever. pg’s batch writer hit exactly this: its thread sends a batch with the &lt;code&gt;writable()&lt;/code&gt; and
&lt;code&gt;writeSome&lt;/code&gt; loop the threads chapter shows, then ends; when the last &lt;code&gt;writeSome&lt;/code&gt; met a full
connection, the end of the batch never left, the server waited for it, and the reader waited for
the server (about one TLS batch in ten under load). A split writer has a thread of its own and its
reading half reads meanwhile, so waiting there cannot hold up the peer’s answers, which is the
deadlock the 2026-11-15 entry avoided by never waiting. Where the writer’s time limit runs out
first, &lt;code&gt;writeSome&lt;/code&gt; still answers the plaintext TLS took (it has been taken and will go), the rest
kept to go before anything else and &lt;code&gt;writable()&lt;/code&gt; sending it as room comes, as before. With it,
ciphertext a wait that failed did not send is kept in order rather than dropped, on both the
connection and its halves (a timed-out &lt;code&gt;write&lt;/code&gt; used to lose the part of a record it had begun,
breaking the TLS session). Unchanged: a whole &lt;code&gt;TlsStream&lt;/code&gt;‘s &lt;code&gt;writeSome&lt;/code&gt; still never waits after
&lt;code&gt;writable()&lt;/code&gt;, since one thread may be both reading and writing it; its kept rest goes at the
connection’s next write, &lt;code&gt;writable()&lt;/code&gt; or close. Alternatives weighed: the reading half sending the
kept rest while it waits for input (it would wait for room on the descriptor the writer’s select
watches, and the runtime’s poller keeps one waiter a direction, so one of them would never be
woken); a flush the caller must call after its last &lt;code&gt;writeSome&lt;/code&gt; (every caller would have to know
it, and a generic &lt;code&gt;StreamWriter&lt;/code&gt; caller cannot); a low-water mark of a whole record on the socket
so a record always fits after &lt;code&gt;writable()&lt;/code&gt; (not settable on every system); the whole connection’s
&lt;code&gt;writeSome&lt;/code&gt; waiting too (a single thread reading and writing a busy peer could deadlock). Its review
question, whether a whole &lt;code&gt;TlsStream&lt;/code&gt;‘s kept rest should also go while a read waits, is settled by
the &lt;code&gt;tls-strand&lt;/code&gt; entry above: it does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;println-atomic&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;println(x)&lt;/code&gt; and
&lt;code&gt;print(x)&lt;/code&gt; render all their arguments (and &lt;code&gt;println&lt;/code&gt; its new line) first, into a string, and add
that to standard output in ONE write, so a line printed is never split by another thread’s
output&lt;/strong&gt; (spec system-library.md, beside &lt;code&gt;eprintln&lt;/code&gt;‘s same promise). Found when two threads’
&lt;code&gt;println(99)&lt;/code&gt; came out &lt;code&gt;9999\n\n&lt;/code&gt;: &lt;code&gt;println&lt;/code&gt; wrote each value and then the new line as separate
writes. The one write is a single &lt;code&gt;fwrite&lt;/code&gt; on the C stream, which holds the stream’s lock for the
whole call, so another thread’s write lands before or after it and a flush sends it out whole, in
order, however long it is. Rendering happens before the write, outside any lock, so a value slow
or large to render holds no other thread up. Consequences: a value rendered for &lt;code&gt;println&lt;/code&gt; is now
built as a string first (one allocation and copy per call; the digits of &lt;code&gt;println(n)&lt;/code&gt; no longer go
out from the stack); a &lt;code&gt;Display&lt;/code&gt; that itself prints puts its own output before the line rather
than inside it, and one that traps part way leaves none of the line rather than a part. Output
built from several calls, or written to &lt;code&gt;StandardOutput&lt;/code&gt; piece by piece, is still several pieces.
Alternatives weighed: hold the stream’s lock across the whole render (a slow render, or one that
parks the thread or waits on a collection, would stall every printing thread, and a &lt;code&gt;Display&lt;/code&gt;
that prints would deadlock); keep separate writes and promise nothing (the spec already promises
whole lines for standard error, and interleaved lines from threads are the commonest complaint);
a per-thread line buffer in the runtime (more machinery for the same guarantee). Review with the
user: only if the extra allocation per &lt;code&gt;println&lt;/code&gt; shows up in a benchmark that prints heavily.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;opaque-types&lt;/code&gt;): &lt;strong&gt;opaque types are spelled &lt;code&gt;opaque type Name[T…] = Repr&lt;/code&gt;&lt;/strong&gt; at the top level, &lt;code&gt;opaque&lt;/code&gt; a declaration word only before &lt;code&gt;type&lt;/code&gt; and a name. Why: an
opaque type reads as the alias it resembles, with one word saying the difference, and the parser
and formatter treat it as an alias. Alternatives weighed: &lt;code&gt;newtype Name = Repr&lt;/code&gt; (a new keyword for
a small feature); &lt;code&gt;data Name(value: Repr)&lt;/code&gt; with an annotation (a data value is an object, and the
layout is the point); &lt;code&gt;type Name = new Repr&lt;/code&gt; (a modifier inside the body reads as part of the
type).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;opaque-types&lt;/code&gt;): &lt;strong&gt;the representation is seen only in the declaring
module, through &lt;code&gt;Name(r)&lt;/code&gt; and &lt;code&gt;x.repr&lt;/code&gt; (and bare &lt;code&gt;repr&lt;/code&gt; in its impls), with no implicit
conversion either way even inside the module.&lt;/strong&gt; Why: an explicit wrap and unwrap keep every
crossing between the type and its representation visible in the source, which is what the type
exists for, and one rule holds everywhere; &lt;code&gt;repr&lt;/code&gt; is one short name that cannot be confused with
a field of the representation. Alternatives weighed: the type transparent inside its module (the
module’s own code could mix &lt;code&gt;UserId&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt; unnoticed, and the type checker would need two
views of every type); a &lt;code&gt;.value&lt;/code&gt; accessor (a common field name of representations, so it would
shadow or be shadowed); an unwrapping pattern &lt;code&gt;Name(n)&lt;/code&gt; (it reads as a constructor pattern of a
data type, which an opaque type is not, and &lt;code&gt;x.repr&lt;/code&gt; covers it). Review with the user: whether the
module that declares the type should see it as its representation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;opaque-types&lt;/code&gt;): &lt;strong&gt;an opaque type is nominal, &lt;code&gt;Type.Opaque(id, name, args, repr)&lt;/code&gt;, a value type that is boxed only where it becomes an &lt;code&gt;Any&lt;/code&gt; or a trait’s value, and
its box names the opaque type over a reference too.&lt;/strong&gt; Its parameters are invariant and take no
bounds; a phantom parameter is allowed. The representation may not be &lt;code&gt;Nothing&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, a union,
a bare type parameter or name the type. Why: laid out as its representation, a &lt;code&gt;Vector[UserId]&lt;/code&gt;
holds the &lt;code&gt;long&lt;/code&gt;s themselves and the type costs nothing; a box naming the opaque type is what lets
&lt;code&gt;x: Any&lt;/code&gt; be matched as &lt;code&gt;UserId&lt;/code&gt; and never as &lt;code&gt;long&lt;/code&gt; or &lt;code&gt;string&lt;/code&gt;, so the abstraction holds through
&lt;code&gt;Any&lt;/code&gt;. Variance would expose the representation’s own variance, which only the module sees;
bounds have nothing to bound, since the representation’s types hold their own. &lt;code&gt;Nothing&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;,
unions and a bare parameter have no single layout to share. Alternatives weighed: reusing the
representation’s box for a reference representation (cheaper, but &lt;code&gt;x is _: string&lt;/code&gt; would find an
&lt;code&gt;Email&lt;/code&gt;); covariant parameters (unsound for a mutable representation); refusing phantom
parameters as an alias does (they are a main use: typed identifiers).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;opaque-types&lt;/code&gt;): &lt;strong&gt;an opaque type is no type constructor&lt;/strong&gt;: a generic
one is refused for a constructor parameter &lt;code&gt;F[_]&lt;/code&gt;, and an opaque type declares no constructor
parameter of its own; it is an ordinary type argument of &lt;code&gt;F[A]&lt;/code&gt;. Why: every instance of a
constructor parameter’s application is laid out as an object, which an opaque type over &lt;code&gt;long&lt;/code&gt;
is not, and a representation &lt;code&gt;F[int]&lt;/code&gt; would leave the opaque type’s layout to each use. Refusing
both is the sound position that can be loosened later. Alternatives weighed: accepting an opaque
type over a reference type as a constructor (sound for the layout, but it would make the rule
depend on the representation, which outside code should not see); accepting &lt;code&gt;opaque type W[F[_]]&lt;/code&gt;
(the layout question is only deferred, to every use).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;opaque-types&lt;/code&gt;): &lt;strong&gt;a refined variant’s result does not name an opaque
type&lt;/strong&gt; (&lt;code&gt;Newest -&amp;gt; Query[UserId]&lt;/code&gt;, &lt;code&gt;Query[Id[User]]&lt;/code&gt;, &lt;code&gt;Query[Vector[UserId]]&lt;/code&gt; are refused); a
variant’s fields may be of opaque types and the type’s own argument may be one. Why: a &lt;code&gt;match&lt;/code&gt;
on a refined variant will learn type equalities from the result, and whether one learning
&lt;code&gt;R = UserId&lt;/code&gt; should see the representation inside the opaque type’s module is not decided; keeping
opaque types out of results is sound and can be loosened once matching on refined variants is
built. Alternatives weighed: accepting them as nominal types now (sound for values and layouts,
but it fixes the answer to the open question before the matching it affects exists).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;opaque-types&lt;/code&gt;): &lt;strong&gt;equality and hashing are the representation’s;
every other trait comes from an impl, which takes the trait’s default bodies; an opaque type
derives nothing and has no supertype.&lt;/strong&gt; Why: every Avin type has &lt;code&gt;==&lt;/code&gt; and a hash, so an opaque
type is a &lt;code&gt;Map&lt;/code&gt; key and a &lt;code&gt;Set&lt;/code&gt; element without ceremony, while order and printing are choices the
module makes for its type (an &lt;code&gt;Email&lt;/code&gt; may print as &lt;code&gt;&amp;lt;…&amp;gt;&lt;/code&gt;, a &lt;code&gt;UserId&lt;/code&gt; may have no order). Default
bodies run on the boxed value, so &lt;code&gt;compare&lt;/code&gt; gives &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;less&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; and sorting. Alternatives
weighed: &lt;code&gt;derives Ord, Display&lt;/code&gt; forwarding to the representation (convenient, but it would show
the representation’s text and order outside the module by default); inheriting every trait of the
representation (the opaque type would leak its representation’s whole interface).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;dwarf&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;-g&lt;/code&gt; is asked for, never implied, and only &lt;code&gt;build&lt;/code&gt; and &lt;code&gt;emit-llvm&lt;/code&gt;
take it.&lt;/strong&gt; Not even &lt;code&gt;-O0&lt;/code&gt; turns it on. Why: a &lt;code&gt;-g&lt;/code&gt; build is slower and larger (every unit carries
the metadata, function text is never cached, macOS runs &lt;code&gt;dsymutil&lt;/code&gt;), and &lt;code&gt;run&lt;/code&gt;/&lt;code&gt;test&lt;/code&gt; executables
live in the cache where no one points a debugger; a flag keeps every existing build exactly as it
was. Alternatives: &lt;code&gt;-O0&lt;/code&gt; implying &lt;code&gt;-g&lt;/code&gt; (the usual “debug build”; costs every &lt;code&gt;-O0&lt;/code&gt; corpus and test
build), &lt;code&gt;run -g&lt;/code&gt;/&lt;code&gt;test -g&lt;/code&gt; (useful for a test under lldb, but the cached executable is not where a
user expects it; easy to add later). Review with the user: whether &lt;code&gt;-O0&lt;/code&gt; should mean “debug build”.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;dwarf&lt;/code&gt;): &lt;strong&gt;what the debugger is told.&lt;/strong&gt; Functions are named by their symbols
(&lt;code&gt;&amp;lt;program&amp;gt;.fact&lt;/code&gt;, &lt;code&gt;&amp;lt;program&amp;gt;.twice[int]&lt;/code&gt;, &lt;code&gt;&amp;lt;program&amp;gt;.main.lambda#1&lt;/code&gt;) as the linkage name, with
the program’s own module prefix left off the readable name; lldb shows the linkage name. The
compile unit says &lt;code&gt;DW_LANG_C&lt;/code&gt;, so lldb reads the basic types in its own words (&lt;code&gt;double&lt;/code&gt;,
&lt;code&gt;char32_t&lt;/code&gt;). &lt;code&gt;char&lt;/code&gt; is a UTF-32 code point, &lt;code&gt;byte&lt;/code&gt; unsigned, &lt;code&gt;bool&lt;/code&gt; a byte; a reference is a
pointer to an opaque structure named by its Avin type. A local a lambda shares (boxed) is not
described, nor is a local the compiler made. DWARF version 4. Why: each is the smallest choice that
makes &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;bt&lt;/code&gt; and &lt;code&gt;frame variable&lt;/code&gt; work with no lldb plugin. Alternatives: a vendor language code
(lldb then treats frames as unknown language), describing objects’ fields as DWARF structures
(a larger item: layouts per descriptor, unions, generics), showing strings as text (needs an lldb
data formatter shipped with avin), describing boxed locals through &lt;code&gt;DW_OP_deref&lt;/code&gt; (small, later).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;dwarf&lt;/code&gt;): &lt;strong&gt;the code taking parameters in has no line&lt;/strong&gt;, so lldb’s breakpoint at a
function’s first line lands after the parameters are stored where their variables are read (a
lambda’s parameter otherwise read a stale slot). A call there still gets the function’s own
location, which LLVM’s verifier asks of every call in a function with debug information.
Alternative: placing that code at the function’s name, as it was first built: lldb then stopped
before the stores and showed the slot’s previous value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;dwarf&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;-g&lt;/code&gt; build never reads or writes function text in the instance
cache, and keeps its lowered code apart (&lt;code&gt;program-O2-g&lt;/code&gt;)&lt;/strong&gt;; each &lt;code&gt;Locate&lt;/code&gt; in a cached entry is kept
counted from its declaration’s start, as trap sites are. Why: metadata is numbered across the module
and locations follow lines no function key covers, so cached text would carry stale lines; the
lowered code is still reused, and &lt;code&gt;AVIN_INCREMENTAL=verify&lt;/code&gt; matches a clean build. Alternatives:
per-function metadata numbering with a renumbering pass (the text cache would then work under
&lt;code&gt;-g&lt;/code&gt;), or a key over absolute positions (every edit above a function would relower it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;dwarf&lt;/code&gt;): &lt;strong&gt;codegen units carry all of the module’s debug metadata&lt;/strong&gt;, as every
other module-level line, so any line moved anywhere changes every unit’s text and recompiles every
unit of a &lt;code&gt;-g&lt;/code&gt; build. Plan to do better when it matters: the splitter follows &lt;code&gt;!N&lt;/code&gt; references from
each unit’s definitions through the metadata lines and renders only the nodes reached (plus the
compile unit and the flags), which also shrinks each unit.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;dwarf&lt;/code&gt;): &lt;strong&gt;the stack overflow report stays without a place.&lt;/strong&gt; The handler runs on
its own stack inside a signal, where reading DWARF (or running &lt;code&gt;atos&lt;/code&gt;, a process) is not safe, and a
build without &lt;code&gt;-g&lt;/code&gt; has no line table at all. Plan: in a &lt;code&gt;-g&lt;/code&gt; build the handler writes the faulting
program counter and the image’s load address (&lt;code&gt;avin: trap: stack overflow at pc 0x… (image 0x…)&lt;/code&gt;),
and &lt;code&gt;avin&lt;/code&gt; (or a user with &lt;code&gt;atos -o prog.dSYM -l &amp;lt;image&amp;gt; &amp;lt;pc&amp;gt;&lt;/code&gt;) turns it into &lt;code&gt;file:line&lt;/code&gt; after the
process has stopped; a table of function start addresses with their names, emitted as a constant,
would let the handler name the function itself, without lines, at any &lt;code&gt;-g&lt;/code&gt; level. Neither is
built: the first needs a runtime change and a symbolizing step, the second a table the emitter does
not make yet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A package’s tests import its gated modules; a test module is read only while every module it
imports is&lt;/strong&gt; (&lt;a href=&quot;/spec/packages/#how-a-feature-gates-modules&quot;&gt;packages&lt;/a&gt;; branch &lt;code&gt;gated-tests&lt;/code&gt;).
The tests were fenced as an always-compiled module, so a test of a gated module had to live inside
that module, and a &lt;code&gt;tests&lt;/code&gt; file importing it was refused even under &lt;code&gt;avin test&lt;/code&gt;, which turns every
feature on. Now &lt;code&gt;tests&lt;/code&gt; and the modules under it have no fences: they may import every module of
the package and its optional dependencies. A build with a feature off passes over each test module
importing a module that is off, and, repeated to the end, each test module importing one passed
over; the rest are read and run. The module stays the unit, so a file of &lt;code&gt;tests&lt;/code&gt; importing a gated
module takes all of &lt;code&gt;tests&lt;/code&gt; with it when that feature is off. &lt;em&gt;Why&lt;/em&gt;: the spec already says
&lt;code&gt;avin test&lt;/code&gt; has every feature on, so the tests see the whole package; and the package’s own
&lt;code&gt;tests&lt;/code&gt; are compiled by &lt;code&gt;build&lt;/code&gt; and &lt;code&gt;run&lt;/code&gt; too, so a selection-independent refusal was the only
thing keeping a build with features off working; deriving each test module’s gate from its imports
keeps that guarantee with no annotation to write. &lt;em&gt;Alternatives&lt;/em&gt;: allowing &lt;code&gt;tests&lt;/code&gt; to import gated
modules only under &lt;code&gt;avin test&lt;/code&gt; (a build or &lt;code&gt;avin test --no-default-features&lt;/code&gt; would then fail at
the import, so the minimal configuration could not be tested); letting a feature list
&lt;code&gt;tests.server&lt;/code&gt; explicitly (works, but repeats in the manifest what the imports already say);
skipping single files rather than modules (finer, but a file of &lt;code&gt;tests&lt;/code&gt; could then lose a helper
another file of it uses, breaking only the build with the feature off). Not covered: a test
importing an optional dependency’s module directly while that dependency is not taken is reported
as an unknown module, since a dependency not taken is not read and its modules are unknown; such a
test reaches the dependency through the package’s gated module. Review with the user: whether a
test module passed over should be named in &lt;code&gt;avin test&lt;/code&gt;‘s output rather than silently absent.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An import refused for its module is one error per import declaration&lt;/strong&gt;, not one per name it
imports (branch &lt;code&gt;gated-tests&lt;/code&gt;): &lt;code&gt;import a.b.{c, d}&lt;/code&gt; refused as gated, as an optional dependency’s,
or as a standard-library module that does not exist, is reported once, at the first name;
two import lines are two errors. &lt;em&gt;Why&lt;/em&gt;: the error is about the module, which the declaration names
once. &lt;em&gt;Alternatives&lt;/em&gt;: one per module per file (hides the second line’s error).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;intersection-bounds&lt;/code&gt;): &lt;strong&gt;several bounds on one type parameter are
joined with &lt;code&gt;&amp;amp;&lt;/code&gt;, the one spelling, and an intersection is a bound only, never a type.&lt;/strong&gt;
&lt;code&gt;[T: Ord &amp;amp; Display]&lt;/code&gt; replaces &lt;code&gt;[T: Ord + Display]&lt;/code&gt; everywhere type parameters are declared
(functions, methods, classes, data types, traits, actors, impl headers, after a lower bound);
&lt;code&gt;+&lt;/code&gt; between bounds is a parse error that says to write &lt;code&gt;&amp;amp;&lt;/code&gt;, and the library, tests and docs are
rewritten. Each operand is a trait or a class, &lt;strong&gt;at most one a class&lt;/strong&gt; (a second class is an
error naming both, a subclass of the first included), and &lt;strong&gt;each written once&lt;/strong&gt; (the same trait
at the same type arguments twice is an error; &lt;code&gt;Make[int] &amp;amp; Make[long]&lt;/code&gt; are two). &lt;strong&gt;Name clashes&lt;/strong&gt;:
methods of one name from two bounds are overloads, resolved by parameter types; two of the same
parameter types are not an error to declare, only a call both accept is, as the existing
ambiguous-call error at the generic definition. &lt;strong&gt;&lt;code&gt;A &amp;amp; B&lt;/code&gt; is not a type&lt;/strong&gt;: written as a
parameter’s, a field’s, a &lt;code&gt;val&lt;/code&gt;‘s, a result’s, a type argument’s or a lower bound’s type it is a
parse error that shows &lt;code&gt;[T: A &amp;amp; B](x: T)&lt;/code&gt; instead. Why: &lt;code&gt;&amp;amp;&lt;/code&gt; reads as “and”, which is what
conformance to every bound means, and makes the bound read as the intersection it is, where &lt;code&gt;+&lt;/code&gt;
reads as arithmetic and was the only use of &lt;code&gt;+&lt;/code&gt; in a type; one spelling, since two ways to write
one thing is the kind of choice the language avoids. Bounds only, because a type parameter
already gives a value of two traits everything an intersection type would, with each instance
calling its type argument’s methods directly; an intersection &lt;em&gt;type&lt;/em&gt; would need a new value
representation (a pair of method tables, or a table per combination), subtyping rules against
unions and variance, and reification for &lt;code&gt;is&lt;/code&gt; — a large addition the language’s programs have
not asked for, and a nominal type system with declared traits covers it by declaring a trait
that requires both (&lt;code&gt;trait Shown: Named, Sized&lt;/code&gt;). At most one class, because a class extends one
superclass, so two unrelated classes can never both be met and a subclass already implies its
superclass. Alternatives weighed: keeping &lt;code&gt;+&lt;/code&gt; (the existing spelling, no source change, but reads
as addition, and the user asked for &lt;code&gt;&amp;amp;&lt;/code&gt;); accepting both (two spellings of one thing);
intersection types in annotations, with &lt;code&gt;A &amp;amp; B &amp;lt;: A&lt;/code&gt;, commutativity, distribution over unions and
a dual-table layout (left out for the reasons above; this decision leaves room to add it, since
&lt;code&gt;A &amp;amp; B&lt;/code&gt; in a type position is an error today, not something else); allowing redundant bounds
silently (a repeated bound is always a slip). Review with the user: whether &lt;code&gt;A &amp;amp; B&lt;/code&gt; should become
a type in annotations later, and whether to keep the &lt;code&gt;+&lt;/code&gt; diagnostic once existing code has moved
(it costs nothing and helps code written before the change). Packages outside this repository
that still write &lt;code&gt;+&lt;/code&gt; (the &lt;code&gt;json&lt;/code&gt; package’s tests) move to &lt;code&gt;&amp;amp;&lt;/code&gt; with the release that carries this.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Byte offsets inside a character&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#string&quot;&gt;types&lt;/a&gt;, branch &lt;code&gt;fix-charat-boundary&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;charAt&lt;/code&gt; at an offset inside a character’s encoding traps, &lt;code&gt;charAt offset is not a character boundary&lt;/code&gt;, as slicing there does; the searches never trap on such an offset and never
answer one.&lt;/strong&gt; &lt;code&gt;indexOf(p, from)&lt;/code&gt; and &lt;code&gt;indexWhere(f, from)&lt;/code&gt; from inside a character start at the
next one, so &lt;code&gt;&amp;quot;café&amp;quot;.indexOf(&amp;quot;&amp;quot;, 4)&lt;/code&gt; is 5; &lt;code&gt;lastIndexOf(p, end)&lt;/code&gt; and &lt;code&gt;lastIndexWhere(f, end)&lt;/code&gt; from
inside one search back from the character it belongs to, so &lt;code&gt;&amp;quot;café&amp;quot;.lastIndexOf(&amp;quot;&amp;quot;, 4)&lt;/code&gt; is 3; and
&lt;code&gt;startsWith(&amp;quot;&amp;quot;, at)&lt;/code&gt; is false inside a character, since the empty string occurs only where a
character begins or at the end. Why: &lt;code&gt;charAt&lt;/code&gt; and &lt;code&gt;slice&lt;/code&gt; read the text at the offset given, so an
offset that is not a place in the text is the caller’s mistake, the trap the spec gives slicing;
a search is asked “where at or after (before) this”, which has an exact answer from any offset,
and answering only offsets where a character begins means every result can be fed to &lt;code&gt;charAt&lt;/code&gt; or
&lt;code&gt;slice&lt;/code&gt; again. The cost on a character boundary is one comparison on a lead byte, none on ASCII.
Alternatives weighed: trapping in the searches too (a search from &lt;code&gt;i + 1&lt;/code&gt; over text with
characters beyond ASCII would then trap where the same search over ASCII succeeds); answering the
offset itself for an empty needle, as before (a result that traps when sliced at).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Initialization&lt;/strong&gt; (&lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;declarations&lt;/a&gt;, branch &lt;code&gt;init-design&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;deadlock-dump&lt;/code&gt;): &lt;strong&gt;A deadlock of the whole program is a trap; a partial
one is not found&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#deadlock&quot;&gt;diagnostics&lt;/a&gt;). The main thread checks when it begins
a wait with no limit, and again each time a worker finds no lightweight thread running or ready
while it waits: the program is deadlocked where no lightweight thread is running or ready, no
timer is set, no thread waits on a socket, no thread the program did not start is attached and no
&lt;code&gt;@threaded&lt;/code&gt; callback is held. Every wake goes through one counter, so a check whose count did not
move between its first look and its last saw one moment of the program and cannot report a
thread that ran meanwhile. The report is &lt;code&gt;avin: trap: deadlock: all threads are waiting&lt;/code&gt; and a line
per thread, the trap’s exit status, and the exit hooks run after it as after any trap. Why: it is
the case a program can never leave, it costs nothing until &lt;code&gt;main&lt;/code&gt; waits (one counter increment
per wake, one clock read per wait for the dump), and a check made only from &lt;code&gt;main&lt;/code&gt;‘s own wait
needs no thread of its own. Alternatives weighed: a monitor that looks periodically (a thread or a
tick for every program, and latency); finding cycles of lock holders (catches partial deadlocks,
but needs owner tracking on every lock and misses channels and conditions, which have no owner);
reporting a held &lt;code&gt;@threaded&lt;/code&gt; callback or an attached foreign thread as deadlocked too (a C thread
may call back at any time, so that would be a false report). Review with the user: whether a
partial deadlock, found by cycles among lock holders and joins, is wanted later.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;deadlock-dump&lt;/code&gt;): &lt;strong&gt;What a thread waits on is named by the runtime’s own queue&lt;/strong&gt;:
a lock, a condition, a join, a sleep, a socket; a condition the library makes for a channel’s
receive or send, a future or an executor’s work says so, through the intrinsic
&lt;code&gt;condition_new_kind&lt;/code&gt;, which &lt;code&gt;Condition&lt;/code&gt;‘s constructor reaches with a second parameter the library
alone can pass (a &lt;code&gt;Condition&lt;/code&gt; needs the library’s private &lt;code&gt;Lock&lt;/code&gt;). A channel’s own lock is “a
lock”. Threads are numbered from 1 in the order they started, not by their identity. A pool’s
idle workers are left out of the deadlock report, whose length would otherwise follow the
machine’s processors, and listed in the dump. Alternatives weighed: a label set around each wait
by the library (a call on every wait); naming waits only by the runtime primitive (“a condition”
for every channel and future, which says little).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;deadlock-dump&lt;/code&gt;): &lt;strong&gt;The quit signal writes a thread dump and the program goes
on.&lt;/strong&gt; A handler in C writes a byte to a pipe; a thread started with the program, with every signal
blocked, reads it and writes the dump, since a handler may not take the scheduler’s locks. A
program that watches the signal hears it instead; one started with it ignored keeps it ignored.
Why: the program under inspection keeps running, which is what a dump is for. Alternatives
weighed: writing the dump from the handler (not safe there); starting the thread only on first
use (a handler cannot start one); ending the program after the dump (loses the program being
looked at). Cost: one thread and one pipe for every program.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;deadlock-dump&lt;/code&gt;): &lt;strong&gt;A thread dump names no functions.&lt;/strong&gt; A frame of the shadow
stack holds its previous frame and its count of slots, nothing naming its function, and walking
the native stack would need a table from code addresses to Avin names, which the compiler does
not emit (the stack-overflow trap has no place for the same reason). Alternatives weighed: a
function’s descriptor stored in each frame (a store on every call); emitting an address table
and unwinding the native stack (a table per program and an unwinder for each platform). Review
with the user: which of the two, if a stack in the dump is wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;deadlock-dump&lt;/code&gt;): &lt;strong&gt;A corpus program’s &lt;code&gt;// stderr: times vary&lt;/code&gt; shows every number
before &lt;code&gt; ms&lt;/code&gt; in its standard error as &lt;code&gt;n&lt;/code&gt;&lt;/strong&gt;, so a thread dump’s durations do not make the test
depend on the machine. Alternative: a dump without durations (loses what a dump is for).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CPU time is read from the kernel’s accounting: &lt;code&gt;getrusage&lt;/code&gt; and &lt;code&gt;wait4&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;cpu-time&lt;/code&gt;,
&lt;a href=&quot;/spec/system-library/#cpu-time&quot;&gt;CPU time&lt;/a&gt;). &lt;code&gt;CpuTime(user: Duration, system: Duration)&lt;/code&gt; with
&lt;code&gt;total&lt;/code&gt; and &lt;code&gt;Add&lt;/code&gt;; &lt;code&gt;process.cpuTime()&lt;/code&gt; and &lt;code&gt;process.childrenCpuTime()&lt;/code&gt; (&lt;code&gt;RUSAGE_SELF&lt;/code&gt;,
&lt;code&gt;RUSAGE_CHILDREN&lt;/code&gt;) answer it plainly, not in a &lt;code&gt;Result&lt;/code&gt;, since &lt;code&gt;getrusage&lt;/code&gt; fails only for a &lt;code&gt;who&lt;/code&gt;
it does not know; &lt;code&gt;waitPidCpu&lt;/code&gt; / &lt;code&gt;tryWaitPidCpu&lt;/code&gt; beside &lt;code&gt;waitPid&lt;/code&gt; / &lt;code&gt;tryWaitPid&lt;/code&gt;; and
&lt;code&gt;Child.cpuTime()&lt;/code&gt;, a pipeline’s stages and a sequence’s parts added. Why: a job manager that
samples its jobs with &lt;code&gt;ps&lt;/code&gt; cannot see the CPU of sub-processes that have already exited, and the
kernel folds each reaped process’s time into its parent’s, so a wait that reads it gives a whole
tree’s. Alternatives weighed: changing &lt;code&gt;waitPid&lt;/code&gt; to answer the pair (breaks every caller; a
return type cannot be overloaded); a &lt;code&gt;ProcessUsage&lt;/code&gt; record with the other &lt;code&gt;rusage&lt;/code&gt; counters (peak
memory, faults, context switches — memory is in different units per platform, and nothing asks
for them yet, so they can join later without breaking &lt;code&gt;CpuTime&lt;/code&gt;); &lt;code&gt;Child.cpuTime()&lt;/code&gt; as an
&lt;code&gt;Option&lt;/code&gt; empty before the wait (a running command’s reaped parts would then be invisible, and
“nothing reaped yet” is already &lt;code&gt;Zero&lt;/code&gt;). Review with the user: the names &lt;code&gt;waitPidCpu&lt;/code&gt; /
&lt;code&gt;tryWaitPidCpu&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A started program is reaped by the library with &lt;code&gt;wait4&lt;/code&gt;, not by its Sysl &lt;code&gt;Spawned&lt;/code&gt;&lt;/strong&gt; (branch
&lt;code&gt;cpu-time&lt;/code&gt;). Sysl’s &lt;code&gt;Spawned.wait&lt;/code&gt; and &lt;code&gt;try_wait&lt;/code&gt; reap with &lt;code&gt;waitpid&lt;/code&gt; and drop the usage, so the
runtime (&lt;code&gt;runtime/avin/rt/cpu.sysl&lt;/code&gt;) reaps the program itself and the &lt;code&gt;Spawned&lt;/code&gt; is then let go of
with &lt;code&gt;detach&lt;/code&gt;. A time limit is kept by the library in consequence, as Sysl kept it: polled with a
backoff to 16 ms up to the deadline, then signal 15, a 200 ms grace, signal 9, and a final wait,
the status &lt;code&gt;TimedOut&lt;/code&gt; with the CPU time it used. Why: the alternative that keeps Sysl as the
reaper, reading &lt;code&gt;RUSAGE_CHILDREN&lt;/code&gt; before and after a wait, is wrong whenever two threads reap at
once, which a job manager’s do. Alternatives weighed: asking Sysl for a &lt;code&gt;wait&lt;/code&gt; that answers usage
(the better home; reported to the sysl session as a gap, and this binding moves to it when it
exists); reaping through Sysl and leaving &lt;code&gt;cpuTime()&lt;/code&gt; empty for commands (no answer to the item).
Review with the user: two reapers of one kind in the stack until Sysl grows the call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Initialization is proved at compile time, by order and by withholding &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt; (branch
&lt;code&gt;init-design&lt;/code&gt;, &lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;Initialization&lt;/a&gt;). No field, module-level
value or &lt;code&gt;lazy val&lt;/code&gt; is read before it is set: an object’s fields are set in the order written and
&lt;code&gt;self&lt;/code&gt; is withheld from everything that could read one later until the last is set; module values
are computed in the order their initializers’ reach requires, a cycle an error; a &lt;code&gt;lazy val&lt;/code&gt; is
the explicit opt-out, its own cycles an error where its code reaches them, a trap only through a
function it hands on. Why: it is sound with no annotation and no cost per read, it keeps the rules
Avin already enforces (every probe of them held), and each rule’s proof is a short argument a
reader can check. Alternatives weighed: a checker of object states (an object cold, then warm,
then hot, a parameter or a method declared to accept a cold object) accepts more, such as passing
a half-made object to a helper that only stores it, but needs those annotations and a far larger
analysis, and the code it would admit is rare; a default value in every field before its
initializer (a wrong value read silently, and Avin has no value every type can hold); a check on
every field read (a cost on every read, and a trap where an error was possible); ordering
modules by their imports (an import cycle would be an error, or the order a guess); making every
module value lazy (a gate on every read, and cycles found only when they run).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A superclass’s arguments use nothing of the object, functions made there included&lt;/strong&gt; (branch
&lt;code&gt;init-design&lt;/code&gt;). A lambda, an argument passed by name, a local function or a method value in them
that uses a field, a method or &lt;code&gt;self&lt;/code&gt; is an error; class parameters and module values are read
freely. Why: avin 0.0.21 lets such a function through, and a superclass calling it in its body
reads a field before it is set: &lt;code&gt;0&lt;/code&gt; for a number, a crash for a string, a vector or a generic
field (a soundness hole, the build plan’s first item). Alternatives weighed: allowing a function
that reads only inherited fields of a class whose constructor finished before (it needs the
superclass chain’s timing at each read, for code no library or example writes); a mark on a
parameter the constructor may call during construction (an annotation for a rare shape).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An object’s own name in its body is &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt; (branch &lt;code&gt;init-design&lt;/code&gt;). &lt;code&gt;O.k&lt;/code&gt; obeys the rule &lt;code&gt;k&lt;/code&gt;
does; in a method, a lambda made after the last field or a lazy initializer, it makes the object
need nothing more. Why: today the name counts as the module value, so a lazy field or a late
lambda naming its own object is refused as a cycle while the bare name is accepted, a false error
with no unsoundness behind it. Alternatives weighed: keeping the refusal (sound, but the two
spellings of one read disagree); counting only code the body runs (the same result, reached by
the module order rather than by the object rules, which then speak of the name twice).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;lazy val&lt;/code&gt; cycle its own code reaches is a compile error; a read through a handed-on function
traps&lt;/strong&gt; (branch &lt;code&gt;init-design&lt;/code&gt;). The reach is the module order’s (calls, every implementation a
dispatched call or an operator may reach, other lazy values’ initializers), without the lambdas,
by-name arguments and method values the initializer makes; for a field, only reads of the same
object (bare name, &lt;code&gt;self.&lt;/code&gt;, methods called on &lt;code&gt;self&lt;/code&gt;) count. Why: a cycle the code always makes
is found where it is written rather than when it runs, while a value referring to itself through
a function it hands on (&lt;code&gt;lazy val ones = LazyList.cons(1, ones)&lt;/code&gt;, a handler naming its button) is
the reason &lt;code&gt;lazy&lt;/code&gt; exists and stays legal; a reach that followed handed-on functions would refuse
those, and one through another instance’s field would refuse recursion over a structure (a
node’s depth). Alternatives weighed: the trap alone (today’s: a cycle anyone could see waits for
a run to reach it); following every function value to every lambda of its type in the program
(sound without a trap, but it refuses the knots and the handlers). &lt;strong&gt;Review with the user:&lt;/strong&gt;
through dispatch the reach counts every override, so a lazy value calling a trait method one of
whose implementations reads the value is refused even where that implementation never runs, as
module values already are.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (branch &lt;code&gt;init-3&lt;/code&gt;): &lt;strong&gt;the module-level part of the
&lt;code&gt;lazy val&lt;/code&gt; rule, and making a lazy field needs nothing.&lt;/strong&gt; &lt;code&gt;Uses&lt;/code&gt; keeps the functions code calls
(with every implementation a call through a method table or an operator may reach, and the
initializers of the lazy values it reads) apart from those it makes; the lazy reach follows only
the first, stopping at another module-level lazy value’s initializer and naming that value, so
the error is &lt;code&gt;the `lazy val` `first` needs its own value to initialize: `first` → `second` → `first` &lt;/code&gt;, a value on its own as &lt;code&gt;`l` → `l`&lt;/code&gt;, reported from the chain’s earliest-declared
member, and a value that only reaches a chain is not named. The module order still follows both,
except a &lt;code&gt;lazy val&lt;/code&gt; field’s initializer where a constructor makes it: only a read of the field
runs it, and every read is a call of it, which the order follows. Why: it follows from the
chapter (the order needs what the body runs while the object is made), and it removes a false
cycle — two objects whose lazy fields read each other, or a module value holding an object whose
lazy field reads that value, were refused. Alternatives weighed: the self-cycle worded as the
module order’s (&lt;code&gt;is needed by its own initializer&lt;/code&gt;), which would give one rule two shapes of
message; dropping every made function from the order (unsound: a lambda the initializer makes
and calls reads what it reads).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-14 (branch &lt;code&gt;init-4&lt;/code&gt;): &lt;strong&gt;the field and local parts of
the &lt;code&gt;lazy val&lt;/code&gt; rule.&lt;/strong&gt; A field’s initializer is followed with the object located where its code
holds it: the class body’s &lt;code&gt;self&lt;/code&gt; it captures, a local given it (&lt;code&gt;val me = self&lt;/code&gt;), the parameter
a called function or method receives it in, and, for an object, every read through the object’s
name anywhere in the program. A call through a method table on the object reaches the override of
every class descending from the one declaring the field; an operator applied to it, the core
trait method of those classes; a local function, the object where its caller sees it. A read of
the same field of the object is a node of the chain, a read of another instance’s is not
followed, and the chain, worded and placed as the module-level one, names lazy fields only. A
local &lt;code&gt;lazy val&lt;/code&gt; is followed through its block’s code and the local functions it calls, the
other local lazy values it reads being the chain’s nodes. A cycle through a module-level lazy
value that reads an object’s field is the module-level value’s cycle as well and is reported for
both. Why: it follows from the chapter’s “only a read of the same object counts”, which a function
given &lt;code&gt;self&lt;/code&gt; or a read through an object’s one name is as much as a method called on &lt;code&gt;self&lt;/code&gt;;
anything less leaves the same cycle to the run-time trap by a change of spelling. Alternatives
weighed: only bare names, &lt;code&gt;self.&lt;/code&gt; and methods called on &lt;code&gt;self&lt;/code&gt; (the chapter’s examples, but
&lt;code&gt;helper(self)&lt;/code&gt; would then trap at run time); following every value of the object’s class (it
would refuse the recursion over a structure, a node’s depth, that the chapter keeps legal).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A lazy initializer waiting for a thread that reads the same value is not detected&lt;/strong&gt; (branch
&lt;code&gt;init-design&lt;/code&gt;). It waits for ever, as threads waiting for one another do
(&lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt;). Why: Avin detects no deadlock but a lock taken twice, and a cycle
through two lazy values’ own code is now a compile error, which leaves only a read through a
function handed to the other thread. Alternative weighed: the runtime following a waiting read
through the initializing thread’s own wait (a &lt;code&gt;join&lt;/code&gt;, another lazy value) and trapping when the
chain returns to the reader, cheap on the slow path. &lt;strong&gt;Review with the user:&lt;/strong&gt; it is liveness, not
soundness, but it is the one way a lazy read can still hang.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The security primitives an API server needs&lt;/strong&gt; (branch &lt;code&gt;security&lt;/code&gt;; &lt;a href=&quot;/spec/system-library/#avinencoding&quot;&gt;&lt;code&gt;avin.encoding&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;/spec/system-library/#avincrypto&quot;&gt;&lt;code&gt;avin.crypto&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;/spec/system-library/#avinrandom&quot;&gt;&lt;code&gt;avin.random&lt;/code&gt;&lt;/a&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a new module &lt;code&gt;avin.encoding&lt;/code&gt; holds hexadecimal, base64 and base64url&lt;/strong&gt; (&lt;code&gt;toHex&lt;/code&gt;,
&lt;code&gt;fromHex&lt;/code&gt;, &lt;code&gt;toBase64&lt;/code&gt;, &lt;code&gt;fromBase64&lt;/code&gt;, &lt;code&gt;toBase64Url&lt;/code&gt;, &lt;code&gt;fromBase64Url&lt;/code&gt;, &lt;code&gt;DecodeError&lt;/code&gt;), and
&lt;code&gt;toHex&lt;/code&gt; moved there from &lt;code&gt;avin.crypto&lt;/code&gt;, which keeps offering it with &lt;code&gt;export avin.encoding.toHex&lt;/code&gt;,
so &lt;code&gt;import avin.crypto.toHex&lt;/code&gt; still works. Why: base64 is not cryptography (data URLs, Basic
authentication, binary in JSON all use it), and hexadecimal in one module and its decoder in
another would split one encoding. Alternatives weighed: everything in &lt;code&gt;avin.crypto&lt;/code&gt; (one import for
a server, but a module named for secrets would hold plain encodings); &lt;code&gt;fromHex&lt;/code&gt; beside &lt;code&gt;toHex&lt;/code&gt; in
&lt;code&gt;avin.crypto&lt;/code&gt; and base64 alone in &lt;code&gt;avin.encoding&lt;/code&gt; (hexadecimal split across two modules).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;decoding is strict, one function per alphabet&lt;/strong&gt;: &lt;code&gt;fromBase64&lt;/code&gt; takes only the standard
alphabet with its &lt;code&gt;=&lt;/code&gt; padding, &lt;code&gt;fromBase64Url&lt;/code&gt; only the URL-safe one with no &lt;code&gt;=&lt;/code&gt;; whitespace and
line breaks are refused, and so is a last digit whose unused bits are not zero (RFC 4648 §3.5
allows a decoder to refuse it). Each byte sequence then has exactly one spelling, so a token or a
signature cannot be sent in a second form that compares unequal as text but decodes equal.
&lt;code&gt;fromHex&lt;/code&gt; takes either case (a digit’s case carries no bits). Errors are checked in order:
characters, then padding, then length, then unused bits, so the first offset named is the first
character wrong. Why: the module exists for an API server reading untrusted text, where
malleability is a defect. Alternatives weighed: Sysl’s forgiving decoder (either alphabet, optional
padding, unused bits ignored), which is friendlier to sloppy writers but accepts many spellings of
one value; a &lt;code&gt;lenient&lt;/code&gt; flag (two behaviours to test and document for no current need). Review with
the user: a reader of MIME-wrapped base64 must strip its line breaks first.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;DecodeError&lt;/code&gt; has four cases&lt;/strong&gt;, &lt;code&gt;BadCharacter(at)&lt;/code&gt;, &lt;code&gt;BadPadding(at)&lt;/code&gt;, &lt;code&gt;Truncated(at)&lt;/code&gt;
(where &lt;code&gt;at&lt;/code&gt; is the text’s length) and &lt;code&gt;UnusedBits(at)&lt;/code&gt;, all byte offsets, and is an &lt;code&gt;Error&lt;/code&gt;. Why:
the cases are what a caller would report differently, as &lt;code&gt;UrlError&lt;/code&gt;‘s are; &lt;code&gt;Truncated&lt;/code&gt; carries the
length so every case has a position. Alternative weighed: binding Sysl’s &lt;code&gt;DecodeError&lt;/code&gt;, whose
&lt;code&gt;BadLength&lt;/code&gt; has no position and whose &lt;code&gt;Short&lt;/code&gt; and &lt;code&gt;Utf8&lt;/code&gt; cannot occur here.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the encoders are written in Avin&lt;/strong&gt;, while the digests stay bound to Sysl. Why:
Avin’s decoder is stricter than Sysl’s (above), and encoding is a few lines of byte arithmetic with
no platform behind it. Alternative weighed: binding &lt;code&gt;sysl.encoding&lt;/code&gt;‘s encoders and writing only the
checks in Avin (two passes over the text, and a second implementation of the alphabet anyway).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-23: &lt;strong&gt;&lt;code&gt;avin.encoding&lt;/code&gt; gains base32&lt;/strong&gt; (RFC 4648 alphabet &lt;code&gt;A&lt;/code&gt;–&lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;–&lt;code&gt;7&lt;/code&gt;): &lt;code&gt;toBase32&lt;/code&gt;
(padded with &lt;code&gt;=&lt;/code&gt; to a multiple of eight), &lt;code&gt;toBase32Unpadded&lt;/code&gt;, &lt;code&gt;toBase32Lower&lt;/code&gt; (lower case, no
padding), each over a &lt;code&gt;Vector[byte]&lt;/code&gt; or a &lt;code&gt;string&lt;/code&gt;, and one &lt;code&gt;fromBase32&lt;/code&gt;. The decoder reads either
case (also mixed) and padded or unpadded text, because a digit’s case and a trailing &lt;code&gt;=&lt;/code&gt; carry no
bits; it stays strict otherwise, with the same &lt;code&gt;DecodeError&lt;/code&gt; cases and check order as base64: a
padded text needs the right count of &lt;code&gt;=&lt;/code&gt; (&lt;code&gt;Truncated&lt;/code&gt; when the length is not a multiple of eight,
&lt;code&gt;BadPadding&lt;/code&gt; for a misplaced &lt;code&gt;=&lt;/code&gt; or more than six), an unpadded one must end on 0, 2, 4, 5 or 7
digits past a multiple of eight (&lt;code&gt;Truncated&lt;/code&gt; otherwise), and a last digit with unused bits set is
&lt;code&gt;UnusedBits&lt;/code&gt;. Why: marshal writes a 128-bit token as 26 lower-case characters (&lt;code&gt;toBase32Lower&lt;/code&gt;),
and a token read back from a case-folding source (a URL host, a file name) must still decode.
Alternatives weighed: an options argument or default arguments for case and padding (the base64
family has one function per spelling, and &lt;code&gt;fromBase64Url&lt;/code&gt; shows the unpadded form as its own
name); four encoders (padded lower case has no user); a decoder strict about case (a token typed
or lower-cased in transit would fail for no gain in uniqueness a caller relies on). Review with the
user: base32 decoding is therefore not one-spelling-per-value as base64’s is (case and padding vary).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;constantTimeEquals(a, b)&lt;/code&gt; in &lt;code&gt;avin.crypto&lt;/code&gt;&lt;/strong&gt;, for &lt;code&gt;Vector[byte]&lt;/code&gt; and for &lt;code&gt;string&lt;/code&gt;
(compared as UTF-8 bytes, so &lt;code&gt;&amp;quot;é&amp;quot;&lt;/code&gt; and &lt;code&gt;&amp;quot;e\u{301}&amp;quot;&lt;/code&gt; differ), bound to Sysl’s &lt;code&gt;sysl.crypto.verify&lt;/code&gt;,
which reads every byte and branches only on the lengths. Why: Sysl pins that function’s
branch-free code with its own codegen tests, which an Avin loop would not have; different lengths
answering &lt;code&gt;false&lt;/code&gt; at once leaks only a length, which a token’s or a tag’s is not secret. Alternatives
weighed: an Avin loop accumulating &lt;code&gt;xor&lt;/code&gt;s (its constant time would rest on the optimizer); a method
on &lt;code&gt;Vector[byte]&lt;/code&gt; (a security property should be found where the secrets are).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;SecureRandom&lt;/code&gt;, an object in &lt;code&gt;avin.random&lt;/code&gt;&lt;/strong&gt;, with &lt;code&gt;Random&lt;/code&gt;‘s drawing methods
(&lt;code&gt;nextBytes&lt;/code&gt;, &lt;code&gt;nextInt&lt;/code&gt;, &lt;code&gt;nextLong&lt;/code&gt;, both bounded, &lt;code&gt;between&lt;/code&gt; for &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;nextReal&lt;/code&gt;,
&lt;code&gt;nextBoolean&lt;/code&gt;, &lt;code&gt;alphanumeric&lt;/code&gt;, &lt;code&gt;shuffle&lt;/code&gt;, &lt;code&gt;choose&lt;/code&gt;) and two token functions, &lt;code&gt;hexToken(byteCount = 32)&lt;/code&gt; and &lt;code&gt;urlToken(byteCount = 32)&lt;/code&gt;. Every draw reads &lt;code&gt;getentropy&lt;/code&gt; through Sysl’s
&lt;code&gt;sysl.posix.rand.entropy_from_os&lt;/code&gt;, which is on macOS, glibc Linux and the BSDs and loops past the
256-byte request limit. A refusal from the operating system traps. Why: one name beside &lt;code&gt;Random&lt;/code&gt;
is found by whoever reads that module’s warning; an object, not a class, because there is no seed
and no state; trapping because a program wanting key material has no safe fallback. 32 bytes is
256 bits, past any guessing. &lt;code&gt;nextGaussian&lt;/code&gt;, &lt;code&gt;chooseWeighted&lt;/code&gt; and &lt;code&gt;setSeed&lt;/code&gt; are left out: no
secret is drawn from a normal or weighted distribution, and there is no seed. Alternatives
weighed: a class &lt;code&gt;SecureRandom()&lt;/code&gt; sharing a trait with &lt;code&gt;Random&lt;/code&gt; (an instance holds nothing, and the
trait would add a dispatch to every PCG draw); a buffered pool of entropy (fewer system calls, but
secret bytes kept in the heap and a lock); &lt;code&gt;secureBytes&lt;/code&gt; and token functions in &lt;code&gt;avin.crypto&lt;/code&gt;
(randomness split across two modules); &lt;code&gt;Result&lt;/code&gt; instead of a trap (a caller of &lt;code&gt;nextInt&lt;/code&gt; would
match on every draw).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Refined variants&lt;/strong&gt; (&lt;a href=&quot;/spec/refined-variants/&quot;&gt;chapter&lt;/a&gt;, branch &lt;code&gt;gadt-design&lt;/code&gt;; designed, not built)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Spelling: a variant’s result after &lt;code&gt;-&amp;gt;&lt;/code&gt;, its own type parameters after its name.&lt;/strong&gt;
&lt;code&gt;IntLit(value: int) -&amp;gt; Expr[int]&lt;/code&gt;, &lt;code&gt;Balance -&amp;gt; Query[long]&lt;/code&gt;, &lt;code&gt;Pair[A, B](…) -&amp;gt; Expr[(A, B)]&lt;/code&gt;; the
data type’s parameter names are every variant’s parameters, so a variant with no result keeps
meaning &lt;code&gt;-&amp;gt; D[T…]&lt;/code&gt;. Why: a variant is a constructor, and &lt;code&gt;(fields) -&amp;gt; Type&lt;/code&gt; is exactly how Avin
writes a function’s signature, so the line reads as the constructor it declares; nothing else is
written after a variant’s fields. Alternatives weighed: &lt;code&gt;IntLit(value: int): Expr[int]&lt;/code&gt; (&lt;code&gt;:&lt;/code&gt; already
types each field on the same line and begins an inheritance list, which a variant is not); a
&lt;code&gt;where T = int&lt;/code&gt; clause (names the equality instead of the instance, and needs a second syntax for
hidden parameters); a separate keyword per refined variant (a second kind of variant where there
is one with an optional result).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A variant fixes only invariant parameters.&lt;/strong&gt; Where the type’s parameter is &lt;code&gt;+T&lt;/code&gt; or &lt;code&gt;-T&lt;/code&gt;, a
variant’s result has &lt;code&gt;T&lt;/code&gt; there. Why: an invariant argument is exact, so the equality an arm learns
is true; a covariant one is an upper bound, and taking it as an equality is unsound (the chapter’s
&lt;code&gt;asDog&lt;/code&gt; makes a cat a &lt;code&gt;Dog&lt;/code&gt;). Alternatives weighed: refining a covariant place by a bound
(&lt;code&gt;Dog &amp;lt;: T&lt;/code&gt;) and a contravariant one by the opposite bound (sound, but it gives one-directional
facts that are hard to read in an error, and no motivating example needs it); forbidding variance
on any type with a refined variant (needlessly strict: unfixed places keep their variance soundly).
Review with the user: whether bound refinement at variance places is wanted later.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Hidden type parameters are allowed, and compiled per pack.&lt;/strong&gt; A variant parameter its result does
not name is a fresh type in each arm, never leaving it; each list of hidden types the program makes
a variant with has its own descriptor, and an arm on it is compiled once per pack and selected by
the descriptor. Why: a typed protocol (a request and its reply address agreeing on a type the
message type does not mention) and a chained plan (&lt;code&gt;Then[Mid]&lt;/code&gt;) need one, and the whole-program
compiler already knows every pack, as it knows every implementer of a trait for dynamic generic
methods, so nothing is boxed and the value-type fields stay unboxed. Alternatives weighed: refusing
hidden parameters (the protocol could then only erase &lt;code&gt;R&lt;/code&gt; behind a trait, losing the type the
design exists to keep); boxing a hidden field behind &lt;code&gt;Any&lt;/code&gt; (a run-time test where none is needed).
Review with the user: code size, since an arm is copied per pack.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Equalities hold exactly where the pattern’s names are in scope, and nowhere outside.&lt;/strong&gt; An arm’s
result is checked against the expected type under them; with none expected, arms yield their types
as written; an inference variable settled in an arm settles to the type as written; a hidden type
in an arm’s result is an error. Why: a fact true only in the arm cannot leak to code that runs
without it, and “as written” is the one reading that does not guess whether an &lt;code&gt;int&lt;/code&gt; was meant as
&lt;code&gt;T&lt;/code&gt;. Alternatives weighed: mapping an arm’s type back through its equalities (ambiguous: &lt;code&gt;int&lt;/code&gt; and
&lt;code&gt;T&lt;/code&gt; are one type there and two outside); inferring the result type of a refining &lt;code&gt;match&lt;/code&gt; (needs a
search the local inference does not do).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Only variants refine.&lt;/strong&gt; Extractors and type patterns learn no equalities. Why: an extractor’s
answer type is its signature’s; a type pattern’s could refine an invariant generic’s arguments by
the same header argument, but it widens the feature to every generic type and every type test.
Alternative weighed: refining by type patterns on invariant instances (sound; deferred). Review
with the user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A union in a result names no variant parameter&lt;/strong&gt;, since a value would not say which member a
parameter is; closed unions (&lt;code&gt;-&amp;gt; Expr[int | string]&lt;/code&gt;) are allowed. Alternative weighed: deciding the
parameter by normal-form order (arbitrary, and wrong for a value made at another member).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An arm no value can reach because its equalities contradict is an error&lt;/strong&gt;, as every unreachable
arm is, and coverage counts only the variants possible at the matched type, carrying each row’s
equalities; a &lt;code&gt;match&lt;/code&gt; on an instance with no possible variant is an error. Alternatives weighed: a
warning for an impossible arm (Avin has no warnings for unreachable code); pruning per column
without carrying equalities along a row (simpler, but demands arms for combinations no value has).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Bounds on a variant’s parameters&lt;/strong&gt; are checked where a value is made and held in the arm, and an
enclosing type parameter equated with a bounded one gains the bound there; a copy at a type
without the bound compiles no such arm. Why: it is what makes a hidden type useful (&lt;code&gt;Sendable&lt;/code&gt; for
a reply, &lt;code&gt;Ord&lt;/code&gt; for a sorted payload), and it costs one more test when an arm is decided at a copy.
Alternative weighed: no bounds on variant parameters (the protocol could not name &lt;code&gt;ActorRef[R]&lt;/code&gt;,
whose parameter is bounded by &lt;code&gt;Sendable&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The nested-data-type rule is measured against the variant’s result&lt;/strong&gt;, and a larger part made of
a hidden parameter is allowed, since its instances exist only where the program makes a pack.
Alternative weighed: measuring against the plain instance &lt;code&gt;D[T…]&lt;/code&gt; (refuses &lt;code&gt;First[A, B](pair: Expr[(A, B)]) -&amp;gt; Expr[A]&lt;/code&gt;, which has finitely many copies).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-1&lt;/code&gt;, the declaration step): &lt;strong&gt;a refined variant’s parameters, the type’s
included, are the variant’s own in the expansion check.&lt;/strong&gt; An instance reaches them through the
result (&lt;code&gt;Expr[X]&lt;/code&gt; holding a &lt;code&gt;Pair&lt;/code&gt; has &lt;code&gt;X = (A, B)&lt;/code&gt;, so &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; lie one level down), and a type
argument of a field that names a hidden parameter adds no edge, since its instances are the packs
the program makes, which step 5’s check of growing packs counts. A growing cycle through a refined
variant names the field and the result it is measured against. Why: it is rule 6 exactly, and it
reuses the one polymorphic-recursion check rather than a second one for variants. Alternatives
weighed: a separate syntactic comparison of each field with the result (misses growth through a
second type, which the flow check already follows).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-1&lt;/code&gt;): &lt;strong&gt;a variant’s own type parameter takes bounds and no variance and no
lower bound&lt;/strong&gt;, and a name reused from the type’s parameters or twice among the variant’s own is an
error. Why: a variant is a constructor, a generic function, whose parameters take no variance; a
lower bound asks of a call’s argument something a &lt;code&gt;match&lt;/code&gt; could not hand back. Alternatives
weighed: allowing &lt;code&gt;&amp;gt;:&lt;/code&gt; (sound at the call, but it gives the arm a one-directional fact, the kind
&lt;a href=&quot;/spec/refined-variants/#variance&quot;&gt;Variance&lt;/a&gt; declines).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-1&lt;/code&gt;): &lt;strong&gt;a result written as the type at its own parameters, &lt;code&gt;If(…) -&amp;gt; Expr[T]&lt;/code&gt;, with no parameters of the variant’s own, is a plain variant&lt;/strong&gt;, the same declaration as
one with no result. A data parameter a refined variant’s result does not name is hidden there like
any other (&lt;code&gt;IntLit(value: T) -&amp;gt; Expr[int]&lt;/code&gt; hides &lt;code&gt;T&lt;/code&gt;). Why: the chapter says the type’s names are
every variant’s parameters, and a written-out plain result changes nothing a value carries.
Alternative weighed: treating any written result as refined (a type would lose its plain uses for
a redundant spelling).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branches &lt;code&gt;gadt-1&lt;/code&gt; and &lt;code&gt;gadt-2&lt;/code&gt;): &lt;strong&gt;a type
with refined variants is named, made and matched like any other&lt;/strong&gt;, and the code the derived
templates write (&lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, any &lt;code&gt;walk&lt;/code&gt;) matches every variant, its copies compiled
only for the variants possible at each instance, each arm at the arguments it reads back from the
instance. The declaration step (&lt;code&gt;gadt-1&lt;/code&gt;) and the values-and-layouts step (&lt;code&gt;gadt-2&lt;/code&gt;) first
refused the type’s uses with “yet” messages; patterns and field reads came with &lt;code&gt;gadt-3&lt;/code&gt;, hidden
parameters with &lt;code&gt;gadt-5&lt;/code&gt; and bounded parameters with &lt;code&gt;gadt-6&lt;/code&gt; (the entries below). Why: lowering
lays out every variant at every instance, so the derived code needs only what lowering knows at a
copy. Alternatives weighed: accepting patterns on plain variants before coverage over the
possible variants existed (it would demand arms for impossible variants that &lt;code&gt;gadt-4&lt;/code&gt; then made
errors).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-2&lt;/code&gt;): &lt;strong&gt;a parameter of the data type that a refined variant names in neither
its fields nor its result is fixed in its signature&lt;/strong&gt; (to &lt;code&gt;Nothing&lt;/code&gt;, which nothing observes), so it
is never inferred and never written: &lt;code&gt;Pair[int, bool](…)&lt;/code&gt; writes &lt;code&gt;Pair&lt;/code&gt;‘s &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;, &lt;code&gt;Done[S]&lt;/code&gt;
of &lt;code&gt;Done -&amp;gt; Plan[From, From]&lt;/code&gt; writes &lt;code&gt;From&lt;/code&gt;, and &lt;code&gt;IntLit[int](1)&lt;/code&gt; takes no type argument. On the
type, &lt;code&gt;Expr[(int, bool)].Pair(…)&lt;/code&gt; names the instance the value makes: the variant’s parameters are
inferred from it and the value is held to it. Why: the chapter says a variant is called as a
generic function, and such a parameter is no parameter of that function; leaving it to inference
would make every call of &lt;code&gt;IntLit&lt;/code&gt; an unsolvable “cannot infer &lt;code&gt;T&lt;/code&gt;“. Alternatives weighed: dropping
the parameter from the variant’s list (its field defaults are functions of the whole list);
reading &lt;code&gt;T[A].V&lt;/code&gt; as written arguments of &lt;code&gt;V&lt;/code&gt; (they are the type’s, and need not match &lt;code&gt;V&lt;/code&gt;‘s own in
number or meaning).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-2&lt;/code&gt;): &lt;strong&gt;a derived trait holds of a refined variant’s own parameter where the
trait on the instance implies it&lt;/strong&gt;: the parameter sits in the result under constructors whose
trait needs their argument’s (a tuple’s, &lt;code&gt;Vector&lt;/code&gt;‘s), tested by whether the constructor at the
parameter has the trait where every other argument does and the parameter alone has none. Where
it is not implied (&lt;code&gt;Hold[A](x: A) -&amp;gt; Odd[Wrap[A]]&lt;/code&gt;, with &lt;code&gt;Wrap&lt;/code&gt; showing itself whatever &lt;code&gt;A&lt;/code&gt; is),
the field falls short and the type has no automatic &lt;code&gt;Display&lt;/code&gt;, as any type with such a field. A
hidden parameter is decided per pack, by the parameter’s bounds (step 5, branch &lt;code&gt;gadt-5&lt;/code&gt;, the
entry below). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether a refined type’s &lt;code&gt;Display&lt;/code&gt; should rather
be decided per instance, at the instance’s own arguments. Why: a derived impl is checked once, over
its type’s parameters, and this is the most that check can know of a variant’s own; it is sound,
since the trait at an instance gives it to the parameter read back there. Alternatives weighed:
no trait for own parameters (every type with &lt;code&gt;Pair&lt;/code&gt; would lose &lt;code&gt;Display&lt;/code&gt;); the trait
unconditionally (unsound for &lt;code&gt;Odd&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-2&lt;/code&gt;, where refined variants meet higher-kinded types): &lt;strong&gt;a variant’s own
type parameters are types, and a constructor parameter of the type keeps its place in a result&lt;/strong&gt;:
&lt;code&gt;V[G[_]](…)&lt;/code&gt; is refused with &lt;code&gt;&amp;quot;a variant&apos;s own type parameters stand for types, not type constructors: `G` of `V` takes type arguments; declare a constructor parameter on the type, as in `data D[G[_]]`&amp;quot;&lt;/code&gt;, and &lt;code&gt;W(…) -&amp;gt; D[Vector, T]&lt;/code&gt; with &lt;code&gt;&amp;quot;a variant fixes no constructor parameter: `W` makes `D[Vector, T]`, and `F` of `D` is a constructor parameter, so its place holds `F`&amp;quot;&lt;/code&gt;, while
&lt;code&gt;Y(x: F[int]) -&amp;gt; D[F, int]&lt;/code&gt;, keeping &lt;code&gt;F&lt;/code&gt; and fixing &lt;code&gt;T&lt;/code&gt;, is accepted (step 1 refused it as “no type
a &lt;code&gt;match&lt;/code&gt; can take apart”, which was a mistake). Why: the &lt;code&gt;gadt-1&lt;/code&gt; entry below settles that no
constructor parameter is fixed, and keeping one in its place fixes nothing. Alternatives weighed: refusing any
refined variant of a type with a constructor parameter (needlessly narrow).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-1&lt;/code&gt;), &lt;strong&gt;for constructor parameters (&lt;a href=&quot;/spec/generics/#higher-kinded-types&quot;&gt;higher-kinded
types&lt;/a&gt;), the conservative reading: a
variant fixes no constructor parameter of its type, its own type parameters are no constructor
parameters, and a result’s argument never applies a constructor parameter&lt;/strong&gt; (&lt;code&gt;-&amp;gt; D[F, F[A]]&lt;/code&gt; is
refused, since &lt;code&gt;F[A]&lt;/code&gt; against a known instance cannot be taken apart where &lt;code&gt;F&lt;/code&gt; is itself a
parameter of the code matching). The declaration step enforces the last two through one rule: a
result’s arguments are built of data types, classes, tuples, function types and the variant’s
parameters, and any other form, a constructor or its application among them, is refused with
&lt;code&gt;&amp;quot;`F[A]` in the result of `V` is no type a `match` can take apart: the result&apos;s arguments are built of data types, classes, tuples and function types&amp;quot;&lt;/code&gt;; a constructor parameter among a
variant’s own (&lt;code&gt;V[G[_]]&lt;/code&gt;) is refused since the two branches met (branch &lt;code&gt;gadt-2&lt;/code&gt;, the entry
above). Fields name constructor applications freely, as any variant’s do. Why: refinement
solves equalities by decomposition, which needs every parameter under a constructor that the
instance’s head determines; an applied parameter is not one. Alternatives weighed: solving &lt;code&gt;F[A] = X&lt;/code&gt; by matching &lt;code&gt;X&lt;/code&gt;‘s head (unsound when &lt;code&gt;F&lt;/code&gt; is a partial application, whose holes may sit anywhere
among &lt;code&gt;X&lt;/code&gt;‘s arguments). Review with the user: whether refinement over constructors is wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-3&lt;/code&gt;, the refinement step): &lt;strong&gt;each pattern on a refined variant gives the
variant’s parameters fresh types of its own&lt;/strong&gt;, so two &lt;code&gt;Pair&lt;/code&gt; patterns, nested or one after the
other, give two unrelated sets, and &lt;strong&gt;the equalities are solved with those fresh types first, then
the enclosing code’s type parameters&lt;/strong&gt;: &lt;code&gt;Vector[A] = Vector[T]&lt;/code&gt; makes &lt;code&gt;A&lt;/code&gt; the &lt;code&gt;T&lt;/code&gt; around the arm,
so a field reads as a type the code can name, and &lt;code&gt;T = (A, B)&lt;/code&gt; keeps &lt;code&gt;T&lt;/code&gt; as the pair of the fresh
types. A union or a type constructor that names a type parameter is not taken apart and teaches
nothing (&lt;code&gt;T | string = int | string&lt;/code&gt; has two solutions); any other two different types, and a
cyclic &lt;code&gt;T = Vector[T]&lt;/code&gt;, are a contradiction, which step 4 (branch &lt;code&gt;gadt-4&lt;/code&gt;) makes an error at the
pattern; the arm’s body is then checked with no equalities, and is not compiled at any copy. The equalities hold where a marker local the pattern declares beside its names is in
scope, which carries them exactly where the names go: an arm, a clause, an &lt;code&gt;is&lt;/code&gt; test’s branch,
the right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt;, the rest of a block after an early return or a binding. At a
copy where a pattern is impossible, lowering leaves out what holds its equalities: the arm, the
branch an &lt;code&gt;is&lt;/code&gt; test then cannot take, the right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt;, a &lt;code&gt;while&lt;/code&gt; body, and the
rest of a block whose taken branch never finishes. Why: the chapter’s “fresh types known only by
these equalities”, and a substitution the arm’s code can read. Alternatives weighed: naming the
fresh types by the data type’s own parameters (two nested patterns would share them); stopping
with an error at an equality not taken apart (refuses sound programs).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-3&lt;/code&gt;): &lt;strong&gt;a variant’s own parameter that the equalities leave a fresh type
never leaves its arm&lt;/strong&gt;, as a hidden one does not (the chapter states it for hidden parameters
only): with no type expected, an arm, a clause, an &lt;code&gt;is&lt;/code&gt; branch or a block whose result names one is
refused with &lt;code&gt;&amp;quot;this arm&apos;s result is an `Expr[A]`, and `A` is a type `Pair` takes from the value it matches, which is not known outside its arm&amp;quot;&lt;/code&gt;, and an inference variable made before the pattern
settled to one with &lt;code&gt;&amp;quot;a type declared outside this arm cannot be settled to an `Expr[A]`: …&amp;quot;&lt;/code&gt;,
reported at the pattern. Why: such a type is known only through the value matched, so no copy can
compile code outside the arm that names it. Alternatives weighed: settling the escaped type as
&lt;code&gt;Nothing&lt;/code&gt; (lays out a value at the wrong type); allowing it (no copy could compile it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-3&lt;/code&gt;): &lt;strong&gt;inside an arm a value of a type an equality fixes is used at what
it is there&lt;/strong&gt; for operators, members and comparisons (&lt;code&gt;x + n&lt;/code&gt; with &lt;code&gt;x: T&lt;/code&gt; and &lt;code&gt;T = int&lt;/code&gt; is an
&lt;code&gt;int&lt;/code&gt;), the type expected of an expression is the one under the equalities (a literal where a &lt;code&gt;T&lt;/code&gt;
that is an &lt;code&gt;int&lt;/code&gt; is expected is an &lt;code&gt;int&lt;/code&gt;, a value where a &lt;code&gt;T&lt;/code&gt; that is &lt;code&gt;Any&lt;/code&gt; is expected is boxed),
while &lt;strong&gt;an inference variable still settles to the type as written&lt;/strong&gt; where it meets one. An arm
that refines, with a type expected, is checked against it under its equalities and &lt;strong&gt;yields the
expected type itself&lt;/strong&gt;; one that does not fit it is refused with &lt;code&gt;&amp;quot;this arm yields int, not the T expected of the `match`&amp;quot;&lt;/code&gt;. Clauses with no declared result that agree on no type are reported as
the chapter reports arms: &lt;code&gt;&amp;quot;the clauses of `f` agree on no type: `IntLit`&apos;s yields an `int`, which is `T` only inside that clause; declare the result type&amp;quot;&lt;/code&gt;. Why: the chapter’s “a type and
anything it equals are one type” and its “as written” rule for inference variables, each where it
can apply. Alternatives weighed: rewriting every type in the arm to its refined form (would settle
variables outside the arm to refined types, against the chapter).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-3&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;val V = x&lt;/code&gt;, where &lt;code&gt;V&lt;/code&gt; is a variant of &lt;code&gt;x&lt;/code&gt;‘s type and that type has
refined variants, takes the value apart&lt;/strong&gt; as the chapter’s &lt;code&gt;val Refl = proof&lt;/code&gt; does; anywhere else
&lt;code&gt;val Name = x&lt;/code&gt; binds a name, as before. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;val V = x&lt;/code&gt; should take
apart a value whenever &lt;code&gt;V&lt;/code&gt; is a variant in scope, as a bare name in a pattern does. Why: the
chapter’s example, with no change for any program written before refined variants. Alternatives
weighed: requiring &lt;code&gt;val V() = x&lt;/code&gt; (not the chapter’s spelling); the general rule (changes what
existing bindings mean).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-3&lt;/code&gt;): &lt;strong&gt;a field of a refined type’s one variant is read by name where the
instance says the field’s type&lt;/strong&gt;: &lt;code&gt;o.value&lt;/code&gt; on &lt;code&gt;One[T]&lt;/code&gt; with &lt;code&gt;Mk(value: int) -&amp;gt; One[int]&lt;/code&gt; is an
&lt;code&gt;int&lt;/code&gt;; an instance the variant cannot make is refused with &lt;code&gt;&amp;quot;`One[bool]` has no values: no variant of `One` makes one&amp;quot;&lt;/code&gt;, and a field whose type keeps a parameter the instance does not say
with &lt;code&gt;&amp;quot;the field `items` of `Hold` has a type a `Holder[T]` does not determine; take the value apart with `match`&amp;quot;&lt;/code&gt;. Why: every value of the instance is the variant’s, so the read is the arm
of a one-arm &lt;code&gt;match&lt;/code&gt;, and only its result type must be one known outside. Alternatives weighed:
refusing every such read (the chapter’s single-variant types would lose field access).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-4&lt;/code&gt;, the coverage step): &lt;strong&gt;coverage counts the variants possible at the
type matched as the equalities in scope see it&lt;/strong&gt;, splitting a column on a refined type’s variant
only where the variant’s result has a solution with the column’s instance, the variant’s own
parameters given types of their own for that split; &lt;strong&gt;the solution carries to the other columns&lt;/strong&gt;,
so a row’s equalities travel along it, and an instance no variant makes is a column with no
values. Why: the chapter’s Coverage, and the same solving the checker does for a pattern, so the
two agree on what is possible. Alternatives weighed: carrying the equalities as a substitution
beside the columns (the same, with every function of the coverage check threading it; applying
them to the columns at each split needs no more state).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-4&lt;/code&gt;): &lt;strong&gt;an impossible pattern is reported at the pattern, by the checker,
with the chapter’s three reasons&lt;/strong&gt;, chosen by re-solving: against the equalities in scope before
its row alone it fails (&lt;code&gt;`Eq` makes an `Expr[bool]`, and the value matched is an `Expr[int]`&lt;/code&gt;,
or the empty-instance message where no variant is possible), a cyclic equality
(&lt;code&gt;`Wrap` needs `T` to be `Vector[T]`, which no type is&lt;/code&gt;), or the first equality of an earlier
pattern of its row that leaves it none (&lt;code&gt;`IntLit` needs `T` to be `int`, and `BoolLit` in the same pattern needs it to be `bool`&lt;/code&gt;). A row is an arm’s pattern, a clause’s arguments (&lt;code&gt;in the same clause&lt;/code&gt;), an &lt;code&gt;is&lt;/code&gt; test’s pattern, a binding’s pattern. &lt;strong&gt;The lead says what never happens&lt;/strong&gt;:
&lt;code&gt;this arm is never reached&lt;/code&gt;, &lt;code&gt;this clause is never reached&lt;/code&gt;, and &lt;code&gt;this pattern never matches&lt;/code&gt; for
an &lt;code&gt;is&lt;/code&gt; test, a binding and one of a set of alternatives, which the chapter does not word. An
impossible pattern on the right of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, under the left’s equalities, is an error the same way.
&lt;strong&gt;A &lt;code&gt;match&lt;/code&gt; on an empty instance is an error at the value matched even when no arm names a
variant&lt;/strong&gt; (&lt;code&gt;_ -&amp;gt; 0&lt;/code&gt; on a &lt;code&gt;Same[int, string]&lt;/code&gt;). Why: the pattern is where the contradiction is,
and a test that can never succeed is dead code as an arm is. Alternatives weighed: reporting
impossible arms from the coverage check (it sees rows, not which equality failed, and would say
only “never reached”); leaving an impossible &lt;code&gt;is&lt;/code&gt; test legal (it folds to &lt;code&gt;false&lt;/code&gt; at every copy,
which hides a mistake). &lt;strong&gt;Review with the user:&lt;/strong&gt; the wording for tests, bindings and alternatives.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-4&lt;/code&gt;): &lt;strong&gt;each alternative of a pattern matches on its own: the equalities an
alternative learns hold neither in the alternatives after it nor in the arm&lt;/strong&gt;, and lowering tests
each alternative at what its own patterns read back from the value. A step-3 bug: an alternative’s
equalities stayed in scope, so &lt;code&gt;IntLit(_) | BoolLit(_) -&amp;gt; 5&lt;/code&gt; on an &lt;code&gt;Expr[T]&lt;/code&gt; was checked as if
&lt;code&gt;T&lt;/code&gt; were &lt;code&gt;int&lt;/code&gt;, and its &lt;code&gt;bool&lt;/code&gt; copy answered &lt;code&gt;false&lt;/code&gt; for the &lt;code&gt;5&lt;/code&gt;; and an alternative was compiled
without its patterns’ arguments, so &lt;code&gt;Pair(IntLit(3), _) | …&lt;/code&gt; never matched. Why: the arm runs for
whichever alternative matched, so only what all of them imply could hold, and alternatives bind
no names. Alternatives weighed: keeping the equalities every alternative implies (sound, but needs
a meet of substitutions the chapter does not describe; no program has needed it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-4&lt;/code&gt;): &lt;strong&gt;two types that read the same in a message are named apart by the
refining patterns that took them&lt;/strong&gt;: &lt;code&gt;expected Expr[A of `Pair` on line 4], found Expr[A of `Pair` on line 5]&lt;/code&gt;, with the column too where both patterns are on one line, in the expected/found,
operator-operand, &lt;code&gt;cannot compare&lt;/code&gt; and declared-result messages. Only where the two names would
otherwise be identical; every other message is unchanged. Why: two patterns on one variant give
two unrelated sets of fresh types with the variant’s parameter names. Alternatives weighed:
numbering the fresh types (&lt;code&gt;A1&lt;/code&gt;, &lt;code&gt;A2&lt;/code&gt;), which every message would show, even where nothing
clashes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-5&lt;/code&gt;, the hidden-parameters step): &lt;strong&gt;a hidden parameter has exactly the
bounds its variant declares, and a trait derived for its type holds of it only by them&lt;/strong&gt;:
&lt;code&gt;Hold[A](value: A)&lt;/code&gt; gives &lt;code&gt;Box&lt;/code&gt; no automatic &lt;code&gt;Display&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt; nor &lt;code&gt;Sendable&lt;/code&gt;, and
&lt;code&gt;Hold[A: Display](value: A)&lt;/code&gt; gives it &lt;code&gt;Display&lt;/code&gt;. A parameter of the type that a refined variant
hides (&lt;code&gt;Hide(value: T) -&amp;gt; Tagged[int]&lt;/code&gt;) is the value’s own, so the impl’s bound on the instance’s
&lt;code&gt;T&lt;/code&gt; does not give it the trait either. The reason a type has no automatic trait names the variant,
its field and the hidden parameter (&lt;code&gt;`Tagged` has no `Display` because its field `Hide.value` names `T`, which the variant hides and a value may hold at any type; bound it, as in `[T: Display]`&lt;/code&gt;), and an explicit &lt;code&gt;derives&lt;/code&gt; says the same. This settles step 2’s “the trait for now”
per pack: the derived code’s arm is compiled once per pack, and only the bounds hold at every
pack. &lt;code&gt;==&lt;/code&gt; and the hash still compare and hash every value, a pack at a time. Consequence: the
chapter’s &lt;code&gt;Expr&lt;/code&gt;, whose &lt;code&gt;First&lt;/code&gt; hides &lt;code&gt;B&lt;/code&gt;, has no automatic &lt;code&gt;Display&lt;/code&gt; unless &lt;code&gt;First&lt;/code&gt; writes &lt;code&gt;[A, B: Display &amp;amp; Debug]&lt;/code&gt;. Why: a derived impl is checked once and must hold wherever any value is,
and a pack’s types are known only where the value is made; deciding by bounds keeps the type’s
traits a fact of its declaration. Alternatives weighed: giving the trait unconditionally (unsound:
a value of a pack without it reaches the derived code); requiring the trait of the hidden types
where each value is made, whenever the type derives it (every &lt;code&gt;Box&lt;/code&gt; made of a class without
&lt;code&gt;Display&lt;/code&gt; would be an error, though the program never shows one, and generic code could not know
whether its instance derives it); rendering a hidden field through its type record (&lt;code&gt;Display&lt;/code&gt; and
&lt;code&gt;Debug&lt;/code&gt; only, and a change to the derive templates). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;Display&lt;/code&gt;
and &lt;code&gt;Debug&lt;/code&gt; should rather render a hidden field through its run-time type, so &lt;code&gt;Expr&lt;/code&gt; prints
without the bound.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-5&lt;/code&gt;): &lt;strong&gt;a bound on a hidden parameter is allowed, &lt;code&gt;T: A &amp;amp; B&lt;/code&gt; included&lt;/strong&gt;;
a bound on a variant’s own parameter that its result names was left to step 6 (branch &lt;code&gt;gadt-6&lt;/code&gt;,
the entries below). A hidden parameter’s bounds are checked where a value is made, as a
call’s are, and the fresh type an arm gives it has them. Why: the chapter states them for hidden
parameters in their own section (“a fresh type, with the bounds its declaration gives it”), and
the typed protocol needs &lt;code&gt;Ask[R: Sendable]&lt;/code&gt;; what step 6 adds, an enclosing type parameter gaining
a bound by equality, does not arise for a hidden one. Alternatives weighed: leaving every bound to
step 6 (the protocol could not be written in step 5).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-5&lt;/code&gt;): &lt;strong&gt;an &lt;code&gt;is&lt;/code&gt; test or a binding takes apart no field of a hidden type&lt;/strong&gt;:
&lt;code&gt;if b is Hold(v, _)&lt;/code&gt; with &lt;code&gt;value: A&lt;/code&gt; hidden is refused with &lt;code&gt;&amp;quot;`Hold` hides `A`, and its field `value` names it: an `is` test or a binding takes apart no field of a hidden type; take the value apart with `match`, whose arm is compiled for each type the value hides&amp;quot;&lt;/code&gt;; &lt;code&gt;b is Hold(_, _, t)&lt;/code&gt;,
testing or binding only fields whose type every pack shares, is accepted and tries each pack. A
&lt;code&gt;match&lt;/code&gt; arm, a clause, a match function and an actor’s or machine’s arm take any field. Why: an
arm is one expression, compiled once per pack; an &lt;code&gt;is&lt;/code&gt; test’s equalities reach the rest of a block
after an early return or the right operand of &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, code that would have to be copied per pack
as far as the names reach. Alternatives weighed: copying the reached code per pack (a block’s
rest, an &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; chain and a &lt;code&gt;while&lt;/code&gt; condition each need their own copying); refusing every hidden
pattern in a test (the tag test and the shared fields are sound and useful).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-5&lt;/code&gt;): &lt;strong&gt;an arm on a variant with hidden parameters is compiled inline,
once per pack, and chosen by comparing the value’s descriptor with each pack’s&lt;/strong&gt;, not as a
function called through the descriptor’s method table as the build plan said. Lowering finds the
packs as it reaches the code making them; an instance compiled for fewer packs than the program
has made by the end is lowered again, until none is stale, and such instances are not kept in the
instance cache. Why: an arm compiled inline keeps &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt;, a &lt;code&gt;var&lt;/code&gt; of the
function and a tail call behaving as in any arm, which a separate function would have to pass
back across a call; the run-time cost is one compare per pack before the arm, against a call
through a table. Alternatives weighed: the plan’s function per pack through the table (each arm
would need its locals captured and its exits returned as codes); boxing hidden fields behind &lt;code&gt;Any&lt;/code&gt;
(the chapter’s alternative, a run-time test where none is needed).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-5&lt;/code&gt;): &lt;strong&gt;in the polymorphic-recursion check, a refining pattern’s fresh types
are its variant’s parameter nodes, a value made with hidden types reaches them, and a type
argument holding a hidden type grows no parameter of the code that the value matched holds&lt;/strong&gt;: so
&lt;code&gt;eval(First(p)) = … eval(p)&lt;/code&gt; at &lt;code&gt;(T, B)&lt;/code&gt; is ordinary, as the chapter says, while a pack built
from ever larger hidden types (&lt;code&gt;Hold(v) -&amp;gt; grow(Hold([v]))&lt;/code&gt;), a generic function making a pack of
its parameter whose arm calls it larger, and a parameter grown beside a hidden type of a value not
holding it, are refused as polymorphic recursion naming the variant. Why: an instance at a hidden
type exists only for a pack, which a value made somewhere holds, and a matched value holding the
parameter can be of a larger pack only where the program made one; growth through the values made
is counted by the construction edges. Alternatives weighed: counting every type argument as
before (refuses the chapter’s &lt;code&gt;eval&lt;/code&gt;); dropping every edge of an argument naming a hidden type
(accepts &lt;code&gt;pairUp((x, y), b)&lt;/code&gt;, which never ends).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-6&lt;/code&gt;, the bounds step): &lt;strong&gt;an enclosing type parameter gains a variant
parameter’s bounds only where an equality in scope equates the two as wholes&lt;/strong&gt;: with
&lt;code&gt;Sorted[A: Ord](items: Vector[A]) -&amp;gt; Coll[A]&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt; of &lt;code&gt;smallest[T](c: Coll[T])&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt; in the
&lt;code&gt;Sorted&lt;/code&gt; arm, a parameter equated in a tuple place (&lt;code&gt;Conv2[A: Into[B], B](…) -&amp;gt; Conv[(A, B)]&lt;/code&gt; on
a &lt;code&gt;Conv[(X, Y)]&lt;/code&gt;, where &lt;code&gt;X&lt;/code&gt; gains &lt;code&gt;Into[Y]&lt;/code&gt;) too; &lt;code&gt;U&lt;/code&gt; of a &lt;code&gt;Coll[Vector[U]]&lt;/code&gt; gains nothing, though
&lt;code&gt;Vector[U]&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt;. The bound holds where the arm’s equalities do: not among alternatives, not
after the arm, not in the other branch of an &lt;code&gt;is&lt;/code&gt; test. Why: the chapter states it for “a fixed
parameter equated with a type parameter”, and inferring &lt;code&gt;U: Ord&lt;/code&gt; from &lt;code&gt;Vector[U]: Ord&lt;/code&gt; would
invert an impl’s condition, which holds only where no other impl gives the trait. Alternatives
weighed: inverting conditional impls (unsound wherever a type has the trait unconditionally);
rewriting &lt;code&gt;T&lt;/code&gt; to the variant’s fresh type in the arm (the arm’s result would then be checked as a
type that leaves its scope).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-6&lt;/code&gt;): &lt;strong&gt;a variant’s bounds do not prune coverage&lt;/strong&gt;: a &lt;code&gt;match&lt;/code&gt; on a
&lt;code&gt;Coll[Thing]&lt;/code&gt;, with &lt;code&gt;Thing&lt;/code&gt; not &lt;code&gt;Ord&lt;/code&gt;, still needs a &lt;code&gt;Sorted&lt;/code&gt; arm (or a wildcard), whose code is
checked at &lt;code&gt;Thing&lt;/code&gt; without the bound, as the chapter’s coverage rule counts equalities alone.
Lowering does leave the variant out of the instance: &lt;code&gt;Coll[Thing]&lt;/code&gt;‘s layout has no descriptor for
&lt;code&gt;Sorted&lt;/code&gt;, and an arm, an &lt;code&gt;is&lt;/code&gt; test or the derived code on it is not compiled there, as for a
variant whose equalities fail. Why: coverage stays a fact of the types’ shapes, unchanged by which
impls the program declares (an impl added in another module would otherwise make a covering
&lt;code&gt;match&lt;/code&gt; incomplete). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether an arm on a variant whose bounds a concrete
instance fails should rather be “never reached”, as an impossible arm is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;gadt-6&lt;/code&gt;): &lt;strong&gt;whether a refined type is sendable is decided at its instance&lt;/strong&gt;: a
variant’s own parameters are read back from the instance’s arguments, so &lt;code&gt;Coll[string]&lt;/code&gt; is
sendable though &lt;code&gt;Sorted&lt;/code&gt;‘s &lt;code&gt;A&lt;/code&gt; is bounded by &lt;code&gt;Ord&lt;/code&gt; alone, and a variant whose result is another
concrete instance holds nothing there (&lt;code&gt;Msg[int]&lt;/code&gt; is sendable though &lt;code&gt;Log&lt;/code&gt;, making only a
&lt;code&gt;Msg[string]&lt;/code&gt;, holds a &lt;code&gt;Buffer&lt;/code&gt;). Where generic arguments do not say what a parameter is, one
bounded by &lt;code&gt;Sendable&lt;/code&gt; is sendable, as a hidden one is, and any other may be any type. A hidden
parameter is still decided by its bounds alone, per the &lt;code&gt;gadt-5&lt;/code&gt; entry: every pack the program
makes was checked where its value was made. Why: before, a refined variant’s own parameters were
read by position, so every instance of a type with &lt;code&gt;Sorted&lt;/code&gt; was unsendable, and an actor could not
receive one. Alternatives weighed: requiring &lt;code&gt;Sendable&lt;/code&gt; on every own parameter (a bound the instance
already decides).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;ascription&lt;/code&gt;; ascription itself approved by the user 2026-11-13):
&lt;strong&gt;Type ascription &lt;code&gt;(value: T)&lt;/code&gt;, written as an item of a parenthesized list&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#type-ascription&quot;&gt;types&lt;/a&gt;).
(1) &lt;em&gt;Where it parses&lt;/em&gt;: a group, a tuple’s part or a call’s argument (a named one’s value
included), never a bare &lt;code&gt;value: T&lt;/code&gt; elsewhere. WHY: inside parentheses &lt;code&gt;:&lt;/code&gt; has no other meaning
(named arguments use &lt;code&gt;=&lt;/code&gt;, a map literal’s &lt;code&gt;:&lt;/code&gt; is inside braces, a field’s or parameter’s type is
in a declaration), so the grammar stays unambiguous with no new token; at a statement’s level
&lt;code&gt;x: T&lt;/code&gt; would read as half of a declaration. ALTERNATIVES: bare &lt;code&gt;value: T&lt;/code&gt; anywhere (collides with
&lt;code&gt;val x: T&lt;/code&gt;, clause signatures and a match arm’s type pattern &lt;code&gt;n: int -&amp;gt; …&lt;/code&gt;); a keyword
(&lt;code&gt;value as T&lt;/code&gt;, a word read as a conversion, which this is not); parentheses only for a group, not
for arguments (&lt;code&gt;f((None: Option[string]))&lt;/code&gt; doubles every bracket).
(2) &lt;em&gt;What it accepts&lt;/em&gt;: exactly what &lt;code&gt;val x: T = value&lt;/code&gt; accepts — literals taking &lt;code&gt;T&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt;,
empty collections and lambdas typed by &lt;code&gt;T&lt;/code&gt;, a subtype’s value, a union’s member — and the
expression is of type &lt;code&gt;T&lt;/code&gt;. WHY: one rule a reader already knows, and no conversion hides in a
form that looks like a type. ALTERNATIVES: also converting numbers (&lt;code&gt;(n: long)&lt;/code&gt; of an &lt;code&gt;int&lt;/code&gt;),
which is the implicit widening the spec refuses; accepting narrowing as a checked downcast, which
is a &lt;code&gt;match&lt;/code&gt;‘s job.
(3) &lt;em&gt;The refusal&lt;/em&gt; says what to write: &lt;code&gt;long(n)&lt;/code&gt; for a numeric conversion, &lt;code&gt;BigInt(k)&lt;/code&gt; /
&lt;code&gt;T.fromInteger(k)&lt;/code&gt; for an integer variable to a type that takes integers, the explicit
&lt;code&gt;BigDecimal.fromReal…&lt;/code&gt; for a &lt;code&gt;real&lt;/code&gt;, and &lt;code&gt;is&lt;/code&gt;/&lt;code&gt;match&lt;/code&gt; for a narrowing.
(4) &lt;em&gt;Ambiguities settled&lt;/em&gt;: &lt;code&gt;(n: long) -&amp;gt; …&lt;/code&gt; stays a lambda; &lt;code&gt;x: int -&amp;gt; body&lt;/code&gt; whose rest is not
type-shaped keeps its hint “a lambda’s parameter with a type is written in parentheses”, while
&lt;code&gt;(f: int -&amp;gt; int)&lt;/code&gt; is an ascription to a function type; at the start of a block’s line
&lt;code&gt;name(x: T)&lt;/code&gt; followed by &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;-&amp;gt;&lt;/code&gt;, an indented block or a clause line still declares a local
function, and a clause signature now needs its next line to be a clause (followed by &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt; or
guards), so two &lt;code&gt;show(n: long)&lt;/code&gt; calls on consecutive lines are calls; a parameter counts as typed
only when a name precedes its &lt;code&gt;:&lt;/code&gt;, so &lt;code&gt;show(1: long)&lt;/code&gt; is never a declaration.
(5) &lt;code&gt;(_: T)&lt;/code&gt; in a placeholder lambda is a parameter of type &lt;code&gt;T&lt;/code&gt;. WHY: it is the one place a
placeholder’s type can be written. ALTERNATIVES: leaving &lt;code&gt;_&lt;/code&gt; untyped inside an ascription (the
ascription would still constrain it, but a mismatch would read as the ascription’s error rather
than the parameter’s). Review with the user: (1)’s rule that a statement-level &lt;code&gt;retry(n: long)&lt;/code&gt;
followed by an indented block is a declaration (write &lt;code&gt;retry((n: long))&lt;/code&gt; to call it).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Actor patterns&lt;/strong&gt; (&lt;a href=&quot;/spec/actors/#routers&quot;&gt;actors&lt;/a&gt;, branch &lt;code&gt;actor-patterns&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;actor-patterns&lt;/code&gt;): &lt;strong&gt;Routers are &lt;code&gt;Router.pool(size, behaviour, routing, onFailure, executor)&lt;/code&gt;, giving back a plain &lt;code&gt;ActorRef[M]&lt;/code&gt;.&lt;/strong&gt; The router is an actor of its
own, the routees its children, so the lifecycle and supervision of actors cover it with nothing
new: &lt;code&gt;stop(router)&lt;/code&gt; ends the routees first, a routee’s &lt;code&gt;onFailure&lt;/code&gt; is the router’s argument, a
routee that ends leaves the pool and the router stops with the last one, and a routee’s
escalation fails the router, which always escalates (the router’s own supervision is not a
parameter). The routings are the &lt;code&gt;data Routing[M]&lt;/code&gt;: &lt;code&gt;RoundRobin&lt;/code&gt; (the default), &lt;code&gt;AtRandom&lt;/code&gt;,
&lt;code&gt;SmallestMailbox&lt;/code&gt;, &lt;code&gt;ByKey(key: @sendable (M) -&amp;gt; long)&lt;/code&gt;. &lt;em&gt;Why&lt;/em&gt;: one reference that accepts the
routees’ own messages is what a caller wants, and asks through it work unchanged; a hop through
the router keeps one sender’s order per routee and keeps the pool’s state in one actor’s turns,
with no lock. &lt;em&gt;Alternatives&lt;/em&gt;: a reference whose &lt;code&gt;tell&lt;/code&gt; picks a routee in the sender’s thread (no
hop, but the pool’s changing membership shared between threads); a &lt;code&gt;Router[M]&lt;/code&gt; object with its
own &lt;code&gt;stop&lt;/code&gt; (a second lifecycle beside the actor’s); a supervision parameter for the router itself
(rarely wanted: it holds no state worth restarting). &lt;code&gt;Random&lt;/code&gt; was not taken as a variant name since
&lt;code&gt;avin.random.Random&lt;/code&gt; is a common import; &lt;code&gt;Router&lt;/code&gt; shares its name with &lt;code&gt;avin.net.http.Router&lt;/code&gt;, in
a different module. &lt;strong&gt;Review with the user:&lt;/strong&gt; the names (&lt;code&gt;AtRandom&lt;/code&gt;, &lt;code&gt;ByKey&lt;/code&gt;) and the router’s
fixed &lt;code&gt;Escalate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;actor-patterns&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;SmallestMailbox&lt;/code&gt; counts the messages waiting,
and &lt;code&gt;ByKey&lt;/code&gt; hashes by highest weight.&lt;/strong&gt; A routee’s mailbox alone keeps a count (an atomic add on
each send and take; other actors’ mailboxes pay nothing), the message being handled not counted,
ties going to the next in turn. &lt;code&gt;ByKey&lt;/code&gt; weighs each routee against the key by mixing the key with
the routee’s number and takes the heaviest, so a key keeps its routee while it lives and a routee
that ends moves only its own keys. &lt;em&gt;Why&lt;/em&gt;: the count is exact and cheap where it is needed; the
weighting needs no ring and stays consistent as the pool shrinks. &lt;em&gt;Alternatives&lt;/em&gt;: counting every
mailbox (a cost to every actor); counting a message until its handling ends (a second atomic per
message); the key modulo the pool’s size (every key moves when one routee leaves); a hash ring
(more state for pools that are small).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;actor-patterns&lt;/code&gt;): &lt;strong&gt;A message a router finds refused goes to another
routee.&lt;/strong&gt; A routee that has begun to end refuses a message, and the router chooses again among the
rest, before it has heard of the end; a message a routee accepted and then dropped as it stopped
is lost, as with any actor that stops. &lt;em&gt;Why&lt;/em&gt;: the window between a routee ending and the router
hearing of it would otherwise lose messages for no reason. &lt;em&gt;Alternative&lt;/em&gt;: dropping them.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;actor-patterns&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;Stash&lt;/code&gt; is a bounded object of the actor’s state,
&lt;code&gt;Stash(self, capacity)&lt;/code&gt;, and adding to a full one traps.&lt;/strong&gt; &lt;code&gt;unstashAll&lt;/code&gt; puts its messages in front of
every message waiting, in the order added, in a queue the actor’s turn reads before its mailbox, so
a restart keeps them as it keeps the mailbox, while what is still stashed is lost with the state.
&lt;em&gt;Why&lt;/em&gt;: the actor’s own state is where an actor’s choices live, and a stash made from the actor’s
own reference cannot be given another actor’s messages; a full stash means the actor’s design did
not foresee the load, which is a bug for supervision to handle, and an actor that wants another
policy checks &lt;code&gt;isFull&lt;/code&gt; first. &lt;em&gt;Alternatives&lt;/em&gt; for overflow: dropping the newest or the oldest
silently (a lost question looks like a timeout with no report), &lt;code&gt;add&lt;/code&gt; answering a &lt;code&gt;bool&lt;/code&gt; (easily
ignored); for the shape: &lt;code&gt;stash(message)&lt;/code&gt; and &lt;code&gt;unstashAll()&lt;/code&gt; on &lt;code&gt;ActorContext&lt;/code&gt; with a capacity
given to &lt;code&gt;spawn&lt;/code&gt; (state outside the actor’s fields, and a parameter every actor carries);
unstashed messages put at the back of the mailbox (behind messages that arrived later, losing
order). &lt;strong&gt;Review with the user:&lt;/strong&gt; trapping on overflow.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;actor-patterns&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;Topic[E]&lt;/code&gt; is a sendable object, not an actor.&lt;/strong&gt;
&lt;code&gt;publish&lt;/code&gt; tells each subscriber in the publisher’s own thread, so one publisher’s events reach
each subscriber in order with no hop; subscriptions live in one atomic value; a subscriber’s end
is watched through its &lt;code&gt;ended()&lt;/code&gt; future from its first subscription, which drops it. An actor is
subscribed once, by its number, the later reference (an adapter, say) replacing the earlier in
its place. &lt;em&gt;Why&lt;/em&gt;: any thread may publish, nothing needs stopping, and no actor’s mailbox sits
between publisher and subscriber. &lt;em&gt;Alternatives&lt;/em&gt;: a topic actor that subscribers and publishers
message, watching subscribers with &lt;code&gt;watch&lt;/code&gt; (an extra hop per event, a lifecycle to manage, and a
count that is only known by asking); topics named in a global registry (shared mutable state by
name).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#higher-kinded-types&quot;&gt;generics&lt;/a&gt;, branch &lt;code&gt;hkt-design&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor parameter is spelled &lt;code&gt;F[_]&lt;/code&gt;&lt;/strong&gt;, &lt;code&gt;F[_, _]&lt;/code&gt; for two holes, and a partial
application of a type writes &lt;code&gt;_&lt;/code&gt; for each argument left open: &lt;code&gt;Result[_, ParseError]&lt;/code&gt;,
&lt;code&gt;Map[string, _]&lt;/code&gt;. Why: the same mark at the declaration and at the use, the &lt;code&gt;_&lt;/code&gt; the language
already uses for “something left out” in patterns and lambdas, and the spelling other chapters’
prose already used for “a &lt;code&gt;Result&lt;/code&gt; of any value with this error”. Alternatives weighed: a kind
annotation (&lt;code&gt;F: * -&amp;gt; *&lt;/code&gt;, notation with no other use in the language); a type-lambda form
(&lt;code&gt;[X] =&amp;gt; Result[X, E]&lt;/code&gt;, general but a second way to write types, and lambdas make constructor
equality undecidable in general); declaring the constructor by an alias only (every partial
application would need a named alias). Review with the user: the spelling is the most visible
choice of the design.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;holes are direct arguments of one nominal type; no nested &lt;code&gt;_&lt;/code&gt;, no constructors of
constructors (&lt;code&gt;F[_[_]]&lt;/code&gt;), no tuple or function constructors.&lt;/strong&gt; A generic alias whose parameters
are each one direct argument of its expansion is a constructor too. Why: a constructor is then a
nominal type with places left open, so equality is structural and inference has one answer, the
core of the soundness argument; composition (&lt;code&gt;Option[List[_]]&lt;/code&gt;) is a data type of the program’s
own. Alternatives: general type lambdas (undecidable equality, inference with many answers);
allowing any alias as a lambda (the same problem behind a name). Review with the user: whether
composed constructors are wanted soon.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a hole may declare variance (&lt;code&gt;F[+_]&lt;/code&gt;) and bounds (&lt;code&gt;F[_: Sendable]&lt;/code&gt;)&lt;/strong&gt;, a demand on the
constructor passed: &lt;code&gt;+_&lt;/code&gt; lets &lt;code&gt;F[Dog]&lt;/code&gt; be an &lt;code&gt;F[Animal]&lt;/code&gt; inside the declaration and takes only
constructors covariant there; a bounded hole is applied only to types meeting the bound, checked
at each &lt;code&gt;F[X]&lt;/code&gt; written, and takes constructors whose parameter’s bounds the hole’s imply. A plain
&lt;code&gt;_&lt;/code&gt; is invariant and unbounded, and refuses a type with a bounded parameter at the hole
(&lt;code&gt;TreeSet&lt;/code&gt;). Why: each is checked at the definition, so no instance can fail; bounded holes are
what let &lt;code&gt;Future&lt;/code&gt; (&lt;code&gt;Sendable&lt;/code&gt;) and sorted collections (&lt;code&gt;Ord&lt;/code&gt;) be constructors at all.
Alternatives: always invariant (loses &lt;code&gt;F[Dog]&lt;/code&gt; as &lt;code&gt;F[Animal]&lt;/code&gt; where code wants it, at no gain in
simplicity); always covariant (unsound for &lt;code&gt;Array&lt;/code&gt;); refusing bounded types outright (excludes
&lt;code&gt;Future&lt;/code&gt; from comprehensions).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;constructor traits are spelled with &lt;code&gt;Self[…]&lt;/code&gt;, the trait’s parameters being the
holes&lt;/strong&gt;: &lt;code&gt;trait Functor[A]&lt;/code&gt; with &lt;code&gt;map[B](f: (A) -&amp;gt; B) -&amp;gt; Self[B]&lt;/code&gt;, bounds written &lt;code&gt;[F[_]: Monad]&lt;/code&gt;.
Why: it reads like every other Avin trait (&lt;code&gt;Iterable[+A]&lt;/code&gt; with &lt;code&gt;map[B]&lt;/code&gt;), keeps &lt;code&gt;impl Trait for Type&lt;/code&gt; as the one form of conformance, and the common case (calling &lt;code&gt;fa.map&lt;/code&gt;, writing
&lt;code&gt;impl Monad for Parser&lt;/code&gt;) needs no new notation beyond &lt;code&gt;Self[B]&lt;/code&gt;. Alternatives: a type-class-style
trait over an explicit parameter (&lt;code&gt;trait Functor[F[_]]&lt;/code&gt; with &lt;code&gt;map[A, B](fa: F[A], …)&lt;/code&gt;, which puts
the receiver in a parameter and makes every call &lt;code&gt;F.map(fa, f)&lt;/code&gt; or needs a second rule for method
syntax); marking constructor traits with a keyword (redundant: &lt;code&gt;Self[B]&lt;/code&gt; already says it). Review
with the user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor trait is a bound and never a type, its parameters take no variance, and
its static members name none of them.&lt;/strong&gt; Why: no object of unknown constructor exists, so no dynamic
dispatch over constructors and no existential is needed; every call is direct in a monomorphized
instance. Alternatives: trait objects of &lt;code&gt;Monad&lt;/code&gt; (need a run-time constructor witness and type
erasure of the element, which reification refuses).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;an impl gives the trait the type’s parameters it leaves open&lt;/strong&gt; (&lt;code&gt;impl[T, E] Monad[T] for Result[T, E]&lt;/code&gt;), &lt;strong&gt;and both may be left off where all are open, in order&lt;/strong&gt; (&lt;code&gt;impl Monad for Option&lt;/code&gt;). Why: the partial application needs no new syntax at the impl, and the common
one-parameter case reads as plainly as &lt;code&gt;impl Ord for Money&lt;/code&gt;. Alternatives: writing the constructor
(&lt;code&gt;impl Monad for Result[_, E]&lt;/code&gt;, which needs &lt;code&gt;E&lt;/code&gt; declared somewhere); requiring the full form always
(noise in the common case). The bare form is the only impl of a generic type without its
parameters, a narrow exception.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a type implements a constructor trait once, at one choice of holes, and the
conformance is not inherited by subclasses or through traits.&lt;/strong&gt; Why: coherence gives each argument
one constructor; an inherited &lt;code&gt;map&lt;/code&gt; answers the superclass’s type, so inheriting would be unsound.
A subclass instance is matched as its nearest superclass with a conformance, then the one trait
with one. Alternatives: a conformance per hole (&lt;code&gt;Either&lt;/code&gt; a functor on both sides, at the cost of
ambiguous inference); inheritance with a check that every method is overridden at the subclass’s
type (a long tail of overrides in the library).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a type’s own methods implement a constructor trait’s where the trait’s call is a call
of them&lt;/strong&gt; with no conversion, no extra bound, their own type parameters decided by the call (a
lower bound by its bound) and a result conforming to the trait’s. Why: &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;,
&lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt; meet the family with their existing overloaded and lower-bounded
&lt;code&gt;flatMap&lt;/code&gt;s, so no collection method is duplicated or changed. This is still nominal: the impl
declares the conformance, and the rule only says which declared method serves. Alternatives:
exact signatures (forces a second &lt;code&gt;flatMap&lt;/code&gt; on every collection, an overload clash); adapters
generated per mismatch (hidden code and conversions). Review with the user: it is a looser
meeting than a class’s override, which takes the parameter types exactly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;inference of a constructor goes through its bound’s conformance&lt;/strong&gt;; without a bound
only a type of exactly the parameter’s arity is inferred, anything wider needs &lt;code&gt;F&lt;/code&gt; written; the
written-out arguments join by the type’s variance (&lt;code&gt;Ok(1)&lt;/code&gt; beside a &lt;code&gt;Result[int, E]&lt;/code&gt;); two
different heads never join. Why: the impl is the one place that says which argument varies, and
joining the fixed arguments keeps &lt;code&gt;Nothing&lt;/code&gt;-typed literals pleasant. Alternatives: the last
argument always the hole (wrong for &lt;code&gt;Result&lt;/code&gt;, whose value is first); unification over every
choice of holes (ambiguous, order-dependent).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor trait’s default bodies are compiled once per implementing constructor
and may call its static members on &lt;code&gt;Self&lt;/code&gt;.&lt;/strong&gt; Why: &lt;code&gt;Monad&lt;/code&gt;‘s &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;map2&lt;/code&gt; from &lt;code&gt;flatMap&lt;/code&gt; and
&lt;code&gt;pure&lt;/code&gt;, so a program’s own monad gives two members. Alternatives: no defaults (every monad writes
four members); defaults shared through a method table, as other traits’ are (no &lt;code&gt;Self&lt;/code&gt; to call
&lt;code&gt;pure&lt;/code&gt; on).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;impls may add to applications of a bounded constructor parameter&lt;/strong&gt;
(&lt;code&gt;impl[F[_]: Traverse, G[_]: Applicative, A] F[G[A]]&lt;/code&gt;), matched through the conformance, with the
rules of impls adding to types built from parameters. Why: &lt;code&gt;xs.sequence()&lt;/code&gt; reads as a method, and
a package can extend every monad at once. Alternatives: free functions only (&lt;code&gt;sequence(xs)&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the standard traits are &lt;code&gt;Functor&lt;/code&gt;, &lt;code&gt;Foldable&lt;/code&gt;, &lt;code&gt;Applicative&lt;/code&gt;, &lt;code&gt;Monad&lt;/code&gt;, &lt;code&gt;Filter&lt;/code&gt;,
&lt;code&gt;Traverse&lt;/code&gt;, and the sendable pair &lt;code&gt;SendableFunctor&lt;/code&gt;/&lt;code&gt;SendableMonad&lt;/code&gt;, in module &lt;code&gt;avin&lt;/code&gt;&lt;/strong&gt;, with
&lt;code&gt;Applicative&lt;/code&gt;‘s second member &lt;code&gt;map2&lt;/code&gt; and &lt;code&gt;Foldable&lt;/code&gt; holding &lt;code&gt;foldLeft&lt;/code&gt; alone. Why: &lt;code&gt;Foldable&lt;/code&gt; is
warranted because &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt; are no &lt;code&gt;Iterable&lt;/code&gt;s and &lt;code&gt;Traverse&lt;/code&gt; needs a fold;
&lt;code&gt;map2&lt;/code&gt; reads better than an &lt;code&gt;ap&lt;/code&gt; over functions; &lt;code&gt;Filter&lt;/code&gt; is the nominal home of a comprehension’s
guard; the sendable pair is how &lt;code&gt;Future&lt;/code&gt;, whose combinators need &lt;code&gt;Sendable&lt;/code&gt; values and &lt;code&gt;@sendable&lt;/code&gt;
functions, meets a family. Alternatives: &lt;code&gt;ap&lt;/code&gt; (the classic, harder to read); &lt;code&gt;zip&lt;/code&gt;/&lt;code&gt;product&lt;/code&gt; as
the second member (&lt;code&gt;zip&lt;/code&gt; already pairs sequences by position and &lt;code&gt;product&lt;/code&gt; multiplies); no
&lt;code&gt;Foldable&lt;/code&gt; (no fold over an option in generic code); &lt;code&gt;Future&lt;/code&gt; left out (breaks comprehensions over
futures). Review with the user: the names, and whether the sendable pair should rather be a hole
bound on the ordinary traits.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;which library types implement what&lt;/strong&gt;: &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result[_, E]&lt;/code&gt;, &lt;code&gt;Either[L, _]&lt;/code&gt; and
the immutable sequences (&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;Seq&lt;/code&gt;) the whole family, &lt;code&gt;Filter&lt;/code&gt;
except on &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt;; &lt;code&gt;LazyList&lt;/code&gt; all but &lt;code&gt;Traverse&lt;/code&gt;; &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt; and
&lt;code&gt;Set&lt;/code&gt; &lt;code&gt;Functor&lt;/code&gt;, &lt;code&gt;Foldable&lt;/code&gt; and &lt;code&gt;Filter&lt;/code&gt;; &lt;code&gt;Future&lt;/code&gt; the sendable pair; &lt;code&gt;Map&lt;/code&gt;, the sorted
collections, &lt;code&gt;Iterator&lt;/code&gt; and &lt;code&gt;Range&lt;/code&gt; none, each for the reason its signatures show. A sequence’s
&lt;code&gt;map2&lt;/code&gt; is cartesian, as its &lt;code&gt;flatMap&lt;/code&gt;. Why: each impl is lawful, and the laws are tested.
Alternatives: &lt;code&gt;Monad&lt;/code&gt; for the mutable collections (lawful, but &lt;code&gt;pure&lt;/code&gt; making a mutable array
surprises); &lt;code&gt;Map&lt;/code&gt; as a functor over its values (its &lt;code&gt;map&lt;/code&gt; takes entries, so it needs a method of
another name).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;for&lt;/code&gt; comprehensions admit their sources by conformance&lt;/strong&gt;: the last generator an
&lt;code&gt;Iterable&lt;/code&gt; or a &lt;code&gt;Functor&lt;/code&gt; (or &lt;code&gt;SendableFunctor&lt;/code&gt;), an earlier one an &lt;code&gt;Iterable&lt;/code&gt; or a &lt;code&gt;Monad&lt;/code&gt; (or
&lt;code&gt;SendableMonad&lt;/code&gt;), a guard an &lt;code&gt;Iterable&lt;/code&gt; (through its lazy &lt;code&gt;withFilter&lt;/code&gt;, whose views become
&lt;code&gt;Iterable&lt;/code&gt;s) or a &lt;code&gt;Filter&lt;/code&gt; (through &lt;code&gt;filter&lt;/code&gt;); in generic code the bounds decide; the calls are
then checked as written out, so mixed sources (&lt;code&gt;for w in words, n in parse(w)&lt;/code&gt;) keep working
through the collections’ own overloads. A type with &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; and no impl is no
longer a source: the error says which impl to declare. Why: the user’s rule that Avin is nominal;
the structural rule admitted any type with methods of those names. Alternatives: keeping the
structural rule (contradicts the rule); desugaring every comprehension through the traits’
members only (loses the collections’ precise mixed-source results and &lt;code&gt;withFilter&lt;/code&gt;‘s laziness, a
visible change in the order of evaluation). Built on branch &lt;code&gt;hkt-8&lt;/code&gt; (&lt;code&gt;admitted_source&lt;/code&gt; in
&lt;code&gt;check.sysl&lt;/code&gt;; &lt;code&gt;tests/run/for_yield_conformance{,_gc}.avin&lt;/code&gt;, &lt;code&gt;tests/reject/for_yield_roles{,_more}.avin&lt;/code&gt;,
&lt;code&gt;tests/reject/for_yield_generator_mismatch.avin&lt;/code&gt;), with a definition a guard follows asking
&lt;code&gt;Monad&lt;/code&gt; of its source, as the collections chapter says, though its &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;filter&lt;/code&gt; would
need only &lt;code&gt;Functor&lt;/code&gt; and &lt;code&gt;Filter&lt;/code&gt;. Review with the user: it breaks programs whose own
types relied on the structural rule, each fixed by one &lt;code&gt;impl&lt;/code&gt;; and whether a guarded definition
should ask only &lt;code&gt;Functor&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Decided by the user 2026-11-14: &lt;strong&gt;a built-in type’s name in a pattern is a type pattern&lt;/strong&gt;:
&lt;code&gt;x is int&lt;/code&gt; tests the type and an arm &lt;code&gt;int -&amp;gt;&lt;/code&gt; matches an int, for every name in the table of
built-in types, the sized integers &lt;code&gt;iN&lt;/code&gt; included; generic forms stay &lt;code&gt;_: Vector[int]&lt;/code&gt;; a name
with a binding is &lt;code&gt;n: int&lt;/code&gt;. Built on branch &lt;code&gt;is-type-name&lt;/code&gt;, where &lt;code&gt;x is int&lt;/code&gt; had bound a new
&lt;code&gt;int&lt;/code&gt; and was always true (&lt;code&gt;tests/run/operands_for_traits.avin&lt;/code&gt; tested nothing). Proposed with it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Such a name never names a value&lt;/strong&gt;: a local (&lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt;), a function’s, a lambda’s or a
class’s parameter, a data field, and a pattern binding it (&lt;code&gt;int: T&lt;/code&gt;, &lt;code&gt;int @ p&lt;/code&gt;, &lt;code&gt;int + 1&lt;/code&gt;, a
comparison pattern, &lt;code&gt;int*&lt;/code&gt;) are errors, &lt;code&gt;`int` is a built-in type, so it cannot name a value&lt;/code&gt; and &lt;code&gt;…, so a pattern cannot bind it: alone it tests for the type, and `n: int` binds the value as one&lt;/code&gt;. Why: with the names type patterns, &lt;code&gt;val (a, int) = p&lt;/code&gt; would test where &lt;code&gt;val int = 3&lt;/code&gt; binds, and &lt;code&gt;int(x)&lt;/code&gt; in an expression would mean the conversion or the local by context;
refusing them everywhere keeps one meaning per name. It also settles the hiding rule for built-in
statics: &lt;code&gt;val string = …; string.byteLength&lt;/code&gt; no longer arises. The library and tests renamed
their locals (&lt;code&gt;unit&lt;/code&gt; → &lt;code&gt;identity&lt;/code&gt;/&lt;code&gt;scale&lt;/code&gt;, the vector tree’s &lt;code&gt;i1&lt;/code&gt;–&lt;code&gt;i6&lt;/code&gt; → &lt;code&gt;d1&lt;/code&gt;–&lt;code&gt;d6&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;,
&lt;code&gt;real&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt; locals in tests). Alternatives: allowing them as &lt;code&gt;val&lt;/code&gt;/parameter names and
refusing them only in patterns (two meanings for one name, and destructuring differs from a
plain binding); allowing only the eight word names and leaving &lt;code&gt;iN&lt;/code&gt; free (the user listed the
sized integers). Review with the user: &lt;code&gt;i1&lt;/code&gt;, &lt;code&gt;i2&lt;/code&gt;, … are common index names, and they are
refused too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every type’s name in a pattern is its type pattern&lt;/strong&gt; (the same decision, extended by the
director 2026-11-14 after &lt;code&gt;a is Cell&lt;/code&gt; was found binding too): a bare or dotted name with no
parentheses that is no variant but resolves to a class, trait, &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt; type, alias,
&lt;code&gt;Any&lt;/code&gt;, &lt;code&gt;Nothing&lt;/code&gt; or type parameter is &lt;code&gt;_: T&lt;/code&gt;. A variant wins where both exist, so
&lt;code&gt;data Cell(value: int)&lt;/code&gt;‘s &lt;code&gt;Cell&lt;/code&gt; stays the variant’s pattern and every variant pattern is
unchanged. A local, a parameter (of a function, local function or lambda) or a pattern binding
named after a type in scope is refused: &lt;code&gt;`Cell` is a type, so it cannot name a value: in a pattern it tests for the type, and `x: Cell` binds a value of it&lt;/code&gt;. Fields named after a user
type are not refused (they are reached as members, and a data field’s pattern is positional).
Why: one meaning per name in a pattern; a capitalised name quietly binding was the same defect.
Alternatives: only refusing capitalised bindings that shadow a type (keeps the always-true test
as an error rather than a feature); including field names (more renames for no pattern
ambiguity).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A generic type’s name alone in a pattern is refused&lt;/strong&gt;, &lt;code&gt;`Box` is a generic type, and a type pattern names its type arguments, as in `_: Box[int]`&lt;/code&gt;. Why: a type pattern compares type
arguments exactly, and the run-time test of “a &lt;code&gt;Box&lt;/code&gt; at any arguments” would be a new kind of
test with no sound meaning for variance and value-type arguments yet. Alternatives: testing the
class at any arguments (needs a class-only run-time test and a binding type, &lt;code&gt;Box[?]&lt;/code&gt;, Avin
lacks); inferring the arguments from the matched type (works only where they are known, and
reads differently by context). Review with the user if a “any instance of &lt;code&gt;Box&lt;/code&gt;“ test is wanted.&lt;/li&gt;
&lt;li&gt;A type alias in a constructor pattern, &lt;code&gt;P(a, b)&lt;/code&gt;, stays refused as before.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Functions and methods may still be named so&lt;/strong&gt; (&lt;code&gt;cli&lt;/code&gt;‘s &lt;code&gt;int(name)&lt;/code&gt; and &lt;code&gt;string(name)&lt;/code&gt;
options): a function is called, never matched, so no pattern can mean it. A missing-member
witness still reads &lt;code&gt;_: string&lt;/code&gt;, which is the same pattern.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;fix-core-promises&lt;/code&gt;): &lt;strong&gt;the standard library’s &lt;code&gt;Sendable&lt;/code&gt; promises are checked
against the structure, except where &lt;code&gt;@trusted_sendable(&amp;quot;why&amp;quot;)&lt;/code&gt; marks a class&lt;/strong&gt;
(&lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;actors&lt;/a&gt;). This replaces the 2026-11-05 settlement’s “the
standard library’s promises are taken as made”, under which &lt;code&gt;Map.withDefault(f)&lt;/code&gt; answered a
sendable map holding a plain function and a thread raced on what it captured. The mark is a
class annotation (it trusts the class whether its header or an impl makes the promise), takes one
non-empty string saying why the class is safe, is refused outside the standard library, and is
an error on a class that promises nothing. Seventeen classes carry it: &lt;code&gt;Lock&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt;,
&lt;code&gt;Mutex&lt;/code&gt;, &lt;code&gt;Atomic&lt;/code&gt;, &lt;code&gt;Channel&lt;/code&gt;, &lt;code&gt;Thread&lt;/code&gt;, and the futures’ &lt;code&gt;Cell&lt;/code&gt;, &lt;code&gt;Pool&lt;/code&gt; and &lt;code&gt;Registry&lt;/code&gt;
(synchronization the runtime does); the running &lt;code&gt;Actor&lt;/code&gt; (its turns are serial) and &lt;code&gt;Isolated&lt;/code&gt;
(an atomic state arbitrates its objects); &lt;code&gt;TcpStream&lt;/code&gt;, &lt;code&gt;TcpListener&lt;/code&gt;, &lt;code&gt;UnixStream&lt;/code&gt;,
&lt;code&gt;UnixListener&lt;/code&gt;, &lt;code&gt;TlsStream&lt;/code&gt; and &lt;code&gt;Child&lt;/code&gt; (one owner at a time, checked by every operation).
&lt;code&gt;Future&lt;/code&gt;, &lt;code&gt;Promise&lt;/code&gt;, &lt;code&gt;Executor&lt;/code&gt; and &lt;code&gt;Once&lt;/code&gt; became sendable by their structure, &lt;code&gt;Cell&lt;/code&gt; gained an
&lt;code&gt;impl[T: Sendable] Sendable&lt;/code&gt; and &lt;code&gt;Lock&lt;/code&gt; a &lt;code&gt;: Sendable&lt;/code&gt; for it. Why: the trust is greppable and
each entry says its reason; trusting the innermost synchronized class rather than each composite
keeps the list short and checks the rest. Alternatives weighed: a list of names in the compiler
(invisible at the type, drifts from the library); trusting every class of &lt;code&gt;avin.threads&lt;/code&gt; (too
wide: it hid nothing here, but would hide the next &lt;code&gt;DefaultMap&lt;/code&gt;); marking the composites
(&lt;code&gt;Future&lt;/code&gt;, &lt;code&gt;Promise&lt;/code&gt;) instead of &lt;code&gt;Cell&lt;/code&gt; (more entries, fewer types checked).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;fix-core-promises&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;withDefault&lt;/code&gt;‘s function is &lt;code&gt;@sendable&lt;/code&gt;&lt;/strong&gt;, and the
&lt;code&gt;DefaultMap&lt;/code&gt; holds its default as a private &lt;code&gt;MapDefault&lt;/code&gt; data value, &lt;code&gt;Fixed(v)&lt;/code&gt; or
&lt;code&gt;Computed(f)&lt;/code&gt;, so &lt;code&gt;withDefaultValue(v)&lt;/code&gt; takes any value and the wrapper is sendable wherever the
map and &lt;code&gt;v&lt;/code&gt; are. Why: &lt;code&gt;Map&lt;/code&gt; promises &lt;code&gt;Sendable&lt;/code&gt; and every map is one, so the default must be
sendable for the wrapper to keep the promise; most defaults (&lt;code&gt;k -&amp;gt; 0&lt;/code&gt;, &lt;code&gt;k -&amp;gt; k.length&lt;/code&gt;) capture
nothing mutable and are unchanged. Alternatives weighed: &lt;code&gt;Map&lt;/code&gt; not promising &lt;code&gt;Sendable&lt;/code&gt; (every
immutable map would stop being sendable); &lt;code&gt;DefaultMap&lt;/code&gt; alone not being a &lt;code&gt;Map&lt;/code&gt; (breaks
&lt;code&gt;val m: Map[K, V] = ….withDefault(f)&lt;/code&gt;); keeping a plain function and making the wrapper not
sendable (a trait’s implementers cannot opt out). Review with the user: a default that mutated a
captured local (a call counter) now uses an &lt;code&gt;Atomic&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;fix-core-promises&lt;/code&gt;): &lt;strong&gt;a &lt;code&gt;TlsStream&lt;/code&gt; checks its owner before every operation&lt;/strong&gt;,
through a token handle as &lt;code&gt;Child&lt;/code&gt; does, so a stream handed to another thread traps its previous
owner at a read served from the bytes read ahead; before, only a read that reached the socket
checked, and a buffered read raced. Why: the same rule a &lt;code&gt;TcpStream&lt;/code&gt; keeps. Alternative: none
sound.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;the build cache keeps itself within a limit, least recently
used first, with no index&lt;/strong&gt;: an entry is a program’s build directory (&lt;code&gt;build/&lt;/code&gt;, &lt;code&gt;test-builds/&lt;/code&gt;) or
one object or archive (&lt;code&gt;units/&lt;/code&gt;, &lt;code&gt;runtime/&lt;/code&gt;, &lt;code&gt;shims/&lt;/code&gt;, &lt;code&gt;cunit/&lt;/code&gt;), and its modification time is its
last use, touched by every build that takes it from the cache (a program’s directory when its
build starts and before each test &lt;code&gt;avin test&lt;/code&gt; runs). Every command that builds sweeps the cache at
most once in ten minutes, a stamp file in the cache shared by every process, and evicts the
oldest entries until the cache is within &lt;code&gt;AVIN_CACHE_LIMIT&lt;/code&gt; (a size with &lt;code&gt;K&lt;/code&gt;/&lt;code&gt;M&lt;/code&gt;/&lt;code&gt;G&lt;/code&gt;/&lt;code&gt;T&lt;/code&gt;, &lt;code&gt;off&lt;/code&gt;
for none, default 5G; a value that is neither is an error from every command). Why: builds run in
many worktrees and sessions at once, so a shared index would need a lock Sysl’s library does not
offer, while a touch is one system call and the existing unit-object trim already worked by
modification time. Alternatives: an index file of use times (a lock, and a writer killed halfway
through it); access times (&lt;code&gt;noatime&lt;/code&gt; mounts, and macOS updates them lazily); a sweep after every
build (the size walk on every build); an hourly sweep (24G had grown within hours). Review with
the user: the 5G default and the ten-minute interval.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;nothing used within the hour is evicted, and an entry is renamed
aside, looked at again and put back if a build touched it in between&lt;/strong&gt;, before it is removed.
Why: no build reading or writing an entry loses it, without a lock; a cache whose fresh entries
alone pass the limit stays past it until they age. Alternatives: lease files naming the process
(Sysl’s library has no way to ask whether a process is alive); &lt;code&gt;flock&lt;/code&gt; (not in Sysl’s library);
no grace (a sweep could take the executable &lt;code&gt;avin test&lt;/code&gt; starts once per test). A shim archive and
the record of the libraries it needs beside it are one entry, the archive evicted first and a
record newer than the sweep’s choice kept, so no build finds the record without its archive.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;an entry gone from under a build is a miss, never a link
error&lt;/strong&gt;: every object and archive a build takes from the cache is touched first, and one missing
(or a shim archive without its record) is built again; the link looks again at everything it takes
from the cache before clang runs and after clang fails, answers an entry gone in between as such
rather than as clang’s error, and the build then compiles again, which builds the entry anew, and
links once more. Why: a cache emptied by hand, or by a disk being cleared, while builds ran made two
gates fail to link a shim archive that had been there when the program compiled (2026-11-13).
Alternatives: holding the entries open across the link (clang opens them by name); copying them
out of the cache first (the copying costs every build).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;another version’s cache is removed three days after its last
use&lt;/strong&gt;, judged by the newest time on it, its kinds and their entries, and only beside the default
cache (never beside a directory &lt;code&gt;AVIN_CACHE&lt;/code&gt; names), and only for a name that is a version’s. Why:
no compiler of this version can read it, and three days spares a user switching back. Alternatives:
removing every other version at once (an older installed compiler still in use would rebuild each
time); never (the unreachable caches are what filled the disk).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;fetched packages are outside the limit and never evicted by a
sweep&lt;/strong&gt;; a sweep removes only the debris of interrupted fetches, and &lt;code&gt;avin cache clean --packages&lt;/code&gt;
removes packages (with &lt;code&gt;--older-than&lt;/code&gt;, those no build has read for that long; a build touches the
package it reads). Why: a package is source pinned by &lt;code&gt;avin.sum&lt;/code&gt;, small beside a build, and
fetching it again needs the network and a tag that may since have been removed, so evicting one
could break an offline or archived build. Alternatives: counting packages in the limit (evicted
first, being rarely touched, for a few hundred kilobytes saved).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;a sweep removes debris&lt;/strong&gt;: anything in the cache whose name holds
&lt;code&gt;.pending-&lt;/code&gt; (a write that was never renamed into place) that nothing has written to for an hour,
and in the temporary directory the directories a build works in (&lt;code&gt;avin-link&lt;/code&gt;, &lt;code&gt;avin-shims&lt;/code&gt;,
&lt;code&gt;avin-c-unit&lt;/code&gt; and the six characters &lt;code&gt;make_temp_dir&lt;/code&gt; adds) that nothing has written to for a day,
and the &lt;code&gt;avin-test-builds&lt;/code&gt; ones the compiler’s tests left before their builds moved into the
cache’s &lt;code&gt;test-builds/&lt;/code&gt;. Why: a killed or out-of-space build leaves these behind, and on this
machine its tests had left 8,673 such directories. A program’s own temporary directories are never
touched, whatever they are called. Alternatives: every &lt;code&gt;avin-&lt;/code&gt; directory (a program may name its
own so); none (the debris is unbounded).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;cache-trim&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin cache info | trim | clean&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;info&lt;/code&gt; shows the cache, the
limit, each kind’s entries and size, the total with its oldest and newest use, debris, fetched
packages and other versions’ caches; &lt;code&gt;trim&lt;/code&gt; sweeps now; &lt;code&gt;clean&lt;/code&gt; removes every entry, the debris and
other versions’ caches, &lt;code&gt;--older-than &amp;lt;n&amp;gt;m|h|d&lt;/code&gt; only what no build has used for that long, and
&lt;code&gt;--packages&lt;/code&gt; the fetched packages too. &lt;code&gt;avin clean&lt;/code&gt; keeps its meaning (one program’s builds, or
&lt;code&gt;--all&lt;/code&gt; every program’s). Why: the user sees what the cache holds and can empty it without
knowing its layout. Alternatives: folding these into &lt;code&gt;avin clean&lt;/code&gt; (whose argument is a program).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a marked parameter survives a function becoming a value only through its type&lt;/strong&gt;
(branch &lt;code&gt;fix-fn-value-marks&lt;/code&gt;): a function, constructor or method whose parameter is &lt;code&gt;@sendable&lt;/code&gt;,
&lt;code&gt;@isolating&lt;/code&gt; or &lt;code&gt;@isolated&lt;/code&gt; is a value only where the value’s type gives that parameter a sendable
type, which for a function is a &lt;code&gt;@sendable&lt;/code&gt; function type; with no function type expected, the
value takes that form of each marked function parameter (&lt;code&gt;val sp = spawn[int]&lt;/code&gt; is a
&lt;code&gt;(@sendable () -&amp;gt; int, long) -&amp;gt; Thread[int]&lt;/code&gt;). A type that is a function (a class naming it, or an
impl of it for a data type) has an &lt;code&gt;apply&lt;/code&gt; that marks a parameter only where its function type
makes that parameter sendable, and a &lt;code&gt;@sendable&lt;/code&gt; parameter matches a &lt;code&gt;@sendable&lt;/code&gt; function type’s.
Why: function types carry no parameter marks, so &lt;code&gt;val sp: (() -&amp;gt; unit, long) -&amp;gt; Thread[unit] = spawn&lt;/code&gt; ran a buffer-capturing closure on four threads, and &lt;code&gt;Isolated&lt;/code&gt;/&lt;code&gt;Mutex&lt;/code&gt; as values kept an
object the caller still used. Alternatives: marks in function types (&lt;code&gt;(@sendable f: () -&amp;gt; unit) -&amp;gt; unit&lt;/code&gt;; a second way to say what &lt;code&gt;@sendable () -&amp;gt; unit&lt;/code&gt; says for functions, and for a non-function
&lt;code&gt;@isolating&lt;/code&gt; value a new kind of type); refusing every such function as a value, as a &lt;code&gt;@threaded&lt;/code&gt;
one is (also sound, but &lt;code&gt;spawn&lt;/code&gt; and &lt;code&gt;onExit&lt;/code&gt; could never be held or passed). A by-name marked
parameter has no sendable type, so &lt;code&gt;isolate&lt;/code&gt; and &lt;code&gt;Future.apply&lt;/code&gt; are never values; an &lt;code&gt;@isolated&lt;/code&gt;
function parameter takes the &lt;code&gt;@sendable&lt;/code&gt; form, which asks a little more than the mark (no
captured &lt;code&gt;var&lt;/code&gt;). Method values keep their own wording, from the call inside the closure they are.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;inside brackets a comma ends a &lt;code&gt;match&lt;/code&gt; arm’s one-line body and the &lt;code&gt;match&lt;/code&gt;&lt;/strong&gt; (branch
&lt;code&gt;fix-match-arg&lt;/code&gt;): in call arguments, tuple, collection literals and &lt;code&gt;with&lt;/code&gt; changes, the comma after
an arm (indented arms included) ends the arm, the &lt;code&gt;match&lt;/code&gt; and the item, so &lt;code&gt;f(x match&lt;/code&gt; … &lt;code&gt;_ -&amp;gt; 0, &amp;quot;a&amp;quot;)&lt;/code&gt; passes two arguments; a tuple body there is parenthesized; a one-line &lt;code&gt;yield&lt;/code&gt; value stops
at the comma the same way. A comma after an arm when the next line at the arms’ depth reads as
another arm (it starts with &lt;code&gt;else&lt;/code&gt; or holds an &lt;code&gt;-&amp;gt;&lt;/code&gt; outside brackets) is reported as a tuple that
needs parentheses. Why: the indented arms were read as lines of a block, so the last arm’s body
swallowed the following arguments as a tuple, a type error far from the cause; a &lt;code&gt;return&lt;/code&gt; value,
a lambda’s and a one-line &lt;code&gt;if&lt;/code&gt;‘s bodies already stop at the comma. Alternatives: keep the arms a
line context (the spec’s “an indented block starts a line again”), which makes &lt;code&gt;_ -&amp;gt; 0, &amp;quot;a&amp;quot;)&lt;/code&gt; a
tuple and needs parentheses around the whole &lt;code&gt;match&lt;/code&gt;; or end the &lt;code&gt;match&lt;/code&gt; only on the arm’s own
line, which would read a middle arm’s comma silently. The arm-shaped-line check can misfire on a
lambda argument written on its own line at the arms’ depth after the &lt;code&gt;match&lt;/code&gt;, a layout nothing
writes. An indented arm body stays a block, where a comma list is a tuple (up to a last line that
closes the brackets, below).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types, kinds and written constructor parameters&lt;/strong&gt; (build plan step 1, branch &lt;code&gt;hkt-1&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a type with a constructor parameter derives nothing through a template, and has no
automatic &lt;code&gt;Display&lt;/code&gt; or &lt;code&gt;Debug&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;derives Eq&lt;/code&gt; on a class, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt; or a library trait is
refused with the parameter named, and a value is shown by its type, as a value of no &lt;code&gt;Display&lt;/code&gt;
is. A data type keeps its built-in structural &lt;code&gt;==&lt;/code&gt;. Why: a template’s impl bounds each of the
type’s parameters by the trait, a bound for types that no constructor parameter takes, and what
displays an &lt;code&gt;F[A]&lt;/code&gt; is unknown where &lt;code&gt;F&lt;/code&gt; is any constructor. Reviewed once step 2 landed (branch
&lt;code&gt;hkt-2&lt;/code&gt;) and kept: a hole’s bounds (&lt;code&gt;F[_: Eq]&lt;/code&gt;) say what &lt;code&gt;F&lt;/code&gt; is applied to, never what an
&lt;code&gt;F[A]&lt;/code&gt; meets, so they give a derivation nothing to call. Alternatives: deriving through a bounded
hole (unsound for the reason above: &lt;code&gt;F[_: Eq]&lt;/code&gt; admits a constructor whose values have no &lt;code&gt;Eq&lt;/code&gt;
of their own beyond identity); requiring &lt;code&gt;F[A]: Display&lt;/code&gt; per field (a constraint on
applications, which impls over constructor parameters, step 6, are the place for). Review with
the user: whether step 6’s impls over constructor parameters should now give a bounded hole’s
types a derivation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;F[-_]&lt;/code&gt; is parsed alongside &lt;code&gt;F[+_]&lt;/code&gt;&lt;/strong&gt;, as the spec writes only &lt;code&gt;+_&lt;/code&gt;. Why: variance
is written the same way everywhere else, and a contravariant hole is the dual demand
(&lt;code&gt;Ordering&lt;/code&gt;-like constructors). Alternatives: refusing &lt;code&gt;-_&lt;/code&gt; until a use appears.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a type whose parameter is bounded is a constructor only for a hole whose bounds imply
that bound&lt;/strong&gt; (step 2, branch &lt;code&gt;hkt-2&lt;/code&gt;, replacing step 1’s refusal of every such type at any hole):
a hole’s bound implies a parameter’s where it is the same trait or class, or one that is an
instance of it (a trait requiring it, a subclass), as &lt;code&gt;Ord&lt;/code&gt; implies &lt;code&gt;Eq&lt;/code&gt;; &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt; need
no hole bound, since every Avin type has them (which is what lets &lt;code&gt;Map[_, V]&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; be
constructors for a plain &lt;code&gt;_&lt;/code&gt;); a parameter’s bound that names the parameter itself is implied by
no hole bound. A constructor parameter passed for another is held the same way by its own holes’
bounds. The check is made where the type arguments are held to their bounds, so a constructor
written and one inferred are refused alike, with one message. Why: an &lt;code&gt;F[_]&lt;/code&gt; may be applied to
any type, so a constructor with a bounded parameter could otherwise be instantiated at a type its
bound refuses; implication is the least the hole must promise. Alternatives: checking each
application at instantiation (an instance could then fail, against the design); entailment
through impls with bounds of their own (no case needs it yet).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;every &lt;code&gt;F[X]&lt;/code&gt; a declaration writes is held to the bounds of &lt;code&gt;F&lt;/code&gt;‘s holes where it is
written&lt;/strong&gt;, once per application, with the message “&lt;code&gt;X&lt;/code&gt; does not conform to &lt;code&gt;B&lt;/code&gt;, the bound of
&lt;code&gt;F&lt;/code&gt;‘s argument in &lt;code&gt;F[_: B]&lt;/code&gt;“: a signature naming &lt;code&gt;F[A]&lt;/code&gt; twice for an &lt;code&gt;A&lt;/code&gt; without the bound reports
both. Why: the spec’s rule is “checked wherever the declaration writes &lt;code&gt;F[X]&lt;/code&gt;“; each place is a
separate mistake to fix. Alternatives: one report per declaration (hides the second place).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a hole’s variance is what makes &lt;code&gt;F[A]&lt;/code&gt; variant&lt;/strong&gt; (step 2, replacing step 1’s
invariance of every applied argument): inside the declaration an argument of &lt;code&gt;F[A]&lt;/code&gt; is at the
position its hole gives it, kept at &lt;code&gt;+_&lt;/code&gt;, flipped at &lt;code&gt;-_&lt;/code&gt;, invariant at &lt;code&gt;_&lt;/code&gt;, so &lt;code&gt;+A&lt;/code&gt; in a field
&lt;code&gt;F[A]&lt;/code&gt; is accepted for &lt;code&gt;F[+_]&lt;/code&gt; and refused for &lt;code&gt;F[_]&lt;/code&gt;; &lt;code&gt;F[Dog]&lt;/code&gt; is an &lt;code&gt;F[Animal]&lt;/code&gt; only at &lt;code&gt;+_&lt;/code&gt;
(and &lt;code&gt;F[Animal]&lt;/code&gt; an &lt;code&gt;F[Dog]&lt;/code&gt; at &lt;code&gt;-_&lt;/code&gt;), where the arguments are references, as for any type. At
each constructor passed, written or inferred, the type’s parameter at a &lt;code&gt;+_&lt;/code&gt; hole must be
covariant and at a &lt;code&gt;-_&lt;/code&gt; hole contravariant; a constructor parameter passed must declare that
variance on its own hole. Why: the subtyping assumed inside the declaration is then exactly what
each instance grants. Alternatives: none sound that keep &lt;code&gt;F[+_]&lt;/code&gt; useful.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor parameter has no &lt;code&gt;Nothing&lt;/code&gt; default&lt;/strong&gt;: one that is neither written nor
inferred is an error, where a plain type parameter left unconstrained defaults to &lt;code&gt;Nothing&lt;/code&gt;.
Why: there is no “empty constructor” to default to. Alternatives: defaulting to a constructor
of &lt;code&gt;Nothing&lt;/code&gt; (meaningless as a constructor).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;with overloads, the first candidate’s type parameters decide which written argument
is resolved as a constructor&lt;/strong&gt;, before a candidate is chosen. Why: written type arguments are
resolved once, before overload resolution, and overloads differing in the kinds of their type
parameters are rare; resolving per candidate would need resolution repeated per overload.
Alternatives: resolving the arguments once per candidate (correct for mixed kinds, more work in
the hottest path); refusing overloads whose type parameters differ in kind. Review with the user
if overloads of mixed kinds turn up.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;&lt;code&gt;_&lt;/code&gt; alone as a written argument at a call is read as a hole&lt;/strong&gt;, so that the checker
says what the argument takes (&lt;code&gt;_&lt;/code&gt; alone names no type, or &lt;code&gt;_&lt;/code&gt; is no type at a type parameter)
instead of &lt;code&gt;unknown type&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a &lt;code&gt;for&lt;/code&gt; loop admits its source by conformance to &lt;code&gt;Iterable&lt;/code&gt;&lt;/strong&gt; (branch
&lt;code&gt;nominal-for-in&lt;/code&gt;): besides a range written in place, a &lt;code&gt;Range&lt;/code&gt; and an array, the source’s type
conforms to &lt;code&gt;Iterable&lt;/code&gt; at some element type through its class’s or data type’s parents and impls,
a type parameter’s bounds, a built-in type’s impls, or, for a union, every member’s. A type with
an &lt;code&gt;iterator()&lt;/code&gt; method and no conformance is refused, the error naming the type and the impl to
declare; &lt;code&gt;Option&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt;, which have &lt;code&gt;iterator()&lt;/code&gt; but are not &lt;code&gt;Iterable&lt;/code&gt;s, are refused too,
an option pointed at &lt;code&gt;toList&lt;/code&gt;. Why: the user’s rule that Avin is nominal, and collections.md
already said a class is iterable by conforming; the structural check admitted any type with a
method of that name. Alternatives: admitting &lt;code&gt;Option&lt;/code&gt; as a loop source (it is not an &lt;code&gt;Iterable&lt;/code&gt;
anywhere else, so a loop would be the one place it acted as one); refusing unions (each member
conforms, and the loop’s &lt;code&gt;iterator()&lt;/code&gt; call is answered by every member).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;select&lt;/code&gt;): &lt;strong&gt;A &lt;code&gt;select&lt;/code&gt; block’s syntax&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#select&quot;&gt;Threads&lt;/a&gt;).
&lt;code&gt;select&lt;/code&gt; ending its line opens a block of arms written as a match’s: &lt;code&gt;ch.receive() as P -&amp;gt; body&lt;/code&gt;,
&lt;code&gt;ch.send(x) -&amp;gt; body&lt;/code&gt;, &lt;code&gt;after d -&amp;gt; body&lt;/code&gt;, and &lt;code&gt;else body&lt;/code&gt; with no arrow; &lt;code&gt;end select&lt;/code&gt; may close it.
&lt;code&gt;select&lt;/code&gt; is a contextual word, a name anywhere else, as &lt;code&gt;actor&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; are. Why: the arms
read as the match arms they are compiled into, &lt;code&gt;-&amp;gt;&lt;/code&gt; is Avin’s one arrow (&lt;code&gt;=&amp;gt;&lt;/code&gt; is rejected
everywhere), and &lt;code&gt;else&lt;/code&gt; is spelled as a match’s is. Alternatives weighed: &lt;code&gt;=&amp;gt;&lt;/code&gt; arms as in the
item’s sketch (refused by the lexer and by the settled rule on arrows); a reserved keyword (breaks
every program naming something &lt;code&gt;select&lt;/code&gt;, and the library’s own prose); a library function taking
lambdas (no binding by pattern, no &lt;code&gt;return&lt;/code&gt;/&lt;code&gt;break&lt;/code&gt; from an arm, every arm a closure).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;select&lt;/code&gt;): &lt;strong&gt;What a receive arm’s pattern means.&lt;/strong&gt; &lt;code&gt;Some(p)&lt;/code&gt; waits for
a value and binds it by &lt;code&gt;p&lt;/code&gt;, any irrefutable pattern a &lt;code&gt;val&lt;/code&gt; takes; &lt;code&gt;None&lt;/code&gt; waits for the channel
closed and drained; a name waits for either and binds the &lt;code&gt;Option&lt;/code&gt;; &lt;code&gt;_&lt;/code&gt; or no pattern waits for
either. Any other pattern (a literal, a tuple, alternatives, a type pattern) is an error. So
&lt;code&gt;Some(p)&lt;/code&gt; alone is never ready on a closed, drained channel: a select whose only arms want values
from closed channels takes its &lt;code&gt;after&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt;, or waits for ever, as a select over a channel no
one sends to does. Why: the pattern says what the arm waits for, so an arm never takes a value it
then cannot match, and the common loop (&lt;code&gt;Some(j)&lt;/code&gt; and &lt;code&gt;None&lt;/code&gt; arms) reads as a match on what
&lt;code&gt;receive&lt;/code&gt; returns. Alternatives weighed: trapping where a closed channel’s &lt;code&gt;None&lt;/code&gt; matches no arm
(turns a finished producer into a crash), any pattern with an unmatched receive dropped (loses
values). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;Some(p)&lt;/code&gt; alone on a closed channel should wait or trap.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;select&lt;/code&gt;): &lt;strong&gt;Choosing and evaluating.&lt;/strong&gt; Every channel, value sent and
&lt;code&gt;after&lt;/code&gt; duration is evaluated once, in the order written, before any arm is tried; the arms are
tried in an order drawn at random each select (a Fisher–Yates shuffle from one shared
split-mix sequence), so of several ready arms each is equally likely. &lt;code&gt;after&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt; together
are an error (a select with &lt;code&gt;else&lt;/code&gt; never waits); two of either is an error. An &lt;code&gt;after&lt;/code&gt; of zero or
less tries the arms once, as &lt;code&gt;else&lt;/code&gt; does. A send arm on a closed channel traps when it is tried,
as &lt;code&gt;send&lt;/code&gt; does. Why: the order of evaluation is the order of reading; a random order is the only
fair one that needs no state per select site. Alternatives weighed: round-robin per select site
(needs a hidden mutable per site, shared between threads); trying in written order (starves the
later arms); a send arm on a closed channel never ready (hides the program’s mistake).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;select&lt;/code&gt;): &lt;strong&gt;How a select waits.&lt;/strong&gt; It waits on the very conditions a
channel’s &lt;code&gt;receive&lt;/code&gt; and &lt;code&gt;send&lt;/code&gt; wait on: in one pass, each arm is tried under its channel’s lock and,
where it cannot complete, a link of the select is enlisted on that condition’s queue before the
lock goes; the thread then parks once. The runtime wakes a link as it wakes any waiter, and the
select’s one token decides, by compare-and-set, whether a notification, the timer or a
cancellation ended the wait; a notification reaching an ended select’s link is passed by to the
next waiter. Woken through an arm, the select tries that arm first and, where it cannot complete
while the channel still holds a value (or room), notifies the next waiter, so no notification is
lost to a select that could not use it; every link is withdrawn when the wait ends. Why: a
channel’s own operations are unchanged, a select costs one park, and a plain &lt;code&gt;receive&lt;/code&gt; and a select
share one queue in arrival order. Alternatives weighed: a list of selects on each channel woken on
every change (wakes every waiting select for each value, a herd of thousands where workers share a
channel); passing every unused notification on whatever the channel holds (idle selects hand one
notification round for ever: two thousand workers ran forty times slower); a select polling with
sleeps (latency and wasted work).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;select&lt;/code&gt;): &lt;strong&gt;The library names a select is read into are public&lt;/strong&gt;:
&lt;code&gt;avin.threads.SelectArm&lt;/code&gt;, &lt;code&gt;SelectReceive&lt;/code&gt;, &lt;code&gt;SelectSend&lt;/code&gt;, &lt;code&gt;selectWaiting&lt;/code&gt;, &lt;code&gt;selectOrElse&lt;/code&gt;,
&lt;code&gt;selectWithin&lt;/code&gt;, and &lt;code&gt;Channel&lt;/code&gt;‘s &lt;code&gt;offerReceive&lt;/code&gt;, &lt;code&gt;offerSend&lt;/code&gt; and &lt;code&gt;passOn&lt;/code&gt;. Their wait parameter is
of a type private to &lt;code&gt;avin.threads&lt;/code&gt;, so no program can call an arm’s operations. Why: the code a
&lt;code&gt;select&lt;/code&gt; is read into is checked in the program’s file, so what it names is public, as the
actor’s &lt;code&gt;ActorContext&lt;/code&gt; is; members have no module-wide visibility. Alternatives weighed: a member
visibility private to the module (a language change of its own); intrinsics the compiler calls
directly (the arms are generic, and the channel logic belongs in Avin).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;timing&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;after&lt;/code&gt; and &lt;code&gt;Ticker&lt;/code&gt; are channels holding a clock, not a
timer&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/#timers-and-deadlines&quot;&gt;Threads&lt;/a&gt;). &lt;code&gt;after(d) -&amp;gt; Channel[Instant]&lt;/code&gt; and
&lt;code&gt;Ticker(period)&lt;/code&gt; with its channel &lt;code&gt;ticks&lt;/code&gt; give ordinary &lt;code&gt;Channel[Instant]&lt;/code&gt;s whose next value’s due
time is kept in the channel; the first receive, &lt;code&gt;tryReceive&lt;/code&gt; or select arm that looks once it is
due delivers it, a waiting receive waits on its condition until then at the most, and a select
parks until the soonest due time among its arms’ channels, then tries them again. The value is the
instant the time fell due (the wall clock, offset by the monotonic clock’s lateness), not when it
was received. Why: an &lt;code&gt;after&lt;/code&gt; nobody receives from, the common loser of a select, then leaves
nothing behind (no timer in the runtime’s heap, no thread, no registration) and is collected as
any object is, whatever its duration; a channel is what a select arm takes, so no new arm kind or
receive-only type is needed. Alternatives weighed: a thread per &lt;code&gt;after&lt;/code&gt; that sleeps and sends (lives
for the whole duration, ten thousand hour-long &lt;code&gt;after&lt;/code&gt;s holding ten thousand stacks); a runtime
timer that sends when it fires (needs the runtime to run Avin code from its timer thread, and a
timer to cancel by finalizer when the channel is dropped); a receive-only &lt;code&gt;Timer&lt;/code&gt; type (a second
kind of select arm for the same wait). &lt;code&gt;Channel&lt;/code&gt;‘s &lt;code&gt;wakeAt&lt;/code&gt;, &lt;code&gt;startClock&lt;/code&gt; and &lt;code&gt;stopClock&lt;/code&gt;, which
the select and the clocks call, are public as the select’s names are, each taking a type private to
&lt;code&gt;avin.threads&lt;/code&gt;, so no program can call them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;timing&lt;/code&gt;): &lt;strong&gt;Nothing sends to a channel &lt;code&gt;after&lt;/code&gt; or a &lt;code&gt;Ticker&lt;/code&gt; made.&lt;/strong&gt; A
&lt;code&gt;send&lt;/code&gt;, &lt;code&gt;trySend&lt;/code&gt;, timed send or select send arm on one traps; &lt;code&gt;close&lt;/code&gt; is allowed and ends it, no
value delivered after. Why: the channel is the clock’s; a value sent into it would take the tick’s
place or sit beside it, and Avin has no receive-only channel type to make the mistake a compile
error. Alternatives weighed: letting sends through (a receiver could not trust a value to be a
tick); a receive-only channel type (a language feature of its own, which a later decision could
still add, making this a compile error). Review with the user if a receive-only view of &lt;code&gt;Channel&lt;/code&gt;
is wanted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;timing&lt;/code&gt;): &lt;strong&gt;A ticker drops the ticks a slow receiver misses, and &lt;code&gt;stop&lt;/code&gt;
drops a waiting one.&lt;/strong&gt; The channel holds one tick; one falling due while it is held is dropped, and
the ticker moves on to its first period after now. The held tick is the oldest missed. &lt;code&gt;stop()&lt;/code&gt;
also drops a tick fallen due and not received, so none is received after it; a period of zero or
less traps; the first tick comes a period after the ticker is made; there is no &lt;code&gt;reset&lt;/code&gt;. Why: a
ticker paces work, and a backlog delivered at once to a receiver that fell behind is the opposite
of pacing; after &lt;code&gt;stop&lt;/code&gt;, a stale tick is a surprise. Alternatives weighed: an unbounded backlog;
the newest missed tick held rather than the oldest (needs a write into a value the receiver may be
taking); keeping the waiting tick after &lt;code&gt;stop&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;timing&lt;/code&gt;): &lt;strong&gt;Timed channel waits are &lt;code&gt;receive(timeout: Duration)&lt;/code&gt; and
&lt;code&gt;send(x, timeout: Duration)&lt;/code&gt;&lt;/strong&gt;, overloads beside the plain forms, as &lt;code&gt;Future.await(timeout)&lt;/code&gt; and
&lt;code&gt;Condition.waitFor(timeout)&lt;/code&gt; are. &lt;code&gt;receive(timeout)&lt;/code&gt; answers &lt;code&gt;Option[T]&lt;/code&gt;: &lt;code&gt;None&lt;/code&gt; for a time that ran
out and for a closed, drained channel alike (&lt;code&gt;isClosed()&lt;/code&gt; tells them apart); &lt;code&gt;send(x, timeout)&lt;/code&gt;
answers whether it sent, and traps on a closed channel as &lt;code&gt;send&lt;/code&gt; does. A timeout of zero or less is
&lt;code&gt;tryReceive&lt;/code&gt;/&lt;code&gt;trySend&lt;/code&gt;. Why: the shape of &lt;code&gt;Future.await(timeout)&lt;/code&gt;, and a loop over a channel’s values
ends the same way whichever ended it. Alternatives weighed: a three-way result (a value, closed,
timed out), heavier at every call for a distinction rarely needed; a &lt;code&gt;within:&lt;/code&gt; named argument (Avin
overloads by type already, and no other timed wait is named so); a millisecond &lt;code&gt;long&lt;/code&gt; overload (the
migration below goes the other way). &lt;strong&gt;Proposed migration, not made here&lt;/strong&gt;: the
millisecond overloads &lt;code&gt;Condition.waitFor(timeoutMillis: long)&lt;/code&gt; and &lt;code&gt;Future.await(timeoutMillis: long)&lt;/code&gt; duplicate their &lt;code&gt;Duration&lt;/code&gt; forms and could be retired in a release that breaks source, their
callers moved to &lt;code&gt;millis(n)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;timing&lt;/code&gt;): &lt;strong&gt;A scope with a time limit is &lt;code&gt;withTimeout(timeout, s -&amp;gt; …) -&amp;gt; Option[T]&lt;/code&gt;&lt;/strong&gt;, &lt;code&gt;None&lt;/code&gt; where the time ran out. The body runs with a new scope on a lightweight thread
of its own while the caller waits in a select with an &lt;code&gt;after&lt;/code&gt;; when the time runs out the body’s
thread is cancelled, which cancels its scope’s threads and all below them, and &lt;code&gt;withTimeout&lt;/code&gt; answers
once every one has ended. A result the body returned is kept, however close to the time; a timeout of
zero or less runs nothing and answers &lt;code&gt;None&lt;/code&gt;; nested timeouts end at the sooner time. Why: &lt;code&gt;Option&lt;/code&gt; is
what &lt;code&gt;Future.await(timeout)&lt;/code&gt; answers, and a timeout is not an error the body made; running the body
on a thread of its own is what lets it be stopped wherever it is, &lt;code&gt;main&lt;/code&gt; included, whose thread no
cancellation reaches, with no new runtime mechanism: a timeout is a scope’s cancellation. Its cost
is that the body is on another thread: &lt;code&gt;isMainThread()&lt;/code&gt; answers &lt;code&gt;false&lt;/code&gt; there, and a lock or a
condition’s mutex the caller holds is not the body’s. Alternatives weighed: &lt;code&gt;Result[T, TimedOut]&lt;/code&gt;
(a new error type for a case with nothing to say); &lt;code&gt;scope(timeout = d, …)&lt;/code&gt; (an overload of &lt;code&gt;scope&lt;/code&gt;
whose result type changes with an argument); a deadline at an &lt;code&gt;Instant&lt;/code&gt; (the wall clock moves, and a
monotonic instant type does not exist yet; one could be added as &lt;code&gt;withDeadline&lt;/code&gt;); cancelling the
calling thread itself from a timer and catching it at the timeout (a new runtime mechanism, an
un-cancellable &lt;code&gt;main&lt;/code&gt;, and a cancellation that must tell its own timeout from an outer cancel).
Review with the user: the body running on another thread is visible to code that asks which
thread it is on.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (built on branch &lt;code&gt;request-context&lt;/code&gt;): &lt;strong&gt;The request
context is ambient: it belongs to the running thread, not to an argument.&lt;/strong&gt; &lt;code&gt;Context.current()&lt;/code&gt;
reads it (&lt;code&gt;deadline&lt;/code&gt;, &lt;code&gt;remaining()&lt;/code&gt;, &lt;code&gt;value(key)&lt;/code&gt;); &lt;code&gt;withValue(key, v, body)&lt;/code&gt; and
&lt;code&gt;withDeadline(t, s -&amp;gt; …)&lt;/code&gt; / &lt;code&gt;withTimeout(d, s -&amp;gt; …)&lt;/code&gt; set it for a dynamic scope, and it is put back
as the scope ends. Why: the API server and the pg driver need a deadline and request values to reach
every call a request makes, and threading a parameter through every signature on the way (the
explicit-argument design) taxes every library in between that does not care, and is lost the first
time one forgets it; Avin already has a thread-shaped structure, the scope, that a cancellation
follows down, so the context follows the same tree. Alternatives weighed: an explicit &lt;code&gt;ctx&lt;/code&gt;
parameter (the tax above); a general thread-local facility (wider than needed, and a thread-local
does not say what a new thread takes, which is the whole question here). The context lives in one
slot of the thread’s runtime context, marked by every collection. Review with the user: ambient
state is invisible at the call site, which is its point and its cost.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (built on branch &lt;code&gt;request-context&lt;/code&gt;): &lt;strong&gt;What a new
thread takes follows what can cancel it.&lt;/strong&gt; A scope’s threads (&lt;code&gt;s.spawn&lt;/code&gt;, and a &lt;code&gt;withTimeout&lt;/code&gt; or
&lt;code&gt;withDeadline&lt;/code&gt; body) take the whole context, deadline and values, since a cancellation of their
scope reaches them. A plain &lt;code&gt;spawn&lt;/code&gt;, a future’s code (&lt;code&gt;Future(…)&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;onComplete&lt;/code&gt;,
&lt;code&gt;executor.future&lt;/code&gt;) and an executor’s task (&lt;code&gt;execute&lt;/code&gt;) take the values with no deadline: nothing
cancels them when it passes, so a deadline there would be a number nothing keeps; a future’s
callback takes the context of the code that attached it, not of the thread that completed the
future. An actor’s turn takes nothing, from the code that told it or from a worker: an actor
outlives any request, and its turns are not a scope’s threads, as for cancellation. A pool worker
runs between tasks with none. Alternatives weighed: everything takes everything (a deadline readable
where it is never enforced, &lt;code&gt;remaining()&lt;/code&gt; reading zero in a thread still running); nothing but a
scope’s threads takes anything (a request id lost at the first &lt;code&gt;Future&lt;/code&gt;); an actor’s turn taking the
teller’s values (a context then travels with a message, which no other message property does).
Review with the user: the actor rule means a request id does not cross a &lt;code&gt;tell&lt;/code&gt;, so tracing across
actors needs it in the message.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (built on branch &lt;code&gt;request-context&lt;/code&gt;): &lt;strong&gt;A deadline is
kept by cancellation, and its error is &lt;code&gt;withDeadline&lt;/code&gt;‘s.&lt;/strong&gt; &lt;code&gt;withDeadline(t, s -&amp;gt; …) -&amp;gt; Result[T, DeadlineExceeded]&lt;/code&gt; is &lt;code&gt;withTimeout&lt;/code&gt; with an instant: the body runs on a thread of its own
and is cancelled when the time comes, so every existing cancellation point observes it (a socket’s
accept, connect, read and write, a pool’s &lt;code&gt;use&lt;/code&gt; and &lt;code&gt;lease&lt;/code&gt;, a channel’s send and receive, &lt;code&gt;select&lt;/code&gt;,
&lt;code&gt;sleep&lt;/code&gt;, a future’s &lt;code&gt;await&lt;/code&gt;, a safepoint poll) and no blocking call gained a new error. Its error is
&lt;code&gt;DeadlineExceeded(deadline: Instant)&lt;/code&gt;, an &lt;code&gt;Error&lt;/code&gt; whose message is &lt;code&gt;deadline exceeded&lt;/code&gt;. A nested
deadline can tighten the context’s deadline and never loosen it: the context keeps the sooner one,
and an outer deadline cancels an inner later one with its body. The wall clock is read once, as the
scope opens; the deadline then runs on the monotonic clock, and &lt;code&gt;deadline&lt;/code&gt; reports the instant asked
for, &lt;code&gt;remaining()&lt;/code&gt; the monotonic time left, never below zero. Why: a deadline is a cancellation at a
time, and the cancellation machinery already reaches every wait, unwinds with deferred statements
run, and gives pooled resources back; &lt;code&gt;Result&lt;/code&gt; because request code returns &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;?&lt;/code&gt;s it
(&lt;code&gt;withTimeout&lt;/code&gt; keeps its &lt;code&gt;Option&lt;/code&gt;). Alternatives weighed: each blocking call checking the context and
answering an error (every wait’s signature and every caller change, and code that computes is never
stopped); cancelling the calling thread itself (rejected for &lt;code&gt;withTimeout&lt;/code&gt; above). Review with the
user: inside the body the deadline is never an error value, it is a stop; code that must tidy up
(pg sending a CancelRequest) does it in a &lt;code&gt;defer&lt;/code&gt;, whose waits are not cancellation points.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (built on branch &lt;code&gt;request-context&lt;/code&gt;): &lt;strong&gt;Keys are typed
and told apart by identity: &lt;code&gt;Key[T](name)&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;withValue[K: Sendable, T](key: Key[K], value: K, body: () -&amp;gt; T)&lt;/code&gt; takes only a value of the key’s type, and &lt;code&gt;value[T](key: Key[T]) -&amp;gt; Option[T]&lt;/code&gt;
answers that type; the value is held as an &lt;code&gt;Any&lt;/code&gt; and recovered by a type pattern inside the library,
which reification makes exact, so no lookup casts. Two keys of one name are two keys, so a module’s
values are reached by its own key alone. The value must be sendable, since the threads a scope starts
read it. Alternatives weighed: string keys (a lookup that must name its type and can be wrong);
keys compared by name (two modules’ &lt;code&gt;&amp;quot;id&amp;quot;&lt;/code&gt; would collide).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types, inference without bounds, hole variance and hole bounds&lt;/strong&gt; (build plan step
2, branch &lt;code&gt;hkt-2&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;an unbounded constructor parameter is inferred from the type an argument or the
expected type gives &lt;code&gt;F[X]&lt;/code&gt;, named bare&lt;/strong&gt;: a data type, class or trait with exactly as many type
parameters as &lt;code&gt;F&lt;/code&gt; has holes, a subclass by its own name (&lt;code&gt;Crate[A]&lt;/code&gt; passed as &lt;code&gt;F[A]&lt;/code&gt; is &lt;code&gt;Crate&lt;/code&gt;,
not its superclass), or another constructor parameter in scope applied to as many arguments.
Once &lt;code&gt;F&lt;/code&gt; is known, the rest of the argument is held to the type it makes with that type’s own
variance, so a covariant argument still widens (&lt;code&gt;both(Some(dog), Some(cat))&lt;/code&gt; for
&lt;code&gt;both[F[_], A](x: F[A], y: F[A])&lt;/code&gt; takes &lt;code&gt;A&lt;/code&gt; as &lt;code&gt;Animal&lt;/code&gt;, since &lt;code&gt;Option&lt;/code&gt; is covariant). A type
of more parameters, of fewer, a type whose parameter takes a constructor, or one that is no
data type, class or trait decides nothing and is reported as “cannot infer &lt;code&gt;F&lt;/code&gt; from &lt;code&gt;T&lt;/code&gt;: …;
write it, as in &lt;code&gt;f[…](arguments)&lt;/code&gt;“, the example leaving open the arguments that match the
application’s own known ones (&lt;code&gt;Either[string, _]&lt;/code&gt; for an &lt;code&gt;F[int]&lt;/code&gt; given an
&lt;code&gt;Either[string, int]&lt;/code&gt;), else the first ones. Why: the spec’s rule (“a type of more is an error
asking for &lt;code&gt;F&lt;/code&gt; to be written”); the example is the likeliest constructor meant. Alternatives:
always leaving the first arguments open in the example (wrong for &lt;code&gt;Either[string, int]&lt;/code&gt;);
holding the arguments invariantly once &lt;code&gt;F&lt;/code&gt; is decided (refuses calls every instance accepts).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a function’s or method’s type arguments taken as a value (&lt;code&gt;k.pick[Dog]&lt;/code&gt;) are held
to their bounds, as at a call&lt;/strong&gt; (a fix found in step 2: a method value checked no bound at all,
so a bounded method could be instantiated at a type its bound refuses, a constructor at a hole
it may not fill among them).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types, constructor traits and their impls&lt;/strong&gt; (build plan step 3, branch &lt;code&gt;hkt-3&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;hkt-3&lt;/code&gt;): &lt;strong&gt;a constructor trait’s default
bodies are compiled once per implementing constructor&lt;/strong&gt;: each instance of a constructor trait’s
method takes the constructor after its type arguments, and &lt;code&gt;Self&lt;/code&gt; stands for it there (the
static members &lt;code&gt;Self.pure&lt;/code&gt; and &lt;code&gt;F.pure&lt;/code&gt; come with step 5, the entry above). Why: a body shared by
every conforming type sees &lt;code&gt;Self&lt;/code&gt; as an object, but a &lt;code&gt;Self[B]&lt;/code&gt; may be an option or another value
laid out as no object is, and a shared &lt;code&gt;mapTwice&lt;/code&gt; built that way crashed at run time.
Alternatives: refusing default bodies in constructor traits (needlessly narrow, and &lt;code&gt;Monad&lt;/code&gt;‘s
&lt;code&gt;map&lt;/code&gt; and &lt;code&gt;map2&lt;/code&gt; come from them).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the methods that meet a constructor trait’s are the type’s own: those its
declaration and its impls declare, never a superclass’s.&lt;/strong&gt; Why: the spec’s rule names “the
type’s own methods”, and a superclass’s method answers the superclass’s type, the reason a
subclass inherits no conformance. Alternatives: also meeting with inherited methods whose
results happen to fit (a &lt;code&gt;foldLeft&lt;/code&gt; would; a &lt;code&gt;map&lt;/code&gt; never does). Review with the user if a class
hierarchy wants an inherited &lt;code&gt;foldLeft&lt;/code&gt; to meet &lt;code&gt;Foldable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;two overloads that both meet one trait method are an error at the impl&lt;/strong&gt;, naming
the method. Why: a call through the bound would have two methods to call, and choosing the
more specific is a second overload resolution no call site shows. Alternatives: the more
specific overload, as a written call would pick (more code, and a choice the reader cannot
see); the first declared (arbitrary).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the meeting decides a method’s own type parameters from where they first appear in
its parameter types, against the trait’s, then in its result; one still undecided takes its
lower bound, and one with none is an error naming it.&lt;/strong&gt; Every parameter and the result are then
checked with what was decided, each seen as the other’s with no conversion (a reference seen as
a supertype, as a covariant part is; never a box). Why: the spec’s “whose own type parameters
that call decides (a lower bound by its bound)”; the order makes &lt;code&gt;List&lt;/code&gt;‘s &lt;code&gt;flatMap(f: (T) -&amp;gt; Iterable[U])&lt;/code&gt; take &lt;code&gt;U&lt;/code&gt; from the trait’s &lt;code&gt;List[B]&lt;/code&gt; seen as an &lt;code&gt;Iterable&lt;/code&gt;. Alternatives: full
inference by the call checker (heavier, and its tiers of defaults would decide what the trait’s
call does not).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor trait requires only constructor traits&lt;/strong&gt;, each at its own parameters
in order; &lt;code&gt;trait Shown[A]: Functor[A], Display&lt;/code&gt; is an error. (Widened by the settled entry of
2026-11-14, branch &lt;code&gt;hkt-7&lt;/code&gt;: it may also require a trait for types that bounds constructors.) Why: a trait for types bounds what
a value is, and the constructor trait’s &lt;code&gt;Self&lt;/code&gt; is no value’s type, so what the requirement would
promise is unclear. Alternatives: reading it as a bound on every application &lt;code&gt;Self[A]&lt;/code&gt; (a
constraint on applications, which impls over constructor parameters, step 6, are the place for).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor trait’s arguments are no position of a variance&lt;/strong&gt; for the conforming
type: &lt;code&gt;List[+T]&lt;/code&gt; and &lt;code&gt;Result[+T, +E]&lt;/code&gt; conform to &lt;code&gt;Monad[T]&lt;/code&gt;, an invariant parameter. Why: no
value has the trait as its type, so &lt;code&gt;Monad[Dog]&lt;/code&gt; and &lt;code&gt;Monad[Animal]&lt;/code&gt; are never compared; the
subtyping of &lt;code&gt;F[Dog]&lt;/code&gt; is the hole’s (&lt;code&gt;F[+_]&lt;/code&gt;). Alternatives: none that let a covariant type
conform.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a class may state a conformance to a constructor trait in its header&lt;/strong&gt;, &lt;code&gt;class Crate[A]: Functor[A]&lt;/code&gt;, held as an impl’s is; the form leaving the trait’s arguments off is an
impl’s only. A class’s methods meeting the trait’s need no &lt;code&gt;override&lt;/code&gt;, and may write it. Why:
a header conformance is one an impl could state, and the meeting methods are the class’s own,
which override nothing. Alternatives: requiring an impl for constructor traits (no reason a
header could not say the same).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the conformance’s errors are reported at the impl, a meeting’s at the method where
the impl declares it and at the impl otherwise&lt;/strong&gt;: a library type’s method that does not meet is
reported where the program’s impl names the trait. Why: the impl is what the program wrote; the
library’s method is not the mistake.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types, inferring a constructor through its bound&lt;/strong&gt; (build plan step 4, branch
&lt;code&gt;hkt-4&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the spec’s third place to look, “the one trait among those it conforms to that has
one”, is left out, since no type can reach it.&lt;/strong&gt; An impl is never for a trait, and a trait that
requires a constructor trait is itself one, so a type conforming to it conforms to what it
requires at the same holes, as its own; a type conforming to it at fixed arguments
(&lt;code&gt;class Digits: Bag[int]&lt;/code&gt;) is refused at the declaration. A type is therefore matched as itself,
then as its superclasses nearest first, and a type with no conformance there is an error naming
the bound and the type. Why: code for a case no program can write would be untested. Review
with the user: it returns, with its “several such traits” error, if traits come to implement
constructor traits by impls (&lt;code&gt;impl Monad for Seq&lt;/code&gt;), which the spec’s &lt;code&gt;pairUp[Seq, …]&lt;/code&gt; example
presumes and the library step will want.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;with several constructor-trait bounds, each conformance the type (or the superclass
matched) has decides; two that leave different arguments open are an error naming both&lt;/strong&gt;
(&lt;code&gt;Pair&lt;/code&gt; implements &lt;code&gt;Mappable&lt;/code&gt; as &lt;code&gt;Pair[int, _]&lt;/code&gt; and &lt;code&gt;Lefty&lt;/code&gt; as &lt;code&gt;Pair[_, int]&lt;/code&gt;), and a bound the
type lacks is reported as for a written constructor. Why: the bounds are one demand on one
constructor, so the nearest type with any of them is the answer the others are checked against.
Alternatives: the first bound written decides (order-dependent); the nearest type with all of
them (skips a subclass’s own conformance for a superclass’s, which the spec’s no-inheritance rule
forbids).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;an argument written out of a constructor joins only where the type’s parameter is
covariant and the argument a reference type known at that argument; the expected type, checked
first, fixes it.&lt;/strong&gt; &lt;code&gt;second(dogs, cats)&lt;/code&gt; makes &lt;code&gt;F&lt;/code&gt; &lt;code&gt;Result[_, Animal]&lt;/code&gt;; with
&lt;code&gt;val r: Result[int, Dog] = second(dogs, cats)&lt;/code&gt; the expected type has made &lt;code&gt;F&lt;/code&gt; &lt;code&gt;Result[_, Dog]&lt;/code&gt; and
the cats are refused. Why: the expected type decides type arguments before the arguments do for
every generic call. An argument the first argument leaves unknown (&lt;code&gt;Ok(1)&lt;/code&gt;‘s error type) is
decided by the next, as an invariant one is.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;inference sees a subclass as its superclass, or a type as a trait, only where a value
is read out&lt;/strong&gt; (a fix found in step 4, which matching through a superclass’s conformance meets):
at an invariant argument or a function’s parameter, inference held a &lt;code&gt;Box[TallShelf[int]]&lt;/code&gt; to be
a &lt;code&gt;Box[Shelf[A]]&lt;/code&gt;, and a &lt;code&gt;(Dog) -&amp;gt; int&lt;/code&gt; an &lt;code&gt;(Animal) -&amp;gt; B&lt;/code&gt;, so generic code could store a &lt;code&gt;Shelf&lt;/code&gt;
in the box or pass a cat to the function, reading memory that was never a &lt;code&gt;TallShelf&lt;/code&gt;‘s or a
&lt;code&gt;Dog&lt;/code&gt;‘s. Both are now refused; a type that is the class itself is still taken there.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types, static members on constructors&lt;/strong&gt; (build plan step 5, branch &lt;code&gt;hkt-5&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor named bare, or with &lt;code&gt;_&lt;/code&gt; for the arguments it leaves open, has as its
static members those of the constructor traits it implements at exactly those holes&lt;/strong&gt;, each
conformance held as a constructor argument’s is (the holes the impl leaves open, the arguments
written out meeting the impl’s bounds): &lt;code&gt;Option.pure&lt;/code&gt;, &lt;code&gt;Result[_, E].pure&lt;/code&gt;, &lt;code&gt;Parsed.pure&lt;/code&gt; for an
alias that is a constructor, and &lt;code&gt;Box[_].pure&lt;/code&gt;, the same as &lt;code&gt;Box&lt;/code&gt;. &lt;code&gt;Result[int, _].pure&lt;/code&gt; is an
error saying &lt;code&gt;Result&lt;/code&gt; implements the trait as &lt;code&gt;Result[_, E]&lt;/code&gt;. Why: a static member of a
constructor trait names no parameter of the trait, so the constructor is all a call needs, and
the conformance says which constructor it is. Alternatives: look the member up on the type at
any arguments (would let &lt;code&gt;Result[int, _]&lt;/code&gt; reach a member of the conformance at the other hole).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a static member of a type’s own conformance to an ordinary trait is not reached on
the type named bare&lt;/strong&gt;: &lt;code&gt;Box.make()&lt;/code&gt; for &lt;code&gt;impl[T] Make for Box[T]&lt;/code&gt; is an error asking for the type
arguments (&lt;code&gt;Box[A].make(…)&lt;/code&gt;), as before. Why: that member’s types name the type’s parameters,
which a bare name leaves unknown. Alternative weighed: inferring them from the call as a generic
function’s are (a separate feature, not part of constructors).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a constructor trait’s static member still takes no default body&lt;/strong&gt;, as every trait’s
static member does: defaults that call &lt;code&gt;Self.pure&lt;/code&gt; are its methods’. Why: the rule for static
members is one rule for every trait; the per-constructor compilation would allow it, so it can be
added later without changing anything written now. Review with the user if the library wants a
derived static member (a &lt;code&gt;Monad.unit&lt;/code&gt; from &lt;code&gt;pure&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;two bounds that each declare a static member of one name and parameter types make a
call of it on the parameter ambiguous&lt;/strong&gt;, by the ordinary overloading rule, rather than one bound
being preferred. Why: nothing says which constructor’s member is meant beyond the bounds.&lt;/li&gt;
&lt;li&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a static member called on a value of &lt;code&gt;F[X]&lt;/code&gt; is an error pointing at &lt;code&gt;F.pure(…)&lt;/code&gt;&lt;/strong&gt;;
on a value of a known type, &lt;code&gt;Some(1).pure(2)&lt;/code&gt;, the existing message names the type. Why: the
member is the constructor’s, and the constructor is what the call writes.&lt;/li&gt;
&lt;li&gt;In each instance a static member called on a constructor is compiled once per constructor: the
type’s own member at &lt;code&gt;Nothing&lt;/code&gt; for the holes, which it never names, so &lt;code&gt;Option.pure&lt;/code&gt; and
&lt;code&gt;F.pure&lt;/code&gt; at &lt;code&gt;Option&lt;/code&gt; are one instance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Higher-kinded types, impls over constructor parameters&lt;/strong&gt; (build plan step 6, branch &lt;code&gt;hkt-6&lt;/code&gt;)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;an impl adding to &lt;code&gt;F[A]&lt;/code&gt; belongs to the trait bounding &lt;code&gt;F&lt;/code&gt;&lt;/strong&gt;: written in the module
of one of &lt;code&gt;F&lt;/code&gt;‘s bounds (or in the core library) it is that trait’s own and seen everywhere, and
written anywhere else it is an extension. With &lt;code&gt;F[G[A]]&lt;/code&gt; it is &lt;code&gt;F&lt;/code&gt;‘s bounds, the head’s, that
count. Why: such an impl adds to every type the bound’s conformance reaches, as &lt;code&gt;impl[T] Seq[T]&lt;/code&gt;
adds to every sequence, and that impl’s home is the trait’s module. Alternatives: always an
extension (would make the library’s own &lt;code&gt;impl[F[_]: Monad, A] F[A]&lt;/code&gt; need an import of its own
module); any module of any bound named in the impl (blurs which module owns it).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;such methods are found after the type’s own, wherever the impl is written&lt;/strong&gt;: a
type’s own method, or the bound’s, of the name and parameter types is called, and a call that
sees only the bound, in generic code, calls the added one. Why: the impl adds to a family of
types as an impl adding to a trait does, and that is the trait rule; the rule for impls adding to
one type built from parameters, which makes a clash with the type’s own method ambiguous, would
make every type that has, say, its own &lt;code&gt;twice&lt;/code&gt; unusable once the library adds one. An extension
adding a method the bound already declares is an error where it is declared (&lt;code&gt;map&lt;/code&gt; on
&lt;code&gt;Mappable&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;the constructor parameter need not be bounded&lt;/strong&gt;: unbounded, &lt;code&gt;F&lt;/code&gt; is matched as
inference matches it without a bound, a type of exactly as many arguments as &lt;code&gt;F&lt;/code&gt; has holes,
named bare. Why: it is the inference rule, unchanged, and refusing it would add a rule; such an
impl’s methods reach nothing of &lt;code&gt;F[A]&lt;/code&gt; but can pass it on. Alternative: require a constructor
trait bound (an error naming the bound to add). Review with the user if the unbounded form should
rather be an error.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a receiver whose type no such impl matches is told why&lt;/strong&gt;: &lt;code&gt;twice&lt;/code&gt; on a
&lt;code&gt;Plain[int]&lt;/code&gt; says the method is for &lt;code&gt;F[A]&lt;/code&gt; where &lt;code&gt;F&lt;/code&gt; implements &lt;code&gt;Mappable&lt;/code&gt; and that &lt;code&gt;Plain&lt;/code&gt; does
not implement it, the reason inference gives; an &lt;code&gt;F[int]&lt;/code&gt; whose &lt;code&gt;F&lt;/code&gt; lacks the bound says its
constructor is bounded by no &lt;code&gt;Pointed&lt;/code&gt;. Of several such impls adding the name, only one is named,
since every generic type is an instance of each; an impl adding to a type the receiver is an
instance of, &lt;code&gt;Option[Option[T]]&lt;/code&gt;, is named first.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15: &lt;strong&gt;a function value of an extension method the file does not see, or of a private
added method, is reported as a call of it is&lt;/strong&gt; (“&lt;code&gt;shout&lt;/code&gt; is added to &lt;code&gt;string&lt;/code&gt; by module
&lt;code&gt;extras&lt;/code&gt;, which this file does not import”), where it said only that the type has no member. This
holds for every extension, not only those over constructor parameters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;No impl of a trait is for &lt;code&gt;F[A]&lt;/code&gt;: a conformance is a type’s, stated once for it, and an
application of a constructor parameter is no type of its own. The impl declares no static member,
as no impl adding to a type built from parameters does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;rendezvous&lt;/code&gt;): &lt;strong&gt;a &lt;a href=&quot;/spec/threads/#rendezvous&quot;&gt;rendezvous&lt;/a&gt; is
&lt;code&gt;Channel[T](0)&lt;/code&gt;, and a channel with no capacity stays unbounded through a default of &lt;code&gt;unbounded&lt;/code&gt;,
a public &lt;code&gt;val&lt;/code&gt; in &lt;code&gt;avin.threads&lt;/code&gt; holding the largest &lt;code&gt;int&lt;/code&gt;.&lt;/strong&gt; This replaces the settled “unbounded
at zero”. Why: zero is the capacity that holds nothing, so reading it as a hand-off says what it
is; &lt;code&gt;Channel[T]()&lt;/code&gt; keeps its meaning, so no program changes (none in the tree passed &lt;code&gt;0&lt;/code&gt;); and an
unbounded channel is the bounded one at a bound it can never reach, so it needs no case of its
own. Alternatives weighed: keeping zero unbounded and adding &lt;code&gt;Channel.rendezvous[T]()&lt;/code&gt; or a
&lt;code&gt;rendezvous&lt;/code&gt; flag (a second spelling of capacity, and zero would still read wrongly);
&lt;code&gt;capacity: Option[int] = None&lt;/code&gt; (every bounded channel would write &lt;code&gt;Some(n)&lt;/code&gt;); a negative sentinel
such as &lt;code&gt;-1&lt;/code&gt; for unbounded (a capacity that is not one, and a negative one traps). Review with the
user: it changes what an explicit &lt;code&gt;Channel[T](0)&lt;/code&gt; means, from unbounded to a rendezvous.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;rendezvous&lt;/code&gt;): &lt;strong&gt;a rendezvous hands values to waiting parties directly,
and a select’s arm is a party that a partner claims.&lt;/strong&gt; A plain sender or receiver waits on a
condition of its own until a partner completes it; a select’s arm on a rendezvous stands on the
channel while it waits, and a partner completes the arm only by first ending the select’s wait
through that arm (&lt;code&gt;select_claim&lt;/code&gt; in &lt;code&gt;runtime/avin/rt/select.sysl&lt;/code&gt;), so no select runs two arms.
A select can be claimed only once every arm of its round is tried and enlisted; a partner that
meets one still trying its arms wakes it (a poke), and the select, trying that arm again, waits
out a partner select still mid-round rather than missing it. Why: it keeps the one-lock-at-a-time
select of buffered channels, and the claim is the one atomic step that decides an arm. The
receiver “has the value” once a sender completes it, so a receiver cancelled after that stops with
the value. Alternatives weighed: a sender depositing its value and waiting for it to be taken (a
select’s send arm cannot deposit without committing to it); locking every channel of a select at
once (a lock order across channels, and a different design for every select). The sender’s wait
is its own kind in the thread dump and deadlock report, “waiting to hand a value to a receiver”.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;hkt-9&lt;/code&gt;): &lt;strong&gt;a diagnostic’s article follows how a type’s name is read.&lt;/strong&gt;
A capital letter standing alone at the start of a name (&lt;code&gt;F[int]&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt;, &lt;code&gt;X2&lt;/code&gt;) is read as the letter,
so it takes &lt;code&gt;an&lt;/code&gt; before A, E, F, H, I, L, M, N, O, R, S and X and &lt;code&gt;a&lt;/code&gt; otherwise (&lt;code&gt;an F[int]&lt;/code&gt;,
&lt;code&gt;a T&lt;/code&gt;, &lt;code&gt;a U&lt;/code&gt;); any other name takes &lt;code&gt;an&lt;/code&gt; before a, e, i, o in either case and &lt;code&gt;a&lt;/code&gt; before &lt;code&gt;u&lt;/code&gt;
(&lt;code&gt;a unit&lt;/code&gt;, &lt;code&gt;a usize&lt;/code&gt;, &lt;code&gt;a Unicorn&lt;/code&gt;), one helper (&lt;code&gt;article&lt;/code&gt; in &lt;code&gt;check.sysl&lt;/code&gt;) for every message. Why:
constructor and type parameters are single letters, and “a &lt;code&gt;F[int]&lt;/code&gt;“ read wrongly; the type names
that begin with &lt;code&gt;u&lt;/code&gt; mostly sound a consonant. Alternatives weighed: treating &lt;code&gt;u&lt;/code&gt; as a vowel, as
three of the four old helpers did (“an &lt;code&gt;unit&lt;/code&gt;“); reading every all-capital name as letters
(&lt;code&gt;an HTTP&lt;/code&gt;, but &lt;code&gt;a NASA&lt;/code&gt; reads as a word, and no type name in the library is one).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;c-void-ptr&lt;/code&gt;): &lt;strong&gt;a C binding’s
&lt;a href=&quot;/spec/c-bindings/#memory-of-no-type&quot;&gt;&lt;code&gt;void *&lt;/code&gt; or &lt;code&gt;const void *&lt;/code&gt; parameter&lt;/a&gt; takes an array of any
element type an array crosses as, or a &lt;code&gt;ByteBlock&lt;/code&gt;, and its length counts bytes.&lt;/strong&gt; The array’s
elements go to C where they are, as for a typed pointer, with no element type checked against the
header (there is none to check); the parameter marked &lt;code&gt;length(p)&lt;/code&gt; is told the array’s length times
its element size, a &lt;code&gt;long&lt;/code&gt;, and an &lt;code&gt;inout&lt;/code&gt; length C writes back is bytes too, bounded by the
array’s bytes. &lt;code&gt;None&lt;/code&gt;, or the word &lt;code&gt;null&lt;/code&gt;, passes null. C writes through &lt;code&gt;void *&lt;/code&gt; and only reads
through &lt;code&gt;const void *&lt;/code&gt;. Still refused: &lt;code&gt;out&lt;/code&gt; or &lt;code&gt;inout&lt;/code&gt; on a &lt;code&gt;void *&lt;/code&gt; (C writes no value of a type
through one), a &lt;code&gt;void *&lt;/code&gt; result other than one discarded by a &lt;code&gt;unit&lt;/code&gt; binding, and an array whose
length no parameter carries, so &lt;code&gt;memcmp&lt;/code&gt;‘s second pointer is refused. Why: the gap was met by
marshal’s &lt;code&gt;sysctlbyname&lt;/code&gt;, the shape of the C library’s every untyped buffer (&lt;code&gt;read&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;,
&lt;code&gt;getentropy&lt;/code&gt;, &lt;code&gt;sysctl&lt;/code&gt;); an array and a block are already the binding layer’s memory, so this adds
no new kind of value, only drops the element check, and counting bytes is what every such C
function means by its length. Alternatives weighed: an &lt;code&gt;Array[byte]&lt;/code&gt; only, decoded in Avin (sound,
but reading an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt; would need a byte decoder in every program, and no such helper
exists); &lt;code&gt;out int *p&lt;/code&gt; written in the prototype where the header says &lt;code&gt;void *&lt;/code&gt; (breaks the rule
that a prototype is the header’s, and needs a size for the length); a length in elements (wrong
for every &lt;code&gt;void *&lt;/code&gt; function, which counts bytes); a shared &lt;code&gt;length(a, b)&lt;/code&gt; for &lt;code&gt;memcmp&lt;/code&gt;-shaped
functions (useful, but a separate feature). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether a shared length is
wanted, and whether a callback’s &lt;code&gt;const void *&lt;/code&gt; should lend a &lt;code&gt;ByteView&lt;/code&gt;, which is still refused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;c-opaque-errno&lt;/code&gt;): &lt;strong&gt;a pointer to an
opaque pointer is &lt;a href=&quot;/spec/c-bindings/#memory-of-no-type&quot;&gt;memory of no type&lt;/a&gt;&lt;/strong&gt;: &lt;code&gt;void **&lt;/code&gt;, and a pointer
to a typedef the headers make &lt;code&gt;void *&lt;/code&gt; or &lt;code&gt;const void *&lt;/code&gt; (&lt;code&gt;rusage_info_t *&lt;/code&gt;), take what &lt;code&gt;void *&lt;/code&gt;
takes, their length in bytes; C fills an array through &lt;code&gt;out void *&lt;/code&gt; or &lt;code&gt;out T *&lt;/code&gt; with &lt;code&gt;T&lt;/code&gt; such a
typedef, its &lt;code&gt;length:&lt;/code&gt; counting bytes, rounded up to whole elements, the rest zero; and C fills a
struct mirror through &lt;code&gt;out void *&lt;/code&gt;, &lt;code&gt;out void **&lt;/code&gt; or a pointer to a typedef. The prototype is still
the header’s: &lt;code&gt;rusage_info_t *&lt;/code&gt;, held to the header exactly. Only the headers say what a typedef
is, so the C unit checks an array’s elements through a pointer to a typedef as the typedef’s
elements &lt;em&gt;or&lt;/em&gt; the typedef being &lt;code&gt;void *&lt;/code&gt;, and measures which, beside the integer measurements, for
lowering to count the length in bytes or in elements; a mirror’s typedef is checked to be its
struct or &lt;code&gt;void *&lt;/code&gt;. Memory of no type C &lt;em&gt;allocates&lt;/em&gt; (&lt;code&gt;out void **&lt;/code&gt; with &lt;code&gt;array:&lt;/code&gt; or &lt;code&gt;bytes:&lt;/code&gt;) is an
&lt;code&gt;Array[byte]&lt;/code&gt;, since its length in bytes need not be a whole number of wider elements, and copying
a rounded-up count would read past C’s allocation. Why: marshal’s &lt;code&gt;proc_pid_rusage&lt;/code&gt; needed a
process’s physical footprint, and every form it tried was refused; the typedef’s kind is decided
where the spec decides every typedef’s, by the Avin type and the C unit’s check. &lt;code&gt;length:&lt;/code&gt; counts
bytes for memory of no type as &lt;code&gt;length(p)&lt;/code&gt; does, so &lt;code&gt;sizeof(struct rusage_info_v2)&lt;/code&gt; is written as
the header says it. Alternatives weighed: a word in the prototype marking the pointer untyped, or a
cast (&lt;code&gt;(void *) rusage_info_t *buffer&lt;/code&gt;), which the C unit’s measurement makes unnecessary; a
&lt;code&gt;length:&lt;/code&gt; in elements for memory C fills (consistent with typed arrays, but the binding would divide
the struct’s size itself); a mirror field for a fixed array (&lt;code&gt;uint8_t ri_uuid[16]&lt;/code&gt;), which would make
the struct mirrorable, left for when a program needs a field after one rather than the array form.
&lt;strong&gt;Review with the user&lt;/strong&gt;: fixed-array fields in struct mirrors.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;c-opaque-errno&lt;/code&gt;): &lt;strong&gt;a binding marked
&lt;a href=&quot;/spec/c-bindings/#errno&quot;&gt;&lt;code&gt;errno&lt;/code&gt;&lt;/a&gt; answers &lt;code&gt;Err&lt;/code&gt; of &lt;code&gt;errno&lt;/code&gt; where C answers -1&lt;/strong&gt;, &lt;code&gt;Result[T, Errno]&lt;/code&gt;
or &lt;code&gt;Result[T, &amp;lt;integer&amp;gt;]&lt;/code&gt;, its &lt;code&gt;Ok&lt;/code&gt; split as a result that is not a status is (the C result kept
as an integer or left out, then the out values). The bare word follows &lt;code&gt;blocking&lt;/code&gt;‘s form. &lt;code&gt;errno&lt;/code&gt;
is read by the C unit’s glue straight after the call, written through a pointer the binding passes
after the arrays’ lengths, so nothing — a &lt;code&gt;length:&lt;/code&gt; expression, a &lt;code&gt;blocking&lt;/code&gt; call’s return to the
scheduler, a collection — runs between the call and the read; the binding is always called through
glue. The failure is the -1, not &lt;code&gt;errno&lt;/code&gt; (a function may set &lt;code&gt;errno&lt;/code&gt; and succeed); a C result of an
unsigned type fails at all ones. &lt;code&gt;avin.c.Errno&lt;/code&gt; is a data type of the standard library with a case
per POSIX error number both macOS and Linux define, named as C names them (&lt;code&gt;ESRCH&lt;/code&gt;, &lt;code&gt;ENOENT&lt;/code&gt;), and
&lt;code&gt;Other(code)&lt;/code&gt;; its &lt;code&gt;message&lt;/code&gt; is the number’s sentence, the same on every platform. The C unit
measures each case’s value by its macro (&lt;code&gt;&amp;lt;errno.h&amp;gt;&lt;/code&gt; is included for a program with an &lt;code&gt;errno&lt;/code&gt;
binding), and lowering compares the number against them. Why: the C bindings’ first decisions named
an &lt;code&gt;errno&lt;/code&gt; flag answering &lt;code&gt;Result[T, int]&lt;/code&gt; from a &lt;code&gt;-1&lt;/code&gt; result as the likely form;
named cases let a program match &lt;code&gt;Err(ESRCH)&lt;/code&gt; without knowing a platform’s numbers, and C’s own
names are what a reader of a man page looks for. Alternatives weighed: mapping to &lt;code&gt;io.IoError&lt;/code&gt;
(loses &lt;code&gt;ESRCH&lt;/code&gt; and &lt;code&gt;EPERM&lt;/code&gt;, which it has no kinds for); an enum mirror in the library (needs a C
unit for every program and traps on a number no variant holds); PascalCase descriptive names
(&lt;code&gt;NoSuchProcess&lt;/code&gt;), which a man page does not use; a null pointer result as the failure too (not
built: a handle or string answered with &lt;code&gt;errno&lt;/code&gt; is still refused, the C result being an integer).
&lt;strong&gt;Review with the user&lt;/strong&gt;: the C names as variant names, and &lt;code&gt;errno&lt;/code&gt; on pointer results.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;c-opaque-errno&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin check&lt;/code&gt;
builds the C unit&lt;/strong&gt;, revising &lt;code&gt;check-stops-early&lt;/code&gt; (2026-11-06) for C: a binding the headers refuse
(a prototype the header contradicts, an array’s elements, a typedef’s kind, a constant) is refused
by &lt;code&gt;check&lt;/code&gt; as by &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt;. Why: marshal met a binding &lt;code&gt;check&lt;/code&gt; passed and &lt;code&gt;test&lt;/code&gt;
refused; the C unit is one clang compile, cached by its source’s hash, far cheaper than the shims
and the lowering &lt;code&gt;check&lt;/code&gt; gave up, and only C bindings make one. The Sysl shims stay behind
&lt;code&gt;--bindings&lt;/code&gt;. Alternatives weighed: keeping &lt;code&gt;check&lt;/code&gt; silent and documenting it (the disagreement
marshal met); moving the checks into the checker (impossible: only the headers know a typedef).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;test-orphans&lt;/code&gt;): &lt;strong&gt;a program &lt;code&gt;avin run&lt;/code&gt; or &lt;code&gt;avin test&lt;/code&gt; starts watches its runner and ends when the runner does, even one killed
with &lt;code&gt;SIGKILL&lt;/code&gt;; and &lt;code&gt;avin run&lt;/code&gt; contains its program too&lt;/strong&gt;, closing the known limit of
&lt;code&gt;runner-orphans&lt;/code&gt; (2026-11-12). The runner names itself in &lt;code&gt;AVIN_RUNNER_PID&lt;/code&gt;; the runtime, as a
program starts, takes the variable out of its environment and, only when the process it names is
the program’s parent, starts a thread that waits for that process to exit (a kqueue
&lt;code&gt;EVFILT_PROC&lt;/code&gt;/&lt;code&gt;NOTE_EXIT&lt;/code&gt; on macOS; elsewhere a check of the parent every 100 ms). When the runner
is gone the program sets its own &lt;code&gt;SIGTERM&lt;/code&gt; aside, sends &lt;code&gt;SIGTERM&lt;/code&gt; to the group it leads (or to
itself when it leads none), waits 200 ms, and sends &lt;code&gt;SIGKILL&lt;/code&gt;. A program started any other way, or
with the variable naming a process that is not its parent, watches nothing. &lt;code&gt;avin run&lt;/code&gt; started
away from a terminal now starts its program as the leader of a group of its own, passes &lt;code&gt;SIGTERM&lt;/code&gt;,
&lt;code&gt;SIGINT&lt;/code&gt; and &lt;code&gt;SIGHUP&lt;/code&gt; on to the group, kills it 2 s after the first if it is still running, exits
with the program’s status, and stops whatever is left of the group once the program has ended.
Started at a terminal as its foreground job, &lt;code&gt;avin run&lt;/code&gt; keeps the program in that job, so the
terminal’s Ctrl-C and Ctrl-Z and the shell’s job control reach both as before; it passes on
&lt;code&gt;SIGTERM&lt;/code&gt; and &lt;code&gt;SIGHUP&lt;/code&gt; to the program alone and lets the program decide what Ctrl-C means. Why: four
test programs of 0.0.21 runs were found alive after 37 h at PPID 1, one still holding a port
another project’s tests then collided with: runners killed outright (a deadline, a stopped
agent) cannot act, and &lt;code&gt;avin run&lt;/code&gt; did not contain its program at all. Alternatives weighed: a
thread in every program that polls its parent (a cost for programs nobody runs under a runner,
and on macOS a kqueue waits for free); Linux’s &lt;code&gt;PR_SET_PDEATHSIG&lt;/code&gt; (fires when the parent
&lt;em&gt;thread&lt;/em&gt; that started the child ends, and runners start programs from worker threads; macOS has
none); keeping the terminal case in a group of its own given the terminal (&lt;code&gt;foreground&lt;/code&gt;), which
would leave a Ctrl-Z stopping the program alone while &lt;code&gt;avin run&lt;/code&gt; waits for it, wedging the shell;
a longer grace for the watch (the runner that would have waited is gone). Known limits: at a
terminal, a program’s own children are not reached when &lt;code&gt;avin run&lt;/code&gt; is killed outright, only the
program; a program that ignores the runner’s death by leaving its group or session is beyond
reach. &lt;strong&gt;Review with the user&lt;/strong&gt;: the terminal case keeping the program in the shell’s job.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-observe&lt;/code&gt;): &lt;strong&gt;a request knows its
client’s address and its route&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#http-server&quot;&gt;system library&lt;/a&gt;).
&lt;code&gt;ServerRequest&lt;/code&gt; gains &lt;code&gt;remote&lt;/code&gt; (the peer’s IP address, numeric, without its port) and &lt;code&gt;route&lt;/code&gt; (the
pattern of the route a router chose, set by &lt;code&gt;Router&lt;/code&gt; as it binds the parameters), and &lt;code&gt;ByteStream&lt;/code&gt;
gains &lt;code&gt;remoteAddress&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; by default, which &lt;code&gt;TcpStream&lt;/code&gt; (accepted and connected) and &lt;code&gt;TlsStream&lt;/code&gt;
answer. Why: a rate limiter keys by client by default and a metric labels by route; a path as a
label would grow without bound, and the address was being dropped at &lt;code&gt;accept&lt;/code&gt;. The address is
without its port, since a client opens many connections and is one client. Alternatives weighed:
wrapping &lt;code&gt;Route&lt;/code&gt;s in a metrics-specific function that knows each pattern (no help for the access log
or a program’s own middleware); taking the address from &lt;code&gt;X-Forwarded-For&lt;/code&gt; (anyone can send it; a
program behind a proxy gives the limiter a &lt;code&gt;key&lt;/code&gt; that reads it). Review with the user: whether
&lt;code&gt;remote&lt;/code&gt; should also carry the port.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-observe&lt;/code&gt;): &lt;strong&gt;the access log.&lt;/strong&gt;
&lt;code&gt;http.accessLog(sink, format, clock, ids)&lt;/code&gt; is a middleware, writing after the handler answers, in
two formats, &lt;code&gt;PlainLines&lt;/code&gt; and &lt;code&gt;JsonLines&lt;/code&gt;, with method, decoded path (escaped so the line stays one
line of fields), status, body length, duration, request id and address. No timestamp: whatever
collects standard error stamps lines, and a test’s lines stay fixed. The query is left out, as it
can hold secrets. A client’s &lt;code&gt;X-Request-Id&lt;/code&gt; is kept when it is 1 to 128 characters of letters,
digits and &lt;code&gt;-._:+/=@&lt;/code&gt;, else replaced by 16 &lt;code&gt;SecureRandom&lt;/code&gt; bytes in hex; the handler reads it from
the request’s own header, which &lt;code&gt;withHeaderReplaced&lt;/code&gt; sets, and the response echoes it unless the
handler set one. A streamed body of unknown length logs &lt;code&gt;-&lt;/code&gt;/&lt;code&gt;null&lt;/code&gt; and not the bytes written,
since the line is written when the handler returns, before the body is. Alternatives weighed: a
common/combined log format (no request id, timestamp in brackets, request line quoted with the
query); counting a streamed body as it is written (the line would wait for the stream to end); a
request-scoped value in place of the header (that mechanism is a separate branch,
&lt;code&gt;api-request-values&lt;/code&gt;; the header is what clients and proxies already read). Review with the user:
a handler that traps writes no line, since Avin has no unwinding; logging the server’s &lt;code&gt;500&lt;/code&gt; would
need a hook in &lt;code&gt;serve&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-observe&lt;/code&gt;): &lt;strong&gt;request metrics.&lt;/strong&gt;
&lt;code&gt;Metrics&lt;/code&gt; holds per-(method, route, status class) counters and per-(method, route) histograms of
fixed buckets in one &lt;code&gt;Mutex&lt;/code&gt;, plus an atomic in-flight gauge, rendered as Prometheus text format
0.0.4 with the names &lt;code&gt;http_requests_total&lt;/code&gt;, &lt;code&gt;http_request_duration_seconds&lt;/code&gt; and
&lt;code&gt;http_requests_in_flight&lt;/code&gt;; times are whole microseconds, written as seconds without trailing
zeros. Default buckets are the usual 5 ms to 10 s. A request with no route is labelled &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;. Why: one
lock per &lt;code&gt;Metrics&lt;/code&gt; is simple and exact, and a request does a few map updates under it; the format is
what every scraper reads. Alternatives weighed: per-route atomics (route series are created on
demand, so a map and a lock are still needed); a metrics registry of general counters and gauges
(more than this item needs; &lt;code&gt;observe&lt;/code&gt; covers counting another way); labelling by status code rather
than class (more series for little gain). Review with the user: a handler that traps leaves the
in-flight gauge one too high, for the same lack of unwinding.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;api-observe&lt;/code&gt;): &lt;strong&gt;rate limiting.&lt;/strong&gt;
&lt;code&gt;RateLimiter(rate, per, burst, key, maxKeys, clock, errors)&lt;/code&gt; is a token bucket per key, computed as
each bucket’s next-token time in integer microseconds (the generic cell rate algorithm, exactly a
token bucket), so a bucket is one &lt;code&gt;long&lt;/code&gt; and needs no floating point. A full bucket equals a new
one, so forgetting it loses nothing; at &lt;code&gt;maxKeys&lt;/code&gt;, making a bucket forgets every full one, or where
none is full the one nearest to full. A &lt;code&gt;429&lt;/code&gt; carries &lt;code&gt;Retry-After&lt;/code&gt; in whole seconds, rounded up and
at least one. Alternatives weighed: refusing a new key when the table is full (a flood of
addresses would lock every new client out); a periodic sweep on a timer thread (a thread per
limiter; sweeping when room is needed bounds memory the same); a sliding-window counter (less
smooth, more state). Review with the user: evicting a bucket that is not full forgives that
client’s debt, which an attacker cycling more than &lt;code&gt;maxKeys&lt;/code&gt; addresses can use; and the default
key, the client’s address, puts every client behind one proxy in one bucket.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (built on branch &lt;code&gt;http-cors&lt;/code&gt;): &lt;strong&gt;CORS middleware.&lt;/strong&gt;
&lt;code&gt;Cors(origins, allowOrigin, methods, headers, exposed, credentials, maxAge)&lt;/code&gt; with a &lt;code&gt;middleware&lt;/code&gt;.
Origins match exactly (a browser’s origin is serialized in lower case, and its own check is
exact); &lt;code&gt;*&lt;/code&gt; with credentials traps at construction; with credentials the origin is echoed, never
&lt;code&gt;*&lt;/code&gt;, and &lt;code&gt;Vary: Origin&lt;/code&gt; is merged into the handler’s. A preflight is always answered &lt;code&gt;204&lt;/code&gt; by the
middleware, granting nothing (no CORS header) for an origin, method or header not allowed, which
is how a browser is told to refuse; empty &lt;code&gt;headers&lt;/code&gt; reflects the requested ones. Defaults are
the safe ones: methods &lt;code&gt;GET, HEAD, POST&lt;/code&gt;, no credentials, no max age. A disallowed origin’s
actual request is still handled (it carries &lt;code&gt;Vary: Origin&lt;/code&gt; so a cache keeps the answers apart).
Alternatives weighed: forwarding a disallowed origin’s preflight to the handler (the handler would
answer a route’s &lt;code&gt;405&lt;/code&gt;, a confusing signal and extra work); case-insensitive origin matching (not
what a browser does); a wildcard that echoes with credentials (the Fetch standard forbids
&lt;code&gt;*&lt;/code&gt; there, and an echo of any origin with credentials is an open door, so &lt;code&gt;allowOrigin&lt;/code&gt; must be
asked for). Review with the user: empty &lt;code&gt;headers&lt;/code&gt; reflecting any requested header is the
common default but allows more than a closed list would.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (built on branch &lt;code&gt;resolve-blocking&lt;/code&gt;): &lt;strong&gt;which library
bindings are &lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;blocking&lt;/a&gt;.&lt;/strong&gt; Name resolution
(&lt;code&gt;sysl.net.resolve&lt;/code&gt;, which &lt;code&gt;TcpStream.connect&lt;/code&gt; calls; since 2026-11-16 made on a helper thread
instead, below) and connecting a Unix socket are, as are
reading, writing and opening a file in &lt;code&gt;avin.fs&lt;/code&gt; and &lt;code&gt;avin.process&lt;/code&gt;‘s redirections (the whole-file
calls, &lt;code&gt;File&lt;/code&gt;‘s &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt; and &lt;code&gt;flush&lt;/code&gt;, and every open), and reading a time zone’s file: each
can wait on a pipe, a FIFO, a device or the network. Asking about a path, listing a directory,
creating, removing and renaming entries are not, nor are closing a file, spawning a process,
reading the OS’s entropy or the in-memory TLS engine. A test in &lt;code&gt;shim_tests.sysl&lt;/code&gt; names each
waiting binding a program reaches and asserts it blocking. Alternatives weighed: binding every
file-system call blocking (the metadata calls do not wait on another party, and each blocking call
is copied across); only the calls that touch the network (a FIFO open or read held its worker and
every collection, which &lt;code&gt;tests/run/fs_fifo_blocking.avin&lt;/code&gt; shows). Review with the user: a
directory operation on a network file system can also wait, and standard input and output, which
the runtime reads and writes through intrinsics rather than bindings, are not yet safe for the
collector while they wait.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (built on branch &lt;code&gt;resolve-cancel&lt;/code&gt;): &lt;strong&gt;a host-name
lookup is a &lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation point&lt;/a&gt;.&lt;/strong&gt; As a blocking call it was not: a
&lt;code&gt;withTimeout&lt;/code&gt; waits for what it cancelled to end, so a slow resolver held a connect’s time limit
past its deadline (a 100 ms &lt;code&gt;withTimeout&lt;/code&gt; around a connect whose lookup took 3 s answered after
3009 ms). The runtime (&lt;code&gt;runtime/avin/rt/lookup.sysl&lt;/code&gt;) makes each lookup on a helper thread and the
caller waits for a byte on a pipe as it waits on a socket, so a cancellation ends the wait at once;
an abandoned lookup runs on to the resolver’s answer, which its helper throws away before closing
the pipe. The host, port and answer are copied into a slot and out again under one lock, so
nothing either thread holds is shared. Helpers are detached, take the oldest queued lookup, and end
once none is queued; at most 64 run at once, which bounds how many abandoned lookups can still be
running. Past the bound a new lookup waits in the queue, and a cancellation drops it from there. A
numeric address is resolved inline. A lightweight thread waiting on a lookup shows in a thread dump
as “looking up a host name”. Tests hold the helpers through a runtime hook (&lt;code&gt;resolve_hold&lt;/code&gt;), since
no resolver that never answers can be stood up without system configuration on every platform.
Alternatives weighed: one detached thread per lookup with no bound (abandoned threads pile up
without limit while the resolver is down); failing a lookup at once past the bound (fails lookups
of hosts that would answer); the platform’s asynchronous resolver (&lt;code&gt;getaddrinfo_a&lt;/code&gt; is glibc’s
alone, and macOS’s is a different API); a resolver of Avin’s own speaking DNS (loses
&lt;code&gt;/etc/hosts&lt;/code&gt;, NSS and the system’s configuration). Review with the user: whether lookups of the
same host and port in flight at once should share one helper, which would keep repeated retries
during a resolver outage from filling the 64.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;byte-writer&lt;/code&gt;, for the PostgreSQL
package’s &lt;code&gt;COPY … TO STDOUT&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.io.ByteWriter&lt;/code&gt; is the byte sink beside &lt;code&gt;Reader&lt;/code&gt;&lt;/strong&gt;
(&lt;a href=&quot;/spec/system-library/#bytewriter&quot;&gt;&lt;code&gt;ByteWriter&lt;/code&gt;&lt;/a&gt;): one method, &lt;code&gt;write(bytes: Array[byte]) -&amp;gt; Result[unit, IoError]&lt;/code&gt;, writing all of &lt;code&gt;bytes&lt;/code&gt;. &lt;code&gt;fs.File&lt;/code&gt;, every &lt;code&gt;net.ByteStream&lt;/code&gt; (&lt;code&gt;TcpStream&lt;/code&gt;,
&lt;code&gt;UnixStream&lt;/code&gt;, &lt;code&gt;TlsStream&lt;/code&gt;), &lt;code&gt;net.StreamWriter&lt;/code&gt; and &lt;code&gt;http.BodyWriter&lt;/code&gt; implement it by the &lt;code&gt;write&lt;/code&gt;
they already had, so no call changes; &lt;code&gt;ByteStream&lt;/code&gt; and &lt;code&gt;StreamWriter&lt;/code&gt; now take &lt;code&gt;write&lt;/code&gt; from the
trait instead of declaring it. &lt;strong&gt;The name&lt;/strong&gt;: the pair of &lt;code&gt;Reader&lt;/code&gt; would be &lt;code&gt;Writer&lt;/code&gt;, but the
prelude’s &lt;code&gt;Writer&lt;/code&gt; (&lt;code&gt;module avin&lt;/code&gt;, seen by every program unqualified) is the text sink values
render into, so &lt;code&gt;avin.io.Writer&lt;/code&gt; would make &lt;code&gt;Writer&lt;/code&gt; mean two things in any program importing it,
and &lt;code&gt;Display&lt;/code&gt;‘s &lt;code&gt;display(out: Writer, …)&lt;/code&gt; would read as the wrong one. Alternatives weighed:
&lt;code&gt;Write&lt;/code&gt; (a verb, as &lt;code&gt;Close&lt;/code&gt; is; but &lt;code&gt;avin.net&lt;/code&gt; already has a &lt;code&gt;Write&lt;/code&gt; case of how a socket is shut
down, and &lt;code&gt;Write&lt;/code&gt;/&lt;code&gt;Writer&lt;/code&gt; side by side invite the wrong one); &lt;code&gt;Sink&lt;/code&gt; (short, but &lt;code&gt;avin.io&lt;/code&gt;‘s
&lt;code&gt;Source&lt;/code&gt; is a TEXT source, so &lt;code&gt;Sink&lt;/code&gt; reads as its text pair); &lt;code&gt;Output&lt;/code&gt; (says nothing of bytes,
and reads as a command’s output); &lt;code&gt;ByteSink&lt;/code&gt;. &lt;code&gt;ByteWriter&lt;/code&gt; says what it takes and pairs with
&lt;code&gt;ByteStream&lt;/code&gt;. &lt;strong&gt;No &lt;code&gt;flush()&lt;/code&gt;&lt;/strong&gt;: files buffer and sockets do not, so a flush on the trait would be
a no-op for most implementations, and TLS keeps a private &lt;code&gt;flush&lt;/code&gt; of its own that a public one
would collide with; whoever opened a file closes it, which flushes. &lt;strong&gt;Not a &lt;code&gt;Close&lt;/code&gt;&lt;/strong&gt;, as &lt;code&gt;Reader&lt;/code&gt;
is not: a &lt;code&gt;BodyWriter&lt;/code&gt; is ended by its response, not closed; code holding a resource that is
both bounds it by both. &lt;strong&gt;&lt;code&gt;io.copy(from: Reader, to: ByteWriter) -&amp;gt; Result[long, IoError]&lt;/code&gt;&lt;/strong&gt;
copies in pieces of at most 64 KiB, answering the count or the first &lt;code&gt;Err&lt;/code&gt;, closing, flushing and
rewinding nothing. Standard output and standard error stay text-only &lt;code&gt;Writer&lt;/code&gt;s: they have no byte
path to write through. No in-memory byte sink is added: a &lt;code&gt;Buffer[byte]&lt;/code&gt; is filled by
&lt;code&gt;addAll&lt;/code&gt;, and a sink of the program’s own is a five-line class. Review with the user: the name
&lt;code&gt;ByteWriter&lt;/code&gt; (against &lt;code&gt;Write&lt;/code&gt; or &lt;code&gt;Sink&lt;/code&gt;), and whether standard output should gain a byte path
and be a &lt;code&gt;ByteWriter&lt;/code&gt; too.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;cbind-gaps&lt;/code&gt;, for the libssh2
binding): &lt;strong&gt;a function pointer marked &lt;code&gt;null&lt;/code&gt; is passed null&lt;/strong&gt;
(&lt;a href=&quot;/spec/c-bindings/#arrays-and-out-parameters&quot;&gt;C bindings&lt;/a&gt;). &lt;code&gt;libssh2_session_init_ex&lt;/code&gt; is the only
way to make a session (&lt;code&gt;libssh2_session_init()&lt;/code&gt; is a macro passing four nulls), and a function
pointer without a &lt;code&gt;userdata&lt;/code&gt; was refused with no way to pass null. The prototype word &lt;code&gt;null&lt;/code&gt;,
which already passed null for any other pointer, now takes a function pointer too; its parameters
are read only as C’s types for the header check (named, no &lt;code&gt;userdata&lt;/code&gt; or &lt;code&gt;length&lt;/code&gt;, any result),
since C never calls it. Refused: &lt;code&gt;null&lt;/code&gt; twice, after &lt;code&gt;out&lt;/code&gt;, on a struct by value or a scalar, and an
unnamed function pointer. &lt;em&gt;Alternatives&lt;/em&gt;: an &lt;code&gt;Option[function]&lt;/code&gt; parameter with only &lt;code&gt;None&lt;/code&gt; legal (a
parameter whose one value is written at every call, and an &lt;code&gt;Option&lt;/code&gt; that never holds &lt;code&gt;Some&lt;/code&gt;);
binding a header macro (&lt;code&gt;libssh2_session_init&lt;/code&gt;), which the C unit cannot type-check as a function
and which most hooks have no macro for.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;cbind-gaps&lt;/code&gt;): &lt;strong&gt;a kept handle no C
reference can hold is kept from the collector until its holder’s &lt;code&gt;release&lt;/code&gt; has run&lt;/strong&gt;
(&lt;a href=&quot;/spec/c-bindings/#kept-handles-and-the-order-they-are-given-back&quot;&gt;C bindings&lt;/a&gt;). libssh2 counts no
references, frees every channel in &lt;code&gt;libssh2_session_free&lt;/code&gt;, and reaches the session from
&lt;code&gt;libssh2_channel_free&lt;/code&gt;; a channel and its session found dead in one collection were finalized in
address order, so the session could go first and the channel’s release free it again. &lt;code&gt;kept:&lt;/code&gt; may
now name a class with no &lt;code&gt;retain&lt;/code&gt; (or with a &lt;code&gt;kept:&lt;/code&gt; of its own): the holder pins the kept handle’s
Avin object in a runtime table, a root of every collection, and lets go of the pin after its own
&lt;code&gt;release&lt;/code&gt;, by &lt;code&gt;close()&lt;/code&gt; or its finalizer; the kept one is finalized in a later collection. Its
&lt;code&gt;kept:&lt;/code&gt; name is the kept handle’s pointer, or null once that handle was closed, so the release
can tell (&lt;code&gt;session ? libssh2_channel_free(self) : 0&lt;/code&gt;). A chain is finalized one link per
collection, holder first. &lt;strong&gt;A cycle through a pin is never collected&lt;/strong&gt; (a session keeping, as its
Avin object, a channel that pins it): both are given back once either is closed. &lt;em&gt;Why&lt;/em&gt;: the
collector finalizes in address order and a finalizer cannot resurrect, so ordering can only come
from keeping the kept object reachable until the holder is done; a root held per holder does that
with no change to the collector. &lt;em&gt;Alternatives&lt;/em&gt;: collector-ordered finalization (topological, as
some collectors offer; the gc library has none, and Avin does not change it); the holder’s release
given back without its kept object, on trust (the unsound state this replaces); a &lt;code&gt;retain:&lt;/code&gt; of the
package’s own (libssh2 has no count to take). &lt;strong&gt;Review with the user&lt;/strong&gt;: that a cycle through a
pin leaks until closed, rather than being refused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;cbind-gaps&lt;/code&gt;): &lt;strong&gt;a handle holds C
integers for its &lt;code&gt;release:&lt;/code&gt;, &lt;code&gt;holds:&lt;/code&gt; on the class and &lt;code&gt;hold:&lt;/code&gt; on a binding&lt;/strong&gt;
(&lt;a href=&quot;/spec/c-bindings/#values-a-handle-holds&quot;&gt;C bindings&lt;/a&gt;). libssh2 is given the socket of an Avin
&lt;code&gt;TcpStream&lt;/code&gt; and writes to it in &lt;code&gt;libssh2_session_free&lt;/code&gt;; a stream finalized first, or closed by
the program first, gives its descriptor’s number to the next one opened, so the session’s
farewell could reach an unrelated connection, and a release that sees only &lt;code&gt;self&lt;/code&gt; cannot say which
socket it used. A class declares &lt;code&gt;holds: &amp;quot;int sock = -1&amp;quot;&lt;/code&gt;, a C declaration of an integer and the
value it starts as; a binding’s &lt;code&gt;hold: &amp;quot;sock&amp;quot;&lt;/code&gt; makes the handle it answers, or its receiver, hold
the value of that integer parameter when the call succeeds, replacing one held before; the release
uses it by name. The value is an entry on the list the glue keeps of what the handle holds, beside
its C references, so the layout of a handle does not change. The package holds a descriptor of its
own, &lt;code&gt;dup&lt;/code&gt;ed from the stream’s, which makes the session’s release sound whichever object the
collector finalizes first and whether the stream was closed before. Refused: &lt;code&gt;holds:&lt;/code&gt; on a
&lt;code&gt;shared&lt;/code&gt; class or one with &lt;code&gt;retain:&lt;/code&gt; (one reference of many), a name &lt;code&gt;release:&lt;/code&gt; does not use, &lt;code&gt;self&lt;/code&gt;
or the &lt;code&gt;kept:&lt;/code&gt; name, a declaration that is no integer; &lt;code&gt;hold:&lt;/code&gt; naming no integer parameter, or a
name the holder’s class does not declare, or on a binding answering no handle and no method of
one. &lt;em&gt;Alternatives&lt;/em&gt;: the kept stream pinned until the session’s release, as kept handles now are
(the release still could not read the descriptor from an Avin object, finalizers running no Avin
code, and a stream the program closed first would hand the release a number already reused);
holding the stream’s own descriptor without &lt;code&gt;dup&lt;/code&gt; (the same reuse); a C handle over the descriptor
(a handle is on a pointer). &lt;strong&gt;Review with the user&lt;/strong&gt;: whether &lt;code&gt;holds:&lt;/code&gt; should also take pointers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;cbind-gaps&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;free:&lt;/code&gt; frees a
string C answers through an &lt;code&gt;out&lt;/code&gt; pointer by an entry &lt;code&gt;&amp;quot;name: how&amp;quot;&lt;/code&gt;&lt;/strong&gt;
(&lt;a href=&quot;/spec/c-bindings/#strings&quot;&gt;C bindings&lt;/a&gt;). &lt;code&gt;libssh2_channel_get_exit_signal&lt;/code&gt; answers three strings
freed by &lt;code&gt;libssh2_free(session, p)&lt;/code&gt;, and &lt;code&gt;free:&lt;/code&gt; covered only a result. &lt;code&gt;how&lt;/code&gt; is a C function of the
string or a C expression in its name, compiled in a glue function per string that a method passes
its receiver’s object: the expression may use &lt;code&gt;self&lt;/code&gt;, the receiver class’s &lt;code&gt;kept:&lt;/code&gt; name and the
values it &lt;code&gt;holds:&lt;/code&gt; (here the channel’s kept session). It is called once the copy is made, never
for null, and on a failed status for each string C answered, unread. Refused: a name that is no
&lt;code&gt;out&lt;/code&gt; parameter answering a string or its bytes, &lt;code&gt;inout&lt;/code&gt; (C may answer the copy it was passed), a
name freed twice, an expression not in the name, and named entries beside arrays &lt;code&gt;array:&lt;/code&gt; frees by
position. &lt;em&gt;Why the spelling&lt;/em&gt;: &lt;code&gt;free:&lt;/code&gt; already says how what C answers is freed, and &lt;code&gt;name:&lt;/code&gt; reads
as the &lt;code&gt;kept: &amp;quot;face: Face&amp;quot;&lt;/code&gt; entries do; a name is needed because a binding answers several strings.
&lt;em&gt;Alternatives&lt;/em&gt;: a separate key (&lt;code&gt;frees:&lt;/code&gt;), a second word for one idea; any parameter of the call in
the expression (the strings C was passed are freed once converted, before the outs are, so only
the receiver’s own names are offered); copying the string in the call’s glue and freeing it there
(a second copy of every string).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-17 (built on branch &lt;code&gt;pool-check-cancel&lt;/code&gt;, for the
PostgreSQL package’s pool under deadlines): &lt;strong&gt;a &lt;code&gt;Pool&lt;/code&gt; call cancelled while &lt;code&gt;validate&lt;/code&gt; checks a
resource puts the resource back as one given back is put back&lt;/strong&gt; (&lt;a href=&quot;/spec/threads/&quot;&gt;Pool&lt;/a&gt;): idle, or
to the first call waiting, destroyed only where the pool was closed meanwhile or the resource has
outlived &lt;code&gt;maxLifetime&lt;/code&gt;. It was destroyed. A deadline (&lt;code&gt;withDeadline&lt;/code&gt;, &lt;code&gt;withTimeout&lt;/code&gt;) cancels a
thread, and a function entry or a loop’s back edge is a cancellation point, so a deadline passing
just as an idle resource was taken stopped its check even where &lt;code&gt;validate&lt;/code&gt; never waits, and good
resources were destroyed: up to 5 of a pool of 4 in a round of 100 calls under short deadlines.
&lt;em&gt;Why it is sound&lt;/em&gt;: every resource is checked before it is lent, one handed to a waiter included,
so one a stopped check left in a bad state (a ping half sent) is caught and destroyed at its next
lend. &lt;em&gt;Alternatives weighed&lt;/em&gt;: running &lt;code&gt;validate&lt;/code&gt; where cancellation cannot stop it (a check that
blocks, a ping to a server that does not answer, would then hold the caller past its own deadline
until the check’s own timeout); destroying the resource only where &lt;code&gt;validate&lt;/code&gt; had begun to wait
(the pool cannot see inside the check, and a resource cut off mid-exchange is caught at its next
check either way). Of the pool’s other cancellable steps, a cancelled &lt;code&gt;create&lt;/code&gt; already gives its
place up, or keeps what it made, and a cancelled &lt;code&gt;f&lt;/code&gt; already gives the resource back; destroying
outlived and closed resources runs where nothing stops it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (built on branch &lt;code&gt;static-link&lt;/code&gt;, for tend’s one
self-contained binary): &lt;strong&gt;a program links its C libraries from their static archives when its
manifest says &lt;code&gt;static-c-libraries = true&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/c-bindings/#linking-statically&quot;&gt;C bindings&lt;/a&gt;).
The user decided that static linking is avin’s own item; the shape is this branch’s. One
top-level key of the root package, a boolean; a dependency’s is not read, since how a program is
linked is decided once for the whole of it, and a library package deciding it would decide for
programs it never sees (Sysl’s &lt;code&gt;link&lt;/code&gt; key, root-only for the same reason). For every library a
&lt;code&gt;pkg-config&lt;/code&gt; module finds, of every package in the program, the build asks &lt;code&gt;pkg-config --static --libs&lt;/code&gt;, which adds what the library links privately (&lt;code&gt;Libs.private&lt;/code&gt;), and replaces each &lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt;
whose &lt;code&gt;lib&amp;lt;name&amp;gt;.a&lt;/code&gt; is in one of the answer’s &lt;code&gt;-L&lt;/code&gt; directories by &lt;strong&gt;the archive’s path&lt;/strong&gt;, the only
spelling that reaches an archive on macOS, where the linker takes a &lt;code&gt;.dylib&lt;/code&gt; over a &lt;code&gt;.a&lt;/code&gt; in the
same directory. A name none of those directories holds is the system’s own (libSystem, libz) and
stays dynamic. &lt;strong&gt;A name whose shared library is in one of them but whose archive is in none stops
the build&lt;/strong&gt; with an error naming the shared library and the archive it lacks, where Sysl’s
&lt;code&gt;link = &amp;quot;static&amp;quot;&lt;/code&gt; links such a library dynamically and says so only under &lt;code&gt;--verbose&lt;/code&gt;: a program
asking for static libraries exists so that the machine running it needs nothing installed, and a
silent &lt;code&gt;.dylib&lt;/code&gt; is the very program the key is there to prevent. A library named by &lt;code&gt;link&lt;/code&gt; is
passed as &lt;code&gt;-l&lt;/code&gt; as before. &lt;em&gt;Alternatives weighed&lt;/em&gt;: a per-library &lt;code&gt;static = true&lt;/code&gt; in &lt;code&gt;c-libraries&lt;/code&gt;
(the library’s author would decide for every program, and a program could not ask for a
dependency’s library); Sysl’s &lt;code&gt;link = &amp;quot;static&amp;quot; | [names]&lt;/code&gt; with a &lt;code&gt;--link&lt;/code&gt; flag (a top-level &lt;code&gt;link&lt;/code&gt;
beside the &lt;code&gt;link&lt;/code&gt; of a C library meaning &lt;code&gt;-l&lt;/code&gt; names would read as one key with two meanings; a list
of names and a flag can come later without changing this one); a &lt;code&gt;--static-libs&lt;/code&gt; build flag alone
(how the program must be linked is a property of the program, and a release built without the flag
would quietly need Homebrew). &lt;strong&gt;Review with the user&lt;/strong&gt;: the key’s name and its boolean shape against
Sysl’s &lt;code&gt;link&lt;/code&gt;; that it is stricter than Sysl’s &lt;code&gt;&amp;quot;static&amp;quot;&lt;/code&gt;; that a library &lt;code&gt;pkg-config&lt;/code&gt; gives no
&lt;code&gt;-L&lt;/code&gt; directory for counts as the system’s, which on Linux leaves a distribution’s &lt;code&gt;/usr/lib&lt;/code&gt;
libraries dynamic; and that the C libraries of a program’s Sysl packages (&lt;code&gt;requires { pkg_config }&lt;/code&gt;)
are not covered.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (branch &lt;code&gt;contra-infer&lt;/code&gt;): &lt;strong&gt;inference holds an argument to its parameter by
each type argument’s variance, and a type argument named at a contravariant argument is decided as
the type given there.&lt;/strong&gt; &lt;code&gt;take[T](b: Box[B, T])&lt;/code&gt; for &lt;code&gt;Box[-I, +T]&lt;/code&gt; accepts a &lt;code&gt;Box[A, int]&lt;/code&gt; where
&lt;code&gt;B&lt;/code&gt; is an &lt;code&gt;A&lt;/code&gt; and takes &lt;code&gt;T&lt;/code&gt; as &lt;code&gt;int&lt;/code&gt;, as the non-generic &lt;code&gt;takeInt(b: Box[B, int])&lt;/code&gt; always did; the
same holds for a function type’s parameters (&lt;code&gt;(A) -&amp;gt; int&lt;/code&gt; given for &lt;code&gt;(B) -&amp;gt; T&lt;/code&gt;) and a constructor
parameter’s contravariant hole. &lt;code&gt;feed[T](b: Box[T, int], x: T)&lt;/code&gt; given a &lt;code&gt;Box[A, int]&lt;/code&gt; takes &lt;code&gt;T&lt;/code&gt; as
&lt;code&gt;A&lt;/code&gt;, the largest type the box accepts, and a later argument must be an instance of it; an earlier
argument that widened &lt;code&gt;T&lt;/code&gt; beyond it is an error. &lt;em&gt;Why&lt;/em&gt;: the spec says constraints are subtype
constraints, and the checker unified a contravariant argument for equality, refusing calls the
same signature accepts without type parameters (it blocked the parsing library’s &lt;code&gt;Rule[-I, +T]&lt;/code&gt;).
&lt;em&gt;Alternatives weighed&lt;/em&gt;: collecting upper bounds and solving to their meet, so two boxes of &lt;code&gt;A&lt;/code&gt;s and
of &lt;code&gt;B&lt;/code&gt;s given for one &lt;code&gt;Box[T, int]&lt;/code&gt; in either order take &lt;code&gt;B&lt;/code&gt; (more complete, but needs a meet the
checker has nowhere else; with the order as written the box of &lt;code&gt;B&lt;/code&gt;s first is accepted today, the
other order is refused); deciding such a type argument from the other arguments only (would refuse
the probe above whenever &lt;code&gt;T&lt;/code&gt; is named nowhere else). A type argument named at a contravariant
argument nested in another contravariant one is still held whole. &lt;strong&gt;Review with the user&lt;/strong&gt;: whether
the meet is worth adding when a program meets the order-dependent case.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (branch &lt;code&gt;stdin-serialize&lt;/code&gt;): &lt;strong&gt;threads read standard input one at a time, and
each read is whole&lt;/strong&gt; (&lt;a href=&quot;/spec/system-library/#standard-input&quot;&gt;system library&lt;/a&gt;). A &lt;code&gt;readLine&lt;/code&gt;, an
iterator’s step, a character and &lt;code&gt;readAll&lt;/code&gt; each hold the input from their look at whether it has
ended to their taking of what they read, so a line goes to exactly one reader, never split
between two or given to both, and a reader past the end gets &lt;code&gt;None&lt;/code&gt;, never a stray empty line.
Found because nothing serialized the one buffer: two lightweight threads reading at once hung
(both parked on the descriptor) or trapped out of range in the runtime. The lock is a runtime lock
of the library’s kind (&lt;code&gt;ParkLock&lt;/code&gt;, held across the reader’s wait for input): a lightweight thread
waiting for it, or waiting for input while holding it, parks, so neither holds up a carrier; it is
a region a trap is not contained in, as any lock’s is, so a contained trap never leaves it held.
&lt;strong&gt;An iterator over standard input takes the line (or character) &lt;code&gt;hasNext&lt;/code&gt; answers for and keeps it
until &lt;code&gt;next&lt;/code&gt;&lt;/strong&gt;, since otherwise another thread could take that line between the two and &lt;code&gt;next&lt;/code&gt;
would fail on a &lt;code&gt;hasNext&lt;/code&gt; that said &lt;code&gt;true&lt;/code&gt;. On one thread this is seen only by code that asks
&lt;code&gt;hasNext&lt;/code&gt; and then reads by another way: the other read gets the line after the one the iterator
holds. Alone, a reader pays two uncontended lock operations per read (2M lines: 0.136 s before,
0.139 s after). &lt;em&gt;Alternatives weighed&lt;/em&gt;: a lock taken inside each runtime call only (the library’s
look at the end and its take are two calls, so a reader could still get &lt;code&gt;Some(&amp;quot;&amp;quot;)&lt;/code&gt; past the end);
an OS lock (held across the wait for input it would block a carrier, and a thread parked holding
it would resume on another carrier and let go of a lock it does not own there); a &lt;code&gt;Mutex&lt;/code&gt; in
&lt;code&gt;avin.io&lt;/code&gt; (the same lock, with an object to keep alive and the module made to depend on
&lt;code&gt;avin.threads&lt;/code&gt;); an iterator whose &lt;code&gt;hasNext&lt;/code&gt; takes nothing (racy across threads, as above).
&lt;strong&gt;Review with the user&lt;/strong&gt;: the iterator’s taking of its line at &lt;code&gt;hasNext&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (built on branch &lt;code&gt;typaram-bound&lt;/code&gt;, for the parsing library’s
&lt;code&gt;Rule[-I: Reader, +T]&lt;/code&gt;): &lt;strong&gt;a function’s or a method’s own type parameter may be bounded by a type
parameter declared before it, &lt;code&gt;[J: I]&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#bounds-by-a-type-parameter&quot;&gt;generics&lt;/a&gt;),
the twin of the lower bound &lt;code&gt;[W &amp;gt;: T]&lt;/code&gt;. A &lt;code&gt;J&lt;/code&gt; is an &lt;code&gt;I&lt;/code&gt; with no conversion and has &lt;code&gt;I&lt;/code&gt;‘s bounds; each
type argument must be the bounding one’s or be seen as it as a covariant part is (so a value type
never stands for a trait there); the bound is a position where a value is passed in, so a &lt;code&gt;-I&lt;/code&gt; may
bound one and a &lt;code&gt;+T&lt;/code&gt; may not; an override writes the overridden method’s bound or none. Choices this
branch made: &lt;strong&gt;only a function’s or a method’s own parameters&lt;/strong&gt; take one, as only they take a lower
bound (a type’s own &lt;code&gt;[A, B: A]&lt;/code&gt; would need its own variance rule, the opposite of a method’s, and no
program needs it yet); &lt;strong&gt;the bounding parameter is declared before it&lt;/strong&gt; (the enclosing type’s or
impl’s, or earlier in the list), which rules out cycles by construction and makes &lt;code&gt;[A: B, B: A]&lt;/code&gt; an
error at its first bound, where lower bounds allow a later parameter and check for a chain leading
back; &lt;strong&gt;one at most&lt;/strong&gt; per parameter (two would be an intersection of two unknowns, which no
instance needs); &lt;strong&gt;inference takes the narrower&lt;/strong&gt;: a type argument decided where a value is passed
in takes the bounding argument when that is a subtype of the type given and not the other way round
(&lt;code&gt;digit() | success(4)&lt;/code&gt; is a &lt;code&gt;Rule[Input, long]&lt;/code&gt;, not an error), and a bounding parameter nothing
else decides is taken from the one it bounds. &lt;em&gt;Alternatives weighed&lt;/em&gt;: refusing &lt;code&gt;digit() | success(4)&lt;/code&gt;
and making the caller write &lt;code&gt;|[Input]&lt;/code&gt; (correct but unpleasant at the most common call shape);
allowing a later parameter with a cycle check, as lower bounds do (more to say for no program that
needs it); a type’s own parameters bounded too (sound only for a covariant or invariant bounding
parameter, a rule that can come when a program asks). &lt;strong&gt;Review with the user&lt;/strong&gt;: the
declared-before rule, which differs from the lower bound’s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-18 (branch &lt;code&gt;contra-join&lt;/code&gt;, for the parsing library’s token streams): &lt;strong&gt;branches
join at a contravariant argument to the meet of the two arguments, and a fully known expected type
wins over a join that misses it&lt;/strong&gt; (&lt;a href=&quot;/spec/generics/#variance&quot;&gt;generics&lt;/a&gt;). &lt;code&gt;In[A]&lt;/code&gt; and &lt;code&gt;In[B]&lt;/code&gt; for
&lt;code&gt;In[-T]&lt;/code&gt; agree on &lt;code&gt;In[B]&lt;/code&gt; (they fell back to a trait both share, &lt;code&gt;Display&lt;/code&gt; where an impl gave one,
and then missed an expected &lt;code&gt;In[B]&lt;/code&gt;); a function type’s parameters join the same way and its
result as a covariant argument, so &lt;code&gt;(A) -&amp;gt; int&lt;/code&gt; and &lt;code&gt;(B) -&amp;gt; int&lt;/code&gt; agree on &lt;code&gt;(B) -&amp;gt; int&lt;/code&gt; (they
agreed on nothing). Choices this branch made: &lt;strong&gt;the meet is one of the two arguments&lt;/strong&gt;, the one
that is a subtype of the other (&lt;code&gt;Nothing&lt;/code&gt; included); where neither is, no type is named as the meet
and the class join does not exist for the pair, so the fallback to a shared trait stands, as for
two classes with no common superclass. &lt;strong&gt;Where the expected type is fully known (no inference
variable left in it), a reference type, and what the branches agree on is not an instance of it
while both branches are, the branches agree on the expected type&lt;/strong&gt;: a &lt;code&gt;Dog&lt;/code&gt; and a &lt;code&gt;Cat&lt;/code&gt; that are
&lt;code&gt;Animal&lt;/code&gt;s and &lt;code&gt;Pet&lt;/code&gt;s agree on &lt;code&gt;Pet&lt;/code&gt; where a &lt;code&gt;Pet&lt;/code&gt; is expected (they agreed on &lt;code&gt;Animal&lt;/code&gt; and failed).
&lt;strong&gt;Where neither the agreement nor a branch is an instance of that expected type, the branch (or
&lt;code&gt;match&lt;/code&gt; arm) is reported&lt;/strong&gt;, “this branch yields Sink[string], not the Sink[B] expected of the
&lt;code&gt;if&lt;/code&gt;“, rather than the fallback trait at the result. Why: the expected type is what the program
asked for, and a join that misses it while every branch meets it is a wrong answer, not an
ambiguity; naming the branch says what to change. &lt;em&gt;Alternatives weighed&lt;/em&gt;: the expected type
always winning where both branches fit (testing a branch against an expected type still being
inferred settles its inference variables, so the rule is held to fully known types and leaves
inference as it was); a nominal meet of unrelated arguments, the greatest common subclass
(none can be named in general, and an intersection type is not a type Avin writes); keeping the
result-level message (it names a trait the program never mentioned).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;open&quot;&gt;Open&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Whether constructor traits may carry parameters that are not holes (an error type fixed per
trait, &lt;code&gt;MonadError[A, E]&lt;/code&gt;), and whether composed constructors (&lt;code&gt;Option[List[_]]&lt;/code&gt;) are wanted; both
are left out of the higher-kinded design and need no change to it to add later.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Exporting a whole module as a member of another (&lt;code&gt;export a.b&lt;/code&gt;), which needs modules as members.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Tooling for exports: completion after &lt;code&gt;m.&lt;/code&gt; and in an import group listing a module’s exports
beside its declarations, and the IntelliJ plugin’s resolution following an export to the
declaration (go-to-definition, find usages, renaming through an export).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What a comprehension over a &lt;code&gt;Map&lt;/code&gt; yields when its values are not pairs (it needs &lt;code&gt;Iterable&lt;/code&gt;‘s own
transformations).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Packages, where Sysl’s choice does not transfer (&lt;a href=&quot;/spec/packages/&quot;&gt;packages&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Whether a build should re-hash &lt;code&gt;vendor/&lt;/code&gt; on every run, catching a hand edit to a committed
vendored package, or trust the hash recorded beside each package as it trusts the cache’s.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Lightweight threads, the open parts of the settled design above (cancellation is under
&lt;a href=&quot;#proposed&quot;&gt;Proposed&lt;/a&gt;): none is left open. Stack size and growth are settled above (branch
&lt;code&gt;lwt-stacks&lt;/code&gt;), and keeping user-interface work on the main thread is settled above as threads
pinned to the main thread (branch &lt;code&gt;main-lwt&lt;/code&gt;). The allocation chunk belongs to the carrier (proposed above), so
thousands of parked lightweight threads hold no chunk each. The collector needs nothing new: its roots are what the
runtime’s callback marks, so a parked lightweight thread’s context keeps its exact shadow stack
and is walked as an attached thread’s is, and switching stacks happens only at the runtime’s own
safepoints, so no collection sees one half done.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-06 (branch &lt;code&gt;check-stops-early&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin check&lt;/code&gt; stops after type checking&lt;/strong&gt;. Checking a
program no longer lowers it, builds the shims of its Sysl bindings or builds its C unit: the
previous &lt;code&gt;check&lt;/code&gt; did all three and threw the result away, 4.9 s against 0.4 s of checking on a
terminal-interface example. Two diagnostics came only from those later steps. &lt;strong&gt;A C declaration
that names no header&lt;/strong&gt; needs no C compiler to find, so &lt;code&gt;check&lt;/code&gt; reports it. &lt;strong&gt;A Sysl binding Sysl
rejects, and what clang rejects of the C unit&lt;/strong&gt; (a constant that does not fit, a prototype the
header contradicts) need the real tools, and stay behind &lt;code&gt;avin check --bindings&lt;/code&gt;, which runs the
whole pipeline up to the emitted code as &lt;code&gt;check&lt;/code&gt; used to. Why: a type error is the common failure
and should cost what checking costs; a binding changes rarely and &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; still
report it. Alternatives weighed: moving the shim’s type-check into the checker (a second
implementation of Sysl’s inference, certain to drift); keeping &lt;code&gt;check&lt;/code&gt; as it was (the slowness
this fixes); dropping binding validation from &lt;code&gt;check&lt;/code&gt; with no flag (leaves no command that
reports a bad binding without linking). The language server already stops at checking, so it
matches the new &lt;code&gt;check&lt;/code&gt;. Review with the user: whether &lt;code&gt;--bindings&lt;/code&gt; should instead be the
default for packages that have bindings. (Revised 2026-11-15, branch &lt;code&gt;c-opaque-errno&lt;/code&gt;: &lt;code&gt;check&lt;/code&gt;
builds the C unit too, so what clang rejects of it is reported without &lt;code&gt;--bindings&lt;/code&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;crypto-pbkdf2-uuid&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;avin.crypto&lt;/code&gt; gains
&lt;code&gt;pbkdf2HmacSha256&lt;/code&gt; and &lt;code&gt;pbkdf2HmacSha512&lt;/code&gt;&lt;/strong&gt;, taking &lt;code&gt;Vector[byte]&lt;/code&gt; or &lt;code&gt;string&lt;/code&gt; for password and
salt as &lt;code&gt;hmacSha256&lt;/code&gt; takes its key and message. Bound to &lt;code&gt;sysl.crypto.pbkdf2_hmac256&lt;/code&gt;/&lt;code&gt;512&lt;/code&gt; through
a runtime shim (&lt;code&gt;avin.rt.digest_pbkdf2_*&lt;/code&gt;), since Sysl’s takes an unsigned count and an output
slice; no OpenSSL involved, as the other digests. A count below 1 and a length below 1 or over 255
digests (8160, 16320) trap in Avin with the library’s message style, so the shim never sees them.
Alternatives weighed: returning a &lt;code&gt;Result&lt;/code&gt; (a bad count is the caller’s bug, as &lt;code&gt;between&lt;/code&gt;‘s bad
bounds are); OpenSSL’s &lt;code&gt;PKCS5_PBKDF2_HMAC&lt;/code&gt; (adds a dependency for a digest Sysl has).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;crypto-pbkdf2-uuid&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;Uuid&lt;/code&gt; lives in its own
module &lt;code&gt;avin.uuid&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;library/avin/uuid/uuid.avin&lt;/code&gt;), as &lt;code&gt;avin.random&lt;/code&gt; and &lt;code&gt;avin.crypto&lt;/code&gt; each have
a directory; it is a &lt;code&gt;data Uuid(high: long, low: long)&lt;/code&gt; so equality, hashing and sending come from
the structure, with &lt;code&gt;Ord&lt;/code&gt; implemented as the unsigned order of the sixteen bytes. &lt;code&gt;parse&lt;/code&gt; and
&lt;code&gt;fromBytes&lt;/code&gt; answer &lt;code&gt;Option&lt;/code&gt; (the input comes from outside); only the canonical text is accepted,
because braces and &lt;code&gt;urn:uuid:&lt;/code&gt; are other formats, not spellings of this one. The constants are
&lt;code&gt;Uuid.Nil&lt;/code&gt; and &lt;code&gt;Uuid.Max&lt;/code&gt;, PascalCase like &lt;code&gt;Duration.Zero&lt;/code&gt;, not &lt;code&gt;nil&lt;/code&gt;. &lt;code&gt;variant()&lt;/code&gt; answers 2 for
RFC 9562’s layout (the value of its bits &lt;code&gt;10&lt;/code&gt;), 0, 6 and 7 for the others, as other platforms
number them. &lt;code&gt;FromParam&lt;/code&gt; is implemented in &lt;code&gt;avin.net.http&lt;/code&gt;‘s &lt;code&gt;params.avin&lt;/code&gt;, which imports
&lt;code&gt;avin.uuid&lt;/code&gt; (which imports nothing from &lt;code&gt;avin.net&lt;/code&gt;, so no cycle). Review with the user: the
&lt;code&gt;Nil&lt;/code&gt;/&lt;code&gt;Max&lt;/code&gt; spelling and the variant numbering.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;real-bits-normalize&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;real&lt;/code&gt; reaches its
IEEE 754 encodings through &lt;code&gt;toBits -&amp;gt; long&lt;/code&gt;, &lt;code&gt;real.fromBits(bits: long)&lt;/code&gt;, &lt;code&gt;toBits32 -&amp;gt; int&lt;/code&gt; and
&lt;code&gt;real.fromBits32(bits: int)&lt;/code&gt;, and there is still no 32-bit float type&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#real-and-char&quot;&gt;types&lt;/a&gt;).
A binary protocol (PostgreSQL’s &lt;code&gt;float4&lt;/code&gt;/&lt;code&gt;float8&lt;/code&gt;) or file format needs the encodings, and a
program that needs binary32 needs it only at that edge, so the 32-bit forms convert at the
boundary rather than adding a type every arithmetic rule would have to cover. The members are
parameterless accessors and statics, as &lt;code&gt;isNaN&lt;/code&gt; and &lt;code&gt;real.PositiveInfinity&lt;/code&gt; are; the encoding is
signed (&lt;code&gt;long&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;) because there are no unsigned integers, so &lt;code&gt;(-0.0).toBits&lt;/code&gt; is
&lt;code&gt;long.MinValue&lt;/code&gt;. Narrowing is the hardware’s conversion: round to nearest, ties to even,
overflow to an infinity, and a NaN quieted with the top of its payload kept (ARM64 and x86-64
agree), so a signaling binary32 NaN does not survive a round trip; binary64 bits pass unchanged.
Bound to &lt;code&gt;sysl&lt;/code&gt;‘s &lt;code&gt;FloatBits&lt;/code&gt; through four runtime functions (&lt;code&gt;avin.rt.real_to_bits&lt;/code&gt; and its
siblings). Alternatives weighed: a &lt;code&gt;float&lt;/code&gt; type (the size of the language change, for an edge
need); returning &lt;code&gt;Vector[byte]&lt;/code&gt; (every protocol orders bytes its own way, and the integer is what
shifting code wants); names &lt;code&gt;doubleToLongBits&lt;/code&gt;-style (Avin names members by what they answer).
Review with the user: whether &lt;code&gt;toBits32&lt;/code&gt; should trap rather than give an infinity on overflow.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;real-bits-normalize&lt;/code&gt;): &lt;strong&gt;Unicode
normalization is &lt;code&gt;string.normalize(form: NormalizationForm)&lt;/code&gt; and &lt;code&gt;isNormalized(form)&lt;/code&gt;, the forms
&lt;code&gt;Nfc&lt;/code&gt;, &lt;code&gt;Nfd&lt;/code&gt;, &lt;code&gt;Nfkc&lt;/code&gt;, &lt;code&gt;Nfkd&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/types/#normalization&quot;&gt;types&lt;/a&gt;). &lt;code&gt;NormalizationForm&lt;/code&gt; mirrors
&lt;code&gt;sysl.unicode.Form&lt;/code&gt;, so the data is utf8proc’s Unicode 17.0.0, the database &lt;code&gt;char&lt;/code&gt;‘s methods and
&lt;code&gt;avin.regex&lt;/code&gt; already answer from, and no table is generated or carried for it; a mirror’s
variants must have the Sysl names, and &lt;code&gt;Nfc&lt;/code&gt; is also how Avin spells an acronym in a name
(&lt;code&gt;Utf8Error&lt;/code&gt;, &lt;code&gt;TlsStream&lt;/code&gt;), so the brief’s &lt;code&gt;NFC&lt;/code&gt; became &lt;code&gt;Nfc&lt;/code&gt;. A code point unassigned in 17.0.0
is left alone (utf8proc’s &lt;code&gt;STABLE&lt;/code&gt;). A string of ASCII characters only is answered without
crossing into Sysl, since it is in every form; &lt;code&gt;isNormalized&lt;/code&gt; normalizes and compares rather than
using the quick-check property, which utf8proc does not expose. Tested against every line of
&lt;code&gt;NormalizationTest.txt&lt;/code&gt; 17.0.0 (committed as &lt;code&gt;tests/fixtures/unicode/NormalizationTest.txt&lt;/code&gt;,
1 MB with the character-name comments removed; the original’s SHA-256 is in the test) and every
code point its part 1 does not list. Alternatives weighed: variants &lt;code&gt;NFC&lt;/code&gt; … (refused by the
mirror, and against the naming rule); four methods &lt;code&gt;toNfc&lt;/code&gt; … (four names for one operation with
a parameter); a table of Avin’s own (a second copy of the database to keep in step). Review with
the user: the variant spelling &lt;code&gt;Nfc&lt;/code&gt; over &lt;code&gt;NFC&lt;/code&gt;, which every other platform writes in capitals.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-15 (branch &lt;code&gt;real-bits-normalize&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;saslPrep(text) -&amp;gt; Option[string]&lt;/code&gt; in &lt;code&gt;avin.crypto&lt;/code&gt;&lt;/strong&gt;, RFC 4013 over RFC 3454’s tables B.1, C.1.2–C.9, A.1, D.1 and
D.2 (&lt;a href=&quot;/spec/system-library/#avin-crypto&quot;&gt;system library&lt;/a&gt;). It lives beside PBKDF2 and HMAC because
its one use is preparing a SCRAM password. The tables are generated from the RFC’s text by
&lt;code&gt;scripts/stringprep_tables.avin&lt;/code&gt; into &lt;code&gt;library/avin/crypto/stringprep_tables.avin&lt;/code&gt; (8 KB of
hexadecimal runs, decoded on first use into a sorted array searched by halves), since stringprep
fixes them at Unicode 3.2 and the current database would answer differently. Unassigned code
points are prohibited, as for a stored string (RFC 3454 §7), the stricter of the two forms, which
PostgreSQL’s own SASLprep also applies; normalization is the current NFKC, which differs from 3.2’s only for
the few CJK compatibility ideographs Unicode corrected since. U+200B, in both C.1.2 and B.1, is
mapped to a space, the C.1.2 mapping being applied first; the two orders differ only for it.
Prohibition and the bidirectional rule are checked on the normalized string, as RFC 3454 §3
orders the steps, so U+0340 (prohibited) normalizes to U+0300 and is accepted. &lt;code&gt;None&lt;/code&gt; carries no
reason, since a client’s only response is to fall back to the password as written. Alternatives
weighed: &lt;code&gt;Result[string, SaslPrepError]&lt;/code&gt; naming the step that refused (no caller acts on the
reason); an &lt;code&gt;allowUnassigned&lt;/code&gt; flag for the query form (no SCRAM use needs it); a generic
&lt;code&gt;stringprep(profile)&lt;/code&gt; (no second profile is wanted). Review with the user: whether a reason
should be returned after all.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (branch &lt;code&gt;gc-pacing&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;AVIN_GC_PERCENT&lt;/code&gt; paces the
collector&lt;/strong&gt; (&lt;a href=&quot;/compiler/#runtime&quot;&gt;runtime&lt;/a&gt;). After a collection the heap may allocate that
percentage of what survived before it collects again, and never less than the 8 MiB floor; the
default stays 100, so the heap keeps within about twice what is live, as before. The value is
decimal digits; one that is not, or is longer than 15 digits, is ignored; 0 paces by the floor
alone, and anything above 100000 is taken as 100000. Measured on a program keeping 200k small
objects (37 MB live) while discarding ~800 bytes per element: collection time falls from 3.79 s
to 2.06 s at 200 and 1.12 s at 400, for a heap 1.2× and 1.5× as large. The pacing itself was
already proportional to what is live, so the cost per element allocated levels off once the live
heap passes the floor; what remains is that every collection traces the whole live heap (about
30 ns an object) and walks every block the sweep can reach. Alternatives weighed: a larger default
(faster, but a program’s memory would grow with no setting of its own; left for the user); a
library call to set it at run time (no program needs to change it mid-run yet); a floor that
scales (it only matters below 8 MiB live). Review with the user: whether the default should be
above 100, since the collector stops every thread and marks on one, so the trade favours memory
less than it would for a concurrent collector.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-16 (branch &lt;code&gt;read-alloc&lt;/code&gt;): &lt;strong&gt;a stream’s &lt;code&gt;read(max)&lt;/code&gt;
allocates what it answers, not &lt;code&gt;max&lt;/code&gt;.&lt;/strong&gt; A TCP, Unix or split socket read receives into a buffer
the runtime keeps per operating system thread (on its carrier), grown to the largest read asked
for up to 256 KiB, and copies out exactly the bytes that arrived; a read asking for more than
256 KiB answers at most that much, which the contract (“up to &lt;code&gt;max&lt;/code&gt;“) already allows. A TLS read
decrypts into a plaintext array the connection keeps, of &lt;code&gt;max&lt;/code&gt; bytes up to one record’s 16 KiB,
reused while reads ask for the same size and replaced when they do not. The contract and API are
unchanged. Alternatives weighed: asking the kernel how many bytes are readable (&lt;code&gt;FIONREAD&lt;/code&gt;; one
more system call per read, and no binding for it); a buffer kept per stream on the Avin side
(the binding still copies the whole buffer in and out at every call, and an idle server would
hold one per connection); reading ahead into the stream’s buffered bytes (changes what a
select’s descriptor says). Review with the user: the 256 KiB ceiling on one socket read.
Each try at a receive ends its view of the carrier’s buffer before the thread can wait (branch
&lt;code&gt;pool-trap&lt;/code&gt;, 2026-11-17): a view held across a park was let go on whichever carrier the thread
resumed on, changing the buffer’s count there while the buffer’s own carrier used it, which
freed it under other threads (a crash in &lt;code&gt;malloc&lt;/code&gt;, or corrupted bytes, with thousands of threads
reading at once).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;http-date&lt;/code&gt;): &lt;strong&gt;HTTP-dates live in &lt;code&gt;avin.time&lt;/code&gt;
as &lt;code&gt;Instant.toHttpDate()&lt;/code&gt; and &lt;code&gt;parseHttpDate(text[, now])&lt;/code&gt;.&lt;/strong&gt; They sit beside the ISO 8601 text and
parse, share &lt;code&gt;TimeParseError&lt;/code&gt;, and &lt;code&gt;avin.net.http&lt;/code&gt; imports them. Writing is IMF-fixdate only, drops
the fraction toward the earlier second, and traps outside years 0000 to 9999 (the form has four
digits; it matches &lt;code&gt;date(...)&lt;/code&gt; trapping out of range, and no real header value is outside it).
Parsing is exact: a day name that is not the date’s is refused (&lt;code&gt;OutOfRange(text, &amp;quot;weekday&amp;quot;)&lt;/code&gt;), names
and &lt;code&gt;GMT&lt;/code&gt; are case-sensitive as RFC 9110’s ABNF is, widths are fixed, extra whitespace anywhere is
refused, &lt;code&gt;asctime&lt;/code&gt;‘s day under ten must be space-padded, a second of &lt;code&gt;60&lt;/code&gt; is refused as in every
other parse. A two-digit RFC 850 year follows RFC 9110’s fifty-year rule against &lt;code&gt;now&lt;/code&gt;, which is an
argument of the two-argument form so the rule is testable and the one-argument form reads the
clock. Alternatives weighed: a lenient parser ignoring the day name or case (what some servers do;
it accepts corrupt dates and hides client bugs, and a caller can always trim or fold case first);
&lt;code&gt;Option&lt;/code&gt; instead of &lt;code&gt;Result&lt;/code&gt; (every other parse here says why); the format as a method on &lt;code&gt;Zoned&lt;/code&gt;
(an HTTP-date is always UTC, so an &lt;code&gt;Instant&lt;/code&gt; method has no zone to get wrong). Review with the
user: strict weekday and case checking on &lt;code&gt;If-Modified-Since&lt;/code&gt;, where a lenient server would
answer 200 instead of ignoring a malformed date, which RFC 9110 also allows.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;http-date-header&lt;/code&gt;): &lt;strong&gt;&lt;code&gt;http.serve&lt;/code&gt; sends a
&lt;code&gt;Date&lt;/code&gt; header on every response, switched off by &lt;code&gt;date: bool = true&lt;/code&gt;.&lt;/strong&gt; RFC 9110 section 6.6.1
requires it of an origin server with a clock in 2xx, 3xx and 4xx and allows it in 1xx and 5xx; it
is sent on every status the server writes (5xx and its own &lt;code&gt;400&lt;/code&gt;/&lt;code&gt;503&lt;/code&gt; included, since a client or
cache gains from the clock there too) and not on the &lt;code&gt;101&lt;/code&gt; of an upgrade, which the protocol
switched to has its own say on. A &lt;code&gt;Date&lt;/code&gt; the handler set, in any case of the name, is kept, as
&lt;code&gt;Last-Modified&lt;/code&gt; and the like are the handler’s. The text comes from &lt;code&gt;DateHeader(clock = now)&lt;/code&gt;, a
public class so its rollover is testable with a clock of the test’s own: one &lt;code&gt;Atomic&lt;/code&gt; holds the
latest second and its text, a read compares the clock’s second with it, and a thread that finds the
second over formats and stores the next (two threads doing so store equal texts, and a store
racing a later one is corrected by the next read, each answer being right for its own clock
read). Alternatives weighed: a mutex around the text (a lock on every request’s path); a timer
actor refreshing the text (a thread idling in every server, and a stale text if it is starved);
formatting on every response (about a microsecond of calendar arithmetic per request); a
&lt;code&gt;Duration&lt;/code&gt;-valued setting naming a refresh period (the second is what the header can show). The
switch is a bool named &lt;code&gt;date&lt;/code&gt;, as the header is. Tests that read raw heads pass &lt;code&gt;date = false&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Settled on the user’s delegation 2026-11-23 (branch &lt;code&gt;http-cookies&lt;/code&gt;): &lt;strong&gt;cookies in &lt;code&gt;avin.net.http&lt;/code&gt;&lt;/strong&gt;
(&lt;code&gt;Cookie&lt;/code&gt;, &lt;code&gt;SetCookie&lt;/code&gt;, &lt;code&gt;SameSite&lt;/code&gt;, &lt;code&gt;CookieError&lt;/code&gt;; &lt;code&gt;ServerRequest.cookies()&lt;/code&gt;/&lt;code&gt;cookie(name)&lt;/code&gt;,
&lt;code&gt;Response.setCookie&lt;/code&gt;/&lt;code&gt;cookies()&lt;/code&gt;). Choices: (1) reading a &lt;code&gt;Cookie&lt;/code&gt; header is lenient and per pair: a
malformed pair is skipped and the others kept (one bad cookie must not hide the session cookie), with
a value read only if every octet is a RFC 6265 cookie octet (commas and spaces in values are skipped,
not accepted as some servers do); duplicates are all kept in order. (2) Making a &lt;code&gt;SetCookie&lt;/code&gt; traps on
a bad name/value/domain/path, on a broken &lt;code&gt;__Host-&lt;/code&gt;/&lt;code&gt;__Secure-&lt;/code&gt; rule (prefixes compared without
regard to case, as browsers do) and on &lt;code&gt;SameSite=None&lt;/code&gt; or &lt;code&gt;Partitioned&lt;/code&gt; without &lt;code&gt;Secure&lt;/code&gt; — the library’s
convention for a programmer-supplied header value (as &lt;code&gt;withHeader&lt;/code&gt;), nothing escaped or cut; the secure
default is that &lt;code&gt;Secure&lt;/code&gt; is never implied, only demanded. (3) The &lt;code&gt;SameSite&lt;/code&gt; variant for &lt;code&gt;None&lt;/code&gt; is
&lt;code&gt;Unrestricted&lt;/code&gt;, since &lt;code&gt;None&lt;/code&gt; is &lt;code&gt;Option&lt;/code&gt;‘s and would make &lt;code&gt;Some(None)&lt;/code&gt; ambiguous; it is written
&lt;code&gt;SameSite=None&lt;/code&gt;. (4) &lt;code&gt;Max-Age&lt;/code&gt; of zero or less is accepted and written &lt;code&gt;0&lt;/code&gt; (the grammar has no negative
and the meaning is the same). (5) &lt;code&gt;SetCookie.parse&lt;/code&gt; (client) is an &lt;code&gt;Err&lt;/code&gt; for what a browser would
reject (bad name/value, prefix rules, &lt;code&gt;SameSite=None&lt;/code&gt;/&lt;code&gt;Partitioned&lt;/code&gt; without &lt;code&gt;Secure&lt;/code&gt;) and ignores
attributes it cannot read; &lt;code&gt;Expires&lt;/code&gt; is read only as an HTTP-date (via &lt;code&gt;parseHttpDate&lt;/code&gt;), not by RFC
6265’s lenient date algorithm. Alternatives weighed: &lt;code&gt;Result&lt;/code&gt; constructors (a second constructor path
for every cookie a handler writes); quoting values that need it (mangling); treating a pair without
&lt;code&gt;=&lt;/code&gt; as an empty-named cookie (6265bis; no server needs it). A cookie jar (domain/path matching,
expiry, public suffixes) is a later item. Review with the user: strict value octets on &lt;code&gt;Cookie&lt;/code&gt;
(a client sending &lt;code&gt;a=b,c&lt;/code&gt; loses that cookie).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>Debugging</title>
    <link href="https://avinlang.dev/getting-started/debugging/"/>
    <id>https://avinlang.dev/getting-started/debugging/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>`avin build -g`, and stopping a program at a line of its Avin source in lldb.</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;avin build -g&lt;/code&gt; builds a program with debug information: where each piece of its code comes from in
the Avin source, and its functions’ parameters and locals. A debugger such as lldb then stops at a
line of an &lt;code&gt;.avin&lt;/code&gt; file, shows the call stack as the program’s own functions and reads the
variables. On macOS the build also writes &lt;code&gt;&amp;lt;executable&amp;gt;.dSYM&lt;/code&gt; beside the executable, which is where
lldb finds the information; on other systems the executable carries it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;fact(n: int) -&amp;gt; int =
  if n &amp;lt;= 1 then 1
  else n * fact(n - 1)

main() =
  val x = fact(5)
  println(x)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;avin build fact.avin -g -O0
lldb ./fact
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;(lldb) b fact.avin:3
Breakpoint 1: where = fact`&amp;lt;program&amp;gt;.fact + … at fact.avin:3:17
(lldb) run
(lldb) bt
* frame #0: fact`&amp;lt;program&amp;gt;.fact(n=5) at fact.avin:3:17
  frame #1: fact`&amp;lt;program&amp;gt;.main at fact.avin:6:11
  frame #2: fact`main + 56
(lldb) c
(lldb) bt
* frame #0: fact`&amp;lt;program&amp;gt;.fact(n=4) at fact.avin:3:17
  frame #1: fact`&amp;lt;program&amp;gt;.fact(n=5) at fact.avin:3:12
  frame #2: fact`&amp;lt;program&amp;gt;.main at fact.avin:6:11
(lldb) frame variable
(int) n = 4
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What the debugger sees:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Functions&lt;/strong&gt; by their symbols, &lt;code&gt;&amp;lt;program&amp;gt;.fact&lt;/code&gt; for a function of the program’s own module and the
module’s name for the library’s; an instance of a generic function by its type arguments,
&lt;code&gt;&amp;lt;program&amp;gt;.twice[int]&lt;/code&gt;; a lambda as the function it is written in, numbered, &lt;code&gt;&amp;lt;program&amp;gt;.main.lambda#1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lines and columns&lt;/strong&gt; of the source as the reader has it: a literate program’s places are the
lines of its &lt;code&gt;.lavin&lt;/code&gt; document, so &lt;code&gt;b doubling.lavin:12&lt;/code&gt; stops at that line of the document.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Variables&lt;/strong&gt;: every parameter, and every local but one a lambda shares (it lives in a box the
debugger is not shown). &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt; and &lt;code&gt;real&lt;/code&gt; read as numbers,
characters and truth values (lldb names them by its own words, &lt;code&gt;double&lt;/code&gt; for &lt;code&gt;real&lt;/code&gt; and &lt;code&gt;char32_t&lt;/code&gt;
for &lt;code&gt;char&lt;/code&gt;); a string, an object or a function value reads as its address, typed by its Avin type,
&lt;code&gt;(string *) s = 0x…&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;-g&lt;/code&gt; changes nothing about what the program does. It goes with either optimization level, but at
&lt;code&gt;-O2&lt;/code&gt; the optimizer moves and merges code and keeps few variables, as optimized code always does, so
&lt;code&gt;-g -O0&lt;/code&gt; is the build to debug. &lt;code&gt;avin emit-llvm -g&lt;/code&gt; writes the module with its debug metadata, for
reading what the compiler made. &lt;code&gt;-g&lt;/code&gt; is a flag of &lt;code&gt;build&lt;/code&gt; and &lt;code&gt;emit-llvm&lt;/code&gt; only: &lt;code&gt;avin run&lt;/code&gt; and
&lt;code&gt;avin test&lt;/code&gt; build into their own cache and never keep debug information.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Contextual parameters</title>
    <link href="https://avinlang.dev/spec/contextual-parameters/"/>
    <id>https://avinlang.dev/spec/contextual-parameters/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>given values and using parameters carry a context — a transaction, a logger, a request — through the calls that need it, resolved lexically at compile time.</summary>
    <content type="html">&lt;p&gt;Some values belong to the work in progress rather than to any one call: the database transaction a
request runs in, the logger it writes to, the request’s own identity, the clock a test controls.
Every function on the way down needs to pass them on, and most of those functions do nothing else
with them. A &lt;strong&gt;contextual parameter&lt;/strong&gt; is such a value. A function declares it after &lt;code&gt;using&lt;/code&gt;, a
caller declares a &lt;strong&gt;&lt;code&gt;given&lt;/code&gt;&lt;/strong&gt; of its type, and each call finds it without its being written:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import app.db.{Db, Row, Transaction}

insert(row: Row, using tx: Transaction) = tx.execute(&amp;quot;insert into rows values (?, ?)&amp;quot;, row.values)

saveAll(rows: Vector[Row], using tx: Transaction)
  for row in rows do insert(row)

main()
  val db = Db.open(&amp;quot;app.sqlite&amp;quot;)
  given tx = db.begin()
  saveAll(loadRows())
  tx.commit()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;saveAll(loadRows())&lt;/code&gt; passes &lt;code&gt;tx&lt;/code&gt; to &lt;code&gt;saveAll&lt;/code&gt;, and inside &lt;code&gt;saveAll&lt;/code&gt; the parameter &lt;code&gt;tx&lt;/code&gt; is itself a
given, so &lt;code&gt;insert(row)&lt;/code&gt; passes it on. Each filled argument is decided by the checker and compiled as
if it had been written; nothing is looked up at run time.&lt;/p&gt;
&lt;h2 id=&quot;what-givens-are-for&quot;&gt;What givens are for&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;A given is a value of the program’s context, never a conformance.&lt;/strong&gt; Which methods a type has, how
it compares, hashes, displays or encodes, is answered by its &lt;a href=&quot;/spec/declarations/#impl&quot;&gt;impl&lt;/a&gt; and
asked for by a &lt;a href=&quot;/spec/generics/#bounds&quot;&gt;bound&lt;/a&gt;, coherently: one answer per trait and type,
everywhere. Givens do not take part in that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A bound is never met by a given, and a given never changes what a bound finds.&lt;/strong&gt; &lt;code&gt;[T: Ord]&lt;/code&gt;
calls &lt;code&gt;T&lt;/code&gt;‘s own &lt;code&gt;compare&lt;/code&gt;, whatever givens are in scope.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A contextual parameter’s type names no type parameter&lt;/strong&gt;, of its function or of an enclosing
class, trait or impl: &lt;code&gt;using codec: Codec[T]&lt;/code&gt; is an error. Its type is fixed where the function is
declared, so every call resolves it the same way at every instance. What a type parameter needs
of its argument is a bound.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A given has no type parameters.&lt;/strong&gt; A given is a value, and no value in Avin is generic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A given’s type is a type of the program’s own kind&lt;/strong&gt;: a class, an object’s type, a trait used as
a type, a &lt;code&gt;data&lt;/code&gt; type or an &lt;a href=&quot;/spec/declarations/#opaque-types&quot;&gt;opaque type&lt;/a&gt;, with closed type
arguments (&lt;code&gt;Pool[Connection]&lt;/code&gt;). A built-in type, a
tuple, a function type and a union are refused: a given &lt;code&gt;int&lt;/code&gt; would be given wherever any &lt;code&gt;int&lt;/code&gt;
is asked for. A trait that mentions &lt;code&gt;Self&lt;/code&gt; or has static members is a bound and not a type, so it
is no given’s type either.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An ordering other than a type’s natural one is an argument of the one call it belongs to
(&lt;code&gt;sortWith&lt;/code&gt;, &lt;code&gt;sortBy&lt;/code&gt; with &lt;code&gt;Reverse&lt;/code&gt;), not a given: it is a decision about that sort, not part of the
surrounding work.&lt;/p&gt;
&lt;h2 id=&quot;declaring-a-given&quot;&gt;Declaring a given&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;given tx = db.begin()
given log: Logger = FileLogger(&amp;quot;app.log&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;given name = value&lt;/code&gt; declares a &lt;code&gt;val&lt;/code&gt; named &lt;code&gt;name&lt;/code&gt; that is also a given; &lt;code&gt;given name: Type = value&lt;/code&gt;
gives its type, which is then the given’s type. A given is a &lt;code&gt;val&lt;/code&gt;: it is never reassigned, and
mutable context is an object whose own state changes.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every given has a name.&lt;/strong&gt; The name is how a call passes the value explicitly, how a diagnostic
names it, and how another file imports it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A given is declared in a block, at a module’s top level, or in an object’s body.&lt;/strong&gt; In a block it
is in scope from its declaration to the end of the block, as a &lt;code&gt;val&lt;/code&gt; is; at the top level, in
every file of its module; in an object’s body, in that body. A class, actor, trait, impl or
&lt;code&gt;data&lt;/code&gt; body declares none: a class or an actor takes its context as &lt;code&gt;using&lt;/code&gt; parameters of its
constructor (below).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A given is not in scope in its own value&lt;/strong&gt;, so &lt;code&gt;given reqLog = log.child(id)&lt;/code&gt; reads the &lt;code&gt;log&lt;/code&gt;
given of an outer scope.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One scope declares one given of a type.&lt;/strong&gt; A second given of the same type in one block, at one
module’s top level or in one object’s body is an error at the second.&lt;/li&gt;
&lt;li&gt;A module or object given is made when that module’s values or that object are, in the same order.
&lt;code&gt;private&lt;/code&gt; keeps a module’s given to its module.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;given&lt;/code&gt; is a keyword only where it begins a given&lt;/strong&gt;: at the start of a statement in a block, and
where a declaration starts at a module’s top level or in an object’s body, before a name and its
&lt;code&gt;:&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt;. Elsewhere it is an ordinary name, so &lt;code&gt;args.given(&amp;quot;out&amp;quot;)&lt;/code&gt;, &lt;code&gt;given = 3&lt;/code&gt;, a function
&lt;code&gt;given(x)&lt;/code&gt; and a field named &lt;code&gt;given&lt;/code&gt; are unaffected. &lt;code&gt;given&lt;/code&gt; before &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; or a capitalized
name (&lt;code&gt;given Logger(…)&lt;/code&gt;) is reported as a given written without a name of its own or as a &lt;code&gt;var&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;using-parameters&quot;&gt;&lt;code&gt;using&lt;/code&gt; parameters&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;log(message: string, level: Level = Level.Info, using logger: Logger) = logger.write(level, message)

class OrderService(using db: Db, logger: Logger)
  place(o: Order)
    log(s&amp;quot;placing ${o.id}&amp;quot;)
    db.transaction(using tx -&amp;gt; insert(o.row))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;using&lt;/code&gt; marks every parameter after it as contextual. The section comes last in the list, after any
repeated parameter, and each of its parameters has a name and a type (in a lambda, the type may be
inferred). &lt;code&gt;using&lt;/code&gt; is a keyword only where it is followed by a parameter’s name in a parameter list;
a parameter named &lt;code&gt;using&lt;/code&gt; (&lt;code&gt;using: Mode&lt;/code&gt;) is still one.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Functions, methods, static members, extensions’ methods, class constructors and actors’ parameter
lists take a &lt;code&gt;using&lt;/code&gt; section.&lt;/strong&gt; A &lt;code&gt;data&lt;/code&gt; variant, &lt;code&gt;main&lt;/code&gt;, a &lt;code&gt;@test&lt;/code&gt; function or hook, a &lt;code&gt;@sysl&lt;/code&gt; or
&lt;code&gt;@c&lt;/code&gt; binding, and a function with no parameter list take none.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inside the body a contextual parameter is a given&lt;/strong&gt;, at the level of the function’s parameters,
so calls in the body pass it on. A class constructor’s contextual parameters are private fields,
and givens in its field initializers and methods, so they are written without &lt;code&gt;val&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; or
&lt;code&gt;private&lt;/code&gt;; an actor’s are givens in its body and its &lt;code&gt;receive&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A contextual parameter is passed by name, so it has a name, and it is a value already made, so it
is neither by-name (&lt;code&gt;-&amp;gt; T&lt;/code&gt;) nor repeated.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A trait’s method with a &lt;code&gt;using&lt;/code&gt; section is implemented with the same section&lt;/strong&gt;: the same names
and types, in order, as an override takes its method’s parameter types. A call through the
trait’s type or a bound resolves the section where it is written.&lt;/li&gt;
&lt;li&gt;A function written as &lt;a href=&quot;/spec/declarations/#clauses&quot;&gt;clauses&lt;/a&gt; writes its &lt;code&gt;using&lt;/code&gt; section on its
signature line; the clauses match the other parameters, and each clause’s body has the givens,
by name too: &lt;code&gt;describe(n: int, using tx: Tx)&lt;/code&gt; is followed by &lt;code&gt;describe(0) = …&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A contextual parameter may have a &lt;strong&gt;default&lt;/strong&gt;, used where a call finds no given:
&lt;code&gt;now(using clock: Clock = SystemClock) -&amp;gt; Instant&lt;/code&gt;. The default is evaluated where the function is
declared, as every default is, and sees the section’s parameters before it:
&lt;code&gt;using tx: Tx, clock: Clock = Clock(tx.start)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;calls&quot;&gt;Calls&lt;/h2&gt;
&lt;p&gt;A call fills each contextual parameter, in order, from the first of these that answers:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;An argument passed by name&lt;/strong&gt;, &lt;code&gt;insert(row, tx = other)&lt;/code&gt;. A contextual parameter is passed
explicitly only by name; a positional argument never reaches it, and one written for it is an
error saying to name it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The given in the nearest scope&lt;/strong&gt; whose type conforms to the parameter’s (below).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The parameter’s default.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Where none answers, the call is an error. The section takes no part in choosing an overload: the
written arguments choose it, and its contextual parameters are filled afterwards, so a missing given
is an error at the chosen overload, never a reason to choose another. A method with one required
parameter is still &lt;a href=&quot;/spec/operators-and-control-flow/#infix-method-calls&quot;&gt;called infix&lt;/a&gt;, its
section filled the same way.&lt;/p&gt;
&lt;p&gt;Filling an argument from a given evaluates nothing: a given is a value already made. The written
arguments are evaluated in the order written; then the section’s omitted defaults, in order; then
the other omitted parameters’ defaults in parameter order, as before. Every default of an ordinary
parameter sees the parameters before it and the whole section, which is filled first:
&lt;code&gt;level: Level = logger.defaultLevel&lt;/code&gt; before &lt;code&gt;using logger: Logger&lt;/code&gt; is legal.&lt;/p&gt;
&lt;h2 id=&quot;resolution-and-scope&quot;&gt;Resolution and scope&lt;/h2&gt;
&lt;p&gt;A call looks for a given outward from where it is written, level by level, and stops at the first
level holding one that fits:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;the enclosing blocks, innermost first, each with the givens declared before the call, where a
local function’s or a lambda’s contextual parameters are a level between its body and the block
it is written in: nearer than that block, and further than the blocks of its body;&lt;/li&gt;
&lt;li&gt;the contextual parameters of the enclosing function;&lt;/li&gt;
&lt;li&gt;the contextual parameters of the enclosing class’s constructor or actor, for its methods, field
initializers and &lt;code&gt;receive&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the givens of the enclosing object’s body, for its methods and fields;&lt;/li&gt;
&lt;li&gt;the module’s own top-level givens together with the givens the file imports.&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A given fits where its type conforms to the parameter’s type&lt;/strong&gt;, as an argument’s must: a given
&lt;code&gt;FileLogger&lt;/code&gt; fills &lt;code&gt;using logger: Logger&lt;/code&gt;, and a given &lt;code&gt;Logger&lt;/code&gt; does not fill
&lt;code&gt;using file: FileLogger&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The nearer level wins outright.&lt;/strong&gt; A given in a block hides the module’s, whatever their types;
there is no ranking by how specific a type is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two givens that fit at one level make the call an error naming both&lt;/strong&gt;, and the call passes one
by name. Within a block or an object this happens only for two different types conforming to the
parameter’s; at the module level, also for a module’s given and an imported one.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;importing-givens&quot;&gt;Importing givens&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;A file sees another module’s given only by importing it by name&lt;/strong&gt;: &lt;code&gt;import app.clock.{systemClock}&lt;/code&gt;
brings &lt;code&gt;systemClock&lt;/code&gt; in as a value and as a given; &lt;code&gt;import app.clock.systemClock&lt;/code&gt; and an &lt;code&gt;as&lt;/code&gt; rename
do the same, and so does importing it through a module that &lt;a href=&quot;/spec/declarations/#visibility-and-modules&quot;&gt;exports&lt;/a&gt;
it. Importing the module whole, &lt;code&gt;import app.clock&lt;/code&gt;, makes &lt;code&gt;clock.systemClock&lt;/code&gt; readable as a value
but not a given. There is no wildcard import, of givens either. An import is its file’s own: another
file of the module sees the given only by importing it too. A module that exports a given has it as
a given of its own files, as it has every name it exports, and two names that reach one given, by
import or export, are one given. A &lt;code&gt;private&lt;/code&gt; given cannot be imported.&lt;/p&gt;
&lt;p&gt;A given decides, without anything written at the call, which value a function receives, so every
file that relies on one says which in its imports. An extension may be seen through any import of
its module because it can only add a method a call names; a given changes what a call does.&lt;/p&gt;
&lt;h2 id=&quot;lambdas-and-function-values&quot;&gt;Lambdas and function values&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A lambda’s body resolves contextual parameters where the lambda is written&lt;/strong&gt;, as any name in it
is resolved, and a given it fills a call with is captured as any value it reads is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A lambda’s parameters after &lt;code&gt;using&lt;/code&gt; are givens in its body&lt;/strong&gt;: &lt;code&gt;db.transaction(using tx -&amp;gt; insert(row))&lt;/code&gt;, &lt;code&gt;(a, using tx: Transaction) -&amp;gt; …&lt;/code&gt;, and as a trailing lambda,
&lt;code&gt;db.transaction using tx -&amp;gt;&lt;/code&gt; with its body indented below. They are positional parameters of the function value all the same: the lambda’s
type is &lt;code&gt;(Transaction) -&amp;gt; unit&lt;/code&gt;, and whoever calls it passes the transaction.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A function type has no &lt;code&gt;using&lt;/code&gt; section&lt;/strong&gt;, as it has no names and no defaults: a function value is
called with positional arguments only, all of them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A function or method taken as a value has its section filled where it is taken&lt;/strong&gt;:
&lt;code&gt;rows.foreach(insert)&lt;/code&gt; with a given &lt;code&gt;tx&lt;/code&gt; in scope is &lt;code&gt;rows.foreach(row -&amp;gt; insert(row))&lt;/code&gt;, the
transaction captured there. Where none is in scope it is the error a call would be. The value’s
type is the parameters before the section, &lt;code&gt;(Row) -&amp;gt; unit&lt;/code&gt; for &lt;code&gt;insert&lt;/code&gt;, so a value never takes the
section explicitly; a lambda does, &lt;code&gt;(row, tx) -&amp;gt; insert(row, tx = tx)&lt;/code&gt;. A contextual parameter no
given fills takes its default at each call of the value, as the lambda would. A method whose
parameters are all in its section is called with &lt;code&gt;()&lt;/code&gt;, so &lt;code&gt;s.current&lt;/code&gt; is its value only where a
function type is expected.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;generic-code&quot;&gt;Generic code&lt;/h2&gt;
&lt;p&gt;A call with a &lt;code&gt;using&lt;/code&gt; section inside a generic function resolves it where the generic function is
written, once, since the section’s type names no type parameter; each instance passes the same
given. The bounds of the generic function’s type parameters are untouched by givens, and a bounded
call such as &lt;code&gt;T.zero()&lt;/code&gt; finds its member through the bound, as always. Errors are reported at the
generic definition, not at an instantiation.&lt;/p&gt;
&lt;h2 id=&quot;threads-and-actors&quot;&gt;Threads and actors&lt;/h2&gt;
&lt;p&gt;A given is a lexical value, not a thread’s or a task’s: nothing carries it across &lt;code&gt;spawn&lt;/code&gt;, a future
or a message by itself. &lt;strong&gt;A closure that fills a call from a given captures it&lt;/strong&gt;, so a &lt;code&gt;@sendable&lt;/code&gt;
body, a thread’s &lt;code&gt;spawn&lt;/code&gt; and an executor’s task are checked for it exactly as for any captured value,
and a given that is not &lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt; is an error there naming it. An
actor that needs a context takes it as a &lt;code&gt;using&lt;/code&gt; parameter of its declaration, filled where the
actor is made and held to the rules of any actor parameter.&lt;/p&gt;
&lt;h2 id=&quot;diagnostics&quot;&gt;Diagnostics&lt;/h2&gt;
&lt;p&gt;Each error is at the place a reader would change, and says what to write:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;no given&lt;/em&gt;: “&lt;code&gt;insert&lt;/code&gt; needs a &lt;code&gt;Transaction&lt;/code&gt; for &lt;code&gt;tx&lt;/code&gt;, and no given of that type is in scope:
declare one (&lt;code&gt;given tx = …&lt;/code&gt;), take one as &lt;code&gt;using&lt;/code&gt;, import one, or pass &lt;code&gt;tx = …&lt;/code&gt;“. Where a module
the file imports whole declares one, it adds: “&lt;code&gt;app.db&lt;/code&gt; declares the given &lt;code&gt;current&lt;/code&gt;, which this
file does not import: &lt;code&gt;import app.db.{current}&lt;/code&gt;“.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;two givens&lt;/em&gt;: “two givens fit &lt;code&gt;tx: Transaction&lt;/code&gt; of &lt;code&gt;insert&lt;/code&gt; here: &lt;code&gt;primary&lt;/code&gt; (a &lt;code&gt;PgTransaction&lt;/code&gt;,
line 4) and &lt;code&gt;replica&lt;/code&gt; (a &lt;code&gt;LiteTransaction&lt;/code&gt;, line 5); pass &lt;code&gt;tx = …&lt;/code&gt;“.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;a second given of one type&lt;/em&gt;: “&lt;code&gt;replica&lt;/code&gt; is a second given of type &lt;code&gt;Transaction&lt;/code&gt; in this block,
beside &lt;code&gt;primary&lt;/code&gt; (line 4)”.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;positional&lt;/em&gt;: “&lt;code&gt;tx&lt;/code&gt; is a contextual parameter of &lt;code&gt;insert&lt;/code&gt;, passed by name: &lt;code&gt;tx = …&lt;/code&gt;“.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;a type parameter&lt;/em&gt;: “&lt;code&gt;codec: Codec[T]&lt;/code&gt; names the type parameter &lt;code&gt;T&lt;/code&gt;; a contextual parameter’s
type is fixed where its function is declared, and what &lt;code&gt;T&lt;/code&gt; needs is a bound: &lt;code&gt;[T: Codec]&lt;/code&gt;“.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;a built-in type&lt;/em&gt;: “a given is of a class, object, trait or data type: &lt;code&gt;int&lt;/code&gt; would be given
wherever an &lt;code&gt;int&lt;/code&gt; is asked for; give it a type of its own (&lt;code&gt;data Retries(count: int)&lt;/code&gt;)”.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;why-it-is-sound&quot;&gt;Why it is sound&lt;/h2&gt;
&lt;p&gt;Each rule above keeps Avin’s nominal typing and its coherent conformances intact; this is the
reason for each.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Coherence: a given never competes with an impl.&lt;/strong&gt; A trait’s implementation for a type is one
per program, found from the type alone (&lt;code&gt;impl&lt;/code&gt;, &lt;a href=&quot;/spec/declarations/#impl&quot;&gt;declarations&lt;/a&gt;), and a
given cannot replace, shadow or add to it, since no bound ever consults a given. So the classic
incoherence cannot arise: a &lt;code&gt;TreeSet[Person]&lt;/code&gt; built in one file orders by &lt;code&gt;Person&lt;/code&gt;‘s &lt;code&gt;Ord&lt;/code&gt;, and
code in a file with any givens at all that inserts into it, merges it with another set or searches
it orders by that same &lt;code&gt;Ord&lt;/code&gt;; two sets of one type never disagree on their order. Where an order
other than the natural one is wanted, it is a value the structure is built with and keeps (a
comparison function passed to &lt;code&gt;sortWith&lt;/code&gt;, or a key wrapped in &lt;code&gt;Reverse&lt;/code&gt;, whose type is then a
different type with its own &lt;code&gt;Ord&lt;/code&gt;), so the order travels with the value, never with the scope
that happens to use it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Determinism: one answer per call, decided at compile time.&lt;/strong&gt; Resolution is lexical: the levels
are fixed by where the call is written, the nearest level that fits wins, and two fits at one
level are an error rather than a choice. No ranking, no import order and no instantiation affects
it, and a contextual type names no type parameter, so every instance of a generic function
receives what the one checked definition resolved. The same source always fills the same
argument.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nominal matching only.&lt;/strong&gt; A given fits by conformance, and conformance in Avin is declared: a
class’s superclass and &lt;code&gt;:&lt;/code&gt; list, a type’s impls. A given is never matched by the members it
happens to have, and a given’s type is a nominal type of the program (a class, an object, a trait
type, a &lt;code&gt;data&lt;/code&gt; type); the structural types (tuples, function types, unions) and the built-in
types, which carry no intent of their own, are refused, so no value fills a parameter merely
because its shape fits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Checked like a written argument.&lt;/strong&gt; A filled argument is type-checked exactly as the same
argument written at the call would be, against the parameter’s declared type; a default used in
its place is checked where it is declared. There is no unchecked path: nothing is cast, nothing
is looked up by name at run time, and a call that cannot be filled does not compile.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No conversions.&lt;/strong&gt; A given only ever fills a contextual parameter with a value already of a
conforming type. It never changes a value’s type, never makes a method appear on a type and never
makes an expression typecheck that would not with the argument written out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No escape from the sharing rules.&lt;/strong&gt; A given is a &lt;code&gt;val&lt;/code&gt; read where the call is written; a closure
that reads it captures it, and the thread, task and actor checks see that capture as any other. A
non-sendable given cannot reach another thread through a contextual parameter, and a &lt;code&gt;var&lt;/code&gt; is
never a given, so no box is shared by accident.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Visible where it acts.&lt;/strong&gt; A file sees another module’s given only by naming it in its imports, so
adding a given to a library module cannot change what any existing call in another file
receives; at worst a newly named import makes a call ambiguous, which is an error, not a silent
change.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;cost&quot;&gt;Cost&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;At run time, none.&lt;/strong&gt; Every contextual argument is decided by the checker and compiled as a
written argument; a given is a &lt;code&gt;val&lt;/code&gt;. &lt;strong&gt;At compile time, little and bounded:&lt;/strong&gt; each contextual
parameter at a call looks through the levels above, usually a handful, each holding a few givens,
and tests each with the conformance the checker already decides for arguments. Nothing is searched
recursively, no instance is made to find a given, and no choice is retried, since a given has no
type parameters and no contextual parameters of its own to resolve.&lt;/p&gt;
&lt;h2 id=&quot;what-this-does-not-do&quot;&gt;What this does not do&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No implicit conversions.&lt;/strong&gt; A given fills a contextual parameter and nothing else; a value of one
type never becomes another unasked.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No givens that are functions&lt;/strong&gt;, built from other givens on demand, and no chains of them: a given
computed from others is declared with a value that uses them, &lt;code&gt;given reqLog = log.child(id)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No generic givens and no givens for bounds&lt;/strong&gt; (above).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No contextual function types&lt;/strong&gt;: a function value’s type is its positional parameters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No dynamically scoped context&lt;/strong&gt;: what a call receives is decided where it is written.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>Collections</title>
    <link href="https://avinlang.dev/spec/collections/"/>
    <id>https://avinlang.dev/spec/collections/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>A rich collection library with precise result types from first-order generics, where Iterator is Iterable and arrays are ordinary collections.</summary>
    <content type="html">&lt;p&gt;The standard library’s collections are a rich, immutable-by-default family with shared operation
families, written in Avin. Each transformation returns the most precise collection type the caller
can know, and the structure below achieves that with first-order generics alone. The collections
also implement the &lt;a href=&quot;/spec/generics/#functor-applicative-monad-traverse&quot;&gt;standard constructor traits&lt;/a&gt;
through their own methods, so code generic over any &lt;code&gt;Monad&lt;/code&gt; takes them unchanged.&lt;/p&gt;
&lt;h2 id=&quot;hierarchy&quot;&gt;Hierarchy&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Iterable[+A]                 iterator(), and the operation families below
├── Iterator[+A]             single-pass; iterator() returns itself
│   └── BufferedIterator[A]  also peek() at the next element
├── Seq[+A]                  ordered, (Int) -&amp;gt; A
│   ├── List[+A]             immutable linked list
│   ├── Vector[+A]           immutable, persistent tree; the default sequence
│   ├── ArraySeq[+A]         immutable, one array; built once, then read
│   ├── Range[A]             immutable arithmetic progression
│   ├── Array[A]             mutable, fixed length, contiguous
│   ├── Buffer[A]            mutable, growable at the end, contiguous
│   ├── Deque[A]             mutable, growable at both ends
│   └── Queue[+A]            immutable first-in, first-out, two lists
├── LazyList[+T]             immutable, elements computed on demand and remembered
├── PriorityQueue[T]         mutable binary heap, greatest first (avin.collections.mutable)
├── Set[A]                   mutable hash set (avin.collections.mutable)
├── LinkedSet[A]             mutable hash set, in insertion order (avin.collections.mutable)
├── TreeSet[A]               mutable sorted set, by Ord (avin.collections.mutable)
├── BitSet                   mutable set of non-negative ints, as bits (avin.collections.mutable)
├── Map[K, V]                mutable hash map (avin.collections.mutable)
├── LinkedMap[K, V]          mutable hash map, in insertion order (avin.collections.mutable)
├── TreeMap[K, V]            mutable sorted map, by Ord (avin.collections.mutable)
├── Set[A]                   immutable sets, (A) -&amp;gt; bool
│   ├── HashSet[A]           by hash; what {a, b} and Set(...) build
│   ├── SeqSet[A]            in insertion order
│   │   └── OrderedSet[A]    by hash, with the order of first insertion
│   └── SortedSet[A]         in order, with the ordered operations
│       ├── TreeSet[A]       sorted by Ord
│       └── BitSet           SortedSet[int] of non-negative ints, as bits
└── Map[K, +V]               immutable maps, (K) -&amp;gt; V
    ├── HashMap[K, +V]       by hash; what {k: v} and Map(...) build
    ├── SeqMap[K, +V]        in insertion order
    │   └── OrderedMap[K, +V]  by hash, with the order of first insertion
    └── SortedMap[K, +V]     in key order, with the ordered operations
        └── TreeMap[K, +V]   sorted by Ord
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;SeqSet&lt;/code&gt;, &lt;code&gt;SortedSet&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;SeqMap&lt;/code&gt; and &lt;code&gt;SortedMap&lt;/code&gt; are traits; the hash-based, insertion-ordered
and tree collections are the data types that conform to them.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[]T&lt;/code&gt; is shorthand for &lt;code&gt;Vector[T]&lt;/code&gt; in any type position (&lt;code&gt;xs: []int&lt;/code&gt;, &lt;code&gt;[][]int&lt;/code&gt;); see
&lt;a href=&quot;/spec/types/&quot;&gt;types&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The mutable &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;BitSet&lt;/code&gt; variants live in &lt;code&gt;avin.collections.mutable&lt;/code&gt;. &lt;code&gt;Buffer&lt;/code&gt; is the one
growable mutable sequence; code that adds and removes at both ends uses a &lt;code&gt;Deque&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Iterator is Iterable.&lt;/strong&gt; Asking an iterator for its iterator returns the same iterator, at its
current position, and traversing it consumes it. Every other collection returns a fresh iterator each
time. Generic code over &lt;code&gt;Iterable&lt;/code&gt; must therefore not assume it can traverse its input twice. There
is no separate traverse-once supertype.&lt;/p&gt;
&lt;p&gt;An iterator is two methods: &lt;code&gt;hasNext()&lt;/code&gt; says whether an element remains, and &lt;code&gt;next()&lt;/code&gt; yields it and
moves past it. &lt;code&gt;next()&lt;/code&gt; on an iterator with nothing left traps. A class of the program’s own is
iterable by conforming to &lt;code&gt;Iterable[A]&lt;/code&gt; and returning an &lt;code&gt;Iterator[A]&lt;/code&gt; of its own from &lt;code&gt;iterator()&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;operations-without-higher-kinded-types&quot;&gt;Operations without higher-kinded types&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Iterable&lt;/code&gt; declares the operation families: transformation (&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;,
&lt;code&gt;zip&lt;/code&gt;), folds and reductions, predicates and searches, grouping and partitioning, and conversions
(&lt;code&gt;toList&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toArray()&lt;/code&gt;, &lt;code&gt;toSet&lt;/code&gt;, &lt;code&gt;toMap&lt;/code&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A transformation on &lt;code&gt;Iterable&lt;/code&gt; (&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;withFilter&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;, &lt;code&gt;zip&lt;/code&gt;)
returns &lt;code&gt;Iterable[B]&lt;/code&gt;, built in iteration order, so a class of the program’s own that conforms to
&lt;code&gt;Iterable&lt;/code&gt; has every one of them. Each concrete collection keeps its own of the same name and
parameter types with a more precise result type: &lt;code&gt;List.map&lt;/code&gt; returns &lt;code&gt;List[B]&lt;/code&gt;, &lt;code&gt;Set.map&lt;/code&gt; returns
&lt;code&gt;Set[B]&lt;/code&gt;, a sequence’s returns a &lt;code&gt;Vector[B]&lt;/code&gt;, and &lt;code&gt;Iterator.map&lt;/code&gt; returns a lazy &lt;code&gt;Iterator[B]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;They are added by an impl, so the receiver’s static type decides which is called: code that
knows it has a &lt;code&gt;List&lt;/code&gt; gets a &lt;code&gt;List&lt;/code&gt; back, and code that sees only an &lt;code&gt;Iterable&lt;/code&gt; gets an &lt;code&gt;Iterable&lt;/code&gt;,
whatever collection it holds. An impl adding to a trait is passed over where one adding the same
name and parameter types to a trait requiring it applies, so &lt;code&gt;Seq&lt;/code&gt;‘s &lt;code&gt;map&lt;/code&gt; is a sequence’s, not
&lt;code&gt;Iterable&lt;/code&gt;‘s.&lt;/li&gt;
&lt;li&gt;A map’s &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; make a map where their function makes pairs, and otherwise answer the
&lt;code&gt;Iterable&lt;/code&gt; every collection’s would, its results in the map’s iteration order:
&lt;code&gt;counts.map((word, n) -&amp;gt; Summary(word, n))&lt;/code&gt; is a collection of summaries, and
&lt;code&gt;counts.map((word, n) -&amp;gt; (n, word))&lt;/code&gt; a map. The function may take the key and the value or the
entry as one pair, and a &lt;code&gt;for&lt;/code&gt; comprehension over a map, guarded or not, chooses the same way by
what it yields. Every map has this, the sorted, ordered and mutable ones included. The body of a
lambda decides it: where the overloads a call could choose all give a lambda the same parameter
types and differ only in the result they need of it, the lambda is checked once with those
parameters and the call chooses by the type its body gives it
(&lt;a href=&quot;/spec/declarations/#default-and-named-arguments&quot;&gt;overloads&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Every collection’s &lt;code&gt;flatMap&lt;/code&gt;, and every iterator’s, also takes a function answering an &lt;code&gt;Option&lt;/code&gt;,
and keeps the values of those that hold one, in a collection of its own kind:
&lt;code&gt;words.flatMap(_.toIntOption())&lt;/code&gt; is a vector of the numbers, a list’s a list, a set’s a set, and a
map’s a map where the options hold pairs. A collection or an iterator of options has &lt;code&gt;flatten&lt;/code&gt;,
the values they hold (&lt;code&gt;[Some(1), None].flatten&lt;/code&gt; is &lt;code&gt;[1]&lt;/code&gt;). So a &lt;code&gt;for&lt;/code&gt; comprehension may draw from
collections and options alike: &lt;code&gt;for w in words, n in parse(w) yield n&lt;/code&gt; keeps the numbers, guarded
or not, and an option’s &lt;code&gt;flatMap&lt;/code&gt; of a function answering a collection is a &lt;code&gt;Vector&lt;/code&gt; of its
elements, none for &lt;code&gt;None&lt;/code&gt;, so one drawing from an option and then from a collection yields a
vector. An option’s own &lt;code&gt;flatMap&lt;/code&gt; of a function answering an option still answers an option. An
option is not itself an &lt;code&gt;Iterable&lt;/code&gt;: &lt;code&gt;toList&lt;/code&gt; or &lt;code&gt;toVector&lt;/code&gt; makes one where a collection is
needed.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;xs.view()&lt;/code&gt; returns a lazy &lt;code&gt;Iterator&lt;/code&gt;, for pipelines that should not build intermediate
collections (see &lt;a href=&quot;#methods-every-iterable-has&quot;&gt;views&lt;/a&gt; below).&lt;/li&gt;
&lt;li&gt;Operations that need something of the elements are added by impls bounding the element type, so
a collection has them only where its elements do. &lt;code&gt;mkString&lt;/code&gt; joins elements that have &lt;code&gt;Display&lt;/code&gt;
into a string: &lt;code&gt;mkString(sep = &amp;quot;, &amp;quot;)&lt;/code&gt; separates them, &lt;code&gt;mkString(start, sep, end)&lt;/code&gt; also brackets
them, so &lt;code&gt;[1, 2, 3].mkString()&lt;/code&gt; is &lt;code&gt;1, 2, 3&lt;/code&gt; and &lt;code&gt;.mkString(&amp;quot;&amp;lt;&amp;quot;, &amp;quot;|&amp;quot;, &amp;quot;&amp;gt;&amp;quot;)&lt;/code&gt; is &lt;code&gt;&amp;lt;1|2|3&amp;gt;&lt;/code&gt;. Every
collection and iterator has it, through an impl adding it to &lt;code&gt;Iterable&lt;/code&gt;, and a map keeps its own,
whose entries join as &lt;code&gt;key: value&lt;/code&gt;, the form a displayed map shows. &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt; on every
collection of &lt;code&gt;Ord&lt;/code&gt; elements answer the greatest or least, the first of equal ones, and trap when
it is empty; &lt;code&gt;maxOption&lt;/code&gt; and &lt;code&gt;minOption&lt;/code&gt; answer &lt;code&gt;Some&lt;/code&gt; of it, or &lt;code&gt;None&lt;/code&gt;. The free functions &lt;code&gt;max(first, rest*)&lt;/code&gt; and &lt;code&gt;min(first, rest*)&lt;/code&gt; take one value or more, with a
&lt;a href=&quot;/spec/declarations/#repeated-parameters&quot;&gt;repeated&lt;/a&gt; parameter, and answer the greatest or least
itself: &lt;code&gt;max(3, 9, 4)&lt;/code&gt; is &lt;code&gt;9&lt;/code&gt;, &lt;code&gt;min(x, ys*)&lt;/code&gt; the least of &lt;code&gt;x&lt;/code&gt; and the elements of &lt;code&gt;ys&lt;/code&gt;.
&lt;code&gt;sum&lt;/code&gt; and &lt;code&gt;product&lt;/code&gt; are added to &lt;code&gt;Iterable&lt;/code&gt; the same way, so every collection has them, ranges
and sets included, where its elements have &lt;code&gt;Add&lt;/code&gt; or &lt;code&gt;Mul&lt;/code&gt;: they answer the total or the product,
and the identity (&lt;code&gt;T.zero()&lt;/code&gt;, &lt;code&gt;T.one()&lt;/code&gt;) when empty, so &lt;code&gt;[1, 2, 3].sum&lt;/code&gt; is &lt;code&gt;6&lt;/code&gt;, &lt;code&gt;(1..5).product&lt;/code&gt;
is &lt;code&gt;120&lt;/code&gt;, and the &lt;code&gt;sum&lt;/code&gt; of no &lt;code&gt;real&lt;/code&gt;s is &lt;code&gt;0.0&lt;/code&gt; and of no strings is &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;. Overflow traps as &lt;code&gt;+&lt;/code&gt; does,
and strings concatenate in &lt;code&gt;sum&lt;/code&gt; but have no &lt;code&gt;product&lt;/code&gt;.
&lt;code&gt;average&lt;/code&gt; and &lt;code&gt;averageOption&lt;/code&gt; are added for elements that are
&lt;a href=&quot;/spec/generics/#bounds&quot;&gt;&lt;code&gt;Numeric&lt;/code&gt;&lt;/a&gt;: the mean, a &lt;code&gt;real&lt;/code&gt;, with the elements totalled as &lt;code&gt;real&lt;/code&gt;s
through &lt;code&gt;toReal&lt;/code&gt;, so integers whose sum would overflow their type still average
(&lt;code&gt;[i8(127), i8(127)].average&lt;/code&gt; is &lt;code&gt;127.0&lt;/code&gt;). &lt;code&gt;average&lt;/code&gt; traps on an empty collection and
&lt;code&gt;averageOption&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt; for it; &lt;code&gt;[1, 2, 3, 4].average&lt;/code&gt; is &lt;code&gt;2.5&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;collect(pf)&lt;/code&gt; takes a &lt;a href=&quot;/spec/types/#partial-functions&quot;&gt;&lt;code&gt;PartialFunction&lt;/code&gt;&lt;/a&gt; and keeps &lt;code&gt;pf&lt;/code&gt; of each
element it is defined at, in order, in the collection &lt;code&gt;map&lt;/code&gt; would make: &lt;code&gt;shapes.collect(match Circle(r) -&amp;gt; r)&lt;/code&gt; is the radii of the circles. Every collection with &lt;code&gt;map&lt;/code&gt; has it, and so does
&lt;code&gt;Option&lt;/code&gt;. &lt;code&gt;collectFirst(pf)&lt;/code&gt;, on every &lt;code&gt;Iterable&lt;/code&gt;, is &lt;code&gt;Some&lt;/code&gt; of &lt;code&gt;pf&lt;/code&gt; of the first element it is
defined at, or &lt;code&gt;None&lt;/code&gt;, and reaches no element after that one. A &lt;code&gt;Map&lt;/code&gt; collects its entries as
pairs into a &lt;code&gt;Map&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;methods-every-iterable-has&quot;&gt;Methods every Iterable has&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Iterable&lt;/code&gt; itself gives &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt; and their &lt;code&gt;Option&lt;/code&gt; forms, which a sequence and a sorted
collection override to reach the end at once, and &lt;code&gt;foldLeft&lt;/code&gt;, by which every &lt;code&gt;Iterable[A]&lt;/code&gt; is a
&lt;a href=&quot;/spec/generics/#functor-applicative-monad-traverse&quot;&gt;&lt;code&gt;Foldable[A]&lt;/code&gt;&lt;/a&gt; and a list or a vector, overriding
it, walks itself. Impls add the rest to &lt;code&gt;Iterable&lt;/code&gt;, each written once
over &lt;code&gt;iterator()&lt;/code&gt;, so every collection has them:
lists, vectors, arrays, buffers, deques, ranges, sets, maps (whose elements are their entries, as
&lt;code&gt;(key, value)&lt;/code&gt; pairs), the mutable sets and maps, iterators, and a class of the program’s own that
conforms to &lt;code&gt;Iterable&lt;/code&gt;. They visit the elements in iteration order. On an iterator they consume it.
A type with a faster way to answer one keeps its own method of the same name and parameter types,
which is found first wherever the type is known: a list walks itself for &lt;code&gt;find&lt;/code&gt; and the
rest, a set and a range know at once whether they are empty, a vector is its own &lt;code&gt;toVector&lt;/code&gt;.
Collections they make are vectors, maps and sets; n is the number of elements.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A collection’s accessors are &lt;a href=&quot;/spec/declarations/#parameterless-methods&quot;&gt;parameterless methods&lt;/a&gt;&lt;/strong&gt;,
read by name with no parentheses, &lt;code&gt;xs.head&lt;/code&gt;, &lt;code&gt;xs.size&lt;/code&gt;, &lt;code&gt;m.keys&lt;/code&gt;, on every collection and through
&lt;code&gt;Iterable[T]&lt;/code&gt;, &lt;code&gt;Seq[T]&lt;/code&gt;, &lt;code&gt;Map[K, V]&lt;/code&gt; and &lt;code&gt;Set[A]&lt;/code&gt; alike: &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;,
&lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, &lt;code&gt;minOption&lt;/code&gt;,
&lt;code&gt;maxOption&lt;/code&gt;, &lt;code&gt;sum&lt;/code&gt;, &lt;code&gt;product&lt;/code&gt;, &lt;code&gt;average&lt;/code&gt;, &lt;code&gt;averageOption&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;, &lt;code&gt;distinct&lt;/code&gt;, &lt;code&gt;indices&lt;/code&gt;, &lt;code&gt;flatten&lt;/code&gt;, &lt;code&gt;transpose&lt;/code&gt;, &lt;code&gt;unzip&lt;/code&gt;,
&lt;code&gt;zipWithIndex&lt;/code&gt;, &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;keySet&lt;/code&gt;, and the conversions to immutable collections &lt;code&gt;toList&lt;/code&gt;,
&lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toArraySeq&lt;/code&gt;, &lt;code&gt;toSet&lt;/code&gt;, &lt;code&gt;toMap&lt;/code&gt;, &lt;code&gt;toSortedSet&lt;/code&gt; and &lt;code&gt;toSortedMap&lt;/code&gt;; so are &lt;code&gt;sorted&lt;/code&gt;, a
sorted map’s or set’s &lt;code&gt;firstKey&lt;/code&gt; and &lt;code&gt;lastKey&lt;/code&gt;, a mutable tree map’s &lt;code&gt;toTreeMap&lt;/code&gt;, a bit set’s
&lt;code&gt;toBitMask&lt;/code&gt;, and a queue’s &lt;code&gt;front&lt;/code&gt;, &lt;code&gt;frontOption&lt;/code&gt;, &lt;code&gt;dequeue&lt;/code&gt;, &lt;code&gt;dequeueOption&lt;/code&gt; and &lt;code&gt;toQueue&lt;/code&gt;, since
dequeuing an immutable queue answers the element and the rest. Each answers from the
collection without changing it. &lt;strong&gt;What hands out something to change or to use up keeps its
parentheses&lt;/strong&gt;: &lt;code&gt;iterator()&lt;/code&gt;, &lt;code&gt;toArray()&lt;/code&gt; and &lt;code&gt;toBuffer()&lt;/code&gt;, each a fresh mutable object, and an
iterator’s &lt;code&gt;next()&lt;/code&gt; and &lt;code&gt;hasNext()&lt;/code&gt;, a mutable collection’s &lt;code&gt;clear()&lt;/code&gt; and the rest of its changes. A
collection of the program’s own declares the accessors it implements the same way, &lt;code&gt;override length -&amp;gt; int = …&lt;/code&gt;, since the shape is part of the signature; a public &lt;code&gt;val&lt;/code&gt; field implements an abstract
one, as in &lt;code&gt;class Fixed(val length: int): Seq[int]&lt;/code&gt;. An iterator is an &lt;code&gt;Iterable&lt;/code&gt;, so it has the same
parameterless accessors, and on an iterator they read from it: &lt;code&gt;it.head&lt;/code&gt; takes one element, and
&lt;code&gt;it.size&lt;/code&gt; and &lt;code&gt;it.toVector&lt;/code&gt; use it up.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Result&lt;/th&gt;&lt;th&gt;Cost&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;T&lt;/code&gt;, the first and the last in iteration order; trap when empty&lt;/td&gt;&lt;td&gt;&lt;code&gt;head&lt;/code&gt; O(1); &lt;code&gt;last&lt;/code&gt; O(n), O(1) on a sequence or a sorted collection&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; when empty&lt;/td&gt;&lt;td&gt;as &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;foldLeft(initial, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;B&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reduce(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;T&lt;/code&gt;; traps when empty&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reduceOption(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt; when empty&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;foreach(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;unit&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;exists(p)&lt;/code&gt;, &lt;code&gt;forall(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;; stops at the first that decides&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;find(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, the first that satisfies &lt;code&gt;p&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;count(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;minBy(key)&lt;/code&gt;, &lt;code&gt;maxBy(key)&lt;/code&gt; (&lt;code&gt;K: Ord&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;T&lt;/code&gt;, the first of equal keys; traps when empty&lt;/td&gt;&lt;td&gt;O(n), &lt;code&gt;key&lt;/code&gt; once per element&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;minByOption(key)&lt;/code&gt;, &lt;code&gt;maxByOption(key)&lt;/code&gt; (&lt;code&gt;K: Ord&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, the first of equal keys&lt;/td&gt;&lt;td&gt;O(n), &lt;code&gt;key&lt;/code&gt; once per element&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;min&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; (&lt;code&gt;T: Ord&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;T&lt;/code&gt;, the first of equal ones; traps when empty&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;minOption&lt;/code&gt;, &lt;code&gt;maxOption&lt;/code&gt; (&lt;code&gt;T: Ord&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, the first of equal ones&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sum&lt;/code&gt; (&lt;code&gt;T: Add&lt;/code&gt;), &lt;code&gt;product&lt;/code&gt; (&lt;code&gt;T: Mul&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;T&lt;/code&gt;; the identity when empty&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;average&lt;/code&gt; (&lt;code&gt;T: Numeric&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;real&lt;/code&gt;, the mean; traps when empty&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;averageOption&lt;/code&gt; (&lt;code&gt;T: Numeric&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[real]&lt;/code&gt;, the mean, or &lt;code&gt;None&lt;/code&gt; when empty&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;mkString(sep)&lt;/code&gt;, &lt;code&gt;mkString(start, sep, end)&lt;/code&gt; (&lt;code&gt;T: Display&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;partition(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;(Vector[T], Vector[T])&lt;/code&gt;: those that satisfy &lt;code&gt;p&lt;/code&gt;, those that do not&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupBy(key)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Map[K, Vector[T]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupMap(key, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Map[K, Vector[V]]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;groupMapReduce(key, f, combine)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Map[K, V]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toList&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toArray()&lt;/code&gt;, &lt;code&gt;toBuffer()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the collection, in order&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toSet&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Set[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;toMap&lt;/code&gt;, on pairs&lt;/td&gt;&lt;td&gt;&lt;code&gt;Map[K, V]&lt;/code&gt;, a later key’s value replacing&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zipWithIndex&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[(T, int)]&lt;/code&gt;, positions from 0&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;collectFirst(pf)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[B]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scanLeft(initial, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[B]&lt;/code&gt;: &lt;code&gt;initial&lt;/code&gt;, then each partial result of &lt;code&gt;foldLeft(initial, f)&lt;/code&gt;; one more than there are elements&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tapEach(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;, the elements, &lt;code&gt;f&lt;/code&gt; called with each in order before it is answered&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;partitionMap(f)&lt;/code&gt; (&lt;code&gt;f: (T) -&amp;gt; Either[A, B]&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;(Vector[A], Vector[B])&lt;/code&gt;: the values of the &lt;code&gt;Left&lt;/code&gt;s and of the &lt;code&gt;Right&lt;/code&gt;s, each in order&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;span(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;(Vector[T], Vector[T])&lt;/code&gt;: the elements before the first that fails &lt;code&gt;p&lt;/code&gt;, and the rest; &lt;code&gt;p&lt;/code&gt; not called after that&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;grouped(size)&lt;/code&gt;, &lt;code&gt;sliding(size, step = 1)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;, an iterator’s own &lt;code&gt;grouped&lt;/code&gt; and &lt;code&gt;sliding&lt;/code&gt; of the elements; a size or step below 1 traps&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;concat(other)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[W]&lt;/code&gt;, the elements then &lt;code&gt;other&lt;/code&gt;‘s, &lt;code&gt;W&lt;/code&gt; a supertype of both element types&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flatten&lt;/code&gt;, on a collection of collections&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;, their elements in order&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;view()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[T]&lt;/code&gt;, lazy; see below&lt;/td&gt;&lt;td&gt;O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Each group of &lt;code&gt;groupBy&lt;/code&gt; and &lt;code&gt;groupMap&lt;/code&gt; keeps its elements’ order; &lt;code&gt;groupMapReduce&lt;/code&gt; combines a key’s
values in that order, so &lt;code&gt;words.groupMapReduce(w -&amp;gt; w.take(1), w -&amp;gt; 1, (a, b) -&amp;gt; a + b)&lt;/code&gt; counts the
words by their first letter. The map’s own order is its keys’ hashes.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val (small, large) = [5, 12, 3, 40].partition(x -&amp;gt; x &amp;lt; 10)    // [5, 3], [12, 40]
(1..6).groupBy(x -&amp;gt; x % 3)                                     // {0: [3, 6], 1: [1, 4], 2: [2, 5]}
[&amp;quot;b&amp;quot;, &amp;quot;a&amp;quot;].zipWithIndex                                      // [(&amp;quot;b&amp;quot;, 0), (&amp;quot;a&amp;quot;, 1)]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;An iterator’s transformations are lazy.&lt;/strong&gt; &lt;code&gt;Iterator&lt;/code&gt; itself has &lt;code&gt;map(f)&lt;/code&gt;, &lt;code&gt;filter(p)&lt;/code&gt;,
&lt;code&gt;flatMap(f)&lt;/code&gt;, &lt;code&gt;collect(pf)&lt;/code&gt;, &lt;code&gt;take(n)&lt;/code&gt;, &lt;code&gt;drop(n)&lt;/code&gt;, &lt;code&gt;takeWhile(p)&lt;/code&gt;, &lt;code&gt;dropWhile(p)&lt;/code&gt;, &lt;code&gt;zip(other)&lt;/code&gt; with
any collection, and &lt;code&gt;zipWithIndex&lt;/code&gt;, each answering an iterator that reads its source only as far as
its own &lt;code&gt;hasNext()&lt;/code&gt; and &lt;code&gt;next()&lt;/code&gt; ask: &lt;code&gt;it.map(f).take(2).toVector&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt; twice however long &lt;code&gt;it&lt;/code&gt;
is. &lt;code&gt;drop(n)&lt;/code&gt; skips when the first element is asked for, &lt;code&gt;flatMap&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt; on an element only once
the collection made of the one before is used up, &lt;code&gt;zip&lt;/code&gt; ends with the shorter side, and
&lt;code&gt;zipWithIndex&lt;/code&gt; here is an &lt;code&gt;Iterator[(T, int)]&lt;/code&gt; rather than a vector. The new iterator shares its
source, which must not then be read on its own. &lt;code&gt;withFilter(p)&lt;/code&gt; is its &lt;code&gt;filter(p)&lt;/code&gt;, already lazy, so a
comprehension over an iterator is an iterator, read element by element.&lt;/p&gt;
&lt;p&gt;An iterator’s own forms of more of the methods are lazy too, found before the ones every &lt;code&gt;Iterable&lt;/code&gt;
has, which build vectors:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method on &lt;code&gt;Iterator[T]&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Result, an iterator&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;it ++ other&lt;/code&gt;, &lt;code&gt;it.concat(other)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the elements, then &lt;code&gt;other&lt;/code&gt;‘s, whose &lt;code&gt;iterator()&lt;/code&gt; is asked for only once these are used up; &lt;code&gt;Iterator[W]&lt;/code&gt;, &lt;code&gt;W&lt;/code&gt; a supertype of both&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scanLeft(initial, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;initial&lt;/code&gt;, then each partial fold, &lt;code&gt;f&lt;/code&gt; called as each result is read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;grouped(size)&lt;/code&gt;, &lt;code&gt;sliding(size, step = 1)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;, windows as a &lt;a href=&quot;#methods-every-seq-has&quot;&gt;sequence’s&lt;/a&gt; are, each read from the source when it is asked for and no element held beyond it; a size or step below 1 traps at the call&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;distinct&lt;/code&gt;, &lt;code&gt;distinctBy(key)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the elements with each one equal to, or whose key equals, an earlier one’s left out; &lt;code&gt;key&lt;/code&gt; once per element read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zipAll(other, thisElement, thatElement)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;pairs as many as the longer side has, the side that has run out filled&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;padTo(total, element)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the elements, then copies of &lt;code&gt;element&lt;/code&gt; up to &lt;code&gt;total&lt;/code&gt; of them&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tapEach(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the elements, &lt;code&gt;f&lt;/code&gt; called with each as it is read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;buffered()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a &lt;code&gt;BufferedIterator[T]&lt;/code&gt; of the elements&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;flatten&lt;/code&gt;, on an iterator of collections&lt;/td&gt;&lt;td&gt;their elements, each collection read when it is reached&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A &lt;code&gt;BufferedIterator&lt;/code&gt; is an iterator that can look ahead: &lt;code&gt;peek()&lt;/code&gt; is the element &lt;code&gt;next()&lt;/code&gt; would give,
read from the source if it has not been and held until &lt;code&gt;next()&lt;/code&gt; gives it, and traps when none is left;
&lt;code&gt;peekOption()&lt;/code&gt; is &lt;code&gt;Some&lt;/code&gt; of it or &lt;code&gt;None&lt;/code&gt;. Since each lazy form reads only as far as it is asked, an
endless source works with all of them: &lt;code&gt;Iterator.from(1).sliding(2).take(3)&lt;/code&gt; reads four elements.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;object Iterator&lt;/code&gt; makes iterators from a value or a function.&lt;/strong&gt; Each is lazy, computing an element
when it is read; an endless one is used through &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt; and the other methods that stop.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Function&lt;/th&gt;&lt;th&gt;Elements&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.empty[T]()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;none&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.single(x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;x&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.iterate(start, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;start&lt;/code&gt;, &lt;code&gt;f(start)&lt;/code&gt;, &lt;code&gt;f(f(start))&lt;/code&gt;, …, endless, each call of &lt;code&gt;f&lt;/code&gt; made when its result is read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.unfold(state, f)&lt;/code&gt; (&lt;code&gt;f: (S) -&amp;gt; Option[(T, S)]&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;while &lt;code&gt;f(state)&lt;/code&gt; is &lt;code&gt;Some((x, next))&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt;, with &lt;code&gt;next&lt;/code&gt; the state after it; the first &lt;code&gt;None&lt;/code&gt; ends it, and &lt;code&gt;f&lt;/code&gt; is called when another element is asked for&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.continually(element)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the by-name &lt;code&gt;element&lt;/code&gt;, evaluated once for each element read, endless&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.from(start)&lt;/code&gt;, &lt;code&gt;Iterator.from(start, step)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;start&lt;/code&gt;, &lt;code&gt;start + step&lt;/code&gt;, …, endless, of any integer type, &lt;code&gt;step&lt;/code&gt; 1 when left out; an overflowing addition traps only when the element past the type’s limit is read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.fill(count, element)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;count&lt;/code&gt; values of the by-name &lt;code&gt;element&lt;/code&gt;, evaluated as each is read&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Iterator.tabulate(count, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;f(0)&lt;/code&gt;, …, &lt;code&gt;f(count - 1)&lt;/code&gt;, each computed when it is read&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;fill&lt;/code&gt; and &lt;code&gt;tabulate&lt;/code&gt; with a &lt;code&gt;count&lt;/code&gt; that is not positive give no elements.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Iterator.unfold((0, 1), p -&amp;gt; Some((p.0, (p.1, p.0 + p.1)))).take(6).toVector   // [0, 1, 1, 2, 3, 5]
Iterator.from(1).map(x -&amp;gt; x * x).takeWhile(x -&amp;gt; x &amp;lt; 50).toVector              // [1, 4, 9, 16, 25, 36, 49]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;An iterator counts by being used up.&lt;/strong&gt; &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;length&lt;/code&gt; on an &lt;code&gt;Iterator&lt;/code&gt; answer the number of
elements remaining as an &lt;code&gt;int&lt;/code&gt;, found by reading them all: &lt;code&gt;hasNext()&lt;/code&gt; is false afterwards and a second
&lt;code&gt;size&lt;/code&gt; is 0. On an iterator made by &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt; and the rest, the source is read to its end, and
&lt;code&gt;f&lt;/code&gt; or &lt;code&gt;p&lt;/code&gt; is called for each element as in any other traversal. An infinite iterator never returns.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Every &lt;code&gt;Iterable&lt;/code&gt; has &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt; and &lt;code&gt;sizeCompare(n)&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;size&lt;/code&gt; is the number of
elements as an &lt;code&gt;int&lt;/code&gt;: by default it counts them by traversing the iterable, so on an iterator it uses
it up, and a collection that holds its count overrides it to answer at once without consuming. A
sequence has &lt;code&gt;length&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt;, equal; sets, maps (immutable and mutable), &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;,
&lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, &lt;code&gt;Range&lt;/code&gt; and &lt;code&gt;NumericRange&lt;/code&gt; answer from their own count. &lt;code&gt;knownSize&lt;/code&gt; is
the count when it is known without traversing and &lt;code&gt;-1&lt;/code&gt; otherwise: an iterator, a view, a &lt;code&gt;List&lt;/code&gt; (except
the empty one, which is 0) and a program’s own &lt;code&gt;Iterable&lt;/code&gt; that has not overridden it answer &lt;code&gt;-1&lt;/code&gt;, and
&lt;code&gt;size&lt;/code&gt; then counts. Both are overridable members, so the answer through &lt;code&gt;Iterable[T]&lt;/code&gt; is the
collection’s own. &lt;code&gt;xs.sizeCompare(n)&lt;/code&gt; is negative, zero or positive as the count is less than, equal to
or greater than &lt;code&gt;n&lt;/code&gt; (&lt;code&gt;-1&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;), reading at most &lt;code&gt;n&lt;/code&gt; elements of an iterable whose count is not
known. A class that implements &lt;code&gt;Iterable&lt;/code&gt; cannot have a member named &lt;code&gt;size&lt;/code&gt;, &lt;code&gt;knownSize&lt;/code&gt; or
&lt;code&gt;sizeCompare&lt;/code&gt; of its own other than as an &lt;code&gt;override&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A view is an iterator.&lt;/strong&gt; &lt;code&gt;xs.view()&lt;/code&gt;, on every collection, is &lt;code&gt;xs.iterator()&lt;/code&gt; taken as the start of
a lazy pipeline: nothing is computed until the view is read, each element is computed once as it is
read, and no intermediate collection is made. &lt;code&gt;toVector&lt;/code&gt;, &lt;code&gt;toList&lt;/code&gt; and the other conversions, or
any method every &lt;code&gt;Iterable&lt;/code&gt; has, force it. A view is single-pass like any iterator, and it reads its
source as it goes, so a mutable source changed before the view is read is seen changed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;(1..1000000000).view().filter(isPrime).map(x -&amp;gt; x * x).take(3).toList   // reads up to 5
map.view().filter(e -&amp;gt; e.1 &amp;gt; 0).map(e -&amp;gt; e.0).toVector                     // a map&apos;s entries as pairs
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;methods-every-seq-has&quot;&gt;Methods every Seq has&lt;/h2&gt;
&lt;p&gt;Impls add these to &lt;code&gt;Seq&lt;/code&gt;, each written once over &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply(i)&lt;/code&gt; and &lt;code&gt;iterator()&lt;/code&gt;, so every
sequence has them: lists, vectors, &lt;code&gt;ArraySeq&lt;/code&gt;s, ranges, arrays, buffers, deques, and a class of the
program’s own that conforms to &lt;code&gt;Seq&lt;/code&gt; by giving &lt;code&gt;length&lt;/code&gt; and &lt;code&gt;apply(i)&lt;/code&gt;. Through &lt;code&gt;Seq[T]&lt;/code&gt; each one
that makes a sequence makes a &lt;code&gt;Vector&lt;/code&gt;. Each concrete type keeps its own method of the same name and
parameter types where it can answer faster or with its own kind, and that one is found first
wherever the type is known:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A list, a vector and an &lt;code&gt;ArraySeq&lt;/code&gt; answer with their own kind&lt;/strong&gt;: &lt;code&gt;list.takeWhile(p)&lt;/code&gt; is a
&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;vector.drop(2)&lt;/code&gt; a &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;arraySeq.reverse&lt;/code&gt; an &lt;code&gt;ArraySeq&lt;/code&gt;. A list shares what it
can: &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;dropWhile&lt;/code&gt;, &lt;code&gt;takeRight&lt;/code&gt;, the second half of &lt;code&gt;splitAt&lt;/code&gt; and &lt;code&gt;span&lt;/code&gt;, and what follows the
replaced element in &lt;code&gt;updated&lt;/code&gt; are its own tails.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An array, a buffer and a deque keep their own kind for the element-wise methods&lt;/strong&gt;, &lt;code&gt;map&lt;/code&gt;,
&lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt; and &lt;code&gt;filterNot&lt;/code&gt;, each a new collection, and answer the structural
ones with a &lt;code&gt;Vector&lt;/code&gt;, leaving themselves unchanged. Their in-place operations (&lt;code&gt;update&lt;/code&gt;,
&lt;code&gt;sortInPlace&lt;/code&gt;, &lt;code&gt;addOne&lt;/code&gt;, &lt;code&gt;append&lt;/code&gt;, &lt;code&gt;prepend&lt;/code&gt;, &lt;code&gt;insert&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt;) are their own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A range answers with a &lt;code&gt;Vector&lt;/code&gt;&lt;/strong&gt;, since it holds only a progression.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;zip&lt;/code&gt;, &lt;code&gt;zipAll&lt;/code&gt;, &lt;code&gt;scanLeft&lt;/code&gt;, &lt;code&gt;grouped&lt;/code&gt;, &lt;code&gt;sliding&lt;/code&gt; and &lt;code&gt;indices&lt;/code&gt; have one form for every sequence.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;A count is held to the sequence&lt;/strong&gt;: below zero it is zero and past the length it is the length, so
&lt;code&gt;take(-1)&lt;/code&gt; and &lt;code&gt;drop(100)&lt;/code&gt; of three elements are both empty, and &lt;code&gt;splitAt(50)&lt;/code&gt; is everything and
nothing. &lt;strong&gt;An index range is not&lt;/strong&gt;: &lt;code&gt;slice(from, until)&lt;/code&gt; traps unless &lt;code&gt;0 &amp;lt;= from &amp;lt;= until &amp;lt;= length&lt;/code&gt;, as it does on a string and an array, and &lt;code&gt;updated(i, x)&lt;/code&gt; traps where &lt;code&gt;xs(i)&lt;/code&gt; would.
&lt;code&gt;tail&lt;/code&gt; and &lt;code&gt;init&lt;/code&gt; trap on the empty sequence.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;intersect&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt; count as multisets.&lt;/strong&gt; Each occurrence in &lt;code&gt;other&lt;/code&gt; matches the first
unmatched equal element of the receiver: &lt;code&gt;[1, 1, 2].intersect([1, 3])&lt;/code&gt; is &lt;code&gt;[1]&lt;/code&gt; and
&lt;code&gt;[1, 1, 2].diff([1, 3])&lt;/code&gt; is &lt;code&gt;[1, 2]&lt;/code&gt;; what is kept stays in the receiver’s order. Equality is the
elements’ own &lt;code&gt;==&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;n is the length of the receiver, m of the other operand, and k the count or size asked for. The cost
on a vector is O(log₃₂ n) where it says so; elsewhere a vector, an &lt;code&gt;ArraySeq&lt;/code&gt;, an array, a buffer, a
deque and a range answer in the same time as a list, which walks from its front.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding an element widens.&lt;/strong&gt; Through &lt;code&gt;Seq[T]&lt;/code&gt; and on a vector, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;:+&lt;/code&gt;, &lt;code&gt;+:&lt;/code&gt; and &lt;code&gt;updated&lt;/code&gt; take
the element as a type parameter bounded below by &lt;code&gt;T&lt;/code&gt;, so a &lt;code&gt;Vector[Dog]&lt;/code&gt; given a cat answers a
&lt;code&gt;Vector[Animal]&lt;/code&gt;, and a &lt;code&gt;Vector[Animal]&lt;/code&gt; that is a vector of dogs given a cat does the same rather
than make a vector of dogs holding a cat. A vector’s &lt;code&gt;toArray()&lt;/code&gt; is a &lt;code&gt;toArray[W &amp;gt;: T]()&lt;/code&gt; alike, an
array of the type the call asks for.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method&lt;/th&gt;&lt;th&gt;Result through &lt;code&gt;Seq[T]&lt;/code&gt;&lt;/th&gt;&lt;th&gt;Own result&lt;/th&gt;&lt;th&gt;Cost&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;map(f)&lt;/code&gt;, &lt;code&gt;flatMap(f)&lt;/code&gt;, &lt;code&gt;collect(pf)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[U]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;each type’s own kind; a range’s is a vector&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;filter(p)&lt;/code&gt;, &lt;code&gt;filterNot(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;each type’s own kind; a range’s is a vector&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;withFilter(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;lazy, for a guard&lt;/td&gt;&lt;td&gt;each type’s own&lt;/td&gt;&lt;td&gt;O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;take(k)&lt;/code&gt;, &lt;code&gt;drop(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq&lt;/td&gt;&lt;td&gt;list O(k); vector O(log n); ArraySeq O(k) for &lt;code&gt;take&lt;/code&gt;, O(n − k) for &lt;code&gt;drop&lt;/code&gt;; others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;takeRight(k)&lt;/code&gt;, &lt;code&gt;dropRight(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq&lt;/td&gt;&lt;td&gt;vector O(log n); others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;takeWhile(p)&lt;/code&gt;, &lt;code&gt;dropWhile(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, ArraySeq; a vector’s is a vector&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;slice(from, until)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;; traps out of order&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq, Array&lt;/td&gt;&lt;td&gt;vector O(log n); others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;splitAt(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;(Vector[T], Vector[T])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq&lt;/td&gt;&lt;td&gt;vector O(log n); others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;span(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;(Vector[T], Vector[T])&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, ArraySeq; a vector’s are vectors&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;; trap when empty&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq&lt;/td&gt;&lt;td&gt;list &lt;code&gt;tail&lt;/code&gt; O(1); vector O(log n); others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reverse&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, ArraySeq; a vector’s is a vector&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs ++ ys&lt;/code&gt;&lt;/td&gt;&lt;td&gt;a collection of its own kind with element &lt;code&gt;W &amp;gt;: T&lt;/code&gt; (a &lt;code&gt;Vector[W]&lt;/code&gt; for any other sequence), &lt;code&gt;ys&lt;/code&gt; any &lt;code&gt;Iterable[W]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List (shares a list &lt;code&gt;ys&lt;/code&gt;), Vector, ArraySeq&lt;/td&gt;&lt;td&gt;vector O(min(n, m)) for another vector; others O(n + m)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs :+ x&lt;/code&gt;, &lt;code&gt;x +: xs&lt;/code&gt;&lt;/td&gt;&lt;td&gt;its own kind with element &lt;code&gt;W&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt; a &lt;code&gt;W &amp;gt;: T&lt;/code&gt;; so &lt;code&gt;(dogs: List[Dog]) :+ cat&lt;/code&gt; is a &lt;code&gt;List[Animal]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq&lt;/td&gt;&lt;td&gt;list &lt;code&gt;+:&lt;/code&gt; O(1), &lt;code&gt;:+&lt;/code&gt; O(n); vector amortized O(1); others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;updated(i, x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;its own kind with element &lt;code&gt;W&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt; a &lt;code&gt;W &amp;gt;: T&lt;/code&gt;; traps outside&lt;/td&gt;&lt;td&gt;List, Vector, ArraySeq&lt;/td&gt;&lt;td&gt;list O(i); vector O(log n); others O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;padTo(total, x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;List, ArraySeq; a vector’s is a vector&lt;/td&gt;&lt;td&gt;O(max(n, total))&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;distinct&lt;/code&gt;, &lt;code&gt;distinctBy(key)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;, the first of each&lt;/td&gt;&lt;td&gt;List, ArraySeq; a vector’s is a vector&lt;/td&gt;&lt;td&gt;O(n) expected, a hash set&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;intersect(other)&lt;/code&gt;, &lt;code&gt;diff(other)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[T]&lt;/code&gt;, as multisets&lt;/td&gt;&lt;td&gt;List, ArraySeq; a vector’s is a vector&lt;/td&gt;&lt;td&gt;O(n + m) expected, a hash map&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;indices&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Range&lt;/code&gt;, &lt;code&gt;0 ..&amp;lt; length&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(1) after &lt;code&gt;length&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zip(other)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[(T, U)]&lt;/code&gt;, as long as the shorter&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(min(n, m))&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;zipAll(other, thisElement, thatElement)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[(T, U)]&lt;/code&gt;, as long as the longer&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(max(n, m))&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scanLeft(initial, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[B]&lt;/code&gt;: &lt;code&gt;initial&lt;/code&gt; and each partial fold, n + 1&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;grouped(size)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;; the last may be shorter; size &amp;lt; 1 traps&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sliding(size, step = 1)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;; ends with the first window to reach the last element, which may be shorter; size or step &amp;lt; 1 traps&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n) to copy the elements, then O(log n) a window&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;indexOf(x)&lt;/code&gt;, &lt;code&gt;indexWhere(p)&lt;/code&gt;, each also &lt;code&gt;(…, from)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, the first index at or after &lt;code&gt;from&lt;/code&gt;; -1 when none&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lastIndexOf(x)&lt;/code&gt;, &lt;code&gt;lastIndexWhere(p)&lt;/code&gt;, each also &lt;code&gt;(…, end)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, the last index at or before &lt;code&gt;end&lt;/code&gt;; -1 when none&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n), by &lt;code&gt;reverseIterator()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;startsWith(prefix)&lt;/code&gt;, &lt;code&gt;endsWith(suffix)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(m), plus &lt;code&gt;length&lt;/code&gt; for &lt;code&gt;endsWith&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sameElements(other)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;: as many, each equal in order&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(min(n, m))&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;corresponds(other, p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;: as many, and &lt;code&gt;p&lt;/code&gt; holds of each pair&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(min(n, m))&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;indexOfSlice(slice, from = 0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, the first index at or after &lt;code&gt;from&lt;/code&gt; where &lt;code&gt;slice&lt;/code&gt; occurs; -1 when none; an empty &lt;code&gt;slice&lt;/code&gt; occurs at &lt;code&gt;from&lt;/code&gt; while &lt;code&gt;from &amp;lt;= n&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n · m)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;lastIndexOfSlice(slice)&lt;/code&gt;, &lt;code&gt;lastIndexOfSlice(slice, end)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, the last index at or before &lt;code&gt;end&lt;/code&gt; where &lt;code&gt;slice&lt;/code&gt; occurs; -1 when none&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n · m)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;containsSlice(slice)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;; the empty slice is in every sequence&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n · m)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;patch(from, other, replaced)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[W]&lt;/code&gt; (&lt;code&gt;W &amp;gt;: T&lt;/code&gt;): &lt;code&gt;replaced&lt;/code&gt; elements from &lt;code&gt;from&lt;/code&gt; taken out and &lt;code&gt;other&lt;/code&gt; put in; &lt;code&gt;from&lt;/code&gt; held to &lt;code&gt;0 .. n&lt;/code&gt;, &lt;code&gt;replaced&lt;/code&gt; below 0 is 0 and past the end takes the rest&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n + m)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;segmentLength(p, from = 0)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, the run of elements satisfying &lt;code&gt;p&lt;/code&gt; from &lt;code&gt;from&lt;/code&gt; (below 0 is 0)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(run)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;findLast(p)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Option[T]&lt;/code&gt;, by &lt;code&gt;reverseIterator()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;scanRight(initial, f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Vector[B]&lt;/code&gt;: &lt;code&gt;f(x0, f(x1, … initial))&lt;/code&gt; first, &lt;code&gt;initial&lt;/code&gt; last, n + 1&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reduceRight(f)&lt;/code&gt;, &lt;code&gt;reduceRightOption(f)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;f(x0, f(x1, … f(x(n-2), x(n-1))))&lt;/code&gt;; &lt;code&gt;reduceRight&lt;/code&gt; traps when empty, the &lt;code&gt;Option&lt;/code&gt; form answers &lt;code&gt;None&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inits()&lt;/code&gt;, &lt;code&gt;tails()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;: the n + 1 prefixes (longest first, the empty one last) or suffixes (likewise)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n) to copy the elements, then O(log n) a vector&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;combinations(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;: each distinct selection of &lt;code&gt;k&lt;/code&gt; elements once; &lt;code&gt;k&lt;/code&gt; of 0 gives &lt;code&gt;[]&lt;/code&gt; once, &lt;code&gt;k&lt;/code&gt; below 0 or above n none&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(k) a step after an O(n) set-up&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;permutations()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;Iterator[Vector[T]]&lt;/code&gt;: each distinct order of all the elements once; the empty sequence gives &lt;code&gt;[]&lt;/code&gt; once&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(n) a step after an O(n) set-up&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;search(x)&lt;/code&gt;, &lt;code&gt;search(x, from, until)&lt;/code&gt; (&lt;code&gt;T: Ord&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;SearchResult&lt;/code&gt;: &lt;code&gt;Found(i)&lt;/code&gt; or &lt;code&gt;InsertionPoint(i)&lt;/code&gt;, see &lt;a href=&quot;#sorting&quot;&gt;sorting&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(log n) comparisons&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;searchBy(key, wanted)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;SearchResult&lt;/code&gt;, the sequence in ascending order of &lt;code&gt;key&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;O(log n) calls of &lt;code&gt;key&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;On a &lt;code&gt;Seq[Seq[T]]&lt;/code&gt;, &lt;code&gt;transpose&lt;/code&gt; answers the &lt;code&gt;Vector[Vector[T]]&lt;/code&gt; of the columns: the first elements of
the rows, then the seconds, and so on. There are no columns for no rows, and rows that are not all as
long as the first trap. On a &lt;code&gt;Seq[(A, B, C)]&lt;/code&gt;, &lt;code&gt;unzip3()&lt;/code&gt; answers &lt;code&gt;(Vector[A], Vector[B], Vector[C])&lt;/code&gt;
as &lt;code&gt;unzip&lt;/code&gt; answers two.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;combinations&lt;/code&gt; and &lt;code&gt;permutations&lt;/code&gt; are distinct by &lt;code&gt;equals&lt;/code&gt;, and lazy.&lt;/strong&gt; Two elements are one where
&lt;code&gt;==&lt;/code&gt; says so, so &lt;code&gt;[1, 1, 2].combinations(2)&lt;/code&gt; is &lt;code&gt;[1, 1]&lt;/code&gt; and &lt;code&gt;[1, 2]&lt;/code&gt;, and &lt;code&gt;[1, 1, 2].permutations()&lt;/code&gt;
is &lt;code&gt;[1, 1, 2]&lt;/code&gt;, &lt;code&gt;[1, 2, 1]&lt;/code&gt; and &lt;code&gt;[2, 1, 1]&lt;/code&gt;; the elements need no &lt;code&gt;Hash&lt;/code&gt; or &lt;code&gt;Ord&lt;/code&gt;. They come as a
dictionary lists words, the elements ranked by their first appearance in the receiver, and each
vector is made when the iterator is stepped, so the first few of &lt;code&gt;(1 .. 20).permutations()&lt;/code&gt; cost
nothing for the other twenty factorial. The iterator holds the classes of the elements as they were
when it was made, so a buffer that changes afterwards does not change it. A count is the multiset
formula: &lt;code&gt;[a, a, b, b, c].permutations()&lt;/code&gt; has 5! / (2! · 2!) = 30.&lt;/p&gt;
&lt;p&gt;Each also has &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply(i)&lt;/code&gt;, &lt;code&gt;lift(i)&lt;/code&gt; (the element as an &lt;code&gt;Option&lt;/code&gt;), &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt; and
their &lt;code&gt;Option&lt;/code&gt; forms read by index, &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;foldRight&lt;/code&gt;, &lt;code&gt;reverseIterator()&lt;/code&gt;, the sorts
(&lt;a href=&quot;#sorting&quot;&gt;sorting&lt;/a&gt;), &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt;, besides everything an &lt;code&gt;Iterable&lt;/code&gt; has.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[1, 2, 3, 4, 5].sliding(3, 2).toVector     // [[1, 2, 3], [3, 4, 5]]
[1, 2, 3, 4, 5].grouped(2).toVector        // [[1, 2], [3, 4], [5]]
(1 .. 4).scanLeft(0, (s, x) -&amp;gt; s + x)        // [0, 1, 3, 6, 10]
(1 .. 3).scanRight(0, (x, s) -&amp;gt; x + s)       // [6, 5, 3, 0]
[1, 2, 3, 1, 2].indexOfSlice([2, 3])         // 1
[1, 2, 3].patch(1, [9, 9, 9], 1)             // [1, 9, 9, 9, 3]
[1, 2, 3].tails().toVector                 // [[1, 2, 3], [2, 3], [3], []]
[[1, 2, 3], [4, 5, 6]].transpose           // [[1, 4], [2, 5], [3, 6]]
val l: List[int] = [1, 2, 3]
val s: Seq[int] = l
l.takeWhile(x -&amp;gt; x &amp;lt; 3)                      // a List: [1, 2]
s.takeWhile(x -&amp;gt; x &amp;lt; 3)                      // a Vector: [1, 2]
[1, 2, 3].zipAll([&amp;quot;a&amp;quot;], 0, &amp;quot;-&amp;quot;)              // [(1, &amp;quot;a&amp;quot;), (2, &amp;quot;-&amp;quot;), (3, &amp;quot;-&amp;quot;)]
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;builders&quot;&gt;Builders&lt;/h2&gt;
&lt;p&gt;Every collection type has a &lt;strong&gt;builder&lt;/strong&gt;, through one library trait: &lt;code&gt;List.newBuilder[int]()&lt;/code&gt;,
&lt;code&gt;Vector.newBuilder[string]()&lt;/code&gt;, &lt;code&gt;Set.newBuilder[A]()&lt;/code&gt;. A builder takes elements with &lt;code&gt;addOne(x)&lt;/code&gt; and
&lt;code&gt;addAll(xs)&lt;/code&gt;, and &lt;code&gt;result()&lt;/code&gt; hands over the finished collection; the builder is then spent, and using
it again traps until &lt;code&gt;clear()&lt;/code&gt; empties it to build another. Transformations, conversions such as
&lt;code&gt;toList&lt;/code&gt; and collection literals all build through builders, and code that assembles a collection
element by element uses one too. The trait is &lt;code&gt;Builder[-A, +C]&lt;/code&gt;: &lt;code&gt;addOne(element: A)&lt;/code&gt;,
&lt;code&gt;addAll(elements: Iterable[A])&lt;/code&gt;, which adds each in turn unless a builder does better,
&lt;code&gt;result() -&amp;gt; C&lt;/code&gt;, &lt;code&gt;clear()&lt;/code&gt;, which every builder defines and which leaves a collection already handed
over unchanged, &lt;code&gt;sizeHint(size: int)&lt;/code&gt;, a hint that about &lt;code&gt;size&lt;/code&gt; elements are coming, which a builder
over an array uses to make room once and the others ignore, and &lt;code&gt;knownSize -&amp;gt; int&lt;/code&gt;, the number of
elements a builder holds where it knows it cheaply and -1 otherwise. A collection that a literal can
build implements &lt;a href=&quot;#literals&quot;&gt;&lt;code&gt;Buildable&lt;/code&gt;&lt;/a&gt; too, whose static &lt;code&gt;newBuilder()&lt;/code&gt; makes one with the element
type its type arguments give, as &lt;code&gt;T.newBuilder()&lt;/code&gt; does for a &lt;code&gt;T: Buildable[int]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A builder is how an immutable collection is built efficiently without being mutable itself. &lt;code&gt;List&lt;/code&gt;‘s
builder appends in constant time and hands back an ordinary immutable &lt;code&gt;List&lt;/code&gt;, so building a list in
order needs neither a second mutable list type nor a &lt;code&gt;reverse&lt;/code&gt; at the end:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;squares(n: int) -&amp;gt; List[int]
  val b = List.newBuilder[int]()
  for i in 1 .. n do b.addOne(i * i)
  b.result()
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;building-from-another-collection&quot;&gt;Building from another collection&lt;/h3&gt;
&lt;p&gt;Every collection companion, immutable or mutable, has &lt;code&gt;from(xs)&lt;/code&gt;, which takes any &lt;code&gt;Iterable&lt;/code&gt; of the
element type and builds the collection from its elements in iteration order: &lt;code&gt;List.from(1..4)&lt;/code&gt;,
&lt;code&gt;TreeSet.from(words)&lt;/code&gt;, &lt;code&gt;HashMap.from(pairs)&lt;/code&gt;, &lt;code&gt;BitSet.from(ids)&lt;/code&gt;. A map’s &lt;code&gt;from&lt;/code&gt; takes an &lt;code&gt;Iterable&lt;/code&gt; of
&lt;code&gt;(key, value)&lt;/code&gt; pairs, and a later pair’s value replaces an earlier one’s for the same key (an ordered
map keeps the key at its first place). A set holds an element equal to an earlier one once. Sorted
targets take their input in any order, and &lt;code&gt;BitSet.from&lt;/code&gt; traps on a negative element. The result’s
element type may be wider than the source’s where the collection is covariant.&lt;/p&gt;
&lt;p&gt;Beside it, &lt;code&gt;Vector.iterate(start, length, f)&lt;/code&gt; is the vector of &lt;code&gt;start&lt;/code&gt;, &lt;code&gt;f(start)&lt;/code&gt;, &lt;code&gt;f(f(start))&lt;/code&gt; and
so on, &lt;code&gt;length&lt;/code&gt; of them (&lt;code&gt;f&lt;/code&gt; is called &lt;code&gt;length - 1&lt;/code&gt; times, and a length that is not positive gives an
empty vector); &lt;code&gt;Vector.unfold(state, f)&lt;/code&gt; and &lt;code&gt;List.unfold(state, f)&lt;/code&gt; repeat &lt;code&gt;f&lt;/code&gt; from &lt;code&gt;state&lt;/code&gt; while it
answers &lt;code&gt;Some((element, next))&lt;/code&gt;, adding each element, and end at its first &lt;code&gt;None&lt;/code&gt;. Any &lt;code&gt;Iterable&lt;/code&gt; of
ordered elements has &lt;code&gt;toSortedSet&lt;/code&gt;, a &lt;code&gt;TreeSet&lt;/code&gt;, and any &lt;code&gt;Iterable&lt;/code&gt; of pairs with ordered keys has
&lt;code&gt;toSortedMap&lt;/code&gt;, a &lt;code&gt;TreeMap&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;maps-and-sets&quot;&gt;Maps and sets&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Map[K, +V]&lt;/code&gt; and &lt;code&gt;Set[A]&lt;/code&gt; are traits, the immutable maps and sets: a function over &lt;code&gt;Map[string, int]&lt;/code&gt;
takes a &lt;code&gt;HashMap&lt;/code&gt; or a &lt;code&gt;TreeMap&lt;/code&gt;. A map literal &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;, &lt;code&gt;Map((k, v), …)&lt;/code&gt;, &lt;code&gt;Map.empty&lt;/code&gt; and
&lt;code&gt;Map.newBuilder&lt;/code&gt; make a &lt;code&gt;HashMap&lt;/code&gt;, typed as a &lt;code&gt;Map&lt;/code&gt;, and &lt;code&gt;{1, 2}&lt;/code&gt;, &lt;code&gt;Set(…)&lt;/code&gt;, &lt;code&gt;Set.empty&lt;/code&gt; and
&lt;code&gt;Set.newBuilder&lt;/code&gt; a &lt;code&gt;HashSet&lt;/code&gt;, typed as a &lt;code&gt;Set&lt;/code&gt;; &lt;code&gt;HashMap&lt;/code&gt; and &lt;code&gt;HashSet&lt;/code&gt; have companions of their own
for a value typed as the hash-based kind.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;HashMap&lt;/code&gt; and &lt;code&gt;HashSet&lt;/code&gt; find keys by their hash and compare them with &lt;code&gt;==&lt;/code&gt;. Every type has both, so
any type is a key: strings and tuples by value, &lt;code&gt;data&lt;/code&gt; values field by field, class instances by
identity unless their class implements &lt;code&gt;Eq&lt;/code&gt; and &lt;code&gt;Hash&lt;/code&gt;. Each key’s hash is spread over all 64 bits
before it is used, so sequential integers and strings sharing long prefixes do not cluster.&lt;/p&gt;
&lt;p&gt;The immutable maps and sets are persistent: &lt;code&gt;m.updated(k, v)&lt;/code&gt;, &lt;code&gt;m.removed(k)&lt;/code&gt;, &lt;code&gt;s.incl(x)&lt;/code&gt; and
&lt;code&gt;s.excl(x)&lt;/code&gt; return a new collection of the same kind, sharing all but the changed path with the
old one, which is left as it was, even when called through the trait: a &lt;code&gt;TreeMap&lt;/code&gt; held as a &lt;code&gt;Map&lt;/code&gt;
answers a &lt;code&gt;TreeMap&lt;/code&gt;. The same holds for &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;--&lt;/code&gt;, &lt;code&gt;updatedWith&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterKeys&lt;/code&gt;,
&lt;code&gt;transform&lt;/code&gt;, &lt;code&gt;mapValues&lt;/code&gt; and a set’s &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt;. The methods that make keys or
elements of another type, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt;, answer a hash-based collection through the
trait, and the tree collection’s own versions answer a tree collection where its type is known. The
hash-based kinds are hash tries, branching on one bit of the spread hash at a time, so an update
copies a path proportional to the logarithm of the size.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;OrderedMap&lt;/code&gt; and &lt;code&gt;OrderedSet&lt;/code&gt;, the &lt;code&gt;SeqMap&lt;/code&gt; and &lt;code&gt;SeqSet&lt;/code&gt; data types, find keys by hash as the hash-based
kinds do and iterate in the order their keys were first added: &lt;code&gt;OrderedMap((&amp;quot;b&amp;quot;, 1), (&amp;quot;a&amp;quot;, 2))&lt;/code&gt; visits
&lt;code&gt;b&lt;/code&gt; then &lt;code&gt;a&lt;/code&gt;, whatever the hashes. Updating a key already present replaces its value and keeps its
place; a key removed and added again goes to the end. &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;keySet&lt;/code&gt;, the
iterators, &lt;code&gt;display&lt;/code&gt; and &lt;code&gt;toString&lt;/code&gt; all follow that order, and &lt;code&gt;reverseIterator()&lt;/code&gt; visits it backwards.
They are persistent like the others: the entries sit in a vector in insertion order, a removed entry
leaving a gap that is dropped, with the keys renumbered, once the gaps outnumber the entries, so a
lookup, an update or a removal takes time in the logarithm of the size (a compaction costs the size,
paid for by the removals that caused it) and the slots never exceed about twice the entries. Equality
ignores the order: an &lt;code&gt;OrderedMap&lt;/code&gt; equals a &lt;code&gt;HashMap&lt;/code&gt; or &lt;code&gt;TreeMap&lt;/code&gt; of the same entries, an
&lt;code&gt;OrderedSet&lt;/code&gt; equals a &lt;code&gt;HashSet&lt;/code&gt; of the same elements, and equal ones hash alike. Updates through
&lt;code&gt;SeqMap&lt;/code&gt; and &lt;code&gt;SeqSet&lt;/code&gt; answer a &lt;code&gt;SeqMap&lt;/code&gt; or &lt;code&gt;SeqSet&lt;/code&gt;; &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; answer hash-based
collections. A literal &lt;code&gt;{k: v}&lt;/code&gt; or &lt;code&gt;{a, b}&lt;/code&gt; where one of them is expected builds it in the order written.&lt;/p&gt;
&lt;p&gt;A map’s values are covariant, so a method that puts a value in takes any supertype of &lt;code&gt;V&lt;/code&gt;, as
&lt;a href=&quot;/spec/generics/#lower-bounds&quot;&gt;lower bounds&lt;/a&gt; allow: &lt;code&gt;updated[W &amp;gt;: V](key, value: W) -&amp;gt; Map[K, W]&lt;/code&gt;,
&lt;code&gt;++[W &amp;gt;: V]&lt;/code&gt;, &lt;code&gt;updatedWith[W &amp;gt;: V]&lt;/code&gt; and &lt;code&gt;getOrElse[W &amp;gt;: V]&lt;/code&gt;. A &lt;code&gt;Map[string, Cat]&lt;/code&gt; updated with a
&lt;code&gt;Dog&lt;/code&gt; is a &lt;code&gt;Map[string, Animal]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Two maps are equal when they hold the same keys bound to equal values, and two sets when they hold
the same elements, whatever their kinds: a &lt;code&gt;HashMap&lt;/code&gt; equals a &lt;code&gt;TreeMap&lt;/code&gt; of the same entries, through
the traits or &lt;code&gt;Any&lt;/code&gt;. Equal collections hash alike, whatever order they were built in.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;var counts = Map.empty[string, int]()
for w in words do counts = counts.updated(w, counts.getOrElse(w, 0) + 1)
for (word, n) in counts do println(s&amp;quot;$word $n&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;m(k)&lt;/code&gt; reads a value and traps when the key is absent; &lt;code&gt;m.get(k)&lt;/code&gt; returns an &lt;code&gt;Option&lt;/code&gt;, and
&lt;code&gt;m.getOrElse(k, d)&lt;/code&gt; evaluates &lt;code&gt;d&lt;/code&gt; only when the key is absent. A set is a function from elements to
&lt;code&gt;bool&lt;/code&gt;: &lt;code&gt;s(x)&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; when &lt;code&gt;x&lt;/code&gt; is an element of &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; otherwise, &lt;code&gt;s.contains(x)&lt;/code&gt;. Sets have &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt; and &lt;code&gt;subsetOf&lt;/code&gt;, which read
well infix: &lt;code&gt;odds union evens&lt;/code&gt;. Their symbol forms take any collection: &lt;code&gt;s ++ xs&lt;/code&gt; is &lt;code&gt;s&lt;/code&gt; with every
element of &lt;code&gt;xs&lt;/code&gt; in it and &lt;code&gt;s -- xs&lt;/code&gt; is &lt;code&gt;s&lt;/code&gt; without them, an element of &lt;code&gt;xs&lt;/code&gt; that &lt;code&gt;s&lt;/code&gt; lacks being
ignored. The &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt; spellings belong to &lt;code&gt;Add&lt;/code&gt; and &lt;code&gt;Sub&lt;/code&gt;, so a single element goes in with
&lt;code&gt;s.incl(x)&lt;/code&gt; and out with &lt;code&gt;s.excl(x)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An immutable map has the same two forms: &lt;code&gt;m ++ pairs&lt;/code&gt; takes any collection of &lt;code&gt;(key, value)&lt;/code&gt; pairs,
the last pair for a key winning, and &lt;code&gt;m -- keys&lt;/code&gt; takes any collection of keys. &lt;code&gt;m.keys&lt;/code&gt; and
&lt;code&gt;m.values&lt;/code&gt; are vectors in the map’s iteration order, the value at each index belonging to the key at
the same index, and &lt;code&gt;m.keySet&lt;/code&gt; is the set of the keys; &lt;code&gt;keysIterator()&lt;/code&gt; and &lt;code&gt;valuesIterator()&lt;/code&gt; visit
them lazily instead. &lt;code&gt;m.filterKeys(p)&lt;/code&gt; keeps the entries whose key passes, &lt;code&gt;m.transform((k, v) -&amp;gt; w)&lt;/code&gt;
binds each key to a value made from both, and &lt;code&gt;m.updatedWith(k, f)&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt; with &lt;code&gt;m.get(k)&lt;/code&gt; and
binds &lt;code&gt;k&lt;/code&gt; to the &lt;code&gt;Some&lt;/code&gt; it answers or leaves it unbound for &lt;code&gt;None&lt;/code&gt;, so it adds, replaces or removes.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;m.withDefault(f)&lt;/code&gt; and &lt;code&gt;m.withDefaultValue(v)&lt;/code&gt; see a map of any kind with a default for the keys it
does not hold: &lt;code&gt;apply&lt;/code&gt; of an absent key answers &lt;code&gt;f(key)&lt;/code&gt; (or &lt;code&gt;v&lt;/code&gt;) where the map’s own &lt;code&gt;apply&lt;/code&gt; traps,
and the default is never stored. Everything else sees only the real entries: &lt;code&gt;get&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt;,
&lt;code&gt;contains&lt;/code&gt; &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;getOrElse&lt;/code&gt; its own default, and &lt;code&gt;size&lt;/code&gt;, iteration, &lt;code&gt;keys&lt;/code&gt; and &lt;code&gt;keySet&lt;/code&gt; are
those of the wrapped map. &lt;code&gt;updated&lt;/code&gt;, &lt;code&gt;removed&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;--&lt;/code&gt;, &lt;code&gt;updatedWith&lt;/code&gt; and &lt;code&gt;filter&lt;/code&gt; answer a map
with the same default, and &lt;code&gt;transform&lt;/code&gt; and &lt;code&gt;mapValues&lt;/code&gt; the wrapped map’s own, with none. The wrapper
is equal to the map it wraps, and to every map of the same entries whatever its default, and hashes
and displays as it does. A default of a supertype of the values makes a map of that type. The
wrapper is sendable where the map it wraps and &lt;code&gt;v&lt;/code&gt; are, so the function &lt;code&gt;f&lt;/code&gt; is &lt;code&gt;@sendable&lt;/code&gt;, using
only sendable values from around it: a default that counts its calls does so through an &lt;code&gt;Atomic&lt;/code&gt;. A
counter reads &lt;code&gt;val counts = HashMap.empty[string, int]().withDefaultValue(0)&lt;/code&gt; and then
&lt;code&gt;counts.updated(w, counts(w) + 1)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A hash, tree or ordered map’s &lt;code&gt;partition((k, v) -&amp;gt; bool)&lt;/code&gt; answers two maps of its own kind, the
entries that pass and those that do not, each keeping the order of the whole and &lt;code&gt;p&lt;/code&gt; called once per
entry; this holds through &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;SortedMap&lt;/code&gt; and &lt;code&gt;SeqMap&lt;/code&gt; as well, whose &lt;code&gt;partition((k, v) -&amp;gt; bool)&lt;/code&gt;
answers maps of the receiver’s kind (a class implementing &lt;code&gt;Map&lt;/code&gt; inherits a default built on
&lt;code&gt;removed&lt;/code&gt;, and may override it). Likewise &lt;code&gt;partition(p)&lt;/code&gt; of a hash, tree, ordered or bit set answers
two sets of its own kind; held as a &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;partition&lt;/code&gt; is &lt;code&gt;Iterable&lt;/code&gt;‘s and answers vectors, since a
set is not a vector. Given a function of one pair, a map’s &lt;code&gt;partition&lt;/code&gt; is &lt;code&gt;Iterable&lt;/code&gt;‘s and answers
vectors. &lt;code&gt;s.subsets()&lt;/code&gt; visits every subset of a set and &lt;code&gt;s.subsets(k)&lt;/code&gt; those of &lt;code&gt;k&lt;/code&gt; elements, as
iterators that make each subset only when it is asked for: each is a set of the receiver’s kind,
visited by size, the empty set first and the set itself last, and those of one size in the
lexicographic order of their elements’ positions in iteration order. A set of &lt;code&gt;n&lt;/code&gt; elements has &lt;code&gt;2^n&lt;/code&gt;
subsets and &lt;code&gt;C(n, k)&lt;/code&gt; of size &lt;code&gt;k&lt;/code&gt;; &lt;code&gt;subsets(k)&lt;/code&gt; of a &lt;code&gt;k&lt;/code&gt; below 0 or above &lt;code&gt;n&lt;/code&gt; is empty, and the empty
set’s &lt;code&gt;subsets()&lt;/code&gt; is itself alone.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;avin.collections.mutable&lt;/code&gt; holds &lt;code&gt;Map[K, V]&lt;/code&gt; and &lt;code&gt;Set[A]&lt;/code&gt;, invariant, updated in place:
&lt;code&gt;m(k) = v&lt;/code&gt; binds a key, &lt;code&gt;m(k) += 1&lt;/code&gt; updates its value, and &lt;code&gt;remove&lt;/code&gt; answers the value removed as an
&lt;code&gt;Option&lt;/code&gt;. They are open-addressed tables, probed linearly, kept at most two thirds full. A program
importing them alongside the immutable ones renames them:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.collections.mutable.{Map as MutableMap}

val seen = MutableMap[string, int]()
seen(&amp;quot;a&amp;quot;) = 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A mutable set or map changes through its compound-assignment methods, which need no &lt;code&gt;var&lt;/code&gt;: &lt;code&gt;s += x&lt;/code&gt;,
&lt;code&gt;s -= x&lt;/code&gt;, &lt;code&gt;s ++= xs&lt;/code&gt;, &lt;code&gt;s --= xs&lt;/code&gt;, and for a map &lt;code&gt;m += (k, v)&lt;/code&gt;, &lt;code&gt;m -= k&lt;/code&gt;, &lt;code&gt;m ++= pairs&lt;/code&gt;, &lt;code&gt;m --= keys&lt;/code&gt;;
removing what is absent is not an error, and &lt;code&gt;s --= s&lt;/code&gt; empties the set. &lt;code&gt;filterInPlace(p)&lt;/code&gt; removes what fails &lt;code&gt;p&lt;/code&gt;, and a map’s
&lt;code&gt;updateWith(k, f)&lt;/code&gt; does what &lt;code&gt;updatedWith&lt;/code&gt; does, in place, answering the new binding. The methods
that build a collection — &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;mapValues&lt;/code&gt;, &lt;code&gt;transform&lt;/code&gt;, &lt;code&gt;filterKeys&lt;/code&gt; and a
set’s &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt; — answer a new mutable one; a mutable map’s &lt;code&gt;keys&lt;/code&gt; and
&lt;code&gt;values&lt;/code&gt; are vector snapshots and its &lt;code&gt;keySet&lt;/code&gt; an immutable set.&lt;/p&gt;
&lt;p&gt;Iteration visits a map’s entries as &lt;code&gt;(key, value)&lt;/code&gt; pairs in an order the program cannot rely on. For
the immutable collections it depends only on the keys’ hashes, so equal maps iterate alike; for the
mutable ones it is the table’s order.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;avin.collections.mutable&lt;/code&gt; also holds &lt;code&gt;LinkedMap[K, V]&lt;/code&gt; and &lt;code&gt;LinkedSet[A]&lt;/code&gt;, which have everything
&lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; have and iterate in insertion order, oldest first, in &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, the
display and every method that builds a collection (which answers a linked one). Binding a key that
is present replaces its value and leaves it in place; &lt;code&gt;putLast(k, v)&lt;/code&gt; and &lt;code&gt;moveToEnd(k)&lt;/code&gt; make it the
newest, and a key that was removed and bound again is new. &lt;code&gt;headOption&lt;/code&gt; and &lt;code&gt;lastOption&lt;/code&gt; answer
the oldest and newest entry, and &lt;code&gt;removeFirst()&lt;/code&gt; and &lt;code&gt;removeLast()&lt;/code&gt; remove and answer one, trapping
when the map is empty, so a least-recently-used cache is a &lt;code&gt;moveToEnd&lt;/code&gt; on each hit and a
&lt;code&gt;removeFirst()&lt;/code&gt; when it is full. A set has the same, with &lt;code&gt;addLast&lt;/code&gt;, &lt;code&gt;moveToEnd&lt;/code&gt;, &lt;code&gt;removeFirst()&lt;/code&gt; and
&lt;code&gt;removeLast()&lt;/code&gt; answering elements. Removing entries while iterating is safe and an entry removed
before the iterator reaches it is not visited; binding new keys while iterating never traps, but
whether the iterator visits them is not defined. Two linked maps, or sets, are equal when they hold
the same entries, whatever order they were bound in.&lt;/p&gt;
&lt;p&gt;Mutable maps and sets, like arrays, compare and hash by their contents at the moment they are
compared; &lt;code&gt;===&lt;/code&gt; tells two of them apart. Every map and set displays in the shape of its literal,
&lt;code&gt;{a: 1, b: 2}&lt;/code&gt; and &lt;code&gt;{1, 2, 3}&lt;/code&gt;, each part in its own &lt;code&gt;Display&lt;/code&gt;, and its &lt;code&gt;Debug&lt;/code&gt; uses the parts’
&lt;code&gt;Debug&lt;/code&gt;, &lt;code&gt;{&amp;quot;a&amp;quot;: 1}&lt;/code&gt;, each where the parts have it; one held as its trait is shown by its own type. An
immutable map has no &lt;code&gt;mkString&lt;/code&gt; of its own: it joins its entries as the pairs they are,
&lt;code&gt;{&amp;quot;a&amp;quot;: 1}.mkString()&lt;/code&gt; is &lt;code&gt;(a, 1)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;sorted-maps-and-sets&quot;&gt;Sorted maps and sets&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;SortedMap[K, +V]&lt;/code&gt; and &lt;code&gt;SortedSet[A]&lt;/code&gt; are traits, a &lt;code&gt;Map&lt;/code&gt; and a &lt;code&gt;Set&lt;/code&gt; kept in order, and &lt;code&gt;TreeMap&lt;/code&gt;
and &lt;code&gt;TreeSet&lt;/code&gt; conform to them. These keep their keys in the order of &lt;code&gt;compare&lt;/code&gt;, so a key must be
&lt;code&gt;Ord&lt;/code&gt;: &lt;code&gt;TreeSet(Point(1, 2))&lt;/code&gt; is an error naming the bound when &lt;code&gt;Point&lt;/code&gt; has no order. They are
persistent like the hash-based kinds, an update copying one path, and they are balanced trees, so a
lookup, an update and each ordered operation below take time in the logarithm of the size.
Iteration, &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;mkString&lt;/code&gt; and the display all visit the keys in
ascending order.&lt;/p&gt;
&lt;p&gt;A sorted map is a &lt;code&gt;Map&lt;/code&gt;, and a sorted set a &lt;code&gt;Set&lt;/code&gt;, so code over &lt;code&gt;Map&lt;/code&gt; or &lt;code&gt;Set&lt;/code&gt; takes either kind. An
update through &lt;code&gt;SortedMap&lt;/code&gt; or &lt;code&gt;SortedSet&lt;/code&gt; answers one, so &lt;code&gt;sorted.updated(k, v).headOption&lt;/code&gt;
type-checks: the sorted traits re-declare &lt;code&gt;updated&lt;/code&gt;, &lt;code&gt;removed&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;--&lt;/code&gt;, &lt;code&gt;updatedWith&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;,
&lt;code&gt;filterKeys&lt;/code&gt;, &lt;code&gt;transform&lt;/code&gt;, &lt;code&gt;mapValues&lt;/code&gt;, a set’s &lt;code&gt;incl&lt;/code&gt;, &lt;code&gt;excl&lt;/code&gt;, &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt; with the sorted
result, and a sorted map’s &lt;code&gt;keySet&lt;/code&gt; is a &lt;code&gt;SortedSet&lt;/code&gt; (a tree map’s a &lt;code&gt;TreeSet&lt;/code&gt;). A tree
collection’s own &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; need the new key to be &lt;code&gt;Ord&lt;/code&gt; and answer a tree
collection; where two entries make the same key, the later one in key order wins.&lt;/p&gt;
&lt;p&gt;The ordered operations, members of &lt;code&gt;SortedMap&lt;/code&gt; and &lt;code&gt;SortedSet&lt;/code&gt;, answering a map’s entries as
&lt;code&gt;(key, value)&lt;/code&gt; pairs:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Operation&lt;/th&gt;&lt;th&gt;Answers&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the least and the greatest entry, as an &lt;code&gt;Option&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the least and the greatest entry; trap when empty&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;firstKey&lt;/code&gt;, &lt;code&gt;lastKey&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the least and the greatest key (of a set, element); trap when empty&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;minAfter(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entry with the least key at least &lt;code&gt;k&lt;/code&gt;, as an &lt;code&gt;Option&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;maxBefore(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entry with the greatest key less than &lt;code&gt;k&lt;/code&gt;, as an &lt;code&gt;Option&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;rangeFrom(low)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entries whose keys are at least &lt;code&gt;low&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;rangeTo(high)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entries whose keys are at most &lt;code&gt;high&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;rangeUntil(high)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entries whose keys are less than &lt;code&gt;high&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;range(low, high)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entries from &lt;code&gt;low&lt;/code&gt; until &lt;code&gt;high&lt;/code&gt;; none when &lt;code&gt;high&lt;/code&gt; is not greater&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;iteratorFrom(k)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entries whose keys are at least &lt;code&gt;k&lt;/code&gt;, in ascending order; a map also has &lt;code&gt;keysIteratorFrom(k)&lt;/code&gt; and &lt;code&gt;valuesIteratorFrom(k)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reverseIterator()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the entries in descending order&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The four slices are collections of the same kind, sharing their structure with the original.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val scores = TreeMap((&amp;quot;cy&amp;quot;, 7), (&amp;quot;al&amp;quot;, 9), (&amp;quot;bo&amp;quot;, 4))
println(scores)                     // {al: 9, bo: 4, cy: 7}
println(scores.range(&amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;))     // {bo: 4}
println(scores.maxBefore(&amp;quot;bz&amp;quot;))     // Some((bo, 4))
println(scores.minAfter(&amp;quot;bo&amp;quot;))      // Some((bo, 4))
val small: TreeSet[int] = {5, 1, 3}
println(small.rangeUntil(4))        // {1, 3}
println(small.rangeTo(3))           // {1, 3}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;TreeMap.empty&lt;/code&gt;, &lt;code&gt;TreeMap.newBuilder&lt;/code&gt; and &lt;code&gt;TreeMap((k, v), …)&lt;/code&gt;, and the same for &lt;code&gt;TreeSet&lt;/code&gt;, make them as
their hash-based counterparts’ companions do, and a set or map literal builds one where one is expected.
&lt;code&gt;SortedMap&lt;/code&gt; and &lt;code&gt;SortedSet&lt;/code&gt; have the same companions, making tree collections typed as the sorted
traits, and a literal where a &lt;code&gt;SortedMap&lt;/code&gt; or &lt;code&gt;SortedSet&lt;/code&gt; is expected builds a tree collection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Mutable sorted maps and sets.&lt;/strong&gt; &lt;code&gt;avin.collections.mutable.TreeMap[K: Ord, V]&lt;/code&gt; and &lt;code&gt;TreeSet[A: Ord]&lt;/code&gt;
are the in-place counterparts, with the whole mutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; API (&lt;code&gt;m(k) = v&lt;/code&gt;, &lt;code&gt;get&lt;/code&gt;,
&lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;getOrElseUpdate&lt;/code&gt;, &lt;code&gt;updateWith&lt;/code&gt;, &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt;, &lt;code&gt;--=&lt;/code&gt;, &lt;code&gt;filterInPlace&lt;/code&gt;, &lt;code&gt;copy()&lt;/code&gt;, and
for a set &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;subsetOf&lt;/code&gt;) and the ordered operations of the table
above: &lt;code&gt;headOption&lt;/code&gt;, &lt;code&gt;lastOption&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;firstKey&lt;/code&gt;, &lt;code&gt;lastKey&lt;/code&gt;, &lt;code&gt;minAfter&lt;/code&gt;,
&lt;code&gt;maxBefore&lt;/code&gt;, &lt;code&gt;reverseIterator()&lt;/code&gt; and the four &lt;code&gt;range&lt;/code&gt; forms. The slices are new mutable collections,
not views. Two operations are their own: &lt;code&gt;removeFirst()&lt;/code&gt; and &lt;code&gt;removeLast()&lt;/code&gt; unbind the least or the
greatest key and answer its entry (a set’s element), trapping when empty, and &lt;code&gt;removeFirstOption()&lt;/code&gt; and
&lt;code&gt;removeLastOption()&lt;/code&gt; answer an &lt;code&gt;Option&lt;/code&gt; instead. A mutable tree collection holds an immutable &lt;code&gt;TreeMap&lt;/code&gt;
or &lt;code&gt;TreeSet&lt;/code&gt; and replaces it at each update, so the cost of every operation is the logarithmic one of
the persistent tree, &lt;code&gt;toTreeMap&lt;/code&gt; and &lt;code&gt;toTreeSet()&lt;/code&gt; hand out the current tree in constant time as a
snapshot later updates do not reach, and an iterator, or a &lt;code&gt;for&lt;/code&gt; loop, goes on over the entries as they
were when it began: updating the collection inside the loop is legal and the loop does not see the
change. Equality and hash follow the contents, and equal an immutable tree collection’s of the same
entries. The two collections of one name are told apart by their modules, the immutable one being
&lt;code&gt;avin.TreeMap&lt;/code&gt; and the mutable one &lt;code&gt;avin.collections.mutable.TreeMap&lt;/code&gt;; where both are used, one is
imported under another name, as for &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.collections.mutable.{TreeMap as MutableTreeMap}

val queue = MutableTreeMap[int, string]()
queue(30) = &amp;quot;c&amp;quot;
queue(10) = &amp;quot;a&amp;quot;
queue(20) = &amp;quot;b&amp;quot;
println(queue.removeFirst()) // (10, a)
println(queue.minAfter(21)) // Some((30, c))
for (k, v) in queue
  queue.remove(k) // the loop still visits both entries
println(queue.isEmpty) // true
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;bit-sets&quot;&gt;Bit sets&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;BitSet&lt;/code&gt; is an immutable &lt;code&gt;SortedSet[int]&lt;/code&gt; that holds its elements as bits: element &lt;code&gt;e&lt;/code&gt; is bit &lt;code&gt;e % 64&lt;/code&gt;
of word &lt;code&gt;e / 64&lt;/code&gt;. Membership takes constant time, &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;symmetricDiff&lt;/code&gt; and
&lt;code&gt;subsetOf&lt;/code&gt; work a word, 64 elements, at a time, and it takes a word for each 64 of its greatest
element, so it suits a dense run of small numbers rather than a few large ones. It has every
operation of a &lt;code&gt;SortedSet&lt;/code&gt;, and an update answers a &lt;code&gt;BitSet&lt;/code&gt; that copies the words it changes and
leaves the old set as it was. It is equal to any set of the same elements, a &lt;code&gt;TreeSet&lt;/code&gt; or a &lt;code&gt;HashSet&lt;/code&gt;
included, and hashes as they do. &lt;code&gt;BitSet(3, 1, 2)&lt;/code&gt;, &lt;code&gt;BitSet.empty()&lt;/code&gt; and &lt;code&gt;BitSet.newBuilder()&lt;/code&gt; make
one.&lt;/p&gt;
&lt;p&gt;A negative number is not an element of any &lt;code&gt;BitSet&lt;/code&gt;. &lt;code&gt;contains&lt;/code&gt; of one answers &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;excl&lt;/code&gt; of
one leaves the set as it was, but anything that would put one in traps: &lt;code&gt;incl&lt;/code&gt;, &lt;code&gt;++&lt;/code&gt;, &lt;code&gt;BitSet(…)&lt;/code&gt;
and the builder. &lt;code&gt;minAfter&lt;/code&gt;, &lt;code&gt;maxBefore&lt;/code&gt; and the four slices take any &lt;code&gt;int&lt;/code&gt;, so &lt;code&gt;rangeFrom(-5)&lt;/code&gt; is
the whole set.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;toBitMask&lt;/code&gt; answers the words as a &lt;code&gt;Vector[long]&lt;/code&gt;, the lowest element in bit 0 of the first, with no
empty word at the end (so the empty set’s is &lt;code&gt;[]&lt;/code&gt;), and &lt;code&gt;BitSet.fromBitMask(words)&lt;/code&gt; is its inverse,
accepting empty words at the end.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val s = BitSet(1, 3, 64)
println(s.toBitMask)                  // [10, 1]
println(BitSet.fromBitMask([10, 1]))    // {1, 3, 64}
println(s.rangeFrom(2))                 // {3, 64}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;avin.collections.mutable.BitSet&lt;/code&gt; is the same set changed in place. &lt;code&gt;add(x)&lt;/code&gt; and &lt;code&gt;remove(x)&lt;/code&gt; answer
whether the set changed, &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, &lt;code&gt;++=&lt;/code&gt; and &lt;code&gt;--=&lt;/code&gt; need no &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;addAll(xs)&lt;/code&gt; and &lt;code&gt;filterInPlace(p)&lt;/code&gt;
are as the mutable &lt;code&gt;Set&lt;/code&gt;‘s, and the in-place algebra &lt;code&gt;unionInPlace(other)&lt;/code&gt;, &lt;code&gt;intersectInPlace(other)&lt;/code&gt;,
&lt;code&gt;diffInPlace(other)&lt;/code&gt; and &lt;code&gt;symmetricDiffInPlace(other)&lt;/code&gt; takes another mutable bit set. &lt;code&gt;union&lt;/code&gt;,
&lt;code&gt;intersect&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt; and &lt;code&gt;symmetricDiff&lt;/code&gt; answer new mutable bit sets, &lt;code&gt;toSet&lt;/code&gt; an immutable &lt;code&gt;BitSet&lt;/code&gt;
and &lt;code&gt;BitSet.fromBitMask(words)&lt;/code&gt; builds one from words. A negative element is refused as above, &lt;code&gt;add&lt;/code&gt;
trapping and &lt;code&gt;contains&lt;/code&gt; and &lt;code&gt;remove&lt;/code&gt; answering &lt;code&gt;false&lt;/code&gt;. Iteration is over the elements the set had when
it began, in ascending order. Like the other mutable collections it compares and hashes by its
contents, and an equal immutable set hashes alike.&lt;/p&gt;
&lt;h2 id=&quot;indexing-and-callable-sequences&quot;&gt;Indexing and callable sequences&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;Seq[A]&lt;/code&gt; is a function from index to element: &lt;code&gt;xs(i)&lt;/code&gt; reads an element. Mutable sequences assign
with &lt;code&gt;xs(i) = v&lt;/code&gt;. An index out of bounds traps; &lt;code&gt;xs.lift(i)&lt;/code&gt; returns an &lt;code&gt;Option&lt;/code&gt;. Square brackets
never index; they are for types and literals.&lt;/p&gt;
&lt;h2 id=&quot;collections-as-functions&quot;&gt;Collections as functions&lt;/h2&gt;
&lt;p&gt;A sequence, a set and a map are each a function, by subtyping: a &lt;a href=&quot;/spec/types/#function-types&quot;&gt;function type&lt;/a&gt;
is among their parents, and their &lt;code&gt;apply&lt;/code&gt; is what a call of one as a function runs.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Collection&lt;/th&gt;&lt;th&gt;Is a&lt;/th&gt;&lt;th&gt;&lt;code&gt;c(x)&lt;/code&gt; is&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Seq[T]&lt;/code&gt;: every list, vector, &lt;code&gt;ArraySeq&lt;/code&gt;, range, array, buffer and deque&lt;/td&gt;&lt;td&gt;&lt;code&gt;(int) -&amp;gt; T&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the element at index &lt;code&gt;x&lt;/code&gt;, trapping outside the sequence&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Set[A]&lt;/code&gt;, immutable and mutable&lt;/td&gt;&lt;td&gt;&lt;code&gt;(A) -&amp;gt; bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;whether &lt;code&gt;x&lt;/code&gt; is an element&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Map[K, V]&lt;/code&gt;, immutable and mutable&lt;/td&gt;&lt;td&gt;&lt;code&gt;(K) -&amp;gt; V&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the value bound to &lt;code&gt;x&lt;/code&gt;, trapping when there is none&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;So a collection is passed, stored and called wherever its function type is expected, with no
conversion, and a lambda of the same type may stand beside it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val words = [&amp;quot;zero&amp;quot;, &amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;]
(0 ..&amp;lt; 2).map(words)                 // [zero, one]
val allowed = Set[string]().incl(&amp;quot;one&amp;quot;)
words.filter(allowed)                // [one]
val table = Map[string, int]().updated(&amp;quot;one&amp;quot;, 1)
[&amp;quot;one&amp;quot;, &amp;quot;one&amp;quot;].map(table)            // [1, 1]
val fs: Vector[(int) -&amp;gt; string] = [words, i -&amp;gt; s&amp;quot;#$i&amp;quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Variance holds through the function type: a &lt;code&gt;Vector[Dog]&lt;/code&gt; is an &lt;code&gt;(int) -&amp;gt; Animal&lt;/code&gt;, since &lt;code&gt;Seq&lt;/code&gt; is
covariant in its element and a function in its result, and a &lt;code&gt;Map[string, Dog]&lt;/code&gt; is a
&lt;code&gt;(string) -&amp;gt; Animal&lt;/code&gt;. A set’s element type and a map’s key type are its own, so a &lt;code&gt;Set[int]&lt;/code&gt; is no
&lt;code&gt;(string) -&amp;gt; bool&lt;/code&gt;. A &lt;code&gt;Range&lt;/code&gt; is a &lt;code&gt;Seq[int]&lt;/code&gt;, so it is an &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt;: &lt;code&gt;(0 ..&amp;lt; 100 by 5)(3)&lt;/code&gt; is
&lt;code&gt;15&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;array&quot;&gt;Array&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Array[T]&lt;/code&gt; is an ordinary invariant collection class, implementing &lt;code&gt;Seq[T]&lt;/code&gt;. It is a contiguous,
fixed-length, mutable buffer whose value elements are stored unboxed, so &lt;code&gt;Array[int]&lt;/code&gt; holds &lt;code&gt;int&lt;/code&gt;s and
&lt;code&gt;Array[Point]&lt;/code&gt; holds &lt;code&gt;Point&lt;/code&gt;s inline. It can be created in generic code (&lt;code&gt;Array.fill(n, x)&lt;/code&gt;), compares
by contents, displays its contents, and has identity.&lt;/p&gt;
&lt;p&gt;Avin has no null reference, so an array never holds an element that is not yet a value. Every array
is made with each element set:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val zeros = Array.fill(8, 0) // eight 0s; the value is evaluated once and shared
val squares = Array.tabulate(5, i -&amp;gt; i * i)
val none = Array.empty[string]()
val given = Array(1, 2, 3) // the elements listed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Naming a collection and listing its elements&lt;/strong&gt; makes one of it: &lt;code&gt;Array(1, 2, 3)&lt;/code&gt;, &lt;code&gt;Vector(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;)&lt;/code&gt;,
&lt;code&gt;List(1, 2)&lt;/code&gt;, &lt;code&gt;Buffer(4)&lt;/code&gt;, &lt;code&gt;Deque(1, 2)&lt;/code&gt;, &lt;code&gt;Queue(1, 2)&lt;/code&gt;, &lt;code&gt;ArraySeq(1, 2)&lt;/code&gt;, &lt;code&gt;LazyList(1, 2)&lt;/code&gt;,
&lt;code&gt;Set(1, 2)&lt;/code&gt; and every other sequence and set of the library, the mutable and sorted ones too (&lt;code&gt;HashSet&lt;/code&gt;, &lt;code&gt;SortedSet&lt;/code&gt;, &lt;code&gt;OrderedSet&lt;/code&gt;, &lt;code&gt;LinkedSet&lt;/code&gt;,
mutable &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt;, &lt;code&gt;BitSet&lt;/code&gt;, &lt;code&gt;PriorityQueue&lt;/code&gt;). It is the companion’s &lt;code&gt;apply&lt;/code&gt; taking its
elements as a &lt;a href=&quot;/spec/declarations/#repeated-parameters&quot;&gt;repeated parameter&lt;/a&gt;, so the element type is
inferred from the elements as for any call (&lt;code&gt;Array(1, 2.5)&lt;/code&gt; is an &lt;code&gt;Array[real]&lt;/code&gt;, and elements of two
types that no widening joins are an error), or comes from the expected type
(&lt;code&gt;val xs: Array[long] = Array(1, 2)&lt;/code&gt;) or from type arguments written at the call
(&lt;code&gt;Array[long](1, 2)&lt;/code&gt;); &lt;code&gt;Array()&lt;/code&gt; with none of them is an error, as is any call whose element type
cannot be inferred. &lt;code&gt;Array(xs*)&lt;/code&gt; makes an array of the elements of &lt;code&gt;xs&lt;/code&gt;, and a set made so holds each
equal element once. A map is never made this way: it is written &lt;code&gt;{&amp;quot;k&amp;quot;: 7}&lt;/code&gt;, and &lt;code&gt;Map(&amp;quot;k&amp;quot; -&amp;gt; 7)&lt;/code&gt; is
refused.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt; and &lt;code&gt;ArraySeq&lt;/code&gt; have the same two companions, with the same shapes:
&lt;code&gt;Vector.tabulate(n, f)&lt;/code&gt; calls &lt;code&gt;f&lt;/code&gt; with &lt;code&gt;0 ..&amp;lt; n&lt;/code&gt; in order, and &lt;code&gt;Vector.fill(n, element)&lt;/code&gt; takes
&lt;code&gt;element&lt;/code&gt; by name and evaluates it once for each position, so &lt;code&gt;List.fill(3, Counter(0))&lt;/code&gt; holds three
distinct objects (an &lt;code&gt;Array&lt;/code&gt;‘s &lt;code&gt;fill&lt;/code&gt; shares one value). A length that is not positive gives an empty
collection.&lt;/p&gt;
&lt;p&gt;An array changes in place with &lt;code&gt;reverseInPlace()&lt;/code&gt;, &lt;code&gt;mapInPlace(f)&lt;/code&gt; (&lt;code&gt;f&lt;/code&gt; of each element, in index
order, of the element type), &lt;code&gt;fillInPlace(x)&lt;/code&gt; (every element the one value &lt;code&gt;x&lt;/code&gt;, as &lt;code&gt;Array.fill&lt;/code&gt;
shares it) and &lt;code&gt;copyTo(dest, at, from = 0, count = length - from)&lt;/code&gt;, which copies &lt;code&gt;count&lt;/code&gt; elements
from index &lt;code&gt;from&lt;/code&gt; into &lt;code&gt;dest&lt;/code&gt; from index &lt;code&gt;at&lt;/code&gt;. A range outside either array traps at the call. &lt;code&gt;dest&lt;/code&gt;
may be the array itself with the ranges overlapping, in either direction: the elements land as they
were before the call.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Array[int]()&lt;/code&gt; is an empty array. &lt;code&gt;xs.length&lt;/code&gt; is the length, which never changes; &lt;code&gt;xs.slice(from, until)&lt;/code&gt;
and &lt;code&gt;xs.copy()&lt;/code&gt; make new arrays; &lt;code&gt;xs.lift(i)&lt;/code&gt; is an &lt;code&gt;Option&lt;/code&gt;. &lt;code&gt;xs(i) += 1&lt;/code&gt;, &lt;code&gt;xs(i) := v&lt;/code&gt; and &lt;code&gt;xs(i)++&lt;/code&gt;
work as they do on a variable, evaluating &lt;code&gt;xs&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; once. Because a call with untyped arguments
before &lt;code&gt;=&lt;/code&gt; assigns an element, a local function’s declaration always types its parameters or has
none: &lt;code&gt;f(x) = 1&lt;/code&gt; is the assignment &lt;code&gt;f.update(x, 1)&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;list-and-cons&quot;&gt;List and cons&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;List[A]&lt;/code&gt; is an immutable singly linked list, the collection for recursive code. &lt;code&gt;x :: xs&lt;/code&gt; makes a
new list with &lt;code&gt;x&lt;/code&gt; in front of &lt;code&gt;xs&lt;/code&gt;, sharing &lt;code&gt;xs&lt;/code&gt;, in constant time. The same spelling takes a list
apart in a pattern, and &lt;code&gt;[]&lt;/code&gt; is the empty list:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;sum(xs: List[int]) -&amp;gt; int = xs match
  [] -&amp;gt; 0
  head :: tail -&amp;gt; head + sum(tail)

pairs[A](xs: List[A]) -&amp;gt; List[(A, A)] = xs match
  a :: b :: rest -&amp;gt; (a, b) :: pairs(rest)
  _ -&amp;gt; []
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;::&lt;/code&gt; needs a &lt;code&gt;List&lt;/code&gt; on its right, so a literal there is built as one: in &lt;code&gt;1 :: 2 :: []&lt;/code&gt;, the &lt;code&gt;[]&lt;/code&gt; is
the empty &lt;code&gt;List[int]&lt;/code&gt;. &lt;code&gt;xs(i)&lt;/code&gt; on a list takes time proportional to &lt;code&gt;i&lt;/code&gt;; code that indexes wants a
&lt;code&gt;Vector&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;List&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type of the core library with two variants, &lt;code&gt;Cons(first: T, rest: List[T])&lt;/code&gt; and
&lt;code&gt;Nil&lt;/code&gt;; &lt;code&gt;x :: xs&lt;/code&gt; is &lt;code&gt;Cons(x, xs)&lt;/code&gt; and &lt;code&gt;[]&lt;/code&gt; is &lt;code&gt;Nil&lt;/code&gt;. &lt;code&gt;::&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt; built as a list, and list patterns
always mean the core library’s &lt;code&gt;List&lt;/code&gt;, even where a program declares its own &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Cons&lt;/code&gt; or
&lt;code&gt;Nil&lt;/code&gt;. The element type of &lt;code&gt;x :: xs&lt;/code&gt; is inferred as a call of &lt;code&gt;Cons&lt;/code&gt; infers it, so a &lt;code&gt;Cat&lt;/code&gt; goes in
front of a &lt;code&gt;List[Dog]&lt;/code&gt; where a &lt;code&gt;List[Animal]&lt;/code&gt; is expected.&lt;/p&gt;
&lt;p&gt;Every operation on a list loops over it rather than recursing, so a list of any length is traversed,
transformed, compared and hashed without deepening the stack; a method that yields a list in order,
such as &lt;code&gt;map&lt;/code&gt; or &lt;code&gt;filter&lt;/code&gt;, builds it reversed and turns it around. &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt;
trap on the empty list, and &lt;code&gt;headOption&lt;/code&gt; and &lt;code&gt;lift(i)&lt;/code&gt; return an &lt;code&gt;Option&lt;/code&gt;. Lists compare and hash by
their contents, and order element by element when their elements are ordered, a list ordering
before every longer list it begins.&lt;/p&gt;
&lt;h2 id=&quot;lazylist&quot;&gt;LazyList&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;LazyList[+T]&lt;/code&gt; is an immutable list whose elements are computed when they are first needed and then
kept. It is a chain of cells, each empty or an element with the lazy list of the rest; a cell is
evaluated the first time something reads it, &lt;strong&gt;at most once&lt;/strong&gt;, and every later read, through the
same list, a list made from it or another iterator over it, gives the cell kept. So a lazy list may
be endless, and may be defined by reference to itself:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;sieve(s: LazyList[int]) -&amp;gt; LazyList[int] =
  s.head #:: sieve(s.tail.filter(_ % s.head != 0))

val primes = sieve(LazyList.from(2))

primes.take(5).toVector // [2, 3, 5, 7, 11]
primes(99) // 541, the hundredth prime

lazy val fibs: LazyList[long] = 0 #:: 1 #:: fibs.zip(fibs.tail).map((a, b) -&amp;gt; a + b)

fibs(90) // 2880067194370816120
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Making one.&lt;/strong&gt; &lt;code&gt;LazyList.empty[T]()&lt;/code&gt; is the empty list. &lt;code&gt;head #:: tail&lt;/code&gt; is a list of &lt;code&gt;head&lt;/code&gt; and then
&lt;code&gt;tail&lt;/code&gt;, which is taken &lt;a href=&quot;/spec/by-name/&quot;&gt;by name&lt;/a&gt;: it is evaluated when the list’s second cell is first
read, once, and not at all if that cell never is; &lt;code&gt;head&lt;/code&gt; is evaluated where it is written. &lt;code&gt;#::&lt;/code&gt;
groups to the right, so &lt;code&gt;0 #:: 1 #:: rest&lt;/code&gt; is &lt;code&gt;0 #:: (1 #:: rest)&lt;/code&gt;, and binds as &lt;code&gt;::&lt;/code&gt; does, more
loosely than arithmetic: &lt;code&gt;n + 1 #:: rest&lt;/code&gt; puts &lt;code&gt;n + 1&lt;/code&gt; in front. It is the companion’s
&lt;a href=&quot;/spec/operators-and-control-flow/#a-right-operand-taken-by-name&quot;&gt;operator&lt;/a&gt; &lt;code&gt;LazyList.#::(head, tail)&lt;/code&gt;, the same as &lt;code&gt;LazyList.cons(head, tail)&lt;/code&gt;. &lt;code&gt;x +: xs&lt;/code&gt; puts &lt;code&gt;x&lt;/code&gt; in front of a list already made,
evaluating &lt;code&gt;xs&lt;/code&gt; at once. The companion’s makers have &lt;code&gt;Iterator&lt;/code&gt;‘s names and argument orders, and evaluate
nothing when called: &lt;code&gt;from(start)&lt;/code&gt; and &lt;code&gt;from(start, step)&lt;/code&gt; over any integer type (an addition that
overflows traps only when the cell past the greatest value is read), &lt;code&gt;iterate(start, f)&lt;/code&gt;,
&lt;code&gt;unfold(state, f)&lt;/code&gt;, &lt;code&gt;continually(element)&lt;/code&gt; (by name, evaluated once per cell), &lt;code&gt;fill(count, element)&lt;/code&gt;
and &lt;code&gt;tabulate(count, f)&lt;/code&gt;. &lt;code&gt;xs.toLazyList()&lt;/code&gt; on every &lt;code&gt;Iterable&lt;/code&gt; reads one iterator of it as the cells
are first read; made from an iterator, the list takes the iterator over.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lazy methods&lt;/strong&gt; evaluate nothing when called; each makes a list whose cells read the source’s cells
as they are themselves read: &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterNot&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeWhile&lt;/code&gt;, &lt;code&gt;dropWhile&lt;/code&gt;,
&lt;code&gt;zip&lt;/code&gt; (with another lazy list), &lt;code&gt;zipWithIndex&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; (&lt;code&gt;f&lt;/code&gt; yielding any &lt;code&gt;Iterable&lt;/code&gt;, read through
its iterator) and &lt;code&gt;++&lt;/code&gt;, whose right operand is by name and evaluated only when the cell after the
left’s last is first read. &lt;code&gt;take(n)&lt;/code&gt; never reads the cell after its &lt;code&gt;n&lt;/code&gt;th; &lt;code&gt;takeWhile&lt;/code&gt; reads the
element that ends it and nothing after.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Forcing methods&lt;/strong&gt; evaluate the cells they need: &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt; and &lt;code&gt;headOption&lt;/code&gt; the first
cell, &lt;code&gt;isEmpty&lt;/code&gt; and &lt;code&gt;nonEmpty&lt;/code&gt; the first cell, &lt;code&gt;apply(i)&lt;/code&gt; and &lt;code&gt;lift(i)&lt;/code&gt; the cells up to &lt;code&gt;i&lt;/code&gt; (none
for a negative index), and &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;force()&lt;/code&gt; and every method an &lt;code&gt;Iterable&lt;/code&gt; has (&lt;code&gt;toVector&lt;/code&gt;,
&lt;code&gt;foldLeft&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;, &lt;code&gt;mkString&lt;/code&gt;, &lt;code&gt;sum&lt;/code&gt; and the rest) all of them; on an endless list such a method
does not return. &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt; and an index out of range trap. &lt;code&gt;isEvaluated()&lt;/code&gt; says whether the
first cell has been evaluated, evaluating nothing, and &lt;code&gt;knownSize&lt;/code&gt; is 0 only for a list already seen
to be empty.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Depth.&lt;/strong&gt; Every method that reads many cells reads them in a loop, and so does &lt;code&gt;filter&lt;/code&gt;,
&lt;code&gt;dropWhile&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt; or &lt;code&gt;flatMap&lt;/code&gt; skipping any number of elements to reach the next, so a list of
millions of cells is walked, counted and converted without deepening the stack. Only a pipeline adds
depth: one frame per stage when a cell of its last stage is first read.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Memory.&lt;/strong&gt; Once a cell is evaluated, the expression that computed it is dropped along with
everything it captured, so a list holds its evaluated elements and the expressions of the cells not
yet evaluated. A list whose head nothing holds is collected cell by cell as a &lt;code&gt;for&lt;/code&gt; loop or an
iterator walks it; a method called on a list holds that list for the length of the call.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Threads.&lt;/strong&gt; A lazy list is not &lt;a href=&quot;/spec/threads/&quot;&gt;sendable&lt;/a&gt;: the cells not yet evaluated are functions
that may hold anything, so a thread’s body may not reach one, and each list belongs to the thread
that made it. A cell is evaluated once, as a &lt;a href=&quot;/spec/declarations/#initialization&quot;&gt;&lt;code&gt;lazy val&lt;/code&gt;&lt;/a&gt; is
initialized (without a lock, since only one thread reaches it), and a cell whose evaluation reads that same cell (an empty list joined to itself,
&lt;code&gt;lazy val e: LazyList[int] = LazyList.empty[int]() ++ e&lt;/code&gt;) traps at that read:
&lt;code&gt;avin: trap: a LazyList cell is read while it is being evaluated&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A list that refers to itself is a &lt;code&gt;lazy val&lt;/code&gt;, at module level, in a class or in a block: a module-level &lt;code&gt;val&lt;/code&gt;
initializes before &lt;code&gt;main&lt;/code&gt; and may not need its own value at all, even inside a delayed expression,
so &lt;code&gt;val fibs = 0 #:: fibs&lt;/code&gt; is an error naming &lt;code&gt;fibs&lt;/code&gt; as needed by its own initializer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Display.&lt;/strong&gt; A lazy list’s &lt;code&gt;Display&lt;/code&gt; and &lt;code&gt;Debug&lt;/code&gt; show the elements evaluated so far, in brackets,
and evaluate nothing: &lt;code&gt;[0, 1, 4, 9]&lt;/code&gt; when every cell has been evaluated, &lt;code&gt;[0, 1, …]&lt;/code&gt; when the cell
after 1 has not, &lt;code&gt;[…]&lt;/code&gt; when nothing has.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;LazyList&lt;/code&gt; is an &lt;code&gt;Iterable&lt;/code&gt; and not a &lt;code&gt;Seq&lt;/code&gt;, and &lt;code&gt;::&lt;/code&gt; and list patterns are &lt;code&gt;List&lt;/code&gt;‘s: there is no
&lt;code&gt;head #:: tail&lt;/code&gt; pattern, since a pattern names an extractor by a word and only &lt;code&gt;::&lt;/code&gt; is written between
its parts. A lazy list is taken apart with &lt;code&gt;headOption&lt;/code&gt; and &lt;code&gt;tail&lt;/code&gt;, or with &lt;code&gt;head&lt;/code&gt; after
&lt;code&gt;isEmpty&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;sequence-patterns&quot;&gt;Sequence patterns&lt;/h2&gt;
&lt;p&gt;A sequence is taken apart with the same brackets that build it. &lt;code&gt;[]&lt;/code&gt; matches an empty sequence, and
&lt;code&gt;[a, b, c]&lt;/code&gt; matches a sequence of exactly three elements, binding or testing each one; this works on
any &lt;code&gt;Seq&lt;/code&gt; — &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;. On a &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;[a, b]&lt;/code&gt; means &lt;code&gt;a :: b :: []&lt;/code&gt;, and the
two forms mix: &lt;code&gt;a :: [b, c]&lt;/code&gt; matches a list of exactly three elements. &lt;code&gt;::&lt;/code&gt; patterns themselves are
for lists only, since splitting off a head is what a list does in constant time.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;describe(xs: Vector[string]) -&amp;gt; string = xs match
  [] -&amp;gt; &amp;quot;nobody&amp;quot;
  [one] -&amp;gt; one
  [first, second] -&amp;gt; s&amp;quot;$first and $second&amp;quot;
  _ -&amp;gt; s&amp;quot;${xs(0)} and ${xs.length - 1} others&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The last part may be &lt;code&gt;rest*&lt;/code&gt;, or &lt;code&gt;_*&lt;/code&gt; where the rest is not used: the pattern then matches a
sequence of at least the elements before it, and &lt;code&gt;rest&lt;/code&gt; is bound to the elements after them. On a
&lt;code&gt;List&lt;/code&gt; that is the tail, so &lt;code&gt;[first, rest*]&lt;/code&gt; is &lt;code&gt;first :: rest&lt;/code&gt;; on any other sequence it is what
&lt;code&gt;drop(n)&lt;/code&gt; answers, a &lt;code&gt;Vector&lt;/code&gt;. That is the one rule, &lt;code&gt;n&lt;/code&gt; being the elements before &lt;code&gt;rest*&lt;/code&gt;, and it
holds where &lt;code&gt;n&lt;/code&gt; is 0: &lt;code&gt;[rest*]&lt;/code&gt; alone matches every sequence and binds what &lt;code&gt;drop(0)&lt;/code&gt; answers, the
list itself on a list, and a &lt;code&gt;Vector&lt;/code&gt; of the elements on a range, an array, a buffer or a deque,
made when the pattern matches.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;total(xs: List[int]) -&amp;gt; int = xs match
  [] -&amp;gt; 0
  [head, tail*] -&amp;gt; head + total(tail)

firstTwo(xs: Vector[string]) -&amp;gt; string = xs match
  [a, b, _*] -&amp;gt; s&amp;quot;$a and $b&amp;quot;
  _ -&amp;gt; &amp;quot;fewer than two&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For exhaustiveness, a sequence pattern covers its own length, and one ending in a rest covers
every length from its own on, on a sequence of any type. So &lt;code&gt;[]&lt;/code&gt; together with &lt;code&gt;[head, tail*]&lt;/code&gt;
covers every sequence, as &lt;code&gt;[]&lt;/code&gt; with &lt;code&gt;head :: tail&lt;/code&gt; covers every &lt;code&gt;List&lt;/code&gt;; fixed-length patterns cover
only their lengths, so a match that uses only them needs a catch-all. A match that leaves lengths
out names one, such as &lt;code&gt;[_, _, _*]&lt;/code&gt; for every length from two on.&lt;/p&gt;
&lt;h2 id=&quot;literals&quot;&gt;Literals&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Literal&lt;/th&gt;&lt;th&gt;Value with no other expected type&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;[1, 2, 3]&lt;/code&gt;, &lt;code&gt;[]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Immutable &lt;code&gt;Vector&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;{1, 2, 3}&lt;/code&gt;, &lt;code&gt;{}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Immutable &lt;code&gt;Set&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;{&amp;quot;a&amp;quot;: 1, &amp;quot;b&amp;quot;: 2}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Immutable &lt;code&gt;Map&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;{a: 1, b: 2}&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The same map; a bare identifier directly before &lt;code&gt;:&lt;/code&gt; is a string key&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Map.empty[string, int]()&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Empty &lt;code&gt;Map&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;A literal builds the collection its expected type asks for.&lt;/strong&gt; With no expected collection type,
or one the default satisfies (&lt;code&gt;Seq[int]&lt;/code&gt;, &lt;code&gt;Iterable[int]&lt;/code&gt;), a sequence literal is a &lt;code&gt;Vector&lt;/code&gt;, a set
literal a &lt;code&gt;Set&lt;/code&gt; and a map literal a &lt;code&gt;Map&lt;/code&gt;. When the expected type is another collection — from an
annotation, a parameter or a field — the literal builds that one instead:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val xs = [1, 2, 3] // Vector[int]
val queue: Buffer[int] = [1, 2, 3] // growable and mutable
val header: Array[byte] = [0x89, 0x50, 0x4e, 0x47]
val stack: List[string] = []
val seen: mutable.Set[int] = {}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A literal is built with its collection’s &lt;a href=&quot;#builders&quot;&gt;builder&lt;/a&gt;: sequence types (&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;,
&lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;) from sequence literals, set types from set literals and map types from
map literals, the mutable &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; of &lt;code&gt;avin.collections.mutable&lt;/code&gt; and &lt;code&gt;TreeSet&lt;/code&gt; and &lt;code&gt;TreeMap&lt;/code&gt;
included. Each is built only by the literal of its own shape: &lt;code&gt;[1, 2]&lt;/code&gt; where a &lt;code&gt;Set&lt;/code&gt; is expected is
an error, as &lt;code&gt;{1, 2}&lt;/code&gt; is where a &lt;code&gt;Vector&lt;/code&gt; is; &lt;code&gt;{}&lt;/code&gt; is the empty set or the empty map, whichever is
expected. A collection is built by a literal through the core trait &lt;code&gt;Buildable[A]&lt;/code&gt;, whose one member,
&lt;code&gt;static newBuilder() -&amp;gt; Builder[A, Self]&lt;/code&gt;, makes the builder; every library collection with a builder
implements it (all but &lt;code&gt;LazyList&lt;/code&gt;, which is never built eagerly; &lt;code&gt;LazyList(1, 2)&lt;/code&gt; makes one), and a
program’s collection joins by an impl in the module of the type or of the trait:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;impl[T] Buildable[T] for Stack[T]
  static newBuilder() -&amp;gt; StackBuilder[T] = StackBuilder()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Such a type is built by a sequence or set literal wherever it is expected, and by a map literal when
its builder takes &lt;code&gt;(key, value)&lt;/code&gt; pairs, each entry given to it as one; so is a type parameter bounded
by the trait, &lt;code&gt;make[C: Buildable[int]]() -&amp;gt; C = [1, 2, 3]&lt;/code&gt;. The conformance is the expected type’s
own: a &lt;code&gt;TreeSet&lt;/code&gt; is built by &lt;code&gt;TreeSet&lt;/code&gt;‘s, never by the one of &lt;code&gt;SortedSet&lt;/code&gt;, a trait it implements,
while a &lt;code&gt;SortedSet&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; or &lt;code&gt;Map&lt;/code&gt; expected is built by the trait type’s own conformance, which
makes its default kind (&lt;code&gt;{}&lt;/code&gt; where a &lt;code&gt;Map&lt;/code&gt; is expected is the empty &lt;code&gt;HashMap&lt;/code&gt;). An impl for one
instance of a generic type, &lt;code&gt;impl Buildable[int] for Count[int]&lt;/code&gt;, builds that instance and no other. A
method named &lt;code&gt;newBuilder&lt;/code&gt; in a companion object builds no literal, and an expected collection that
is not &lt;code&gt;Buildable&lt;/code&gt; and not an instance of the default (&lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; or &lt;code&gt;Map&lt;/code&gt;) is an error naming
the trait: &lt;code&gt;val c: Count[string] = [1]&lt;/code&gt; is one. A companion’s &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;Deque(1, 2, 3)&lt;/code&gt;, is an
ordinary method taking a repeated parameter, whose &lt;code&gt;Vector&lt;/code&gt; is built through &lt;code&gt;Vector&lt;/code&gt;‘s own
conformance, as a literal is. The
elements take their types from the expected element type when there is one (&lt;code&gt;Array[byte]&lt;/code&gt; makes
each literal a &lt;code&gt;byte&lt;/code&gt;), and otherwise from the elements themselves, which agree on a type as the
branches of an &lt;code&gt;if&lt;/code&gt; do: &lt;code&gt;[dog, cat]&lt;/code&gt; is a &lt;code&gt;Vector[Animal]&lt;/code&gt;, and &lt;code&gt;[1, &amp;quot;two&amp;quot;]&lt;/code&gt; is an error. A number
literal among them takes the type the others decide, wherever it is written
(&lt;a href=&quot;/spec/generics/#inference&quot;&gt;generics&lt;/a&gt;): &lt;code&gt;[long(1), 2]&lt;/code&gt; and &lt;code&gt;[2, long(1)]&lt;/code&gt; are &lt;code&gt;Vector[long]&lt;/code&gt;, and
&lt;code&gt;[1.5, 2]&lt;/code&gt; is a &lt;code&gt;Vector[real]&lt;/code&gt;. So does a number literal in a literal given as an argument, from
what the receiver and the other arguments decide of its parameter, an overloaded method’s included:
with &lt;code&gt;v: Vector[long]&lt;/code&gt;, &lt;code&gt;v ++ [400]&lt;/code&gt; and &lt;code&gt;v ++ [5_000_000_000]&lt;/code&gt; are &lt;code&gt;Vector[long]&lt;/code&gt;, &lt;code&gt;l ++ List(400)&lt;/code&gt;
on a &lt;code&gt;List[long]&lt;/code&gt; is a &lt;code&gt;List[long]&lt;/code&gt;, and beside a &lt;code&gt;Vector[BigInt]&lt;/code&gt; or a &lt;code&gt;Vector&lt;/code&gt; of a type that
&lt;a href=&quot;/spec/types/#integers-meet-a-type-that-takes-them&quot;&gt;takes integers&lt;/a&gt; the literal’s numbers are that
type’s values; &lt;code&gt;v ++ [&amp;quot;a&amp;quot;]&lt;/code&gt; is still an error. A map
literal’s keys agree on one type and its values on another, so &lt;code&gt;{a: dog, b: cat}&lt;/code&gt; is a
&lt;code&gt;Map[string, Animal]&lt;/code&gt;. A literal in braces is all elements or all entries; &lt;code&gt;{1, b: 2}&lt;/code&gt; is an
error. Set and map literals nest inside one another and inside sequence literals, and like them may
spread over lines, a trailing comma allowed. An empty literal, &lt;code&gt;[]&lt;/code&gt; or &lt;code&gt;{}&lt;/code&gt;, or a literal holding
one anywhere among its parts, joined with values of a collection type takes its type from them
where nothing useful is expected of the join (nothing, or &lt;code&gt;Any&lt;/code&gt;): among the elements of a literal,
the keys or the values of a map literal, the branches of an &lt;code&gt;if&lt;/code&gt; and the arms of a &lt;code&gt;match&lt;/code&gt;, it is
checked after the others and against the type they agree on. So &lt;code&gt;[{1: [2]}, {}]&lt;/code&gt; is a
&lt;code&gt;Vector[Map[int, Vector[int]]]&lt;/code&gt;, &lt;code&gt;if c then {1: [2]} else {}&lt;/code&gt; a &lt;code&gt;Map[int, Vector[int]]&lt;/code&gt;, and
&lt;code&gt;[{1: {}}, {2: {3: &amp;quot;x&amp;quot;}}]&lt;/code&gt; a vector of &lt;code&gt;Map[int, Map[int, string]]&lt;/code&gt;; &lt;code&gt;{}&lt;/code&gt; beside a set is the empty
set, and beside a sequence, which a set literal cannot build, it is still a set. An empty literal
with nothing else to say what it holds takes its type from a later use, as &lt;code&gt;None&lt;/code&gt; does, and is
otherwise an error asking for an annotation: &lt;code&gt;if c then {} else {}&lt;/code&gt; and &lt;code&gt;[{}, {}]&lt;/code&gt; are. A literal compared with &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt; or an ordering takes the other
operand’s type as its expected type, so &lt;code&gt;xs == [1, 2]&lt;/code&gt; compares a &lt;code&gt;List&lt;/code&gt; with a &lt;code&gt;List&lt;/code&gt; when &lt;code&gt;xs&lt;/code&gt; is
one. That type is only suggested to it: where it is one no literal builds, such as a &lt;code&gt;Range&lt;/code&gt;, the
literal is its default, so &lt;code&gt;(1 .. 3) == [1, 2, 3]&lt;/code&gt;
compares the range with a &lt;code&gt;Vector&lt;/code&gt;, as any two sequences compare. Only a type demanded of the
literal, by a declaration, a parameter, a result or an ascription, is an error there:
&lt;code&gt;val r: Range = [1, 2]&lt;/code&gt; is one.&lt;/p&gt;
&lt;p&gt;Literals always build the library’s types, even when a user type named &lt;code&gt;Vector&lt;/code&gt; is in scope.&lt;/p&gt;
&lt;h2 id=&quot;buffer&quot;&gt;Buffer&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Buffer[T]&lt;/code&gt; is invariant, growable and mutable. &lt;code&gt;Buffer[int]()&lt;/code&gt; is an empty buffer; &lt;code&gt;addOne(x)&lt;/code&gt;,
&lt;code&gt;append(x)&lt;/code&gt; or &lt;code&gt;b += x&lt;/code&gt; appends in amortized constant time, &lt;code&gt;addAll(xs)&lt;/code&gt;, &lt;code&gt;appendAll(xs)&lt;/code&gt; or
&lt;code&gt;b ++= xs&lt;/code&gt; appends each in turn, &lt;code&gt;prepend(x)&lt;/code&gt; and &lt;code&gt;prependAll(xs)&lt;/code&gt; put elements in front,
&lt;code&gt;insert(i, x)&lt;/code&gt;, &lt;code&gt;insertAll(i, xs)&lt;/code&gt; and &lt;code&gt;remove(i)&lt;/code&gt; work at any index, &lt;code&gt;sizeHint(n)&lt;/code&gt; makes room for
&lt;code&gt;n&lt;/code&gt; elements at once, and &lt;code&gt;clear()&lt;/code&gt; empties it. A buffer given itself to add or insert, &lt;code&gt;b ++= b&lt;/code&gt;,
places the elements it held when the call began, once. &lt;code&gt;b(i)&lt;/code&gt; and &lt;code&gt;b(i) = v&lt;/code&gt; read and replace an element, and an index outside &lt;code&gt;0 ..&amp;lt; length&lt;/code&gt; traps
at the caller’s line. Its elements live in an array with spare capacity, which never holds a value
that is read before one is written, so a buffer needs no value to fill it with.&lt;/p&gt;
&lt;p&gt;A buffer changes in place beyond adding and removing one element: &lt;code&gt;remove(i, n)&lt;/code&gt; takes out &lt;code&gt;n&lt;/code&gt;
elements from &lt;code&gt;i&lt;/code&gt; on, &lt;code&gt;trimStart(n)&lt;/code&gt; and &lt;code&gt;trimEnd(n)&lt;/code&gt; the first or last &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;filterInPlace(p)&lt;/code&gt; keeps
the elements that satisfy &lt;code&gt;p&lt;/code&gt;, &lt;code&gt;mapInPlace(f)&lt;/code&gt; replaces each with &lt;code&gt;f&lt;/code&gt; of it (&lt;code&gt;f&lt;/code&gt; returns the element
type), &lt;code&gt;patchInPlace(from, other, replaced)&lt;/code&gt; replaces the &lt;code&gt;replaced&lt;/code&gt; elements from &lt;code&gt;from&lt;/code&gt; with those
of &lt;code&gt;other&lt;/code&gt; (read before any change, so &lt;code&gt;b.patchInPlace(i, b, n)&lt;/code&gt; is well defined), and
&lt;code&gt;reverseInPlace()&lt;/code&gt; reverses. A buffer of &lt;code&gt;Eq&lt;/code&gt; elements has &lt;code&gt;subtractOne(x)&lt;/code&gt;, which takes out the first
element equal to &lt;code&gt;x&lt;/code&gt; and answers whether there was one. A range or count outside the buffer traps at
the call (&lt;code&gt;n = 0&lt;/code&gt; is always fine at &lt;code&gt;0 ..&amp;lt; length&lt;/code&gt; and at &lt;code&gt;length&lt;/code&gt;). A predicate or function given
to &lt;code&gt;filterInPlace&lt;/code&gt; or &lt;code&gt;mapInPlace&lt;/code&gt; must not change the buffer: the call traps once it returns to a
buffer whose length changed.&lt;/p&gt;
&lt;h2 id=&quot;vector&quot;&gt;Vector&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Vector[+T]&lt;/code&gt; is the default sequence: immutable, covariant and persistent. A changed vector shares
almost everything with the one it came from, so keeping both costs little, and either may be
changed again.&lt;/p&gt;
&lt;p&gt;Its elements are in a tree of arrays of 32. The tree has a balanced middle and, at every level, a
prefix and a suffix beside it: the arrays at the two ends, which is where a vector grows. Reading
an element takes one array per level, and a vector of up to 2^31 elements has at most six. Adding
an element at either end makes a new array at that end of the bottom level, and only when that
array is full does the next level gain one; so &lt;code&gt;:+&lt;/code&gt; and &lt;code&gt;+:&lt;/code&gt; take amortized constant time.
&lt;code&gt;updated&lt;/code&gt; copies the arrays on one path from the top of the tree to the element. Slicing cuts the
arrays at its two edges and shares the rest, so it takes time in the depth of the tree, not in the
length of the slice.&lt;/p&gt;
&lt;p&gt;Every array in a vector’s tree is exactly the size it holds and is never written once it is in the
tree. The library ends the filling of each with a release fence, before the array is stored in
another, and the vector’s constructor ends with the fence &lt;a href=&quot;/spec/threads/&quot;&gt;threads&lt;/a&gt; describe, so a
vector made by one thread is whole to any other thread that reads it.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Operation&lt;/th&gt;&lt;th&gt;Cost&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs(i)&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(log₃₂ n), at most six arrays&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs :+ x&lt;/code&gt;, &lt;code&gt;x +: xs&lt;/code&gt;&lt;/td&gt;&lt;td&gt;amortized O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;updated(i, x)&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(log₃₂ n), one path copied&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;takeRight&lt;/code&gt;, &lt;code&gt;dropRight&lt;/code&gt;, &lt;code&gt;splitAt&lt;/code&gt;, &lt;code&gt;tail&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(log₃₂ n)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs ++ ys&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(min(length of xs, length of ys))&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;length&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;iterator()&lt;/code&gt;, &lt;code&gt;reverseIterator()&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;foldLeft&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n), a leaf at a time&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Vector.newBuilder()&lt;/code&gt;, &lt;code&gt;toVector&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n), each array made once&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A vector’s iterators read one leaf after another, finding the next leaf only when one is used up.
A builder fills leaves of 32 as elements come and makes the tree above them once, at &lt;code&gt;result()&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;arrayseq&quot;&gt;ArraySeq&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;ArraySeq[+T]&lt;/code&gt; is the immutable sequence whose elements are in one array that nothing writes to
after it is made. There is no level between an index and its element, so &lt;code&gt;xs(i)&lt;/code&gt; reads one array
however long the sequence is, but every operation that makes a changed sequence (&lt;code&gt;xs :+ x&lt;/code&gt;,
&lt;code&gt;x +: xs&lt;/code&gt;, &lt;code&gt;xs ++ ys&lt;/code&gt;, &lt;code&gt;updated&lt;/code&gt;) copies all of them: it is for elements built once and then read.
&lt;code&gt;slice&lt;/code&gt; copies the elements it keeps. &lt;code&gt;ArraySeq.empty[T]()&lt;/code&gt; and &lt;code&gt;ArraySeq.newBuilder[T]()&lt;/code&gt; make one, as
does &lt;code&gt;toArraySeq&lt;/code&gt; on any collection, or a literal whose expected type is an &lt;code&gt;ArraySeq&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;val xs: ArraySeq[int] = [1, 2, 3]
val ys = xs :+ 4 // [1, 2, 3, 4], a copy; xs is unchanged
val v = ys.toVector // a Vector of the same elements
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Operation&lt;/th&gt;&lt;th&gt;Cost&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs(i)&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(1)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs :+ x&lt;/code&gt;, &lt;code&gt;x +: xs&lt;/code&gt;, &lt;code&gt;updated(i, x)&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(n), a copy&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;xs ++ ys&lt;/code&gt;&lt;/td&gt;&lt;td&gt;O(length of xs + length of ys)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;collect&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt;, iteration&lt;/td&gt;&lt;td&gt;O(n)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Both &lt;code&gt;Vector&lt;/code&gt; and &lt;code&gt;ArraySeq&lt;/code&gt; compare and hash by their elements in order, and display as an array
does, &lt;code&gt;[1, 2, 3]&lt;/code&gt;, where their elements display.&lt;/p&gt;
&lt;h2 id=&quot;seq&quot;&gt;Seq&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Seq[+T]&lt;/code&gt; is what every indexed sequence shares, so a function over &lt;code&gt;Seq[T]&lt;/code&gt; takes a list, a vector,
an &lt;code&gt;ArraySeq&lt;/code&gt;, a range, an array, a buffer or a deque. A sequence supplies &lt;code&gt;length&lt;/code&gt; and &lt;code&gt;apply(index)&lt;/code&gt;, and has the rest
from them: &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt;, &lt;code&gt;nonEmpty&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; (trapping when empty) with &lt;code&gt;headOption&lt;/code&gt; and
&lt;code&gt;lastOption&lt;/code&gt;, read by index, &lt;code&gt;foldRight&lt;/code&gt;, &lt;code&gt;indexWhere&lt;/code&gt; (-1 when no element satisfies it), &lt;code&gt;toVector&lt;/code&gt;,
an iterator, and &lt;code&gt;reverseIterator&lt;/code&gt;, which walks
from the last element to the first. The &lt;a href=&quot;#methods-every-iterable-has&quot;&gt;methods every Iterable has&lt;/a&gt;,
&lt;code&gt;foldLeft&lt;/code&gt;, &lt;code&gt;exists&lt;/code&gt;, &lt;code&gt;count&lt;/code&gt; and the rest, it has as every collection does. A sequence that reaches
its elements another way overrides the ones that would be slow: a list walks from its front, so on a
list each of them takes time proportional to its length.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Equality is written once on &lt;code&gt;Seq&lt;/code&gt;&lt;/strong&gt;: two sequences with equal elements in the same order are equal
and hash alike, whichever kinds they are, so &lt;code&gt;[1, 2, 3] == List(1, 2, 3)&lt;/code&gt; and &lt;code&gt;[1, 2, 3] == (1..3)&lt;/code&gt;
are &lt;code&gt;true&lt;/code&gt;, and a &lt;code&gt;Seq[int]&lt;/code&gt; key finds an entry stored under a vector, a list or a range of the same
elements. The two sides need the same element type. A class of the program’s own that implements
&lt;code&gt;Seq&lt;/code&gt; is compared the same way unless it implements &lt;code&gt;Eq&lt;/code&gt; itself. The same holds through &lt;code&gt;Any&lt;/code&gt; and
trait-typed values: an &lt;code&gt;Any&lt;/code&gt; holding a vector equals a list of the same elements, compared element
by element as &lt;code&gt;Any&lt;/code&gt; values are, and the hashes agree, so a set or map keyed by &lt;code&gt;Any&lt;/code&gt; finds a
sequence under any class of the same elements.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;total(xs: Seq[int]) -&amp;gt; int = xs.foldLeft(0, (acc, x) -&amp;gt; acc + x)

total([1, 2, 3])                   // a Vector
total(Array.fill(4, 1))            // an Array
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Impls add more to every sequence (&lt;a href=&quot;/spec/declarations/#impl&quot;&gt;impl&lt;/a&gt;), written once on &lt;code&gt;Seq&lt;/code&gt; and
reached through generic code over &lt;code&gt;Seq[T]&lt;/code&gt; as on each sequence type: &lt;code&gt;contains(element)&lt;/code&gt; and
&lt;code&gt;indexOf(element)&lt;/code&gt;, which compare with &lt;code&gt;equals&lt;/code&gt; and are &lt;code&gt;exists&lt;/code&gt; and &lt;code&gt;indexWhere&lt;/code&gt;, so a list walks
itself once; where the elements are ordered, the sorts, &lt;code&gt;sorted&lt;/code&gt;, &lt;code&gt;sortBy&lt;/code&gt; and &lt;code&gt;sortWith&lt;/code&gt;
(&lt;a href=&quot;#sorting&quot;&gt;sorting&lt;/a&gt;); and the transformations and structural methods in
&lt;a href=&quot;#methods-every-seq-has&quot;&gt;methods every Seq has&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;present[T](xs: Seq[T], x: T) -&amp;gt; bool = xs.contains(x)

present([3, 1, 4], 4)              // true
Array.fill(2, &amp;quot;a&amp;quot;).mkString(&amp;quot;-&amp;quot;)   // a-a
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;deque&quot;&gt;Deque&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Deque[T]&lt;/code&gt; is invariant, growable and mutable at both ends. &lt;code&gt;Deque[int]()&lt;/code&gt; is an empty deque;
&lt;code&gt;prepend(x)&lt;/code&gt; and &lt;code&gt;append(x)&lt;/code&gt; (or &lt;code&gt;addOne(x)&lt;/code&gt;) put an element at the front or the back in amortized
constant time, and &lt;code&gt;removeHead()&lt;/code&gt; and &lt;code&gt;removeLast()&lt;/code&gt; take one off and return it, trapping on an empty
deque. So a deque is a queue, &lt;code&gt;append&lt;/code&gt; with &lt;code&gt;removeHead&lt;/code&gt;, and a stack, &lt;code&gt;append&lt;/code&gt; with &lt;code&gt;removeLast&lt;/code&gt;.
&lt;code&gt;prependAll(xs)&lt;/code&gt; and &lt;code&gt;appendAll(xs)&lt;/code&gt; (or &lt;code&gt;addAll(xs)&lt;/code&gt;) put several at an end in their order, and
&lt;code&gt;insert(i, x)&lt;/code&gt; and &lt;code&gt;insertAll(i, xs)&lt;/code&gt; at an index, moving the rest along. &lt;code&gt;d(i)&lt;/code&gt; and &lt;code&gt;d(i) = v&lt;/code&gt; read
and replace the element &lt;code&gt;i&lt;/code&gt; places from the front, an index outside &lt;code&gt;0 ..&amp;lt; length&lt;/code&gt; trapping, and
&lt;code&gt;clear()&lt;/code&gt; empties it; a deque given itself to add places the elements it held when the call began,
once. Its elements live in an array as a ring that wraps
around from the array’s end to its start, doubling as a buffer’s does when full. A deque compares and
hashes by its elements in order, displays as &lt;code&gt;[1, 2, 3]&lt;/code&gt;, has &lt;code&gt;mkString&lt;/code&gt; where its elements display,
and is built by &lt;code&gt;Deque.newBuilder&lt;/code&gt; and by a sequence literal where one is expected.&lt;/p&gt;
&lt;p&gt;A deque has the same in-place operations as a buffer, with the same traps and the same meaning in
terms of the elements front first: &lt;code&gt;remove(i, n)&lt;/code&gt;, &lt;code&gt;trimStart(n)&lt;/code&gt;, &lt;code&gt;trimEnd(n)&lt;/code&gt;, &lt;code&gt;filterInPlace(p)&lt;/code&gt;,
&lt;code&gt;mapInPlace(f)&lt;/code&gt;, &lt;code&gt;patchInPlace(from, other, replaced)&lt;/code&gt;, &lt;code&gt;reverseInPlace()&lt;/code&gt; and, for &lt;code&gt;Eq&lt;/code&gt; elements,
&lt;code&gt;subtractOne(x)&lt;/code&gt;. They work wherever the ring’s elements wrap around the array’s end.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val pending: Deque[string] = [&amp;quot;build&amp;quot;, &amp;quot;test&amp;quot;]
pending.prepend(&amp;quot;fetch&amp;quot;)
while pending.nonEmpty do run(pending.removeHead())
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;priority-queues&quot;&gt;Priority queues&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;avin.collections.mutable.PriorityQueue[T]&lt;/code&gt; is a mutable binary heap: elements go in in any order
and &lt;code&gt;dequeue&lt;/code&gt; takes out the greatest. &lt;code&gt;PriorityQueue[int]()&lt;/code&gt; orders by the element type’s &lt;code&gt;Ord&lt;/code&gt;;
&lt;code&gt;PriorityQueue.withOrdering(compare)&lt;/code&gt; takes a comparison, positive where its first argument is to
come out before its second. A queue giving the least first is made with &lt;code&gt;Reverse&lt;/code&gt; elements or with
&lt;code&gt;reverseOrder&lt;/code&gt;, and &lt;code&gt;compareBy&lt;/code&gt; and &lt;code&gt;thenBy&lt;/code&gt; build the comparison from keys.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val q = PriorityQueue[int]()
q.enqueue(3, 9, 1)
q += 5
q.head           // 9, left in the queue
q.dequeue()      // 9
q.dequeueAll()     // [5, 3, 1], and q is empty

val soonest = PriorityQueue.withOrdering(reverseOrder(compareBy((t: Task) -&amp;gt; t.due)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;enqueue(xs*)&lt;/code&gt;, &lt;code&gt;addOne(x)&lt;/code&gt;, &lt;code&gt;addAll(xs)&lt;/code&gt;, &lt;code&gt;+=&lt;/code&gt; and &lt;code&gt;++=&lt;/code&gt; add, each in O(log n) per element;
&lt;code&gt;dequeue&lt;/code&gt; and &lt;code&gt;head&lt;/code&gt; trap on an empty queue, &lt;code&gt;dequeueOption&lt;/code&gt; and &lt;code&gt;headOption&lt;/code&gt; answer &lt;code&gt;None&lt;/code&gt;;
&lt;code&gt;size&lt;/code&gt;, &lt;code&gt;isEmpty&lt;/code&gt; and &lt;code&gt;nonEmpty&lt;/code&gt; take constant time, and &lt;code&gt;clear()&lt;/code&gt; empties the queue.
&lt;code&gt;copy()&lt;/code&gt; makes an independent queue with the same comparison, and &lt;code&gt;PriorityQueue.newBuilder&lt;/code&gt; a
builder. A queue is &lt;code&gt;Iterable&lt;/code&gt;: &lt;code&gt;iterator()&lt;/code&gt; and &lt;code&gt;toVector&lt;/code&gt; give the elements in heap order, the
greatest first and the rest in no promised order, and an iterator is a snapshot, unaffected by
changes made while it runs. &lt;code&gt;toSortedVector()&lt;/code&gt; gives the elements in the order &lt;code&gt;dequeue&lt;/code&gt; would,
leaving the queue as it is. Elements the comparison finds equal come out in no promised order; the
queue is not stable.&lt;/p&gt;
&lt;h2 id=&quot;queue&quot;&gt;Queue&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Queue[+T]&lt;/code&gt; is an immutable first-in, first-out sequence. &lt;code&gt;Queue(1, 2, 3)&lt;/code&gt; has 1 at its front and
&lt;code&gt;Queue.empty[int]()&lt;/code&gt; is empty. &lt;code&gt;q.enqueue(x)&lt;/code&gt; makes a queue with &lt;code&gt;x&lt;/code&gt; after the others and
&lt;code&gt;q.enqueueAll(xs)&lt;/code&gt; one with every element of &lt;code&gt;xs&lt;/code&gt;; &lt;code&gt;q.dequeue&lt;/code&gt; answers the front element and the
queue of the rest as a pair, trapping on an empty queue, &lt;code&gt;q.dequeueOption&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt; instead,
and &lt;code&gt;q.front&lt;/code&gt; and &lt;code&gt;q.frontOption&lt;/code&gt; read the front. Each leaves &lt;code&gt;q&lt;/code&gt; as it was, so any earlier
version stays usable. The elements are held in two lists, the front in order and the back reversed;
when the front runs out the back is turned around into it. &lt;code&gt;enqueue&lt;/code&gt;, &lt;code&gt;dequeue&lt;/code&gt;, &lt;code&gt;front&lt;/code&gt; and &lt;code&gt;isEmpty&lt;/code&gt;
take amortized constant time, and &lt;code&gt;q(i)&lt;/code&gt; takes time proportional to &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A queue is a &lt;code&gt;Seq&lt;/code&gt;, front first, so it has every sequence method, compares and hashes as any sequence
does (equal to a &lt;code&gt;Vector&lt;/code&gt; or &lt;code&gt;List&lt;/code&gt; of the same elements, however its two lists are split),
displays as &lt;code&gt;[1, 2, 3]&lt;/code&gt; and is built by &lt;code&gt;Queue.newBuilder&lt;/code&gt;. It is covariant: &lt;code&gt;enqueue&lt;/code&gt; and
&lt;code&gt;enqueueAll&lt;/code&gt; take &lt;code&gt;W &amp;gt;: T&lt;/code&gt;, so enqueueing a &lt;code&gt;Cat&lt;/code&gt; to a &lt;code&gt;Queue[Dog]&lt;/code&gt; makes a &lt;code&gt;Queue[Animal]&lt;/code&gt;. &lt;code&gt;map&lt;/code&gt;,
&lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;filterNot&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; answer queues.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val jobs = Queue(&amp;quot;build&amp;quot;, &amp;quot;test&amp;quot;)
val (next, rest) = jobs.enqueue(&amp;quot;deploy&amp;quot;).dequeue
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;sorting&quot;&gt;Sorting&lt;/h2&gt;
&lt;p&gt;Every sequence sorts into a new one, and the mutable sequences also sort in place. A comparison is
what &lt;code&gt;Ord.compare&lt;/code&gt; answers: negative, zero or positive as its first argument orders before, with or
after its second.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On every &lt;code&gt;Seq&lt;/code&gt;: &lt;code&gt;sorted&lt;/code&gt; where the elements are &lt;code&gt;Ord&lt;/code&gt;, ascending, and &lt;code&gt;sortedDescending&lt;/code&gt;,
descending; &lt;code&gt;sortBy(key)&lt;/code&gt;, ascending by
a key that is &lt;code&gt;Ord&lt;/code&gt;; and &lt;code&gt;sortWith(compare)&lt;/code&gt;, by any comparison. They answer a &lt;code&gt;Vector&lt;/code&gt; and leave
the sequence as it was. A &lt;code&gt;List&lt;/code&gt; has its own four, which answer a &lt;code&gt;List&lt;/code&gt;, as its &lt;code&gt;map&lt;/code&gt; and
&lt;code&gt;filter&lt;/code&gt; do: a list sorted is usually used as a list, walked from its front or matched with &lt;code&gt;::&lt;/code&gt;,
and the conversion would otherwise be the caller’s every time. A vector needs no sorts of its own,
since &lt;code&gt;Seq&lt;/code&gt;‘s already answer a vector.&lt;/li&gt;
&lt;li&gt;On &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt; and &lt;code&gt;Deque&lt;/code&gt;: &lt;code&gt;sortInPlace()&lt;/code&gt;, &lt;code&gt;sortInPlaceBy(key)&lt;/code&gt; and
&lt;code&gt;sortInPlaceWith(compare)&lt;/code&gt; reorder the elements in place and answer unit, and where the elements
are &lt;code&gt;Ord&lt;/code&gt;, &lt;code&gt;sortInPlaceDescending()&lt;/code&gt; as well. A deque sorts front
first, wherever its ring starts. Being sequences, they also have &lt;code&gt;sorted&lt;/code&gt;, &lt;code&gt;sortBy&lt;/code&gt; and
&lt;code&gt;sortWith&lt;/code&gt;, answering a sorted &lt;code&gt;Vector&lt;/code&gt; and leaving the collection as it was.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Every sort is stable&lt;/strong&gt;: elements that compare equal keep the order they had, so sorting by one
field and then by another orders by the second with the first breaking ties. &lt;strong&gt;Every sort takes
time proportional to n log n comparisons in the worst case&lt;/strong&gt; and memory for one copy of the
elements: it is a merge sort, which sorts runs of 16 elements by insertion and then merges them
pairwise between the elements and one scratch array, the runs doubling each pass.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;sortBy&lt;/code&gt; and &lt;code&gt;sortInPlaceBy&lt;/code&gt; compute &lt;code&gt;key&lt;/code&gt; once for each element&lt;/strong&gt;, before any comparison, and
sort the elements as their keys sort; so a key that is costly to compute, such as a string built from
the element, costs n computations rather than one per comparison, at the price of an array of the
keys. &lt;code&gt;sortWith&lt;/code&gt; calls &lt;code&gt;compare&lt;/code&gt; as the sort needs it, and &lt;code&gt;sorted&lt;/code&gt; is &lt;code&gt;sortWith&lt;/code&gt; by &lt;code&gt;compare&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data Entry(rank: int, name: string)

val entries = [Entry(2, &amp;quot;b&amp;quot;), Entry(1, &amp;quot;a&amp;quot;), Entry(2, &amp;quot;c&amp;quot;)]
entries.sortBy(e -&amp;gt; e.rank)                         // a, b, c: b still before c
entries.sortWith((x, y) -&amp;gt; y.rank.compare(x.rank))   // b, c, a
val scores: Array[int] = [3, 1, 2]
scores.sortInPlace()                                 // [1, 2, 3]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Ordering toolkit.&lt;/strong&gt; An &lt;code&gt;ArraySeq&lt;/code&gt; is &lt;code&gt;Ord&lt;/code&gt; where its elements are, as a &lt;code&gt;List&lt;/code&gt; is: element by
element, the first pair that differs deciding, and a sequence ordering before every longer one it
begins. &lt;strong&gt;Descending order by a key is &lt;code&gt;Reverse&lt;/code&gt;&lt;/strong&gt;; &lt;code&gt;sortedDescending&lt;/code&gt; is only the whole elements’
order turned round, and being stable it keeps equal elements in their order, which &lt;code&gt;sorted.reverse&lt;/code&gt;
would turn round with the rest. &lt;code&gt;data Reverse[T: Ord](value: T)&lt;/code&gt; orders the opposite way to &lt;code&gt;value&lt;/code&gt;, and as a sort key, alone or one
part of a tuple, it sorts descending: &lt;code&gt;people.sortBy(p -&amp;gt; (Reverse(p.age), p.name))&lt;/code&gt; is oldest first,
ties by name. &lt;code&gt;Reverse(Reverse(x))&lt;/code&gt; orders as &lt;code&gt;x&lt;/code&gt;. &lt;code&gt;clamp(x, lo, hi)&lt;/code&gt; is &lt;code&gt;x&lt;/code&gt; limited to &lt;code&gt;lo ..= hi&lt;/code&gt;
and traps where &lt;code&gt;hi &amp;lt; lo&lt;/code&gt;. For &lt;code&gt;sortWith&lt;/code&gt;, &lt;code&gt;compareBy(key)&lt;/code&gt; is the comparison of two values by their
keys, &lt;code&gt;reverseOrder(cmp)&lt;/code&gt; the same comparison the other way round, and &lt;code&gt;thenBy(first, second)&lt;/code&gt; the
first, with the second deciding where the first finds two values equal:
&lt;code&gt;people.sortWith(thenBy(reverseOrder(compareBy(p -&amp;gt; p.age)), compareBy(p -&amp;gt; p.name)))&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A sequence in ascending order is searched by halving.&lt;/strong&gt; On a &lt;code&gt;Seq[T]&lt;/code&gt; with &lt;code&gt;T: Ord&lt;/code&gt;,
&lt;code&gt;search(x)&lt;/code&gt; answers a &lt;code&gt;SearchResult&lt;/code&gt;: &lt;code&gt;Found(i)&lt;/code&gt; where &lt;code&gt;i&lt;/code&gt; is the index of the &lt;strong&gt;first&lt;/strong&gt; element equal
to &lt;code&gt;x&lt;/code&gt;, or &lt;code&gt;InsertionPoint(i)&lt;/code&gt; where &lt;code&gt;i&lt;/code&gt; is the index &lt;code&gt;x&lt;/code&gt; would have if put in, that of the first
element ordering after it, or the length. It takes O(log n) comparisons, and an index read by
position is O(log n) on a vector, an array or a range. &lt;code&gt;search(x, from, until)&lt;/code&gt; looks only at that
window, the two held to the sequence as a count is, and answers indices of the whole sequence.
&lt;code&gt;searchBy(key, wanted)&lt;/code&gt; is the same for a sequence in ascending order of &lt;code&gt;key&lt;/code&gt;, comparing &lt;code&gt;key&lt;/code&gt; of
an element with &lt;code&gt;wanted&lt;/code&gt; (a &lt;code&gt;K: Ord&lt;/code&gt;). A sequence that is not in order gives some answer but not a
meaningful one. &lt;code&gt;SearchResult&lt;/code&gt; is a data type, so &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt; work on it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val xs = [1, 3, 3, 5]
xs.search(3)      // Found(1)
xs.search(4)      // InsertionPoint(3)
xs.search(9)      // InsertionPoint(4)
xs.search(3, 2, 4) // Found(2)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Strings order by code point (their bytes, which in UTF-8 order the same), so every capital comes
before every small letter; reals order as IEEE 754 does. Sorting elements without &lt;code&gt;Ord&lt;/code&gt; by
&lt;code&gt;sorted&lt;/code&gt; or &lt;code&gt;sortInPlace()&lt;/code&gt; is a compile-time error naming the bound, and &lt;code&gt;sortWith&lt;/code&gt; is the way to sort
them.&lt;/p&gt;
&lt;h2 id=&quot;ranges&quot;&gt;Ranges&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;a..b&lt;/code&gt; (inclusive) and &lt;code&gt;a..&amp;lt;b&lt;/code&gt; (exclusive) are expressions that construct an immutable
&lt;code&gt;Range[T]&lt;/code&gt;, which is a &lt;code&gt;Seq&lt;/code&gt;. Each endpoint is evaluated once, left to right. The default step is
+1, so a descending range is empty; &lt;code&gt;by&lt;/code&gt; sets another step. Iteration stops without stepping past the
type’s maximum. Range &lt;strong&gt;patterns&lt;/strong&gt; in &lt;code&gt;match&lt;/code&gt; arms are a separate feature: a test, not a value.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;a..b by s&lt;/code&gt; is the infix call &lt;code&gt;(a..b).by(s)&lt;/code&gt;: a negative step counts down, so &lt;code&gt;10..0 by -2&lt;/code&gt; is 10, 8,
…, 0, and a step of zero traps. A range is empty when its start already lies past its limit in the
step’s direction, and &lt;code&gt;r.isEmpty&lt;/code&gt; says so. Iteration never steps past the largest or smallest
value of the type: &lt;code&gt;for i in 2147483640..2147483647 by 5&lt;/code&gt; yields 2147483640 and 2147483645 and stops.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Range&lt;/code&gt; of &lt;code&gt;int&lt;/code&gt;s is a &lt;code&gt;Seq[int]&lt;/code&gt;, and answers its own sequence questions from its bounds in
constant time: &lt;code&gt;length&lt;/code&gt; (trapping for a range of more values than the largest &lt;code&gt;int&lt;/code&gt;, such as
&lt;code&gt;int.MinValue .. int.MaxValue&lt;/code&gt;), &lt;code&gt;r(i)&lt;/code&gt;, which is &lt;code&gt;start + i * step&lt;/code&gt; and traps outside &lt;code&gt;0 ..&amp;lt; length&lt;/code&gt;, and
&lt;code&gt;contains(x)&lt;/code&gt;, which is whether &lt;code&gt;x&lt;/code&gt; lies between the first and last values a whole number of steps
from the first, so &lt;code&gt;(1 ..&amp;lt; 10 by 3).contains(7)&lt;/code&gt; is true and &lt;code&gt;.contains(8)&lt;/code&gt; false. &lt;code&gt;lift(i)&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;,
&lt;code&gt;last&lt;/code&gt; and their &lt;code&gt;Option&lt;/code&gt; forms are answered from the bounds too, so they work on a range too long
for &lt;code&gt;length&lt;/code&gt;. Everything else
it has as &lt;a href=&quot;#methods-every-seq-has&quot;&gt;every sequence&lt;/a&gt; does, and what those make of it, &lt;code&gt;map&lt;/code&gt; and
&lt;code&gt;filter&lt;/code&gt; as much as &lt;code&gt;take&lt;/code&gt; and &lt;code&gt;reverse&lt;/code&gt;, is a &lt;code&gt;Vector&lt;/code&gt;: &lt;code&gt;(1 .. 5).map(x -&amp;gt; x * x)&lt;/code&gt; is
&lt;code&gt;[1, 4, 9, 16, 25]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A range displays as it is written, its bounds as given and &lt;code&gt;by&lt;/code&gt; and the step where the step is not
1: &lt;code&gt;1..5&lt;/code&gt;, &lt;code&gt;0..&amp;lt;10&lt;/code&gt;, &lt;code&gt;0..&amp;lt;10 by 2&lt;/code&gt;, &lt;code&gt;10..1 by -3&lt;/code&gt;. Its &lt;code&gt;Debug&lt;/code&gt; form is the same, so &lt;code&gt;println(r)&lt;/code&gt;,
&lt;code&gt;s&amp;quot;$r&amp;quot;&lt;/code&gt;, &lt;code&gt;f&amp;quot;${r}%8s&amp;quot;&lt;/code&gt; and &lt;code&gt;debug(r)&lt;/code&gt; all show that text, and a range inside a collection, an option or
a tuple shows it there. A &lt;code&gt;NumericRange&lt;/code&gt; displays the same way.&lt;/p&gt;
&lt;h3 id=&quot;ranges-of-other-integer-types&quot;&gt;Ranges of other integer types&lt;/h3&gt;
&lt;p&gt;Where the endpoints are integers of a type other than &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;a..b&lt;/code&gt; and &lt;code&gt;a..&amp;lt;b&lt;/code&gt; make a
&lt;code&gt;NumericRange[T]&lt;/code&gt; of that type, a &lt;code&gt;Seq[T]&lt;/code&gt; that behaves as &lt;code&gt;Range&lt;/code&gt; does: an integer literal endpoint
takes its type from the other, &lt;code&gt;by&lt;/code&gt; takes a step of type &lt;code&gt;T&lt;/code&gt;, a zero step traps, and iteration never
passes the largest or smallest value of &lt;code&gt;T&lt;/code&gt;. &lt;code&gt;lift&lt;/code&gt;, &lt;code&gt;r(i)&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;contains(x)&lt;/code&gt; and &lt;code&gt;isEmpty&lt;/code&gt;
are answered from the bounds without wrapping, so a range from the smallest &lt;code&gt;long&lt;/code&gt; to the largest contains 0, and an
&lt;code&gt;i8&lt;/code&gt; range from 100 to 127 by 20 has the values 100 and 120. &lt;code&gt;length&lt;/code&gt; traps for more values than an &lt;code&gt;int&lt;/code&gt;
holds, as it does for &lt;code&gt;Range&lt;/code&gt;; a range of &lt;code&gt;long&lt;/code&gt;s past that still answers &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt; and
&lt;code&gt;lift(i)&lt;/code&gt;. A range whose ends lie more than the largest &lt;code&gt;long&lt;/code&gt; apart cannot be counted, so
&lt;code&gt;last&lt;/code&gt; and &lt;code&gt;length&lt;/code&gt; on it trap, while iterating it, &lt;code&gt;lift&lt;/code&gt; and &lt;code&gt;contains&lt;/code&gt; work.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val big: long = 5000000000
val r = 0 .. big by 1000000000
r.length      // 6
r.last        // 5000000000
r.contains(3000000000)   // true
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;for-comprehensions&quot;&gt;for comprehensions&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;for&lt;/code&gt; with &lt;code&gt;yield&lt;/code&gt; is sugar over collection methods: generators become &lt;code&gt;flatMap&lt;/code&gt;/&lt;code&gt;map&lt;/code&gt; and guards
become lazy filters. A source is admitted by what it is, nominally: an &lt;code&gt;Iterable&lt;/code&gt;, or a type
implementing the &lt;a href=&quot;/spec/generics/#functor-applicative-monad-traverse&quot;&gt;standard constructor traits&lt;/a&gt;
(below). Scope and the order of evaluation follow the source. A &lt;code&gt;for&lt;/code&gt; without &lt;code&gt;yield&lt;/code&gt; is a loop over the source’s &lt;code&gt;iterator()&lt;/code&gt;, described next.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;for pattern in xs&lt;/code&gt; followed by an indented body, or &lt;code&gt;for pattern in xs do body&lt;/code&gt; on one line, runs the
body once per element, binding each by the pattern: a name, &lt;code&gt;_&lt;/code&gt;, a tuple or a variant pattern that
every element matches. Each element is a new binding, so a closure made in the body keeps the
element it saw. &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; work as in &lt;code&gt;while&lt;/code&gt;. A range written in place (&lt;code&gt;0..&amp;lt;n&lt;/code&gt;, of any
integer type) is counted without making a &lt;code&gt;Range&lt;/code&gt;, and an array is indexed; anything else must
conform to &lt;code&gt;Iterable&lt;/code&gt; and is traversed through its &lt;code&gt;iterator()&lt;/code&gt;, which is what &lt;code&gt;foreach&lt;/code&gt; does for
the library’s collections, and lets &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; leave the body directly.
Conformance is by name, as everywhere: a class or data type declaring &lt;code&gt;Iterable[A]&lt;/code&gt; among its
parents or given it by an impl, an &lt;code&gt;Iterator&lt;/code&gt;, a type parameter bounded by &lt;code&gt;Iterable&lt;/code&gt; or by a trait
requiring it, or a union whose every member is one. A type that merely has an &lt;code&gt;iterator()&lt;/code&gt; method is
not a source until it conforms, and neither is an &lt;code&gt;Option&lt;/code&gt; or an &lt;code&gt;Either&lt;/code&gt;, which have &lt;code&gt;iterator()&lt;/code&gt;
but are not &lt;code&gt;Iterable&lt;/code&gt;s (&lt;code&gt;toList&lt;/code&gt; makes one of an option’s value). Any other source, such as an
&lt;code&gt;int&lt;/code&gt;, is an error that names its type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for i in 0 ..&amp;lt; n do total += i
for (name, age) in people
  if age &amp;lt; 18 then continue
  println(name)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A loop takes the clauses a comprehension does (below): several generators separated by commas,
&lt;code&gt;if&lt;/code&gt; guards after each, and value definitions &lt;code&gt;pattern = value&lt;/code&gt; between them. It runs as the loops
they would be written as one inside another: each generator a &lt;code&gt;for&lt;/code&gt; over its source inside the one
before it, each guard an &lt;code&gt;if&lt;/code&gt; around the rest, each definition a &lt;code&gt;val&lt;/code&gt; before the rest. So a later
source is evaluated anew for each element of the earlier generators, a guard is tested once for each
element that reaches it, and &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; act on the innermost generator’s loop, as in the
nested form; &lt;code&gt;return&lt;/code&gt; leaves the function from any depth. Each generator is counted, indexed or
iterated as a loop of its own is, so a loop over ranges and arrays allocates nothing.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for i in 0 ..&amp;lt; n, j in i + 1 ..&amp;lt; n if a(i) &amp;gt; a(j) do swaps += 1
// runs as
for i in 0 ..&amp;lt; n
  for j in i + 1 ..&amp;lt; n
    if a(i) &amp;gt; a(j) then swaps += 1

for x in xs if x &amp;gt; 0, y = f(x), z in g(y)
  println(z)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The one-to-a-line block form after &lt;code&gt;for&lt;/code&gt; is a comprehension’s alone: a loop’s clauses go on the
&lt;code&gt;for&lt;/code&gt; line, and an indented line after them is its body.&lt;/p&gt;
&lt;h3 id=&quot;generators-guards-and-yield&quot;&gt;Generators, guards and &lt;code&gt;yield&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A comprehension is &lt;code&gt;for&lt;/code&gt;, one or more generators separated by commas, and &lt;code&gt;yield&lt;/code&gt; with the value
to collect, on the rest of the line or in an indented block. A generator is &lt;code&gt;pattern in source&lt;/code&gt;,
and any number of guards, &lt;code&gt;if condition&lt;/code&gt;, may follow it. Between the generators, and after the last,
come value definitions, &lt;code&gt;pattern = value&lt;/code&gt;, each with guards of its own. When the generators do not
fit on one line they go one to a line in an indented block after &lt;code&gt;for&lt;/code&gt;, a line starting with &lt;code&gt;if&lt;/code&gt;
adding a guard to the generator or definition above it, and &lt;code&gt;yield&lt;/code&gt; starts the line after the block.
Generators on the &lt;code&gt;for&lt;/code&gt; line may also be followed by &lt;code&gt;yield&lt;/code&gt; on the next line, indented under it, with
its value on the rest of that line or in a block indented under &lt;code&gt;yield&lt;/code&gt;; nothing else follows the
&lt;code&gt;yield&lt;/code&gt; line inside that indentation. &lt;code&gt;yield&lt;/code&gt; is a keyword.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;others(c: int) -&amp;gt; Vector[int] =
  for d in 0 ..&amp;lt; 3 if d != c
    yield d
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val pairs = for x in xs, y in ys if x &amp;lt; y yield (x, y)

val grid = for
  row in 0 ..&amp;lt; height
  if row % 2 == 0
  col in 0 ..&amp;lt; width
  cell = row * width + col
yield cell * cell

val priced = for item in order, (name, cost) = lookup(item) if cost &amp;gt; 0 yield s&amp;quot;$name: $cost&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The last generator’s source is called with &lt;code&gt;map&lt;/code&gt; and the yielded value, every earlier one with
&lt;code&gt;flatMap&lt;/code&gt; and the rest of the comprehension, and each guard becomes &lt;code&gt;withFilter&lt;/code&gt; on the source it
follows:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for x in xs if p(x), y in ys yield f(x, y)
xs.withFilter(x -&amp;gt; p(x)).flatMap(x -&amp;gt; ys.map(y -&amp;gt; f(x, y)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value definition is evaluated once for each element that reaches it and binds by its pattern,
which matches every value as a &lt;code&gt;val&lt;/code&gt;‘s does, in its guards, the later generators and definitions,
and the yielded value. Definitions that no guard follows are bound beside the element in the
function passed to its generator’s source, as &lt;code&gt;val&lt;/code&gt;s are in a block:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for x in xs, y = f(x), z in g(y) yield h(z)
xs.flatMap(x -&amp;gt;
  val y = f(x)
  g(y).map(z -&amp;gt; h(z)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A guard after a definition has to see its value before the element goes on, so the definition, and
every one before it after the same generator, pairs each element with its value through &lt;code&gt;map&lt;/code&gt;, and
the guard and everything after it take the pair apart. On a collection &lt;code&gt;map&lt;/code&gt; makes a collection, so
such a definition is evaluated for every element before its guard tests any:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for x in xs, y = f(x) if p(y) yield h(y)
xs.map(x -&amp;gt; (x, f(x))).withFilter(pair -&amp;gt; p(pair.1)).map(pair -&amp;gt; h(pair.1))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A definition binds in its generator’s scope, as a &lt;code&gt;val&lt;/code&gt; does in a block: it may not bind a name the
generator or an earlier definition after it binds, though a later generator may bind any name again.
A comprehension starts with a generator.&lt;/p&gt;
&lt;p&gt;The calls are checked as if written out, so the first source decides the result’s type: &lt;code&gt;map&lt;/code&gt; and
&lt;code&gt;flatMap&lt;/code&gt; on a &lt;code&gt;List&lt;/code&gt; give a &lt;code&gt;List&lt;/code&gt;, on a &lt;code&gt;Vector&lt;/code&gt;, an &lt;code&gt;Array&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt; or a &lt;code&gt;Deque&lt;/code&gt; that collection, on a
&lt;code&gt;Set&lt;/code&gt; a &lt;code&gt;Set&lt;/code&gt;, on an &lt;code&gt;Option&lt;/code&gt; an &lt;code&gt;Option&lt;/code&gt;, and on a &lt;code&gt;Range&lt;/code&gt;, which holds only a progression, or any
other &lt;code&gt;Seq&lt;/code&gt;, a sequence of the program’s own among them, a &lt;code&gt;Vector&lt;/code&gt;, through the
&lt;a href=&quot;#methods-every-seq-has&quot;&gt;methods every Seq has&lt;/a&gt;. A &lt;code&gt;Map&lt;/code&gt;‘s elements are its entries as &lt;code&gt;(key, value)&lt;/code&gt; pairs, and a comprehension over one
yields pairs and makes a &lt;code&gt;Map&lt;/code&gt;. Over a mutable &lt;code&gt;Set&lt;/code&gt; or &lt;code&gt;Map&lt;/code&gt; the result is a new mutable set or map,
as over an &lt;code&gt;Array&lt;/code&gt;, a &lt;code&gt;Buffer&lt;/code&gt; or a &lt;code&gt;Deque&lt;/code&gt; it is a new one of those, and the source is unchanged. &lt;code&gt;flatMap&lt;/code&gt; on the library’s collections takes any &lt;code&gt;Iterable&lt;/code&gt; from its
function, so a later generator may draw from another kind of collection than the first; an
&lt;code&gt;Option&lt;/code&gt;‘s &lt;code&gt;flatMap&lt;/code&gt; takes an &lt;code&gt;Option&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Which sources a comprehension takes is decided by conformance, never by the methods a type
happens to have.&lt;/strong&gt; Each source is checked for the role the desugaring gives it, then its calls are
checked as written out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The last generator’s source&lt;/strong&gt; is an &lt;code&gt;Iterable&lt;/code&gt;, or its type’s constructor implements &lt;code&gt;Functor&lt;/code&gt;
or &lt;code&gt;SendableFunctor&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A generator followed by another&lt;/strong&gt;, or by a definition a guard follows, is an &lt;code&gt;Iterable&lt;/code&gt;, a
&lt;code&gt;Monad&lt;/code&gt; or a &lt;code&gt;SendableMonad&lt;/code&gt;, so a comprehension over futures is a future, as before.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A guard&lt;/strong&gt; filters an &lt;code&gt;Iterable&lt;/code&gt; through &lt;code&gt;withFilter&lt;/code&gt;, lazily as below, and any other source
through &lt;code&gt;Filter&lt;/code&gt;‘s &lt;code&gt;filter&lt;/code&gt;. The views &lt;code&gt;withFilter&lt;/code&gt; makes are &lt;code&gt;Iterable&lt;/code&gt;s themselves, so the calls
after a guard are on an &lt;code&gt;Iterable&lt;/code&gt; too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In generic code&lt;/strong&gt; the bounds decide: &lt;code&gt;fa: F[A]&lt;/code&gt; with &lt;code&gt;F[_]: Monad &amp;amp; Filter&lt;/code&gt; takes every role,
and with &lt;code&gt;F[_]: Functor&lt;/code&gt; alone only the last generator’s.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So &lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result[_, E]&lt;/code&gt; and &lt;code&gt;Either[L, _]&lt;/code&gt; draw in a comprehension as the collections do, and so
does a type of the program’s own that implements &lt;code&gt;Monad&lt;/code&gt; (and &lt;code&gt;Filter&lt;/code&gt;, for guards). A type with a
&lt;code&gt;map&lt;/code&gt; and a &lt;code&gt;flatMap&lt;/code&gt; and no such impl is no source:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;for x in box, y in other yield x + y
// error: `box` is a `Box[int]`, which is neither an `Iterable` nor a `Monad`, and a generator
// followed by another draws only from those: declare `impl Monad for Box`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A source admitted for its role whose call still fails is reported at the generator that caused it:
in &lt;code&gt;for p in parser, n in maybeInt yield …&lt;/code&gt; where &lt;code&gt;parser&lt;/code&gt; is a &lt;code&gt;Parser[int]&lt;/code&gt;, the error names the
second generator, an &lt;code&gt;Option[int]&lt;/code&gt; where &lt;code&gt;Parser&lt;/code&gt;‘s &lt;code&gt;flatMap&lt;/code&gt; takes a function yielding a &lt;code&gt;Parser&lt;/code&gt;.
A guard on a source that is neither an &lt;code&gt;Iterable&lt;/code&gt; nor a &lt;code&gt;Filter&lt;/code&gt; names the guard and the bound it
needs. A refused source is told what to declare where the module can declare it: the impl, for a
type of its own, or the bound, for a constructor parameter (add &lt;code&gt;Monad&lt;/code&gt; to the bounds of &lt;code&gt;F&lt;/code&gt;);
another module’s type, such as &lt;code&gt;Result&lt;/code&gt;, which is no &lt;code&gt;Filter&lt;/code&gt;, is only refused.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;withFilter&lt;/code&gt; is lazy. It returns a view of the collection that tests each element just before
&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; or &lt;code&gt;foreach&lt;/code&gt; uses it, and another &lt;code&gt;withFilter&lt;/code&gt; on the view combines the tests. So
the order of evaluation follows the source element by element: the first source is evaluated once,
then for each of its elements its guards run and, for an element that passes them, the next
generator’s source is evaluated anew and its elements taken in turn, down to the yielded value. A
guard that prints shows its output interleaved with the yielded values’, not all before them.
&lt;code&gt;Option&lt;/code&gt;‘s &lt;code&gt;withFilter&lt;/code&gt; is its &lt;code&gt;filter&lt;/code&gt;, since with one value at most the two are the same.&lt;/p&gt;
&lt;p&gt;Each generator binds by its pattern, as a &lt;code&gt;for&lt;/code&gt; loop does: a name, &lt;code&gt;_&lt;/code&gt;, a tuple or a variant pattern
that every element matches; a pattern some elements would not match is an error, not a filter. The
bindings are visible to the generator’s guards and to everything after it, and each element is a
new binding. A guard is a &lt;code&gt;bool&lt;/code&gt;. The guards, the value definitions and the yielded value are
functions passed to the sources’ methods, so &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and &lt;code&gt;?&lt;/code&gt; cannot leave
them, though a loop inside the yielded block may be left as usual. A &lt;code&gt;for&lt;/code&gt; without &lt;code&gt;yield&lt;/code&gt; is not
built of these calls but of nested loops, which &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; leave as usual.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>C bindings</title>
    <link href="https://avinlang.dev/spec/c-bindings/"/>
    <id>https://avinlang.dev/spec/c-bindings/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Avin calls a C library directly, through bindings written in Avin whose C prototypes clang checks against the library&apos;s own headers.</summary>
    <content type="html">&lt;p&gt;A C library reaches Avin through a &lt;strong&gt;C binding&lt;/strong&gt;: an Avin declaration that copies the C function’s
prototype from the library’s header and states the signature Avin code calls it with, in Avin
types. The compiler calls the C function directly from Avin’s own code, converting each argument and
the result at the call, and links the library the package’s manifest names.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;module mlt

@c(type: &amp;quot;mlt_properties&amp;quot;, release: &amp;quot;mlt_properties_close&amp;quot;, retain: &amp;quot;mlt_properties_inc_ref&amp;quot;)
class Properties
  @c(&amp;quot;char *mlt_properties_get(mlt_properties self, const char *name)&amp;quot;)
  get(name: string) -&amp;gt; Option[string]

  @c(&amp;quot;int mlt_properties_set(mlt_properties self, const char *name, const char *value)&amp;quot;)
  set(name: string, value: string) -&amp;gt; Result[unit, int]

@c(&amp;quot;mlt_properties mlt_properties_new(void)&amp;quot;)
newProperties() -&amp;gt; Option[Properties]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A binding is a declaration without a body, as a &lt;a href=&quot;/spec/sysl-bindings/&quot;&gt;Sysl binding&lt;/a&gt; is: a top-level
function, or a method of a C handle. &lt;code&gt;@c&lt;/code&gt; takes the prototype as one string, written as the header
writes it, parameter names optional; the C parameters correspond to the Avin parameters &lt;strong&gt;by
position&lt;/strong&gt;, the receiver first for a method. Bindings are usually private, with a public function
giving the Avin-shaped API. A binding is otherwise an ordinary function: it is called, overloaded,
given defaults and passed as a value like any other.&lt;/p&gt;
&lt;p&gt;A prototype the header does not declare, or declares otherwise, is rejected at the binding with
clang’s own words:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the C binding `get` does not match `mlt_properties_get` in framework/mlt.h: the header declares &apos;char *(mlt_properties, const char *)&apos;, but the binding says &apos;char *(mlt_properties, char *)&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;how-a-c-binding-is-compiled&quot;&gt;How a C binding is compiled&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;A C binding is a direct call.&lt;/strong&gt; Settled on the user’s question (“Why should C interop go through
Sysl since avin generates LLVM IR?”): Avin emits LLVM IR, and a C function is called from LLVM IR by
declaring its symbol and calling it. The &lt;a href=&quot;/spec/sysl-bindings/#how-a-binding-is-compiled&quot;&gt;Sysl shim&lt;/a&gt;
exists so that Sysl checks a binding against a Sysl signature; a C binding has no Sysl signature, so
a shim would add a compile step, a cache and a Sysl dependency and check nothing.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Check&lt;/strong&gt; reads each prototype into a C signature — scalar types, pointers, &lt;code&gt;const&lt;/code&gt;, the names of
typedefs, function pointers — and holds it against the Avin signature by the rules below, so a
binding whose Avin types cannot carry its C types is rejected before anything is built.&lt;/li&gt;
&lt;li&gt;The driver generates one C file for the program, the &lt;strong&gt;C unit&lt;/strong&gt;, and compiles it with clang,
using the include flags of the &lt;a href=&quot;#c-libraries&quot;&gt;C libraries&lt;/a&gt; the program names. It holds:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;the header check&lt;/strong&gt;: for every binding, a &lt;code&gt;_Static_assert&lt;/code&gt; that the function the header
declares has exactly the type the prototype says (&lt;code&gt;__builtin_types_compatible_p&lt;/code&gt;), and, for
every typedef a prototype names, that it is the kind of type its Avin position needs (an
integer, a pointer, a struct);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;the measurements&lt;/strong&gt;: the width and sign of each typedef in an integer position, the size,
alignment and field offsets of each &lt;a href=&quot;#structs&quot;&gt;mirrored struct&lt;/a&gt;, the value of each
&lt;a href=&quot;#enums-and-constants&quot;&gt;enumerator and constant&lt;/a&gt;, stored as data in the object file, which the
driver reads without running it, so a build for another machine measures that machine;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;the glue&lt;/strong&gt;: a small C function for each thing that is a C &lt;em&gt;expression&lt;/em&gt; rather than a function
— a field read, a &lt;a href=&quot;#handles&quot;&gt;&lt;code&gt;retain&lt;/code&gt; or &lt;code&gt;release&lt;/code&gt;&lt;/a&gt; written as an expression, a
&lt;a href=&quot;#handles-and-c-s-inheritance&quot;&gt;conversion between handle types&lt;/a&gt;, a &lt;a href=&quot;#buffers&quot;&gt;buffer’s
length&lt;/a&gt;, a struct &lt;a href=&quot;#structs-by-value&quot;&gt;passed by value&lt;/a&gt;, a macro.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lower&lt;/strong&gt; gives each binding a body: convert the arguments, call the C symbol (or its glue),
convert the result, as MIR the rest of the compiler already knows. &lt;strong&gt;Emit&lt;/strong&gt; declares the C symbol
(&lt;code&gt;declare i32 @mlt_properties_set(ptr, ptr, ptr)&lt;/code&gt;) with the attributes the target’s C convention
asks for — &lt;code&gt;signext&lt;/code&gt; or &lt;code&gt;zeroext&lt;/code&gt; on an integer narrower than 32 bits, as the &lt;a href=&quot;/spec/sysl-bindings/#integer-parameters&quot;&gt;Sysl
boundary&lt;/a&gt; already does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Link&lt;/strong&gt; passes the C unit’s object, the objects of the &lt;a href=&quot;#c-sources-a-package-ships&quot;&gt;C sources the packages
ship&lt;/a&gt; and the libraries’ link flags to clang with the program.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The C unit is cached by a hash of its source, the include and link flags &lt;code&gt;pkg-config&lt;/code&gt; answers, and
&lt;code&gt;clang --version&lt;/code&gt;. Nothing about a C binding needs the &lt;code&gt;sysl&lt;/code&gt; command. &lt;code&gt;avin check&lt;/code&gt; builds the C
unit too, so a binding its headers refuse is refused by &lt;code&gt;check&lt;/code&gt; exactly as by a build.&lt;/p&gt;
&lt;h2 id=&quot;c-libraries&quot;&gt;C libraries&lt;/h2&gt;
&lt;p&gt;A package that binds a C library names it in its manifest, under &lt;code&gt;c-libraries&lt;/code&gt;, with the
&lt;code&gt;pkg-config&lt;/code&gt; module that finds it and the headers its bindings are checked against:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-libraries {
  mlt {
    pkg-config = &amp;quot;mlt-framework-7&amp;quot;
    headers    = [&amp;quot;framework/mlt.h&amp;quot;]
    install    = &amp;quot;MLT 7: `brew install mlt`; Debian&apos;s libmlt-dev&amp;quot;
  }
  libc { headers = [&amp;quot;&amp;lt;stdlib.h&amp;gt;&amp;quot;, &amp;quot;&amp;lt;string.h&amp;gt;&amp;quot;] }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;pkg-config&lt;/code&gt; names the module whose &lt;code&gt;--cflags&lt;/code&gt; the C unit is compiled with and whose &lt;code&gt;--libs&lt;/code&gt; the
program is linked with; both are asked at every build, so a library that moved is still found.
&lt;code&gt;link = [&amp;quot;z&amp;quot;]&lt;/code&gt; names libraries directly instead, each passed as &lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt;; an entry with neither
needs nothing at the link (the C library itself, whose headers are named only to check against).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;headers&lt;/code&gt; are included by the C unit, in order, for every binding of the package. &lt;strong&gt;A binding is
checked against a header, always&lt;/strong&gt;: a package with a &lt;code&gt;@c&lt;/code&gt; binding and no &lt;code&gt;headers&lt;/code&gt; is refused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A header may be named by a macro&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). An entry that is a C
identifier rather than a path is included as &lt;code&gt;#include NAME&lt;/code&gt;, which C expands to the header the
macro names, so it must be defined by an entry before it. FreeType names its headers this way,
each through a macro &lt;code&gt;&amp;lt;ft2build.h&amp;gt;&lt;/code&gt; defines:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-libraries {
  freetype {
    pkg-config = &amp;quot;freetype2&amp;quot;
    headers    = [&amp;quot;&amp;lt;ft2build.h&amp;gt;&amp;quot;, &amp;quot;FT_FREETYPE_H&amp;quot;, &amp;quot;FT_MODULE_H&amp;quot;, &amp;quot;FT_MULTIPLE_MASTERS_H&amp;quot;,
                  &amp;quot;FT_TRUETYPE_TABLES_H&amp;quot;]
    install    = &amp;quot;FreeType 2: `brew install freetype`; Debian&apos;s libfreetype-dev&amp;quot;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A macro no earlier header defines is reported at the entry, with clang’s own words:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the header `FT_FREETYPE_H` of the C library `freetype` of package `freetype` is not a macro any earlier header defines: clang says &apos;expected &amp;quot;FILENAME&amp;quot; or &amp;lt;FILENAME&amp;gt;&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;install&lt;/code&gt; is what a build that cannot find the module says to do:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the C library `mlt` of package `mlt` was not found: `pkg-config --cflags mlt-framework-7` failed. MLT 7: `brew install mlt`; Debian&apos;s libmlt-dev
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What else links it&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;settled&lt;/a&gt;), each optional and added to what
&lt;code&gt;pkg-config&lt;/code&gt; or &lt;code&gt;link&lt;/code&gt; gives:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;files&lt;/code&gt; names archives and shared libraries by their paths, linked as named;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;search&lt;/code&gt; names the directories its &lt;code&gt;link&lt;/code&gt; names are searched in, passed as &lt;code&gt;-L&lt;/code&gt; when it is
linked dynamically;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;include&lt;/code&gt; names the directories its headers are included from, passed to the C unit as &lt;code&gt;-I&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;frameworks&lt;/code&gt; names macOS frameworks, each passed as &lt;code&gt;-framework &amp;lt;name&amp;gt;&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;link-flags&lt;/code&gt; are passed to the linker as they are, the way out for anything else.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The paths of &lt;code&gt;files&lt;/code&gt;, &lt;code&gt;search&lt;/code&gt; and &lt;code&gt;include&lt;/code&gt; are relative to the package’s directory&lt;/strong&gt;, and
none may be absolute or leave it (a &lt;code&gt;..&lt;/code&gt; segment), so a package that vendors its library builds
wherever it is fetched:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-libraries {
  foo {
    files   = [&amp;quot;vendor/libfoo.a&amp;quot;]
    include = [&amp;quot;vendor/include&amp;quot;]
    headers = [&amp;quot;foo.h&amp;quot;]
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A file that is not there, or a search directory that is not one, stops the build with the
library, the package and the path; &lt;code&gt;avin check&lt;/code&gt; says the same.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;dynamic-only&lt;/code&gt; says why the library is never linked statically, for a licence that asks for it or
an installation that has no archive. It is a requirement, not a choice: how a program meets it is
in &lt;a href=&quot;#how-a-program-links-its-c-libraries&quot;&gt;How a program links its C libraries&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;sources&lt;/code&gt; names C files the package ships, compiled into the program, and &lt;code&gt;cflags&lt;/code&gt; the flags they
are compiled with: &lt;a href=&quot;#c-sources-a-package-ships&quot;&gt;C sources a package ships&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;A program builds with the C libraries of every package in it&lt;/strong&gt;, as it does with their
&lt;a href=&quot;/spec/packages/#sysl-dependencies&quot;&gt;Sysl dependencies&lt;/a&gt;, so a library that binds MLT works in a
program that never names MLT itself. A package whose bindings name a &lt;a href=&quot;#handles-of-another-package&quot;&gt;handle of another
package&lt;/a&gt; is checked with that package’s headers too.&lt;/p&gt;
&lt;h3 id=&quot;c-sources-a-package-ships&quot;&gt;C sources a package ships&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A package that ships its C library’s source names the files in &lt;code&gt;sources&lt;/code&gt;&lt;/strong&gt;, and the build compiles
them into the program (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;settled&lt;/a&gt;). Many small libraries are distributed
this way, one &lt;code&gt;sqlite3.c&lt;/code&gt; or a directory of &lt;code&gt;.c&lt;/code&gt; files, and a package binding one builds wherever it
is fetched, with nothing installed:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-libraries {
  sqlite {
    sources = [&amp;quot;vendor/sqlite/sqlite3.c&amp;quot;]
    cflags  = [&amp;quot;-DSQLITE_THREADSAFE=0&amp;quot;, &amp;quot;-DSQLITE_OMIT_LOAD_EXTENSION&amp;quot;]
    include = [&amp;quot;vendor/sqlite&amp;quot;]
    headers = [&amp;quot;sqlite3.h&amp;quot;]
  }
  miniz { sources = [&amp;quot;vendor/miniz/*.c&amp;quot;], include = [&amp;quot;vendor/miniz&amp;quot;], headers = [&amp;quot;miniz.h&amp;quot;] }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;sources&lt;/code&gt; are paths relative to the package’s directory&lt;/strong&gt;, under the rules of &lt;code&gt;files&lt;/code&gt;: none
absolute, none with a &lt;code&gt;..&lt;/code&gt; segment. A &lt;code&gt;*&lt;/code&gt; matches any run of characters within one name
(&lt;code&gt;vendor/*/*.c&lt;/code&gt; reaches one directory down; &lt;code&gt;**&lt;/code&gt; is refused), never a name beginning with &lt;code&gt;.&lt;/code&gt; unless
the pattern’s does, and never a directory. A pattern’s matches are taken in sorted order, and a file
named twice is compiled once.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;They are compiled by the clang the C unit is compiled with&lt;/strong&gt;, for the machine the build is for,
with &lt;code&gt;-O2&lt;/code&gt; unless &lt;code&gt;cflags&lt;/code&gt; names a level, whatever the program’s own &lt;code&gt;-O&lt;/code&gt; (the library is not what a
debug build of the program is debugging, and both builds share one object); then the library’s
&lt;code&gt;include&lt;/code&gt; directories, as &lt;code&gt;-I&lt;/code&gt;; then the &lt;code&gt;--cflags&lt;/code&gt; of its &lt;code&gt;pkg-config&lt;/code&gt; module, when it names one;
then &lt;code&gt;cflags&lt;/code&gt;, last, so each of them has the last word. The C unit is not compiled with &lt;code&gt;cflags&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;cflags&lt;/code&gt; says what the package’s C means and how well it is compiled&lt;/strong&gt;: defines (&lt;code&gt;-D&lt;/code&gt;, &lt;code&gt;-U&lt;/code&gt;), the
optimization level (&lt;code&gt;-O0&lt;/code&gt; to &lt;code&gt;-O3&lt;/code&gt;, &lt;code&gt;-Os&lt;/code&gt;, &lt;code&gt;-Oz&lt;/code&gt;), warnings (&lt;code&gt;-W…&lt;/code&gt;, &lt;code&gt;-w&lt;/code&gt;, &lt;code&gt;-pedantic&lt;/code&gt;), the language
standard (&lt;code&gt;-std=&lt;/code&gt;) and code generation (&lt;code&gt;-f…&lt;/code&gt;). Any other flag is refused where it is written: an
include directory is the library’s &lt;code&gt;include&lt;/code&gt;, a flag for the linker its &lt;code&gt;link-flags&lt;/code&gt;, and the
target, the output and the like are the build’s. &lt;code&gt;cflags&lt;/code&gt; with no &lt;code&gt;sources&lt;/code&gt; is an error too.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `-Ivendor` names an include directory, which a C library names in `include`, relative to its package&apos;s directory: `cflags` holds defines (`-D`, `-U`), an optimization level (`-O`), warnings (`-W`, `-w`), the language standard (`-std=`) and code generation (`-f`)
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The objects are linked into the program, statically, always&lt;/strong&gt;, before the libraries’ link flags,
whatever &lt;code&gt;c-linking&lt;/code&gt;, &lt;code&gt;static-c-libraries&lt;/code&gt; or the command line say of the library: they are part of
the program, so &lt;code&gt;otool -L&lt;/code&gt; lists nothing for them. A library naming both &lt;code&gt;sources&lt;/code&gt; and
&lt;code&gt;dynamic-only&lt;/code&gt; is refused at the entry. &lt;code&gt;sources&lt;/code&gt; may go with &lt;code&gt;pkg-config&lt;/code&gt; or &lt;code&gt;link&lt;/code&gt;, for a source
compiled against, or calling, a library that is installed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Each source compiles once.&lt;/strong&gt; Its object is kept in the build cache by a key over its text, its
flags, the target, the compiler’s version and &lt;code&gt;clang --version&lt;/code&gt;, and the path and text of every
header it includes; an edited source, an edited header it includes or a changed flag compiles it
again, and nothing else does. Two packages of a program shipping the same file, with the same
headers and flags, share one object, compiled once and linked once. The sources of a build compile
at the same time, one clang per processor at most.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A source that does not compile stops the build&lt;/strong&gt; with clang’s own words, which name the file and
the line, after the library and its package; a source that compiles shows no warnings:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the source `vendor/vend.c` of the C library `vend` of package `vend` does not compile:
/home/ana/vend/vendor/vend.c:3:38: error: expected &apos;;&apos; after return statement
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A source that is not there and a pattern matching no file are errors naming the path; &lt;code&gt;avin check&lt;/code&gt;
reports those too, and compiles no source:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the sources `vendor/*.c` of the C library `vend` of package `vend` match no file: `/home/ana/vend/vendor/*.c`
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sources that differ by machine are entries with an &lt;a href=&quot;/spec/packages/#machines&quot;&gt;&lt;code&gt;if&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;: what is
common in one entry, and each machine’s own in another, each a C library of the package.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-libraries {
  vend       { sources = [&amp;quot;vendor/common.c&amp;quot;], include = [&amp;quot;vendor&amp;quot;], headers = [&amp;quot;vend.h&amp;quot;] }
  vend-macos { if = &amp;quot;macos&amp;quot;, sources = [&amp;quot;vendor/macos.c&amp;quot;] }
  vend-linux { if = &amp;quot;linux&amp;quot;, sources = [&amp;quot;vendor/linux/*.c&amp;quot;] }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A header-only library needs nothing more&lt;/strong&gt;: its package ships the one-line source that asks for
the implementation, and names it in &lt;code&gt;sources&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;#define STB_IMAGE_IMPLEMENTATION
#include &amp;quot;stb_image.h&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;linking-statically&quot;&gt;Linking statically&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A program whose manifest says &lt;code&gt;static-c-libraries = true&lt;/code&gt; links its C libraries from their static
archives&lt;/strong&gt;, so the machine it runs on needs none of them installed
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;settled&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;package { name = &amp;quot;tend&amp;quot;, version = &amp;quot;0.1.0&amp;quot; }

static-c-libraries = true

dependencies {
  ssh { git = &amp;quot;github.com/avin-lang/ssh&amp;quot;, version = &amp;quot;0.0.1&amp;quot; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The program decides, for every package in it.&lt;/strong&gt; Only the root package’s key is read: a library
package that says it is built dynamically into a program that does not, and a program that says
it links the C libraries of its dependencies statically too. Without the key, or with &lt;code&gt;false&lt;/code&gt;,
every library is linked as &lt;code&gt;pkg-config --libs&lt;/code&gt; answers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For each library a &lt;code&gt;pkg-config&lt;/code&gt; module finds, the build asks &lt;code&gt;pkg-config --static --libs&lt;/code&gt;, which
adds the libraries it links privately (&lt;code&gt;Libs.private&lt;/code&gt;: libssh2’s OpenSSL), and replaces each
&lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt; whose &lt;code&gt;lib&amp;lt;name&amp;gt;.a&lt;/code&gt; is in one of the answer’s &lt;code&gt;-L&lt;/code&gt; directories by the archive’s path, the
first directory holding one winning. &lt;strong&gt;The path, because on macOS the linker takes a &lt;code&gt;.dylib&lt;/code&gt; over
a &lt;code&gt;.a&lt;/code&gt; in the same directory&lt;/strong&gt;, and Homebrew installs both side by side. The &lt;code&gt;-L&lt;/code&gt; and run-path flags
are dropped; every other flag (&lt;code&gt;-framework&lt;/code&gt;, &lt;code&gt;-pthread&lt;/code&gt;) is kept.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The system’s own libraries stay dynamic.&lt;/strong&gt; A name none of the &lt;code&gt;-L&lt;/code&gt; directories holds is one the
linker finds by itself, in the system (libSystem and libz on macOS), and stays &lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt;, unless
the program names it in &lt;a href=&quot;#the-system-s-libraries&quot;&gt;&lt;code&gt;static-system&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A library &lt;code&gt;link&lt;/code&gt; names is linked the same way&lt;/strong&gt;, from its library’s &lt;code&gt;search&lt;/code&gt; directories: each
&lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt; whose &lt;code&gt;lib&amp;lt;name&amp;gt;.a&lt;/code&gt; is in one of them becomes the archive’s path, and a name none of them
holds is the system’s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A library with no archive stops the build.&lt;/strong&gt; A name whose shared library is in one of the
search directories but whose archive is in none would be linked dynamically, the very program the
key is there to prevent, so it is an error naming what is missing; &lt;code&gt;avin check&lt;/code&gt; reports it too:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the C library `libssh2` of package `ssh` is linked statically (`static-c-libraries = true`), but `-lcrypto`, which `pkg-config --static --libs libssh2` names, has no static archive: `/opt/homebrew/opt/openssl@4/lib/libcrypto.dylib` has no `libcrypto.a` beside it
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A file named by its path is linked as named&lt;/strong&gt;, an archive always statically. A shared library
(&lt;code&gt;.dylib&lt;/code&gt;, &lt;code&gt;.tbd&lt;/code&gt;, &lt;code&gt;.so&lt;/code&gt;) of a library linked statically is replaced by the archive of the same
name beside it, and is an error without one.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;otool -L&lt;/code&gt; is the check: a program binding libssh2 and built this way lists only
&lt;code&gt;/usr/lib/libSystem.B.dylib&lt;/code&gt; and &lt;code&gt;/usr/lib/libz.1.dylib&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;how-a-program-links-its-c-libraries&quot;&gt;How a program links its C libraries&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;The program chooses library by library in its &lt;code&gt;c-linking&lt;/code&gt; block&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;settled&lt;/a&gt;),
read from the root package only, as &lt;code&gt;static-c-libraries&lt;/code&gt; is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hocon&quot;&gt;c-linking {
  default       = &amp;quot;static&amp;quot;            # or &amp;quot;dynamic&amp;quot;, the default when unsaid
  dynamic       = [&amp;quot;mlt&amp;quot;]              # linked dynamically whatever the default
  static        = [&amp;quot;ssh/libssh2&amp;quot;]      # linked statically whatever the default
  static-system = [&amp;quot;z&amp;quot;]                # the system&apos;s libz, from its archive
  search        = [&amp;quot;/opt/homebrew/opt/zlib/lib&amp;quot;]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A library is named as its package’s &lt;code&gt;c-libraries&lt;/code&gt; names it&lt;/strong&gt;, &lt;code&gt;mlt&lt;/code&gt;, or with its package,
&lt;code&gt;ssh/libssh2&lt;/code&gt;, where two packages name libraries alike; a bare name names each library of that
name. A name that is no C library of the program is an error at the name, listing the program’s
libraries, and so is one name in both lists.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;default&lt;/code&gt; is how every library neither list names is linked.&lt;/strong&gt; &lt;code&gt;static-c-libraries = true&lt;/code&gt; is
&lt;code&gt;default = &amp;quot;static&amp;quot;&lt;/code&gt;, kept as its shorthand; a manifest saying both is refused, so there is never
a question which wins.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Linked dynamically means as named&lt;/strong&gt;: the flags &lt;code&gt;pkg-config --libs&lt;/code&gt; answers, &lt;code&gt;-L&lt;/code&gt; and &lt;code&gt;-l&lt;/code&gt; for
&lt;code&gt;link&lt;/code&gt; and &lt;code&gt;search&lt;/code&gt;, and &lt;code&gt;files&lt;/code&gt; as they are, so a vendored archive is linked statically either
way. &lt;strong&gt;Linked statically is a promise&lt;/strong&gt;: no shared library of a search directory is taken, and
one that would be is an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The command line overrides the default for one build.&lt;/strong&gt; &lt;code&gt;avin build&lt;/code&gt;, &lt;code&gt;run&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;check&lt;/code&gt;
take &lt;code&gt;--static-c-libraries&lt;/code&gt; or &lt;code&gt;--dynamic-c-libraries&lt;/code&gt;, which stand in for the manifest’s &lt;code&gt;default&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;a library &lt;code&gt;c-linking&lt;/code&gt; names in &lt;code&gt;static&lt;/code&gt; or &lt;code&gt;dynamic&lt;/code&gt; is linked that way;&lt;/li&gt;
&lt;li&gt;any other is linked as the command line says, when it says;&lt;/li&gt;
&lt;li&gt;and otherwise by the manifest’s &lt;code&gt;default&lt;/code&gt; (or &lt;code&gt;static-c-libraries&lt;/code&gt;), dynamically when it says none.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A name in the manifest is the program saying something about one library, often for a reason (a
licence, an archive that does not exist), so a flag about all of them does not overrule it. A build
cached by &lt;code&gt;avin run&lt;/code&gt; or &lt;code&gt;avin test&lt;/code&gt; is kept apart for each way of linking.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A library package may require being linked dynamically&lt;/strong&gt;, never statically, with
&lt;code&gt;dynamic-only = &amp;quot;&amp;lt;why&amp;gt;&amp;quot;&lt;/code&gt;. A program that would link it statically, by its &lt;code&gt;default&lt;/code&gt;, by
&lt;code&gt;--static-c-libraries&lt;/code&gt; or by naming it in &lt;code&gt;static&lt;/code&gt;, is refused with the package’s reason:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the C library `mlt` of package `mlt` is never linked statically, as its package says (`dynamic-only`): LGPL-2.1: its users may replace it; the program links it statically by `static-c-libraries = true`: name it in `c-linking { dynamic = [&amp;quot;mlt&amp;quot;] }` to link it dynamically
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Naming it in &lt;code&gt;dynamic&lt;/code&gt; is how the program says it has seen the requirement; the rest of the program
stays static. The library is not linked dynamically silently: a program asking to be static would
otherwise ship needing the library installed, and learn it on another machine.&lt;/p&gt;
&lt;h4 id=&quot;the-system-s-libraries&quot;&gt;The system’s libraries&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;static-system&lt;/code&gt; names &lt;code&gt;-l&lt;/code&gt; names the program links from their archives although the system
provides them&lt;/strong&gt;, an opt-in; without it the system’s libraries stay dynamic. Each name is looked for
as &lt;code&gt;lib&amp;lt;name&amp;gt;.a&lt;/code&gt; in the search directories of the library that links it, then in &lt;code&gt;c-linking&lt;/code&gt;‘s
&lt;code&gt;search&lt;/code&gt;, each absolute or relative to the root package’s directory (the program’s own machine is
its business, so absolute paths are allowed here and nowhere else). It applies however the library
is linked. A name found in none of them is an error listing the directories searched, and a name no
library of the program links is an error too.&lt;/p&gt;
&lt;h4 id=&quot;on-linux&quot;&gt;On Linux&lt;/h4&gt;
&lt;p&gt;Linux is not built yet. The surface maps onto its linker as follows: an archive is still linked by
its path, which needs no flag; a &lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt; kept for the system stays &lt;code&gt;-l&amp;lt;name&amp;gt;&lt;/code&gt;; and a name
&lt;code&gt;static-system&lt;/code&gt; asks for may equally be written &lt;code&gt;-Wl,-Bstatic -l&amp;lt;name&amp;gt; -Wl,-Bdynamic&lt;/code&gt;, which takes
&lt;code&gt;lib&amp;lt;name&amp;gt;.a&lt;/code&gt; from the linker’s own path. &lt;code&gt;frameworks&lt;/code&gt; are macOS’s alone, and a package for Linux
names none.&lt;/p&gt;
&lt;h2 id=&quot;prototypes&quot;&gt;Prototypes&lt;/h2&gt;
&lt;p&gt;The prototype is C’s declaration with three words of its own, which say what C’s types cannot. They
are written before the parameter’s type and removed before the header check:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Word&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;out&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A pointer C writes a value through; the value is part of the binding’s &lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;result&lt;/a&gt;, and the parameter is not an Avin parameter&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;inout&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A pointer C reads a value through and writes one back; an Avin parameter and part of the result&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;userdata&lt;/code&gt;&lt;/td&gt;&lt;td&gt;The &lt;code&gt;void *&lt;/code&gt; that travels beside a &lt;a href=&quot;#callbacks&quot;&gt;callback&lt;/a&gt;; not an Avin parameter&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A pointer, a function pointer among them, the binding &lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;passes null&lt;/a&gt;; not an Avin parameter&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;length(data)&lt;/code&gt; before an integer parameter says it is the length of the array parameter &lt;code&gt;data&lt;/code&gt;, and
it is filled in from the array rather than written by the caller. It is written first, before the
parameter’s type and before &lt;code&gt;inout&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A binding whose Avin result is &lt;code&gt;unit&lt;/code&gt; discards the C result, whatever it is. Every other C result is
converted.&lt;/p&gt;
&lt;h2 id=&quot;scalars&quot;&gt;Scalars&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;C type&lt;/th&gt;&lt;th&gt;Avin type&lt;/th&gt;&lt;th&gt;Crossing&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;signed char&lt;/code&gt;, &lt;code&gt;short&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;long long&lt;/code&gt;, &lt;code&gt;intN_t&lt;/code&gt;, &lt;code&gt;ssize_t&lt;/code&gt;, &lt;code&gt;ptrdiff_t&lt;/code&gt;, &lt;code&gt;intptr_t&lt;/code&gt; and their &lt;code&gt;unsigned&lt;/code&gt; forms, &lt;code&gt;size_t&lt;/code&gt;, &lt;code&gt;uintN_t&lt;/code&gt;, an integer typedef, an enum&lt;/td&gt;&lt;td&gt;any integer type&lt;/td&gt;&lt;td&gt;Converted with a check, in each direction, as a &lt;a href=&quot;/spec/sysl-bindings/#integer-results&quot;&gt;Sysl integer&lt;/a&gt; is: a value the other side cannot hold stops the program at the call, naming the C type by its sign and width&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;unsigned char&lt;/code&gt;, &lt;code&gt;uint8_t&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;byte&lt;/code&gt;&lt;/td&gt;&lt;td&gt;By value. A C &lt;code&gt;char&lt;/code&gt; as a value is a byte, whatever its sign on the machine&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;_Bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;By value&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;an integer type or typedef used as a truth value (Cairo’s &lt;code&gt;cairo_bool_t&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A result is &lt;code&gt;false&lt;/code&gt; for zero and &lt;code&gt;true&lt;/code&gt; otherwise; a parameter passes &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;double&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;By value&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;float&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;real&lt;/code&gt;&lt;/td&gt;&lt;td&gt;A parameter is rounded to the nearest &lt;code&gt;float&lt;/code&gt;, as C converts one; a result is widened exactly&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Avin has no unsigned integers, so a &lt;code&gt;size_t&lt;/code&gt; or a &lt;code&gt;uint32_t&lt;/code&gt; is a &lt;code&gt;long&lt;/code&gt; (or an &lt;code&gt;int&lt;/code&gt;, where the
values fit) and a negative value passed for one stops the program:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: value out of range for u64 (size_t) at main.avin:12:5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The width of &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;size_t&lt;/code&gt; and each typedef is the target’s, measured by the C unit; the check is
emitted for the widths measured. &lt;code&gt;long double&lt;/code&gt;, &lt;code&gt;_Complex&lt;/code&gt; types and vector types are refused.&lt;/p&gt;
&lt;p&gt;A typedef crosses as the Avin type of its kind, which the C unit checks: an integer typedef as an
integer type, one an integer one byte wide as &lt;code&gt;byte&lt;/code&gt;, a &lt;code&gt;bool&lt;/code&gt; as &lt;code&gt;bool&lt;/code&gt;, and a &lt;code&gt;float&lt;/code&gt; or a &lt;code&gt;double&lt;/code&gt;
as &lt;code&gt;real&lt;/code&gt;. &lt;code&gt;signed char&lt;/code&gt; crosses only as an integer type, and &lt;code&gt;char&lt;/code&gt; only as &lt;code&gt;byte&lt;/code&gt;. A result one past
what the binding’s Avin type holds stops the program naming that type, as a Sysl binding’s does:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: value out of range for long at main.avin:13:13
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;strings&quot;&gt;Strings&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;const char *&lt;/code&gt; parameter takes a &lt;code&gt;string&lt;/code&gt;&lt;/strong&gt;, copied into NUL-terminated memory that lives for
the call, and until its result is converted, since C may answer a pointer into it (&lt;code&gt;strchr&lt;/code&gt;). A
string holding U+0000 stops the program at the call, since C would read the NUL as its end:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: the string passed to `name` of `set` holds a NUL at byte 3 at main.avin:9:5
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;char *&lt;/code&gt; result, or a &lt;code&gt;const char *&lt;/code&gt; one, is copied into a new &lt;code&gt;string&lt;/code&gt;&lt;/strong&gt;, up to its NUL. The
bytes must be UTF-8; text that is not stops the program at the call, naming the byte the first
ill-formed sequence starts at:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `mlt_properties_get` answered a string that is not UTF-8 at byte 2 at main.avin:7:9
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A binding that wants the bytes as they are answers &lt;code&gt;Array[byte]&lt;/code&gt; instead, copied up to the NUL,
and nothing is checked.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;C keeps its own string.&lt;/strong&gt; A string C answers is borrowed: it is copied and left as it was. One the
caller must free is bound with &lt;code&gt;free:&lt;/code&gt; naming the function that frees it, called once the copy is
made: &lt;code&gt;@c(&amp;quot;char *mlt_properties_serialise_yaml(mlt_properties self)&amp;quot;, free: &amp;quot;free&amp;quot;)&lt;/code&gt;. The C unit
checks that the headers declare it taking the string or any pointer and answering nothing; it is
not called for null. A binding with &lt;code&gt;free:&lt;/code&gt; whose result is &lt;code&gt;unit&lt;/code&gt; frees what C answered and
discards it (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A string C answers through an &lt;code&gt;out&lt;/code&gt; pointer is freed by an entry of &lt;code&gt;free:&lt;/code&gt; naming it&lt;/strong&gt;
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): &lt;code&gt;&amp;quot;name: how&amp;quot;&lt;/code&gt;, &lt;code&gt;how&lt;/code&gt; a C function of the string or a C
expression in its name, compiled in the C unit’s glue and called once the copy is made, never for
null; where a status fails, a string C answered is freed unread. A method’s expression may also use
&lt;code&gt;self&lt;/code&gt;, its receiver’s &lt;code&gt;kept:&lt;/code&gt; name and the values the receiver &lt;a href=&quot;#values-a-handle-holds&quot;&gt;holds&lt;/a&gt;, as
its class’s &lt;code&gt;release:&lt;/code&gt; does. libssh2 answers a channel’s exit signal and its message in strings
freed by &lt;code&gt;libssh2_free(session, p)&lt;/code&gt;, and the session is the one the channel keeps:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
  &amp;quot;int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *self, out char **exitsignal, out size_t *exitsignal_len, out char **errmsg, out size_t *errmsg_len, null char **langtag, null size_t *langtag_len)&amp;quot;,
  free: [&amp;quot;exitsignal: libssh2_free(session, exitsignal)&amp;quot;, &amp;quot;errmsg: libssh2_free(session, errmsg)&amp;quot;]
)
private exitSignalRaw() -&amp;gt; Result[(Option[string], long, Option[string], long), int]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;free:&lt;/code&gt; names each out string once, an &lt;code&gt;out&lt;/code&gt; one answering a string or its bytes, never &lt;code&gt;inout&lt;/code&gt;,
since C may answer the copy it was passed; an entry without a name frees the result as before, and a
binding whose &lt;code&gt;array:&lt;/code&gt; names arrays frees them by position and no out string besides.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A typedef of either pointer crosses as the header’s type is&lt;/strong&gt;: as a result a &lt;code&gt;char *&lt;/code&gt; or a
&lt;code&gt;const char *&lt;/code&gt; typedef, as a parameter only a &lt;code&gt;const char *&lt;/code&gt; one, which the C unit checks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;So does one pointer to a typedef of &lt;code&gt;char&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;), as
FreeType’s &lt;code&gt;const FT_String *&lt;/code&gt; is (&lt;code&gt;typedef char FT_String&lt;/code&gt;): through a chain of typedefs, with
&lt;code&gt;const&lt;/code&gt; before the typedef, after it or inside it (&lt;code&gt;typedef const char T&lt;/code&gt;), at a parameter, a
result, an &lt;code&gt;out&lt;/code&gt; value, a callback’s parameter and a field, wherever &lt;code&gt;char *&lt;/code&gt; and &lt;code&gt;const char *&lt;/code&gt;
cross as a string. Only the headers say what the typedef is, so the C unit checks the whole
pointer is &lt;code&gt;char *&lt;/code&gt; or &lt;code&gt;const char *&lt;/code&gt; by the rule above; a typedef of &lt;code&gt;unsigned char&lt;/code&gt; or
&lt;code&gt;signed char&lt;/code&gt; holds bytes rather than text, and is refused saying so
(&lt;code&gt;the C type `const FT_Byte *` of the result points at `unsigned char` or `signed char` in the headers, which hold bytes rather than text&lt;/code&gt;), as a field pointing at either is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A &lt;code&gt;char *&lt;/code&gt; parameter, which C may write, does not take a &lt;code&gt;string&lt;/code&gt;: it takes an
&lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;array&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;null&quot;&gt;Null&lt;/h2&gt;
&lt;p&gt;A pointer C may answer null is bound as an &lt;code&gt;Option&lt;/code&gt;: null is &lt;code&gt;None&lt;/code&gt;. Bound as the type itself, a null
result stops the program at the call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `mlt_profile_init` answered null at main.avin:4:15
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A pointer parameter bound as an &lt;code&gt;Option&lt;/code&gt; passes null for &lt;code&gt;None&lt;/code&gt;. Strings, handles and arrays may each
be wrapped this way, and so may a &lt;a href=&quot;#structs-by-pointer&quot;&gt;mirror passed by &lt;code&gt;const&lt;/code&gt; pointer&lt;/a&gt;; nothing
else is.&lt;/p&gt;
&lt;h2 id=&quot;status-results&quot;&gt;Status results&lt;/h2&gt;
&lt;p&gt;C reports most failures as an integer. A C integer result bound as &lt;code&gt;Result[unit, int]&lt;/code&gt; is &lt;code&gt;Ok(())&lt;/code&gt;
when it is zero and &lt;code&gt;Err(code)&lt;/code&gt; otherwise. The code may be any integer type, converted with the check
a scalar result has (&lt;code&gt;Result[unit, long]&lt;/code&gt; for a &lt;code&gt;long long&lt;/code&gt; status). With &lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;out parameters&lt;/a&gt;, a status result
bound as &lt;code&gt;Result[T, int]&lt;/code&gt; holds the out values in its &lt;code&gt;Ok&lt;/code&gt;, and they are read only when the status is
zero. A function that answers -1 and says why in &lt;code&gt;errno&lt;/code&gt; is bound &lt;a href=&quot;#errno&quot;&gt;with &lt;code&gt;errno&lt;/code&gt;&lt;/a&gt;; other
conventions, a negative error number among them, are written in Avin over the integer, and a public
function maps the code to the library’s own error type.&lt;/p&gt;
&lt;p&gt;A status that is a C enum may be bound as &lt;code&gt;Result[unit, E]&lt;/code&gt; with &lt;code&gt;E&lt;/code&gt; its &lt;a href=&quot;#enums-and-constants&quot;&gt;mirror&lt;/a&gt;:
&lt;code&gt;Ok(())&lt;/code&gt; for the enumerator whose value is zero, &lt;code&gt;Err&lt;/code&gt; of the variant otherwise. The mirror keeps its
zero variant, since the same type is what a &lt;a href=&quot;#callbacks&quot;&gt;callback&lt;/a&gt; answers C with
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(&amp;quot;cairo_status_t cairo_surface_write_to_png(cairo_surface_t *self, const char *filename)&amp;quot;)
private writePngRaw(filename: string) -&amp;gt; Result[unit, Status]
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;errno&quot;&gt;errno&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A binding marked &lt;code&gt;errno&lt;/code&gt; answers &lt;code&gt;Err&lt;/code&gt; of &lt;code&gt;errno&lt;/code&gt; where C answers -1&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#settled&quot;&gt;settled&lt;/a&gt;).
The word is written among &lt;code&gt;@c&lt;/code&gt;‘s arguments, as &lt;code&gt;blocking&lt;/code&gt; is, and the binding answers a &lt;code&gt;Result&lt;/code&gt;:
&lt;code&gt;Ok&lt;/code&gt; of what the C result and the out values make, by the rules for a result that is
&lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;not a status&lt;/a&gt; (the C result kept as an integer or left out, followed by
the out values), and &lt;code&gt;Err&lt;/code&gt; of why. The error is an &lt;code&gt;avin.c.Errno&lt;/code&gt;, each POSIX error number by its
own name, &lt;code&gt;ENOENT&lt;/code&gt;, &lt;code&gt;ESRCH&lt;/code&gt;, &lt;code&gt;EACCES&lt;/code&gt;, whatever value it has on the machine the program is built for,
which the C unit measures, and &lt;code&gt;Other(code)&lt;/code&gt; for a number no named case is; or it is the number
itself, any integer type. An &lt;code&gt;Errno&lt;/code&gt; is an &lt;code&gt;Error&lt;/code&gt;, whose message is the number’s sentence, the same
on every platform (&lt;code&gt;no such process&lt;/code&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.c.{Errno, ENOENT, EACCES}

@c(&amp;quot;int access(const char *path, int mode)&amp;quot;, errno)
private access(path: string, mode: int) -&amp;gt; Result[unit, Errno]

describe(path: string) -&amp;gt; string = access(path, 4) match
  Ok(()) -&amp;gt; &amp;quot;readable&amp;quot;
  Err(ENOENT) -&amp;gt; &amp;quot;missing&amp;quot;
  Err(EACCES) -&amp;gt; &amp;quot;forbidden&amp;quot;
  Err(e) -&amp;gt; e.message
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;errno&lt;/code&gt; is read by the binding’s glue in the C unit straight after the call, before anything else
runs, a &lt;code&gt;length:&lt;/code&gt; expression and a &lt;code&gt;blocking&lt;/code&gt; call’s return among them, so what it holds is what the
function left. It is read only where the C result is -1, which is the failure, whatever &lt;code&gt;errno&lt;/code&gt;
holds; a function that sets &lt;code&gt;errno&lt;/code&gt; and answers anything else has not failed, and the out values are
read only where it has not, as a status’s are. A C result of an unsigned type fails at its greatest
value, which -1 converts to. A binding marked &lt;code&gt;errno&lt;/code&gt; answers a &lt;code&gt;Result&lt;/code&gt; whose error is an &lt;code&gt;Errno&lt;/code&gt; or
an integer, over a C integer result, and its &lt;code&gt;Ok&lt;/code&gt; holds no status of its own; each is refused at the
binding otherwise:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the result of the C binding `text` is `Result[string, Errno]` in Avin and `const char *` in C: `errno` marks a C function that answers -1 where it fails, so its result is a C integer
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;errors-kept-on-the-object&quot;&gt;Errors kept on the object&lt;/h3&gt;
&lt;p&gt;Some libraries do not answer a failure at all: they &lt;strong&gt;latch&lt;/strong&gt; it on the object, which turns inert, and
answer it when asked. Every Cairo call on a context or surface in error does nothing, and a
constructor that fails answers a static object in an error state rather than null. A binding needs
nothing new for this: the query is bound like any other (&lt;code&gt;@c(&amp;quot;cairo_status_t cairo_status(cairo_t *self)&amp;quot;) status() -&amp;gt; Result[unit, Status]&lt;/code&gt;), and the library’s public functions
ask it where the user can act on the answer — after a constructor, before output is produced, and on
request — while the drawing calls answer &lt;code&gt;unit&lt;/code&gt;. A latched error is never lost, since every later
query answers it, so checking at those points sees every failure the calls before them made.&lt;/p&gt;
&lt;h2 id=&quot;handles&quot;&gt;Handles&lt;/h2&gt;
&lt;p&gt;A C object Avin holds without seeing inside is a &lt;strong&gt;handle&lt;/strong&gt;: a &lt;code&gt;class&lt;/code&gt; declared with &lt;code&gt;@c(type: …)&lt;/code&gt;
naming the C pointer type, and the function that gives the object back:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;mlt_producer&amp;quot;, release: &amp;quot;mlt_producer_close&amp;quot;, retain: &amp;quot;mlt_properties_inc_ref(mlt_producer_properties(self))&amp;quot;)
class Producer
  @c(&amp;quot;int mlt_producer_get_length(mlt_producer self)&amp;quot;)
  length() -&amp;gt; int
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A handle is the &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl handle&lt;/a&gt; over a C pointer, and keeps its rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Only a binding makes a handle&lt;/strong&gt;, and &lt;strong&gt;each handle owns one reference&lt;/strong&gt; to its C object, given
back by &lt;code&gt;release&lt;/code&gt; exactly once: by &lt;code&gt;close()&lt;/code&gt;, or by the collector’s finalizer when the object is
freed. Closing again does nothing; a closed handle used stops the program at the call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;release&lt;/code&gt; and &lt;code&gt;retain&lt;/code&gt; name a C function of the handle’s pointer, or a C expression in &lt;code&gt;self&lt;/code&gt;&lt;/strong&gt;,
compiled in the C unit’s glue and type-checked there by clang.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A pointer C answers is owned by default&lt;/strong&gt;: the handle takes the reference the call gave. A
binding whose pointer C only lends — MLT’s &lt;code&gt;mlt_playlist_get_clip&lt;/code&gt;, &lt;code&gt;mlt_tractor_get_track&lt;/code&gt; — says
&lt;code&gt;borrowed&lt;/code&gt;, and the handle takes a reference of its own through &lt;code&gt;retain&lt;/code&gt; before it is made. A
handle with no &lt;code&gt;retain&lt;/code&gt; cannot be borrowed, and the binding is refused, since nothing could keep
the lent object alive:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the C binding `clip` lends a `Producer`, and `Producer` declares no `retain`: a lent object is kept only by a reference of its own
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle passed to C is lent for the call.&lt;/strong&gt; C’s own convention is that a pointer it is handed is
borrowed, and most functions keep to it. One that &lt;strong&gt;keeps&lt;/strong&gt; what it is handed past the call — MLT’s
producers keep a pointer to their profile and take no reference to it — is bound with &lt;code&gt;keeps:&lt;/code&gt;
naming the parameter, or a list of them (&lt;code&gt;keeps: [&amp;quot;library&amp;quot;, &amp;quot;base&amp;quot;]&lt;/code&gt;): the handle the binding
makes (or, for a method, the receiver) then holds the
Avin object passed, so it is not collected while the holder lives; a kept handle whose class
declares &lt;code&gt;retain&lt;/code&gt; is held by &lt;a href=&quot;#kept-handles-and-the-order-they-are-given-back&quot;&gt;a C reference&lt;/a&gt;
instead. One that &lt;strong&gt;takes&lt;/strong&gt; the reference
it is handed is bound with &lt;code&gt;consumes:&lt;/code&gt;, and the handle passed is closed by the call without
&lt;code&gt;release&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle belongs to one owner at a time&lt;/strong&gt;, checked at every use as a Sysl handle’s is: C
libraries rarely let two threads use one object at once. A class whose C object is safe to use from
any thread is declared &lt;code&gt;shared&lt;/code&gt;; its owner is not checked, and it is
&lt;a href=&quot;/spec/actors/#what-may-be-sent&quot;&gt;sendable&lt;/a&gt;. Whether a handle passed across threads hands its
ownership on follows the &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl handle’s rule&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle is compared by identity&lt;/strong&gt;, and has no &lt;code&gt;Display&lt;/code&gt; of its own.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle’s own method without a body is a C binding&lt;/strong&gt; whose prototype takes the receiver first,
named &lt;code&gt;self&lt;/code&gt;, and the method’s parameters after it, by position; a method with a body is an
ordinary method and may call the bound ones. &lt;code&gt;shared&lt;/code&gt; is written among the class’s words,
&lt;code&gt;@c(type: …, release: …, shared)&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What keeps is the handle the binding answers&lt;/strong&gt;, and for a method that answers none, its
receiver; a method answering a handle names its receiver as &lt;code&gt;self&lt;/code&gt; to have the new handle keep it
(&lt;code&gt;@c(&amp;quot;FT_Error FT_Get_MM_Var(FT_Face self, …)&amp;quot;, keeps: &amp;quot;self&amp;quot;)&lt;/code&gt;). What a call keeps is kept only
when it succeeds: the handle answered is not null, or the status answered is zero. &lt;strong&gt;&lt;code&gt;consumes:&lt;/code&gt;
closes the handle passed whatever the call answers&lt;/strong&gt;, and it may name &lt;code&gt;self&lt;/code&gt;; what a consumed
handle keeps it goes on keeping until it is collected or closed
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A parameter may take a handle as its class’s C type &lt;code&gt;const&lt;/code&gt;-qualified&lt;/strong&gt; (&lt;code&gt;const cairo_t *&lt;/code&gt;),
the same pointer to C; a result answers exactly the class’s type.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;when-c-holds-the-object-longer-than-avin-does&quot;&gt;When C holds the object longer than Avin does&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;keeps:&lt;/code&gt; holds the kept object on the Avin handle, and that is enough while the handle’s reference is
the C object’s last. It is not enough where C takes references of its own: a Cairo context and a
surface pattern each reference their surface, so the Avin &lt;code&gt;Surface&lt;/code&gt; may be collected, and its
reference given back, while C still draws into the surface — and into the pixel memory or font file
the surface was made over. A library that tells its objects’ owner when C frees one (Cairo’s
&lt;code&gt;cairo_surface_set_user_data&lt;/code&gt;, MLT’s &lt;code&gt;mlt_properties_set_data&lt;/code&gt; with a destructor) lets the binding
tie a kept object to &lt;strong&gt;the C object’s&lt;/strong&gt; lifetime instead, with &lt;code&gt;attach:&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    type: &amp;quot;cairo_surface_t *&amp;quot;,
    release: &amp;quot;cairo_surface_destroy&amp;quot;,
    retain: &amp;quot;cairo_surface_reference&amp;quot;,
    attach: &amp;quot;cairo_surface_set_user_data(self, key, data, destroy)&amp;quot;,
    key: &amp;quot;cairo_user_data_key_t&amp;quot;
)
class Surface
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;attach:&lt;/code&gt; is a C expression, compiled in the glue, over four names: &lt;code&gt;self&lt;/code&gt;; &lt;code&gt;key&lt;/code&gt;, the address of a
static object of the type &lt;code&gt;key:&lt;/code&gt; names, one per class, defined by the C unit; &lt;code&gt;data&lt;/code&gt;, the address of
the runtime’s record of what the handle keeps; and &lt;code&gt;destroy&lt;/code&gt;, the runtime’s function that releases the
record. On a class with &lt;code&gt;attach:&lt;/code&gt;, the first &lt;code&gt;keeps:&lt;/code&gt; of a C object puts its kept objects in that
record, made a root of the collector, and attaches it; C’s call of &lt;code&gt;destroy&lt;/code&gt;, whenever and on whichever
thread the last reference goes, unpins it, and runs no Avin code. An &lt;code&gt;attach:&lt;/code&gt; expression that answers
non-zero stops the program at the call, since what it would keep could not be kept. Without &lt;code&gt;attach:&lt;/code&gt;,
&lt;code&gt;keeps:&lt;/code&gt; holds only as long as the handle (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A binding answering its handle in a &lt;code&gt;Result[H, E]&lt;/code&gt; answers that failure instead&lt;/strong&gt;
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): &lt;code&gt;Ok&lt;/code&gt; of the handle where C was told, and otherwise &lt;code&gt;Err&lt;/code&gt; of
what &lt;code&gt;attach:&lt;/code&gt; answered — &lt;code&gt;E&lt;/code&gt; an integer type, checked against its width, or an enum mirror, a value no
variant holds stopping the program — the handle’s reference given back and nothing kept. Cairo answers
a surface it could not make as a surface in an error state, and &lt;code&gt;cairo_surface_set_user_data&lt;/code&gt; on it
answers that surface’s status, so the status comes back as the error, with no check before the call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    &amp;quot;cairo_surface_t *cairo_image_surface_create_for_data(unsigned char *pixels, cairo_format_t format, int width, int height, int stride)&amp;quot;,
    keeps: &amp;quot;pixels&amp;quot;
)
private surfaceForData(
    pixels: ByteBlock,
    format: Format,
    width: int,
    height: int,
    stride: int
) -&amp;gt; Result[Surface, Status]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Such a binding answers no out values, its handle is never in an &lt;code&gt;Option&lt;/code&gt;, its class has &lt;code&gt;attach:&lt;/code&gt; and
it keeps something; a C result that is null still stops the program.&lt;/p&gt;
&lt;p&gt;The record belongs to one handle object: a later &lt;code&gt;keeps:&lt;/code&gt; through the same handle adds to it, and the
handle lets go of it when its reference goes back, by &lt;code&gt;close()&lt;/code&gt; or its finalizer, while C keeps it until
&lt;code&gt;destroy&lt;/code&gt;. On such a class every kept object, a handle or a &lt;code&gt;ByteBlock&lt;/code&gt;, is held as the Avin object, so
a kept handle’s own reference lives as long as the record. &lt;code&gt;key:&lt;/code&gt; may be left out, and &lt;code&gt;key&lt;/code&gt; is then the
address of a &lt;code&gt;char&lt;/code&gt; of the class’s own; &lt;code&gt;attach:&lt;/code&gt; must name &lt;code&gt;self&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt; and &lt;code&gt;destroy&lt;/code&gt;, &lt;code&gt;key:&lt;/code&gt; comes
only with &lt;code&gt;attach:&lt;/code&gt;, and a &lt;code&gt;shared&lt;/code&gt; class has no &lt;code&gt;attach:&lt;/code&gt;, since the handle’s owner alone updates the
record (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;kept-handles-and-the-order-they-are-given-back&quot;&gt;Kept handles, and the order they are given back&lt;/h3&gt;
&lt;p&gt;The collector frees what is unreachable in no order of its own: a holder and the handle it keeps,
found dead in one collection, are finalized in either order. That is harmless where the holder’s
&lt;code&gt;release&lt;/code&gt; never touches what it keeps, and a use after free where it does. A FreeType face belongs to
its library, freeing the library frees every face still in it, and &lt;code&gt;FT_Done_Face&lt;/code&gt; on one of them
afterwards frees it twice.&lt;/p&gt;
&lt;p&gt;So &lt;strong&gt;a kept handle whose class declares &lt;code&gt;retain&lt;/code&gt; is held by a C reference&lt;/strong&gt;
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): when the call succeeds the holder takes a reference of its
own through the kept class’s &lt;code&gt;retain&lt;/code&gt;, records the C pointer, and gives it back through that class’s
&lt;code&gt;release&lt;/code&gt; &lt;strong&gt;after its own &lt;code&gt;release&lt;/code&gt;&lt;/strong&gt;. Whichever finalizer the collector runs first, C sees the holder
released before what it keeps. FreeType counts both its libraries (&lt;code&gt;FT_Reference_Library&lt;/code&gt;) and its
faces (&lt;code&gt;FT_Reference_Face&lt;/code&gt;), so a face keeps its library this way. &lt;strong&gt;The &lt;code&gt;release&lt;/code&gt; gives back one
reference and no more&lt;/strong&gt;: &lt;code&gt;FT_Done_Library&lt;/code&gt; drops the count and frees the library with its last, so
the library’s own handle, given back while a face still holds a reference, only drops a count.
&lt;code&gt;FT_Done_FreeType&lt;/code&gt;, the pair of &lt;code&gt;FT_Init_FreeType&lt;/code&gt;, is not a &lt;code&gt;release&lt;/code&gt;: after dropping the count it
frees the library’s memory manager whatever the count is, and a face kept past it allocates through
freed memory at its next load:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;FT_Library&amp;quot;, release: &amp;quot;FT_Done_Library&amp;quot;, retain: &amp;quot;FT_Reference_Library&amp;quot;)
class Library

@c(&amp;quot;FT_Error FT_New_Face(FT_Library library, const char *path, FT_Long index, out FT_Face *face)&amp;quot;, keeps: &amp;quot;library&amp;quot;)
private newFace(library: Library, path: string, index: long) -&amp;gt; Result[Face, int]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The holder also takes a reference to each C object the kept handle so holds&lt;/strong&gt;, after the kept
one’s, and gives them back after it (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A variation descriptor
keeping a face keeps the face’s library too, so when the face’s own handle is collected first, and
gives back its reference to the library, the library still outlives the face the descriptor’s
&lt;code&gt;release&lt;/code&gt; reaches through.&lt;/p&gt;
&lt;p&gt;A kept handle with no &lt;code&gt;retain&lt;/code&gt; that no &lt;code&gt;kept:&lt;/code&gt; names, a &lt;code&gt;ByteBlock&lt;/code&gt; and a callback’s closure are held
as the Avin object, as before, and the holder’s &lt;code&gt;release&lt;/code&gt; must not use them: that is taken on
&lt;a href=&quot;#soundness&quot;&gt;trust&lt;/a&gt;. One a &lt;code&gt;kept:&lt;/code&gt; names is kept for the holder’s release, as below.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A holder’s &lt;code&gt;release&lt;/code&gt; may name what it keeps.&lt;/strong&gt; A class declaring &lt;code&gt;kept: &amp;quot;face: Face&amp;quot;&lt;/code&gt; is made only
by bindings that keep exactly one &lt;code&gt;Face&lt;/code&gt;, and its &lt;code&gt;release:&lt;/code&gt; and &lt;code&gt;retain:&lt;/code&gt; may use &lt;code&gt;face&lt;/code&gt; as that
handle’s C pointer, valid until after &lt;code&gt;release&lt;/code&gt; since the reference to it is given back last. A
FreeType variation descriptor is freed through the library its face belongs to, and FreeType
publishes that library in the face’s glyph slot:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;FT_MM_Var *&amp;quot;, kept: &amp;quot;face: Face&amp;quot;, release: &amp;quot;FT_Done_MM_Var(face-&amp;gt;glyph-&amp;gt;library, self)&amp;quot;)
class MMVar

@c(&amp;quot;FT_Error FT_Get_MM_Var(FT_Face face, out FT_MM_Var **master)&amp;quot;, keeps: &amp;quot;face&amp;quot;)
private mmVar(face: Face) -&amp;gt; Result[MMVar, int]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A class with &lt;code&gt;kept:&lt;/code&gt; made by a binding that does not keep one handle of that class is refused at the
binding, as is a &lt;code&gt;kept:&lt;/code&gt; name that &lt;code&gt;release:&lt;/code&gt; and &lt;code&gt;retain:&lt;/code&gt; never use. The class &lt;code&gt;kept:&lt;/code&gt; names is a C
handle of the holder’s module, or one written with its module (&lt;code&gt;freetype.Face&lt;/code&gt;). &lt;code&gt;retain:&lt;/code&gt; sees the
name where it takes the reference of a &lt;code&gt;borrowed&lt;/code&gt; result, as the pointer of the handle the binding
keeps (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A kept handle no C reference can hold is kept from the collector until the holder’s &lt;code&gt;release&lt;/code&gt; has
run&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): one whose class declares no &lt;code&gt;retain&lt;/code&gt;, or a &lt;code&gt;kept:&lt;/code&gt; of its
own. libssh2 counts no references: a channel belongs to its session, &lt;code&gt;libssh2_session_free&lt;/code&gt; frees
every channel still open, and &lt;code&gt;libssh2_channel_free&lt;/code&gt; reaches through the channel to its session. So
the channel’s class names its session with &lt;code&gt;kept:&lt;/code&gt;, and the session’s handle is held as its Avin
object, a root of every collection while the channel’s handle holds it; the collector may find both
dead at once, and finalizes the channel then and the session in a later collection. &lt;strong&gt;The name is the
kept handle’s pointer, or null once that handle was closed&lt;/strong&gt;, so a release that must not run after
the kept object’s own says so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;LIBSSH2_CHANNEL *&amp;quot;, kept: &amp;quot;session: Session&amp;quot;, release: &amp;quot;session ? libssh2_channel_free(self) : 0&amp;quot;)
class Channel
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A chain is given back in its order: a handle keeping a channel this way is finalized first, the
channel in the next collection and the session in the one after. What the closed handle freed with
it is the release’s to know; only its own pointer is passed. &lt;strong&gt;A cycle through such a kept handle is
never collected&lt;/strong&gt;: a session whose handle keeps, as its Avin object, a channel that keeps the session
this way is reachable from the channel’s root for as long as both are open, and both are given back
once either is closed (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). The handle is kept by one root for each
holder, and a holder closed lets go of its own at once.&lt;/p&gt;
&lt;h3 id=&quot;values-a-handle-holds&quot;&gt;Values a handle holds&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A handle may hold C integers for its &lt;code&gt;release:&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;), declared by
its class with &lt;code&gt;holds:&lt;/code&gt;, a C declaration or a list of them, each starting at the value written
(&lt;code&gt;= -1&lt;/code&gt;) or zero. A binding names with &lt;code&gt;hold:&lt;/code&gt; the parameters whose values the handle it answers, or
for a method answering none its receiver, holds, when the call succeeds, converted to the declared
type; a later &lt;code&gt;hold:&lt;/code&gt; of the same name replaces the value. &lt;code&gt;release:&lt;/code&gt; uses each by its name.&lt;/p&gt;
&lt;p&gt;libssh2 is handed the socket of a session and never closes it, and &lt;code&gt;libssh2_session_free&lt;/code&gt; writes to
it. An Avin &lt;code&gt;TcpStream&lt;/code&gt; closes its socket when it is closed or collected, and its descriptor’s number
goes to the next one opened, so a session given the stream’s own descriptor could write its farewell
into an unrelated connection. Given a descriptor of its own, &lt;code&gt;dup&lt;/code&gt;ed from the stream’s, the session
owns what its release writes to, whichever is collected first and whether or not the stream was
closed before it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
  type: &amp;quot;LIBSSH2_SESSION *&amp;quot;,
  holds: &amp;quot;int sock = -1&amp;quot;,
  release: &amp;quot;(libssh2_session_set_blocking(self, 1), libssh2_session_free(self), sock &amp;gt;= 0 ? close(sock) : 0)&amp;quot;
)
class Session
  @c(&amp;quot;int libssh2_session_handshake(LIBSSH2_SESSION *self, int sock)&amp;quot;, hold: &amp;quot;sock&amp;quot;)
  private handshakeRaw(sock: int) -&amp;gt; Result[unit, int]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value held is a C integer, no wider than a pointer, never a reference: what it names is the
release’s to give back, and a holder holds nothing for another. A class with &lt;code&gt;holds:&lt;/code&gt; is not &lt;code&gt;shared&lt;/code&gt;,
since only the handle’s owner sets what it holds, and declares no &lt;code&gt;retain:&lt;/code&gt;, since what it holds is the
one handle’s. Each name is used by &lt;code&gt;release:&lt;/code&gt;, and is neither &lt;code&gt;self&lt;/code&gt; nor the &lt;code&gt;kept:&lt;/code&gt; name; &lt;code&gt;hold:&lt;/code&gt;
names integer parameters, on a binding answering a handle or a method of one whose class declares
each name.&lt;/p&gt;
&lt;h3 id=&quot;handles-of-another-package&quot;&gt;Handles of another package&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A binding may take or answer a handle class another package declares&lt;/strong&gt;
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;), when its package depends on that one and the class is
public. Cairo’s FreeType font faces are made from FreeType’s &lt;code&gt;FT_Face&lt;/code&gt;, so &lt;code&gt;avin-lang/cairo&lt;/code&gt; depends
on &lt;code&gt;avin-lang/freetype&lt;/code&gt; and names its &lt;code&gt;Face&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;module cairo

import freetype.Face

@c(&amp;quot;cairo_font_face_t *cairo_ft_font_face_create_for_ft_face(FT_Face face, int load_flags)&amp;quot;, keeps: &amp;quot;face&amp;quot;)
private ftFontFace(face: Face, loadFlags: int) -&amp;gt; FontFace
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The prototype names the class’s own C type&lt;/strong&gt;, or one of its &lt;code&gt;as:&lt;/code&gt; types, by the rule for any
handle; the class’s &lt;code&gt;type:&lt;/code&gt;, &lt;code&gt;retain&lt;/code&gt;, &lt;code&gt;release&lt;/code&gt; and &lt;code&gt;as:&lt;/code&gt; glue are the declaring package’s, compiled
once in the C unit, and called by the other package’s bindings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The C unit checks the binding with the declaring package’s headers and flags first&lt;/strong&gt;: a
package’s bindings are compiled after the &lt;code&gt;headers&lt;/code&gt; of every package whose handle classes they
name, in dependency order, and with those packages’ &lt;code&gt;pkg-config&lt;/code&gt; flags beside its own, so &lt;code&gt;FT_Face&lt;/code&gt;
is declared whether or not Cairo’s header includes FreeType’s. A header included twice is guarded by
the header itself, as C’s always are.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ownership crosses unchanged.&lt;/strong&gt; A handle passed is lent for the call, and &lt;code&gt;keeps:&lt;/code&gt;, &lt;code&gt;consumes:&lt;/code&gt; and
&lt;code&gt;attach:&lt;/code&gt; hold, take or tie it exactly as they would a handle of the binding’s own package; a
pointer answered makes the declaring class’s handle, owned, or &lt;code&gt;borrowed&lt;/code&gt; through its &lt;code&gt;retain&lt;/code&gt;. The
owner check is the handle’s own, whichever package’s binding uses it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A binding naming a handle class of a package its own does not depend on cannot name it at all, since
the class is not in scope; one naming a private class is refused as any use of it is.&lt;/p&gt;
&lt;h3 id=&quot;handles-and-c-s-inheritance&quot;&gt;Handles and C’s inheritance&lt;/h3&gt;
&lt;p&gt;C libraries model inheritance by a struct whose first member is its parent: an MLT producer is a
service, and a service is a property bag. A handle declares the other C types it may be passed as,
each with the C function or expression that makes one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    type: &amp;quot;mlt_playlist&amp;quot;,
    release: &amp;quot;mlt_playlist_close&amp;quot;,
    retain: &amp;quot;mlt_properties_inc_ref(mlt_playlist_properties(self))&amp;quot;,
    as: [
      &amp;quot;mlt_producer = mlt_playlist_producer(self)&amp;quot;,
      &amp;quot;mlt_service = mlt_playlist_service(self)&amp;quot;,
      &amp;quot;mlt_properties = mlt_playlist_properties(self)&amp;quot;
    ]
)
class Playlist
  @c(&amp;quot;int mlt_properties_set_int(mlt_properties self, const char *name, int value)&amp;quot;)
  setInt(name: string, value: int) -&amp;gt; Result[unit, int]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A handle is passed where a prototype names one of its &lt;code&gt;as&lt;/code&gt; types, receiver or parameter, through
that conversion; the conversion lends, and the handle stays the owner. A method whose receiver’s C
type is neither the handle’s type nor an &lt;code&gt;as&lt;/code&gt; type is refused at the method.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An entry is a C pointer type, &lt;code&gt;=&lt;/code&gt;, and a C function of the handle’s pointer or an expression in
&lt;code&gt;self&lt;/code&gt;&lt;/strong&gt;, as &lt;code&gt;release:&lt;/code&gt; is: &lt;code&gt;&amp;quot;mlt_service = mlt_playlist_service&amp;quot;&lt;/code&gt; calls the function with the
handle’s pointer. &lt;code&gt;as:&lt;/code&gt; is one string or a list; each type is named once, and never the class’s
own. The C unit compiles each into glue and checks that what the expression makes &lt;strong&gt;is&lt;/strong&gt; the
entry’s type, so a conversion to the wrong type is refused at the class rather than passing C the
wrong pointer:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the `as:` conversion of the C handle `Derived` to `fxf_middle` makes another type: `&amp;amp;self-&amp;gt;middle.base` is not a `fxf_middle` in its headers
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The conversion is made at the call, after the closed and owner checks&lt;/strong&gt;, from the handle’s own
pointer: a closed handle stops the program at the call whichever type it is passed as, and &lt;code&gt;None&lt;/code&gt;
passes null with no conversion made. A parameter takes an &lt;code&gt;as&lt;/code&gt; type &lt;code&gt;const&lt;/code&gt;-qualified as it takes
the class’s own.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What a binding keeps or takes is the handle&lt;/strong&gt;, not the converted pointer: &lt;code&gt;keeps:&lt;/code&gt; of a handle
passed as an &lt;code&gt;as&lt;/code&gt; type holds it by its class’s own &lt;code&gt;retain&lt;/code&gt;, and &lt;code&gt;consumes:&lt;/code&gt; closes it
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A result answers only the class’s own type&lt;/strong&gt;: a pointer C answers as another type is a handle of
the class on that type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The glue is the declaring package’s&lt;/strong&gt;, so another package’s bindings pass the handle through it
as they pass it as its own type.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;field-accessors&quot;&gt;Field accessors&lt;/h3&gt;
&lt;p&gt;A handle on a struct whose layout the header publishes reads and writes its fields through methods
bound with &lt;code&gt;field:&lt;/code&gt;. The reader takes no parameters and answers the field; the writer takes one and
answers &lt;code&gt;unit&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;mlt_profile&amp;quot;, release: &amp;quot;mlt_profile_close&amp;quot;)
class Profile
  @c(field: &amp;quot;width&amp;quot;)
  width() -&amp;gt; int
  @c(field: &amp;quot;frame_rate_num&amp;quot;)
  frameRateNum() -&amp;gt; int
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The field’s C type is the header’s, so its conversion is the &lt;a href=&quot;#scalars&quot;&gt;scalar&lt;/a&gt; one for that type; a
field that is a pointer is read as a string or a borrowed handle by the same rules as a result.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The field is a member path of the struct &lt;code&gt;self&lt;/code&gt; points at&lt;/strong&gt;, &lt;code&gt;&amp;quot;width&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;origin.x&amp;quot;&lt;/code&gt;,
&lt;code&gt;&amp;quot;glyph-&amp;gt;bitmap.rows&amp;quot;&lt;/code&gt;, read as &lt;code&gt;self-&amp;gt;&lt;/code&gt; followed by it. The handle’s type must point at a struct
the headers define; one they only declare is refused when the C unit compiles the accessor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A field is read as an integer type, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, an enum mirror, a struct mirror, a string or a handle&lt;/strong&gt;, or the memory
a byte pointer points at is lent as a &lt;a href=&quot;#buffers&quot;&gt;view&lt;/a&gt; with &lt;code&gt;view&lt;/code&gt; and &lt;code&gt;length:&lt;/code&gt;. The C unit
checks the field is the kind its Avin type needs (an integer or enumeration, one byte wide for
&lt;code&gt;byte&lt;/code&gt;, a &lt;code&gt;bool&lt;/code&gt; or an integer for &lt;code&gt;bool&lt;/code&gt;, a floating-point type for &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char *&lt;/code&gt; or
&lt;code&gt;const char *&lt;/code&gt; for a string, and the class’s own C type for a handle) and measures its width and
sign, so an integer the Avin type cannot hold stops the program at the read, as a result does. A
null string is &lt;code&gt;None&lt;/code&gt; for an &lt;code&gt;Option[string]&lt;/code&gt; and stops the program otherwise; a string is copied
and checked as UTF-8, and never freed, since the struct owns it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A field may be read and written as an &lt;a href=&quot;#enums-and-constants&quot;&gt;enum mirror&lt;/a&gt;&lt;/strong&gt;
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): the field is of an integer type, the enum the mirror
mirrors or another (a union member C declares &lt;code&gt;int&lt;/code&gt;), measured as any integer field is. A value
read that no variant holds stops the program at the read
(&lt;code&gt; the field `cells[i].header.kind` of `Path` held a value no variant of `PathDataType` holds&lt;/code&gt;),
and a variant is written as its enumerator’s value. A mirror in an &lt;code&gt;Option&lt;/code&gt; is neither, since a field
is never null. Cairo’s path data is a union whose header holds the element’s kind:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(field: &amp;quot;data[i].header.type&amp;quot;, bound: &amp;quot;self-&amp;gt;num_data&amp;quot;)
kind(i: int) -&amp;gt; PathDataType
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A field may be read and written as a &lt;a href=&quot;#structs-by-value&quot;&gt;struct mirror&lt;/a&gt;&lt;/strong&gt;, whole
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): the field is the struct the mirror mirrors, which the C
unit checks, reached by any member path, through pointers and into arrays. The reader copies the
struct into memory of its own and reads a new value of the mirror out of it, each field converted
as a mirror C fills is, with the same traps, its strings copied and left to C, the mirrors and enum
mirrors it holds read in place; the writer lays the value out as C’s struct and assigns it. A
mirror holding a string, in a field of its own or of a mirror it holds, is only read, as a string
field is, and a mirror in an &lt;code&gt;Option&lt;/code&gt; is neither. FreeType’s face box and size metrics:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(field: &amp;quot;bbox&amp;quot;)
boundingBox() -&amp;gt; BBox

@c(field: &amp;quot;size-&amp;gt;metrics&amp;quot;)
sizeMetrics() -&amp;gt; SizeMetrics
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A handle read from a field is lent&lt;/strong&gt;, as a &lt;code&gt;borrowed&lt;/code&gt; result is: it takes a reference of its own
through its class’s &lt;code&gt;retain&lt;/code&gt;, so the class must declare one, and a class with &lt;code&gt;kept:&lt;/code&gt; cannot be
read, since the accessor keeps nothing. &lt;code&gt;borrowed&lt;/code&gt; is not written.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A writer answers &lt;code&gt;unit&lt;/code&gt;, and its last parameter is the value&lt;/strong&gt;, written as an argument of the
field’s type is converted: a value the field cannot hold stops the program at the call. Only a
scalar, an enum mirror or a struct mirror holding no string is written: a string or a handle stored into a struct would leave C holding memory or a
reference no one gives back, so those fields are read only (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).
A &lt;code&gt;const&lt;/code&gt; field, an array, or anything else C cannot assign is refused at the accessor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Every other parameter is an index&lt;/strong&gt;, an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt; the field names, passed to C as a
&lt;code&gt;long long&lt;/code&gt;. &lt;code&gt;bound:&lt;/code&gt; gives each one’s bound in order, one string for one index or a list for more
(&lt;code&gt;bound: [&amp;quot;self-&amp;gt;rows&amp;quot;, &amp;quot;self-&amp;gt;columns&amp;quot;]&lt;/code&gt;), each a C expression in &lt;code&gt;self&lt;/code&gt; and the indices.
An index the field does not name, a &lt;code&gt;bound:&lt;/code&gt; on an accessor with no index, and a count of bounds
that is not the count of indices are refused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The accessor checks its receiver as any method does&lt;/strong&gt;: it stops the program on a closed handle,
or one another thread owns, before anything is read.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;A field may be an expression&lt;/strong&gt;: a C lvalue in &lt;code&gt;self&lt;/code&gt; and the accessor’s parameters, reaching through
the struct to an array it points at, and a union’s members. An integer parameter used as an index is
given a &lt;code&gt;bound:&lt;/code&gt;, a C expression in &lt;code&gt;self&lt;/code&gt;; the accessor stops the program unless &lt;code&gt;0 &amp;lt;= i &amp;lt; bound&lt;/code&gt;
before C reads anything (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). That is how a C-owned array of a
union is read — Cairo’s &lt;code&gt;cairo_path_t&lt;/code&gt;, whose &lt;code&gt;data&lt;/code&gt; is &lt;code&gt;num_data&lt;/code&gt; elements of a union of a header
(&lt;code&gt;type&lt;/code&gt;, &lt;code&gt;length&lt;/code&gt;) and a point (&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;), freed whole by &lt;code&gt;cairo_path_destroy&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;cairo_path_t *&amp;quot;, release: &amp;quot;cairo_path_destroy&amp;quot;)
class CPath
  @c(field: &amp;quot;num_data&amp;quot;)
  count() -&amp;gt; int
  @c(field: &amp;quot;data[i].header.type&amp;quot;, bound: &amp;quot;self-&amp;gt;num_data&amp;quot;)
  kind(i: int) -&amp;gt; PathDataType
  @c(field: &amp;quot;data[i].header.length&amp;quot;, bound: &amp;quot;self-&amp;gt;num_data&amp;quot;)
  span(i: int) -&amp;gt; int
  @c(field: &amp;quot;data[i].point.x&amp;quot;, bound: &amp;quot;self-&amp;gt;num_data&amp;quot;)
  x(i: int) -&amp;gt; real
  @c(field: &amp;quot;data[i].point.y&amp;quot;, bound: &amp;quot;self-&amp;gt;num_data&amp;quot;)
  y(i: int) -&amp;gt; real
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The library walks the handle once, by each header’s &lt;code&gt;length&lt;/code&gt;, into immutable Avin data (a
&lt;code&gt;Vector[PathElement]&lt;/code&gt; of &lt;code&gt;MoveTo&lt;/code&gt;, &lt;code&gt;LineTo&lt;/code&gt;, &lt;code&gt;CurveTo&lt;/code&gt; and &lt;code&gt;ClosePath&lt;/code&gt;) and closes it; the union never
reaches Avin code. An accessor with an index and no &lt;code&gt;bound:&lt;/code&gt; is refused.&lt;/p&gt;
&lt;h2 id=&quot;structs&quot;&gt;Structs&lt;/h2&gt;
&lt;h3 id=&quot;structs-by-pointer&quot;&gt;Structs by pointer&lt;/h3&gt;
&lt;p&gt;A struct C allocates and Avin reaches through a pointer is a &lt;a href=&quot;#handles&quot;&gt;handle&lt;/a&gt;, its fields read
through &lt;a href=&quot;#field-accessors&quot;&gt;accessors&lt;/a&gt;. A struct Avin makes and passes by pointer, for C to read or
fill, is a &lt;a href=&quot;#structs-by-value&quot;&gt;mirror&lt;/a&gt; passed as &lt;code&gt;const T *&lt;/code&gt; (read) or &lt;code&gt;out T *&lt;/code&gt; (filled, part of the
result); the pointer is to a copy that lives for the call. A &lt;code&gt;const T *&lt;/code&gt; C may be given null for —
Cairo’s &lt;code&gt;cairo_recording_surface_create&lt;/code&gt; takes null extents for an unbounded surface — takes an
&lt;code&gt;Option&lt;/code&gt; of the mirror (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). Cairo’s &lt;code&gt;cairo_matrix_t&lt;/code&gt;,
&lt;code&gt;cairo_text_extents_t&lt;/code&gt;, &lt;code&gt;cairo_font_extents_t&lt;/code&gt; and &lt;code&gt;cairo_rectangle_t&lt;/code&gt; are mirrors: C fills them
through &lt;code&gt;out&lt;/code&gt; (&lt;code&gt;cairo_text_extents&lt;/code&gt;), reads them through &lt;code&gt;const&lt;/code&gt; (&lt;code&gt;cairo_set_matrix&lt;/code&gt;) and updates them
through &lt;code&gt;inout&lt;/code&gt; (&lt;code&gt;cairo_matrix_translate&lt;/code&gt;).&lt;/p&gt;
&lt;h3 id=&quot;structs-by-value&quot;&gt;Structs by value&lt;/h3&gt;
&lt;p&gt;A struct passed by value is &lt;strong&gt;mirrored&lt;/strong&gt; by a &lt;code&gt;data&lt;/code&gt; type with one variant named as the type, as a
&lt;a href=&quot;/spec/sysl-bindings/#mirrors&quot;&gt;Sysl struct&lt;/a&gt; is (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). &lt;code&gt;struct:&lt;/code&gt;
names the struct by its typedef or its tag, &lt;code&gt;struct as_tagged&lt;/code&gt;; a union, a pointer or a scalar is
refused. Its fields are matched by name, the Avin lowerCamelCase to C’s snake_case (&lt;code&gt;maxXAdvance&lt;/code&gt;
is &lt;code&gt;max_x_advance&lt;/code&gt;), or by a field’s own &lt;code&gt;@c(&amp;quot;name&amp;quot;)&lt;/code&gt;; every C field is mirrored, in the header’s
order, and each field is an integer type, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, a &lt;code&gt;string&lt;/code&gt; or &lt;code&gt;Option[string]&lt;/code&gt; (a
&lt;code&gt;const char *&lt;/code&gt;, null &lt;code&gt;None&lt;/code&gt;), an &lt;a href=&quot;#enums-and-constants&quot;&gt;enum mirror&lt;/a&gt;, or another struct mirror that
does not hold it. The C unit measures each field’s offset and C type and the struct’s size, and
asserts that the fields come in the header’s order, each where C’s alignment places it after the one
before, nothing after the last, and none left out between them; a field crosses at its C type’s
width, converted as a scalar argument or result is, with the same traps. A mirror’s value is a copy
in C memory that lives for the call: strings in it are copies freed after the call, and strings C
writes into one it fills are copied out and left to C.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(struct: &amp;quot;mlt_color&amp;quot;)
data Color
  Color(r: byte, g: byte, b: byte, a: byte)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A struct passed by value whose layout Avin does not mirror — a union, a struct with a bit-field or a
flexible array, one a library documents as opaque but passes by value — is an &lt;strong&gt;opaque value&lt;/strong&gt;: a
class declared with &lt;code&gt;@c(value: &amp;quot;mlt_event_data&amp;quot;)&lt;/code&gt;, whose object holds a copy of the C value’s bytes
and is passed and answered by value, never through a pointer, &lt;code&gt;inout&lt;/code&gt; or in an &lt;code&gt;Option&lt;/code&gt;; each object
is its own, compared by identity, and made only by a binding that answers one. Its methods are
bindings taking the value as their receiver:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(value: &amp;quot;mlt_event_data&amp;quot;)
class EventData
  @c(&amp;quot;int mlt_event_data_to_int(mlt_event_data self)&amp;quot;)
  toInt() -&amp;gt; int
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A call that passes or answers a struct by value goes through glue.&lt;/strong&gt; LLVM IR does not lower an
aggregate to the registers the platform’s C convention names; clang does. So a binding with a struct
by value is called through a C function the C unit defines, which takes and answers the struct
through pointers and makes the real call, and clang classifies the aggregate for whatever target the
program is built for (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;; a classification of Avin’s own, per
target, in lowering, may replace it where a measurement says the extra call matters). Scalars,
pointers and structs by pointer need no classification and are called directly.&lt;/p&gt;
&lt;h2 id=&quot;enums-and-constants&quot;&gt;Enums and constants&lt;/h2&gt;
&lt;p&gt;A C enum is an integer, and a binding may take or answer it as one. Mirrored, it is a &lt;code&gt;data&lt;/code&gt; type
whose variants have no fields, each the enumerator of its words in snake_case after a prefix, or the
one its own &lt;code&gt;@c(&amp;quot;name&amp;quot;)&lt;/code&gt; names:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(enum: &amp;quot;mlt_image_format&amp;quot;, prefix: &amp;quot;mlt_image_&amp;quot;)
data ImageFormat
  None
  Rgb
  Rgba
  Yuv422
  @c(&amp;quot;mlt_image_yuv420p&amp;quot;)
  Yuv420p
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The words are matched in the prefix’s case, so an upper-case prefix matches upper-case enumerators:
&lt;code&gt;@c(enum: &amp;quot;cairo_format_t&amp;quot;, prefix: &amp;quot;CAIRO_FORMAT_&amp;quot;)&lt;/code&gt; mirrors &lt;code&gt;CAIRO_FORMAT_ARGB32&lt;/code&gt; as &lt;code&gt;Argb32&lt;/code&gt; and
&lt;code&gt;CAIRO_FORMAT_A8&lt;/code&gt; as &lt;code&gt;A8&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A word starts at each upper-case
letter of the variant’s name, and a digit or &lt;code&gt;_&lt;/code&gt; stays with the word before it: &lt;code&gt;ColorDodge&lt;/code&gt; is
&lt;code&gt;COLOR_DODGE&lt;/code&gt; and &lt;code&gt;Rgb16_565&lt;/code&gt; is &lt;code&gt;RGB16_565&lt;/code&gt;. An enumerator whose name starts with a digit after the
prefix, &lt;code&gt;CAIRO_PDF_VERSION_1_4&lt;/code&gt;, is no variant’s words, so its variant names it with &lt;code&gt;@c&lt;/code&gt;. Two mirrors
of one module may share a variant’s name, as Cairo’s slant and weight share &lt;code&gt;Normal&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A mirror’s variant may have a core library variant’s name, as &lt;code&gt;ImageFormat.None&lt;/code&gt; does. In the
binding’s module it hides &lt;code&gt;Option&lt;/code&gt;‘s, yet wherever an &lt;code&gt;Option&lt;/code&gt; is expected, a &lt;code&gt;-&amp;gt; Option[T]&lt;/code&gt;
result, an &lt;code&gt;Option&lt;/code&gt; parameter or a pattern on an option, the bare &lt;code&gt;None&lt;/code&gt; is still &lt;code&gt;Option&lt;/code&gt;‘s
(&lt;a href=&quot;/spec/declarations/#data&quot;&gt;data types&lt;/a&gt;; &lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Each enumerator’s value is measured by the C unit, which checks the mirrored type is an enumeration or
an integer type and that the headers declare every enumerator. A mirror crosses where the prototype
writes the type it mirrors, as a parameter, a result, a status or an out value, at that type’s width.
A value C answers that no variant holds stops the program at the call:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: `cairo_status` answered a value no variant of `Status` holds at status.avin:7:1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where two enumerators have one value, both variants cross as it, and the value comes back as the
first. A mirror need not list every enumerator: one it leaves out is a value it cannot
take. An enum whose values are &lt;strong&gt;flags&lt;/strong&gt; combined with &lt;code&gt;|&lt;/code&gt; (Cairo’s &lt;code&gt;cairo_pdf_outline_flags_t&lt;/code&gt;) is
bound as an integer, its flags as constants, and the library gives it an Avin type of its own.&lt;/p&gt;
&lt;p&gt;A constant the header defines — an enumerator, a &lt;code&gt;#define&lt;/code&gt;, a &lt;code&gt;static const&lt;/code&gt; — is bound as a
top-level &lt;code&gt;val&lt;/code&gt; without an initializer, measured by the C unit and folded into the program as a
constant:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(const: &amp;quot;LIBMLT_VERSION_INT&amp;quot;)
val mltVersion: int
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A constant is an integer, a &lt;code&gt;real&lt;/code&gt; or a &lt;code&gt;string&lt;/code&gt;: a string literal the header defines (Cairo’s
&lt;code&gt;CAIRO_TAG_DEST&lt;/code&gt;, &lt;code&gt;&amp;quot;cairo.dest&amp;quot;&lt;/code&gt;) is stored by the C unit as its bytes, read by the driver like any
measurement, and checked as UTF-8 then (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). An integer constant
may be any integer constant expression, an enumerator or a character among them, and one its Avin
type cannot hold is refused at the constant, naming its value; a &lt;code&gt;real&lt;/code&gt; may be given an integer
constant, and holds NaN, the infinities and minus zero as C defines them.&lt;/p&gt;
&lt;h2 id=&quot;arrays-and-out-parameters&quot;&gt;Arrays and out parameters&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An array parameter is a pointer.&lt;/strong&gt; An &lt;code&gt;Array[byte]&lt;/code&gt; goes to a &lt;code&gt;uint8_t *&lt;/code&gt;, &lt;code&gt;char *&lt;/code&gt; or
&lt;code&gt;unsigned char *&lt;/code&gt;, an &lt;code&gt;Array[int]&lt;/code&gt; to an &lt;code&gt;int32_t *&lt;/code&gt; or &lt;code&gt;int *&lt;/code&gt;, an &lt;code&gt;Array[long]&lt;/code&gt; to an
&lt;code&gt;int64_t *&lt;/code&gt;, an &lt;code&gt;Array[real]&lt;/code&gt; to a &lt;code&gt;double *&lt;/code&gt;; the element types must be the same size and kind,
and nothing is converted. A typedef of such a type takes the array too; the C unit checks what the
pointer points at, by kind and size, and an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt; element as signed
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A &lt;code&gt;const&lt;/code&gt; pointer is only read; a pointer that is not
&lt;code&gt;const&lt;/code&gt; may be written, and what C writes is in the array after the call. Its length goes to the
parameter marked &lt;code&gt;length(data)&lt;/code&gt;, which is not an Avin parameter, converted to that parameter’s C
type as any &lt;code&gt;int&lt;/code&gt; argument is: an array too long for it stops the program at the call. The length
may come before the array or after it, and a call may take several arrays, each with its own. A
binding taking an array whose length nothing carries is refused, since C could read past its end;
one C fills with as many elements as another call says is &lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;an &lt;code&gt;out&lt;/code&gt; array&lt;/a&gt;
the binding allocates.
An &lt;code&gt;Option&lt;/code&gt; of an array passes null and a length of zero for &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(&amp;quot;ssize_t read(int fd, uint8_t *into, length(into) size_t count)&amp;quot;)
private readInto(fd: int, into: Array[byte]) -&amp;gt; long
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;length(data)&lt;/code&gt; may also mark an &lt;code&gt;inout&lt;/code&gt; pointer to an integer, for C that is told the length and
answers how much it used (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): the array’s length is written in
before the call, and the value C writes back is part of the result, an integer, stopping the
program if it exceeds the array’s length. An &lt;code&gt;Option&lt;/code&gt; of the array passes null and a length of
zero for &lt;code&gt;None&lt;/code&gt;, which is how a C function is asked the size it needs, and bounds nothing. FreeType’s &lt;code&gt;FT_Load_Sfnt_Table&lt;/code&gt; is asked
twice, once with no buffer for the table’s size and once to fill one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
  &amp;quot;FT_Error FT_Load_Sfnt_Table(FT_Face self, FT_ULong tag, FT_Long offset, FT_Byte *buffer, length(buffer) inout FT_ULong *length)&amp;quot;
)
private loadSfntTableRaw(tag: long, offset: long, buffer: Option[Array[byte]]) -&amp;gt; Result[long, int]
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An array of a mirror goes to a &lt;code&gt;const&lt;/code&gt; pointer to its struct&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).
A mirror’s Avin layout is not C’s, so the elements are converted into C memory that lives for the
call, laid out as the header lays the struct out, and nothing is written back; a pointer that is not
&lt;code&gt;const&lt;/code&gt; does not take one. Cairo’s glyphs are drawn this way, with no &lt;code&gt;cairo_glyph_allocate&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(struct: &amp;quot;cairo_glyph_t&amp;quot;)
data Glyph
  Glyph(index: long, x: real, y: real)

@c(&amp;quot;void cairo_show_glyphs(cairo_t *self, const cairo_glyph_t *glyphs, length(glyphs) int num_glyphs)&amp;quot;)
showGlyphs(glyphs: Array[Glyph])
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An array C allocates and answers is copied&lt;/strong&gt;, as an &lt;code&gt;Array&lt;/code&gt; of a scalar or a mirror: an &lt;code&gt;out&lt;/code&gt;
pointer named with &lt;code&gt;array:&lt;/code&gt;, given a &lt;code&gt;length:&lt;/code&gt; (a C expression, as for &lt;a href=&quot;#buffers&quot;&gt;buffers&lt;/a&gt;) and a
&lt;code&gt;free:&lt;/code&gt; naming the C function or the C expression in the array’s name that frees it once the copy
is made — Cairo’s &lt;code&gt;cairo_scaled_font_text_to_glyphs&lt;/code&gt;, freed by &lt;code&gt;cairo_glyph_free(glyphs)&lt;/code&gt;. The
length is computed in the C unit’s glue after the call, over the parameters and the out values by
their names; the length’s own out value stays in the result. Null is &lt;code&gt;None&lt;/code&gt; for an &lt;code&gt;Option&lt;/code&gt; of the
array, an empty array where the length is zero, and stops the program otherwise, as a negative
length does; where a status fails, the array is freed unread (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).
&lt;code&gt;bytes:&lt;/code&gt; is the same for an &lt;code&gt;Array[byte]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An array C fills is allocated by the binding&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): an &lt;code&gt;out&lt;/code&gt;
pointer to the elements themselves, &lt;code&gt;out double *dashes&lt;/code&gt;, named with &lt;code&gt;array:&lt;/code&gt; and given a
&lt;code&gt;length:&lt;/code&gt;, a C expression over the parameters evaluated in the glue &lt;em&gt;before&lt;/em&gt; the call, since C
writes as many elements as some other call says and no parameter tells it how many. The glue
allocates that many, C fills them, and the array is copied into a new &lt;code&gt;Array&lt;/code&gt; and freed. Cairo’s dash
pattern is as long as &lt;code&gt;cairo_get_dash_count&lt;/code&gt; says:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    &amp;quot;void cairo_get_dash(cairo_t *self, out double *dashes, out double *offset)&amp;quot;,
    array: &amp;quot;dashes&amp;quot;,
    length: &amp;quot;cairo_get_dash_count(self)&amp;quot;
)
dash() -&amp;gt; (Array[real], real)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A length of zero is an empty array, C still called. A negative length, or one longer than an array
holds, calls nothing and stops the program (&lt;code&gt; `cairo_get_dash` answered through `dashes` a negative length&lt;/code&gt;). The array is never null, so never in an &lt;code&gt;Option&lt;/code&gt;, and the binding frees it, so it takes
no &lt;code&gt;free:&lt;/code&gt;; its elements are those of an array C allocates, and an out value’s name is not yet
written when the length is evaluated, so a &lt;code&gt;length:&lt;/code&gt; naming one is refused by clang in the glue.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Several arrays in one call are named as a list&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):
&lt;code&gt;array:&lt;/code&gt; (or &lt;code&gt;bytes:&lt;/code&gt;) a list of the out parameters, &lt;code&gt;length:&lt;/code&gt; a list of their lengths in the same
order, and &lt;code&gt;free:&lt;/code&gt;, where it is given, a list of how each is freed, &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; for an array C fills or one
nothing frees. Each array is copied and freed by its own entry, and where a status fails every array
C answered is freed unread. The result keeps the prototype’s order whatever order the lists name the
arrays in. A list names each array once, each an &lt;code&gt;out&lt;/code&gt; parameter, and a list of lengths or of frees
comes only with a list of arrays.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A pointer marked &lt;code&gt;null&lt;/code&gt; is passed null&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): the word is
written before the parameter’s type, as &lt;code&gt;out&lt;/code&gt; is, for a pointer C allows to be null — an out value
the binding does not want, or an optional pointer it leaves out. It is no Avin parameter and no part
of the result, and the header check holds it to the header’s type like any other. A function whose
caller chooses is bound twice. Cairo’s &lt;code&gt;cairo_scaled_font_text_to_glyphs&lt;/code&gt; answers glyphs and
clusters, each allocated by Cairo with its own count and its own free function, and takes null for
the clusters, their count and their flags where they are not wanted:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    &amp;quot;cairo_status_t cairo_scaled_font_text_to_glyphs(cairo_scaled_font_t *self, double x, double y, const char *utf8, int utf8_len, out cairo_glyph_t **glyphs, out int *num_glyphs, out cairo_text_cluster_t **clusters, out int *num_clusters, out cairo_text_cluster_flags_t *cluster_flags)&amp;quot;,
    array: [&amp;quot;glyphs&amp;quot;, &amp;quot;clusters&amp;quot;],
    length: [&amp;quot;num_glyphs&amp;quot;, &amp;quot;num_clusters&amp;quot;],
    free: [&amp;quot;cairo_glyph_free&amp;quot;, &amp;quot;cairo_text_cluster_free&amp;quot;]
)
private textToGlyphsRaw(x: real, y: real, utf8: string, length: int) -&amp;gt; Result[
  (Array[Glyph], int, Array[TextCluster], int, ClusterFlags),
  Status
]

@c(
    &amp;quot;cairo_status_t cairo_scaled_font_text_to_glyphs(cairo_scaled_font_t *self, double x, double y, const char *utf8, int utf8_len, out cairo_glyph_t **glyphs, out int *num_glyphs, null cairo_text_cluster_t **clusters, null int *num_clusters, null cairo_text_cluster_flags_t *cluster_flags)&amp;quot;,
    array: &amp;quot;glyphs&amp;quot;,
    length: &amp;quot;num_glyphs&amp;quot;,
    free: &amp;quot;cairo_glyph_free&amp;quot;
)
private glyphsRaw(x: real, y: real, utf8: string, length: int) -&amp;gt; Result[(Array[Glyph], int), Status]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;null&lt;/code&gt; is never &lt;code&gt;out&lt;/code&gt;, &lt;code&gt;inout&lt;/code&gt; or &lt;code&gt;userdata&lt;/code&gt; besides, never written twice, never an array a length
is filled in from, and never a callback’s parameter; a struct passed by value or a scalar is no
pointer, and is refused.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A function pointer marked &lt;code&gt;null&lt;/code&gt; is passed null too&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;), for C
that takes optional hooks and uses its own where it is given none. libssh2 makes a session only
through &lt;code&gt;libssh2_session_init_ex&lt;/code&gt;, which takes an allocator, a free function, a reallocator and the
&lt;code&gt;void *&lt;/code&gt; they share, &lt;code&gt;libssh2_session_init()&lt;/code&gt; being a macro that passes four nulls:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
  &amp;quot;LIBSSH2_SESSION *libssh2_session_init_ex(null void *(*my_alloc)(size_t count, void **abstract), null void (*my_free)(void *ptr, void **abstract), null void *(*my_realloc)(void *ptr, size_t count, void **abstract), null void *abstract)&amp;quot;
)
private sessionInit() -&amp;gt; Option[Session]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;C never calls a function it is passed null for, so its parameters are read only as C’s types, for the
header check: it is named, as every function pointer is, takes no &lt;code&gt;userdata&lt;/code&gt; or &lt;code&gt;length&lt;/code&gt; among its
parameters, and may answer any type, a string too. A function pointer passed null sits beside a
callback C does call, and beside every other kind of parameter.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An out parameter is part of the result.&lt;/strong&gt; The Avin result is the C result followed by each
&lt;code&gt;out&lt;/code&gt; and &lt;code&gt;inout&lt;/code&gt; value in order, as a tuple; a C result bound as &lt;code&gt;unit&lt;/code&gt; leaves the tuple without
it, one value alone is not a tuple, and a status bound as &lt;code&gt;Result[T, int]&lt;/code&gt; holds the rest in its
&lt;code&gt;Ok&lt;/code&gt;. An out value is a scalar, a string, a handle (owned, unless the binding says &lt;code&gt;borrowed&lt;/code&gt;) or a
mirror. &lt;code&gt;out&lt;/code&gt; and &lt;code&gt;inout&lt;/code&gt; are written before the parameter’s type, which is a pointer to what is
answered, never to &lt;code&gt;const&lt;/code&gt;. A C result that is not &lt;code&gt;void&lt;/code&gt; is left out where the binding answers the
out values alone. Each is a slot in the call’s frame, zero or null until C writes it; an &lt;code&gt;inout&lt;/code&gt; one
holds the converted argument first, a string as a copy C may move the pointer into, and a handle is
never passed &lt;code&gt;inout&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A handle answered through an out
pointer keeps what the call &lt;code&gt;keeps:&lt;/code&gt; where the C result is no handle.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(&amp;quot;int mlt_service_get_frame(mlt_service self, out mlt_frame *frame, int index)&amp;quot;)
private getFrame(index: int) -&amp;gt; Result[Frame, int]
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;memory-of-no-type&quot;&gt;Memory of no type&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;void *&lt;/code&gt; or &lt;code&gt;const void *&lt;/code&gt; parameter takes an array of any element type an array crosses as, or
a &lt;code&gt;ByteBlock&lt;/code&gt;, and its length counts bytes&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#settled&quot;&gt;settled&lt;/a&gt;). C’s untyped
buffers are memory whose type the caller chooses: &lt;code&gt;sysctlbyname&lt;/code&gt; writes an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;
reads any bytes. So an &lt;code&gt;Array[byte]&lt;/code&gt;, &lt;code&gt;Array[int]&lt;/code&gt;, &lt;code&gt;Array[long]&lt;/code&gt; or &lt;code&gt;Array[real]&lt;/code&gt; goes to the pointer
as it is, its elements where they are, and the header has no element type to check. The parameter
marked &lt;code&gt;length(p)&lt;/code&gt; is told the array’s length times the size of its element, as a &lt;code&gt;long&lt;/code&gt;, converted
to the parameter’s C type as any &lt;code&gt;long&lt;/code&gt; argument is; an &lt;code&gt;inout&lt;/code&gt; length C writes back through is in
bytes too, and stops the program where it exceeds the array’s bytes. C writes through &lt;code&gt;void *&lt;/code&gt;, and
what it wrote is in the array after the call, and only reads through &lt;code&gt;const void *&lt;/code&gt;. An &lt;code&gt;Option&lt;/code&gt; of
the array passes null and a length of zero for &lt;code&gt;None&lt;/code&gt;, and a &lt;code&gt;void *&lt;/code&gt; marked &lt;code&gt;null&lt;/code&gt; is passed null.
A &lt;code&gt;ByteBlock&lt;/code&gt; is passed as a pointer to its bytes, as to any pointer.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
  &amp;quot;int sysctlbyname(const char *name, void *oldp, length(oldp) inout size_t *oldlenp, null void *newp, size_t newlen)&amp;quot;
)
private sysctlRaw(name: string, into: Array[int], newlen: long) -&amp;gt; (int, long)

// The `int` the kernel holds under `name`, where it holds one.
sysctlInt(name: string) -&amp;gt; Option[int] =
  val v = Array.fill(1, 0)
  sysctlRaw(name, v, 0) match
    (0, 4) -&amp;gt; Some(v(0))
    _ -&amp;gt; None
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;sysctlInt(&amp;quot;kern.maxfilesperproc&amp;quot;)&lt;/code&gt; answers the limit; the same binding over an &lt;code&gt;Array[long]&lt;/code&gt; reads
&lt;code&gt;hw.memsize&lt;/code&gt;, and asked with &lt;code&gt;None&lt;/code&gt; for the array (bound as an &lt;code&gt;Option&lt;/code&gt;), C answers the size it
needs. The header check holds a &lt;code&gt;void *&lt;/code&gt; to the header’s type as it holds every pointer, so a binding
saying &lt;code&gt;const void *&lt;/code&gt; where the header writes &lt;code&gt;void *&lt;/code&gt; is refused, and so is one saying &lt;code&gt;void *&lt;/code&gt;
where the header writes a typed pointer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A pointer to an opaque pointer points at memory of no type too&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#settled&quot;&gt;settled&lt;/a&gt;):
&lt;code&gt;void **&lt;/code&gt;, and a pointer to a typedef the headers make &lt;code&gt;void *&lt;/code&gt; or &lt;code&gt;const void *&lt;/code&gt;, as Apple’s
&lt;code&gt;rusage_info_t *&lt;/code&gt; is. Headers write one where C writes whatever the caller’s flavour says through it.
Passed in, it takes what &lt;code&gt;void *&lt;/code&gt; takes, its length in bytes. Only the headers say what a typedef
is, so the C unit measures it, and checks the elements of an array passed to a pointer to a typedef
are either what the typedef is or the typedef is &lt;code&gt;void *&lt;/code&gt;; a typedef of an integer type points at
elements, which its length counts. The header check still holds the prototype to the header’s own
type, so the binding writes &lt;code&gt;rusage_info_t *&lt;/code&gt;, as the header does, never &lt;code&gt;void *&lt;/code&gt; or the struct.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C fills memory of no type through &lt;code&gt;out&lt;/code&gt;&lt;/strong&gt;: through &lt;code&gt;out void *&lt;/code&gt; or a pointer to a typedef that is
&lt;code&gt;void *&lt;/code&gt;, &lt;code&gt;out rusage_info_t *buffer&lt;/code&gt;, it fills &lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;an array the binding allocates&lt;/a&gt;,
named with &lt;code&gt;array:&lt;/code&gt;, its &lt;code&gt;length:&lt;/code&gt; counting &lt;strong&gt;bytes&lt;/strong&gt;, as many elements of the array’s type as hold
them, the last zero past what C writes; or a struct mirror, which &lt;code&gt;out void **&lt;/code&gt; takes as well, the
C unit checking a typedef is the mirror’s struct or &lt;code&gt;void *&lt;/code&gt;. &lt;code&gt;proc_pid_rusage&lt;/code&gt; writes a
&lt;code&gt;struct rusage_info_v2&lt;/code&gt; through its &lt;code&gt;rusage_info_t *&lt;/code&gt;, sixteen bytes of &lt;code&gt;ri_uuid&lt;/code&gt;, which no mirror’s
field holds, then eighteen &lt;code&gt;uint64_t&lt;/code&gt; fields, so its bytes are answered as &lt;code&gt;long&lt;/code&gt;s:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.c.Errno

@c(
  &amp;quot;int proc_pid_rusage(int pid, int flavor, out rusage_info_t *buffer)&amp;quot;,
  array: &amp;quot;buffer&amp;quot;,
  length: &amp;quot;sizeof(struct rusage_info_v2)&amp;quot;,
  errno
)
private rusage(pid: int, flavor: int) -&amp;gt; Result[Array[long], Errno]

@c(const: &amp;quot;RUSAGE_INFO_V2&amp;quot;)
val rusageInfoV2: int

// The physical footprint of the process `pid`, in bytes: the ninth `uint64_t` after `ri_uuid`&apos;s
// two `long`s. A process that does not exist is `Err(ESRCH)`.
footprintBytes(pid: int) -&amp;gt; Result[long, Errno] = rusage(pid, rusageInfoV2).map(info -&amp;gt; info(9))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Memory of no type C allocates and answers through &lt;code&gt;out void **&lt;/code&gt;, named with &lt;code&gt;bytes:&lt;/code&gt; or &lt;code&gt;array:&lt;/code&gt;, is
an &lt;code&gt;Array[byte]&lt;/code&gt;, as long as its &lt;code&gt;length:&lt;/code&gt; says in bytes, which need not be a whole number of wider
elements. What is still refused:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;an array whose length no parameter carries&lt;/strong&gt;, as everywhere: &lt;code&gt;memcmp(const void *a, const void *b, size_t n)&lt;/code&gt; carries one length for two, and its second array is refused;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;a value through &lt;code&gt;out void *&lt;/code&gt;, and &lt;code&gt;inout void *&lt;/code&gt;&lt;/strong&gt;: C writes no value of a type through one
(&lt;code&gt;C writes no value through `out void *p`, which points at memory of no type&lt;/code&gt;), so the memory is
an array or a block passed in, or an array or a struct mirror C fills;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;an array of anything but bytes for memory of no type C allocates&lt;/strong&gt; (&lt;code&gt;C allocates memory of no type for `p`, whose length in bytes need not be a whole number of `long`s, so it is answered as an `Array[byte]`&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;anything else for a &lt;code&gt;void *&lt;/code&gt; parameter&lt;/strong&gt;: a scalar, a string or an array of strings (&lt;code&gt;`const void *` points at memory of no type, so it takes an `Array[byte]`, `Array[int]`, `Array[long]` or `Array[real]`, its length in bytes carried by the parameter marked `length(buf)`, or a `ByteBlock`&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;a &lt;code&gt;void *&lt;/code&gt; result&lt;/strong&gt;, whose length nothing says, except that a binding answering &lt;code&gt;unit&lt;/code&gt;
discards it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;buffers&quot;&gt;Buffers&lt;/h2&gt;
&lt;p&gt;Pixels and samples are memory C owns, often megabytes of it, valid while the object that owns them
is unchanged. A binding answers such memory in one of two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Copied&lt;/strong&gt;, as an &lt;code&gt;Array[byte]&lt;/code&gt;: an &lt;code&gt;out&lt;/code&gt; pointer to bytes named with &lt;code&gt;bytes:&lt;/code&gt; and given a
&lt;code&gt;length:&lt;/code&gt;, a C expression over the call’s parameters and out values, evaluated in the glue after
the call. The array never reads C’s memory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Borrowed&lt;/strong&gt;, as a &lt;code&gt;ByteView&lt;/code&gt; from &lt;code&gt;avin.c&lt;/code&gt;, named with &lt;code&gt;view:&lt;/code&gt; and given a &lt;code&gt;length:&lt;/code&gt;: a handle on
the C memory that reads it in place, bounds-checked — &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;apply(i)&lt;/code&gt;, &lt;code&gt;slice(from, until)&lt;/code&gt;
copying a range out, and &lt;code&gt;copy()&lt;/code&gt; — and holds a reference to the handle that owns the memory, so
the owner is not collected while the view is open. &lt;strong&gt;A view is valid until its owner is used
again&lt;/strong&gt;: any bound method of the owner, or its &lt;code&gt;close()&lt;/code&gt;, closes every view it lent first, since a
second call may free or replace the memory (MLT converts a frame’s image in place). A closed view
used stops the program (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: the `ByteView` of `Frame` was closed when `Frame` was used again at main.avin:22:17
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(type: &amp;quot;mlt_frame&amp;quot;, release: &amp;quot;mlt_frame_close&amp;quot;, retain: &amp;quot;mlt_properties_inc_ref(mlt_frame_properties(self))&amp;quot;)
class Frame
  @c(
      &amp;quot;int mlt_frame_get_image(mlt_frame self, out uint8_t **buffer, inout mlt_image_format *format, out int *width, out int *height, int writable)&amp;quot;,
      view: &amp;quot;buffer&amp;quot;,
      length: &amp;quot;mlt_image_format_size(format, width, height, NULL)&amp;quot;
  )
  private imageRaw(format: ImageFormat, writable: int) -&amp;gt; Result[(ByteView, ImageFormat, int, int), int]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A binding whose C &lt;em&gt;result&lt;/em&gt; is the pointer to the memory says &lt;code&gt;view&lt;/code&gt; with no name, and its &lt;code&gt;length:&lt;/code&gt;
is a C expression over the parameters:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    &amp;quot;unsigned char *cairo_image_surface_get_data(cairo_surface_t *self)&amp;quot;,
    view,
    writable,
    length: &amp;quot;cairo_image_surface_get_stride(self) * cairo_image_surface_get_height(self)&amp;quot;
)
private dataRaw() -&amp;gt; Option[MutByteView]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;a href=&quot;#field-accessors&quot;&gt;field accessor&lt;/a&gt; whose field is a byte pointer says &lt;code&gt;view&lt;/code&gt; the same way, its
&lt;code&gt;length:&lt;/code&gt; a C expression in &lt;code&gt;self&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A FreeType glyph’s bitmap
is a field of the face’s glyph slot, &lt;code&gt;|pitch| * rows&lt;/code&gt; bytes that the face’s next load replaces — the
view’s own rule, since that load is a use of the face. &lt;code&gt;pitch&lt;/code&gt; is negative for a bitmap stored bottom
row first, and the buffer then begins with the bottom row, so the length takes its magnitude:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    field: &amp;quot;glyph-&amp;gt;bitmap.buffer&amp;quot;,
    view,
    length: &amp;quot;(self-&amp;gt;glyph-&amp;gt;bitmap.pitch &amp;lt; 0 ? -self-&amp;gt;glyph-&amp;gt;bitmap.pitch : self-&amp;gt;glyph-&amp;gt;bitmap.pitch) * self-&amp;gt;glyph-&amp;gt;bitmap.rows&amp;quot;
)
private bitmapRaw() -&amp;gt; Option[ByteView]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The buffer is null for a glyph with no pixels (a space), answered as &lt;code&gt;None&lt;/code&gt;. Reading a row as &lt;code&gt;row * pitch&lt;/code&gt; with a negative pitch is caught by the view’s bounds check rather than read from before the
buffer.&lt;/p&gt;
&lt;p&gt;Such an accessor takes &lt;code&gt;view&lt;/code&gt;, &lt;code&gt;length:&lt;/code&gt; and &lt;code&gt;writable&lt;/code&gt; beside &lt;code&gt;field:&lt;/code&gt; and &lt;code&gt;bound:&lt;/code&gt;, and nothing
else: &lt;code&gt;length:&lt;/code&gt; is a C expression in &lt;code&gt;self&lt;/code&gt; and the indices, evaluated after the field is read, and
an index is checked against its bound before either. The C unit checks the field points at an integer
type one byte wide, and that a &lt;code&gt;writable&lt;/code&gt; one is not &lt;code&gt;const&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: the field `name` of the C handle `Face` points at `const` memory in the headers, so `Face.name` cannot lend it `writable`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A field view is lent and closed by the rules of every view below: its handle’s next use closes it,
another field accessor among them, and a &lt;code&gt;shared&lt;/code&gt; handle lends none. A writer lends nothing, and an
accessor answering a view without saying &lt;code&gt;view&lt;/code&gt;, or a &lt;code&gt;ByteBlock&lt;/code&gt; at all, is refused.&lt;/p&gt;
&lt;h3 id=&quot;writing-into-c-s-memory&quot;&gt;Writing into C’s memory&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;ByteView&lt;/code&gt; is read-only. A binding marked &lt;code&gt;writable&lt;/code&gt; answers an &lt;code&gt;avin.c.MutByteView&lt;/code&gt;&lt;/strong&gt;, which is
a &lt;code&gt;ByteView&lt;/code&gt; with &lt;code&gt;update(i, b)&lt;/code&gt;, &lt;code&gt;fill(from, until, b)&lt;/code&gt; and &lt;code&gt;write(at, bytes)&lt;/code&gt; added, every one
bounds-checked, and is closed by the same rule: the owner’s next use closes it
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A &lt;code&gt;writable&lt;/code&gt; binding needs a pointer that is not &lt;code&gt;const&lt;/code&gt;. Whether
C sees the bytes is the library’s own protocol, written in Avin over the owner: Cairo’s surface is
flushed before its data is lent and told with &lt;code&gt;cairo_surface_mark_dirty&lt;/code&gt; once it was written, and since
&lt;code&gt;markDirty()&lt;/code&gt; is a use of the owner it closes the view, so a write after it is caught:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;val px = surface.pixels()?
px.fill(0, 4, byte(255))
surface.markDirty()
px.update(4, byte(0))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: the `MutByteView` of `Surface` was closed when `Surface` was used again at main.avin:4:5
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;memory-avin-gives-c&quot;&gt;Memory Avin gives C&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Memory C keeps, and writes into, is an &lt;code&gt;avin.c.ByteBlock&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):
a fixed number of bytes outside the collected heap, zeroed when made by &lt;code&gt;ByteBlock(length)&lt;/code&gt;, read and
written in place by the methods of a &lt;code&gt;MutByteView&lt;/code&gt; and freed when it is collected. It is passed where a
prototype names a byte pointer, as an array is, with its length filled into &lt;code&gt;length(p)&lt;/code&gt;, but &lt;strong&gt;never
copied&lt;/strong&gt;: its address does not move, so it may be passed to a &lt;code&gt;blocking&lt;/code&gt; call, and kept by C past the
call. A binding that hands it to C for keeps says &lt;code&gt;keeps:&lt;/code&gt;, and on a class with
&lt;a href=&quot;#when-c-holds-the-object-longer-than-avin-does&quot;&gt;&lt;code&gt;attach:&lt;/code&gt;&lt;/a&gt; the block lives as long as C’s object:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    &amp;quot;cairo_surface_t *cairo_image_surface_create_for_data(unsigned char *pixels, cairo_format_t format, int width, int height, int stride)&amp;quot;,
    keeps: &amp;quot;pixels&amp;quot;
)
private surfaceForData(pixels: ByteBlock, format: Format, width: int, height: int, stride: int) -&amp;gt; Surface
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cairo reads &lt;code&gt;height * stride&lt;/code&gt; bytes from &lt;code&gt;pixels&lt;/code&gt; and no prototype says so; the library checks
&lt;code&gt;pixels.length &amp;gt;= height * stride&lt;/code&gt; before the call, a precondition the binding takes on trust like
any &lt;code&gt;length&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ByteBlock(length)&lt;/code&gt; with a negative length stops the program, and the class’s own constructor,
&lt;code&gt;ByteBlock()&lt;/code&gt;, makes a block of no bytes, passed to C as null. A block is a &lt;code&gt;MutByteView&lt;/code&gt; that nothing
closes, since nothing lent it; it belongs to the code that made it and moves between threads as a handle
does, so another thread’s use stops the program (&lt;code&gt; `ByteBlock` belongs to another thread&lt;/code&gt;). Only a
block is passed to C: a view is memory C lent, never passed back. It is never in an &lt;code&gt;Option&lt;/code&gt; and never
&lt;code&gt;inout&lt;/code&gt;, and the C unit checks that the pointer it is passed to points at bytes one byte wide.&lt;/p&gt;
&lt;h3 id=&quot;the-rules-of-views-and-blocks&quot;&gt;The rules of views and blocks&lt;/h3&gt;
&lt;p&gt;A view’s length and its indices are &lt;code&gt;int&lt;/code&gt;s, as an array’s are. Where the binding’s &lt;code&gt;length:&lt;/code&gt; is
negative, or longer than the greatest &lt;code&gt;int&lt;/code&gt;, the program stops at the call (&lt;code&gt; `bf_frame_static` answered more bytes than a view holds&lt;/code&gt;). C lending null is &lt;code&gt;None&lt;/code&gt; where the binding answers an
&lt;code&gt;Option&lt;/code&gt;, whatever the length; otherwise null with a length of zero is an empty view, and null with any
other length stops the program (&lt;code&gt; `frame_data` answered null&lt;/code&gt;). &lt;code&gt;bytes:&lt;/code&gt; answers the same way, with an
empty array for a null of length zero (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A view is lent only by a method of a C handle, its lender, and only by a handle that is not &lt;code&gt;shared&lt;/code&gt;:
the view belongs to the code that owns its lender, wherever that code runs, so a lightweight thread
reads its view across its own switches, a thread’s body that captures a view takes its lender with it,
and any other thread’s use stops the program (&lt;code&gt; the `ByteView` of `Frame` belongs to another thread&lt;/code&gt;). A field accessor is a use of its handle as a method is, and closes the view it lent. Each
operation of a view or a block checks, in order, the code running, that a view is still open, and the
indices: &lt;code&gt;index out of range&lt;/code&gt; for &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt;, &lt;code&gt;slice out of range&lt;/code&gt; for &lt;code&gt;slice&lt;/code&gt; and &lt;code&gt;fill&lt;/code&gt;,
and &lt;code&gt;write out of range&lt;/code&gt; for a &lt;code&gt;write&lt;/code&gt; that does not fit, which writes nothing. A failed status lends
nothing (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&quot;calls-that-wait&quot;&gt;Calls that wait&lt;/h2&gt;
&lt;p&gt;A C function that may wait — for a frame, for a thread, for input — is bound with &lt;code&gt;blocking&lt;/code&gt;, as a
&lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;Sysl one&lt;/a&gt; is: &lt;code&gt;@c(&amp;quot;…&amp;quot;, blocking)&lt;/code&gt;. The call is bracketed by
the runtime’s &lt;code&gt;avin_rt_enter_safe&lt;/code&gt; and &lt;code&gt;avin_rt_leave_safe&lt;/code&gt;, so a collection runs while it waits.
Every argument is converted first, and none points into the Avin heap during the call: a string’s
copy is not on the heap, an array is copied into memory outside it and back after the call, and a
handle’s C pointer is a plain value whose object the call’s frame keeps alive. The result is
converted once the thread is running again.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;blocking&lt;/code&gt; array’s copy is copied back only where the pointer is not &lt;code&gt;const&lt;/code&gt;, and freed, before
the result is converted; a handle’s object is used once the thread is running again, so the frame
keeps it alive across the wait (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A call that is not &lt;code&gt;blocking&lt;/code&gt; is made with the thread running, so it holds up every collection for
as long as it runs, and may be passed pointers into the Avin heap — an array’s elements — directly.&lt;/p&gt;
&lt;h2 id=&quot;callbacks&quot;&gt;Callbacks&lt;/h2&gt;
&lt;p&gt;C calls back through a function pointer with a &lt;code&gt;void *&lt;/code&gt; beside it. A binding’s parameter of
function-pointer type takes an Avin function, and the &lt;code&gt;void *&lt;/code&gt; marked &lt;code&gt;userdata&lt;/code&gt;, in the binding’s
prototype and in the function pointer’s own, carries it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
    &amp;quot;mlt_event mlt_events_listen(mlt_properties self, userdata void *data, const char *id, void (*listener)(mlt_properties owner, userdata void *data, mlt_event_data event))&amp;quot;,
    keeps: &amp;quot;listener&amp;quot;
)
on(event: string, @threaded listener: (Properties, EventData) -&amp;gt; unit)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The Avin function’s parameters are the C function’s, without the &lt;code&gt;userdata&lt;/code&gt;&lt;/strong&gt;, in order, each
crossing out of C as a result does: a pointer to a handle’s type is a handle C lends, made through
&lt;code&gt;retain&lt;/code&gt;, a string copied and checked, a value no Avin type holds stopping the program where the
binding was called; and the function’s answer crosses into C as a parameter does: a scalar, a
truth value or an enum mirror, and &lt;code&gt;unit&lt;/code&gt; exactly where C’s function answers &lt;code&gt;void&lt;/code&gt;
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). A string or a handle is never a callback’s answer: it
would have to outlive the call, with nothing to free it. A binding takes one function per
&lt;code&gt;userdata&lt;/code&gt;, which the function pointer’s own &lt;code&gt;userdata&lt;/code&gt; names (&lt;code&gt;listener&lt;/code&gt;‘s &lt;code&gt;data&lt;/code&gt; above), and a
function pointer with no &lt;code&gt;userdata&lt;/code&gt; beside it is refused: there is nowhere to find the closure. One
C allows null is &lt;a href=&quot;#arrays-and-out-parameters&quot;&gt;marked &lt;code&gt;null&lt;/code&gt;&lt;/a&gt; and passed null instead.
libc’s &lt;code&gt;qsort&lt;/code&gt; and &lt;code&gt;bsearch&lt;/code&gt; are such functions; a binding reaches them through a C function that
passes a &lt;code&gt;userdata&lt;/code&gt; of its own, as &lt;code&gt;qsort_r&lt;/code&gt; does.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory C lends a callback is a view&lt;/strong&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;). In a function
pointer’s prototype, a byte pointer with a &lt;code&gt;length(p)&lt;/code&gt; parameter beside it crosses as a &lt;code&gt;ByteView&lt;/code&gt;
when it is &lt;code&gt;const&lt;/code&gt; and a &lt;code&gt;MutByteView&lt;/code&gt; when it is not, the length filled from C’s and not an Avin
parameter, and the view is closed when the callback returns. That is Cairo’s PNG stream, written
(&lt;code&gt;cairo_write_func_t&lt;/code&gt;) and read (&lt;code&gt;cairo_read_func_t&lt;/code&gt;) through a closure. A function-pointer typedef
is written out in the binding’s prototype, where the marker words go; clang finds the two the same
type:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;@c(
  &amp;quot;cairo_status_t cairo_surface_write_to_png_stream(cairo_surface_t *self, cairo_status_t (*write)(userdata void *closure, const unsigned char *data, length(data) unsigned int length), userdata void *closure)&amp;quot;
)
private writePngStream(write: (ByteView) -&amp;gt; Status) -&amp;gt; Result[unit, Status]

toPng(surface: Surface) -&amp;gt; Result[Array[byte], CairoError] =
  val out = Buffer[byte]()

  collect(chunk: ByteView) -&amp;gt; Status =
    out.appendAll(chunk.copy())
    Status.Success

  surface.writePngStream(collect).mapErr(CairoError.from)?
  Ok(out.toArray())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The length may come before its pointer and be of any integer type; a function may be lent several
views; and null crosses by the &lt;a href=&quot;#the-rules-of-views-and-blocks&quot;&gt;rules of views&lt;/a&gt;, &lt;code&gt;None&lt;/code&gt; for an
&lt;code&gt;Option[ByteView]&lt;/code&gt;, an empty view for a length of zero, and otherwise a stop where the binding was
called (&lt;code&gt; C lent the function given to `writePngStream` null&lt;/code&gt;). A view lent a callback has no
lender: it belongs to the code the callback runs in, so a thread the callback starts cannot read it
(&lt;code&gt; the `ByteView` lent to the function given to `writePngStream` belongs to another thread&lt;/code&gt;),
and a view kept past the call stops the program at its use
(&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap: the `ByteView` lent to the function given to `writePngStream` was closed when it returned at main.avin:14:13
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A callback answers no view, and the C unit checks each lent pointer points at bytes one byte wide.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The compiler makes one trampoline per parameter taking a function&lt;/strong&gt;, a function with C’s
convention whose address is passed for the pointer (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;): two
bindings of one C type may cross it as different Avin types. It finds the closure through the &lt;code&gt;userdata&lt;/code&gt;, which points at the
runtime’s record of it (the record Sysl callbacks use, &lt;code&gt;callback_pin&lt;/code&gt;), enters the runtime as a
Sysl callback does (&lt;code&gt;callback_enter&lt;/code&gt;), converts the arguments, calls the function, converts its
answer and leaves. A callback with a struct by value among its parameters has a C trampoline in
the glue that copies the struct out and calls the compiler’s.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A callback C calls only during the binding&lt;/strong&gt; is released when the binding returns. &lt;strong&gt;A callback C
keeps&lt;/strong&gt; is bound with &lt;code&gt;keeps:&lt;/code&gt; naming its parameter: the record is held by the receiver (or the
handle the binding makes), so the closure lives as long as that handle. When the handle is
released, its class’s &lt;code&gt;forget:&lt;/code&gt; expression is run for each callback it holds, with &lt;code&gt;userdata&lt;/code&gt; the
record’s address, before &lt;code&gt;release&lt;/code&gt; — MLT’s &lt;code&gt;mlt_events_disconnect&lt;/code&gt; — so a C object something else
keeps alive cannot call into a freed record; a &lt;code&gt;forget:&lt;/code&gt; that is a C function’s name alone is
called &lt;code&gt;name(self, userdata)&lt;/code&gt;. A handle class that keeps callbacks and declares no &lt;code&gt;forget&lt;/code&gt; is
refused, as is a binding whose &lt;code&gt;keeps:&lt;/code&gt; names a function with no handle to keep it, and a
&lt;code&gt;consumes:&lt;/code&gt; naming a function. The record roots the function until then, so a kept function that
captures its own holder keeps both until &lt;code&gt;close()&lt;/code&gt; (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Any C call may run a callback C keeps&lt;/strong&gt;, so in a program that passes C a function every call of
a C library function is one during which the collector may run.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A callback belongs to the code that gave it&lt;/strong&gt;, and a call from any other thread stops the program,
as for a Sysl callback. &lt;strong&gt;A parameter marked &lt;code&gt;@threaded&lt;/code&gt; takes a function any thread may call&lt;/strong&gt;,
checked by its captures as a &lt;a href=&quot;/spec/sysl-bindings/#callbacks&quot;&gt;Sysl &lt;code&gt;@threaded&lt;/code&gt;
parameter&lt;/a&gt; is. A thread C started — MLT’s consumer renders on one
and fires &lt;code&gt;consumer-frame-show&lt;/code&gt; there — is attached to the runtime for the call and detached after,
so it may allocate, and a collection waits for it as for any running thread. A binding with a
&lt;code&gt;@threaded&lt;/code&gt; parameter is &lt;code&gt;blocking&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;C cannot say whether it calls from another thread&lt;/strong&gt;, as Sysl’s &lt;code&gt;&amp;amp;sync Fn&lt;/code&gt; does. A binding that
leaves &lt;code&gt;@threaded&lt;/code&gt; off a function C calls from its own thread is caught at run time, by the owner
check, at the first such call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A trap inside a callback stops the program, reported at its own place, however deep in C.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-is-refused&quot;&gt;What is refused&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Refused&lt;/th&gt;&lt;th&gt;Instead&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;A variadic function (&lt;code&gt;...&lt;/code&gt;)&lt;/td&gt;&lt;td&gt;A fixed-arity function the library offers, or a C wrapper the package carries (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;void *&lt;/code&gt; other than a callback’s &lt;code&gt;userdata&lt;/code&gt; or a parameter taking an array or a &lt;code&gt;ByteBlock&lt;/code&gt; (&lt;a href=&quot;#memory-of-no-type&quot;&gt;memory of no type&lt;/a&gt;)&lt;/td&gt;&lt;td&gt;A handle on a typed pointer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A pointer type in Avin code&lt;/td&gt;&lt;td&gt;Handles, arrays, out parameters and views&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A function pointer C answers&lt;/td&gt;&lt;td&gt;Bind the C functions it would point at&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;long double&lt;/code&gt;, &lt;code&gt;_Complex&lt;/code&gt;, vector types, &lt;code&gt;va_list&lt;/code&gt;&lt;/td&gt;&lt;td&gt;—&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A binding with no header to check it against&lt;/td&gt;&lt;td&gt;Name the header in &lt;code&gt;c-libraries&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Writing through a &lt;code&gt;ByteView&lt;/code&gt;, or a &lt;code&gt;writable&lt;/code&gt; binding of a &lt;code&gt;const&lt;/code&gt; pointer&lt;/td&gt;&lt;td&gt;A &lt;code&gt;MutByteView&lt;/code&gt; from a &lt;code&gt;writable&lt;/code&gt; binding, an array C fills, or a &lt;code&gt;ByteBlock&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An array of mirrors to a pointer that is not &lt;code&gt;const&lt;/code&gt;&lt;/td&gt;&lt;td&gt;An &lt;code&gt;out&lt;/code&gt; array C allocates (&lt;code&gt;array:&lt;/code&gt;), or a binding per element&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An array of strings, handles, &lt;code&gt;bool&lt;/code&gt;, or integers narrower than &lt;code&gt;int&lt;/code&gt;; an &lt;code&gt;Array[int]&lt;/code&gt; or &lt;code&gt;Array[long]&lt;/code&gt; to unsigned elements&lt;/td&gt;&lt;td&gt;A binding per element, or a buffer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An array whose length no parameter carries, or one passed &lt;code&gt;inout&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Mark the length &lt;code&gt;length(data)&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;An indexed field accessor with no &lt;code&gt;bound:&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Name the C expression that bounds the index&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;keeps:&lt;/code&gt; naming an array parameter, whose C copy lives for the call (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;)&lt;/td&gt;&lt;td&gt;A &lt;code&gt;ByteBlock&lt;/code&gt;, which is never copied&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;kept:&lt;/code&gt; on a class some binding makes without keeping one handle of the named class&lt;/td&gt;&lt;td&gt;Keep it in every binding that makes the class&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;soundness&quot;&gt;Soundness&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Avin has no pointer type and no &lt;code&gt;unsafe&lt;/code&gt; block.&lt;/strong&gt; Every pointer lives inside a binding’s
conversions, and safe Avin code sees only strings, arrays, handles, views, byte blocks and mirrors, each of which
is bounds-checked, owner-checked and closed-checked. &lt;strong&gt;The binding declarations are the trusted
surface&lt;/strong&gt;, and the whole of it: what a reviewer reads to trust a library is the lines that begin
&lt;code&gt;@c(&lt;/code&gt;, and the C glue they generate (&lt;a href=&quot;/spec/decisions/#proposed&quot;&gt;proposed&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;What the compiler checks of that surface is what it can: the prototype against the header, by clang;
the Avin types against the prototype; every integer at run time; every typedef’s kind and width and
every mirror’s layout on the target built for. What it takes on trust is what no header says: that a
result is owned or &lt;code&gt;borrowed&lt;/code&gt;, that a function &lt;code&gt;keeps&lt;/code&gt; or &lt;code&gt;consumes&lt;/code&gt; a pointer, that a buffer’s
&lt;code&gt;length&lt;/code&gt; or &lt;code&gt;bound:&lt;/code&gt; is right, that C calls a function only from the thread a missing &lt;code&gt;@threaded&lt;/code&gt;
implies, that &lt;code&gt;forget&lt;/code&gt; stops the callbacks, that &lt;code&gt;attach:&lt;/code&gt;‘s &lt;code&gt;destroy&lt;/code&gt; is called only once C has
finished with what it keeps, that a holder’s &lt;code&gt;release&lt;/code&gt; does not use a kept object held as the Avin
object (a handle with no &lt;code&gt;retain&lt;/code&gt; that no &lt;code&gt;kept:&lt;/code&gt; names, a &lt;code&gt;ByteBlock&lt;/code&gt;), which the collector may free
first, that a value a handle &lt;code&gt;holds:&lt;/code&gt; is its own to use in its release (a descriptor &lt;code&gt;dup&lt;/code&gt;ed for it,
not one another object closes), that what a closed &lt;code&gt;kept:&lt;/code&gt; handle freed with it is not touched, and that C
reads no more of a &lt;code&gt;ByteBlock&lt;/code&gt; than the library checked. A wrong &lt;code&gt;borrowed&lt;/code&gt; or &lt;code&gt;length&lt;/code&gt; is a binding bug of the kind a wrong
&lt;code&gt;extern&lt;/code&gt; is in C.&lt;/p&gt;
&lt;h2 id=&quot;an-example-two-clips-rendered-with-mlt&quot;&gt;An example: two clips rendered with MLT&lt;/h2&gt;
&lt;p&gt;The bindings, in the &lt;code&gt;mlt&lt;/code&gt; package’s own module (abridged to what the program uses):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;module mlt

import avin.threads
import avin.time

data MltError
  UnknownService(kind: string, name: string)
  InvalidProfile(name: string)
  Failed(call: string, code: int)

@c(type: &amp;quot;mlt_profile&amp;quot;, release: &amp;quot;mlt_profile_close&amp;quot;)
class Profile
  @c(field: &amp;quot;width&amp;quot;)
  width() -&amp;gt; int

@c(&amp;quot;mlt_profile mlt_profile_init(const char *name)&amp;quot;)
private profileInit(name: string) -&amp;gt; Option[Profile]

profile(name: string) -&amp;gt; Result[Profile, MltError] =
  profileInit(name).toRight(InvalidProfile(name))

@c(type: &amp;quot;mlt_properties&amp;quot;, release: &amp;quot;mlt_properties_close&amp;quot;, retain: &amp;quot;mlt_properties_inc_ref&amp;quot;)
class Properties

@c(value: &amp;quot;mlt_event_data&amp;quot;)
class EventData

@c(
    type: &amp;quot;mlt_producer&amp;quot;,
    release: &amp;quot;mlt_producer_close&amp;quot;,
    retain: &amp;quot;mlt_properties_inc_ref(mlt_producer_properties(self))&amp;quot;,
    as: [&amp;quot;mlt_service = mlt_producer_service(self)&amp;quot;]
)
class Producer

@c(
    &amp;quot;mlt_producer mlt_factory_producer(mlt_profile profile, const char *service, const char *resource)&amp;quot;,
    keeps: &amp;quot;profile&amp;quot;
)
private factoryProducer(profile: Profile, service: Option[string], resource: string) -&amp;gt; Option[Producer]

producer(profile: Profile, resource: string) -&amp;gt; Result[Producer, MltError] =
  factoryProducer(profile, None, resource).toRight(UnknownService(&amp;quot;producer&amp;quot;, resource))

@c(
    type: &amp;quot;mlt_playlist&amp;quot;,
    release: &amp;quot;mlt_playlist_close&amp;quot;,
    retain: &amp;quot;mlt_properties_inc_ref(mlt_playlist_properties(self))&amp;quot;,
    as: [&amp;quot;mlt_service = mlt_playlist_service(self)&amp;quot;]
)
class Playlist
  @c(&amp;quot;int mlt_playlist_append_io(mlt_playlist self, mlt_producer producer, int in, int out)&amp;quot;)
  private appendIoRaw(clip: Producer, from: int, to: int) -&amp;gt; Result[unit, int]

  appendIo(clip: Producer, from: int, to: int) -&amp;gt; Result[unit, MltError] =
    appendIoRaw(clip, from, to).mapErr(code -&amp;gt; Failed(&amp;quot;mlt_playlist_append_io&amp;quot;, code))

@c(&amp;quot;mlt_playlist mlt_playlist_new(mlt_profile profile)&amp;quot;, keeps: &amp;quot;profile&amp;quot;)
private playlistNew(profile: Profile) -&amp;gt; Option[Playlist]

playlist(profile: Profile) -&amp;gt; Result[Playlist, MltError] =
  playlistNew(profile).toRight(Failed(&amp;quot;mlt_playlist_new&amp;quot;, 0))

@c(
    type: &amp;quot;mlt_consumer&amp;quot;,
    release: &amp;quot;mlt_consumer_close&amp;quot;,
    retain: &amp;quot;mlt_properties_inc_ref(mlt_consumer_properties(self))&amp;quot;,
    as: [&amp;quot;mlt_properties = mlt_consumer_properties(self)&amp;quot;],
    forget: &amp;quot;mlt_events_disconnect(mlt_consumer_properties(self), userdata)&amp;quot;
)
class Consumer
  @c(&amp;quot;int mlt_properties_set(mlt_properties self, const char *name, const char *value)&amp;quot;)
  private setRaw(name: string, value: string) -&amp;gt; Result[unit, int]

  @c(&amp;quot;int mlt_properties_set_int(mlt_properties self, const char *name, int value)&amp;quot;)
  private setIntRaw(name: string, value: int) -&amp;gt; Result[unit, int]

  @c(
      &amp;quot;mlt_event mlt_events_listen(mlt_properties self, userdata void *data, const char *id, void (*listener)(mlt_properties owner, userdata void *data, mlt_event_data event))&amp;quot;,
      keeps: &amp;quot;listener&amp;quot;
  )
  on(event: string, @threaded listener: (Properties, EventData) -&amp;gt; unit)

  @c(&amp;quot;int mlt_consumer_connect(mlt_consumer self, mlt_service producer)&amp;quot;, keeps: &amp;quot;source&amp;quot;)
  private connectRaw(source: Playlist) -&amp;gt; Result[unit, int]

  @c(&amp;quot;int mlt_consumer_start(mlt_consumer self)&amp;quot;)
  private startRaw() -&amp;gt; Result[unit, int]

  @c(&amp;quot;int mlt_consumer_is_stopped(mlt_consumer self)&amp;quot;)
  private isStoppedRaw() -&amp;gt; int

  @c(&amp;quot;int mlt_consumer_stop(mlt_consumer self)&amp;quot;, blocking)
  private stopRaw() -&amp;gt; Result[unit, int]

  set(name: string, value: string) -&amp;gt; Result[unit, MltError] =
    setRaw(name, value).mapErr(code -&amp;gt; Failed(&amp;quot;mlt_properties_set&amp;quot;, code))

  setInt(name: string, value: int) -&amp;gt; Result[unit, MltError] =
    setIntRaw(name, value).mapErr(code -&amp;gt; Failed(&amp;quot;mlt_properties_set_int&amp;quot;, code))

  connect(source: Playlist) -&amp;gt; Result[unit, MltError] =
    connectRaw(source).mapErr(code -&amp;gt; Failed(&amp;quot;mlt_consumer_connect&amp;quot;, code))

  run() -&amp;gt; Result[unit, MltError] =
    startRaw().mapErr(code -&amp;gt; Failed(&amp;quot;mlt_consumer_start&amp;quot;, code))?
    while isStoppedRaw() == 0 do threads.sleep(time.millis(10))
    stopRaw().mapErr(code -&amp;gt; Failed(&amp;quot;mlt_consumer_stop&amp;quot;, code))

@c(
    &amp;quot;mlt_consumer mlt_factory_consumer(mlt_profile profile, const char *service, const char *input)&amp;quot;,
    keeps: &amp;quot;profile&amp;quot;
)
private factoryConsumer(profile: Profile, service: string, input: string) -&amp;gt; Option[Consumer]

consumer(profile: Profile, service: string, target: string) -&amp;gt; Result[Consumer, MltError] =
  factoryConsumer(profile, service, target).toRight(UnknownService(&amp;quot;consumer&amp;quot;, service))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The program: two coloured clips, one second each, rendered to an MP4, counting the frames the
consumer shows from its render thread.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import mlt.{profile, playlist, producer, consumer, MltError}
import avin.threads.Atomic

renderTitle(file: string) -&amp;gt; Result[int, MltError] =
  val prof = profile(&amp;quot;atsc_720p_25&amp;quot;)?
  val show = playlist(prof)?

  show.appendIo(producer(prof, &amp;quot;color:#202020&amp;quot;)?, 0, 24)?
  show.appendIo(producer(prof, &amp;quot;color:#c04000&amp;quot;)?, 0, 24)?

  val out = consumer(prof, &amp;quot;avformat&amp;quot;, file)?
  val frames = Atomic(0)

  out.set(&amp;quot;vcodec&amp;quot;, &amp;quot;mpeg4&amp;quot;)?
  out.setInt(&amp;quot;an&amp;quot;, 1)?
  out.on(&amp;quot;consumer-frame-show&amp;quot;, (_, _) -&amp;gt; frames.add(1))
  out.connect(show)?
  out.run()?

  Ok(frames.load())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What each piece of the chapter does here: &lt;code&gt;profile&lt;/code&gt; answers &lt;code&gt;None&lt;/code&gt; for a null &lt;code&gt;mlt_profile_init&lt;/code&gt;;
the producers and the playlist keep the profile, since MLT keeps only its pointer; &lt;code&gt;appendIo&lt;/code&gt; lends
each producer, and MLT takes its own reference, so the producers made inline are collected without
leaving the playlist; the listener is &lt;code&gt;@threaded&lt;/code&gt;, captures only a &lt;code&gt;val&lt;/code&gt; holding an &lt;code&gt;Atomic&lt;/code&gt;, and is
called on MLT’s render thread, attached for each call; the consumer keeps it until it is released,
and &lt;code&gt;forget&lt;/code&gt; disconnects it first; &lt;code&gt;run&lt;/code&gt; waits by polling, each &lt;code&gt;sleep&lt;/code&gt; safe for the collector, and
&lt;code&gt;stop&lt;/code&gt;, which joins the render thread, is &lt;code&gt;blocking&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;an-example-a-glyph-from-freetype-and-the-same-face-drawn-by-cairo&quot;&gt;An example: a glyph from FreeType, and the same face drawn by Cairo&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;freetype&lt;/code&gt; package binds FreeType 2, with the manifest &lt;a href=&quot;#c-libraries&quot;&gt;above&lt;/a&gt;; abridged to what the
program uses:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;module freetype

data FreeTypeError
  Failed(call: string, code: int)

@c(enum: &amp;quot;FT_Render_Mode&amp;quot;, prefix: &amp;quot;FT_RENDER_MODE_&amp;quot;)
data RenderMode
  Normal
  Light
  Mono
  Lcd
  LcdV

@c(const: &amp;quot;FT_LOAD_DEFAULT&amp;quot;)
val loadDefault: int

@c(type: &amp;quot;FT_Library&amp;quot;, release: &amp;quot;FT_Done_Library&amp;quot;, retain: &amp;quot;FT_Reference_Library&amp;quot;)
class Library

@c(&amp;quot;FT_Error FT_Init_FreeType(out FT_Library *library)&amp;quot;)
private initRaw() -&amp;gt; Result[Library, int]

init() -&amp;gt; Result[Library, FreeTypeError] = initRaw().mapErr(code -&amp;gt; Failed(&amp;quot;FT_Init_FreeType&amp;quot;, code))

@c(&amp;quot;FT_Error FT_New_Face(FT_Library library, const char *path, FT_Long index, out FT_Face *face)&amp;quot;, keeps: &amp;quot;library&amp;quot;)
private newFaceRaw(library: Library, path: string, index: long) -&amp;gt; Result[Face, int]

@c(
    &amp;quot;FT_Error FT_New_Memory_Face(FT_Library library, const FT_Byte *base, length(base) FT_Long size, FT_Long index, out FT_Face *face)&amp;quot;,
    keeps: [&amp;quot;library&amp;quot;, &amp;quot;base&amp;quot;]
)
private memoryFaceRaw(library: Library, base: ByteBlock, index: long) -&amp;gt; Result[Face, int]

openFace(library: Library, path: string) -&amp;gt; Result[Face, FreeTypeError] =
  newFaceRaw(library, path, 0).mapErr(code -&amp;gt; Failed(&amp;quot;FT_New_Face&amp;quot;, code))

data Glyph
  Glyph(width: int, rows: int, left: int, top: int, advance: real, pixels: Array[byte])

@c(struct: &amp;quot;FT_BBox&amp;quot;)
data BBox(@c(&amp;quot;xMin&amp;quot;) xMin: long, @c(&amp;quot;yMin&amp;quot;) yMin: long, @c(&amp;quot;xMax&amp;quot;) xMax: long, @c(&amp;quot;yMax&amp;quot;) yMax: long)

@c(struct: &amp;quot;FT_Size_Metrics&amp;quot;)
data SizeMetrics(
    xPpem: int,
    yPpem: int,
    xScale: long,
    yScale: long,
    ascender: long,
    descender: long,
    height: long,
    maxAdvance: long
)

@c(type: &amp;quot;FT_Face&amp;quot;, release: &amp;quot;FT_Done_Face&amp;quot;, retain: &amp;quot;FT_Reference_Face&amp;quot;, as: [&amp;quot;FT_GlyphSlot = self-&amp;gt;glyph&amp;quot;])
class Face
  @c(field: &amp;quot;family_name&amp;quot;)
  familyName() -&amp;gt; Option[string]

  @c(field: &amp;quot;num_glyphs&amp;quot;)
  glyphCount() -&amp;gt; long

  @c(field: &amp;quot;bbox&amp;quot;)
  boundingBox() -&amp;gt; BBox

  @c(field: &amp;quot;size-&amp;gt;metrics&amp;quot;)
  sizeMetrics() -&amp;gt; SizeMetrics

  @c(&amp;quot;FT_Error FT_Set_Pixel_Sizes(FT_Face self, FT_UInt width, FT_UInt height)&amp;quot;)
  private setPixelSizesRaw(width: int, height: int) -&amp;gt; Result[unit, int]

  @c(&amp;quot;FT_Error FT_Load_Char(FT_Face self, FT_ULong code, FT_Int32 flags)&amp;quot;)
  private loadCharRaw(code: long, flags: int) -&amp;gt; Result[unit, int]

  @c(&amp;quot;FT_Error FT_Render_Glyph(FT_GlyphSlot self, FT_Render_Mode mode)&amp;quot;)
  private renderRaw(mode: RenderMode) -&amp;gt; Result[unit, int]

  @c(field: &amp;quot;glyph-&amp;gt;bitmap.width&amp;quot;)
  private bitmapWidth() -&amp;gt; int
  @c(field: &amp;quot;glyph-&amp;gt;bitmap.rows&amp;quot;)
  private bitmapRows() -&amp;gt; int
  @c(field: &amp;quot;glyph-&amp;gt;bitmap.pitch&amp;quot;)
  private bitmapPitch() -&amp;gt; int
  @c(field: &amp;quot;glyph-&amp;gt;bitmap_left&amp;quot;)
  private bitmapLeft() -&amp;gt; int
  @c(field: &amp;quot;glyph-&amp;gt;bitmap_top&amp;quot;)
  private bitmapTop() -&amp;gt; int
  @c(field: &amp;quot;glyph-&amp;gt;advance.x&amp;quot;)
  private advanceX() -&amp;gt; long

  @c(
      field: &amp;quot;glyph-&amp;gt;bitmap.buffer&amp;quot;,
      view,
      length: &amp;quot;(self-&amp;gt;glyph-&amp;gt;bitmap.pitch &amp;lt; 0 ? -self-&amp;gt;glyph-&amp;gt;bitmap.pitch : self-&amp;gt;glyph-&amp;gt;bitmap.pitch) * self-&amp;gt;glyph-&amp;gt;bitmap.rows&amp;quot;
  )
  private bitmapRaw() -&amp;gt; Option[ByteView]

  setPixelSizes(width: int, height: int) -&amp;gt; Result[unit, FreeTypeError] =
    setPixelSizesRaw(width, height).mapErr(code -&amp;gt; Failed(&amp;quot;FT_Set_Pixel_Sizes&amp;quot;, code))

  render(c: char, mode: RenderMode = RenderMode.Normal) -&amp;gt; Result[Glyph, FreeTypeError] =
    loadCharRaw(long(int(c)), loadDefault).mapErr(code -&amp;gt; Failed(&amp;quot;FT_Load_Char&amp;quot;, code))?
    renderRaw(mode).mapErr(code -&amp;gt; Failed(&amp;quot;FT_Render_Glyph&amp;quot;, code))?
    val (width, rows, pitch) = (bitmapWidth(), bitmapRows(), bitmapPitch())
    val (left, top, advance) = (bitmapLeft(), bitmapTop(), real(advanceX()) / 64.0)
    val stride = if pitch &amp;lt; 0 then -pitch else pitch
    val pixels = Buffer[byte]()
    bitmapRaw() match
      Some(bits) -&amp;gt;
        for r in 0 ..&amp;lt; rows
          val row = if pitch &amp;gt; 0 then r else rows - 1 - r
          pixels.appendAll(bits.slice(row * stride, row * stride + width))
      None -&amp;gt; ()
    Ok(Glyph(width, rows, left, top, advance, pixels.toArray()))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What each piece does here: a &lt;code&gt;Face&lt;/code&gt; holds a C reference to its &lt;code&gt;Library&lt;/code&gt;, so the two are given back
in FreeType’s order whichever the collector finalizes first, each reference by &lt;code&gt;FT_Done_Library&lt;/code&gt;,
which frees the library only with its last; a face’s box and its size’s metrics are read whole as
struct mirrors, and the family name, an &lt;code&gt;FT_String *&lt;/code&gt;, a typedef of &lt;code&gt;char&lt;/code&gt;, is a string; a face made
over memory keeps the &lt;code&gt;ByteBlock&lt;/code&gt; FreeType reads lazily for the face’s whole life, which an array,
copied for the call, could not be (&lt;code&gt;FT_Done_Face&lt;/code&gt; reads none of it, so the block may be freed first). The glyph slot is
the face’s own, reached through field expressions and passed to &lt;code&gt;FT_Render_Glyph&lt;/code&gt; through &lt;code&gt;as:&lt;/code&gt;,
since it has no reference count of its own to be a handle by. Its scalar fields are read before the
bitmap is lent, because each read is a use of the face and would close the view; the bitmap is copied
row by row into immutable data, top row first whatever the sign of &lt;code&gt;pitch&lt;/code&gt;, and the advance, in 26.6
fixed point, is divided by 64. A load or render that fails answers the library’s error; the glyph’s
pixels are never read from a failed load.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;cairo&lt;/code&gt; package depends on &lt;code&gt;freetype&lt;/code&gt; and makes a Cairo font face from a FreeType one. &lt;strong&gt;Cairo
keeps the &lt;code&gt;FT_Face&lt;/code&gt; without referencing it, and the face must outlive every Cairo font face made from
it&lt;/strong&gt; — Cairo’s own documentation asks for the face to be given back from the font face’s user-data
destructor. Contexts and scaled fonts reference the font face, so it can outlive the Avin &lt;code&gt;FontFace&lt;/code&gt;,
and &lt;code&gt;keeps:&lt;/code&gt; on the handle alone would let the &lt;code&gt;Face&lt;/code&gt; be collected while Cairo still draws with it.
The &lt;code&gt;FontFace&lt;/code&gt; class ties what it keeps to the C object instead, with
&lt;a href=&quot;#when-c-holds-the-object-longer-than-avin-does&quot;&gt;&lt;code&gt;attach:&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;module cairo

import freetype.Face

@c(
    type: &amp;quot;cairo_font_face_t *&amp;quot;,
    release: &amp;quot;cairo_font_face_destroy&amp;quot;,
    retain: &amp;quot;cairo_font_face_reference&amp;quot;,
    attach: &amp;quot;cairo_font_face_set_user_data(self, key, data, destroy)&amp;quot;,
    key: &amp;quot;cairo_user_data_key_t&amp;quot;
)
class FontFace
  @c(&amp;quot;cairo_status_t cairo_font_face_status(cairo_font_face_t *self)&amp;quot;)
  status() -&amp;gt; Result[unit, Status]

@c(&amp;quot;cairo_font_face_t *cairo_ft_font_face_create_for_ft_face(FT_Face face, int load_flags)&amp;quot;, keeps: &amp;quot;face&amp;quot;)
private ftFontFace(face: Face, loadFlags: int) -&amp;gt; FontFace

fontFace(face: Face) -&amp;gt; Result[FontFace, CairoError] =
  val made = ftFontFace(face, 0)
  made.status().mapErr(CairoError.from)?
  Ok(made)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The manifest adds the &lt;code&gt;cairo-ft&lt;/code&gt; module (&lt;code&gt;pkg-config = &amp;quot;cairo-ft&amp;quot;&lt;/code&gt;, &lt;code&gt;headers = [&amp;quot;&amp;lt;cairo-ft.h&amp;gt;&amp;quot;]&lt;/code&gt;),
and the binding is checked with &lt;code&gt;freetype&lt;/code&gt;‘s headers included first. The &lt;code&gt;Face&lt;/code&gt; goes into the font
face’s attached record, a root of the collector, and Cairo’s call of &lt;code&gt;destroy&lt;/code&gt; when the last
reference to the font face goes — from a context, a scaled font or the Avin handle, in any order —
unpins it; the &lt;code&gt;Face&lt;/code&gt; is then collected like any other, and its finalizer gives back the face, and
after it the face’s reference to its library. Cairo answers the font face it already has for an
&lt;code&gt;FT_Face&lt;/code&gt; and flags it was given before, and attaching again replaces the record, calling &lt;code&gt;destroy&lt;/code&gt;
for the old one, while the new record keeps the &lt;code&gt;Face&lt;/code&gt;. A failure is latched on the font face, as
Cairo’s &lt;a href=&quot;#errors-kept-on-the-object&quot;&gt;errors kept on the object&lt;/a&gt; are, and &lt;code&gt;fontFace&lt;/code&gt; asks it at once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cairo uses the &lt;code&gt;FT_Face&lt;/code&gt; itself&lt;/strong&gt;: drawing text with the font face sets its size and loads glyphs
into its slot, so a glyph rendered through the &lt;code&gt;Face&lt;/code&gt; after Cairo has drawn must be loaded again,
which &lt;code&gt;render&lt;/code&gt; always does, and the two are used on one thread, the &lt;code&gt;Face&lt;/code&gt;‘s owner check holding for
the Avin calls. &lt;code&gt;cairo_ft_font_options_substitute&lt;/code&gt; takes a fontconfig pattern, and is left to a
fontconfig binding.&lt;/p&gt;
&lt;h2 id=&quot;relationship-to-sysl-bindings&quot;&gt;Relationship to Sysl bindings&lt;/h2&gt;
&lt;p&gt;The two kinds of binding sit side by side, and a program may use both. A library Sysl already binds
well is reached through Sysl; a C library is bound directly. The Sysl boundary’s rules are the C
boundary’s wherever both have the same question — integer conversions, &lt;code&gt;Option&lt;/code&gt;, handles and their
owners, &lt;code&gt;blocking&lt;/code&gt;, callbacks and &lt;code&gt;@threaded&lt;/code&gt; — and differ where C has no Sysl signature to check
against: the header is checked instead, by clang, and what no header says is written in the binding.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Call-by-name</title>
    <link href="https://avinlang.dev/spec/by-name/"/>
    <id>https://avinlang.dev/spec/by-name/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>Parameters written value -&gt; T are evaluated on each use, never at the call and never cached.</summary>
    <content type="html">&lt;p&gt;A parameter declared &lt;code&gt;value: -&amp;gt; T&lt;/code&gt; takes an expression that is &lt;strong&gt;not&lt;/strong&gt; evaluated at the call. Each
read of the parameter evaluates the expression again, and a parameter that is never read never
evaluates it. There is no memoization; a body that needs the value twice binds it to a &lt;code&gt;val&lt;/code&gt; once.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;twice(value: -&amp;gt; int) = value + value

unless(condition: bool, action: -&amp;gt; unit)
  if !condition then action
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The arrow is Sysl’s &lt;code&gt;-&amp;gt;&lt;/code&gt;, as in every Avin function type.&lt;/p&gt;
&lt;h2 id=&quot;modes-are-part-of-the-type&quot;&gt;Modes are part of the type&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;(-&amp;gt; int) -&amp;gt; int&lt;/code&gt; takes a by-name input; &lt;code&gt;(int) -&amp;gt; int&lt;/code&gt; takes a strict one; &lt;code&gt;(() -&amp;gt; int) -&amp;gt; int&lt;/code&gt;
takes a function value, which the body calls explicitly. These are three different types, and a value
of one does not convert implicitly to another.&lt;/p&gt;
&lt;p&gt;Passing a by-name parameter on to another by-name parameter forwards the delayed expression without
evaluating it. &lt;code&gt;f: -&amp;gt; (int) -&amp;gt; int&lt;/code&gt; delays the production of a function, and &lt;code&gt;f(1)&lt;/code&gt; first evaluates
the delayed expression, then calls the result.&lt;/p&gt;
&lt;h2 id=&quot;defaults&quot;&gt;Defaults&lt;/h2&gt;
&lt;p&gt;A by-name parameter may have a &lt;a href=&quot;/spec/declarations/#default-and-named-arguments&quot;&gt;default&lt;/a&gt;, which is
a delayed expression like any argument to it: a call that omits the argument passes the default
unevaluated, each read of the parameter evaluates it again, and a parameter that is never read never
evaluates it. A default that reads an earlier by-name parameter evaluates that parameter’s argument
at each of its own evaluations.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;orElse(value: int, fallback: -&amp;gt; int = expensive()) = if value &amp;gt;= 0 then value else fallback
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A named argument to a by-name parameter is delayed too, though the arguments written around it are
evaluated at the call.&lt;/p&gt;
&lt;h2 id=&quot;trailing-blocks&quot;&gt;Trailing blocks&lt;/h2&gt;
&lt;p&gt;A by-name last parameter takes an indented block written after the call’s line as its
&lt;a href=&quot;/spec/operators-and-control-flow/#trailing-blocks&quot;&gt;trailing block&lt;/a&gt;, which makes a function read like
a control form of the language:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;times(n: int, action: -&amp;gt; unit)
  var i = 0
  while i &amp;lt; n
    action
    i += 1

times(3)
  println(&amp;quot;tick&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The block is the delayed expression, with every rule above: it runs at each read of &lt;code&gt;action&lt;/code&gt;, never
at the call, it yields its last expression, and a &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; leaving it is an
error.&lt;/p&gt;
&lt;h2 id=&quot;restrictions&quot;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;data&lt;/code&gt; fields cannot be by-name, and neither can repeated (&lt;code&gt;T*&lt;/code&gt;) parameters, nor the parameters
of a function defined by clauses, whose patterns match the arguments’ values. Inside a delayed
expression, a &lt;code&gt;return&lt;/code&gt;, &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; that would leave the expression is a compile error.&lt;/p&gt;
&lt;h2 id=&quot;representation&quot;&gt;Representation&lt;/h2&gt;
&lt;p&gt;A delayed argument is a closure with no parameters. When it cannot escape, which is always the case
for a parameter that is only read or forwarded, its environment lives on the caller’s stack.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Actors and state machines</title>
    <link href="https://avinlang.dev/spec/actors/"/>
    <id>https://avinlang.dev/spec/actors/</id>
    <updated>2026-11-25T23:48:40.523555309Z</updated>
    <summary>`actor` and `machine` declarations: typed messages, what may be sent and how the compiler checks it, `tell` and `ask`, supervision of a trap, lifecycle and watching, scheduling on a pool, routers and topics, and states with transitions and stashed messages.</summary>
    <content type="html">&lt;p&gt;Avin’s way to thread safety is &lt;strong&gt;no shared data where it can be avoided&lt;/strong&gt;. An actor owns its state
outright, and the only way to reach that state is to send the actor a message. Messages carry
immutable values, or hand over the ownership of something mutable, and never a reference that two
actors could both change. The compiler checks every message type, so a program that compiles never
shares mutable data through a message.&lt;/p&gt;
&lt;p&gt;The pieces fit together without special cases: an actor is declared like a class, its messages are a
&lt;code&gt;data&lt;/code&gt; type, receiving one is a &lt;code&gt;match&lt;/code&gt;, a reply arrives as a &lt;a href=&quot;/spec/threads/#futures&quot;&gt;&lt;code&gt;Future&lt;/code&gt;&lt;/a&gt;, and
an actor’s behaviour, where it has distinct phases, is written as a state machine in the same body.
Everything runs on the threads, executors and memory model of &lt;a href=&quot;/spec/threads/&quot;&gt;&lt;code&gt;avin.threads&lt;/code&gt;&lt;/a&gt;; the
library is &lt;code&gt;avin.actors&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;declaring-an-actor&quot;&gt;Declaring an actor&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.actors.{ActorRef, spawn}

data CounterMsg
  Increment(by: int)
  Get(replyTo: ActorRef[int])
  Reset

actor Counter(start: int) receives CounterMsg
  var count = start

  receive
    Increment(by) -&amp;gt; count += by
    Get(replyTo) -&amp;gt; replyTo.tell(count)
    Reset -&amp;gt; count = 0
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;actor Name(params) receives M&lt;/code&gt;&lt;/strong&gt; declares an actor whose messages are of type &lt;code&gt;M&lt;/code&gt;, usually a
&lt;code&gt;data&lt;/code&gt; type whose variants are the messages. An actor may be generic, &lt;code&gt;actor Cache[K: Hash + Sendable, V: Sendable](limit: int) receives CacheMsg[K, V]&lt;/code&gt;, and its parameters follow the rules
for a class’s, with defaults and named arguments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The body is the actor’s start.&lt;/strong&gt; Its fields and statements run once, on the actor’s own
execution, before it handles any message: that is where its state is made. The parameters are its
immutable fields, as a class’s plain parameters are, and each one’s type must be &lt;code&gt;Sendable&lt;/code&gt;, which
is checked where the actor is declared. Since an actor runs on any of an executor’s workers,
nothing its body, its arms or its methods reach may be a module-level &lt;code&gt;var&lt;/code&gt; or a module-level
value that is not sendable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;receive&lt;/code&gt; holds the arms&lt;/strong&gt; that handle a message: exactly a &lt;code&gt;match&lt;/code&gt;‘s arms over &lt;code&gt;M&lt;/code&gt;, with
patterns, guards and block bodies, and checked for exhaustiveness and for unreachable arms in the same way. A message the
actor wants to ignore is handled by an arm that does nothing, &lt;code&gt;_ -&amp;gt; ()&lt;/code&gt;, so ignoring one is always
written down. Each arm’s value is discarded.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Methods&lt;/strong&gt; in the body are the actor’s own helpers, with the implicit receiver a class’s methods
have. They are private: an actor has no members anyone else can call, since only its messages
reach it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;self&lt;/code&gt; is the actor’s reference&lt;/strong&gt;, an &lt;code&gt;ActorRef[M]&lt;/code&gt;, which it hands out so others can reply to
it or send it more work. The object holding the actor’s fields is never a value the program sees,
so no reference to an actor’s state can escape the actor.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;Counter(0)&lt;/code&gt; does not start anything. It makes a &lt;strong&gt;&lt;code&gt;Behaviour[CounterMsg]&lt;/code&gt;&lt;/strong&gt;: an immutable value
holding the declaration and its arguments, which &lt;code&gt;spawn&lt;/code&gt; starts. Keeping the two apart lets the
program say how a new actor is to be supervised and where it runs before it starts, and lets the
runtime start the actor again from the same arguments after a failure (&lt;a href=&quot;#supervision&quot;&gt;Supervision&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A behaviour is also made without a declaration, from a name and a start:
&lt;strong&gt;&lt;code&gt;Behaviour[M](name: string, start: @sendable (ActorRef[M]) -&amp;gt; (M) -&amp;gt; unit)&lt;/code&gt;&lt;/strong&gt;. The start runs
once, on the actor’s first turn, is given the actor’s own reference, makes the actor’s state in its
locals and gives back the handler of each message. It is a &lt;a href=&quot;/spec/types/#function-types&quot;&gt;&lt;code&gt;@sendable&lt;/code&gt;
function&lt;/a&gt;, so it captures only sendable values and no &lt;code&gt;var&lt;/code&gt;, and
reaches no module-level mutable state. An &lt;code&gt;actor&lt;/code&gt; declaration is this, written as a class is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.actors.{Behaviour, spawn}
import avin.threads.Promise

main()
  val total = Promise[int]()
  val counter = spawn(Behaviour[int](&amp;quot;Counter&amp;quot;, me -&amp;gt;
    var count = 0
    n -&amp;gt;
      count += n
      if n == 0 then total.complete(count)))
  counter.tell(5)
  counter tell 2
  counter.tell(0)
  println(total.future.await())
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;starting-telling-and-asking&quot;&gt;Starting, telling and asking&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;import avin.actors.{spawn, AskError}
import avin.time

main() -&amp;gt; int
  val counter = spawn(Counter(10))
  counter.tell(Increment(5))
  counter tell Increment(2)
  val answer = counter.ask(r -&amp;gt; Get(r), timeout = time.seconds(1)).await()
  answer match
    Ok(n) -&amp;gt; n
    Err(_) -&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;spawn[M](behaviour: Behaviour[M], onFailure: Supervision = Escalate, executor: Executor = Executor.shared(), mailbox: Mailbox = Unbounded) -&amp;gt; ActorRef[M]&lt;/code&gt;&lt;/strong&gt; starts the actor and gives back
its reference at once; the body runs on the executor’s threads, and messages sent before it has
finished queue behind it. Called by code an actor is running, &lt;code&gt;spawn&lt;/code&gt; starts a &lt;strong&gt;child&lt;/strong&gt; of that
actor; called anywhere else (&lt;code&gt;main&lt;/code&gt;, a thread, a future’s body) it starts a &lt;strong&gt;top-level&lt;/strong&gt; actor.
&lt;code&gt;mailbox&lt;/code&gt; &lt;a href=&quot;#bounded-mailboxes&quot;&gt;bounds&lt;/a&gt; the messages that may wait.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tell(message: M)&lt;/code&gt;&lt;/strong&gt; puts the message in the actor’s mailbox and returns at once; it never waits
and never fails. A tell to a full &lt;a href=&quot;#bounded-mailboxes&quot;&gt;bounded mailbox&lt;/a&gt; is dropped as its overflow
policy says. &lt;code&gt;!&lt;/code&gt; is a reserved spelling in Avin, so there is no operator for it, and &lt;code&gt;tell&lt;/code&gt; is
written infix where that reads better (&lt;code&gt;counter tell Reset&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;ask[R: Sendable](make: ActorRef[R] -&amp;gt; M, timeout: Duration) -&amp;gt; Future[Result[R, AskError]]&lt;/code&gt;&lt;/strong&gt;
makes a reference that accepts one reply, builds the message around it with &lt;code&gt;make&lt;/code&gt;, sends it, and
gives back the future of the reply. The first message to the reply reference completes the future
with &lt;code&gt;Ok&lt;/code&gt;; any later one is dropped. &lt;code&gt;AskError&lt;/code&gt; is &lt;code&gt;TimedOut&lt;/code&gt; where no reply arrived within
&lt;code&gt;timeout&lt;/code&gt;, &lt;code&gt;Ended&lt;/code&gt; where the asked actor had already ended, so the message could not be
delivered, and &lt;code&gt;Full&lt;/code&gt; where its bounded mailbox was full, so the question was not put in it. The
timeout is required: an ask always ends.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A reply address is an ordinary &lt;code&gt;ActorRef[R]&lt;/code&gt;.&lt;/strong&gt; An actor that asks another passes the reply
reference &lt;code&gt;ask&lt;/code&gt; makes, or its own &lt;code&gt;self&lt;/code&gt; where its message type is &lt;code&gt;R&lt;/code&gt;, or an &lt;strong&gt;adapter&lt;/strong&gt;:
&lt;code&gt;adapter[R: Sendable](f: R -&amp;gt; M) -&amp;gt; ActorRef[R]&lt;/code&gt;, called in an actor, makes a reference whose
messages arrive in this actor’s mailbox as &lt;code&gt;f&lt;/code&gt; of them, so an actor talks to one with another
protocol without widening its own message type. &lt;code&gt;f&lt;/code&gt; runs where the message is sent, so it is
&lt;code&gt;@sendable&lt;/code&gt;; the adapter refers to this actor, equal to its &lt;code&gt;self&lt;/code&gt; and ending with it. The
reference an ask makes is shown as &lt;code&gt;Reply#1&lt;/code&gt;, the replies numbered apart from the actors, and
ends once its ask is answered or has timed out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;ActorRef[-M]&lt;/code&gt;&lt;/strong&gt; is contravariant: a reference that accepts every &lt;code&gt;Shape&lt;/code&gt; is also one that
accepts &lt;code&gt;Circle&lt;/code&gt;s. It compares by the actor it refers to (&lt;code&gt;==&lt;/code&gt; and &lt;code&gt;hash&lt;/code&gt;), is &lt;code&gt;Sendable&lt;/code&gt; and is shown
as the declaration’s name and a number, &lt;code&gt;Counter#3&lt;/code&gt;, the actors of a program being numbered from
one in the order they are spawned. It holds no state, so holding one keeps
nothing but the reference alive.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any thread may &lt;code&gt;tell&lt;/code&gt; and &lt;code&gt;ask&lt;/code&gt;. Inside an actor, waiting for an ask’s future with &lt;code&gt;await&lt;/code&gt; holds the
actor: it handles no other message until the reply comes, which is sometimes what is wanted. The
usual way is &lt;strong&gt;&lt;code&gt;pipeToSelf[T](future: Future[T], f: T -&amp;gt; M)&lt;/code&gt;&lt;/strong&gt;, which sends the actor &lt;code&gt;f&lt;/code&gt; of the
value once the future completes, so the actor goes on handling messages meanwhile; a future complete
already sends at once, before anything the actor sends itself after the call. &lt;code&gt;f&lt;/code&gt; runs in the
actor’s own turn, so a trap in it fails this actor, not whatever completed the future. An actor
that awaits an ask of itself waits until the timeout.&lt;/p&gt;
&lt;p&gt;An adapter’s &lt;code&gt;f&lt;/code&gt; runs where the message is sent, so a trap in it is the sender’s: it fails the
actor that sent, or stops the program where &lt;code&gt;main&lt;/code&gt; or a thread sent.&lt;/p&gt;
&lt;h3 id=&quot;mailboxes-and-order&quot;&gt;Mailboxes and order&lt;/h3&gt;
&lt;p&gt;A mailbox is a queue, unbounded unless the actor was given a bound. &lt;strong&gt;Two messages one sender sends
to one actor arrive in the order they were sent&lt;/strong&gt;; messages from different senders interleave in any
order. A message sent to an actor that has ended is dropped, since an actor ending while messages
are on their way to it is an ordinary race and not a bug; a program that needs to know when an
actor ends &lt;a href=&quot;#lifecycle&quot;&gt;watches&lt;/a&gt; it, and an ask of one completes with &lt;code&gt;Ended&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;bounded-mailboxes&quot;&gt;Bounded mailboxes&lt;/h3&gt;
&lt;p&gt;An unbounded mailbox lets a fast sender grow a slow actor’s memory without limit. An actor spawned
with &lt;strong&gt;&lt;code&gt;mailbox = Bounded(capacity, overflow)&lt;/code&gt;&lt;/strong&gt; holds at most &lt;code&gt;capacity&lt;/code&gt; of the messages its
references send, and its senders choose how to meet a full one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.actors.{Bounded, DropOldest, spawn}
import avin.threads.{Future, Promise}
import avin.time

data Reading
  Pause(started: Promise[unit], resume: Future[unit])
  Value(n: int)
  Latest(values: Promise[string])

actor Gauge receives Reading
  val values = Buffer[int]()
  receive
    Pause(started, resume) -&amp;gt;
      started.complete(())
      resume.await()
    Value(n) -&amp;gt; values.append(n)
    Latest(p) -&amp;gt; p.complete(s&amp;quot;$values&amp;quot;)

main()
  val gauge = spawn(Gauge(), mailbox = Bounded(3, DropOldest))
  val started = Promise[unit]()
  val resume = Promise[unit]()
  gauge.tell(Pause(started, resume.future))
  started.future.await()
  for n in 1 .. 5 do gauge tell Value(n)
  println(gauge.offer(Value(6)))
  println(gauge.dropped())
  resume.complete(())
  val latest = Promise[string]()
  println(gauge.send(Latest(latest), time.seconds(5)))
  println(latest.future.await())
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Err(the actor&apos;s mailbox was full)
2
Ok(())
[3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;data Mailbox&lt;/code&gt;&lt;/strong&gt; is &lt;code&gt;Unbounded&lt;/code&gt;, the default, or &lt;strong&gt;&lt;code&gt;Bounded(capacity: int, overflow: Overflow)&lt;/code&gt;&lt;/strong&gt;. A capacity less than one traps in &lt;code&gt;spawn&lt;/code&gt;. The bound is the actor’s for its whole
life: a &lt;a href=&quot;#supervision&quot;&gt;restart&lt;/a&gt; keeps the mailbox, the messages in it and its bound.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tell&lt;/code&gt; never waits&lt;/strong&gt;, so a tell to a full mailbox is settled by the &lt;strong&gt;&lt;code&gt;Overflow&lt;/code&gt;&lt;/strong&gt;: &lt;strong&gt;&lt;code&gt;DropNewest&lt;/code&gt;&lt;/strong&gt;
drops the message told, and &lt;strong&gt;&lt;code&gt;DropOldest&lt;/code&gt;&lt;/strong&gt; drops the oldest message waiting that a reference
sent, and puts the one told at the back. Either way the message dropped is gone as a message sent
to an ended actor is; a question among them times out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;offer(message: M) -&amp;gt; Result[unit, SendError]&lt;/code&gt;&lt;/strong&gt; puts the message in only where there is room
now, and never waits: &lt;code&gt;Err(Full)&lt;/code&gt; where the mailbox is full, &lt;code&gt;Err(Ended)&lt;/code&gt; where the actor has
ended, the message then put nowhere and its handles still the sender’s. An unbounded mailbox is
never full.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;send(message: M) -&amp;gt; Result[unit, SendError]&lt;/code&gt;&lt;/strong&gt; waits while the mailbox is full until the actor
takes a message and there is room, the backpressure a producer that must not outrun its consumer
wants; &lt;strong&gt;&lt;code&gt;send(message: M, timeout: Duration)&lt;/code&gt;&lt;/strong&gt; waits at most &lt;code&gt;timeout&lt;/code&gt;, answering &lt;code&gt;Err(TimedOut)&lt;/code&gt;
where no room came, and a timeout of zero or less is &lt;code&gt;offer&lt;/code&gt;. A sender waiting when the actor ends
is told &lt;code&gt;Err(Ended)&lt;/code&gt;. The wait parks only the waiting thread, counts for the
&lt;a href=&quot;/spec/threads/#deadlock&quot;&gt;deadlock check&lt;/a&gt;, and is a &lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation
point&lt;/a&gt;: a cancelled sender stops there and leaves nothing in the
mailbox. Senders waiting are let in as room frees, each sender’s messages in the order it sent
them. An actor that sends to its own full mailbox has &lt;code&gt;Err(Full)&lt;/code&gt; at once, since nothing could make
room while its turn waits; to an unbounded or roomy one, &lt;code&gt;send&lt;/code&gt; is &lt;code&gt;tell&lt;/code&gt; that answers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;ask&lt;/code&gt; never waits for room&lt;/strong&gt; and never drops for it: an ask of a full mailbox completes at once
with &lt;code&gt;Err(Full)&lt;/code&gt;, under either policy, rather than waiting out its timeout.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;dropped() -&amp;gt; long&lt;/code&gt;&lt;/strong&gt; on the reference counts the messages the overflow policy has dropped since
the actor started; a refused &lt;code&gt;offer&lt;/code&gt; or &lt;code&gt;send&lt;/code&gt;, and the messages dropped as the actor ends, are not
among them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What the actor arranged for itself is never refused.&lt;/strong&gt; A &lt;a href=&quot;#lifecycle&quot;&gt;watch&lt;/a&gt;‘s notice of an end,
a &lt;a href=&quot;#timers&quot;&gt;timer&lt;/a&gt;‘s message and a &lt;code&gt;pipeToSelf&lt;/code&gt;‘s message are put in the mailbox whatever it holds
and do not count against the bound, so a full mailbox drops no notice. A stop, a restart and a
child’s failure are not messages, and a full mailbox never holds them back. The messages a
&lt;a href=&quot;#setting-messages-aside&quot;&gt;stash&lt;/a&gt; gives back have passed the bound once, and do not count against it
again.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SendError&lt;/code&gt; is &lt;code&gt;Full&lt;/code&gt;, &lt;code&gt;TimedOut&lt;/code&gt; or &lt;code&gt;Ended&lt;/code&gt;; &lt;code&gt;Full&lt;/code&gt; and &lt;code&gt;Ended&lt;/code&gt; are names &lt;code&gt;AskError&lt;/code&gt; has too, and
each is decided by the type expected where it is written.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-may-be-sent&quot;&gt;What may be sent&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;A message type, an actor’s parameters and every type &lt;code&gt;ask&lt;/code&gt; and &lt;code&gt;adapter&lt;/code&gt; carry must be
&lt;code&gt;Sendable&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;Sendable&lt;/code&gt; is a trait the compiler decides for each type from its structure; it is
written as a bound like any trait (&lt;code&gt;[T: Sendable]&lt;/code&gt;), and &lt;code&gt;ActorRef[M]&lt;/code&gt;‘s parameter is bounded by it,
so the check is made once, where the type is named, and never at a send:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Sendable&lt;/th&gt;&lt;th&gt;Why&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;int&lt;/code&gt; and the other integers, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;real&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;unit&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;&lt;/td&gt;&lt;td&gt;immutable values&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;tuples, &lt;code&gt;data&lt;/code&gt; types (&lt;code&gt;Option&lt;/code&gt;, &lt;code&gt;Result&lt;/code&gt; and &lt;code&gt;Either&lt;/code&gt; among them) whose fields are all sendable&lt;/td&gt;&lt;td&gt;immutable values&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Vector&lt;/code&gt;, &lt;code&gt;ArraySeq&lt;/code&gt;, &lt;code&gt;Range&lt;/code&gt;, the immutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt;, of sendable elements&lt;/td&gt;&lt;td&gt;immutable, persistent collections&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;a class with no &lt;code&gt;var&lt;/code&gt; field, whose fields are all sendable, and which is not &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt;; an &lt;code&gt;object&lt;/code&gt; likewise&lt;/td&gt;&lt;td&gt;deeply immutable: no code can change it, and a subclass cannot add a &lt;code&gt;var&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;a trait declared &lt;code&gt;: Sendable&lt;/code&gt;&lt;/td&gt;&lt;td&gt;every type implementing it is checked to be sendable, at its &lt;code&gt;impl&lt;/code&gt; or declaration&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ActorRef[M]&lt;/code&gt;, &lt;code&gt;Behaviour[M]&lt;/code&gt;, &lt;code&gt;Future[T]&lt;/code&gt; and &lt;code&gt;Promise[T]&lt;/code&gt; of a sendable &lt;code&gt;T&lt;/code&gt;&lt;/td&gt;&lt;td&gt;made to be handed between threads&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Channel[T]&lt;/code&gt; and &lt;code&gt;Atomic[T]&lt;/code&gt; of a sendable &lt;code&gt;T&lt;/code&gt;, &lt;code&gt;Mutex[T]&lt;/code&gt; and &lt;code&gt;RwLock[T]&lt;/code&gt; of any &lt;code&gt;T&lt;/code&gt;, a mutex’s &lt;code&gt;Condition&lt;/code&gt;, &lt;code&gt;Once&lt;/code&gt;, &lt;code&gt;WaitGroup&lt;/code&gt;, &lt;code&gt;Semaphore&lt;/code&gt;, &lt;code&gt;Barrier&lt;/code&gt;&lt;/td&gt;&lt;td&gt;synchronization: every access is synchronized, and a mutex’s value is reached only under its lock, so a mutex is the one deliberate door to shared mutable state&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Thread[T]&lt;/code&gt; of a sendable &lt;code&gt;T&lt;/code&gt;, an &lt;code&gt;Executor&lt;/code&gt;&lt;/td&gt;&lt;td&gt;joining a thread and giving an executor work are synchronized&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;a &lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl handle&lt;/a&gt;&lt;/td&gt;&lt;td&gt;sent by handing over its ownership, checked when it is used (below)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Isolated[T]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;an object graph nothing else reaches, or an array moved out of the sender’s hands (below)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;a &lt;a href=&quot;/spec/types/#function-types&quot;&gt;&lt;code&gt;@sendable&lt;/code&gt; function type&lt;/a&gt;, &lt;code&gt;@sendable (A) -&amp;gt; B&lt;/code&gt;&lt;/td&gt;&lt;td&gt;checked where each value is made: it captures only sendable values and no &lt;code&gt;var&lt;/code&gt;, and reaches no module-level mutable state&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Not sendable&lt;/strong&gt;: &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;, the mutable maps and sets, a class with a &lt;code&gt;var&lt;/code&gt; field
or a field that is not sendable, an &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class, a &lt;a href=&quot;#state-machines&quot;&gt;machine&lt;/a&gt;, a
thread &lt;code&gt;Scope&lt;/code&gt;, a value of a plain function type, and &lt;code&gt;Any&lt;/code&gt;. A plain function value is not sendable
because its type does not say what it captures, and a captured &lt;code&gt;var&lt;/code&gt; is shared with the scope that
made it; a closure given to another thread is checked instead by what it captures, where it is
written, and one made as a &lt;code&gt;@sendable&lt;/code&gt; function is checked where it is made (&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;what is
shared&lt;/a&gt;). The error names the part that is not sendable:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: `JobMsg` cannot be sent between actors: its variant `Fill` holds a `Buffer[byte]`, which is mutable; send an immutable copy (`toVector`), or the buffer as an `Isolated[Buffer[byte]]`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An &lt;code&gt;Array&lt;/code&gt; is not sendable either, however it is used; it crosses without a copy as an
&lt;code&gt;Isolated[Array[T]]&lt;/code&gt;, made by &lt;a href=&quot;#handing-over-ownership&quot;&gt;&lt;code&gt;Isolated.move&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A declaration may also &lt;strong&gt;promise&lt;/strong&gt; &lt;code&gt;Sendable&lt;/code&gt;: a trait or a class after &lt;code&gt;:&lt;/code&gt; in its header, a data
type in an impl (&lt;code&gt;impl Sendable for Reading&lt;/code&gt;). The promise is checked against the structure, and
the error says what breaks it (&lt;code&gt;`Blob` promises to be `Sendable`, but its field `size` is a `var`&lt;/code&gt;).
An &lt;code&gt;open&lt;/code&gt; or &lt;code&gt;abstract&lt;/code&gt; class that promises it is sendable, each subclass being checked in turn, as
each type implementing a trait that promises it is. A generic trait that promises &lt;code&gt;Sendable&lt;/code&gt; is
sendable at sendable type arguments, and a type implementing it has the parameters it passes to the
trait taken as sendable when it is checked. A type that implements one through a generic trait,
&lt;code&gt;HashMap[K, V]&lt;/code&gt; through &lt;code&gt;Map[K, V]&lt;/code&gt;, is sendable at sendable arguments for those parameters. The
immutable &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;Set&lt;/code&gt; traits promise it, and &lt;code&gt;Vector&lt;/code&gt; of sendable elements, and the standard
library’s promises are checked against the structure as every other one is. A few of its types are
safe to share for a reason the structure cannot show, synchronization the runtime does or an owner
every operation checks, and each is marked &lt;code&gt;@trusted_sendable(&amp;quot;why&amp;quot;)&lt;/code&gt; with the reason, so that
nothing is trusted silently: &lt;code&gt;Mutex&lt;/code&gt;, &lt;code&gt;Condition&lt;/code&gt;, &lt;code&gt;Atomic&lt;/code&gt;, &lt;code&gt;Channel&lt;/code&gt; and &lt;code&gt;Thread&lt;/code&gt;, the lock, the
cell, the pool and the registry inside them and the futures, a running actor, &lt;code&gt;Isolated&lt;/code&gt;, and the
connections, listeners and child processes, which belong to one thread at a time. A &lt;code&gt;Future&lt;/code&gt;, a &lt;code&gt;Promise&lt;/code&gt;, an &lt;code&gt;Executor&lt;/code&gt; and a
&lt;code&gt;Once&lt;/code&gt; are sendable by their structure, built of those. The mark is the standard library’s alone.
&lt;code&gt;Sendable&lt;/code&gt; is only a bound and a promise, never the type of a value.&lt;/p&gt;
&lt;h3 id=&quot;handing-over-ownership&quot;&gt;Handing over ownership&lt;/h3&gt;
&lt;p&gt;Some mutable things have to move: a socket accepted by a listener goes to the actor that serves the
connection, and a large buffer filled by one actor goes to the next.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A Sysl handle in a message is handed over.&lt;/strong&gt; A handle has an owner, the execution that may use
it (&lt;a href=&quot;/spec/sysl-bindings/#handles&quot;&gt;Sysl bindings&lt;/a&gt;), and an actor is an owner. Sending a message
to an actor hands every handle it holds that the sender owns to that actor, as the message is put
in its mailbox, so the receiver uses it and the sender’s later use of it traps (&lt;code&gt;`TcpStream` belongs to another thread&lt;/code&gt;), whether or not the receiver has used it yet. A handle the sender
does not own stays as it is, so one sent twice goes with the first message, and the second
receiver’s use traps; a receiver that sends one on hands it over in turn. A message dropped
because its actor has ended leaves its handles the sender’s. A reply to an &lt;code&gt;ask&lt;/code&gt; completes a
future, which puts its handles in transit for the code that waits for it. The compiler knows
which types can hold a handle, so a send walks the message only for those: a message of numbers
and strings, of immutable collections of them or of actors’ references is never walked. The walk
follows what the message holds — its fields, a collection’s elements, what a function value
captures, an &lt;code&gt;Isolated&lt;/code&gt;‘s objects — and stops at what is shared between owners, an actor’s
reference, a future, a promise, a channel, a mutex, an atomic, a thread or an executor, whose
handles keep their owners.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A mutable object graph moves inside an &lt;code&gt;Isolated[T]&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;isolate(body)&lt;/code&gt; runs its body, a by-name
argument written in place or as a trailing block, and wraps what it returns:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val chunk = isolate
  val b = Buffer[byte]()
  for i in 0 ..&amp;lt; size do b.append(byte.wrap(i))
  b
worker tell Fill(chunk)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The compiler checks that &lt;strong&gt;the body reads nothing from around it that is not sendable&lt;/strong&gt;, and that
&lt;strong&gt;nothing it calls, however indirectly, reaches module-level mutable state&lt;/strong&gt; (a module-level
&lt;code&gt;var&lt;/code&gt;, or a module-level value or &lt;code&gt;object&lt;/code&gt; whose type is not sendable, a &lt;code&gt;lazy val&lt;/code&gt; among them).
Avin compiles the whole program, so the second is known for every function, in every module,
through every trait method a call may reach, every function value made inside the body and the
initializer of every &lt;code&gt;lazy val&lt;/code&gt; field it reads. Every
mutable object the body leaves reachable from its result was therefore made inside it, and
nothing outside holds one. The body may read a &lt;code&gt;var&lt;/code&gt; of the code around it whose type is
sendable, since it runs at once, and module-level values that are immutable and sendable; an
actor’s own state, its parameters among them, is read through a &lt;code&gt;val&lt;/code&gt; copied first. The receiver
gets the objects out with &lt;strong&gt;&lt;code&gt;take() -&amp;gt; T&lt;/code&gt;&lt;/strong&gt;, after which they are ordinary objects it owns; a
second &lt;code&gt;take&lt;/code&gt;, by anyone, traps with &lt;code&gt;`Isolated` was already taken&lt;/code&gt;, one atomic
compare-and-set deciding which take wins. &lt;strong&gt;&lt;code&gt;with[R: Sendable](f: T -&amp;gt; R) -&amp;gt; R&lt;/code&gt;&lt;/strong&gt; works on the
objects while leaving them isolated, &lt;code&gt;f&lt;/code&gt; being checked by the body’s rule, so a pipeline of actors
can fill, pass, change and pass one buffer without a copy. &lt;code&gt;with&lt;/code&gt; holds the objects while &lt;code&gt;f&lt;/code&gt;
runs, so a &lt;code&gt;take&lt;/code&gt; or a &lt;code&gt;with&lt;/code&gt; of the same &lt;code&gt;Isolated&lt;/code&gt; meanwhile, from another thread or from inside
&lt;code&gt;f&lt;/code&gt;, traps with &lt;code&gt;`Isolated` is in use by `with`&lt;/code&gt;, and a &lt;code&gt;with&lt;/code&gt; after the objects are taken
traps as a second &lt;code&gt;take&lt;/code&gt; does.&lt;/p&gt;
&lt;p&gt;The rule is a parameter’s mark, &lt;strong&gt;&lt;code&gt;@isolating&lt;/code&gt;&lt;/strong&gt;, which a program’s own functions may write too
(&lt;a href=&quot;/spec/threads/#what-is-shared&quot;&gt;what is shared&lt;/a&gt;): &lt;code&gt;isolate[T](@isolating body: -&amp;gt; T) -&amp;gt; Isolated[T]&lt;/code&gt;, and &lt;code&gt;with&lt;/code&gt;‘s &lt;code&gt;f&lt;/code&gt;. &lt;code&gt;Isolated&lt;/code&gt; and &lt;code&gt;isolate&lt;/code&gt; are imported from &lt;code&gt;avin.actors&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An array the program already holds moves with &lt;code&gt;Isolated.move(items)&lt;/code&gt;&lt;/strong&gt;, with no copy:
&lt;code&gt;move[T: Sendable](items: Array[T]) -&amp;gt; Isolated[Array[T]]&lt;/code&gt;. A buffer a socket read filled, or one
a relay hands back and forth, was not made inside an &lt;code&gt;isolate&lt;/code&gt;, and the code that holds it may
hold other references to it too, in a field or a closure. So the array itself carries its owner:
every array has an owner word beside its length, empty until the array is first moved. A move
gives it an owner no running code is, and &lt;strong&gt;every use of the array after it, through any
reference, traps&lt;/strong&gt; with &lt;code&gt;`Array` was moved to another owner&lt;/code&gt; — reading or writing an element,
its length, a slice, a copy into it or out of it, an iterator’s next step, handing it to a Sysl or
C binding, and moving it again. The code that takes it out of the &lt;code&gt;Isolated&lt;/code&gt; becomes its owner, and
uses it through any reference it holds; &lt;code&gt;with&lt;/code&gt; makes the code running it the owner while &lt;code&gt;f&lt;/code&gt; runs
and moves the array again after. An array taken back by the code that moved it is that code’s
again, through the references it kept:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;val chunk = conn.read(16384)?
writer.send(Isolated.move(chunk))      // chunk(0) here traps
val again = done.receive().get.take()  // the same array, ours again: again === chunk
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Its elements must be sendable, since they are shared with the receiver as they are; an array of
buffers is refused. Only an &lt;code&gt;Array&lt;/code&gt; moves this way: a slice is a copy, so one taken before the
move stays the sender’s, and a &lt;code&gt;Buffer&lt;/code&gt;, a map or any other mutable object moves inside an
&lt;code&gt;isolate&lt;/code&gt;. An array never moved, which is every array most programs make, pays eight bytes of
header and no check beyond its bounds check: a move rewrites the length word so that every index
fails that check, and only then is the owner compared.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The cheapest way across stays the plainest: build with a &lt;code&gt;Buffer&lt;/code&gt; or a builder, turn the result into
an immutable collection, and send that.&lt;/p&gt;
&lt;h2 id=&quot;supervision&quot;&gt;Supervision&lt;/h2&gt;
&lt;p&gt;A trap reports a bug. In a thread it stops the program, because the state the threads share is in
doubt. &lt;strong&gt;An actor shares no mutable state&lt;/strong&gt;, so a trap in one leaves only that actor’s own state in
doubt, and the runtime can contain it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A trap in an actor fails the actor&lt;/strong&gt;: in its body, an arm, a timer’s message, or an &lt;code&gt;enter&lt;/code&gt; or
&lt;code&gt;leave&lt;/code&gt; block. The runtime unwinds the actor’s frames back to the worker running it, drops the
message being handled, and reports the trap as it reports any, naming the actor:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;avin: trap in Counter#3: integer overflow at counter.avin:12:31
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A trap inside the core library is reported where the actor’s code called it, as any library trap
is. The actor’s &lt;code&gt;Failed&lt;/code&gt; reason is the trap’s reason, without its place: &lt;code&gt;Failed(integer overflow)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Where the trap leaves shared state in doubt, the program stops instead&lt;/strong&gt;, as it would for a
thread: a trap while the actor holds a &lt;code&gt;Mutex&lt;/code&gt;, reads or writes a &lt;code&gt;RwLock&lt;/code&gt;, holds a semaphore’s
permit in &lt;code&gt;withPermit&lt;/code&gt;, runs a barrier’s action, runs a &lt;code&gt;Once&lt;/code&gt; body or initializes a &lt;code&gt;lazy val&lt;/code&gt;
(each of which other threads may be waiting on), or inside a Sysl call: an Avin function Sysl
called back, or a value a binding cannot take. The report still names the actor. A stack that
runs out stops the program too, with the same &lt;code&gt;avin: trap: stack overflow&lt;/code&gt; a thread’s does, since
it may run out anywhere, inside the runtime or the C library among the places.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The supervision given to &lt;code&gt;spawn&lt;/code&gt; decides what follows&lt;/strong&gt;, a value of the &lt;code&gt;data&lt;/code&gt; type
&lt;code&gt;Supervision&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Escalate&lt;/code&gt;&lt;/strong&gt;, the default: the parent fails as if it had trapped, and its own supervision
decides. A top-level actor that escalates stops the program, with the trap already reported. So a
program that supervises nothing behaves as it would with threads: a bug stops it. The actor
that escalated handles nothing more and waits for its parent’s failure to stop it, so a failure
escalated to the top stops the program with no &lt;code&gt;stopping&lt;/code&gt; block run; it ends &lt;code&gt;Failed&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Stop&lt;/code&gt;&lt;/strong&gt;: the actor ends, its children first, and its watchers are told it failed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Restart(limit: int, within: Duration)&lt;/code&gt;&lt;/strong&gt;: the actor’s children are stopped and waited for,
its timers and watches cancelled, its &lt;code&gt;stopping&lt;/code&gt; block runs, and its body runs again from the
same &lt;code&gt;Behaviour&lt;/code&gt;, so it starts again with fresh state; the messages still in its mailbox stay
there, and its reference, number and watchers are unchanged. A restart is reported on standard
error after the trap, as &lt;code&gt;avin: restarting Counter#3&lt;/code&gt;. A failure that would make more than
&lt;code&gt;limit&lt;/code&gt; restarts within the last &lt;code&gt;within&lt;/code&gt; escalates instead, so &lt;code&gt;Restart(0, …)&lt;/code&gt; never restarts.
A limit less than zero, or a window not more than zero, traps in &lt;code&gt;spawn&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;There is no resuming with the old state.&lt;/strong&gt; The trap stopped the actor part-way through changing
its state, so the state is not kept.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What was asked of a failed actor.&lt;/strong&gt; The question whose message trapped is dropped with it, so
its ask times out; questions still in the mailbox are dropped and time out where the actor ends,
and are answered by the fresh state where it restarts; a question sent once it has ended answers
&lt;code&gt;Ended&lt;/code&gt;. A failure escalated to a parent that is already ending or restarting changes nothing,
since the parent is stopping its children already.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;lifecycle&quot;&gt;Lifecycle&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An actor runs until it stops.&lt;/strong&gt; &lt;code&gt;stop()&lt;/code&gt; in an actor ends it once the current message is
handled; what is left in its mailbox is dropped. &lt;code&gt;stop(child)&lt;/code&gt; ends one of its own children, and
stopping any other actor is an error: an actor that should end on request is sent a message
saying so.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Children end first.&lt;/strong&gt; An ending actor stops each child, and waits for their ends, before it ends
itself; an actor’s tree of children is torn down from the leaves.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;stopping&lt;/code&gt;&lt;/strong&gt; is a block in the actor’s body that runs whenever the actor ends or restarts, the
place to close handles and tell others. It runs after a failure too, on state the trap may have
left half changed, so it does only what is safe on any state. A trap inside it is reported and the
actor ends without running it again: &lt;code&gt;Failed&lt;/code&gt; with that trap’s reason, or with the first one where
a trap had failed it already, and with no supervision asked, so a block that traps during a
restart ends the actor instead. Of several &lt;code&gt;onStopping&lt;/code&gt; functions, those after one that traps do
not run.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Watching.&lt;/strong&gt; &lt;code&gt;watch(ref, message: M)&lt;/code&gt; asks for &lt;code&gt;message&lt;/code&gt; in this actor’s own mailbox when the
actor &lt;code&gt;ref&lt;/code&gt; ends, for whatever reason, and &lt;code&gt;watch(ref, f: Ending -&amp;gt; M)&lt;/code&gt; for &lt;code&gt;f&lt;/code&gt; of how it ended;
&lt;code&gt;unwatch(ref)&lt;/code&gt; stops asking. Watching an actor that has already ended delivers at once. &lt;code&gt;Ending&lt;/code&gt; is
&lt;code&gt;Stopped&lt;/code&gt; or &lt;code&gt;Failed(reason: string)&lt;/code&gt;; a restart is not an ending.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;From outside any actor&lt;/strong&gt;, &lt;code&gt;ref.ended() -&amp;gt; Future[Ending]&lt;/code&gt; completes when the actor ends, so &lt;code&gt;main&lt;/code&gt;
waits for the top-level actor that runs the program with &lt;code&gt;spawn(App()).ended().await()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An actor is not collected because nothing refers to it&lt;/strong&gt;: an actor nobody can send to still runs
its timers and its children. It ends by stopping, by its parent ending, or with the program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The program ends when &lt;code&gt;main&lt;/code&gt; returns&lt;/strong&gt;, as it does with threads, with every actor still running.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An actor also has &lt;strong&gt;&lt;code&gt;children() -&amp;gt; Vector[ActorRef[Nothing]]&lt;/code&gt;&lt;/strong&gt;, its own reference &lt;code&gt;self&lt;/code&gt; and its
parent’s in &lt;strong&gt;&lt;code&gt;parent() -&amp;gt; Option[ActorRef[Nothing]]&lt;/code&gt;&lt;/strong&gt;, an &lt;code&gt;ActorRef[Nothing]&lt;/code&gt; being one that may be
watched and compared but not sent to.&lt;/p&gt;
&lt;p&gt;These are the actor’s own methods, those of &lt;strong&gt;&lt;code&gt;ActorContext[M]&lt;/code&gt;&lt;/strong&gt; in &lt;code&gt;avin.actors&lt;/code&gt;, which the object
holding an actor’s state extends; a field or method of the actor’s own with the same name and
parameters is an error. A behaviour written as a library value makes one in its start from the
reference it is given, &lt;code&gt;ActorContext(me)&lt;/code&gt;, and &lt;code&gt;ctx.onStopping(f)&lt;/code&gt; gives it what a &lt;code&gt;stopping&lt;/code&gt; block
is. Made, or called, by any code other than the actor’s own, an &lt;code&gt;ActorContext&lt;/code&gt; traps. The details:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;children()&lt;/code&gt; lists the children that have not ended, in the order they started; &lt;code&gt;parent()&lt;/code&gt; is
&lt;code&gt;None&lt;/code&gt; for a top-level actor, and for one a future’s body started, which is not an actor’s code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stop(self)&lt;/code&gt; is &lt;code&gt;stop()&lt;/code&gt;. Stopping an actor that has ended does nothing, whoever started it.&lt;/li&gt;
&lt;li&gt;An actor started while its parent is ending, from its &lt;code&gt;stopping&lt;/code&gt; block, is stopped at once, and the
parent does not wait for it.&lt;/li&gt;
&lt;li&gt;Watching an actor again replaces the earlier watch, so its end is told once. An actor that watches
itself is told nothing, since its mailbox ends with it. The &lt;code&gt;f&lt;/code&gt; of &lt;code&gt;watch(ref, f)&lt;/code&gt; runs in this
actor’s own turn, when it takes the message, so a trap in it fails this actor and never the one
watched; it is &lt;code&gt;@sendable&lt;/code&gt;, since it is carried to the mailbox from wherever the end is known.
&lt;code&gt;unwatch&lt;/code&gt;, and cancelling a timer, also drop
the message already queued and not yet handled.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;stopping&lt;/code&gt; block runs once the body has run: the body gives it to the context last. An actor has
one.&lt;/li&gt;
&lt;li&gt;The state of an actor is never captured by a &lt;code&gt;@sendable&lt;/code&gt; function, whatever its fields, since its
methods act for the actor that is running; a body that needs a field copies it into a &lt;code&gt;val&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;timers&quot;&gt;Timers&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;after(delay: Duration, message: M) -&amp;gt; Timer&lt;/code&gt; sends the actor &lt;code&gt;message&lt;/code&gt; once &lt;code&gt;delay&lt;/code&gt; has passed, and
&lt;code&gt;every(interval: Duration, message: M) -&amp;gt; Timer&lt;/code&gt; each time &lt;code&gt;interval&lt;/code&gt; passes. &lt;code&gt;cancel()&lt;/code&gt; on the
&lt;code&gt;Timer&lt;/code&gt; stops it; an actor’s timers are all cancelled when it ends or restarts. A timer’s message is
queued like any other, so it never interrupts an arm.&lt;/p&gt;
&lt;p&gt;Timers fire in the order they fall due, those due at the same time in the order they were set; a
delay of zero or less is due at once. A repeating timer is set again an interval after it fires, and
an interval of zero or less traps. A &lt;code&gt;Timer&lt;/code&gt; is sendable, and &lt;code&gt;cancel()&lt;/code&gt; works from any thread. One
thread the runtime starts with the first timer keeps every actor’s timers.&lt;/p&gt;
&lt;h2 id=&quot;scheduling&quot;&gt;Scheduling&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Actors are many; threads are few.&lt;/strong&gt; An actor’s messages are handled in &lt;strong&gt;turns&lt;/strong&gt;, and each turn
is a &lt;a href=&quot;/spec/threads/#lightweight-threads&quot;&gt;lightweight thread&lt;/a&gt; of its own, run by the same workers,
about one per processor, as every other thread. An actor given an executor,
&lt;code&gt;spawn(b, executor = Executor.fixed(1))&lt;/code&gt;, runs its turns as tasks on that executor’s workers
instead, which bounds how many of them work at once:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;An actor with messages has one turn queued.&lt;/strong&gt; A send to an actor with an empty mailbox queues a
turn, which handles its messages one at a time. &lt;strong&gt;An actor never runs two turns at once&lt;/strong&gt;, not
even while a turn is parked and new messages arrive meanwhile, and the handling of each message
happens before the handling of the next, wherever each runs, so an actor’s fields need no lock
and no &lt;code&gt;Atomic&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fairness.&lt;/strong&gt; A turn handles at most 16 messages before the actor’s next turn goes to the back of
the queue, so a busy actor cannot hold a worker from the others. Within one message, a turn is
time-sliced as any thread is: one that computes for a second shares its worker with the other
ready threads at its safepoints, though the actor itself handles nothing else meanwhile. On an
executor of its own, a task is not set aside, so an arm that computes for a second holds that
executor’s place for that second.
The body runs in the actor’s first turn and is not one of the 16; a turn ends early when the
mailbox is empty. An actor’s executor being shut down does not end it: its turns still run there,
on a worker started for them where none is left, so &lt;code&gt;tell&lt;/code&gt; never fails.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An actor may move between workers&lt;/strong&gt;, between messages and, where a turn parks, within one. A
turn sets its context’s owner word to the actor before handling its messages, so the handles an
actor owns are its own on any worker and never trap. &lt;code&gt;spawn&lt;/code&gt; gives the actor the handles its behaviour reaches that the
spawning code owns, as a thread’s &lt;code&gt;spawn&lt;/code&gt; does with its body.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Waiting.&lt;/strong&gt; A turn that waits, in &lt;code&gt;await&lt;/code&gt;, an ask, a &lt;code&gt;sleep&lt;/code&gt;, a channel or a lock, parks: its
worker runs other actors and threads meanwhile, and the actor handles no other message until the
turn goes on. A thousand actors each sleeping in a turn hold no worker between them. A
&lt;a href=&quot;/spec/sysl-bindings/#calls-that-wait&quot;&gt;blocking binding&lt;/a&gt; holds its worker, and the runtime runs
another worker in its place while it does. On an executor of its own, a task that waits in &lt;code&gt;await&lt;/code&gt;
or &lt;code&gt;threads.blocking(body)&lt;/code&gt; leaves its place to another worker of that executor, and one that
waits otherwise keeps it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cancellation.&lt;/strong&gt; No scope’s &lt;a href=&quot;/spec/threads/#cancellation&quot;&gt;cancellation&lt;/a&gt; reaches an actor: one
started by a scope’s thread runs on once that thread is cancelled, and a turn is not a scope’s
thread, so it is never cancelled, though a scope it runs may cancel its own threads. An asker
cancelled while it awaits an &lt;code&gt;ask&lt;/code&gt; leaves its question in the mailbox, handled in its turn, the
reply going nowhere.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory model.&lt;/strong&gt; A &lt;code&gt;tell&lt;/code&gt; happens before the handling of the message it sent, and a reply’s
&lt;code&gt;tell&lt;/code&gt; happens before the &lt;code&gt;await&lt;/code&gt; or &lt;code&gt;pipeToSelf&lt;/code&gt; that delivers it, joining the edges of
&lt;a href=&quot;/spec/threads/#the-memory-model&quot;&gt;the memory model&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;threads-channels-and-futures&quot;&gt;Threads, channels and futures&lt;/h3&gt;
&lt;p&gt;Actors are built on &lt;code&gt;avin.threads&lt;/code&gt; and live beside it. Any thread may start, tell and ask actors;
an ask is a future, and a future’s value reaches an actor by &lt;code&gt;pipeToSelf&lt;/code&gt;. A &lt;code&gt;Channel&lt;/code&gt; is the tool
for a fixed pipeline of threads, and an actor that receives from a channel parks its turn and
handles nothing else while it waits, so between actors, messages are the channel. Locks remain for the state that genuinely
must be shared; a &lt;code&gt;Mutex&lt;/code&gt; is sendable for that reason.&lt;/p&gt;
&lt;h2 id=&quot;routers&quot;&gt;Routers&lt;/h2&gt;
&lt;p&gt;A &lt;strong&gt;router&lt;/strong&gt; is one reference that spreads its messages over a pool of actors started from one
behaviour, its &lt;strong&gt;routees&lt;/strong&gt;, so work that one actor would handle in turn is handled by several at once:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.actors.{ActorRef, Router, RoundRobin}
import avin.time

data Job
  Square(n: int, replyTo: ActorRef[string])

actor Squarer receives Job
  receive
    Square(n, replyTo) -&amp;gt; replyTo.tell(s&amp;quot;$self: ${n * n}&amp;quot;)

main()
  val pool = Router.pool(3, Squarer(), RoundRobin)
  for n in 1 .. 4
    println(pool.ask(r -&amp;gt; Square(n, r), timeout = time.seconds(5)).await())
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Ok(Squarer#2: 1)
Ok(Squarer#3: 4)
Ok(Squarer#4: 9)
Ok(Squarer#2: 16)
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Router.pool[M: Sendable](size: int, behaviour: Behaviour[M], routing: Routing[M] = RoundRobin, onFailure: Supervision = Escalate, executor: Executor = Executor.shared(), mailbox: Mailbox = Unbounded) -&amp;gt; ActorRef[M]&lt;/code&gt;&lt;/strong&gt; starts a router and &lt;code&gt;size&lt;/code&gt; routees of &lt;code&gt;behaviour&lt;/code&gt;, the router’s
children, and gives back the router’s reference at once. The router is a child of the code that
calls &lt;code&gt;pool&lt;/code&gt;, as &lt;code&gt;spawn&lt;/code&gt;‘s actor is, and its reference is shown as &lt;code&gt;Router#n&lt;/code&gt;, the router numbered
before its routees. A size less than one, a &lt;code&gt;Restart&lt;/code&gt; that &lt;code&gt;spawn&lt;/code&gt; would refuse, and a bounded
mailbox’s capacity less than one, trap in the calling code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each message sent to the router goes to one routee&lt;/strong&gt;, chosen by the &lt;code&gt;Routing&lt;/code&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;RoundRobin&lt;/code&gt;&lt;/strong&gt;, the default: each routee in turn.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;AtRandom&lt;/code&gt;&lt;/strong&gt;: any routee, each equally likely.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;SmallestMailbox&lt;/code&gt;&lt;/strong&gt;: the routee with the fewest messages waiting in its mailbox, the next in
turn among equals, so a free routee takes work that round robin would queue behind a busy one.
The message a routee is handling does not count as waiting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;ByKey(key: @sendable (M) -&amp;gt; long)&lt;/code&gt;&lt;/strong&gt;: by the key &lt;code&gt;key&lt;/code&gt; gives the message, so every message
with one key goes to one routee for as long as that routee lives; the keys spread over the pool,
and a routee that ends moves only its own keys to the others.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order.&lt;/strong&gt; Two messages one sender sends that go to one routee arrive in the order they were sent,
so with &lt;code&gt;ByKey&lt;/code&gt;, each key’s messages from one sender are handled in order.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A bounded pool.&lt;/strong&gt; A &lt;code&gt;Bounded&lt;/code&gt; mailbox bounds the router’s own mailbox and each routee’s, at the
same capacity. The router waits for room in the routee it chose rather than drop, handling nothing
else meanwhile, so once the routees are full the router’s own mailbox fills, and there the overflow
policy, &lt;code&gt;offer&lt;/code&gt;, &lt;code&gt;send&lt;/code&gt;, &lt;code&gt;ask&lt;/code&gt; and &lt;code&gt;dropped()&lt;/code&gt; act as for any &lt;a href=&quot;#bounded-mailboxes&quot;&gt;bounded
mailbox&lt;/a&gt;: a pool of &lt;code&gt;n&lt;/code&gt; routees of capacity &lt;code&gt;c&lt;/code&gt; holds at most &lt;code&gt;(n + 1) × c&lt;/code&gt;
messages waiting, and one more the router is placing. &lt;code&gt;RoundRobin&lt;/code&gt;, &lt;code&gt;AtRandom&lt;/code&gt; and &lt;code&gt;ByKey&lt;/code&gt; wait on
the routee they chose; &lt;code&gt;SmallestMailbox&lt;/code&gt; waits only when every routee is full, and its count is the
bounded mailbox’s own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An ask through a router&lt;/strong&gt; is answered by the routee that takes the question; the reply goes to
the asker’s reply reference as any reply does. An ask of a router that has ended answers &lt;code&gt;Ended&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Supervision as a group.&lt;/strong&gt; Each routee is supervised by &lt;code&gt;onFailure&lt;/code&gt; and runs on &lt;code&gt;executor&lt;/code&gt;. A
routee that restarts keeps its place in the pool and its mailbox; one that ends, whether it
stopped itself or failed under &lt;code&gt;Stop&lt;/code&gt;, leaves the pool, a message the router finds it no longer
accepts going to another routee; and the router stops once no routee is left. A routee’s failure
under &lt;code&gt;Escalate&lt;/code&gt; fails the router, which escalates in turn: a top-level router stops the program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lifecycle.&lt;/strong&gt; The router ends as any actor does: stopped by its parent with &lt;code&gt;stop(router)&lt;/code&gt;, or with
its parent, and a router that ends stops its routees first, so its end is known once theirs are.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;topics&quot;&gt;Topics&lt;/h2&gt;
&lt;p&gt;A &lt;strong&gt;topic&lt;/strong&gt; carries events from any number of publishers to every actor subscribed:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.actors.{Topic, spawn}
import avin.threads.Channel

actor Log(out: Channel[string]) receives string
  receive
    line -&amp;gt; out.send(s&amp;quot;$self: $line&amp;quot;)

main()
  val news = Topic[string]()
  val out = Channel[string]()
  news.subscribe(spawn(Log(out)))
  news.publish(&amp;quot;one&amp;quot;)
  news.publish(&amp;quot;two&amp;quot;)
  println(out.receive().get)
  println(out.receive().get)
  println(news.subscribers)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Log#1: one
Log#1: two
[Log#1]
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Topic[E: Sendable]()&lt;/code&gt;&lt;/strong&gt; makes one. A topic is not an actor; it is a sendable object any thread
may use, sent to actors in messages as any sendable value is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;subscribe(subscriber: ActorRef[E])&lt;/code&gt;&lt;/strong&gt; subscribes an actor from now on; an actor of another
protocol subscribes an &lt;a href=&quot;#starting-telling-and-asking&quot;&gt;adapter&lt;/a&gt;. An actor is subscribed once,
however many of its references are given: subscribing it again keeps its first place and the
reference given last. &lt;strong&gt;&lt;code&gt;unsubscribe(subscriber: ActorRef[Nothing])&lt;/code&gt;&lt;/strong&gt; stops telling it; an actor
not subscribed is left as it is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;publish(event: E)&lt;/code&gt;&lt;/strong&gt; tells the event to every actor subscribed, in the order they subscribed,
and returns at once; with nobody subscribed it does nothing. &lt;strong&gt;A subscriber is told one
publisher’s events in the order published&lt;/strong&gt;; the events of different publishers interleave in any
order. An event holding a Sysl handle goes with the first subscriber’s copy, as a &lt;a href=&quot;#handing-over-ownership&quot;&gt;handle sent
twice&lt;/a&gt; does.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A subscriber that ends leaves the topic of itself&lt;/strong&gt;: its end is watched from the moment it
subscribes, so a topic keeps no ended actor for longer than it takes to hear of the end, and an
actor that had ended already when it subscribed is not kept.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;subscribers -&amp;gt; Vector[ActorRef[E]]&lt;/code&gt;&lt;/strong&gt; is the actors subscribed now, in the order they
subscribed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;state-machines&quot;&gt;State machines&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;machine&lt;/code&gt;&lt;/strong&gt; declares a type whose objects move between declared &lt;strong&gt;states&lt;/strong&gt;, driven by &lt;strong&gt;events&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data DoorEvent
  Open
  Close
  Lock(code: int)
  Unlock(code: int)

machine Door receives DoorEvent
  var opened = 0

  state Closed
    Open -&amp;gt;
      opened += 1
      Opened
    Lock(code) -&amp;gt; Locked(code)

  state Opened
    enter
      println(&amp;quot;open&amp;quot;)
    Close -&amp;gt; Closed

  state Locked(code: int)
    Unlock(c) if c == code -&amp;gt; Closed

  receive
    _ -&amp;gt; stay
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Each &lt;code&gt;state&lt;/code&gt; declares a state&lt;/strong&gt;, optionally with parameters, the data that state holds; its
arms, &lt;code&gt;enter&lt;/code&gt; and &lt;code&gt;leave&lt;/code&gt; blocks read them by name. The machine’s own fields and parameters are
the data every state shares. A machine is declared like a class, generic and with parameters, and
its other methods are ordinary methods.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;An arm’s value is the next state&lt;/strong&gt;: a state written as a constructor (&lt;code&gt;Locked(code)&lt;/code&gt;), or
&lt;strong&gt;&lt;code&gt;stay&lt;/code&gt;&lt;/strong&gt;, which keeps the current state and its data. There is no separate transition statement:
what an arm yields is where the machine goes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The first &lt;code&gt;state&lt;/code&gt; is where the machine starts&lt;/strong&gt;, and takes no parameters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;enter&lt;/code&gt; runs when the machine moves into the state, and &lt;code&gt;leave&lt;/code&gt; when it moves out&lt;/strong&gt;, &lt;code&gt;leave&lt;/code&gt;
before &lt;code&gt;enter&lt;/code&gt;. An arm yielding a state, even the current one, is a transition and runs both;
&lt;code&gt;stay&lt;/code&gt; runs neither. The first state’s &lt;code&gt;enter&lt;/code&gt; runs when the machine is made, after the body.
The arm runs first; in &lt;code&gt;leave&lt;/code&gt;, &lt;code&gt;state()&lt;/code&gt; still answers the state being left, and in &lt;code&gt;enter&lt;/code&gt; the
new one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;receive&lt;/code&gt; holds the arms every state shares&lt;/strong&gt;, tried after the current state’s own. &lt;strong&gt;Every
state must handle every event&lt;/strong&gt;: the compiler checks, state by state, that its own arms and the
shared ones together cover the event type, as a &lt;code&gt;match&lt;/code&gt; is checked, guarded arms not counting.
A state’s own arm that its arms above it already cover, and a shared arm the shared arms above
it already cover, is never reached and is an error; a shared arm that a state’s own arms cover is
not, since a state overrides a shared arm by handling the event itself.
Without its shared &lt;code&gt;receive&lt;/code&gt;, &lt;code&gt;Door&lt;/code&gt; would be refused:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;error: state `Locked` of `Door` does not handle `Open`, `Close`, `Lock(_)` or `Unlock(_)` where the guard is false
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Using a machine.&lt;/strong&gt; &lt;code&gt;Door()&lt;/code&gt; makes one in its first state. &lt;code&gt;handle(event) -&amp;gt; Door.State&lt;/code&gt; applies
one event and answers the new state, and &lt;code&gt;state() -&amp;gt; Door.State&lt;/code&gt; reads the current one, where
&lt;code&gt;Door.State&lt;/code&gt; is a &lt;code&gt;data&lt;/code&gt; type the declaration makes, with a variant for each state and the state’s
parameters as its fields, so a program matches on it:
&lt;code&gt;door.state() is Locked(_)&lt;/code&gt;. Its variants are names of the machine’s module, as every variant
is, and may share a name with another machine’s state or an event’s variant, as &lt;a href=&quot;/spec/declarations/#data&quot;&gt;variants of
different types may&lt;/a&gt;: an arm’s result is its own machine’s state,
an event passed to &lt;code&gt;handle&lt;/code&gt; is the event type’s, and &lt;code&gt;door.state() is Idle&lt;/code&gt; matches against
&lt;code&gt;Door.State&lt;/code&gt;. A machine is a mutable object, so it is not sendable; handling an
event from inside one of its own arms, &lt;code&gt;enter&lt;/code&gt; or &lt;code&gt;leave&lt;/code&gt; blocks traps, as taking a held mutex does.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;an-actor-s-states&quot;&gt;An actor’s states&lt;/h3&gt;
&lt;p&gt;An actor’s body takes the same &lt;code&gt;state&lt;/code&gt; blocks, so an actor with phases is written as a machine
driven by its mailbox. Each message is an event, the arms yield the next state, and &lt;code&gt;enter&lt;/code&gt;,
&lt;code&gt;leave&lt;/code&gt;, &lt;code&gt;stay&lt;/code&gt; and the check that every state handles every message work as they do in a machine:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;data ConnMsg
  Connect(host: string)
  Connected(socket: Socket)
  Send(bytes: Vector[byte])
  Closed

actor Connection receives ConnMsg
  var pending = Vector[Vector[byte]]()

  state Idle
    Connect(host) -&amp;gt;
      pipeToSelf(openSocket(host), s -&amp;gt; Connected(s))
      Connecting

  state Connecting
    Connected(socket) -&amp;gt;
      for b in pending do socket.write(b)
      pending = Vector()
      Ready(socket)
    Send(bytes) -&amp;gt;
      pending = pending :+ bytes
      stay

  state Ready(socket: Socket)
    leave
      socket.close()
    Send(bytes) -&amp;gt;
      socket.write(bytes)
      stay
    Closed -&amp;gt; Idle

  receive
    _ -&amp;gt; stay
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An actor with states needs no &lt;code&gt;receive&lt;/code&gt; block; its shared arms, where it has them, yield states as
a machine’s do. Its first state’s &lt;code&gt;enter&lt;/code&gt; runs after the body, when the actor starts. A message that
arrives, a timer that falls due or a reply piped to itself is handled by the state current when it
is handled, not the one that asked for it. Only a transition runs &lt;code&gt;leave&lt;/code&gt;: an actor that stops or
fails runs its &lt;code&gt;stopping&lt;/code&gt; block, where &lt;code&gt;state()&lt;/code&gt; answers the state it ended in. A trap in an
&lt;code&gt;enter&lt;/code&gt; or &lt;code&gt;leave&lt;/code&gt; fails the actor as one in an arm does. A restarted actor starts again in its
first state. The actor’s &lt;code&gt;State&lt;/code&gt; type, its states and &lt;code&gt;state()&lt;/code&gt; are its own, private to its module
as the actor’s state is. Its states share names as a machine’s do, with a message’s variant, another
actor’s state or a machine’s: an arm’s result is the actor’s own state, an arm’s pattern the message
type’s, and a bare name nothing decides is refused, naming the qualified forms (&lt;code&gt;Ev.Idle&lt;/code&gt;,
&lt;code&gt;Connection.State.Idle&lt;/code&gt;). An actor without &lt;code&gt;state&lt;/code&gt; blocks is one whose arms all &lt;code&gt;stay&lt;/code&gt;, which is why
its arms yield nothing.&lt;/p&gt;
&lt;h3 id=&quot;setting-messages-aside&quot;&gt;Setting messages aside&lt;/h3&gt;
&lt;p&gt;A message an actor cannot handle in its present state is set aside in a &lt;strong&gt;&lt;code&gt;Stash&lt;/code&gt;&lt;/strong&gt; and given back
once the state changes, which is what &lt;code&gt;Connection&lt;/code&gt; above does by hand with &lt;code&gt;pending&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-avin&quot;&gt;import avin.actors.{ActorRef, Stash, spawn}
import avin.time

data Msg
  Write(text: string)
  Ready
  Show(replyTo: ActorRef[string])

actor Writer receives Msg
  val waiting = Stash(self, 100)
  val written = Buffer[string]()

  state Starting
    Write(text) -&amp;gt;
      waiting.add(Write(text))
      stay
    Ready -&amp;gt; Running

  state Running
    enter
      waiting.unstashAll()
    Write(text) -&amp;gt;
      written.append(text)
      stay

  receive
    Show(replyTo) -&amp;gt;
      replyTo.tell(s&amp;quot;$written&amp;quot;)
      stay
    _ -&amp;gt; stay

main()
  val w = spawn(Writer())
  w.tell(Write(&amp;quot;a&amp;quot;))
  w.tell(Write(&amp;quot;b&amp;quot;))
  w.tell(Ready)
  w.tell(Write(&amp;quot;c&amp;quot;))
  println(w.ask(r -&amp;gt; Show(r), timeout = time.seconds(5)).await())
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Ok([a, b, c])
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;Stash[M: Sendable](owner: ActorRef[M], capacity: int)&lt;/code&gt;&lt;/strong&gt; is made by the actor’s own code from its
own reference, &lt;code&gt;self&lt;/code&gt; in a declaration or the reference a behaviour’s start is given; made by any
other code it traps, as an &lt;code&gt;ActorContext&lt;/code&gt; does. A capacity less than one traps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;add(message: M)&lt;/code&gt;&lt;/strong&gt; sets a message aside. &lt;strong&gt;Adding to a full stash traps&lt;/strong&gt;, failing the actor,
whose supervision decides what follows; an actor that would rather drop or answer the message
reads &lt;strong&gt;&lt;code&gt;isFull&lt;/code&gt;&lt;/strong&gt; first. &lt;strong&gt;&lt;code&gt;length&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;isEmpty&lt;/code&gt;&lt;/strong&gt; say what it holds, and &lt;code&gt;capacity&lt;/code&gt; how much
it may.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;unstashAll()&lt;/code&gt;&lt;/strong&gt; gives back every message held, in the order they were added, &lt;strong&gt;in front of every
message waiting in the mailbox&lt;/strong&gt;, so the actor handles them next and the messages that arrived
meanwhile after them, and leaves the stash empty. Messages given back while others given back
earlier still wait go in front of those. A message given back that the actor still cannot handle
is added again, behind the ones added since. Given back from a state’s &lt;code&gt;enter&lt;/code&gt;, they are handled by
that state, the usual place.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;clear()&lt;/code&gt;&lt;/strong&gt; drops what the stash holds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A stash is the actor’s state.&lt;/strong&gt; Its messages are lost where the actor ends or restarts, as its
fields are, and a question among them times out; messages already given back are in the mailbox,
which a restart keeps, so the fresh state handles them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Under a &lt;a href=&quot;#bounded-mailboxes&quot;&gt;bounded mailbox&lt;/a&gt;&lt;/strong&gt;, a message stashed has left the mailbox and made
room, and the messages &lt;code&gt;unstashAll&lt;/code&gt; gives back do not count against the bound, which they passed
once already: however many come back, none is dropped.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;keywords&quot;&gt;Keywords&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;actor&lt;/code&gt; and &lt;code&gt;machine&lt;/code&gt; are keywords only where a declaration starts, before the declaration’s name;
&lt;code&gt;receives&lt;/code&gt; only after an actor’s or machine’s header; and &lt;code&gt;state&lt;/code&gt;, &lt;code&gt;receive&lt;/code&gt;, &lt;code&gt;enter&lt;/code&gt;, &lt;code&gt;leave&lt;/code&gt;,
&lt;code&gt;stopping&lt;/code&gt; and &lt;code&gt;stay&lt;/code&gt; only inside an actor’s or a machine’s body, at the start of a line (&lt;code&gt;stay&lt;/code&gt; as
an arm’s value). Everywhere else they are ordinary names, so a variable called &lt;code&gt;state&lt;/code&gt; stays legal.&lt;/p&gt;</content>
  </entry>
</feed>
