diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-08 09:52:15 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-10 03:18:32 -0600 |
commit | b667b4cded1b9d974157f27761d8648b372d27bf (patch) | |
tree | be37e4ecd58fee0a88664db5516b877d7683a0ab /src/libexpr/nixexpr.hh | |
parent | 71e0114708d406fdc0d9ca34d4b67cb190881439 (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/nixexpr.hh')
-rw-r--r-- | src/libexpr/nixexpr.hh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 793e1a707..cb630d201 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -129,6 +129,18 @@ struct ExprVar : Expr COMMON_METHODS }; +struct ExprInheritFrom : ExprVar +{ + ExprInheritFrom(PosIdx pos, Displacement displ): ExprVar(pos, {}) + { + this->level = 0; + this->displ = displ; + this->fromWith = nullptr; + } + + void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env); +}; + struct ExprSelect : Expr { PosIdx pos; @@ -189,6 +201,7 @@ struct ExprAttrs : Expr }; typedef std::map<Symbol, AttrDef> AttrDefs; AttrDefs attrs; + std::unique_ptr<std::vector<Expr *>> inheritFromExprs; struct DynamicAttrDef { Expr * nameExpr, * valueExpr; PosIdx pos; @@ -202,6 +215,9 @@ struct ExprAttrs : Expr PosIdx getPos() const override { return pos; } COMMON_METHODS + std::shared_ptr<const StaticEnv> bindInheritSources( + EvalState & es, const std::shared_ptr<const StaticEnv> & env); + Env * buildInheritFromEnv(EvalState & state, Env & up); void showBindings(const SymbolTable & symbols, std::ostream & str) const; }; |