Commit e232636
committed
Auto merge of rust-lang#59897 - tmandry:variantful-generators, r=eddyb
Multi-variant layouts for generators
This allows generators to overlap fields using variants, but doesn't do any such overlapping yet. It creates one variant for every state of the generator (unresumed, returned, panicked, plus one for every yield), and puts every stored local in each of the yield-point variants.
Required for optimizing generator layouts (rust-lang#52924).
There was quite a lot of refactoring needed for this change. I've done my best in later commits to eliminate assumptions in the code that only certain kinds of types are multi-variant, and to centralize knowledge of the inner mechanics of generators in as few places as possible.
This change also emits debuginfo about the fields contained in each variant, as well as preserving debuginfo about stored locals while running in the generator.
Also, fixes rust-lang#59972.
Future work:
- Use this change for an optimization pass that actually overlaps locals within the generator struct (rust-lang#52924)
- In the type layout fields, don't include locals that are uninitialized for a particular variant, so miri and UB sanitizers can check our memory (see rust-lang#59972 (comment))
- Preserve debuginfo scopes across generator yield pointsFile tree
22 files changed
+804
-331
lines changed- src
- librustc_codegen_llvm
- debuginfo
- librustc_codegen_ssa/mir
- librustc_mir
- borrow_check/nll/type_check
- build/expr
- interpret
- transform
- util
- librustc
- mir
- ty
- test
- debuginfo
- mir-opt
22 files changed
+804
-331
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2030 | 2030 | | |
2031 | 2031 | | |
2032 | 2032 | | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
2033 | 2037 | | |
2034 | 2038 | | |
2035 | 2039 | | |
| |||
2589 | 2593 | | |
2590 | 2594 | | |
2591 | 2595 | | |
2592 | | - | |
2593 | | - | |
2594 | | - | |
2595 | | - | |
2596 | | - | |
2597 | 2596 | | |
2598 | 2597 | | |
2599 | 2598 | | |
| |||
3031 | 3030 | | |
3032 | 3031 | | |
3033 | 3032 | | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| 3039 | + | |
3034 | 3040 | | |
3035 | 3041 | | |
3036 | 3042 | | |
3037 | | - | |
| 3043 | + | |
| 3044 | + | |
| 3045 | + | |
| 3046 | + | |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
3038 | 3056 | | |
3039 | 3057 | | |
3040 | 3058 | | |
| |||
3223 | 3241 | | |
3224 | 3242 | | |
3225 | 3243 | | |
3226 | | - | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
3227 | 3247 | | |
3228 | 3248 | | |
3229 | 3249 | | |
| |||
3598 | 3618 | | |
3599 | 3619 | | |
3600 | 3620 | | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
3601 | 3630 | | |
3602 | 3631 | | |
3603 | 3632 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
607 | | - | |
608 | 607 | | |
609 | | - | |
610 | | - | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
611 | 619 | | |
612 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
613 | 664 | | |
614 | 665 | | |
615 | 666 | | |
| |||
1647 | 1698 | | |
1648 | 1699 | | |
1649 | 1700 | | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
1650 | 1709 | | |
1651 | 1710 | | |
1652 | 1711 | | |
| |||
1721 | 1780 | | |
1722 | 1781 | | |
1723 | 1782 | | |
1724 | | - | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
1725 | 1796 | | |
1726 | 1797 | | |
1727 | 1798 | | |
| |||
1741 | 1812 | | |
1742 | 1813 | | |
1743 | 1814 | | |
1744 | | - | |
1745 | | - | |
1746 | | - | |
1747 | | - | |
1748 | | - | |
| 1815 | + | |
1749 | 1816 | | |
1750 | 1817 | | |
1751 | 1818 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
2416 | 2417 | | |
2417 | 2418 | | |
2418 | 2419 | | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
2419 | 2425 | | |
2420 | 2426 | | |
2421 | 2427 | | |
2422 | 2428 | | |
2423 | 2429 | | |
| 2430 | + | |
2424 | 2431 | | |
2425 | 2432 | | |
2426 | 2433 | | |
| |||
0 commit comments