Skip to content

Commit

Permalink
mir-opt & codegen test updates
Browse files Browse the repository at this point in the history
`SimplifyArm` and such are currently in `-Zunsound-mir-opts` and thus weren't running by default, so having something like them for the new desugar shouldn't be necessary for switching.
  • Loading branch information
scottmcm committed May 6, 2021
1 parent 266a726 commit 47b9948
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 346 deletions.
21 changes: 19 additions & 2 deletions src/test/codegen/try_identity.rs
Expand Up @@ -7,11 +7,28 @@

type R = Result<u64, i32>;

// This was written to the `?` from `try_trait`,
// but `try_trait_v2` uses a different structure,
// so the relevant desugar is copied inline
// in order to keep the test testing the same thing.
#[no_mangle]
fn try_identity(x: R) -> R {
pub fn try_identity(x: R) -> R {
// CHECK: start:
// CHECK-NOT: br {{.*}}
// CHECK ret void
let y = x?;
let y = match into_result(x) {
Err(e) => return from_error(From::from(e)),
Ok(v) => v,
};
Ok(y)
}

#[inline]
fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
r
}

#[inline]
fn from_error<T, E>(e: E) -> Result<T, E> {
Err(e)
}
70 changes: 30 additions & 40 deletions src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir
Expand Up @@ -4,21 +4,20 @@ fn test() -> Option<Box<u32>> {
let mut _0: std::option::Option<std::boxed::Box<u32>>; // return place in scope 0 at $DIR/issue-62289.rs:8:14: 8:30
let mut _1: std::boxed::Box<u32>; // in scope 0 at $DIR/issue-62289.rs:9:10: 9:21
let mut _2: std::boxed::Box<u32>; // in scope 0 at $DIR/issue-62289.rs:9:10: 9:21
let mut _3: std::result::Result<u32, std::option::NoneError>; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
let mut _3: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
let mut _4: std::option::Option<u32>; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:19
let mut _5: isize; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let _6: std::option::NoneError; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let _6: std::option::Option<std::convert::Infallible>; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let mut _7: !; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let mut _8: std::option::NoneError; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let mut _9: std::option::NoneError; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let _10: u32; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
let mut _8: std::option::Option<std::convert::Infallible>; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
let _9: u32; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
scope 1 {
debug err => _6; // in scope 1 at $DIR/issue-62289.rs:9:19: 9:20
debug residual => _6; // in scope 1 at $DIR/issue-62289.rs:9:19: 9:20
scope 2 {
}
}
scope 3 {
debug val => _10; // in scope 3 at $DIR/issue-62289.rs:9:15: 9:20
debug val => _9; // in scope 3 at $DIR/issue-62289.rs:9:15: 9:20
scope 4 {
}
}
Expand All @@ -30,10 +29,10 @@ fn test() -> Option<Box<u32>> {
StorageLive(_3); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
StorageLive(_4); // scope 0 at $DIR/issue-62289.rs:9:15: 9:19
_4 = Option::<u32>::None; // scope 0 at $DIR/issue-62289.rs:9:15: 9:19
_3 = <Option<u32> as Try>::into_result(move _4) -> [return: bb1, unwind: bb12]; // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
_3 = <Option<u32> as Try>::branch(move _4) -> [return: bb1, unwind: bb11]; // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
// mir::Constant
// + span: $DIR/issue-62289.rs:9:15: 9:20
// + literal: Const { ty: fn(std::option::Option<u32>) -> std::result::Result<<std::option::Option<u32> as std::ops::Try>::Ok, <std::option::Option<u32> as std::ops::Try>::Error> {<std::option::Option<u32> as std::ops::Try>::into_result}, val: Value(Scalar(<ZST>)) }
// + literal: Const { ty: fn(std::option::Option<u32>) -> std::ops::ControlFlow<<std::option::Option<u32> as std::ops::Try>::Residual, <std::option::Option<u32> as std::ops::Try>::Output> {<std::option::Option<u32> as std::ops::Try>::branch}, val: Value(Scalar(<ZST>)) }
}

bb1: {
Expand All @@ -43,12 +42,12 @@ fn test() -> Option<Box<u32>> {
}

bb2: {
StorageLive(_10); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
_10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
(*_2) = _10; // scope 4 at $DIR/issue-62289.rs:9:15: 9:20
StorageDead(_10); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
StorageLive(_9); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
_9 = ((_3 as Continue).0: u32); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
(*_2) = _9; // scope 4 at $DIR/issue-62289.rs:9:15: 9:20
StorageDead(_9); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
_1 = move _2; // scope 0 at $DIR/issue-62289.rs:9:10: 9:21
drop(_2) -> [return: bb7, unwind: bb11]; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
drop(_2) -> [return: bb6, unwind: bb10]; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
}

bb3: {
Expand All @@ -57,62 +56,53 @@ fn test() -> Option<Box<u32>> {

bb4: {
StorageLive(_6); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
_6 = ((_3 as Err).0: std::option::NoneError); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
_6 = ((_3 as Break).0: std::option::Option<std::convert::Infallible>); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
StorageLive(_8); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
StorageLive(_9); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
_9 = _6; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
_8 = <NoneError as From<NoneError>>::from(move _9) -> [return: bb5, unwind: bb12]; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
_8 = _6; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
_0 = <Option<Box<u32>> as FromResidual<Option<Infallible>>>::from_residual(move _8) -> [return: bb5, unwind: bb11]; // scope 2 at $DIR/issue-62289.rs:9:15: 9:20
// mir::Constant
// + span: $DIR/issue-62289.rs:9:19: 9:20
// + literal: Const { ty: fn(std::option::NoneError) -> std::option::NoneError {<std::option::NoneError as std::convert::From<std::option::NoneError>>::from}, val: Value(Scalar(<ZST>)) }
// + literal: Const { ty: fn(std::option::Option<std::convert::Infallible>) -> std::option::Option<std::boxed::Box<u32>> {<std::option::Option<std::boxed::Box<u32>> as std::ops::FromResidual<std::option::Option<std::convert::Infallible>>>::from_residual}, val: Value(Scalar(<ZST>)) }
}

bb5: {
StorageDead(_9); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
_0 = <Option<Box<u32>> as Try>::from_error(move _8) -> [return: bb6, unwind: bb12]; // scope 2 at $DIR/issue-62289.rs:9:15: 9:20
// mir::Constant
// + span: $DIR/issue-62289.rs:9:15: 9:20
// + literal: Const { ty: fn(<std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::Error) -> std::option::Option<std::boxed::Box<u32>> {<std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::from_error}, val: Value(Scalar(<ZST>)) }
}

bb6: {
StorageDead(_8); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
StorageDead(_6); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
drop(_2) -> bb9; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
drop(_2) -> bb8; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
}

bb7: {
bb6: {
StorageDead(_2); // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
_0 = Option::<Box<u32>>::Some(move _1); // scope 0 at $DIR/issue-62289.rs:9:5: 9:22
drop(_1) -> bb8; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
drop(_1) -> bb7; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
}

bb8: {
bb7: {
StorageDead(_1); // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
StorageDead(_3); // scope 0 at $DIR/issue-62289.rs:10:1: 10:2
goto -> bb10; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
goto -> bb9; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
}

bb9: {
bb8: {
StorageDead(_2); // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
StorageDead(_1); // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
StorageDead(_3); // scope 0 at $DIR/issue-62289.rs:10:1: 10:2
goto -> bb10; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
goto -> bb9; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
}

bb10: {
bb9: {
return; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
}

bb11 (cleanup): {
drop(_1) -> bb13; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
bb10 (cleanup): {
drop(_1) -> bb12; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
}

bb12 (cleanup): {
drop(_2) -> bb13; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
bb11 (cleanup): {
drop(_2) -> bb12; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
}

bb13 (cleanup): {
bb12 (cleanup): {
resume; // scope 0 at $DIR/issue-62289.rs:8:1: 10:2
}
}
17 changes: 16 additions & 1 deletion src/test/mir-opt/simplify-arm.rs
Expand Up @@ -20,8 +20,23 @@ fn id_result(r: Result<u8, i32>) -> Result<u8, i32> {
}
}

fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
r
}

fn from_error<T, E>(e: E) -> Result<T, E> {
Err(e)
}

// This was written to the `?` from `try_trait`,
// but `try_trait_v2` uses a different structure,
// so the relevant desugar is copied inline
// in order to keep the test testing the same thing.
fn id_try(r: Result<u8, i32>) -> Result<u8, i32> {
let x = r?;
let x = match into_result(r) {
Err(e) => return from_error(From::from(e)),
Ok(v) => v,
};
Ok(x)
}

Expand Down

0 comments on commit 47b9948

Please sign in to comment.