fix merge issues

This commit is contained in:
Ben Burdette 2021-11-30 14:15:02 -07:00
parent 64c4ba8f66
commit e82aec4efc
5 changed files with 16 additions and 21 deletions

View file

@ -68,7 +68,7 @@ extern std::function<void(const Error & error, const Env & env, const Expr & exp
ref<EvalState> EvalCommand::getEvalState() ref<EvalState> EvalCommand::getEvalState()
{ {
if (!evalState) { if (!evalState) {
evalState = std::make_shared<EvalState>(searchPath, getStore()); evalState = std::make_shared<EvalState>(searchPath, getEvalStore(), getStore());
if (startReplOnEvalErrors) if (startReplOnEvalErrors)
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env, const Expr & expr) { debuggerHook = [evalState{ref<EvalState>(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()); 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<Store> EvalCommand::getEvalStore()
return ref<Store>(evalStore); return ref<Store>(evalStore);
} }
ref<EvalState> EvalCommand::getEvalState()
{
if (!evalState)
evalState = std::make_shared<EvalState>(searchPath, getEvalStore(), getStore());
return ref<EvalState>(evalState);
}
BuiltPathsCommand::BuiltPathsCommand(bool recursive) BuiltPathsCommand::BuiltPathsCommand(bool recursive)
: recursive(recursive) : recursive(recursive)
{ {

View file

@ -205,6 +205,7 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
if (!files.empty()) { if (!files.empty()) {
for (auto & i : files) for (auto & i : files)
loadedFiles.push_back(i); loadedFiles.push_back(i);
}
reloadFiles(); reloadFiles();
if (!loadedFiles.empty()) notice(""); if (!loadedFiles.empty()) notice("");
@ -639,7 +640,7 @@ void NixRepl::addAttrsToScope(Value & attrs)
{ {
state->forceAttrs(attrs); state->forceAttrs(attrs);
for (auto & i : *attrs.attrs) for (auto & i : *attrs.attrs)
addVarToScope(i.name, *i.value); addVarToScope(i.name, i.value);
notice("Added %1% variables.", attrs.attrs->size()); 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"); throw Error("environment full; cannot add more variables");
staticEnv->vars.emplace_back(name, displ); staticEnv->vars.emplace_back(name, displ);
staticEnv->sort(); staticEnv->sort();
env->values[displ++] = &v; env->values[displ++] = v;
varNames.insert((string) name); varNames.insert((string) name);
} }

View file

@ -591,7 +591,7 @@ Value * EvalState::addConstant(const string & name, Value & v)
void 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; baseEnv.values[baseEnvDispl++] = v;
string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name;
baseEnv.values[0]->attrs->push_back(Attr(symbols.create(name2), v)); 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. */ user. */
for (auto & i : *args[0]->attrs) for (auto & i : *args[0]->attrs)
if (lambda.formals->argNames.find(i.name) == lambda.formals->argNames.end()) 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 abort(); // can't happen
} }
} }

View file

@ -346,7 +346,7 @@ void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
Displacement displ = 0; Displacement displ = 0;
for (auto & i : attrs) 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. // No need to sort newEnv since attrs is in sorted order.
@ -391,13 +391,13 @@ void ExprLambda::bindVars(const std::shared_ptr<const StaticEnv> &env)
Displacement displ = 0; Displacement displ = 0;
if (!arg.empty()) newEnv.vars.emplace_back(arg, displ++); if (!arg.empty()) newEnv->vars.emplace_back(arg, displ++);
if (hasFormals()) { if (hasFormals()) {
for (auto & i : formals->formals) 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) for (auto & i : formals->formals)
if (i.def) i.def->bindVars(newEnv); if (i.def) i.def->bindVars(newEnv);
@ -406,7 +406,7 @@ void ExprLambda::bindVars(const std::shared_ptr<const StaticEnv> &env)
body->bindVars(newEnv); body->bindVars(newEnv);
} }
void ExprCall::bindVars(const StaticEnv & env) void ExprCall::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook) if (debuggerHook)
staticenv = env; staticenv = env;
@ -416,7 +416,7 @@ void ExprCall::bindVars(const StaticEnv & env)
e->bindVars(env); e->bindVars(env);
} }
void ExprLet::bindVars(const StaticEnv & env) void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook) if (debuggerHook)
staticenv = env; staticenv = env;
@ -425,7 +425,7 @@ void ExprLet::bindVars(const StaticEnv & env)
Displacement displ = 0; Displacement displ = 0;
for (auto & i : attrs->attrs) 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. // No need to sort newEnv since attrs->attrs is in sorted order.

View file

@ -188,7 +188,7 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
unsigned int displ = 0; unsigned int displ = 0;
for (auto & attr : *vScope->attrs) { for (auto & attr : *vScope->attrs) {
staticEnv.vars.emplace_back(attr.name, displ); staticEnv->vars.emplace_back(attr.name, displ);
env->values[displ++] = attr.value; env->values[displ++] = attr.value;
} }
@ -3750,7 +3750,7 @@ void EvalState::createBaseEnv()
because attribute lookups expect it to be sorted. */ because attribute lookups expect it to be sorted. */
baseEnv.values[0]->attrs->sort(); baseEnv.values[0]->attrs->sort();
staticBaseEnv.sort(); staticBaseEnv->sort();
/* Note: we have to initialize the 'derivation' constant *after* /* Note: we have to initialize the 'derivation' constant *after*
building baseEnv/staticBaseEnv because it uses 'builtins'. */ building baseEnv/staticBaseEnv because it uses 'builtins'. */