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

ICEs should always print the top of the query stack. #70953

Closed
eddyb opened this issue Apr 9, 2020 · 16 comments
Closed

ICEs should always print the top of the query stack. #70953

eddyb opened this issue Apr 9, 2020 · 16 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@eddyb
Copy link
Member

eddyb commented Apr 9, 2020

E.g. for #70942, instead of:

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

We could print something more like

error: internal compiler error: unexpected panic
    while const-evaluating `main::{{constant}}#0`
    ... (full query stack hidden, use `RUST_BACKTRACE=1` to enable)

note: the compiler unexpectedly panicked. this is a bug.

(not super sure about the RUST_BACKTRACE=1 suggestion message)

This (and the query stack more generally) should allow quicker diagnosis, and there should be no cost to just having this on by default for ICEs.

It could also be useful to users, as they could use it to figure out roughly where in their code they're triggering the ICE (similar to the Span from a span_bug!), to work around the ICE in the meanwhile or know which error to fix (in case it's a side-effect of an error) to get rid of the ICE.

cc @rust-lang/compiler @rust-lang/wg-diagnostics

@eddyb eddyb added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics labels Apr 9, 2020
@eddyb
Copy link
Member Author

eddyb commented Apr 9, 2020

Nominating for a vibe check (this should be easy to implement if we agree we want it).

@Zoxc
Copy link
Contributor

Zoxc commented Apr 9, 2020

Getting / printing the query stack may panic, so I'd prefer it to be done after printing the backtrace, but I guess that would be hidden by default anyway.

@bjorn3
Copy link
Member

bjorn3 commented Apr 9, 2020

I think always enabling backtraces for rustc would be useful, as it ensures that all bug reports contain a backtrace. Even when the issue is not reproducable.

@pnkfelix
Copy link
Member

discussed in yesterday's T-compiler meeting. There was general support for adding information about the query context to the ICE output.

when we had a second ad hoc triage meeting today, @eddyb added that we had issues in the past with trying to always emit backtraces (but it is possible that they have been fixed).

  • To be honest, I wasn't clear on whether @bjorn3 's suggest was to print out (unconditionally) the call stack backtrace, or the query stack.

In any case, it seems like we can immediately work on adding a printout for the top of the query stack, and leave the question of whether to add more info beyond that to a later discussion.

@eddyb
Copy link
Member Author

eddyb commented Apr 10, 2020

we had issues in the past with trying to always emit backtrace

Not "always emit", but rather issues when enabling it via RUST_BACKTRACE=1, e.g. taking minute to compute the backtrace, or strange crashes. We may have updated/fixed libbacktrace since, though.

If we ever made the default to emit the backtrace, RUST_BACKTRACE=0 could be used as an opt-out.

@bjorn3
Copy link
Member

bjorn3 commented Apr 10, 2020

To be honest, I wasn't clear on whether @bjorn3 's suggest was to print out (unconditionally) the call stack backtrace, or the query stack.

Both

@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 12, 2020
@eddyb
Copy link
Member Author

eddyb commented May 31, 2020

Something I completely forgot is that the query stack sometimes even has Spans (originally added for query cycle errors), so we could also try to show those, which could give even more precision to what part of the user code triggered the query that ICE'd.

@oli-obk oli-obk added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Jul 30, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Jul 30, 2020

For anyone looking to implement this. The relevant work needs to be done in

pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
. The query stack is reported in
TyCtxt::try_print_query_stack(&handler);
, so I think we need another function for printing just the top of the query stack.

@oli-obk oli-obk added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jul 30, 2020
@georgio
Copy link
Contributor

georgio commented Jul 31, 2020

I'm trying to work on this. Is there some sort of template we are targeting?

My proposed solution is adding something like
pub fn try_print_query_stack_head(handler: &Handler) {...}
somewhere around here

pub fn try_print_query_stack(handler: &Handler) {

@oli-obk
Copy link
Contributor

oli-obk commented Aug 1, 2020

You could also add a num_frames: Option<usize> argument to try_print_query_stack that makes it stop after that number of elements (if any). This way you can just adjust a few invocation sites instead of having to build a new function that does almost the same.

@georgio
Copy link
Contributor

georgio commented Aug 1, 2020

Great idea, thanks. I assumed that we might break a lot of other functions by changing the signature of try_print_query_stack, turns out it's only being called twice. Will confirm after running tests.

@Dylan-DPC-zz
Copy link

@georgio any updates on this?

@hosseind75
Copy link
Contributor

guys I am working on it and as @oli-obk recommendation, I want to add num_frames argument to try_print_query_stack function to break while loop when loop counter is equal to num_frames, but I am not sure that is it correct or not?
and also I am not sure that we should ask the user to set an environment variable that determines how much of the query stack should we print or just pass a strict value to this function?

@oli-obk
Copy link
Contributor

oli-obk commented Sep 19, 2020

We can just pass a strict value. This only happens when the compiler panics and is just a single line of information. I don't think this is something we really need to make configurable.

@hosseind75
Copy link
Contributor

ok thanks, I will pass f.e 2 to just show two first queries

@GroteGnoom
Copy link

This should be closed because of
#77493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests