refactor(3p/nix/libexpr): Make nix::AttrName a std::variant
nix:AttrName was one of the few classes that relied on the default constructor of nix::Symbol (which I am trying to remove in a separate change). The class essentially represents the name of an attribute in a set, which is either just a string expression or a dynamically evaluated expression (e.g. string interpolation). Previously it would be constructed by only setting one of the fields and defaulting the other, now it is an explicit std::variant. Note that there are several code paths where not all eventualities are handled and this code is bug-for-bug compatible with those, except that unknown conditions (which should never work) are now throwing instead of silently doing ... something. The language tests pass with this change, and the depot derivations that I tested with evaluated successfully. Change-Id: Icf1ee60a5f8308f4ab18a82749e00cf37a938a8f Reviewed-on: https://cl.tvl.fyi/c/depot/+/1138 Reviewed-by: edef <edef@edef.eu> Reviewed-by: glittershark <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
693661fe87
commit
f3165f48aa
7 changed files with 67 additions and 53 deletions
22
third_party/nix/src/libexpr/nixexpr.cc
vendored
22
third_party/nix/src/libexpr/nixexpr.cc
vendored
|
|
@ -1,9 +1,11 @@
|
|||
#include "libexpr/nixexpr.hh"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <variant>
|
||||
|
||||
#include "libstore/derivations.hh"
|
||||
#include "libutil/util.hh"
|
||||
#include "libutil/visitor.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -198,17 +200,17 @@ std::ostream& operator<<(std::ostream& str, const Pos& pos) {
|
|||
std::string showAttrPath(const AttrPath& attrPath) {
|
||||
std::ostringstream out;
|
||||
bool first = true;
|
||||
for (auto& i : attrPath) {
|
||||
for (auto& attr : attrPath) {
|
||||
if (!first) {
|
||||
out << '.';
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
if (i.symbol.set()) {
|
||||
out << i.symbol;
|
||||
} else {
|
||||
out << "\"${" << *i.expr << "}\"";
|
||||
}
|
||||
|
||||
std::visit(util::overloaded{
|
||||
[&](const Symbol& sym) { out << sym; },
|
||||
[&](const Expr* expr) { out << "\"${" << *expr << "}\""; }},
|
||||
attr);
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
|
@ -268,8 +270,8 @@ void ExprSelect::bindVars(const StaticEnv& env) {
|
|||
def->bindVars(env);
|
||||
}
|
||||
for (auto& i : attrPath) {
|
||||
if (!i.symbol.set()) {
|
||||
i.expr->bindVars(env);
|
||||
if (auto* expr = std::get_if<Expr*>(&i)) {
|
||||
(*expr)->bindVars(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -277,8 +279,8 @@ void ExprSelect::bindVars(const StaticEnv& env) {
|
|||
void ExprOpHasAttr::bindVars(const StaticEnv& env) {
|
||||
e->bindVars(env);
|
||||
for (auto& i : attrPath) {
|
||||
if (!i.symbol.set()) {
|
||||
i.expr->bindVars(env);
|
||||
if (auto* expr = std::get_if<Expr*>(&i)) {
|
||||
(*expr)->bindVars(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue