-
Notifications
You must be signed in to change notification settings - Fork 13.4k
De-LLVM the unchecked shifts [MCP#693] #123226
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2224,18 +2224,20 @@ extern "rust-intrinsic" { | |
/// Safe wrappers for this intrinsic are available on the integer | ||
/// primitives via the `checked_shl` method. For example, | ||
/// [`u32::checked_shl`] | ||
#[cfg(not(bootstrap))] | ||
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")] | ||
#[rustc_nounwind] | ||
pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T; | ||
pub fn unchecked_shl<T: Copy, U: Copy>(x: T, y: U) -> T; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to make shift amount generic? Why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the shift amount always u32 was actually what I did first. However, MIR actually supports arbitrary heterogeneous shifts, even though for the unchecked once those weren't accessible. So when the RHS was always So supporting mixed types here is helpful in that we can still write tests that exercise those codepaths in CTFE and Codegen. And it doesn't make the lowering to MIR any harder, nor add any extra work to what the backends already needed to handle. It also turned out convenient in that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit weird (given that we don't publicly expose this), but given this does not make backend more complex, ig this is fine. |
||
/// Performs an unchecked right shift, resulting in undefined behavior when | ||
/// `y < 0` or `y >= N`, where N is the width of T in bits. | ||
/// | ||
/// Safe wrappers for this intrinsic are available on the integer | ||
/// primitives via the `checked_shr` method. For example, | ||
/// [`u32::checked_shr`] | ||
#[cfg(not(bootstrap))] | ||
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")] | ||
#[rustc_nounwind] | ||
pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T; | ||
pub fn unchecked_shr<T: Copy, U: Copy>(x: T, y: U) -> T; | ||
|
||
/// Returns the result of an unchecked addition, resulting in | ||
/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`. | ||
|
Uh oh!
There was an error while loading. Please reload this page.