Skip to content

Commit 6fb1566

Browse files
committed
Simplify codegen diagnostic handling.
To send a diagnostic from a codegen thread to the main thread, `SharedEmitter` currently converts the `rustc_errors::Diagnostic` into a one or more `rustc_codegen_ssa::Diagnostic`s, sends them, and then `SharedEmitterMain` reconstructs them at the other end into a `rustc_errors::Diagnostic`. This is a lossy operation, because of differences between the two `Diagnostic` types. Instead we can just clone the `rustc_errors::Diagnostic` and send it directly. Maybe in the past `rustc_errors::Diagnostic` wasn't `Send`? But it works now. Much simpler and nicer.
1 parent 4e3eed4 commit 6fb1566

File tree

2 files changed

+5
-36
lines changed

2 files changed

+5
-36
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+3-34
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1515
use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::emitter::Emitter;
1717
use rustc_errors::translation::Translate;
18-
use rustc_errors::{
19-
DiagCtxt, DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, ErrCode,
20-
FatalError, FluentBundle, Level, Style,
21-
};
18+
use rustc_errors::{DiagCtxt, Diagnostic, DiagnosticBuilder, FatalError, FluentBundle, Level};
2219
use rustc_fs_util::link_or_copy;
2320
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2421
use rustc_incremental::{
@@ -997,13 +994,6 @@ pub(crate) enum Message<B: WriteBackendMethods> {
997994
/// process another codegen unit.
998995
pub struct CguMessage;
999996

1000-
struct Diagnostic {
1001-
msgs: Vec<(DiagnosticMessage, Style)>,
1002-
args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>,
1003-
code: Option<ErrCode>,
1004-
lvl: Level,
1005-
}
1006-
1007997
#[derive(PartialEq, Clone, Copy, Debug)]
1008998
enum MainThreadState {
1009999
/// Doing nothing.
@@ -1811,22 +1801,7 @@ impl Translate for SharedEmitter {
18111801

18121802
impl Emitter for SharedEmitter {
18131803
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
1814-
let args: FxHashMap<DiagnosticArgName, DiagnosticArgValue> =
1815-
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
1816-
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
1817-
msgs: diag.messages.clone(),
1818-
args: args.clone(),
1819-
code: diag.code,
1820-
lvl: diag.level(),
1821-
})));
1822-
for child in &diag.children {
1823-
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
1824-
msgs: child.messages.clone(),
1825-
args: args.clone(),
1826-
code: None,
1827-
lvl: child.level,
1828-
})));
1829-
}
1804+
drop(self.sender.send(SharedEmitterMessage::Diagnostic(diag.clone())));
18301805
drop(self.sender.send(SharedEmitterMessage::AbortIfErrors));
18311806
}
18321807

@@ -1852,13 +1827,7 @@ impl SharedEmitterMain {
18521827

18531828
match message {
18541829
Ok(SharedEmitterMessage::Diagnostic(diag)) => {
1855-
let dcx = sess.dcx();
1856-
let mut d = rustc_errors::Diagnostic::new_with_messages(diag.lvl, diag.msgs);
1857-
if let Some(code) = diag.code {
1858-
d.code(code);
1859-
}
1860-
d.replace_args(diag.args);
1861-
dcx.emit_diagnostic(d);
1830+
sess.dcx().emit_diagnostic(diag);
18621831
}
18631832
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
18641833
assert!(matches!(level, Level::Error | Level::Warning | Level::Note));

tests/ui/lto/issue-11154.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
error: cannot prefer dynamic linking when performing LTO
2-
3-
note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
2+
|
3+
= note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
44

55
error: aborting due to 1 previous error
66

0 commit comments

Comments
 (0)