Skip to content

Commit 6721ef5

Browse files
authored
Merge branch 'master' into fix-fetch-to-store-caching
2 parents 4b9735b + be92b18 commit 6721ef5

33 files changed

+592
-536
lines changed

maintainers/flake-module.nix

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,6 @@
106106
enable = true;
107107
excludes = [
108108
# We haven't linted these files yet
109-
''^tests/functional/dump-db\.sh$''
110-
''^tests/functional/dyn-drv/eval-outputOf\.sh$''
111-
''^tests/functional/dyn-drv/old-daemon-error-hack\.sh$''
112-
''^tests/functional/dyn-drv/recursive-mod-json\.sh$''
113-
''^tests/functional/eval-store\.sh$''
114-
''^tests/functional/export-graph\.sh$''
115-
''^tests/functional/export\.sh$''
116-
''^tests/functional/extra-sandbox-profile\.sh$''
117-
''^tests/functional/fetchClosure\.sh$''
118-
''^tests/functional/fetchGit\.sh$''
119-
''^tests/functional/fetchGitRefs\.sh$''
120-
''^tests/functional/fetchGitSubmodules\.sh$''
121-
''^tests/functional/fetchGitVerification\.sh$''
122-
''^tests/functional/fetchMercurial\.sh$''
123-
''^tests/functional/fixed\.builder1\.sh$''
124-
''^tests/functional/fixed\.builder2\.sh$''
125-
''^tests/functional/fixed\.sh$''
126-
''^tests/functional/flakes/absolute-paths\.sh$''
127-
''^tests/functional/flakes/check\.sh$''
128-
''^tests/functional/flakes/config\.sh$''
129-
''^tests/functional/flakes/flakes\.sh$''
130-
''^tests/functional/flakes/follow-paths\.sh$''
131109
''^tests/functional/flakes/prefetch\.sh$''
132110
''^tests/functional/flakes/run\.sh$''
133111
''^tests/functional/flakes/show\.sh$''
@@ -214,10 +192,6 @@
214192
''^tests/functional/user-envs\.sh$''
215193
''^tests/functional/why-depends\.sh$''
216194

217-
# Shellcheck doesn't support fish or zsh shell syntax
218-
''^misc/fish/completion\.fish$''
219-
''^misc/zsh/completion\.zsh$''
220-
221195
# Content-addressed test files that use recursive-*looking* sourcing
222196
# (cd .. && source <self>), causing shellcheck to loop
223197
# They're small wrapper scripts with not a lot going on

misc/fish/completion.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=all
12
function _nix_complete
23
# Get the current command up to a cursor.
34
# - Behaves correctly even with pipes and nested in commands like env.

misc/zsh/completion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=all
12
#compdef nix
23

34
function _nix() {

src/libcmd/repl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
760760

761761
void NixRepl::initEnv()
762762
{
763-
env = &state->allocEnv(envSize);
763+
env = &state->mem.allocEnv(envSize);
764764
env->up = &state->baseEnv;
765765
displ = 0;
766766
staticEnv->vars.clear();

src/libexpr-c/nix_api_value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ nix_err nix_bindings_builder_insert(nix_c_context * context, BindingsBuilder * b
679679
context->last_err_code = NIX_OK;
680680
try {
681681
auto & v = check_value_not_null(value);
682-
nix::Symbol s = bb->builder.state.get().symbols.create(name);
682+
nix::Symbol s = bb->builder.symbols.get().create(name);
683683
bb->builder.insert(s, &v);
684684
}
685685
NIXC_CATCH_ERRS

src/libexpr/attr-set.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ Bindings Bindings::emptyBindings;
1010
/* Allocate a new array of attributes for an attribute set with a specific
1111
capacity. The space is implicitly reserved after the Bindings
1212
structure. */
13-
Bindings * EvalState::allocBindings(size_t capacity)
13+
Bindings * EvalMemory::allocBindings(size_t capacity)
1414
{
1515
if (capacity == 0)
1616
return &Bindings::emptyBindings;
1717
if (capacity > std::numeric_limits<Bindings::size_type>::max())
1818
throw Error("attribute set of size %d is too big", capacity);
19-
nrAttrsets++;
20-
nrAttrsInAttrsets += capacity;
19+
stats.nrAttrsets++;
20+
stats.nrAttrsInAttrsets += capacity;
2121
return new (allocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings();
2222
}
2323

2424
Value & BindingsBuilder::alloc(Symbol name, PosIdx pos)
2525
{
26-
auto value = state.get().allocValue();
26+
auto value = mem.get().allocValue();
2727
bindings->push_back(Attr(name, value, pos));
2828
return *value;
2929
}
3030

3131
Value & BindingsBuilder::alloc(std::string_view name, PosIdx pos)
3232
{
33-
return alloc(state.get().symbols.create(name), pos);
33+
return alloc(symbols.get().create(name), pos);
3434
}
3535

3636
void Bindings::sort()

src/libexpr/eval.cc

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
194194

195195
static constexpr size_t BASE_ENV_SIZE = 128;
196196

197+
EvalMemory::EvalMemory()
198+
#if NIX_USE_BOEHMGC
199+
: valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
200+
, env1AllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
201+
#endif
202+
{
203+
assertGCInitialized();
204+
}
205+
197206
EvalState::EvalState(
198207
const LookupPath & lookupPathFromArguments,
199208
ref<Store> store,
@@ -267,12 +276,10 @@ EvalState::EvalState(
267276
, fileEvalCache(make_ref<decltype(fileEvalCache)::element_type>())
268277
, regexCache(makeRegexCache())
269278
#if NIX_USE_BOEHMGC
270-
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
271-
, env1AllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
272-
, baseEnvP(std::allocate_shared<Env *>(traceable_allocator<Env *>(), &allocEnv(BASE_ENV_SIZE)))
279+
, baseEnvP(std::allocate_shared<Env *>(traceable_allocator<Env *>(), &mem.allocEnv(BASE_ENV_SIZE)))
273280
, baseEnv(**baseEnvP)
274281
#else
275-
, baseEnv(allocEnv(BASE_ENV_SIZE))
282+
, baseEnv(mem.allocEnv(BASE_ENV_SIZE))
276283
#endif
277284
, staticBaseEnv{std::make_shared<StaticEnv>(nullptr, nullptr)}
278285
{
@@ -281,8 +288,6 @@ EvalState::EvalState(
281288

282289
countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";
283290

284-
assertGCInitialized();
285-
286291
static_assert(sizeof(Env) <= 16, "environment must be <= 16 bytes");
287292
static_assert(sizeof(Counter) == 64, "counters must be 64 bytes");
288293

@@ -878,11 +883,10 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
878883
}
879884
}
880885

881-
ListBuilder::ListBuilder(EvalState & state, size_t size)
886+
ListBuilder::ListBuilder(size_t size)
882887
: size(size)
883888
, elems(size <= 2 ? inlineElems : (Value **) allocBytes(size * sizeof(Value *)))
884889
{
885-
state.nrListElems += size;
886890
}
887891

888892
Value * EvalState::getBool(bool b)
@@ -1176,7 +1180,7 @@ void ExprPath::eval(EvalState & state, Env & env, Value & v)
11761180

11771181
Env * ExprAttrs::buildInheritFromEnv(EvalState & state, Env & up)
11781182
{
1179-
Env & inheritEnv = state.allocEnv(inheritFromExprs->size());
1183+
Env & inheritEnv = state.mem.allocEnv(inheritFromExprs->size());
11801184
inheritEnv.up = &up;
11811185

11821186
Displacement displ = 0;
@@ -1195,7 +1199,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
11951199
if (recursive) {
11961200
/* Create a new environment that contains the attributes in
11971201
this `rec'. */
1198-
Env & env2(state.allocEnv(attrs.size()));
1202+
Env & env2(state.mem.allocEnv(attrs.size()));
11991203
env2.up = &env;
12001204
dynamicEnv = &env2;
12011205
Env * inheritEnv = inheritFromExprs ? buildInheritFromEnv(state, env2) : nullptr;
@@ -1287,7 +1291,7 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
12871291
{
12881292
/* Create a new environment that contains the attributes in this
12891293
`let'. */
1290-
Env & env2(state.allocEnv(attrs->attrs.size()));
1294+
Env & env2(state.mem.allocEnv(attrs->attrs.size()));
12911295
env2.up = &env;
12921296

12931297
Env * inheritEnv = attrs->inheritFromExprs ? attrs->buildInheritFromEnv(state, env2) : nullptr;
@@ -1493,7 +1497,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
14931497
ExprLambda & lambda(*vCur.lambda().fun);
14941498

14951499
auto size = (!lambda.arg ? 0 : 1) + (lambda.hasFormals() ? lambda.formals->formals.size() : 0);
1496-
Env & env2(allocEnv(size));
1500+
Env & env2(mem.allocEnv(size));
14971501
env2.up = vCur.lambda().env;
14981502

14991503
Displacement displ = 0;
@@ -1782,7 +1786,7 @@ values, or passed explicitly with '--arg' or '--argstr'. See
17821786

17831787
void ExprWith::eval(EvalState & state, Env & env, Value & v)
17841788
{
1785-
Env & env2(state.allocEnv(1));
1789+
Env & env2(state.mem.allocEnv(1));
17861790
env2.up = &env;
17871791
env2.values[0] = attrs->maybeThunk(state, env);
17881792

@@ -2909,10 +2913,12 @@ void EvalState::printStatistics()
29092913
std::chrono::microseconds cpuTimeDuration = getCpuUserTime();
29102914
float cpuTime = std::chrono::duration_cast<std::chrono::duration<float>>(cpuTimeDuration).count();
29112915

2912-
uint64_t bEnvs = nrEnvs * sizeof(Env) + nrValuesInEnvs * sizeof(Value *);
2913-
uint64_t bLists = nrListElems * sizeof(Value *);
2914-
uint64_t bValues = nrValues * sizeof(Value);
2915-
uint64_t bAttrsets = nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr);
2916+
auto & memstats = mem.getStats();
2917+
2918+
uint64_t bEnvs = memstats.nrEnvs * sizeof(Env) + memstats.nrValuesInEnvs * sizeof(Value *);
2919+
uint64_t bLists = memstats.nrListElems * sizeof(Value *);
2920+
uint64_t bValues = memstats.nrValues * sizeof(Value);
2921+
uint64_t bAttrsets = memstats.nrAttrsets * sizeof(Bindings) + memstats.nrAttrsInAttrsets * sizeof(Attr);
29162922

29172923
#if NIX_USE_BOEHMGC
29182924
GC_word heapSize, totalBytes;
@@ -2938,28 +2944,28 @@ void EvalState::printStatistics()
29382944
#endif
29392945
};
29402946
topObj["envs"] = {
2941-
{"number", nrEnvs.load()},
2942-
{"elements", nrValuesInEnvs.load()},
2947+
{"number", memstats.nrEnvs.load()},
2948+
{"elements", memstats.nrValuesInEnvs.load()},
29432949
{"bytes", bEnvs},
29442950
};
29452951
topObj["nrExprs"] = Expr::nrExprs.load();
29462952
topObj["list"] = {
2947-
{"elements", nrListElems.load()},
2953+
{"elements", memstats.nrListElems.load()},
29482954
{"bytes", bLists},
29492955
{"concats", nrListConcats.load()},
29502956
};
29512957
topObj["values"] = {
2952-
{"number", nrValues.load()},
2958+
{"number", memstats.nrValues.load()},
29532959
{"bytes", bValues},
29542960
};
29552961
topObj["symbols"] = {
29562962
{"number", symbols.size()},
29572963
{"bytes", symbols.totalSize()},
29582964
};
29592965
topObj["sets"] = {
2960-
{"number", nrAttrsets.load()},
2966+
{"number", memstats.nrAttrsets.load()},
29612967
{"bytes", bAttrsets},
2962-
{"elements", nrAttrsInAttrsets.load()},
2968+
{"elements", memstats.nrAttrsInAttrsets.load()},
29632969
};
29642970
topObj["sizes"] = {
29652971
{"Env", sizeof(Env)},

src/libexpr/include/nix/expr/attr-set.hh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace nix {
1515

16-
class EvalState;
16+
class EvalMemory;
1717
struct Value;
1818

1919
/**
@@ -426,7 +426,7 @@ public:
426426
return res;
427427
}
428428

429-
friend class EvalState;
429+
friend class EvalMemory;
430430
};
431431

432432
static_assert(std::forward_iterator<Bindings::iterator>);
@@ -448,12 +448,13 @@ private:
448448
Bindings * bindings;
449449
Bindings::size_type capacity_;
450450

451-
friend class EvalState;
451+
friend class EvalMemory;
452452

453-
BindingsBuilder(EvalState & state, Bindings * bindings, size_type capacity)
453+
BindingsBuilder(EvalMemory & mem, SymbolTable & symbols, Bindings * bindings, size_type capacity)
454454
: bindings(bindings)
455455
, capacity_(capacity)
456-
, state(state)
456+
, mem(mem)
457+
, symbols(symbols)
457458
{
458459
}
459460

@@ -471,7 +472,8 @@ private:
471472
}
472473

473474
public:
474-
std::reference_wrapper<EvalState> state;
475+
std::reference_wrapper<EvalMemory> mem;
476+
std::reference_wrapper<SymbolTable> symbols;
475477

476478
void insert(Symbol name, Value * value, PosIdx pos = noPos)
477479
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ inline void * allocBytes(size_t n)
2626
}
2727

2828
[[gnu::always_inline]]
29-
Value * EvalState::allocValue()
29+
Value * EvalMemory::allocValue()
3030
{
3131
#if NIX_USE_BOEHMGC
3232
/* We use the boehm batch allocator to speed up allocations of Values (of which there are many).
@@ -48,15 +48,15 @@ Value * EvalState::allocValue()
4848
void * p = allocBytes(sizeof(Value));
4949
#endif
5050

51-
nrValues++;
51+
stats.nrValues++;
5252
return (Value *) p;
5353
}
5454

5555
[[gnu::always_inline]]
56-
Env & EvalState::allocEnv(size_t size)
56+
Env & EvalMemory::allocEnv(size_t size)
5757
{
58-
nrEnvs++;
59-
nrValuesInEnvs += size;
58+
stats.nrEnvs++;
59+
stats.nrValuesInEnvs += size;
6060

6161
Env * env;
6262

0 commit comments

Comments
 (0)