@@ -43,7 +43,14 @@ crate fn is_enabled(tcx: TyCtxt<'_>) -> bool {
43
43
return enabled;
44
44
}
45
45
46
- tcx. sess . mir_opt_level ( ) >= 3
46
+ // If you change this optimization level, also change the level in
47
+ // `mir_drops_elaborated_and_const_checked` for the call to `mir_inliner_callees`.
48
+ // Otherwise you will get an ICE about stolen MIR.
49
+ match tcx. sess . mir_opt_level ( ) {
50
+ 0 | 1 => false ,
51
+ 2 => tcx. sess . opts . incremental == None ,
52
+ _ => true ,
53
+ }
47
54
}
48
55
49
56
impl < ' tcx > MirPass < ' tcx > for Inline {
@@ -325,6 +332,17 @@ impl Inliner<'tcx> {
325
332
}
326
333
}
327
334
335
+ // At mir-opt-level=1, only inline `#[inline(always)]` functions
336
+ if self . tcx . sess . mir_opt_level ( ) == 1 && callee_attrs. inline != InlineAttr :: Always {
337
+ return Err ( "at mir-opt-level=1, only inline(always) is inlined" ) ;
338
+ }
339
+
340
+ if self . tcx . sess . mir_opt_level ( ) == 1
341
+ && self . tcx . sess . opts . optimize != rustc_session:: config:: OptLevel :: Aggressive
342
+ {
343
+ return Err ( "at mir-opt-level=1, only inline if -O is specified" ) ;
344
+ }
345
+
328
346
Ok ( ( ) )
329
347
}
330
348
@@ -470,8 +488,24 @@ impl Inliner<'tcx> {
470
488
}
471
489
472
490
if let InlineAttr :: Always = callee_attrs. inline {
473
- debug ! ( "INLINING {:?} because inline(always) [cost={}]" , callsite, cost) ;
474
- Ok ( ( ) )
491
+ if self . tcx . sess . mir_opt_level ( ) == 1 {
492
+ if cost <= 25 {
493
+ debug ! (
494
+ "INLINING {:?} because inline(always) and [cost={} <= threshold=25]" ,
495
+ callsite, cost
496
+ ) ;
497
+ Ok ( ( ) )
498
+ } else {
499
+ debug ! (
500
+ "NOT inlining {:?} because inline(always) but [cost={} > threshold=25]" ,
501
+ callsite, cost
502
+ ) ;
503
+ Err ( "cost above threshold" )
504
+ }
505
+ } else {
506
+ debug ! ( "INLINING {:?} because inline(always) [cost={}]" , callsite, cost) ;
507
+ Ok ( ( ) )
508
+ }
475
509
} else {
476
510
if cost <= threshold {
477
511
debug ! ( "INLINING {:?} [cost={} <= threshold={}]" , callsite, cost, threshold) ;
0 commit comments