@@ -76,9 +76,13 @@ impl<'tcx> crate::MirPass<'tcx> for Inline {
7676pub struct ForceInline ;
7777
7878impl ForceInline {
79- pub fn should_run_pass_for_callee < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
79+ pub fn needs_callgraph_for_callee < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
8080 matches ! ( tcx. codegen_fn_attrs( def_id) . inline, InlineAttr :: Force { .. } )
8181 }
82+
83+ pub fn applies_for_resolved_callee < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
84+ matches ! ( tcx. codegen_fn_attrs( def_id) . inline, InlineAttr :: Force { .. } | InlineAttr :: Early )
85+ }
8286}
8387
8488impl < ' tcx > crate :: MirPass < ' tcx > for ForceInline {
@@ -117,7 +121,7 @@ trait Inliner<'tcx> {
117121 fn changed ( self ) -> bool ;
118122
119123 /// Should inlining happen for a given callee?
120- fn should_inline_for_callee ( & self , def_id : DefId ) -> bool ;
124+ fn should_inline_for_callee ( & self , instance_kind : & InstanceKind < ' tcx > ) -> bool ;
121125
122126 fn check_codegen_attributes_extra (
123127 & self ,
@@ -187,15 +191,22 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
187191 self . changed
188192 }
189193
190- fn should_inline_for_callee ( & self , def_id : DefId ) -> bool {
191- ForceInline :: should_run_pass_for_callee ( self . tcx ( ) , def_id)
194+ fn should_inline_for_callee ( & self , instance_kind : & InstanceKind < ' tcx > ) -> bool {
195+ if let InstanceKind :: Item ( def_id) = instance_kind
196+ && let InlineAttr :: Force { .. } | InlineAttr :: Early =
197+ self . tcx ( ) . codegen_fn_attrs ( def_id) . inline
198+ {
199+ true
200+ } else {
201+ false
202+ }
192203 }
193204
194205 fn check_codegen_attributes_extra (
195206 & self ,
196207 callee_attrs : & CodegenFnAttrs ,
197208 ) -> Result < ( ) , & ' static str > {
198- debug_assert_matches ! ( callee_attrs. inline, InlineAttr :: Force { .. } ) ;
209+ debug_assert_matches ! ( callee_attrs. inline, InlineAttr :: Force { .. } | InlineAttr :: Early ) ;
199210 Ok ( ( ) )
200211 }
201212
@@ -247,23 +258,26 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
247258
248259 fn on_inline_failure ( & self , callsite : & CallSite < ' tcx > , reason : & ' static str ) {
249260 let tcx = self . tcx ( ) ;
250- let InlineAttr :: Force { attr_span, reason : justification } =
251- tcx. codegen_fn_attrs ( callsite. callee . def_id ( ) ) . inline
252- else {
253- bug ! ( "called on item without required inlining" ) ;
254- } ;
255-
256- let call_span = callsite. source_info . span ;
257- tcx. dcx ( ) . emit_err ( crate :: errors:: ForceInlineFailure {
258- call_span,
259- attr_span,
260- caller_span : tcx. def_span ( self . def_id ) ,
261- caller : tcx. def_path_str ( self . def_id ) ,
262- callee_span : tcx. def_span ( callsite. callee . def_id ( ) ) ,
263- callee : tcx. def_path_str ( callsite. callee . def_id ( ) ) ,
264- reason,
265- justification : justification. map ( |sym| crate :: errors:: ForceInlineJustification { sym } ) ,
266- } ) ;
261+ match tcx. codegen_fn_attrs ( callsite. callee . def_id ( ) ) . inline {
262+ InlineAttr :: Early => {
263+ // Ok, we don't actually mind if this fails.
264+ }
265+ InlineAttr :: Force { attr_span, reason : justification } => {
266+ let call_span = callsite. source_info . span ;
267+ tcx. dcx ( ) . emit_err ( crate :: errors:: ForceInlineFailure {
268+ call_span,
269+ attr_span,
270+ caller_span : tcx. def_span ( self . def_id ) ,
271+ caller : tcx. def_path_str ( self . def_id ) ,
272+ callee_span : tcx. def_span ( callsite. callee . def_id ( ) ) ,
273+ callee : tcx. def_path_str ( callsite. callee . def_id ( ) ) ,
274+ reason,
275+ justification : justification
276+ . map ( |sym| crate :: errors:: ForceInlineJustification { sym } ) ,
277+ } ) ;
278+ }
279+ _ => bug ! ( "called on item without required inlining" ) ,
280+ }
267281 }
268282}
269283
@@ -334,7 +348,7 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
334348 self . changed
335349 }
336350
337- fn should_inline_for_callee ( & self , _: DefId ) -> bool {
351+ fn should_inline_for_callee ( & self , _: & InstanceKind < ' tcx > ) -> bool {
338352 true
339353 }
340354
@@ -556,16 +570,16 @@ fn resolve_callsite<'tcx, I: Inliner<'tcx>>(
556570 if let TerminatorKind :: Call { ref func, fn_span, .. } = terminator. kind {
557571 let func_ty = func. ty ( caller_body, tcx) ;
558572 if let ty:: FnDef ( def_id, args) = * func_ty. kind ( ) {
559- if !inliner. should_inline_for_callee ( def_id) {
560- debug ! ( "not enabled" ) ;
561- return None ;
562- }
563-
564573 // To resolve an instance its args have to be fully normalized.
565574 let args = tcx. try_normalize_erasing_regions ( inliner. typing_env ( ) , args) . ok ( ) ?;
566575 let callee =
567576 Instance :: try_resolve ( tcx, inliner. typing_env ( ) , def_id, args) . ok ( ) . flatten ( ) ?;
568577
578+ if !inliner. should_inline_for_callee ( & callee. def ) {
579+ debug ! ( "not enabled" ) ;
580+ return None ;
581+ }
582+
569583 if let InstanceKind :: Virtual ( ..) | InstanceKind :: Intrinsic ( _) = callee. def {
570584 return None ;
571585 }
0 commit comments