Skip to content

Commit

Permalink
Auto merge of #117029 - rmehri01:mir_opt_filecheck_inline_tests, r=cj…
Browse files Browse the repository at this point in the history
…gillot

Add FileCheck annotations to MIR-opt inlining tests

Part of #116971, adds FileCheck annotations to MIR-opt tests in `tests/mir-opt/inline`.

I left out a few (such as `inline_cycle`) where it mentioned that the particular outcome of inlining isn't important, just that the inliner doesn't get stuck in an infinite loop.

r? cjgillot
  • Loading branch information
bors committed Nov 1, 2023
2 parents b0a0759 + 5f75326 commit 75b064d
Show file tree
Hide file tree
Showing 29 changed files with 156 additions and 51 deletions.
6 changes: 5 additions & 1 deletion tests/mir-opt/inline/asm_unwind.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// skip-filecheck
// Tests inlining of `may_unwind` inline assembly.
//
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// needs-asm-support
// needs-unwind
// compile-flags: -Zinline-mir-hint-threshold=1000
#![feature(asm_unwind)]

Expand All @@ -20,5 +20,9 @@ fn foo() {

// EMIT_MIR asm_unwind.main.Inline.diff
pub fn main() {
// CHECK-LABEL: fn main(
// CHECK: (inlined foo)
// CHECK: asm!("", options(MAY_UNWIND)) -> [return: {{bb.*}}, unwind: [[unwind:bb.*]]];
// CHECK: [[unwind]] (cleanup)
foo();
}
6 changes: 5 additions & 1 deletion tests/mir-opt/inline/caller_with_trivial_bound.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// needs-unwind

Expand All @@ -16,8 +15,13 @@ impl<T> Factory<T> for IntFactory {
// EMIT_MIR caller_with_trivial_bound.foo.Inline.diff
pub fn foo<T>()
where
// Because of this trivial bound, the inliner fails to normalize
// `<IntFactory as Factory<T>>::Item`.
// Verify that we do not inline anything, which would cause validation ICEs.
IntFactory: Factory<T>,
{
// CHECK-LABEL: fn foo(
// CHECK-NOT: (inlined bar::<T>)
let mut x: <IntFactory as Factory<T>>::Item = bar::<T>();
}

Expand Down
11 changes: 10 additions & 1 deletion tests/mir-opt/inline/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// compile-flags: -Zinline-mir-hint-threshold=1000

// EMIT_MIR cycle.f.Inline.diff
#[inline(always)]
fn f(g: impl Fn()) {
// CHECK-LABEL: fn f(
// CHECK-NOT: inlined
g();
}

// EMIT_MIR cycle.g.Inline.diff
#[inline(always)]
fn g() {
// CHECK-LABEL: fn g(
// CHECK-NOT: inlined
// CHECK: (inlined f::<fn() {main}>)
// CHECK-NOT: inlined
f(main);
}

// EMIT_MIR cycle.main.Inline.diff
fn main() {
// CHECK-LABEL: fn main(
// CHECK-NOT: inlined
// CHECK: (inlined f::<fn() {g}>)
// CHECK-NOT: inlined
f(g);
}
3 changes: 2 additions & 1 deletion tests/mir-opt/inline/dont_ice_on_generic_rust_call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// compile-flags: -Zmir-enable-passes=+Inline --crate-type=lib

Expand All @@ -8,5 +7,7 @@ use std::marker::Tuple;

// EMIT_MIR dont_ice_on_generic_rust_call.call.Inline.diff
pub fn call<I: Tuple>(mut mock: Box<dyn FnMut<I, Output = ()>>, input: I) {
// CHECK-LABEL: fn call(
// CHECK-NOT: inlined
mock.call_mut(input)
}
9 changes: 8 additions & 1 deletion tests/mir-opt/inline/dyn_trait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
#![crate_type = "lib"]

Expand All @@ -20,18 +19,26 @@ pub trait Query {
// EMIT_MIR dyn_trait.mk_cycle.Inline.diff
#[inline(always)]
pub fn mk_cycle<V: Debug>(c: &dyn Cache<V = V>) {
// CHECK-LABEL: fn mk_cycle(
// CHECK-NOT: inlined
c.store_nocache()
}

// EMIT_MIR dyn_trait.try_execute_query.Inline.diff
#[inline(always)]
pub fn try_execute_query<C: Cache>(c: &C) {
// CHECK-LABEL: fn try_execute_query(
// CHECK: (inlined mk_cycle::<<C as Cache>::V>)
mk_cycle(c)
}

// EMIT_MIR dyn_trait.get_query.Inline.diff
#[inline(always)]
pub fn get_query<Q: Query, T>(t: &T) {
// CHECK-LABEL: fn get_query(
// CHECK-NOT: inlined
let c = Q::cache(t);
// CHECK: (inlined try_execute_query::<<Q as Query>::C>)
// CHECK: (inlined mk_cycle::<<Q as Query>::V>)
try_execute_query(c)
}
10 changes: 9 additions & 1 deletion tests/mir-opt/inline/exponential_runtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// Checks that code with exponential runtime does not have exponential behavior in inlining.

Expand Down Expand Up @@ -85,5 +84,14 @@ impl A for () {

// EMIT_MIR exponential_runtime.main.Inline.diff
fn main() {
// CHECK-LABEL: fn main(
// CHECK-NOT: inlined
// CHECK: (inlined <() as G>::call)
// CHECK: (inlined <() as F>::call)
// CHECK: (inlined <() as E>::call)
// CHECK: (inlined <() as D>::call)
// CHECK: (inlined <() as C>::call)
// CHECK: (inlined <() as B>::call)
// CHECK-NOT: inlined
<() as G>::call();
}
3 changes: 2 additions & 1 deletion tests/mir-opt/inline/inline_any_operand.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// compile-flags: -Z span_free_formats

// Tests that MIR inliner works for any operand
Expand All @@ -9,6 +8,8 @@ fn main() {

// EMIT_MIR inline_any_operand.bar.Inline.after.mir
fn bar() -> bool {
// CHECK-LABEL: fn bar(
// CHECK: (inlined foo)
let f = foo;
f(1, -1)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/mir-opt/inline/inline_box_fn.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// unit-test: Inline
// compile-flags: --crate-type=lib

// EMIT_MIR inline_box_fn.call.Inline.diff
fn call(x: Box<dyn Fn(i32)>) {
// CHECK-LABEL: fn call(
// CHECK-NOT: inlined
x(1);
}
4 changes: 3 additions & 1 deletion tests/mir-opt/inline/inline_closure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// compile-flags: -Z span_free_formats

// Tests that MIR inliner can handle closure arguments. (#45894)
Expand All @@ -10,5 +9,8 @@ fn main() {
// EMIT_MIR inline_closure.foo.Inline.after.mir
fn foo<T: Copy>(_t: T, q: i32) -> i32 {
let x = |_t, _q| _t;

// CHECK-LABEL: fn foo(
// CHECK: (inlined foo::<T>::{closure#0})
x(q, q)
}
4 changes: 3 additions & 1 deletion tests/mir-opt/inline/inline_closure_borrows_arg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// compile-flags: -Z span_free_formats -Zunsound-mir-opts

// Tests that MIR inliner can handle closure arguments,
Expand All @@ -14,5 +13,8 @@ fn foo<T: Copy>(_t: T, q: &i32) -> i32 {
let variable = &*r;
*variable
};

// CHECK-LABEL: fn foo(
// CHECK: (inlined foo::<T>::{closure#0})
x(q, q)
}
4 changes: 3 additions & 1 deletion tests/mir-opt/inline/inline_closure_captures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// compile-flags: -Z span_free_formats

// Tests that MIR inliner can handle closure captures.
Expand All @@ -10,5 +9,8 @@ fn main() {
// EMIT_MIR inline_closure_captures.foo.Inline.after.mir
fn foo<T: Copy>(t: T, q: i32) -> (i32, T) {
let x = |_q| (q, t);

// CHECK-LABEL: fn foo(
// CHECK: (inlined foo::<T>::{closure#0})
x(q)
}
22 changes: 11 additions & 11 deletions tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
fn main() -> () {
let mut _0: ();
let _1: std::ops::CoroutineState<i32, bool>;
let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>;
let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
let mut _4: {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>;
let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
let mut _4: {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
+ let mut _5: bool;
scope 1 {
debug _r => _1;
}
+ scope 2 (inlined g) {
+ }
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new) {
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) {
+ debug pointer => _3;
+ scope 4 {
+ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new_unchecked) {
+ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) {
+ debug pointer => _3;
+ }
+ }
+ }
+ scope 6 (inlined g::{closure#0}) {
+ debug a => _5;
+ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
+ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
+ let mut _7: u32;
+ let mut _8: i32;
+ }
Expand All @@ -34,22 +34,22 @@
StorageLive(_3);
StorageLive(_4);
- _4 = g() -> [return: bb1, unwind unreachable];
+ _4 = {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8 (#0)};
+ _4 = {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8 (#0)};
+ _3 = &mut _4;
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}> { pointer: move _3 };
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { pointer: move _3 };
+ StorageDead(_3);
+ StorageLive(_5);
+ _5 = const false;
+ StorageLive(_6);
+ StorageLive(_7);
+ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8});
+ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8});
+ _7 = discriminant((*_6));
+ switchInt(move _7) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9];
}

bb1: {
- _3 = &mut _4;
- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind unreachable];
- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new(move _3) -> [return: bb2, unwind unreachable];
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageDead(_5);
Expand All @@ -59,7 +59,7 @@

bb2: {
- StorageDead(_3);
- _1 = <{coroutine@$DIR/inline_coroutine.rs:17:5: 17:8} as Coroutine<bool>>::resume(move _2, const false) -> [return: bb3, unwind unreachable];
- _1 = <{coroutine@$DIR/inline_coroutine.rs:19:5: 19:8} as Coroutine<bool>>::resume(move _2, const false) -> [return: bb3, unwind unreachable];
+ StorageDead(_4);
+ _0 = const ();
+ StorageDead(_1);
Expand Down
22 changes: 11 additions & 11 deletions tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
fn main() -> () {
let mut _0: ();
let _1: std::ops::CoroutineState<i32, bool>;
let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>;
let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
let mut _4: {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>;
let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
let mut _4: {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
+ let mut _5: bool;
scope 1 {
debug _r => _1;
}
+ scope 2 (inlined g) {
+ }
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new) {
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) {
+ debug pointer => _3;
+ scope 4 {
+ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new_unchecked) {
+ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) {
+ debug pointer => _3;
+ }
+ }
+ }
+ scope 6 (inlined g::{closure#0}) {
+ debug a => _5;
+ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
+ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
+ let mut _7: u32;
+ let mut _8: i32;
+ }
Expand All @@ -37,20 +37,20 @@
- }
-
- bb1: {
+ _4 = {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8 (#0)};
+ _4 = {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8 (#0)};
_3 = &mut _4;
- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind: bb5];
- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new(move _3) -> [return: bb2, unwind: bb5];
- }
-
- bb2: {
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}> { pointer: move _3 };
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { pointer: move _3 };
StorageDead(_3);
- _1 = <{coroutine@$DIR/inline_coroutine.rs:17:5: 17:8} as Coroutine<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
- _1 = <{coroutine@$DIR/inline_coroutine.rs:19:5: 19:8} as Coroutine<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
+ StorageLive(_5);
+ _5 = const false;
+ StorageLive(_6);
+ StorageLive(_7);
+ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8});
+ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8});
+ _7 = discriminant((*_6));
+ switchInt(move _7) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
}
Expand Down
4 changes: 3 additions & 1 deletion tests/mir-opt/inline/inline_coroutine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// compile-flags: -Zinline-mir-hint-threshold=1000
#![feature(coroutines, coroutine_trait)]
Expand All @@ -8,6 +7,9 @@ use std::pin::Pin;

// EMIT_MIR inline_coroutine.main.Inline.diff
fn main() {
// CHECK-LABEL: fn main(
// CHECK: (inlined g)
// CHECK: (inlined g::{closure#0})
let _r = Pin::new(&mut g()).resume(false);
}

Expand Down
8 changes: 7 additions & 1 deletion tests/mir-opt/inline/inline_diverging.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// Tests inlining of diverging calls.
//
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
Expand All @@ -7,6 +6,8 @@

// EMIT_MIR inline_diverging.f.Inline.diff
pub fn f() {
// CHECK-LABEL: fn f(
// CHECK: (inlined sleep)
sleep();
}

Expand All @@ -15,12 +16,17 @@ pub fn g(i: i32) -> u32 {
if i > 0 {
i as u32
} else {
// CHECK-LABEL: fn g(
// CHECK: (inlined panic)
panic();
}
}

// EMIT_MIR inline_diverging.h.Inline.diff
pub fn h() {
// CHECK-LABEL: fn h(
// CHECK: (inlined call_twice::<!, fn() -> ! {sleep}>)
// CHECK-NOT: inlined
call_twice(sleep);
}

Expand Down
Loading

0 comments on commit 75b064d

Please sign in to comment.