Skip to content

MIR move elimination [2/6]: TailCopyToMove - #163336

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Amanieu:move-elimination/tail-copy-to-move
Sep 30, 2026
Merged

rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Amanieu:move-elimination/tail-copy-to-move

Conversation

@Amanieu

@Amanieu Amanieu commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Depends on #163335

This PR implements a pre-pass for the MoveElimination pass from rust-lang/rfcs#3943.

TailCopyToMove turns Copy into Move just before a Return terminator. This is valid even for places that have been borrowed because the Return will invalidate borrows anyway. This is necessary to allow the source of the copy to be unified with the return place.

r? tmiasko

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 25, 2026
@Amanieu

Amanieu commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

LLM disclosure: I actually tried getting an LLM to write this entire pass for me. It was a disaster that was unsound in new and interesting ways. That draft was promptly nuked and replaced with a properly thought out implementation. LLMs were also used to generate the boilerplate for the MIR tests, but each test was manually reviewed and adjusted before committing.

@oli-obk oli-obk added the llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. label Sep 25, 2026
Comment thread compiler/rustc_mir_transform/src/tail_copy_to_move.rs Outdated
@tmiasko

tmiasko commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 12eb7ef has been tentatively approved by tmiasko

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 30, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #163336 (MIR move elimination [2/6]: TailCopyToMove)
 - #162380 (merge candidate responses equal except for region constraints)
 - #163476 (update deferred subtype test)
 - #163500 (disable toctou test for qnx)
@rust-bors
rust-bors Bot merged commit c336759 into rust-lang:main Sep 30, 2026
13 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 30, 2026
Rollup merge of #163336 - Amanieu:move-elimination/tail-copy-to-move, r=tmiasko

MIR move elimination [2/6]: TailCopyToMove

Depends on #163335

This PR implements a pre-pass for the `MoveElimination` pass from rust-lang/rfcs#3943.

`TailCopyToMove` turns `Copy` into `Move` just before a `Return` terminator. This is valid even for places that have been borrowed because the `Return` will invalidate borrows anyway. This is necessary to allow the source of the copy to be unified with the return place.

r? tmiasko
@rustbot rustbot added this to the 1.101.0 milestone Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants