Commit 5b24e12
committed
Auto merge of rust-lang#111395 - scottmcm:slice-iter-zst-experiment, r=the8472
Simplify the implementation of iterators over slices of ZSTs
Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`.
That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like rust-lang#42789, for example.
This PR instead changes it to just `end = ptr::invalid(len)` instead.
That's easier to think about (IMHO, at least) as well as easier to represent.
`next` is still to big to get inlined into the mir-opt/pre-codegen/ tests, but if I bump the inline threshold to force it to show the whole thing, this implementation is also less MIR:
```
> git diff --numstat
241 370 tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.mir
255 329 tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.mir
184 216 tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.mir
182 254 tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.mir
```
(That's ≈70 lines less for `Iter::next`, for example.)
r? `@ghost`
~~Built atop rust-lang#111282, so draft until that lands.~~3 files changed
+51
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
452 | 465 | | |
453 | 466 | | |
454 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 70 | + | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | | - | |
98 | | - | |
| 95 | + | |
99 | 96 | | |
100 | 97 | | |
101 | 98 | | |
| |||
193 | 190 | | |
194 | 191 | | |
195 | 192 | | |
196 | | - | |
197 | | - | |
198 | | - | |
| 193 | + | |
199 | 194 | | |
200 | 195 | | |
201 | 196 | | |
| |||
235 | 230 | | |
236 | 231 | | |
237 | 232 | | |
238 | | - | |
239 | | - | |
| 233 | + | |
240 | 234 | | |
241 | 235 | | |
242 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
3 | 24 | | |
4 | 25 | | |
5 | | - | |
6 | | - | |
7 | 26 | | |
8 | | - | |
| 27 | + | |
9 | 28 | | |
10 | 29 | | |
11 | 30 | | |
12 | 31 | | |
13 | 32 | | |
14 | 33 | | |
15 | 34 | | |
16 | | - | |
17 | 35 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 36 | + | |
21 | 37 | | |
22 | 38 | | |
23 | 39 | | |
24 | 40 | | |
25 | | - | |
| 41 | + | |
26 | 42 | | |
27 | 43 | | |
28 | 44 | | |
| |||
50 | 66 | | |
51 | 67 | | |
52 | 68 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
| |||
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| 84 | + | |
76 | 85 | | |
77 | 86 | | |
78 | | - | |
79 | 87 | | |
80 | | - | |
81 | 88 | | |
82 | 89 | | |
83 | | - | |
84 | | - | |
| 90 | + | |
85 | 91 | | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
| |||
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 165 | + | |
161 | 166 | | |
162 | 167 | | |
163 | 168 | | |
| |||
356 | 361 | | |
357 | 362 | | |
358 | 363 | | |
359 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
360 | 369 | | |
361 | 370 | | |
362 | 371 | | |
| |||
0 commit comments