-
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: introduce marker::ValMut and reserve Mut for unique access #75200
Conversation
Code is 39d212aa11e018e6edf7c33f7dbfed20429ac5fa and not a great leap forward, performance the same. |
☔ The latest upstream changes (presumably #75071) made this pull request unmergeable. Please resolve the merge conflicts. |
1550be0
to
160cdff
Compare
☔ The latest upstream changes (presumably #75329) made this pull request unmergeable. Please resolve the merge conflicts. |
553756c
to
f611130
Compare
Now also moved range_search down into the rest of iterator support navigate.rs, ruling out its use on Mut handlers, and emphasizing the unsafe part. And putting map.rs on a diet. |
@@ -512,6 +525,24 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> { | |||
} | |||
} | |||
|
|||
impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::ValMut<'a>, K, V, Type> { |
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.
This hands out a &'a mut [K]
to the key slice despite being just ValMut, which seems wrong?
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.
Yes, but this PR tries to only stick the ValMut label on (copies of) existing code and #73971 replaces this copy of into_slices_mut
entirely. Though I did already remove the mut
-ness of tbe keys in into_kv_valmut
, which also gets replaced, so that's not consistent. And in the navigate methods and all the way up to the map functions, but these take on their final form.
I guess, looking at this in solation, it's not sound to call it ValMut and have mut
keys. One could also argue that changing keys is not a problem, as long as you preserve order. Like we used to manually renumber lines in Basic programs, What really matters in this PR is the separation between structure altering handle types and methods versus K/V-altering tpyes and methods. So instead of ValMut, it could be KeyValMut, or ImmutLayout or so.
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.
Anyways, fixed according to the ValMut philosophy.
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.
Yeah I see that now, but I think if we're going to call it ValMut and not something like TreeImmut (which sounds confusing, don't use it), we should go with this.
@bors r+ |
📌 Commit 55bdf17e1bacbf681d98e0adcef89b41a1984fbb has been approved by |
… r=Mark-Simulacrum BTreeMap: purge innocent use of into_kv_mut Replace the use of `into_kv_mut` into more precise calls. This makes more sense if you know that the single remaining use of `into_kv_mut` is in fact evil and can be trialled in court (rust-lang#75200) and sent to a correction facility (rust-lang#73971). No real performance difference reported (but functions that might benefit a tiny constant bit like `BTreeMap::get_mut` aren't benchmarked): ``` benchcmp old new --threshold 5 name old ns/iter new ns/iter diff ns/iter diff % speedup btree::map::clone_fat_100 63,073 59,256 -3,817 -6.05% x 1.06 btree::map::iter_100 3,514 3,235 -279 -7.94% x 1.09 ```
☔ The latest upstream changes (presumably #75538) made this pull request unmergeable. Please resolve the merge conflicts. |
@Mark-Simulacrum seems this needs to be re r+'ed after the rebase |
@bors r+ |
📌 Commit e5f9d7f has been approved by |
…crum BTreeMap: introduce marker::ValMut and reserve Mut for unique access The mutable BTreeMap iterators (apart from `DrainFilter`) are double-ended, meaning they have to rely on a front and a back handle that each represent a reference into the tree. Reserve a type category `marker::ValMut` for them, so that we guarantee that they cannot reach operations on handles with borrow type `marker::Mut`and that these operations can assume unique access to the tree. Including rust-lang#75195, benchmarks report no genuine change: ``` benchcmp old new --threshold 5 name old ns/iter new ns/iter diff ns/iter diff % speedup btree::map::iter_100 3,333 3,023 -310 -9.30% x 1.10 btree::map::range_unbounded_vs_iter 36,624 31,569 -5,055 -13.80% x 1.16 ``` r? @Mark-Simulacrum
…crum BTreeMap: introduce marker::ValMut and reserve Mut for unique access The mutable BTreeMap iterators (apart from `DrainFilter`) are double-ended, meaning they have to rely on a front and a back handle that each represent a reference into the tree. Reserve a type category `marker::ValMut` for them, so that we guarantee that they cannot reach operations on handles with borrow type `marker::Mut`and that these operations can assume unique access to the tree. Including rust-lang#75195, benchmarks report no genuine change: ``` benchcmp old new --threshold 5 name old ns/iter new ns/iter diff ns/iter diff % speedup btree::map::iter_100 3,333 3,023 -310 -9.30% x 1.10 btree::map::range_unbounded_vs_iter 36,624 31,569 -5,055 -13.80% x 1.16 ``` r? @Mark-Simulacrum
☀️ Test successful - checks-actions, checks-azure |
I doubt this PR alone, which is indeed a ramp up to others, has any discernable effect on performance, but I'm beyond caring. |
…lacrum BTree: remove outdated traces of coercions The introduction of `marker::ValMut` (rust-lang#75200) meant iterators no longer see mutable keys but their code still pretends it does. And settle on the majority style `Some(unsafe {…})` over `unsafe { Some(…) }`. r? `@Mark-Simulacrum`
The mutable BTreeMap iterators (apart from
DrainFilter
) are double-ended, meaning they have to rely on a front and a back handle that each represent a reference into the tree. Reserve a type categorymarker::ValMut
for them, so that we guarantee that they cannot reach operations on handles with borrow typemarker::Mut
and that these operations can assume unique access to the tree.Including #75195, benchmarks report no genuine change:
r? @Mark-Simulacrum