mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Validate and test -Zmir-enable-passes
This commit is contained in:
parent
2a9cc8f4d6
commit
94371d5a8c
@ -34,3 +34,5 @@ mir_transform_undefined_transmute = pointers cannot be transmuted to integers du
|
||||
.note = at compile-time, pointers do not have an integer value
|
||||
.note2 = avoiding this restriction via `union` or raw pointers leads to compile-time undefined behavior
|
||||
.help = for more information, see https://doc.rust-lang.org/std/mem/fn.transmute.html
|
||||
|
||||
mir_transform_unknown_pass_name = MIR pass `{$name}` is unknown and will be ignored
|
||||
|
@ -38,6 +38,12 @@ pub(crate) struct UnalignedPackedRef {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(mir_transform_unknown_pass_name)]
|
||||
pub(crate) struct UnknownPassName<'a> {
|
||||
pub(crate) name: &'a str,
|
||||
}
|
||||
|
||||
pub(crate) struct AssertLint<P> {
|
||||
pub span: Span,
|
||||
pub assert_kind: AssertKind<P>,
|
||||
|
@ -90,7 +90,6 @@ macro_rules! declare_passes {
|
||||
)+
|
||||
)*
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
static PASS_NAMES: LazyLock<Vec<String>> = LazyLock::new(|| vec![
|
||||
// Fake marker pass
|
||||
"PreCodegen".to_string(),
|
||||
|
@ -8,7 +8,7 @@ use rustc_session::Session;
|
||||
use tracing::trace;
|
||||
|
||||
use crate::lint::lint_body;
|
||||
use crate::validate;
|
||||
use crate::{errors, validate};
|
||||
|
||||
thread_local! {
|
||||
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
|
||||
@ -198,13 +198,29 @@ fn run_passes_inner<'tcx>(
|
||||
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
|
||||
trace!(?overridden_passes);
|
||||
|
||||
let named_passes: FxIndexSet<_> =
|
||||
overridden_passes.iter().map(|(name, _)| name.as_str()).collect();
|
||||
let known_passes: FxIndexSet<_> = crate::PASS_NAMES.iter().map(|p| p.as_str()).collect();
|
||||
|
||||
for &name in named_passes.difference(&known_passes) {
|
||||
tcx.dcx().emit_warn(errors::UnknownPassName { name });
|
||||
}
|
||||
|
||||
// Verify that no passes are missing from the `declare_passes` invocation
|
||||
#[cfg(debug_assertions)]
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
{
|
||||
let used_passes: FxIndexSet<_> = passes.iter().map(|p| p.name()).collect();
|
||||
let known_passes: FxIndexSet<_> = crate::PASS_NAMES.iter().map(|p| p.as_str()).collect();
|
||||
|
||||
for &name in used_passes.difference(&known_passes) {
|
||||
tcx.dcx().bug(format!("pass `{name}` is not declared in `PASS_NAMES`"));
|
||||
let undeclared = used_passes.difference(&known_passes).collect::<Vec<_>>();
|
||||
if let Some((name, rest)) = undeclared.split_first() {
|
||||
let mut err =
|
||||
tcx.dcx().struct_bug(format!("pass `{name}` is not declared in `PASS_NAMES`"));
|
||||
for name in rest {
|
||||
err.note(format!("pass `{name}` is also not declared in `PASS_NAMES`"));
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
14
tests/ui/mir/enable_passes_validation.all_unknown.stderr
Normal file
14
tests/ui/mir/enable_passes_validation.all_unknown.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
warning: MIR pass `ThisPass` is unknown and will be ignored
|
||||
|
||||
warning: MIR pass `DoesNotExist` is unknown and will be ignored
|
||||
|
||||
warning: MIR pass `ThisPass` is unknown and will be ignored
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
warning: MIR pass `DoesNotExist` is unknown and will be ignored
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
warning: 4 warnings emitted
|
||||
|
2
tests/ui/mir/enable_passes_validation.empty.stderr
Normal file
2
tests/ui/mir/enable_passes_validation.empty.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: incorrect value `` for unstable option `mir-enable-passes` - a comma-separated list of strings, with elements beginning with + or - was expected
|
||||
|
8
tests/ui/mir/enable_passes_validation.mixed.stderr
Normal file
8
tests/ui/mir/enable_passes_validation.mixed.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
warning: MIR pass `ThisPassDoesNotExist` is unknown and will be ignored
|
||||
|
||||
warning: MIR pass `ThisPassDoesNotExist` is unknown and will be ignored
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
warning: 2 warnings emitted
|
||||
|
21
tests/ui/mir/enable_passes_validation.rs
Normal file
21
tests/ui/mir/enable_passes_validation.rs
Normal file
@ -0,0 +1,21 @@
|
||||
//@ revisions: empty unprefixed all_unknown all_known mixed
|
||||
|
||||
//@[empty] compile-flags: -Zmir-enable-passes=
|
||||
//@[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
|
||||
|
||||
//@[unprefixed] compile-flags: -Zmir-enable-passes=CheckAlignment
|
||||
//@[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
|
||||
|
||||
//@[all_unknown] check-pass
|
||||
//@[all_unknown] compile-flags: -Zmir-enable-passes=+ThisPass,-DoesNotExist
|
||||
//@[all_unknown] error-pattern: warning: MIR pass `ThisPass` is unknown and will be ignored
|
||||
//@[all_unknown] error-pattern: warning: MIR pass `DoesNotExist` is unknown and will be ignored
|
||||
|
||||
//@[all_known] check-pass
|
||||
//@[all_known] compile-flags: -Zmir-enable-passes=+CheckAlignment,+LowerIntrinsics
|
||||
|
||||
//@[mixed] check-pass
|
||||
//@[mixed] compile-flags: -Zmir-enable-passes=+ThisPassDoesNotExist,+CheckAlignment
|
||||
//@[mixed] error-pattern: warning: MIR pass `ThisPassDoesNotExist` is unknown and will be ignored
|
||||
|
||||
fn main() {}
|
2
tests/ui/mir/enable_passes_validation.unprefixed.stderr
Normal file
2
tests/ui/mir/enable_passes_validation.unprefixed.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: incorrect value `CheckAlignment` for unstable option `mir-enable-passes` - a comma-separated list of strings, with elements beginning with + or - was expected
|
||||
|
Loading…
Reference in New Issue
Block a user