mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-08 16:07:43 +00:00
Auto merge of #132662 - RalfJung:const-panic-inlining, r=tgross35
tweak attributes for const panic macro Let's do some random mutations of this macro to see if that can re-gain the perf lost in https://github.com/rust-lang/rust/pull/132542.
This commit is contained in:
commit
8adb4b30f4
@ -2989,14 +2989,35 @@ pub(crate) macro const_eval_select {
|
|||||||
$(#[$compiletime_attr:meta])* $compiletime:block
|
$(#[$compiletime_attr:meta])* $compiletime:block
|
||||||
else
|
else
|
||||||
$(#[$runtime_attr:meta])* $runtime:block
|
$(#[$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])*
|
$(#[$runtime_attr])*
|
||||||
fn runtime($($arg: $ty),*) $( -> $ret )? {
|
fn runtime($($arg: $ty),*) $( -> $ret )? {
|
||||||
$runtime
|
$runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline] // prevent codegen on this function
|
|
||||||
$(#[$compiletime_attr])*
|
$(#[$compiletime_attr])*
|
||||||
const fn compiletime($($arg: $ty),*) $( -> $ret )? {
|
const fn compiletime($($arg: $ty),*) $( -> $ret )? {
|
||||||
// Don't warn if one of the arguments is unused.
|
// Don't warn if one of the arguments is unused.
|
||||||
|
@ -1268,8 +1268,9 @@ impl f128 {
|
|||||||
min <= max,
|
min <= max,
|
||||||
"min > max, or either was NaN",
|
"min > max, or either was NaN",
|
||||||
"min > max, or either was NaN. min = {min:?}, max = {max:?}",
|
"min > max, or either was NaN. min = {min:?}, max = {max:?}",
|
||||||
min: f128,
|
// FIXME(f16_f128): Passed by-ref to avoid codegen crashes
|
||||||
max: f128,
|
min: &f128 = &min,
|
||||||
|
max: &f128 = &max,
|
||||||
);
|
);
|
||||||
|
|
||||||
if self < min {
|
if self < min {
|
||||||
|
@ -1243,8 +1243,9 @@ impl f16 {
|
|||||||
min <= max,
|
min <= max,
|
||||||
"min > max, or either was NaN",
|
"min > max, or either was NaN",
|
||||||
"min > max, or either was NaN. min = {min:?}, max = {max:?}",
|
"min > max, or either was NaN. min = {min:?}, max = {max:?}",
|
||||||
min: f16,
|
// FIXME(f16_f128): Passed by-ref to avoid codegen crashes
|
||||||
max: f16,
|
min: &f16 = &min,
|
||||||
|
max: &f16 = &max,
|
||||||
);
|
);
|
||||||
|
|
||||||
if self < min {
|
if self < min {
|
||||||
|
@ -206,15 +206,16 @@ pub macro const_panic {
|
|||||||
// add the `rustc_allow_const_fn_unstable`. This is okay to do
|
// add the `rustc_allow_const_fn_unstable`. This is okay to do
|
||||||
// because both variants will panic, just with different messages.
|
// because both variants will panic, just with different messages.
|
||||||
#[rustc_allow_const_fn_unstable(const_eval_select)]
|
#[rustc_allow_const_fn_unstable(const_eval_select)]
|
||||||
#[inline(always)]
|
#[inline(always)] // inline the wrapper
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_panic", since = "CURRENT_RUSTC_VERSION"))]
|
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_panic", since = "CURRENT_RUSTC_VERSION"))]
|
||||||
const fn do_panic($($arg: $ty),*) -> ! {
|
const fn do_panic($($arg: $ty),*) -> ! {
|
||||||
$crate::intrinsics::const_eval_select!(
|
$crate::intrinsics::const_eval_select!(
|
||||||
@capture { $($arg: $ty),* } -> !:
|
@capture { $($arg: $ty = $arg),* } -> !:
|
||||||
if const #[track_caller] {
|
#[noinline]
|
||||||
|
if const #[track_caller] #[inline] { // Inline this, to prevent codegen
|
||||||
$crate::panic!($const_msg)
|
$crate::panic!($const_msg)
|
||||||
} else #[track_caller] {
|
} else #[track_caller] { // Do not inline this, it makes perf worse
|
||||||
$crate::panic!($runtime_msg)
|
$crate::panic!($runtime_msg)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user