mirror of
https://github.com/NixOS/nix
synced 2025-06-26 11:41:15 +02:00
* Allow a default value in attribute selection by writing
x.y.z or default (as originally proposed in https://mail.cs.uu.nl/pipermail/nix-dev/2009-September/002989.html). For instance, an expression like stdenv.lib.attrByPath ["features" "ckSched"] false args can now be written as args.features.ckSched or false
This commit is contained in:
parent
2b9e29b1c8
commit
0a623a10c7
9 changed files with 70 additions and 22 deletions
|
@ -632,7 +632,6 @@ void ExprVar::eval(EvalState & state, Env & env, Value & v)
|
|||
|
||||
|
||||
unsigned long nrLookups = 0;
|
||||
unsigned long nrLookupSize = 0;
|
||||
|
||||
void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||
{
|
||||
|
@ -646,11 +645,20 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
|||
|
||||
foreach (AttrPath::const_iterator, i, attrPath) {
|
||||
nrLookups++;
|
||||
state.forceAttrs(*vAttrs);
|
||||
nrLookupSize += vAttrs->attrs->size();
|
||||
Bindings::iterator j;
|
||||
if ((j = vAttrs->attrs->find(*i)) == vAttrs->attrs->end())
|
||||
throwEvalError("attribute `%1%' missing", showAttrPath(attrPath));
|
||||
if (def) {
|
||||
state.forceValue(*vAttrs);
|
||||
if (vAttrs->type != tAttrs ||
|
||||
(j = vAttrs->attrs->find(*i)) == vAttrs->attrs->end())
|
||||
{
|
||||
state.eval(env, def, v);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
state.forceAttrs(*vAttrs);
|
||||
if ((j = vAttrs->attrs->find(*i)) == vAttrs->attrs->end())
|
||||
throwEvalError("attribute `%1%' missing", showAttrPath(attrPath));
|
||||
}
|
||||
vAttrs = j->value;
|
||||
pos = j->pos;
|
||||
}
|
||||
|
@ -1270,7 +1278,6 @@ void EvalState::printStats()
|
|||
printMsg(v, format(" number of thunks: %1%") % nrThunks);
|
||||
printMsg(v, format(" number of thunks avoided: %1%") % nrAvoided);
|
||||
printMsg(v, format(" number of attr lookups: %1%") % nrLookups);
|
||||
printMsg(v, format(" attr lookup size: %1%") % nrLookupSize);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue