Skip to content

Commit

Permalink
refactor: Use EvalState::getBuiltins()
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Nov 19, 2024
1 parent 8a36d2d commit 5c258d7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void EvalState::addConstant(const std::string & name, Value * v, Constant info)
/* Install value the base environment. */
staticBaseEnv->vars.emplace_back(symbols.create(name), baseEnvDispl);
baseEnv.values[baseEnvDispl++] = v;
baseEnv.values[0]->payload.attrs->push_back(Attr(symbols.create(name2), v));
getBuiltins().payload.attrs->push_back(Attr(symbols.create(name2), v));
}
}

Expand Down Expand Up @@ -516,7 +516,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
else {
staticBaseEnv->vars.emplace_back(envName, baseEnvDispl);
baseEnv.values[baseEnvDispl++] = v;
baseEnv.values[0]->payload.attrs->push_back(Attr(symbols.create(primOp.name), v));
getBuiltins().payload.attrs->push_back(Attr(symbols.create(primOp.name), v));
}

return v;
Expand All @@ -531,7 +531,7 @@ Value & EvalState::getBuiltins()

Value & EvalState::getBuiltin(const std::string & name)
{
auto it = baseEnv.values[0]->attrs()->get(symbols.create(name));
auto it = getBuiltins().attrs()->get(symbols.create(name));
if (it)
return *it->value;
else
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4937,7 +4937,7 @@ void EvalState::createBaseEnv()

/* Now that we've added all primops, sort the `builtins' set,
because attribute lookups expect it to be sorted. */
baseEnv.values[0]->payload.attrs->sort();
getBuiltins().payload.attrs->sort();

staticBaseEnv->sort();

Expand Down
3 changes: 2 additions & 1 deletion src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ void mainWrapped(int argc, char * * argv)
evalSettings.pureEval = false;
EvalState state({}, openStore("dummy://"), fetchSettings, evalSettings);
auto builtinsJson = nlohmann::json::object();
for (auto & builtin : *state.baseEnv.values[0]->attrs()) {
for (auto & builtinPtr : state.getBuiltins().attrs()->lexicographicOrder(state.symbols)) {
auto & builtin = *builtinPtr;
auto b = nlohmann::json::object();
if (!builtin.value->isPrimOp()) continue;
auto primOp = builtin.value->primOp();
Expand Down

0 comments on commit 5c258d7

Please sign in to comment.