@@ -165,7 +165,8 @@ where
165165 // estimates.
166166 {
167167 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) ;
169170 debug_dump ( tcx, "MERGE" , & codegen_units) ;
170171 }
171172
@@ -200,7 +201,6 @@ where
200201 I : Iterator < Item = MonoItem < ' tcx > > ,
201202{
202203 let mut codegen_units = UnordMap :: default ( ) ;
203- let is_incremental_build = cx. tcx . sess . opts . incremental . is_some ( ) ;
204204 let mut internalization_candidates = UnordSet :: default ( ) ;
205205
206206 // Determine if monomorphizations instantiated in this crate will be made
@@ -227,20 +227,8 @@ where
227227 }
228228 }
229229
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) ;
244232 let cgu = codegen_units. entry ( cgu_name) . or_insert_with ( || CodegenUnit :: new ( cgu_name) ) ;
245233
246234 let mut can_be_internalized = true ;
@@ -321,7 +309,7 @@ where
321309fn merge_codegen_units < ' tcx > (
322310 cx : & PartitioningCx < ' _ , ' tcx > ,
323311 codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
324- ) {
312+ ) -> UnordMap < Symbol , Vec < Symbol > > {
325313 assert ! ( cx. tcx. sess. codegen_units( ) . as_usize( ) >= 1 ) ;
326314
327315 // A sorted order here ensures merging is deterministic.
@@ -331,6 +319,10 @@ fn merge_codegen_units<'tcx>(
331319 let mut cgu_contents: UnordMap < Symbol , Vec < Symbol > > =
332320 codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
333321
322+ if cx. tcx . is_compiler_builtins ( LOCAL_CRATE ) {
323+ return cgu_contents;
324+ }
325+
334326 // If N is the maximum number of CGUs, and the CGUs are sorted from largest
335327 // to smallest, we repeatedly find which CGU in codegen_units[N..] has the
336328 // greatest overlap of inlined items with codegen_units[N-1], merge that
@@ -421,8 +413,15 @@ fn merge_codegen_units<'tcx>(
421413 // Don't update `cgu_contents`, that's only for incremental builds.
422414 }
423415
424- let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
416+ cgu_contents
417+ }
425418
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 ) ;
426425 // Rename the newly merged CGUs.
427426 if cx. tcx . sess . opts . incremental . is_some ( ) {
428427 // If we are doing incremental compilation, we want CGU names to
@@ -678,13 +677,21 @@ fn characteristic_def_id_of_mono_item<'tcx>(
678677 }
679678}
680679
681- fn compute_codegen_unit_name (
682- tcx : TyCtxt < ' _ > ,
680+ fn compute_codegen_unit_name < ' tcx > (
681+ tcx : TyCtxt < ' tcx > ,
683682 name_builder : & mut CodegenUnitNameBuilder < ' _ > ,
684- def_id : DefId ,
685- volatile : bool ,
683+ mono_item : MonoItem < ' tcx > ,
686684 cache : & mut CguNameCache ,
687685) -> 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+
688695 // Find the innermost module that is not nested within a function.
689696 let mut current_def_id = def_id;
690697 let mut cgu_def_id = None ;
@@ -712,6 +719,8 @@ fn compute_codegen_unit_name(
712719
713720 let cgu_def_id = cgu_def_id. unwrap ( ) ;
714721
722+ let is_incremental_build = tcx. sess . opts . incremental . is_some ( ) ;
723+ let volatile = is_incremental_build && mono_item. is_generic_fn ( ) ;
715724 * cache. entry ( ( cgu_def_id, volatile) ) . or_insert_with ( || {
716725 let def_path = tcx. def_path ( cgu_def_id) ;
717726
0 commit comments