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

Register wf obligation before normalizing in wfcheck #100046

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Aug 2, 2022

Fixes #100041.

Why are we normalizing in wfcheck at all? Should we just be dealing w unnormalized types? I guess whether we normalize or not at all has effects on implied bounds...

cc @rust-lang/types

r? types

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 2, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 2, 2022
if obligation.predicate.has_projections() {
// Normalizing WellFormed predicates is not sound, see #100041
if obligation.predicate.has_projections()
&& !matches!(
Copy link
Member Author

Choose a reason for hiding this comment

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

This shouldn't be necessary once @lcnr's PR #99217 lands, and we should use obligation.predicate.allow_normalization() here instead.

@compiler-errors compiler-errors changed the title Don't normalize types in wfcheck Register wf obligation before normalizing in wfcheck Aug 2, 2022
@lcnr
Copy link
Contributor

lcnr commented Aug 2, 2022

this is a breaking change again, for similar reasons to #99217.

I think we would want to merge these two PRs and get another crater run in 😅

apart from that lgtm
r? @lcnr

@rust-highfive rust-highfive assigned lcnr and unassigned jackh726 Aug 2, 2022
@lcnr
Copy link
Contributor

lcnr commented Aug 2, 2022

Why are we normalizing in wfcheck at all?

anything that's not wf checking pretty much expects normalized inputs 😅 without lazy norm having unnormalized projections tends to be bad™️. we do normalize in fulfill so for obligations that requirement doesn't really exist anymore1, but e.g. combine (infcx.at(cause, param_env).eq(a, b)) still expect a and b to be normalized as much as possible.

Footnotes

  1. maybe we do want to completely stop normalizing obligations before adding them as that should improve error messages, not sure about the perf impact.

@compiler-errors
Copy link
Member Author

@lcnr yeah, I'm more curious about whether it's correct/important to have normalized types before we add them to the implied bounds list, like here: https://github.com/rust-lang/rust/blob/master/compiler/rustc_typeck/src/check/wfcheck.rs#L1523

This PR doesn't affect that, for example (just moves the WF obligation on that fn sig's types to before they get normalized). Should we be normalizing types there at all?

@lcnr
Copy link
Contributor

lcnr commented Aug 2, 2022

@lcnr yeah, I'm more curious about whether it's correct/important to have normalized types before we add them to the implied bounds list, like here: https://github.com/rust-lang/rust/blob/master/compiler/rustc_typeck/src/check/wfcheck.rs#L1523

This PR doesn't affect that, for example (just moves the WF obligation on that fn sig's types to before they get normalized). Should we be normalizing types there at all?

With the changes to normalization in fulfill, and maybe some other ones of #99217, we are allowed to (and should) add both. We do need to add the normalized ones as we currently don't elaborate implied bounds. If you have <T as Trait<'a>>::Assoc which normalizes to &'a T, just adding <T as Trait<'a>>::Assoc as an implied bound doesn't allow you to assume T: 'a inside of the function. If we merge your PR with #99217 we should check that every time we add implied bounds, we add both normalized and unnormalized ones (alternatively, add unnormalized ones and also add the normalized ones in add_implied_bounds 😁)

@compiler-errors
Copy link
Member Author

Alright. That makes sense, thanks for the explanation.

As a first step I can cherry-pick #99217 onto this branch so we can do another crater run of the merged code.

I'll think a bit more about the best way that we can collect both the normalized and un-normalized forms of those types in wfcheck.

@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Aug 4, 2022

⌛ Trying commit 854a9eb2d1feaa755ed9827216f314bd29cd7854 with merge d76952bc2a74b981479554f7e1e2c6f8a8c3e3bf...

@bors
Copy link
Contributor

bors commented Aug 4, 2022

☀️ Try build successful - checks-actions
Build commit: d76952bc2a74b981479554f7e1e2c6f8a8c3e3bf (d76952bc2a74b981479554f7e1e2c6f8a8c3e3bf)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-100046 created and queued.
🤖 Automatically detected try build d76952bc2a74b981479554f7e1e2c6f8a8c3e3bf
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2022
@craterbot
Copy link
Collaborator

🚧 Experiment pr-100046 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-100046 is completed!
📊 31 regressed and 3 fixed (240511 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 12, 2022
@compiler-errors
Copy link
Member Author

We do need to add the normalized ones as we currently don't elaborate implied bounds

ok crater shows clearly that yeah i need to do this then

@compiler-errors compiler-errors 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2022
compiler-errors added a commit to compiler-errors-contrib/itsybitesyspider-retriever that referenced this pull request Aug 14, 2022
@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

Agreed we should be checking WF before normalization.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Aug 17, 2022
@rfcbot
Copy link

rfcbot commented Aug 17, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Aug 17, 2022
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Aug 27, 2022
@rfcbot
Copy link

rfcbot commented Aug 27, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Aug 27, 2022
@compiler-errors
Copy link
Member Author

Lol, so this PR cannot land as-is anymore because of #100676 and a few other PRs. I need to rework this now.

@compiler-errors
Copy link
Member Author

@lcnr I think this is blocked on your work to get both the unnormalized and normalized versions of a type to be considered implied wf types, correct? Since e6b8a2129fdfe4fcde1e418a8b3ec479a23c87f1 is obsolete (we don't collect implied wf tys here anymore).

@bors
Copy link
Contributor

bors commented Aug 31, 2022

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

Comment on lines +291 to +292
// Normalizing WellFormed predicates is not sound, see #100041
if obligation.predicate.has_projections() && obligation.predicate.allow_normalization() {
Copy link
Contributor

Choose a reason for hiding this comment

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

already dealt with by try_normalize_with_depth_to, no need to check for allow_normalization here

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh cool

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Sep 8, 2022
@lcnr lcnr added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 12, 2022
@lcnr
Copy link
Contributor

lcnr commented Sep 12, 2022

blocked on implied bounds for unnormalized types, should hopefully implement this over the next few weeks

@aliemjay
Copy link
Member

#105948 should probably be fixed first. Otherwise this will break the following arguably correct code:

trait Trait { type Ty; }
impl<T> Trait for T { type Ty = (); }
fn pass<T>(_: <&'static T as Trait>::Ty) {}

@lcnr
Copy link
Contributor

lcnr commented Mar 22, 2023

closing this PR as #100046 (comment) is blocked on -Ztrait-solver=next plus additional work, so that's going to take a while

@lcnr lcnr closed this Mar 22, 2023
@compiler-errors compiler-errors deleted the dont-normalize-in-wfcheck branch March 22, 2023 15:12
@aliemjay
Copy link
Member

It is not clear to me why this is blocked on the next trait solver. Is it because of the regression in this ui test? If so it can be simply unblocked by fixing #105948 first.

@lcnr
Copy link
Contributor

lcnr commented Mar 31, 2023

we need the unnormalized implied bounds for impl headers as well. Fixing #105948 would only fix it in function signatures 🤔 I think the following test breaks with this PR:

trait Trait {}

trait ToUnit {
    type Assoc;
}
impl<T> ToUnit for T {
    type Assoc = ();
}

impl<'a, 'b> Trait for <&'a &'b () as ToUnit>::Assoc {}

itsybitesyspider added a commit to itsybitesyspider/retriever that referenced this pull request Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Normalization can skip WF