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

Gracefully handle overflow errors in impl rematching #122539

Closed
wants to merge 3 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 15, 2024

fixes #122529

I believe the second commit is entirely sound, because all we're doing is turning an ICE into a hard error.

The first commit is where we now enable more situations to have non-fatal overflow. There are multiple fishy things, that I will leave comments on directly in the diff.

r? @lcnr

@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 Mar 15, 2024
Ok(term) => term.ty().unwrap(),
Err(oflo) => {
self.overflowed = Err(oflo);
return ty;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

slight behaviour change, before this PR the normalize_projection_type would replace the entire projection with an inference variable and set up the correct obligations. I can replicate the previous behaviour, but afaict we're in a doomed normalization anyway.

}
Err(ProjectionNormalizationFailure::Overflow(oflo)) => {
self.overflowed = Err(oflo);
return ty;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't even bother to recurse with super_fold_with, could probably do that, as it's what callers expect.

@@ -925,6 +925,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// since we don't actually use them.
&mut vec![],
)
.ok()?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if normalization overflowed, we will not do the migration. To combine both infallible overflowing normalization and this migration, some truly cursed shenanigans are necessary, if possible at all.

@@ -40,7 +40,8 @@ fn normalize_canonicalized_projection_ty<'tcx>(
cause,
0,
&mut obligations,
);
)
.map_err(|_| NoSolution)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overflow would have errored out below anyway, causing NoSolution, so we're just doing this early now

ReservationImpl,
#[allow(dead_code)]
TypeError(TypeError<'tcx>),
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

why allow(dead_code)?

@lcnr
Copy link
Contributor

lcnr commented Mar 22, 2024

I believe this to be necessary because project doesn't fatally error when encoutering overflow (and so do canonical queries), but they still cache the result, which is wonderful, because it means the candidate_cache is recursion depth dependent but does not track it.

While your fix tampers over this, imo the underlying issue is not fixeable. E.g. the change in match_impl can also affect the final result of a goal, so you can somehow get completely different results based on this.

idk, I am annoyed by this and would like to just keep the ICE around but do accept that apart from your approach, there's nothing feasible we can do here. Disabling the cache when hitting the recursion_limit in project causes hangs, so that's not an option either. Can review to make sure this doesn't allow any new code to pass depending on how much you care about fixing that ICE

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 22, 2024

Let's keep the ICE around. There are useful errors in addition to the ICE and the new solver fixes it correctly

@oli-obk oli-obk closed this Mar 22, 2024
@oli-obk oli-obk deleted the impl_confirmation_ice branch March 22, 2024 14:10
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: impl .. was matchable against Binder { .. } but now is not
3 participants