Skip to content

Commit 4968a8b

Browse files
committed
Auto merge of #87986 - Aaron1011:incr-double-panic, r=estebank
Prevent double panic when handling incremental fingerprint mismatch When an incremental fingerprint mismatch occurs, we debug-print our `DepNode` and query result. Unfortunately, the debug printing process may cause us to run additional queries, which can result in a re-entrant fingerprint mismatch error. To avoid a double panic, this commit adds a thread-local variable to detect re-entrant calls.
2 parents ad1eaff + 77b02ee commit 4968a8b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

compiler/rustc_query_system/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(hash_raw_entry)]
44
#![feature(iter_zip)]
55
#![feature(min_specialization)]
6+
#![feature(thread_local_const_init)]
67

78
#[macro_use]
89
extern crate tracing;

compiler/rustc_query_system/src/query/plumbing.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_data_structures::thin_vec::ThinVec;
2020
use rustc_errors::DiagnosticBuilder;
2121
use rustc_errors::{Diagnostic, FatalError};
2222
use rustc_span::{Span, DUMMY_SP};
23+
use std::cell::Cell;
2324
use std::collections::hash_map::Entry;
2425
use std::fmt::Debug;
2526
use std::hash::{Hash, Hasher};
@@ -618,12 +619,32 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
618619
} else {
619620
"`cargo clean`".to_string()
620621
};
621-
tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
622-
.help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
623-
.note(&"Please follow the instructions below to create a bug report with the provided information")
624-
.note(&"See <https://github.com/rust-lang/rust/issues/84970> for more information")
625-
.emit();
626-
panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
622+
623+
// When we emit an error message and panic, we try to debug-print the `DepNode`
624+
// and query result. Unforunately, this can cause us to run additional queries,
625+
// which may result in another fingerprint mismatch while we're in the middle
626+
// of processing this one. To avoid a double-panic (which kills the process
627+
// before we can print out the query static), we print out a terse
628+
// but 'safe' message if we detect a re-entrant call to this method.
629+
thread_local! {
630+
static INSIDE_VERIFY_PANIC: Cell<bool> = const { Cell::new(false) };
631+
};
632+
633+
let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
634+
635+
if old_in_panic {
636+
tcx.sess().struct_err("internal compiler error: re-entrant incremental verify failure, suppressing message")
637+
.emit();
638+
} else {
639+
tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
640+
.help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
641+
.note(&"Please follow the instructions below to create a bug report with the provided information")
642+
.note(&"See <https://github.com/rust-lang/rust/issues/84970> for more information")
643+
.emit();
644+
panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
645+
}
646+
647+
INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));
627648
}
628649
}
629650

0 commit comments

Comments
 (0)