Repository navigation
Dynamic attrs - #132
Dynamic attrs#132shlevy wants to merge 76 commits into
Conversation
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
The AttrName class doesn't exist yet, I'm trying a tdd-style approach Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
…own type Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
I misunderstood the function, it's not useless This reverts commit bf682a4. Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
… case Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
std::map<k,v>::iterator is of type pair<const k, v>, so calling eval has no effect unless we make a local copy. Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
…ness Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
…their exprs Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
…attributes Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
…ent attribute Signed-off-by: Shea Levy <[email protected]>
I have no idea how to naturally trigger this code path to test. Signed-off-by: Shea Levy <[email protected]>
Signed-off-by: Shea Levy <[email protected]>
|
Wouldn't it be easier to implement this by desugaring to hasAttr/getAttr calls? E.g. |
|
This is actually the first time I've really touched a parser and don't know what's involved in implementing sugar. Wouldn't there be issues with the fact that multiple selects are joined into an |
|
Desugaring is a matter of returning an AST that corresponds to the desugared expression. For instance, Set construction can be desugared to something like |
|
Ah OK, that seems reasonable enough (though IMO the |
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]>
|
Closing in favor of #134 |
Update language.rst
…are.sh WARM=1 drops NIX_V3_NO_DISK_CACHE (disk bytecode cache ON) + adds one discarded warmup run to populate it — measures the PRODUCTION steady state where parse+lower is amortized (the cache-off gap overstates the real gap). Cold path unchanged (preserves the committed cache-off baseline). For darwin-4. 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
Production gap (warm, darwin-4): firefox 2.49x CPU/1.64x RSS, M5 1.83x CPU/2.26x RSS — cache-off overstates it (parse+lower 32-40% of cold CPU, amortized). Copyright (c) 2026 Moritz Angermann <[email protected]>, Input Output Group. SPDX-License-Identifier: Apache-2.0
This series adds a new syntax for attribute names:
attrs.${name}is equivalent tobuiltins.getAttr name attrsattrs ? ${name}is equivalentbuiltins.hasAttr name attrsattrs.${name} or defis equivalent toif builtins.isAttrs attrs && builtins.hasAttr name attrs then builtins.getAttr name attrs else def{ ${name1} = value1; ${name2} = value2; }is equivalent tobuiltins.listToAttrs [ { name = name1; value = value1; } { name = name2; value = value2; } ]This eliminates the need for the bulky
getAttr,hasAttr, andlistToAttrsbuiltins with a much more nixy syntax.Sorry for the massive number of commits, I was testing out a new development style (which actually worked fairly well)