-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
stabilize ptr_offset_from #74238
stabilize ptr_offset_from #74238
Conversation
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
8bcbf6b
to
db6acc1
Compare
@rfcbot fcp merge |
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This used to just be implemented with normal code, IIRC. Is there some observable semantics that the intrinsic provides? Or is it just for optimization/miri convenience? |
Hm... so in terms of const-eval, there is definitely something observable, as the implementation with normal code just does not work. (CTFE stops when you try to subtract integers that were obtained from pointers, as this is not an operation we can support in general.) But you are right that the part that is being stabilized here could actually be implemented (possibly less efficiently) without the intrinsic. I had not thought of that. |
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.
Removing nomination since we discussed in today's @rust-lang/lang meeting. No concerns were raised. |
cc @cramertj @pnkfelix @withoutboats @sfackler for remaining checkboxes :) |
☔ The latest upstream changes (presumably #73265) made this pull request unmergeable. Please resolve the merge conflicts. |
💔 Test failed - checks-actions |
The @bors r=oli-obk |
📌 Commit 74a860bf2693b58b8058ba371dc93ade6b3810cc has been approved by |
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.
The stable versions should be 1.47, unless you're planning a really quick beta backport...
@bors r- |
also needs another rustfmt run |
One other thing that came to mind: The safety requirement is currently that the pointers differ by a multiple of the size of T. And interestingly there's no requirement that the pointers actually be aligned. That's no a soundness gap -- the current implementation doesn't depend on the pointers being aligned -- but it made me wonder if it should be more constrained than it currently is. |
Good point. This also means it should land before Tuesday or it'll be 1.48 instead. |
In that case however we'd also need a version of this function that works with unaligned pointers. And I cannot imagine how pointers being aligned helps here. Can you? |
Co-authored-by: Josh Stone <cuviper@gmail.com>
@bors r=oli-obk |
📌 Commit 4129e07 has been approved by |
☀️ Test successful - checks-actions, checks-azure |
@RalfJung No, I don't think I can come up with a reason. And I guess with All good as-is, then. |
This stabilizes ptr::offset_from, and closes #41079. It also removes the deprecated
wrapping_offset_from
. This function was deprecated 19 days ago and was never stable; given an FCP of 10 days and some waiting time until FCP starts, that leaves at least a month between deprecation and removal which I think is fine for a nightly-only API.Regarding the open questions in #41079:
Also nominating the lang team because this exposes an intrinsic.
The stabilized method is best described by its doc-comment. The documentation forgot to mention the requirement that both pointers must "have the same provenance", aka "be derived from pointers to the same allocation", which I am adding in this PR. This is a precondition that Miri already implements and that, should LLVM ever obtain a
psub
operation to subtract pointers, will likely be required for that operation (following the semantics in this paper).