diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index c11d8c460..5eeb0c500 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -46,7 +46,7 @@ void processExpr(EvalState & state, const Strings & attrPaths, if (autoArgs.empty()) vRes = v; else - state.autoCallFunction(autoArgs, v, vRes, noPos); + vRes = state.autoCallFunction(autoArgs, v, noPos); if (output == okRaw) std::cout << *state.coerceToString(noPos, vRes, context, "while generating the nix-instantiate output", StringCoercionMode::Strict); // We intentionally don't output a newline here. The default PS1 for Bash in NixOS starts with a newline diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index d7c5d4a3d..f8b78d58c 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -236,8 +236,7 @@ void SourceExprCommand::completeInstallable(EvalState & state, AddCompletions & auto [v1, pos] = findAlongAttrPath(state, prefix_, *autoArgs, root); state.forceValue(v1, pos); - Value v2; - state.autoCallFunction(*autoArgs, v1, v2, pos); + Value v2 = state.autoCallFunction(*autoArgs, v1, pos); if (v2.type() == nAttrs) { for (auto & i : *v2.attrs()) { diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index 9a4d01f0f..efc09ec48 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -1288,9 +1288,8 @@ void NixRepl::loadFile(const Path & path) try { loaded.remove(loadable); loaded.push_back(loadable); - Value v2; Value v = state.evalFile(state.aio.blockOn(lookupFileArg(evaluator, path)).unwrap(always_progresses)); - state.autoCallFunction(*autoArgs, v, v2, noPos); + Value v2 = state.autoCallFunction(*autoArgs, v, noPos); addAttrsToScope(v2); } catch (...) { // In case of failure, do not keep the loaded path. diff --git a/lix/libexpr/attr-path.cc b/lix/libexpr/attr-path.cc index 509bf88b3..8f7c509c7 100644 --- a/lix/libexpr/attr-path.cc +++ b/lix/libexpr/attr-path.cc @@ -83,9 +83,7 @@ findAlongAttrPath(EvalState & state, const std::string & attrPath, Bindings & au auto attrIndex = string2Int(attr); /* Evaluate the expression. */ - Value vNew; - state.autoCallFunction(autoArgs, v, vNew, pos); - v = vNew; + v = state.autoCallFunction(autoArgs, v, pos); state.forceValue(v, noPos); /* It should evaluate to either a set or an expression, diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 7856a3bec..200cdc259 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -1306,8 +1306,7 @@ void EvalStatistics::addCall(ExprLambda & fun) functionCalls[&fun]++; } - -void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res, PosIdx pos) +Value EvalState::autoCallFunction(Bindings & args, Value & fun, PosIdx pos) { forceValue(fun, pos); @@ -1316,18 +1315,16 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res, PosI if (found) { Value v = callFunction(found->value, fun, pos); forceValue(v, pos); - return autoCallFunction(args, v, res, pos); + return autoCallFunction(args, v, pos); } } if (!fun.isLambda()) { - res = fun; - return; + return fun; } auto pattern = dynamic_cast(fun.lambda().fun->pattern.get()); if (!pattern) { - res = fun; - return; + return fun; } auto attrs = ctx.buildBindings(std::max(static_cast(pattern->formals.size()), args.size())); @@ -1362,7 +1359,7 @@ https://docs.lix.systems/manual/lix/stable/language/constructs.html#functions)", } Value vAttrs{NewValueAs::attrs, attrs.finish()}; - res = callFunction(fun, vAttrs, pos); + return callFunction(fun, vAttrs, pos); } void EvalState::concatLists( diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index e571e8ba2..76bb0349b 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -798,7 +798,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, PosIdx pos); + Value autoCallFunction(Bindings & args, Value & fun, PosIdx pos); void mkPos(Value & v, PosIdx pos); diff --git a/lix/libexpr/get-drvs.cc b/lix/libexpr/get-drvs.cc index c08f296ed..8fd4c7a89 100644 --- a/lix/libexpr/get-drvs.cc +++ b/lix/libexpr/get-drvs.cc @@ -451,8 +451,7 @@ static void getDerivations(EvalState & state, Value & vIn, PosIdx pos, DrvInfos & drvs, Done & done, bool ignoreAssertionFailures) { - Value v; - state.autoCallFunction(autoArgs, vIn, v, pos); + Value v = state.autoCallFunction(autoArgs, vIn, pos); bool shouldRecurse = getDerivation(state, v, pathPrefix, drvs, ignoreAssertionFailures); if (!shouldRecurse) { diff --git a/lix/nix/repl.cc b/lix/nix/repl.cc index 2f46a9ea4..1626f7012 100644 --- a/lix/nix/repl.cc +++ b/lix/nix/repl.cc @@ -68,8 +68,7 @@ struct CmdRepl : RawInstallablesCommand auto what = installable.what(); state->forceValue(val, pos); auto autoArgs = getAutoArgs(*evaluator); - Value valPost; - state->autoCallFunction(*autoArgs, val, valPost, pos); + Value valPost = state->autoCallFunction(*autoArgs, val, 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 20e75133c..b06dac581 100644 --- a/subprojects/nix-eval-jobs/src/worker.cc +++ b/subprojects/nix-eval-jobs/src/worker.cc @@ -57,11 +57,7 @@ static nix::Value releaseExprTopLevelValue(nix::EvalState &state, .unwrap()); } - nix::Value vRoot; - - state.autoCallFunction(autoArgs, vTop, vRoot, {}); - - return vRoot; + return state.autoCallFunction(autoArgs, vTop, {}); } static std::string attrPathJoin(nix::JSON input) { @@ -196,8 +192,7 @@ try { nix::findAlongAttrPath(*state, attrPathS, autoArgs, vRoot) .first; - nix::Value v; - state->autoCallFunction(autoArgs, vTmp, v, {}); + nix::Value v = state->autoCallFunction(autoArgs, vTmp, {}); if (v.type() == nix::nAttrs) { if (auto drvInfo = nix::getDerivation(*state, v, false)) {