Skip to content

Commit 14430e6

Browse files
committed
Use the hook on tcx instead of the local function
1 parent 0d508bb commit 14430e6

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

compiler/rustc_monomorphize/src/collector.rs

+17-23
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ fn collect_items_rec<'tcx>(
400400
let instance = Instance::mono(tcx, def_id);
401401

402402
// 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));
404404

405405
let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
406406
// Nested statics have no type.
@@ -432,7 +432,7 @@ fn collect_items_rec<'tcx>(
432432
}
433433
MonoItem::Fn(instance) => {
434434
// 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));
436436

437437
// Keep track of the monomorphization recursion depth
438438
recursion_depth_reset = Some(check_recursion_limit(
@@ -476,7 +476,7 @@ fn collect_items_rec<'tcx>(
476476
}
477477
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
478478
let instance = Instance::mono(tcx, *def_id);
479-
if should_codegen_locally(tcx, instance) {
479+
if tcx.should_codegen_locally(instance) {
480480
trace!("collecting static {:?}", def_id);
481481
used_items.push(dummy_spanned(MonoItem::Static(*def_id)));
482482
}
@@ -713,7 +713,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
713713
if let ty::Closure(def_id, args) = *source_ty.kind() {
714714
let instance =
715715
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) {
717717
self.used_items.push(create_fn_mono_item(self.tcx, instance, span));
718718
}
719719
} else {
@@ -723,7 +723,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
723723
mir::Rvalue::ThreadLocalRef(def_id) => {
724724
assert!(self.tcx.is_thread_local_static(def_id));
725725
let instance = Instance::mono(self.tcx, def_id);
726-
if should_codegen_locally(self.tcx, instance) {
726+
if self.tcx.should_codegen_locally(instance) {
727727
trace!("collecting thread-local static {:?}", def_id);
728728
self.used_items.push(respan(span, MonoItem::Static(def_id)));
729729
}
@@ -750,7 +750,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
750750
let tcx = self.tcx;
751751
let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| {
752752
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) {
754754
this.used_items.push(create_fn_mono_item(tcx, instance, source));
755755
}
756756
};
@@ -784,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
784784
}
785785
mir::InlineAsmOperand::SymStatic { def_id } => {
786786
let instance = Instance::mono(self.tcx, def_id);
787-
if should_codegen_locally(self.tcx, instance) {
787+
if self.tcx.should_codegen_locally(instance) {
788788
trace!("collecting asm sym static {:?}", def_id);
789789
self.used_items.push(respan(source, MonoItem::Static(def_id)));
790790
}
@@ -874,7 +874,7 @@ fn visit_instance_use<'tcx>(
874874
output: &mut MonoItems<'tcx>,
875875
) {
876876
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) {
878878
return;
879879
}
880880
if let ty::InstanceKind::Intrinsic(def_id) = instance.def {
@@ -886,13 +886,13 @@ fn visit_instance_use<'tcx>(
886886
// codegen a call to that function without generating code for the function itself.
887887
let def_id = tcx.require_lang_item(LangItem::PanicNounwind, None);
888888
let panic_instance = Instance::mono(tcx, def_id);
889-
if should_codegen_locally(tcx, panic_instance) {
889+
if tcx.should_codegen_locally(panic_instance) {
890890
output.push(create_fn_mono_item(tcx, panic_instance, source));
891891
}
892892
} else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
893893
// Codegen the fallback body of intrinsics with fallback bodies
894894
let instance = ty::Instance::new(def_id, instance.args);
895-
if should_codegen_locally(tcx, instance) {
895+
if tcx.should_codegen_locally(instance) {
896896
output.push(create_fn_mono_item(tcx, instance, source));
897897
}
898898
}
@@ -931,7 +931,7 @@ fn visit_instance_use<'tcx>(
931931

932932
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
933933
/// 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 {
935935
let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else {
936936
return true;
937937
};
@@ -968,12 +968,6 @@ pub(crate) fn should_codegen_locally_hook<'tcx>(tcx: TyCtxtAt<'tcx>, instance: I
968968
true
969969
}
970970

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-
977971
/// For a given pair of source and target type that occur in an unsizing coercion,
978972
/// this function finds the pair of types that determines the vtable linking
979973
/// them.
@@ -1134,7 +1128,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
11341128
None
11351129
}
11361130
VtblEntry::Method(instance) => {
1137-
Some(*instance).filter(|instance| should_codegen_locally(tcx, *instance))
1131+
Some(*instance).filter(|instance| tcx.should_codegen_locally(*instance))
11381132
}
11391133
})
11401134
.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
11511145
GlobalAlloc::Static(def_id) => {
11521146
assert!(!tcx.is_thread_local_static(def_id));
11531147
let instance = Instance::mono(tcx, def_id);
1154-
if should_codegen_locally(tcx, instance) {
1148+
if tcx.should_codegen_locally(instance) {
11551149
trace!("collecting static {:?}", def_id);
11561150
output.push(dummy_spanned(MonoItem::Static(def_id)));
11571151
}
@@ -1169,7 +1163,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
11691163
}
11701164
}
11711165
GlobalAlloc::Function { instance, .. } => {
1172-
if should_codegen_locally(tcx, instance) {
1166+
if tcx.should_codegen_locally(instance) {
11731167
trace!("collecting {:?} with {:#?}", alloc_id, instance);
11741168
output.push(create_fn_mono_item(tcx, instance, DUMMY_SP));
11751169
}
@@ -1291,7 +1285,7 @@ fn visit_mentioned_item<'tcx>(
12911285
if let ty::Closure(def_id, args) = *source_ty.kind() {
12921286
let instance =
12931287
Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce);
1294-
if should_codegen_locally(tcx, instance) {
1288+
if tcx.should_codegen_locally(instance) {
12951289
output.push(create_fn_mono_item(tcx, instance, span));
12961290
}
12971291
} else {
@@ -1564,7 +1558,7 @@ fn create_mono_items_for_default_impls<'tcx>(
15641558
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, DUMMY_SP);
15651559

15661560
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) {
15681562
output.push(mono_item);
15691563
}
15701564
}
@@ -1622,5 +1616,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16221616
}
16231617

16241618
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;
16261620
}

compiler/rustc_monomorphize/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ mod partitioning;
2222
mod polymorphize;
2323
mod util;
2424

25-
use collector::should_codegen_locally;
26-
2725
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
2826

2927
fn custom_coerce_unsize_info<'tcx>(
@@ -73,7 +71,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
7371
!def_id.is_local()
7472
&& tcx.is_compiler_builtins(LOCAL_CRATE)
7573
&& !is_llvm_intrinsic(tcx, def_id)
76-
&& !should_codegen_locally(tcx, instance)
74+
&& !tcx.should_codegen_locally(instance)
7775
}
7876

7977
pub fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)