-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
All intrinsics are callable in const fn
#61495
Comments
Note that this is not the same as the problem fixed by #61493: that was about promotion (in a runtime function), the issue here is about calls happening in const context. |
I believe that as far as the "core" intrinsics go, there actually is no issue on stable because the only intrinsic you can directly call on stable is But SIMD intrinsics might be a different story, it might be that those are publicly reexported. Cc @gnzlbg |
I think this is only a problem on nightly, MWE (playground): #![feature(const_fn, core_intrinsics)]
pub const fn bar(a: i32, b: i32) -> (i32, bool) {
unsafe { core::intrinsics::add_with_overflow(a, b) }
} Note that, right now, the type of pub unsafe extern "rust-intrinsic" fn add_with_overflow<T>(
x: T,
y: T
) -> (T, bool) which is not a Being able to call a non- mod foo {
pub unsafe extern "rust-intrinsic" fn add_with_overflow<T>(
x: T,
y: T
) -> (T, bool)
} and just use
I don't think |
Maybe a temporary way to fix, at least for the ones exposed in mod intrinsics {
#[inline(always)]
pub unsafe fn add_with_overflow<T>(x: T, y: T) -> (T, bool) {
extern "rust-intrinsic" { fn add_with_overflow<T>(x: T, y: T) -> (T, bool); }
add_with_overflow(x, y)
}
} that would make the MWE above fail to compile because the functions in |
The bug is not about accidentally executing intrinsics during CTFE. That's impossible, those intrinsics are not even implemented in rustc. (Miri's implementations live out-of-tree.) The bug is about accepting code that calls (stable) (SIMD) intrinsics in a |
So this cannot happen, because we use the pattern I showed here (#61495 (comment)) to implement all stable SIMD intrinsics. That is, all stable SIMD "intrinsics" are not intrinsics, but Rust functions that call intrinsics. The intrinsics themselves are not stable, and the intent is to never stabilize them. |
I see, makes sense. So it seems like this bug does not affect stable, but that's mostly luck (e.g., without #57997 this would be observable on stable). |
@RalfJung The stable whitelist should be https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_mir/transform/qualify_min_const_fn.rs.html#378 and I hope that isn't borked. |
That only applies in stable |
This is still an issue: #![feature(const_fn, core_intrinsics)]
pub const fn bar() {
unsafe { core::intrinsics::assume(true) }
} I think #61835 is supposed to fix this. |
But that PR got closed, so right now there's noone working on this issue AFAK. |
I will take a look in this week. Closed it because not to be pinged by triage. Currently I am rebasing the master. |
@vertexclique any update on this? |
Well... yes and no. It is resolved, but I still want to change it so we don't have these lists at all but instead make all intrinsics use |
At some point we lost the check making sure that in const context (
const
/static
items,const fn
), you can only call a select few whitelisted intrinsics. Instead, you can now call all of them.The issue is that the check happening here does not complain when there is an intrinsic in const context (unlike the checks here that complain about other kinds of function calls in const context).
Cc @oli-obk @eddyb
The text was updated successfully, but these errors were encountered: