@@ -118,18 +118,81 @@ use crate::errors::{
118
118
CouldntDumpMonoStats , SymbolAlreadyDefined , UnknownCguCollectionMode , UnknownPartitionStrategy ,
119
119
} ;
120
120
121
+ enum Partitioner {
122
+ Default ( default:: DefaultPartitioning ) ,
123
+ // Other partitioning strategies can go here.
124
+ Unknown ,
125
+ }
126
+
127
+ impl < ' tcx > Partition < ' tcx > for Partitioner {
128
+ fn place_root_mono_items < I > (
129
+ & mut self ,
130
+ cx : & PartitioningCx < ' _ , ' tcx > ,
131
+ mono_items : & mut I ,
132
+ ) -> PreInliningPartitioning < ' tcx >
133
+ where
134
+ I : Iterator < Item = MonoItem < ' tcx > > ,
135
+ {
136
+ match self {
137
+ Partitioner :: Default ( partitioner) => partitioner. place_root_mono_items ( cx, mono_items) ,
138
+ Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
139
+ }
140
+ }
141
+
142
+ fn merge_codegen_units (
143
+ & mut self ,
144
+ cx : & PartitioningCx < ' _ , ' tcx > ,
145
+ initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
146
+ ) {
147
+ match self {
148
+ Partitioner :: Default ( partitioner) => {
149
+ partitioner. merge_codegen_units ( cx, initial_partitioning)
150
+ }
151
+ Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
152
+ }
153
+ }
154
+
155
+ fn place_inlined_mono_items (
156
+ & mut self ,
157
+ cx : & PartitioningCx < ' _ , ' tcx > ,
158
+ initial_partitioning : PreInliningPartitioning < ' tcx > ,
159
+ ) -> PostInliningPartitioning < ' tcx > {
160
+ match self {
161
+ Partitioner :: Default ( partitioner) => {
162
+ partitioner. place_inlined_mono_items ( cx, initial_partitioning)
163
+ }
164
+ Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
165
+ }
166
+ }
167
+
168
+ fn internalize_symbols (
169
+ & mut self ,
170
+ cx : & PartitioningCx < ' _ , ' tcx > ,
171
+ post_inlining_partitioning : & mut PostInliningPartitioning < ' tcx > ,
172
+ ) {
173
+ match self {
174
+ Partitioner :: Default ( partitioner) => {
175
+ partitioner. internalize_symbols ( cx, post_inlining_partitioning)
176
+ }
177
+ Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
178
+ }
179
+ }
180
+ }
181
+
121
182
pub struct PartitioningCx < ' a , ' tcx > {
122
183
tcx : TyCtxt < ' tcx > ,
123
184
target_cgu_count : usize ,
124
185
inlining_map : & ' a InliningMap < ' tcx > ,
125
186
}
126
187
127
- trait Partitioner < ' tcx > {
128
- fn place_root_mono_items (
188
+ trait Partition < ' tcx > {
189
+ fn place_root_mono_items < I > (
129
190
& mut self ,
130
191
cx : & PartitioningCx < ' _ , ' tcx > ,
131
- mono_items : & mut dyn Iterator < Item = MonoItem < ' tcx > > ,
132
- ) -> PreInliningPartitioning < ' tcx > ;
192
+ mono_items : & mut I ,
193
+ ) -> PreInliningPartitioning < ' tcx >
194
+ where
195
+ I : Iterator < Item = MonoItem < ' tcx > > ;
133
196
134
197
fn merge_codegen_units (
135
198
& mut self ,
@@ -150,26 +213,27 @@ trait Partitioner<'tcx> {
150
213
) ;
151
214
}
152
215
153
- fn get_partitioner < ' tcx > ( tcx : TyCtxt < ' tcx > ) -> Box < dyn Partitioner < ' tcx > > {
216
+ fn get_partitioner ( tcx : TyCtxt < ' _ > ) -> Partitioner {
154
217
let strategy = match & tcx. sess . opts . unstable_opts . cgu_partitioning_strategy {
155
218
None => "default" ,
156
219
Some ( s) => & s[ ..] ,
157
220
} ;
158
221
159
222
match strategy {
160
- "default" => Box :: new ( default:: DefaultPartitioning ) ,
161
- _ => {
162
- tcx. sess . emit_fatal ( UnknownPartitionStrategy ) ;
163
- }
223
+ "default" => Partitioner :: Default ( default:: DefaultPartitioning ) ,
224
+ _ => Partitioner :: Unknown ,
164
225
}
165
226
}
166
227
167
- pub fn partition < ' tcx > (
228
+ pub fn partition < ' tcx , I > (
168
229
tcx : TyCtxt < ' tcx > ,
169
- mono_items : & mut dyn Iterator < Item = MonoItem < ' tcx > > ,
230
+ mono_items : & mut I ,
170
231
max_cgu_count : usize ,
171
232
inlining_map : & InliningMap < ' tcx > ,
172
- ) -> Vec < CodegenUnit < ' tcx > > {
233
+ ) -> Vec < CodegenUnit < ' tcx > >
234
+ where
235
+ I : Iterator < Item = MonoItem < ' tcx > > ,
236
+ {
173
237
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning" ) ;
174
238
175
239
let mut partitioner = get_partitioner ( tcx) ;
@@ -182,7 +246,9 @@ pub fn partition<'tcx>(
182
246
partitioner. place_root_mono_items ( cx, mono_items)
183
247
} ;
184
248
185
- initial_partitioning. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. create_size_estimate ( tcx) ) ;
249
+ for cgu in & mut initial_partitioning. codegen_units {
250
+ cgu. create_size_estimate ( tcx) ;
251
+ }
186
252
187
253
debug_dump ( tcx, "INITIAL PARTITIONING:" , initial_partitioning. codegen_units . iter ( ) ) ;
188
254
@@ -202,7 +268,9 @@ pub fn partition<'tcx>(
202
268
partitioner. place_inlined_mono_items ( cx, initial_partitioning)
203
269
} ;
204
270
205
- post_inlining. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. create_size_estimate ( tcx) ) ;
271
+ for cgu in & mut post_inlining. codegen_units {
272
+ cgu. create_size_estimate ( tcx) ;
273
+ }
206
274
207
275
debug_dump ( tcx, "POST INLINING:" , post_inlining. codegen_units . iter ( ) ) ;
208
276
@@ -380,7 +448,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
380
448
|| {
381
449
let mut codegen_units = partition (
382
450
tcx,
383
- & mut items. iter ( ) . cloned ( ) ,
451
+ & mut items. iter ( ) . copied ( ) ,
384
452
tcx. sess . codegen_units ( ) ,
385
453
& inlining_map,
386
454
) ;
0 commit comments