@@ -40,77 +40,158 @@ use tracing::{debug, trace};
40
40
#[ macro_use]
41
41
mod pass_manager;
42
42
43
+ use std:: sync:: LazyLock ;
44
+
43
45
use pass_manager:: { self as pm, Lint , MirLint , MirPass , WithMinOptLevel } ;
44
46
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;
58
47
mod cost_checker;
59
- mod coverage;
60
48
mod cross_crate_inline;
61
- mod ctfe_limit;
62
- mod dataflow_const_prop;
63
- mod dead_store_elimination;
64
49
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;
72
50
mod errors;
73
51
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;
83
52
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;
103
53
mod shim;
104
54
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
+ /// We import passes via this macro so that we can have a static list of pass names
57
+ /// (used to verify CLI arguments). It takes a list of modules, followed by the passes
58
+ /// declared within them.
59
+ /// ```ignore,macro-test
60
+ /// declare_passes! {
61
+ /// // Declare a single pass from the module `abort_unwinding_calls`
62
+ /// mod abort_unwinding_calls : AbortUnwindingCalls;
63
+ /// // When passes are grouped together as an enum, declare the two constituent passes
64
+ /// mod add_call_guards : AddCallGuards {
65
+ /// AllCallEdges,
66
+ /// CriticalCallEdges
67
+ /// };
68
+ /// // Declares multiple pass groups, each containing their own constituent passes
69
+ /// mod simplify : SimplifyCfg {
70
+ /// Initial,
71
+ /// /* omitted */
72
+ /// }, SimplifyLocals {
73
+ /// BeforeConstProp,
74
+ /// /* omitted */
75
+ /// };
76
+ /// }
77
+ /// ```
78
+ macro_rules! declare_passes {
79
+ (
80
+ $(
81
+ $vis: vis mod $mod_name: ident : $( $pass_name: ident $( { $( $ident: ident) ,* } ) ?) ,+ $( , ) ?;
82
+ ) *
83
+ ) => {
84
+ $(
85
+ $vis mod $mod_name;
86
+ $(
87
+ // Make sure the type name is correct
88
+ #[ allow( unused_imports) ]
89
+ use $mod_name:: $pass_name as _;
90
+ ) +
91
+ ) *
92
+
93
+ static PASS_NAMES : LazyLock <FxIndexSet <& str >> = LazyLock :: new( || [
94
+ // Fake marker pass
95
+ "PreCodegen" ,
96
+ $(
97
+ $(
98
+ stringify!( $pass_name) ,
99
+ $(
100
+ $(
101
+ $mod_name:: $pass_name:: $ident. name( ) ,
102
+ ) *
103
+ ) ?
104
+ ) +
105
+ ) *
106
+ ] . into_iter( ) . collect( ) ) ;
107
+ } ;
108
+ }
109
+
110
+ declare_passes ! {
111
+ mod abort_unwinding_calls : AbortUnwindingCalls ;
112
+ mod add_call_guards : AddCallGuards { AllCallEdges , CriticalCallEdges } ;
113
+ mod add_moves_for_packed_drops : AddMovesForPackedDrops ;
114
+ mod add_retag : AddRetag ;
115
+ mod add_subtyping_projections : Subtyper ;
116
+ mod check_alignment : CheckAlignment ;
117
+ mod check_const_item_mutation : CheckConstItemMutation ;
118
+ mod check_packed_ref : CheckPackedRef ;
119
+ mod check_undefined_transmutes : CheckUndefinedTransmutes ;
120
+ // This pass is public to allow external drivers to perform MIR cleanup
121
+ pub mod cleanup_post_borrowck : CleanupPostBorrowck ;
122
+
123
+ mod copy_prop : CopyProp ;
124
+ mod coroutine : StateTransform ;
125
+ mod coverage : InstrumentCoverage ;
126
+ mod ctfe_limit : CtfeLimit ;
127
+ mod dataflow_const_prop : DataflowConstProp ;
128
+ mod dead_store_elimination : DeadStoreElimination {
129
+ Initial ,
130
+ Final
131
+ } ;
132
+ mod deduplicate_blocks : DeduplicateBlocks ;
133
+ mod deref_separator : Derefer ;
134
+ mod dest_prop : DestinationPropagation ;
135
+ pub mod dump_mir : Marker ;
136
+ mod early_otherwise_branch : EarlyOtherwiseBranch ;
137
+ mod elaborate_box_derefs : ElaborateBoxDerefs ;
138
+ mod elaborate_drops : ElaborateDrops ;
139
+ mod function_item_references : FunctionItemReferences ;
140
+ mod gvn : GVN ;
141
+ // Made public so that `mir_drops_elaborated_and_const_checked` can be overridden
142
+ // by custom rustc drivers, running all the steps by themselves. See #114628.
143
+ pub mod inline : Inline ;
144
+ mod instsimplify : InstSimplify { BeforeInline , AfterSimplifyCfg } ;
145
+ mod jump_threading : JumpThreading ;
146
+ mod known_panics_lint : KnownPanicsLint ;
147
+ mod large_enums : EnumSizeOpt ;
148
+ mod lower_intrinsics : LowerIntrinsics ;
149
+ mod lower_slice_len : LowerSliceLenCalls ;
150
+ mod match_branches : MatchBranchSimplification ;
151
+ mod mentioned_items : MentionedItems ;
152
+ mod multiple_return_terminators : MultipleReturnTerminators ;
153
+ mod nrvo : RenameReturnPlace ;
154
+ mod post_drop_elaboration : CheckLiveDrops ;
155
+ mod prettify : ReorderBasicBlocks , ReorderLocals ;
156
+ mod promote_consts : PromoteTemps ;
157
+ mod ref_prop : ReferencePropagation ;
158
+ mod remove_noop_landing_pads : RemoveNoopLandingPads ;
159
+ mod remove_place_mention : RemovePlaceMention ;
160
+ mod remove_storage_markers : RemoveStorageMarkers ;
161
+ mod remove_uninit_drops : RemoveUninitDrops ;
162
+ mod remove_unneeded_drops : RemoveUnneededDrops ;
163
+ mod remove_zsts : RemoveZsts ;
164
+ mod required_consts : RequiredConstsVisitor ;
165
+ mod reveal_all : RevealAll ;
166
+ mod sanity_check : SanityCheck ;
167
+ // This pass is public to allow external drivers to perform MIR cleanup
168
+ pub mod simplify :
169
+ SimplifyCfg {
170
+ Initial ,
171
+ PromoteConsts ,
172
+ RemoveFalseEdges ,
173
+ PostAnalysis ,
174
+ PreOptimizations ,
175
+ Final ,
176
+ MakeShim ,
177
+ AfterUnreachableEnumBranching
178
+ } ,
179
+ SimplifyLocals {
180
+ BeforeConstProp ,
181
+ AfterGVN ,
182
+ Final
183
+ } ;
184
+ mod simplify_branches : SimplifyConstCondition {
185
+ AfterConstProp ,
186
+ Final
187
+ } ;
188
+ mod simplify_comparison_integral : SimplifyComparisonIntegral ;
189
+ mod single_use_consts : SingleUseConsts ;
190
+ mod sroa : ScalarReplacementOfAggregates ;
191
+ mod unreachable_enum_branching : UnreachableEnumBranching ;
192
+ mod unreachable_prop : UnreachablePropagation ;
193
+ mod validate : Validator ;
194
+ }
114
195
115
196
rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
116
197
0 commit comments