@@ -200,7 +200,16 @@ impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
200200}
201201
202202// 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+
204213
205214pub fn partition < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
206215 trans_items : I ,
@@ -297,7 +306,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
297306
298307 let codegen_unit_name = match characteristic_def_id {
299308 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 ) ,
301310 } ;
302311
303312 let make_codegen_unit = || {
@@ -381,7 +390,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
381390 // always ensure we have at least one CGU; otherwise, if we have a
382391 // crate with just types (for example), we could wind up with no CGU
383392 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 ) ;
385394 codegen_units. insert ( codegen_unit_name. clone ( ) ,
386395 CodegenUnit :: new ( codegen_unit_name. clone ( ) ) ) ;
387396 }
@@ -630,10 +639,10 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
630639 // Unfortunately we cannot just use the `ty::item_path` infrastructure here
631640 // because we need paths to modules and the DefIds of those are not
632641 // available anymore for external items.
633- let mut mod_path = String :: with_capacity ( 64 ) ;
642+ let mut cgu_name = String :: with_capacity ( 64 ) ;
634643
635644 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 ( ) ) ;
637646
638647 for part in tcx. def_path ( def_id)
639648 . data
@@ -644,15 +653,21 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
644653 _ => false ,
645654 }
646655 } ) {
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 ( ) ) ;
649658 }
650659
651660 if volatile {
652- mod_path . push_str ( ".volatile" ) ;
661+ cgu_name . push_str ( ".volatile" ) ;
653662 }
654663
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 ( )
656671}
657672
658673fn numbered_codegen_unit_name ( crate_name : & str , index : usize ) -> InternedString {
0 commit comments