From 03c6364160316fb0625877e26fe471973599b3c6 Mon Sep 17 00:00:00 2001 From: oli Date: Sat, 23 Jan 2021 13:49:20 +0000 Subject: [PATCH] Move test to mir-opt so we actually see that no inlining is happening --- src/test/mir-opt/inline/cycle.f.Inline.diff | 42 +++++++++++++++++++ src/test/mir-opt/inline/cycle.g.Inline.diff | 25 +++++++++++ .../mir-opt/inline/cycle.main.Inline.diff | 25 +++++++++++ .../inline/cycle.rs} | 7 ++-- 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 src/test/mir-opt/inline/cycle.f.Inline.diff create mode 100644 src/test/mir-opt/inline/cycle.g.Inline.diff create mode 100644 src/test/mir-opt/inline/cycle.main.Inline.diff rename src/test/{ui/inline_cycle.rs => mir-opt/inline/cycle.rs} (50%) diff --git a/src/test/mir-opt/inline/cycle.f.Inline.diff b/src/test/mir-opt/inline/cycle.f.Inline.diff new file mode 100644 index 00000000000..4f7924170b4 --- /dev/null +++ b/src/test/mir-opt/inline/cycle.f.Inline.diff @@ -0,0 +1,42 @@ +- // MIR for `f` before Inline ++ // MIR for `f` after Inline + + fn f(_1: impl Fn()) -> () { + debug g => _1; // in scope 0 at $DIR/cycle.rs:3:6: 3:7 + let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:3:20: 3:20 + let _2: (); // in scope 0 at $DIR/cycle.rs:4:5: 4:8 + let mut _3: &impl Fn(); // in scope 0 at $DIR/cycle.rs:4:5: 4:6 + let mut _4: (); // in scope 0 at $DIR/cycle.rs:4:5: 4:8 + + bb0: { + StorageLive(_2); // scope 0 at $DIR/cycle.rs:4:5: 4:8 + StorageLive(_3); // scope 0 at $DIR/cycle.rs:4:5: 4:6 + _3 = &_1; // scope 0 at $DIR/cycle.rs:4:5: 4:6 + StorageLive(_4); // scope 0 at $DIR/cycle.rs:4:5: 4:8 + _2 = >::call(move _3, move _4) -> [return: bb1, unwind: bb3]; // scope 0 at $DIR/cycle.rs:4:5: 4:8 + // mir::Constant + // + span: $DIR/cycle.rs:4:5: 4:6 + // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r impl Fn(), ()) -> >::Output {>::call}, val: Value(Scalar()) } + } + + bb1: { + StorageDead(_4); // scope 0 at $DIR/cycle.rs:4:7: 4:8 + StorageDead(_3); // scope 0 at $DIR/cycle.rs:4:7: 4:8 + StorageDead(_2); // scope 0 at $DIR/cycle.rs:4:8: 4:9 + _0 = const (); // scope 0 at $DIR/cycle.rs:3:20: 5:2 + drop(_1) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/cycle.rs:5:1: 5:2 + } + + bb2: { + return; // scope 0 at $DIR/cycle.rs:5:2: 5:2 + } + + bb3 (cleanup): { + drop(_1) -> bb4; // scope 0 at $DIR/cycle.rs:5:1: 5:2 + } + + bb4 (cleanup): { + resume; // scope 0 at $DIR/cycle.rs:3:1: 5:2 + } + } + diff --git a/src/test/mir-opt/inline/cycle.g.Inline.diff b/src/test/mir-opt/inline/cycle.g.Inline.diff new file mode 100644 index 00000000000..4fbdce3eb0a --- /dev/null +++ b/src/test/mir-opt/inline/cycle.g.Inline.diff @@ -0,0 +1,25 @@ +- // MIR for `g` before Inline ++ // MIR for `g` after Inline + + fn g() -> () { + let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:9:8: 9:8 + let _1: (); // in scope 0 at $DIR/cycle.rs:10:5: 10:12 + + bb0: { + StorageLive(_1); // scope 0 at $DIR/cycle.rs:10:5: 10:12 + _1 = f::(main) -> bb1; // scope 0 at $DIR/cycle.rs:10:5: 10:12 + // mir::Constant + // + span: $DIR/cycle.rs:10:5: 10:6 + // + literal: Const { ty: fn(fn() {main}) {f::}, val: Value(Scalar()) } + // mir::Constant + // + span: $DIR/cycle.rs:10:7: 10:11 + // + literal: Const { ty: fn() {main}, val: Value(Scalar()) } + } + + bb1: { + StorageDead(_1); // scope 0 at $DIR/cycle.rs:10:12: 10:13 + _0 = const (); // scope 0 at $DIR/cycle.rs:9:8: 11:2 + return; // scope 0 at $DIR/cycle.rs:11:2: 11:2 + } + } + diff --git a/src/test/mir-opt/inline/cycle.main.Inline.diff b/src/test/mir-opt/inline/cycle.main.Inline.diff new file mode 100644 index 00000000000..3c7dfc2494e --- /dev/null +++ b/src/test/mir-opt/inline/cycle.main.Inline.diff @@ -0,0 +1,25 @@ +- // MIR for `main` before Inline ++ // MIR for `main` after Inline + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:14:11: 14:11 + let _1: (); // in scope 0 at $DIR/cycle.rs:15:5: 15:9 + + bb0: { + StorageLive(_1); // scope 0 at $DIR/cycle.rs:15:5: 15:9 + _1 = f::(g) -> bb1; // scope 0 at $DIR/cycle.rs:15:5: 15:9 + // mir::Constant + // + span: $DIR/cycle.rs:15:5: 15:6 + // + literal: Const { ty: fn(fn() {g}) {f::}, val: Value(Scalar()) } + // mir::Constant + // + span: $DIR/cycle.rs:15:7: 15:8 + // + literal: Const { ty: fn() {g}, val: Value(Scalar()) } + } + + bb1: { + StorageDead(_1); // scope 0 at $DIR/cycle.rs:15:9: 15:10 + _0 = const (); // scope 0 at $DIR/cycle.rs:14:11: 16:2 + return; // scope 0 at $DIR/cycle.rs:16:2: 16:2 + } + } + diff --git a/src/test/ui/inline_cycle.rs b/src/test/mir-opt/inline/cycle.rs similarity index 50% rename from src/test/ui/inline_cycle.rs rename to src/test/mir-opt/inline/cycle.rs index 60767f10660..0be6fec99dd 100644 --- a/src/test/ui/inline_cycle.rs +++ b/src/test/mir-opt/inline/cycle.rs @@ -1,17 +1,16 @@ -// Needs build-pass to trigger `optimized_mir` on all mir bodies -// build-pass -// compile-flags: -Zmir-opt-level=2 - +// EMIT_MIR cycle.f.Inline.diff #[inline(always)] fn f(g: impl Fn()) { g(); } +// EMIT_MIR cycle.g.Inline.diff #[inline(always)] fn g() { f(main); } +// EMIT_MIR cycle.main.Inline.diff fn main() { f(g); }