Repository navigation
Conversation
Prior to this commit, `{ a = {}; a.b = null; }` would desugar to
`{ a = { b = null; }; }`, while `{ a.b = null; a = {}; }` would be a
parse error. This makes both parse errors, which I believe is the
appropriate behavior as writing `a = {};` in an attribute set would lead
the developer to reasonably think that `attrs.a == {}` while some later
declaration in the set could change that.
There are no files in nixpkgs ending in `.nix` which fail to parse with
this commit, and two files in nixos ending in `.nix` which fail to parse
but are easily fixable.
This change uses no additional space, adds an extra initialization (of a
bool) for each AttrDef initialized, and, in cases where one AttrPath
partially matches an earlier one in the set, replaces a dynamic_cast +
null check with a bool check (with a later static_cast, which has no
runtime cost).
As an additional perk, this change will make it possible to do dynamic
binds attrpath desugaring (e.g. { ${foo} = bar; } to the equivalent of
listToAttrs [{ name = foo; value = bar; }]) relatively efficiently
without changing the normal attrpath code path at all.
Signed-off-by: Shea Levy <[email protected]>
This adds new syntax for attribute names:
* `attrs.${name}` => `getAttr name attrs`
* `attrs ? ${name}` => `isAttrs attrs && hasAttr attrs name`
* `attrs.${name} or def` => `if attrs ? ${name} then attrs.${name} else def`
* { ${name} = value; } => `listToAttrs [{ inherit name value; }]`
Of course, it's a bit more complicated than that. The attribute chains
can be arbitrarily long and contain combinations of static and dynamic
parts (e.g. `attrs.${foo}.bar.${baz} or qux`), which is relatively
straightforward for the getAttrs/hasAttrs cases but is more complex for
the listToAttrs case due to rules about duplicate attribute definitions.
For attribute sets with dynamic attribute names, duplicate static
attributes are detected at parse time while duplicate dynamic attributes
are detected when the attribute set is forced. So, for example, `{ a =
{}; a.b = null; ${"c"} = true; }` will be a parse-time error, while `{ a
= {}; ${"a"}.b = null; c = true; }` will be an eval-time error
(technically that case could theoretically be detected at parse time,
but the general case would require full evaluation). The rules for
duplicate attributes are the same in both cases, though: if some
sub-chain of an attribute path already has a value, that's an error (for
example, `{ a.b = true; a.b.c = false; }` would cause an error when
parsing the `a.b.c` since `a.b`, a sub-chain, has a value. `{ a.b.d =
true; a.b.c = false; }`, on the other hand, is fine as neither is a
subchain of the other.
Finally, recursive attribute sets with dynamic attributes have the
static attributes in scope but not the dynamic ones. So `rec { a = true;
${"b"} = a; }` is equivalent to `{ a = true; b = true; }` but `rec {
${"a"} = true; b = a; }` would be an error or use `a` from the
surrounding scope if it exists.
This is an alternative solution to NixOS#132
Signed-off-by: Shea Levy <[email protected]>
Certain desugaring schemes may require the parser to use some builtin function to do some of the work (e.g. currently `throw` is used to lazily cause an error if a `<>`-style path is not in the search path, and `import` is used to import a nix expression to do most of the work for desugaring dynamic attribute names). Unfortunately, these names are not reserved keywords, so an expression that uses such a syntactic sugar construct will not see the expected behavior (see tests/lang/eval-okay-redefine-builtin.nix for an example). This adds the ExprBuiltin AST type, which when evaluated uses the value from the rootmost variable scope (which of course is initialized internally and can't shadow any of the builtins). Signed-off-by: Shea Levy <[email protected]>
|
@edolstra thoughts? |
|
Why not use the string syntax for this in stead of the ${...}. Somehow that seems more natural to me. |
|
What do you mean with string syntax? |
|
I think he means something like |
|
Indeed, I meant having foo."${bar}". That way it would also allow easier (shorter) construction of 'names'. E.g. foo."prefix-${bar}" |
Instead of `foo.${bar}` (and all variants thereof), the syntax is now
`foo."${bar}"`. This is nice both because it's a natural extension of
the `foo."bar"` syntax we already have, and because it makes name
construction easier (`foo."bar-${baz}"`, not `foo.${"bar-${baz}"}`)
Signed-off-by: Shea Levy <[email protected]>
|
Last commit: Use strings for dynamic attrname syntax Instead of |
|
@edolstra ping? |
1 similar comment
|
@edolstra ping? |
|
This causes a parse error in NixOS: And another one in the zfs module. This can be easily fixed in NixOS (arguably the fact that it works at all is accidental) but it would be better not to have regressions. |
|
Ah, you mentioned this above. But breaking NixOS is probably still a bad idea. |
There was a problem hiding this comment.
Hm, why do you have two productions for parsing attribute sets? I would expect dynamic attributes to be handled in "attrpath". Having two different ways to parse attribute sets seems ambiguous, and might be slow because it causes the GLR parser to fork the parse stack. But maybe Bison is smarter than I thought...
There was a problem hiding this comment.
The goal was to avoid impacting performance of non-dynamic attribute sets as much as possible. There's no ambiguity: an attrpath can't have an attr_dynamic, and an attrpath_dynamic must have at least one. Handling attr_dynamic in attrpath would mean changing attrpath from vector<Symbol> to vector<Expr *> (or vector<TaggedUnionOfSymbolAndExprConcatStrings*>) and adding a later check to see if it was a dynamic or static attr. I don't really know the performance implications of the extra productions though, so perhaps that would be better?
This adds new syntax for attribute names:
* attrs."${name}" => getAttr name attrs
* attrs ? "${name}" => isAttrs attrs && hasAttr attrs name
* attrs."${name}" or def => if attrs ? "${name}" then attrs."${name}" else def
{ "${name}" = value; } => listToAttrs [{ inherit name value; }]
Of course, it's a bit more complicated than that. The attribute chains
can be arbitrarily long and contain combinations of static and dynamic
parts (e.g. attrs."${foo}".bar."${baz}" or qux), which is relatively
straightforward for the getAttrs/hasAttrs cases but is more complex for
the listToAttrs case due to rules about duplicate attribute definitions.
For attribute sets with dynamic attribute names, duplicate static
attributes are detected at parse time while duplicate dynamic attributes
are detected when the attribute set is forced. So, for example, { a =
null; a.b = null; "${"c"}" = true; } will be a parse-time error, while
{ a = {}; "${"a"}".b = null; c = true; } will be an eval-time error
(technically that case could theoretically be detected at parse time,
but the general case would require full evaluation). The rules for
duplicate attributes are the same in both cases, though: if some
sub-chain of an attribute path already has a value, that's an error (for
example, { a.b = true; a.b.c = false; } would cause an error when
parsing the a.b.c since a.b, a sub-chain, has a value. { a.b.d =
true; a.b.c = false; }, on the other hand, is fine as neither is a
subchain of the other.
Finally, recursive attribute sets with dynamic attributes have the
static attributes in scope but not the dynamic ones. So rec { a = true;
"${"b"}" = a; } is equivalent to { a = true; b = true; } but rec {
"${"a"}" = true; b = a; } would be an error or use a from the
surrounding scope if it exists.
Note that the error checking for attribute sets is pretty hairy, in part
because I wanted to leave the non-dynamic code path as untouched as I
could. Essentially, this creates a list of lists of attribute paths (
e.g. { a.b.c = 1; a.d = 2; } would go to [ [ "a" "b" "c" ] [ "a" "d"] ]
) for all of the attributes, static and dynamic, and then as each
dynamic attribute is added to the set its attribute path is checked
against that list. Possibly this could be cleaned up a bit.
This is an alternative solution to NixOS#134
Signed-off-by: Shea Levy <[email protected]>
This adds new syntax for attribute names:
* attrs."${name}" => getAttr name attrs
* attrs ? "${name}" => isAttrs attrs && hasAttr attrs name
* attrs."${name}" or def => if attrs ? "${name}" then attrs."${name}" else def
* { "${name}" = value; } => listToAttrs [{ inherit name value; }]
Of course, it's a bit more complicated than that. The attribute chains
can be arbitrarily long and contain combinations of static and dynamic
parts (e.g. attrs."${foo}".bar."${baz}" or qux), which is relatively
straightforward for the getAttrs/hasAttrs cases but is more complex for
the listToAttrs case due to rules about duplicate attribute definitions.
For attribute sets with dynamic attribute names, duplicate static
attributes are detected at parse time while duplicate dynamic attributes
are detected when the attribute set is forced. So, for example, { a =
null; a.b = null; "${"c"}" = true; } will be a parse-time error, while
{ a = {}; "${"a"}".b = null; c = true; } will be an eval-time error
(technically that case could theoretically be detected at parse time,
but the general case would require full evaluation). The rules for
duplicate attributes are the same in both cases, though: if some
sub-chain of an attribute path already has a value, that's an error (for
example, { a.b = true; a.b.c = false; } would cause an error when
parsing the a.b.c since a.b, a sub-chain, has a value. { a.b.d =
true; a.b.c = false; }, on the other hand, is fine as neither is a
subchain of the other.
Finally, recursive attribute sets with dynamic attributes have the
static attributes in scope but not the dynamic ones. So rec { a = true;
"${"b"}" = a; } is equivalent to { a = true; b = true; } but rec {
"${"a"}" = true; b = a; } would be an error or use a from the
surrounding scope if it exists.
Note that the error checking for attribute sets is pretty hairy, in part
because I wanted to leave the non-dynamic code path as untouched as I
could. Essentially, this creates a list of lists of attribute paths (
e.g. { a.b.c = 1; a.d = 2; } would go to [ [ "a" "b" "c" ] [ "a" "d"] ]
) for all of the attributes, static and dynamic, and then as each
dynamic attribute is added to the set its attribute path is checked
against that list. Possibly this could be cleaned up a bit.
This is an alternative solution to NixOS#134
Signed-off-by: Shea Levy <[email protected]>
|
Obsoleted by #167, closing. |
…dont-build nix flake check: Skip substitutable derivations
The catalog has accumulated enough cross-pass review work to need a permanent rule about what counts as evidence. Prior passes shipped findings that turned out to rest on weak ground: - E2 grep'd `nix::settings.*` field reads in src/*-c/ and concluded no settings type was exposed across the C ABI. V1 found that 5 of 6 C-API libraries install their *_internal.h(h) files, exposing layout to C++ consumers through the public include path. The inventory was correct; the conclusion was wrong because it reasoned about source-tree contents rather than shipped headers. - E6 predicted "16/22 fixtures fit cleanly" for an N41 consolidation; V5 verified each fixture against the source body and corrected to "27/28 with (subdir, suffix)". The catalog body did not mark E6's numbers as predicted. - The "NixOS#136 keystone for NixOS#134/NixOS#135/NixOS#137/NixOS#144/NixOS#149" chain propagated through three passes before B1 found that NixOS#135 does not actually depend on NixOS#136. Citation alone is not evidence; later passes inherited prior framing without re-deriving. - E8 wrote "negligible performance benefit" without measuring; V4 confirmed Direction A on four non-perf grounds and downgraded the perf framing. - E4 reported "61 positional-format sites in libstore" as wire-crossing without filtering by reachability from a daemon-side WorkerProto::Op handler. (V2 still in flight.) - B2 found that forceAttrs/forceList look like the rest of the force* family but use withTrace rather than addTrace+try/catch. The "10 force* overloads" claim was structurally similar function names treated as the same problem. Add an "Evidentiary standard" section to candidates/README.md enumerating eight rules: 1. Walk the call graph (behaviour claims trace at least one caller; lifetime claims trace destruction order). 2. Trace what ships, not what is in src/ (ABI claims must check install rules). 3. Counts require closed enumeration. 4. Distinguish predicted from verified. 5. Re-derive inherited claims (citation alone is not evidence). 6. "Same shape" is not "same problem". 7. Numbers require measurement (or label "structural reasoning, unmeasured"). 8. Comments are hypotheses; verify against code. Add review/AGENT-CHARTER.md as the operational form of the same rules, intended for any future agent prompt to reference. The charter requires every report to include a Method section, a per-rule statement of which rules were exercised, and per-claim verifiability labels (verified / predicted / unsupported). Also drops the prior "8 verified counts" snapshot from INVENTORY.md and replaces it with a pointer to the per-section catalog (the snapshot was stale by the time the consolidation pass ran). Drops one count line that referenced WorkerProto::latest as "1.38" without disambiguating from the PROTOCOL_VERSION macro (now 1.39); the macro and the struct are two genuinely different version handles, see review/F3-proto-version-drift.md. Lands all completed review reports under doc/inventory/review/: E1-E8 + F1-F3 + B1-B3 + C1 + V1, V3, V4, V5. V2 still in flight and will land separately. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Folds the findings from E1-E8, F1-F3, B1-B3, C1, and V1-V5 into the candidate sections as in-place body edits. Each affected candidate now carries a See also: line pointing at the verifying report(s); counts are re-derived where the V-pass produced a verified number; mechanism corrections from source-level investigations replace inherited framing. Substantive corrections to existing candidates: - NixOS#134 / NixOS#135 / NixOS#138 (15-globals-settings.md): - B1 found that the catalog's "NixOS#136 keystone for NixOS#134/NixOS#135/NixOS#137/ NixOS#144/NixOS#149" chain is wrong about NixOS#135. The body's keystone block now lists only NixOS#134/NixOS#137/NixOS#144/NixOS#149 as NixOS#136-blocked; NixOS#135 is independent. The reasoning is preserved in NixOS#134's and NixOS#135's bodies (asymmetry between virtual-base diamond and inline-member flattening). - V1 found that 5 of 6 C-API libraries install_headers with their *_internal.h(h) files, exposing layout to C++ consumers. The NixOS#138 body now spells out the C++ ABI caveat for deleting the dead nix::ref<bool> readOnlyMode field, with a release-note requirement. - F1+V3 confirmed (via end-to-end source trace) a latent UAF in the _new-without-_load path: the heap bool is destroyed by nix_eval_state_builder_free while the resulting EvalState still holds a bool * to it. NixOS#138's body now folds the UAF repair into the readOnlyMode -> Store migration, so deleting the dangling field sweeps the bug away in the same change. - NixOS#65 / NixOS#211 (08-duplicated-parsers.md, 21-eval-core-evalstate-value.md): - B2 verified by source reading that NixOS#65 has 79 canonical-template sites plus ~135 bespoke. NixOS#211 has 7 structurally-shared bodies, not 10 and not 16: forceAttrs/forceList use withTrace (a different shape) and forceString(NixStringContext &, ...) / forceStringNoCtx delegate to the single-overload forceString. The catalog's proposed merge of NixOS#65+NixOS#211 was rejected on different-risk-profile and different-consumer-scope grounds. NixOS#211 first (~1 week, internal); NixOS#65 second (~4-6 weeks, user-visible trace migration). - NixOS#213 (21-eval-core-evalstate-value.md): - E8+V4 recommend Direction A on four non-perf grounds. V4 downgraded the unsupported "negligible perf benefit" framing and surfaced a critical observation: ExprOpEq::eval evaluates into stack-local Value v1/v2 and ExprVar::eval ends with v = *v2; — the highest- frequency eqValues caller cannot benefit from canonical pointer- equality regardless of direction. - NixOS#18 (03-repeated-boilerplate.md): - B3 verified the hand-written CloneableError derivation count is 17 (catalog said 14). 18a (the MakeError macro itself) is not a real refactor target because MakeError already is CRTP sugar. 18b is per-class because most carry intrinsic payload. 18c is too small for top-level status. Body now documents the SQLiteBusy/SQLiteError cross-link and the BadNixStringContextElem/GitError err.msg- mutation fragility. - NixOS#166 (17-cross-cutting.md): - E7 verified per-file unique-header counts: 8 Source, 5 Sink, 20 Store, 12 EvalState, 7 Value, 6 StorePath, 10 StoreDirConfig. Recommendation: ship serialise-fwd.hh AND store-fwd.hh AND eval-fwd.hh together. Self-forward-decl caveat: don't replace the inline self-decls in store-api.hh and eval.hh. Zero C-API impact. - NixOS#125 (14-vestigial-stdlib.md): - E4+V2+F2 verified the wire-crossing scope. Daemon does NOT link libexpr; libexpr's 107 throws are local-only. Wire-crossing surface is libstore (199 throws, 71 positional %N%, 51 reachable) plus libutil (281 all-format, 50 positional, 45 reachable). V2 found 5 categories of sites E4's grep missed including the load-bearing store-api.hh::Store::requireStoreObjectAccessor. F2 found a second wire-crossing text-grep contract: "is not valid" in BasicClientConnection::queryPathInfo. Phasing constraint: text-grep contracts span both %s and %1% sites; Phase 2 cannot batch positional and non-positional separately for any contract-bearing site. - NixOS#128 (14-vestigial-stdlib.md): - Note added per CLAUDE.md: the landed cleanup/libmain-shared branch bundled this with the unrelated blockInt deletion (NixOS#49). Soft style issue; recorded for future cleanup-branch authors. - NixOS#140 (15-globals-settings.md): - E1's verification cleared the deletion path. nm -m on the built dylib confirms internal linkage; lix already deleted it; commit 50912d0 (2022-03-31) intended full removal but missed the namespace-scope definition. - N41 (24-test-infrastructure-mirrors.md): - V5 verified each fixture body. 28 declaring fixture classes (E6's "22" was an undercount). 19 fit cleanly with subdir-only ctor; 27 of 28 fit with (subdir, suffix) ctor pair. One structural hazard: CaDerivationAdvancedAttrsTest reassigns unitTestData in SetUp() and is linked to DerivationAdvancedAttrsTest via TYPED_TEST_SUITE — needs common abstract base. New candidate NixOS#218 (12-libutil-libstore-core-extras.md): - The Hash::dummy / StorePath::dummy sentinels are overloaded as both "uninitialised placeholder" and "wire-marker for missing". Independent grep identified 16 sites in three classes: placeholder-then-overwrite (6, including two FIXME-tagged sites in nar-info.cc), wire-marker (3 in worker-protocol.cc, serve-protocol.cc, legacy-ssh-store.cc), and test-fixture (3 + one legitimate constant). The right factoring is std::optional<Hash> / std::optional<StorePath> for the placeholder sites and a separately-named sentinel for the wire-marker sites. Resumption documentation: - INVENTORY.md was missing pointers to STATUS.md, AGENT-CHARTER.md, and review/00-INDEX.md. Added a paragraph after the "Consolidated duplication and refactoring candidates" section documenting all three plus the five-step read-first ordering for resumption. - INVENTORY.md updated: 217 per-shard candidates -> 218 (with NixOS#218 added during integration). - STATUS.md cleaned up: dropped the 13 stale "Integration" sub-bullets (those tasks are now in candidate bodies), collapsed the duplicate "E1 implementation" entries, fixed the vague "completed in commit ahead of HEAD~0" line, added "E3 implementation" and "E5 verifiable-counts manifest" to the queue. "Recently completed" annotated to note the post-integration count is 218 + 44. - review/00-INDEX.md updated with an integration-status note above the "How a new agent should pick a report to read" section. Self-check against AGENT-CHARTER.md eight rules: 1. Call graphs walked: V3's UAF chain through ~ProgressBar / ~InterruptCallbackImpl was already in V3's report; B1's addSetting(this) analysis already in B1's report. 2. Shipping artefacts traced: V1's install_headers finding cited in NixOS#134 and NixOS#138 bodies. 3. Counts cited their source: re-derived for the dummy pattern (16 sites) and CloneableError derivations (17); took V-counts where verified (V2's 71/281, V5's 28/19/27/1). 4. Predictions labelled: N41's V5-verified replaces E6's prediction. 5. Inherited claims re-derived: B3 said 22 hand-written CloneableError; my grep produced 17; used 17. 6. Same-shape walked individually: the dummy pattern split into 3 classes (placeholder vs wire-marker vs test) rather than C1's single shape. 7. No invented numbers: V4's downgrade applied to NixOS#213. 8. Comments verified vs code: NixOS#213's "not a singleton" comment treated as hypothesis the consumers contradict. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…KILL the lever
Kills hypothesis: "v3 over-creates trivial thunks (bare var-refs, constants)
that TW's maybeThunk avoids; avoiding them cuts arena RSS + ALLOC-CPU."
Measure-first (NIX_V3_THUNK_BODY_STATS, gated, now retired): categorized EVERY
thunk v3 creates at runtime by body shape.
firefox.drvPath: 2,880,002 thunks — alias(var) 0.5% + const 0.1% =
AVOIDABLE 0.7%; real deferred work 99.3%.
M5 .name: same RATIO (0.7% avoidable).
v3's opt passes (dce/beta/inline/const-fold, default-on) ALREADY remove trivial
alias/const thunks at compile time — only 0.7% survive to runtime. There is no
maybeThunk gap to close. The v3-vs-TW thunk-COUNT excess (~730K) is real
deferred subcomputations = <=17MB arena (24B/thunk), negligible vs the 1543MB
M5 arena. The 637MB thunk arena is REAL laziness (TW carries the same thunks at
16B); thunk SIZE is already at the 24B floor (FP-2 complete).
Re-prioritization (lode/M4_THUNK_AVOIDANCE_RCA_2026-06-23.md):
- Real arena RSS lever = the LIVE SET (ImportCache eviction, NixOS#134), NOT thunk count.
- Real thunk lever = CHURN (62-67% unforced, profile) — a CPU lever needing
strictness/eager-eval (byte-id risk), the L3-hard deferred item, NOT maybeThunk.
- Structural CPU lever stays JIT (NixOS#137).
Instrument retired (Rule 0: falsify -> delete code + gate); net vm.cc diff is
comment-only, hello.drvPath byte-identical.
Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output
Group. SPDX-License-Identifier: Apache-2.0
…e is now the NixOS#1 RSS lever NixOS#135 (thunk-count avoidance) falsified + killed (207c9b4): the arena's RSS is not reducible by thunk count. Promote NixOS#134 (ImportCache eviction = un-pin the live arena subgraphs) to the NixOS#1 RSS lever; JIT (NixOS#137) stays the structural CPU lever. Sequencing + M4 sections updated. Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
…no-release wall Kills hypothesis (M1's mis-promotion): "ImportCache eviction un-pins arena Value subgraphs → the NixOS#1 RSS lever." The lever was ALREADY falsified 2026-05-30 (4728718: HNE +0.0 MB at safe thresholds, +177 MB regression aggressive). Measure-twice re-confirmed it on the CURRENT binary (nursery/gen-major/mid-eval all active), firefox cache-off: MAX_ENTRIES=0 (no evict) 675 MB ; =256 727 MB (+52) ; =64 890 MB (+215). Eviction makes RSS monotonically WORSE. Root cause: the v3 arena never releases pages to the OS. Eviction drops the cache reference but the cells' pages stay mapped, and re-import allocates FRESH cells → arena grows past the prior peak. This is the SAME pin that killed mid-eval reuse as an RSS lever this session (reclaims 36% of the bump for reuse, peak unchanged — no munmap). Two reclaim levers, one root cause. Reframe: reclaim-based RSS levers are DEAD. Only paths = allocate fewer cells (FP-2/FP-3 mostly closed; churn L3-hard) + arena page-release (M3, hard, low ceiling: even perfect reclaim leaves firefox 1.34x TW, M5 live arena alone ~= TW's whole RSS). Surfaced a NEW un-explored lever: MALLOC_SMALL CU-shrink (NixOS#139, 690 MB NixOS#2 bucket — libc malloc, NOT arena-pinned). Beating TW on RSS is a broad foundational program, not a single lever. NIX_V3_IMPORT_CACHE_MAX_ENTRIES stays opt-in infra (carcass rule; only activates paired with M3). lode/M2_IMPORTCACHE_FALSIFIED_2026-06-23.md. Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
…ement Kills hypothesis: "mid-eval arena reclaim can be made visible to the OS (mmap blocks + whole-block-free / evacuation), lowering peak RSS." Measure-first via the per-block density histogram + evac-opportunity report (NIX_VM_STATS R2.1), driven by this session's mid-eval sweep on firefox.drvPath. Both page-return mechanisms measured ~0: - whole-block-free: blocksFreed=0 on EVERY sweep (reclaim% 18->56% but not one 16MB block goes fully dead — live cells scattered across every block). - evacuation (Immix): sparseBlocks=0 at all mid-eval trigger points (blocks cluster 25-75% live, ZERO <25%); evacuable_RSS~=0. Only teardown (C-stack unwound) shows 1 sparse block (16.8MB). Plus 12-27% cells C-stack-pinned (unmovable) during mid-eval. So mid-eval reclaim CANNOT become peak-RSS reduction (confirms MIDEVAL_REUSE_RCA with the root mechanism). Even the paused multi-week Immix evacuation project (GC_DECISION/GC_PAUSE 2026-05-29) would free ~0 RSS at these density profiles. Completes the RSS-lever sweep: NixOS#135 thunk-avoidance KILL, NixOS#134 eviction KILL, NixOS#136 page-release KILL, NixOS#139 MALLOC_SMALL modest/foundational. ALL reclaim-based RSS levers dead; only path = allocate fewer/smaller cells (FP-2/3 mostly closed, churn L3-hard) + structural (MALLOC_SMALL foundational, Boehm FFI). Beating TW on RSS = shrink the LIVE representation = broad foundational program, no single lever. NixOS#138 (GC mark cost) was gated on M3 shipping a default sweep -> moot, closed. lode/M3_ARENA_PAGE_RELEASE_KILL_2026-06-23.md. Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
…n gap measured Answers: "what is the REAL production gap" (the cache-off 3x includes v3's one-time parse+lower, amortized in production). darwin-4, median-of-N, HEAD binary, tight spreads. firefox cold 3.64x CPU/1.89x RSS -> WARM 2.49x CPU/1.64x RSS M5 cold 3.06x CPU/3.04x RSS -> WARM 1.83x CPU/2.26x RSS Findings: - parse+lower is 32% (firefox) / 40% (M5) of v3's cold CPU -> production CPU gap is 1.83-2.49x, NOT 3x. Cache-off OVERSTATES the gap. - warm also cuts RSS hugely (firefox -91MB, M5 -765MB/-26%): cold builds+retains IR/parse structures (MALLOC_SMALL churn + fragmentation); warm loads bytecode from SQLite without those transients. So much of the cold RSS (and the NixOS#139 ~360MB "fragmentation") is parse/lower TRANSIENT, not steady-state. - TW warm-insensitive (no persistent cache, eval-dominated CPU) -> stable anchor. Production gap to close: CPU 1.83-2.49x = structural per-op dispatch -> JIT (NixOS#137); RSS 1.64-2.26x = live representation > TW's 16B niche Value -> broad foundational (all reclaim levers killed NixOS#134/NixOS#136). Confirms prior-session warm reframe on fresh darwin-4 data. P0.2 COMPLETE. lode/P02_WARM_HEADTOHEAD_2026-06-23.md. Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
Kills hypothesis: "the 402MB Boehm is v3->TW bridge Values from FFI primop wrappers, reducible by moving heavy crossings native." Measure-first (firefox.drvPath): - bridge=0 (NIX_VM_STATS): zero TW thunk-routing. Not bridge. - GC_get_heap_size = constant ~402.9MB (appears even for 1+1, RSS 31MB) = Boehm's upfront mapped reservation, NOT a workload metric. Methodology trap; M1's vmmap 402MB-resident on M5 is the real number. - GC_get_total_bytes (cumulative): 1+1=0, firefox=452MB -> v3 churns ~431MB TW. - Per-primop self-attribution (NIX_V3_BOEHM_ATTR, gated, now retired): store- boundary leaves allocate ~0 (readFile 0.0MB, pathExists 0.0MB); churn attributed to higher-order list primops (concatMap 228, all 96, ...) -- but those are v3-NATIVE (primConcatMap=allocList=arena), so that's an INCLUSIVE artifact (the main OP_CALL_PRIMOP path bypasses the child-accounting -> native higher-order primops absorb their callback subtree's Boehm). Robust findings: NOT store/FFI boundaries (those are ~0), NOT bridge (=0); it's ~431MB transient TW churn under the package-set subtree, held resident by macOS no-unmap (same wall as NixOS#134/NixOS#136). Change-5 premise ("move store primops native") FALSIFIED -- store leaves don't allocate it. NixOS#156/NixOS#157 re-scoped; the precise leaf needs a complete-attribution instrument (hook the main OP_CALL_PRIMOP path) = follow-up. Pattern holds: Changes 1/3/5 all modest/blocked; real levers = Change 2 (HAMT) + Change 4 (JIT). Instrument retired per Rule 0 (per-primop numbers carry the inclusive artifact). hello.drvPath byte-id; vm.cc reverted to baseline. lode/C5_BOEHM_RCA_2026-06-23.md. Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
…2x RSS regression Rule 0 — hypothesis killed: "a persistent HAMT Bindings is an RSS+CPU win over the flat/Chain representation (O(changed) // sharing + O(1) countDistinct)." The HAMT is fully implemented + byte-identical (hello/git/firefox.drvPath; 20-pkg gate-on-vs-default sweep 20/20; gate-on --brute 21/22) yet measures a STRUCTURAL 4.7-9.2x RSS regression + 1.3x CPU regression on darwin-4 (cache-off, median-of-5): firefox default 2.69s/673MB vs HAMT 3.54s/6178MB (1.32x CPU, 9.18x RSS) git default 1.44s/410MB vs HAMT 1.88s/1916MB (1.31x CPU, 4.67x RSS) CONTROLLED EXPERIMENT (this commit): the materialize() shortcut was the prime suspect (every consumer allocated+memoized a full Sorted copy of a Kind::Hamt). OP_ATTRS_SELECT (highest-frequency consumer) was rewritten HAMT-native — direct hamtLookupSlot, no copy, no writeback into the shared node (safe chain parent-hit semantics; memo still lives in the App/Thunk cell). Removing the dominant consumer-side allocation left RSS ESSENTIALLY UNCHANGED (9.28x->9.18x firefox, 4.80x->4.67x git). Effect persists after removing the suspected cause => the cause is elsewhere: the HamtNode allocation itself. ROOT CAUSE: persistent // path-copies O(|b|.log n) TENURED interior nodes per merge; the arena NEVER releases pages (proven this session: NixOS#134/NixOS#136/mid-eval all KILLed on the same pin). nixpkgs does an enormous number of //; every node ever allocated stays resident -> monotonic 6GB accumulation. The incumbent ChainBindings already shares // via ONE O(|b|) overlay + parent pointer (zero interior-node copies) and already memoizes countDistinct (O(1)). HAMT allocates strictly more and cannot win. LESSON: a path-copying persistent structure is the wrong tool under a never-freeing arena — its churn accumulates with no reclamation. Chain was already the memory- optimal // representation for this allocator. "More principled" != "less memory" when the allocator can't reclaim the principle's churn (the FP-2/3 allocated-churn- !=-live trap, one level up). Gate NIX_V3_HAMT_BINDINGS stays default-OFF. gate-off --brute 22/22 ALL GREEN. Disposition (delete vs keep falsified reference) deferred to user — large, correct, validated subsystem; the moving-GC integration (GK_HAMT mirror of GK_ENV) is a reusable shared-tenured-cell reference. Full RCA: lode/C2_HAMT_FALSIFIED_2026-06-24.md Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
This adds new syntax for attribute names:
attrs.${name}=>getAttr name attrsattrs ? ${name}=>isAttrs attrs && hasAttr attrs nameattrs.${name} or def=>if attrs ? ${name} then attrs.${name} else def{ ${name} = value; }=>listToAttrs [{ inherit name value; }]Of course, it's a bit more complicated than that. The attribute chains
can be arbitrarily long and contain combinations of static and dynamic
parts (e.g.
attrs.${foo}.bar.${baz} or qux), which is relativelystraightforward for the getAttrs/hasAttrs cases but is more complex for
the listToAttrs case due to rules about duplicate attribute definitions.
For attribute sets with dynamic attribute names, duplicate static
attributes are detected at parse time while duplicate dynamic attributes
are detected when the attribute set is forced. So, for example,
{ a = {}; a.b = null; ${"c"} = true; }will be a parse-time error, while{ a = {}; ${"a"}.b = null; c = true; }will be an eval-time error(technically that case could theoretically be detected at parse time,
but the general case would require full evaluation). The rules for
duplicate attributes are the same in both cases, though: if some
sub-chain of an attribute path already has a value, that's an error (for
example,
{ a.b = true; a.b.c = false; }would cause an error whenparsing the
a.b.csincea.b, a sub-chain, has a value.{ a.b.d = true; a.b.c = false; }, on the other hand, is fine as neither is asubchain of the other.
Finally, recursive attribute sets with dynamic attributes have the
static attributes in scope but not the dynamic ones. So
rec { a = true; ${"b"} = a; }is equivalent to{ a = true; b = true; }butrec { ${"a"} = true; b = a; }would be an error or useafrom thesurrounding scope if it exists.
This solution includes shlevy/nix@9681699, which fixes an inconsistency in nix's parsing but causes some existing cases to break. Without that commit,
{ a = {}; a.b = null; }is equivalent to{ a = { b = null; }; }, but{ a.b = null; a = {}; }andlet attrs = {}; in { a = attrs; a.b = null; }are parse errors. I explain in that commit message why I think the first behavior is wrong and what the cost of the change is.This is an alternative solution to #132