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
This commit is contained in:
eldritch horrors 2024-11-27 02:09:08 +01:00
parent 3593f5555e
commit cb8262e11c
18 changed files with 23 additions and 40 deletions

View file

@ -240,7 +240,7 @@ static void main_nix_build(std::string programName, Strings argv)
else else
for (auto i : left) { for (auto i : left) {
if (fromArgs) 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 { else {
auto absolute = i; auto absolute = i;
try { try {
@ -338,7 +338,7 @@ static void main_nix_build(std::string programName, Strings argv)
try { try {
auto & expr = state->parseExprFromString( auto & expr = state->parseExprFromString(
"(import <nixpkgs> {}).bashInteractive", "(import <nixpkgs> {}).bashInteractive",
state->rootPath(CanonPath::fromCwd())); CanonPath::fromCwd());
Value v; Value v;
state->eval(expr, v); state->eval(expr, v);

View file

@ -415,7 +415,7 @@ static void queryInstSources(EvalState & state,
loadSourceExpr(state, *instSource.nixExprPath, vArg); loadSourceExpr(state, *instSource.nixExprPath, vArg);
for (auto & i : args) { for (auto & i : args) {
Expr & eFun = state.parseExprFromString(i, state.rootPath(CanonPath::fromCwd())); Expr & eFun = state.parseExprFromString(i, CanonPath::fromCwd());
Value vFun, vTmp; Value vFun, vTmp;
state.eval(eFun, vFun); state.eval(eFun, vFun);
vTmp.mkApp(&vFun, &vArg); vTmp.mkApp(&vFun, &vArg);
@ -1528,7 +1528,7 @@ static int main_nix_env(std::string programName, Strings argv)
globals.instSource.nixExprPath = std::make_shared<SourcePath>( globals.instSource.nixExprPath = std::make_shared<SourcePath>(
file != "" file != ""
? lookupFileArg(*globals.state, file) ? lookupFileArg(*globals.state, file)
: globals.state->rootPath(CanonPath(nixExprPath))); : CanonPath(nixExprPath));
globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state); globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state);

View file

@ -184,7 +184,7 @@ static int main_nix_instantiate(std::string programName, Strings argv)
for (auto & i : files) { for (auto & i : files) {
Expr & e = fromArgs Expr & e = fromArgs
? state->parseExprFromString(i, state->rootPath(CanonPath::fromCwd())) ? state->parseExprFromString(i, CanonPath::fromCwd())
: state->parseExprFromFile(resolveExprPath(state->checkSourcePath(lookupFileArg(*state, i)))); : state->parseExprFromFile(resolveExprPath(state->checkSourcePath(lookupFileArg(*state, i))));
processExpr(*state, attrPaths, parseOnly, strict, autoArgs, processExpr(*state, attrPaths, parseOnly, strict, autoArgs,
evalOnly, outputKind, xmlOutputSourceLocation, e); evalOnly, outputKind, xmlOutputSourceLocation, e);

View file

@ -100,7 +100,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
Value envBuilder; Value envBuilder;
state.eval(state.parseExprFromString( state.eval(state.parseExprFromString(
#include "buildenv.nix.gen.hh" #include "buildenv.nix.gen.hh"
, state.rootPath(CanonPath::root)), envBuilder); , CanonPath::root), envBuilder);
/* Construct a Nix expression that calls the user environment /* Construct a Nix expression that calls the user environment
builder with the manifest as argument. */ builder with the manifest as argument. */

View file

@ -20,7 +20,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
auto manifestFile = userEnv + "/manifest.nix"; auto manifestFile = userEnv + "/manifest.nix";
if (pathExists(manifestFile)) { if (pathExists(manifestFile)) {
Value v; Value v;
state.evalFile(state.rootPath(CanonPath(manifestFile)), v); state.evalFile(CanonPath(manifestFile), v);
Bindings & bindings(*state.allocBindings(0)); Bindings & bindings(*state.allocBindings(0));
getDerivations(state, v, "", bindings, elems, false); getDerivations(state, v, "", bindings, elems, false);
} }

View file

@ -177,7 +177,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
for (auto & i : autoArgs) { for (auto & i : autoArgs) {
auto v = state.allocValue(); auto v = state.allocValue();
if (i.second[0] == 'E') 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 else
v->mkString(((std::string_view) i.second).substr(1)); v->mkString(((std::string_view) i.second).substr(1));
res.insert(state.symbols.create(i.first), v); res.insert(state.symbols.create(i.first), v);
@ -196,18 +196,18 @@ SourcePath lookupFileArg(EvalState & state, std::string_view fileArg)
/* locked */ false /* locked */ false
); );
StorePath const storePath = downloaded.tree.storePath; 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:")) { } else if (fileArg.starts_with("flake:")) {
experimentalFeatureSettings.require(Xp::Flakes); experimentalFeatureSettings.require(Xp::Flakes);
static constexpr size_t FLAKE_LEN = std::string_view("flake:").size(); static constexpr size_t FLAKE_LEN = std::string_view("flake:").size();
auto flakeRef = parseFlakeRef(std::string(fileArg.substr(FLAKE_LEN)), {}, true, false); auto flakeRef = parseFlakeRef(std::string(fileArg.substr(FLAKE_LEN)), {}, true, false);
auto storePath = flakeRef.resolve(state.store).fetchTree(state.store).first.storePath; 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) == '>') { } else if (fileArg.size() > 2 && fileArg.at(0) == '<' && fileArg.at(fileArg.size() - 1) == '>') {
Path p(fileArg.substr(1, fileArg.size() - 2)); Path p(fileArg.substr(1, fileArg.size() - 2));
return state.findFile(p); return state.findFile(p);
} else { } else {
return state.rootPath(CanonPath::fromCwd(fileArg)); return CanonPath::fromCwd(fileArg);
} }
} }

View file

@ -447,7 +447,7 @@ Installables SourceExprCommand::parseInstallables(
else if (file) else if (file)
state->evalFile(lookupFileArg(*state, *file), *vFile); state->evalFile(lookupFileArg(*state, *file), *vFile);
else { else {
auto & e = state->parseExprFromString(*expr, state->rootPath(CanonPath::fromCwd())); auto & e = state->parseExprFromString(*expr, CanonPath::fromCwd());
state->eval(e, *vFile); state->eval(e, *vFile);
} }

View file

@ -1078,7 +1078,7 @@ Value * NixRepl::bindingsToAttrs()
Expr & NixRepl::parseString(std::string s) 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);
} }

View file

@ -259,7 +259,7 @@ EvalState::EvalState(
std::shared_ptr<Store> buildStore) std::shared_ptr<Store> buildStore)
: s(symbols) : s(symbols)
, repair(NoRepair) , repair(NoRepair)
, derivationInternal(rootPath(CanonPath("/builtin/derivation.nix"))) , derivationInternal(CanonPath("/builtin/derivation.nix"))
, store(store) , store(store)
, buildStore(buildStore ? buildStore : store) , buildStore(buildStore ? buildStore : store)
, regexCache(makeRegexCache()) , regexCache(makeRegexCache())
@ -2762,7 +2762,7 @@ Expr & EvalState::parseStdin()
// drainFD should have left some extra space for terminators // drainFD should have left some extra space for terminators
auto s = make_ref<std::string>(buffer); auto s = make_ref<std::string>(buffer);
buffer.append("\0\0", 2); 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);
} }

View file

@ -328,12 +328,6 @@ public:
std::shared_ptr<Store> buildStore = nullptr); std::shared_ptr<Store> buildStore = nullptr);
~EvalState(); ~EvalState();
/**
* Return a `SourcePath` that refers to `path` in the root
* filesystem.
*/
SourcePath rootPath(CanonPath path);
/** /**
* Allow access to a path. * Allow access to a path.
*/ */

View file

@ -205,7 +205,6 @@ libexpr_sources = files(
'json-to-value.cc', 'json-to-value.cc',
'nixexpr.cc', 'nixexpr.cc',
'parser/parser.cc', 'parser/parser.cc',
'paths.cc',
'primops.cc', 'primops.cc',
'print-ambiguous.cc', 'print-ambiguous.cc',
'print.cc', 'print.cc',

View file

@ -1,10 +0,0 @@
#include "lix/libexpr/eval.hh"
namespace nix {
SourcePath EvalState::rootPath(CanonPath path)
{
return path;
}
}

View file

@ -131,7 +131,7 @@ static SourcePath realisePath(EvalState & state, const PosIdx pos, Value & v, co
try { try {
StringMap rewrites = state.realiseContext(context); 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 return flags.checkForPureEval
? state.checkSourcePath(realPath) ? 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); auto output = runProgram(program, true, commandArgs);
Expr * parsed; Expr * parsed;
try { try {
parsed = &state.parseExprFromString(std::move(output), state.rootPath(CanonPath::root)); parsed = &state.parseExprFromString(std::move(output), CanonPath::root);
} catch (Error & e) { } catch (Error & e) {
e.addTrace(state.positions[pos], "while parsing the output from '%1%'", program); e.addTrace(state.positions[pos], "while parsing the output from '%1%'", program);
throw; throw;
@ -1540,7 +1540,7 @@ static void addPath(
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) { if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
auto dstPath = fetchToStore( 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) if (expectedHash && expectedStorePath != dstPath)
state.error<EvalError>( state.error<EvalError>(
"store path mismatch in (possibly filtered) path added from '%s'", "store path mismatch in (possibly filtered) path added from '%s'",

View file

@ -68,7 +68,7 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption
if (apply) { if (apply) {
auto vApply = state->allocValue(); 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(); auto vRes = state->allocValue();
state->callFunction(*vApply, *v, *vRes, noPos); state->callFunction(*vApply, *v, *vRes, noPos);
v = vRes; v = vRes;

View file

@ -31,7 +31,7 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url)
// FIXME: use nixpkgs flake // FIXME: use nixpkgs flake
state.eval(state.parseExprFromString( state.eval(state.parseExprFromString(
"import <nixpkgs/pkgs/build-support/fetchurl/mirrors.nix>", "import <nixpkgs/pkgs/build-support/fetchurl/mirrors.nix>",
state.rootPath(CanonPath::root)), CanonPath::root),
vMirrors); vMirrors);
state.forceAttrs(vMirrors, noPos, "while evaluating the set of all mirrors"); state.forceAttrs(vMirrors, noPos, "while evaluating the set of all mirrors");

View file

@ -290,7 +290,7 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
auto state = std::make_unique<EvalState>(SearchPath{}, store); auto state = std::make_unique<EvalState>(SearchPath{}, store);
auto v = state->allocValue(); 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)); Bindings & bindings(*state->allocBindings(0));
auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v).first; auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v).first;

View file

@ -28,7 +28,7 @@ namespace nix {
} }
Value eval(std::string input, bool forceValue = true, const FeatureSettings & fSettings = featureSettings) { Value eval(std::string input, bool forceValue = true, const FeatureSettings & fSettings = featureSettings) {
Value v; Value v;
Expr & e = state.parseExprFromString(input, state.rootPath(CanonPath::root), fSettings); Expr & e = state.parseExprFromString(input, CanonPath::root, fSettings);
state.eval(e, v); state.eval(e, v);
if (forceValue) if (forceValue)
state.forceValue(v, noPos); state.forceValue(v, noPos);

View file

@ -388,7 +388,7 @@ TEST_F(ValuePrintingTests, ansiColorsStringElided)
TEST_F(ValuePrintingTests, ansiColorsPath) TEST_F(ValuePrintingTests, ansiColorsPath)
{ {
Value v; Value v;
v.mkPath(state.rootPath(CanonPath("puppy"))); v.mkPath(CanonPath("puppy"));
test(v, test(v,
ANSI_GREEN "/puppy" ANSI_NORMAL, ANSI_GREEN "/puppy" ANSI_NORMAL,