-
Notifications
You must be signed in to change notification settings - Fork 288
Constants as arguments don't really work #1011
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
Comments
you'll have to use const generics. in fact, it's hoped that we can move all of stdarch to const generics at some point (but it's a fair way off). |
At the moment the only way is to use one of the |
@Amanieu Does the compiler change involve being able to do const math on a const generic? For example, I've designed a wrapper function To make things a bit clearer:-
|
Unfortunately that's not possible due to limitations on const generics. There are plans for const generics to allow that in the future though. |
In the mean time you can sometimes use macros to get a similar situation. |
@Lokathor Thank you. That's exactly what I did yesterday. I do wonder about how llvm will optimize what I've done, but I wont look at that until I'm happy with the design of what I'm trying to achieve (for interest: iterating over a bit set trying to find contiguous ranges of bits with different alignments). Depending how things end up I might end up writing everything using assembler, in any event*. @Amanieu Thank you. That plans going to need us to push back on the compiler currently preventing the definition of I'm beginning to worry that const generics are lacking a proper high-level usage plan - they're coming in drips and drabs, which, from the point of view of gaining experience, is good for their designers but they do need to be driven by real-world use, too. That could be seen as unfair from those on the inside, but it's intended as expression of a worry, not an attack. Everytime I've tried to nudge a point into the conversation, it's been effectively ignored, and the responses here reinforce that view. * this is because intrinsics struggle to express concepts like |
Closing as it seems there's not much more to say. |
I'm adding some wrappers around some of the AVX512 intrinsics to make them a bit more useful. In doing so, I found that there's no real way to propagate that an intrinsic with an argument marked as constant by the
[rustc_args_required_const]
attribute is constant in any wrapper.This seems to also have been an issue in implementing the Altivec intrinsics, eg rust-lang/rust#61180. It's also a pain when adding one's own implementation of an intrinsic that needs to take a constant argument, eg
_kshiftli_mask8()
. One can decorate the function, but it then needs nightly to work (but it needs it anyway to use additional target features like avx512bw to get access to the__mmask8
type).Is there any possibility this working group could push a way of passing arguments as constants as part of const generics into wider Rust? At the moment, I can workaround this problem with the world's worst looking match statement...
The text was updated successfully, but these errors were encountered: