1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 06:52:43 +01:00

Use concurrent_flat_map_fwd.hpp

This commit is contained in:
Eelco Dolstra 2025-09-12 17:49:15 +02:00
parent 4b63ff63a4
commit 8d8f49cb5a
2 changed files with 22 additions and 38 deletions

View file

@ -193,27 +193,6 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
static constexpr size_t BASE_ENV_SIZE = 128; static constexpr size_t BASE_ENV_SIZE = 128;
struct EvalState::SrcToStore
{
boost::concurrent_flat_map<SourcePath, StorePath> inner;
};
struct EvalState::ImportResolutionCache
{
boost::concurrent_flat_map<SourcePath, SourcePath> inner;
};
struct EvalState::FileEvalCache
{
boost::concurrent_flat_map<
SourcePath,
Value *,
std::hash<SourcePath>,
std::equal_to<SourcePath>,
traceable_allocator<std::pair<const SourcePath, Value *>>>
inner;
};
EvalState::EvalState( EvalState::EvalState(
const LookupPath & lookupPathFromArguments, const LookupPath & lookupPathFromArguments,
ref<Store> store, ref<Store> store,
@ -286,9 +265,9 @@ EvalState::EvalState(
, debugRepl(nullptr) , debugRepl(nullptr)
, debugStop(false) , debugStop(false)
, trylevel(0) , trylevel(0)
, srcToStore(make_ref<SrcToStore>()) , srcToStore(make_ref<decltype(srcToStore)::element_type>())
, importResolutionCache(make_ref<ImportResolutionCache>()) , importResolutionCache(make_ref<decltype(importResolutionCache)::element_type>())
, fileEvalCache(make_ref<FileEvalCache>()) , fileEvalCache(make_ref<decltype(fileEvalCache)::element_type>())
, regexCache(makeRegexCache()) , regexCache(makeRegexCache())
#if NIX_USE_BOEHMGC #if NIX_USE_BOEHMGC
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr)) , valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
@ -1100,14 +1079,14 @@ struct ExprParseFile : Expr
void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
{ {
auto resolvedPath = getConcurrent(importResolutionCache->inner, path); auto resolvedPath = getConcurrent(*importResolutionCache, path);
if (!resolvedPath) { if (!resolvedPath) {
resolvedPath = resolveExprPath(path); 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); forceValue(**v2, noPos);
v = **v2; v = **v2;
return; return;
@ -1116,7 +1095,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
Value * vExpr; Value * vExpr;
ExprParseFile expr{*resolvedPath, mustBeTrivial}; ExprParseFile expr{*resolvedPath, mustBeTrivial};
fileEvalCache->inner.try_emplace_and_cvisit( fileEvalCache->try_emplace_and_cvisit(
*resolvedPath, *resolvedPath,
nullptr, nullptr,
[&](auto & i) { [&](auto & i) {
@ -1133,8 +1112,8 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
void EvalState::resetFileCache() void EvalState::resetFileCache()
{ {
fileEvalCache->inner.clear(); importResolutionCache->clear();
fileEvalCache->inner.rehash(0); fileEvalCache->clear();
inputCache->clear(); inputCache->clear();
} }
@ -2419,7 +2398,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
if (nix::isDerivation(path.path.abs())) if (nix::isDerivation(path.path.abs()))
error<EvalError>("file names are not allowed to end in '%1%'", drvExtension).debugThrow(); error<EvalError>("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 = dstPathCached ? *dstPathCached : [&]() {
auto dstPath = fetchToStore( auto dstPath = fetchToStore(
@ -2432,7 +2411,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
nullptr, nullptr,
repair); repair);
allowPath(dstPath); allowPath(dstPath);
srcToStore->inner.try_emplace(path, dstPath); srcToStore->try_emplace(path, dstPath);
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath)); printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath));
return dstPath; return dstPath;
}(); }();

View file

@ -21,6 +21,8 @@
#include "nix/expr/config.hh" #include "nix/expr/config.hh"
#include <boost/unordered/unordered_flat_map.hpp> #include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/concurrent_flat_map_fwd.hpp>
#include <map> #include <map>
#include <optional> #include <optional>
#include <functional> #include <functional>
@ -411,21 +413,24 @@ private:
/* Cache for calls to addToStore(); maps source paths to the store /* Cache for calls to addToStore(); maps source paths to the store
paths. */ paths. */
struct SrcToStore; ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
ref<SrcToStore> srcToStore;
/** /**
* A cache that maps paths to "resolved" paths for importing Nix * A cache that maps paths to "resolved" paths for importing Nix
* expressions, i.e. `/foo` to `/foo/default.nix`. * expressions, i.e. `/foo` to `/foo/default.nix`.
*/ */
struct ImportResolutionCache; ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
ref<ImportResolutionCache> importResolutionCache;
/** /**
* A cache from resolved paths to values. * A cache from resolved paths to values.
*/ */
struct FileEvalCache; ref<boost::concurrent_flat_map<
ref<FileEvalCache> fileEvalCache; SourcePath,
Value *,
std::hash<SourcePath>,
std::equal_to<SourcePath>,
traceable_allocator<std::pair<const SourcePath, Value *>>>>
fileEvalCache;
/** /**
* Associate source positions of certain AST nodes with their preceding doc comment, if they have one. * Associate source positions of certain AST nodes with their preceding doc comment, if they have one.