From c068aeaf61cb14acdb443413bb2686764f115c2f Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 26 Apr 2025 22:14:05 +0200 Subject: [PATCH] treewide: don't determinePos in autoCallFunction add a position parameter to the autocaller instead, and pass it much more accurate position information where we have it easily available Change-Id: If2f1c3006ca3f2b413492842905d079a8b752542 --- lix/legacy/nix-instantiate.cc | 2 +- lix/libcmd/installables.cc | 2 +- lix/libcmd/repl.cc | 2 +- lix/libexpr/attr-path.cc | 2 +- lix/libexpr/eval.cc | 6 ++---- lix/libexpr/eval.hh | 2 +- lix/libexpr/get-drvs.cc | 19 +++++++++++++++---- lix/nix/repl.cc | 2 +- subprojects/nix-eval-jobs/src/worker.cc | 4 ++-- 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index 7ba3e0d51..9f19d5024 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -47,7 +47,7 @@ void processExpr(EvalState & state, const Strings & attrPaths, if (autoArgs.empty()) vRes = v; else - state.autoCallFunction(autoArgs, v, vRes); + state.autoCallFunction(autoArgs, v, vRes, noPos); if (output == okXML) printValueAsXML(state, strict, location, vRes, std::cout, context, noPos); else if (output == okJSON) { diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index e2fb2ea57..30ebcf050 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -239,7 +239,7 @@ void SourceExprCommand::completeInstallable(EvalState & state, AddCompletions & Value &v1(*v); state.forceValue(v1, pos); Value v2; - state.autoCallFunction(*autoArgs, v1, v2); + state.autoCallFunction(*autoArgs, v1, v2, pos); if (v2.type() == nAttrs) { for (auto & i : *v2.attrs) { diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index fe2984cab..b9c301ce0 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -885,7 +885,7 @@ void NixRepl::loadFile(const Path & path) loadedFiles.push_back(path); Value v, v2; state.evalFile(state.aio.blockOn(lookupFileArg(evaluator, path)).unwrap(always_progresses), v); - state.autoCallFunction(*autoArgs, v, v2); + state.autoCallFunction(*autoArgs, v, v2, noPos); addAttrsToScope(v2); } diff --git a/lix/libexpr/attr-path.cc b/lix/libexpr/attr-path.cc index 670d18814..a055e6827 100644 --- a/lix/libexpr/attr-path.cc +++ b/lix/libexpr/attr-path.cc @@ -85,7 +85,7 @@ std::pair findAlongAttrPath(EvalState & state, const std::strin /* Evaluate the expression. */ Value * vNew = state.ctx.mem.allocValue(); - state.autoCallFunction(autoArgs, *v, *vNew); + state.autoCallFunction(autoArgs, *v, *vNew, pos); v = vNew; state.forceValue(*v, noPos); diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 698f53c81..564b0ab8a 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -1787,10 +1787,8 @@ void EvalStatistics::addCall(ExprLambda & fun) } -void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res) +void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res, PosIdx pos) { - auto pos = fun.determinePos(noPos); - forceValue(fun, pos); if (fun.type() == nAttrs) { @@ -1799,7 +1797,7 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res) Value * v = ctx.mem.allocValue(); callFunction(*found->value, fun, *v, pos); forceValue(*v, pos); - return autoCallFunction(args, *v, res); + return autoCallFunction(args, *v, res, pos); } } diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 6b96d46f8..81108a000 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -854,7 +854,7 @@ public: * Automatically call a function for which each argument has a * default value or has a binding in the `args` map. */ - void autoCallFunction(Bindings & args, Value & fun, Value & res); + void autoCallFunction(Bindings & args, Value & fun, Value & res, PosIdx pos); void mkPos(Value & v, PosIdx pos); diff --git a/lix/libexpr/get-drvs.cc b/lix/libexpr/get-drvs.cc index cedfd05aa..8bcbdc2e2 100644 --- a/lix/libexpr/get-drvs.cc +++ b/lix/libexpr/get-drvs.cc @@ -415,13 +415,13 @@ static std::regex attrRegex = regex::parse("[A-Za-z_][A-Za-z0-9-_+]*"); /* Evaluate value `v'. If it evaluates to a set of type `derivation', then put information about it in `drvs'. If it evaluates to a different kind of set recurse (unless it's already in `done'). */ -static void getDerivations(EvalState & state, Value & vIn, +static void getDerivations(EvalState & state, Value & vIn, PosIdx pos, const std::string & pathPrefix, Bindings & autoArgs, DrvInfos & drvs, Done & done, bool ignoreAssertionFailures) { Value v; - state.autoCallFunction(autoArgs, vIn, v); + state.autoCallFunction(autoArgs, vIn, v, pos); bool shouldRecurse = getDerivation(state, v, pathPrefix, drvs, ignoreAssertionFailures); if (!shouldRecurse) { @@ -439,6 +439,7 @@ static void getDerivations(EvalState & state, Value & vIn, getDerivations( state, *elem, + pos, joinedAttrPath, autoArgs, drvs, @@ -481,7 +482,16 @@ static void getDerivations(EvalState & state, Value & vIn, } std::string joinedAttrPath = addToPath(pathPrefix, state.ctx.symbols[attr->name]); if (combineChannels) { - getDerivations(state, *attr->value, joinedAttrPath, autoArgs, drvs, done, ignoreAssertionFailures); + getDerivations( + state, + *attr->value, + attr->pos, + joinedAttrPath, + autoArgs, + drvs, + done, + ignoreAssertionFailures + ); } else if (getDerivation(state, *attr->value, joinedAttrPath, drvs, ignoreAssertionFailures)) { /* If the value of this attribute is itself a set, should we recurse into it? => Only if it has a @@ -503,6 +513,7 @@ static void getDerivations(EvalState & state, Value & vIn, getDerivations( state, *attr->value, + attr->pos, joinedAttrPath, autoArgs, drvs, @@ -519,7 +530,7 @@ void getDerivations(EvalState & state, Value & v, const std::string & pathPrefix Bindings & autoArgs, DrvInfos & drvs, bool ignoreAssertionFailures) { Done done; - getDerivations(state, v, pathPrefix, autoArgs, drvs, done, ignoreAssertionFailures); + getDerivations(state, v, noPos, pathPrefix, autoArgs, drvs, done, ignoreAssertionFailures); } diff --git a/lix/nix/repl.cc b/lix/nix/repl.cc index 4fe51aedd..8895ab78c 100644 --- a/lix/nix/repl.cc +++ b/lix/nix/repl.cc @@ -69,7 +69,7 @@ struct CmdRepl : RawInstallablesCommand state->forceValue(*val, pos); auto autoArgs = getAutoArgs(*evaluator); auto valPost = evaluator->mem.allocValue(); - state->autoCallFunction(*autoArgs, *val, *valPost); + state->autoCallFunction(*autoArgs, *val, *valPost, pos); state->forceValue(*valPost, pos); values.push_back( {valPost, what }); } else { diff --git a/subprojects/nix-eval-jobs/src/worker.cc b/subprojects/nix-eval-jobs/src/worker.cc index 8431e019d..e10a39378 100644 --- a/subprojects/nix-eval-jobs/src/worker.cc +++ b/subprojects/nix-eval-jobs/src/worker.cc @@ -59,7 +59,7 @@ static nix::Value *releaseExprTopLevelValue(nix::EvalState &state, auto vRoot = state.ctx.mem.allocValue(); - state.autoCallFunction(autoArgs, vTop, *vRoot); + state.autoCallFunction(autoArgs, vTop, *vRoot, {}); return vRoot; } @@ -172,7 +172,7 @@ void worker(nix::ref evaluator, .first; auto v = evaluator->mem.allocValue(); - state->autoCallFunction(autoArgs, *vTmp, *v); + state->autoCallFunction(autoArgs, *vTmp, *v, {}); if (v->type() == nix::nAttrs) { if (auto drvInfo = nix::getDerivation(*state, *v, false)) {