-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for iter::repeat_n()
(feature(iter_repeat_n)
)
#104434
Comments
`VecDeque::resize` should re-use the buffer in the passed-in element Today it always copies it for *every* appended element, but one of those clones is avoidable. This adds `iter::repeat_n` (rust-lang#104434) as the primitive needed to do this. If this PR is acceptable, I'll also use this in `Vec` rather than its custom `ExtendElement` type & infrastructure that is harder to share between multiple different containers: https://github.com/rust-lang/rust/blob/101e1822c3e54e63996c8aaa014d55716f3937eb/library/alloc/src/vec/mod.rs#L2479-L2492
`VecDeque::resize` should re-use the buffer in the passed-in element Today it always copies it for *every* appended element, but one of those clones is avoidable. This adds `iter::repeat_n` (rust-lang/rust#104434) as the primitive needed to do this. If this PR is acceptable, I'll also use this in `Vec` rather than its custom `ExtendElement` type & infrastructure that is harder to share between multiple different containers: https://github.com/rust-lang/rust/blob/101e1822c3e54e63996c8aaa014d55716f3937eb/library/alloc/src/vec/mod.rs#L2479-L2492
…ith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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. |
Is this still going to be blocked on item shadowing, to avoid breaking itertools? |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@joshtriplett No shadowing concerns for this because it's a function, not a trait method. It'll only be an issue if you |
@scottmcm 🤦 Right, of course. Thank you. |
…lnay Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729 - [ ] ACP: rust-lang/libs-team#120 (this is actually ACP for repeat_n but this is nearly the same functionality so hijacking it so both approaches can be discussed in one place)
…ith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729
…lnay Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729 - [ ] ACP: rust-lang/libs-team#120 (this is actually ACP for repeat_n but this is nearly the same functionality so hijacking it so both approaches can be discussed in one place)
…ith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
…atrieb Stabilize `iter::repeat_n` ACP completed in rust-lang#104434 (comment)
Rollup merge of rust-lang#129294 - scottmcm:stabilize-repeat-n, r=Noratrieb Stabilize `iter::repeat_n` ACP completed in rust-lang#104434 (comment)
Given that repeating zero times is a completely acceptable thing to do -- just like |
This aligns the toolchain with Binius: https://gitlab.com/IrreducibleOSS/binius/-/blob/main/rust-toolchain.toml?ref_type=heads By updating the toolchain, we solve the following error: ``` cargo run --release Compiling ark-bn254 v0.4.0 Compiling binius_field v0.1.0 (https://gitlab.com/UlvetannaOSS/binius#33eab8c9) error[E0658]: use of unstable library feature 'iter_repeat_n' --> /Users/user/.cargo/git/checkouts/binius-073c6a8ffd019076/33eab8c/crates/field/src/packed.rs:225:76 | 225 | self.iter().skip(block_idx * block_len).take(block_len).flat_map(|elem| iter::repeat_n(elem, repeat)) | ^^^^^^^^^^^^^^ | = note: see issue #104434 <rust-lang/rust#104434> for more information = help: add `#![feature(iter_repeat_n)]` to the crate attributes to enable = note: this compiler was built on 2024-07-31; consider upgrading it if it is out of date For more information about this error, try `rustc --explain E0658`. error: could not compile `binius_field` (lib) due to 1 previous error ``` It solves an issue with the nightly compiler version and the use of `iter::repeat_n` that was introduced three days ago: https://gitlab.com/IrreducibleOSS/binius/-/commit/0c8c49b5cf7145949d5cbd4a237cda736c0dd1d3
This aligns the toolchain with Binius: https://gitlab.com/IrreducibleOSS/binius/-/blob/main/rust-toolchain.toml?ref_type=heads By updating the toolchain, we solve the following error: ``` cargo run --release Compiling ark-bn254 v0.4.0 Compiling binius_field v0.1.0 (https://gitlab.com/UlvetannaOSS/binius#33eab8c9) error[E0658]: use of unstable library feature 'iter_repeat_n' --> /Users/user/.cargo/git/checkouts/binius-073c6a8ffd019076/33eab8c/crates/field/src/packed.rs:225:76 | 225 | self.iter().skip(block_idx * block_len).take(block_len).flat_map(|elem| iter::repeat_n(elem, repeat)) | ^^^^^^^^^^^^^^ | = note: see issue #104434 <rust-lang/rust#104434> for more information = help: add `#![feature(iter_repeat_n)]` to the crate attributes to enable = note: this compiler was built on 2024-07-31; consider upgrading it if it is out of date For more information about this error, try `rustc --explain E0658`. error: could not compile `binius_field` (lib) due to 1 previous error ``` It solves an issue with the nightly compiler version and the use of `iter::repeat_n` that was introduced three days ago: https://gitlab.com/IrreducibleOSS/binius/-/commit/0c8c49b5cf7145949d5cbd4a237cda736c0dd1d3
Feature gate:
#![feature(iter_repeat_n)]
This is a tracking issue for the
iter::repeat_n
function and its associatediter::RepeatN
type.This is like
repeat
, but count-limited so it can re-use the buffer when generating the last item.ACP rust-lang/libs-team#120 is still open, but I'm sending a PR for it anyway as part of fixing a bug inVecDeque
.Public API
Steps / History
doc(hidden)
:VecDeque::resize
should re-use the buffer in the passed-in element #104435iter::repeat_n
from itertools libs-team#120iter::repeat_n
#120045Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: