Make more float intrinsics generic - #162395
Conversation
|
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri
cc @rust-lang/miri
cc @tgross35 Some changes occurred to the CTFE machinery
cc @Amanieu, @folkertdev, @sayantn Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr
cc @rust-lang/miri Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri
cc @bjorn3
cc @rust-lang/wg-const-eval |
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
| #[rustc_const_unstable(feature = "core_intrinsics", issue = "none")] | ||
| #[rustc_intrinsic_const_stable_indirect] |
There was a problem hiding this comment.
Noted this required adding #[rustc_const_unstable] to the whole intrinsic,
Why was this needed? I guess it is because the body now needs unstable const features, namely const traits? We should ensure const traits are stable enough before we do that.
(I now notice that you already did the same for fabs. We should have already checked this there then but forgot.)
@BoxyUwU @lcnr @oli-obk are const traits in a state where we can use them internally in const functions that can be called by public monomorphic stable const functions? I think this still allows us to change the syntax and logic for const traits pretty much arbitrarily as long as we keep some way of invoking trait functions in a const fn.
| #[rustc_const_unstable(feature = "core_intrinsics", issue = "none")] | ||
| #[rustc_intrinsic_const_stable_indirect] |
There was a problem hiding this comment.
This combination of attributes is a strange one.
#[rustc_const_unstable(feature = "core_intrinsics", issue = "none")]
#[rustc_intrinsic_const_stable_indirect]
I don't think I ever intended for this combination to be used. It looks quite unsafe, from a const-stability perspective. We should disallow it and require something like rustc_allow_const_fn_unstable instead.
There was a problem hiding this comment.
fabs seems to be the only intrinsic using this. I am quite uncomfortable with adding more such intrinsics. If possible, we should remove this from fabs as well. Unfortunately I won't have time to work on fixing this hole in our const stability checks any time soon. (Well I can easily add the check that rejects this but probably cannot explore adding alternatives.)
There was a problem hiding this comment.
i admit this is me just trying to understand how to make things compile. very happy to do something else or exploring adding/fixing an attribute
- without
#[rustc_const_unstable(feature = "core_intrinsics", issue = "none")], we get "const function that might be (indirectly) exposed to stable cannot use#[feature(const_trait_impl)]" - without
#[rustc_intrinsic_const_stable_indirect], we get "const function that might be (indirectly) exposed to stable cannot use#[feature(core_intrinsics)]"
There was a problem hiding this comment.
fixed (folded into the relevant commits), there now is rustc_allow_const_fn_unstable; i guess this needs some approval
d78924b to
06625b8
Compare
|
cc @rust-lang/clippy |
06625b8 to
da4599d
Compare
This comment has been minimized.
This comment has been minimized.
ca3f9a9 to
b4275be
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
b4275be to
49057d4
Compare
|
Please also update the PR description to reflect which intrinsics are actually being changed here now. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| // bitwise, no NaN adjustments | ||
| sym::fabs => interp_ok(x.abs().into()), |
There was a problem hiding this comment.
This comment is only correct for fabs. The code makes it currently look like it applies to all of them.
| where | ||
| F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>, | ||
| { | ||
| let x: F = x.to_float()?; |
There was a problem hiding this comment.
By removing this here, now every caller needs to call to_float first... is that really better?
View all comments
Another (big) step of #153834 + #160989
Makemore remaining float intrinsics generic! Each commit is self-contained.
In order:
ceil,floor,trunc,round,round_ties_even, with const libm fallbacks (using#[rustc_do_not_const_check], see Intrinsics should allow a non-const fallback body if hooked for CTFE #150961, cc @RalfJung @tgross35)sqrt, with libm fallbackspowf, with libm fallbacksfmaandfmuladd, with libm fallbacks (+#[rustc_do_not_const_check]) and a shared fallback, respectively.powi, with no fallback (it already didn't have any)The first commit just removes the f16/f128 fallbacks for
fabs, as mentioned here. I didn't try making the backends use more fallbacks, to make the PR less risky since it's quite large. Happy to do changes there though (cc @folkertdev)copysign,minimum_number_nsz,maximum_number_nsz,minimum,maximumwill be handled separately as they requirerustc_allow_const_fn_unstable