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

resolve: collect trait aliases along with traits #59166

Merged
merged 2 commits into from
Apr 2, 2019

Conversation

seanmonstar
Copy link
Contributor

It seems trait aliases weren't being collected as TraitCandidates in resolve, this should change that. (I can't compile the full compiler locally, so relying on CI...)

Fixes #56485

r? @alexreg

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 13, 2019
@alexreg
Copy link
Contributor

alexreg commented Mar 13, 2019

@seanmonstar Okay, all looks good. Thanks for the PR! I'll r+ when CI passes.

Is there any case concerning the importing of trait aliases that you think should be supported but still isn't, after this PR?

@alexreg
Copy link
Contributor

alexreg commented Mar 13, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Mar 13, 2019

📌 Commit b63230fa4e7b13e98cc62629a0116eeb986c548b has been approved by alexreg

@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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 13, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (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.
travis_time:end:00157aa0:start=1552515438494384411,finish=1552515525729300107,duration=87234915696
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---
travis_time:start:test_ui
Check compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:09:57] 
[01:09:57] running 5467 tests
[01:09:59] ..............................................................................................F..... 100/5467
[01:10:06] .................................................................................................... 300/5467
[01:10:09] .................................................................................................... 400/5467
[01:10:12] .................................................................................................... 500/5467
[01:10:16] ..........................................i......................................................... 600/5467
---
[01:12:51] ............i....................................................................................... 4700/5467
[01:12:57] .................................................................................................... 4800/5467
[01:13:00] .................................................................................................... 4900/5467
[01:13:04] .................................................................................................... 5000/5467
[01:13:08] ..................................F................................................................. 5100/5467
[01:13:14] .................................................................................................... 5300/5467
[01:13:17] .................................................................................................... 5400/5467
[01:13:19] .....i.............................................................
[01:13:19] failures:
[01:13:19] failures:
[01:13:19] 
[01:13:19] ---- [ui] ui/associated-types/associated-types-overridden-binding-2.rs stdout ----
[01:13:19] 
[01:13:19] error: Error: expected failure status (Some(1)) but received status Some(101).
[01:13:19] status: exit code: 101
[01:13:19] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/associated-types/associated-types-overridden-binding-2.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-types/associated-types-overridden-binding-2/a" "-Crpath" "-O" "-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/associated-types/associated-types-overridden-binding-2/auxiliary" "-A" "unused"
[01:13:19] ------------------------------------------
[01:13:19] 
[01:13:19] ------------------------------------------
[01:13:19] stderr:
---
[01:13:19] note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
[01:13:19] 
[01:13:19] note: rustc 1.35.0-dev running on x86_64-unknown-linux-gnu
[01:13:19] 
[01:13:19] note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath
[01:13:19] 
[01:13:19] ------------------------------------------
[01:13:19] 
[01:13:19] thread '[ui] ui/associated-types/associated-types-overridden-binding-2.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3325:9
[01:13:19] thread '[ui] ui/associated-types/associated-types-overridden-binding-2.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3325:9
[01:13:19] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:13:19] 
[01:13:19] ---- [ui] ui/traits/trait-alias-object.rs stdout ----
[01:13:19] 
[01:13:19] error: Error: expected failure status (Some(1)) but received status Some(101).
[01:13:19] status: exit code: 101
[01:13:19] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/traits/trait-alias-object.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/traits/trait-alias-object/a" "-Crpath" "-O" "-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/traits/trait-alias-object/auxiliary" "-A" "unused"
[01:13:19] ------------------------------------------
[01:13:19] 
[01:13:19] ------------------------------------------
[01:13:19] stderr:
---
[01:13:19] note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
[01:13:19] 
[01:13:19] note: rustc 1.35.0-dev running on x86_64-unknown-linux-gnu
[01:13:19] 
[01:13:19] note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath
[01:13:19] 
[01:13:19] ------------------------------------------
[01:13:19] 
[01:13:19] thread '[ui] ui/traits/trait-alias-object.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3325:9
---
[01:13:19] 
[01:13:19] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:496:22
[01:13:19] 
[01:13:19] 
[01:13:19] 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 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -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"
[01:13:19] 
[01:13:19] 
[01:13:19] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:13:19] Build completed unsuccessfully in 0:04:24
[01:13:19] Build completed unsuccessfully in 0:04:24
[01:13:19] Makefile:48: recipe for target 'check' failed
[01:13:19] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0006e7f0
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Mar 13 23:32:14 UTC 2019

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)

@seanmonstar
Copy link
Contributor Author

Is there any case concerning the importing of trait aliases that you think should be supported but still isn't, after this PR?

I'd love some sort of late bounds on associated types that are themselves generic. Like this example:

trait Svc<Req> {
    type Res;
}

mod http {
    struct Req;
    struct Res<B>(pub B);

    trait Body {}

    trait HttpSvc = <B> super::Svc<Req, Res = Res<B>> {
        type Res = B;
    }
}

I'd need some way to propagate the body generic out of the Res<B>, but without requiring the generic on the HttpSvc itself (so not HttpSvc<B>), since it's based on an associated type.

@seanmonstar
Copy link
Contributor Author

Oh noes, those errors... too bad the tests aren't run with RUST_BACKTRACE=1, I've no idea where those unwraps are...

@alexreg
Copy link
Contributor

alexreg commented Mar 14, 2019

Weird... Bors didn't auto-cancel this PR.

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 14, 2019
@alexreg
Copy link
Contributor

alexreg commented Mar 14, 2019

@seanmonstar Poke me once you have the backtraces for those errors.

@alexreg
Copy link
Contributor

alexreg commented Mar 14, 2019

I'd love some sort of late bounds on associated types that are themselves generic. ...

I think you're talking generic associated types, unless I'm mistaken? This feature has been in the works for a while now, and should be in nightly in the coming months, we hope, though it's hard to predict exactly.

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 14, 2019

@seanmonstar
Support for resolving methods from traits in scope contains two components - collecting the traits in scope (this PR does that), and then processing the collected traits in fn assemble_extension_candidates_for_traits_in_scope and looks like that function is not prepared to encounter trait aliases in the list yet.

@petrochenkov
Copy link
Contributor

petrochenkov unassigned alexreg just now

(The unassignment is unintentional and looks like it's performed automatically by GitHub as a side effect of blocking.)

@davidbarsky
Copy link
Contributor

@seanmonstar I was able to build and test your branch. I've pasted the test failures into a gist.

@alexreg
Copy link
Contributor

alexreg commented Mar 14, 2019

Thanks for that, @davidbarsky. Yes, the error is clearly occurring in get_traits_in_module_containing_item in rustc_resolve.

@seanmonstar So, I think the issue is that during the assembly of the map of all traits, trait aliases is being ignored. Take a look at compute_all_traits in src/librustc_typeck/check/method/suggest.rs

Specifically, I think you want to modify

        fn visit_item(&mut self, i: &'v hir::Item) {
            if let hir::ItemKind::Trait(..) = i.node {
                let def_id = self.map.local_def_id_from_hir_id(i.hir_id);
                self.traits.push(def_id);
            }
        }

as well as the match below (in handle_external_def) to account for ItemKind::TraitAlias too. That may be enough.

@seanmonstar
Copy link
Contributor Author

So I've managed to get the compiler building, and have since gone down a rabbit hole figuring this out:

  • Even though I'd modified visit_item and such, the get_traits_in_module_containing_item won't ever return it because a trait alias never contains anything.
  • I learned how the compiler resolves an alias when there's fn foo<T: SomeAlias>, by treating all the aliased traits as "super" traits in rustc_typeck::check::method::probe::elaborate_bounds.

So I'm thinking about next steps, possibly one of these is better:

  • I could try to do something like elaborate bounds for trait aliases in rustc_resolve, but it doesn't do that for anything else, and it may be out of place.
  • In get_traits_id_module_containing_item, I could just slurp all imported aliases without checking if they contain the item, and then in probe, try to elaborate bounds if the candidate is an alias.

Are both of those too crazy?

@seanmonstar
Copy link
Contributor Author

I went for the second option, which got the one new run-pass test passing. I'm still a little iffy about it, and there should probably be some more compile-fail tests added. That come to mind:

  • That a type that implements part of the alias but not all doesn't have it's methods resolved.
  • Does this pollute resolution/probing for other types in the same module?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (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.
travis_time:end:014845bf:start=1552686990128486521,finish=1552687065743304101,duration=75614817580
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
Setting environment variables from .travis.yml
---

[00:03:38] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:39] tidy error: /checkout/src/librustc_typeck/check/method/probe.rs:899: TODO is deprecated; use FIXME
[00:03:39] tidy error: /checkout/src/librustc_typeck/check/method/probe.rs:911: line longer than 100 chars
[00:03:39] tidy error: /checkout/src/librustc_typeck/check/method/probe.rs:912: line longer than 100 chars
[00:03:39] tidy error: /checkout/src/librustc_resolve/lib.rs:4393: line longer than 100 chars
[00:03:39] tidy error: /checkout/src/librustc_resolve/lib.rs:4412: line longer than 100 chars
[00:03:40] some tidy checks failed
[00:03:40] 
[00:03:40] 
[00:03:40] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:03:40] 
[00:03:40] 
[00:03:40] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:40] Build completed unsuccessfully in 0:00:48
[00:03:40] Build completed unsuccessfully in 0:00:48
[00:03:40] Makefile:67: recipe for target 'tidy' failed
[00:03:40] make: *** [tidy] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:02fa50c0
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Fri Mar 15 22:01:34 UTC 2019
---
travis_time:end:12cf1686:start=1552687295649469690,finish=1552687295654195313,duration=4725623
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:255d56db
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1b552b78
travis_time:start:1b552b78
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:1cbcb5bf
$ dmesg | grep -i kill

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)

Copy link
Contributor

@alexreg alexreg left a comment

Choose a reason for hiding this comment

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

Good work. I think this is roughly the right approach, though I'll wait for someone else to confirm. See my suggestions in any case.

src/librustc_typeck/check/method/probe.rs Outdated Show resolved Hide resolved
src/librustc_typeck/check/method/suggest.rs Show resolved Hide resolved
}, false);
if is_trait_alias {
debug!("assemble_extension_candidates_for_trait; no items, assuming alias, elaborating bounds");
self.elaborate_bounds(iter::once(trait_ref.to_poly_trait_ref()), |this, new_trait_ref, item| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this call is right, but I'm no expert on this area, so perhaps someone else can confirm.

src/librustc_typeck/check/method/probe.rs Outdated Show resolved Hide resolved
src/librustc_typeck/check/method/probe.rs Outdated Show resolved Hide resolved
@alexreg
Copy link
Contributor

alexreg commented Mar 15, 2019

@seanmonstar

Oh, and not sure if you noticed, but your previous build failed early because of tidy checks -- so just wrap these lines.

[00:03:39] tidy error: /checkout/src/librustc_typeck/check/method/probe.rs:899: TODO is deprecated; use FIXME
[00:03:39] tidy error: /checkout/src/librustc_typeck/check/method/probe.rs:911: line longer than 100 chars
[00:03:39] tidy error: /checkout/src/librustc_typeck/check/method/probe.rs:912: line longer than 100 chars
[00:03:39] tidy error: /checkout/src/librustc_resolve/lib.rs:4393: line longer than 100 chars
[00:03:39] tidy error: /checkout/src/librustc_resolve/lib.rs:4412: line longer than 100 chars
[00:03:40] some tidy checks failed

@seanmonstar
Copy link
Contributor Author

Updated.

@bors
Copy link
Contributor

bors commented Apr 1, 2019

📌 Commit 3ccd35c has been approved by alexreg

@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 Apr 1, 2019
Centril added a commit to Centril/rust that referenced this pull request Apr 1, 2019
…lexreg

resolve: collect trait aliases along with traits

It seems trait aliases weren't being collected as `TraitCandidates` in resolve, this should change that. (I can't compile the full compiler locally, so relying on CI...)

Fixes rust-lang#56485

r? @alexreg
@bors
Copy link
Contributor

bors commented Apr 2, 2019

⌛ Testing commit 3ccd35c with merge 2ad603c82a9a5ea9cc0b28b0c850e80587148a5d...

@bors
Copy link
Contributor

bors commented Apr 2, 2019

💔 Test failed - checks-travis

@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (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.
Attempting to download s3://rust-lang-ci-sccache2/docker/e5e901098d9f2105078bcb654b17506cd01eea0f02060d26aa331e8f112a225803bc62c7b3167e5ec5c1e7d33c624e0a4ca42b427f270616c34617da72606f42
[00:06:42] Attempting with retry: curl -y 30 -Y 10 --connect-timeout 30 -f -L -C - -o /tmp/rustci_docker_cache https://s3-us-west-1.amazonaws.com/rust-lang-ci-sccache2/docker/e5e901098d9f2105078bcb654b17506cd01eea0f02060d26aa331e8f112a225803bc62c7b3167e5ec5c1e7d33c624e0a4ca42b427f270616c34617da72606f42
[00:06:42]   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
[00:06:42]                                  Dload  Upload   Total   Spent    Left  Speed
No output has been received in the last 30m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received
The build has been terminated

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)

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 2, 2019
@Centril
Copy link
Contributor

Centril commented Apr 2, 2019

@bors retry

@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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 2, 2019
@bors
Copy link
Contributor

bors commented Apr 2, 2019

⌛ Testing commit 3ccd35c with merge 23fa5c9586a98c9681ea76d6217f702e6ab473fb...

Centril added a commit to Centril/rust that referenced this pull request Apr 2, 2019
…lexreg

resolve: collect trait aliases along with traits

It seems trait aliases weren't being collected as `TraitCandidates` in resolve, this should change that. (I can't compile the full compiler locally, so relying on CI...)

Fixes rust-lang#56485

r? @alexreg
@Centril
Copy link
Contributor

Centril commented Apr 2, 2019

@bors retry

bors added a commit that referenced this pull request Apr 2, 2019
Rollup of 4 pull requests

Successful merges:

 - #59166 (resolve: collect trait aliases along with traits)
 - #59341 (Fix custom relative libdir)
 - #59446 (Fix stack overflow when generating debuginfo for 'recursive' type)
 - #59529 (Added documentation on the remainder (Rem) operator for floating points.)

Failed merges:

r? @ghost
@bors bors merged commit 3ccd35c into rust-lang:master Apr 2, 2019
@alexreg
Copy link
Contributor

alexreg commented Apr 2, 2019

Great, finally merged! Would someone kindly tick off the box on the issue #41517 and add (implemented by #59166) to the end of that that line? Maybe @Centril?

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.

Bringing a trait alias into scope doesn't allow calling methods from its component traits
8 participants