Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libexpr-c/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ EvalState * nix_eval_state_build(nix_c_context * context, nix_eval_state_builder
return EvalState{
.fetchSettings = std::move(builder->fetchSettings),
.settings = std::move(builder->settings),
.state = nix::EvalState(builder->lookupPath, builder->store, self->fetchSettings, self->settings),
.statePtr = std::make_shared<nix::EvalState>(
builder->lookupPath, builder->store, self->fetchSettings, self->settings),
.state = *self->statePtr,
};
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr-c/nix_api_expr_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct EvalState
{
nix::fetchers::Settings fetchSettings;
nix::EvalSettings settings;
nix::EvalState state;
std::shared_ptr<nix::EvalState> statePtr;
nix::EvalState & state;
};

struct BindingsBuilder
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr-tests/dynamic-attrs-bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static void BM_EvalDynamicAttrs(benchmark::State & state)
EvalSettings evalSettings{readOnlyMode};
evalSettings.nixPath = {};

EvalState st({}, store, fetchSettings, evalSettings, nullptr);
auto stPtr = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
auto & st = *stPtr;
Expr * expr = st.parseExprFromString(exprStr, st.rootPath(CanonPath::root));

Value v;
Expand Down
6 changes: 4 additions & 2 deletions src/libexpr-tests/get-drvs-bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ struct GetDerivationsEnv
fetchers::Settings fetchSettings{};
bool readOnlyMode = true;
EvalSettings evalSettings{readOnlyMode};
EvalState state;
std::shared_ptr<EvalState> statePtr;
EvalState & state;

Bindings * autoArgs = nullptr;
Value attrsValue;
Expand All @@ -27,7 +28,8 @@ struct GetDerivationsEnv
settings.nixPath = {};
return settings;
}())
, state({}, store, fetchSettings, evalSettings, nullptr)
, statePtr(std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr))
, state(*statePtr)
{
autoArgs = state.buildBindings(0).finish();

Expand Down
3 changes: 2 additions & 1 deletion src/libexpr-tests/regex-cache-bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ static void BM_EvalManyBuiltinsMatchSameRegex(benchmark::State & state)
EvalSettings evalSettings{readOnlyMode};
evalSettings.nixPath = {};

EvalState st({}, store, fetchSettings, evalSettings, nullptr);
auto stPtr = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
auto & st = *stPtr;
Expr * expr = st.parseExprFromString(std::string(exprStr), st.rootPath(CanonPath::root));

Value v;
Expand Down
10 changes: 6 additions & 4 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel)

evalSettings.restrictEval = true;
evalSettings.pureEval = true;
EvalState state(
{},
auto statePtr = std::make_shared<EvalState>(
LookupPath{},
openStore(StoreReference{.variant = StoreReference::Specified{.scheme = "dummy"}}),
fetchSettings,
evalSettings);
auto & state = *statePtr;

auto vGenerateManpage = state.allocValue();
state.eval(
Expand Down Expand Up @@ -454,11 +455,12 @@ void mainWrapped(int argc, char ** argv)
Xp::FetchTree,
};
evalSettings.pureEval = false;
EvalState state(
{},
auto statePtr = std::make_shared<EvalState>(
LookupPath{},
openStore(StoreReference{.variant = StoreReference::Specified{.scheme = "dummy"}}),
fetchSettings,
evalSettings);
auto & state = *statePtr;
auto builtinsJson = nlohmann::json::object();
for (auto & builtinPtr : state.getBuiltins().attrs()->lexicographicOrder(state.symbols)) {
auto & builtin = *builtinPtr;
Expand Down
2 changes: 1 addition & 1 deletion src/nix/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static void main_nix_build(int argc, char ** argv)
auto store = openStore();
auto evalStore = myArgs.evalStoreUrl ? openStore(StoreReference{*myArgs.evalStoreUrl}) : store;

auto state = std::make_unique<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
auto state = std::make_shared<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
state->repair = myArgs.repair;
if (myArgs.repair)
buildMode = bmRepair;
Expand Down
2 changes: 1 addition & 1 deletion src/nix/nix-instantiate/nix-instantiate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static int main_nix_instantiate(int argc, char ** argv)
auto store = openStore();
auto evalStore = myArgs.evalStoreUrl ? openStore(StoreReference{*myArgs.evalStoreUrl}) : store;

auto state = std::make_unique<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
auto state = std::make_shared<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
state->repair = myArgs.repair;

Bindings & autoArgs = *myArgs.getAutoArgs(*state);
Expand Down
2 changes: 1 addition & 1 deletion src/nix/prefetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static int main_nix_prefetch_url(int argc, char ** argv)
setLogFormat("bar");

auto store = openStore();
auto state = std::make_unique<EvalState>(myArgs.lookupPath, store, fetchSettings, evalSettings);
auto state = std::make_shared<EvalState>(myArgs.lookupPath, store, fetchSettings, evalSettings);

Bindings & autoArgs = *myArgs.getAutoArgs(*state);

Expand Down
2 changes: 1 addition & 1 deletion src/nix/upgrade-nix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
auto req = FileTransferRequest(parseURL(upgradeSettings.storePathUrl.get()));
auto res = getFileTransfer()->download(req);

auto state = std::make_unique<EvalState>(LookupPath{}, store, fetchSettings, evalSettings);
auto state = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings);
auto v = state->allocValue();
state->eval(state->parseExprFromString(res.data, state->rootPath(CanonPath("/no-such-path"))), *v);
Bindings & bindings = Bindings::emptyBindings;
Expand Down
Loading