@@ -400,7 +400,7 @@ fn collect_items_rec<'tcx>(
400
400
let instance = Instance :: mono ( tcx, def_id) ;
401
401
402
402
// Sanity check whether this ended up being collected accidentally
403
- debug_assert ! ( should_codegen_locally( tcx , instance) ) ;
403
+ debug_assert ! ( tcx . should_codegen_locally( instance) ) ;
404
404
405
405
let DefKind :: Static { nested, .. } = tcx. def_kind ( def_id) else { bug ! ( ) } ;
406
406
// Nested statics have no type.
@@ -432,7 +432,7 @@ fn collect_items_rec<'tcx>(
432
432
}
433
433
MonoItem :: Fn ( instance) => {
434
434
// Sanity check whether this ended up being collected accidentally
435
- debug_assert ! ( should_codegen_locally( tcx , instance) ) ;
435
+ debug_assert ! ( tcx . should_codegen_locally( instance) ) ;
436
436
437
437
// Keep track of the monomorphization recursion depth
438
438
recursion_depth_reset = Some ( check_recursion_limit (
@@ -476,7 +476,7 @@ fn collect_items_rec<'tcx>(
476
476
}
477
477
hir:: InlineAsmOperand :: SymStatic { path : _, def_id } => {
478
478
let instance = Instance :: mono ( tcx, * def_id) ;
479
- if should_codegen_locally ( tcx , instance) {
479
+ if tcx . should_codegen_locally ( instance) {
480
480
trace ! ( "collecting static {:?}" , def_id) ;
481
481
used_items. push ( dummy_spanned ( MonoItem :: Static ( * def_id) ) ) ;
482
482
}
@@ -713,7 +713,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
713
713
if let ty:: Closure ( def_id, args) = * source_ty. kind ( ) {
714
714
let instance =
715
715
Instance :: resolve_closure ( self . tcx , def_id, args, ty:: ClosureKind :: FnOnce ) ;
716
- if should_codegen_locally ( self . tcx , instance) {
716
+ if self . tcx . should_codegen_locally ( instance) {
717
717
self . used_items . push ( create_fn_mono_item ( self . tcx , instance, span) ) ;
718
718
}
719
719
} else {
@@ -723,7 +723,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
723
723
mir:: Rvalue :: ThreadLocalRef ( def_id) => {
724
724
assert ! ( self . tcx. is_thread_local_static( def_id) ) ;
725
725
let instance = Instance :: mono ( self . tcx , def_id) ;
726
- if should_codegen_locally ( self . tcx , instance) {
726
+ if self . tcx . should_codegen_locally ( instance) {
727
727
trace ! ( "collecting thread-local static {:?}" , def_id) ;
728
728
self . used_items . push ( respan ( span, MonoItem :: Static ( def_id) ) ) ;
729
729
}
@@ -750,7 +750,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
750
750
let tcx = self . tcx ;
751
751
let push_mono_lang_item = |this : & mut Self , lang_item : LangItem | {
752
752
let instance = Instance :: mono ( tcx, tcx. require_lang_item ( lang_item, Some ( source) ) ) ;
753
- if should_codegen_locally ( tcx , instance) {
753
+ if tcx . should_codegen_locally ( instance) {
754
754
this. used_items . push ( create_fn_mono_item ( tcx, instance, source) ) ;
755
755
}
756
756
} ;
@@ -784,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
784
784
}
785
785
mir:: InlineAsmOperand :: SymStatic { def_id } => {
786
786
let instance = Instance :: mono ( self . tcx , def_id) ;
787
- if should_codegen_locally ( self . tcx , instance) {
787
+ if self . tcx . should_codegen_locally ( instance) {
788
788
trace ! ( "collecting asm sym static {:?}" , def_id) ;
789
789
self . used_items . push ( respan ( source, MonoItem :: Static ( def_id) ) ) ;
790
790
}
@@ -874,7 +874,7 @@ fn visit_instance_use<'tcx>(
874
874
output : & mut MonoItems < ' tcx > ,
875
875
) {
876
876
debug ! ( "visit_item_use({:?}, is_direct_call={:?})" , instance, is_direct_call) ;
877
- if !should_codegen_locally ( tcx , instance) {
877
+ if !tcx . should_codegen_locally ( instance) {
878
878
return ;
879
879
}
880
880
if let ty:: InstanceKind :: Intrinsic ( def_id) = instance. def {
@@ -886,13 +886,13 @@ fn visit_instance_use<'tcx>(
886
886
// codegen a call to that function without generating code for the function itself.
887
887
let def_id = tcx. require_lang_item ( LangItem :: PanicNounwind , None ) ;
888
888
let panic_instance = Instance :: mono ( tcx, def_id) ;
889
- if should_codegen_locally ( tcx , panic_instance) {
889
+ if tcx . should_codegen_locally ( panic_instance) {
890
890
output. push ( create_fn_mono_item ( tcx, panic_instance, source) ) ;
891
891
}
892
892
} else if tcx. has_attr ( def_id, sym:: rustc_intrinsic) {
893
893
// Codegen the fallback body of intrinsics with fallback bodies
894
894
let instance = ty:: Instance :: new ( def_id, instance. args ) ;
895
- if should_codegen_locally ( tcx , instance) {
895
+ if tcx . should_codegen_locally ( instance) {
896
896
output. push ( create_fn_mono_item ( tcx, instance, source) ) ;
897
897
}
898
898
}
@@ -931,7 +931,7 @@ fn visit_instance_use<'tcx>(
931
931
932
932
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
933
933
/// can just link to the upstream crate and therefore don't need a mono item.
934
- pub ( crate ) fn should_codegen_locally_hook < ' tcx > ( tcx : TyCtxtAt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
934
+ fn should_codegen_locally < ' tcx > ( tcx : TyCtxtAt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
935
935
let Some ( def_id) = instance. def . def_id_if_not_guaranteed_local_codegen ( ) else {
936
936
return true ;
937
937
} ;
@@ -968,12 +968,6 @@ pub(crate) fn should_codegen_locally_hook<'tcx>(tcx: TyCtxtAt<'tcx>, instance: I
968
968
true
969
969
}
970
970
971
- /// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
972
- /// can just link to the upstream crate and therefore don't need a mono item.
973
- pub ( crate ) fn should_codegen_locally < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> bool {
974
- tcx. should_codegen_locally ( instance)
975
- }
976
-
977
971
/// For a given pair of source and target type that occur in an unsizing coercion,
978
972
/// this function finds the pair of types that determines the vtable linking
979
973
/// them.
@@ -1134,7 +1128,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
1134
1128
None
1135
1129
}
1136
1130
VtblEntry :: Method ( instance) => {
1137
- Some ( * instance) . filter ( |instance| should_codegen_locally ( tcx , * instance) )
1131
+ Some ( * instance) . filter ( |instance| tcx . should_codegen_locally ( * instance) )
1138
1132
}
1139
1133
} )
1140
1134
. map ( |item| create_fn_mono_item ( tcx, item, source) ) ;
@@ -1151,7 +1145,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
1151
1145
GlobalAlloc :: Static ( def_id) => {
1152
1146
assert ! ( !tcx. is_thread_local_static( def_id) ) ;
1153
1147
let instance = Instance :: mono ( tcx, def_id) ;
1154
- if should_codegen_locally ( tcx , instance) {
1148
+ if tcx . should_codegen_locally ( instance) {
1155
1149
trace ! ( "collecting static {:?}" , def_id) ;
1156
1150
output. push ( dummy_spanned ( MonoItem :: Static ( def_id) ) ) ;
1157
1151
}
@@ -1169,7 +1163,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
1169
1163
}
1170
1164
}
1171
1165
GlobalAlloc :: Function { instance, .. } => {
1172
- if should_codegen_locally ( tcx , instance) {
1166
+ if tcx . should_codegen_locally ( instance) {
1173
1167
trace ! ( "collecting {:?} with {:#?}" , alloc_id, instance) ;
1174
1168
output. push ( create_fn_mono_item ( tcx, instance, DUMMY_SP ) ) ;
1175
1169
}
@@ -1291,7 +1285,7 @@ fn visit_mentioned_item<'tcx>(
1291
1285
if let ty:: Closure ( def_id, args) = * source_ty. kind ( ) {
1292
1286
let instance =
1293
1287
Instance :: resolve_closure ( tcx, def_id, args, ty:: ClosureKind :: FnOnce ) ;
1294
- if should_codegen_locally ( tcx , instance) {
1288
+ if tcx . should_codegen_locally ( instance) {
1295
1289
output. push ( create_fn_mono_item ( tcx, instance, span) ) ;
1296
1290
}
1297
1291
} else {
@@ -1564,7 +1558,7 @@ fn create_mono_items_for_default_impls<'tcx>(
1564
1558
let instance = ty:: Instance :: expect_resolve ( tcx, param_env, method. def_id , args, DUMMY_SP ) ;
1565
1559
1566
1560
let mono_item = create_fn_mono_item ( tcx, instance, DUMMY_SP ) ;
1567
- 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) {
1568
1562
output. push ( mono_item) ;
1569
1563
}
1570
1564
}
@@ -1622,5 +1616,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
1622
1616
}
1623
1617
1624
1618
pub fn provide ( providers : & mut Providers ) {
1625
- providers. hooks . should_codegen_locally = should_codegen_locally_hook ;
1619
+ providers. hooks . should_codegen_locally = should_codegen_locally ;
1626
1620
}
0 commit comments