summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_passes/src/reachable.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_passes/src/reachable.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_passes/src/reachable.rs')
-rw-r--r--compiler/rustc_passes/src/reachable.rs62
1 files changed, 11 insertions, 51 deletions
diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs
index 1239d6d91..650bb97c4 100644
--- a/compiler/rustc_passes/src/reachable.rs
+++ b/compiler/rustc_passes/src/reachable.rs
@@ -18,43 +18,10 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_session::config::CrateType;
use rustc_target::spec::abi::Abi;
-// Returns true if the given item must be inlined because it may be
-// monomorphized or it was marked with `#[inline]`. This will only return
-// true for functions.
-fn item_might_be_inlined(tcx: TyCtxt<'_>, item: &hir::Item<'_>, attrs: &CodegenFnAttrs) -> bool {
- if attrs.requests_inline() {
- return true;
- }
-
- match item.kind {
- hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => true,
- hir::ItemKind::Impl { .. } | hir::ItemKind::Fn(..) => {
- let generics = tcx.generics_of(item.owner_id);
- generics.requires_monomorphization(tcx)
- }
- _ => false,
- }
-}
-
-fn method_might_be_inlined(
- tcx: TyCtxt<'_>,
- impl_item: &hir::ImplItem<'_>,
- impl_src: LocalDefId,
-) -> bool {
- let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id().owner.to_def_id());
- let generics = tcx.generics_of(impl_item.owner_id);
- if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
- return true;
- }
- if let hir::ImplItemKind::Fn(method_sig, _) = &impl_item.kind {
- if method_sig.header.is_const() {
- return true;
- }
- }
- match tcx.hir().find_by_def_id(impl_src) {
- Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs),
- Some(..) | None => span_bug!(impl_item.span, "impl did is not an item"),
- }
+fn item_might_be_inlined(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
+ tcx.generics_of(def_id).requires_monomorphization(tcx)
+ || tcx.cross_crate_inlinable(def_id)
+ || tcx.is_const_fn(def_id)
}
// Information needed while computing reachability.
@@ -97,7 +64,9 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
_ => None,
};
- if let Some(res) = res && let Some(def_id) = res.opt_def_id().and_then(|el| el.as_local()) {
+ if let Some(res) = res
+ && let Some(def_id) = res.opt_def_id().and_then(|el| el.as_local())
+ {
if self.def_id_represents_local_inlined_item(def_id.to_def_id()) {
self.worklist.push(def_id);
} else {
@@ -148,9 +117,7 @@ impl<'tcx> ReachableContext<'tcx> {
match self.tcx.hir().find_by_def_id(def_id) {
Some(Node::Item(item)) => match item.kind {
- hir::ItemKind::Fn(..) => {
- item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id))
- }
+ hir::ItemKind::Fn(..) => item_might_be_inlined(self.tcx, def_id.into()),
_ => false,
},
Some(Node::TraitItem(trait_method)) => match trait_method.kind {
@@ -162,9 +129,7 @@ impl<'tcx> ReachableContext<'tcx> {
Some(Node::ImplItem(impl_item)) => match impl_item.kind {
hir::ImplItemKind::Const(..) => true,
hir::ImplItemKind::Fn(..) => {
- let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
- let impl_did = self.tcx.hir().get_parent_item(hir_id);
- method_might_be_inlined(self.tcx, impl_item, impl_did.def_id)
+ item_might_be_inlined(self.tcx, impl_item.hir_id().owner.to_def_id())
}
hir::ImplItemKind::Type(_) => false,
},
@@ -224,11 +189,7 @@ impl<'tcx> ReachableContext<'tcx> {
Node::Item(item) => {
match item.kind {
hir::ItemKind::Fn(.., body) => {
- if item_might_be_inlined(
- self.tcx,
- &item,
- self.tcx.codegen_fn_attrs(item.owner_id),
- ) {
+ if item_might_be_inlined(self.tcx, item.owner_id.into()) {
self.visit_nested_body(body);
}
}
@@ -277,8 +238,7 @@ impl<'tcx> ReachableContext<'tcx> {
self.visit_nested_body(body);
}
hir::ImplItemKind::Fn(_, body) => {
- let impl_def_id = self.tcx.local_parent(search_item);
- if method_might_be_inlined(self.tcx, impl_item, impl_def_id) {
+ if item_might_be_inlined(self.tcx, impl_item.hir_id().owner.to_def_id()) {
self.visit_nested_body(body)
}
}