104
104
105
105
use monomorphize:: collector:: InliningMap ;
106
106
use rustc:: dep_graph:: WorkProductId ;
107
- use rustc:: hir:: def_id:: DefId ;
107
+ use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
108
108
use rustc:: hir:: map:: DefPathData ;
109
109
use rustc:: mir:: mono:: { Linkage , Visibility } ;
110
110
use rustc:: middle:: exported_symbols:: SymbolExportLevel ;
@@ -114,7 +114,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
114
114
use std:: collections:: hash_map:: Entry ;
115
115
use std:: cmp;
116
116
use syntax:: ast:: NodeId ;
117
- use syntax:: symbol:: { Symbol , InternedString } ;
117
+ use syntax:: symbol:: InternedString ;
118
118
use rustc:: mir:: mono:: MonoItem ;
119
119
use monomorphize:: item:: { MonoItemExt , InstantiationMode } ;
120
120
@@ -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
}
@@ -328,7 +320,7 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
328
320
} ;
329
321
330
322
let codegen_unit = codegen_units. entry ( codegen_unit_name. clone ( ) )
331
- . or_insert_with ( make_codegen_unit) ;
323
+ . or_insert_with ( make_codegen_unit) ;
332
324
333
325
let mut can_be_internalized = true ;
334
326
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>,
491
483
}
492
484
}
493
485
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 ) {
497
489
assert ! ( target_cgu_count >= 1 ) ;
498
490
let codegen_units = & mut initial_partitioning. codegen_units ;
499
491
@@ -522,7 +514,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
522
514
}
523
515
524
516
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) ) ;
526
518
}
527
519
}
528
520
@@ -727,42 +719,26 @@ fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
727
719
def_id : DefId ,
728
720
volatile : bool )
729
721
-> 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
-
735
722
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
- }
750
723
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 ( ) ) ;
754
730
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" )
757
733
} else {
758
- CodegenUnit :: mangle_name ( & cgu_name )
734
+ None
759
735
} ;
760
736
761
- Symbol :: intern ( & cgu_name [ .. ] ) . as_interned_str ( )
737
+ CodegenUnit :: build_cgu_name ( tcx , def_path . krate , components , volatile_suffix )
762
738
}
763
739
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) )
766
742
}
767
743
768
744
fn debug_dump < ' a , ' b , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments