105
105
use monomorphize:: collector:: InliningMap ;
106
106
use rustc:: dep_graph:: WorkProductId ;
107
107
use rustc:: hir:: CodegenFnAttrFlags ;
108
- use rustc:: hir:: def_id:: DefId ;
108
+ use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
109
109
use rustc:: hir:: map:: DefPathData ;
110
110
use rustc:: mir:: mono:: { Linkage , Visibility } ;
111
111
use rustc:: middle:: exported_symbols:: SymbolExportLevel ;
@@ -115,7 +115,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
115
115
use std:: collections:: hash_map:: Entry ;
116
116
use std:: cmp;
117
117
use syntax:: ast:: NodeId ;
118
- use syntax:: symbol:: { Symbol , InternedString } ;
118
+ use syntax:: symbol:: InternedString ;
119
119
use rustc:: mir:: mono:: MonoItem ;
120
120
use monomorphize:: item:: { MonoItemExt , InstantiationMode } ;
121
121
@@ -204,16 +204,9 @@ impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
204
204
205
205
// Anything we can't find a proper codegen unit for goes into this.
206
206
fn 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" ) )
214
208
}
215
209
216
-
217
210
pub fn partition < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
218
211
mono_items : I ,
219
212
strategy : PartitioningStrategy ,
@@ -224,8 +217,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
224
217
// In the first step, we place all regular monomorphizations into their
225
218
// respective 'home' codegen unit. Regular monomorphizations are all
226
219
// 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) ;
229
221
230
222
initial_partitioning. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. estimate_size ( & tcx) ) ;
231
223
@@ -234,7 +226,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
234
226
// If the partitioning should produce a fixed count of codegen units, merge
235
227
// until that count is reached.
236
228
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) ;
238
230
239
231
debug_dump ( tcx, "POST MERGING:" , initial_partitioning. codegen_units . iter ( ) ) ;
240
232
}
@@ -552,9 +544,9 @@ fn default_visibility(tcx: TyCtxt, id: DefId, is_generic: bool) -> Visibility {
552
544
}
553
545
}
554
546
555
- fn merge_codegen_units < ' tcx > ( initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
556
- target_cgu_count : usize ,
557
- crate_name : & str ) {
547
+ fn merge_codegen_units < ' tcx > ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
548
+ initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
549
+ target_cgu_count : usize ) {
558
550
assert ! ( target_cgu_count >= 1 ) ;
559
551
let codegen_units = & mut initial_partitioning. codegen_units ;
560
552
@@ -583,7 +575,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
583
575
}
584
576
585
577
for ( index, cgu) in codegen_units. iter_mut ( ) . enumerate ( ) {
586
- cgu. set_name ( numbered_codegen_unit_name ( crate_name , index) ) ;
578
+ cgu. set_name ( numbered_codegen_unit_name ( tcx , index) ) ;
587
579
}
588
580
}
589
581
@@ -787,42 +779,26 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
787
779
def_id : DefId ,
788
780
volatile : bool )
789
781
-> InternedString {
790
- // Unfortunately we cannot just use the `ty::item_path` infrastructure here
791
- // because we need paths to modules and the DefIds of those are not
792
- // available anymore for external items.
793
- let mut cgu_name = String :: with_capacity ( 64 ) ;
794
-
795
782
let def_path = tcx. def_path ( def_id) ;
796
- cgu_name. push_str ( & tcx. crate_name ( def_path. krate ) . as_str ( ) ) ;
797
-
798
- for part in tcx. def_path ( def_id)
799
- . data
800
- . iter ( )
801
- . take_while ( |part| {
802
- match part. data {
803
- DefPathData :: Module ( ..) => true ,
804
- _ => false ,
805
- }
806
- } ) {
807
- cgu_name. push_str ( "-" ) ;
808
- cgu_name. push_str ( & part. data . as_interned_str ( ) . as_str ( ) ) ;
809
- }
810
783
811
- if volatile {
812
- cgu_name. push_str ( ".volatile" ) ;
813
- }
784
+ let components = def_path. data . iter ( ) . take_while ( |part| {
785
+ match part. data {
786
+ DefPathData :: Module ( ..) => true ,
787
+ _ => false ,
788
+ }
789
+ } ) . map ( |part| part. data . as_interned_str ( ) ) ;
814
790
815
- let cgu_name = if tcx . sess . opts . debugging_opts . human_readable_cgu_names {
816
- cgu_name
791
+ let volatile_suffix = if volatile {
792
+ Some ( "volatile" )
817
793
} else {
818
- CodegenUnit :: mangle_name ( & cgu_name )
794
+ None
819
795
} ;
820
796
821
- Symbol :: intern ( & cgu_name [ .. ] ) . as_interned_str ( )
797
+ CodegenUnit :: build_cgu_name ( tcx , def_path . krate , components , volatile_suffix )
822
798
}
823
799
824
- fn numbered_codegen_unit_name ( crate_name : & str , index : usize ) -> InternedString {
825
- Symbol :: intern ( & format ! ( "{}{}" , crate_name , index) ) . as_interned_str ( )
800
+ fn numbered_codegen_unit_name ( tcx : TyCtxt , index : usize ) -> InternedString {
801
+ CodegenUnit :: build_cgu_name_no_mangle ( tcx , LOCAL_CRATE , & [ "cgu" ] , Some ( index) )
826
802
}
827
803
828
804
fn debug_dump < ' a , ' b , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments