@@ -106,6 +106,7 @@ use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
106
106
use rustc_middle:: ty:: print:: characteristic_def_id_of_type;
107
107
use rustc_middle:: ty:: query:: Providers ;
108
108
use rustc_middle:: ty:: { self , DefIdTree , InstanceDef , TyCtxt } ;
109
+ use rustc_session:: config:: OptLevel ;
109
110
use rustc_span:: symbol:: { Symbol , SymbolStr } ;
110
111
111
112
use crate :: monomorphize:: collector:: InliningMap ;
@@ -137,6 +138,8 @@ where
137
138
138
139
initial_partitioning. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. estimate_size ( tcx) ) ;
139
140
141
+ initial_partitioning. codegen_units . sort_by_key ( |cgu| cgu. name ( ) . as_str ( ) ) ;
142
+
140
143
debug_dump ( tcx, "INITIAL PARTITIONING:" , initial_partitioning. codegen_units . iter ( ) ) ;
141
144
142
145
// Merge until we have at most `max_cgu_count` codegen units.
@@ -152,7 +155,8 @@ where
152
155
// local functions the definition of which is marked with `#[inline]`.
153
156
let mut post_inlining = {
154
157
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_inline_items" ) ;
155
- place_inlined_mono_items ( initial_partitioning, inlining_map)
158
+ let is_debug_incremental = tcx. sess . opts . optimize == OptLevel :: No && tcx. sess . opts . incremental . is_some ( ) ;
159
+ place_inlined_mono_items ( initial_partitioning, inlining_map, is_debug_incremental)
156
160
} ;
157
161
158
162
post_inlining. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. estimate_size ( tcx) ) ;
@@ -226,15 +230,19 @@ where
226
230
let characteristic_def_id = characteristic_def_id_of_mono_item ( tcx, mono_item) ;
227
231
let is_volatile = is_incremental_build && mono_item. is_generic_fn ( ) ;
228
232
229
- let codegen_unit_name = match characteristic_def_id {
230
- Some ( def_id) => compute_codegen_unit_name (
233
+ let codegen_unit_name = match ( characteristic_def_id, mono_item. is_local ( ) ) {
234
+ ( Some ( def_id) , false ) if is_incremental_build && tcx. sess . opts . optimize == OptLevel :: No => {
235
+ let crate_name = tcx. crate_name ( def_id. krate ) ;
236
+ cgu_name_builder. build_cgu_name ( LOCAL_CRATE , & [ & * crate_name. as_str ( ) , if mono_item. has_closure_generic_argument ( ) { "has_closure" } else { "" } ] , Some ( "cgu" ) )
237
+ } ,
238
+ ( Some ( def_id) , _) => compute_codegen_unit_name (
231
239
tcx,
232
240
cgu_name_builder,
233
241
def_id,
234
242
is_volatile,
235
243
cgu_name_cache,
236
244
) ,
237
- None => fallback_cgu_name ( cgu_name_builder) ,
245
+ ( None , _ ) => fallback_cgu_name ( cgu_name_builder) ,
238
246
} ;
239
247
240
248
let codegen_unit = codegen_units
@@ -459,7 +467,7 @@ fn merge_codegen_units<'tcx>(
459
467
assert ! ( target_cgu_count >= 1 ) ;
460
468
let codegen_units = & mut initial_partitioning. codegen_units ;
461
469
462
- if tcx. is_compiler_builtins ( LOCAL_CRATE ) {
470
+ if tcx. is_compiler_builtins ( LOCAL_CRATE ) || ( tcx . dep_graph . is_fully_enabled ( ) && tcx . sess . opts . optimize == OptLevel :: No ) {
463
471
// Compiler builtins require some degree of control over how mono items
464
472
// are partitioned into compilation units. Provide it by keeping the
465
473
// original partitioning when compiling the compiler builtins crate.
@@ -555,6 +563,7 @@ fn merge_codegen_units<'tcx>(
555
563
fn place_inlined_mono_items < ' tcx > (
556
564
initial_partitioning : PreInliningPartitioning < ' tcx > ,
557
565
inlining_map : & InliningMap < ' tcx > ,
566
+ is_debug_incremental : bool ,
558
567
) -> PostInliningPartitioning < ' tcx > {
559
568
let mut new_partitioning = Vec :: new ( ) ;
560
569
let mut mono_item_placements = FxHashMap :: default ( ) ;
@@ -587,10 +596,14 @@ fn place_inlined_mono_items<'tcx>(
587
596
) ;
588
597
}
589
598
590
- // This is a CGU-private copy.
591
- new_codegen_unit
592
- . items_mut ( )
593
- . insert ( mono_item, ( Linkage :: Internal , Visibility :: Default ) ) ;
599
+ // In debug-incremental, do not create CGU-private copies unless it's for an external symbol
600
+ // FIXME: put external symbols in a separate codegen unit
601
+ if !is_debug_incremental || !mono_item. is_local ( ) {
602
+ // This is a CGU-private copy.
603
+ new_codegen_unit
604
+ . items_mut ( )
605
+ . insert ( mono_item, ( Linkage :: Internal , Visibility :: Default ) ) ;
606
+ }
594
607
}
595
608
596
609
if !single_codegen_unit {
0 commit comments