@@ -15,17 +15,17 @@ use monomorphize::Instance;
15
15
use rustc:: hir;
16
16
use rustc:: hir:: def_id:: CrateNum ;
17
17
use rustc:: hir:: def_id:: { DefId , LOCAL_CRATE } ;
18
- use rustc:: middle:: exported_symbols:: SymbolExportLevel ;
18
+ use rustc:: middle:: exported_symbols:: { SymbolExportLevel , ExportedSymbol } ;
19
19
use rustc:: session:: config;
20
- use rustc:: ty:: TyCtxt ;
20
+ use rustc:: ty:: { TyCtxt , SymbolName } ;
21
21
use rustc:: ty:: maps:: Providers ;
22
22
use rustc:: util:: nodemap:: { FxHashMap , DefIdSet } ;
23
23
use rustc_allocator:: ALLOCATOR_METHODS ;
24
24
use syntax:: attr;
25
25
26
26
pub type ExportedSymbols = FxHashMap <
27
27
CrateNum ,
28
- Arc < Vec < ( String , Option < DefId > , SymbolExportLevel ) > > ,
28
+ Arc < Vec < ( String , SymbolExportLevel ) > > ,
29
29
> ;
30
30
31
31
pub fn threshold ( tcx : TyCtxt ) -> SymbolExportLevel {
@@ -78,9 +78,10 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
78
78
let reachable_non_generics = tcx
79
79
. exported_symbols ( LOCAL_CRATE )
80
80
. 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) {
84
85
return Some ( def_id)
85
86
}
86
87
}
@@ -100,8 +101,7 @@ fn is_reachable_non_generic_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
100
101
101
102
fn exported_symbols_provider_local < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
102
103
cnum : CrateNum )
103
- -> Arc < Vec < ( String ,
104
- Option < DefId > ,
104
+ -> Arc < Vec < ( ExportedSymbol ,
105
105
SymbolExportLevel ) > >
106
106
{
107
107
assert_eq ! ( cnum, LOCAL_CRATE ) ;
@@ -176,34 +176,40 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
176
176
let mut symbols: Vec < _ > = reachable_non_generics
177
177
. iter ( )
178
178
. map ( |& def_id| {
179
- let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
180
179
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)
183
184
} )
184
185
. collect ( ) ;
185
186
186
187
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 ) ) ;
188
192
}
189
193
190
194
if tcx. sess . allocator_kind . get ( ) . is_some ( ) {
191
195
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 ) ) ;
195
200
}
196
201
}
197
202
198
203
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 ) ) ;
202
208
}
203
209
204
210
// 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 )
207
213
} ) ;
208
214
209
215
Arc :: new ( symbols)
@@ -218,8 +224,7 @@ pub fn provide(providers: &mut Providers) {
218
224
219
225
fn exported_symbols_provider_extern < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
220
226
cnum : CrateNum )
221
- -> Arc < Vec < ( String ,
222
- Option < DefId > ,
227
+ -> Arc < Vec < ( ExportedSymbol ,
223
228
SymbolExportLevel ) > >
224
229
{
225
230
// 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>,
243
248
. reachable_non_generics ( cnum)
244
249
. iter ( )
245
250
. map ( |& def_id| {
246
- let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
247
251
let export_level = if special_runtime_crate {
252
+ let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
248
253
// We can probably do better here by just ensuring that
249
254
// it has hidden visibility rather than public
250
255
// 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>,
262
267
} else {
263
268
tcx. symbol_export_level ( def_id)
264
269
} ;
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)
267
276
} )
268
277
. collect ( ) ;
269
278
270
279
// 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 )
273
282
} ) ;
274
283
275
284
Arc :: new ( crate_exports)
0 commit comments