-
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
BTreeMap: clean up access to MaybeUninit arrays #79520
Conversation
This comment has been minimized.
This comment has been minimized.
4b16dcb
to
3221438
Compare
unsafe fn edge_area(self) -> &'a [MaybeUninit<BoxedNode<K, V>>] { | ||
Self::as_internal(&self).edges.as_slice() | ||
unsafe fn edge_area(mut self) -> &'a [MaybeUninit<BoxedNode<K, V>>] { | ||
Self::as_internal_mut(&mut self).edges.as_slice() |
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 seems quite odd to require unique access to get a read-only slice of the edges -- can you say more about the use case here?
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 change is not to require unique access (to the tree), we admit that the caller has it and needs to have it. We don't get you a slice of edges, but a slice of containers of edges. If you only have shared access to the tree, the only thing you could ever do with those containers is to read the initialized ones, and we already have better methods for that.
The actual use case is to unify the various methods that access MaybeUninit
s in another PR.
Why is this good? It feels like we should not impose exclusive access just to reborrow into a shared reference? |
3221438
to
1f71886
Compare
I've returned a |
/// Exposes the entire key storage area in the node, | ||
/// regardless of the node's current length, | ||
/// having exclusive access to the entire node. | ||
unsafe fn key_area(self) -> &'a [MaybeUninit<K>] { | ||
Self::as_leaf(&self).keys.as_slice() | ||
unsafe fn key_area(mut self) -> &'a mut [MaybeUninit<K>] { |
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.
Ok, so I was initially confused by this change -- it still seems unnecessary, as this PR doesn't introduce any cases where key_area is being used with the unique access being provided here. Since this PR is an attempt to split off part of #79347, I took a look there, and it looks like the change this is maybe.. not going far enough?
Can we include the next step of this refactor (but avoid the other changes)? I would expect, I guess, a PR that just switches away from using the different key_area/into_key_area etc methods to a single one, but doesn't do anything else (no introduction of e.g. slice_move). That would make it easier to judge whether the generics and such suggested in the other PR are worth it to me. As-is, it's hard to determine what the outcome is looking like quite yet.
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 still seems unnecessary, as this PR doesn't introduce any cases where key_area is being used with the unique access being provided here
The compiler doesn't notice, but I think the uniqueness is being used and required. You cannot sensibly copy a MaybeUninit<K>
if there might be someone else copying it too, because the key would be duplicated. The callers of key_area
move ownership, so they need uniqueness, even though the ptr::copy
doing the hard work for them doesn't care about the uniqueness of the source .
Can we include the next step of this refactor (but avoid the other changes)?
Not sure which next step and other changes you mean.
As-is, it's hard to determine what the outcome is looking like quite yet.
Again, not sure which outcome you mean. In my mind, the outcome looks a lot like #79347 (just needs rebase for the last tweaks).
More concretely, it feels like this PR combines together many refactors in one commit, and that makes it hard for me to understand the intent behind each and evaluate it. (Or figure out when things are intended to depend on each other or be related). |
Apart from the really small stuff, I see 4 changes that could be here (each repeated for the key, val and edge arrays):
I think (1) is a worth while clarification on its own, but it seems you're not convinced. #79347 does (2) first, but it seemed sensible to combine with (3) rather than come up with additional methods. It's possible to do (4) first |
1f71886
to
621869e
Compare
☔ The latest upstream changes (presumably #80005) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
621869e
to
9f129de
Compare
☔ The latest upstream changes (presumably #79347) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
9f129de
to
0d2548a
Compare
Focusing on the point discussed here, the rest is for later PRs. PS Another way to defend my crusade against shared access to |
@bors r+ rollup=never Ok, this seems fine. I think I am at least somewhat convinced by the ownership argument, but ultimately it doesn't matter too much, and this seems to let us delete some unused APIs which is great. |
📌 Commit 0d2548a has been approved by |
☀️ Test successful - checks-actions |
Stop exposing and using immutable access to
MaybeUninit
slices when we need and have exclusive access to the tree.r? @Mark-Simulacrum