From 0a370d8b28a2354425622f2dc9cbc83f9287b005 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 14 Nov 2024 21:18:17 +0900 Subject: [PATCH] Revert "Auto merge of #132662 - RalfJung:const-panic-inlining, r=tgross35" This reverts commit 8adb4b30f40e6fbd21dc1ba26c3301c7eeb6de3c, reversing changes made to a00df61387e5389d6fe23e38e657f90d672668b1. --- library/core/src/intrinsics/mod.rs | 25 ++----------------------- library/core/src/num/f128.rs | 5 ++--- library/core/src/num/f16.rs | 5 ++--- library/core/src/panic.rs | 9 ++++----- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 72e34e5faf5a7..cbf32e0b550ad 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -3463,35 +3463,14 @@ pub(crate) macro const_eval_select { $(#[$compiletime_attr:meta])* $compiletime:block else $(#[$runtime_attr:meta])* $runtime:block - ) => { - // Use the `noinline` arm, after adding explicit `inline` attributes - $crate::intrinsics::const_eval_select!( - @capture { $($arg : $ty = $val),* } $(-> $ret)? : - #[noinline] - if const - #[inline] // prevent codegen on this function - $(#[$compiletime_attr])* - $compiletime - else - #[inline] // avoid the overhead of an extra fn call - $(#[$runtime_attr])* - $runtime - ) - }, - // With a leading #[noinline], we don't add inline attributes - ( - @capture { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? : - #[noinline] - if const - $(#[$compiletime_attr:meta])* $compiletime:block - else - $(#[$runtime_attr:meta])* $runtime:block ) => {{ + #[inline] // avoid the overhead of an extra fn call $(#[$runtime_attr])* fn runtime($($arg: $ty),*) $( -> $ret )? { $runtime } + #[inline] // prevent codegen on this function $(#[$compiletime_attr])* const fn compiletime($($arg: $ty),*) $( -> $ret )? { // Don't warn if one of the arguments is unused. diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index c3862d994986a..3fac1ef099f35 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -1258,9 +1258,8 @@ impl f128 { min <= max, "min > max, or either was NaN", "min > max, or either was NaN. min = {min:?}, max = {max:?}", - // FIXME(f16_f128): Passed by-ref to avoid codegen crashes - min: &f128 = &min, - max: &f128 = &max, + min: f128, + max: f128, ); if self < min { diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index ed35316cf8f9c..eaac19f22f751 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -1235,9 +1235,8 @@ impl f16 { min <= max, "min > max, or either was NaN", "min > max, or either was NaN. min = {min:?}, max = {max:?}", - // FIXME(f16_f128): Passed by-ref to avoid codegen crashes - min: &f16 = &min, - max: &f16 = &max, + min: f16, + max: f16, ); if self < min { diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs index e702056f00ab4..f8f3962ce55ac 100644 --- a/library/core/src/panic.rs +++ b/library/core/src/panic.rs @@ -206,16 +206,15 @@ pub macro const_panic { // add the `rustc_allow_const_fn_unstable`. This is okay to do // because both variants will panic, just with different messages. #[rustc_allow_const_fn_unstable(const_eval_select)] - #[inline(always)] // inline the wrapper + #[inline(always)] #[track_caller] #[cfg_attr(bootstrap, rustc_const_stable(feature = "const_panic", since = "CURRENT_RUSTC_VERSION"))] const fn do_panic($($arg: $ty),*) -> ! { $crate::intrinsics::const_eval_select!( - @capture { $($arg: $ty = $arg),* } -> !: - #[noinline] - if const #[track_caller] #[inline] { // Inline this, to prevent codegen + @capture { $($arg: $ty),* } -> !: + if const #[track_caller] { $crate::panic!($const_msg) - } else #[track_caller] { // Do not inline this, it makes perf worse + } else #[track_caller] { $crate::panic!($runtime_msg) } )