Add a debug-mode MIR pre-codegen test for ?-on-Option

This commit is contained in:
Scott McMurray 2025-07-25 21:11:26 -07:00
parent c441640f0e
commit e1a38ec2ab
5 changed files with 197 additions and 0 deletions

View file

@ -0,0 +1,37 @@
// MIR for `option_direct` after PreCodegen
fn option_direct(_1: Option<u32>) -> Option<u32> {
debug x => _1;
let mut _0: std::option::Option<u32>;
let mut _2: isize;
let _3: u32;
let mut _4: u32;
scope 1 {
debug x => _3;
}
bb0: {
_2 = discriminant(_1);
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
}
bb1: {
_0 = Option::<u32>::None;
goto -> bb3;
}
bb2: {
_3 = copy ((_1 as Some).0: u32);
_4 = Not(copy _3);
_0 = Option::<u32>::Some(move _4);
goto -> bb3;
}
bb3: {
return;
}
bb4: {
unreachable;
}
}

View file

@ -0,0 +1,37 @@
// MIR for `option_direct` after PreCodegen
fn option_direct(_1: Option<u32>) -> Option<u32> {
debug x => _1;
let mut _0: std::option::Option<u32>;
let mut _2: isize;
let _3: u32;
let mut _4: u32;
scope 1 {
debug x => _3;
}
bb0: {
_2 = discriminant(_1);
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
}
bb1: {
_0 = Option::<u32>::None;
goto -> bb3;
}
bb2: {
_3 = copy ((_1 as Some).0: u32);
_4 = Not(copy _3);
_0 = Option::<u32>::Some(move _4);
goto -> bb3;
}
bb3: {
return;
}
bb4: {
unreachable;
}
}

View file

@ -0,0 +1,47 @@
// MIR for `option_traits` after PreCodegen
fn option_traits(_1: Option<u32>) -> Option<u32> {
debug x => _1;
let mut _0: std::option::Option<u32>;
let mut _2: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
let mut _3: isize;
let _4: u32;
let mut _5: u32;
scope 1 {
debug residual => const Option::<Infallible>::None;
scope 2 {
}
}
scope 3 {
debug val => _4;
scope 4 {
}
}
bb0: {
_2 = <Option<u32> as Try>::branch(copy _1) -> [return: bb1, unwind unreachable];
}
bb1: {
_3 = discriminant(_2);
switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb5];
}
bb2: {
_4 = copy ((_2 as Continue).0: u32);
_5 = Not(copy _4);
_0 = <Option<u32> as Try>::from_output(move _5) -> [return: bb4, unwind unreachable];
}
bb3: {
_0 = <Option<u32> as FromResidual<Option<Infallible>>>::from_residual(const Option::<Infallible>::None) -> [return: bb4, unwind unreachable];
}
bb4: {
return;
}
bb5: {
unreachable;
}
}

View file

@ -0,0 +1,47 @@
// MIR for `option_traits` after PreCodegen
fn option_traits(_1: Option<u32>) -> Option<u32> {
debug x => _1;
let mut _0: std::option::Option<u32>;
let mut _2: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
let mut _3: isize;
let _4: u32;
let mut _5: u32;
scope 1 {
debug residual => const Option::<Infallible>::None;
scope 2 {
}
}
scope 3 {
debug val => _4;
scope 4 {
}
}
bb0: {
_2 = <Option<u32> as Try>::branch(copy _1) -> [return: bb1, unwind continue];
}
bb1: {
_3 = discriminant(_2);
switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb5];
}
bb2: {
_4 = copy ((_2 as Continue).0: u32);
_5 = Not(copy _4);
_0 = <Option<u32> as Try>::from_output(move _5) -> [return: bb4, unwind continue];
}
bb3: {
_0 = <Option<u32> as FromResidual<Option<Infallible>>>::from_residual(const Option::<Infallible>::None) -> [return: bb4, unwind continue];
}
bb4: {
return;
}
bb5: {
unreachable;
}
}

View file

@ -0,0 +1,29 @@
//@ compile-flags: -Copt-level=0 -Zmir-opt-level=1 -Cdebuginfo=limited
//@ edition: 2024
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
#![crate_type = "lib"]
#![feature(try_blocks)]
// EMIT_MIR option_bubble_debug.option_direct.PreCodegen.after.mir
pub fn option_direct(x: Option<u32>) -> Option<u32> {
// CHECK-LABEL: fn option_direct(_1: Option<u32>) -> Option<u32>
// CHECK: = discriminant(_1);
// CHECK: [[TEMP:_.+]] = Not({{.+}});
// CHECK: _0 = Option::<u32>::Some(move [[TEMP]]);
match x {
Some(x) => Some(!x),
None => None,
}
}
// EMIT_MIR option_bubble_debug.option_traits.PreCodegen.after.mir
pub fn option_traits(x: Option<u32>) -> Option<u32> {
// CHECK-LABEL: fn option_traits(_1: Option<u32>) -> Option<u32>
// CHECK: = <Option<u32> as Try>::branch(copy _1)
// CHECK: [[TEMP:_.+]] = Not({{.+}});
// CHECK: _0 = <Option<u32> as Try>::from_output(move [[TEMP]])
try { !(x?) }
}