-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Implement Integer funnel shifts #145690
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
base: master
Are you sure you want to change the base?
Implement Integer funnel shifts #145690
Conversation
This comment has been minimized.
This comment has been minimized.
I see there is a tracking issue, but not an ACP for this. Could you create one? It's an issue template at https://github.com/rust-lang/libs-team/issues. |
81da1f2
to
b91850b
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
b91850b
to
400a29d
Compare
This comment has been minimized.
This comment has been minimized.
400a29d
to
23601d2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5f4c412
to
63fde15
Compare
This comment has been minimized.
This comment has been minimized.
@bjorn3 could you look into this ICE? The clif code looks fine enough, and I don't have enough expertise on clif to see what's going wrong. |
At the very least there is a bug in the Cranelift IR verifier causing it to panic at https://github.com/bytecodealliance/wasmtime/blob/ecda6e330a946821b5edc0a90bd62288cf7df943/cranelift/codegen/src/verifier/mod.rs#L1907 But the thing you are doing wrong is Edit: I'm not sure how that even passed the typecheck pass of the verifier. |
63fde15
to
3d0b3fb
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the tracking issue to have signatures matching rust-lang/libs-team#642 (comment)? This should match then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍🏽, could you check if it makes sense (I'm bad at writing docs etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier than that: tracking issues should show function signatures in something like an impl uX { ... }
block, no need to write docs :)
- Add a fallback implementation for the intrinsics Co-Authored-By: folkertdev <[email protected]>
Co-Authored-By: folkertdev <[email protected]>
3d0b3fb
to
d1f3861
Compare
Should I add more variants of the functions? (e.g. |
I don't think there is any need in the initial PR here. They can be added as a followup |
Also worth mentioning that the hardest part here is getting the intrinsic and actual functionality working, since all the other variants, at least for shifts, just require a few explicit checks. |
In that case, I guess this PR is ready. @rustbot ready |
#[rustc_nounwind] | ||
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] | ||
#[unstable(feature = "funnel_shifts", issue = "145686")] | ||
#[miri::intrinsic_fallback_is_spec] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This attribute means the fallback implementation must check the size to be valid and do unreachable_unchecked
(or equivalent) in that case.
Please add Miri tests to ensure this works correctly: all cases of UB must be detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation, I don't think you are checking for UB here. Seems like unchecked_funnel_shl(0, 0, n)
will just work for any n
.
Please don't just blindly add attributes like this, make sure you understand them or ask what to do. Adding this attribute incorrectly introduces hard-to-find bugs into the very tools unsafe code authors trust to find bugs for them.
EDIT: Or, are you relying on the checks in unchecked_shr
/unchecked_shl
? That's super subtle, definitely needs a comment at least.
Parent: #145686
ACP: rust-lang/libs-team#642
This implements funnel shifts on primitive integer types. Implements this for cg_llvm, with a fallback impl for everything else
Thanks @folkertdev for the fixes and tests
cc @rust-lang/libs-api