Skip to content

Commit d1d9092

Browse files
wesleywisercjgillot
authored andcommitted
Test enabling MIR inliner
1 parent b33c6e1 commit d1d9092

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Diff for: compiler/rustc_mir_transform/src/inline.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::mir::visit::*;
99
use rustc_middle::mir::*;
1010
use rustc_middle::ty::subst::Subst;
1111
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
12+
use rustc_session::config::OptLevel;
1213
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
1314
use 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

Diff for: src/test/ui/polymorphization/generators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// build-fail
2-
// compile-flags:-Zpolymorphize=on
2+
// compile-flags:-Zpolymorphize=on -Zinline-mir=off
33
#![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
44
//~^ WARN the feature `generic_const_exprs` is incomplete
55

0 commit comments

Comments
 (0)