vrtbl / passerine

A small extensible programming language designed for concise expression with little code.
https://passerine.io
MIT License
1.05k stars 38 forks source link

Intern strings in the Lexer #42

Closed Plecra closed 3 years ago

Plecra commented 3 years ago

https://github.com/vrtbl/passerine/blob/3796465ae108bba8b3a66f5c3ab71709a76b3fc8/src/compiler/ast.rs#L13

This is an easy little optimization that we can implement in the lexer - A crate like https://docs.rs/lasso is probably worth using

slightknack commented 3 years ago

So, we actually do this in the hoist step:

https://github.com/vrtbl/passerine/blob/3796465ae108bba8b3a66f5c3ab71709a76b3fc8/src/compiler/sst.rs#L59

Where UniqueSymbol is a wrapper around an integer, basically.

The issue is that this step occurs too late, imo. I mentioned this on discord, but it would be ideal to do this right after parsing, which also opens up richer semantics for macros and types.

slightknack commented 3 years ago

By the way, in the records branch, I've started to intern Strings in the lexer with the introduction of SharedSymbol, which is a wrapper around an unsigned integer. We actually don't have to intern any strings, so to speak, as we can just use Spans to reconstruct the string we parsed.

slightknack commented 3 years ago

This is fully implemented in the records branch, so I'm closing this issue. This should be merged into master by the next release. 🚀