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

Use wrapper structs for iterators in BTreeMap/Set and HashMap/Set #19770

Merged
merged 4 commits into from
Dec 17, 2014

Conversation

csouth3
Copy link
Contributor

@csouth3 csouth3 commented Dec 12, 2014

Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code.

This PR changes the iterators of BTreeMap, BTreeSet, HashMap, and HashSet to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].

@@ -610,8 +610,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Default for HashSet<T, H> {
}

/// HashSet iterator
pub type SetItems<'a, K> =
iter::Map<'static, (&'a K, &'a ()), &'a K, Entries<'a, K, ()>>;
pub type SetItems<'a, K> = Keys<'a, K, ()>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Admittedly, it's sort of a band-aid to switch from one type alias to another here, but I figured it's better to go with the path of least change in this pull request to keep it focused. However, I am working on another separate pull request based on top of this one to clean up HashSet a little (including but not limited to doing the type alias conversions), so a proper solution for this is coming.

@alexcrichton
Copy link
Member

r? @gankro

self.inner.size_hint()
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well flatten these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was conforming to local file style here. Would you like me to flatten the couple of impl's that look like this just above as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure.

@Gankra
Copy link
Contributor

Gankra commented Dec 12, 2014

LGTM. But I just realized that this is technically a breaking change to do (since it's fair-game to treat a type-alias as the aliased type). Need to mark the PR as a [breaking-change]

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 12, 2014

Cool, never done that before so let me just clarify...the [breaking-change] tag goes on the commit messages, rather than the PR/merge commit message, right? Do I need to write anything else specifically besides the tag (tried to look for the breaking change policy, couldn't seem to find it.)

@Gankra
Copy link
Contributor

Gankra commented Dec 12, 2014

Has to go at the end of the PR or the commit. I usually do both. You should also note e.g. how to deal with the breakage (in this case, just need to note that it is no longer an alias, but a proper new type).

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 12, 2014

Cool, impl's collapsed down and both commits and PR are annotated as breaking changes.
@gankro

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 13, 2014

So, I just got finished doing the same type of conversion for BTreeSet and HashSet and debated whether to open a new pull request for them or tack them on here. I decided that since it's the same thing, and because the HashSet changes need to be based on top of this PR, that adding them on to this one would be best.
@gankro is that alright with you? If so, would you mind taking a look at the two commits I just added?

@csouth3 csouth3 changed the title Use wrapper structs for iterators in BTreeMap and HashMap Use wrapper structs for iterators in BTreeMap/Set and HashMap/Set Dec 13, 2014
@Gankra
Copy link
Contributor

Gankra commented Dec 13, 2014

Should be fine.

@csouth3 csouth3 force-pushed the iterator-wrapperstructs branch 2 times, most recently from 48e05bc to e38de8a Compare December 14, 2014 03:32
@csouth3
Copy link
Contributor Author

csouth3 commented Dec 14, 2014

All right, and now I've gotten this rebased post-closure unboxing.
@gankro Sorry for all of the duplicate reviewing!

@Gankra
Copy link
Contributor

Gankra commented Dec 14, 2014

(I'll let you in on a secret: I'm not really looking very hard this time)

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 14, 2014

Hmm, just out of curiosity, what is the 'rollup' command for bors? I've never seen it before!

@Gankra
Copy link
Contributor

Gankra commented Dec 14, 2014

bors added a commit that referenced this pull request Dec 14, 2014
Use wrapper structs for iterators in BTreeMap/Set and HashMap/Set

Reviewed-by: Gankro
bors referenced this pull request Dec 16, 2014
This creates an enormous amount of spew.
@csouth3
Copy link
Contributor Author

csouth3 commented Dec 16, 2014

Dang it...looks like BTreeSet doesn't use core::iter anymore and I forgot to remove it. While that didn't fail my local build, it just caused the buildbot to fail the rollup. I'll get that fixed ASAP :(

Edit: @gankro Removed the offending use (though I should figure out how to make problems like that fail my local build as well), and made sure the same problem didn't exist in any of the other 3.

Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.

This commit changes the keys and values iterators of `BTreeMap` to use
proper new types, rather than type aliases.  However, since it is
fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.

This commit changes the iterators of `BTreeSet` to use
proper new types, rather than type aliases.  However, since it is
fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.

This commit changes the keys and values iterators of `HashMap` to use
proper new types, rather than type aliases.  However, since it is
fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.

This commit changes the iterators of `HashSet` to use
proper new types, rather than type aliases.  However, since it is
fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
@Gankra
Copy link
Contributor

Gankra commented Dec 16, 2014

Are you running full make check? Some "lint" errors only trigger after stage 2 or even the full test suite.

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 16, 2014

So, I must admit that for this particular case I used make check-stage1-collections NO_BENCH=1, but I'm doing a full make check now and will continue to do the same for all future submissions. That was my mistake. Though interestingly, buildbot failed at stage1/libcollections, which I'm pretty sure built in my case...

No matter, I will just make sure to run the full test suite from now on and I'll ping you once I ensure that make check is happy now. Sorry for the mess!

@Gankra
Copy link
Contributor

Gankra commented Dec 16, 2014

It's not a compilation or test error, it's a lint. It's likely that check-LIBRARY doesn't bother with that stuff.

It still would have shown up as a warning in the logs, though.

( and yeah, we've all messed up by not doing a full check :D )

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 16, 2014

Duly noted that check-* ignores lints. Also, I'm sure it did show up as a warning (because I saw an identical one for HashSet, for which I removed the same use :P) but the compilation of collectionstest is quite noisy with warnings (deprecated methods in tests, etc.) that I've no doubt that one slipped past me. Either way chalk this one up as another "won't let that silliness slip through again". Thanks for the tip!

bors added a commit that referenced this pull request Dec 16, 2014
Use wrapper structs for iterators in BTreeMap/Set and HashMap/Set

Reviewed-by: Gankro
bors referenced this pull request Dec 16, 2014
Using a type alias for iterator implementations is fragile since this
exposes the implementation to users of the iterator, and any changes
could break existing code.

This commit changes the iterators of `VecMap` to use
proper new types, rather than type aliases.  However, since it is
fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
bors added a commit that referenced this pull request Dec 16, 2014
Use wrapper structs for iterators in BTreeMap/Set and HashMap/Set

Reviewed-by: Gankro
brson added a commit to brson/rust that referenced this pull request Dec 16, 2014
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code.

This PR changes the iterators of `BTreeMap`, `BTreeSet`, `HashMap`, and `HashSet` to use proper new types, rather than type aliases.  However, since it is fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
bors added a commit that referenced this pull request Dec 17, 2014
Use wrapper structs for iterators in BTreeMap/Set and HashMap/Set

Reviewed-by: Gankro
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 17, 2014
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code.

This PR changes the iterators of `BTreeMap`, `BTreeSet`, `HashMap`, and `HashSet` to use proper new types, rather than type aliases.  However, since it is fair-game to treat a type-alias as the aliased type, this is a:

[breaking-change].
@bors bors merged commit 341cf40 into rust-lang:master Dec 17, 2014
@csouth3 csouth3 deleted the iterator-wrapperstructs branch December 18, 2014 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants