about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/inline.rs
diff options
context:
space:
mode:
authorDavid Wood <david.wood2@arm.com>2024-12-10 12:06:24 +0000
committerDavid Wood <david.wood2@arm.com>2025-01-10 18:37:55 +0000
commit450793923ef1941bfca291f4deebf3c902d59c2f (patch)
tree0c3d00dd443a68798db9873213d573cab4aa3d78 /compiler/rustc_mir_transform/src/inline.rs
parent02d423cd24944b17783e9fa4062e6a4e8e4d351f (diff)
downloadrust-450793923ef1941bfca291f4deebf3c902d59c2f.tar.gz
rust-450793923ef1941bfca291f4deebf3c902d59c2f.zip
inline: force inlining shims
Diffstat (limited to 'compiler/rustc_mir_transform/src/inline.rs')
-rw-r--r--compiler/rustc_mir_transform/src/inline.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs
index a5a4b5987f5..cdb0ed761cf 100644
--- a/compiler/rustc_mir_transform/src/inline.rs
+++ b/compiler/rustc_mir_transform/src/inline.rs
@@ -6,7 +6,7 @@ use std::ops::{Range, RangeFrom};
 use rustc_abi::{ExternAbi, FieldIdx};
 use rustc_attr_parsing::InlineAttr;
 use rustc_hir::def::DefKind;
-use rustc_hir::def_id::{DefId, LocalDefId};
+use rustc_hir::def_id::DefId;
 use rustc_index::Idx;
 use rustc_index::bit_set::BitSet;
 use rustc_middle::bug;
@@ -98,12 +98,12 @@ impl<'tcx> crate::MirPass<'tcx> for ForceInline {
 }
 
 trait Inliner<'tcx> {
-    fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<'tcx>) -> Self;
+    fn new(tcx: TyCtxt<'tcx>, def_id: DefId, body: &Body<'tcx>) -> Self;
 
     fn tcx(&self) -> TyCtxt<'tcx>;
     fn typing_env(&self) -> ty::TypingEnv<'tcx>;
     fn history(&self) -> &[DefId];
-    fn caller_def_id(&self) -> LocalDefId;
+    fn caller_def_id(&self) -> DefId;
 
     /// Has the caller body been changed?
     fn changed(self) -> bool;
@@ -146,7 +146,7 @@ struct ForceInliner<'tcx> {
     tcx: TyCtxt<'tcx>,
     typing_env: ty::TypingEnv<'tcx>,
     /// `DefId` of caller.
-    def_id: LocalDefId,
+    def_id: DefId,
     /// Stack of inlined instances.
     /// We only check the `DefId` and not the args because we want to
     /// avoid inlining cases of polymorphic recursion.
@@ -158,7 +158,7 @@ struct ForceInliner<'tcx> {
 }
 
 impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
-    fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<'tcx>) -> Self {
+    fn new(tcx: TyCtxt<'tcx>, def_id: DefId, body: &Body<'tcx>) -> Self {
         Self { tcx, typing_env: body.typing_env(tcx), def_id, history: Vec::new(), changed: false }
     }
 
@@ -174,7 +174,7 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
         &self.history
     }
 
-    fn caller_def_id(&self) -> LocalDefId {
+    fn caller_def_id(&self) -> DefId {
         self.def_id
     }
 
@@ -248,7 +248,7 @@ struct NormalInliner<'tcx> {
     tcx: TyCtxt<'tcx>,
     typing_env: ty::TypingEnv<'tcx>,
     /// `DefId` of caller.
-    def_id: LocalDefId,
+    def_id: DefId,
     /// Stack of inlined instances.
     /// We only check the `DefId` and not the args because we want to
     /// avoid inlining cases of polymorphic recursion.
@@ -263,7 +263,7 @@ struct NormalInliner<'tcx> {
 }
 
 impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
-    fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<'tcx>) -> Self {
+    fn new(tcx: TyCtxt<'tcx>, def_id: DefId, body: &Body<'tcx>) -> Self {
         let typing_env = body.typing_env(tcx);
         let codegen_fn_attrs = tcx.codegen_fn_attrs(def_id);
 
@@ -284,7 +284,7 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
         self.tcx
     }
 
-    fn caller_def_id(&self) -> LocalDefId {
+    fn caller_def_id(&self) -> DefId {
         self.def_id
     }
 
@@ -442,7 +442,7 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
 }
 
 fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
-    let def_id = body.source.def_id().expect_local();
+    let def_id = body.source.def_id();
 
     // Only do inlining into fn bodies.
     if !tcx.hir().body_owner_kind(def_id).is_fn_or_closure() {
@@ -723,7 +723,11 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
         return Ok(());
     }
 
-    if callee_def_id.is_local() {
+    if callee_def_id.is_local()
+        && !inliner
+            .tcx()
+            .is_lang_item(inliner.tcx().parent(caller_def_id), rustc_hir::LangItem::FnOnce)
+    {
         // If we know for sure that the function we're calling will itself try to
         // call us, then we avoid inlining that function.
         if inliner.tcx().mir_callgraph_reachable((callee, caller_def_id.expect_local())) {