Skip to content

Always use a DropTree to build drops#159537

Draft
cjgillot wants to merge 6 commits into
rust-lang:mainfrom
cjgillot:rm-build_scope_drops
Draft

Always use a DropTree to build drops#159537
cjgillot wants to merge 6 commits into
rust-lang:mainfrom
cjgillot:rm-build_scope_drops

Conversation

@cjgillot

Copy link
Copy Markdown
Contributor

MIR building currently has 2 ways to build drops.

A normal exit from a scope uses leave_top_scopes, which calls build_scope_drops. That method generates a compact sequence of StorageDead statements and Drop terminators.

For anormal exits (else, break, continue, return, unwind and coroutine drop), we use a DropTree which is a much more flexible structure in which we record blocks as entry points.

In order to work correctly, build_scope_drops assumes a lot about the structure of the DropTree. This forbids us from unscheduling drops for moved-from locals. This PR removes it altogether, to always use the more flexible DropTree. The generated MIR should be equivalent, but more verbose.

r? @ghost for perf, and because of a borrowck corner case

cjgillot added 6 commits July 18, 2026 20:50
And some more cases along the way.

We have a specific optimization to avoid generating useless drops, use it.
In particular, aggregate construction are very similar to function calls
for which this is designed.
@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 Jul 18, 2026
@cjgillot

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 18, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 18, 2026
Always use a `DropTree` to build drops
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests/ui/mir/issue-80949.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/mir/issue-80949.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/mir/issue-80949" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0597]: `storage` does not live long enough
##[error]  --> /checkout/tests/ui/mir/issue-80949.rs:32:23
   |
---
LL |     diff(dyn_trait, storage_ref);
LL | }
   | -
   | |
   | `storage` dropped here while still borrowed
   | borrow might be used here, when `dyn_trait` is dropped and runs the destructor for type `Box<dyn Trait<Item = &()>>`
   |
   = note: values in a scope are dropped in the opposite order they are defined

error: aborting due to 1 previous error

@rust-bors

rust-bors Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 21c512d (21c512d73ff422b9805f6729b4b9b80672506a07)
Base parent: eff8269 (eff8269f797067c30555e77f160ec84c0ed15cd9)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (21c512d): 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 rustc-perf
@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.6% [0.1%, 1.4%] 45
Regressions ❌
(secondary)
1.0% [0.1%, 3.1%] 53
Improvements ✅
(primary)
-0.4% [-0.7%, -0.2%] 17
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 10
All ❌✅ (primary) 0.3% [-0.7%, 1.4%] 62

Max RSS (memory usage)

Results (primary -1.5%, secondary 2.5%)

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)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
-1.5% [-2.8%, -0.7%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.5% [-2.8%, -0.7%] 3

Cycles

Results (secondary 4.2%)

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)
4.2% [2.2%, 6.9%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.3%, secondary -0.1%)

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

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 0.7%] 3
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 3
Improvements ✅
(primary)
-0.4% [-1.8%, -0.0%] 45
Improvements ✅
(secondary)
-0.2% [-1.8%, -0.0%] 24
All ❌✅ (primary) -0.3% [-1.8%, 0.7%] 48

Bootstrap: 489.126s -> 486.369s (-0.56%)
Artifact size: 389.52 MiB -> 389.47 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 Jul 19, 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.

4 participants