@@ -228,6 +228,7 @@ use rustc_middle::ty::{
228228 self , AssocKind , GenericParamDefKind , Instance , InstanceKind , Ty , TyCtxt , TypeFoldable ,
229229 TypeVisitableExt , VtblEntry ,
230230} ;
231+ use rustc_middle:: util:: Providers ;
231232use rustc_middle:: { bug, span_bug} ;
232233use rustc_session:: config:: EntryFnType ;
233234use rustc_session:: Limit ;
@@ -399,7 +400,7 @@ fn collect_items_rec<'tcx>(
399400 let instance = Instance :: mono ( tcx, def_id) ;
400401
401402 // Sanity check whether this ended up being collected accidentally
402- debug_assert ! ( should_codegen_locally( tcx , instance) ) ;
403+ debug_assert ! ( tcx . should_codegen_locally( instance) ) ;
403404
404405 let DefKind :: Static { nested, .. } = tcx. def_kind ( def_id) else { bug ! ( ) } ;
405406 // Nested statics have no type.
@@ -431,7 +432,7 @@ fn collect_items_rec<'tcx>(
431432 }
432433 MonoItem :: Fn ( instance) => {
433434 // Sanity check whether this ended up being collected accidentally
434- debug_assert ! ( should_codegen_locally( tcx , instance) ) ;
435+ debug_assert ! ( tcx . should_codegen_locally( instance) ) ;
435436
436437 // Keep track of the monomorphization recursion depth
437438 recursion_depth_reset = Some ( check_recursion_limit (
@@ -475,7 +476,7 @@ fn collect_items_rec<'tcx>(
475476 }
476477 hir:: InlineAsmOperand :: SymStatic { path : _, def_id } => {
477478 let instance = Instance :: mono ( tcx, * def_id) ;
478- if should_codegen_locally ( tcx , instance) {
479+ if tcx . should_codegen_locally ( instance) {
479480 trace ! ( "collecting static {:?}" , def_id) ;
480481 used_items. push ( dummy_spanned ( MonoItem :: Static ( * def_id) ) ) ;
481482 }
@@ -712,7 +713,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
712713 if let ty:: Closure ( def_id, args) = * source_ty. kind ( ) {
713714 let instance =
714715 Instance :: resolve_closure ( self . tcx , def_id, args, ty:: ClosureKind :: FnOnce ) ;
715- if should_codegen_locally ( self . tcx , instance) {
716+ if self . tcx . should_codegen_locally ( instance) {
716717 self . used_items . push ( create_fn_mono_item ( self . tcx , instance, span) ) ;
717718 }
718719 } else {
@@ -722,7 +723,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
722723 mir:: Rvalue :: ThreadLocalRef ( def_id) => {
723724 assert ! ( self . tcx. is_thread_local_static( def_id) ) ;
724725 let instance = Instance :: mono ( self . tcx , def_id) ;
725- if should_codegen_locally ( self . tcx , instance) {
726+ if self . tcx . should_codegen_locally ( instance) {
726727 trace ! ( "collecting thread-local static {:?}" , def_id) ;
727728 self . used_items . push ( respan ( span, MonoItem :: Static ( def_id) ) ) ;
728729 }
@@ -749,7 +750,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
749750 let tcx = self . tcx ;
750751 let push_mono_lang_item = |this : & mut Self , lang_item : LangItem | {
751752 let instance = Instance :: mono ( tcx, tcx. require_lang_item ( lang_item, Some ( source) ) ) ;
752- if should_codegen_locally ( tcx , instance) {
753+ if tcx . should_codegen_locally ( instance) {
753754 this. used_items . push ( create_fn_mono_item ( tcx, instance, source) ) ;
754755 }
755756 } ;
@@ -783,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
783784 }
784785 mir:: InlineAsmOperand :: SymStatic { def_id } => {
785786 let instance = Instance :: mono ( self . tcx , def_id) ;
786- if should_codegen_locally ( self . tcx , instance) {
787+ if self . tcx . should_codegen_locally ( instance) {
787788 trace ! ( "collecting asm sym static {:?}" , def_id) ;
788789 self . used_items . push ( respan ( source, MonoItem :: Static ( def_id) ) ) ;
789790 }
@@ -873,7 +874,7 @@ fn visit_instance_use<'tcx>(
873874 output : & mut MonoItems < ' tcx > ,
874875) {
875876 debug ! ( "visit_item_use({:?}, is_direct_call={:?})" , instance, is_direct_call) ;
876- if !should_codegen_locally ( tcx , instance) {
877+ if !tcx . should_codegen_locally ( instance) {
877878 return ;
878879 }
879880 if let ty:: InstanceKind :: Intrinsic ( def_id) = instance. def {
@@ -885,13 +886,13 @@ fn visit_instance_use<'tcx>(
885886 // codegen a call to that function without generating code for the function itself.
886887 let def_id = tcx. require_lang_item ( LangItem :: PanicNounwind , None ) ;
887888 let panic_instance = Instance :: mono ( tcx, def_id) ;
888- if should_codegen_locally ( tcx , panic_instance) {
889+ if tcx . should_codegen_locally ( panic_instance) {
889890 output. push ( create_fn_mono_item ( tcx, panic_instance, source) ) ;
890891 }
891892 } else if tcx. has_attr ( def_id, sym:: rustc_intrinsic) {
892893 // Codegen the fallback body of intrinsics with fallback bodies
893894 let instance = ty:: Instance :: new ( def_id, instance. args ) ;
894- if should_codegen_locally ( tcx , instance) {
895+ if tcx . should_codegen_locally ( instance) {
895896 output. push ( create_fn_mono_item ( tcx, instance, source) ) ;
896897 }
897898 }
@@ -930,7 +931,7 @@ fn visit_instance_use<'tcx>(
930931
931932/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
932933/// can just link to the upstream crate and therefore don't need a mono item.
933- pub ( crate ) fn should_codegen_locally < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
934+ fn should_codegen_locally < ' tcx > ( tcx : TyCtxtAt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
934935 let Some ( def_id) = instance. def . def_id_if_not_guaranteed_local_codegen ( ) else {
935936 return true ;
936937 } ;
@@ -946,7 +947,7 @@ pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance
946947 }
947948
948949 if tcx. is_reachable_non_generic ( def_id)
949- || instance. polymorphize ( tcx) . upstream_monomorphization ( tcx) . is_some ( )
950+ || instance. polymorphize ( * tcx) . upstream_monomorphization ( * tcx) . is_some ( )
950951 {
951952 // We can link to the item in question, no instance needed in this crate.
952953 return false ;
@@ -1127,7 +1128,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
11271128 None
11281129 }
11291130 VtblEntry :: Method ( instance) => {
1130- Some ( * instance) . filter ( |instance| should_codegen_locally ( tcx , * instance) )
1131+ Some ( * instance) . filter ( |instance| tcx . should_codegen_locally ( * instance) )
11311132 }
11321133 } )
11331134 . map ( |item| create_fn_mono_item ( tcx, item, source) ) ;
@@ -1144,7 +1145,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
11441145 GlobalAlloc :: Static ( def_id) => {
11451146 assert ! ( !tcx. is_thread_local_static( def_id) ) ;
11461147 let instance = Instance :: mono ( tcx, def_id) ;
1147- if should_codegen_locally ( tcx , instance) {
1148+ if tcx . should_codegen_locally ( instance) {
11481149 trace ! ( "collecting static {:?}" , def_id) ;
11491150 output. push ( dummy_spanned ( MonoItem :: Static ( def_id) ) ) ;
11501151 }
@@ -1162,7 +1163,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
11621163 }
11631164 }
11641165 GlobalAlloc :: Function { instance, .. } => {
1165- if should_codegen_locally ( tcx , instance) {
1166+ if tcx . should_codegen_locally ( instance) {
11661167 trace ! ( "collecting {:?} with {:#?}" , alloc_id, instance) ;
11671168 output. push ( create_fn_mono_item ( tcx, instance, DUMMY_SP ) ) ;
11681169 }
@@ -1284,7 +1285,7 @@ fn visit_mentioned_item<'tcx>(
12841285 if let ty:: Closure ( def_id, args) = * source_ty. kind ( ) {
12851286 let instance =
12861287 Instance :: resolve_closure ( tcx, def_id, args, ty:: ClosureKind :: FnOnce ) ;
1287- if should_codegen_locally ( tcx , instance) {
1288+ if tcx . should_codegen_locally ( instance) {
12881289 output. push ( create_fn_mono_item ( tcx, instance, span) ) ;
12891290 }
12901291 } else {
@@ -1557,7 +1558,7 @@ fn create_mono_items_for_default_impls<'tcx>(
15571558 let instance = ty:: Instance :: expect_resolve ( tcx, param_env, method. def_id , args, DUMMY_SP ) ;
15581559
15591560 let mono_item = create_fn_mono_item ( tcx, instance, DUMMY_SP ) ;
1560- if mono_item. node . is_instantiable ( tcx) && should_codegen_locally ( tcx , instance) {
1561+ if mono_item. node . is_instantiable ( tcx) && tcx . should_codegen_locally ( instance) {
15611562 output. push ( mono_item) ;
15621563 }
15631564 }
@@ -1613,3 +1614,7 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16131614
16141615 ( mono_items, state. usage_map . into_inner ( ) )
16151616}
1617+
1618+ pub fn provide ( providers : & mut Providers ) {
1619+ providers. hooks . should_codegen_locally = should_codegen_locally;
1620+ }
0 commit comments