@@ -121,8 +121,6 @@ trait Inliner<'tcx> {
121121 callee_attrs : & CodegenFnAttrs ,
122122 ) -> Result < ( ) , & ' static str > ;
123123
124- fn check_caller_mir_body ( & self , body : & Body < ' tcx > ) -> bool ;
125-
126124 /// Returns inlining decision that is based on the examination of callee MIR body.
127125 /// Assumes that codegen attributes have been checked for compatibility already.
128126 fn check_callee_mir_body (
@@ -196,10 +194,6 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
196194 Ok ( ( ) )
197195 }
198196
199- fn check_caller_mir_body ( & self , _: & Body < ' tcx > ) -> bool {
200- true
201- }
202-
203197 #[ instrument( level = "debug" , skip( self , callee_body) ) ]
204198 fn check_callee_mir_body (
205199 & self ,
@@ -346,17 +340,6 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
346340 }
347341 }
348342
349- fn check_caller_mir_body ( & self , body : & Body < ' tcx > ) -> bool {
350- // Avoid inlining into coroutines, since their `optimized_mir` is used for layout computation,
351- // which can create a cycle, even when no attempt is made to inline the function in the other
352- // direction.
353- if body. coroutine . is_some ( ) {
354- return false ;
355- }
356-
357- true
358- }
359-
360343 #[ instrument( level = "debug" , skip( self , callee_body) ) ]
361344 fn check_callee_mir_body (
362345 & self ,
@@ -499,10 +482,6 @@ fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> b
499482 }
500483
501484 let mut inliner = T :: new ( tcx, def_id, body) ;
502- if !inliner. check_caller_mir_body ( body) {
503- return false ;
504- }
505-
506485 let blocks = START_BLOCK ..body. basic_blocks . next_index ( ) ;
507486 process_blocks ( & mut inliner, body, blocks) ;
508487 inliner. changed ( )
@@ -771,11 +750,12 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
771750 && !inliner
772751 . tcx ( )
773752 . is_lang_item ( inliner. tcx ( ) . parent ( caller_def_id) , rustc_hir:: LangItem :: FnOnce )
753+ // The caller may be a shim.
754+ && let Some ( caller_def_id) = caller_def_id. as_local ( )
774755 {
775756 // If we know for sure that the function we're calling will itself try to
776757 // call us, then we avoid inlining that function.
777- if inliner. tcx ( ) . mir_callgraph_cyclic ( caller_def_id. expect_local ( ) ) . contains ( & callee_def_id)
778- {
758+ if inliner. tcx ( ) . mir_callgraph_cyclic ( caller_def_id) . contains ( & callee_def_id) {
779759 debug ! ( "query cycle avoidance" ) ;
780760 return Err ( "caller might be reachable from callee" ) ;
781761 }
0 commit comments