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
This commit is contained in:
eldritch horrors
2025-04-27 17:38:57 +00:00
parent db738ddb14
commit c068aeaf61
9 changed files with 25 additions and 16 deletions
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -85,7 +85,7 @@ std::pair<Value *, PosIdx> 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);
+2 -4
View File
@@ -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);
}
}
+1 -1
View File
@@ -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);
+15 -4
View File
@@ -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);
}
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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<nix::eval_cache::CachingEvaluator> 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)) {