Skip to content

Commit b30d9be

Browse files
authored
Rollup merge of #64799 - Aaron1011:fix/double-panic, r=Mark-Simulacrum
Fix double panic when printing query stack during an ICE On the latest nightly, any call to `bug` or `span_bug` will result in two panics - the first one as a normal result of calling `bug` / `span_bug`, and the second as a result of trying to print the query stack from the panic handler. This is caused by the query-printing code attempting to acquire a lock on `HandlerInnder`, which is still being held by `bug`. This PR moves the actual panic out of `HandlerInner`, into `Handler`. This allows us to release the lock on `HandlerInner` before triggering the panic, ensuring that the panic handler will be able to acquire the lock if necessary.
2 parents a874c65 + 97906bc commit b30d9be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/librustc/ty/query/plumbing.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use errors::DiagnosticBuilder;
1515
use errors::Level;
1616
use errors::Diagnostic;
1717
use errors::FatalError;
18+
use errors::Handler;
1819
use rustc_data_structures::fx::{FxHashMap};
1920
use rustc_data_structures::sync::{Lrc, Lock};
2021
use rustc_data_structures::sharded::Sharded;
@@ -321,9 +322,12 @@ impl<'tcx> TyCtxt<'tcx> {
321322
})
322323
}
323324

324-
pub fn try_print_query_stack() {
325+
pub fn try_print_query_stack(handler: &Handler) {
325326
eprintln!("query stack during panic:");
326327

328+
// Be careful reyling on global state here: this code is called from
329+
// a panic hook, which means that the global `Handler` may be in a weird
330+
// state if it was responsible for triggering the panic.
327331
tls::with_context_opt(|icx| {
328332
if let Some(icx) = icx {
329333
let mut current_query = icx.query.clone();
@@ -336,7 +340,7 @@ impl<'tcx> TyCtxt<'tcx> {
336340
query.info.query.name(),
337341
query.info.query.describe(icx.tcx)));
338342
diag.span = icx.tcx.sess.source_map().def_span(query.info.span).into();
339-
icx.tcx.sess.diagnostic().force_print_diagnostic(diag);
343+
handler.force_print_diagnostic(diag);
340344

341345
current_query = query.parent.clone();
342346
i += 1;

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12311231
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
12321232

12331233
if backtrace {
1234-
TyCtxt::try_print_query_stack();
1234+
TyCtxt::try_print_query_stack(&handler);
12351235
}
12361236

12371237
#[cfg(windows)]

0 commit comments

Comments
 (0)