Stream: compiler development

Topic: Symbol lookups


view this post on Zulip Richard Feldman (Feb 03 2024 at 04:03):

I'm working on canonicalization and I'm thinking about how Symbol gets used in various places. It seems like although they're globally unique, we don't actually rely on that property in practice - e.g. we keep track of a scope in type checking and code gen so that we can change the meaning of a given Symbol as we traverse various scopes

view this post on Zulip Richard Feldman (Feb 03 2024 at 04:04):

it would definitely simplify things and reduce memory usage if we could drop the property that symbols need to be globally unique and instead have them be essentially per-module string interning IDs and that's it

view this post on Zulip Richard Feldman (Feb 03 2024 at 04:04):

so I'm wondering - does anyone know of any places in the compiler where we rely on symbols being globally unique?

view this post on Zulip Brian Carroll (Feb 03 2024 at 09:47):

Would a symbol imported from another module not cause a potential clash in this system?

view this post on Zulip Richard Feldman (Feb 03 2024 at 11:24):

oh those will already need to be translated

view this post on Zulip Richard Feldman (Feb 03 2024 at 11:26):

because of caching - if we want to cache the canonical IR for a given module on disk, then it can't have (our current concept of) ModuleId in any of its identifiers, because those can change depending on which modules are being compiled, random chance involving when threads happen to finish work, etc.

view this post on Zulip Richard Feldman (Feb 03 2024 at 11:27):

so I guess I shouldn't have said globally unique, but rather unique within the module :big_smile:


Last updated: Jul 06 2025 at 12:14 UTC