@@ -15,17 +15,17 @@ use monomorphize::Instance;
1515use rustc:: hir;
1616use rustc:: hir:: def_id:: CrateNum ;
1717use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
18- use rustc:: middle:: exported_symbols:: SymbolExportLevel ;
18+ use rustc:: middle:: exported_symbols:: { SymbolExportLevel , ExportedSymbol } ;
1919use rustc:: session:: config;
20- use rustc:: ty:: TyCtxt ;
20+ use rustc:: ty:: { TyCtxt , SymbolName } ;
2121use rustc:: ty:: maps:: Providers ;
2222use rustc:: util:: nodemap:: { FxHashMap , DefIdSet } ;
2323use rustc_allocator:: ALLOCATOR_METHODS ;
2424use syntax:: attr;
2525
2626pub type ExportedSymbols = FxHashMap <
2727 CrateNum ,
28- Arc < Vec < ( String , Option < DefId > , SymbolExportLevel ) > > ,
28+ Arc < Vec < ( String , SymbolExportLevel ) > > ,
2929> ;
3030
3131pub fn threshold ( tcx : TyCtxt ) -> SymbolExportLevel {
@@ -78,9 +78,10 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7878 let reachable_non_generics = tcx
7979 . exported_symbols ( LOCAL_CRATE )
8080 . iter ( )
81- . filter_map ( |& ( _, opt_def_id, level) | {
82- if let Some ( def_id) = opt_def_id {
83- if level. is_below_threshold ( export_threshold) {
81+ . filter_map ( |& ( exported_symbol, _) | {
82+ if let ExportedSymbol :: NonGeneric ( def_id) = exported_symbol {
83+ if tcx. symbol_export_level ( def_id)
84+ . is_below_threshold ( export_threshold) {
8485 return Some ( def_id)
8586 }
8687 }
@@ -100,8 +101,7 @@ fn is_reachable_non_generic_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
100101
101102fn exported_symbols_provider_local < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
102103 cnum : CrateNum )
103- -> Arc < Vec < ( String ,
104- Option < DefId > ,
104+ -> Arc < Vec < ( ExportedSymbol ,
105105 SymbolExportLevel ) > >
106106{
107107 assert_eq ! ( cnum, LOCAL_CRATE ) ;
@@ -176,34 +176,40 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
176176 let mut symbols: Vec < _ > = reachable_non_generics
177177 . iter ( )
178178 . map ( |& def_id| {
179- let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
180179 let export_level = tcx. symbol_export_level ( def_id) ;
181- debug ! ( "EXPORTED SYMBOL (local): {} ({:?})" , name, export_level) ;
182- ( str:: to_owned ( & name) , Some ( def_id) , export_level)
180+ debug ! ( "EXPORTED SYMBOL (local): {} ({:?})" ,
181+ tcx. symbol_name( Instance :: mono( tcx, def_id) ) ,
182+ export_level) ;
183+ ( ExportedSymbol :: NonGeneric ( def_id) , export_level)
183184 } )
184185 . collect ( ) ;
185186
186187 if let Some ( _) = * tcx. sess . entry_fn . borrow ( ) {
187- symbols. push ( ( "main" . to_string ( ) , None , SymbolExportLevel :: C ) ) ;
188+ let symbol_name = "main" . to_string ( ) ;
189+ let exported_symbol = ExportedSymbol :: NoDefId ( SymbolName :: new ( & symbol_name) ) ;
190+
191+ symbols. push ( ( exported_symbol, SymbolExportLevel :: C ) ) ;
188192 }
189193
190194 if tcx. sess . allocator_kind . get ( ) . is_some ( ) {
191195 for method in ALLOCATOR_METHODS {
192- symbols. push ( ( format ! ( "__rust_{}" , method. name) ,
193- None ,
194- SymbolExportLevel :: Rust ) ) ;
196+ let symbol_name = format ! ( "__rust_{}" , method. name) ;
197+ let exported_symbol = ExportedSymbol :: NoDefId ( SymbolName :: new ( & symbol_name) ) ;
198+
199+ symbols. push ( ( exported_symbol, SymbolExportLevel :: Rust ) ) ;
195200 }
196201 }
197202
198203 if tcx. sess . crate_types . borrow ( ) . contains ( & config:: CrateTypeDylib ) {
199- symbols. push ( ( metadata_symbol_name ( tcx) ,
200- None ,
201- SymbolExportLevel :: Rust ) ) ;
204+ let symbol_name = metadata_symbol_name ( tcx) ;
205+ let exported_symbol = ExportedSymbol :: NoDefId ( SymbolName :: new ( & symbol_name) ) ;
206+
207+ symbols. push ( ( exported_symbol, SymbolExportLevel :: Rust ) ) ;
202208 }
203209
204210 // Sort so we get a stable incr. comp. hash.
205- symbols. sort_unstable_by ( |& ( ref name1 , ..) , & ( ref name2 , ..) | {
206- name1 . cmp ( name2 )
211+ symbols. sort_unstable_by ( |& ( ref symbol1 , ..) , & ( ref symbol2 , ..) | {
212+ symbol1 . compare_stable ( tcx , symbol2 )
207213 } ) ;
208214
209215 Arc :: new ( symbols)
@@ -218,8 +224,7 @@ pub fn provide(providers: &mut Providers) {
218224
219225fn exported_symbols_provider_extern < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
220226 cnum : CrateNum )
221- -> Arc < Vec < ( String ,
222- Option < DefId > ,
227+ -> Arc < Vec < ( ExportedSymbol ,
223228 SymbolExportLevel ) > >
224229{
225230 // If this crate is a plugin and/or a custom derive crate, then
@@ -243,8 +248,8 @@ fn exported_symbols_provider_extern<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
243248 . reachable_non_generics ( cnum)
244249 . iter ( )
245250 . map ( |& def_id| {
246- let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
247251 let export_level = if special_runtime_crate {
252+ let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
248253 // We can probably do better here by just ensuring that
249254 // it has hidden visibility rather than public
250255 // visibility, as this is primarily here to ensure it's
@@ -262,14 +267,18 @@ fn exported_symbols_provider_extern<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
262267 } else {
263268 tcx. symbol_export_level ( def_id)
264269 } ;
265- debug ! ( "EXPORTED SYMBOL (re-export): {} ({:?})" , name, export_level) ;
266- ( str:: to_owned ( & name) , Some ( def_id) , export_level)
270+
271+ debug ! ( "EXPORTED SYMBOL (re-export): {} ({:?})" ,
272+ tcx. symbol_name( Instance :: mono( tcx, def_id) ) ,
273+ export_level) ;
274+
275+ ( ExportedSymbol :: NonGeneric ( def_id) , export_level)
267276 } )
268277 . collect ( ) ;
269278
270279 // Sort so we get a stable incr. comp. hash.
271- crate_exports. sort_unstable_by ( |& ( ref name1 , ..) , & ( ref name2 , ..) | {
272- name1 . cmp ( name2 )
280+ crate_exports. sort_unstable_by ( |& ( ref symbol1 , ..) , & ( ref symbol2 , ..) | {
281+ symbol1 . compare_stable ( tcx , symbol2 )
273282 } ) ;
274283
275284 Arc :: new ( crate_exports)
0 commit comments