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

Update to fix regression 90319 and correctly emit overflow errors when not inside an error reporting context #91238

Closed
wants to merge 1 commit into from

Conversation

tom7980
Copy link
Contributor

@tom7980 tom7980 commented Nov 25, 2021

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

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 25, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 1, 2021
@bors
Copy link
Contributor

bors commented Dec 2, 2021

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

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 3, 2021

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

@tom7980 tom7980 force-pushed the issue-90319-fix branch 2 times, most recently from 75387e7 to 6322948 Compare December 3, 2021 20:38
@tom7980
Copy link
Contributor Author

tom7980 commented Dec 3, 2021

r? @Mark-Simulacrum

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

@rust-log-analyzer

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
@Mark-Simulacrum
Copy link
Member

r? @jackh726 perhaps? I'm not familiar enough with this code I think to review this well.

@jackh726
Copy link
Member

jackh726 commented Dec 7, 2021

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.

@tom7980
Copy link
Contributor Author

tom7980 commented Dec 7, 2021

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 probe_op to suggest conversion methods where all errors are ignored because we're only interested in whether the method does the conversion for an error suggestion.

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

Copy link
Contributor

@estebank estebank left a 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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this removed?

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 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.

Copy link
Contributor

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?

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 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

Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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 selecting to be tainted_by_errors also work instead of adding a new field?

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 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.

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 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

Copy link
Contributor Author

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.

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 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

Copy link
Contributor

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.

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 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();
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

@tom7980 tom7980 Dec 9, 2021

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()

@tom7980
Copy link
Contributor Author

tom7980 commented Dec 9, 2021

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 is_tainted_by_errors() due to it being set between passes (resolution then type checking) and I would like to push the changes so people can decide which option work better.

@estebank
Copy link
Contributor

You can push to another branch and I think there's a way to see a diff between two branches on GH's ui.

@tom7980
Copy link
Contributor Author

tom7980 commented Dec 10, 2021

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 set_tainted_by_errors is likely to be set earlier between passes i.e. in this case name resolution and type checking, whereas I want to be able to set a flag when we error in the middle of a pass and need to supress new ones.

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:
tom7980/rust@issue-90319-fix...tom7980:issue-90319-fix-2

@bors
Copy link
Contributor

bors commented Dec 13, 2021

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

@jackh726
Copy link
Member

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.

@rust-highfive rust-highfive assigned estebank and unassigned jackh726 Dec 18, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 30, 2022
@estebank estebank added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 17, 2022
@Dylan-DPC
Copy link
Member

closing this based on comment by author #94391 (comment)

@Dylan-DPC Dylan-DPC closed this Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

regression: ICE ErrorReporting Overflow should not reach report_selection_err call