1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-11 11:31:03 +01:00

Rename AttrPath -> AttrSelectionPath

This commit is contained in:
Eelco Dolstra 2025-12-05 12:57:19 +01:00
parent a595348f7c
commit 294e68a3f6
5 changed files with 28 additions and 19 deletions

View file

@ -1368,7 +1368,7 @@ void ExprVar::eval(EvalState & state, Env & env, Value & v)
v = *v2; v = *v2;
} }
static std::string showAttrPath(EvalState & state, Env & env, std::span<const AttrName> attrPath) static std::string showAttrSelectionPath(EvalState & state, Env & env, std::span<const AttrName> attrPath)
{ {
std::ostringstream out; std::ostringstream out;
bool first = true; bool first = true;
@ -1404,7 +1404,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
env, env,
getPos(), getPos(),
"while evaluating the attribute '%1%'", "while evaluating the attribute '%1%'",
showAttrPath(state, env, getAttrPath())) showAttrSelectionPath(state, env, getAttrPath()))
: nullptr; : nullptr;
for (auto & i : getAttrPath()) { for (auto & i : getAttrPath()) {
@ -1445,7 +1445,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
auto origin = std::get_if<SourcePath>(&pos2r.origin); auto origin = std::get_if<SourcePath>(&pos2r.origin);
if (!(origin && *origin == state.derivationInternal)) if (!(origin && *origin == state.derivationInternal))
state.addErrorTrace( state.addErrorTrace(
e, pos2, "while evaluating the attribute '%1%'", showAttrPath(state, env, getAttrPath())); e, pos2, "while evaluating the attribute '%1%'", showAttrSelectionPath(state, env, getAttrPath()));
} }
throw; throw;
} }

View file

@ -87,9 +87,9 @@ struct AttrName
static_assert(std::is_trivially_copy_constructible_v<AttrName>); static_assert(std::is_trivially_copy_constructible_v<AttrName>);
typedef std::vector<AttrName> AttrPath; typedef std::vector<AttrName> AttrSelectionPath;
std::string showAttrPath(const SymbolTable & symbols, std::span<const AttrName> attrPath); std::string showAttrSelectionPath(const SymbolTable & symbols, std::span<const AttrName> attrPath);
using UpdateQueue = SmallTemporaryValueVector<conservativeStackReservation>; using UpdateQueue = SmallTemporaryValueVector<conservativeStackReservation>;

View file

@ -163,20 +163,25 @@ struct ParserState
static constexpr Expr::AstSymbols s = StaticEvalSymbols::create().exprSymbols; static constexpr Expr::AstSymbols s = StaticEvalSymbols::create().exprSymbols;
const EvalSettings & settings; const EvalSettings & settings;
void dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos); void dupAttr(const AttrSelectionPath & attrPath, const PosIdx pos, const PosIdx prevPos);
void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos); void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos);
void addAttr( void addAttr(
ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc); ExprAttrs * attrs,
void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def); AttrSelectionPath && attrPath,
const ParserLocation & loc,
Expr * e,
const ParserLocation & exprLoc);
void addAttr(ExprAttrs * attrs, AttrSelectionPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def);
void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {}); void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {});
Expr * stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es); Expr * stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es);
PosIdx at(const ParserLocation & loc); PosIdx at(const ParserLocation & loc);
}; };
inline void ParserState::dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos) inline void ParserState::dupAttr(const AttrSelectionPath & attrPath, const PosIdx pos, const PosIdx prevPos)
{ {
throw ParseError( throw ParseError(
{.msg = HintFmt("attribute '%1%' already defined at %2%", showAttrPath(symbols, attrPath), positions[prevPos]), {.msg = HintFmt(
"attribute '%1%' already defined at %2%", showAttrSelectionPath(symbols, attrPath), positions[prevPos]),
.pos = positions[pos]}); .pos = positions[pos]});
} }
@ -188,9 +193,13 @@ inline void ParserState::dupAttr(Symbol attr, const PosIdx pos, const PosIdx pre
} }
inline void ParserState::addAttr( inline void ParserState::addAttr(
ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc) ExprAttrs * attrs,
AttrSelectionPath && attrPath,
const ParserLocation & loc,
Expr * e,
const ParserLocation & exprLoc)
{ {
AttrPath::iterator i; AttrSelectionPath::iterator i;
// All attrpaths have at least one attr // All attrpaths have at least one attr
assert(!attrPath.empty()); assert(!attrPath.empty());
auto pos = at(loc); auto pos = at(loc);
@ -236,7 +245,7 @@ inline void ParserState::addAttr(
* symbol as its last element. * symbol as its last element.
*/ */
inline void inline void
ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def) ParserState::addAttr(ExprAttrs * attrs, AttrSelectionPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def)
{ {
ExprAttrs::AttrDefs::iterator j = attrs->attrs->find(symbol); ExprAttrs::AttrDefs::iterator j = attrs->attrs->find(symbol);
if (j != attrs->attrs->end()) { if (j != attrs->attrs->end()) {

View file

@ -57,7 +57,7 @@ void ExprSelect::show(const SymbolTable & symbols, std::ostream & str) const
{ {
str << "("; str << "(";
e->show(symbols, str); e->show(symbols, str);
str << ")." << showAttrPath(symbols, getAttrPath()); str << ")." << showAttrSelectionPath(symbols, getAttrPath());
if (def) { if (def) {
str << " or ("; str << " or (";
def->show(symbols, str); def->show(symbols, str);
@ -69,7 +69,7 @@ void ExprOpHasAttr::show(const SymbolTable & symbols, std::ostream & str) const
{ {
str << "(("; str << "((";
e->show(symbols, str); e->show(symbols, str);
str << ") ? " << showAttrPath(symbols, attrPath) << ")"; str << ") ? " << showAttrSelectionPath(symbols, attrPath) << ")";
} }
void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const
@ -261,7 +261,7 @@ void ExprPos::show(const SymbolTable & symbols, std::ostream & str) const
str << "__curPos"; str << "__curPos";
} }
std::string showAttrPath(const SymbolTable & symbols, std::span<const AttrName> attrPath) std::string showAttrSelectionPath(const SymbolTable & symbols, std::span<const AttrName> attrPath)
{ {
std::ostringstream out; std::ostringstream out;
bool first = true; bool first = true;

View file

@ -418,7 +418,7 @@ struct CmdFlakeCheck : FlakeCommand
return std::nullopt; return std::nullopt;
}; };
std::map<DerivedPath, std::vector<AttrPath>> attrPathsByDrv; std::map<DerivedPath, std::vector<AttrSelectionPath>> attrPathsByDrv;
auto checkApp = [&](const std::string & attrPath, Value & v, const PosIdx pos) { auto checkApp = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try { try {
@ -618,7 +618,7 @@ struct CmdFlakeCheck : FlakeCommand
}; };
// Build and store the attribute path for error reporting // Build and store the attribute path for error reporting
AttrPath attrPath; AttrSelectionPath attrPath;
attrPath.push_back(AttrName(state->symbols.create(name))); attrPath.push_back(AttrName(state->symbols.create(name)));
attrPath.push_back(AttrName(attr.name)); attrPath.push_back(AttrName(attr.name));
attrPath.push_back(AttrName(attr2.name)); attrPath.push_back(AttrName(attr2.name));
@ -820,7 +820,7 @@ struct CmdFlakeCheck : FlakeCommand
auto it = attrPathsByDrv.find(result.path); auto it = attrPathsByDrv.find(result.path);
if (it != attrPathsByDrv.end() && !it->second.empty()) { if (it != attrPathsByDrv.end() && !it->second.empty()) {
for (auto & attrPath : it->second) { for (auto & attrPath : it->second) {
auto attrPathStr = showAttrPath(state->symbols, attrPath); auto attrPathStr = showAttrSelectionPath(state->symbols, attrPath);
reportError(Error( reportError(Error(
"failed to build attribute '%s', build of '%s' failed: %s", "failed to build attribute '%s', build of '%s' failed: %s",
attrPathStr, attrPathStr,