From e82aec4efcd06cbd60d57f401fb7e93ab595128c Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Tue, 30 Nov 2021 14:15:02 -0700 Subject: [PATCH] fix merge issues --- src/libcmd/command.cc | 9 +-------- src/libcmd/repl.cc | 5 +++-- src/libexpr/eval.cc | 5 +++-- src/libexpr/nixexpr.cc | 14 +++++++------- src/libexpr/primops.cc | 4 ++-- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 4c5d985aa..2e00b42ff 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -68,7 +68,7 @@ extern std::function EvalCommand::getEvalState() { if (!evalState) { - evalState = std::make_shared(searchPath, getStore()); + evalState = std::make_shared(searchPath, getEvalStore(), getStore()); if (startReplOnEvalErrors) debuggerHook = [evalState{ref(evalState)}](const Error & error, const Env & env, const Expr & expr) { printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what()); @@ -102,13 +102,6 @@ ref EvalCommand::getEvalStore() return ref(evalStore); } -ref EvalCommand::getEvalState() -{ - if (!evalState) - evalState = std::make_shared(searchPath, getEvalStore(), getStore()); - return ref(evalState); -} - BuiltPathsCommand::BuiltPathsCommand(bool recursive) : recursive(recursive) { diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 6faa9f9fa..910f0f694 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -205,6 +205,7 @@ void NixRepl::mainLoop(const std::vector & files) if (!files.empty()) { for (auto & i : files) loadedFiles.push_back(i); + } reloadFiles(); if (!loadedFiles.empty()) notice(""); @@ -639,7 +640,7 @@ void NixRepl::addAttrsToScope(Value & attrs) { state->forceAttrs(attrs); for (auto & i : *attrs.attrs) - addVarToScope(i.name, *i.value); + addVarToScope(i.name, i.value); notice("Added %1% variables.", attrs.attrs->size()); } @@ -650,7 +651,7 @@ void NixRepl::addVarToScope(const Symbol & name, Value * v) throw Error("environment full; cannot add more variables"); staticEnv->vars.emplace_back(name, displ); staticEnv->sort(); - env->values[displ++] = &v; + env->values[displ++] = v; varNames.insert((string) name); } diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index a20123f34..8737930b5 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -591,7 +591,7 @@ Value * EvalState::addConstant(const string & name, Value & v) void EvalState::addConstant(const string & name, Value * v) { - staticBaseEnv.vars.emplace_back(symbols.create(name), baseEnvDispl); + staticBaseEnv->vars.emplace_back(symbols.create(name), baseEnvDispl); baseEnv.values[baseEnvDispl++] = v; string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; baseEnv.values[0]->attrs->push_back(Attr(symbols.create(name2), v)); @@ -1459,7 +1459,8 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & user. */ for (auto & i : *args[0]->attrs) if (lambda.formals->argNames.find(i.name) == lambda.formals->argNames.end()) - throwTypeError(pos, "%1% called with unexpected argument '%2%'", lambda, i.name); + throwTypeError(pos, "%1% called with unexpected argument '%2%'", + lambda, i.name, *fun.lambda.env, &lambda); abort(); // can't happen } } diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 696b149e3..dd0031a7c 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -346,7 +346,7 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) Displacement displ = 0; for (auto & i : attrs) - newEnv.vars.emplace_back(i.first, i.second.displ = displ++); + newEnv->vars.emplace_back(i.first, i.second.displ = displ++); // No need to sort newEnv since attrs is in sorted order. @@ -391,13 +391,13 @@ void ExprLambda::bindVars(const std::shared_ptr &env) Displacement displ = 0; - if (!arg.empty()) newEnv.vars.emplace_back(arg, displ++); + if (!arg.empty()) newEnv->vars.emplace_back(arg, displ++); if (hasFormals()) { for (auto & i : formals->formals) - newEnv.vars.emplace_back(i.name, displ++); + newEnv->vars.emplace_back(i.name, displ++); - newEnv.sort(); + newEnv->sort(); for (auto & i : formals->formals) if (i.def) i.def->bindVars(newEnv); @@ -406,7 +406,7 @@ void ExprLambda::bindVars(const std::shared_ptr &env) body->bindVars(newEnv); } -void ExprCall::bindVars(const StaticEnv & env) +void ExprCall::bindVars(const std::shared_ptr &env) { if (debuggerHook) staticenv = env; @@ -416,7 +416,7 @@ void ExprCall::bindVars(const StaticEnv & env) e->bindVars(env); } -void ExprLet::bindVars(const StaticEnv & env) +void ExprLet::bindVars(const std::shared_ptr &env) { if (debuggerHook) staticenv = env; @@ -425,7 +425,7 @@ void ExprLet::bindVars(const StaticEnv & env) Displacement displ = 0; for (auto & i : attrs->attrs) - newEnv.vars.emplace_back(i.first, i.second.displ = displ++); + newEnv->vars.emplace_back(i.first, i.second.displ = displ++); // No need to sort newEnv since attrs->attrs is in sorted order. diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index a9ee96bfa..2638b0076 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -188,7 +188,7 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS unsigned int displ = 0; for (auto & attr : *vScope->attrs) { - staticEnv.vars.emplace_back(attr.name, displ); + staticEnv->vars.emplace_back(attr.name, displ); env->values[displ++] = attr.value; } @@ -3750,7 +3750,7 @@ void EvalState::createBaseEnv() because attribute lookups expect it to be sorted. */ baseEnv.values[0]->attrs->sort(); - staticBaseEnv.sort(); + staticBaseEnv->sort(); /* Note: we have to initialize the 'derivation' constant *after* building baseEnv/staticBaseEnv because it uses 'builtins'. */