1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 19:03:16 +02:00

Make the file cache keyed on SourcePath

This commit is contained in:
Eelco Dolstra 2022-05-12 16:48:22 +02:00
parent bc57bd2202
commit cd893a22f5
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
7 changed files with 28 additions and 47 deletions

View file

@ -1010,17 +1010,14 @@ Value * ExprPath::maybeThunk(EvalState & state, Env & env)
void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
{
// FIXME: use SourcePath as cache key
auto pathKey = path.to_string();
FileEvalCache::iterator i;
if ((i = fileEvalCache.find(pathKey)) != fileEvalCache.end()) {
if ((i = fileEvalCache.find(path)) != fileEvalCache.end()) {
v = i->second;
return;
}
auto resolvedPath = resolveExprPath(path);
auto resolvedPathKey = resolvedPath.to_string();
if ((i = fileEvalCache.find(resolvedPathKey)) != fileEvalCache.end()) {
if ((i = fileEvalCache.find(resolvedPath)) != fileEvalCache.end()) {
v = i->second;
return;
}
@ -1028,7 +1025,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
printTalkative("evaluating file '%1%'", resolvedPath);
Expr * e = nullptr;
auto j = fileParseCache.find(resolvedPathKey);
auto j = fileParseCache.find(resolvedPath);
if (j != fileParseCache.end())
e = j->second;
@ -1038,24 +1035,6 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
e = parseExprFromFile(checkSourcePath(resolvedPath));
#endif
cacheFile(pathKey, resolvedPathKey, e, v, mustBeTrivial);
}
void EvalState::resetFileCache()
{
fileEvalCache.clear();
fileParseCache.clear();
}
void EvalState::cacheFile(
const Path & path,
const Path & resolvedPath,
Expr * e,
Value & v,
bool mustBeTrivial)
{
fileParseCache[resolvedPath] = e;
try {
@ -1066,7 +1045,7 @@ void EvalState::cacheFile(
throw EvalError("file '%s' must be an attribute set", path);
eval(e, v);
} catch (Error & e) {
addErrorTrace(e, "while evaluating the file '%1%':", resolvedPath);
addErrorTrace(e, "while evaluating the file '%1%':", resolvedPath.to_string());
throw;
}
@ -1075,6 +1054,13 @@ void EvalState::cacheFile(
}
void EvalState::resetFileCache()
{
fileEvalCache.clear();
fileParseCache.clear();
}
void EvalState::eval(Expr * e, Value & v)
{
e->eval(*this, baseEnv, v);