about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-11-07 07:26:00 +0100
committerRalf Jung <post@ralfj.de>2024-11-13 09:53:42 +0100
commitc00d64250b0066d7ed736b111cbe7f7bf5c8cbba (patch)
treee5e7939e3908ce05c527914a7db1ab8a9818d895
parent78bb5ee79e0261e8e47476b631da02acc1cb03ef (diff)
downloadrust-c00d64250b0066d7ed736b111cbe7f7bf5c8cbba.tar.gz
rust-c00d64250b0066d7ed736b111cbe7f7bf5c8cbba.zip
const_panic: don't wrap it in a separate function
-rw-r--r--library/core/src/intrinsics/mod.rs25
-rw-r--r--library/core/src/num/f128.rs5
-rw-r--r--library/core/src/num/f16.rs5
-rw-r--r--library/core/src/panic.rs9
4 files changed, 34 insertions, 10 deletions
diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs
index d33a403cfda..bf4e4a0b32f 100644
--- a/library/core/src/intrinsics/mod.rs
+++ b/library/core/src/intrinsics/mod.rs
@@ -2965,14 +2965,35 @@ 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 0484611958d..46e86c306fb 100644
--- a/library/core/src/num/f128.rs
+++ b/library/core/src/num/f128.rs
@@ -1268,8 +1268,9 @@ impl f128 {
             min <= max,
             "min > max, or either was NaN",
             "min > max, or either was NaN. min = {min:?}, max = {max:?}",
-            min: f128,
-            max: f128,
+            // FIXME(f16_f128): Passed by-ref to avoid codegen crashes
+            min: &f128 = &min,
+            max: &f128 = &max,
         );
 
         if self < min {
diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs
index 898caf835bf..91a9bb5cbbe 100644
--- a/library/core/src/num/f16.rs
+++ b/library/core/src/num/f16.rs
@@ -1243,8 +1243,9 @@ impl f16 {
             min <= max,
             "min > max, or either was NaN",
             "min > max, or either was NaN. min = {min:?}, max = {max:?}",
-            min: f16,
-            max: f16,
+            // FIXME(f16_f128): Passed by-ref to avoid codegen crashes
+            min: &f16 = &min,
+            max: &f16 = &max,
         );
 
         if self < min {
diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs
index f8f3962ce55..e702056f00a 100644
--- a/library/core/src/panic.rs
+++ b/library/core/src/panic.rs
@@ -206,15 +206,16 @@ 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(always)] // inline the wrapper
         #[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),* } -> !:
-                if const #[track_caller] {
+                @capture { $($arg: $ty = $arg),* } -> !:
+                #[noinline]
+                if const #[track_caller] #[inline] { // Inline this, to prevent codegen
                     $crate::panic!($const_msg)
-                } else #[track_caller] {
+                } else #[track_caller] { // Do not inline this, it makes perf worse
                     $crate::panic!($runtime_msg)
                 }
             )