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

stabilize more of collections #20356

Merged
merged 1 commit into from
Jan 2, 2015
Merged

stabilize more of collections #20356

merged 1 commit into from
Jan 2, 2015

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Dec 31, 2014

This stabilizes most of libcollections, carefully avoiding sections of API which are being managed in other PRs. APIs which are not stable are marked explicitly unstable with a reason.

Deprecates:

  • DList
    • rotate_forward
    • rotate_backward
    • prepend
    • insert_when
    • insert_ordered
    • merge
  • VecMap
    • update
    • update_with_key
  • Renames and newtypes the Bitv and BitvSet iterators to match conventions.
  • Removes the Copy impl from DList's Iter.

as such this is a

[breaking-change]

@rust-highfive
Copy link
Collaborator

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

r? @aturon

@rust-highfive rust-highfive assigned aturon and unassigned huonw Dec 31, 2014
@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

@csouth3 if you're still on a quest to Fix All The Iterators, Bitv/BitvSet still need renaming/newtyping.

@@ -578,7 +579,7 @@ impl Bitv {
/// assert_eq!(bv.iter().filter(|x| *x).count(), 7);
/// ```
#[inline]
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn iter<'a>(&'a self) -> Bits<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

I've been taking advantage of elision wherever possible when stabilizing APIs as it generally makes the signatures look a little prettier (just something to keep in mind).

Copy link
Member

Choose a reason for hiding this comment

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

This may also not want to be stable just yet until Bits has been renamed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The collection maintainers are a bit... paranoid... about elision when it comes to types. I can change them all, if you'd like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I've seen some argue that it doesn't necessarily help with clarity in this case, because it's not "clear" that the returned type borrows. You have to know that it's eliding a lifetime.

Copy link
Member

Choose a reason for hiding this comment

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

I've generally been removing them for strings (and I think @aturon has as well for vectors), so we should probably be consistent at the very least. I understand low level code wanting to avoid elision, but I'm not sure I buy the "without elision it's more clear" case because that's largely the purpose of elision (to move the lifetimes out of the way of what's going on).

For all these higher-level apis for collections I would personally elide as much as possible, but I'm curious what @aturon thinks

Copy link
Member

Choose a reason for hiding this comment

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

This seems mostly like a rustdoc bug; e.g. rustdoc could/should show all signatures elided by default, with an option to display elided lifetimes, entirely independent of whether or not there are lifetimes in the source.

Copy link
Member

Choose a reason for hiding this comment

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

I do understand the worry about confusion when a type "silently" takes a
lifetime parameter, but this is why we have ensured it's very easy to
determine whether a type does: it's explicit in the definition. (Other
options would allow it to be implicit even there, but that seemed truly
problematic.) My feeling is that, just as you learn that & takes a
lifetime, you come to learn this about other types in play. It's similar to
knowing whether a type is Copy or not -- it's a very fundamental aspect of
the type. So I personally have no problem eliding in these cases.

As @huonw notes, though, what shows up in rustdoc should probably be more
uniform/independent of these concerns.

On Tue, Dec 30, 2014 at 6:34 PM, Alex Crichton notifications@github.com
wrote:

In src/libcollections/bit.rs
#20356 (diff):

@@ -578,7 +579,7 @@ impl Bitv {
/// assert_eq!(bv.iter().filter(|x| *x).count(), 7);
/// ```
#[inline]

  • #[unstable = "matches collection reform specification, waiting for dust to settle"]
  • #[stable]
    pub fn iter<'a>(&'a self) -> Bits<'a> {

I've generally been removing them for strings (and I think @aturon
https://github.com/aturon has as well for vectors), so we should
probably be consistent at the very least. I understand low level code
wanting to avoid elision, but I'm not sure I buy the "without elision it's
more clear" case because that's largely the purpose of elision (to move the
lifetimes out of the way of what's going on).

For all these higher-level apis for collections I would personally elide
as much as possible, but I'm curious what @aturon
https://github.com/aturon thinks


Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/20356/files#r22373132.

@csouth3
Copy link
Contributor

csouth3 commented Dec 31, 2014

@gankro I'd be glad to
Fix All The Iterators
but I'm away on a trip so I can't submit the patch until this Thursday afternoon. If that timeline would block other important progress too long then by all means go ahead and get it done sooner. Otherwise I'll get right on it as soon as I can!

@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

Ack, I've run into the tangled-ness of the Bitv types. They both want an Iter type. Might need to do some trix to get the exports right.

@csouth3
Copy link
Contributor

csouth3 commented Dec 31, 2014

Oh that's right, I hadn't thought of that...sounds somewhat messy.

@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

@alexcrichton I think I've addressed all your issues. There weren't too many methods I could elide since many used the lifetime variable in the body, or had "more exotic" lifetime usage.

@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

I've squashed all the updates into a second commit which I can fully squash when you've reviewed.

pub fn iter<'a>(&'a self) -> BitPositions<'a> {
BitPositions {set: self, next_idx: 0u}
#[stable]
pub fn iter(&self) -> SetIter {
Copy link
Member

Choose a reason for hiding this comment

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

Hm, maybe this should be #[unstable] to see if we can figure out what to do about this iterator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The public API should show it yields bitv_set::Iter, as this is the only public name it is available under.

@alexcrichton
Copy link
Member

Thanks looks fantastic @gankro, thanks!

I'm basically ready to r+, but I'd like to give @aturon a chance to look this over as well to double check me.

@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

nits addressed

pub fn iter<'a>(&'a self) -> BitPositions<'a> {
BitPositions {set: self, next_idx: 0u}
#[stable]
pub fn iter(&self) -> bitv_set::Iter {
Copy link
Member

Choose a reason for hiding this comment

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

How will this return type show up in rustdoc?

@aturon
Copy link
Member

aturon commented Dec 31, 2014

OK, I've looked this over and it looks fantastic. Nice work by the whole community rolling collections reform out! I'm so excited to see this land. :)

@Gankra
Copy link
Contributor Author

Gankra commented Dec 31, 2014

squashed

@aturon
Copy link
Member

aturon commented Dec 31, 2014

Needs a rebase.

bors added a commit that referenced this pull request Jan 2, 2015
This stabilizes most of libcollections, carefully avoiding sections of API which are being managed in other PRs. APIs which are not stable are marked explicitly unstable with a reason.

Deprecates:

* DList
  * rotate_forward
  * rotate_backward
  * prepend
  * insert_when
  * insert_ordered
  * merge

* VecMap
  * update
  * update_with_key

* Renames and newtypes the Bitv and BitvSet iterators to match conventions.

* Removes the Copy impl from DList's Iter.

as such this is a

[breaking-change]
@alexcrichton alexcrichton merged commit 8dbaa71 into rust-lang:master Jan 2, 2015
@alexcrichton
Copy link
Member

I pushed this manually to master as it passed all platforms but one where a test timed out (a known failure case today).

///
/// This operation should compute in O(max(N, M)) time.
/// Deprecated: Use custom methods on IterMut.
#[deprecated = "Use custom methods on IterMut"]
pub fn merge<F>(&mut self, mut other: DList<T>, mut f: F) where F: FnMut(&T, &T) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

If the user has to implement merge themselves (using other methods), then that will require deallocating and allocating a lot of list nodes, while merge merges two DLists without a single allocation. It should stay.

It's a shame to remove the methods that make DList uniquely useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right; I misread the source of it. That said, can you provide a usecase for using DList like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also if you're interested in really complex DList manipulation, consider checking out my experimental DList with a full Cursor API, which I think is the more correct solution to this kind of complex manipulation problem.

I'd really love to get more feedback from DList power-users!

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 23, 2021
…manieu

Remove surplus prepend LinkedList fn

This nightly library feature provides a function on `LinkedList<T>` that is identical to `fn append` with a reversed order of arguments. Observe this diff against the `fn append` doctest:
```diff
+#![feature(linked_list_prepend)]
 fn main() {
    use std::collections::LinkedList;
    let mut list1 = LinkedList::new();
    list1.push_back('a');
    let mut list2 = LinkedList::new();
    list2.push_back('b');
    list2.push_back('c');

-    list1.append(&mut list2);
+    list2.prepend(&mut list1);

-    let mut iter = list1.iter();
+    let mut iter = list2.iter();
     assert_eq!(iter.next(), Some(&'a'));
     assert_eq!(iter.next(), Some(&'b'));
     assert_eq!(iter.next(), Some(&'c'));
     assert!(iter.next().is_none());

-    assert!(list2.is_empty());
+    assert!(list1.is_empty());
 }
```

As this has received no obvious request to stabilize it, nor does it have a tracking issue, and was left on nightly and the consensus seems to have been to deprecate it in this pre-1.0 PR in 2014, rust-lang#20356, I propose simply removing it.
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.

8 participants