Skip to content

Design library cache seed independence

Eric Stern edited this page Nov 17, 2026 · 3 revisions

Library cache content does not depend on the process hash seed

STATUS: APPROVED (with amendments, section 9); in progress REV: 1 BASE: f4ebde918, 2026-11-17

Issue: maxon#178. Governing design: Design-hashing (maxon#78, ruling 10a): compiler output is byte-identical under every process seed, and the library cache is compiler output.

1. The problem, as a measurement

One program, one stored library digest seed, one hash tier, two fresh cache roots, two values of MAXON_HASH_SEED:

pack seed 1111111111111111 seed 2222222222222222
baseline-<key>.mxlc 2,033,874 bytes 2,033,874 bytes differs, same size
parses-<key>-<key>.mxlc 1,732,702 bytes 1,732,668 bytes differs
views-<key>.mxlc 3,165,227 bytes 3,165,227 bytes identical

Expected: all identical. Seven seed pairs over three programs and both hash tiers differ the same way. The control (one seed twice, two fresh roots) is byte-identical. The core and audit pack kinds were not produced by these compiles (section 9 requires them).

2a. Source facts

Every differing byte is attributed.

cause pack where share
A. A generated Map or Set writer walks the table baseline, parses one emit rule, Emitter.alias_helpers in scripts/library-cache/codec_emit.py; 126 generated writers use it (102 Map, 24 Set) 1.65 MB of the baseline, 42 KB of the parses
B. An array filled by walking a table, and positions into it baseline, parses declTokenStreamPaths, noteAuthorMintSpellings, settleContestedFunctionSpellings and the name walk in footprintOf (SignatureIndexSettle.maxon); genericTemplateKeys (SignatureIndexGenericTypes.maxon) 5.7 KB
C. A tuple layout records its first minter's file parses registerTupleLayout mints only when the name is not yet registered (SignatureIndexInstances.maxon); each file's copy carries that path (adoptTupleLayout) 272 bytes
D. GenericInstanceIds numbered in table order parses internAggregateElementInstances walks structSlots and internEnumElementInstances walks enumTypes (SignatureIndexInstances.maxon); footprintOf then sorts rows by id 75 bytes, plus the rows the sort moves

No hand-written cache writer walks a table: cacheWriteHashDigestSet sits in a generated region and is cause A; the hand writers in LibraryCacheCodecs.maxon and LibraryCacheFormat.maxon are positional.

Key types of the 126 writers: ByteArray (96), String paths (7), ElementIndex (7), ValueId (7), ParamCount (1), HashDigest (1), TypeParamId (1), TypeNameId (1), GenericInstanceId (5).

Readers do not depend on order. The schema fingerprint hashes every generated line, so changing the emit rule moves it once; fixing B, C or D does not.

3. The approach

One class, four sites: a walk with an order-sensitive effect visits a table in table order.

  • A. One emit rule, in the generator. A generated Map or Set writer writes its entries in key order, through one table of key type to ordering and one helper per ordering. Orderings: byte order for ByteArray; byte order of the text for String; numeric for ElementIndex, ValueId, ParamCount; the digest's value for HashDigest and TypeParamId; numeric for TypeNameId and GenericInstanceId once their numbering is seed-independent. A key type with no entry is a generator error. Readers are unchanged; the sort runs only on the write path.
  • B, C, D. Every effect that mints is a function of the program. "Mints" means: registers a first-wins entry, interns a name, numbers an id, or appends to an array that is written or indexed. Every walk over a table whose body can mint goes through one ordered-walk helper, which shares the generated writers' one ordering per key type and does not compile for a key type that has none. A walk stays unordered only when it iterates no table, or when its body touches only its own key's entry or folds by count, min or max. A lazily minted tuple layout takes its slot as well as its file from arrival order; with every walk ordered, mint order is a function of the program and first-wins stands.
  • The gate. Two fixed, distinct process seeds, one tier, one planted stored seed, two fresh cache roots; every pack kind (views, parses, baseline, core, audit) byte for byte; each kind must exist and be non-empty in both roots first.

Rejected: sorting on the read path; ordered maps; patching writers one by one; writing names in place of GenericInstanceIds; each file's copy recording its own file (C option B); a "no one file" origin (C option C, #18's work); a tests/docs gate against hand-written table-walking writers.

4. Blast radius

scripts/library-cache/*; every @generated library-cache region (regenerated); SignatureIndexInstances.maxon (the interning walks, the tuple registration); the four builders in SignatureIndexSettle.maxon and SignatureIndexGenericTypes.maxon; C's walk once located; one new tests/ case, its helper, tests/README.md.

5. Obligations

No error code. No emitted runtime. The cache schema fingerprint moves (wanted). No release note: the cache is internal. A warm compile's allocations do not change.

6. Acceptance

  • The two-seed pack compare over all five kinds: red on the parent with all four causes shown, green after.
  • generate-codecs.py --check.
  • A warm compile's allocations against a control built from the parent.

7. Staging

One /land, unless a file another change holds forces part of B, C or D to follow; then the emit rule lands first with a narrower red-first case, and the full compare lands with the last cause.

8. Open questions

None (ruled, section 9).

9. Amendments (orchestrator's ruling, 2026-11-17)

  1. C: option A, as an instance of the class rule. Locate C's walk with the instrument (tag the caller at registerTupleLayout's mint under two seeds), not by reading. Parse mints are already adopted in source-path order, so the seed-ordered minter is on the compiling thread; a candidate, unverified, is adoptRequestedTupleLayouts. A walk in a Parser*.maxon file or a function another task holds is a BLOCKED.
  2. No tests/docs gate. The generator's refusal of a key type with no ordering is the by-construction gate for generated writers; the two-seed compare is the gate for everything else.
  3. A parse section's ids differing by which program wrote it is not #178 (the footprint-and-rebase design). The DONE reports whether hello and fannkuch wrote that library file's section under the same key; if so and alternating the two misses each time, that is a separate FOUND.
  4. core and audit must be measured. The gate compiles as many programs or commands as it takes for all five kinds to be written in both roots (core: a program that instantiates a library generic function template; audit: a compile that runs the library's unused-declaration audit with a shareable program). audit is an array of findings, a cause-B suspect: attribute any differing bytes before fixing. A missing pack fails the gate.
  5. Ordering by digest value is approved. TypeParamId is a truncated SHA-256, ordered alike everywhere. A HashDigest folded from the stored seed is independent of the process seed and stable within one root. Hold: no digest that reaches a pack is folded under the process's own seed (before installLibraryDigestSeed) or comes from a table's hash; the gate shows it. DigestSeed is not edited.
  6. The gate's seeds: two fixed, distinct MAXON_HASH_SEED pins on the processes the test starts; one tier, no tier doubling; one stored seed planted in both roots (#78 ruling 10a.4).
  7. The schema fingerprint moving is accepted and wanted.
  8. Replaced (cost, measured, 2026-11-17): ordering every settle-tail walk costs +48 to +56 allocations and about 127 KB per warm compile, wall time inside noise; the key-ordered writers cost +0.2% to +0.6% allocations on a cold compile that writes the packs, nothing warm. So the uniform ordered walk of section 3 applies, with no preference order, no per-site "only these keys mint" subset, no "smallest path wins", and no seeding from the stored seed. The slot-and-path instrument under two seeds is the proof for C. Acceptance: a warm compile at most 100 allocations and 0.05% bytes over the parent; a warm self-compile within ±0.05%; a cold compile writing the packs at most 1% over; the scale ladder does not bend.

Clone this wiki locally