Skip to content

Commit 13d4f27

Browse files
committed
ADD - implement IntoDiagnostic for thorin::Error wrapper
1 parent a25f939 commit 13d4f27

File tree

3 files changed

+269
-15
lines changed

3 files changed

+269
-15
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,7 @@ fn link_dwarf_object<'a>(
662662
}) {
663663
Ok(()) => {}
664664
Err(e) => {
665-
let thorin_error = errors::ThorinErrorWrapper(e);
666-
sess.emit_err(errors::ThorinDwarfLinking { thorin_error });
665+
sess.emit_err(errors::ThorinErrorWrapper(e));
667666
sess.abort_if_errors();
668667
}
669668
}

compiler/rustc_codegen_ssa/src/errors.rs

+192-10
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,200 @@ pub enum LinkRlibError {
129129
NotFound { crate_name: Symbol },
130130
}
131131

132-
#[derive(Diagnostic)]
133-
#[diag(codegen_ssa::thorin_dwarf_linking)]
134-
#[note]
135-
pub struct ThorinDwarfLinking {
136-
pub thorin_error: ThorinErrorWrapper,
137-
}
138132
pub struct ThorinErrorWrapper(pub thorin::Error);
139133

140-
// FIXME: How should we support translations for external crate errors?
141-
impl IntoDiagnosticArg for ThorinErrorWrapper {
142-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
143-
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
134+
impl IntoDiagnostic<'_> for ThorinErrorWrapper {
135+
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
136+
let mut diag;
137+
match self.0 {
138+
thorin::Error::ReadInput(_) => {
139+
diag = handler.struct_err(fluent::codegen_ssa::thorin_read_input_failure);
140+
diag
141+
}
142+
thorin::Error::ParseFileKind(_) => {
143+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_input_file_kind);
144+
diag
145+
}
146+
thorin::Error::ParseObjectFile(_) => {
147+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_input_object_file);
148+
diag
149+
}
150+
thorin::Error::ParseArchiveFile(_) => {
151+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_input_archive_file);
152+
diag
153+
}
154+
thorin::Error::ParseArchiveMember(_) => {
155+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_archive_member);
156+
diag
157+
}
158+
thorin::Error::InvalidInputKind => {
159+
diag = handler.struct_err(fluent::codegen_ssa::thorin_invalid_input_kind);
160+
diag
161+
}
162+
thorin::Error::DecompressData(_) => {
163+
diag = handler.struct_err(fluent::codegen_ssa::thorin_decompress_data);
164+
diag
165+
}
166+
thorin::Error::NamelessSection(_, offset) => {
167+
diag = handler.struct_err(fluent::codegen_ssa::thorin_section_without_name);
168+
diag.set_arg("offset", format!("0x{:08x}", offset));
169+
diag
170+
}
171+
thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
172+
diag =
173+
handler.struct_err(fluent::codegen_ssa::thorin_relocation_with_invalid_symbol);
174+
diag.set_arg("section", section);
175+
diag.set_arg("offset", format!("0x{:08x}", offset));
176+
diag
177+
}
178+
thorin::Error::MultipleRelocations(section, offset) => {
179+
diag = handler.struct_err(fluent::codegen_ssa::thorin_multiple_relocations);
180+
diag.set_arg("section", section);
181+
diag.set_arg("offset", format!("0x{:08x}", offset));
182+
diag
183+
}
184+
thorin::Error::UnsupportedRelocation(section, offset) => {
185+
diag = handler.struct_err(fluent::codegen_ssa::thorin_unsupported_relocation);
186+
diag.set_arg("section", section);
187+
diag.set_arg("offset", format!("0x{:08x}", offset));
188+
diag
189+
}
190+
thorin::Error::MissingDwoName(id) => {
191+
diag = handler.struct_err(fluent::codegen_ssa::thorin_missing_dwo_name);
192+
diag.set_arg("id", format!("0x{:08x}", id));
193+
diag
194+
}
195+
thorin::Error::NoCompilationUnits => {
196+
diag = handler.struct_err(fluent::codegen_ssa::thorin_no_compilation_units);
197+
diag
198+
}
199+
thorin::Error::NoDie => {
200+
diag = handler.struct_err(fluent::codegen_ssa::thorin_no_die);
201+
diag
202+
}
203+
thorin::Error::TopLevelDieNotUnit => {
204+
diag = handler.struct_err(fluent::codegen_ssa::thorin_top_level_die_not_unit);
205+
diag
206+
}
207+
thorin::Error::MissingRequiredSection(section) => {
208+
diag = handler.struct_err(fluent::codegen_ssa::thorin_missing_required_section);
209+
diag.set_arg("section", section);
210+
diag
211+
}
212+
thorin::Error::ParseUnitAbbreviations(_) => {
213+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit_abbreviations);
214+
diag
215+
}
216+
thorin::Error::ParseUnitAttribute(_) => {
217+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit_attribute);
218+
diag
219+
}
220+
thorin::Error::ParseUnitHeader(_) => {
221+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit_header);
222+
diag
223+
}
224+
thorin::Error::ParseUnit(_) => {
225+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_unit);
226+
diag
227+
}
228+
thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
229+
diag = handler.struct_err(fluent::codegen_ssa::thorin_incompatible_index_version);
230+
diag.set_arg("section", section);
231+
diag.set_arg("actual", actual);
232+
diag.set_arg("format", format);
233+
diag
234+
}
235+
thorin::Error::OffsetAtIndex(_, index) => {
236+
diag = handler.struct_err(fluent::codegen_ssa::thorin_offset_at_index);
237+
diag.set_arg("index", index);
238+
diag
239+
}
240+
thorin::Error::StrAtOffset(_, offset) => {
241+
diag = handler.struct_err(fluent::codegen_ssa::thorin_str_at_offset);
242+
diag.set_arg("offset", format!("0x{:08x}", offset));
243+
diag
244+
}
245+
thorin::Error::ParseIndex(_, section) => {
246+
diag = handler.struct_err(fluent::codegen_ssa::thorin_parse_index);
247+
diag.set_arg("section", section);
248+
diag
249+
}
250+
thorin::Error::UnitNotInIndex(unit) => {
251+
diag = handler.struct_err(fluent::codegen_ssa::thorin_unit_not_in_index);
252+
diag.set_arg("unit", format!("0x{:08x}", unit));
253+
diag
254+
}
255+
thorin::Error::RowNotInIndex(_, row) => {
256+
diag = handler.struct_err(fluent::codegen_ssa::thorin_row_not_in_index);
257+
diag.set_arg("row", row);
258+
diag
259+
}
260+
thorin::Error::SectionNotInRow => {
261+
diag = handler.struct_err(fluent::codegen_ssa::thorin_section_not_in_row);
262+
diag
263+
}
264+
thorin::Error::EmptyUnit(unit) => {
265+
diag = handler.struct_err(fluent::codegen_ssa::thorin_empty_unit);
266+
diag.set_arg("unit", format!("0x{:08x}", unit));
267+
diag
268+
}
269+
thorin::Error::MultipleDebugInfoSection => {
270+
diag = handler.struct_err(fluent::codegen_ssa::thorin_multiple_debug_info_section);
271+
diag
272+
}
273+
thorin::Error::MultipleDebugTypesSection => {
274+
diag = handler.struct_err(fluent::codegen_ssa::thorin_multiple_debug_types_section);
275+
diag
276+
}
277+
thorin::Error::NotSplitUnit => {
278+
diag = handler.struct_err(fluent::codegen_ssa::thorin_not_split_unit);
279+
diag
280+
}
281+
thorin::Error::DuplicateUnit(unit) => {
282+
diag = handler.struct_err(fluent::codegen_ssa::thorin_duplicate_unit);
283+
diag.set_arg("unit", format!("0x{:08x}", unit));
284+
diag
285+
}
286+
thorin::Error::MissingReferencedUnit(unit) => {
287+
diag = handler.struct_err(fluent::codegen_ssa::thorin_missing_referenced_unit);
288+
diag.set_arg("unit", format!("0x{:08x}", unit));
289+
diag
290+
}
291+
thorin::Error::NoOutputObjectCreated => {
292+
diag = handler.struct_err(fluent::codegen_ssa::thorin_not_output_object_created);
293+
diag
294+
}
295+
thorin::Error::MixedInputEncodings => {
296+
diag = handler.struct_err(fluent::codegen_ssa::thorin_mixed_input_encodings);
297+
diag
298+
}
299+
thorin::Error::Io(e) => {
300+
diag = handler.struct_err(fluent::codegen_ssa::thorin_io);
301+
diag.set_arg("error", format!("{e}"));
302+
diag
303+
}
304+
thorin::Error::ObjectRead(e) => {
305+
diag = handler.struct_err(fluent::codegen_ssa::thorin_object_read);
306+
diag.set_arg("error", format!("{e}"));
307+
diag
308+
}
309+
thorin::Error::ObjectWrite(e) => {
310+
diag = handler.struct_err(fluent::codegen_ssa::thorin_object_write);
311+
diag.set_arg("error", format!("{e}"));
312+
diag
313+
}
314+
thorin::Error::GimliRead(e) => {
315+
diag = handler.struct_err(fluent::codegen_ssa::thorin_gimli_read);
316+
diag.set_arg("error", format!("{e}"));
317+
diag
318+
}
319+
thorin::Error::GimliWrite(e) => {
320+
diag = handler.struct_err(fluent::codegen_ssa::thorin_gimli_write);
321+
diag.set_arg("error", format!("{e}"));
322+
diag
323+
}
324+
_ => unimplemented!("Untranslated thorin error"),
325+
}
144326
}
145327
}
146328

compiler/rustc_error_messages/locales/en-US/codegen_ssa.ftl

+76-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,86 @@ codegen_ssa_rlib_only_rmeta_found = could not find rlib for: `{$crate_name}`, fo
3434
3535
codegen_ssa_rlib_not_found = could not find rlib for: `{$crate_name}`
3636
37-
codegen_ssa_thorin_dwarf_linking = linking dwarf objects with thorin failed
38-
.note = {$thorin_error}
39-
4037
codegen_ssa_linking_failed = linking with `{$linker_path}` failed: {$exit_status}
4138
4239
codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
4340
4441
codegen_ssa_specify_libraries_to_link = use the `-l` flag to specify native libraries to link
4542
4643
codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
44+
45+
codegen_ssa_thorin_read_input_failure = failed to read input file
46+
47+
codegen_ssa_thorin_parse_input_file_kind = failed to parse input file kind
48+
49+
codegen_ssa_thorin_parse_input_object_file = failed to parse input object file
50+
51+
codegen_ssa_thorin_parse_input_archive_file = failed to parse input archive file
52+
53+
codegen_ssa_thorin_parse_archive_member = failed to parse archive member
54+
55+
codegen_ssa_thorin_invalid_input_kind = input is not an archive or elf object
56+
57+
codegen_ssa_thorin_decompress_data = failed to decompress compressed section
58+
59+
codegen_ssa_thorin_section_without_name = section without name at offset {$offset}
60+
61+
codegen_ssa_thorin_relocation_with_invalid_symbol = relocation with invalid symbol for section `{$section}` at offset {$offset}
62+
63+
codegen_ssa_thorin_multiple_relocations = multiple relocations for section `{$section}` at offset {$offset}
64+
65+
codegen_ssa_thorin_unsupported_relocation = unsupported relocation for section {$section} at offset {$offset}
66+
67+
codegen_ssa_thorin_missing_dwo_name = missing path attribute to DWARF object ({$id})
68+
69+
codegen_ssa_thorin_no_compilation_units = input object has no compilation units
70+
71+
codegen_ssa_thorin_no_die = no top-level debugging information entry in compilation/type unit
72+
73+
codegen_ssa_thorin_top_level_die_not_unit = top-level debugging information entry is not a compilation/type unit
74+
75+
codegen_ssa_thorin_missing_required_section = input object missing required section `{$section}`
76+
77+
codegen_ssa_thorin_parse_unit_abbreviations = failed to parse unit abbreviations
78+
79+
codegen_ssa_thorin_parse_unit_attribute = failed to parse unit attribute
80+
81+
codegen_ssa_thorin_parse_unit_header = failed to parse unit header
82+
83+
codegen_ssa_thorin_parse_unit = failed to parse unit
84+
85+
codegen_ssa_thorin_incompatible_index_version = incompatible `{$section}` index version: found version {$actual}, expected version {$format}
86+
87+
codegen_ssa_thorin_offset_at_index = read offset at index {$index} of `.debug_str_offsets.dwo` section
88+
89+
codegen_ssa_thorin_str_at_offset = read string at offset {$offset} of `.debug_str.dwo` section
90+
91+
codegen_ssa_thorin_parse_index = failed to parse `{$section}` index section
92+
93+
codegen_ssa_thorin_unit_not_in_index = unit {$unit} from input package is not in its index
94+
95+
codegen_ssa_thorin_row_not_in_index = row {$row} found in index's hash table not present in index
96+
97+
codegen_ssa_thorin_section_not_in_row = section not found in unit's row in index
98+
99+
codegen_ssa_thorin_empty_unit = unit {$unit} in input DWARF object with no data
100+
101+
codegen_ssa_thorin_multiple_debug_info_section = multiple `.debug_info.dwo` sections
102+
103+
codegen_ssa_thorin_multiple_debug_types_section = multiple `.debug_types.dwo` sections in a package
104+
105+
codegen_ssa_thorin_not_split_unit = regular compilation unit in object (missing dwo identifier)
106+
107+
codegen_ssa_thorin_duplicate_unit = duplicate split compilation unit ({$unit})
108+
109+
codegen_ssa_thorin_missing_referenced_unit = unit {$unit} referenced by executable was not found
110+
111+
codegen_ssa_thorin_not_output_object_created = no output object was created from inputs
112+
113+
codegen_ssa_thorin_mixed_input_encodings = input objects haved mixed encodings
114+
115+
codegen_ssa_thorin_io = {$error}
116+
codegen_ssa_thorin_object_read = {$error}
117+
codegen_ssa_thorin_object_write = {$error}
118+
codegen_ssa_thorin_gimli_read = {$error}
119+
codegen_ssa_thorin_gimli_write = {$error}

0 commit comments

Comments
 (0)