New treatment of symbols and keywords within the compiler

A number of PRs have landed recently that make symbol handling faster and simpler. Most notably, a few hundred static (pre-interned) symbols are now available.

For example, where previously you might have written Symbol::intern("doc"), now you can write sym::doc. As well as being shorter, it’s faster because it avoids a hash table lookup in a global table that is accessed via TLS.

The current list of available symbols is here. We have been extending this list on a by-need basis, particularly for hot code paths. But we don’t want to stick every possible symbol in there, because pre-interning does have a small upfront cost.

The ability to equate a Symbol with a string has also been removed, because it was a performance hazard: a slow(ish) operation that doesn’t look slow. The availability of many pre-interned symbols means this shouldn’t cause much inconvenience.

Keywords are now also easier to use. Where previously you would write keywords::Unsafe.name() you can now just write kw::Unsafe, and the type of that value is Symbol.

Both sym and kw are available within syntax::symbol and syntax_pos::symbol, so you can import them via whichever path is more convenient; the former is more common.

18 Likes