From bb9f9cf553fbb5b474f4115e434f11e5207177f7 Mon Sep 17 00:00:00 2001 From: skye Date: Fri, 3 Apr 2026 13:45:31 -0400 Subject: [PATCH] lixexpr/primops: Migrate import helper fn to return a Value Part of #1136 Change-Id: Ia2cdd540a105ae874430c0f6ba456d4d6a6a6964 --- lix/libexpr/builtins/scopedImport.md | 2 +- lix/libexpr/primops.cc | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lix/libexpr/builtins/scopedImport.md b/lix/libexpr/builtins/scopedImport.md index e2627ca3e..2c35c9446 100644 --- a/lix/libexpr/builtins/scopedImport.md +++ b/lix/libexpr/builtins/scopedImport.md @@ -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 --- diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index b617f9fe5..1b0ce2b8e 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -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 */