@@ -164,7 +164,8 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
164164 tcx. reachable_non_generics ( def_id. krate ) . contains_key ( & def_id)
165165}
166166
167- fn exported_symbols_provider_local < ' tcx > (
167+ // FIXME maybe split into two functions
168+ fn exported_symbols_provider_local < ' tcx , const GENERIC : bool > (
168169 tcx : TyCtxt < ' tcx > ,
169170 _: LocalCrate ,
170171) -> & ' tcx [ ( ExportedSymbol < ' tcx > , SymbolExportInfo ) ] {
@@ -174,9 +175,13 @@ fn exported_symbols_provider_local<'tcx>(
174175
175176 // FIXME: Sorting this is unnecessary since we are sorting later anyway.
176177 // 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+ } ;
180185
181186 let mut symbols: Vec < _ > =
182187 sorted. iter ( ) . map ( |& ( & def_id, & info) | ( ExportedSymbol :: NonGeneric ( def_id) , info) ) . collect ( ) ;
@@ -197,7 +202,7 @@ fn exported_symbols_provider_local<'tcx>(
197202 } ) )
198203 }
199204
200- if tcx. entry_fn ( ( ) ) . is_some ( ) {
205+ if ! GENERIC && tcx. entry_fn ( ( ) ) . is_some ( ) {
201206 let exported_symbol =
202207 ExportedSymbol :: NoDefId ( SymbolName :: new ( tcx, tcx. sess . target . entry_name . as_ref ( ) ) ) ;
203208
@@ -212,7 +217,7 @@ fn exported_symbols_provider_local<'tcx>(
212217 }
213218
214219 // 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 ( ) {
216221 for symbol_name in ALLOCATOR_METHODS
217222 . iter ( )
218223 . map ( |method| mangle_internal_symbol ( tcx, global_fn_name ( method. name ) . as_str ( ) ) )
@@ -235,7 +240,7 @@ fn exported_symbols_provider_local<'tcx>(
235240 }
236241 }
237242
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 ( ) {
239244 // These are weak symbols that point to the profile version and the
240245 // profile name, which need to be treated as exported so LTO doesn't nix
241246 // them.
@@ -255,7 +260,7 @@ fn exported_symbols_provider_local<'tcx>(
255260 } ) ) ;
256261 }
257262
258- if tcx. sess . opts . unstable_opts . sanitizer . contains ( SanitizerSet :: MEMORY ) {
263+ if ! GENERIC && tcx. sess . opts . unstable_opts . sanitizer . contains ( SanitizerSet :: MEMORY ) {
259264 let mut msan_weak_symbols = Vec :: new ( ) ;
260265
261266 // Similar to profiling, preserve weak msan symbol during LTO.
@@ -280,7 +285,7 @@ fn exported_symbols_provider_local<'tcx>(
280285 } ) ) ;
281286 }
282287
283- if tcx. crate_types ( ) . contains ( & CrateType :: Dylib )
288+ if ! GENERIC && tcx. crate_types ( ) . contains ( & CrateType :: Dylib )
284289 || tcx. crate_types ( ) . contains ( & CrateType :: ProcMacro )
285290 {
286291 let symbol_name = metadata_symbol_name ( tcx) ;
@@ -296,7 +301,7 @@ fn exported_symbols_provider_local<'tcx>(
296301 ) ) ;
297302 }
298303
299- if tcx. local_crate_exports_generics ( ) {
304+ if GENERIC && tcx. local_crate_exports_generics ( ) {
300305 use rustc_middle:: mir:: mono:: { Linkage , MonoItem , Visibility } ;
301306 use rustc_middle:: ty:: InstanceKind ;
302307
@@ -458,7 +463,7 @@ fn upstream_monomorphizations_provider(
458463 let async_drop_in_place_fn_def_id = tcx. lang_items ( ) . async_drop_in_place_fn ( ) ;
459464
460465 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 ( ) {
462467 let ( def_id, args) = match * exported_symbol {
463468 ExportedSymbol :: Generic ( def_id, args) => ( def_id, args) ,
464469 ExportedSymbol :: DropGlue ( ty) => {
@@ -480,10 +485,7 @@ fn upstream_monomorphizations_provider(
480485 ExportedSymbol :: AsyncDropGlue ( def_id, ty) => ( def_id, tcx. mk_args ( & [ ty. into ( ) ] ) ) ,
481486 ExportedSymbol :: NonGeneric ( ..)
482487 | ExportedSymbol :: ThreadLocalShim ( ..)
483- | ExportedSymbol :: NoDefId ( ..) => {
484- // These are no monomorphizations
485- continue ;
486- }
488+ | ExportedSymbol :: NoDefId ( ..) => unreachable ! ( ) ,
487489 } ;
488490
489491 let args_map = instances. entry ( def_id) . or_default ( ) ;
@@ -538,7 +540,8 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId)
538540pub ( crate ) fn provide ( providers : & mut Providers ) {
539541 providers. reachable_non_generics = reachable_non_generics_provider;
540542 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 > ;
542545 providers. upstream_monomorphizations = upstream_monomorphizations_provider;
543546 providers. is_unreachable_local_definition = is_unreachable_local_definition_provider;
544547 providers. upstream_drop_glue_for = upstream_drop_glue_for_provider;
0 commit comments