getAttr
lib.attrsets.getAttr
Primop
Docs pulled from | This Revision | 18 days ago
Nix manual
Takes 2 arguments
s, set
getAttr returns the attribute named s from set. Evaluation
aborts if the attribute doesn’t exist. This is a dynamic version of
the . operator, since s is an expression rather than an
identifier.
Has O(log n) time complexity, where n is number of attributes in the set.
Noogle detected
Detected Type
getAttr :: String -> AttrSet -> a
Implementation
This function is implemented in c++ and is part of the native nix runtime.
void prim_getAttr(EvalState & state, CallSite callSite, Value * const * args, Value & v)
{
auto attr =
state.forceStringNoCtx(*args[0], noPos, "while evaluating the first argument passed to builtins.getAttr");
state.forceAttrs(*args[1], noPos, "while evaluating the second argument passed to builtins.getAttr");
auto i = state.getAttr(state.symbols.create(attr), args[1]->attrs(), "in the attribute set under consideration");
// !!! add to stack trace?
if (state.countCalls && i->pos)
state.attrSelects->try_emplace_or_visit(i->pos, 1, [](auto & j) { j.second++; });
state.forceValue(*i->value, noPos);
v = *i->value;
}
Implementation
The following is the current implementation of this function.
getAttr