@@ -182,19 +182,7 @@ pub fn partition<'tcx, I>(tcx: &TyCtxt<'tcx>,
182
182
// easily determine which declarations need to be placed within each one.
183
183
let post_declarations = place_declarations ( post_inlining, reference_map) ;
184
184
185
- let mut final_partitioning = post_declarations. 0 ;
186
-
187
- if final_partitioning. len ( ) == 0 {
188
- // Some crates don't contain anything that will result in a translation
189
- // item. We still want to have at least one (empty) codegen unit in that
190
- // case.
191
- final_partitioning. push ( CodegenUnit {
192
- name : token:: intern_and_get_ident ( & format ! ( "{}.0" , tcx. crate_name) [ ..] ) ,
193
- items : FnvHashMap ( )
194
- } ) ;
195
- }
196
-
197
- final_partitioning
185
+ post_declarations. 0
198
186
}
199
187
200
188
struct PreInliningPartitioning < ' tcx > {
@@ -268,10 +256,6 @@ fn place_root_translation_items<'tcx, I>(tcx: &TyCtxt<'tcx>,
268
256
fn merge_codegen_units < ' tcx > ( initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
269
257
target_cgu_count : usize ,
270
258
crate_name : & str ) {
271
- if target_cgu_count >= initial_partitioning. codegen_units . len ( ) {
272
- return ;
273
- }
274
-
275
259
assert ! ( target_cgu_count >= 1 ) ;
276
260
let codegen_units = & mut initial_partitioning. codegen_units ;
277
261
@@ -290,7 +274,22 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
290
274
}
291
275
292
276
for ( index, cgu) in codegen_units. iter_mut ( ) . enumerate ( ) {
293
- cgu. name = token:: intern_and_get_ident ( & format ! ( "{}.{}" , crate_name, index) [ ..] ) ;
277
+ cgu. name = numbered_codegen_unit_name ( crate_name, index) ;
278
+ }
279
+
280
+ // If the initial partitioning contained less than target_cgu_count to begin
281
+ // with, we won't have enough codegen units here, so add a empty units until
282
+ // we reach the target count
283
+ while codegen_units. len ( ) < target_cgu_count {
284
+ let index = codegen_units. len ( ) ;
285
+ codegen_units. push ( CodegenUnit {
286
+ name : numbered_codegen_unit_name ( crate_name, index) ,
287
+ items : FnvHashMap ( )
288
+ } ) ;
289
+ }
290
+
291
+ fn numbered_codegen_unit_name ( crate_name : & str , index : usize ) -> InternedString {
292
+ token:: intern_and_get_ident ( & format ! ( "{}.{}" , crate_name, index) [ ..] )
294
293
}
295
294
}
296
295
0 commit comments