Skip to content

Commit 8d8f49c

Browse files
committed
Use concurrent_flat_map_fwd.hpp
1 parent 4b63ff6 commit 8d8f49c

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

src/libexpr/eval.cc

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,6 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
193193

194194
static constexpr size_t BASE_ENV_SIZE = 128;
195195

196-
struct EvalState::SrcToStore
197-
{
198-
boost::concurrent_flat_map<SourcePath, StorePath> inner;
199-
};
200-
201-
struct EvalState::ImportResolutionCache
202-
{
203-
boost::concurrent_flat_map<SourcePath, SourcePath> inner;
204-
};
205-
206-
struct EvalState::FileEvalCache
207-
{
208-
boost::concurrent_flat_map<
209-
SourcePath,
210-
Value *,
211-
std::hash<SourcePath>,
212-
std::equal_to<SourcePath>,
213-
traceable_allocator<std::pair<const SourcePath, Value *>>>
214-
inner;
215-
};
216-
217196
EvalState::EvalState(
218197
const LookupPath & lookupPathFromArguments,
219198
ref<Store> store,
@@ -286,9 +265,9 @@ EvalState::EvalState(
286265
, debugRepl(nullptr)
287266
, debugStop(false)
288267
, trylevel(0)
289-
, srcToStore(make_ref<SrcToStore>())
290-
, importResolutionCache(make_ref<ImportResolutionCache>())
291-
, fileEvalCache(make_ref<FileEvalCache>())
268+
, srcToStore(make_ref<decltype(srcToStore)::element_type>())
269+
, importResolutionCache(make_ref<decltype(importResolutionCache)::element_type>())
270+
, fileEvalCache(make_ref<decltype(fileEvalCache)::element_type>())
292271
, regexCache(makeRegexCache())
293272
#if NIX_USE_BOEHMGC
294273
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
@@ -1100,14 +1079,14 @@ struct ExprParseFile : Expr
11001079

11011080
void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
11021081
{
1103-
auto resolvedPath = getConcurrent(importResolutionCache->inner, path);
1082+
auto resolvedPath = getConcurrent(*importResolutionCache, path);
11041083

11051084
if (!resolvedPath) {
11061085
resolvedPath = resolveExprPath(path);
1107-
importResolutionCache->inner.emplace(path, *resolvedPath);
1086+
importResolutionCache->emplace(path, *resolvedPath);
11081087
}
11091088

1110-
if (auto v2 = getConcurrent(fileEvalCache->inner, *resolvedPath)) {
1089+
if (auto v2 = getConcurrent(*fileEvalCache, *resolvedPath)) {
11111090
forceValue(**v2, noPos);
11121091
v = **v2;
11131092
return;
@@ -1116,7 +1095,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
11161095
Value * vExpr;
11171096
ExprParseFile expr{*resolvedPath, mustBeTrivial};
11181097

1119-
fileEvalCache->inner.try_emplace_and_cvisit(
1098+
fileEvalCache->try_emplace_and_cvisit(
11201099
*resolvedPath,
11211100
nullptr,
11221101
[&](auto & i) {
@@ -1133,8 +1112,8 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
11331112

11341113
void EvalState::resetFileCache()
11351114
{
1136-
fileEvalCache->inner.clear();
1137-
fileEvalCache->inner.rehash(0);
1115+
importResolutionCache->clear();
1116+
fileEvalCache->clear();
11381117
inputCache->clear();
11391118
}
11401119

@@ -2419,7 +2398,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
24192398
if (nix::isDerivation(path.path.abs()))
24202399
error<EvalError>("file names are not allowed to end in '%1%'", drvExtension).debugThrow();
24212400

2422-
auto dstPathCached = getConcurrent(srcToStore->inner, path);
2401+
auto dstPathCached = getConcurrent(*srcToStore, path);
24232402

24242403
auto dstPath = dstPathCached ? *dstPathCached : [&]() {
24252404
auto dstPath = fetchToStore(
@@ -2432,7 +2411,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
24322411
nullptr,
24332412
repair);
24342413
allowPath(dstPath);
2435-
srcToStore->inner.try_emplace(path, dstPath);
2414+
srcToStore->try_emplace(path, dstPath);
24362415
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath));
24372416
return dstPath;
24382417
}();

src/libexpr/include/nix/expr/eval.hh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "nix/expr/config.hh"
2222

2323
#include <boost/unordered/unordered_flat_map.hpp>
24+
#include <boost/unordered/concurrent_flat_map_fwd.hpp>
25+
2426
#include <map>
2527
#include <optional>
2628
#include <functional>
@@ -411,21 +413,24 @@ private:
411413

412414
/* Cache for calls to addToStore(); maps source paths to the store
413415
paths. */
414-
struct SrcToStore;
415-
ref<SrcToStore> srcToStore;
416+
ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
416417

417418
/**
418419
* A cache that maps paths to "resolved" paths for importing Nix
419420
* expressions, i.e. `/foo` to `/foo/default.nix`.
420421
*/
421-
struct ImportResolutionCache;
422-
ref<ImportResolutionCache> importResolutionCache;
422+
ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
423423

424424
/**
425425
* A cache from resolved paths to values.
426426
*/
427-
struct FileEvalCache;
428-
ref<FileEvalCache> fileEvalCache;
427+
ref<boost::concurrent_flat_map<
428+
SourcePath,
429+
Value *,
430+
std::hash<SourcePath>,
431+
std::equal_to<SourcePath>,
432+
traceable_allocator<std::pair<const SourcePath, Value *>>>>
433+
fileEvalCache;
429434

430435
/**
431436
* Associate source positions of certain AST nodes with their preceding doc comment, if they have one.

0 commit comments

Comments
 (0)