diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 5629865f0..93916d465 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -193,27 +193,6 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env) static constexpr size_t BASE_ENV_SIZE = 128; -struct EvalState::SrcToStore -{ - boost::concurrent_flat_map inner; -}; - -struct EvalState::ImportResolutionCache -{ - boost::concurrent_flat_map inner; -}; - -struct EvalState::FileEvalCache -{ - boost::concurrent_flat_map< - SourcePath, - Value *, - std::hash, - std::equal_to, - traceable_allocator>> - inner; -}; - EvalState::EvalState( const LookupPath & lookupPathFromArguments, ref store, @@ -286,9 +265,9 @@ EvalState::EvalState( , debugRepl(nullptr) , debugStop(false) , trylevel(0) - , srcToStore(make_ref()) - , importResolutionCache(make_ref()) - , fileEvalCache(make_ref()) + , srcToStore(make_ref()) + , importResolutionCache(make_ref()) + , fileEvalCache(make_ref()) , regexCache(makeRegexCache()) #if NIX_USE_BOEHMGC , valueAllocCache(std::allocate_shared(traceable_allocator(), nullptr)) @@ -1100,14 +1079,14 @@ struct ExprParseFile : Expr void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) { - auto resolvedPath = getConcurrent(importResolutionCache->inner, path); + auto resolvedPath = getConcurrent(*importResolutionCache, path); if (!resolvedPath) { resolvedPath = resolveExprPath(path); - importResolutionCache->inner.emplace(path, *resolvedPath); + importResolutionCache->emplace(path, *resolvedPath); } - if (auto v2 = getConcurrent(fileEvalCache->inner, *resolvedPath)) { + if (auto v2 = getConcurrent(*fileEvalCache, *resolvedPath)) { forceValue(**v2, noPos); v = **v2; return; @@ -1116,7 +1095,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) Value * vExpr; ExprParseFile expr{*resolvedPath, mustBeTrivial}; - fileEvalCache->inner.try_emplace_and_cvisit( + fileEvalCache->try_emplace_and_cvisit( *resolvedPath, nullptr, [&](auto & i) { @@ -1133,8 +1112,8 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) void EvalState::resetFileCache() { - fileEvalCache->inner.clear(); - fileEvalCache->inner.rehash(0); + importResolutionCache->clear(); + fileEvalCache->clear(); inputCache->clear(); } @@ -2419,7 +2398,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat if (nix::isDerivation(path.path.abs())) error("file names are not allowed to end in '%1%'", drvExtension).debugThrow(); - auto dstPathCached = getConcurrent(srcToStore->inner, path); + auto dstPathCached = getConcurrent(*srcToStore, path); auto dstPath = dstPathCached ? *dstPathCached : [&]() { auto dstPath = fetchToStore( @@ -2432,7 +2411,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat nullptr, repair); allowPath(dstPath); - srcToStore->inner.try_emplace(path, dstPath); + srcToStore->try_emplace(path, dstPath); printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath)); return dstPath; }(); diff --git a/src/libexpr/include/nix/expr/eval.hh b/src/libexpr/include/nix/expr/eval.hh index 57f0f3f9d..a5e3a2bc7 100644 --- a/src/libexpr/include/nix/expr/eval.hh +++ b/src/libexpr/include/nix/expr/eval.hh @@ -21,6 +21,8 @@ #include "nix/expr/config.hh" #include +#include + #include #include #include @@ -411,21 +413,24 @@ private: /* Cache for calls to addToStore(); maps source paths to the store paths. */ - struct SrcToStore; - ref srcToStore; + ref> srcToStore; /** * A cache that maps paths to "resolved" paths for importing Nix * expressions, i.e. `/foo` to `/foo/default.nix`. */ - struct ImportResolutionCache; - ref importResolutionCache; + ref> importResolutionCache; /** * A cache from resolved paths to values. */ - struct FileEvalCache; - ref fileEvalCache; + ref, + std::equal_to, + traceable_allocator>>> + fileEvalCache; /** * Associate source positions of certain AST nodes with their preceding doc comment, if they have one.