@@ -319,6 +319,13 @@ fn merge_codegen_units<'tcx>(
319
319
let mut cgu_contents: UnordMap < Symbol , Vec < Symbol > > =
320
320
codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
321
321
322
+ // When compiling compiler_builtins, we do not want to put multiple intrinsics in a CGU.
323
+ // There may be mergeable CGUs under this constraint, but just skipping over merging is much
324
+ // simpler.
325
+ if cx. tcx . is_compiler_builtins ( LOCAL_CRATE ) {
326
+ return cgu_contents;
327
+ }
328
+
322
329
// If N is the maximum number of CGUs, and the CGUs are sorted from largest
323
330
// to smallest, we repeatedly find which CGU in codegen_units[N..] has the
324
331
// greatest overlap of inlined items with codegen_units[N-1], merge that
@@ -680,6 +687,16 @@ fn compute_codegen_unit_name<'tcx>(
680
687
mono_item : MonoItem < ' tcx > ,
681
688
cache : & mut CguNameCache ,
682
689
) -> Symbol {
690
+ // When compiling compiler_builtins, we do not want to put multiple intrinsics in a CGU.
691
+ // Using the symbol name as the CGU name puts every GloballyShared item in its own CGU, but in
692
+ // an optimized build we actually want every item in the crate that isn't an intrinsic to get
693
+ // LocalCopy so that it is easy to inline away. In an unoptimized build, this CGU naming
694
+ // strategy probably generates more CGUs than we strictly need. But it is simple.
695
+ if tcx. is_compiler_builtins ( LOCAL_CRATE ) {
696
+ let name = mono_item. symbol_name ( tcx) ;
697
+ return Symbol :: intern ( name. name ) ;
698
+ }
699
+
683
700
let Some ( def_id) = characteristic_def_id_of_mono_item ( tcx, mono_item) else {
684
701
return fallback_cgu_name ( name_builder) ;
685
702
} ;
0 commit comments