lixexpr/primops: Migrate import helper fn to return a Value

Part of #1136

Change-Id: Ia2cdd540a105ae874430c0f6ba456d4d6a6a6964
This commit is contained in:
skye
2026-04-07 22:37:25 -04:00
parent 86126d6c89
commit bb9f9cf553
2 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
---
name: scopedImport
implementation: "[](EvalState & state, Value ** args, Value & v) { import(state, *args[1], args[0], v); }"
implementation: "[](EvalState & state, Value ** args, Value & v) { v = import(state, *args[1], args[0]); }"
args: [scope, path]
renameInGlobalScope: false
---
+7 -6
View File
@@ -173,7 +173,7 @@ static void mkOutputString(
/* Load and evaluate an expression from path specified by the
argument. */
static void import(EvalState & state, Value & vPath, Value * vScope, Value & v)
static Value import(EvalState & state, Value & vPath, Value * vScope)
{
auto path = realisePath(state, vPath);
auto path2 = path.canonical().abs();
@@ -223,12 +223,13 @@ static void import(EvalState & state, Value & vPath, Value * vScope, Value & v)
noPos,
"while evaluating imported-drv-to-derivation.nix.gen.hh"
);
v = {NewValueAs::app, state.ctx.mem, *state.ctx.caches.vImportedDrvToDerivation, w};
Value v = {NewValueAs::app, state.ctx.mem, *state.ctx.caches.vImportedDrvToDerivation, w};
state.forceAttrs(v, noPos, "while calling imported-drv-to-derivation.nix.gen.hh");
return v;
}
else if (path2 == corepkgsPrefix + "fetchurl.nix") {
v = state.eval(state.ctx.parseExprFromString(
return state.eval(state.ctx.parseExprFromString(
#include "fetchurl.nix.gen.hh"
, CanonPath::root
));
@@ -236,7 +237,7 @@ static void import(EvalState & state, Value & vPath, Value * vScope, Value & v)
else {
if (!vScope)
v = state.evalFile(path);
return state.evalFile(path);
else {
state.forceAttrs(*vScope, noPos, "while evaluating the first argument passed to builtins.scopedImport");
@@ -259,14 +260,14 @@ static void import(EvalState & state, Value & vPath, Value * vScope, Value & v)
debug("evaluating file '%1%'", path);
Expr & e = state.ctx.parseExprFromFile(state.ctx.paths.resolveExprPath(path), staticEnv);
v = e.eval(state, *env);
return e.eval(state, *env);
}
}
}
static void prim_import(EvalState & state, Value * * args, Value & v)
{
import(state, *args[0], nullptr, v);
v = import(state, *args[0], nullptr);
}
/* Want reasonable symbol names, so extern C */