mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
Use the hook on tcx instead of the local function
This commit is contained in:
parent
0d508bb0cd
commit
14430e66be
@ -400,7 +400,7 @@ fn collect_items_rec<'tcx>(
|
|||||||
let instance = Instance::mono(tcx, def_id);
|
let instance = Instance::mono(tcx, def_id);
|
||||||
|
|
||||||
// Sanity check whether this ended up being collected accidentally
|
// Sanity check whether this ended up being collected accidentally
|
||||||
debug_assert!(should_codegen_locally(tcx, instance));
|
debug_assert!(tcx.should_codegen_locally(instance));
|
||||||
|
|
||||||
let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
|
let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
|
||||||
// Nested statics have no type.
|
// Nested statics have no type.
|
||||||
@ -432,7 +432,7 @@ fn collect_items_rec<'tcx>(
|
|||||||
}
|
}
|
||||||
MonoItem::Fn(instance) => {
|
MonoItem::Fn(instance) => {
|
||||||
// Sanity check whether this ended up being collected accidentally
|
// Sanity check whether this ended up being collected accidentally
|
||||||
debug_assert!(should_codegen_locally(tcx, instance));
|
debug_assert!(tcx.should_codegen_locally(instance));
|
||||||
|
|
||||||
// Keep track of the monomorphization recursion depth
|
// Keep track of the monomorphization recursion depth
|
||||||
recursion_depth_reset = Some(check_recursion_limit(
|
recursion_depth_reset = Some(check_recursion_limit(
|
||||||
@ -476,7 +476,7 @@ fn collect_items_rec<'tcx>(
|
|||||||
}
|
}
|
||||||
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
|
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
|
||||||
let instance = Instance::mono(tcx, *def_id);
|
let instance = Instance::mono(tcx, *def_id);
|
||||||
if should_codegen_locally(tcx, instance) {
|
if tcx.should_codegen_locally(instance) {
|
||||||
trace!("collecting static {:?}", def_id);
|
trace!("collecting static {:?}", def_id);
|
||||||
used_items.push(dummy_spanned(MonoItem::Static(*def_id)));
|
used_items.push(dummy_spanned(MonoItem::Static(*def_id)));
|
||||||
}
|
}
|
||||||
@ -713,7 +713,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||||||
if let ty::Closure(def_id, args) = *source_ty.kind() {
|
if let ty::Closure(def_id, args) = *source_ty.kind() {
|
||||||
let instance =
|
let instance =
|
||||||
Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce);
|
Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce);
|
||||||
if should_codegen_locally(self.tcx, instance) {
|
if self.tcx.should_codegen_locally(instance) {
|
||||||
self.used_items.push(create_fn_mono_item(self.tcx, instance, span));
|
self.used_items.push(create_fn_mono_item(self.tcx, instance, span));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -723,7 +723,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||||||
mir::Rvalue::ThreadLocalRef(def_id) => {
|
mir::Rvalue::ThreadLocalRef(def_id) => {
|
||||||
assert!(self.tcx.is_thread_local_static(def_id));
|
assert!(self.tcx.is_thread_local_static(def_id));
|
||||||
let instance = Instance::mono(self.tcx, def_id);
|
let instance = Instance::mono(self.tcx, def_id);
|
||||||
if should_codegen_locally(self.tcx, instance) {
|
if self.tcx.should_codegen_locally(instance) {
|
||||||
trace!("collecting thread-local static {:?}", def_id);
|
trace!("collecting thread-local static {:?}", def_id);
|
||||||
self.used_items.push(respan(span, MonoItem::Static(def_id)));
|
self.used_items.push(respan(span, MonoItem::Static(def_id)));
|
||||||
}
|
}
|
||||||
@ -750,7 +750,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| {
|
let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| {
|
||||||
let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source)));
|
let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source)));
|
||||||
if should_codegen_locally(tcx, instance) {
|
if tcx.should_codegen_locally(instance) {
|
||||||
this.used_items.push(create_fn_mono_item(tcx, instance, source));
|
this.used_items.push(create_fn_mono_item(tcx, instance, source));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -784,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
mir::InlineAsmOperand::SymStatic { def_id } => {
|
mir::InlineAsmOperand::SymStatic { def_id } => {
|
||||||
let instance = Instance::mono(self.tcx, def_id);
|
let instance = Instance::mono(self.tcx, def_id);
|
||||||
if should_codegen_locally(self.tcx, instance) {
|
if self.tcx.should_codegen_locally(instance) {
|
||||||
trace!("collecting asm sym static {:?}", def_id);
|
trace!("collecting asm sym static {:?}", def_id);
|
||||||
self.used_items.push(respan(source, MonoItem::Static(def_id)));
|
self.used_items.push(respan(source, MonoItem::Static(def_id)));
|
||||||
}
|
}
|
||||||
@ -874,7 +874,7 @@ fn visit_instance_use<'tcx>(
|
|||||||
output: &mut MonoItems<'tcx>,
|
output: &mut MonoItems<'tcx>,
|
||||||
) {
|
) {
|
||||||
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
|
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
|
||||||
if !should_codegen_locally(tcx, instance) {
|
if !tcx.should_codegen_locally(instance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ty::InstanceKind::Intrinsic(def_id) = instance.def {
|
if let ty::InstanceKind::Intrinsic(def_id) = instance.def {
|
||||||
@ -886,13 +886,13 @@ fn visit_instance_use<'tcx>(
|
|||||||
// codegen a call to that function without generating code for the function itself.
|
// codegen a call to that function without generating code for the function itself.
|
||||||
let def_id = tcx.require_lang_item(LangItem::PanicNounwind, None);
|
let def_id = tcx.require_lang_item(LangItem::PanicNounwind, None);
|
||||||
let panic_instance = Instance::mono(tcx, def_id);
|
let panic_instance = Instance::mono(tcx, def_id);
|
||||||
if should_codegen_locally(tcx, panic_instance) {
|
if tcx.should_codegen_locally(panic_instance) {
|
||||||
output.push(create_fn_mono_item(tcx, panic_instance, source));
|
output.push(create_fn_mono_item(tcx, panic_instance, source));
|
||||||
}
|
}
|
||||||
} else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
|
} else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
|
||||||
// Codegen the fallback body of intrinsics with fallback bodies
|
// Codegen the fallback body of intrinsics with fallback bodies
|
||||||
let instance = ty::Instance::new(def_id, instance.args);
|
let instance = ty::Instance::new(def_id, instance.args);
|
||||||
if should_codegen_locally(tcx, instance) {
|
if tcx.should_codegen_locally(instance) {
|
||||||
output.push(create_fn_mono_item(tcx, instance, source));
|
output.push(create_fn_mono_item(tcx, instance, source));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -931,7 +931,7 @@ fn visit_instance_use<'tcx>(
|
|||||||
|
|
||||||
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
|
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
|
||||||
/// can just link to the upstream crate and therefore don't need a mono item.
|
/// can just link to the upstream crate and therefore don't need a mono item.
|
||||||
pub(crate) fn should_codegen_locally_hook<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -> bool {
|
fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -> bool {
|
||||||
let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else {
|
let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -968,12 +968,6 @@ pub(crate) fn should_codegen_locally_hook<'tcx>(tcx: TyCtxtAt<'tcx>, instance: I
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
|
|
||||||
/// can just link to the upstream crate and therefore don't need a mono item.
|
|
||||||
pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
|
|
||||||
tcx.should_codegen_locally(instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// For a given pair of source and target type that occur in an unsizing coercion,
|
/// For a given pair of source and target type that occur in an unsizing coercion,
|
||||||
/// this function finds the pair of types that determines the vtable linking
|
/// this function finds the pair of types that determines the vtable linking
|
||||||
/// them.
|
/// them.
|
||||||
@ -1134,7 +1128,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
VtblEntry::Method(instance) => {
|
VtblEntry::Method(instance) => {
|
||||||
Some(*instance).filter(|instance| should_codegen_locally(tcx, *instance))
|
Some(*instance).filter(|instance| tcx.should_codegen_locally(*instance))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|item| create_fn_mono_item(tcx, item, source));
|
.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
|
|||||||
GlobalAlloc::Static(def_id) => {
|
GlobalAlloc::Static(def_id) => {
|
||||||
assert!(!tcx.is_thread_local_static(def_id));
|
assert!(!tcx.is_thread_local_static(def_id));
|
||||||
let instance = Instance::mono(tcx, def_id);
|
let instance = Instance::mono(tcx, def_id);
|
||||||
if should_codegen_locally(tcx, instance) {
|
if tcx.should_codegen_locally(instance) {
|
||||||
trace!("collecting static {:?}", def_id);
|
trace!("collecting static {:?}", def_id);
|
||||||
output.push(dummy_spanned(MonoItem::Static(def_id)));
|
output.push(dummy_spanned(MonoItem::Static(def_id)));
|
||||||
}
|
}
|
||||||
@ -1169,7 +1163,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalAlloc::Function { instance, .. } => {
|
GlobalAlloc::Function { instance, .. } => {
|
||||||
if should_codegen_locally(tcx, instance) {
|
if tcx.should_codegen_locally(instance) {
|
||||||
trace!("collecting {:?} with {:#?}", alloc_id, instance);
|
trace!("collecting {:?} with {:#?}", alloc_id, instance);
|
||||||
output.push(create_fn_mono_item(tcx, instance, DUMMY_SP));
|
output.push(create_fn_mono_item(tcx, instance, DUMMY_SP));
|
||||||
}
|
}
|
||||||
@ -1291,7 +1285,7 @@ fn visit_mentioned_item<'tcx>(
|
|||||||
if let ty::Closure(def_id, args) = *source_ty.kind() {
|
if let ty::Closure(def_id, args) = *source_ty.kind() {
|
||||||
let instance =
|
let instance =
|
||||||
Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce);
|
Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce);
|
||||||
if should_codegen_locally(tcx, instance) {
|
if tcx.should_codegen_locally(instance) {
|
||||||
output.push(create_fn_mono_item(tcx, instance, span));
|
output.push(create_fn_mono_item(tcx, instance, span));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1564,7 +1558,7 @@ fn create_mono_items_for_default_impls<'tcx>(
|
|||||||
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, DUMMY_SP);
|
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, DUMMY_SP);
|
||||||
|
|
||||||
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
|
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
|
||||||
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {
|
if mono_item.node.is_instantiable(tcx) && tcx.should_codegen_locally(instance) {
|
||||||
output.push(mono_item);
|
output.push(mono_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1622,5 +1616,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
providers.hooks.should_codegen_locally = should_codegen_locally_hook;
|
providers.hooks.should_codegen_locally = should_codegen_locally;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@ mod partitioning;
|
|||||||
mod polymorphize;
|
mod polymorphize;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use collector::should_codegen_locally;
|
|
||||||
|
|
||||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||||
|
|
||||||
fn custom_coerce_unsize_info<'tcx>(
|
fn custom_coerce_unsize_info<'tcx>(
|
||||||
@ -73,7 +71,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
|
|||||||
!def_id.is_local()
|
!def_id.is_local()
|
||||||
&& tcx.is_compiler_builtins(LOCAL_CRATE)
|
&& tcx.is_compiler_builtins(LOCAL_CRATE)
|
||||||
&& !is_llvm_intrinsic(tcx, def_id)
|
&& !is_llvm_intrinsic(tcx, def_id)
|
||||||
&& !should_codegen_locally(tcx, instance)
|
&& !tcx.should_codegen_locally(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
|
Loading…
Reference in New Issue
Block a user