@@ -173,7 +173,7 @@ where
173
173
// monomorphizations have to go into each codegen unit. These additional
174
174
// monomorphizations can be drop-glue, functions from external crates, and
175
175
// local functions the definition of which is marked with `#[inline]`.
176
- let mono_item_placements = {
176
+ {
177
177
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_inline_items" ) ;
178
178
place_inlined_mono_items ( cx, & mut codegen_units)
179
179
} ;
@@ -188,12 +188,7 @@ where
188
188
// more freedom to optimize.
189
189
if !tcx. sess . link_dead_code ( ) {
190
190
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_internalize_symbols" ) ;
191
- internalize_symbols (
192
- cx,
193
- & mut codegen_units,
194
- mono_item_placements,
195
- internalization_candidates,
196
- ) ;
191
+ internalize_symbols ( cx, & mut codegen_units, internalization_candidates) ;
197
192
}
198
193
199
194
let instrument_dead_code =
@@ -401,19 +396,10 @@ fn merge_codegen_units<'tcx>(
401
396
codegen_units. sort_by ( |a, b| a. name ( ) . as_str ( ) . cmp ( b. name ( ) . as_str ( ) ) ) ;
402
397
}
403
398
404
- /// For symbol internalization, we need to know whether a symbol/mono-item is
405
- /// used from outside the codegen unit it is defined in. This type is used
406
- /// to keep track of that.
407
- #[ derive( Clone , PartialEq , Eq , Debug ) ]
408
- enum MonoItemPlacement {
409
- SingleCgu { cgu_name : Symbol } ,
410
- MultipleCgus ,
411
- }
412
-
413
399
fn place_inlined_mono_items < ' tcx > (
414
400
cx : & PartitioningCx < ' _ , ' tcx > ,
415
401
codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
416
- ) -> FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > {
402
+ ) {
417
403
for cgu in codegen_units. iter_mut ( ) {
418
404
// Collect all inlined items that need to be available in this codegen unit.
419
405
let mut reachable_inlined_items = FxHashSet :: default ( ) ;
@@ -432,33 +418,6 @@ fn place_inlined_mono_items<'tcx>(
432
418
}
433
419
}
434
420
435
- let mut mono_item_placements = FxHashMap :: default ( ) ;
436
- let single_codegen_unit = codegen_units. len ( ) == 1 ;
437
-
438
- for cgu in codegen_units. iter_mut ( ) {
439
- for item in cgu. items ( ) . keys ( ) {
440
- if !single_codegen_unit {
441
- // If there is more than one codegen unit, we need to keep track
442
- // in which codegen units each monomorphization is placed.
443
- match mono_item_placements. entry ( * item) {
444
- Entry :: Occupied ( e) => {
445
- let placement = e. into_mut ( ) ;
446
- debug_assert ! ( match * placement {
447
- MonoItemPlacement :: SingleCgu { cgu_name } => cgu_name != cgu. name( ) ,
448
- MonoItemPlacement :: MultipleCgus => true ,
449
- } ) ;
450
- * placement = MonoItemPlacement :: MultipleCgus ;
451
- }
452
- Entry :: Vacant ( e) => {
453
- e. insert ( MonoItemPlacement :: SingleCgu { cgu_name : cgu. name ( ) } ) ;
454
- }
455
- }
456
- }
457
- }
458
- }
459
-
460
- return mono_item_placements;
461
-
462
421
fn get_reachable_inlined_items < ' tcx > (
463
422
tcx : TyCtxt < ' tcx > ,
464
423
item : MonoItem < ' tcx > ,
@@ -477,11 +436,42 @@ fn place_inlined_mono_items<'tcx>(
477
436
fn internalize_symbols < ' tcx > (
478
437
cx : & PartitioningCx < ' _ , ' tcx > ,
479
438
codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
480
- mono_item_placements : FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > ,
481
439
internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
482
440
) {
441
+ /// For symbol internalization, we need to know whether a symbol/mono-item
442
+ /// is used from outside the codegen unit it is defined in. This type is
443
+ /// used to keep track of that.
444
+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
445
+ enum MonoItemPlacement {
446
+ SingleCgu { cgu_name : Symbol } ,
447
+ MultipleCgus ,
448
+ }
449
+
450
+ let mut mono_item_placements = FxHashMap :: default ( ) ;
483
451
let single_codegen_unit = codegen_units. len ( ) == 1 ;
484
452
453
+ if !single_codegen_unit {
454
+ for cgu in codegen_units. iter_mut ( ) {
455
+ for item in cgu. items ( ) . keys ( ) {
456
+ // If there is more than one codegen unit, we need to keep track
457
+ // in which codegen units each monomorphization is placed.
458
+ match mono_item_placements. entry ( * item) {
459
+ Entry :: Occupied ( e) => {
460
+ let placement = e. into_mut ( ) ;
461
+ debug_assert ! ( match * placement {
462
+ MonoItemPlacement :: SingleCgu { cgu_name } => cgu_name != cgu. name( ) ,
463
+ MonoItemPlacement :: MultipleCgus => true ,
464
+ } ) ;
465
+ * placement = MonoItemPlacement :: MultipleCgus ;
466
+ }
467
+ Entry :: Vacant ( e) => {
468
+ e. insert ( MonoItemPlacement :: SingleCgu { cgu_name : cgu. name ( ) } ) ;
469
+ }
470
+ }
471
+ }
472
+ }
473
+ }
474
+
485
475
// For each internalization candidates in each codegen unit, check if it is
486
476
// used from outside its defining codegen unit.
487
477
for cgu in codegen_units {
0 commit comments