Skip to content

Commit e87d73b

Browse files
committed
Validate and test -Zmir-enable-passes
1 parent 71042b4 commit e87d73b

9 files changed

+83
-2
lines changed

compiler/rustc_mir_transform/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ mir_transform_undefined_transmute = pointers cannot be transmuted to integers du
3434
.note = at compile-time, pointers do not have an integer value
3535
.note2 = avoiding this restriction via `union` or raw pointers leads to compile-time undefined behavior
3636
.help = for more information, see https://doc.rust-lang.org/std/mem/fn.transmute.html
37+
38+
mir_transform_unknown_pass_name = MIR pass `{$name}` is unknown and will be ignored

compiler/rustc_mir_transform/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub(crate) struct UnalignedPackedRef {
3838
pub span: Span,
3939
}
4040

41+
#[derive(Diagnostic)]
42+
#[diag(mir_transform_unknown_pass_name)]
43+
pub(crate) struct UnknownPassName<'a> {
44+
pub(crate) name: &'a str,
45+
}
46+
4147
pub(crate) struct AssertLint<P> {
4248
pub span: Span,
4349
pub assert_kind: AssertKind<P>,

compiler/rustc_mir_transform/src/pass_manager.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::cell::RefCell;
22
use std::collections::hash_map::Entry;
33

4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
55
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
66
use rustc_middle::ty::TyCtxt;
77
use rustc_session::Session;
88
use tracing::trace;
99

1010
use crate::lint::lint_body;
11-
use crate::validate;
11+
use crate::{errors, validate};
1212

1313
thread_local! {
1414
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
@@ -197,6 +197,12 @@ fn run_passes_inner<'tcx>(
197197
) {
198198
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
199199
trace!(?overridden_passes);
200+
let named_passes =
201+
overridden_passes.iter().map(|(name, _)| name.as_str()).collect::<FxIndexSet<_>>();
202+
let known_passes = passes.iter().map(|p| p.name()).collect::<FxIndexSet<_>>();
203+
for &name in named_passes.difference(&known_passes) {
204+
tcx.dcx().emit_warn(errors::UnknownPassName { name });
205+
}
200206

201207
let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));
202208

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: MIR pass `CheckAlignment` is unknown and will be ignored
2+
3+
warning: MIR pass `LowerIntrinsics` is unknown and will be ignored
4+
5+
warning: MIR pass `CheckAlignment` is unknown and will be ignored
6+
|
7+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8+
9+
warning: MIR pass `LowerIntrinsics` is unknown and will be ignored
10+
|
11+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
12+
13+
warning: 4 warnings emitted
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: MIR pass `ThisPass` is unknown and will be ignored
2+
3+
warning: MIR pass `DoesNotExist` is unknown and will be ignored
4+
5+
warning: MIR pass `ThisPass` is unknown and will be ignored
6+
|
7+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8+
9+
warning: MIR pass `DoesNotExist` is unknown and will be ignored
10+
|
11+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
12+
13+
warning: 4 warnings emitted
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: incorrect value `` for unstable option `mir-enable-passes` - a comma-separated list of strings, with elements beginning with + or - was expected
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: MIR pass `ThisPassDoesNotExist` is unknown and will be ignored
2+
3+
warning: MIR pass `CheckAlignment` is unknown and will be ignored
4+
5+
warning: MIR pass `ThisPassDoesNotExist` is unknown and will be ignored
6+
|
7+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8+
9+
warning: MIR pass `CheckAlignment` is unknown and will be ignored
10+
|
11+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
12+
13+
warning: 4 warnings emitted
14+
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ revisions: empty unprefixed all_unknown all_known mixed
2+
3+
//@[empty] compile-flags: -Zmir-enable-passes=
4+
//@[empty] error-pattern error: incorrect value `` for unstable option `mir-enable-passes` - a comma-separated list of strings, with elements beginning with + or - was expected
5+
6+
//@[unprefixed] compile-flags: -Zmir-enable-passes=CheckAlignment
7+
//@[unprefixed] error-pattern error: incorrect value `CheckAlignment` for unstable option `mir-enable-passes` - a comma-separated list of strings, with elements beginning with + or - was expected
8+
9+
//@[all_unknown] check-pass
10+
//@[all_unknown] compile-flags: -Zmir-enable-passes=+ThisPass,-DoesNotExist
11+
//@[all_unknown] error-pattern: warning: MIR pass `ThisPass` is unknown and will be ignored
12+
//@[all_unknown] error-pattern: warning: MIR pass `DoesNotExist` is unknown and will be ignored
13+
14+
//@[all_known] check-pass
15+
//@[all_known] compile-flags: -Zmir-enable-passes=+CheckAlignment,+LowerIntrinsics
16+
17+
//@[mixed] check-pass
18+
//@[mixed] compile-flags: -Zmir-enable-passes=+ThisPassDoesNotExist,+CheckAlignment
19+
//@[mixed] error-pattern: warning: MIR pass `ThisPassDoesNotExist` is unknown and will be ignored
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: incorrect value `CheckAlignment` for unstable option `mir-enable-passes` - a comma-separated list of strings, with elements beginning with + or - was expected
2+

0 commit comments

Comments
 (0)