diff options
| author | bors <bors@rust-lang.org> | 2021-05-06 11:29:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-06 11:29:29 +0000 |
| commit | 109248a4eb99bc83684c94ca4ef36f2fadc17e2a (patch) | |
| tree | f4f0300e6922d1cc9b449185fd3911c3cd80859b /compiler/rustc_errors/src | |
| parent | 1d99508b52499c9efd213738e71927458c1d394e (diff) | |
| parent | b98629bfbc66f2011d989138b0d82d7598471445 (diff) | |
| download | rust-109248a4eb99bc83684c94ca4ef36f2fadc17e2a.tar.gz rust-109248a4eb99bc83684c94ca4ef36f2fadc17e2a.zip | |
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 |
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index f1a31f0d4f5..6aee769298b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -294,6 +294,7 @@ impl error::Error for ExplicitBug {} pub use diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic}; pub use diagnostic_builder::DiagnosticBuilder; +use std::backtrace::Backtrace; /// A handler deals with errors and other compiler output. /// Certain errors (fatal, bug, unimpl) may cause immediate exit, @@ -317,7 +318,7 @@ struct HandlerInner { deduplicated_err_count: usize, emitter: Box<dyn Emitter + sync::Send>, delayed_span_bugs: Vec<Diagnostic>, - delayed_good_path_bugs: Vec<Diagnostic>, + delayed_good_path_bugs: Vec<DelayedDiagnostic>, /// This set contains the `DiagnosticId` of all emitted diagnostics to avoid /// emitting the same diagnostic with extended help (`--teach`) twice, which @@ -388,7 +389,7 @@ impl Drop for HandlerInner { if !self.has_any_message() { let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new()); self.flush_delayed( - bugs, + bugs.into_iter().map(DelayedDiagnostic::decorate).collect(), "no warnings or errors encountered even though `delayed_good_path_bugs` issued", ); } @@ -968,12 +969,12 @@ impl HandlerInner { } fn delay_good_path_bug(&mut self, msg: &str) { - let mut diagnostic = Diagnostic::new(Level::Bug, msg); + let diagnostic = Diagnostic::new(Level::Bug, msg); if self.flags.report_delayed_bugs { self.emit_diagnostic(&diagnostic); } - diagnostic.note(&format!("delayed at {}", std::backtrace::Backtrace::force_capture())); - self.delayed_good_path_bugs.push(diagnostic); + let backtrace = std::backtrace::Backtrace::force_capture(); + self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace)); } fn failure(&mut self, msg: &str) { @@ -1042,6 +1043,22 @@ impl HandlerInner { } } +struct DelayedDiagnostic { + inner: Diagnostic, + note: Backtrace, +} + +impl DelayedDiagnostic { + fn with_backtrace(diagnostic: Diagnostic, backtrace: Backtrace) -> Self { + DelayedDiagnostic { inner: diagnostic, note: backtrace } + } + + fn decorate(mut self) -> Diagnostic { + self.inner.note(&format!("delayed at {}", self.note)); + self.inner + } +} + #[derive(Copy, PartialEq, Clone, Hash, Debug, Encodable, Decodable)] pub enum Level { Bug, |
