Skip to content

Commit 93b2acd

Browse files
Rollup merge of #100744 - 5225225:migrate-rustc-mir-dataflow, r=davidtwco
Migrate rustc_mir_dataflow to diagnostic structs
2 parents b543444 + f20cc9a commit 93b2acd

File tree

8 files changed

+129
-22
lines changed

8 files changed

+129
-22
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -4213,11 +4213,14 @@ dependencies = [
42134213
"regex",
42144214
"rustc_ast",
42154215
"rustc_data_structures",
4216+
"rustc_errors",
42164217
"rustc_graphviz",
42174218
"rustc_hir",
42184219
"rustc_index",
4220+
"rustc_macros",
42194221
"rustc_middle",
42204222
"rustc_serialize",
4223+
"rustc_session",
42214224
"rustc_span",
42224225
"rustc_target",
42234226
"smallvec",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
mir_dataflow_path_must_end_in_filename =
2+
path must end in a filename
3+
4+
mir_dataflow_unknown_formatter =
5+
unknown formatter
6+
7+
mir_dataflow_duplicate_values_for =
8+
duplicate values for `{$name}`
9+
10+
mir_dataflow_requires_an_argument =
11+
`{$name}` requires an argument
12+
13+
mir_dataflow_stop_after_dataflow_ended_compilation =
14+
stop_after_dataflow ended compilation
15+
16+
mir_dataflow_peek_must_be_place_or_ref_place =
17+
rustc_peek: argument expression must be either `place` or `&place`
18+
19+
mir_dataflow_peek_must_be_not_temporary =
20+
dataflow::sanity_check cannot feed a non-temp to rustc_peek
21+
22+
mir_dataflow_peek_bit_not_set =
23+
rustc_peek: bit not set
24+
25+
mir_dataflow_peek_argument_not_a_local =
26+
rustc_peek: argument was not a local
27+
28+
mir_dataflow_peek_argument_untracked =
29+
rustc_peek: argument untracked

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fluent_messages! {
4747
save_analysis => "../locales/en-US/save_analysis.ftl",
4848
ty_utils => "../locales/en-US/ty_utils.ftl",
4949
typeck => "../locales/en-US/typeck.ftl",
50+
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
5051
}
5152

5253
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

compiler/rustc_mir_dataflow/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1313
tracing = "0.1"
1414
rustc_ast = { path = "../rustc_ast" }
1515
rustc_data_structures = { path = "../rustc_data_structures" }
16+
rustc_errors = { path = "../rustc_errors" }
1617
rustc_graphviz = { path = "../rustc_graphviz" }
1718
rustc_hir = { path = "../rustc_hir" }
1819
rustc_index = { path = "../rustc_index" }
20+
rustc_macros = { path = "../rustc_macros" }
1921
rustc_middle = { path = "../rustc_middle" }
2022
rustc_serialize = { path = "../rustc_serialize" }
23+
rustc_session = { path = "../rustc_session" }
2124
rustc_target = { path = "../rustc_target" }
2225
rustc_span = { path = "../rustc_span" }
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::{Span, Symbol};
3+
4+
#[derive(SessionDiagnostic)]
5+
#[diag(mir_dataflow::path_must_end_in_filename)]
6+
pub(crate) struct PathMustEndInFilename {
7+
#[primary_span]
8+
pub span: Span,
9+
}
10+
11+
#[derive(SessionDiagnostic)]
12+
#[diag(mir_dataflow::unknown_formatter)]
13+
pub(crate) struct UnknownFormatter {
14+
#[primary_span]
15+
pub span: Span,
16+
}
17+
18+
#[derive(SessionDiagnostic)]
19+
#[diag(mir_dataflow::duplicate_values_for)]
20+
pub(crate) struct DuplicateValuesFor {
21+
#[primary_span]
22+
pub span: Span,
23+
pub name: Symbol,
24+
}
25+
26+
#[derive(SessionDiagnostic)]
27+
#[diag(mir_dataflow::requires_an_argument)]
28+
pub(crate) struct RequiresAnArgument {
29+
#[primary_span]
30+
pub span: Span,
31+
pub name: Symbol,
32+
}
33+
34+
#[derive(SessionDiagnostic)]
35+
#[diag(mir_dataflow::stop_after_dataflow_ended_compilation)]
36+
pub(crate) struct StopAfterDataFlowEndedCompilation;
37+
38+
#[derive(SessionDiagnostic)]
39+
#[diag(mir_dataflow::peek_must_be_place_or_ref_place)]
40+
pub(crate) struct PeekMustBePlaceOrRefPlace {
41+
#[primary_span]
42+
pub span: Span,
43+
}
44+
45+
#[derive(SessionDiagnostic)]
46+
#[diag(mir_dataflow::peek_must_be_not_temporary)]
47+
pub(crate) struct PeekMustBeNotTemporary {
48+
#[primary_span]
49+
pub span: Span,
50+
}
51+
52+
#[derive(SessionDiagnostic)]
53+
#[diag(mir_dataflow::peek_bit_not_set)]
54+
pub(crate) struct PeekBitNotSet {
55+
#[primary_span]
56+
pub span: Span,
57+
}
58+
59+
#[derive(SessionDiagnostic)]
60+
#[diag(mir_dataflow::peek_argument_not_a_local)]
61+
pub(crate) struct PeekArgumentNotALocal {
62+
#[primary_span]
63+
pub span: Span,
64+
}
65+
66+
#[derive(SessionDiagnostic)]
67+
#[diag(mir_dataflow::peek_argument_untracked)]
68+
pub(crate) struct PeekArgumentUntracked {
69+
#[primary_span]
70+
pub span: Span,
71+
}

compiler/rustc_mir_dataflow/src/framework/engine.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! A solver for dataflow problems.
22
3+
use crate::errors::{
4+
DuplicateValuesFor, PathMustEndInFilename, RequiresAnArgument, UnknownFormatter,
5+
};
36
use crate::framework::BitSetExt;
47

58
use std::ffi::OsString;
@@ -347,7 +350,7 @@ impl RustcMirAttrs {
347350
match path.file_name() {
348351
Some(_) => Ok(path),
349352
None => {
350-
tcx.sess.span_err(attr.span(), "path must end in a filename");
353+
tcx.sess.emit_err(PathMustEndInFilename { span: attr.span() });
351354
Err(())
352355
}
353356
}
@@ -356,7 +359,7 @@ impl RustcMirAttrs {
356359
Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
357360
sym::gen_kill | sym::two_phase => Ok(s),
358361
_ => {
359-
tcx.sess.span_err(attr.span(), "unknown formatter");
362+
tcx.sess.emit_err(UnknownFormatter { span: attr.span() });
360363
Err(())
361364
}
362365
})
@@ -377,8 +380,7 @@ impl RustcMirAttrs {
377380
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
378381
) -> Result<(), ()> {
379382
if field.is_some() {
380-
tcx.sess
381-
.span_err(attr.span(), &format!("duplicate values for `{}`", attr.name_or_empty()));
383+
tcx.sess.emit_err(DuplicateValuesFor { span: attr.span(), name: attr.name_or_empty() });
382384

383385
return Err(());
384386
}
@@ -387,8 +389,7 @@ impl RustcMirAttrs {
387389
*field = Some(mapper(s)?);
388390
Ok(())
389391
} else {
390-
tcx.sess
391-
.span_err(attr.span(), &format!("`{}` requires an argument", attr.name_or_empty()));
392+
tcx.sess.emit_err(RequiresAnArgument { span: attr.span(), name: attr.name_or_empty() });
392393
Err(())
393394
}
394395
}

compiler/rustc_mir_dataflow/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#![feature(stmt_expr_attributes)]
88
#![feature(trusted_step)]
99
#![recursion_limit = "256"]
10+
#![deny(rustc::untranslatable_diagnostic)]
11+
#![deny(rustc::diagnostic_outside_of_impl)]
1012

1113
#[macro_use]
1214
extern crate tracing;
@@ -33,6 +35,7 @@ use self::move_paths::MoveData;
3335

3436
pub mod drop_flag_effects;
3537
pub mod elaborate_drops;
38+
mod errors;
3639
mod framework;
3740
pub mod impls;
3841
pub mod move_paths;

compiler/rustc_mir_dataflow/src/rustc_peek.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use rustc_middle::mir::MirPass;
66
use rustc_middle::mir::{self, Body, Local, Location};
77
use rustc_middle::ty::{self, Ty, TyCtxt};
88

9+
use crate::errors::{
10+
PeekArgumentNotALocal, PeekArgumentUntracked, PeekBitNotSet, PeekMustBeNotTemporary,
11+
PeekMustBePlaceOrRefPlace, StopAfterDataFlowEndedCompilation,
12+
};
913
use crate::framework::BitSetExt;
1014
use crate::impls::{
1115
DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPlaces,
@@ -64,7 +68,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
6468
}
6569

6670
if has_rustc_mir_with(tcx, def_id, sym::stop_after_dataflow).is_some() {
67-
tcx.sess.fatal("stop_after_dataflow ended compilation");
71+
tcx.sess.emit_fatal(StopAfterDataFlowEndedCompilation);
6872
}
6973
}
7074
}
@@ -133,9 +137,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>(
133137
}
134138

135139
_ => {
136-
let msg = "rustc_peek: argument expression \
137-
must be either `place` or `&place`";
138-
tcx.sess.span_err(call.span, msg);
140+
tcx.sess.emit_err(PeekMustBePlaceOrRefPlace { span: call.span });
139141
}
140142
}
141143
}
@@ -204,18 +206,12 @@ impl PeekCall {
204206
if let Some(local) = place.as_local() {
205207
local
206208
} else {
207-
tcx.sess.diagnostic().span_err(
208-
span,
209-
"dataflow::sanity_check cannot feed a non-temp to rustc_peek.",
210-
);
209+
tcx.sess.emit_err(PeekMustBeNotTemporary { span });
211210
return None;
212211
}
213212
}
214213
_ => {
215-
tcx.sess.diagnostic().span_err(
216-
span,
217-
"dataflow::sanity_check cannot feed a non-temp to rustc_peek.",
218-
);
214+
tcx.sess.emit_err(PeekMustBeNotTemporary { span });
219215
return None;
220216
}
221217
};
@@ -255,12 +251,12 @@ where
255251
let bit_state = flow_state.contains(peek_mpi);
256252
debug!("rustc_peek({:?} = &{:?}) bit_state: {}", call.arg, place, bit_state);
257253
if !bit_state {
258-
tcx.sess.span_err(call.span, "rustc_peek: bit not set");
254+
tcx.sess.emit_err(PeekBitNotSet { span: call.span });
259255
}
260256
}
261257

262258
LookupResult::Parent(..) => {
263-
tcx.sess.span_err(call.span, "rustc_peek: argument untracked");
259+
tcx.sess.emit_err(PeekArgumentUntracked { span: call.span });
264260
}
265261
}
266262
}
@@ -276,12 +272,12 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
276272
) {
277273
info!(?place, "peek_at");
278274
let Some(local) = place.as_local() else {
279-
tcx.sess.span_err(call.span, "rustc_peek: argument was not a local");
275+
tcx.sess.emit_err(PeekArgumentNotALocal { span: call.span });
280276
return;
281277
};
282278

283279
if !flow_state.contains(local) {
284-
tcx.sess.span_err(call.span, "rustc_peek: bit not set");
280+
tcx.sess.emit_err(PeekBitNotSet { span: call.span });
285281
}
286282
}
287283
}

0 commit comments

Comments
 (0)