@@ -20,7 +20,7 @@ use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol, metadat
20
20
use rustc:: session:: config;
21
21
use rustc:: ty:: { TyCtxt , SymbolName } ;
22
22
use rustc:: ty:: maps:: Providers ;
23
- use rustc:: util:: nodemap:: { FxHashMap , DefIdSet } ;
23
+ use rustc:: util:: nodemap:: { FxHashMap , DefIdMap } ;
24
24
use rustc_allocator:: ALLOCATOR_METHODS ;
25
25
26
26
pub type ExportedSymbols = FxHashMap <
@@ -56,51 +56,12 @@ pub fn crates_export_threshold(crate_types: &[config::CrateType])
56
56
57
57
fn reachable_non_generics_provider < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
58
58
cnum : CrateNum )
59
- -> Lrc < DefIdSet >
59
+ -> Lrc < DefIdMap < SymbolExportLevel > >
60
60
{
61
61
assert_eq ! ( cnum, LOCAL_CRATE ) ;
62
62
63
63
if !tcx. sess . opts . output_types . should_trans ( ) {
64
- return Lrc :: new ( DefIdSet ( ) )
65
- }
66
-
67
- let export_threshold = threshold ( tcx) ;
68
-
69
- // We already collect all potentially reachable non-generic items for
70
- // `exported_symbols`. Now we just filter them down to what is actually
71
- // exported for the given crate we are compiling.
72
- let reachable_non_generics = tcx
73
- . exported_symbols ( LOCAL_CRATE )
74
- . iter ( )
75
- . filter_map ( |& ( exported_symbol, level) | {
76
- if let ExportedSymbol :: NonGeneric ( def_id) = exported_symbol {
77
- if level. is_below_threshold ( export_threshold) {
78
- return Some ( def_id)
79
- }
80
- }
81
-
82
- None
83
- } )
84
- . collect ( ) ;
85
-
86
- Lrc :: new ( reachable_non_generics)
87
- }
88
-
89
- fn is_reachable_non_generic_provider < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
90
- def_id : DefId )
91
- -> bool {
92
- tcx. reachable_non_generics ( def_id. krate ) . contains ( & def_id)
93
- }
94
-
95
- fn exported_symbols_provider_local < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
96
- cnum : CrateNum )
97
- -> Arc < Vec < ( ExportedSymbol < ' tcx > ,
98
- SymbolExportLevel ) > >
99
- {
100
- assert_eq ! ( cnum, LOCAL_CRATE ) ;
101
-
102
- if !tcx. sess . opts . output_types . should_trans ( ) {
103
- return Arc :: new ( vec ! [ ] )
64
+ return Lrc :: new ( DefIdMap ( ) )
104
65
}
105
66
106
67
// Check to see if this crate is a "special runtime crate". These
@@ -113,7 +74,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
113
74
let special_runtime_crate = tcx. is_panic_runtime ( LOCAL_CRATE ) ||
114
75
tcx. is_compiler_builtins ( LOCAL_CRATE ) ;
115
76
116
- let reachable_non_generics: DefIdSet = tcx. reachable_set ( LOCAL_CRATE ) . 0
77
+ let mut reachable_non_generics: DefIdMap < _ > = tcx. reachable_set ( LOCAL_CRATE ) . 0
117
78
. iter ( )
118
79
. filter_map ( |& node_id| {
119
80
// We want to ignore some FFI functions that are not exposed from
@@ -166,11 +127,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
166
127
_ => None
167
128
}
168
129
} )
169
- . collect ( ) ;
170
-
171
- let mut symbols: Vec < _ > = reachable_non_generics
172
- . iter ( )
173
- . map ( |& def_id| {
130
+ . map ( |def_id| {
174
131
let export_level = if special_runtime_crate {
175
132
let name = tcx. symbol_name ( Instance :: mono ( tcx, def_id) ) ;
176
133
// We can probably do better here by just ensuring that
@@ -193,20 +150,59 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
193
150
debug ! ( "EXPORTED SYMBOL (local): {} ({:?})" ,
194
151
tcx. symbol_name( Instance :: mono( tcx, def_id) ) ,
195
152
export_level) ;
196
- ( ExportedSymbol :: NonGeneric ( def_id) , export_level)
153
+ ( def_id, export_level)
197
154
} )
198
155
. collect ( ) ;
199
156
200
157
if let Some ( id) = tcx. sess . derive_registrar_fn . get ( ) {
201
158
let def_id = tcx. hir . local_def_id ( id) ;
202
- symbols . push ( ( ExportedSymbol :: NonGeneric ( def_id) , SymbolExportLevel :: C ) ) ;
159
+ reachable_non_generics . insert ( def_id, SymbolExportLevel :: C ) ;
203
160
}
204
161
205
162
if let Some ( id) = tcx. sess . plugin_registrar_fn . get ( ) {
206
163
let def_id = tcx. hir . local_def_id ( id) ;
207
- symbols . push ( ( ExportedSymbol :: NonGeneric ( def_id) , SymbolExportLevel :: C ) ) ;
164
+ reachable_non_generics . insert ( def_id, SymbolExportLevel :: C ) ;
208
165
}
209
166
167
+ Lrc :: new ( reachable_non_generics)
168
+ }
169
+
170
+ fn is_reachable_non_generic_provider_local < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
171
+ def_id : DefId )
172
+ -> bool {
173
+ let export_threshold = threshold ( tcx) ;
174
+
175
+ if let Some ( & level) = tcx. reachable_non_generics ( def_id. krate ) . get ( & def_id) {
176
+ level. is_below_threshold ( export_threshold)
177
+ } else {
178
+ false
179
+ }
180
+ }
181
+
182
+ fn is_reachable_non_generic_provider_extern < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
183
+ def_id : DefId )
184
+ -> bool {
185
+ tcx. reachable_non_generics ( def_id. krate ) . contains_key ( & def_id)
186
+ }
187
+
188
+ fn exported_symbols_provider_local < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
189
+ cnum : CrateNum )
190
+ -> Arc < Vec < ( ExportedSymbol < ' tcx > ,
191
+ SymbolExportLevel ) > >
192
+ {
193
+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
194
+
195
+ if !tcx. sess . opts . output_types . should_trans ( ) {
196
+ return Arc :: new ( vec ! [ ] )
197
+ }
198
+
199
+ let mut symbols: Vec < _ > = tcx. reachable_non_generics ( LOCAL_CRATE )
200
+ . iter ( )
201
+ . map ( |( & def_id, & level) | {
202
+ ( ExportedSymbol :: NonGeneric ( def_id) , level)
203
+ } )
204
+ . collect ( ) ;
205
+
210
206
if let Some ( _) = * tcx. sess . entry_fn . borrow ( ) {
211
207
let symbol_name = "main" . to_string ( ) ;
212
208
let exported_symbol = ExportedSymbol :: NoDefId ( SymbolName :: new ( & symbol_name) ) ;
@@ -240,13 +236,13 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
240
236
241
237
pub fn provide ( providers : & mut Providers ) {
242
238
providers. reachable_non_generics = reachable_non_generics_provider;
243
- providers. is_reachable_non_generic = is_reachable_non_generic_provider ;
239
+ providers. is_reachable_non_generic = is_reachable_non_generic_provider_local ;
244
240
providers. exported_symbols = exported_symbols_provider_local;
245
241
providers. symbol_export_level = symbol_export_level_provider;
246
242
}
247
243
248
244
pub fn provide_extern ( providers : & mut Providers ) {
249
- providers. is_reachable_non_generic = is_reachable_non_generic_provider ;
245
+ providers. is_reachable_non_generic = is_reachable_non_generic_provider_extern ;
250
246
providers. symbol_export_level = symbol_export_level_provider;
251
247
}
252
248
0 commit comments