-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Consider limiting #[rustc_args_required_const(...)] to intrinsics. #70271
Comments
Why does |
While it's implemented using an LLVM IR instruction that supports variable indices, the corresponding C intrinsics and AVX instructions require an immediate, i.e., a compile time constant index. Variable indices on that target with that vector type lower to "store the vector to the stack and load the desired element from it" instead. So the attribute is useful for consistency with C, to avoid surprisingly bad code generation, and to avoid reliance on LLVM specifics. |
From the perspective of users of the relevant Intel and ARM APIs here, these are expected to be intrinsic functions, even though they are effectively provided as a library. So, parsing this request is a bit challenging. What is the desired outcome here? |
Library APIs for users should be using const generics ideally. We could even make the intrinsics use const generics, but I think some APIs with |
That is correct, as seen in the code you quoted, these were stabilized in #49664 in 1.27 i.e. Rust 2018 with const generic stabilization not in sight and after passing a final comment period in #48556. They had their rustc_args_required_const adornment added at the same time as they were added, That means these APIs have parameters that ask for const values that can be turned into immediates in a form that conforms well with the expected API of the Intel intrinsic functions in C and C++ compilers, as we can see here: So I imagine it's a very "drop in" experience for someone who is used to Intel intrinsics, but is... Admittedly Kinda Awkward in Rust terms. |
Note that we can remove the |
Sure, I thought they already had that. All the calls to these intrinsics use actual literal integer constants, I just want the library function to not have that attribute, as it does not forward its constant argument to the inner intrinsics, it does some runtime check on it. |
So, my understanding, partly informed by @Lokathor's explanation at #73542 (comment), is that this is because it is matching the design of Intel's API. The input to that intrinsic function must be a value that can be compiled as an x86 asm immediate (expressed in the intrinsic function in Intel's guide as |
Yes that's also my understanding. These intrinsics aren't truly accepting const args, they're actually a high level approximation of immediate values being encoded into an assembly instruction. It's not breaking to Rust to suddenly allow a varying argument in a future release, but then it would absolutely fail to do the one job it's supposed to do. Rust is unfortunately bad at expressing a few low level concepts, this is one of them. |
But this sounds like once const generics are sufficiently far along, we could provide new APIs based on const generics, deprecate the old ones, remove their Basically I am not sure if keeping |
given rust-lang/stdarch#876 (comment)
cc @Amanieu |
Yeah, once const generics can handle this they're basically the more "rusty" way to do all this. However, this is actually farther along the dev timeline than |
cc @lcnr ^ |
That requires us to be comfortable using a limited set of |
|
I've just been made aware that functions like this exist: https://github.com/rust-lang/stdarch/blob/abe96ca3b87fcca6aa1dfcefd40d8c8d92d2e673/crates/core_arch/src/x86_64/avx2.rs#L28-L34
I was under the impression that
#[rustc_args_required_const(...)]
would be used primarily for intrinsics (including the behind-rustc
's-back imported LLVM intrinsics), and maybe unstable implementation details.At least right now I am uncomfortable letting
#[rustc_args_required_const(...)]
proliferate any further, and would much prefer any stabilized library-defined functions that rely on the attribute, to become true intrinsics.Sadly, there are a few of them, so this won't be trivial.
cc @rust-lang/compiler
The text was updated successfully, but these errors were encountered: