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.
This commit is contained in:
commit
b30d9beafb
@ -15,6 +15,7 @@
|
||||
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;
|
||||
@ -321,9 +322,12 @@ pub(super) fn report_cycle(
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
// 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();
|
||||
@ -336,7 +340,7 @@ pub fn try_print_query_stack() {
|
||||
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;
|
||||
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user