Commit f836c83
authored
Rollup merge of rust-lang#155114 - pitaj:rangeinclusiveiter-optimize, r=Mark-Simulacrum
Add `Step::forward/backward_overflowing` to enable RangeInclusive loop optimizations
ACP: rust-lang/libs-team#767
This adds new required methods to the Step trait:
```rust
trait Step: ... {
// ... existing functions
// New required functions
fn forward_overflowing(start: Self, count: usize) -> (Self, bool);
fn backward_overflowing(start: Self, count: usize) -> (Self, bool);
}
```
It was found that using these to implement RangeInclusive's Iterator impl enabled optimizations previously only applicable to the exclusive-ended `Range`.
This required changing how "exhaustion" works for `RangeInclusive`. I've nominated this for libs-api discussion because of one insta-stable change:
The new implementations now only set `exhausted` when overflow occurs, and `start` is now advanced past `end` otherwise. I doubt anyone depends on the prior behavior, but it's probably worth a crater run.
The exhaustion changes also affect `Debug` but my understanding is that debug formatting is never guaranteed stable.
I have now changed the `nth` impls to use the new functions as well.
r? libs12 files changed
Lines changed: 429 additions & 144 deletions
File tree
- compiler
- rustc_abi/src
- rustc_index_macros/src
- library
- coretests/tests
- iter
- core/src
- iter
- ops
- tests
- codegen-llvm
- mir-opt/pre-codegen
- ui/impl-trait
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
990 | 990 | | |
991 | 991 | | |
992 | 992 | | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
993 | 1000 | | |
994 | 1001 | | |
995 | 1002 | | |
| |||
1005 | 1012 | | |
1006 | 1013 | | |
1007 | 1014 | | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
1008 | 1022 | | |
1009 | 1023 | | |
1010 | 1024 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
139 | 153 | | |
140 | 154 | | |
141 | 155 | | |
| |||
0 commit comments