libexpr: Migrate EvalState::autoCallFunction to return a Value
Change-Id: I426c3d413b18848090dd05674a08e5fb6a6a6964
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
+1
-2
@@ -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.
|
||||
|
||||
@@ -83,9 +83,7 @@ findAlongAttrPath(EvalState & state, const std::string & attrPath, Bindings & au
|
||||
auto attrIndex = string2Int<unsigned int>(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,
|
||||
|
||||
+5
-8
@@ -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<AttrsPattern *>(fun.lambda().fun->pattern.get());
|
||||
if (!pattern) {
|
||||
res = fun;
|
||||
return;
|
||||
return fun;
|
||||
}
|
||||
|
||||
auto attrs = ctx.buildBindings(std::max(static_cast<uint32_t>(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(
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+1
-2
@@ -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 {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user