1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-30 06:01:00 +01: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);

View file

@ -116,17 +116,17 @@ private:
/* A cache from path names to parse trees. */
#if HAVE_BOEHMGC
typedef std::map<Path, Expr *, std::less<Path>, traceable_allocator<std::pair<const Path, Expr *> > > FileParseCache;
typedef std::map<SourcePath, Expr *, std::less<SourcePath>, traceable_allocator<std::pair<const SourcePath, Expr *>>> FileParseCache;
#else
typedef std::map<Path, Expr *> FileParseCache;
typedef std::map<SourcePath, Expr *> FileParseCache;
#endif
FileParseCache fileParseCache;
/* A cache from path names to values. */
#if HAVE_BOEHMGC
typedef std::map<Path, Value, std::less<Path>, traceable_allocator<std::pair<const Path, Value> > > FileEvalCache;
typedef std::map<SourcePath, Value, std::less<SourcePath>, traceable_allocator<std::pair<const SourcePath, Value> >> FileEvalCache;
#else
typedef std::map<Path, Value> FileEvalCache;
typedef std::map<SourcePath, Value> FileEvalCache;
#endif
FileEvalCache fileEvalCache;
@ -200,14 +200,6 @@ public:
trivial (i.e. doesn't require arbitrary computation). */
void evalFile(const SourcePath & path, Value & v, bool mustBeTrivial = false);
/* Like `cacheFile`, but with an already parsed expression. */
void cacheFile(
const Path & path,
const Path & resolvedPath,
Expr * e,
Value & v,
bool mustBeTrivial = false);
void resetFileCache();
/* Look up a file in the search path. */