-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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: dig a moat around raw node pointers #79093
Conversation
src/etc/gdb_providers.py
Outdated
if node_ptr.type.name.startswith(node_path + "BoxedNode<"): | ||
node_ptr = node_ptr["ptr"] | ||
else: | ||
pass # BACKCOMPAT: from #78104 to this PR |
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.
I would simplify this if #78104 and this PR make it through in the same release.
ab6f368
to
4c2e294
Compare
☔ The latest upstream changes (presumably #78104) 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:
|
4c2e294
to
46fa6be
Compare
@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
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.
I am not sure that the added abstraction here is worth it. It doesn't really abstract away the raw pointer at all -- we still provide and use accessors to the raw contents in almost all places that I can see. Can you elaborate on the goal here?
/// | ||
/// However, `UnboxedNode` contains no information as to whether it owns or | ||
/// shares the node and has no implicit destructor. | ||
pub(super) struct UnboxedNode<K, V> { |
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.
I'm not sure why this is called "Unboxed" -- it seems to be equivalent to a NodeRef just without some of the type parameters?
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.
I'm not sure why BoxedNode
is called what it is… it's boxed in the alloc::boxed sense of the word (though it doesn't have to be - the first leaf can in theory be integrated into struct BTreeMap
or other wrappers) but in my mind the purpose is to squeeze it into a small box. I would probably call them (BoxedNode
and the newcomer) PackedNodePtr
and NodePtr
, if they came in out of the blue.
One may ask why the
This PR splits off the first layer. Recently I've kind of shielded that layer by putting it into associated functions. Basically, #78222 tried to capture the first two layers at once (in something called You may say that the first layer is not such a big deal any more, because the raw pointer stored is no longer completely fake since you killed the shared empty root, but when I look at the newcomer, there is enough going on for me to think this is worth while. But it's probably better to move down a few more bits of the higher layer stuff. Maybe all the data access, meaning that the definition of |
Looking into this again, I'm reminded why it's hard to make this lowest layer do more: access to internal stuff has to be unsafe. Unless you painfully duplicate that data access: unsafe down below, and safe wrappers in Therefore, retreating a little with an earlier version. #79339. |
I don't think I'm seeing any interesting or complicated logic in the new file -- it all looks pretty short and not too "interesting" -- but maybe I'm missing something? |
I think it's interesting to see where and how these two pointers get cast back and forth, in a more narrow scope than the use of a |
But none of the complexity in casting is being moved? There's no logic in the new module, it's just hiding the casts behind methods? |
It depends on what you consider to be casting. To me, this PR does move some complexity, the fact we have raw LeafNode pointers and raw InternalNode pointers but we store them in a peculiar way. If it weren't for gdb_providers, this lowest layer could easily eliminate pointer casting from node.rs, because they're only required for packing into and from Of course it still leaves the challenge that you get a If you think that layer not valuable, where's the value in |
I would be fine with such a type alias rewrite, yes, I think it's better than this PR probably. My perspective is that the pointer storage is not particularly interesting because it is really quite simple AFAICT. |
…Mark-Simulacrum BTreeMap: cut out the ceremony around BoxedNode The opposite direction of rust-lang#79093. r? `@Mark-Simulacrum`
Continues on #78104. Moves
BoxedNode
and the heart ofNodeRef
to an island with the lowest layer of abstraction, where all the raw pointer sorcery happens. After many attempts this looks a lot better by moving the node's height along with the pointerr? @Mark-Simulacrum .