Skip to content

Shrink no-op drop elaboration - #157491

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
cjgillot:elaborate-drop-chain
Jul 8, 2026
Merged

Shrink no-op drop elaboration#157491
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
cjgillot:elaborate-drop-chain

Conversation

@cjgillot

@cjgillot cjgillot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Drop elaboration can be very verbose, especially when locals are move-from by parts. This happens a lot with ? desugaring for instance.

I start from the example given in #157463 and attempt to shrink the generated code.

The remaining empty goto blocks come from resetting drop flags. The cost/benefit of the refactor was less interesting.

@rustbot

rustbot commented Jun 5, 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 Jun 5, 2026
@rustbot

rustbot commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 21 candidates

@cjgillot

cjgillot commented Jun 5, 2026

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 Jun 5, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 5, 2026
@rust-bors

rust-bors Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 0f76dc7 (0f76dc763580d699bfbe02f2ca1ca32d8db54243, parent: 39ec825c441918a4ae623a9b8840d1ccd446dcff)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0f76dc7): 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)
0.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 3
Improvements ✅
(primary)
-0.7% [-1.2%, -0.1%] 10
Improvements ✅
(secondary)
-0.7% [-1.2%, -0.3%] 10
All ❌✅ (primary) -0.5% [-1.2%, 0.7%] 11

Max RSS (memory usage)

Results (primary 1.0%, secondary 0.8%)

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

mean range count
Regressions ❌
(primary)
2.7% [1.8%, 3.7%] 2
Regressions ❌
(secondary)
3.4% [3.4%, 3.4%] 1
Improvements ✅
(primary)
-2.4% [-2.4%, -2.4%] 1
Improvements ✅
(secondary)
-0.6% [-0.6%, -0.5%] 2
All ❌✅ (primary) 1.0% [-2.4%, 3.7%] 3

Cycles

Results (secondary -1.4%)

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.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-4.0%, -2.1%] 3
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.0%, secondary -0.0%)

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.5%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.1%, -0.0%] 26
Improvements ✅
(secondary)
-0.0% [-0.1%, -0.0%] 38
All ❌✅ (primary) -0.0% [-0.1%, 0.5%] 28

Bootstrap: 514.669s -> 516.17s (0.29%)
Artifact size: 400.66 MiB -> 400.87 MiB (0.05%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 5, 2026
@saethlin

saethlin commented Jun 5, 2026

Copy link
Copy Markdown
Member

r? me

@rustbot rustbot assigned saethlin and unassigned mejrs Jun 5, 2026
@ashi009

This comment was marked as low quality.

cjgillot added 4 commits July 4, 2026 23:21
These would become simple gotos anyway, so save the cost of creating such
blocks.
We are not modifying these blocks afterwards, so no need to create clean
ones each time.

Drive-by fix for async drops with enums.
@cjgillot
cjgillot force-pushed the elaborate-drop-chain branch from c7f866c to 80705e8 Compare July 5, 2026 03:19
@rustbot

rustbot commented Jul 5, 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.

@saethlin

saethlin commented Jul 7, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 80705e8 has been approved by saethlin

It is now in the queue for this repository.

@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 Jul 7, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 8, 2026
@rust-bors

rust-bors Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: saethlin
Duration: 3h 8m 2s
Pushing 99576cf to main...

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 5e91de6 (parent) -> 99576cf (this PR)

Test differences

Show 6 test diffs

Stage 1

  • [mir-opt] tests/mir-opt/building/fallible_struct_drop.rs: [missing] -> pass (J0)

Stage 2

  • [mir-opt] tests/mir-opt/building/fallible_struct_drop.rs: [missing] -> pass (J1)

Additionally, 4 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 99576cf2ebc870c305225e9856b9423228872c56 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. arm-android: 1h 47m -> 1h 3m (-40.4%)
  2. x86_64-gnu-gcc-core-tests: 13m 51s -> 8m 45s (-36.9%)
  3. dist-arm-linux-gnueabi: 1h 1m -> 1h 23m (+35.2%)
  4. x86_64-gnu-gcc: 1h 11m -> 48m 44s (-31.6%)
  5. x86_64-mingw-1: 2h 9m -> 2h 46m (+28.9%)
  6. x86_64-msvc-1: 2h 5m -> 2h 29m (+19.5%)
  7. pr-check-1: 30m 26s -> 25m 34s (-16.0%)
  8. dist-x86_64-linux-alt: 2h 19m -> 1h 57m (-15.8%)
  9. x86_64-gnu-nopt: 2h 26m -> 2h 3m (-15.4%)
  10. x86_64-gnu-tools: 1h 3m -> 54m 30s (-13.9%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (99576cf): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.2%, -0.3%] 10
Improvements ✅
(secondary)
-0.7% [-1.1%, -0.3%] 10
All ❌✅ (primary) -0.7% [-1.2%, -0.3%] 10

Max RSS (memory usage)

Results (primary -2.0%, secondary 0.8%)

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.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-2.0% [-6.1%, -0.5%] 5
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.8%] 1
All ❌✅ (primary) -2.0% [-6.1%, -0.5%] 5

Cycles

Results (primary -2.7%)

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)
-2.7% [-3.2%, -2.1%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.7% [-3.2%, -2.1%] 2

Binary size

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

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.0%, 0.2%] 5
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
-0.1% [-0.3%, -0.0%] 13
Improvements ✅
(secondary)
-0.0% [-0.1%, -0.0%] 8
All ❌✅ (primary) -0.1% [-0.3%, 0.2%] 18

Bootstrap: 487.812s -> 488.508s (0.14%)
Artifact size: 388.49 MiB -> 388.95 MiB (0.12%)

@rustbot rustbot removed the perf-regression Performance regression. label Jul 8, 2026
@cjgillot
cjgillot deleted the elaborate-drop-chain branch July 8, 2026 10:50
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 1, 2026
…aethlin

Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to rust-lang#157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 1, 2026
…aethlin

Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to rust-lang#157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 2, 2026
…aethlin

Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to rust-lang#157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
rust-bors Bot pushed a commit that referenced this pull request Aug 2, 2026
Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to #157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 2, 2026
…aethlin

Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to rust-lang#157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
rust-timer added a commit that referenced this pull request Aug 2, 2026
Rollup merge of #159195 - cjgillot:elaborate-drop-flags, r=saethlin

Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to #157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. 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.

6 participants