From 71c392ae0fde3105686b9880a59103fb8cbee087 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 3 Dec 2024 20:38:41 +0100 Subject: [PATCH] libexpr: associate parsing and builtins with EvalContext Change-Id: Iff56246bb344405c9acecb967423554d25fe47f5 --- lix/legacy/nix-env.cc | 2 +- lix/legacy/user-env.cc | 2 +- lix/libexpr/eval.cc | 6 +++--- lix/libexpr/flake/flake.cc | 4 ++-- lix/libexpr/primops.cc | 18 +++++++++--------- lix/nix/prefetch.cc | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index d45d65d56..053e5d09b 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -416,7 +416,7 @@ static void queryInstSources(EvalState & state, loadSourceExpr(state, *instSource.nixExprPath, vArg); for (auto & i : args) { - Expr & eFun = state.parseExprFromString(i, CanonPath::fromCwd()); + Expr & eFun = state.ctx.parseExprFromString(i, CanonPath::fromCwd()); Value vFun, vTmp; state.eval(eFun, vFun); vTmp.mkApp(&vFun, &vArg); diff --git a/lix/legacy/user-env.cc b/lix/legacy/user-env.cc index ea3f9e58a..4e0fa9442 100644 --- a/lix/legacy/user-env.cc +++ b/lix/legacy/user-env.cc @@ -97,7 +97,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, /* Get the environment builder expression. */ Value envBuilder; - state.eval(state.parseExprFromString( + state.eval(state.ctx.parseExprFromString( #include "buildenv.nix.gen.hh" , CanonPath::root), envBuilder); diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 8ddfec48f..e6b7d1b30 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -953,14 +953,14 @@ void EvalState::evalFile(const SourcePath & path_, Value & v) } debug("evaluating file '%1%'", resolvedPath); - Expr & e = parseExprFromFile(ctx.paths.checkSourcePath(resolvedPath)); + Expr & e = ctx.parseExprFromFile(ctx.paths.checkSourcePath(resolvedPath)); try { auto dts = ctx.debug ? makeDebugTraceStacker( *this, e, - this->builtins.env, + ctx.builtins.env, e.getPos() ? std::make_shared(ctx.positions[e.getPos()]) : nullptr, "while evaluating the file '%1%':", resolvedPath.to_string()) : nullptr; @@ -985,7 +985,7 @@ void EvalState::resetFileCache() void EvalState::eval(Expr & e, Value & v) { - e.eval(*this, builtins.env, v); + e.eval(*this, ctx.builtins.env, v); } diff --git a/lix/libexpr/flake/flake.cc b/lix/libexpr/flake/flake.cc index bfa36c301..6be09f370 100644 --- a/lix/libexpr/flake/flake.cc +++ b/lix/libexpr/flake/flake.cc @@ -243,7 +243,7 @@ static Flake getFlake( // FIXME: symlink attack auto resolvedFlakeFile = resolveExprPath(state.ctx.paths.checkSourcePath(CanonPath(flakeFile))); - Expr & flakeExpr = state.parseExprFromFile(state.ctx.paths.checkSourcePath(resolvedFlakeFile)); + Expr & flakeExpr = state.ctx.parseExprFromFile(state.ctx.paths.checkSourcePath(resolvedFlakeFile)); // Enforce that 'flake.nix' is a direct attrset, not a computation. if (!(dynamic_cast(&flakeExpr))) { @@ -793,7 +793,7 @@ void callFlake(EvalState & state, if (!state.caches.vCallFlake) { state.caches.vCallFlake = allocRootValue(state.ctx.mem.allocValue()); - state.eval(state.parseExprFromString( + state.eval(state.ctx.parseExprFromString( #include "call-flake.nix.gen.hh" , CanonPath::root), **state.caches.vCallFlake); } diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index a2cbedf4e..f4a092f53 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -208,7 +208,7 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v if (!state.caches.vImportedDrvToDerivation) { state.caches.vImportedDrvToDerivation = allocRootValue(state.ctx.mem.allocValue()); - state.eval(state.parseExprFromString( + state.eval(state.ctx.parseExprFromString( #include "imported-drv-to-derivation.nix.gen.hh" , CanonPath::root), **state.caches.vImportedDrvToDerivation); } @@ -223,7 +223,7 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v } else if (path2 == corepkgsPrefix + "fetchurl.nix") { - state.eval(state.parseExprFromString( + state.eval(state.ctx.parseExprFromString( #include "fetchurl.nix.gen.hh" , CanonPath::root), v); } @@ -235,10 +235,10 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v state.forceAttrs(*vScope, pos, "while evaluating the first argument passed to builtins.scopedImport"); Env * env = &state.ctx.mem.allocEnv(vScope->attrs->size()); - env->up = &state.builtins.env; + env->up = &state.ctx.builtins.env; auto staticEnv = std::make_shared( - nullptr, state.builtins.staticEnv.get(), vScope->attrs->size() + nullptr, state.ctx.builtins.staticEnv.get(), vScope->attrs->size() ); unsigned int displ = 0; @@ -251,7 +251,7 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v // args[0]->attrs is already sorted. debug("evaluating file '%1%'", path); - Expr & e = state.parseExprFromFile(resolveExprPath(path), staticEnv); + Expr & e = state.ctx.parseExprFromFile(resolveExprPath(path), staticEnv); e.eval(state, *env, v); } @@ -332,7 +332,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v) auto output = runProgram(program, true, commandArgs); Expr * parsed; try { - parsed = &state.parseExprFromString(std::move(output), CanonPath::root); + parsed = &state.ctx.parseExprFromString(std::move(output), CanonPath::root); } catch (Error & e) { e.addTrace(state.ctx.positions[pos], "while parsing the output from '%1%'", program); throw; @@ -1382,7 +1382,7 @@ static void prim_readDir(EvalState & state, const PosIdx pos, Value * * args, Va auto epath = state.ctx.mem.allocValue(); epath->mkPath(path + name); if (!readFileType) - readFileType = &state.builtins.get("readFileType"); + readFileType = &state.ctx.builtins.get("readFileType"); attr.mkApp(readFileType, epath); } else { // This branch of the conditional is much more likely. @@ -2847,8 +2847,8 @@ void EvalBuiltins::createBaseEnv(const SearchPath & searchPath, const Path & sto char code[] = #include "primops/derivation.nix.gen.hh" ; - auto & expr = *state.parse( - code, sizeof(code), Pos::Hidden{}, {CanonPath::root}, state.builtins.staticEnv + auto & expr = *state.ctx.parse( + code, sizeof(code), Pos::Hidden{}, {CanonPath::root}, state.ctx.builtins.staticEnv ); state.eval(expr, v); }, diff --git a/lix/nix/prefetch.cc b/lix/nix/prefetch.cc index 29333416f..04fed2ba0 100644 --- a/lix/nix/prefetch.cc +++ b/lix/nix/prefetch.cc @@ -29,7 +29,7 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url) Value vMirrors; // FIXME: use nixpkgs flake - state.eval(state.parseExprFromString( + state.eval(state.ctx.parseExprFromString( "import ", CanonPath::root), vMirrors);