libexpr: Migrate EvalState::evalFile to return a Value

Change-Id: I19ce8623477dd96628476b3e3dd58cfd6a6a6964
This commit is contained in:
skye
2026-02-28 15:53:10 -05:00
parent debf5554e0
commit f856d4fd25
9 changed files with 24 additions and 28 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ static void loadSourceExpr(EvalState & state, const SourcePath & path_, Value &
auto st = path.stat();
if (isNixExpr(state.ctx.paths, path, st))
state.evalFile(path, v);
v = state.evalFile(path);
/* The path is a directory. Put the Nix expressions in the
directory in a set, with the file name of each expression as
+1 -2
View File
@@ -20,8 +20,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
throw Error("profile '%s' is incompatible with 'nix-env'; please use 'nix profile' instead", userEnv);
auto manifestFile = userEnv + "/manifest.nix";
if (pathExists(manifestFile)) {
Value v;
state.evalFile(CanonPath(manifestFile), v);
Value v = state.evalFile(CanonPath(manifestFile));
Bindings & bindings(*state.ctx.mem.allocBindings(0));
getDerivations(state, v, "", bindings, elems, false);
}
+1 -1
View File
@@ -455,7 +455,7 @@ Installables SourceExprCommand::parseInstallables(
vFile = state.eval(e);
}
else if (file)
state.evalFile(state.aio.blockOn(lookupFileArg(*evaluator, *file)).unwrap(), vFile);
vFile = state.evalFile(state.aio.blockOn(lookupFileArg(*evaluator, *file)).unwrap());
else {
auto & e = evaluator->parseExprFromString(*expr, CanonPath::fromCwd());
vFile = state.eval(e);
+2 -4
View File
@@ -1288,10 +1288,8 @@ void NixRepl::loadFile(const Path & path)
try {
loaded.remove(loadable);
loaded.push_back(loadable);
Value v, v2;
state.evalFile(
state.aio.blockOn(lookupFileArg(evaluator, path)).unwrap(always_progresses), v
);
Value v2;
Value v = state.evalFile(state.aio.blockOn(lookupFileArg(evaluator, path)).unwrap(always_progresses));
state.autoCallFunction(*autoArgs, v, v2, noPos);
addAttrsToScope(v2);
} catch (...) {
+12 -10
View File
@@ -931,19 +931,17 @@ struct CachedEvalFile
explicit CachedEvalFile(Value result): result(result) {}
};
void EvalState::evalFile(const SourcePath & path_, Value & v)
Value EvalState::evalFile(const SourcePath & path_)
{
auto path = ctx.paths.checkSourcePath(path_);
if (auto i = ctx.caches.fileEval.find(path); i != ctx.caches.fileEval.end()) {
v = i->second->result;
return;
return i->second->result;
}
auto resolvedPath = ctx.paths.resolveExprPath(path);
if (auto i = ctx.caches.fileEval.find(resolvedPath); i != ctx.caches.fileEval.end()) {
v = i->second->result;
return;
return i->second->result;
}
debug("evaluating file '%1%'", resolvedPath);
@@ -959,15 +957,19 @@ void EvalState::evalFile(const SourcePath & path_, Value & v)
"while evaluating the file '%1%':", resolvedPath.to_string())
: nullptr;
v = eval(e);
Value v = eval(e);
auto cache = std::allocate_shared<CachedEvalFile>(TraceableAllocator<CachedEvalFile>(), v);
ctx.caches.fileEval[resolvedPath] = cache;
if (path != resolvedPath) {
ctx.caches.fileEval[path] = cache;
}
return v;
} catch (Error & e) {
e.addTrace(nullptr, "while evaluating the file '%1%':", resolvedPath.to_string());
throw;
}
auto cache = std::allocate_shared<CachedEvalFile>(TraceableAllocator<CachedEvalFile>(), v);
ctx.caches.fileEval[resolvedPath] = cache;
if (path != resolvedPath) ctx.caches.fileEval[path] = cache;
}
+1 -1
View File
@@ -646,7 +646,7 @@ public:
/**
* Evaluate an expression read from the given file to normal form.
*/
void evalFile(const SourcePath & path, Value & v);
Value evalFile(const SourcePath & path);
void resetFileCache();
+1 -1
View File
@@ -225,7 +225,7 @@ static void import(EvalState & state, Value & vPath, Value * vScope, Value & v)
else {
if (!vScope)
state.evalFile(path, v);
v = state.evalFile(path);
else {
state.forceAttrs(*vScope, noPos, "while evaluating the first argument passed to builtins.scopedImport");
+3 -5
View File
@@ -204,11 +204,9 @@ static int main_nix_prefetch_url(AsyncIoRoot & aio, std::string programName, Str
throw UsageError("you must specify a URL");
url = args[0];
} else {
Value vRoot;
state->evalFile(
evaluator->paths.resolveExprPath(
aio.blockOn(lookupFileArg(*evaluator, args.empty() ? "." : args[0])).unwrap()),
vRoot);
Value vRoot = state->evalFile(evaluator->paths.resolveExprPath(
aio.blockOn(lookupFileArg(*evaluator, args.empty() ? "." : args[0])).unwrap()
));
Value v(findAlongAttrPath(*state, attrPath, autoArgs, vRoot).first);
state->forceAttrs(v, noPos, "while evaluating the source attribute to prefetch");
+2 -3
View File
@@ -52,10 +52,9 @@ static nix::Value releaseExprTopLevelValue(nix::EvalState &state,
nix::CanonPath::fromCwd());
vTop = state.eval(e);
} else {
state.evalFile(
vTop = state.evalFile(
state.aio.blockOn(nix::lookupFileArg(state.ctx, args.releaseExpr))
.unwrap(),
vTop);
.unwrap());
}
nix::Value vRoot;