Overhaul rustc_codegen_ssa:🔙:write::Diagnostic
.
- Make it more closely match `rustc_errors::Diagnostic`, by making the
field names match, and adding `children`, which requires adding
`rustc_codegen_ssa:🔙:write::Subdiagnostic`.
- Check that we aren't missing important info when converting
diagnostics.
- Add better comments.
- Tweak `rustc_errors::Diagnostic::replace_args` so that we don't need
to do any cloning when converting diagnostics.
This commit is contained in:
parent
b38ed1afa6
commit
ad5d7f43c9
@ -17,7 +17,7 @@ use rustc_errors::emitter::Emitter;
|
|||||||
use rustc_errors::translation::Translate;
|
use rustc_errors::translation::Translate;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
DiagCtxt, DiagnosticArgMap, DiagnosticBuilder, DiagnosticMessage, ErrCode, FatalError,
|
DiagCtxt, DiagnosticArgMap, DiagnosticBuilder, DiagnosticMessage, ErrCode, FatalError,
|
||||||
FluentBundle, Level, Style,
|
FluentBundle, Level, MultiSpan, Style,
|
||||||
};
|
};
|
||||||
use rustc_fs_util::link_or_copy;
|
use rustc_fs_util::link_or_copy;
|
||||||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||||
@ -999,11 +999,29 @@ pub(crate) enum Message<B: WriteBackendMethods> {
|
|||||||
/// process another codegen unit.
|
/// process another codegen unit.
|
||||||
pub struct CguMessage;
|
pub struct CguMessage;
|
||||||
|
|
||||||
|
// A cut-down version of `rustc_errors::Diagnostic` that impls `Send`, which
|
||||||
|
// can be used to send diagnostics from codegen threads to the main thread.
|
||||||
|
// It's missing the following fields from `rustc_errors::Diagnostic`.
|
||||||
|
// - `span`: it doesn't impl `Send`.
|
||||||
|
// - `suggestions`: it doesn't impl `Send`, and isn't used for codegen
|
||||||
|
// diagnostics.
|
||||||
|
// - `sort_span`: it doesn't impl `Send`.
|
||||||
|
// - `is_lint`: lints aren't relevant during codegen.
|
||||||
|
// - `emitted_at`: not used for codegen diagnostics.
|
||||||
struct Diagnostic {
|
struct Diagnostic {
|
||||||
msgs: Vec<(DiagnosticMessage, Style)>,
|
level: Level,
|
||||||
args: DiagnosticArgMap,
|
messages: Vec<(DiagnosticMessage, Style)>,
|
||||||
code: Option<ErrCode>,
|
code: Option<ErrCode>,
|
||||||
lvl: Level,
|
children: Vec<Subdiagnostic>,
|
||||||
|
args: DiagnosticArgMap,
|
||||||
|
}
|
||||||
|
|
||||||
|
// A cut-down version of `rustc_errors::SubDiagnostic` that impls `Send`. It's
|
||||||
|
// missing the following fields from `rustc_errors::SubDiagnostic`.
|
||||||
|
// - `span`: it doesn't impl `Send`.
|
||||||
|
pub struct Subdiagnostic {
|
||||||
|
level: Level,
|
||||||
|
messages: Vec<(DiagnosticMessage, Style)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||||
@ -1812,23 +1830,29 @@ impl Translate for SharedEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SharedEmitter {
|
impl Emitter for SharedEmitter {
|
||||||
fn emit_diagnostic(&mut self, diag: rustc_errors::Diagnostic) {
|
fn emit_diagnostic(&mut self, mut diag: rustc_errors::Diagnostic) {
|
||||||
let args: DiagnosticArgMap =
|
// Check that we aren't missing anything interesting when converting to
|
||||||
diag.args.iter().map(|(name, arg)| (name.clone(), arg.clone())).collect();
|
// the cut-down local `Diagnostic`.
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
assert_eq!(diag.span, MultiSpan::new());
|
||||||
msgs: diag.messages.clone(),
|
assert_eq!(diag.suggestions, Ok(vec![]));
|
||||||
args: args.clone(),
|
assert_eq!(diag.sort_span, rustc_span::DUMMY_SP);
|
||||||
code: diag.code,
|
assert_eq!(diag.is_lint, None);
|
||||||
lvl: diag.level(),
|
// No sensible check for `diag.emitted_at`.
|
||||||
})));
|
|
||||||
for child in &diag.children {
|
let args = mem::replace(&mut diag.args, DiagnosticArgMap::default());
|
||||||
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
drop(
|
||||||
msgs: child.messages.clone(),
|
self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||||
args: args.clone(),
|
level: diag.level(),
|
||||||
code: None,
|
messages: diag.messages,
|
||||||
lvl: child.level,
|
code: diag.code,
|
||||||
})));
|
children: diag
|
||||||
}
|
.children
|
||||||
|
.into_iter()
|
||||||
|
.map(|child| Subdiagnostic { level: child.level, messages: child.messages })
|
||||||
|
.collect(),
|
||||||
|
args,
|
||||||
|
})),
|
||||||
|
);
|
||||||
drop(self.sender.send(SharedEmitterMessage::AbortIfErrors));
|
drop(self.sender.send(SharedEmitterMessage::AbortIfErrors));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1854,9 +1878,21 @@ impl SharedEmitterMain {
|
|||||||
|
|
||||||
match message {
|
match message {
|
||||||
Ok(SharedEmitterMessage::Diagnostic(diag)) => {
|
Ok(SharedEmitterMessage::Diagnostic(diag)) => {
|
||||||
|
// The diagnostic has been received on the main thread.
|
||||||
|
// Convert it back to a full `Diagnostic` and emit.
|
||||||
let dcx = sess.dcx();
|
let dcx = sess.dcx();
|
||||||
let mut d = rustc_errors::Diagnostic::new_with_messages(diag.lvl, diag.msgs);
|
let mut d =
|
||||||
|
rustc_errors::Diagnostic::new_with_messages(diag.level, diag.messages);
|
||||||
d.code = diag.code; // may be `None`, that's ok
|
d.code = diag.code; // may be `None`, that's ok
|
||||||
|
d.children = diag
|
||||||
|
.children
|
||||||
|
.into_iter()
|
||||||
|
.map(|sub| rustc_errors::SubDiagnostic {
|
||||||
|
level: sub.level,
|
||||||
|
messages: sub.messages,
|
||||||
|
span: MultiSpan::new(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
d.args = diag.args;
|
d.args = diag.args;
|
||||||
dcx.emit_diagnostic(d);
|
dcx.emit_diagnostic(d);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
error: cannot prefer dynamic linking when performing LTO
|
error: cannot prefer dynamic linking when performing LTO
|
||||||
|
|
|
||||||
note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
|
= note: only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user