Skip to content

Commit 109248a

Browse files
committed
Auto merge of #84965 - the8472:lazy-delayed-diagnostics, r=Mark-Simulacrum
lazify backtrace formatting for delayed diagnostics Formatting backtraces causes debug info to be parsed, which is superfluous work if the delayed bugs get cleared later. Lazifying them results in these speedups for the UI testsuite: | | debuginfo = 0 | debuginfo = 1 | debuginfo = 2 | |-------|---------------|---------------|---------------| | eager | 31.59s | 37.55s | 42.64s | | lazy | 30.44s | 30.86s | 34.07s |
2 parents 1d99508 + b98629b commit 109248a

File tree

1 file changed

+22
-5
lines changed
  • compiler/rustc_errors/src

1 file changed

+22
-5
lines changed

Diff for: compiler/rustc_errors/src/lib.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl error::Error for ExplicitBug {}
294294

295295
pub use diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic};
296296
pub use diagnostic_builder::DiagnosticBuilder;
297+
use std::backtrace::Backtrace;
297298

298299
/// A handler deals with errors and other compiler output.
299300
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
@@ -317,7 +318,7 @@ struct HandlerInner {
317318
deduplicated_err_count: usize,
318319
emitter: Box<dyn Emitter + sync::Send>,
319320
delayed_span_bugs: Vec<Diagnostic>,
320-
delayed_good_path_bugs: Vec<Diagnostic>,
321+
delayed_good_path_bugs: Vec<DelayedDiagnostic>,
321322

322323
/// This set contains the `DiagnosticId` of all emitted diagnostics to avoid
323324
/// emitting the same diagnostic with extended help (`--teach`) twice, which
@@ -388,7 +389,7 @@ impl Drop for HandlerInner {
388389
if !self.has_any_message() {
389390
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
390391
self.flush_delayed(
391-
bugs,
392+
bugs.into_iter().map(DelayedDiagnostic::decorate).collect(),
392393
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
393394
);
394395
}
@@ -968,12 +969,12 @@ impl HandlerInner {
968969
}
969970

970971
fn delay_good_path_bug(&mut self, msg: &str) {
971-
let mut diagnostic = Diagnostic::new(Level::Bug, msg);
972+
let diagnostic = Diagnostic::new(Level::Bug, msg);
972973
if self.flags.report_delayed_bugs {
973974
self.emit_diagnostic(&diagnostic);
974975
}
975-
diagnostic.note(&format!("delayed at {}", std::backtrace::Backtrace::force_capture()));
976-
self.delayed_good_path_bugs.push(diagnostic);
976+
let backtrace = std::backtrace::Backtrace::force_capture();
977+
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
977978
}
978979

979980
fn failure(&mut self, msg: &str) {
@@ -1042,6 +1043,22 @@ impl HandlerInner {
10421043
}
10431044
}
10441045

1046+
struct DelayedDiagnostic {
1047+
inner: Diagnostic,
1048+
note: Backtrace,
1049+
}
1050+
1051+
impl DelayedDiagnostic {
1052+
fn with_backtrace(diagnostic: Diagnostic, backtrace: Backtrace) -> Self {
1053+
DelayedDiagnostic { inner: diagnostic, note: backtrace }
1054+
}
1055+
1056+
fn decorate(mut self) -> Diagnostic {
1057+
self.inner.note(&format!("delayed at {}", self.note));
1058+
self.inner
1059+
}
1060+
}
1061+
10451062
#[derive(Copy, PartialEq, Clone, Hash, Debug, Encodable, Decodable)]
10461063
pub enum Level {
10471064
Bug,

0 commit comments

Comments
 (0)