Skip to content

Commit 5f1fd2f

Browse files
committed
Add test.
1 parent e792ee8 commit 5f1fd2f

3 files changed

+150
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
- // MIR for `identity` before PreCodegen
2+
+ // MIR for `identity` after PreCodegen
3+
4+
fn identity(_1: Result<i32, i32>) -> Result<i32, i32> {
5+
debug x => _1;
6+
let mut _0: std::result::Result<i32, i32>;
7+
let mut _4: std::ops::ControlFlow<std::result::Result<std::convert::Infallible, i32>, i32>;
8+
let _5: i32;
9+
let _8: std::result::Result<std::convert::Infallible, i32>;
10+
scope 1 {
11+
debug residual => _8;
12+
scope 2 {
13+
scope 8 (inlined #[track_caller] <Result<i32, i32> as FromResidual<Result<Infallible, i32>>>::from_residual) {
14+
debug residual => _8;
15+
let _9: i32;
16+
scope 9 {
17+
debug e => _9;
18+
scope 10 (inlined <i32 as From<i32>>::from) {
19+
debug t => _9;
20+
}
21+
}
22+
}
23+
}
24+
}
25+
scope 3 {
26+
debug val => _5;
27+
scope 4 {
28+
}
29+
}
30+
scope 5 (inlined <Result<i32, i32> as Try>::branch) {
31+
debug self => _1;
32+
let mut _2: isize;
33+
let _3: i32;
34+
let _6: i32;
35+
let mut _7: std::result::Result<std::convert::Infallible, i32>;
36+
scope 6 {
37+
debug v => _3;
38+
}
39+
scope 7 {
40+
debug e => _6;
41+
}
42+
}
43+
44+
bb0: {
45+
StorageLive(_4);
46+
StorageLive(_2);
47+
StorageLive(_3);
48+
StorageLive(_6);
49+
_2 = discriminant(_1);
50+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb3];
51+
}
52+
53+
bb1: {
54+
_3 = ((_1 as Ok).0: i32);
55+
_4 = ControlFlow::<Result<Infallible, i32>, i32>::Continue(_3);
56+
StorageDead(_6);
57+
StorageDead(_3);
58+
StorageDead(_2);
59+
_5 = ((_4 as Continue).0: i32);
60+
_0 = Result::<i32, i32>::Ok(_5);
61+
StorageDead(_4);
62+
return;
63+
}
64+
65+
bb2: {
66+
_6 = ((_1 as Err).0: i32);
67+
StorageLive(_7);
68+
_7 = Result::<Infallible, i32>::Err(_6);
69+
_4 = ControlFlow::<Result<Infallible, i32>, i32>::Break(move _7);
70+
StorageDead(_7);
71+
StorageDead(_6);
72+
StorageDead(_3);
73+
StorageDead(_2);
74+
_8 = ((_4 as Break).0: std::result::Result<std::convert::Infallible, i32>);
75+
_9 = ((_8 as Err).0: i32);
76+
_0 = Result::<i32, i32>::Err(_9);
77+
StorageDead(_4);
78+
return;
79+
}
80+
81+
bb3: {
82+
unreachable;
83+
}
84+
}
85+

tests/mir-opt/separate_const_switch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#![feature(control_flow_enum)]
33
#![feature(try_trait_v2)]
44

5-
// compile-flags: -Zunsound-mir-opts
6-
75
use std::ops::ControlFlow;
86

97
// EMIT_MIR separate_const_switch.too_complex.JumpThreading.diff
8+
// EMIT_MIR separate_const_switch.too_complex.PreCodegen.diff
109
fn too_complex(x: Result<i32, usize>) -> Option<i32> {
1110
// The pass should break the outer match into
1211
// two blocks that only have one parent each.
@@ -24,6 +23,7 @@ fn too_complex(x: Result<i32, usize>) -> Option<i32> {
2423
}
2524

2625
// EMIT_MIR separate_const_switch.identity.JumpThreading.diff
26+
// EMIT_MIR separate_const_switch.identity.PreCodegen.diff
2727
fn identity(x: Result<i32, i32>) -> Result<i32, i32> {
2828
Ok(x?)
2929
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
- // MIR for `too_complex` before PreCodegen
2+
+ // MIR for `too_complex` after PreCodegen
3+
4+
fn too_complex(_1: Result<i32, usize>) -> Option<i32> {
5+
debug x => _1;
6+
let mut _0: std::option::Option<i32>;
7+
let mut _2: isize;
8+
let _3: i32;
9+
let mut _4: std::ops::ControlFlow<usize, i32>;
10+
let _5: i32;
11+
let _6: usize;
12+
let _7: usize;
13+
scope 1 {
14+
debug v => _3;
15+
}
16+
scope 2 {
17+
debug r => _6;
18+
}
19+
scope 3 {
20+
debug v => _5;
21+
}
22+
scope 4 {
23+
debug r => _7;
24+
}
25+
26+
bb0: {
27+
StorageLive(_4);
28+
_2 = discriminant(_1);
29+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
30+
}
31+
32+
bb1: {
33+
_3 = ((_1 as Ok).0: i32);
34+
_4 = ControlFlow::<usize, i32>::Continue(_3);
35+
_5 = ((_4 as Continue).0: i32);
36+
_0 = Option::<i32>::Some(_5);
37+
goto -> bb3;
38+
}
39+
40+
bb2: {
41+
_6 = ((_1 as Err).0: usize);
42+
_4 = ControlFlow::<usize, i32>::Break(_6);
43+
StorageLive(_7);
44+
_7 = ((_4 as Break).0: usize);
45+
_0 = const Option::<i32>::None;
46+
StorageDead(_7);
47+
goto -> bb3;
48+
}
49+
50+
bb3: {
51+
StorageDead(_4);
52+
return;
53+
}
54+
55+
bb4: {
56+
unreachable;
57+
}
58+
}
59+
60+
ALLOC0 (size: 8, align: 4) {
61+
00 00 00 00 __ __ __ __ │ ....░░░░
62+
}
63+

0 commit comments

Comments
 (0)