@@ -12,7 +12,7 @@ use std::{env, mem, str};
12
12
13
13
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
14
14
use rustc_middle:: middle:: dependency_format:: Linkage ;
15
- use rustc_middle:: middle:: exported_symbols:: SymbolExportKind ;
15
+ use rustc_middle:: middle:: exported_symbols:: { ExportedSymbol , SymbolExportInfo , SymbolExportKind } ;
16
16
use rustc_middle:: ty:: TyCtxt ;
17
17
use rustc_serialize:: { json, Encoder } ;
18
18
use rustc_session:: config:: { self , CrateType , DebugInfo , LinkerPluginLto , Lto , OptLevel , Strip } ;
@@ -1519,22 +1519,13 @@ impl<'a> L4Bender<'a> {
1519
1519
}
1520
1520
}
1521
1521
1522
- pub ( crate ) fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1523
- if let Some ( ref exports) = tcx. sess . target . override_export_symbols {
1524
- return exports. clone ( ) ;
1525
- }
1526
-
1527
- let mut symbols = Vec :: new ( ) ;
1528
-
1529
- let export_threshold = symbol_export:: crates_export_threshold ( & [ crate_type] ) ;
1522
+ fn for_each_exported_symbols_include_dep < ' tcx > (
1523
+ tcx : TyCtxt < ' tcx > ,
1524
+ crate_type : CrateType ,
1525
+ mut callback : impl FnMut ( ExportedSymbol < ' tcx > , SymbolExportInfo , CrateNum ) ,
1526
+ ) {
1530
1527
for & ( symbol, info) in tcx. exported_symbols ( LOCAL_CRATE ) . iter ( ) {
1531
- if info. level . is_below_threshold ( export_threshold) {
1532
- symbols. push ( symbol_export:: symbol_name_for_instance_in_crate (
1533
- tcx,
1534
- symbol,
1535
- LOCAL_CRATE ,
1536
- ) ) ;
1537
- }
1528
+ callback ( symbol, info, LOCAL_CRATE ) ;
1538
1529
}
1539
1530
1540
1531
let formats = tcx. dependency_formats ( ( ) ) ;
@@ -1544,16 +1535,26 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
1544
1535
let cnum = CrateNum :: new ( index + 1 ) ;
1545
1536
// For each dependency that we are linking to statically ...
1546
1537
if * dep_format == Linkage :: Static {
1547
- // ... we add its symbol list to our export list.
1548
1538
for & ( symbol, info) in tcx. exported_symbols ( cnum) . iter ( ) {
1549
- if !info. level . is_below_threshold ( export_threshold) {
1550
- continue ;
1551
- }
1552
-
1553
- symbols. push ( symbol_export:: symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ) ;
1539
+ callback ( symbol, info, cnum) ;
1554
1540
}
1555
1541
}
1556
1542
}
1543
+ }
1544
+
1545
+ pub ( crate ) fn exported_symbols ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1546
+ if let Some ( ref exports) = tcx. sess . target . override_export_symbols {
1547
+ return exports. clone ( ) ;
1548
+ }
1549
+
1550
+ let mut symbols = Vec :: new ( ) ;
1551
+
1552
+ let export_threshold = symbol_export:: crates_export_threshold ( & [ crate_type] ) ;
1553
+ for_each_exported_symbols_include_dep ( tcx, crate_type, |symbol, info, cnum| {
1554
+ if info. level . is_below_threshold ( export_threshold) {
1555
+ symbols. push ( symbol_export:: symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ) ;
1556
+ }
1557
+ } ) ;
1557
1558
1558
1559
symbols
1559
1560
}
@@ -1572,33 +1573,14 @@ pub(crate) fn linked_symbols(
1572
1573
let mut symbols = Vec :: new ( ) ;
1573
1574
1574
1575
let export_threshold = symbol_export:: crates_export_threshold ( & [ crate_type] ) ;
1575
- for & ( symbol, info) in tcx . exported_symbols ( LOCAL_CRATE ) . iter ( ) {
1576
+ for_each_exported_symbols_include_dep ( tcx , crate_type , | symbol, info, cnum| {
1576
1577
if info. level . is_below_threshold ( export_threshold) || info. used {
1577
1578
symbols. push ( (
1578
- symbol_export:: symbol_name_for_instance_in_crate ( tcx, symbol, LOCAL_CRATE ) ,
1579
+ symbol_export:: symbol_name_for_instance_in_crate ( tcx, symbol, cnum ) ,
1579
1580
info. kind ,
1580
1581
) ) ;
1581
1582
}
1582
- }
1583
-
1584
- let formats = tcx. dependency_formats ( ( ) ) ;
1585
- let deps = formats. iter ( ) . find_map ( |( t, list) | ( * t == crate_type) . then_some ( list) ) . unwrap ( ) ;
1586
-
1587
- for ( index, dep_format) in deps. iter ( ) . enumerate ( ) {
1588
- let cnum = CrateNum :: new ( index + 1 ) ;
1589
- // For each dependency that we are linking to statically ...
1590
- if * dep_format == Linkage :: Static {
1591
- // ... we add its symbol list to our export list.
1592
- for & ( symbol, info) in tcx. exported_symbols ( cnum) . iter ( ) {
1593
- if info. level . is_below_threshold ( export_threshold) || info. used {
1594
- symbols. push ( (
1595
- symbol_export:: symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ,
1596
- info. kind ,
1597
- ) ) ;
1598
- }
1599
- }
1600
- }
1601
- }
1583
+ } ) ;
1602
1584
1603
1585
symbols
1604
1586
}
0 commit comments