Skip to content

Commit e1a38ec

Browse files
committed
Add a debug-mode MIR pre-codegen test for ?-on-Option
1 parent c441640 commit e1a38ec

5 files changed

+197
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// MIR for `option_direct` after PreCodegen
2+
3+
fn option_direct(_1: Option<u32>) -> Option<u32> {
4+
debug x => _1;
5+
let mut _0: std::option::Option<u32>;
6+
let mut _2: isize;
7+
let _3: u32;
8+
let mut _4: u32;
9+
scope 1 {
10+
debug x => _3;
11+
}
12+
13+
bb0: {
14+
_2 = discriminant(_1);
15+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
16+
}
17+
18+
bb1: {
19+
_0 = Option::<u32>::None;
20+
goto -> bb3;
21+
}
22+
23+
bb2: {
24+
_3 = copy ((_1 as Some).0: u32);
25+
_4 = Not(copy _3);
26+
_0 = Option::<u32>::Some(move _4);
27+
goto -> bb3;
28+
}
29+
30+
bb3: {
31+
return;
32+
}
33+
34+
bb4: {
35+
unreachable;
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// MIR for `option_direct` after PreCodegen
2+
3+
fn option_direct(_1: Option<u32>) -> Option<u32> {
4+
debug x => _1;
5+
let mut _0: std::option::Option<u32>;
6+
let mut _2: isize;
7+
let _3: u32;
8+
let mut _4: u32;
9+
scope 1 {
10+
debug x => _3;
11+
}
12+
13+
bb0: {
14+
_2 = discriminant(_1);
15+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
16+
}
17+
18+
bb1: {
19+
_0 = Option::<u32>::None;
20+
goto -> bb3;
21+
}
22+
23+
bb2: {
24+
_3 = copy ((_1 as Some).0: u32);
25+
_4 = Not(copy _3);
26+
_0 = Option::<u32>::Some(move _4);
27+
goto -> bb3;
28+
}
29+
30+
bb3: {
31+
return;
32+
}
33+
34+
bb4: {
35+
unreachable;
36+
}
37+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// MIR for `option_traits` after PreCodegen
2+
3+
fn option_traits(_1: Option<u32>) -> Option<u32> {
4+
debug x => _1;
5+
let mut _0: std::option::Option<u32>;
6+
let mut _2: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
7+
let mut _3: isize;
8+
let _4: u32;
9+
let mut _5: u32;
10+
scope 1 {
11+
debug residual => const Option::<Infallible>::None;
12+
scope 2 {
13+
}
14+
}
15+
scope 3 {
16+
debug val => _4;
17+
scope 4 {
18+
}
19+
}
20+
21+
bb0: {
22+
_2 = <Option<u32> as Try>::branch(copy _1) -> [return: bb1, unwind unreachable];
23+
}
24+
25+
bb1: {
26+
_3 = discriminant(_2);
27+
switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb5];
28+
}
29+
30+
bb2: {
31+
_4 = copy ((_2 as Continue).0: u32);
32+
_5 = Not(copy _4);
33+
_0 = <Option<u32> as Try>::from_output(move _5) -> [return: bb4, unwind unreachable];
34+
}
35+
36+
bb3: {
37+
_0 = <Option<u32> as FromResidual<Option<Infallible>>>::from_residual(const Option::<Infallible>::None) -> [return: bb4, unwind unreachable];
38+
}
39+
40+
bb4: {
41+
return;
42+
}
43+
44+
bb5: {
45+
unreachable;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// MIR for `option_traits` after PreCodegen
2+
3+
fn option_traits(_1: Option<u32>) -> Option<u32> {
4+
debug x => _1;
5+
let mut _0: std::option::Option<u32>;
6+
let mut _2: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
7+
let mut _3: isize;
8+
let _4: u32;
9+
let mut _5: u32;
10+
scope 1 {
11+
debug residual => const Option::<Infallible>::None;
12+
scope 2 {
13+
}
14+
}
15+
scope 3 {
16+
debug val => _4;
17+
scope 4 {
18+
}
19+
}
20+
21+
bb0: {
22+
_2 = <Option<u32> as Try>::branch(copy _1) -> [return: bb1, unwind continue];
23+
}
24+
25+
bb1: {
26+
_3 = discriminant(_2);
27+
switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb5];
28+
}
29+
30+
bb2: {
31+
_4 = copy ((_2 as Continue).0: u32);
32+
_5 = Not(copy _4);
33+
_0 = <Option<u32> as Try>::from_output(move _5) -> [return: bb4, unwind continue];
34+
}
35+
36+
bb3: {
37+
_0 = <Option<u32> as FromResidual<Option<Infallible>>>::from_residual(const Option::<Infallible>::None) -> [return: bb4, unwind continue];
38+
}
39+
40+
bb4: {
41+
return;
42+
}
43+
44+
bb5: {
45+
unreachable;
46+
}
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ compile-flags: -Copt-level=0 -Zmir-opt-level=1 -Cdebuginfo=limited
2+
//@ edition: 2024
3+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
4+
5+
#![crate_type = "lib"]
6+
#![feature(try_blocks)]
7+
8+
// EMIT_MIR option_bubble_debug.option_direct.PreCodegen.after.mir
9+
pub fn option_direct(x: Option<u32>) -> Option<u32> {
10+
// CHECK-LABEL: fn option_direct(_1: Option<u32>) -> Option<u32>
11+
// CHECK: = discriminant(_1);
12+
// CHECK: [[TEMP:_.+]] = Not({{.+}});
13+
// CHECK: _0 = Option::<u32>::Some(move [[TEMP]]);
14+
15+
match x {
16+
Some(x) => Some(!x),
17+
None => None,
18+
}
19+
}
20+
21+
// EMIT_MIR option_bubble_debug.option_traits.PreCodegen.after.mir
22+
pub fn option_traits(x: Option<u32>) -> Option<u32> {
23+
// CHECK-LABEL: fn option_traits(_1: Option<u32>) -> Option<u32>
24+
// CHECK: = <Option<u32> as Try>::branch(copy _1)
25+
// CHECK: [[TEMP:_.+]] = Not({{.+}});
26+
// CHECK: _0 = <Option<u32> as Try>::from_output(move [[TEMP]])
27+
28+
try { !(x?) }
29+
}

0 commit comments

Comments
 (0)