@@ -65,7 +65,6 @@ use meth;
6565use mir;
6666use monomorphize:: { self , Instance } ;
6767use partitioning:: { self , PartitioningStrategy , CodegenUnit } ;
68- use symbol_map:: SymbolMap ;
6968use symbol_names_test;
7069use trans_item:: { TransItem , DefPathBasedNames } ;
7170use type_:: Type ;
@@ -803,7 +802,6 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
803802 scx : & SharedCrateContext < ' a , ' tcx > ,
804803 translation_items : & FxHashSet < TransItem < ' tcx > > ,
805804 llvm_modules : & [ ModuleLlvm ] ,
806- symbol_map : & SymbolMap < ' tcx > ,
807805 exported_symbols : & ExportedSymbols ) {
808806 let export_threshold =
809807 symbol_export:: crates_export_threshold ( & sess. crate_types . borrow ( ) ) ;
@@ -855,7 +853,7 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
855853 let mut linkage_fixed_explicitly = FxHashSet ( ) ;
856854
857855 for trans_item in translation_items {
858- let symbol_name = symbol_map . get_or_compute ( scx , * trans_item) ;
856+ let symbol_name = str :: to_owned ( & trans_item. symbol_name ( tcx ) ) ;
859857 if trans_item. explicit_linkage ( tcx) . is_some ( ) {
860858 linkage_fixed_explicitly. insert ( symbol_name. clone ( ) ) ;
861859 }
@@ -1109,7 +1107,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11091107
11101108 // Run the translation item collector and partition the collected items into
11111109 // codegen units.
1112- let ( translation_items, codegen_units, symbol_map ) =
1110+ let ( translation_items, codegen_units) =
11131111 collect_and_partition_translation_items ( & shared_ccx) ;
11141112
11151113 let mut all_stats = Stats :: default ( ) ;
@@ -1269,8 +1267,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12691267
12701268 let sess = shared_ccx. sess ( ) ;
12711269
1272- let exported_symbols = ExportedSymbols :: compute_from ( & shared_ccx,
1273- & symbol_map) ;
1270+ let exported_symbols = ExportedSymbols :: compute ( & shared_ccx) ;
12741271
12751272 // Get the list of llvm modules we created. We'll do a few wacky
12761273 // transforms on them now.
@@ -1290,7 +1287,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12901287 & shared_ccx,
12911288 & translation_items,
12921289 & llvm_modules,
1293- & symbol_map,
12941290 & exported_symbols) ;
12951291 } ) ;
12961292
@@ -1516,10 +1512,57 @@ fn gather_type_sizes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
15161512 }
15171513}
15181514
1515+ #[ inline( never) ] // give this a place in the profiler
1516+ fn assert_symbols_are_distinct < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , trans_items : I )
1517+ where I : Iterator < Item =& ' a TransItem < ' tcx > >
1518+ {
1519+ let mut symbols: Vec < _ > = trans_items. map ( |trans_item| {
1520+ ( trans_item, trans_item. symbol_name ( tcx) )
1521+ } ) . collect ( ) ;
1522+
1523+ ( & mut symbols[ ..] ) . sort_by ( |& ( _, ref sym1) , & ( _, ref sym2) |{
1524+ sym1. cmp ( sym2)
1525+ } ) ;
1526+
1527+ for pair in ( & symbols[ ..] ) . windows ( 2 ) {
1528+ let sym1 = & pair[ 0 ] . 1 ;
1529+ let sym2 = & pair[ 1 ] . 1 ;
1530+
1531+ if * sym1 == * sym2 {
1532+ let trans_item1 = pair[ 0 ] . 0 ;
1533+ let trans_item2 = pair[ 1 ] . 0 ;
1534+
1535+ let span1 = trans_item1. local_span ( tcx) ;
1536+ let span2 = trans_item2. local_span ( tcx) ;
1537+
1538+ // Deterministically select one of the spans for error reporting
1539+ let span = match ( span1, span2) {
1540+ ( Some ( span1) , Some ( span2) ) => {
1541+ Some ( if span1. lo . 0 > span2. lo . 0 {
1542+ span1
1543+ } else {
1544+ span2
1545+ } )
1546+ }
1547+ ( Some ( span) , None ) |
1548+ ( None , Some ( span) ) => Some ( span) ,
1549+ _ => None
1550+ } ;
1551+
1552+ let error_message = format ! ( "symbol `{}` is already defined" , sym1) ;
1553+
1554+ if let Some ( span) = span {
1555+ tcx. sess . span_fatal ( span, & error_message)
1556+ } else {
1557+ tcx. sess . fatal ( & error_message)
1558+ }
1559+ }
1560+ }
1561+ }
1562+
15191563fn collect_and_partition_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > )
15201564 -> ( FxHashSet < TransItem < ' tcx > > ,
1521- Vec < CodegenUnit < ' tcx > > ,
1522- SymbolMap < ' tcx > ) {
1565+ Vec < CodegenUnit < ' tcx > > ) {
15231566 let time_passes = scx. sess ( ) . time_passes ( ) ;
15241567
15251568 let collection_mode = match scx. sess ( ) . opts . debugging_opts . print_trans_items {
@@ -1547,7 +1590,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
15471590 collector:: collect_crate_translation_items ( & scx, collection_mode)
15481591 } ) ;
15491592
1550- let symbol_map = SymbolMap :: build ( scx, items. iter ( ) . cloned ( ) ) ;
1593+ assert_symbols_are_distinct ( scx. tcx ( ) , items. iter ( ) ) ;
15511594
15521595 let strategy = if scx. sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
15531596 PartitioningStrategy :: PerModule
@@ -1620,5 +1663,5 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
16201663 }
16211664 }
16221665
1623- ( translation_items, codegen_units, symbol_map )
1666+ ( translation_items, codegen_units)
16241667}
0 commit comments