Commit 4abed50
Generalize SizeEq to SizeFrom, support shrinking
Generalize `SizeEq`, renaming it to `SizeFrom`, and supporting casts
which shrink rather than preserve referent size.
This requires fairly deep surgery in our transmute taxonomy. We can no
longer rely on `SizeFrom::cast_from_raw` preserving referent size, which
means that all pointer transmutes must now reason about two types of
transmutes:
- Size-shrinking transmutes (in which the source value is larger than
the destination value)
- Overwriting transmutes (in which the source value is larger than the
destination value *and* the destination permits mutation). In an
overwriting transmute, the resulting value is a concatenation of a
valid `T` and the *suffix* of a valid `U`.
(Note that size-preserving transmutes can be viewed as a special case of
size-shrinking transmutes.)
In order to support these semantics, we split `TransmuteFrom` into two
traits: `TransmuteFrom` (which supports shriking transmutes) and
`TransmuteOverwrite` (which supports overwriting transmutes).
While we're here, we simplify the relationship between
`TryTransmuteFromPtr`, `MutationCompatible`, and `Read`. In particular,
`TryTransmuteFromPtr` now has a single blanket impl which is bounded by
`MutationCompatible`, and `MutationCompatible` now directly supports
three cases (and no longer delegates to `Read`):
- Exclusive reference transmutes in which the destination type may be
transmuted into the source type
- Shared reference transmutes in which both the source and the
destination type are `Immutable`
- Shared reference transmutes which permit interior mutation, in which
the source and destination types may both be transmuted into one
another, and in which the source and destination types support
compatible interior mutation
Makes progress on #1817
Co-authored-by: Jack Wrenn <jswrenn@amazon.com>
gherrit-pr-id: I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b1 parent df3a207 commit 4abed50
File tree
13 files changed
+450
-300
lines changed- src
- pointer
- util
- zerocopy-derive/src
13 files changed
+450
-300
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | | - | |
| 113 | + | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| |||
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
137 | | - | |
138 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
139 | 142 | | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
143 | | - | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| |||
167 | 170 | | |
168 | 171 | | |
169 | 172 | | |
170 | | - | |
| 173 | + | |
| 174 | + | |
171 | 175 | | |
172 | 176 | | |
173 | 177 | | |
174 | 178 | | |
175 | 179 | | |
176 | | - | |
| 180 | + | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
396 | 400 | | |
397 | 401 | | |
398 | 402 | | |
399 | | - | |
400 | | - | |
| 403 | + | |
| 404 | + | |
401 | 405 | | |
402 | 406 | | |
403 | 407 | | |
404 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
405 | 411 | | |
406 | 412 | | |
407 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
408 | 416 | | |
409 | 417 | | |
410 | | - | |
411 | | - | |
412 | | - | |
| 418 | + | |
| 419 | + | |
413 | 420 | | |
414 | 421 | | |
415 | | - | |
416 | | - | |
| 422 | + | |
| 423 | + | |
417 | 424 | | |
418 | 425 | | |
419 | 426 | | |
420 | 427 | | |
421 | 428 | | |
422 | | - | |
| 429 | + | |
423 | 430 | | |
424 | 431 | | |
425 | 432 | | |
426 | 433 | | |
427 | 434 | | |
428 | 435 | | |
429 | | - | |
430 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
431 | 441 | | |
432 | 442 | | |
433 | 443 | | |
434 | 444 | | |
435 | 445 | | |
436 | 446 | | |
437 | | - | |
| 447 | + | |
438 | 448 | | |
439 | 449 | | |
440 | 450 | | |
441 | 451 | | |
442 | 452 | | |
443 | 453 | | |
444 | 454 | | |
445 | | - | |
| 455 | + | |
446 | 456 | | |
447 | 457 | | |
448 | 458 | | |
| |||
452 | 462 | | |
453 | 463 | | |
454 | 464 | | |
455 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
456 | 468 | | |
457 | 469 | | |
458 | 470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
612 | 612 | | |
613 | 613 | | |
614 | 614 | | |
615 | | - | |
| 615 | + | |
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
620 | | - | |
| 620 | + | |
621 | 621 | | |
622 | 622 | | |
623 | | - | |
| 623 | + | |
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
| 384 | + | |
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| |||
1840 | 1840 | | |
1841 | 1841 | | |
1842 | 1842 | | |
1843 | | - | |
| 1843 | + | |
1844 | 1844 | | |
1845 | 1845 | | |
1846 | 1846 | | |
| |||
1852 | 1852 | | |
1853 | 1853 | | |
1854 | 1854 | | |
1855 | | - | |
1856 | | - | |
1857 | | - | |
| 1855 | + | |
1858 | 1856 | | |
1859 | 1857 | | |
1860 | 1858 | | |
| |||
2421 | 2419 | | |
2422 | 2420 | | |
2423 | 2421 | | |
2424 | | - | |
2425 | | - | |
| 2422 | + | |
2426 | 2423 | | |
2427 | 2424 | | |
2428 | 2425 | | |
| |||
2434 | 2431 | | |
2435 | 2432 | | |
2436 | 2433 | | |
2437 | | - | |
2438 | | - | |
2439 | | - | |
| 2434 | + | |
2440 | 2435 | | |
2441 | 2436 | | |
2442 | 2437 | | |
| |||
2844 | 2839 | | |
2845 | 2840 | | |
2846 | 2841 | | |
2847 | | - | |
| 2842 | + | |
2848 | 2843 | | |
2849 | 2844 | | |
2850 | 2845 | | |
| |||
2856 | 2851 | | |
2857 | 2852 | | |
2858 | 2853 | | |
2859 | | - | |
| 2854 | + | |
2860 | 2855 | | |
2861 | 2856 | | |
2862 | 2857 | | |
| |||
3832 | 3827 | | |
3833 | 3828 | | |
3834 | 3829 | | |
3835 | | - | |
3836 | | - | |
| 3830 | + | |
| 3831 | + | |
3837 | 3832 | | |
3838 | 3833 | | |
3839 | 3834 | | |
| |||
4301 | 4296 | | |
4302 | 4297 | | |
4303 | 4298 | | |
4304 | | - | |
| 4299 | + | |
4305 | 4300 | | |
4306 | | - | |
4307 | | - | |
4308 | | - | |
| 4301 | + | |
4309 | 4302 | | |
4310 | 4303 | | |
4311 | 4304 | | |
| |||
4662 | 4655 | | |
4663 | 4656 | | |
4664 | 4657 | | |
4665 | | - | |
| 4658 | + | |
4666 | 4659 | | |
4667 | 4660 | | |
4668 | 4661 | | |
| |||
4781 | 4774 | | |
4782 | 4775 | | |
4783 | 4776 | | |
4784 | | - | |
| 4777 | + | |
4785 | 4778 | | |
4786 | | - | |
| 4779 | + | |
4787 | 4780 | | |
4788 | 4781 | | |
4789 | 4782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | 201 | | |
221 | 202 | | |
222 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 20 | + | |
24 | 21 | | |
25 | 22 | | |
26 | 23 | | |
| |||
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
| 30 | + | |
34 | 31 | | |
35 | 32 | | |
36 | 33 | | |
37 | 34 | | |
38 | 35 | | |
39 | | - | |
| 36 | + | |
40 | 37 | | |
0 commit comments