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
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 <nixpkgs> {}).bashInteractive",
state->rootPath(CanonPath::fromCwd()));
CanonPath::fromCwd());
Value v;
state->eval(expr, v);

View file

@ -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<SourcePath>(
file != ""
? lookupFileArg(*globals.state, file)
: globals.state->rootPath(CanonPath(nixExprPath)));
: CanonPath(nixExprPath));
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) {
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);

View file

@ -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. */

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -259,7 +259,7 @@ EvalState::EvalState(
std::shared_ptr<Store> 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<std::string>(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);
}

View file

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

View file

@ -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',

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 {
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<EvalError>(
"store path mismatch in (possibly filtered) path added from '%s'",

View file

@ -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;

View file

@ -31,7 +31,7 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url)
// FIXME: use nixpkgs flake
state.eval(state.parseExprFromString(
"import <nixpkgs/pkgs/build-support/fetchurl/mirrors.nix>",
state.rootPath(CanonPath::root)),
CanonPath::root),
vMirrors);
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 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;

View file

@ -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);

View file

@ -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,