Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Convert NameScope from struct to class #4623

Merged
merged 22 commits into from
Dec 6, 2024

Conversation

bricknerb
Copy link
Contributor

@bricknerb bricknerb commented Dec 4, 2024

This is a preparation change for adding name poisoning support (#4622), which is expected to require more elaborate logic around NameScope since a name can be not defined yet, defined, or poisoned.

The API separates looking up a name from getting the full entry since we have cases where the entries are invalidated between the time we're looking for the name and when we access (and sometimes modify) the entry.

This change has the following benefits:

  • names and name_map are internal to NameScope and are guaranteed to match.
  • extended_scopes and import_ir_scopes can not be manipulated (only new scopes can be added).
  • inst_id, name_id and parent_scope_id are constants.
  • has_error can only be mutated from false to true.

This is a preparation change for adding name poisoning support, which is expected to require more elaborate logic around NameScope since a name can be not defined yet, defined, or poisoned.

This change has the following benefits:
* names_ and name_map_ are internal to NameScope and are guaranteed to match.
* extended_scopes and import_ir_scopes can not be manipulated (only new scopes can be added).
* inst_id, name_id and parent_scope_id are constants.
* has_error can only be mutated from false to true.
* Make EntryId a struct that inherits from IdBase.
* Return ArrayRef and not const vector &.
* Rename AddImportIrScope() to AddImportIRScope() to be consistent with ImportIRId and SemIR.
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! As noted before, I'm good with the general direction here towards a class, I agree it'll probably help with name poisoning (plus, we want to keep abstracting out name lookup logic in general).

toolchain/sem_ir/name_scope.h Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope.h Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope_test.cpp Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope_test.cpp Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope_test.cpp Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope.h Show resolved Hide resolved
toolchain/sem_ir/name_scope.h Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope.h Outdated Show resolved Hide resolved
toolchain/sem_ir/name_scope.h Show resolved Hide resolved
toolchain/check/handle_impl.cpp Outdated Show resolved Hide resolved
@bricknerb bricknerb requested a review from jonmeow December 5, 2024 08:55
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The changes look good, I'm going to go ahead and try to merge this.

@jonmeow jonmeow enabled auto-merge December 5, 2024 16:52
@bricknerb
Copy link
Contributor Author

bricknerb commented Dec 6, 2024

Thanks! The changes look good, I'm going to go ahead and try to merge this.

Thanks @jonmeow !
It seems like this is not merged yet.
What should be the next action here?

@jonmeow
Copy link
Contributor

jonmeow commented Dec 6, 2024

Thanks for the note, I missed a button due to a GH beta UI. But also it looks like your PR is failing against trunk. The issue looks basic so I'll fix that for now; we tend to give out contributor privs to ease this workflow issue.

@jonmeow jonmeow added this pull request to the merge queue Dec 6, 2024
Merged via the queue into carbon-language:trunk with commit daba2c7 Dec 6, 2024
7 of 8 checks passed
@bricknerb bricknerb deleted the scope branch December 13, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants