aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/nixexpr.hh
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-04-22 21:45:39 +0200
committerpennae <github@quasiparticle.net>2022-04-25 15:37:01 +0200
commita385e51a086006c0f7d7c4bc6ed910dbe5375c4d (patch)
tree2b9776ddd7fa0977827e21379cd138cc54943071 /src/libexpr/nixexpr.hh
parent7f814d6d9af9d78f922d59115a94078f807676a8 (diff)
rename SymbolIdx -> Symbol, Symbol -> SymbolStr
after #6218 `Symbol` no longer confers a uniqueness invariant on the string it wraps, it is now possible to create multiple symbols that compare equal but whose string contents have different addresses. this guarantee is now only provided by `SymbolIdx`, leaving `Symbol` only as a string wrapper that knows about the intricacies of how symbols need to be formatted for output. this change renames `SymbolIdx` to `Symbol` to restore the previous semantics of `Symbol` to that name. we also keep the wrapper type and rename it to `SymbolStr` instead of returning plain strings from lookups into the symbol table because symbols are formatted for output in many places. theoretically we do not need `SymbolStr`, only a function that formats a string for output as a symbol, but having to wrap every symbol that appears in a message into eg `formatSymbol()` is error-prone and inconvient.
Diffstat (limited to 'src/libexpr/nixexpr.hh')
-rw-r--r--src/libexpr/nixexpr.hh34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 217c7e74d..cba099f9c 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -126,9 +126,9 @@ struct StaticEnv;
/* An attribute path is a sequence of attribute names. */
struct AttrName
{
- SymbolIdx symbol;
+ Symbol symbol;
Expr * expr;
- AttrName(const SymbolIdx & s) : symbol(s) {};
+ AttrName(const Symbol & s) : symbol(s) {};
AttrName(Expr * e) : expr(e) {};
};
@@ -146,7 +146,7 @@ struct Expr
virtual void bindVars(const EvalState & es, const StaticEnv & env);
virtual void eval(EvalState & state, Env & env, Value & v);
virtual Value * maybeThunk(EvalState & state, Env & env);
- virtual void setName(SymbolIdx name);
+ virtual void setName(Symbol name);
};
#define COMMON_METHODS \
@@ -196,7 +196,7 @@ typedef uint32_t Displacement;
struct ExprVar : Expr
{
PosIdx pos;
- SymbolIdx name;
+ Symbol name;
/* Whether the variable comes from an environment (e.g. a rec, let
or function argument) or from a "with". */
@@ -211,8 +211,8 @@ struct ExprVar : Expr
Level level;
Displacement displ;
- ExprVar(const SymbolIdx & name) : name(name) { };
- ExprVar(const PosIdx & pos, const SymbolIdx & name) : pos(pos), name(name) { };
+ ExprVar(const Symbol & name) : name(name) { };
+ ExprVar(const PosIdx & pos, const Symbol & name) : pos(pos), name(name) { };
COMMON_METHODS
Value * maybeThunk(EvalState & state, Env & env);
};
@@ -223,7 +223,7 @@ struct ExprSelect : Expr
Expr * e, * def;
AttrPath attrPath;
ExprSelect(const PosIdx & pos, Expr * e, const AttrPath & attrPath, Expr * def) : pos(pos), e(e), def(def), attrPath(attrPath) { };
- ExprSelect(const PosIdx & pos, Expr * e, const SymbolIdx & name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); };
+ ExprSelect(const PosIdx & pos, Expr * e, const Symbol & name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); };
COMMON_METHODS
};
@@ -248,7 +248,7 @@ struct ExprAttrs : Expr
: inherited(inherited), e(e), pos(pos) { };
AttrDef() { };
};
- typedef std::map<SymbolIdx, AttrDef> AttrDefs;
+ typedef std::map<Symbol, AttrDef> AttrDefs;
AttrDefs attrs;
struct DynamicAttrDef {
Expr * nameExpr, * valueExpr;
@@ -273,7 +273,7 @@ struct ExprList : Expr
struct Formal
{
PosIdx pos;
- SymbolIdx name;
+ Symbol name;
Expr * def;
};
@@ -283,9 +283,9 @@ struct Formals
Formals_ formals;
bool ellipsis;
- bool has(SymbolIdx arg) const {
+ bool has(Symbol arg) const {
auto it = std::lower_bound(formals.begin(), formals.end(), arg,
- [] (const Formal & f, const SymbolIdx & sym) { return f.name < sym; });
+ [] (const Formal & f, const Symbol & sym) { return f.name < sym; });
return it != formals.end() && it->name == arg;
}
@@ -304,11 +304,11 @@ struct Formals
struct ExprLambda : Expr
{
PosIdx pos;
- SymbolIdx name;
- SymbolIdx arg;
+ Symbol name;
+ Symbol arg;
Formals * formals;
Expr * body;
- ExprLambda(PosIdx pos, SymbolIdx arg, Formals * formals, Expr * body)
+ ExprLambda(PosIdx pos, Symbol arg, Formals * formals, Expr * body)
: pos(pos), arg(arg), formals(formals), body(body)
{
};
@@ -316,7 +316,7 @@ struct ExprLambda : Expr
: pos(pos), formals(formals), body(body)
{
}
- void setName(SymbolIdx name);
+ void setName(Symbol name);
std::string showNamePos(const EvalState & state) const;
inline bool hasFormals() const { return formals != nullptr; }
COMMON_METHODS
@@ -426,7 +426,7 @@ struct StaticEnv
const StaticEnv * up;
// Note: these must be in sorted order.
- typedef std::vector<std::pair<SymbolIdx, Displacement>> Vars;
+ typedef std::vector<std::pair<Symbol, Displacement>> Vars;
Vars vars;
StaticEnv(bool isWith, const StaticEnv * up, size_t expectedSize = 0) : isWith(isWith), up(up) {
@@ -450,7 +450,7 @@ struct StaticEnv
vars.erase(it, end);
}
- Vars::const_iterator find(const SymbolIdx & name) const
+ Vars::const_iterator find(const Symbol & name) const
{
Vars::value_type key(name, 0);
auto i = std::lower_bound(vars.begin(), vars.end(), key);