-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make some float methods unstable const fn
#130568
base: master
Are you sure you want to change the base?
Conversation
The Miri subtree was changed cc @rust-lang/miri Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
4c6f58d
to
e60ae9b
Compare
r=me on the interpreter and Miri parts. |
e60ae9b
to
bf34851
Compare
I made |
This comment has been minimized.
This comment has been minimized.
bf34851
to
10c3e6c
Compare
You can go ahead and do this in advance, I don't think there is any reason these would be rejected |
#[rustc_const_unstable(feature = "f128", issue = "116909")] | ||
pub const fn is_sign_positive(self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for including f16 and f128 :) would you mind adding a commented out gate on methods from this feature? E.g.
// #[rustc_const_unstable(feature = "const_float_methods", issue = "...")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
pub const fn is_sign_positive(self) -> bool {
We just do that to keep things somewhat linked if API falls under >1 gate.
7caa07b
to
c06c255
Compare
This comment has been minimized.
This comment has been minimized.
Created tracking issue: #130843 For f16/f32 methods, I placed commented gates under the same feature as f32/f64 (e.g., |
c06c255
to
a79103f
Compare
☔ The latest upstream changes (presumably #130157) made this pull request unmergeable. Please resolve the merge conflicts. |
a79103f
to
fa312ed
Compare
I believe |
src/tools/miri/src/intrinsics/mod.rs
Outdated
@@ -249,28 +249,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |||
this.write_scalar(res, dest)?; | |||
} | |||
|
|||
"minnumf32" | "maxnumf32" | "copysignf32" => { | |||
"copysignf32" => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, is there a reason you are not including copy_sign
in this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could move it to rustc_const_eval. But, do we want to make copysign
and abs
const? Ideally, we'd want to, but since they are implemented in libstd instead of libcore, I'm not sure what's the deal with those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we wouldn't make them const.
I also don't know why they are in std
, maybe the intrinsic is sometimes compiled to a libcall or so... let's just leave them where they are. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make them const. But I find it quite weird that we have operations like min/max or %
in libcore, while we are afraid to have operations like abs
or copysign
that can be trivially implemented with bitwise operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree. Maybe file an issue for that?
EDIT: Ah, an issue already exists: #50145
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made abs
, copysign
and signum
(which uses copysign
) const.
} | ||
} | ||
|
||
enum FloatBinOp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum FloatBinOp { | |
enum FloatBinIntrinsic { |
We use BinOp
for the MIR binops, IMO we shouldn't mix up that terminology.
Also please move this above the functions that use it.
@@ -0,0 +1,46 @@ | |||
//@ run-pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//@ run-pass | |
//@ run-pass | |
//! Tests the float intrinsics: min, max, abs, copysign |
a61692c
to
593f644
Compare
LGTM from the interpreter side. r? libs-api |
593f644
to
ab0560c
Compare
Rebased to pick #131256 and remove |
☔ The latest upstream changes (presumably #131581) made this pull request unmergeable. Please resolve the merge conflicts. |
Some float methods are now `const fn` under the `const_float_methods` feature gate (except `f16` and `f128` versions, which I placed under `f16` and `f128` feature gates respectively). In order to support `min` / `max`, the implementation of some intrinsics had to be moved from Miri to rustc_const_eval.
ab0560c
to
3a32e66
Compare
If libs-api can just okay unstably adding @rustbot label +I-libs-api-nominated |
Some float methods are now
const fn
under theconst_float_methods
feature gate (exceptf16
andf128
versions, which I placed underf16
andf128
feature gates respectively).I also made some unstable methods
const fn
, keeping their constness under their respective feature gate.In order to support
min
/max
, the implementation of some intrinsics had to be moved from Miri to rustc_const_eval (cc @RalfJung).Tracking issue: #130843
r? libs-api