Skip to content

MIR move elimination [1/6]: MIR preparation - #163335

Draft
Amanieu wants to merge 16 commits into
rust-lang:mainfrom
Amanieu:move-elimination/mir-preparation
Draft

Amanieu wants to merge 16 commits into
rust-lang:mainfrom
Amanieu:move-elimination/mir-preparation

Conversation

@Amanieu

@Amanieu Amanieu commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

View all comments

This PR contains preparatory work for supporting the new MIR semantics from rust-lang/rfcs#3943.

  • Adds -Zmir-move-elimination which both opts-in to the new semantics and enables the new optimization pass.
  • Updates doc comments with the new semantics of MIR under the flag.
  • Adds the StorageAlloc MIR statement. This is used by the MIR inliner when it needs to borrow a destination place that hasn't been initialized.
  • Fixes several cases where ZST unit values are not properly initialized.
  • Fixes async drop elaboration which incorrectly used a move instead of a copy, leading to a use-after-move.

r? tmiasko

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to constck

cc @fee1-dead

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @vakaras

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2026
@rustbot rustbot added T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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: this PR is in large part the result of an LLM-assisted audit of all existing MIR transformations against the new MIR semantics as implemented in Miri in #163340. LLMs were also used to generate the boilerplate for the MIR tests, but each test was manually reviewed and adjusted before committing.

Comment thread compiler/rustc_borrowck/src/def_use.rs Outdated
@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_session/src/options.rs
Comment thread compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs Outdated
Comment thread compiler/rustc_borrowck/src/type_check/mod.rs Outdated
Comment thread compiler/rustc_borrowck/src/def_use.rs Outdated
Comment thread compiler/rustc_borrowck/src/lib.rs Outdated
Comment thread compiler/rustc_middle/src/mir/syntax.rs
@tmiasko

tmiasko commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

We started with a single pull request with 65 files changed, and now ended up with multiple "smaller" pull requests, where the first one has 115 files changed. This is not exactly what I expected. Could you move some parts to smaller pull requests still. For example parts of "Fix missing ZST initialization in MIR passes" which don't depend on -Zmir-move-elimination at all.

@Amanieu

Amanieu commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

I'm currently working to make none of the changes in this PR depend on -Zmir-move-elimination. That way we always have MIR that works with both the old and new semantics, and we don't need to make this a target modifier.

The main concern is that this means restricting RemoveZsts to never remove assignments, which is causing a lot of churn in the mir-opt test snapshots. Most of these assignments are later removed by DSE, but most mir-opt tests only run a single MIR pass.

I will then move all of the ZST-related changes to a separate PR since they no longer depend on the flag.

@Amanieu

Amanieu commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

I've moved the ZST-related changes to #163359.

We started with a single pull request with 65 files changed, and now ended up with multiple "smaller" pull requests, where the first one has 115 files changed. This is not exactly what I expected.

Most of the difference come from this preparation work which adjusts the rest of the compiler to work with the new semantics, which ends up touching a lot of tests. The actual compiler code changes are not that big.

@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/mir-preparation branch from 43c741c to 7d28b47 Compare September 25, 2026 23:20
@Amanieu

Amanieu commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

I moved the MIR validity changes to the Miri PR.

Comment thread compiler/rustc_mir_dataflow/src/impls/liveness.rs Outdated
Comment thread compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs Outdated
Comment thread compiler/rustc_mir_transform/src/sroa.rs
Comment thread compiler/rustc_mir_transform/src/simplify.rs
Comment thread compiler/rustc_mir_transform/src/copy_prop.rs
@Amanieu

Amanieu commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

I addressed all the review comments, as well as #163388. I also noticed that the handling of the destination place in inlining was incorrect: the destination place must become allocated-but-uninitialized if the call unwinds. This means we always need to use StorageAlloc on the destination place (unless it is indirect) since it needs to become initialized even if the inlined callee unwinds.

@rust-log-analyzer

This comment has been minimized.

@RalfJung

RalfJung commented Sep 28, 2026 via email

Copy link
Copy Markdown
Member

@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/mir-preparation branch from b366400 to d39204c Compare September 28, 2026 17:39
@Amanieu
Amanieu force-pushed the move-elimination/mir-preparation branch from d39204c to f352c99 Compare September 30, 2026 12:49
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 30, 2026
@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/mir-preparation branch from f352c99 to dc6558c Compare September 30, 2026 13:03
@rustbot

rustbot commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Sep 30, 2026
@Amanieu
Amanieu marked this pull request as draft September 30, 2026 13:05
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2026

This branch has not been deployed

No deployments
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-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants