-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(improve): Remove scan through globals (#6282)
# Description ## Problem\* Resolves #5001 ## Summary\* Removes the search for a global by local module ID and name when elaborating a global variable declaration. Instead simply looks up the global by the ID that we have in the definition we are elaborating. In fact the elaboration starts from a global ID of an unresolved global. I could be way off the mark on whether this is the right thing to do. ## Additional Context I found a couple of things odd: * `NodeInterner::push_global` pushes a `DefinitionKind::Global(id)` with the exact ID that the `GlobalInfo` will have, ie. it is self-referential (just an observation). This is called during the collection of unresolved globals. * `Elaborator::add_global_variable_decl` only looks for globals by `local_id` and `name`, but _not_ by `definition`, even though at this point we know that the `definition` must contain a `GlobalId`, otherwise we would have stayed in `Elaborator::add_variable_decl`. * if a global cannot be found, it calls `NodeInterner::push_definition` with the `definition` in the parameters; since we know it contains a `GlobalId` and that the same ID must have been inserted in `push_global` as well, it will now be part of two definitions at different locations - not sure exactly what this means or looks like in code I added some assertions in the commits to check that during the tests on CI, the `global_id` and the `definition`, and any results found by the lookup by local+name, are always consistent, which is why in the end I thought that if the only thing we can find is the one we can get by ID, why not get just get it? ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
4 changed files
with
10 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters