@@ -65,7 +65,6 @@ use meth;
65
65
use mir;
66
66
use monomorphize:: { self , Instance } ;
67
67
use partitioning:: { self , PartitioningStrategy , CodegenUnit } ;
68
- use symbol_map:: SymbolMap ;
69
68
use symbol_names_test;
70
69
use trans_item:: { TransItem , DefPathBasedNames } ;
71
70
use type_:: Type ;
@@ -803,7 +802,6 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
803
802
scx : & SharedCrateContext < ' a , ' tcx > ,
804
803
translation_items : & FxHashSet < TransItem < ' tcx > > ,
805
804
llvm_modules : & [ ModuleLlvm ] ,
806
- symbol_map : & SymbolMap < ' tcx > ,
807
805
exported_symbols : & ExportedSymbols ) {
808
806
let export_threshold =
809
807
symbol_export:: crates_export_threshold ( & sess. crate_types . borrow ( ) ) ;
@@ -855,7 +853,7 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
855
853
let mut linkage_fixed_explicitly = FxHashSet ( ) ;
856
854
857
855
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 ) ) ;
859
857
if trans_item. explicit_linkage ( tcx) . is_some ( ) {
860
858
linkage_fixed_explicitly. insert ( symbol_name. clone ( ) ) ;
861
859
}
@@ -1109,7 +1107,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1109
1107
1110
1108
// Run the translation item collector and partition the collected items into
1111
1109
// codegen units.
1112
- let ( translation_items, codegen_units, symbol_map ) =
1110
+ let ( translation_items, codegen_units) =
1113
1111
collect_and_partition_translation_items ( & shared_ccx) ;
1114
1112
1115
1113
let mut all_stats = Stats :: default ( ) ;
@@ -1269,8 +1267,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1269
1267
1270
1268
let sess = shared_ccx. sess ( ) ;
1271
1269
1272
- let exported_symbols = ExportedSymbols :: compute_from ( & shared_ccx,
1273
- & symbol_map) ;
1270
+ let exported_symbols = ExportedSymbols :: compute ( & shared_ccx) ;
1274
1271
1275
1272
// Get the list of llvm modules we created. We'll do a few wacky
1276
1273
// transforms on them now.
@@ -1290,7 +1287,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1290
1287
& shared_ccx,
1291
1288
& translation_items,
1292
1289
& llvm_modules,
1293
- & symbol_map,
1294
1290
& exported_symbols) ;
1295
1291
} ) ;
1296
1292
@@ -1516,10 +1512,57 @@ fn gather_type_sizes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
1516
1512
}
1517
1513
}
1518
1514
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
+
1519
1563
fn collect_and_partition_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > )
1520
1564
-> ( FxHashSet < TransItem < ' tcx > > ,
1521
- Vec < CodegenUnit < ' tcx > > ,
1522
- SymbolMap < ' tcx > ) {
1565
+ Vec < CodegenUnit < ' tcx > > ) {
1523
1566
let time_passes = scx. sess ( ) . time_passes ( ) ;
1524
1567
1525
1568
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
1547
1590
collector:: collect_crate_translation_items ( & scx, collection_mode)
1548
1591
} ) ;
1549
1592
1550
- let symbol_map = SymbolMap :: build ( scx, items. iter ( ) . cloned ( ) ) ;
1593
+ assert_symbols_are_distinct ( scx. tcx ( ) , items. iter ( ) ) ;
1551
1594
1552
1595
let strategy = if scx. sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
1553
1596
PartitioningStrategy :: PerModule
@@ -1620,5 +1663,5 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
1620
1663
}
1621
1664
}
1622
1665
1623
- ( translation_items, codegen_units, symbol_map )
1666
+ ( translation_items, codegen_units)
1624
1667
}
0 commit comments