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

Remove last uses of gensyms #64623

Merged
merged 4 commits into from
Oct 16, 2019
Merged

Conversation

matthewjasper
Copy link
Contributor

@matthewjasper matthewjasper commented Sep 19, 2019

Underscore bindings now use unique SyntaxContexts 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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2019
src/test/ui/underscore-imports/hygiene-2.rs Outdated Show resolved Hide resolved
src/test/ui/underscore-imports/hygiene.rs Outdated Show resolved Hide resolved
@@ -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();
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.)

Copy link
Contributor Author

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.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 21, 2019
Copy link
Contributor

@nnethercote nnethercote left a 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.

src/libsyntax_pos/symbol.rs Outdated Show resolved Hide resolved
@matthewjasper matthewjasper force-pushed the underscore-imports branch 2 times, most recently from 06e5858 to 50660a1 Compare September 28, 2019 13:15
@matthewjasper
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Sep 28, 2019

⌛ Trying commit 50660a1817e3c403c532dfcdd15210917a653921 with merge a9bcdfe8870fc7bed62b6bb47e31b50629067f15...

@bors
Copy link
Contributor

bors commented Sep 28, 2019

☀️ Try build successful - checks-azure
Build commit: a9bcdfe8870fc7bed62b6bb47e31b50629067f15 (a9bcdfe8870fc7bed62b6bb47e31b50629067f15)

@rust-timer
Copy link
Collaborator

Queued a9bcdfe8870fc7bed62b6bb47e31b50629067f15 with parent f3c8eba, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit a9bcdfe8870fc7bed62b6bb47e31b50629067f15, comparison URL.

@matthewjasper
Copy link
Contributor Author

matthewjasper commented Sep 28, 2019

Having a quick look at unused-warnings, I think this is caused by the sorting of reexports. I'll investigate properly tomorrow.

@nnethercote
Copy link
Contributor

unused-warnings is one of the least important benchmarks. Still, 3-5% regressions are fairly large so if it's easy to avoid them that would be good.

@matthewjasper
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Sep 29, 2019

⌛ Trying commit 0e1c0b5 with merge 3498eec...

bors added a commit that referenced this pull request Sep 29, 2019
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
@bors
Copy link
Contributor

bors commented Sep 29, 2019

☀️ Try build successful - checks-azure
Build commit: 3498eec (3498eec87d0c5f25b7df91c424ad1bc6130f8677)

@rust-timer
Copy link
Collaborator

Queued 3498eec with parent d046ffd, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 3498eec, comparison URL.

@matthewjasper matthewjasper removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 2, 2019
@JohnCSimon
Copy link
Member

Ping from triage
@petrochenkov This appears to be waiting on review.
CC: @Mark-Simulacrum
Thanks.

@petrochenkov
Copy link
Contributor

I didn't forget about this, just need some continuous period of time to focus on this.
Perhaps this weekend.

@petrochenkov
Copy link
Contributor

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.
I've opened #65351 to describe the issues and possibly address them, marking this PR as blocked on it for now.

@petrochenkov petrochenkov added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 13, 2019
@petrochenkov
Copy link
Contributor

@matthewjasper
Do you still have the branch with underscores implemented as per-module indices?
It may be a better short term way to unblock the removal of gensyms.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Oct 14, 2019
src/librustc_resolve/lib.rs Outdated Show resolved Hide resolved
@@ -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, .. }, .. } => {}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 14, 2019
@petrochenkov
Copy link
Contributor

r=me with the typo #64623 (comment) fixed or not

@matthewjasper
Copy link
Contributor Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Oct 15, 2019

📌 Commit 4198df1 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 15, 2019
tmandry added a commit to tmandry/rust that referenced this pull request Oct 15, 2019
…=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
bors added a commit that referenced this pull request Oct 15, 2019
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
@bors bors merged commit 4198df1 into rust-lang:master Oct 16, 2019
@matthewjasper matthewjasper deleted the underscore-imports branch October 16, 2019 08:09
@tshepang tshepang mentioned this pull request May 10, 2020
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

syntax_pos::symbol::Symbol::gensym() is incompatible with stable hashing.
9 participants