-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets #134689
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
Conversation
|
rustbot has assigned @workingjubilee. Use |
|
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @rust-lang/wg-const-eval |
71fbca1 to
313c4bc
Compare
This comment has been minimized.
This comment has been minimized.
oli-obk
left a comment
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.
r=me with output blessed
…dd offsets in the type
313c4bc to
af1c8da
Compare
|
@bors r=oli-obk |
|
Somehow this does not show up in the queue? |
|
@bors r=oli-obk |
|
💡 This pull request was already approved, no need to approve it again.
|
|
@bors rollup |
Rollup of 5 pull requests Successful merges: - rust-lang#134638 (Fix effect predicates from item bounds in old solver) - rust-lang#134662 (Fix safety docs for `dyn Any + Send {+ Sync}`) - rust-lang#134689 (core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets) - rust-lang#134699 (Belay new reviews for workingjubilee) - rust-lang#134701 (Correctly note item kind in `NonConstFunctionCall` error message) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#134689 - RalfJung:ptr-swap-test, r=oli-obk core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets Ensure that the pointer gets swapped correctly even if it is not stored at an aligned offset. This rules out implementations that copy things in a `usize` loop -- so our implementation needs to be adjusted to avoid such a loop when running in const context. Part of rust-lang#133668
Redo the swap code for better tail & padding handling A couple of parts here ## Fixes rust-lang#134713 Actually using the type passed to `ptr::swap_nonoverlapping` for anything other than its size + align turns out to not work, so this redo goes back to *always* swapping via not-`!noundef` integers. (Except in `const`, which keeps doing the same thing as before to preserve `@RalfJung's` fix from rust-lang#134689) ## Fixes rust-lang#134946 I'd previously moved the swapping to use auto-vectorization, but someone pointed out on Discord that the tail loop handling from that left a whole bunch of byte-by-byte swapping around. This PR goes back to a manual chunk, with at most logarithmic more instructions for the tail. (There are other ways that could potentially handle the tail even better, but this seems to be pretty good, since it's how LLVM ends up lowering operations on types like `i56`.) ## Polymorphization Since it's silly to have separate copies of swapping -- especially *untyped* swapping! -- for `u32`, `i32`, `f32`, `[u16; 2]`, etc, this sends everything to byte versions, but still mono'd by alignment. That should make it more ok that the code is somewhat more complex, since we only get 7 monomorphizations of the complicated bit. (One day we'll be able to remove some of the hacks by being able to just call `foo::<{align_of::<T>()}>`, but since alignments are only powers of two, the manual dispatch out isn't a big deal.)
Ensure that the pointer gets swapped correctly even if it is not stored at an aligned offset. This rules out implementations that copy things in a
usizeloop -- so our implementation needs to be adjusted to avoid such a loop when running in const context.Part of #133668