-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 FusedIterator #47463
Stabilize FusedIterator #47463
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
This only exists for specialization right? Are we comfortable stabilizing these kinds of things before specialization itself? |
That is the right question and I think FusedIterator does not depend on any controversial or hard part of specialization, so it seems ok. meanwhile I can't understand what tidy wants me to fix.. |
644f111
to
96e6103
Compare
rebased to fix newer FusedIterator impls. That should fix tidy. |
The worst case is that this becomes a slightly weird/useless trait if we have to do something drastic like roll back specialization entirely. Seems okay to stabilize I guess. @rfcbot fcp merge |
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Maybe I don't understand how it is used, but isn't one of the main use cases essentially something like this: trait Fuse {
type Fused;
fn fuse(self) -> Self::Fused;
}
impl<T: Iterator> Fuse for T { ... }
impl<T: FusedIterator> Fuse for T { ... } This would involve specializing the associated type, which is one of the trickiest parts of specialization (because it could result in different impl instantiations at typeck time from trans time). |
The main use is in .fused and it is method specialization only, no associated types. Your example is interesting in itself but not what std is using now. |
In Iterator::fuse. |
Is there perhaps a "banner use case" for this trait right now? I've personally only ever seen it as a pretty niche optimization that almost never comes up in practice (I can't remember the last time I used I'm also pretty worried about the specialization here. If we roll it back I feel like it would be a breaking change with a trait like this. Users would use this trait only for the performance improvement (right?) and if we break that then we're effectively breaking the trait? |
@alexcrichton .fuse() is something itertools uses a lot, so it's typical of that use case -- when we build upon iterators completely generically. For example, The use case would be to implement the marker trait As a small nice thing, having I think the specialization that is assumed here really is the basics and it was my impression that we are pretty certain to ship that part sooner rather than later. |
@bluss ok cool thanks for the info! To clarify as well, would you consider it a breaking change if we end up later neutering the trait to not actually do anything (if specialization is removed)? The state of specialization AFAIK is sort of "continuously in the air" where there's always a few known soundness holes with no known fixes, but there's a big chunk that's known as highly desirable and safe but unknown how to stabilize. |
No, I can't see how it is a breaking change. We would have performance setbacks all over libcore without spec, fuse is not among the most important, and I imagine we would want other mechanisms to get the same effects. There is a risk that the trait becomes obsolete then yes if the new mechanism is not trait based. |
Hm ok, if you're ok with that outcome so am I! |
Triage ping, ticky boxes for you @BurntSushi! |
@BurntSushi there is a nice checkbox in #47463 (comment) waiting for you! |
src/libcore/char.rs
Outdated
@@ -904,5 +904,5 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "fused", issue = "35602")] | |||
#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DecodeUtf8
is still unstable so this should be #[unstable(feature = "decode_utf8", issue = "33906")]
.
src/libcore/iter/range.rs
Outdated
@@ -420,5 +420,5 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "fused", issue = "35602")] | |||
#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RangeInclusive
is still unstable so this should be #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
.
src/libcore/slice/mod.rs
Outdated
@@ -2494,7 +2494,7 @@ impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "fused", issue = "35602")] | |||
#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExactChunks
is still unstable so this should be #[unstable(feature = "exact_chunks", issue = "47115")]
.
src/libcore/slice/mod.rs
Outdated
@@ -2591,7 +2591,7 @@ impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "fused", issue = "35602")] | |||
#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExactChunksMut
is still unstable so this should be #[unstable(feature = "exact_chunks", issue = "47115")]
.
src/libstd_unicode/u_str.rs
Outdated
@@ -127,7 +127,7 @@ impl<I> Iterator for Utf16Encoder<I> | |||
} | |||
} | |||
|
|||
#[unstable(feature = "fused", issue = "35602")] | |||
#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utf16Encoder
is still unstable so this line can be removed.
src/libcore/slice/mod.rs
Outdated
@@ -1847,7 +1847,7 @@ impl<'a, T, P> SplitIter for RSplit<'a, T, P> where P: FnMut(&T) -> bool { | |||
} | |||
} | |||
|
|||
//#[unstable(feature = "fused", issue = "35602")] | |||
//#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSplit
is still unstable so this line can just be removed.
src/libcore/slice/mod.rs
Outdated
@@ -1906,7 +1906,7 @@ impl<'a, T, P> DoubleEndedIterator for RSplitMut<'a, T, P> where | |||
} | |||
} | |||
|
|||
//#[unstable(feature = "fused", issue = "35602")] | |||
//#[stable(feature = "fused", since = "1.25.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSplitMut
is still unstable so this line can just be removed.
🔔 This is now entering its final comment period, as per the review above. 🔔 |
⌛ Testing commit c7c23fe with merge d9455e8a7f272c0fec238dbba7af39b560dbf2f0... |
💔 Test failed - status-travis |
@bors: retry
|
⌛ Testing commit c7c23fe with merge 386cd00ba6fa150f64cdae31223f5a648fcf08c4... |
💔 Test failed - status-appveyor |
Stabilize FusedIterator FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate. Closes rust-lang#35602
Aw, that's quite the fight with bors. You pushed it over the finish line @alexcrichton, thank you! |
…r=bluss Unstabilize FusedIterator for Flatten since Flatten is unstable PR rust-lang#47463 made `impl<I, U> FusedIterator for Flatten<I>` stable but shouldn't have since `Flatten` is still unstable. This PR makes the impl unstable again.
FusedIterator is a marker trait that promises that the implementing
iterator continues to return
None
from.next()
once it has returnedNone
once (and/or.next_back()
, if implemented).The effects of FusedIterator are already widely available through
.fuse()
, but with stableFusedIterator
, stable Rust users canimplement this trait for their iterators when appropriate.
Closes #35602