-
Notifications
You must be signed in to change notification settings - Fork 14k
don't normalize where-clauses when checking well-formedness #148477
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
base: main
Are you sure you want to change the base?
Conversation
|
@bors try |
This comment has been minimized.
This comment has been minimized.
crater: don't normalize where-clauses when checking well-formedness
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
☔ The latest upstream changes (presumably #139558) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Affected projects: 2 dependencies of
|
|
I think we should also stop normalizing in rust/compiler/rustc_hir_analysis/src/check/wfcheck.rs Lines 1154 to 1163 in a7b3715
|
|
And probably these
|
This comment has been minimized.
This comment has been minimized.
|
wrt to normalizing obligations for default params before proving them 😅 we do need to normalize obligations before proving them in the old solver and this already doesn't normalize
rust/compiler/rustc_middle/src/ty/predicate.rs Lines 125 to 127 in 5dbf406
The only "issue" is when normalizing obligations (or types - which we currently sometimes do intentionally because of implied bounds stuff) before checking that the obligation is well-formed, and this only happens before calling |
|
@bors try |
This comment has been minimized.
This comment has been minimized.
crater: don't normalize where-clauses when checking well-formedness
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
@rfcbot fcp merge types SummaryThis remove the normalization of where-clauses before checking that they are well-formed, causing the following pattern to now error: pub struct View<A>(A);
pub trait Data {
type Elem;
}
impl<'a, A> Data for View<&'a A> {
type Elem = A;
}
pub fn repro<'a, T>()
where
<View<&'a T> as Data>::Elem: Sized, // ERRROR: requires `T: 'a`
{
}We generally do not want to check well-formedness after normalization. Normalization expects its input to be well-formed and we break that invariant by normalizing before we ever check well-formedness. Due to reasons we currently do sometimes normalize before checking well-formedness. Notably we do so for impl headers. We are only able to use the normalized impl header for implied bounds, so checking that the unnormalized impl header is well-formed results in undesirable errors. Note that this is currently unsound, cc #100051. Other parts of the type system do check well-formedness before normalizing, e.g. function signatures are checked for well-formedness before normalization inside of MIR borrowck. We also check WF of types inside of bodies before normalization. We generally want to move towards always checking WF before normalization. While it currently can result in WF types in the source being accepted, e.g. We should move everything to check well-formedness before normalization once we've got proper implied bounds support, as that allows us to use implied bounds from unnormalized types in the signature without being unsound. Until then, I would also like to move as much code as possible to check WF before normalization as long as the resulting breakage is acceptable. I spent some time looking at the relevant code and it's somewhat of a mess and expect us to be able to do a lot here even before then. E.g. we should start checking also checking the type of constants for WF before normalizing it #100041. I do think this is a step in the right direction and would like to merge this as is. I am open to mentoring somebody already somewhat experienced here. We should probably start by collecting and documenting the status quo: where do we check WF before normalization and where do we not so yet. This fixes the divergence between the old and new solver from rust-lang/trait-system-refactor-initiative#255 by also emitting an error in the old solver. What is stabilized n/aWhat isn't stabilized n/aDesignReferenceThe reference does not describe whether and how we normalize before checking well-formedness. RFC history n/aAnswers to unresolved questions n/aPost-RFC changes n/aKey points n/aNightly extensions n/aDoors closed n/aFeedbackCall for testing n/aNightly use n/aImplementationMajor parts n/aCoverage@lqd, please add the test from rust-lang/trait-system-refactor-initiative#255 Outstanding bugsOur handling of well-formedness is generally something of a mess right now. While some of these issues require proper implied bounds on binders support, not all of them do and we should look into fixing some of them. We don't check WF before normalization in places where we should, e.g. #100041. Even when only getting implied bounds after normalization, our handling of them is still unsound #100051. We also sometimes don't check WF at all, e.g. #123312 or #104478. Outstanding FIXMEs n/aTool changes n/aBreaking changesCrater report: #148477 (comment) We've got
we should reach out to https://github.com/vilicvane/unipipe to suggest moving the self-type as a trait argument of the generated traits, see #t-types/nominated > #148477: crater: don't normalize where-clauses when checkin… @ 💬. I think we should opening a PR for them before landing this. If that fix does not work out I would still land this breakage regardless. Type system, opsemCompile-time checks n/aType system rules n/aSound by default? n/aBreaks the AM? n/aCommon interactionsTemporaries n/aDrop order n/aPre-expansion / post-expansion n/aEdition hygiene n/aSemVer implications n/aExposing other features n/aHistoryWould be nice, so much effort though and I don't want to block this PR on that 😅 Acknowledgments n/aOpen items
References n/a |
|
@rfcbot ping |
|
This PR changes a file inside |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rfcbot fcp merge types |
|
Team member @lcnr has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@lcnr can you say more here? Do you mean, if the fix "works" but isn't what they "want", we should still land the breakage? Or even if the fix doesn't work? Or if they just don't land it, etc.? I would like to land this, but I feel mildy uncomfortable landing without a fix that actually works. I'm okay to land if @lqd's fix works and they don't land it for whatever reason, but less okay if the fix doesn't actually work. |
|
@jackh726 To be clear, I have working fixes for both crates. The maintainers could improve upon them for sure, but they are at least one way where the crates won't be broken by this PR, and that was the important point to me to minimize the breakage. |
I would landed this even if we were unable to come up with a localized fix, though @lqd ended up with a working fix, so that point is moot :> |
WfCheck checks where-clauses after normalization, and we'd like to see what would break if it didn't for rust-lang/trait-system-refactor-initiative#255
r? ghost