Commit 7745a7a
committed
Auto merge of #46142 - eddyb:even-mirer-2, r=nikomatsakis
MIR: split Operand::Consume into Copy and Move.
By encoding the choice of leaving the source untouched (`Copy`) and invalidating it (`Move`) in MIR, we can express moves of copyable values and have MIR borrow-checking enforce them, *including* ownership transfer of stack locals in calls (when the ABI passes by indirection).
Optimizations could turn a "last-use" `Copy` into a `Move`, and the MIR borrow-checker, at least within the confines of safe code, could even do this when the underlying lvalue was borrowed.
(However, that last part would be the first time lifetime inference affects code generation, AFAIK).
Furthermore, as `Move`s invalidate borrows as well, for any local that is initialized only once, we can ignore borrows that happened before a `Move` and safely reuse/replace its memory storage.
This will allow us to perform NRVO in the presence of short-lived borrows, unlike LLVM (currently), and even compute optimal `StorageLive...StorageDead` ranges instead of discarding them.File tree
72 files changed
+438
-445
lines changed- src
- librustc_mir
- build
- expr
- matches
- dataflow/move_paths
- hair/cx
- transform
- util
- librustc_passes
- librustc_trans/mir
- librustc
- ich
- mir
- test/mir-opt
- nll
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
72 files changed
+438
-445
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
423 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
424 | 427 | | |
425 | 428 | | |
426 | 429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
1286 | | - | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
1287 | 1297 | | |
1288 | 1298 | | |
1289 | 1299 | | |
| |||
1292 | 1302 | | |
1293 | 1303 | | |
1294 | 1304 | | |
1295 | | - | |
| 1305 | + | |
| 1306 | + | |
1296 | 1307 | | |
1297 | 1308 | | |
1298 | 1309 | | |
| |||
2089 | 2100 | | |
2090 | 2101 | | |
2091 | 2102 | | |
2092 | | - | |
| 2103 | + | |
| 2104 | + | |
2093 | 2105 | | |
2094 | 2106 | | |
2095 | 2107 | | |
2096 | 2108 | | |
2097 | 2109 | | |
2098 | 2110 | | |
2099 | | - | |
| 2111 | + | |
| 2112 | + | |
2100 | 2113 | | |
2101 | 2114 | | |
2102 | 2115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
| 234 | + | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
611 | 611 | | |
612 | 612 | | |
613 | 613 | | |
614 | | - | |
615 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
616 | 619 | | |
617 | 620 | | |
618 | 621 | | |
| |||
679 | 682 | | |
680 | 683 | | |
681 | 684 | | |
682 | | - | |
| 685 | + | |
683 | 686 | | |
684 | 687 | | |
685 | 688 | | |
| |||
860 | 863 | | |
861 | 864 | | |
862 | 865 | | |
863 | | - | |
| 866 | + | |
| 867 | + | |
864 | 868 | | |
865 | 869 | | |
866 | 870 | | |
| |||
913 | 917 | | |
914 | 918 | | |
915 | 919 | | |
916 | | - | |
| 920 | + | |
| 921 | + | |
917 | 922 | | |
918 | 923 | | |
919 | 924 | | |
| |||
924 | 929 | | |
925 | 930 | | |
926 | 931 | | |
927 | | - | |
| 932 | + | |
| 933 | + | |
928 | 934 | | |
929 | 935 | | |
930 | 936 | | |
| |||
0 commit comments