Make min/max and copysign intrinsics generic - #162414
Conversation
|
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr
cc @bjorn3
cc @rust-lang/clippy
cc @rust-lang/miri
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri
cc @rust-lang/wg-const-eval
cc @rust-lang/wg-const-eval Some changes occurred to the CTFE machinery |
|
|
I just realized that we can maybe just use |
|
doesn't that feel a bit hackier / risk prone that just doing it like this? though i don't mind, we are calling externs from |
This comment has been minimized.
This comment has been minimized.
IMO it makes sense -- in both cases it's a fallback body that we don't want to use for const-eval, just the reason for not using it is different. |
|
CI is red. Also please add the same kind of test as in your other PR. Yeah that means they will conflict -- sorry for that. Shouldn't be too hard of a conflict to deal with I hope. @rustbot author |
1514b9c to
101eb51
Compare
|
de-constified the trait, as done in #162409, and switched to |
There was a problem hiding this comment.
LGTM on the Rust + LLVM side, but I can't review the other codegen backends. Looks like the GCC changes already got approved -- @bjorn3 could you look at the cranelift changes?
| } else if y < x { | ||
| #[rustc_do_not_const_check] | ||
| pub const fn maximum_number_nsz<T: bounds::FloatPrimitive>(x: T, y: T) -> T { | ||
| if x.is_nan() || y >= x { |
There was a problem hiding this comment.
FWIW this would have been easier to review if you had kept the original order of the intrinsics. Please keep that in mind when writing a PR that someone else is expected to review -- never reorder and change code at the same time, git can't really deal with that.
| /// Therefore, implementations must not require the user to uphold | ||
| /// any safety invariants. | ||
| #[rustc_nounwind] | ||
| #[rustc_intrinsic_const_stable_indirect] |
There was a problem hiding this comment.
Is this attribute needed? It was not needed before...
There was a problem hiding this comment.
Well it will be needed with my PR, so let's keep it. :) Just curious why you added it here as I didn't think anything would force you to add it before my PR.
There was a problem hiding this comment.
Process-wise, adding the attribute is covered by the FCP in #130843 (comment).
There was a problem hiding this comment.
No wait, that was for min/maximum_number_nsz. This here is min/maximum which is not yet stable. It really shouldn't get the attribute then.
Add #[rustc_const_unstable] instead.
| /// Used to distinguish fallbacks of float intrinsics. For some we have a codegen fallback, | ||
| /// while for others we fallback to an external libcall. | ||
| enum IntrinsicFallback { | ||
| Fallback(&'static str), |
There was a problem hiding this comment.
So this does not refer to a Rust fallback body? Please pick a different name then, this is confusing. Maybe Libcall or so?
Or, given that this is pre-existing, at least please add a comment.
There was a problem hiding this comment.
I think all cases which use IntrinsicFallback::Fallback should be able to be removed and just use the Rust fallback body? In which case adding a FIXME here to remove it in a future PR seems like a good idea.
|
☔ The latest upstream changes (presumably #162445) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
| // Check that the float intrinsics carrying `#[rustc_do_not_const_check]` can actually be called in | ||
| // a const context, for every float width. Their bodies are never const-checked and never run by | ||
| // const-eval, which has to implement each of these intrinsics itself. |
There was a problem hiding this comment.
FWIW there's no good reason to only cover rustc_do_not_const_check intrinsics here. All const intrinsics without const-capable fallback body should ideally be covered somewhere. Maybe we already test some of them somewhere? I don't know.
| let arg = AbiParam::new(ty); | ||
| fx.lib_call(name, vec![arg, arg], vec![arg], &[x, y])[0] | ||
| } | ||
| }; |
There was a problem hiding this comment.
The fallback variant is never used here.
Split off from #162395
Make the following intrinsics generic over the float type:
copysign, with a shared fallback (bit manipulations). Note that this required adding#[rustc_const_unstable]to the whole intrinsic, whichcopysignf16andcopysignf128didn't have. This was already FCP'd, see rust-lang/rust#153834 (comment).minimum_number_nsz,maximum_number_nsz,minimum,maximum, with shared fallbacks.Because these are generic and require const trait impls to have a fallback, I had to add
#[rustc_allow_const_fn_unstable]to them:copysignneedsconst_ops,const_trait_implminimum_number_nszandmaximum_number_nszneedconst_cmp,const_trait_implminimumandmaximumneedconst_cmp,const_ops,const_trait_implI have also bundled in the addition of the attribute to
fabs, which used these features without having a formal approval (see #162409 -- this was introduced in #153834)See #162395 (comment)
r? RalfJung