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

View File

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

View File

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