@@ -955,26 +955,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
955955 return true ;
956956 }
957957
958- if tcx. is_reachable_non_generic ( def_id)
959- || instance. polymorphize ( * tcx) . upstream_monomorphization ( * tcx) . is_some ( )
960- {
961- // We can link to the item in question, no instance needed in this crate.
962- return false ;
963- }
964-
965- if let DefKind :: Static { .. } = tcx. def_kind ( def_id) {
966- // We cannot monomorphize statics from upstream crates.
967- return false ;
968- }
969-
970- if !tcx. is_mir_available ( def_id) {
971- tcx. dcx ( ) . emit_fatal ( NoOptimizedMir {
972- span : tcx. def_span ( def_id) ,
973- crate_name : tcx. crate_name ( def_id. krate ) ,
974- } ) ;
975- }
976-
977- true
958+ tcx. should_codegen_locally_slow ( instance)
978959}
979960
980961/// For a given pair of source and target type that occur in an unsizing coercion,
@@ -1630,4 +1611,27 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16301611pub ( crate ) fn provide ( providers : & mut Providers ) {
16311612 providers. hooks . should_codegen_locally = should_codegen_locally;
16321613 providers. items_of_instance = items_of_instance;
1614+ providers. should_codegen_locally_slow = |tcx, instance| {
1615+ let def_id = instance. def_id ( ) ;
1616+ if let DefKind :: Static { .. } = tcx. def_kind ( def_id) {
1617+ // We cannot monomorphize statics from upstream crates.
1618+ return false ;
1619+ }
1620+
1621+ if tcx. is_reachable_non_generic ( def_id)
1622+ || instance. polymorphize ( tcx) . upstream_monomorphization ( tcx) . is_some ( )
1623+ {
1624+ // We can link to the item in question, no instance needed in this crate.
1625+ return false ;
1626+ }
1627+
1628+ if !tcx. is_mir_available ( def_id) {
1629+ tcx. dcx ( ) . emit_fatal ( NoOptimizedMir {
1630+ span : tcx. def_span ( def_id) ,
1631+ crate_name : tcx. crate_name ( def_id. krate ) ,
1632+ } ) ;
1633+ }
1634+
1635+ true
1636+ } ;
16331637}
0 commit comments