Skip to content
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

Merged
merged 3 commits into from
Oct 20, 2015

Conversation

mystor
Copy link
Contributor

@mystor mystor commented Aug 12, 2015

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.

@rust-highfive
Copy link
Collaborator

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.

@bluss
Copy link
Member

bluss commented Aug 14, 2015

RFC: rust-lang/rfcs/pull/1257

@bors
Copy link
Contributor

bors commented Aug 16, 2015

☔ 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 _)
Copy link
Contributor

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

Copy link
Member

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

Copy link
Contributor

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)

Copy link
Member

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.

@bluss bluss assigned bluss and unassigned Gankra Aug 31, 2015
@bluss
Copy link
Member

bluss commented Aug 31, 2015

I was given the review from gankro

@mystor
Copy link
Contributor Author

mystor commented Sep 22, 2015

Ping @bluss :)

@bluss
Copy link
Member

bluss commented Sep 22, 2015

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;

Copy link
Member

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.

@bluss
Copy link
Member

bluss commented Sep 22, 2015

Very nice work! Everything looks very solid. Love the exhaustive testing.

As a general point I'd like the copy and wrap_copy methods better if they used the same convention as ptr::copy: first source, then destination. This is something that changed in ptr::copy half a year ago or so. Because changing that around might touch a lot of code not in this PR(?), we can wait and handle it separately.

@bluss
Copy link
Member

bluss commented Sep 22, 2015

Reminder: the PR is marked with merge conflicts

@mystor mystor force-pushed the vecdeque_drain_range branch from ff9793b to 45be6fc Compare September 22, 2015 22:57
@mystor
Copy link
Contributor Author

mystor commented Sep 22, 2015

Should have all of the suggested fixes applied :)

// the drain.
//
// T t h H
// [. . . o o x x o o . . .]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟

@bluss
Copy link
Member

bluss commented Sep 22, 2015

reviewers can send this off with r=me as soon as the sync/send test is fixed

@Gankra
Copy link
Contributor

Gankra commented Sep 23, 2015

@mystor I'm so sorry that it took us so long!

@bluss Thank you for being the hero this PR deserved.

@bluss
Copy link
Member

bluss commented Sep 24, 2015

Ah, with drain now using raw pointers, it needs the manual Send / Sync impls.

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> {}

@mystor
Copy link
Contributor Author

mystor commented Sep 24, 2015

Yup! I already have a patch with that, but haven't had the time to push it - I'll do that hopefully tonight.

@mystor
Copy link
Contributor Author

mystor commented Sep 24, 2015

@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?

@mystor
Copy link
Contributor Author

mystor commented Sep 24, 2015

@bluss Actually, can't you have an unconstrained Sync? as you can't do anything with a &Drain<'a, T> except get the length of the drained range...

@bluss
Copy link
Member

bluss commented Sep 25, 2015

I agree with the analysis but I think we should use the Sync bound because 1) It's how all other iterators do and 2) Without T: Sync it restricts which methods could ever be added (no element reading &self methods; an element reading Debug impl is actually plausible in the future).

The drain -> drain(..) fix for the sync send test is still missing by the way.

@Gankra
Copy link
Contributor

Gankra commented Sep 25, 2015

(specifically, unconstrained sync is basically relying on &Iterator being parametric -- usually true, but hard to guard against)

@mystor mystor force-pushed the vecdeque_drain_range branch from 1c29250 to 5fa3208 Compare October 6, 2015 13:32
@mystor
Copy link
Contributor Author

mystor commented Oct 6, 2015

Sorry for taking so long to make the 1-line change. I completely forgot about this PR :S.

@bluss or @gankro I think this can be merged then when the checks pass.

@bluss
Copy link
Member

bluss commented Oct 6, 2015

You need to update test/run-pass/sync-send-iterators-in-libcollections.rs too (See travis build log)

@mystor mystor force-pushed the vecdeque_drain_range branch from 5fa3208 to 493355d Compare October 8, 2015 13:49
@bluss
Copy link
Member

bluss commented Oct 17, 2015

See the travis log, some errors, this is the first:

src/libcollectionstest/vec_deque.rs:478:30: 478:37 error: this function takes 1 parameter but 0 parameters were supplied [E0061]
src/libcollectionstest/vec_deque.rs:478             let mut iter = d.drain();
                                                                     ^~~~~~~

@bluss
Copy link
Member

bluss commented Oct 20, 2015

Yay! (There is no notification on pushes fyi, so a message on the PR calls attention to it).

@bluss
Copy link
Member

bluss commented Oct 20, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Oct 20, 2015

📌 Commit dec0ea0 has been approved by bluss

@bors
Copy link
Contributor

bors commented Oct 20, 2015

⌛ Testing commit dec0ea0 with merge e7eb7d5...

bors added a commit that referenced this pull request Oct 20, 2015
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.
@Gankra
Copy link
Contributor

Gankra commented Oct 20, 2015

T H E D R E A M I S R E A L

🍶

@bors bors merged commit dec0ea0 into rust-lang:master Oct 20, 2015
@bluss
Copy link
Member

bluss commented Oct 20, 2015

🔔 🔔 drain is in

@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Oct 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants