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

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.
This commit is contained in:
pennae 2022-04-22 21:45:39 +02:00
parent 7f814d6d9a
commit a385e51a08
18 changed files with 171 additions and 159 deletions

View file

@ -19,10 +19,10 @@ struct Attr
both of them are uint32 wrappers, they are next to each other
to make sure that Attr has no padding on 64 bit machines. that
way we keep Attr size at two words with no wasted space. */
SymbolIdx name;
Symbol name;
PosIdx pos;
Value * value;
Attr(SymbolIdx name, Value * value, PosIdx pos = noPos)
Attr(Symbol name, Value * value, PosIdx pos = noPos)
: name(name), pos(pos), value(value) { };
Attr() { };
bool operator < (const Attr & a) const
@ -66,7 +66,7 @@ public:
attrs[size_++] = attr;
}
iterator find(const SymbolIdx & name)
iterator find(const Symbol & name)
{
Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key);
@ -74,7 +74,7 @@ public:
return end();
}
Attr * get(const SymbolIdx & name)
Attr * get(const Symbol & name)
{
Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key);
@ -128,7 +128,7 @@ public:
: bindings(bindings), state(state)
{ }
void insert(SymbolIdx name, Value * value, PosIdx pos = noPos)
void insert(Symbol name, Value * value, PosIdx pos = noPos)
{
insert(Attr(name, value, pos));
}
@ -143,7 +143,7 @@ public:
bindings->push_back(attr);
}
Value & alloc(const SymbolIdx & name, PosIdx pos = noPos);
Value & alloc(const Symbol & name, PosIdx pos = noPos);
Value & alloc(std::string_view name, PosIdx pos = noPos);