File tree 4 files changed +34
-10
lines changed
4 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -2965,14 +2965,35 @@ pub(crate) macro const_eval_select {
2965
2965
$( #[ $compiletime_attr: meta] ) * $compiletime: block
2966
2966
else
2967
2967
$( #[ $runtime_attr: meta] ) * $runtime: block
2968
+ ) => {
2969
+ // Use the `noinline` arm, after adding explicit `inline` attributes
2970
+ $crate:: intrinsics:: const_eval_select!(
2971
+ @capture { $( $arg : $ty = $val) , * } $( -> $ret) ? :
2972
+ #[ noinline]
2973
+ if const
2974
+ #[ inline] // prevent codegen on this function
2975
+ $( #[ $compiletime_attr] ) *
2976
+ $compiletime
2977
+ else
2978
+ #[ inline] // avoid the overhead of an extra fn call
2979
+ $( #[ $runtime_attr] ) *
2980
+ $runtime
2981
+ )
2982
+ } ,
2983
+ // With a leading #[noinline], we don't add inline attributes
2984
+ (
2985
+ @capture { $( $arg: ident : $ty: ty = $val: expr) , * $( , ) ? } $( -> $ret: ty ) ? :
2986
+ #[ noinline]
2987
+ if const
2988
+ $( #[ $compiletime_attr: meta] ) * $compiletime: block
2989
+ else
2990
+ $( #[ $runtime_attr: meta] ) * $runtime: block
2968
2991
) => { {
2969
- #[ inline] // avoid the overhead of an extra fn call
2970
2992
$( #[ $runtime_attr] ) *
2971
2993
fn runtime( $( $arg: $ty) , * ) $( -> $ret ) ? {
2972
2994
$runtime
2973
2995
}
2974
2996
2975
- #[ inline] // prevent codegen on this function
2976
2997
$( #[ $compiletime_attr] ) *
2977
2998
const fn compiletime( $( $arg: $ty) , * ) $( -> $ret ) ? {
2978
2999
// Don't warn if one of the arguments is unused.
Original file line number Diff line number Diff line change @@ -1268,8 +1268,9 @@ impl f128 {
1268
1268
min <= max,
1269
1269
"min > max, or either was NaN" ,
1270
1270
"min > max, or either was NaN. min = {min:?}, max = {max:?}" ,
1271
- min: f128,
1272
- max: f128,
1271
+ // FIXME(f16_f128): Passed by-ref to avoid codegen crashes
1272
+ min: & f128 = & min,
1273
+ max: & f128 = & max,
1273
1274
) ;
1274
1275
1275
1276
if self < min {
Original file line number Diff line number Diff line change @@ -1243,8 +1243,9 @@ impl f16 {
1243
1243
min <= max,
1244
1244
"min > max, or either was NaN" ,
1245
1245
"min > max, or either was NaN. min = {min:?}, max = {max:?}" ,
1246
- min: f16,
1247
- max: f16,
1246
+ // FIXME(f16_f128): Passed by-ref to avoid codegen crashes
1247
+ min: & f16 = & min,
1248
+ max: & f16 = & max,
1248
1249
) ;
1249
1250
1250
1251
if self < min {
Original file line number Diff line number Diff line change @@ -206,15 +206,16 @@ pub macro const_panic {
206
206
// add the `rustc_allow_const_fn_unstable`. This is okay to do
207
207
// because both variants will panic, just with different messages.
208
208
#[ rustc_allow_const_fn_unstable( const_eval_select) ]
209
- #[ inline( always) ]
209
+ #[ inline( always) ] // inline the wrapper
210
210
#[ track_caller]
211
211
#[ cfg_attr( bootstrap, rustc_const_stable( feature = "const_panic" , since = "CURRENT_RUSTC_VERSION" ) ) ]
212
212
const fn do_panic ( $( $arg: $ty) , * ) -> ! {
213
213
$crate:: intrinsics:: const_eval_select!(
214
- @capture { $( $arg: $ty) , * } -> !:
215
- if const #[ track_caller] {
214
+ @capture { $( $arg: $ty = $arg) , * } -> !:
215
+ #[ noinline]
216
+ if const #[ track_caller] #[ inline] { // Inline this, to prevent codegen
216
217
$crate :: panic!( $const_msg)
217
- } else #[ track_caller] {
218
+ } else #[ track_caller] { // Do not inline this, it makes perf worse
218
219
$crate :: panic!( $runtime_msg)
219
220
}
220
221
)
You can’t perform that action at this time.
0 commit comments