don't use Symbol in Pos to represent a path

PosTable deduplicates origin information, so using symbols for paths is no
longer necessary. moving away from path Symbols also reduces the usage of
symbols for things that are not keys in attribute sets, which will become
important in the future when we turn symbols into indices as well.
This commit is contained in:
pennae 2022-03-05 17:31:50 +01:00
parent 6526d1676b
commit 00a3280232
6 changed files with 12 additions and 14 deletions

View file

@ -934,7 +934,7 @@ void EvalState::mkThunk_(Value & v, Expr * expr)
void EvalState::mkPos(Value & v, PosIdx p)
{
auto pos = positions[p];
if (pos.file.set()) {
if (!pos.file.empty()) {
auto attrs = buildBindings(3);
attrs.alloc(sFile).mkString(pos.file);
attrs.alloc(sLine).mkInt(pos.line);
@ -1296,7 +1296,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
} catch (Error & e) {
auto pos2r = state.positions[pos2];
if (pos2 && pos2r.file != state.sDerivationNix)
if (pos2 && pos2r.file != state.derivationNixPath)
state.addErrorTrace(e, pos2, "while evaluating the attribute '%1%'",
showAttrPath(state, env, attrPath));
throw;

View file

@ -75,6 +75,8 @@ public:
SymbolTable symbols;
PosTable positions;
static inline std::string derivationNixPath = "//builtin/derivation.nix";
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
sFile, sLine, sColumn, sFunctor, sToString,

View file

@ -26,7 +26,7 @@ MakeError(RestrictedPathError, Error);
struct Pos
{
Symbol file;
std::string file;
FileOrigin origin;
uint32_t line;
uint32_t column;
@ -64,10 +64,10 @@ public:
explicit Origin(uint32_t idx): idx(idx), file{}, origin{} {}
public:
const Symbol file;
const std::string file;
const FileOrigin origin;
Origin(Symbol file, FileOrigin origin): file(file), origin(origin) {}
Origin(std::string file, FileOrigin origin): file(std::move(file)), origin(origin) {}
};
struct Offset {

View file

@ -648,14 +648,14 @@ Expr * EvalState::parse(char * text, size_t length, FileOrigin origin,
const PathView path, const PathView basePath, StaticEnv & staticEnv)
{
yyscan_t scanner;
Symbol file;
std::string file;
switch (origin) {
case foFile:
file = symbols.create(path);
file = path;
break;
case foStdin:
case foString:
file = symbols.create(text);
file = text;
break;
default:
assert(false);

View file

@ -3915,7 +3915,7 @@ void EvalState::createBaseEnv()
/* Add a wrapper around the derivation primop that computes the
`drvPath' and `outPath' attributes lazily. */
sDerivationNix = symbols.create("//builtin/derivation.nix");
sDerivationNix = symbols.create(derivationNixPath);
auto vDerivation = allocValue();
addConstant("derivation", vDerivation);

View file

@ -87,11 +87,7 @@ struct ErrPos {
origin = pos.origin;
line = pos.line;
column = pos.column;
// is file symbol null?
if (pos.file.set())
file = pos.file;
else
file = "";
return *this;
}