1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-08 18:11:02 +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;
}
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;
bool first = true;
@ -1404,7 +1404,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
env,
getPos(),
"while evaluating the attribute '%1%'",
showAttrPath(state, env, getAttrPath()))
showAttrSelectionPath(state, env, getAttrPath()))
: nullptr;
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);
if (!(origin && *origin == state.derivationInternal))
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;
}

View file

@ -87,9 +87,9 @@ struct 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>;

View file

@ -163,20 +163,25 @@ struct ParserState
static constexpr Expr::AstSymbols s = StaticEvalSymbols::create().exprSymbols;
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 addAttr(
ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc);
void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def);
ExprAttrs * attrs,
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 = {});
Expr * stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es);
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(
{.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]});
}
@ -188,9 +193,13 @@ inline void ParserState::dupAttr(Symbol attr, const PosIdx pos, const PosIdx pre
}
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
assert(!attrPath.empty());
auto pos = at(loc);
@ -236,7 +245,7 @@ inline void ParserState::addAttr(
* symbol as its last element.
*/
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);
if (j != attrs->attrs->end()) {

View file

@ -57,7 +57,7 @@ void ExprSelect::show(const SymbolTable & symbols, std::ostream & str) const
{
str << "(";
e->show(symbols, str);
str << ")." << showAttrPath(symbols, getAttrPath());
str << ")." << showAttrSelectionPath(symbols, getAttrPath());
if (def) {
str << " or (";
def->show(symbols, str);
@ -69,7 +69,7 @@ void ExprOpHasAttr::show(const SymbolTable & symbols, std::ostream & str) const
{
str << "((";
e->show(symbols, str);
str << ") ? " << showAttrPath(symbols, attrPath) << ")";
str << ") ? " << showAttrSelectionPath(symbols, attrPath) << ")";
}
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";
}
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;
bool first = true;

View file

@ -418,7 +418,7 @@ struct CmdFlakeCheck : FlakeCommand
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) {
try {
@ -618,7 +618,7 @@ struct CmdFlakeCheck : FlakeCommand
};
// 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(attr.name));
attrPath.push_back(AttrName(attr2.name));
@ -820,7 +820,7 @@ struct CmdFlakeCheck : FlakeCommand
auto it = attrPathsByDrv.find(result.path);
if (it != attrPathsByDrv.end() && !it->second.empty()) {
for (auto & attrPath : it->second) {
auto attrPathStr = showAttrPath(state->symbols, attrPath);
auto attrPathStr = showAttrSelectionPath(state->symbols, attrPath);
reportError(Error(
"failed to build attribute '%s', build of '%s' failed: %s",
attrPathStr,