Expand description
String interning.
Identifiers are compared constantly: on every macro lookup, every scope lookup, every
typedef disambiguation. Interning turns those comparisons into an integer compare and
turns the storage into one arena instead of a String per occurrence. The lexer interns
during the scan rather than after it, per spec/06-lexer-and-parser.md, so an identifier
is never materialised as a String at all.
§Determinism
Symbol ordering is allocation order, which is the order the source was read in. That
is deterministic for a given input, and it is the reason the compiler can sort by symbol
anywhere it needs a stable order without reaching for the string. Hashing a Symbol must
never leak into output ordering, because hash order is not stable across runs, and
spec/02-the-goal.md makes byte-identical output a requirement rather than a nicety.
Structs§
- Interner
- An append-only set of strings, each mapped to a
Symbol. - Symbol
- An interned string.
- Symbol
Table - Marker for the symbol table, so that
Idx<SymbolTable>cannot be confused with any other index.