@@ -165,7 +165,8 @@ where
165
165
// estimates.
166
166
{
167
167
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_merge_cgus" ) ;
168
- merge_codegen_units ( cx, & mut codegen_units) ;
168
+ let cgu_contents = merge_codegen_units ( cx, & mut codegen_units) ;
169
+ rename_codegen_units ( cx, & mut codegen_units, cgu_contents) ;
169
170
debug_dump ( tcx, "MERGE" , & codegen_units) ;
170
171
}
171
172
@@ -200,7 +201,6 @@ where
200
201
I : Iterator < Item = MonoItem < ' tcx > > ,
201
202
{
202
203
let mut codegen_units = UnordMap :: default ( ) ;
203
- let is_incremental_build = cx. tcx . sess . opts . incremental . is_some ( ) ;
204
204
let mut internalization_candidates = UnordSet :: default ( ) ;
205
205
206
206
// Determine if monomorphizations instantiated in this crate will be made
@@ -227,20 +227,8 @@ where
227
227
}
228
228
}
229
229
230
- let characteristic_def_id = characteristic_def_id_of_mono_item ( cx. tcx , mono_item) ;
231
- let is_volatile = is_incremental_build && mono_item. is_generic_fn ( ) ;
232
-
233
- let cgu_name = match characteristic_def_id {
234
- Some ( def_id) => compute_codegen_unit_name (
235
- cx. tcx ,
236
- cgu_name_builder,
237
- def_id,
238
- is_volatile,
239
- cgu_name_cache,
240
- ) ,
241
- None => fallback_cgu_name ( cgu_name_builder) ,
242
- } ;
243
-
230
+ let cgu_name =
231
+ compute_codegen_unit_name ( cx. tcx , cgu_name_builder, mono_item, cgu_name_cache) ;
244
232
let cgu = codegen_units. entry ( cgu_name) . or_insert_with ( || CodegenUnit :: new ( cgu_name) ) ;
245
233
246
234
let mut can_be_internalized = true ;
@@ -321,7 +309,7 @@ where
321
309
fn merge_codegen_units < ' tcx > (
322
310
cx : & PartitioningCx < ' _ , ' tcx > ,
323
311
codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
324
- ) {
312
+ ) -> UnordMap < Symbol , Vec < Symbol > > {
325
313
assert ! ( cx. tcx. sess. codegen_units( ) . as_usize( ) >= 1 ) ;
326
314
327
315
// A sorted order here ensures merging is deterministic.
@@ -331,6 +319,10 @@ fn merge_codegen_units<'tcx>(
331
319
let mut cgu_contents: UnordMap < Symbol , Vec < Symbol > > =
332
320
codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
333
321
322
+ if cx. tcx . is_compiler_builtins ( LOCAL_CRATE ) {
323
+ return cgu_contents;
324
+ }
325
+
334
326
// If N is the maximum number of CGUs, and the CGUs are sorted from largest
335
327
// to smallest, we repeatedly find which CGU in codegen_units[N..] has the
336
328
// greatest overlap of inlined items with codegen_units[N-1], merge that
@@ -421,8 +413,15 @@ fn merge_codegen_units<'tcx>(
421
413
// Don't update `cgu_contents`, that's only for incremental builds.
422
414
}
423
415
424
- let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
416
+ cgu_contents
417
+ }
425
418
419
+ fn rename_codegen_units < ' tcx > (
420
+ cx : & PartitioningCx < ' _ , ' tcx > ,
421
+ codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
422
+ cgu_contents : UnordMap < Symbol , Vec < Symbol > > ,
423
+ ) {
424
+ let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
426
425
// Rename the newly merged CGUs.
427
426
if cx. tcx . sess . opts . incremental . is_some ( ) {
428
427
// If we are doing incremental compilation, we want CGU names to
@@ -678,13 +677,21 @@ fn characteristic_def_id_of_mono_item<'tcx>(
678
677
}
679
678
}
680
679
681
- fn compute_codegen_unit_name (
682
- tcx : TyCtxt < ' _ > ,
680
+ fn compute_codegen_unit_name < ' tcx > (
681
+ tcx : TyCtxt < ' tcx > ,
683
682
name_builder : & mut CodegenUnitNameBuilder < ' _ > ,
684
- def_id : DefId ,
685
- volatile : bool ,
683
+ mono_item : MonoItem < ' tcx > ,
686
684
cache : & mut CguNameCache ,
687
685
) -> Symbol {
686
+ if tcx. is_compiler_builtins ( LOCAL_CRATE ) {
687
+ let name = mono_item. symbol_name ( tcx) ;
688
+ return Symbol :: intern ( name. name ) ;
689
+ }
690
+
691
+ let Some ( def_id) = characteristic_def_id_of_mono_item ( tcx, mono_item) else {
692
+ return fallback_cgu_name ( name_builder) ;
693
+ } ;
694
+
688
695
// Find the innermost module that is not nested within a function.
689
696
let mut current_def_id = def_id;
690
697
let mut cgu_def_id = None ;
@@ -712,6 +719,8 @@ fn compute_codegen_unit_name(
712
719
713
720
let cgu_def_id = cgu_def_id. unwrap ( ) ;
714
721
722
+ let is_incremental_build = tcx. sess . opts . incremental . is_some ( ) ;
723
+ let volatile = is_incremental_build && mono_item. is_generic_fn ( ) ;
715
724
* cache. entry ( ( cgu_def_id, volatile) ) . or_insert_with ( || {
716
725
let def_path = tcx. def_path ( cgu_def_id) ;
717
726
0 commit comments