Skip to content

Remove redundant drop terminators ahead of mir_coroutine_witnesses#155022

Draft
tmandry wants to merge 10 commits intorust-lang:mainfrom
tmandry:remove-dead-drops
Draft

Remove redundant drop terminators ahead of mir_coroutine_witnesses#155022
tmandry wants to merge 10 commits intorust-lang:mainfrom
tmandry:remove-dead-drops

Conversation

@tmandry
Copy link
Copy Markdown
Member

@tmandry tmandry commented Apr 9, 2026

View all comments

This change is meant to fix #151942. Putting this up to see the perf effects of running it on every MIR body; then I'll work out a strategy to merge it.

Related issues to triage:


Coroutine traits like Send and Sync are computed based on the mir_coroutine_witnesses query to get the types saved in the coroutine. This query runs the regular coroutine analysis pass on mir_promoted to compute which locals are saved across suspension points.

At this stage of MIR, drop terminators exist along every exit path of the function, even when a local has already been moved from. Those extra drop terminators causes locals (like guard in the case below) to appear live over suspension points, even when they have just been dropped.

async fn bar(mutex: &Mutex<()>) {
    let mut guard = mutex.lock().unwrap();
    loop {
        drop(guard);
        foo().await;
        guard = mutex.lock().unwrap();
    }
}

See this gist for MIR of a simplified version of this function.

Later MIR passes like drop_elaboration and remove_unneeded_drops remove the redundant drop terminators, but they depend on type info to check needs_drop on a place's type. Since mir_coroutine_witnesses query is run inside typeck, we cannot depend on this without introducing cycles.

Instead, we implement a simple pass that removes drop terminators for definitely-uninitialized places. It avoids the need for type info by skipping the check for whether types have destructors.

r? @ghost

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 9, 2026
@tmandry tmandry changed the title Remove dead drops Remove redundant drop terminators ahead of mir_coroutine_witnesses Apr 9, 2026
@tmandry
Copy link
Copy Markdown
Member Author

tmandry commented Apr 9, 2026

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 9, 2026
Remove redundant drop terminators ahead of mir_coroutine_witnesses
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 9, 2026
@rust-log-analyzer

This comment was marked as off-topic.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 9, 2026

☀️ Try build successful (CI)
Build commit: 5cfde26 (5cfde2679121005039f5e66aeb50f0105493903e, parent: 900485642855f4729d926ecf24680a791f9293cf)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5cfde26): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.1% [0.2%, 5.1%] 55
Regressions ❌
(secondary)
1.5% [0.1%, 5.6%] 96
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [0.2%, 5.1%] 55

Max RSS (memory usage)

Results (primary 6.7%, secondary 5.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
6.7% [0.5%, 14.6%] 66
Regressions ❌
(secondary)
5.1% [1.2%, 11.8%] 46
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 6.7% [0.5%, 14.6%] 66

Cycles

Results (primary 2.9%, secondary 2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.9% [2.1%, 5.5%] 13
Regressions ❌
(secondary)
3.1% [1.3%, 4.9%] 16
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) 2.9% [2.1%, 5.5%] 13

Binary size

Results (primary 0.1%, secondary -0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.1%, 0.1%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.1%, -0.0%] 12
All ❌✅ (primary) 0.1% [0.1%, 0.1%] 5

Bootstrap: 489.506s -> 497.499s (1.63%)
Artifact size: 395.50 MiB -> 395.57 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 9, 2026
@rust-log-analyzer

This comment was marked as off-topic.

@tmandry tmandry force-pushed the remove-dead-drops branch from 4d04916 to 11e9fef Compare April 9, 2026 06:13
@tmandry
Copy link
Copy Markdown
Member Author

tmandry commented Apr 9, 2026

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 9, 2026
Remove redundant drop terminators ahead of mir_coroutine_witnesses
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 9, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 9, 2026

☀️ Try build successful (CI)
Build commit: dc4f33d (dc4f33d8604405ae6c35c052336e3c3eb37de413, parent: d0442e2800d356ae282ddcdbe0eff8798fe648b6)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (dc4f33d): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.5% [0.2%, 0.8%] 35
Regressions ❌
(secondary)
1.1% [0.1%, 3.6%] 89
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) 0.5% [0.2%, 0.8%] 35

Max RSS (memory usage)

Results (primary 6.7%, secondary 4.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
6.7% [0.5%, 14.2%] 65
Regressions ❌
(secondary)
5.3% [0.9%, 11.8%] 42
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.8%, -2.0%] 3
All ❌✅ (primary) 6.7% [0.5%, 14.2%] 65

Cycles

Results (primary 1.8%, secondary 3.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.8% [1.3%, 2.4%] 2
Regressions ❌
(secondary)
3.4% [2.6%, 5.4%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.8% [1.3%, 2.4%] 2

Binary size

Results (secondary -0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.1%, -0.0%] 12
All ❌✅ (primary) - - 0

Bootstrap: 489.468s -> 489.718s (0.05%)
Artifact size: 395.51 MiB -> 395.60 MiB (0.02%)

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 10, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 10, 2026
Remove redundant drop terminators ahead of mir_coroutine_witnesses
@rust-log-analyzer

This comment was marked as off-topic.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 10, 2026

☀️ Try build successful (CI)
Build commit: 0af2e44 (0af2e4420b164861a451f4f1efe42f951dc8709c, parent: 8317fef20409adedaa7c385fa6e954867bf626fc)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0af2e44): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.1% [0.1%, 11.9%] 47
Regressions ❌
(secondary)
1.2% [0.0%, 3.8%] 84
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [0.1%, 11.9%] 47

Max RSS (memory usage)

Results (primary 5.4%, secondary 5.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
5.6% [0.7%, 15.2%] 82
Regressions ❌
(secondary)
5.3% [0.7%, 11.0%] 47
Improvements ✅
(primary)
-2.3% [-2.4%, -2.2%] 2
Improvements ✅
(secondary)
-3.1% [-3.1%, -3.1%] 1
All ❌✅ (primary) 5.4% [-2.4%, 15.2%] 84

Cycles

Results (primary 7.5%, secondary -0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
7.5% [2.8%, 12.0%] 4
Regressions ❌
(secondary)
3.8% [3.6%, 4.3%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.6% [-5.3%, -4.0%] 3
All ❌✅ (primary) 7.5% [2.8%, 12.0%] 4

Binary size

Results (secondary -0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.1%, -0.0%] 12
All ❌✅ (primary) - - 0

Bootstrap: 489.232s -> 489.714s (0.10%)
Artifact size: 395.57 MiB -> 395.73 MiB (0.04%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 10, 2026
@tmandry
Copy link
Copy Markdown
Member Author

tmandry commented Apr 10, 2026

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 10, 2026
Remove redundant drop terminators ahead of mir_coroutine_witnesses
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 10, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 11, 2026

☀️ Try build successful (CI)
Build commit: a0e885e (a0e885e3aa4ea171798eea1b7cfb6285f4a7e1d1, parent: 02c7f9bec0fd583160f8bcccb830216023b07bee)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a0e885e): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.1% [0.2%, 11.9%] 40
Regressions ❌
(secondary)
1.2% [0.2%, 3.8%] 75
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [0.2%, 11.9%] 40

Max RSS (memory usage)

Results (primary 6.5%, secondary 5.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
6.6% [0.6%, 14.6%] 71
Regressions ❌
(secondary)
5.5% [0.6%, 10.8%] 47
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) 6.5% [-0.8%, 14.6%] 72

Cycles

Results (primary 6.6%, secondary 2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
6.6% [2.1%, 13.2%] 5
Regressions ❌
(secondary)
6.1% [4.0%, 8.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-3.8%, -3.8%] 1
All ❌✅ (primary) 6.6% [2.1%, 13.2%] 5

Binary size

Results (primary 0.1%, secondary -0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.1%, 0.1%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.1%, -0.0%] 12
All ❌✅ (primary) 0.1% [0.1%, 0.1%] 2

Bootstrap: 491.759s -> 492.365s (0.12%)
Artifact size: 394.19 MiB -> 394.40 MiB (0.05%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 11, 2026
tmandry added 2 commits April 13, 2026 15:21
This should fix performance issues, but includes at least one test change that is likely unacceptable (pass => fail).
@tmandry
Copy link
Copy Markdown
Member Author

tmandry commented Apr 13, 2026

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 13, 2026
Remove redundant drop terminators ahead of mir_coroutine_witnesses
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 13, 2026
@rust-log-analyzer

This comment was marked as off-topic.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 14, 2026

☀️ Try build successful (CI)
Build commit: 764a690 (764a690366084d99756efd2887abda48831d4299, parent: 17584a181979f04f2aaad867332c22db1caa511a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (764a690): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
2.7% [0.2%, 25.9%] 31
Regressions ❌
(secondary)
0.4% [0.1%, 0.8%] 27
Improvements ✅
(primary)
-0.5% [-0.8%, -0.2%] 14
Improvements ✅
(secondary)
-0.5% [-0.9%, -0.2%] 21
All ❌✅ (primary) 1.7% [-0.8%, 25.9%] 45

Max RSS (memory usage)

Results (primary -1.0%, secondary -0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.3% [2.3%, 4.2%] 2
Regressions ❌
(secondary)
6.4% [6.4%, 6.4%] 1
Improvements ✅
(primary)
-2.0% [-4.2%, -1.1%] 9
Improvements ✅
(secondary)
-2.7% [-4.3%, -1.5%] 3
All ❌✅ (primary) -1.0% [-4.2%, 4.2%] 11

Cycles

Results (primary 11.4%, secondary -2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
11.4% [2.5%, 26.1%] 7
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-7.7% [-7.7%, -7.7%] 1
All ❌✅ (primary) 11.4% [2.5%, 26.1%] 7

Binary size

Results (secondary -0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.1%, -0.0%] 12
All ❌✅ (primary) - - 0

Bootstrap: 489.468s -> 490.649s (0.24%)
Artifact size: 394.17 MiB -> 394.27 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Async function's future not Send even when non-Send type is not alive across await expression

4 participants