@@ -936,26 +936,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
936936 return true ;
937937 }
938938
939- if tcx. is_reachable_non_generic ( def_id)
940- || instance. polymorphize ( * tcx) . upstream_monomorphization ( * tcx) . is_some ( )
941- {
942- // We can link to the item in question, no instance needed in this crate.
943- return false ;
944- }
945-
946- if let DefKind :: Static { .. } = tcx. def_kind ( def_id) {
947- // We cannot monomorphize statics from upstream crates.
948- return false ;
949- }
950-
951- if !tcx. is_mir_available ( def_id) {
952- tcx. dcx ( ) . emit_fatal ( NoOptimizedMir {
953- span : tcx. def_span ( def_id) ,
954- crate_name : tcx. crate_name ( def_id. krate ) ,
955- } ) ;
956- }
957-
958- true
939+ tcx. should_codegen_locally_slow ( instance)
959940}
960941
961942/// For a given pair of source and target type that occur in an unsizing coercion,
@@ -1596,4 +1577,27 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
15961577
15971578pub ( crate ) fn provide ( providers : & mut Providers ) {
15981579 providers. hooks . should_codegen_locally = should_codegen_locally;
1580+ providers. should_codegen_locally_slow = |tcx, instance| {
1581+ let def_id = instance. def_id ( ) ;
1582+ if let DefKind :: Static { .. } = tcx. def_kind ( def_id) {
1583+ // We cannot monomorphize statics from upstream crates.
1584+ return false ;
1585+ }
1586+
1587+ if tcx. is_reachable_non_generic ( def_id)
1588+ || instance. polymorphize ( tcx) . upstream_monomorphization ( tcx) . is_some ( )
1589+ {
1590+ // We can link to the item in question, no instance needed in this crate.
1591+ return false ;
1592+ }
1593+
1594+ if !tcx. is_mir_available ( def_id) {
1595+ tcx. dcx ( ) . emit_fatal ( NoOptimizedMir {
1596+ span : tcx. def_span ( def_id) ,
1597+ crate_name : tcx. crate_name ( def_id. krate ) ,
1598+ } ) ;
1599+ }
1600+
1601+ true
1602+ } ;
15991603}
0 commit comments