Commit 5a377c4
committed
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 <[email protected]>
gherrit-pr-id: I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b
[WIP] Break TransmuteFrom into Shrink vs Overwrite
Also, only implement TryTransmuteFromPtr once in terms of
MutationCompatible.
gherrit-pr-id: I1e15473bf871e5b53a6c093e6a79f48e6498aa041 parent 46e2a46 commit 5a377c4
File tree
14 files changed
+442
-348
lines changed- src
- pointer
- util
- zerocopy-derive/src
14 files changed
+442
-348
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 | | - | |
| 139 | + | |
| 140 | + | |
138 | 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 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
| |||
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 | | |
| |||
3835 | 3830 | | |
3836 | 3831 | | |
3837 | 3832 | | |
3838 | | - | |
3839 | | - | |
| 3833 | + | |
| 3834 | + | |
3840 | 3835 | | |
3841 | 3836 | | |
3842 | 3837 | | |
| |||
4304 | 4299 | | |
4305 | 4300 | | |
4306 | 4301 | | |
4307 | | - | |
| 4302 | + | |
4308 | 4303 | | |
4309 | | - | |
4310 | | - | |
4311 | | - | |
| 4304 | + | |
4312 | 4305 | | |
4313 | 4306 | | |
4314 | 4307 | | |
| |||
4665 | 4658 | | |
4666 | 4659 | | |
4667 | 4660 | | |
4668 | | - | |
| 4661 | + | |
4669 | 4662 | | |
4670 | 4663 | | |
4671 | 4664 | | |
| |||
4784 | 4777 | | |
4785 | 4778 | | |
4786 | 4779 | | |
4787 | | - | |
| 4780 | + | |
4788 | 4781 | | |
4789 | | - | |
| 4782 | + | |
4790 | 4783 | | |
4791 | 4784 | | |
4792 | 4785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
160 | 162 | | |
161 | 163 | | |
162 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
163 | 186 | | |
164 | 187 | | |
165 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
0 commit comments