1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 15:51:15 +02:00

* Evaluate lets directly (i.e. without desugaring to `rec { attrs...;

<let-body> = e; }.<let-body>).  This prevents the unnecessary
  allocation of an attribute set.
This commit is contained in:
Eelco Dolstra 2010-04-13 13:42:25 +00:00
parent ac1e8f40d4
commit 7d47498b5e
5 changed files with 45 additions and 1 deletions

View file

@ -456,6 +456,31 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
}
void ExprLet::eval(EvalState & state, Env & env, Value & v)
{
/* Create a new environment that contains the attributes in this
`let'. */
Env & env2(state.allocEnv());
env2.up = &env;
/* The recursive attributes are evaluated in the new
environment. */
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs) {
Value & v2 = env2.bindings[i->first];
mkThunk(v2, env2, i->second);
}
/* The inherited attributes, on the other hand, are evaluated in
the original environment. */
foreach (list<Symbol>::iterator, i, attrs->inherited) {
Value & v2 = env2.bindings[*i];
mkCopy(v2, *state.lookupVar(&env, *i));
}
state.eval(env2, body, v);
}
void ExprList::eval(EvalState & state, Env & env, Value & v)
{
state.mkList(v, elems.size());