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

Fix `extend` from assuming a fused iterator. #150

Merged
merged 1 commit into from Jun 8, 2019

Conversation

@ehuss
Copy link
Contributor

ehuss commented Jun 6, 2019

Iterators may resume after returning None. I think it is generally expected that extend should stop on the first None.

Fixes #147. Specifically, in rustc, there are some situations where an iterator of Results are collected into a Result<SmallVec, _> (such as here which ends up in this call to collect). The Result adapter returns None for the first Err in the sequence. However, it is possible for an iterator to have additional elements after the first Err. With this bug, SmallVec was falling through to the slow-path for loop, and resuming the iterator grabbing too many elements. I believe this was having some bad interactions with the type interner where the additional elements after the Err were getting processed (via a map()) and interned when they shouldn't be (or otherwise having some side effects from the map).


This change is Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Jun 7, 2019

The latest upstream changes (presumably #152) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

emilio left a comment

This looks reasonable, but can you elaborate on the commit message / PR description how exactly this fixes the rustc issue?

@ehuss ehuss force-pushed the ehuss:extend-resume branch from 1c59a72 to 1fbaf10 Jun 7, 2019
@ehuss
Copy link
Contributor Author

ehuss commented Jun 7, 2019

I updated the comment, but the exact details are quite complex (and dealing with parts of librustc I know little about).

@emilio
Copy link
Member

emilio commented Jun 8, 2019

Sure, looks good, thanks!

@emilio
emilio approved these changes Jun 8, 2019
@emilio
Copy link
Member

emilio commented Jun 8, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Jun 8, 2019

📌 Commit 1fbaf10 has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jun 8, 2019

Testing commit 1fbaf10 with merge 88b62b6...

bors-servo added a commit that referenced this pull request Jun 8, 2019
Fix `extend` from assuming a fused iterator.

Iterators may resume after returning None.  I think it is generally expected that `extend` should stop on the first None.

Fixes #147.  Specifically, in rustc, there are some situations where an iterator of Results are collected into a `Result<SmallVec, _>` (such as [here](https://github.com/rust-lang/rust/blob/c1c60d292e2dd2deff7084208274f9a02f750d43/src/librustc/ty/relate.rs#L139-L142) which ends up in [this call to `collect`](https://github.com/rust-lang/rust/blob/c1c60d292e2dd2deff7084208274f9a02f750d43/src/librustc/ty/context.rs#L3002)).  The [Result adapter](https://github.com/rust-lang/rust/blob/c1c60d292e2dd2deff7084208274f9a02f750d43/src/libcore/result.rs#L1245-L1258) returns None for the first `Err` in the sequence.  However, it is possible for an iterator to have additional elements after the first Err.  With this bug, SmallVec was falling through to the slow-path `for` loop, and resuming the iterator grabbing too many elements.  I believe this was having some bad interactions with the type interner where the additional elements after the `Err` were getting processed (via a `map()`) and interned when they shouldn't be (or otherwise having some side effects from the `map`).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/150)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 8, 2019

☀️ Test successful - checks-travis
Approved by: emilio
Pushing 88b62b6 to master...

@bors-servo bors-servo merged commit 1fbaf10 into servo:master Jun 8, 2019
2 checks passed
2 checks passed
Travis CI - Pull Request Build Passed
Details
homu Test successful
Details
@jdm jdm mentioned this pull request Jun 10, 2019
bors-servo added a commit that referenced this pull request Jun 10, 2019
Publish 0.6.10.

This incorporates #144, #152, #150, and #151, which should all be minor version updates according to semver.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/153)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.