pxp-lang / pxp

A suite of high-performance tools for PHP developers – includes a code formatter, static analyser, language server and superset language.
https://pxplang.org
Other
784 stars 0 forks source link

Symbol: Add a new singleton API for SymbolTable #42

Closed ryangjchandler closed 8 months ago

ryangjchandler commented 8 months ago

The problem with using symbols is that they are annoying to debug or display, since they're just integers pointing to magical strings.

With this change, we can use a new SymbolTable::the() method to grab a singleton instance of a SymbolTable using some "unsafe" Rust. This will allow us to impl Debug and Display for the new struct based Symbol and provide more accurate output.

Performance wise, I can't see any negative impacts from this change. If anything, my rudimentary benchmarks are ~2% faster.

I'm not saying that this new singleton API is the absolute best way to go, but it definitely helps out in a lot of cases such as testing, debugging and displaying symbols.