@@ -228,6 +228,7 @@ use rustc_middle::ty::{
228
228
self , AssocKind , GenericParamDefKind , Instance , InstanceKind , Ty , TyCtxt , TypeFoldable ,
229
229
TypeVisitableExt , VtblEntry ,
230
230
} ;
231
+ use rustc_middle:: util:: Providers ;
231
232
use rustc_middle:: { bug, span_bug} ;
232
233
use rustc_session:: config:: EntryFnType ;
233
234
use rustc_session:: Limit ;
@@ -399,7 +400,7 @@ fn collect_items_rec<'tcx>(
399
400
let instance = Instance :: mono ( tcx, def_id) ;
400
401
401
402
// 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) ) ;
403
404
404
405
let DefKind :: Static { nested, .. } = tcx. def_kind ( def_id) else { bug ! ( ) } ;
405
406
// Nested statics have no type.
@@ -431,7 +432,7 @@ fn collect_items_rec<'tcx>(
431
432
}
432
433
MonoItem :: Fn ( instance) => {
433
434
// 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) ) ;
435
436
436
437
// Keep track of the monomorphization recursion depth
437
438
recursion_depth_reset = Some ( check_recursion_limit (
@@ -475,7 +476,7 @@ fn collect_items_rec<'tcx>(
475
476
}
476
477
hir:: InlineAsmOperand :: SymStatic { path : _, def_id } => {
477
478
let instance = Instance :: mono ( tcx, * def_id) ;
478
- if should_codegen_locally ( tcx , instance) {
479
+ if tcx . should_codegen_locally ( instance) {
479
480
trace ! ( "collecting static {:?}" , def_id) ;
480
481
used_items. push ( dummy_spanned ( MonoItem :: Static ( * def_id) ) ) ;
481
482
}
@@ -712,7 +713,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
712
713
if let ty:: Closure ( def_id, args) = * source_ty. kind ( ) {
713
714
let instance =
714
715
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) {
716
717
self . used_items . push ( create_fn_mono_item ( self . tcx , instance, span) ) ;
717
718
}
718
719
} else {
@@ -722,7 +723,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
722
723
mir:: Rvalue :: ThreadLocalRef ( def_id) => {
723
724
assert ! ( self . tcx. is_thread_local_static( def_id) ) ;
724
725
let instance = Instance :: mono ( self . tcx , def_id) ;
725
- if should_codegen_locally ( self . tcx , instance) {
726
+ if self . tcx . should_codegen_locally ( instance) {
726
727
trace ! ( "collecting thread-local static {:?}" , def_id) ;
727
728
self . used_items . push ( respan ( span, MonoItem :: Static ( def_id) ) ) ;
728
729
}
@@ -749,7 +750,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
749
750
let tcx = self . tcx ;
750
751
let push_mono_lang_item = |this : & mut Self , lang_item : LangItem | {
751
752
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) {
753
754
this. used_items . push ( create_fn_mono_item ( tcx, instance, source) ) ;
754
755
}
755
756
} ;
@@ -783,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
783
784
}
784
785
mir:: InlineAsmOperand :: SymStatic { def_id } => {
785
786
let instance = Instance :: mono ( self . tcx , def_id) ;
786
- if should_codegen_locally ( self . tcx , instance) {
787
+ if self . tcx . should_codegen_locally ( instance) {
787
788
trace ! ( "collecting asm sym static {:?}" , def_id) ;
788
789
self . used_items . push ( respan ( source, MonoItem :: Static ( def_id) ) ) ;
789
790
}
@@ -873,7 +874,7 @@ fn visit_instance_use<'tcx>(
873
874
output : & mut MonoItems < ' tcx > ,
874
875
) {
875
876
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) {
877
878
return ;
878
879
}
879
880
if let ty:: InstanceKind :: Intrinsic ( def_id) = instance. def {
@@ -885,13 +886,13 @@ fn visit_instance_use<'tcx>(
885
886
// codegen a call to that function without generating code for the function itself.
886
887
let def_id = tcx. require_lang_item ( LangItem :: PanicNounwind , None ) ;
887
888
let panic_instance = Instance :: mono ( tcx, def_id) ;
888
- if should_codegen_locally ( tcx , panic_instance) {
889
+ if tcx . should_codegen_locally ( panic_instance) {
889
890
output. push ( create_fn_mono_item ( tcx, panic_instance, source) ) ;
890
891
}
891
892
} else if tcx. has_attr ( def_id, sym:: rustc_intrinsic) {
892
893
// Codegen the fallback body of intrinsics with fallback bodies
893
894
let instance = ty:: Instance :: new ( def_id, instance. args ) ;
894
- if should_codegen_locally ( tcx , instance) {
895
+ if tcx . should_codegen_locally ( instance) {
895
896
output. push ( create_fn_mono_item ( tcx, instance, source) ) ;
896
897
}
897
898
}
@@ -930,7 +931,7 @@ fn visit_instance_use<'tcx>(
930
931
931
932
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
932
933
/// 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 {
934
935
let Some ( def_id) = instance. def . def_id_if_not_guaranteed_local_codegen ( ) else {
935
936
return true ;
936
937
} ;
@@ -946,7 +947,7 @@ pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance
946
947
}
947
948
948
949
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 ( )
950
951
{
951
952
// We can link to the item in question, no instance needed in this crate.
952
953
return false ;
@@ -1127,7 +1128,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
1127
1128
None
1128
1129
}
1129
1130
VtblEntry :: Method ( instance) => {
1130
- Some ( * instance) . filter ( |instance| should_codegen_locally ( tcx , * instance) )
1131
+ Some ( * instance) . filter ( |instance| tcx . should_codegen_locally ( * instance) )
1131
1132
}
1132
1133
} )
1133
1134
. 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
1144
1145
GlobalAlloc :: Static ( def_id) => {
1145
1146
assert ! ( !tcx. is_thread_local_static( def_id) ) ;
1146
1147
let instance = Instance :: mono ( tcx, def_id) ;
1147
- if should_codegen_locally ( tcx , instance) {
1148
+ if tcx . should_codegen_locally ( instance) {
1148
1149
trace ! ( "collecting static {:?}" , def_id) ;
1149
1150
output. push ( dummy_spanned ( MonoItem :: Static ( def_id) ) ) ;
1150
1151
}
@@ -1162,7 +1163,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
1162
1163
}
1163
1164
}
1164
1165
GlobalAlloc :: Function { instance, .. } => {
1165
- if should_codegen_locally ( tcx , instance) {
1166
+ if tcx . should_codegen_locally ( instance) {
1166
1167
trace ! ( "collecting {:?} with {:#?}" , alloc_id, instance) ;
1167
1168
output. push ( create_fn_mono_item ( tcx, instance, DUMMY_SP ) ) ;
1168
1169
}
@@ -1284,7 +1285,7 @@ fn visit_mentioned_item<'tcx>(
1284
1285
if let ty:: Closure ( def_id, args) = * source_ty. kind ( ) {
1285
1286
let instance =
1286
1287
Instance :: resolve_closure ( tcx, def_id, args, ty:: ClosureKind :: FnOnce ) ;
1287
- if should_codegen_locally ( tcx , instance) {
1288
+ if tcx . should_codegen_locally ( instance) {
1288
1289
output. push ( create_fn_mono_item ( tcx, instance, span) ) ;
1289
1290
}
1290
1291
} else {
@@ -1557,7 +1558,7 @@ fn create_mono_items_for_default_impls<'tcx>(
1557
1558
let instance = ty:: Instance :: expect_resolve ( tcx, param_env, method. def_id , args, DUMMY_SP ) ;
1558
1559
1559
1560
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) {
1561
1562
output. push ( mono_item) ;
1562
1563
}
1563
1564
}
@@ -1613,3 +1614,7 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
1613
1614
1614
1615
( mono_items, state. usage_map . into_inner ( ) )
1615
1616
}
1617
+
1618
+ pub fn provide ( providers : & mut Providers ) {
1619
+ providers. hooks . should_codegen_locally = should_codegen_locally;
1620
+ }
0 commit comments