gen-memo is the incremental plane: a decision layer over the evaluator that never evaluates, only decides reuse. Its definition is a byte-parity oracle against a cold evaluation — a plane output must be byte-identical to what a cold run produces — so the plane is correct exactly when it is invisible in the result and visible only in the work avoided.
It answers one question — given the last evaluation, must key K be recomputed? — and performs the minimal recompute plus reuse. In the Mokhov decomposition it is the rebuilder dimension alone; the scheduler is Nix's own laziness, which the evaluator already takes.
nixpkgs-lib-free. lib/ depends on gen-prelude and gen-graph, both pure and nixpkgs-lib-free,
and on no <nixpkgs>. A dedicated purity suite pins that as a checked property.
- Overview
- The name
- Gen Ecosystem
- Design Principles
- Quick Start
- API Reference
- Edge Convention
- Scope and Soundness
- Testing
- Theoretical Foundations
- Limitations
| Term | Definition |
|---|---|
| Store | flat relocatable id-keyed result map { <id> = value; } — plain values, not thunks closed over an evaluation |
| Trace | per-key { deps; hash } verifying record |
| Cone | the dependent cone of x — everyone who transitively depends on it |
| Dirty set | changed ids together with their dependent cones (the cheap over-approximation) |
| Affected set | the exact subset whose hash actually moved, discovered by the propagation |
| Splice | priorStore // fix-of-cone — recompute the cone, reuse the rest |
The flatness and relocatability of the store are this library's own design claims about its own store, stated in its own voice. They are not attributed to any paper; see Theoretical Foundations.
The plane is named for its contract, not its mechanism. memo names the reuse decision — defined
by byte-parity against a cold run — while the mechanisms assigned to it stay free to evolve without
staling the name. "Memoization" is the vocabulary the module system already promises and this plane
discharges.
The runner-up, gen-delta, was rejected on the permanent δ homonym in shared spec space. Recorded so
it is not re-proposed.
| Library | Role |
|---|---|
| gen-prelude | Pure nixpkgs-lib-free utility base |
| gen-scope | Demand-driven attribute grammar evaluator — the sole evaluator, which this plane decides over and never replaces |
| gen-graph | Accessor-based graph query combinators — supplies the reverse reachability the dependent cone is read from, and the one published SCC partition door |
| gen-algebra | Pure Nix algebra: records, intensional functions |
| gen-memo | This lib — the incremental plane (the reuse decision, defined by byte-parity against cold) |
- The plane never evaluates. It decides whether to recompute; it never is the recompute.
Evaluation belongs to the evaluator, which is kept thin and sole. The node-eval arrives as a
caller-supplied
recompute. - The plane does not schedule. The scheduler is Nix's own laziness; writing one here would duplicate the language runtime.
- The plane reads a cone; it never computes one. Reverse reachability and the SCC partition are gen-graph's, consumed through its published surfaces and never re-implemented here.
- Byte-parity is the definition, not a test target. A plane that is fast and not byte-parity is not a faster plane; it is a wrong one.
- A plane that accumulates its own evaluation state has failed. It observes the evaluator's graph and decides against it. It does not become a second place where results live and drift — a "cache" that is not defined by the parity oracle is that failure under another name.
- Loops are iterative and their accumulators are forced. Nix does not reuse a tail call's frame, so a recursive loop's descent depth is its round count and it aborts uncatchably; an unforced accumulator field chains a thunk per round and overflows a different stack. Both are constructions here, not conventions.
{
inputs.gen-memo.url = "github:sini/gen-memo";
}Then gen-memo.lib is the genMemo attrset.
import (fetchTarball "https://github.com/sini/gen-memo/archive/main.tar.gz") {
prelude = /* gen-prelude lib */;
graph = /* gen-graph lib */;
}The standalone entry is a function of the library's dependencies, per the gen root-file convention.
Every entry point that reaches a store takes the ENGINE first among its operands. The plane decides reuse and never
evaluates, so it populates no store of its own: it hands the engine a domain, a base and a decision,
and the engine produces the values. A caller that has an evaluator hands that; a caller that has
none — a test, an example — hands the reference scheduler, which ships outside lib/ at
reference/schedule.nix precisely because it is not part of the plane.
let
engine = import "${genMemo-src}/reference/schedule.nix" { prelude = gen-prelude.lib; };
ctx = genMemo.build { } engine {
accessor = someGraphAccessor; # the topology oracle
recompute = acc: store: id: /* … */; # the node-eval
hashOf = v: builtins.hashString "sha256" (builtins.toJSON v);
};
after = genMemo.override engine ctx "someNode" { newData = 1; };
in
after.store # the prior store, splicedThe engine is never stored on the returned context — it is supplied at each entry, so nothing the plane carries forward is an evaluator.
examples/dag is a runnable version of exactly this, including the poisoned-recompute proof that
untouched nodes are never re-evaluated.
The fold above works over the plane's own store. The warm fold works over an EVALUATION, and the evaluator is passed in rather than depended on:
let
after = genMemo.warmOverride (engine // { inherit (genScope) foldEquations; }) ctx "someHost" {
class = "db";
};
in
after.eval.get "someHost" "resolved" # re-derived; everything outside the cone is reusedOne engine record, two capabilities: foldEquations seals the warm evaluation, and schedule
populates the memo context beside it. They travel together because they are one thing — the
evaluation environment the caller already has.
ctx is a resolved context, the seal genScope.foldEquations returns — the scope, the schedule,
the settings, the accessor and a prior evaluation. The plane reads that prior through the
evaluator's restricted facade, decides, and hands the decision back to foldEquations, which runs
the warm evaluation and seals it with the expressions it seals a cold fold with. So the returned
ctx's node list, its dependency relation and its trace are the warm evaluation's, what a cold fold
of the edited data publishes, and none of them is built by the plane.
Migrating an engine record. The warm fold used to call evalWarm and now calls foldEquations.
A record carrying evalWarm alone is refused at warmOverride / warmResolve, by name and
catchably, with the repair: add inherit (genScope) foldEquations; to it. evalWarm itself is
unchanged and still exported by gen-scope; only the field the fold reads moved. A ctx assembled by
hand rather than sealed by foldEquations must now also carry schedule and settings — the
simplest repair is to seal it through foldEquations.
31 exports, in seven groups.
The argument grammar. Options come first, as one closed set; operands follow, positional, with
configuration first and the subject last; a record is kept only where its fields have no order among
them, and it is open (an extra field is admitted). A step taking a record is a prelude.door, so a
missing field, an unknown option, or an option placed on the record instead of the options is refused
by name, catchably, where that step is applied, and its field contract is published as __contract.
The reshaped call shapes:
build { fixpoint ? null; } engine { accessor; recompute; hashOf; }
why / whyNot { cutoffs ? { }; } ctx changedId id
whyFor / whyNotFor { cutoffs ? { }; } ctx changedId # then id, once per node
needsEval { trace; coneSet; newHashOf; accessor'; } changedId id
runScc ascend { accessor; store; recompute; scc; higherStrata; lattices; }
mkAccessor { dependencies; nodes; nodeData; parent; }
verify ctx accessor' spliced id
earlyCutoff hashOf oldHash newValue
affectedSet engine ctx accessor' changedIds
warmDecision accessor prior seeds # .identitiesHeld { remerged ? [ ]; } { priorIdentities; nextIdentities; }
warmOverride engine ctx id newDecls
warmResolve engine ctx edits
warmTrace edited decisionWhich exports take the engine. Every operation that reaches a store takes it as its FIRST
operand (build after its options): build, override, propagate, force, forceCtx, retract, applyEdgeDelta,
affectedSet, restabilize, propagateEager, and the two warm folds. The rest — the pure queries,
the strategy predicates, the two observations, applyDelta, batch, runScc, mkAccessor — do
not, because they populate no store.
Build and reuse decision
| Export | What it does |
|---|---|
build |
Full evaluation into a store and a verifying trace, the store populated by the engine handed in. Pre-checks acyclicity and throws a located, tryEval-catchable blame on a cycle. With a fixpoint argument it relaxes the check and solves stratified over the condensation |
needsEval |
Whether a node must be recomputed, before any cutoff |
earlyCutoff |
Whether a recomputed value's hash moved, after recompute |
verify |
Whether a node's trace is still valid — deps unchanged and all dep hashes clean |
Three predicates deciding at three different times; that is the plane's precision story, and they are not the same predicate under three names.
Cones
| Export | What it does |
|---|---|
affected / impactOf |
The dependent cone of one id |
dirtySet |
The cheap over-approximation: changed ids together with their cones |
affectedSet |
The exact subset whose hash actually moved, post-filtered from the propagation |
Change and propagate
| Export | What it does |
|---|---|
applyDelta |
Data change only: rewrite one node's data, mark it pending, recompute nothing |
batch |
Fold applyDelta over several deltas |
propagate |
Drain the pending set to quiescence over the union cone |
override |
The fused convenience — propagate after applyDelta |
force / forceCtx |
Pull semantics: drain, then read a value (or the quiescent context) |
propagateEager |
The cut-heavy fast path: rank-ordered push that recomputes only enqueued nodes |
Topology change
| Export | What it does |
|---|---|
mkAccessor |
Rebuild a full accessor record |
retract |
Delete a node and splice it out of its dependents |
applyEdgeDelta |
Replace a node's declared edge set, sub-building any newly reachable producers |
The warm fold — reuse decided for an evaluator
| Export | What it does |
|---|---|
warmDecision |
The decision itself: isClean (the complement of the dirty cone) and reusable (the evaluator's own resolutional vocabulary). Two total functions and no values |
warmOverride |
Splice one node's declaration, decide, and hand the evaluator one warm pass |
warmResolve |
The batch form: N edits, one union cone, one pass |
The evaluator is a PARAMETER, not a dependency. This library declares no evaluator input; the
fold takes { foldEquations } and calls it. So the call reads
warmOverride { inherit (genScope) foldEquations; } ctx id newDecls, and what comes back is the
context re-evaluated under the decision and sealed by gen-scope — every value, and the relation and
trace over them, produced there, none by the plane.
warmDecision is exported apart from the fold on purpose. It is the whole of what the plane
contributes, and a surface that offered only the fold would leave the interface the design rests on
unobservable.
The observed decision — an evaluator's warm answer, watched rather than made
| Export | What it does |
|---|---|
warmAdmits |
Whether a caller's edit has the shape a warm pass may be asked for: its key set is exactly the one reuse-bearing argument named, so every other argument is unchanged by construction rather than by comparison |
warmTrace |
The evaluator's published decision, narrowed to the six fields a consumer reads (mode reason reused remerged modules inert), attached only to a result that was reached through an edit; an evaluator that states no inert reads null there, never false |
These two OBSERVE; the group above DECIDES, and that split is why warmTrace is not called
warmDecision. warmDecision is this plane's own answer — two total functions over a declared
node graph. warmTrace is a record about an answer some evaluator already gave, carried in that
evaluator's own field names so a consumer reads the answer and not a translation of it. Neither
function here calls an evaluator or names one: the reuse-bearing argument key is a parameter,
because which key carries reuse is a fact about the caller's call surface and this library declares
no evaluator input to learn it from.
The admission test is syntactic over argument keys because the semantic test is unavailable, not
because it is cheaper — in Nix == never reports two function values equal, not even one binding
against itself, so for an argument carrying a function there is no equality that can witness
"unchanged".
Cycles and provenance
| Export | What it does |
|---|---|
runScc |
Solve one strongly connected component to its least fixed point |
restabilize |
The cyclic-capable analogue of override |
support / supportDirect |
The transitive (or immediate) declared producers of a node |
why |
The verdict an override would produce for a node: recomputed, cutoff or unaffected |
whyNot |
The same as a total record — { reason; at } for every verdict |
whyFor / whyNotFor |
The same two questions curried on the change: one cone bound, spent over many nodes |
The internal hash guards (hashGuarded, hashEq, hashMoved) are not on this surface. They are
imported directly by the files that need them; the evaluator this plane decides for is owed no hash
surface at all.
accessor.dependencies id is the ids that id depends on — consumer to producer. A dependent
cone is therefore reverse reachability over that relation.
The name is not edges, and the distinction is load-bearing rather than cosmetic. This relation is
the node-level dependency relation (Knuth's D(T)); edges is what gen-graph's generic
operators call the scope-to-scope relation they walk, and they keep that name. The two are crossed
at one place — lib/graph-view.nix — so every call into gen-graph constructs its argument
explicitly instead of relying on the two vocabularies having happened to coincide.
The plane is parametric over its dependency oracle, and the two instantiations that ship do not
agree on which ids dependencies will answer for. Which one you hold decides what is legal to ask.
- Caller-built. The relation is total over probed ids, including ids outside
accessor.nodes— herenodesmeans the live set, not every id the relation knows.applyEdgeDelta's new-producer sub-build and thewhy/whyNotwalks depend on that totality: discovering an id that is not yet a member is how a fresh producer gets found and built. - Substrate-contracted. The relation is the normalized union of a structural and a declared half, and it is fail-closed — a non-member id is refused by name. Its domain is exactly the evaluated node set.
The two cannot meet by accident, because the membership contract bounds every id an edge names: the structural half is refused at the projection when an endpoint is not a node, and the declared half is contracted at minting. A contracted edge set therefore names only members, so the discovery walk has no foreign id to reach. Cross them deliberately and the boundary is loud — the membership refusal fires at the first probe and the operation aborts naming the id.
One asymmetry follows from this and is a stated fact rather than a bug: why decides cone
membership by walking the relation, so a foreign id under a contracted accessor aborts, while
whyFor decides it by set lookup, so the same id misses the cone and comes back unaffected. The
two agree by construction on their verdict branches, within a mode; they differ in the domain their
membership oracle accepts. lib/graph-view.nix carries the full statement and the condition under
which it must be revisited; ci/tests/accessor-modes.nix pins both halves.
overrideis a DATA-change operation. It replaces one node's data; edges are fixed. Its soundness claim is "data-change override equals a full rebuild", not unconditional soundness. Topology changes go throughretract/applyEdgeDelta, which rebuild the accessor and re-run a located cycle check.warmOverrideis a data-change operation too, and refuses the other kind BY NAME. It decides reuse from a cone read over the topology as it stands, so an edit carrying an edge key throws rather than being served a decision computed against a shape that no longer holds.- The warm pass is armed with the relation the cold fold sealed.
warmOverridehands the ctx'sdeclaredDependenciestofoldEquations, so a node it recomputes refuses an undeclaredself.node,self.getorself.getRepresentativeread exactly as the cold fold does, and a reader of that kind is never left outside the cone to be served a stale prior. A ctx whosedeclaredDependenciesis notgen-graph.mkDeclaredEdges' relation, a missing field included, is refused by name. The guard reaches those three names only: a body reading another node through a different field of its reader is not refused and, outside the cone, is still served its stale prior. For those reads soundness still rests on the relation OVER-DECLARING them.ci/tests/warm-override-cross-node.nixandci/tests/warm-read-seam.nixwitness the refusal and a served prior. - Store equality is over hashable values. A node whose value carries a function is sound by being always-dirty, not by comparing equal.
- The cyclic path is outside the acyclic envelope. Per-SCC convergence rests on the consumer's
unchecked monotonicity and finite-height obligations; the only runtime divergence guard is the
consumer-declared per-member
maxIter, which refuses with a catchable located blame. maxIteris required of every cyclic member and has no default. The bound is honest only as the consumer's own assertion about their own lattice; supplying one here would have the engine assert a bound about a lattice it cannot inspect — neither monotonicity nor height is checkable — and then blame the consumer at a number the consumer never wrote. A member with nomaxIteris a build error naming the members that owe one, not a silent fallback.
nix develop ./ci --command ci # run everything, guarded
nix develop ./ci --command ci byte-parity # a single suite, guarded
nix flake check ./ci # what CI runs; unguarded
nix-unit --flake ./ci#tests # run everything; unguardedci refuses when anything under a declared read root is unknown to git — any extension or name,
_-prefixed included — and the remedy is git add or a move. The unguarded forms read a
git-filtered copy of the tree, so an untracked cell is silently absent and the run stays green.
35 suites, 476 tests (nix-unit --flake ./ci#tests ⇒ 476/476 successful). Beyond the migrated content's own, two are the plane's oracles, and one more, gen-ci-examples, is gen-harness's examples guard (declared in ci/tests/examples.nix, gen.ci.examples), holding that examples/ directory names equal the declared names and that every declared example forces under deepSeq:
byte-parity— the definition, armed: the same input evaluated twice, once with the decision forced to nothing-is-clean, compared on the image the admission projection produces wherever the output holds a derivation (keyed by itsdrvPath), and on the value otherwise. The comparator IS that projection, not a second implementation of it, and the sharing is load-bearing in two directions: a comparator returning a baredrvPathstring observes a derivation and a plain string equal to thatdrvPathas the same value — a false-clean collision in the one instrument whose whole claim is byte-parity — and a comparator re-implementing the projection could drift from the one the plane hashes with. It carries its own live control, because a comparator that reported parity for everything would pass every other cell in the file.fleet— the measurement lab's Arm R: a shared producer with dependent hosts, a localized single-host edit, the byte gate plus the poisoned-recompute proof, and the>= 0.60saving floor. Which half of that floor migrated and which did not is stated in the suite itself.
nix-unit collects only cells named test-*; a cell that loses the prefix disappears from the
nix-unit run, which still reports green. nix flake check — what CI runs — backstops this: gen's
asserter does not filter on the prefix. AGENTS.md carries both armings and the both-ways
reconciliation command.
★ CITATION PROVENANCE. Every primary this library cites with a section coordinate is in the papers archive, and each such coordinate was located in that source rather than carried on the retiring library's authority.
The excluded axis, named in the same breath, because a scoped sentence read as a universal is how
the previous revision of this section went wrong. Some cited names are held as primaries and some
are not — and not held as a primary is not the same fact as absent from the archive. The
second is what a filename sweep measures, and it is the weaker instrument. At content granularity
across used/ and reference-catalog/, with archived names as live controls and a nonsense token
⇒ 0 as the negative control:
| cited name | primary? | discussed in archived work |
|---|---|---|
| Kosaraju / Sharir | no | ⇒ 0 at both granularities — genuinely absent, nothing checkable |
| Tarjan 1972 | no | named in 3 archived works, one of them Mokhov 2017 — itself a primary this ecosystem cites. A recorded acquisition gap |
| Kleene | no | named in 5 archived works |
| Magnusson–Hedin | no | the construct is described in archived primaries on exactly the cited subject — Söderberg 2013 lists "Magnusson, E., Hedin, G.: Circular reference attributed grammars" and describes their fixed-point iteration; Hedin 2000 is a co-author primary on reference attribute grammars. Checkable here; not an absence |
None of these carries a section coordinate, which is why the scoping holds and why it has to be said: they are attributions to a named idea. What that means differs per row — unverifiable for Kosaraju/Sharir, verifiable at one remove for the other three — and collapsing them into one "absent" list was itself a measurement stated wider than its instrument.
And "located in that source" means BY CONTENT, not by heading. The Acar extraction carries no
numbered section headings at all — its only headings are the title and 47 ## Page N markers — so no
§-digit can be confirmed against it. The rule is total, and deliberately not an enumeration: every
Acar §-number anywhere in this repository is content-verified and coordinate-unverifiable at the
current extraction. An enumerated list stood here and was already wrong, naming §4.3/§4.4/§4.5/§7 and
missing §8; a hand-maintained list of coordinates drifts from the files it describes the moment either
moves, and a total rule cannot go stale.
Three claims are the library's own and are attributed to no paper, in each case because the cited section was read and does not contain them: the store's flatness and relocatability (not in Mokhov §3.1), the reverse-topological splice (not in the Acar paper), and "eager push" (RTD supplies the topological order; the eager characterisation is this library's).
★ The splice exclusion's ground, restated because one supporting figure was wrong. It rests on
topolog ⇒ 0 and reverse ⇒ 0, and both still hold, so the conclusion is unchanged. A third figure
carried beside them was not: order maintenance ⇒ 0 was measured with a space against a
hyphenated surface — hyphen-tolerant it is ⇒ 7, and the paper's efficient implementation is
built on an order-maintenance structure. A predicate that cannot match the surface it is aimed at
returns an absence indistinguishable from a finding.
What stays hedged is a claim about reach, not provenance: RTD's true O(|AFFECTED|) optimality
and its characteristic graphs are not reached by this implementation in pure evaluation.
★ An earlier revision of this section said RTD 1983 and Acar 2002 were "not in the archive". They
are, in reference-catalog/ — a different tier from used/, and not the same claim. The sentence
was inherited from a document that scoped its own measurement correctly and widened it in the next
clause, and repeated here without re-measuring.
-
Mokhov, Mitchell & Peyton Jones (2018), Build Systems à la Carte. The scheduler/rebuilder decomposition. gen-memo is the rebuilder dimension; the scheduler is Nix's own laziness, taken by the evaluator. In the paper's Table 2 the claimed cell is suspending (§4.1.3) × verifying traces (§4.2.2) — deliberately not the paper's own Nix row,
nix = suspending dctRebuilder, which is deep constructive traces (§4.2.4) and does not support the early cutoff the invalidation claim needs.The memory claim is NARROWED, and the narrowing is written here rather than inferred from what got built. §4.2.2's cross-build memory is not what this plane has: a Mokhov rebuilder consults build information that "persists from one invocation of the build system to the next" (§3.1), and a pure Nix evaluation has no cross-invocation persistence. The plane's memory is the prior evaluation's own accessor, live inside the same evaluation, and its scope is intra-evaluation reuse — the override cone, and reuse across the many targets composed within one evaluation. What survives is the verifying-trace shape, the rebuilder/scheduler decomposition, and the reuse decision itself. What does not is persistence across invocations, in any form.
The store's flatness and relocatability are NOT Mokhov's. §3.1 defines the Store and states neither property. They are this library's own claim about its own store, and are made in its own voice everywhere they appear.
-
Reps, Teitelbaum & Demers (1983). Reverse-transitive-dependency propagation supplies the invalidation relation: the AFFECTED set (§4.3) and the unchanged-value cutoff (§4.1). True
O(|AFFECTED|)optimality and characteristic graphs are recorded as not reached in pure evaluation — a finding about this implementation's reach that travelled with the content. The attributions themselves are verified at the primary, including the paper's own point that AFFECTED "is determined as a result of the updating process itself" — the reason the cheap cone is an over-approximation and the exact set is post-filtered from hashes. -
Acar (2002). The change/propagate split is the paper's:
applyDeltaandpropagateare its two metafunctions, de-conflated here rather than fused — verified at the primary. The reverse-topological splice is not there at all, so that mechanism is this library's own and is attributed to no one. -
Arntzenius (2016), Datafun. Reverse reachability, and the per-SCC least fixed point by iterate-from-bottom on finite-height semilattices.
-
Fleischer, Hendrickson & Pınar (2000) by way of gen-graph, whose partition door supplies the SCC quotient this library reads and does not compute.
The definition, not a citation. The plane's correctness condition is the byte-parity oracle: a plane output must be byte-identical to a cold evaluation.
- A node value is hashed only if a BOUNDED walk finishes on it; otherwise it is always-dirty.
The null-hash rule records the first partiality — Nix's hash is partial on function-bearing
values, so those get
hash = nulland are conservatively always-dirty. That rule has no paper behind it; it is an operational Nix fact. The second partiality is a value whose walk never ends — a self-loop, a two-cycle, an unboundedly generated value — which an unbounded walker met at the evaluator's call-depth ceiling, aborting where the cold evaluation had a value. A Nix derivation is the ordinary member (drv.all's first element is the derivation itself), and it is removed at every depth by the admission projection — a shape test applied before descending, which yields an image keyed by the derivation'sdrvPathand never walks into its self-referential attributes (below, the image of a derivation);ci/tests/byte-parity.nixdrives derivation-valued nodes through the plane. Everything else lands on the null rule: "finite" is only semi-decidable, and the walk is its bounded run — past the depth bound below it endsexhaustedand the value is always-dirty, a change of cost and never of answer (ci/tests/hash.nix, andci/tests/eager.nixthrough the plane: cold parity, the null hash, and every host behind a self-referential node recomputed where a plain one is cut). The third partiality is a catchable bottom the walk reaches and no cold read does (below). - The walk reads the image
hashOfis handed. It runs overproject value, so a derivation'sdrvPathcontent is walked like any other position: a function there answers null, and a loop there meets the bound. - One bound, D = 2500 levels, an engine constant and a real ceiling (
lib/hash.nix). Re-derive it when an evaluator, itsmax-call-depthdefault or the walk changes. The walk is depth-first, in the unbounded walk's order, and spends two call frames per level (the walker and thebuiltins.anythat calls it); measured, an unbounded walker of this shape last completes a chain 4998 deep andtoJSONone 9996 deep. So D levels cost 2·D frames against a defaultmax-call-depthof 10000, and D = 2500 leaves half to the caller. ONE value on upstream Nix, Determinate and Lix. The depth is carried by WHICH walker runs — the walker at depth k binds the one at k + 1 once in its closure — so a position costs what it cost the unbounded walk, with no counter threaded through it. Nothing counts positions: a wide acyclic value hashes whatever its size. - What the bound costs.
- The walker family: at most D closures per import of
lib/hash.nix, built lazily and only as deep as a value has reached. Nothing per value. - A value that exhausts costs Θ(D × the acyclic mass the walk completes before each step down the cycle). A self-loop costs D steps; bulk ahead of the back edge, in attribute-name order, is re-walked on every unrolling (measured: 1000 records ahead of a self-reference, about 4 s per hash on upstream Nix). Such a value aborted uncatchably before the bound existed.
- Reuse: an acyclic value with a container at image depth D or deeper is always-dirty. The unbounded walk hashed such values only when its caller left room — at caller depth c, only below depth (10000 − c)/2 — so the loss is reuse and never an answer.
- The walker family: at most D closures per import of
- The enumerated exception to the walk's totality. The certificate is scoped to a caller at
most
max-call-depth− 2·D frames deep (measured with the suite'sunderFrames, on all three evaluators: 4990 open frames for the self-loop, 4992 for the deepest admitted chain, one below the walk before it ran undertryEval). A caller deeper than that still meets the uncatchable abort on its deepest admitted values — as it did before, and at the same place.ci/tests/hash.nix'stest-depth-bound-leaves-caller-margincertifies 4500 frames; a loweredmax-call-depthsetting shrinks the margin with it. The budget assumes ahashOfthat spends one frame per level, as the plane'stoJSONdoes:hashOfis supplied by the caller, and one that recurses deeper per level narrows the caller's half. - The fallback is silent. Nothing tells a consumer that its node went always-dirty on the
bound or on a throw; the reason is internal to
lib/hash.nix(classify, read by tests). Emitting it is owed through a warned-outcome channel: the result carrying its own provenance. - A walk that throws is always-dirty. The walk forces every position of the value up to the
first function (depth-first, in attribute-name and list order), which is strictly more than a
cold read that forces only what its consumer reads. A lazy
throworassertthe walk reaches and no consumer does is caught around the walk, and the value hashes tonull: the plane recomputes the node and answers what the cold evaluation answers. This is the ordinary case, not an edge — nixpkgs signals "do not evaluate this" with lazy throws (the first attribute ofpkgsin name order, aliases, the unfree/broken/insecure meta checks), so a node value carryingpkgs, a package set or an inadmissible package lands here (ci/tests/hash.nix, andci/tests/eager.nixthrough the plane). The catch is never around the caller'shashOf: a throw fromhashOfis the caller's own error and stays loud. - The residue: an uncatchable bottom still aborts. A missing attribute, a type error,
abortor a stack overflow in the walk's prefix is outside whattryEvalcontains, so it takes the evaluation down where a cold read that never touches it succeeds — unchanged from before the catch. No Nix construction contains it; it is the one enumerated exception to the rule that every operation returns a value or a named, catchable refusal. - What the catch costs.
- Per hash, a constant independent of value size (operation census,
NIX_SHOW_STATS, identical on upstream Nix, Determinate and Lix, A/A 0): +0 function calls, +1 primop call (thetryEval), +2 thunks, +3 lookups. In user-space instructions (perf stat, 3 reps, A/A within 0.9998–1.0004): +~2415 on upstream Nix, +~3400 on Determinate, +~1950 on Lix. - As a ratio that constant is largest where the hash is cheapest: a bare-int node hashes 1.105–1.156× slower (Lix 1.105, upstream 1.144, Determinate 1.156), a small record 1.06–1.09×, a config-shaped record 1.02×. That band is a benchmark acceptance bound, not a production constraint: it states what has been verified, and it is reviewed at the recurring performance gate rather than enforced automatically.
- Always-dirty is not the cold cost. The walk still pays to reach its verdict, in addition to
the recompute, and a value the throw used to end early now pays for the whole walk and
evaluates: a node holding
pkgs.perlPackageswalks +1.28 M thunks past the import floor per first hash. That cost is the walk's own strictness, unchanged by the catch; what the catch changes is that the value reaches it instead of failing.
- Per hash, a constant independent of value size (operation census,
- The image of a derivation, and what it reads UNCHANGED (a declared exception to
"a value or a named refusal"). The outermost derivation's
drvPathkeys the image; its other own attributes are hashed structurally, withoutalland the output attributes. Every key enters the image through one injective escape, at every position, the outermost included:outPathbecomes__outPath, every key beginning__gains one more_, and every other key is unchanged. SotoJSONno longer reads an attrset carryingoutPathas that string alone, and no user data can spell a stand-in the image writes (__drvPath,__outPath,__sealed,__nestedDrv). A literal tag, a derivation overlaid with//(at any depth) and an attrset beside anoutPaththerefore separate. Inside a derivation's attributes a function, a nested derivation (itsdrvPathnever read),passthru,testsand every attribute named inpassthruare sealed present/absent, because reading them instantiates what they reach (measured over 2855 nixpkgs packages: 19.8× thunks and 8 of 29 chunks dead when they are read, 1.008× with them sealed). So two values read UNCHANGED, where a cold evaluation distinguishes them, when they differ only at (R1) a changed function inside a derivation's attributes; (R2) a nested derivation swapped where it does not feed the outerdrvPath; (R3) anything insidepassthruortests, or in an attribute named inpassthru, an attribute named there asoutPathor__toStringincluded, since passthru content is sealed and so collides by sealing, not by spelling; (R5) a derivation's output attributes orall, overlaid or absent, which the image drops. Each is pinned as a collision byci/tests/hash.nix'stest-c5cj-residue-is-stated. The former R4, a literal record spelling a stand-in ({ __outPath = x; }against{ outPath = x; }, a literal__sealed/__nestedDrv/__drvPath, a derivation's image written out), is closed by the escape and pinned separating by thetest-x67vn-*cells. A package carrying a package set outsidepassthruwhose walk throws (Haskellscope, Lisppkgs: 12 of the 2855) is always-dirty. - The projection is not injective, only because it seals and drops. Every remaining collision forgets information (R1–R3 keep presence only, R5 keeps nothing); none is user data spelling a stand-in. Its codomain is a subset of its domain, and that does not make it idempotent: projecting an image escapes the image's own keys, so a derivation's image written out literally separates from the derivation. The residual direction is false-clean, which is the unsound one.
- The plane holds no store fix, and that is not yet the same as holding no evaluator. A
self-referential store over the node set, passed into the caller's node computation, is gone from
lib/— the sites that had one now hand the engine a domain, a base and a decision. But a fold threading its own accumulator of resolved outputs across a traversal it drives is the same construct by another spelling, and one remains:runScc'sfinalinlib/restabilize.nix, the per-SCC Kleene ascent. It is exempt because lattice-shaped ascent is a separate carrier's subject and the engine hosts none, not because it is clean. The enumeration lives inci/tests/purity.nixastest-node-eval-applications-are-pinned, at SITE granularity, so a fifth application reds it even when added to a file already on the list — named by binding, with no line coordinate and no rev anchor, because a binding survives what a coordinate does not. - The store-fix scan does not close the import route either, so it is scanned separately. A
lib/file writingimport ../reference/schedule.nixand callingscheduleitself would have the knot back with noprelude.fixtoken anywhere inlib/— measured, that plant leaves the token arm green. Reaching the reference scheduler from inside the plane is what would make it the plane's; being handed it at the call is what makes it the caller's. The path has its own cell, with the library's real./hash.niximports as the live control. - No cross-invocation persistence, by design and by the narrowing above.
batchlayers its accessor overrides, so N deltas leave an N-deepnodeDataclosure chain paid on every later read. Forcing the accumulator does not flatten it; only re-expressing the override as one data map would, and that is a change to whatapplyDeltameans.