Skip to content

Commit cb47eaa

Browse files
committed
Declare all MIR passes in a list
1 parent 71042b4 commit cb47eaa

File tree

2 files changed

+132
-62
lines changed

2 files changed

+132
-62
lines changed

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 121 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -40,77 +40,137 @@ use tracing::{debug, trace};
4040
#[macro_use]
4141
mod pass_manager;
4242

43+
use std::sync::LazyLock;
44+
4345
use pass_manager::{self as pm, Lint, MirLint, MirPass, WithMinOptLevel};
4446

45-
mod abort_unwinding_calls;
46-
mod add_call_guards;
47-
mod add_moves_for_packed_drops;
48-
mod add_retag;
49-
mod add_subtyping_projections;
50-
mod check_alignment;
51-
mod check_const_item_mutation;
52-
mod check_packed_ref;
53-
mod check_undefined_transmutes;
54-
// This pass is public to allow external drivers to perform MIR cleanup
55-
pub mod cleanup_post_borrowck;
56-
mod copy_prop;
57-
mod coroutine;
5847
mod cost_checker;
59-
mod coverage;
6048
mod cross_crate_inline;
61-
mod ctfe_limit;
62-
mod dataflow_const_prop;
63-
mod dead_store_elimination;
6449
mod deduce_param_attrs;
65-
mod deduplicate_blocks;
66-
mod deref_separator;
67-
mod dest_prop;
68-
pub mod dump_mir;
69-
mod early_otherwise_branch;
70-
mod elaborate_box_derefs;
71-
mod elaborate_drops;
7250
mod errors;
7351
mod ffi_unwind_calls;
74-
mod function_item_references;
75-
mod gvn;
76-
// Made public so that `mir_drops_elaborated_and_const_checked` can be overridden
77-
// by custom rustc drivers, running all the steps by themselves. See #114628.
78-
pub mod inline;
79-
mod instsimplify;
80-
mod jump_threading;
81-
mod known_panics_lint;
82-
mod large_enums;
8352
mod lint;
84-
mod lower_intrinsics;
85-
mod lower_slice_len;
86-
mod match_branches;
87-
mod mentioned_items;
88-
mod multiple_return_terminators;
89-
mod nrvo;
90-
mod post_drop_elaboration;
91-
mod prettify;
92-
mod promote_consts;
93-
mod ref_prop;
94-
mod remove_noop_landing_pads;
95-
mod remove_place_mention;
96-
mod remove_storage_markers;
97-
mod remove_uninit_drops;
98-
mod remove_unneeded_drops;
99-
mod remove_zsts;
100-
mod required_consts;
101-
mod reveal_all;
102-
mod sanity_check;
10353
mod shim;
10454
mod ssa;
105-
// This pass is public to allow external drivers to perform MIR cleanup
106-
pub mod simplify;
107-
mod simplify_branches;
108-
mod simplify_comparison_integral;
109-
mod single_use_consts;
110-
mod sroa;
111-
mod unreachable_enum_branching;
112-
mod unreachable_prop;
113-
mod validate;
55+
56+
macro_rules! declare_passes {
57+
(
58+
$(
59+
$vis:vis mod $mod_name:ident : $($pass_name:ident $( { $($ident:ident),* } )?),+;
60+
)*
61+
) => {
62+
$(
63+
$vis mod $mod_name;
64+
$(
65+
// Make sure the type name is correct
66+
#[allow(unused_imports)]
67+
use $mod_name::$pass_name as _;
68+
)+
69+
)*
70+
71+
#[cfg(debug_assertions)]
72+
static PASS_NAMES: LazyLock<Vec<String>> = LazyLock::new(|| vec![
73+
// Fake marker pass
74+
"PreCodegen".to_string(),
75+
$(
76+
$(
77+
stringify!($pass_name).to_string(),
78+
$(
79+
$(
80+
$mod_name::$pass_name::$ident.name().to_string(),
81+
)*
82+
)?
83+
)+
84+
)*
85+
]);
86+
};
87+
}
88+
89+
declare_passes! {
90+
mod abort_unwinding_calls : AbortUnwindingCalls;
91+
mod add_call_guards : AddCallGuards { AllCallEdges, CriticalCallEdges };
92+
mod add_moves_for_packed_drops : AddMovesForPackedDrops;
93+
mod add_retag : AddRetag;
94+
mod add_subtyping_projections : Subtyper;
95+
mod check_alignment : CheckAlignment;
96+
mod check_const_item_mutation : CheckConstItemMutation;
97+
mod check_packed_ref : CheckPackedRef;
98+
mod check_undefined_transmutes : CheckUndefinedTransmutes;
99+
// This pass is public to allow external drivers to perform MIR cleanup
100+
pub mod cleanup_post_borrowck : CleanupPostBorrowck;
101+
102+
mod copy_prop : CopyProp;
103+
mod coroutine : StateTransform;
104+
mod coverage : InstrumentCoverage;
105+
mod ctfe_limit : CtfeLimit;
106+
mod dataflow_const_prop : DataflowConstProp;
107+
mod dead_store_elimination : DeadStoreElimination {
108+
Initial,
109+
Final
110+
};
111+
mod deduplicate_blocks : DeduplicateBlocks;
112+
mod deref_separator : Derefer;
113+
mod dest_prop : DestinationPropagation;
114+
pub mod dump_mir : Marker;
115+
mod early_otherwise_branch : EarlyOtherwiseBranch;
116+
mod elaborate_box_derefs : ElaborateBoxDerefs;
117+
mod elaborate_drops : ElaborateDrops;
118+
mod function_item_references : FunctionItemReferences;
119+
mod gvn : GVN;
120+
// Made public so that `mir_drops_elaborated_and_const_checked` can be overridden
121+
// by custom rustc drivers, running all the steps by themselves. See #114628.
122+
pub mod inline : Inline;
123+
mod instsimplify : InstSimplify { BeforeInline, AfterSimplifyCfg };
124+
mod jump_threading : JumpThreading;
125+
mod known_panics_lint : KnownPanicsLint;
126+
mod large_enums : EnumSizeOpt;
127+
mod lower_intrinsics : LowerIntrinsics;
128+
mod lower_slice_len : LowerSliceLenCalls;
129+
mod match_branches : MatchBranchSimplification;
130+
mod mentioned_items : MentionedItems;
131+
mod multiple_return_terminators : MultipleReturnTerminators;
132+
mod nrvo : RenameReturnPlace;
133+
mod post_drop_elaboration : CheckLiveDrops;
134+
mod prettify : ReorderBasicBlocks, ReorderLocals;
135+
mod promote_consts : PromoteTemps;
136+
mod ref_prop : ReferencePropagation;
137+
mod remove_noop_landing_pads : RemoveNoopLandingPads;
138+
mod remove_place_mention : RemovePlaceMention;
139+
mod remove_storage_markers : RemoveStorageMarkers;
140+
mod remove_uninit_drops : RemoveUninitDrops;
141+
mod remove_unneeded_drops : RemoveUnneededDrops;
142+
mod remove_zsts : RemoveZsts;
143+
mod required_consts : RequiredConstsVisitor;
144+
mod reveal_all : RevealAll;
145+
mod sanity_check : SanityCheck;
146+
// This pass is public to allow external drivers to perform MIR cleanup
147+
pub mod simplify :
148+
SimplifyCfg {
149+
Initial,
150+
PromoteConsts,
151+
RemoveFalseEdges,
152+
PostAnalysis,
153+
PreOptimizations,
154+
Final,
155+
MakeShim,
156+
AfterUnreachableEnumBranching
157+
},
158+
SimplifyLocals {
159+
BeforeConstProp,
160+
AfterGVN,
161+
Final
162+
};
163+
mod simplify_branches : SimplifyConstCondition {
164+
AfterConstProp,
165+
Final
166+
};
167+
mod simplify_comparison_integral : SimplifyComparisonIntegral;
168+
mod single_use_consts : SingleUseConsts;
169+
mod sroa : ScalarReplacementOfAggregates;
170+
mod unreachable_enum_branching : UnreachableEnumBranching;
171+
mod unreachable_prop : UnreachablePropagation;
172+
mod validate : Validator;
173+
}
114174

115175
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
116176

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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;
@@ -198,6 +198,16 @@ fn run_passes_inner<'tcx>(
198198
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
199199
trace!(?overridden_passes);
200200

201+
#[cfg(debug_assertions)]
202+
{
203+
let used_passes: FxIndexSet<_> = passes.iter().map(|p| p.name()).collect();
204+
let known_passes: FxIndexSet<_> = crate::PASS_NAMES.iter().map(|p| p.as_str()).collect();
205+
206+
for &name in used_passes.difference(&known_passes) {
207+
tcx.dcx().bug(format!("pass `{name}` is not declared in `PASS_NAMES`"));
208+
}
209+
}
210+
201211
let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));
202212

203213
if !body.should_skip() {

0 commit comments

Comments
 (0)