-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for const_swap_nonoverlapping #133668
Comments
…lnay Move some functions out of const_swap feature gate - `swap_unchecked` is still unstable as a regular fn, so that feature gate can also cover its constness. - `swap_nonoverlapping` isn't ready to be stabilized yet, so make it a different feature gate. Part of rust-lang#83163, rust-lang#88539, rust-lang#133668
…lnay Move some functions out of const_swap feature gate - `swap_unchecked` is still unstable as a regular fn, so that feature gate can also cover its constness. - `swap_nonoverlapping` isn't ready to be stabilized yet, so make it a different feature gate. Part of rust-lang#83163, rust-lang#88539, rust-lang#133668
Rollup merge of rust-lang#133669 - RalfJung:const_swap_splitup, r=dtolnay Move some functions out of const_swap feature gate - `swap_unchecked` is still unstable as a regular fn, so that feature gate can also cover its constness. - `swap_nonoverlapping` isn't ready to be stabilized yet, so make it a different feature gate. Part of rust-lang#83163, rust-lang#88539, rust-lang#133668
I guess the alternative is that we could just error when there is a pointer straddling the boundary of one of the to-be-swapped chunks. That is what happens today, and it doesn't seem entirely unreasonable? This is probably a very rare situation, after all. @rust-lang/wg-const-eval @rust-lang/lang @rust-lang/opsem do you think it is acceptable for the example code above to error? See here for what the error looks like, and here for a variant of the code that does work since the pointer is entirely contained within a single chunk. (The type used for the chunk does not matter, only its size is relevant.) Operations that read/write a part of a pointer generally don't work in const-eval. For The other option would be to add full support for "pointer fragments" to const-eval, so that parts a pointer can indeed be copied around and reassambled to a fully usable pointer. That's more attractive honestly (solving the problem properly rather than papering over it with a special-case intrinsic), but also is even more work and risks slowing down the common case where we don't have such pointer fragments. (See rust-lang/const-eval#72.) |
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
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
Feature gate:
#![feature(const_swap_nonoverlapping)]
This is a tracking issue for making
swap_nonoverlapping
aconst fn
.Public API
Steps / History
Blocking Issues
ptr::swap_nonoverlapping
has a limitation currently where it can fail when the data-to-swap contains pointers that cross the "element boundary" of such a swap (i.e.,count > 0
and the pointer straddles the boundary between twoT
). Here's an example of code that unexpectedly fails:The proper way to fix this is to implement rust-lang/const-eval#72.
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: