Skip to content

Commit 765ac22

Browse files
authored
Rollup merge of rust-lang#117029 - rmehri01:mir_opt_filecheck_inline_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
2 parents c0ed667 + 2fcb4d9 commit 765ac22

28 files changed

+145
-40
lines changed

tests/mir-opt/inline/asm_unwind.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// skip-filecheck
21
// Tests inlining of `may_unwind` inline assembly.
32
//
43
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
54
// needs-asm-support
5+
// needs-unwind
66
// compile-flags: -Zinline-mir-hint-threshold=1000
77
#![feature(asm_unwind)]
88

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

2121
// EMIT_MIR asm_unwind.main.Inline.diff
2222
pub fn main() {
23+
// CHECK-LABEL: fn main(
24+
// CHECK: (inlined foo)
25+
// CHECK: asm!("", options(MAY_UNWIND)) -> [return: {{bb.*}}, unwind: [[unwind:bb.*]]];
26+
// CHECK: [[unwind]] (cleanup)
2327
foo();
2428
}

tests/mir-opt/inline/caller_with_trivial_bound.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// needs-unwind
43

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

tests/mir-opt/inline/cycle.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// compile-flags: -Zinline-mir-hint-threshold=1000
43

54
// EMIT_MIR cycle.f.Inline.diff
65
#[inline(always)]
76
fn f(g: impl Fn()) {
7+
// CHECK-LABEL: fn f(
8+
// CHECK-NOT: inlined
89
g();
910
}
1011

1112
// EMIT_MIR cycle.g.Inline.diff
1213
#[inline(always)]
1314
fn g() {
15+
// CHECK-LABEL: fn g(
16+
// CHECK-NOT: inlined
17+
// CHECK: (inlined f::<fn() {main}>)
18+
// CHECK-NOT: inlined
1419
f(main);
1520
}
1621

1722
// EMIT_MIR cycle.main.Inline.diff
1823
fn main() {
24+
// CHECK-LABEL: fn main(
25+
// CHECK-NOT: inlined
26+
// CHECK: (inlined f::<fn() {g}>)
27+
// CHECK-NOT: inlined
1928
f(g);
2029
}

tests/mir-opt/inline/dont_ice_on_generic_rust_call.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// compile-flags: -Zmir-enable-passes=+Inline --crate-type=lib
43

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

98
// EMIT_MIR dont_ice_on_generic_rust_call.call.Inline.diff
109
pub fn call<I: Tuple>(mut mock: Box<dyn FnMut<I, Output = ()>>, input: I) {
10+
// CHECK-LABEL: fn call(
11+
// CHECK-NOT: inlined
1112
mock.call_mut(input)
1213
}

tests/mir-opt/inline/dyn_trait.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
#![crate_type = "lib"]
43

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

2627
// EMIT_MIR dyn_trait.try_execute_query.Inline.diff
2728
#[inline(always)]
2829
pub fn try_execute_query<C: Cache>(c: &C) {
30+
// CHECK-LABEL: fn try_execute_query(
31+
// CHECK: (inlined mk_cycle::<<C as Cache>::V>)
2932
mk_cycle(c)
3033
}
3134

3235
// EMIT_MIR dyn_trait.get_query.Inline.diff
3336
#[inline(always)]
3437
pub fn get_query<Q: Query, T>(t: &T) {
38+
// CHECK-LABEL: fn get_query(
39+
// CHECK-NOT: inlined
3540
let c = Q::cache(t);
41+
// CHECK: (inlined try_execute_query::<<Q as Query>::C>)
42+
// CHECK: (inlined mk_cycle::<<Q as Query>::V>)
3643
try_execute_query(c)
3744
}

tests/mir-opt/inline/exponential_runtime.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// Checks that code with exponential runtime does not have exponential behavior in inlining.
43

@@ -85,5 +84,14 @@ impl A for () {
8584

8685
// EMIT_MIR exponential_runtime.main.Inline.diff
8786
fn main() {
87+
// CHECK-LABEL: fn main(
88+
// CHECK-NOT: inlined
89+
// CHECK: (inlined <() as G>::call)
90+
// CHECK: (inlined <() as F>::call)
91+
// CHECK: (inlined <() as E>::call)
92+
// CHECK: (inlined <() as D>::call)
93+
// CHECK: (inlined <() as C>::call)
94+
// CHECK: (inlined <() as B>::call)
95+
// CHECK-NOT: inlined
8896
<() as G>::call();
8997
}

tests/mir-opt/inline/inline_any_operand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// compile-flags: -Z span_free_formats
32

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

109
// EMIT_MIR inline_any_operand.bar.Inline.after.mir
1110
fn bar() -> bool {
11+
// CHECK-LABEL: fn bar(
12+
// CHECK: (inlined foo)
1213
let f = foo;
1314
f(1, -1)
1415
}

tests/mir-opt/inline/inline_box_fn.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// unit-test: Inline
43
// compile-flags: --crate-type=lib
54

65
// EMIT_MIR inline_box_fn.call.Inline.diff
76
fn call(x: Box<dyn Fn(i32)>) {
7+
// CHECK-LABEL: fn call(
8+
// CHECK-NOT: inlined
89
x(1);
910
}

tests/mir-opt/inline/inline_closure.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// compile-flags: -Z span_free_formats
32

43
// Tests that MIR inliner can handle closure arguments. (#45894)
@@ -10,5 +9,8 @@ fn main() {
109
// EMIT_MIR inline_closure.foo.Inline.after.mir
1110
fn foo<T: Copy>(_t: T, q: i32) -> i32 {
1211
let x = |_t, _q| _t;
12+
13+
// CHECK-LABEL: fn foo(
14+
// CHECK: (inlined foo::<T>::{closure#0})
1315
x(q, q)
1416
}

tests/mir-opt/inline/inline_closure_borrows_arg.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// compile-flags: -Z span_free_formats -Zunsound-mir-opts
32

43
// Tests that MIR inliner can handle closure arguments,
@@ -14,5 +13,8 @@ fn foo<T: Copy>(_t: T, q: &i32) -> i32 {
1413
let variable = &*r;
1514
*variable
1615
};
16+
17+
// CHECK-LABEL: fn foo(
18+
// CHECK: (inlined foo::<T>::{closure#0})
1719
x(q, q)
1820
}

tests/mir-opt/inline/inline_closure_captures.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// compile-flags: -Z span_free_formats
32

43
// Tests that MIR inliner can handle closure captures.
@@ -10,5 +9,8 @@ fn main() {
109
// EMIT_MIR inline_closure_captures.foo.Inline.after.mir
1110
fn foo<T: Copy>(t: T, q: i32) -> (i32, T) {
1211
let x = |_q| (q, t);
12+
13+
// CHECK-LABEL: fn foo(
14+
// CHECK: (inlined foo::<T>::{closure#0})
1315
x(q)
1416
}

tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: std::ops::CoroutineState<i32, bool>;
7-
let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>;
8-
let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
9-
let mut _4: {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
7+
let mut _2: std::pin::Pin<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>;
8+
let mut _3: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
9+
let mut _4: {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
1010
+ let mut _5: bool;
1111
scope 1 {
1212
debug _r => _1;
1313
}
1414
+ scope 2 (inlined g) {
1515
+ }
16-
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new) {
16+
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) {
1717
+ debug pointer => _3;
1818
+ scope 4 {
19-
+ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new_unchecked) {
19+
+ scope 5 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) {
2020
+ debug pointer => _3;
2121
+ }
2222
+ }
2323
+ }
2424
+ scope 6 (inlined g::{closure#0}) {
2525
+ debug a => _5;
26-
+ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8};
26+
+ let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8};
2727
+ let mut _7: u32;
2828
+ let mut _8: i32;
2929
+ }
@@ -37,20 +37,20 @@
3737
- }
3838
-
3939
- bb1: {
40-
+ _4 = {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8 (#0)};
40+
+ _4 = {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8 (#0)};
4141
_3 = &mut _4;
42-
- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}>::new(move _3) -> [return: bb2, unwind: bb5];
42+
- _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new(move _3) -> [return: bb2, unwind: bb5];
4343
- }
4444
-
4545
- bb2: {
46-
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8}> { pointer: move _3 };
46+
+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}> { pointer: move _3 };
4747
StorageDead(_3);
48-
- _1 = <{coroutine@$DIR/inline_coroutine.rs:17:5: 17:8} as Coroutine<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
48+
- _1 = <{coroutine@$DIR/inline_coroutine.rs:19:5: 19:8} as Coroutine<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
4949
+ StorageLive(_5);
5050
+ _5 = const false;
5151
+ StorageLive(_6);
5252
+ StorageLive(_7);
53-
+ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:17:5: 17:8});
53+
+ _6 = (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8});
5454
+ _7 = discriminant((*_6));
5555
+ switchInt(move _7) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
5656
}

tests/mir-opt/inline/inline_coroutine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// compile-flags: -Zinline-mir-hint-threshold=1000
43
#![feature(coroutines, coroutine_trait)]
@@ -8,6 +7,9 @@ use std::pin::Pin;
87

98
// EMIT_MIR inline_coroutine.main.Inline.diff
109
fn main() {
10+
// CHECK-LABEL: fn main(
11+
// CHECK: (inlined g)
12+
// CHECK: (inlined g::{closure#0})
1113
let _r = Pin::new(&mut g()).resume(false);
1214
}
1315

tests/mir-opt/inline/inline_diverging.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// Tests inlining of diverging calls.
32
//
43
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
@@ -7,6 +6,8 @@
76

87
// EMIT_MIR inline_diverging.f.Inline.diff
98
pub fn f() {
9+
// CHECK-LABEL: fn f(
10+
// CHECK: (inlined sleep)
1011
sleep();
1112
}
1213

@@ -15,12 +16,17 @@ pub fn g(i: i32) -> u32 {
1516
if i > 0 {
1617
i as u32
1718
} else {
19+
// CHECK-LABEL: fn g(
20+
// CHECK: (inlined panic)
1821
panic();
1922
}
2023
}
2124

2225
// EMIT_MIR inline_diverging.h.Inline.diff
2326
pub fn h() {
27+
// CHECK-LABEL: fn h(
28+
// CHECK: (inlined call_twice::<!, fn() -> ! {sleep}>)
29+
// CHECK-NOT: inlined
2430
call_twice(sleep);
2531
}
2632

tests/mir-opt/inline/inline_instruction_set.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// Checks that only functions with the compatible instruction_set attributes are inlined.
32
//
43
// A function is "compatible" when the *callee* has the same attribute or no attribute.
@@ -47,16 +46,26 @@ fn inline_always_and_using_inline_asm() {
4746
// EMIT_MIR inline_instruction_set.t32.Inline.diff
4847
#[instruction_set(arm::t32)]
4948
pub fn t32() {
49+
// CHECK-LABEL: fn t32(
50+
// CHECK-NOT: (inlined instruction_set_a32)
5051
instruction_set_a32();
52+
// CHECK: (inlined instruction_set_t32)
5153
instruction_set_t32();
54+
// CHECK: (inlined instruction_set_default)
5255
instruction_set_default();
56+
// CHECK-NOT: (inlined inline_always_and_using_inline_asm)
5357
inline_always_and_using_inline_asm();
5458
}
5559

5660
// EMIT_MIR inline_instruction_set.default.Inline.diff
5761
pub fn default() {
62+
// CHECK-LABEL: fn default(
63+
// CHECK-NOT: (inlined instruction_set_a32)
5864
instruction_set_a32();
65+
// CHECK-NOT: (inlined instruction_set_t32)
5966
instruction_set_t32();
67+
// CHECK: (inlined instruction_set_default)
6068
instruction_set_default();
69+
// CHECK: (inlined inline_always_and_using_inline_asm)
6170
inline_always_and_using_inline_asm();
6271
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// skip-filecheck
21
// ignore-endian-big
32
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
43
// ignore-debug MIR alignment checks in std alter the diff, breaking the test
54
// compile-flags: -Zmir-opt-level=4 -Zinline-mir-hint-threshold=200
65

76
// EMIT_MIR inline_into_box_place.main.Inline.diff
87
fn main() {
8+
// CHECK-LABEL: fn main(
9+
// CHECK: (inlined Box::<Vec<u32>>::new)
910
let _x: Box<Vec<u32>> = Box::new(Vec::new());
1011
}

tests/mir-opt/inline/inline_options.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// Checks that inlining threshold can be controlled with
43
// inline-mir-threshold and inline-hint-threshold options.
@@ -8,7 +7,10 @@
87

98
// EMIT_MIR inline_options.main.Inline.after.mir
109
fn main() {
10+
// CHECK-LABEL: fn main(
11+
// CHECK-NOT: (inlined not_inlined)
1112
not_inlined();
13+
// CHECK: (inlined inlined::<u32>)
1214
inlined::<u32>();
1315
}
1416

tests/mir-opt/inline/inline_retag.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// compile-flags: -Z span_free_formats -Z mir-emit-retag
32

43
// Tests that MIR inliner fixes up `Retag`'s `fn_entry` flag
@@ -9,6 +8,17 @@ fn main() {
98

109
// EMIT_MIR inline_retag.bar.Inline.after.mir
1110
fn bar() -> bool {
11+
// CHECK-LABEL: fn bar(
12+
// CHECK: (inlined foo)
13+
// CHECK: debug x => [[x:_.*]];
14+
// CHECK: debug y => [[y:_.*]];
15+
// CHECK: bb0: {
16+
// CHECK: Retag
17+
// CHECK: Retag
18+
// CHECK: Retag([[x]]);
19+
// CHECK: Retag([[y]]);
20+
// CHECK: return;
21+
// CHECK-NEXT: }
1222
let f = foo;
1323
f(&1, &-1)
1424
}

0 commit comments

Comments
 (0)