From cb8262e11c388dfa8fdf0298dc6d9a1bff12a7e4 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 27 Nov 2024 02:09:08 +0100 Subject: [PATCH] libexpr: remove EvalState::rootPath this belongs to lazy trees, which we neither have nor intend to have. we will keep SourcePath as that may come in handy at some later date. Change-Id: I44b8f1dd6c435d7486c393fabdcd272766b2b56b --- lix/legacy/nix-build.cc | 4 ++-- lix/legacy/nix-env.cc | 4 ++-- lix/legacy/nix-instantiate.cc | 2 +- lix/legacy/user-env.cc | 2 +- lix/libcmd/cmd-profiles.cc | 2 +- lix/libcmd/common-eval-args.cc | 8 ++++---- lix/libcmd/installables.cc | 2 +- lix/libcmd/repl.cc | 2 +- lix/libexpr/eval.cc | 4 ++-- lix/libexpr/eval.hh | 6 ------ lix/libexpr/meson.build | 1 - lix/libexpr/paths.cc | 10 ---------- lix/libexpr/primops.cc | 6 +++--- lix/nix/eval.cc | 2 +- lix/nix/prefetch.cc | 2 +- lix/nix/upgrade-nix.cc | 2 +- tests/unit/libexpr-support/tests/libexpr.hh | 2 +- tests/unit/libexpr/value/print.cc | 2 +- 18 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 lix/libexpr/paths.cc diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index 7064e93df..98e7f82a4 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -240,7 +240,7 @@ static void main_nix_build(std::string programName, Strings argv) else for (auto i : left) { if (fromArgs) - exprs.push_back(state->parseExprFromString(std::move(i), state->rootPath(CanonPath::fromCwd()))); + exprs.push_back(state->parseExprFromString(std::move(i), CanonPath::fromCwd())); else { auto absolute = i; try { @@ -338,7 +338,7 @@ static void main_nix_build(std::string programName, Strings argv) try { auto & expr = state->parseExprFromString( "(import {}).bashInteractive", - state->rootPath(CanonPath::fromCwd())); + CanonPath::fromCwd()); Value v; state->eval(expr, v); diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index f20673327..8814346d0 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -415,7 +415,7 @@ static void queryInstSources(EvalState & state, loadSourceExpr(state, *instSource.nixExprPath, vArg); for (auto & i : args) { - Expr & eFun = state.parseExprFromString(i, state.rootPath(CanonPath::fromCwd())); + Expr & eFun = state.parseExprFromString(i, CanonPath::fromCwd()); Value vFun, vTmp; state.eval(eFun, vFun); vTmp.mkApp(&vFun, &vArg); @@ -1528,7 +1528,7 @@ static int main_nix_env(std::string programName, Strings argv) globals.instSource.nixExprPath = std::make_shared( file != "" ? lookupFileArg(*globals.state, file) - : globals.state->rootPath(CanonPath(nixExprPath))); + : CanonPath(nixExprPath)); globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state); diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index af6a67676..c5cdc0641 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -184,7 +184,7 @@ static int main_nix_instantiate(std::string programName, Strings argv) for (auto & i : files) { Expr & e = fromArgs - ? state->parseExprFromString(i, state->rootPath(CanonPath::fromCwd())) + ? state->parseExprFromString(i, CanonPath::fromCwd()) : state->parseExprFromFile(resolveExprPath(state->checkSourcePath(lookupFileArg(*state, i)))); processExpr(*state, attrPaths, parseOnly, strict, autoArgs, evalOnly, outputKind, xmlOutputSourceLocation, e); diff --git a/lix/legacy/user-env.cc b/lix/legacy/user-env.cc index cf918b9c5..ad238622f 100644 --- a/lix/legacy/user-env.cc +++ b/lix/legacy/user-env.cc @@ -100,7 +100,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, Value envBuilder; state.eval(state.parseExprFromString( #include "buildenv.nix.gen.hh" - , state.rootPath(CanonPath::root)), envBuilder); + , CanonPath::root), envBuilder); /* Construct a Nix expression that calls the user environment builder with the manifest as argument. */ diff --git a/lix/libcmd/cmd-profiles.cc b/lix/libcmd/cmd-profiles.cc index 994e29829..a14940629 100644 --- a/lix/libcmd/cmd-profiles.cc +++ b/lix/libcmd/cmd-profiles.cc @@ -20,7 +20,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv) auto manifestFile = userEnv + "/manifest.nix"; if (pathExists(manifestFile)) { Value v; - state.evalFile(state.rootPath(CanonPath(manifestFile)), v); + state.evalFile(CanonPath(manifestFile), v); Bindings & bindings(*state.allocBindings(0)); getDerivations(state, v, "", bindings, elems, false); } diff --git a/lix/libcmd/common-eval-args.cc b/lix/libcmd/common-eval-args.cc index 7d82dc234..32866233e 100644 --- a/lix/libcmd/common-eval-args.cc +++ b/lix/libcmd/common-eval-args.cc @@ -177,7 +177,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state) for (auto & i : autoArgs) { auto v = state.allocValue(); if (i.second[0] == 'E') - state.mkThunk_(*v, state.parseExprFromString(i.second.substr(1), state.rootPath(CanonPath::fromCwd()))); + state.mkThunk_(*v, state.parseExprFromString(i.second.substr(1), CanonPath::fromCwd())); else v->mkString(((std::string_view) i.second).substr(1)); res.insert(state.symbols.create(i.first), v); @@ -196,18 +196,18 @@ SourcePath lookupFileArg(EvalState & state, std::string_view fileArg) /* locked */ false ); StorePath const storePath = downloaded.tree.storePath; - return state.rootPath(CanonPath(state.store->toRealPath(storePath))); + return CanonPath(state.store->toRealPath(storePath)); } else if (fileArg.starts_with("flake:")) { experimentalFeatureSettings.require(Xp::Flakes); static constexpr size_t FLAKE_LEN = std::string_view("flake:").size(); auto flakeRef = parseFlakeRef(std::string(fileArg.substr(FLAKE_LEN)), {}, true, false); auto storePath = flakeRef.resolve(state.store).fetchTree(state.store).first.storePath; - return state.rootPath(CanonPath(state.store->toRealPath(storePath))); + return CanonPath(state.store->toRealPath(storePath)); } else if (fileArg.size() > 2 && fileArg.at(0) == '<' && fileArg.at(fileArg.size() - 1) == '>') { Path p(fileArg.substr(1, fileArg.size() - 2)); return state.findFile(p); } else { - return state.rootPath(CanonPath::fromCwd(fileArg)); + return CanonPath::fromCwd(fileArg); } } diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index f4e799390..a353feb79 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -447,7 +447,7 @@ Installables SourceExprCommand::parseInstallables( else if (file) state->evalFile(lookupFileArg(*state, *file), *vFile); else { - auto & e = state->parseExprFromString(*expr, state->rootPath(CanonPath::fromCwd())); + auto & e = state->parseExprFromString(*expr, CanonPath::fromCwd()); state->eval(e, *vFile); } diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index 541811ef1..fdb890429 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -1078,7 +1078,7 @@ Value * NixRepl::bindingsToAttrs() Expr & NixRepl::parseString(std::string s) { - return state.parseExprFromString(std::move(s), state.rootPath(CanonPath::fromCwd()), staticEnv); + return state.parseExprFromString(std::move(s), CanonPath::fromCwd(), staticEnv); } diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index c14375532..62d554c39 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -259,7 +259,7 @@ EvalState::EvalState( std::shared_ptr buildStore) : s(symbols) , repair(NoRepair) - , derivationInternal(rootPath(CanonPath("/builtin/derivation.nix"))) + , derivationInternal(CanonPath("/builtin/derivation.nix")) , store(store) , buildStore(buildStore ? buildStore : store) , regexCache(makeRegexCache()) @@ -2762,7 +2762,7 @@ Expr & EvalState::parseStdin() // drainFD should have left some extra space for terminators auto s = make_ref(buffer); buffer.append("\0\0", 2); - return *parse(buffer.data(), buffer.size(), Pos::Stdin{.source = s}, rootPath(CanonPath::fromCwd()), staticBaseEnv); + return *parse(buffer.data(), buffer.size(), Pos::Stdin{.source = s}, CanonPath::fromCwd(), staticBaseEnv); } diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index 166bd3749..acc184b7b 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -328,12 +328,6 @@ public: std::shared_ptr buildStore = nullptr); ~EvalState(); - /** - * Return a `SourcePath` that refers to `path` in the root - * filesystem. - */ - SourcePath rootPath(CanonPath path); - /** * Allow access to a path. */ diff --git a/lix/libexpr/meson.build b/lix/libexpr/meson.build index 8e3bfa4fb..dcbc12e7d 100644 --- a/lix/libexpr/meson.build +++ b/lix/libexpr/meson.build @@ -205,7 +205,6 @@ libexpr_sources = files( 'json-to-value.cc', 'nixexpr.cc', 'parser/parser.cc', - 'paths.cc', 'primops.cc', 'print-ambiguous.cc', 'print.cc', diff --git a/lix/libexpr/paths.cc b/lix/libexpr/paths.cc deleted file mode 100644 index 4fad48c81..000000000 --- a/lix/libexpr/paths.cc +++ /dev/null @@ -1,10 +0,0 @@ -#include "lix/libexpr/eval.hh" - -namespace nix { - -SourcePath EvalState::rootPath(CanonPath path) -{ - return path; -} - -} diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index d722eb59a..c20c38722 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -131,7 +131,7 @@ static SourcePath realisePath(EvalState & state, const PosIdx pos, Value & v, co try { StringMap rewrites = state.realiseContext(context); - auto realPath = state.rootPath(CanonPath(state.toRealPath(rewriteStrings(path.path.abs(), rewrites), context))); + auto realPath = CanonPath(state.toRealPath(rewriteStrings(path.path.abs(), rewrites), context)); return flags.checkForPureEval ? state.checkSourcePath(realPath) @@ -326,7 +326,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), state.rootPath(CanonPath::root)); + parsed = &state.parseExprFromString(std::move(output), CanonPath::root); } catch (Error & e) { e.addTrace(state.positions[pos], "while parsing the output from '%1%'", program); throw; @@ -1540,7 +1540,7 @@ static void addPath( if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) { auto dstPath = fetchToStore( - *state.store, state.rootPath(CanonPath(path)), name, method, &filter, state.repair); + *state.store, CanonPath(path), name, method, &filter, state.repair); if (expectedHash && expectedStorePath != dstPath) state.error( "store path mismatch in (possibly filtered) path added from '%s'", diff --git a/lix/nix/eval.cc b/lix/nix/eval.cc index b705072a5..d99382516 100644 --- a/lix/nix/eval.cc +++ b/lix/nix/eval.cc @@ -68,7 +68,7 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption if (apply) { auto vApply = state->allocValue(); - state->eval(state->parseExprFromString(*apply, state->rootPath(CanonPath::fromCwd())), *vApply); + state->eval(state->parseExprFromString(*apply, CanonPath::fromCwd()), *vApply); auto vRes = state->allocValue(); state->callFunction(*vApply, *v, *vRes, noPos); v = vRes; diff --git a/lix/nix/prefetch.cc b/lix/nix/prefetch.cc index 3085d667f..ad759d1be 100644 --- a/lix/nix/prefetch.cc +++ b/lix/nix/prefetch.cc @@ -31,7 +31,7 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url) // FIXME: use nixpkgs flake state.eval(state.parseExprFromString( "import ", - state.rootPath(CanonPath::root)), + CanonPath::root), vMirrors); state.forceAttrs(vMirrors, noPos, "while evaluating the set of all mirrors"); diff --git a/lix/nix/upgrade-nix.cc b/lix/nix/upgrade-nix.cc index fb08ff2a0..85d34732a 100644 --- a/lix/nix/upgrade-nix.cc +++ b/lix/nix/upgrade-nix.cc @@ -290,7 +290,7 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand auto state = std::make_unique(SearchPath{}, store); auto v = state->allocValue(); - state->eval(state->parseExprFromString(data, state->rootPath(CanonPath("/no-such-path"))), *v); + state->eval(state->parseExprFromString(data, CanonPath("/no-such-path")), *v); Bindings & bindings(*state->allocBindings(0)); auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v).first; diff --git a/tests/unit/libexpr-support/tests/libexpr.hh b/tests/unit/libexpr-support/tests/libexpr.hh index 7196bd5d0..fb7947b46 100644 --- a/tests/unit/libexpr-support/tests/libexpr.hh +++ b/tests/unit/libexpr-support/tests/libexpr.hh @@ -28,7 +28,7 @@ namespace nix { } Value eval(std::string input, bool forceValue = true, const FeatureSettings & fSettings = featureSettings) { Value v; - Expr & e = state.parseExprFromString(input, state.rootPath(CanonPath::root), fSettings); + Expr & e = state.parseExprFromString(input, CanonPath::root, fSettings); state.eval(e, v); if (forceValue) state.forceValue(v, noPos); diff --git a/tests/unit/libexpr/value/print.cc b/tests/unit/libexpr/value/print.cc index 8eaa54b8b..5331057d2 100644 --- a/tests/unit/libexpr/value/print.cc +++ b/tests/unit/libexpr/value/print.cc @@ -388,7 +388,7 @@ TEST_F(ValuePrintingTests, ansiColorsStringElided) TEST_F(ValuePrintingTests, ansiColorsPath) { Value v; - v.mkPath(state.rootPath(CanonPath("puppy"))); + v.mkPath(CanonPath("puppy")); test(v, ANSI_GREEN "/puppy" ANSI_NORMAL,