104104
105105use monomorphize:: collector:: InliningMap ;
106106use rustc:: dep_graph:: WorkProductId ;
107- use rustc:: hir:: def_id:: DefId ;
107+ use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
108108use rustc:: hir:: map:: DefPathData ;
109109use rustc:: mir:: mono:: { Linkage , Visibility } ;
110110use rustc:: middle:: exported_symbols:: SymbolExportLevel ;
@@ -114,7 +114,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
114114use std:: collections:: hash_map:: Entry ;
115115use std:: cmp;
116116use syntax:: ast:: NodeId ;
117- use syntax:: symbol:: { Symbol , InternedString } ;
117+ use syntax:: symbol:: InternedString ;
118118use rustc:: mir:: mono:: MonoItem ;
119119use monomorphize:: item:: { MonoItemExt , InstantiationMode } ;
120120
@@ -204,16 +204,9 @@ impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
204204
205205// Anything we can't find a proper codegen unit for goes into this.
206206fn fallback_cgu_name ( tcx : TyCtxt ) -> InternedString {
207- const FALLBACK_CODEGEN_UNIT : & ' static str = "__rustc_fallback_codegen_unit" ;
208-
209- if tcx. sess . opts . debugging_opts . human_readable_cgu_names {
210- Symbol :: intern ( FALLBACK_CODEGEN_UNIT ) . as_interned_str ( )
211- } else {
212- Symbol :: intern ( & CodegenUnit :: mangle_name ( FALLBACK_CODEGEN_UNIT ) ) . as_interned_str ( )
213- }
207+ CodegenUnit :: build_cgu_name ( tcx, LOCAL_CRATE , & [ "fallback" ] , Some ( "cgu" ) )
214208}
215209
216-
217210pub fn partition < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
218211 mono_items : I ,
219212 strategy : PartitioningStrategy ,
@@ -224,8 +217,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
224217 // In the first step, we place all regular monomorphizations into their
225218 // respective 'home' codegen unit. Regular monomorphizations are all
226219 // functions and statics defined in the local crate.
227- let mut initial_partitioning = place_root_mono_items ( tcx,
228- mono_items) ;
220+ let mut initial_partitioning = place_root_mono_items ( tcx, mono_items) ;
229221
230222 initial_partitioning. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. estimate_size ( & tcx) ) ;
231223
@@ -234,7 +226,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
234226 // If the partitioning should produce a fixed count of codegen units, merge
235227 // until that count is reached.
236228 if let PartitioningStrategy :: FixedUnitCount ( count) = strategy {
237- merge_codegen_units ( & mut initial_partitioning, count, & tcx . crate_name . as_str ( ) ) ;
229+ merge_codegen_units ( tcx , & mut initial_partitioning, count) ;
238230
239231 debug_dump ( tcx, "POST MERGING:" , initial_partitioning. codegen_units . iter ( ) ) ;
240232 }
@@ -328,7 +320,7 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
328320 } ;
329321
330322 let codegen_unit = codegen_units. entry ( codegen_unit_name. clone ( ) )
331- . or_insert_with ( make_codegen_unit) ;
323+ . or_insert_with ( make_codegen_unit) ;
332324
333325 let mut can_be_internalized = true ;
334326 let default_visibility = |id : DefId , is_generic : bool | {
@@ -491,9 +483,9 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
491483 }
492484}
493485
494- fn merge_codegen_units < ' tcx > ( initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
495- target_cgu_count : usize ,
496- crate_name : & str ) {
486+ fn merge_codegen_units < ' tcx > ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
487+ initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
488+ target_cgu_count : usize ) {
497489 assert ! ( target_cgu_count >= 1 ) ;
498490 let codegen_units = & mut initial_partitioning. codegen_units ;
499491
@@ -522,7 +514,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
522514 }
523515
524516 for ( index, cgu) in codegen_units. iter_mut ( ) . enumerate ( ) {
525- cgu. set_name ( numbered_codegen_unit_name ( crate_name , index) ) ;
517+ cgu. set_name ( numbered_codegen_unit_name ( tcx , index) ) ;
526518 }
527519}
528520
@@ -727,42 +719,26 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
727719 def_id : DefId ,
728720 volatile : bool )
729721 -> InternedString {
730- // Unfortunately we cannot just use the `ty::item_path` infrastructure here
731- // because we need paths to modules and the DefIds of those are not
732- // available anymore for external items.
733- let mut cgu_name = String :: with_capacity ( 64 ) ;
734-
735722 let def_path = tcx. def_path ( def_id) ;
736- cgu_name. push_str ( & tcx. crate_name ( def_path. krate ) . as_str ( ) ) ;
737-
738- for part in tcx. def_path ( def_id)
739- . data
740- . iter ( )
741- . take_while ( |part| {
742- match part. data {
743- DefPathData :: Module ( ..) => true ,
744- _ => false ,
745- }
746- } ) {
747- cgu_name. push_str ( "-" ) ;
748- cgu_name. push_str ( & part. data . as_interned_str ( ) . as_str ( ) ) ;
749- }
750723
751- if volatile {
752- cgu_name. push_str ( ".volatile" ) ;
753- }
724+ let components = def_path. data . iter ( ) . take_while ( |part| {
725+ match part. data {
726+ DefPathData :: Module ( ..) => true ,
727+ _ => false ,
728+ }
729+ } ) . map ( |part| part. data . as_interned_str ( ) ) ;
754730
755- let cgu_name = if tcx . sess . opts . debugging_opts . human_readable_cgu_names {
756- cgu_name
731+ let volatile_suffix = if volatile {
732+ Some ( "volatile" )
757733 } else {
758- CodegenUnit :: mangle_name ( & cgu_name )
734+ None
759735 } ;
760736
761- Symbol :: intern ( & cgu_name [ .. ] ) . as_interned_str ( )
737+ CodegenUnit :: build_cgu_name ( tcx , def_path . krate , components , volatile_suffix )
762738}
763739
764- fn numbered_codegen_unit_name ( crate_name : & str , index : usize ) -> InternedString {
765- Symbol :: intern ( & format ! ( "{}{}" , crate_name , index) ) . as_interned_str ( )
740+ fn numbered_codegen_unit_name ( tcx : TyCtxt , index : usize ) -> InternedString {
741+ CodegenUnit :: build_cgu_name_no_mangle ( tcx , LOCAL_CRATE , & [ "cgu" ] , Some ( index) )
766742}
767743
768744fn debug_dump < ' a , ' b , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments