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

Stop using identity args for RPIT wf checks #114574

Closed
wants to merge 1 commit into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Aug 7, 2023

and instead load the args from the single use of a RPIT in its parent function's return type

follow up to #113661

fixes #114285

Before this PR, we used the RPIT identity substs for checking its hidden type's bounds. This means various late bound lifetimes from the function now became early bound lifetimes on the RPIT. That worked just fine, until you had nested RPITs that capture lifetimes, too. By accident it mostly worked, unless closures were involved.

While investigating this mess, I realized that we were going about all of this the wrong way around. Instead of trying to patch up the nested opaque types' hidden types, we could also just find the correct generic args of the opaque type that we're checking and not have to patch up anything after the fact.

So now, we walk the return type of the function, find the hidden type within that return type, and take its generic arguments. These generic arguments are in terms of the function signature, so they will have all late bound lifetimes still be in a binder. So we dismiss the binder by replacing all late bound vars in it with new inference vars, and then run the previous checks (minus the patching up, which was now dead code).

@rustbot
Copy link
Collaborator

rustbot commented Aug 7, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 7, 2023
…he args from the single use of a RPIT in its parent function's return type
@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 7, 2023

r? @compiler-errors @lcnr

@rustbot rustbot assigned compiler-errors and unassigned TaKO8Ki Aug 7, 2023
Comment on lines +648 to 652
ty::Alias(ty::Projection, alias) => {
if let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = self.tcx.opt_rpitit_info(alias.def_id) && fn_def_id == self.fn_def_id {
self.tcx.type_of(alias.def_id).instantiate(self.tcx, alias.args).visit_with(self)?;
}
_ => (),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was removed in #114267, but we would probably have had issues if RPITITs were behind binders or sth. Now that we always do this for every RPIT, there are no more hidden ICEs under rare circumstances, instead we now always find the usage unconditionally and ICE if we don't find it.

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 8, 2023

Superseded by #114602

@oli-obk oli-obk closed this Aug 8, 2023
@oli-obk oli-obk deleted the tait_wtf branch August 8, 2023 10:10
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 8, 2023
…s, r=oli-obk

Map RPIT duplicated lifetimes back to fn captured lifetimes

Use the [`lifetime_mapping`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html#structfield.lifetime_mapping) to map an RPIT's captured lifetimes back to the early- or late-bound lifetimes from its parent function. We may be going thru several layers of mapping, since opaques can be nested, so we introduce `TyCtxt::map_rpit_lifetime_to_fn_lifetime` to loop through several opaques worth of mapping, and handle turning it into a `ty::Region` as well.

We can then use this instead of the identity substs for RPITs in `check_opaque_meets_bounds` to address rust-lang#114285.

We can then also use `map_rpit_lifetime_to_fn_lifetime` to properly install bidirectional-outlives predicates for both RPITs and RPITITs. This addresses rust-lang#114601.

I based this on rust-lang#114574, but I don't actually know how much of that PR we still need, so some code may be redundant now... 🤷

---

Fixes rust-lang#114597
Fixes rust-lang#114579
Fixes rust-lang#114285

Also fixes rust-lang#114601, since it turns out we had other bugs with RPITITs and their duplicated lifetime params 😅.

Supersedes rust-lang#114574

r? `@oli-obk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: Region parameter out of range when substituting in region
4 participants