@@ -37,21 +37,27 @@ struct CallSite<'tcx> {
37
37
source_info : SourceInfo ,
38
38
}
39
39
40
+ /// Returns true if MIR inlining is enabled in the current compilation session.
41
+ crate fn is_enabled ( tcx : TyCtxt < ' _ > ) -> bool {
42
+ if tcx. sess . opts . debugging_opts . instrument_coverage {
43
+ // Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage
44
+ // counters can be invalidated, such as by merging coverage counter statements from
45
+ // a pre-inlined function into a different function. This kind of change is invalid,
46
+ // so inlining must be skipped. Note: This check is performed here so inlining can
47
+ // be disabled without preventing other optimizations (regardless of `mir_opt_level`).
48
+ return false ;
49
+ }
50
+
51
+ if let Some ( enabled) = tcx. sess . opts . debugging_opts . inline_mir {
52
+ return enabled;
53
+ }
54
+
55
+ tcx. sess . opts . debugging_opts . mir_opt_level >= 2
56
+ }
57
+
40
58
impl < ' tcx > MirPass < ' tcx > for Inline {
41
59
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
42
- // If you change this optimization level, also change the level in
43
- // `mir_drops_elaborated_and_const_checked` for the call to `mir_inliner_callees`.
44
- // Otherwise you will get an ICE about stolen MIR.
45
- if tcx. sess . opts . debugging_opts . mir_opt_level < 2 {
46
- return ;
47
- }
48
-
49
- if tcx. sess . opts . debugging_opts . instrument_coverage {
50
- // Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage
51
- // counters can be invalidated, such as by merging coverage counter statements from
52
- // a pre-inlined function into a different function. This kind of change is invalid,
53
- // so inlining must be skipped. Note: This check is performed here so inlining can
54
- // be disabled without preventing other optimizations (regardless of `mir_opt_level`).
60
+ if !is_enabled ( tcx) {
55
61
return ;
56
62
}
57
63
0 commit comments