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

Fix double panic when printing query stack during an ICE #64799

Merged
merged 2 commits into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use errors::DiagnosticBuilder;
use errors::Level;
use errors::Diagnostic;
use errors::FatalError;
use errors::Handler;
use rustc_data_structures::fx::{FxHashMap};
use rustc_data_structures::sync::{Lrc, Lock};
use rustc_data_structures::sharded::Sharded;
Expand Down Expand Up @@ -321,9 +322,12 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

pub fn try_print_query_stack() {
pub fn try_print_query_stack(handler: &Handler) {
eprintln!("query stack during panic:");

// Be careful reyling on global state here: this code is called from
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Be careful reyling on global state here: this code is called from
// Be careful relying on global state here: this code is called from

// a panic hook, which means that the global `Handler` may be in a weird
// state if it was responsible for triggering the panic.
tls::with_context_opt(|icx| {
if let Some(icx) = icx {
let mut current_query = icx.query.clone();
Expand All @@ -336,7 +340,7 @@ impl<'tcx> TyCtxt<'tcx> {
query.info.query.name(),
query.info.query.describe(icx.tcx)));
diag.span = icx.tcx.sess.source_map().def_span(query.info.span).into();
icx.tcx.sess.diagnostic().force_print_diagnostic(diag);
handler.force_print_diagnostic(diag);

current_query = query.parent.clone();
i += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);

if backtrace {
TyCtxt::try_print_query_stack();
TyCtxt::try_print_query_stack(&handler);
}

#[cfg(windows)]
Expand Down