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

Double check that hidden types match the expected hidden type #113661

Merged
merged 5 commits into from
Jul 26, 2023

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 13, 2023

Fixes #113278 specifically, but I left a TODO for where we should also add some hardening.

It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands.

r? @compiler-errors @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 13, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 14, 2023
"{}, {}",
tcx.type_of(key.def_id).subst(tcx, key.substs),
ty.hidden_type.ty
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should hit this bug? 🤔 or do we avoid it because we have OpaqueCast everywhere we would assign to/from opaques?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was surprised, too, but I didn't debug it.

Copy link
Contributor

Choose a reason for hiding this comment

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

do we run the validator before optimizations by default 😅 iirc we only do it with -Zvalidate-mir 🤔

Copy link
Member

Choose a reason for hiding this comment

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

#114121 :D

@oli-obk oli-obk force-pushed the tait_wtf branch 2 times, most recently from 92e7e6d to 7c75895 Compare July 20, 2023 09:36
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the tait_wtf branch 2 times, most recently from fa82e44 to 82fa94e Compare July 24, 2023 14:02
@rust-log-analyzer

This comment has been minimized.

/// // desugared to
///
/// // hidden type is `&'bDup ()`
/// // During wfcheck the hidden type of `Inner` is `&'a ()`, but
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// // During wfcheck the hidden type of `Inner` is `&'a ()`, but
/// // During wfcheck the hidden type of `Inner` is `&'b ()`, but

i feel like it is a bit weird to talk about 'bDup if it is unclear where 'b comes from. I prefer using 'a and 'aDup everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well... unless I double confused myself, your diff is wrong, so it's good that I made it explicit 😆

Copy link
Contributor

@lcnr lcnr Jul 24, 2023

Choose a reason for hiding this comment

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

how can the inner type in wf check be 'a if we wf check in the scope of the opaque type which does not have a 'a in scope? 😅

also, "During wfcheck of Outer ...", would make this clearer I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because RPITs aren't desugerable currently (ok I guess that's what you meant by "unclear where 'b comes from"), they only work by construction and are cheating. I rewrote the example to be more like how it actually works, is that clearer?

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

r=me after final comment nits

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

accurately documenting the desugaring is messy (because the desugaring is messy :3)

because RPITs aren't desugerable currently (ok I guess that's what you meant by "unclear where 'b comes from"), they only work by construction and are cheating. I rewrote the example to be more like how it actually works, is that clearer?

idk 😅 i don't know how much of my nits are "the actual impl is a mess" and how much is "the comment is wrong/incomplete"

@@ -545,17 +545,23 @@ fn sanity_check_found_hidden_type<'tcx>(
/// }
/// fn func<'a>(x: &'a ()) -> impl Id<Assoc = impl Sized + 'a> { x }
/// // desugared to
/// fn func<'a>(x: &'a () -> Outer<'a, Assoc = Inner<'a>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// fn func<'a>(x: &'a () -> Outer<'a, Assoc = Inner<'a>> {
/// fn func<'a>(x: &'a () -> Outer<'a, 'a> {

? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea... I don't know how to represent the fact that we walk the item bounds of Outer

/// // hidden type is `&'cDup ()`
/// type Inner<'c, 'cDup> = impl Sized + 'cDup;
/// fn func<'a>(x: &'a () -> Outer<'static, 'a> { x }
/// // hidden type is `&'aDupOuter ()`
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels wrong, if the hidden type of Outer is &'aDupOuter (), shouldn't wf check of Outer define the hidden type of Inner to be <&'aDupOuter () as Id>::Assoc which is &'aDupOuter (), so this should worK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because we figure out the hidden type of Inner anew during wf check of Outer, we don't get it from type_of. We get the hidden type of Outer, which is &'a (), so the id projection is also &'a ()

/// // So we walk the signature of `func` to find the use of `Inner<'a>`
/// // and then use that to replace the lifetimes in the hidden type, obtaining
/// // `&'a ()`.
/// type Outer<'aDupOuter> = impl Id<Assoc = Inner<'aDupOuter>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

is the 'a param of Inner 'a or 'aDupOuter here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'a, it is inherited from the function.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 25, 2023

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Jul 25, 2023

📌 Commit df4bfd9 has been approved by lcnr

It is now in the queue for this repository.

@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 25, 2023
@bors
Copy link
Contributor

bors commented Jul 25, 2023

⌛ Testing commit df4bfd9 with merge 50bb51b2201e3aa6ca651a9446f62088ca32d9f0...

@bors
Copy link
Contributor

bors commented Jul 25, 2023

💔 Test failed - checks-actions

@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 25, 2023
@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)

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 25, 2023

@bors retry nothing failed? Not sure what happened

@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 25, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#112995 (Check for `<&NotClone as Clone>::clone()` calls and suggest to add Clone trait appropriately)
 - rust-lang#113578 (Don't say that a type is uncallable if its fn signature has errors in it)
 - rust-lang#113661 (Double check that hidden types match the expected hidden type)
 - rust-lang#114044 (factor out more stable impls)
 - rust-lang#114062 (CI: split nested GHA groups instead of panicking)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0b13deb into rust-lang:master Jul 26, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 26, 2023
@oli-obk oli-obk deleted the tait_wtf branch July 27, 2023 08:13
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 14, 2023
… r=jackh726

Paper over an accidental regression

r? types

cc rust-lang#115781 (do not close issue until beta backport has been performed)

The PR reasons are explained with comments in the source.

In order to keep the diff simple, this PR effectively reverts rust-lang#113661, but only for RPITs. I will submit a follow up PR that fixes this correctly instead of just disabling the newly added check for RPITs. This PR should be significantly easier to review for beta backport
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 14, 2023
Rollup merge of rust-lang#115844 - oli-obk:opaque_lifetime_ambiguity, r=jackh726

Paper over an accidental regression

r? types

cc rust-lang#115781 (do not close issue until beta backport has been performed)

The PR reasons are explained with comments in the source.

In order to keep the diff simple, this PR effectively reverts rust-lang#113661, but only for RPITs. I will submit a follow up PR that fixes this correctly instead of just disabling the newly added check for RPITs. This PR should be significantly easier to review for beta backport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opaque type wf check anchor usage is unsound
7 participants