Skip to content

Commit ac59260

Browse files
committed
restore EvalState::allocValue() forwarding to EvalMemory::allocValue()
this is to reduce code churn and merge conflicts
1 parent d6a158e commit ac59260

File tree

20 files changed

+59
-54
lines changed

20 files changed

+59
-54
lines changed

src/libcmd/common-eval-args.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
155155
{
156156
auto res = state.buildBindings(autoArgs.size());
157157
for (auto & [name, arg] : autoArgs) {
158-
auto v = state.mem.allocValue();
158+
auto v = state.allocValue();
159159
std::visit(
160160
overloaded{
161161
[&](const AutoArgExpr & arg) {

src/libcmd/installables.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ ref<eval_cache::EvalCache> openEvalCache(EvalState & state, std::shared_ptr<flak
454454
if (getEnv("NIX_ALLOW_EVAL").value_or("1") == "0")
455455
throw Error("not everything is cached, but evaluation is not allowed");
456456

457-
auto vFlake = state.mem.allocValue();
457+
auto vFlake = state.allocValue();
458458
flake::callFlake(state, *lockedFlake, *vFlake);
459459

460460
state.forceAttrs(*vFlake, noPos, "while parsing cached flake data");
@@ -495,7 +495,7 @@ Installables SourceExprCommand::parseInstallables(ref<Store> store, std::vector<
495495
}
496496

497497
auto state = getEvalState();
498-
auto vFile = state->mem.allocValue();
498+
auto vFile = state->allocValue();
499499

500500
if (file == "-") {
501501
auto e = state->parseStdin();

src/libcmd/repl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
697697
if (p != std::string::npos && p < line.size() && line[p + 1] != '='
698698
&& isVarName(name = removeWhitespace(line.substr(0, p)))) {
699699
Expr * e = parseString(line.substr(p + 1));
700-
Value & v(*state->mem.allocValue());
700+
Value & v(*state->allocValue());
701701
v.mkThunk(env, e);
702702
addVarToScope(state->symbols.create(name), v);
703703
} else {

src/libexpr-c/nix_api_value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ nix_value * nix_alloc_value(nix_c_context * context, EvalState * state)
160160
if (context)
161161
context->last_err_code = NIX_OK;
162162
try {
163-
nix_value * res = as_nix_value_ptr(state->state.mem.allocValue());
163+
nix_value * res = as_nix_value_ptr(state->state.allocValue());
164164
nix_gc_incref(nullptr, res);
165165
return res;
166166
}

src/libexpr-tests/derived-path.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST_F(DerivedPathExpressionTest, force_init) {}
2222

2323
RC_GTEST_FIXTURE_PROP(DerivedPathExpressionTest, prop_opaque_path_round_trip, (const SingleDerivedPath::Opaque & o))
2424
{
25-
auto * v = state.mem.allocValue();
25+
auto * v = state.allocValue();
2626
state.mkStorePathString(o.path, *v);
2727
auto d = state.coerceToSingleDerivedPath(noPos, *v, "");
2828
RC_ASSERT(SingleDerivedPath{o} == d);
@@ -41,7 +41,7 @@ RC_GTEST_FIXTURE_PROP(
4141
ExperimentalFeatureSettings mockXpSettings;
4242
mockXpSettings.set("experimental-features", "ca-derivations dynamic-derivations");
4343

44-
auto * v = state.mem.allocValue();
44+
auto * v = state.allocValue();
4545
state.mkOutputString(*v, b, std::nullopt, mockXpSettings);
4646
auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings);
4747
RC_ASSERT(SingleDerivedPath{b} == d);
@@ -55,7 +55,7 @@ RC_GTEST_FIXTURE_PROP(
5555
ExperimentalFeatureSettings mockXpSettings;
5656
mockXpSettings.set("experimental-features", "dynamic-derivations");
5757

58-
auto * v = state.mem.allocValue();
58+
auto * v = state.allocValue();
5959
state.mkOutputString(*v, b, outPath, mockXpSettings);
6060
auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings);
6161
RC_ASSERT(SingleDerivedPath{b} == d);

src/libexpr/attr-path.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ findAlongAttrPath(EvalState & state, const std::string & attrPath, Bindings & au
5252
auto attrIndex = string2Int<unsigned int>(attr);
5353

5454
/* Evaluate the expression. */
55-
Value * vNew = state.mem.allocValue();
55+
Value * vNew = state.allocValue();
5656
state.autoCallFunction(autoArgs, *v, *vNew);
5757
v = vNew;
5858
state.forceValue(*v, noPos);

src/libexpr/eval.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void EvalState::checkURI(const std::string & uri)
423423

424424
Value * EvalState::addConstant(const std::string & name, Value & v, Constant info)
425425
{
426-
Value * v2 = mem.allocValue();
426+
Value * v2 = allocValue();
427427
*v2 = v;
428428
addConstant(name, v2, info);
429429
return v2;
@@ -489,7 +489,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
489489
the primop to a dummy value. */
490490
if (primOp.arity == 0) {
491491
primOp.arity = 1;
492-
auto vPrimOp = mem.allocValue();
492+
auto vPrimOp = allocValue();
493493
vPrimOp->mkPrimOp(new PrimOp(primOp));
494494
Value v;
495495
v.mkApp(vPrimOp, vPrimOp);
@@ -506,7 +506,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
506506
if (hasPrefix(primOp.name, "__"))
507507
primOp.name = primOp.name.substr(2);
508508

509-
Value * v = mem.allocValue();
509+
Value * v = allocValue();
510510
v->mkPrimOp(new PrimOp(primOp));
511511

512512
if (primOp.internal)
@@ -989,7 +989,7 @@ void EvalState::mkSingleDerivedPathString(const SingleDerivedPath & p, Value & v
989989

990990
Value * Expr::maybeThunk(EvalState & state, Env & env)
991991
{
992-
Value * v = state.mem.allocValue();
992+
Value * v = state.allocValue();
993993
mkThunk(*v, env, this);
994994
return v;
995995
}
@@ -1099,7 +1099,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
10991099
*resolvedPath,
11001100
nullptr,
11011101
[&](auto & i) {
1102-
vExpr = mem.allocValue();
1102+
vExpr = allocValue();
11031103
vExpr->mkThunk(&baseEnv, expr);
11041104
i.second = vExpr;
11051105
},
@@ -1216,7 +1216,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
12161216
for (auto & i : attrs) {
12171217
Value * vAttr;
12181218
if (hasOverrides && i.second.kind != AttrDef::Kind::Inherited) {
1219-
vAttr = state.mem.allocValue();
1219+
vAttr = state.allocValue();
12201220
mkThunk(*vAttr, *i.second.chooseByKind(&env2, &env, inheritEnv), i.second.e);
12211221
} else
12221222
vAttr = i.second.e->maybeThunk(state, *i.second.chooseByKind(&env2, &env, inheritEnv));
@@ -1484,7 +1484,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
14841484
auto makeAppChain = [&]() {
14851485
vRes = vCur;
14861486
for (auto arg : args) {
1487-
auto fun2 = mem.allocValue();
1487+
auto fun2 = allocValue();
14881488
*fun2 = vRes;
14891489
vRes.mkPrimOpApp(fun2, arg);
14901490
}
@@ -1682,7 +1682,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
16821682
/* 'vCur' may be allocated on the stack of the calling
16831683
function, but for functors we may keep a reference, so
16841684
heap-allocate a copy and use that instead. */
1685-
Value * args2[] = {mem.allocValue(), args[0]};
1685+
Value * args2[] = {allocValue(), args[0]};
16861686
*args2[0] = vCur;
16871687
try {
16881688
callFunction(*functor->value, args2, vCur, functor->pos);
@@ -1742,7 +1742,7 @@ void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res
17421742
if (fun.type() == nAttrs) {
17431743
auto found = fun.attrs()->get(s.functor);
17441744
if (found) {
1745-
Value * v = mem.allocValue();
1745+
Value * v = allocValue();
17461746
callFunction(*found->value, fun, *v, pos);
17471747
forceValue(*v, pos);
17481748
return autoCallFunction(args, *v, res);
@@ -1783,7 +1783,7 @@ values, or passed explicitly with '--arg' or '--argstr'. See
17831783
}
17841784
}
17851785

1786-
callFunction(fun, mem.allocValue()->mkAttrs(attrs), res, pos);
1786+
callFunction(fun, allocValue()->mkAttrs(attrs), res, pos);
17871787
}
17881788

17891789
void ExprWith::eval(EvalState & state, Env & env, Value & v)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ public:
511511
std::shared_ptr<Store> buildStore = nullptr);
512512
~EvalState();
513513

514+
inline Value * allocValue()
515+
{
516+
return mem.allocValue();
517+
}
518+
514519
LookupPath getLookupPath()
515520
{
516521
return lookupPath;

src/libexpr/json-to-value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class JSONSax : nlohmann::json_sax<json>
4040
Value & value(EvalState & state)
4141
{
4242
if (!v)
43-
v = allocRootValue(state.mem.allocValue());
43+
v = allocRootValue(state.allocValue());
4444
return **v;
4545
}
4646

src/libexpr/primops.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace nix {
4545

4646
static inline Value * mkString(EvalState & state, const std::csub_match & match)
4747
{
48-
Value * v = state.mem.allocValue();
48+
Value * v = state.allocValue();
4949
v->mkString({match.first, match.second});
5050
return v;
5151
}
@@ -227,15 +227,15 @@ void derivationToValue(
227227
auto list = state.buildList(drv.outputs.size());
228228
for (const auto & [i, o] : enumerate(drv.outputs)) {
229229
mkOutputString(state, attrs, storePath, o);
230-
(list[i] = state.mem.allocValue())->mkString(o.first);
230+
(list[i] = state.allocValue())->mkString(o.first);
231231
}
232232
attrs.alloc(state.s.outputs).mkList(list);
233233

234-
auto w = state.mem.allocValue();
234+
auto w = state.allocValue();
235235
w->mkAttrs(attrs);
236236

237237
if (!state.vImportedDrvToDerivation) {
238-
state.vImportedDrvToDerivation = allocRootValue(state.mem.allocValue());
238+
state.vImportedDrvToDerivation = allocRootValue(state.allocValue());
239239
state.eval(
240240
state.parseExprFromString(
241241
#include "imported-drv-to-derivation.nix.gen.hh"
@@ -2317,7 +2317,7 @@ static void prim_readDir(EvalState & state, const PosIdx pos, Value ** args, Val
23172317
// Some filesystems or operating systems may not be able to return
23182318
// detailed node info quickly in this case we produce a thunk to
23192319
// query the file type lazily.
2320-
auto epath = state.mem.allocValue();
2320+
auto epath = state.allocValue();
23212321
epath->mkPath(path / name);
23222322
if (!readFileType)
23232323
readFileType = &state.getBuiltin("readFileType");
@@ -3059,7 +3059,7 @@ static struct LazyPosAccessors
30593059

30603060
void operator()(EvalState & state, const PosIdx pos, Value & line, Value & column)
30613061
{
3062-
Value * posV = state.mem.allocValue();
3062+
Value * posV = state.allocValue();
30633063
posV->mkInt(pos.id);
30643064
line.mkApp(&lineOfPos, posV);
30653065
column.mkApp(&columnOfPos, posV);
@@ -3405,7 +3405,7 @@ static void prim_mapAttrs(EvalState & state, const PosIdx pos, Value ** args, Va
34053405

34063406
for (auto & i : *args[1]->attrs()) {
34073407
Value * vName = Value::toPtr(state.symbols[i.name]);
3408-
Value * vFun2 = state.mem.allocValue();
3408+
Value * vFun2 = state.allocValue();
34093409
vFun2->mkApp(args[0], vName);
34103410
attrs.alloc(i.name).mkApp(vFun2, i.value);
34113411
}
@@ -3471,10 +3471,10 @@ static void prim_zipAttrsWith(EvalState & state, const PosIdx pos, Value ** args
34713471

34723472
for (auto & [sym, elem] : attrsSeen) {
34733473
auto name = Value::toPtr(state.symbols[sym]);
3474-
auto call1 = state.mem.allocValue();
3474+
auto call1 = state.allocValue();
34753475
call1->mkApp(args[0], name);
3476-
auto call2 = state.mem.allocValue();
3477-
auto arg = state.mem.allocValue();
3476+
auto call2 = state.allocValue();
3477+
auto arg = state.allocValue();
34783478
arg->mkList(*elem.list);
34793479
call2->mkApp(call1, arg);
34803480
attrs.insert(sym, call2);
@@ -3625,7 +3625,7 @@ static void prim_map(EvalState & state, const PosIdx pos, Value ** args, Value &
36253625

36263626
auto list = state.buildList(args[1]->listSize());
36273627
for (const auto & [n, v] : enumerate(list))
3628-
(v = state.mem.allocValue())->mkApp(args[0], args[1]->listView()[n]);
3628+
(v = state.allocValue())->mkApp(args[0], args[1]->listView()[n]);
36293629
v.mkList(list);
36303630
}
36313631

@@ -3768,7 +3768,7 @@ static void prim_foldlStrict(EvalState & state, const PosIdx pos, Value ** args,
37683768
auto listView = args[2]->listView();
37693769
for (auto [n, elem] : enumerate(listView)) {
37703770
Value * vs[]{vCur, elem};
3771-
vCur = n == args[2]->listSize() - 1 ? &v : state.mem.allocValue();
3771+
vCur = n == args[2]->listSize() - 1 ? &v : state.allocValue();
37723772
state.callFunction(*args[0], vs, *vCur, pos);
37733773
}
37743774
state.forceValue(v, pos);
@@ -3866,9 +3866,9 @@ static void prim_genList(EvalState & state, const PosIdx pos, Value ** args, Val
38663866

38673867
auto list = state.buildList(len);
38683868
for (const auto & [n, v] : enumerate(list)) {
3869-
auto arg = state.mem.allocValue();
3869+
auto arg = state.allocValue();
38703870
arg->mkInt(n);
3871-
(v = state.mem.allocValue())->mkApp(args[0], arg);
3871+
(v = state.allocValue())->mkApp(args[0], arg);
38723872
}
38733873
v.mkList(list);
38743874
}
@@ -4734,7 +4734,7 @@ void prim_split(EvalState & state, const PosIdx pos, Value ** args, Value & v)
47344734
v2 = mkString(state, match[si + 1]);
47354735
}
47364736

4737-
(list[idx++] = state.mem.allocValue())->mkList(list2);
4737+
(list[idx++] = state.allocValue())->mkList(list2);
47384738

47394739
// Add a string for non-matched suffix characters.
47404740
if (idx == 2 * len)
@@ -4985,7 +4985,7 @@ static void prim_splitVersion(EvalState & state, const PosIdx pos, Value ** args
49854985
}
49864986
auto list = state.buildList(components.size());
49874987
for (const auto & [n, component] : enumerate(components))
4988-
(list[n] = state.mem.allocValue())->mkString(std::move(component));
4988+
(list[n] = state.allocValue())->mkString(std::move(component));
49894989
v.mkList(list);
49904990
}
49914991

@@ -5253,7 +5253,7 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
52535253
auto attrs = buildBindings(2);
52545254
attrs.alloc("path").mkString(i.path.s);
52555255
attrs.alloc("prefix").mkString(i.prefix.s);
5256-
(list[n] = mem.allocValue())->mkAttrs(attrs);
5256+
(list[n] =.allocValue())->mkAttrs(attrs);
52575257
}
52585258
v.mkList(list);
52595259
addConstant(
@@ -5307,7 +5307,7 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
53075307
53085308
Null docs because it is documented separately.
53095309
*/
5310-
auto vDerivation = mem.allocValue();
5310+
auto vDerivation =.allocValue();
53115311
addConstant(
53125312
"derivation",
53135313
vDerivation,

0 commit comments

Comments
 (0)