@@ -80,6 +80,7 @@ use meth;
8080use mir;
8181use monomorphize:: { self , Instance } ;
8282use partitioning:: { self , PartitioningStrategy , CodegenUnit } ;
83+ use symbol_map:: SymbolMap ;
8384use symbol_names_test;
8485use trans_item:: TransItem ;
8586use tvec;
@@ -97,6 +98,7 @@ use libc::c_uint;
9798use std:: ffi:: { CStr , CString } ;
9899use std:: cell:: { Cell , RefCell } ;
99100use std:: collections:: { HashMap , HashSet } ;
101+ use std:: rc:: Rc ;
100102use std:: str;
101103use std:: { i8, i16, i32, i64} ;
102104use syntax:: codemap:: { Span , DUMMY_SP } ;
@@ -2595,14 +2597,18 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
25952597 } ;
25962598 let no_builtins = attr:: contains_name ( & krate. attrs , "no_builtins" ) ;
25972599
2598- let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
2600+ let ( codegen_units, symbol_map) =
2601+ collect_and_partition_translation_items ( & shared_ccx) ;
25992602 let codegen_unit_count = codegen_units. len ( ) ;
26002603
26012604 assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
26022605 tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
26032606
2604- let crate_context_list = CrateContextList :: new ( & shared_ccx , codegen_units ) ;
2607+ let symbol_map = Rc :: new ( symbol_map ) ;
26052608
2609+ let crate_context_list = CrateContextList :: new ( & shared_ccx,
2610+ codegen_units,
2611+ symbol_map. clone ( ) ) ;
26062612 let modules = crate_context_list. iter ( )
26072613 . map ( |ccx| ModuleTranslation {
26082614 name : String :: from ( & ccx. codegen_unit ( ) . name [ ..] ) ,
@@ -2700,8 +2706,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27002706 let sess = shared_ccx. sess ( ) ;
27012707 let mut reachable_symbols = shared_ccx. reachable ( ) . iter ( ) . map ( |& id| {
27022708 let def_id = shared_ccx. tcx ( ) . map . local_def_id ( id) ;
2703- Instance :: mono ( & shared_ccx, def_id ) . symbol_name ( & shared_ccx )
2709+ symbol_for_def_id ( def_id , & shared_ccx, & symbol_map )
27042710 } ) . collect :: < Vec < _ > > ( ) ;
2711+
27052712 if sess. entry_fn . borrow ( ) . is_some ( ) {
27062713 reachable_symbols. push ( "main" . to_string ( ) ) ;
27072714 }
@@ -2723,7 +2730,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27232730 reachable_symbols. extend ( syms. into_iter ( ) . filter ( |did| {
27242731 sess. cstore . is_extern_item ( shared_ccx. tcx ( ) , * did)
27252732 } ) . map ( |did| {
2726- Instance :: mono ( & shared_ccx, did ) . symbol_name ( & shared_ccx )
2733+ symbol_for_def_id ( did , & shared_ccx, & symbol_map )
27272734 } ) ) ;
27282735 }
27292736
@@ -2817,7 +2824,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TransItemsWithinModVisitor<'a, 'tcx> {
28172824}
28182825
28192826fn collect_and_partition_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > )
2820- -> Vec < CodegenUnit < ' tcx > > {
2827+ -> ( Vec < CodegenUnit < ' tcx > > , SymbolMap < ' tcx > ) {
28212828 let time_passes = scx. sess ( ) . time_passes ( ) ;
28222829
28232830 let collection_mode = match scx. sess ( ) . opts . debugging_opts . print_trans_items {
@@ -2840,10 +2847,13 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
28402847 None => TransItemCollectionMode :: Lazy
28412848 } ;
28422849
2843- let ( items, inlining_map) = time ( time_passes, "translation item collection" , || {
2844- collector:: collect_crate_translation_items ( & scx, collection_mode)
2850+ let ( items, inlining_map) =
2851+ time ( time_passes, "translation item collection" , || {
2852+ collector:: collect_crate_translation_items ( & scx, collection_mode)
28452853 } ) ;
28462854
2855+ let symbol_map = SymbolMap :: build ( scx, items. iter ( ) . cloned ( ) ) ;
2856+
28472857 let strategy = if scx. sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
28482858 PartitioningStrategy :: PerModule
28492859 } else {
@@ -2917,5 +2927,24 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
29172927 }
29182928 }
29192929
2920- codegen_units
2930+ ( codegen_units, symbol_map)
2931+ }
2932+
2933+ fn symbol_for_def_id < ' a , ' tcx > ( def_id : DefId ,
2934+ scx : & SharedCrateContext < ' a , ' tcx > ,
2935+ symbol_map : & SymbolMap < ' tcx > )
2936+ -> String {
2937+ // Just try to look things up in the symbol map. If nothing's there, we
2938+ // recompute.
2939+ if let Some ( node_id) = scx. tcx ( ) . map . as_local_node_id ( def_id) {
2940+ if let Some ( sym) = symbol_map. get ( TransItem :: Static ( node_id) ) {
2941+ return sym. to_owned ( ) ;
2942+ }
2943+ }
2944+
2945+ let instance = Instance :: mono ( scx, def_id) ;
2946+
2947+ symbol_map. get ( TransItem :: Fn ( instance) )
2948+ . map ( str:: to_owned)
2949+ . unwrap_or_else ( || instance. symbol_name ( scx) )
29212950}
0 commit comments