Skip to content

Commit 8ea2dd0

Browse files
committed
Enable MIR inlinig for #[inline(always)] when mir-opt-level=1
1 parent 0f0d5d7 commit 8ea2dd0

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

compiler/rustc_mir_transform/src/inline.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
4545
return enabled;
4646
}
4747

48-
match sess.mir_opt_level() {
49-
0 | 1 => false,
50-
2 => {
51-
(sess.opts.optimize == OptLevel::Default
52-
|| sess.opts.optimize == OptLevel::Aggressive)
53-
&& sess.opts.incremental == None
54-
}
55-
_ => true,
56-
}
48+
sess.mir_opt_level() > 0
5749
}
5850

5951
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -341,7 +333,23 @@ impl<'tcx> Inliner<'tcx> {
341333
) -> Result<(), &'static str> {
342334
match callee_attrs.inline {
343335
InlineAttr::Never => return Err("never inline hint"),
344-
InlineAttr::Always | InlineAttr::Hint => {}
336+
InlineAttr::Always => {}
337+
InlineAttr::Hint => match self.tcx.sess.mir_opt_level() {
338+
0 | 1 => return Err("at mir-opt-level=1, only #[inline(always)] is inlined"),
339+
2 if self.tcx.sess.opts.optimize != OptLevel::Default
340+
&& self.tcx.sess.opts.optimize != OptLevel::Aggressive =>
341+
{
342+
return Err(
343+
"at mir-opt-level=2, only #[inline(always)] is inlined when opt-level<2",
344+
);
345+
}
346+
2 if self.tcx.sess.opts.incremental != None => {
347+
return Err(
348+
"at mir-opt-level=2, only #[inline(always)] is inlined when incremental compilation is enabled",
349+
);
350+
}
351+
_ => {}
352+
},
345353
InlineAttr::None => {
346354
if self.tcx.sess.mir_opt_level() <= 2 {
347355
return Err("at mir-opt-level=2, only #[inline] is inlined");

src/test/codegen-units/partitioning/inlining-from-extern-crate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// incremental
55
// compile-flags:-Zprint-mono-items=lazy
66
// compile-flags:-Zinline-in-all-cgus
7+
// To keep mir from doing any inlining
8+
// compile-flags:-Zmir-opt-level=0
79

810
#![crate_type="lib"]
911

src/test/codegen-units/partitioning/local-inlining.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// incremental
55
// compile-flags:-Zprint-mono-items=lazy
66
// compile-flags:-Zinline-in-all-cgus
7+
// To keep mir from doing any inlining
8+
// compile-flags:-Zmir-opt-level=0
79

810
#![allow(dead_code)]
911
#![crate_type="lib"]

src/test/codegen-units/partitioning/local-transitive-inlining.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// incremental
55
// compile-flags:-Zprint-mono-items=lazy
66
// compile-flags:-Zinline-in-all-cgus
7+
// To keep mir from doing any inlining
8+
// compile-flags:-Zmir-opt-level=0
79

810
#![allow(dead_code)]
911
#![crate_type="rlib"]

src/test/incremental/hashes/function_interfaces.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// build-pass (FIXME(62277): could be check-pass?)
99
// revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6
1010
// compile-flags: -Z query-dep-graph -O
11+
// To keep mir from doing any inlining
12+
// compile-flags: -Z mir-opt-level=0
1113
// [cfail1]compile-flags: -Zincremental-ignore-spans
1214
// [cfail2]compile-flags: -Zincremental-ignore-spans
1315
// [cfail3]compile-flags: -Zincremental-ignore-spans

0 commit comments

Comments
 (0)