@@ -200,7 +200,16 @@ impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
200
200
}
201
201
202
202
// Anything we can't find a proper codegen unit for goes into this.
203
- const FALLBACK_CODEGEN_UNIT : & ' static str = "__rustc_fallback_codegen_unit" ;
203
+ fn fallback_cgu_name ( tcx : TyCtxt ) -> InternedString {
204
+ const FALLBACK_CODEGEN_UNIT : & ' static str = "__rustc_fallback_codegen_unit" ;
205
+
206
+ if tcx. sess . opts . debugging_opts . human_readable_cgu_names {
207
+ Symbol :: intern ( FALLBACK_CODEGEN_UNIT ) . as_str ( )
208
+ } else {
209
+ Symbol :: intern ( & CodegenUnit :: mangle_name ( FALLBACK_CODEGEN_UNIT ) ) . as_str ( )
210
+ }
211
+ }
212
+
204
213
205
214
pub fn partition < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
206
215
trans_items : I ,
@@ -297,7 +306,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
297
306
298
307
let codegen_unit_name = match characteristic_def_id {
299
308
Some ( def_id) => compute_codegen_unit_name ( tcx, def_id, is_volatile) ,
300
- None => Symbol :: intern ( FALLBACK_CODEGEN_UNIT ) . as_str ( ) ,
309
+ None => fallback_cgu_name ( tcx ) ,
301
310
} ;
302
311
303
312
let make_codegen_unit = || {
@@ -381,7 +390,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
381
390
// always ensure we have at least one CGU; otherwise, if we have a
382
391
// crate with just types (for example), we could wind up with no CGU
383
392
if codegen_units. is_empty ( ) {
384
- let codegen_unit_name = Symbol :: intern ( FALLBACK_CODEGEN_UNIT ) . as_str ( ) ;
393
+ let codegen_unit_name = fallback_cgu_name ( tcx ) ;
385
394
codegen_units. insert ( codegen_unit_name. clone ( ) ,
386
395
CodegenUnit :: new ( codegen_unit_name. clone ( ) ) ) ;
387
396
}
@@ -630,10 +639,10 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
630
639
// Unfortunately we cannot just use the `ty::item_path` infrastructure here
631
640
// because we need paths to modules and the DefIds of those are not
632
641
// available anymore for external items.
633
- let mut mod_path = String :: with_capacity ( 64 ) ;
642
+ let mut cgu_name = String :: with_capacity ( 64 ) ;
634
643
635
644
let def_path = tcx. def_path ( def_id) ;
636
- mod_path . push_str ( & tcx. crate_name ( def_path. krate ) . as_str ( ) ) ;
645
+ cgu_name . push_str ( & tcx. crate_name ( def_path. krate ) . as_str ( ) ) ;
637
646
638
647
for part in tcx. def_path ( def_id)
639
648
. data
@@ -644,15 +653,21 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
644
653
_ => false ,
645
654
}
646
655
} ) {
647
- mod_path . push_str ( "-" ) ;
648
- mod_path . push_str ( & part. data . as_interned_str ( ) ) ;
656
+ cgu_name . push_str ( "-" ) ;
657
+ cgu_name . push_str ( & part. data . as_interned_str ( ) ) ;
649
658
}
650
659
651
660
if volatile {
652
- mod_path . push_str ( ".volatile" ) ;
661
+ cgu_name . push_str ( ".volatile" ) ;
653
662
}
654
663
655
- return Symbol :: intern ( & mod_path[ ..] ) . as_str ( ) ;
664
+ let cgu_name = if tcx. sess . opts . debugging_opts . human_readable_cgu_names {
665
+ cgu_name
666
+ } else {
667
+ CodegenUnit :: mangle_name ( & cgu_name)
668
+ } ;
669
+
670
+ Symbol :: intern ( & cgu_name[ ..] ) . as_str ( )
656
671
}
657
672
658
673
fn numbered_codegen_unit_name ( crate_name : & str , index : usize ) -> InternedString {
0 commit comments