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

nll type annotations in multisegment path #55093

Merged
merged 19 commits into from
Oct 17, 2018

Conversation

nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Oct 15, 2018

This turned out to be sort of tricky. The problem is that if you have a path like

<Foo<&'static u32>>::bar

and it comes from an impl like impl<T> Foo<T> then the self-type the user gave doesn't directly map to the substitutions that the impl wants. To handle this, then, we have to preserve not just the "user-given substs" we used to do, but also a "user-given self-ty", which we have to apply later. This PR makes those changes.

It also removes the code from NLL relate-ops that handled canonical variables and moves to use normal inference variables instead. This simplifies a few things and gives us a bit more flexibility (for example, I predict we are going to have to start normalizing at some point, and it would be easy now).

r? @matthewjasper -- you were just touching this code, do you feel comfortable reviewing this?

Fixes #54574

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 15, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.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.

[00:04:12] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:13] tidy error: /checkout/src/librustc_mir/hair/cx/expr.rs:725: line longer than 100 chars
[00:04:13] tidy error: /checkout/src/librustc/mir/visit.rs:217: line longer than 100 chars
[00:04:13] tidy error: /checkout/src/librustc/mir/visit.rs:786: line longer than 100 chars
[00:04:14] some tidy checks failed
[00:04:14] 
[00:04:14] 
[00:04:14] 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:04:14] 
[00:04:14] 
[00:04:14] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:14] Build completed unsuccessfully in 0:00:46
[00:04:14] Build completed unsuccessfully in 0:00:46
[00:04:14] Makefile:79: recipe for target 'tidy' failed
[00:04:14] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:1c2510b8
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:0c8fd2b9:start=1539609067031300881,finish=1539609067035337065,duration=4036184
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:200a90a8
$ 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:02ceb97a
travis_time:start:02ceb97a
$ 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:0beccaec
$ 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)

src/librustc/ty/subst.rs Outdated Show resolved Hide resolved
src/librustc/infer/nll_relate/mod.rs Outdated Show resolved Hide resolved
@rust-highfive

This comment has been minimized.

@nikomatsakis nikomatsakis force-pushed the nll-issue-54574-multisegment-path branch from d5eba13 to 63f5057 Compare October 15, 2018 16:14
@bors
Copy link
Contributor

bors commented Oct 15, 2018

☔ The latest upstream changes (presumably #54858) made this pull request unmergeable. Please resolve the merge conflicts.

At some point, I had thought to use this code to handle equality
comparisons for the `IfEq` verify bounds; at that point, we might not
have had an infcx to talk about. But we wound up doing "SCC
representatives" instead, so that's fine.
This used to be public, then I made it private in a previous PR, but
there really wasn't a strong need for that.
We used to use a kind of "home-grown" variant where we tracked the
value of each canonical variable.
The name is not great. Nor is the existence of this code great.  It
should be merged with the main "type relating code" at some point.
@nikomatsakis nikomatsakis force-pushed the nll-issue-54574-multisegment-path branch from 049f1e6 to 7ce2e7a Compare October 15, 2018 20:25
Copy link
Contributor

@matthewjasper matthewjasper left a comment

Choose a reason for hiding this comment

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

LGTM. Not sure how confident I am reviewing a PR of this size though.

@nikomatsakis
Copy link
Contributor Author

r? @pnkfelix

Copy link
Member

@pnkfelix pnkfelix left a comment

Choose a reason for hiding this comment

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

If you end up rebasing this PR, you might as well move 24bee00 down next to e339e84 and then squash the former into the latter.

(But I haven't seen anything yet that would stop me from r+'ing this, I'm just noting it.)

Copy link
Member

@pnkfelix pnkfelix left a comment

Choose a reason for hiding this comment

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

hooray for the new UserTypeAnnotation enum! I hope this will make the corresponding visit methods easier to grok

Copy link
Member

@pnkfelix pnkfelix left a comment

Choose a reason for hiding this comment

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

Eeek regarding e7ed997; its a shame we couldn't continue keeping the contents of nll_relate hidden away under rustc_mir::borrow_check::nll ...

pub substs: &'tcx Substs<'tcx>,

/// The self-type, in the case of a `<T>::Item` path (when applied
/// to an inherent impl). See `UserSubsts` below.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand where the reader is meant to be led by the "See UserSubsts below."

Copy link
Member

Choose a reason for hiding this comment

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

(Probably a typo for UserSelfTy.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, fixing

struct A<'a> { x: &'a u32 }

impl<'a> A<'a> {
fn new<'b, T>(x: &'a u32, y: T) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

why is there a 'b here?

Copy link
Member

Choose a reason for hiding this comment

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

(I see the same thing occuring in the other tests. To be honest I had thought that we didn't allow unreferenced lifetimes in generic binders ... but I guess that is just a lint, when it comes to lifetimes...?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy and paste error, I think


fn foo<'a>() {
let v = 22;
let x = A::<'a>::new(&v, 22);
Copy link
Member

Choose a reason for hiding this comment

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

I think you and I mirrored each other on our respective PR's; there should be an //~ ERROR on this line, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eep yes, will add.

@pnkfelix
Copy link
Member

I had a slew of nits. But none of them should block landing this PR, and frankly, I want to rebase my own work pronto on top of this.

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 16, 2018

📌 Commit 7ce2e7a has been approved by pnkfelix

@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 Oct 16, 2018
@nikomatsakis
Copy link
Contributor Author

@bors p=1 -- lots of stuff wants to build on this

@nikomatsakis
Copy link
Contributor Author

@pnkfelix

Eeek regarding e7ed997; its a shame we couldn't continue keeping the contents of nll_relate hidden away under rustc_mir::borrow_check::nll ...

Well, I was hoping they will get unified at some point, in which case it makes sense.

@nikomatsakis
Copy link
Contributor Author

@bors r=pnkfelix p=1

@bors
Copy link
Contributor

bors commented Oct 16, 2018

📌 Commit b70b4a6 has been approved by pnkfelix

@bors
Copy link
Contributor

bors commented Oct 16, 2018

⌛ Testing commit b70b4a6 with merge 01ca85b...

bors added a commit that referenced this pull request Oct 16, 2018
…, r=pnkfelix

nll type annotations in multisegment path

This turned out to be sort of tricky. The problem is that if you have a path like

```
<Foo<&'static u32>>::bar
```

and it comes from an impl like `impl<T> Foo<T>` then the self-type the user gave doesn't *directly* map to the substitutions that the impl wants. To handle this, then, we have to preserve not just the "user-given substs" we used to do, but also a "user-given self-ty", which we have to apply later. This PR makes those changes.

It also removes the code from NLL relate-ops that handled canonical variables and moves to use normal inference variables instead. This simplifies a few things and gives us a bit more flexibility (for example, I predict we are going to have to start normalizing at some point, and it would be easy now).

r? @matthewjasper -- you were just touching this code, do you feel comfortable reviewing this?

Fixes #54574
@bors
Copy link
Contributor

bors commented Oct 17, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing 01ca85b to master...

@bors bors merged commit b70b4a6 into rust-lang:master Oct 17, 2018
@tmandry tmandry added the WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 label May 24, 2023
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. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nll should respect lifetime annotations from multi-segment paths
6 participants