aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/parser.y
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-08 09:52:15 +0100
committereldritch horrors <pennae@lix.systems>2024-03-10 03:18:32 -0600
commitb667b4cded1b9d974157f27761d8648b372d27bf (patch)
treebe37e4ecd58fee0a88664db5516b877d7683a0ab /src/libexpr/parser.y
parent71e0114708d406fdc0d9ca34d4b67cb190881439 (diff)
evaluate inherit (from) exprs only once per directive
desugaring inherit-from to syntactic duplication of the source expr also duplicates side effects of the source expr (such as trace calls) and expensive computations (such as derivationStrict). (cherry picked from commit cefd0302b55b3360dbca59cfcb4bf6a750d6cdcf) Change-Id: Iff519f991adef2e51683ba2c552d37a3df7a179e
Diffstat (limited to 'src/libexpr/parser.y')
-rw-r--r--src/libexpr/parser.y7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index ae5723a6f..ee44a6d7a 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -319,14 +319,17 @@ binds
}
| binds INHERIT '(' expr ')' attrs ';'
{ $$ = $1;
- /* !!! Should ensure sharing of the expression in $4. */
+ if (!$$->inheritFromExprs)
+ $$->inheritFromExprs = std::make_unique<std::vector<Expr *>>();
+ $$->inheritFromExprs->push_back($4);
+ auto from = new nix::ExprInheritFrom(state->at(@4), $$->inheritFromExprs->size() - 1);
for (auto & i : *$6) {
if ($$->attrs.find(i.symbol) != $$->attrs.end())
state->dupAttr(i.symbol, state->at(@6), $$->attrs[i.symbol].pos);
$$->attrs.emplace(
i.symbol,
ExprAttrs::AttrDef(
- new ExprSelect(CUR_POS, $4, i.symbol),
+ new ExprSelect(CUR_POS, from, i.symbol),
state->at(@6),
ExprAttrs::AttrDef::Kind::InheritedFrom));
}