Make nix search lazier

Only 4 evals left \o/
This commit is contained in:
regnat 2021-06-10 09:11:47 +02:00
parent 71650c83c6
commit ea792bcdc8
3 changed files with 21 additions and 12 deletions

View File

@ -1198,12 +1198,8 @@ EvalState::LazyValueType EvalState::lazyGetAttrField(Value & attrs, const std::v
}
auto [ cacheResult, resultingCursor ] = eval_cache.getValue(*this, selector, dest);
updateCacheStats(cacheResult);
switch (cacheResult.returnCode) {
case ValueCache::CacheHit:
if (cacheResult.lastQueriedSymbolIfMissing)
return LazyValueType::Missing;
return LazyValueType::PlainValue;
case ValueCache::Forward: {
auto delayValue = [&](ValueCache & cursor) {
auto recordAsVar = new ExprCastedVar(&attrs);
auto accessExpr = new ExprSelect(pos, recordAsVar, selector);
auto thunk = (Thunk*)allocBytes(sizeof(Thunk));
@ -1212,10 +1208,21 @@ EvalState::LazyValueType EvalState::lazyGetAttrField(Value & attrs, const std::v
dest.mkCachedThunk(
thunk,
new ValueCache(resultingCursor)
new ValueCache(cursor)
);
return LazyValueType::DelayedAttrSet;
}
};
switch (cacheResult.returnCode) {
case ValueCache::CacheHit:
if (cacheResult.lastQueriedSymbolIfMissing)
return LazyValueType::Missing;
return LazyValueType::PlainValue;
case ValueCache::UnCacheable:
delayValue(resultingCursor);
return LazyValueType::DelayedUncacheable;
case ValueCache::Forward:
delayValue(resultingCursor);
return LazyValueType::DelayedAttr;
default:
if(getAttrField(attrs, selector, pos, dest))
return LazyValueType::PlainValue;

View File

@ -359,7 +359,8 @@ public:
enum struct LazyValueType {
PlainValue,
DelayedAttrSet,
DelayedUncacheable,
DelayedAttr,
Missing,
};

View File

@ -98,9 +98,10 @@ struct CmdSearch : InstallableCommand, MixJSON
attrPath2.push_back(attrName);
auto attrValue = state->allocValue();
auto value_ = allocRootValue(attrValue);
state->lazyGetAttrField(current, {attrName}, noPos,
auto childField = state->lazyGetAttrField(current, {attrName}, noPos,
*attrValue);
visit(*attrValue, attrPath2, false);
if (childField != EvalState::LazyValueType::DelayedUncacheable)
visit(*attrValue, attrPath2, false);
} catch (EvalError &e) {
if (!(attrPath.size() > 0 &&
attrPath[0] == "legacyPackages"))