-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Update to fix regression 90319 and correctly emit overflow errors when not inside an error reporting context #91238
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #91354) made this pull request unmergeable. Please resolve the merge conflicts. |
90e3314
to
2f18023
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #91491) made this pull request unmergeable. Please resolve the merge conflicts. |
75387e7
to
6322948
Compare
Not sure if Matt is reviewing PR's but this one keeps hitting merge conflicts so would like to merge it before I have to rebase it again haha |
This comment has been minimized.
This comment has been minimized.
…n not in suggestion context Remove reintrod with_constness() selection context Update to fix regression 90319 and correctly emit overflow errors tidy run Update to fix regression 90319 and correctly emit overflow errors
6322948
to
930df17
Compare
r? @jackh726 perhaps? I'm not familiar enough with this code I think to review this well. |
I remember seeing #89576, but not thinking too much about it. Thinking about this a bit, I'm wondering if the fix applied there and here are not the best fix. I'm wondering if a better fix would be to delay omitting all overflow errors. As shown in #91430, there are cases where we don't really need to emit overflow errors — though, we need to be really careful that we don't accidently not emit them when we should. I'll look a little bit closer at this PR to think about if this really a band-aid fix we want to pursue right now. |
I think you're right that we still want to emit overflow errors when we should, perhaps it should be a delay_span_bug instead so that we still emit overflow if we get to the end of typechecking however I'm not sure if the reason we emit overflow errors unconditionally at the moment is that there are times where if we don't then the compiler hangs. Currently I know of the two paths to get to this error and it's during a Then there is the second path here which happens during typechecking trait bounds where honestly we do want to emit the overflow error because the trait is overflowing without a concrete implementation for the trait on the type you're calling the method on so it'll never compile anyway. Let me know what you think, you could well be right that we're being over eager on overflow errors but I think they are one error that perhaps we should be due to the nature of them making code hit infinite loops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great on fixing the ICE! But I have a couple of nitpicks :)
@@ -143,7 +143,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
Err(e) => e, | |||
}; | |||
|
|||
self.set_tainted_by_errors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually moved it to the top of probe_for_return
in the probe module as having it in this location meant that it was being hit when we weren't in an error context during trait bound fulfillment.
Moving it to the new location meant it only got set when we were actively looking for a method suggestion in an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does keeping this call to set_tainted_by_errors
cause any undesired effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried it but can test it out - I think you're right that it can be kept there, I'm fairly sure that both spot I've tried it in are in error reporting pathways anyway.
I think the bigger issue is that set_tainted_by_errors
is being called elsewhere before this point due to name resolution being unable to resolve Thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try getting this back in to see the effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replied in the wrong place - see my comment on the other review but I'm going to push a change tomorrow that I think works better
@@ -1469,7 +1470,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | |||
let cause = traits::ObligationCause::misc(self.span, self.body_id); | |||
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate(); | |||
let obligation = traits::Obligation::new(cause, self.param_env, predicate); | |||
traits::SelectionContext::new(self).select(&obligation) | |||
traits::SelectionContext::with_suggestion(self, self.is_suggestion.0).select(&obligation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't modifying the selection context before select
ing to be tainted_by_errors
also work instead of adding a new field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea so looking back at it I'm not sure I even need this new field I think I actually just needed to move where I set that we were tainted by errors. I'll see if I can change it this evening so we don't need the new selection context field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what's happen is I wanted a way to distinguish inside the selection context itself whether we were creating a suggestion but forgetting that it derefs down into the function context that spawned it which already has the tainted_by_errors
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a look at it this evening - it starts ICEing again if I rely on is_tainted_by_errors()
check in the overflow check I expect that the function context is set as tainted_by_errors
elsewhere in the typechecking stage before reporting fulfilment errors so it reports an incorrect overflow error.
I need to confirm this first however so will do some more digging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can say for sure that without the new field in the selection context struct if Thing
is not found during resolution then it is resolved to a Res:Err
which causes set_tainted_by_errors()
to be called before we go into the fulfilment context. I'm having second thoughts about relying on is_tainted_by_errors()
anywhere because it may have even been set before I do it myself and I need to know for sure at the overflow error site whether I should be emitting an error or propagating one back up the call stack.
It may be better to add the field to the infer_ctx struct to set instead of tainting it with errors so that I can be confident that I set it and can handle the overflow errors correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a reasonable avenue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can put it back however in my other implementation of this I don't rely on it anymore instead preferring to use a flag in the inferctx, I've linked my other implementation in the PR at the bottom which I think is more robust
@@ -262,6 +262,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
"probe(self_ty={:?}, return_type={}, scope_expr_id={})", | |||
self_ty, return_type, scope_expr_id | |||
); | |||
self.set_tainted_by_errors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank I moved it here because we only hit it when we're in an error reporting context here as probe_for_return_type
is only used to generate suggestions whereas in the old location we could hit the set_tainted_by_errors
call when we weren't doing error reporting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the code in demand_coerce_diag
once we move after the try_coerce
we are always in an error reporting pathway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are correct - I think either location is fine but if you prefer it to be here then I can move it. I think however that we probably need a new flag to suppress errors that happen in the same pass, as is_tainted_by_errors
can be set before here between name resolution and type checking which is what is causing the ICE currently as the check before the overflow error is for is_tainted_by_errors()
Is there a good way to push a commit as a second option for a change? I did some work on this tonight as I don't really like having to rely on |
You can push to another branch and I think there's a way to see a diff between two branches on GH's ui. |
Okay I've created a new branch with the changes I'd prefer to make - I think the changes to the InferCtx are better because Let me know what you think, I personally believe this is more robust & can be easily lifted out if we decide to change how we handle overflow errors in type checking. Here is the diff: |
☔ The latest upstream changes (presumably #91549) made this pull request unmergeable. Please resolve the merge conflicts. |
Going to go ahead and r? @estebank, since they reviewed the previous PR and have done a partial review here. I do think changing how we propagate overflow errors is something work experimenting with, but that's probably a bigger task and not worth blocking this. |
closing this based on comment by author #94391 (comment) |
This fixes #90319 to correctly report overflow errors instead of an ICE while also keeping the functionality of not reporting excess overflow errors during error reporting and method suggestions.
cc: @Mark-Simulacrum @estebank @dtolnay