From 47b99485a391e21caf3e0312969ed00ccbc6c167 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 25 Apr 2021 22:02:48 -0700 Subject: mir-opt & codegen test updates `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. --- src/test/codegen/try_identity.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/test/codegen') diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs index 81e2435e5b8..78da06b2fe4 100644 --- a/src/test/codegen/try_identity.rs +++ b/src/test/codegen/try_identity.rs @@ -7,11 +7,28 @@ type R = Result; +// 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(r: Result) -> Result { + r +} + +#[inline] +fn from_error(e: E) -> Result { + Err(e) +} -- cgit 1.4.1-3-g733a5 From bf0e34c00159b60472ca2f78adb8837b9f5849a2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 9 May 2021 22:05:02 -0700 Subject: PR feedback --- library/alloc/src/lib.rs | 4 ++-- library/core/src/iter/traits/iterator.rs | 3 ++- src/test/codegen/try_identity.rs | 8 ++++---- src/test/mir-opt/simplify-arm.rs | 8 ++++---- src/test/mir-opt/simplify_try.rs | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src/test/codegen') diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index a635d6ffe99..3bc376482e9 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -140,8 +140,8 @@ #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_uninit_array)] #![feature(alloc_layout_extra)] #![feature(trusted_random_access)] -#![feature(try_trait)] -#![feature(try_trait_v2)] +#![cfg_attr(bootstrap, feature(try_trait))] +#![cfg_attr(not(bootstrap), feature(try_trait_v2))] #![feature(min_type_alias_impl_trait)] #![feature(associated_type_bounds)] #![feature(slice_group_by)] diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index ffac4534b20..777e4bc2c89 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -2418,7 +2418,8 @@ pub trait Iterator { Self: Sized, F: FnMut(&Self::Item) -> R, R: Try, - // FIXME: This is a weird bound; the API should change + // FIXME: This bound is rather strange, but means minimal breakage on nightly. + // See #85115 for the issue tracking a holistic solution for this and try_map. R: crate::ops::TryV2>, { #[inline] diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs index 78da06b2fe4..71bfc3b44da 100644 --- a/src/test/codegen/try_identity.rs +++ b/src/test/codegen/try_identity.rs @@ -7,10 +7,10 @@ type R = Result; -// 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. +// 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. +// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 #[no_mangle] pub fn try_identity(x: R) -> R { // CHECK: start: diff --git a/src/test/mir-opt/simplify-arm.rs b/src/test/mir-opt/simplify-arm.rs index b789b87f6c2..6a6e39e68f9 100644 --- a/src/test/mir-opt/simplify-arm.rs +++ b/src/test/mir-opt/simplify-arm.rs @@ -28,10 +28,10 @@ fn from_error(e: E) -> Result { 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. +// 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. +// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 fn id_try(r: Result) -> Result { let x = match into_result(r) { Err(e) => return from_error(From::from(e)), diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs index a95cb665a97..b91a7bfe68f 100644 --- a/src/test/mir-opt/simplify_try.rs +++ b/src/test/mir-opt/simplify_try.rs @@ -13,10 +13,10 @@ fn from_error(e: E) -> Result { 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. +// 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. +// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 fn try_identity(x: Result) -> Result { let y = match into_result(x) { Err(e) => return from_error(From::from(e)), -- cgit 1.4.1-3-g733a5 From 6f7dea74d7699707cfdcf81435c200923d0a5047 Mon Sep 17 00:00:00 2001 From: scottmcm Date: Tue, 18 May 2021 18:29:34 +0000 Subject: Mention the issue number for the new mir-opt in the FIXMEs Thanks for the suggestions, lcnr! Co-authored-by: lcnr --- src/test/codegen/try_identity.rs | 2 +- src/test/mir-opt/simplify-arm.rs | 2 +- src/test/mir-opt/simplify_try.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/test/codegen') diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs index 71bfc3b44da..0363b9dd19e 100644 --- a/src/test/codegen/try_identity.rs +++ b/src/test/codegen/try_identity.rs @@ -9,7 +9,7 @@ type R = Result; // 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. -// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR optimization // that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 #[no_mangle] pub fn try_identity(x: R) -> R { diff --git a/src/test/mir-opt/simplify-arm.rs b/src/test/mir-opt/simplify-arm.rs index 6a6e39e68f9..e0c7b95a5ec 100644 --- a/src/test/mir-opt/simplify-arm.rs +++ b/src/test/mir-opt/simplify-arm.rs @@ -30,7 +30,7 @@ fn from_error(e: E) -> Result { // 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. -// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR optimization // that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 fn id_try(r: Result) -> Result { let x = match into_result(r) { diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs index b91a7bfe68f..46c239ebe32 100644 --- a/src/test/mir-opt/simplify_try.rs +++ b/src/test/mir-opt/simplify_try.rs @@ -15,7 +15,7 @@ fn from_error(e: E) -> Result { // 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. -// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR optimization // that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 fn try_identity(x: Result) -> Result { let y = match into_result(x) { -- cgit 1.4.1-3-g733a5 From e2edee4da07032de72ac930df1453780dbe73f3b Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 18 May 2021 11:48:00 -0700 Subject: No matter how trivial the change, tidy always finds a way to complain... --- src/test/codegen/try_identity.rs | 4 ++-- src/test/mir-opt/simplify-arm.rs | 4 ++-- src/test/mir-opt/simplify_try.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/test/codegen') diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs index 0363b9dd19e..3ff77163b9f 100644 --- a/src/test/codegen/try_identity.rs +++ b/src/test/codegen/try_identity.rs @@ -9,8 +9,8 @@ type R = Result; // 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. -// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR optimization -// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 +// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR +// optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. #[no_mangle] pub fn try_identity(x: R) -> R { // CHECK: start: diff --git a/src/test/mir-opt/simplify-arm.rs b/src/test/mir-opt/simplify-arm.rs index e0c7b95a5ec..f7dcaa13449 100644 --- a/src/test/mir-opt/simplify-arm.rs +++ b/src/test/mir-opt/simplify-arm.rs @@ -30,8 +30,8 @@ fn from_error(e: E) -> Result { // 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. -// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR optimization -// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 +// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR +// optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. fn id_try(r: Result) -> Result { let x = match into_result(r) { Err(e) => return from_error(From::from(e)), diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs index 46c239ebe32..15e351e7d50 100644 --- a/src/test/mir-opt/simplify_try.rs +++ b/src/test/mir-opt/simplify_try.rs @@ -15,8 +15,8 @@ fn from_error(e: E) -> Result { // 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. -// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR optimization -// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 +// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR +// optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. fn try_identity(x: Result) -> Result { let y = match into_result(x) { Err(e) => return from_error(From::from(e)), -- cgit 1.4.1-3-g733a5