-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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? The context here is that operations that read/write a part of a pointer generally don't work in const-eval. 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.) We could beef up const-eval so that it can support this kind of code (see rust-lang/const-eval#72), but doing so is non-trivial. |
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
I personally think that as these errors are unrecoverable (i.e. I would be hesitant if ctfe were able to silently fail during candidate selection with const generics) then erroring in this case for now seems totally acceptable for me, especially if it unblocks an otherwise useful function. Adding pointer fragments in the future would be backwards compatible afaict |
Yeah this behaves like other dynamically detected "const cannot do this" errors, such as |
@rust-lang/lang any comment on this? This is the last raw pointer function that is |
@RalfJung Wearing a lang hat but not speaking for the rest of the lang team:
|
Generally things that take this shape get a warm reception. It sounds fine to me. We'll try to get to this one in the meeting next week. |
If this is a 2-way door (sounds like yes) then I have no objection to stabilizing. I admit I don't 100% understand the details of the question @RalfJung that you are asking though. |
@rustbot labels -I-lang-nominated We talked about this in the meeting today and had positive vibes. Please nominate for us the stabilization PR and we'll FCP that. |
Stabilization is never a 2-way door, we cannot un-do a stabilization... so I am confused by the first part of your message. For the second part, basically I am asking whether it is okay to stabilize a function that sometimes leads to a const-eval failure in a situation where the code doesn't have UB or anything like that -- it's just a situation that is hard to support in const-eval, and our current implementation does not support it. |
@RalfJung For the first part, the conclusion was "this doesn't commit us to continuing to fail in this case, we can start handling it in the future". @nikomatsakis I think you wanted "not closing a one-way door" rather than "is a two-way door". :) |
Let me restate my summary of what is happening to check my understanding: If I understand, the impl of @RalfJung the two-way door I was referring to is: we can fix this impl bug in the future. |
No, it has nothing to do with that. It is always UB to do any kind of access on adjacent allocations. The |
I came up with a new version of the example, maybe that makes it more clear. :) Stabilization PR is up at #137280. |
The issue is that doing a bytewise copy of memory containing pointers will fail as we cannot represent a single byte of a pointer right now. |
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 > 1
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: