Skip to content

Commit bf3171b

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

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
@@ -418,7 +418,7 @@ void EvalState::checkURI(const std::string & uri)
418418

419419
Value * EvalState::addConstant(const std::string & name, Value & v, Constant info)
420420
{
421-
Value * v2 = mem.allocValue();
421+
Value * v2 = allocValue();
422422
*v2 = v;
423423
addConstant(name, v2, info);
424424
return v2;
@@ -484,7 +484,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
484484
the primop to a dummy value. */
485485
if (primOp.arity == 0) {
486486
primOp.arity = 1;
487-
auto vPrimOp = mem.allocValue();
487+
auto vPrimOp = allocValue();
488488
vPrimOp->mkPrimOp(new PrimOp(primOp));
489489
Value v;
490490
v.mkApp(vPrimOp, vPrimOp);
@@ -501,7 +501,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
501501
if (hasPrefix(primOp.name, "__"))
502502
primOp.name = primOp.name.substr(2);
503503

504-
Value * v = mem.allocValue();
504+
Value * v = allocValue();
505505
v->mkPrimOp(new PrimOp(primOp));
506506

507507
if (primOp.internal)
@@ -984,7 +984,7 @@ void EvalState::mkSingleDerivedPathString(const SingleDerivedPath & p, Value & v
984984

985985
Value * Expr::maybeThunk(EvalState & state, Env & env)
986986
{
987-
Value * v = state.mem.allocValue();
987+
Value * v = state.allocValue();
988988
mkThunk(*v, env, this);
989989
return v;
990990
}
@@ -1094,7 +1094,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
10941094
*resolvedPath,
10951095
nullptr,
10961096
[&](auto & i) {
1097-
vExpr = mem.allocValue();
1097+
vExpr = allocValue();
10981098
vExpr->mkThunk(&baseEnv, expr);
10991099
i.second = vExpr;
11001100
},
@@ -1211,7 +1211,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
12111211
for (auto & i : attrs) {
12121212
Value * vAttr;
12131213
if (hasOverrides && i.second.kind != AttrDef::Kind::Inherited) {
1214-
vAttr = state.mem.allocValue();
1214+
vAttr = state.allocValue();
12151215
mkThunk(*vAttr, *i.second.chooseByKind(&env2, &env, inheritEnv), i.second.e);
12161216
} else
12171217
vAttr = i.second.e->maybeThunk(state, *i.second.chooseByKind(&env2, &env, inheritEnv));
@@ -1479,7 +1479,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
14791479
auto makeAppChain = [&]() {
14801480
vRes = vCur;
14811481
for (auto arg : args) {
1482-
auto fun2 = mem.allocValue();
1482+
auto fun2 = allocValue();
14831483
*fun2 = vRes;
14841484
vRes.mkPrimOpApp(fun2, arg);
14851485
}
@@ -1677,7 +1677,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
16771677
/* 'vCur' may be allocated on the stack of the calling
16781678
function, but for functors we may keep a reference, so
16791679
heap-allocate a copy and use that instead. */
1680-
Value * args2[] = {mem.allocValue(), args[0]};
1680+
Value * args2[] = {allocValue(), args[0]};
16811681
*args2[0] = vCur;
16821682
try {
16831683
callFunction(*functor->value, args2, vCur, functor->pos);
@@ -1737,7 +1737,7 @@ void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res
17371737
if (fun.type() == nAttrs) {
17381738
auto found = fun.attrs()->get(s.functor);
17391739
if (found) {
1740-
Value * v = mem.allocValue();
1740+
Value * v = allocValue();
17411741
callFunction(*found->value, fun, *v, pos);
17421742
forceValue(*v, pos);
17431743
return autoCallFunction(args, *v, res);
@@ -1778,7 +1778,7 @@ values, or passed explicitly with '--arg' or '--argstr'. See
17781778
}
17791779
}
17801780

1781-
callFunction(fun, mem.allocValue()->mkAttrs(attrs), res, pos);
1781+
callFunction(fun, allocValue()->mkAttrs(attrs), res, pos);
17821782
}
17831783

17841784
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
@@ -509,6 +509,11 @@ public:
509509
std::shared_ptr<Store> buildStore = nullptr);
510510
~EvalState();
511511

512+
inline Value * allocValue()
513+
{
514+
return mem.allocValue();
515+
}
516+
512517
LookupPath getLookupPath()
513518
{
514519
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)