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

Make vec::IntoIter covariant again #35733

Merged
merged 1 commit into from
Aug 17, 2016
Merged

Make vec::IntoIter covariant again #35733

merged 1 commit into from
Aug 17, 2016

Conversation

apasel422
Copy link
Contributor

Closes #35721

r? @alexcrichton

@apasel422
Copy link
Contributor Author

apasel422 commented Aug 16, 2016

This uses integer indices instead of pointers to avoid aliasing RawVec's underlying Unique, but could be rewritten, albeit with some duplication from RawVec, to use a struct layout like

struct IntoIter<T> {
  buf: Shared<T>,
  cap: usize,
  head: Shared<T>,
  tail: Shared<T>,
}

@@ -1812,27 +1786,22 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
unsafe {
if self.end == self.ptr {
if self.head == self.tail {
Copy link
Member

Choose a reason for hiding this comment

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

This could also be: if self.is_empty(), I think?

@alexcrichton
Copy link
Member

In the past this has been pretty performance-sensitive, could you benchmark just a forward iteration of a IntoIter to ensure that it didn't regress? Other than that looks great to me, thanks!

Also nominating for backport as beta was cut today and we don't want to miss this.

@alexcrichton alexcrichton added beta-nominated Nominated for backporting to the compiler in the beta channel. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 16, 2016
@apasel422
Copy link
Contributor Author

@alexcrichton Ah, if someone else could help out with benchmarks, that'd be great. If they indicate that this approach is slower, I'd be happy to rewrite this to use the other approach I mentioned.

@alexcrichton
Copy link
Member

alexcrichton commented Aug 16, 2016

@apasel422 could you gist the IR for this:

extern {
    fn bar(a: u8);
}
pub fn sum(v: Vec<u8>) {
    for e in v.into_iter() {
        unsafe { bar(e); }
    }
}

For me, rustc bar.rs -O --crate-type lib --emit llvm-ir looks like this. I think we basically just need to be sure that this still optimizes to a tight loop.

@apasel422
Copy link
Contributor Author

@alexcrichton
Copy link
Member

Hm so that's different because LLVM still has an add instruction, I'm not sure how much that'll end up translating to missed optimizations though. Maybe it's worth to stick to a two-pointers-approaching-each-other implementation though?

@apasel422
Copy link
Contributor Author

@alexcrichton Done.

@alexcrichton
Copy link
Member

@bors: r+ 7e148cd

Thanks! (also wow that was fast)

@bors
Copy link
Contributor

bors commented Aug 17, 2016

⌛ Testing commit 7e148cd with merge 76fa587...

bors added a commit that referenced this pull request Aug 17, 2016
Make `vec::IntoIter` covariant again

Closes #35721

r? @alexcrichton
@bors bors merged commit 7e148cd into rust-lang:master Aug 17, 2016
@apasel422 apasel422 deleted the issue-35721 branch August 17, 2016 16:51
@retep998
Copy link
Member

Might be worth backporting this to beta, as the regression lived just long enough to jump into beta.

@apasel422
Copy link
Contributor Author

@alexcrichton Can we get this backported to beta?

@alexcrichton
Copy link
Member

Yes this is tagged with beta-nominated, and we'll discuss at the next libs triage meeting. It'll likely be an obvious "yes let's backport"

brendanzab added a commit to brendanzab/gluon that referenced this pull request Aug 20, 2016
The regression in rust-lang/rust#35721 will most likely not be backported to beta until next week - see rust-lang/rust#35733 - so it probably makes sense to disable it for now.
@alexcrichton
Copy link
Member

Discussion at @rust-lang/libs today decided to accept for backport

@alexcrichton alexcrichton added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Aug 23, 2016
@brson brson removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants