-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove last uses of gensyms #64623
Remove last uses of gensyms #64623
Conversation
90eef3e
to
da01d31
Compare
@@ -584,7 +588,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { | |||
let parent_scope = &self.parent_scope; | |||
let parent = parent_scope.module; | |||
let expansion = parent_scope.expansion; | |||
let ident = item.ident.gensym_if_underscore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'd expect every _
name to get SyntaxContext
from a fresh macro expansion with def-site in empty_module
, like it was done for other gensyms in #63919.
Thus we'll reuse the same common mechanism, and when hygiene data becomes encodable we'll be able to properly encode _
s in metadata as well, thus resolving the "FIXME: We shouldn't create the gensym here" below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glob imports operate on the actual hygiene data: https://github.com/rust-lang/rust/blob/da01d31ff97feb199036359c364aedc809711123/src/librustc_resolve/resolve_imports.rs#L563
I'll see if there's a way to do this without increasing the complexity of reverse_glob_adjust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, the difference is that _
s bring traits into scope for the purpose of type-based resolution, and names from opaque macros don't.
This difference is orthogonal to globs, so perhaps it's collection of traits in scope that needs to be adjusted, not reverse_glob_adjust
.
(It's somewhat unfortunate that the difference exists and the features cannot be fully unified, but in both cases the behavior looks entirely reasonable and appropriate.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm specifically concerned about preserving the behavior of the following:
mod x {
use Trait as _;
}
use x::*;
fn f() {
().method_on_trait();
// ^This resolves if the whole snippet comes from a single macro expansion
// It generally doesn't resolve otherwise
}
I think I have a working solution for this, which I'll push once I'm happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be interested to see a perf run on this before it lands, see if it improves things.
06e5858
to
50660a1
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 50660a1817e3c403c532dfcdd15210917a653921 with merge a9bcdfe8870fc7bed62b6bb47e31b50629067f15... |
☀️ Try build successful - checks-azure |
Queued a9bcdfe8870fc7bed62b6bb47e31b50629067f15 with parent f3c8eba, future comparison URL. |
Finished benchmarking try commit a9bcdfe8870fc7bed62b6bb47e31b50629067f15, comparison URL. |
Having a quick look at unused-warnings, I think this is caused by the sorting of reexports. I'll investigate properly tomorrow. |
|
50660a1
to
0e1c0b5
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion |
Remove last uses of gensyms Bindings are now indexed in resolve with an additional disambiguator that's used for underscore bindings. This is the last use of gensyms in the compiler. I'm not completely happy with this approach, so suggestions are welcome. Moving undescore bindings into their own map didn't turn out any better: master...matthewjasper:remove-underscore-gensyms. closes #49300 cc #60869 r? @petrochenkov
☀️ Try build successful - checks-azure |
Queued 3498eec with parent d046ffd, future comparison URL. |
Finished benchmarking try commit 3498eec, comparison URL. |
Ping from triage |
I didn't forget about this, just need some continuous period of time to focus on this. |
So, I still want to pursue the approach with underscores mostly being identifiers with def-site spans produced by unique macros defined in the empty module, with all special casing done for code collecting traits in scope (the only detail in which the underscores are different). That's why I started looking at the existing code determining the set of traits in scope and I didn't like what I had seen. |
@matthewjasper |
bc38b56
to
bdb37e5
Compare
@@ -349,9 +350,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { | |||
|
|||
self.r.indeterminate_imports.push(directive); | |||
match directive.subclass { | |||
// Don't add unresolved underscore imports to modules | |||
SingleImport { target: Ident { name: kw::Underscore, .. }, .. } => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this special case is removed? Some diagnostics regress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, we just won't be able to remove it in resolve_imports.rs:831
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, the disambiguator is not available in that context.
r=me with the typo #64623 (comment) fixed or not |
Instead add a disambiguator to the keys used for distinguishing resolutions.
bdb37e5
to
4198df1
Compare
@bors r=petrochenkov |
📌 Commit 4198df1 has been approved by |
…=petrochenkov Remove last uses of gensyms Underscore bindings now use unique `SyntaxContext`s to avoid collisions. This was the last use of gensyms in the compiler, so this PR also removes them. closes rust-lang#49300 cc rust-lang#60869 r? @petrochenkov
Rollup of 14 pull requests Successful merges: - #64603 (Reducing spurious unused lifetime warnings.) - #64623 (Remove last uses of gensyms) - #65235 (don't assume we can *always* find a return type hint in async fn) - #65242 (Fix suggestion to constrain trait for method to be found) - #65265 (Cleanup librustc mir err codes) - #65293 (Optimize `try_expand_impl_trait_type`) - #65307 (Try fix incorrect "explicit lifetime name needed") - #65308 (Add long error explanation for E0574) - #65353 (save-analysis: Don't ICE when resolving qualified type paths in struct members) - #65389 (Return `false` from `needs_drop` for all zero-sized arrays.) - #65402 (Add troubleshooting section to PGO chapter in rustc book.) - #65425 (Optimize `BitIter`) - #65438 (Organize `never_type` tests) - #65444 (Implement AsRef<[T]> for List<T>) Failed merges: - #65390 (Add long error explanation for E0576) r? @ghost
Underscore bindings now use unique
SyntaxContext
s to avoid collisions. This was the last use of gensyms in the compiler, so this PR also removes them.closes #49300
cc #60869
r? @petrochenkov