@@ -124,8 +124,6 @@ trait Inliner<'tcx> {
124124 callee_attrs : & CodegenFnAttrs ,
125125 ) -> Result < ( ) , & ' static str > ;
126126
127- fn check_caller_mir_body ( & self , body : & Body < ' tcx > ) -> bool ;
128-
129127 /// Returns inlining decision that is based on the examination of callee MIR body.
130128 /// Assumes that codegen attributes have been checked for compatibility already.
131129 fn check_callee_mir_body (
@@ -199,10 +197,6 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
199197 Ok ( ( ) )
200198 }
201199
202- fn check_caller_mir_body ( & self , _: & Body < ' tcx > ) -> bool {
203- true
204- }
205-
206200 #[ instrument( level = "debug" , skip( self , callee_body) ) ]
207201 fn check_callee_mir_body (
208202 & self ,
@@ -349,17 +343,6 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
349343 }
350344 }
351345
352- fn check_caller_mir_body ( & self , body : & Body < ' tcx > ) -> bool {
353- // Avoid inlining into coroutines, since their `optimized_mir` is used for layout computation,
354- // which can create a cycle, even when no attempt is made to inline the function in the other
355- // direction.
356- if body. coroutine . is_some ( ) {
357- return false ;
358- }
359-
360- true
361- }
362-
363346 #[ instrument( level = "debug" , skip( self , callee_body) ) ]
364347 fn check_callee_mir_body (
365348 & self ,
@@ -502,10 +485,6 @@ fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> b
502485 }
503486
504487 let mut inliner = T :: new ( tcx, def_id, body) ;
505- if !inliner. check_caller_mir_body ( body) {
506- return false ;
507- }
508-
509488 let blocks = START_BLOCK ..body. basic_blocks . next_index ( ) ;
510489 process_blocks ( & mut inliner, body, blocks) ;
511490 inliner. changed ( )
@@ -774,11 +753,12 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
774753 && !inliner
775754 . tcx ( )
776755 . is_lang_item ( inliner. tcx ( ) . parent ( caller_def_id) , rustc_hir:: LangItem :: FnOnce )
756+ // The caller may be a shim.
757+ && let Some ( caller_def_id) = caller_def_id. as_local ( )
777758 {
778759 // If we know for sure that the function we're calling will itself try to
779760 // call us, then we avoid inlining that function.
780- if inliner. tcx ( ) . mir_callgraph_cyclic ( caller_def_id. expect_local ( ) ) . contains ( & callee_def_id)
781- {
761+ if inliner. tcx ( ) . mir_callgraph_cyclic ( caller_def_id) . contains ( & callee_def_id) {
782762 debug ! ( "query cycle avoidance" ) ;
783763 return Err ( "caller might be reachable from callee" ) ;
784764 }
0 commit comments