@@ -164,7 +164,8 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
164
164
tcx. reachable_non_generics ( def_id. krate ) . contains_key ( & def_id)
165
165
}
166
166
167
- fn exported_symbols_provider_local < ' tcx > (
167
+ // FIXME maybe split into two functions
168
+ fn exported_symbols_provider_local < ' tcx , const GENERIC : bool > (
168
169
tcx : TyCtxt < ' tcx > ,
169
170
_: LocalCrate ,
170
171
) -> & ' tcx [ ( ExportedSymbol < ' tcx > , SymbolExportInfo ) ] {
@@ -174,9 +175,13 @@ fn exported_symbols_provider_local<'tcx>(
174
175
175
176
// FIXME: Sorting this is unnecessary since we are sorting later anyway.
176
177
// Can we skip the later sorting?
177
- let sorted = tcx. with_stable_hashing_context ( |hcx| {
178
- tcx. reachable_non_generics ( LOCAL_CRATE ) . to_sorted ( & hcx, true )
179
- } ) ;
178
+ let sorted = if GENERIC {
179
+ vec ! [ ]
180
+ } else {
181
+ tcx. with_stable_hashing_context ( |hcx| {
182
+ tcx. reachable_non_generics ( LOCAL_CRATE ) . to_sorted ( & hcx, true )
183
+ } )
184
+ } ;
180
185
181
186
let mut symbols: Vec < _ > =
182
187
sorted. iter ( ) . map ( |& ( & def_id, & info) | ( ExportedSymbol :: NonGeneric ( def_id) , info) ) . collect ( ) ;
@@ -197,7 +202,7 @@ fn exported_symbols_provider_local<'tcx>(
197
202
} ) )
198
203
}
199
204
200
- if tcx. entry_fn ( ( ) ) . is_some ( ) {
205
+ if ! GENERIC && tcx. entry_fn ( ( ) ) . is_some ( ) {
201
206
let exported_symbol =
202
207
ExportedSymbol :: NoDefId ( SymbolName :: new ( tcx, tcx. sess . target . entry_name . as_ref ( ) ) ) ;
203
208
@@ -212,7 +217,7 @@ fn exported_symbols_provider_local<'tcx>(
212
217
}
213
218
214
219
// Mark allocator shim symbols as exported only if they were generated.
215
- if allocator_kind_for_codegen ( tcx) . is_some ( ) {
220
+ if ! GENERIC && allocator_kind_for_codegen ( tcx) . is_some ( ) {
216
221
for symbol_name in ALLOCATOR_METHODS
217
222
. iter ( )
218
223
. map ( |method| mangle_internal_symbol ( tcx, global_fn_name ( method. name ) . as_str ( ) ) )
@@ -235,7 +240,7 @@ fn exported_symbols_provider_local<'tcx>(
235
240
}
236
241
}
237
242
238
- if tcx. sess . instrument_coverage ( ) || tcx. sess . opts . cg . profile_generate . enabled ( ) {
243
+ if ! GENERIC && tcx. sess . instrument_coverage ( ) || tcx. sess . opts . cg . profile_generate . enabled ( ) {
239
244
// These are weak symbols that point to the profile version and the
240
245
// profile name, which need to be treated as exported so LTO doesn't nix
241
246
// them.
@@ -255,7 +260,7 @@ fn exported_symbols_provider_local<'tcx>(
255
260
} ) ) ;
256
261
}
257
262
258
- if tcx. sess . opts . unstable_opts . sanitizer . contains ( SanitizerSet :: MEMORY ) {
263
+ if ! GENERIC && tcx. sess . opts . unstable_opts . sanitizer . contains ( SanitizerSet :: MEMORY ) {
259
264
let mut msan_weak_symbols = Vec :: new ( ) ;
260
265
261
266
// Similar to profiling, preserve weak msan symbol during LTO.
@@ -280,7 +285,7 @@ fn exported_symbols_provider_local<'tcx>(
280
285
} ) ) ;
281
286
}
282
287
283
- if tcx. crate_types ( ) . contains ( & CrateType :: Dylib )
288
+ if ! GENERIC && tcx. crate_types ( ) . contains ( & CrateType :: Dylib )
284
289
|| tcx. crate_types ( ) . contains ( & CrateType :: ProcMacro )
285
290
{
286
291
let symbol_name = metadata_symbol_name ( tcx) ;
@@ -296,7 +301,7 @@ fn exported_symbols_provider_local<'tcx>(
296
301
) ) ;
297
302
}
298
303
299
- if tcx. local_crate_exports_generics ( ) {
304
+ if GENERIC && tcx. local_crate_exports_generics ( ) {
300
305
use rustc_middle:: mir:: mono:: { Linkage , MonoItem , Visibility } ;
301
306
use rustc_middle:: ty:: InstanceKind ;
302
307
@@ -458,7 +463,7 @@ fn upstream_monomorphizations_provider(
458
463
let async_drop_in_place_fn_def_id = tcx. lang_items ( ) . async_drop_in_place_fn ( ) ;
459
464
460
465
for & cnum in cnums. iter ( ) {
461
- for ( exported_symbol, _) in tcx. exported_symbols ( cnum) . iter ( ) {
466
+ for ( exported_symbol, _) in tcx. exported_generic_symbols ( cnum) . iter ( ) {
462
467
let ( def_id, args) = match * exported_symbol {
463
468
ExportedSymbol :: Generic ( def_id, args) => ( def_id, args) ,
464
469
ExportedSymbol :: DropGlue ( ty) => {
@@ -480,10 +485,7 @@ fn upstream_monomorphizations_provider(
480
485
ExportedSymbol :: AsyncDropGlue ( def_id, ty) => ( def_id, tcx. mk_args ( & [ ty. into ( ) ] ) ) ,
481
486
ExportedSymbol :: NonGeneric ( ..)
482
487
| ExportedSymbol :: ThreadLocalShim ( ..)
483
- | ExportedSymbol :: NoDefId ( ..) => {
484
- // These are no monomorphizations
485
- continue ;
486
- }
488
+ | ExportedSymbol :: NoDefId ( ..) => unreachable ! ( ) ,
487
489
} ;
488
490
489
491
let args_map = instances. entry ( def_id) . or_default ( ) ;
@@ -538,7 +540,8 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId)
538
540
pub ( crate ) fn provide ( providers : & mut Providers ) {
539
541
providers. reachable_non_generics = reachable_non_generics_provider;
540
542
providers. is_reachable_non_generic = is_reachable_non_generic_provider_local;
541
- providers. exported_symbols = exported_symbols_provider_local;
543
+ providers. exported_non_generic_symbols = exported_symbols_provider_local :: < false > ;
544
+ providers. exported_generic_symbols = exported_symbols_provider_local :: < true > ;
542
545
providers. upstream_monomorphizations = upstream_monomorphizations_provider;
543
546
providers. is_unreachable_local_definition = is_unreachable_local_definition_provider;
544
547
providers. upstream_drop_glue_for = upstream_drop_glue_for_provider;
0 commit comments