@@ -9,6 +9,7 @@ use rustc_middle::mir::visit::*;
99use rustc_middle:: mir:: * ;
1010use rustc_middle:: ty:: subst:: Subst ;
1111use rustc_middle:: ty:: { self , ConstKind , Instance , InstanceDef , ParamEnv , Ty , TyCtxt } ;
12+ use rustc_session:: config:: OptLevel ;
1213use rustc_span:: { hygiene:: ExpnKind , ExpnData , LocalExpnId , Span } ;
1314use rustc_target:: spec:: abi:: Abi ;
1415
@@ -43,7 +44,15 @@ impl<'tcx> MirPass<'tcx> for Inline {
4344 return enabled;
4445 }
4546
46- sess. opts . mir_opt_level ( ) >= 3
47+ match sess. mir_opt_level ( ) {
48+ 0 | 1 => false ,
49+ 2 => {
50+ ( sess. opts . optimize == OptLevel :: Default
51+ || sess. opts . optimize == OptLevel :: Aggressive )
52+ && sess. opts . incremental == None
53+ }
54+ _ => true ,
55+ }
4756 }
4857
4958 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
@@ -321,8 +330,14 @@ impl<'tcx> Inliner<'tcx> {
321330 callsite : & CallSite < ' tcx > ,
322331 callee_attrs : & CodegenFnAttrs ,
323332 ) -> Result < ( ) , & ' static str > {
324- if let InlineAttr :: Never = callee_attrs. inline {
325- return Err ( "never inline hint" ) ;
333+ match callee_attrs. inline {
334+ InlineAttr :: Never => return Err ( "never inline hint" ) ,
335+ InlineAttr :: Always => { }
336+ _ => {
337+ if self . tcx . sess . mir_opt_level ( ) <= 2 {
338+ return Err ( "at mir-opt-level=2, only #[inline(always)] is inlined" ) ;
339+ }
340+ }
326341 }
327342
328343 // Only inline local functions if they would be eligible for cross-crate
@@ -505,14 +520,12 @@ impl<'tcx> Inliner<'tcx> {
505520 if let InlineAttr :: Always = callee_attrs. inline {
506521 debug ! ( "INLINING {:?} because inline(always) [cost={}]" , callsite, cost) ;
507522 Ok ( ( ) )
523+ } else if cost <= threshold {
524+ debug ! ( "INLINING {:?} [cost={} <= threshold={}]" , callsite, cost, threshold) ;
525+ Ok ( ( ) )
508526 } else {
509- if cost <= threshold {
510- debug ! ( "INLINING {:?} [cost={} <= threshold={}]" , callsite, cost, threshold) ;
511- Ok ( ( ) )
512- } else {
513- debug ! ( "NOT inlining {:?} [cost={} > threshold={}]" , callsite, cost, threshold) ;
514- Err ( "cost above threshold" )
515- }
527+ debug ! ( "NOT inlining {:?} [cost={} > threshold={}]" , callsite, cost, threshold) ;
528+ Err ( "cost above threshold" )
516529 }
517530 }
518531
0 commit comments