-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement drain over a range for VecDeque #27723
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @gankro (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
☔ The latest upstream changes (presumably #27818) made this pull request unmergeable. Please resolve the merge conflicts. |
self.inner.pop_front() | ||
self.iter.next().map(|elt| | ||
unsafe { | ||
ptr::read(elt as *const _) |
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 pretty sure these as
's shouldn't be neccesary
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.
copied from my mistake of doing this in vec's drain
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.
(back then it might've been necessary fwiw -- full &mut to *const coercion is relatively new)
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 can be fixed, just drop the cast.
I was given the review from gankro |
Ping @bluss :) |
I'm reading! Pen & paper ready. I'm sorry that I didn't get to it sooner. |
// "forget" about the values after the start of the drain until after | ||
// the drain is complete and the Drain destructor is run. | ||
self.head = drain_tail; | ||
|
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.
From reading experience, this code (which indices are stored where) would be easier to understand with a comment.
The deque's elements are parted into three segments, separated by the indices tail, drain_tail, drain_head, head
. tail, drain_tail
are stored in self
, and drain_head, head
are stored in the Drain
's after_
fields.
Maybe a comment that explains this or at least explains the after_*
names.
Very nice work! Everything looks very solid. Love the exhaustive testing. As a general point I'd like the |
Reminder: the PR is marked with merge conflicts |
ff9793b
to
45be6fc
Compare
Should have all of the suggested fixes applied :) |
// the drain. | ||
// | ||
// T t h H | ||
// [. . . o o x x o o . . .] |
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.
🌟
reviewers can send this off with r=me as soon as the sync/send test is fixed |
Ah, with drain now using raw pointers, it needs the manual impls identical with Vec's Drain should be fine: unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}
unsafe impl<'a, T: Send> Send for Drain<'a, T> {} |
Yup! I already have a patch with that, but haven't had the time to push it - I'll do that hopefully tonight. |
@bluss Actually, shouldn't it be unsafe impl<'a, T: Send> Send for Drain<'a, T> {}
unsafe impl<'a, T: Send> Sync for Drain<'a, T> {} Because Drain transfers ownership, so T must be send, but need not be sync? |
@bluss Actually, can't you have an unconstrained |
I agree with the analysis but I think we should use the The |
(specifically, unconstrained sync is basically relying on &Iterator being parametric -- usually true, but hard to guard against) |
1c29250
to
5fa3208
Compare
You need to update test/run-pass/sync-send-iterators-in-libcollections.rs too (See travis build log) |
5fa3208
to
493355d
Compare
See the travis log, some errors, this is the first:
|
Yay! (There is no notification on pushes fyi, so a message on the PR calls attention to it). |
@bors r+ |
📌 Commit dec0ea0 has been approved by |
⌛ Testing commit dec0ea0 with merge e7eb7d5... |
This is a WIP PR for my implementation of drain over the VecDeque data structure supporting ranges. It brings the VecDeque drain implementation in line with Vec's. Tests haven't been written for the new function yet.
T H E D R E A M I S R E A L 🍶 |
🔔 🔔 drain is in |
This is a WIP PR for my implementation of drain over the VecDeque data structure supporting ranges. It brings the VecDeque drain implementation in line with Vec's.
Tests haven't been written for the new function yet.