1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-19 16:59:35 +01:00

Set the cache when opening a flake

This commit is contained in:
regnat 2021-06-03 06:59:19 +02:00
parent 6396416dfa
commit 8d95e1f299
3 changed files with 27 additions and 3 deletions

View file

@ -1173,10 +1173,11 @@ bool EvalState::getAttrField(Value & attrs, const std::vector<Symbol> & selector
auto [ cacheResult, resultingCursor ] = eval_cache.getValue(*this, selector, dest);
switch (cacheResult.returnCode) {
case ValueCache::CacheHit:
if (cacheResult.lastQueriedSymbolIfMissing)
return false;
return true;
case ValueCache::CacheMiss:
return false;
case ValueCache::Forward: // Fixme: Handle properly
case ValueCache::CacheMiss: // FIXME: Handle properly
case ValueCache::Forward: // FIXME: Handle properly
case ValueCache::NoCacheKey:
case ValueCache::UnCacheable:
;
@ -2162,6 +2163,21 @@ Strings EvalSettings::getDefaultNixPath()
return res;
}
std::shared_ptr<tree_cache::Cache> EvalState::openTreeCache(Hash cacheKey)
{
if (auto iter = evalCache.find(cacheKey); iter != evalCache.end())
return iter->second;
if (!(evalSettings.useEvalCache && evalSettings.pureEval))
return nullptr;
auto thisCache = tree_cache::Cache::tryCreate(
cacheKey,
symbols
);
evalCache.insert({cacheKey, thisCache});
return thisCache;
}
EvalSettings evalSettings;
static GlobalConfig::Register rEvalSettings(&evalSettings);

View file

@ -116,6 +116,7 @@ private:
typedef std::map<Path, Value> FileEvalCache;
#endif
FileEvalCache fileEvalCache;
std::map<Hash, std::shared_ptr<tree_cache::Cache>> evalCache;
SearchPath searchPath;
@ -132,6 +133,8 @@ public:
EvalState(const Strings & _searchPath, ref<Store> store);
~EvalState();
std::shared_ptr<tree_cache::Cache> openTreeCache(Hash);
void addToSearchPath(const string & s);
SearchPath getSearchPath() { return searchPath; }

View file

@ -620,6 +620,11 @@ void callFlake(EvalState & state,
state.callFunction(**vCallFlake, *vLocks, *vTmp1, noPos);
state.callFunction(*vTmp1, *vRootSrc, *vTmp2, noPos);
state.callFunction(*vTmp2, *vRootSubdir, vRes, noPos);
state.forceAttrs(vRes); // FIXME: Make more robust and lazy
auto fingerprint = lockedFlake.getFingerprint();
auto evalCache = state.openTreeCache(fingerprint);
auto cacheRoot = evalCache ? evalCache->getRoot() : nullptr;
vRes.attrs->eval_cache = ValueCache(cacheRoot);
}
static void prim_getFlake(EvalState & state, const Pos & pos, Value * * args, Value & v)