@@ -124,8 +124,6 @@ trait Inliner<'tcx> {
124
124
callee_attrs : & CodegenFnAttrs ,
125
125
) -> Result < ( ) , & ' static str > ;
126
126
127
- fn check_caller_mir_body ( & self , body : & Body < ' tcx > ) -> bool ;
128
-
129
127
/// Returns inlining decision that is based on the examination of callee MIR body.
130
128
/// Assumes that codegen attributes have been checked for compatibility already.
131
129
fn check_callee_mir_body (
@@ -199,10 +197,6 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
199
197
Ok ( ( ) )
200
198
}
201
199
202
- fn check_caller_mir_body ( & self , _: & Body < ' tcx > ) -> bool {
203
- true
204
- }
205
-
206
200
#[ instrument( level = "debug" , skip( self , callee_body) ) ]
207
201
fn check_callee_mir_body (
208
202
& self ,
@@ -349,17 +343,6 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
349
343
}
350
344
}
351
345
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
-
363
346
#[ instrument( level = "debug" , skip( self , callee_body) ) ]
364
347
fn check_callee_mir_body (
365
348
& self ,
@@ -502,10 +485,6 @@ fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> b
502
485
}
503
486
504
487
let mut inliner = T :: new ( tcx, def_id, body) ;
505
- if !inliner. check_caller_mir_body ( body) {
506
- return false ;
507
- }
508
-
509
488
let blocks = START_BLOCK ..body. basic_blocks . next_index ( ) ;
510
489
process_blocks ( & mut inliner, body, blocks) ;
511
490
inliner. changed ( )
@@ -774,11 +753,12 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
774
753
&& !inliner
775
754
. tcx ( )
776
755
. 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 ( )
777
758
{
778
759
// If we know for sure that the function we're calling will itself try to
779
760
// 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) {
782
762
debug ! ( "query cycle avoidance" ) ;
783
763
return Err ( "caller might be reachable from callee" ) ;
784
764
}
0 commit comments