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

src/librustc_resolve/lib.rs Outdated Show resolved Hide resolved
@matthewjasper matthewjasper force-pushed the matthewjasper:underscore-imports branch from 90eef3e to da01d31 Sep 20, 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();

This comment has been minimized.

Copy link
@petrochenkov

petrochenkov Sep 21, 2019

Contributor

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.

This comment has been minimized.

Copy link
@matthewjasper

matthewjasper Sep 21, 2019

Author Contributor

Glob imports operate on the actual hygiene data:

let scope = match ident.span.reverse_glob_adjust(module.expansion, directive.span) {

I'll see if there's a way to do this without increasing the complexity of reverse_glob_adjust

This comment has been minimized.

Copy link
@petrochenkov

petrochenkov Sep 22, 2019

Contributor

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

This comment has been minimized.

Copy link
@matthewjasper

matthewjasper Sep 22, 2019

Author Contributor

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.

Copy link
Contributor

nnethercote left a comment

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 matthewjasper:underscore-imports branch 2 times, most recently from 06e5858 to 50660a1 Sep 28, 2019
@matthewjasper

This comment has been minimized.

Copy link
Contributor Author

matthewjasper commented Sep 28, 2019

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Sep 28, 2019

Awaiting bors try build completion

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Sep 28, 2019

⌛️ Trying commit 50660a1 with merge a9bcdfe...

bors added a commit that referenced this pull request Sep 28, 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

This comment has been minimized.

Copy link
Contributor

bors commented Sep 28, 2019

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

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Sep 28, 2019

Queued a9bcdfe with parent f3c8eba, future comparison URL.

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Sep 28, 2019

Finished benchmarking try commit a9bcdfe, comparison URL.

@matthewjasper

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

nnethercote commented Sep 29, 2019

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 matthewjasper force-pushed the matthewjasper:underscore-imports branch from 50660a1 to 0e1c0b5 Sep 29, 2019
@matthewjasper

This comment has been minimized.

Copy link
Contributor Author

matthewjasper commented Sep 29, 2019

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Sep 29, 2019

Awaiting bors try build completion

@bors

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

bors commented Sep 29, 2019

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

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Sep 29, 2019

Queued 3498eec with parent d046ffd, future comparison URL.

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Sep 30, 2019

Finished benchmarking try commit 3498eec, comparison URL.

@matthewjasper matthewjasper force-pushed the matthewjasper:underscore-imports branch from 0e1c0b5 to bc38b56 Oct 4, 2019
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Oct 4, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-04T19:50:10.4158558Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-04T19:50:10.4424274Z ##[command]git config gc.auto 0
2019-10-04T19:50:10.4513400Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-04T19:50:10.4573286Z ##[command]git config --get-all http.proxy
2019-10-04T19:50:10.4712472Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/64623/merge:refs/remotes/pull/64623/merge
---
2019-10-04T20:58:23.9953030Z .................................................................................................... 1500/9107
2019-10-04T20:58:31.6863574Z .................................................................................................... 1600/9107
2019-10-04T20:58:41.8406804Z .................................................................................................... 1700/9107
2019-10-04T20:58:52.2243378Z .......i...............i............................................................................ 1800/9107
2019-10-04T20:59:00.2286763Z ..................................................................................................ii 1900/9107
2019-10-04T20:59:18.6646335Z iii................................................................................................. 2000/9107
2019-10-04T20:59:28.4400643Z .................................................................................................... 2200/9107
2019-10-04T20:59:31.3826357Z .................................................................................................... 2300/9107
2019-10-04T20:59:38.3619987Z .................................................................................................... 2400/9107
2019-10-04T20:59:44.6144517Z .................................................................................................... 2500/9107
---
2019-10-04T21:03:03.9335971Z .......................................................................................i............ 4700/9107
2019-10-04T21:03:12.8986169Z ...i................................................................................................ 4800/9107
2019-10-04T21:03:25.0106536Z .................................................................................................... 4900/9107
2019-10-04T21:03:31.4869218Z .................................................................................................... 5000/9107
2019-10-04T21:03:45.7463071Z ................................................................................ii.ii............... 5100/9107
2019-10-04T21:03:56.9256357Z .................................................................................................... 5300/9107
2019-10-04T21:04:08.5555366Z .................................................................................................... 5400/9107
2019-10-04T21:04:16.7202513Z ..............................................i..................................................... 5500/9107
2019-10-04T21:04:24.8833702Z .................................................................................................... 5600/9107
2019-10-04T21:04:24.8833702Z .................................................................................................... 5600/9107
2019-10-04T21:04:37.3028798Z .................................................................................................... 5700/9107
2019-10-04T21:04:46.3077043Z ...........................................ii...i..ii...........i................................... 5800/9107
2019-10-04T21:05:15.9407191Z .................................................................................................... 6000/9107
2019-10-04T21:05:26.5517748Z .................................................................................................... 6100/9107
2019-10-04T21:05:26.5517748Z .................................................................................................... 6100/9107
2019-10-04T21:05:42.3666292Z .................................................i..ii.............................................. 6200/9107
2019-10-04T21:06:10.3318355Z .................................................................................................... 6400/9107
2019-10-04T21:06:12.8623231Z .........i.......................................................................................... 6500/9107
2019-10-04T21:06:15.4617625Z .................................................................................i.................. 6600/9107
2019-10-04T21:06:18.5499138Z .................................................................................................... 6700/9107
---
2019-10-04T21:11:04.4438757Z diff of stderr:
2019-10-04T21:11:04.4438805Z 
2019-10-04T21:11:04.4447065Z 5    |           ^^^^^ method not found in `&()`
2019-10-04T21:11:04.4447228Z 6    |
2019-10-04T21:11:04.4450100Z 7    = help: items from traits can only be used if the trait is in scope
2019-10-04T21:11:04.4450939Z - help: the following trait is implemented but not in scope, perhaps add a `use` for it:
2019-10-04T21:11:04.4451428Z + help: the following trait is implemented but not in scope; perhaps add a `use` for it:
2019-10-04T21:11:04.4452437Z 10 LL | use std::ops::Deref;
2019-10-04T21:11:04.4452483Z 11    |
2019-10-04T21:11:04.4454241Z 
2019-10-04T21:11:04.4454307Z 17    |               ^^^^^^^^^ method not found in `&mut ()`
2019-10-04T21:11:04.4454307Z 17    |               ^^^^^^^^^ method not found in `&mut ()`
2019-10-04T21:11:04.4454352Z 18    |
2019-10-04T21:11:04.4454417Z 19    = help: items from traits can only be used if the trait is in scope
2019-10-04T21:11:04.4454892Z - help: the following trait is implemented but not in scope, perhaps add a `use` for it:
2019-10-04T21:11:04.4454953Z + help: the following trait is implemented but not in scope; perhaps add a `use` for it:
2019-10-04T21:11:04.4455060Z 22 LL | use std::ops::DerefMut;
2019-10-04T21:11:04.4455100Z 23    |
2019-10-04T21:11:04.4455145Z 
2019-10-04T21:11:04.4455169Z 
2019-10-04T21:11:04.4455169Z 
2019-10-04T21:11:04.4455211Z The actual stderr differed from the expected stderr.
2019-10-04T21:11:04.4455512Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/underscore-imports/hygiene/hygiene.stderr
2019-10-04T21:11:04.4455924Z To update references, rerun the tests and pass the `--bless` flag
2019-10-04T21:11:04.4456366Z To only update this specific test, also pass `--test-args underscore-imports/hygiene.rs`
2019-10-04T21:11:04.4457151Z error: 1 errors occurred comparing output.
2019-10-04T21:11:04.4457197Z status: exit code: 1
2019-10-04T21:11:04.4457197Z status: exit code: 1
2019-10-04T21:11:04.4458253Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/underscore-imports/hygiene.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/underscore-imports/hygiene" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/underscore-imports/hygiene/auxiliary" "-A" "unused"
2019-10-04T21:11:04.4458617Z ------------------------------------------
2019-10-04T21:11:04.4458669Z 
2019-10-04T21:11:04.4458896Z ------------------------------------------
2019-10-04T21:11:04.4458941Z stderr:
2019-10-04T21:11:04.4458941Z stderr:
2019-10-04T21:11:04.4459171Z ------------------------------------------
2019-10-04T21:11:04.4465029Z error[E0599]: no method named `deref` found for type `&()` in the current scope
2019-10-04T21:11:04.4465452Z   --> /checkout/src/test/ui/underscore-imports/hygiene.rs:38:11
2019-10-04T21:11:04.4465534Z    |
2019-10-04T21:11:04.4465584Z LL |     (&()).deref();              //~ ERROR no method named `deref`
2019-10-04T21:11:04.4465635Z    |           ^^^^^ method not found in `&()`
2019-10-04T21:11:04.4465745Z    = help: items from traits can only be used if the trait is in scope
2019-10-04T21:11:04.4465745Z    = help: items from traits can only be used if the trait is in scope
2019-10-04T21:11:04.4465799Z help: the following trait is implemented but not in scope; perhaps add a `use` for it:
2019-10-04T21:11:04.4466259Z LL | use std::ops::Deref;
2019-10-04T21:11:04.4466306Z    |
2019-10-04T21:11:04.4467211Z 
2019-10-04T21:11:04.4467296Z error[E0599]: no method named `deref_mut` found for type `&mut ()` in the current scope
2019-10-04T21:11:04.4467296Z error[E0599]: no method named `deref_mut` found for type `&mut ()` in the current scope
2019-10-04T21:11:04.4467685Z   --> /checkout/src/test/ui/underscore-imports/hygiene.rs:39:15
2019-10-04T21:11:04.4467736Z    |
2019-10-04T21:11:04.4467786Z LL |     (&mut ()).deref_mut();      //~ ERROR no method named `deref_mut`
2019-10-04T21:11:04.4467855Z    |               ^^^^^^^^^ method not found in `&mut ()`
2019-10-04T21:11:04.4467944Z    = help: items from traits can only be used if the trait is in scope
2019-10-04T21:11:04.4467944Z    = help: items from traits can only be used if the trait is in scope
2019-10-04T21:11:04.4468019Z help: the following trait is implemented but not in scope; perhaps add a `use` for it:
2019-10-04T21:11:04.4468108Z LL | use std::ops::DerefMut;
2019-10-04T21:11:04.4468166Z    |
2019-10-04T21:11:04.4468193Z 
2019-10-04T21:11:04.4468237Z error: aborting due to 2 previous errors
---
2019-10-04T21:11:04.4502434Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-10-04T21:11:04.4502557Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-10-04T21:11:04.4526484Z 
2019-10-04T21:11:04.4526584Z 
2019-10-04T21:11:04.4529489Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-10-04T21:11:04.4529788Z 
2019-10-04T21:11:04.4529822Z 
2019-10-04T21:11:04.4535192Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-10-04T21:11:04.4535267Z Build completed unsuccessfully in 1:13:07
2019-10-04T21:11:04.4535267Z Build completed unsuccessfully in 1:13:07
2019-10-04T21:11:04.4603407Z == clock drift check ==
2019-10-04T21:11:04.4615695Z   local time: Fri Oct  4 21:11:04 UTC 2019
2019-10-04T21:11:04.5608058Z   network time: Fri, 04 Oct 2019 21:11:04 GMT
2019-10-04T21:11:04.5612707Z == end clock drift check ==
2019-10-04T21:11:05.9729302Z ##[error]Bash exited with code '1'.
2019-10-04T21:11:05.9795738Z ##[section]Starting: Checkout
2019-10-04T21:11:05.9797981Z ==============================================================================
2019-10-04T21:11:05.9798072Z Task         : Get sources
2019-10-04T21:11:05.9798119Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@JohnCSimon

This comment has been minimized.

Copy link
Member

JohnCSimon commented Oct 12, 2019

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

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Oct 12, 2019

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

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Oct 13, 2019

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

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Oct 13, 2019

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

@matthewjasper matthewjasper force-pushed the matthewjasper:underscore-imports branch from bc38b56 to bdb37e5 Oct 13, 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, .. }, .. } => {}

This comment has been minimized.

Copy link
@petrochenkov

petrochenkov Oct 14, 2019

Contributor

What happens if this special case is removed? Some diagnostics regress?

This comment has been minimized.

Copy link
@matthewjasper

matthewjasper Oct 15, 2019

Author Contributor

I don't think so, we just won't be able to remove it in resolve_imports.rs:831.

This comment has been minimized.

Copy link
@petrochenkov

petrochenkov Oct 15, 2019

Contributor

Ah, I see, the disambiguator is not available in that context.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Oct 15, 2019

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

Instead add a disambiguator to the keys used for distinguishing
resolutions.
@matthewjasper matthewjasper force-pushed the matthewjasper:underscore-imports branch from bdb37e5 to 4198df1 Oct 15, 2019
@matthewjasper

This comment has been minimized.

Copy link
Contributor Author

matthewjasper commented Oct 15, 2019

@bors r=petrochenkov

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 15, 2019

📌 Commit 4198df1 has been approved by petrochenkov

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
4 checks passed
4 checks passed
pr Build #20191015.53 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (LinuxTools) LinuxTools succeeded
Details
@matthewjasper matthewjasper deleted the matthewjasper:underscore-imports branch Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.