diff options
author | Vincent Ambo <mail@tazj.in> | 2020-07-13T19·52+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-07-13T20·14+0000 |
commit | f3165f48aa960a0167c403ec99320affd8425004 (patch) | |
tree | ce69c3803510a1a483c36c9f736c04d1e59d4889 /third_party/nix/src/libexpr/nixexpr.hh | |
parent | 693661fe8777d6eb5bcf612a5103d1704ec97eff (diff) |
refactor(3p/nix/libexpr): Make nix::AttrName a std::variant r/1278
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
Diffstat (limited to 'third_party/nix/src/libexpr/nixexpr.hh')
-rw-r--r-- | third_party/nix/src/libexpr/nixexpr.hh | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/third_party/nix/src/libexpr/nixexpr.hh b/third_party/nix/src/libexpr/nixexpr.hh index 0bf5245181ec..7ec6f7f17f39 100644 --- a/third_party/nix/src/libexpr/nixexpr.hh +++ b/third_party/nix/src/libexpr/nixexpr.hh @@ -1,6 +1,7 @@ #pragma once #include <map> +#include <variant> #include "libexpr/symbol-table.hh" #include "libexpr/value.hh" @@ -60,12 +61,7 @@ class EvalState; struct StaticEnv; /* An attribute path is a sequence of attribute names. */ -struct AttrName { - Symbol symbol; - Expr* expr; - AttrName(const Symbol& s) : symbol(s){}; - AttrName(Expr* e) : expr(e){}; -}; +using AttrName = std::variant<Symbol, Expr*>; typedef std::vector<AttrName> AttrPath; |