mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 16:59:35 +01:00
Make getFields just return the name of the fields
Makes it much easier to deal with non-evaluating stuff
This commit is contained in:
parent
3a9753132e
commit
1f8541258c
3 changed files with 20 additions and 30 deletions
|
|
@ -1297,7 +1297,7 @@ void EvalState::getAttrFieldThrow(Value & attrs, const std::vector<Symbol> & sel
|
||||||
throw Error("Missing attribute path '%s'", "ImTooLazyToImplementThisRightNow");
|
throw Error("Missing attribute path '%s'", "ImTooLazyToImplementThisRightNow");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Attr> EvalState::getFields(Value & attrs, const Pos & pos)
|
std::vector<Symbol> EvalState::getFields(Value & attrs, const Pos & pos)
|
||||||
{
|
{
|
||||||
auto eval_cache = attrs.getEvalCache();
|
auto eval_cache = attrs.getEvalCache();
|
||||||
if (eval_cache.isEmpty()) {
|
if (eval_cache.isEmpty()) {
|
||||||
|
|
@ -1305,34 +1305,14 @@ std::vector<Attr> EvalState::getFields(Value & attrs, const Pos & pos)
|
||||||
eval_cache = attrs.getEvalCache();
|
eval_cache = attrs.getEvalCache();
|
||||||
}
|
}
|
||||||
if (auto attrNames = eval_cache.listChildren(symbols)) {
|
if (auto attrNames = eval_cache.listChildren(symbols)) {
|
||||||
bool everythingCached = true;
|
return *attrNames;
|
||||||
std::vector<Attr> res;
|
|
||||||
for (auto & attrName : *attrNames) {
|
|
||||||
auto newValue = allocValue();
|
|
||||||
try {
|
|
||||||
if (lazyGetAttrField(attrs, {attrName}, pos, *newValue) != LazyValueType::Missing) {
|
|
||||||
res.push_back(Attr(attrName, newValue));
|
|
||||||
} else {
|
|
||||||
everythingCached = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (EvalError & e) {
|
|
||||||
// XXX: Ugly hack to hide the error
|
|
||||||
newValue->mkThunk(
|
|
||||||
&baseEnv,
|
|
||||||
new ExprApp(
|
|
||||||
parseExprFromString("throw", "/"),
|
|
||||||
new ExprString(symbols.create(e.what()))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (everythingCached) return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
forceValue(attrs);
|
forceValue(attrs);
|
||||||
auto attrsStart = attrs.attrs->attrs;
|
std::vector<Symbol> res;
|
||||||
return std::vector<Attr>(attrsStart, attrsStart + attrs.attrs->size());
|
for (auto & attr : *attrs.attrs)
|
||||||
|
res.push_back(attr.name);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ public:
|
||||||
// found
|
// found
|
||||||
void getAttrFieldThrow(Value & attrs, const std::vector<Symbol> & selector, const Pos & pos, Value & dest);
|
void getAttrFieldThrow(Value & attrs, const std::vector<Symbol> & selector, const Pos & pos, Value & dest);
|
||||||
|
|
||||||
std::vector<Attr> getFields(Value & attrs, const Pos & pos);
|
std::vector<Symbol> getFields(Value & attrs, const Pos & pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,20 @@ struct CmdSearch : InstallableCommand, MixJSON
|
||||||
fmt("evaluating '%s'", concatStringsSep(".", attrPath)));
|
fmt("evaluating '%s'", concatStringsSep(".", attrPath)));
|
||||||
auto recurse = [&]()
|
auto recurse = [&]()
|
||||||
{
|
{
|
||||||
for (auto & attr : state->getFields(current, noPos)) {
|
for (auto & attrName : state->getFields(current, noPos)) {
|
||||||
|
try {
|
||||||
auto attrPath2(attrPath);
|
auto attrPath2(attrPath);
|
||||||
attrPath2.push_back(attr.name);
|
attrPath2.push_back(attrName);
|
||||||
visit2(*attr.value, attrPath2, false);
|
auto attrValue = state->allocValue();
|
||||||
|
auto value_ = allocRootValue(attrValue);
|
||||||
|
state->lazyGetAttrField(current, {attrName}, noPos,
|
||||||
|
*attrValue);
|
||||||
|
visit2(*attrValue, attrPath2, false);
|
||||||
|
} catch (EvalError &e) {
|
||||||
|
if (!(attrPath.size() > 0 &&
|
||||||
|
attrPath[0] == "legacyPackages"))
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue