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:
parent
6526d1676b
commit
00a3280232
|
@ -934,7 +934,7 @@ void EvalState::mkThunk_(Value & v, Expr * expr)
|
||||||
void EvalState::mkPos(Value & v, PosIdx p)
|
void EvalState::mkPos(Value & v, PosIdx p)
|
||||||
{
|
{
|
||||||
auto pos = positions[p];
|
auto pos = positions[p];
|
||||||
if (pos.file.set()) {
|
if (!pos.file.empty()) {
|
||||||
auto attrs = buildBindings(3);
|
auto attrs = buildBindings(3);
|
||||||
attrs.alloc(sFile).mkString(pos.file);
|
attrs.alloc(sFile).mkString(pos.file);
|
||||||
attrs.alloc(sLine).mkInt(pos.line);
|
attrs.alloc(sLine).mkInt(pos.line);
|
||||||
|
@ -1296,7 +1296,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
|
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
auto pos2r = state.positions[pos2];
|
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%'",
|
state.addErrorTrace(e, pos2, "while evaluating the attribute '%1%'",
|
||||||
showAttrPath(state, env, attrPath));
|
showAttrPath(state, env, attrPath));
|
||||||
throw;
|
throw;
|
||||||
|
|
|
@ -75,6 +75,8 @@ public:
|
||||||
SymbolTable symbols;
|
SymbolTable symbols;
|
||||||
PosTable positions;
|
PosTable positions;
|
||||||
|
|
||||||
|
static inline std::string derivationNixPath = "//builtin/derivation.nix";
|
||||||
|
|
||||||
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
|
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
|
||||||
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
|
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
|
||||||
sFile, sLine, sColumn, sFunctor, sToString,
|
sFile, sLine, sColumn, sFunctor, sToString,
|
||||||
|
|
|
@ -26,7 +26,7 @@ MakeError(RestrictedPathError, Error);
|
||||||
|
|
||||||
struct Pos
|
struct Pos
|
||||||
{
|
{
|
||||||
Symbol file;
|
std::string file;
|
||||||
FileOrigin origin;
|
FileOrigin origin;
|
||||||
uint32_t line;
|
uint32_t line;
|
||||||
uint32_t column;
|
uint32_t column;
|
||||||
|
@ -64,10 +64,10 @@ public:
|
||||||
explicit Origin(uint32_t idx): idx(idx), file{}, origin{} {}
|
explicit Origin(uint32_t idx): idx(idx), file{}, origin{} {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Symbol file;
|
const std::string file;
|
||||||
const FileOrigin origin;
|
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 {
|
struct Offset {
|
||||||
|
|
|
@ -648,14 +648,14 @@ Expr * EvalState::parse(char * text, size_t length, FileOrigin origin,
|
||||||
const PathView path, const PathView basePath, StaticEnv & staticEnv)
|
const PathView path, const PathView basePath, StaticEnv & staticEnv)
|
||||||
{
|
{
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
Symbol file;
|
std::string file;
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
case foFile:
|
case foFile:
|
||||||
file = symbols.create(path);
|
file = path;
|
||||||
break;
|
break;
|
||||||
case foStdin:
|
case foStdin:
|
||||||
case foString:
|
case foString:
|
||||||
file = symbols.create(text);
|
file = text;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
|
@ -3915,7 +3915,7 @@ void EvalState::createBaseEnv()
|
||||||
|
|
||||||
/* Add a wrapper around the derivation primop that computes the
|
/* Add a wrapper around the derivation primop that computes the
|
||||||
`drvPath' and `outPath' attributes lazily. */
|
`drvPath' and `outPath' attributes lazily. */
|
||||||
sDerivationNix = symbols.create("//builtin/derivation.nix");
|
sDerivationNix = symbols.create(derivationNixPath);
|
||||||
auto vDerivation = allocValue();
|
auto vDerivation = allocValue();
|
||||||
addConstant("derivation", vDerivation);
|
addConstant("derivation", vDerivation);
|
||||||
|
|
||||||
|
|
|
@ -87,11 +87,7 @@ struct ErrPos {
|
||||||
origin = pos.origin;
|
origin = pos.origin;
|
||||||
line = pos.line;
|
line = pos.line;
|
||||||
column = pos.column;
|
column = pos.column;
|
||||||
// is file symbol null?
|
file = pos.file;
|
||||||
if (pos.file.set())
|
|
||||||
file = pos.file;
|
|
||||||
else
|
|
||||||
file = "";
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue