Refactor NameResolution to use non_glob_binding and glob_binding#142547
Refactor NameResolution to use non_glob_binding and glob_binding#142547b-naber wants to merge 4 commits intorust-lang:masterfrom
Conversation
|
I gave this a quick read and it seems cleaner than before! |
f6807eb to
f9a6e87
Compare
| // However, it causes resolution/expansion to stuck too often (#53144), so, to make | ||
| // progress, we have to ignore those potential unresolved invocations from other modules | ||
| // and prohibit access to macro-expanded `macro_export` macros instead (unless restricted | ||
| // shadowing is enabled, see `macro_expanded_macro_export_errors`). |
There was a problem hiding this comment.
Could you make sure none of the comments is lost, like in this case?
| } | ||
| } | ||
|
|
||
| // Forbid expanded shadowing to avoid time travel. |
There was a problem hiding this comment.
This also indicates that the conversion to scopes wasn't done properly.
Ideally MoreExpandedVsOuter should be reported here in a similar way to how it's done in early_resolve_ident_in_lexical_scope.
There was a problem hiding this comment.
Can you elaborate on what you expect this logic to look like with the change to NameResolution?
There was a problem hiding this comment.
I really need to experiment on this myself to give a good answer.
Basically, this logic should be subsumed by the innermost_result checking logic in early_resolve_ident_in_lexical_scope.
And the AmbiguityKind::GlobVsExpanded logic in try_define should be subsumed by it as well.
cc #gsoc > Project: Parallel Macro Expansion @ 💬
|
|
||
| /// Scopes used for resolving an `Ident` in a `Module`. | ||
| #[derive(Debug, Copy, Clone, PartialEq)] | ||
| enum ModuleScope { |
There was a problem hiding this comment.
Instead of this, I think enum Scope above should also get two variants ModuleNonGlobs and ModuleGlobs instead of one Module.
Then finding any resolution inside a module would be done using a new ScopeSet variant including just two scopes, but other ScopeSet would just iterate over ModuleNonGlobs and ModuleGlobs as a part of the common loop.
This would also be a much larger refactoring.
There was a problem hiding this comment.
hm while I do think it would be more consistent to have those two scopes in the Scope enum, it would also add more complexity to it. I kind of like that the resolution of an Ident in a module is isolated with the current resolve_ident_in_module, and using a separate ModuleScope for that method simplifies things imo.
There was a problem hiding this comment.
The logic in early_resolve_ident_in_lexical_scope should see the explicit resolution and the glob resolution in a module as two separate steps.
So either Scope::Module should be split into two scopes, or resolve_ident_in_module_unadjusted should somehow produce the both resolutions so that early_resolve_ident_in_lexical_scope could process them as if they were from two separate scopes.
There was a problem hiding this comment.
I'm open to try to implement this, but I still don't understand why this is necessary. Can you explain in more detail, please?
There was a problem hiding this comment.
Pretty much the same answer as in #142547 (comment).
Sorry, I'll try to produce some more details later.
|
I think this is a small step in the right direction, but it probably doesn't move us much closer to implementing the open namespace proposal, splitting modules into scopes properly is a large refactoring that only partially intersects with open namespaces. Also not sure if landing just this part of the refactoring is beneficial. |
This comment has been minimized.
This comment has been minimized.
81fff03 to
7148d37
Compare
This comment has been minimized.
This comment has been minimized.
|
Don't understand the CI failure. It seems to checkout old code, the line that fails isn't on this branch. edit: Should have rebased and run a check. |
|
I changed |
This comment has been minimized.
This comment has been minimized.
3beb2f8 to
c0f41d4
Compare
|
Could you move the |
|
I'd prefer if you would review the changes to The introduction of |
|
I don't have anything new to add now besides repeating #142547 (comment) and #142547 (comment). |
|
Reminder, once the PR becomes ready for a review, use |
|
Since that causes me extra work, I would like to at least get a justification for why that is necessary. The (non_)glob-part of this re-factoring is simplified by introducing As I previously said, I would be open to remove |
|
@LorrensP-2158466 will do #142547 (comment). |
|
☔ The latest upstream changes (presumably #143721) made this pull request unmergeable. Please resolve the merge conflicts. |
…extraction, r=petrochenkov Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name` This pr the work Vadim asked for in rust-lang#142547 (comment). This part: > finalize_module_binding/single_import_can_define_name extraction Cherry-picked commits of b-naber. Extraction of 2 processes in `resolve_ident_in_module_unadjusted`: - `finalize_module_binding` - `single_import_can_define_name` r? `@petrochenkov`
…extraction, r=petrochenkov Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name` This pr the work Vadim asked for in rust-lang#142547 (comment). This part: > finalize_module_binding/single_import_can_define_name extraction Cherry-picked commits of b-naber. Extraction of 2 processes in `resolve_ident_in_module_unadjusted`: - `finalize_module_binding` - `single_import_can_define_name` r? ``@petrochenkov``
…extraction, r=petrochenkov Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name` This pr the work Vadim asked for in rust-lang#142547 (comment). This part: > finalize_module_binding/single_import_can_define_name extraction Cherry-picked commits of b-naber. Extraction of 2 processes in `resolve_ident_in_module_unadjusted`: - `finalize_module_binding` - `single_import_can_define_name` r? ```@petrochenkov```
Rollup merge of #143728 - LorrensP-2158466:refactor-resolve-extraction, r=petrochenkov Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name` This pr the work Vadim asked for in #142547 (comment). This part: > finalize_module_binding/single_import_can_define_name extraction Cherry-picked commits of b-naber. Extraction of 2 processes in `resolve_ident_in_module_unadjusted`: - `finalize_module_binding` - `single_import_can_define_name` r? ```@petrochenkov```
…resolution-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in rust-lang#142547 (comment). This part: > move the `(non)_glob_binding` change r? `@petrochenkov`
…resolution-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in rust-lang#142547 (comment). This part: > move the `(non)_glob_binding` change r? ``@petrochenkov``
…n, r=petrochenkov Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name` This pr the work Vadim asked for in rust-lang/rust#142547 (comment). This part: > finalize_module_binding/single_import_can_define_name extraction Cherry-picked commits of b-naber. Extraction of 2 processes in `resolve_ident_in_module_unadjusted`: - `finalize_module_binding` - `single_import_can_define_name` r? ```@petrochenkov```
…resolution-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in rust-lang#142547 (comment). This part: > move the `(non)_glob_binding` change r? ```@petrochenkov```
…resolution-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in rust-lang#142547 (comment). This part: > move the `(non)_glob_binding` change r? ````@petrochenkov````
Rollup merge of #143734 - LorrensP-2158466:refactor-resolve-resolution-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in #142547 (comment). This part: > move the `(non)_glob_binding` change r? ````@petrochenkov````
…n-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in rust-lang/rust#142547 (comment). This part: > move the `(non)_glob_binding` change r? ````@petrochenkov````
Refactoring that should help with introducing name resolution for namespaced crates.
r? @petrochenkov
Edit: This PR was split into two PRs. #143734 and #143728 cherry-picked the commits.