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

Fix const-generics ICE related to binding #86795

Merged
merged 5 commits into from
Jul 3, 2021
Merged

Conversation

JohnTitor
Copy link
Member

@JohnTitor JohnTitor commented Jul 1, 2021

Fixes #83765, fixes #85848
r? @jackh726 as you're familiar with Binding. I'd like to get some views if the current approach is right path.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 1, 2021
@rust-log-analyzer

This comment has been minimized.

@jackh726
Copy link
Member

jackh726 commented Jul 2, 2021

So, unfortunately this isn't correct :/

As you can see from the failed test, this indeed is a tricky case (see https://github.com/rust-lang/rust/pull/83825/files#diff-a54c982c1e255569ddede4404cdf85ecfbd93c20edfa8a090a5f2dc2bc1dff6bR119 where we were going to just shunt that BoundVarsCollector into the corner for now).

I knew that issue-64494#full was creating bound types that lose their Binder. But I just now found out that there are tests that create bound regions that lose their Binder.

Ultimately, the "solution" is to either 1) not be creating bound vars (I'm not familiar with the originating code) or 2) Ensure that we also keep the Binder (in rcvr_substs in this example) when creating the bound vars.

@camelid thinks that these are originating from the coherence code, but hasn't been able to track down more specifically.

One alternative to "fix" things for now, is to move BoundVarsCollector here as I would like in #83825 then just re-add the code that collects regions. Ideally, I would like the real fix, but I would also be fine with merging the patch. I left a few reviews on #83825; if you want to use that PR as a base, work through the review, and re-add the region code, I'm sure @camelid wouldn't mind :)

@JohnTitor
Copy link
Member Author

JohnTitor commented Jul 2, 2021

Thanks for checking!

  1. Ensure that we also keep the Binder (in rcvr_substs in this example) when creating the bound vars.

Could we achieve this by following?

- let bound_vars = tcx
-             .mk_bound_variable_kinds(std::iter::once(ty::BoundVariableKind::Region(ty::BrAnon(0))));
+ let bound_vars = trait_ref.to_poly_trait_ref().bound_vars();

And it's odd not to reproduce the issue-64494's failure on my local, how could I reproduce it?

@JohnTitor
Copy link
Member Author

JohnTitor commented Jul 2, 2021

Okay, moved BoundVarsCollector here (didn't actually move them because it'd cause a cyclic dependency error unless we move all the changes on #83825 here), added FIXME comment, and removed bug! macro. Can this be a "fix" for now? Actually not :(

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

I think I would rather this completely subsume the other PR, rather than just duplicate BoundVarsCollector (honestly, should be pretty quick).

compiler/rustc_ty_utils/src/instance.rs Show resolved Hide resolved
@jackh726
Copy link
Member

jackh726 commented Jul 2, 2021

Could we achieve this by following?

- let bound_vars = tcx
-             .mk_bound_variable_kinds(std::iter::once(ty::BoundVariableKind::Region(ty::BrAnon(0))));
+ let bound_vars = trait_ref.to_poly_trait_ref().bound_vars();

Nope! If you look at to_poly_trait_ref, it actually wraps it in a Binder::dummy (I would like at some point to remove these functions in favor of being more explicit at the call sites)

And it's odd not to reproduce the issue-64494's failure on my local, how could I reproduce it?

Weid. When I do ./x.py test src/test/ui/const-generics it repros fine

@JohnTitor
Copy link
Member Author

Thanks for the pointer! Pulled the changes from that PR applying your review comments.

Weid. When I do ./x.py test src/test/ui/const-generics it repros fine

Hmm, then maybe my config.toml or something else is wrong. For now, I'm using CI here for testing.

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

Some comments. Sorry this ended up being a bit more involved than you probably expected. 🙃

compiler/rustc_ty_utils/src/instance.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/wfcheck.rs Show resolved Hide resolved
Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

One small change (it gets removed in #85499 anyways, but would rather not make that here)

Then LGTM!

compiler/rustc_typeck/src/check/wfcheck.rs Show resolved Hide resolved
@jackh726
Copy link
Member

jackh726 commented Jul 2, 2021

@bors r+ rollup=never

There might be a slight perf improvement because of Binder::dummy, but the perf run done in #83825 suggests this is very slight, if any.

@bors
Copy link
Contributor

bors commented Jul 2, 2021

📌 Commit 58f6cb4 has been approved by jackh726

@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 Jul 2, 2021
@bors
Copy link
Contributor

bors commented Jul 2, 2021

⌛ Testing commit 58f6cb4 with merge b3af93d71879ea99014f96f89d1179326b25447b...

@bors
Copy link
Contributor

bors commented Jul 2, 2021

💔 Test failed - checks-actions

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@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 Jul 2, 2021
@JohnTitor
Copy link
Member Author

2021-07-02T23:00:37.2702922Z ##[group]Run exit 1
2021-07-02T23:00:37.3307585Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2021-07-02T23:00:37.3308542Z ##[endgroup]
2021-07-02T23:00:37.3778908Z ##[error]Process completed with exit code 1.
2021-07-02T23:00:37.3810471Z Cleaning up orphan processes

@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 Jul 2, 2021
@bors
Copy link
Contributor

bors commented Jul 3, 2021

⌛ Testing commit 58f6cb4 with merge cd48e61...

@bors
Copy link
Contributor

bors commented Jul 3, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing cd48e61 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 3, 2021
@bors bors merged commit cd48e61 into rust-lang:master Jul 3, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 3, 2021
@bors bors mentioned this pull request Jul 3, 2021
@JohnTitor JohnTitor deleted the fix-bind branch July 3, 2021 10:27
@Alexendoo Alexendoo mentioned this pull request Aug 9, 2021
@lcnr lcnr added the A-const-generics Area: const generics (parameters and arguments) label Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) merged-by-bors This PR was explicitly merged by bors. 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.

ICE in rust nightly 2021-05-30 ICE: Trying to collect bound vars with a bound region:
8 participants