Expand description
ContentMemo + the thread_local_content_memo! macro — a byte-neutral,
content-keyed memo of a pure function (the extracted shape hand-rolled at
the NAR-hash / referenced-idents / overlay-flatten memo sites).
ContentMemo — a byte-neutral, content-keyed memo of a PURE function.
§The load-bearing invariant (why this is safe on a byte-parity path)
The memoized value is a pure function of its content-key, so a cache
hit is byte-identical to a recompute. That is exactly what makes
memoization safe on sui’s byte-parity-critical eval path: a memoized nix
evaluation must produce the identical drvPath whether the value was
freshly computed or served from the memo. The key IS the content address;
the value is fully determined by it.
RISK — do not violate: never memoize a value that depends on anything
other than its key — wall-clock (currentTime), environment (getEnv),
mutable filesystem reads, or eval-order-sensitive identity. Those are not
pure functions of the key, so a hit would NOT equal a recompute and could
change a drvPath. If the value can vary for a fixed key, it is not a
ContentMemo candidate.
§Why it’s a primitive
This exact shape — a thread-local Map<ContentKey, Rc<Value>> of a pure
function, cleared at a natural boundary — was hand-rolled three times
before this module (the sui-compat NAR-hash memo, the sui-eval
referenced-idents memo, the sui-eval overlay-flatten cache). This is the
extracted, packaged shape: declare one with thread_local_content_memo!
and get a memoized accessor + a clear fn for free.
Single-threaded by construction (Rc + RefCell), matching sui’s
single-threaded evaluator.
Structs§
- Content
Key - A content address derived by construction from a value of type
T. - Content
Memo - A single-threaded content-keyed memo.
Kis the content address; the valueRc<V>is a pure function ofK(see the module invariant). A hit is a cheapRc::clone.