Skip to content

Commit

Permalink
Rollup merge of rust-lang#117029 - rmehri01:mir_opt_filecheck_inline_…
Browse files Browse the repository at this point in the history
…tests, r=cjgillot

Add FileCheck annotations to MIR-opt inlining tests

Part of rust-lang#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
matthiaskrgr authored Oct 24, 2023
2 parents d1723f6 + 1f35769 commit b90e06e
Show file tree
Hide file tree
Showing 31 changed files with 221 additions and 101 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)
}
11 changes: 10 additions & 1 deletion tests/mir-opt/inline/inline_compatibility.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// Checks that only functions with compatible attributes are inlined.
//
// only-x86_64
Expand All @@ -12,22 +11,30 @@
// EMIT_MIR inline_compatibility.inlined_target_feature.Inline.diff
#[target_feature(enable = "sse2")]
pub unsafe fn inlined_target_feature() {
// CHECK-LABEL: fn inlined_target_feature(
// CHECK: (inlined target_feature)
target_feature();
}

// EMIT_MIR inline_compatibility.not_inlined_target_feature.Inline.diff
pub unsafe fn not_inlined_target_feature() {
// CHECK-LABEL: fn not_inlined_target_feature(
// CHECK-NOT: (inlined target_feature)
target_feature();
}

// EMIT_MIR inline_compatibility.inlined_no_sanitize.Inline.diff
#[no_sanitize(address)]
pub unsafe fn inlined_no_sanitize() {
// CHECK-LABEL: fn inlined_no_sanitize(
// CHECK: (inlined no_sanitize)
no_sanitize();
}

// EMIT_MIR inline_compatibility.not_inlined_no_sanitize.Inline.diff
pub unsafe fn not_inlined_no_sanitize() {
// CHECK-LABEL: fn not_inlined_no_sanitize(
// CHECK-NOT: (inlined no_sanitize)
no_sanitize();
}

Expand All @@ -41,6 +48,8 @@ pub unsafe fn no_sanitize() {}

// EMIT_MIR inline_compatibility.not_inlined_c_variadic.Inline.diff
pub unsafe fn not_inlined_c_variadic() {
// CHECK-LABEL: fn not_inlined_c_variadic(
// CHECK-NOT: (inlined sum)
let s = sum(4u32, 4u32, 30u32, 200u32, 1000u32);
}

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
11 changes: 10 additions & 1 deletion tests/mir-opt/inline/inline_instruction_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// Checks that only functions with the compatible instruction_set attributes are inlined.
//
// A function is "compatible" when the *callee* has the same attribute or no attribute.
Expand Down Expand Up @@ -47,16 +46,26 @@ fn inline_always_and_using_inline_asm() {
// EMIT_MIR inline_instruction_set.t32.Inline.diff
#[instruction_set(arm::t32)]
pub fn t32() {
// CHECK-LABEL: fn t32(
// CHECK-NOT: (inlined instruction_set_a32)
instruction_set_a32();
// CHECK: (inlined instruction_set_t32)
instruction_set_t32();
// CHECK: (inlined instruction_set_default)
instruction_set_default();
// CHECK-NOT: (inlined inline_always_and_using_inline_asm)
inline_always_and_using_inline_asm();
}

// EMIT_MIR inline_instruction_set.default.Inline.diff
pub fn default() {
// CHECK-LABEL: fn default(
// CHECK-NOT: (inlined instruction_set_a32)
instruction_set_a32();
// CHECK-NOT: (inlined instruction_set_t32)
instruction_set_t32();
// CHECK: (inlined instruction_set_default)
instruction_set_default();
// CHECK: (inlined inline_always_and_using_inline_asm)
inline_always_and_using_inline_asm();
}
3 changes: 2 additions & 1 deletion tests/mir-opt/inline/inline_into_box_place.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// skip-filecheck
// ignore-endian-big
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// ignore-debug MIR alignment checks in std alter the diff, breaking the test
// compile-flags: -Zmir-opt-level=4 -Zinline-mir-hint-threshold=200

// EMIT_MIR inline_into_box_place.main.Inline.diff
fn main() {
// CHECK-LABEL: fn main(
// CHECK: (inlined Box::<Vec<u32>>::new)
let _x: Box<Vec<u32>> = Box::new(Vec::new());
}
Loading

0 comments on commit b90e06e

Please sign in to comment.