Repository navigation
Design hashing
STATUS: accepted. The seeded runtime, tiers, variables, harness seeding and SHA-256 digests are on main (c8112863d) under rulings 1–10. Ruling 11 as amended by ruling 11a (2026-11-16) replaces the hash surface that commit ships. Its work is planned as #108, then #112 and #109 (never at the same time), then #79, then #110, with #107 after #109. None of it is started. Ruling 11.6a (2026-11-16): HashSeed.random() still ignores a pinned MAXON_HASH_SEED until #162 lands (in progress, ruling 11.6b).
The rulings are on the design issue.
| Need | Function | Lives |
|---|---|---|
Map and Set keys |
the type's hash, structural unless the type writes its own, under the table's own seed |
inside one table, never observable |
| A hash the program computes |
Hasher, from a HashSeed (a fresh random one by default) |
beside its seed, on one tier |
| Anything that crosses a process, host or file | SHA-256, truncated where short | anywhere |
The compiler supplies structural equality, ordering and hashing, as it supplies clone. One derivation produces a type's equals, compare and hash from one walk, so the operator, the method, the conformance and the table cannot disagree.
Equality is supplied. a.equals(b) and the Equatable conformance exist, with no declaration, for:
- the leaves: every integer and
bitstype,bool,float,Character,String, a payload-free enum (its case), andArray with EwhenEhas equality; - a record whose every field has equality;
- a union with payloads whose every payload has equality;
- a tuple whose every element has equality;
- a generic instance, judged per instance.
Inside a generic body, a T field has equality only under where T is Equatable. Fields are compared in declaration order, short-circuiting, whatever their visibility. Recursive types are judged coinductively. Two different types stay E3005. A float field compares as float does, so NaN is not equal to itself. Nothing is compared by address.
The operators. == and != are the type's equals, and <, <=, > and >= are its compare, on every type that has them, except a union with payloads. A union is inspected with match, so all six operators on a union value are E3066. A union's supplied or written equals, compare and hash are ordinary members:
-
a.equals(b)is callable; - a table, a
whereconstraint and an enclosing type's walk use them; - so a union with hashable payloads is a key, and a record holding one has
==.
When the union has the member, E3066 adds "to compare two whole values, call a.equals(b)" (or a.compare(b)).
What has no equality, ordering or hash:
- a function value, an interface value, a promise;
- a compiler-owned aggregate:
__ManagedMemory, a file, socket or pin handle,HashSink; - a
Mapand aSet, as in Go:==on one is refused; - a type parameter without the constraint;
- any record, union, tuple or instance that reaches one of these through a field with no member of its own in between.
Content comparison of tables is a library method, contentEquals(other): on Set always, on Map where its value has equality. It is not equals and grants no conformance.
Ordering is supplied where the type's equality is structural and every part has an ordering. The order is lexicographic in declaration order: the first field that differs decides.
| Type | Order |
|---|---|
integers and bits
|
numeric |
bool |
false before true
|
float |
its operators are IEEE (false against NaN); float.compare is a total order: NaN first, two NaNs equalTo, -0.0 and 0.0 equalTo; a walk uses compare
|
Character and String
|
by Unicode scalar values, a prefix first; no locale, collation or case folding |
| every enum | by case declaration order, raw values included |
Array, tuple, record |
element by element (a prefix first), field by field |
| union with payloads | case order, then payloads; a member only, never an operator |
Reordering fields or cases changes the order of values and of every sort over them, so a type whose order must not follow its layout writes compare.
A type may write its own. A record, union or generic type declares the clause and the member:
| Clause | Member |
|---|---|
implements Equatable |
equals(other Self) returns bool |
implements Comparable |
compare(other Self) returns Ordering |
implements Hashable |
hash(sink HashSink) |
That body is the type's answer for every reader. The rules:
- The clause means "I write the member", and nothing else. A clause without its member is refused ("supplied; remove the clause"). A member without its clause, or with another shape, is refused.
- A different meaning is allowed even where a structural one exists (
FilePath,StringIndex). - A type that writes
equalsgets no structuralcompareorhash. It is ordered only if it writescompare, and a key only if it writeshash. - Declaring a member anywhere in the type's package removes the structural one.
- A leaf, an enum, a
Mapand aSetdeclare none of the three. - Only the type's own package declares them (#36, ruling 13).
For hand-written members the compiler cannot check the law: equal values pass the same sequence to the sink, and compare is equalTo exactly when equals is true, except for NaN. The documentation states it beside the interfaces, and that a violation loses keys or mis-sorts silently.
A Map key or Set element is Hashable, and interface Hashable extends Equatable. A type is Hashable when:
- it is a leaf: every integer and
bitstype,bool,float,Character,String, or a payload-free enum; - it is
Array with EwhereEisHashable; - its equality is structural and every part is
Hashable: a record, a union with payloads, a tuple, a generic instance, a recursive type; - or it writes
equalsandhash.
A tuple of Hashable elements is a key. A type that writes equals and no hash is not a key: its answer to "same?" is its own, and the compiler cannot derive a hash that agrees with it. where K is Hashable is the whole constraint; it implies Equatable.
0.0 and -0.0 hash alike, and a NaN key is never found.
A written hash goes into a sink it cannot read. interface Hashable requires function hash(sink HashSink), which returns nothing. HashSink has no public member or constructor, no equality, no clone and no toString. A program can only pass it on, as in self.name.hash(sink); only the standard library creates and finishes one. So a hash body sees no seed, state or result, and no program can observe a hash. E3187's no-writing rule binds hash.
A process draws a secret from the operating system before main. Each table draws its own seed from it when the table is created, and a clone keeps its source's seed. No API returns a table's seed or a key's hash. One hidden generator, keyed by the startup secret, gives the n-th table seed and, under a pin, the n-th HashSeed.random(). It has two streams, each with its own atomic index: library seeds (HashSeed.random()) and table seeds. Its output is a fixed function of the pin, the stream and the index within that stream, independent of the tier, and its draw is safe across workers. Concurrent draws within one stream are ordered by scheduling, so a program that needs a draw at a stable index makes it before it fans out. Every draw goes through one runtime door, which alone knows whether the process is pinned (ruling 11.6b). A draw is an effect that releases no record: discarding one still advances the pin's index, and it ends no hold (ruling 11.6c). Unpinned, HashSeed.random() is operating-system entropy (ruling 11.6a).
Hasher folds from a HashSeed: a fresh HashSeed.random() unless the program passes its own. A program passes its own seed to reproduce or store a fold; toBytes and fromBytes let it keep the seed beside its digests. The compiler's library cache does this. Hasher.combineValue drives value.hash with a sink over the Hasher's own state.
| Tier | Where | Function |
|---|---|---|
aes |
a CPU with AES instructions | AES rounds |
software |
every host; the only tier on wasm32-wasi
|
a multiply fold, the same digest on every target |
A digest depends on the seed, the steps and the tier. A third tier needs a supported class of hosts that has its instructions and lacks AES.
Map and Set iterate in table order, which is unspecified and differs between runs, and between two tables holding the same keys. A program that needs an order sorts.
| Variable | Value | A bad value |
|---|---|---|
MAXON_HASH_SEED |
16 hexadecimal digits | ends the program before main with exit 1, naming the value |
MAXON_HASH_TIER |
aes or software
|
the same, and also for a tier the host lacks |
A run is reproduced by its seed and its tier together.
Both variables are read by the hash runtime, which a program contains only when it hashes. Such a program validates both before main; a program that hashes nothing does not read them and runs whatever they hold (ruling 5a).
A pinned seed is not a secret: it stays in the environment, the program can read it, and child processes inherit it. A process running under a pin has no collision resistance against anyone who knows the pin, so a deployed program is not pinned. Under a pin, the n-th table created and the n-th HashSeed.random() get the same seeds on every run. How a pin maps to those seeds is unspecified beyond "same seed, tier and program, same hashes" (ruling 8b).
A suite run is never pinned. spec-test and maxon test draw one seed per run, pass it to every program that does not pin its own, and print the seed and the tier with every failure.
A pin belongs to:
- a spec case:
<!-- env: MAXON_HASH_SEED=... -->; - a test under
tests/, for a process the test starts; - a measurement (
scale-test, a benchmark); - reproducing a reported failure.
A case whose expected output depends on a hash value or an iteration order also sets MAXON_HASH_TIER=software, the one tier every lane has. A case whose subject is not hashing sorts instead of pinning.
Before the flip lands, the specs show:
- structural
equals,compareandhashagree for a record, a union, a tuple, a nested generic and a recursive type, each used as a key and sorted; -
HashSinkhas no public surface; - a hand-written
equalswith nohashis refused as a key; - a type holding a
Mapis refused as a key and at==; - output is byte-identical under two seeds.
Errors name the cause and the path, from the one verdict: the first failing field in declaration order, followed to a terminal reason. The reasons are a closed list: function value; interface value; promise; a named handle; a Map or Set; an unconstrained type parameter; "declares its own equals and no hash/compare"; "applies only where …".
- An operator or method on a type that lacks it has its own code ("has no equality", "has no ordering").
- An unmet
Equatable,ComparableorHashableconstraint (a key, a sort, anywhere) is E3017, with the path.
For example: 'Order' has no '==': field 'route' (Route) → field 'stops' is a Map, which has no equality. Declare 'implements Equatable' on 'Order' or 'Route' and write 'equals'; compare two maps with 'contentEquals'.
The other codes:
- E3066 refuses
==,<and the rest on a union with payloads, and namesequalsorcomparewhen the union has it. - E3005 refuses two different types.
- E3130 covers
equals,compareandhashon every type. - E3016 refuses a clause without its member, with "remove the clause".
- An enum that names one of the three interfaces, or declares one of the members, is refused.
The library cache's digest seed is an ordinary HashSeed.random(), stored beside its digests; the compiler has no pin logic of its own. Under a pinned MAXON_HASH_SEED a cold cache root's seed is the pin's n-th seed, the same on every run; unpinned it is fresh entropy. A root that holds a seed file uses it, pinned or not: the file is the root's only persistent pin. A root first written under a pin has a seed known to whoever knows the pin, so such a root is a test's or a measurement's (ruling 11.6a).
Compiler output is byte-identical under every seed, both the executable and the debug file. Emitters walk registries in name order, never table order, and a tests/cli gate builds one program under two seeds and compares the output. Names that reach output (generic instance names, tuple and type-parameter tokens, the build-id) and --shard are truncated SHA-256. The library cache is compiler output too (ruling 10a): with one stored digest seed and one tier, every cache entry is byte-identical under every process seed. A table that reaches the cache is written in key order, and no walk that registers a first-wins entry, interns a name, numbers an id or fills a written array visits a table in table order: such a walk goes through one ordered-walk helper with the writers' ordering per key type, unless it iterates no table or its body touches only its own key's entry or folds by count, min or max; a mint's position counts as well as its recorded provenance (10a.3a). The measured cost is tens of allocations per warm compile. A tests/ gate builds under two process seeds with one stored seed in two fresh roots and compares every pack kind byte for byte (#178, in progress).
The derivation that supplies equals, compare and hash is one verdict per type. The operator, the method, the conformance, the table and the diagnostic read it, and none decides on its own.
Insertion-ordered Map and Set; opt-in seeding; FNV-1a or djb2 under any spelling; a hash value in a file, a name or a protocol; a suite-wide seed pin; a process-wide table seed; a public function returning a table's seed or a key's hash.
Also ruled out (ruling 11a):
- a hash member that returns a value or sees a seed or state;
- a public member on
HashSink; - a structural
hashorcomparebeside a hand-writtenequals; - a redundant clause;
- these members on leaves, enums,
MaporSet; -
==or<on a union with payloads; - equality, ordering or hashing of a
MaporSet; - a marker that withdraws equality;
- locale-aware
Stringorder; - equality by address;
-
FilePathKeyas a requirement.