Skip to content

Simplify the canonical enum clone branches to a copy statement#148034

Merged
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
dianqk:matchbr-copy
Feb 19, 2026
Merged

Simplify the canonical enum clone branches to a copy statement#148034
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
dianqk:matchbr-copy

Conversation

@dianqk
Copy link
Member

@dianqk dianqk commented Oct 23, 2025

I have overhauled MatchBranchSimplification in this PR. This pass tries to unify statements one by one, which is more readable and extensible.

This PR also unifies the following pattern that is mostly generated by GVN into one basic block that contains the copy statement:

match a {
    Foo::A(_) => *a,
    Foo::B => Foo::B
}

Fixes #128081.

@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 Oct 23, 2025
@dianqk
Copy link
Member Author

dianqk commented Oct 23, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 23, 2025
rust-bors bot added a commit that referenced this pull request Oct 23, 2025
[WIP] Simplify the canonical enum clone branches to a copy statement
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Contributor

rust-bors bot commented Oct 23, 2025

💔 Test for b4269e3 failed: CI. Failed jobs:

@dianqk
Copy link
Member Author

dianqk commented Oct 23, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 23, 2025
[WIP] Simplify the canonical enum clone branches to a copy statement
@rust-bors
Copy link
Contributor

rust-bors bot commented Oct 24, 2025

☀️ Try build successful (CI)
Build commit: 673e3f6 (673e3f61f8b218d304147e821d485edf0ebf3b09, parent: 6501e64fcb02d22b49d6e59d10a7692ec8095619)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (673e3f6): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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.3%, 0.4%] 6
Improvements ✅
(primary)
-1.0% [-2.4%, -0.1%] 6
Improvements ✅
(secondary)
-0.2% [-1.3%, -0.1%] 17
All ❌✅ (primary) -0.8% [-2.4%, 0.7%] 7

Max RSS (memory usage)

Results (primary 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.8% [1.9%, 4.3%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.8% [1.9%, 4.3%] 3

Cycles

Results (primary -3.4%, secondary -2.0%)

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)
-3.4% [-3.4%, -3.4%] 1
Improvements ✅
(secondary)
-2.7% [-4.5%, -2.1%] 6
All ❌✅ (primary) -3.4% [-3.4%, -3.4%] 1

Binary size

Results (primary -0.1%, 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.1% [0.0%, 0.2%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.4%, -0.0%] 20
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 41
All ❌✅ (primary) -0.1% [-0.4%, 0.2%] 23

Bootstrap: 476.496s -> 474.095s (-0.50%)
Artifact size: 390.49 MiB -> 390.42 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 Oct 24, 2025
@dianqk dianqk force-pushed the matchbr-copy branch 2 times, most recently from d2deaa3 to 8a2e9e4 Compare October 26, 2025 05:22
@dianqk dianqk changed the title [WIP] Simplify the canonical enum clone branches to a copy statement Simplify the canonical enum clone branches to a copy statement Oct 26, 2025
@dianqk
Copy link
Member Author

dianqk commented Oct 26, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 26, 2025
Simplify the canonical enum clone branches to a copy statement
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 26, 2025
@rust-bors
Copy link
Contributor

rust-bors bot commented Oct 26, 2025

☀️ Try build successful (CI)
Build commit: da8af3c (da8af3c91a895fd9646d0e6ef1477767ea0b6076, parent: e5177985a5493c783d6ba20960d2723d9d2e9214)

@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 Feb 17, 2026
Simplify the canonical enum clone branches to a copy statement
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 17, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

☀️ Try build successful (CI)
Build commit: 5f821fd (5f821fdf3e550566d4aa962998f26d502fb3b896, parent: 3c9faa0d037b9eecda4a440cc482ff7f960fb8a5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5f821fd): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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.3%, 0.3%] 2
Improvements ✅
(primary)
-1.1% [-2.0%, -0.7%] 4
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 6
All ❌✅ (primary) -0.8% [-2.0%, 0.7%] 5

Max RSS (memory usage)

Results (primary -3.6%, secondary 5.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)
5.5% [5.5%, 5.5%] 1
Improvements ✅
(primary)
-3.6% [-4.5%, -2.4%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.6% [-4.5%, -2.4%] 4

Cycles

This benchmark run did not return any relevant results for this metric.

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.2% [-0.8%, -0.0%] 9
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 2
All ❌✅ (primary) -0.1% [-0.8%, 0.2%] 14

Bootstrap: 480.798s -> 481.457s (0.14%)
Artifact size: 395.81 MiB -> 397.87 MiB (0.52%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 17, 2026
@dianqk
Copy link
Member Author

dianqk commented Feb 17, 2026

From the several results, it appears regex-automata-0.4.8 is flaky.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 17, 2026
@cjgillot
Copy link
Contributor

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

📌 Commit b4e3de0 has been approved by cjgillot

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 Feb 17, 2026
@JonathanBrouwer
Copy link
Contributor

@bors p=2
Scheduling

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 19, 2026
Simplify the canonical enum clone branches to a copy statement

I have overhauled MatchBranchSimplification in this PR. This pass tries to unify statements one by one, which is more readable and extensible.

This PR also unifies the following pattern that is mostly generated by GVN into one basic block that contains the copy statement:

```rust
match a {
    Foo::A(_) => *a,
    Foo::B => Foo::B
}
```

Fixes #128081.
@JonathanBrouwer
Copy link
Contributor

@bors yield
Yielding to the rollup that spuriously failed

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 19, 2026

Auto build cancelled. Cancelled workflows:

The next pull request likely to be tested is #152825.

@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 Feb 19, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 19, 2026

☀️ Test successful - CI
Approved by: cjgillot
Duration: 3h 12m 54s
Pushing 41198cb to main...

@rust-bors rust-bors bot merged commit 41198cb into rust-lang:main Feb 19, 2026
13 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 19, 2026
@dianqk dianqk deleted the matchbr-copy branch February 19, 2026 13:10
@github-actions
Copy link
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 fbd6934 (parent) -> 41198cb (this PR)

Test differences

Show 30 test diffs

Stage 1

  • [mir-opt] tests/mir-opt/pre-codegen/copy_and_clone.rs#CLONE: [missing] -> pass (J1)
  • [mir-opt] tests/mir-opt/pre-codegen/copy_and_clone.rs#COPY: [missing] -> pass (J1)

Stage 2

  • [mir-opt] tests/mir-opt/pre-codegen/copy_and_clone.rs#CLONE: [missing] -> pass (J0)
  • [mir-opt] tests/mir-opt/pre-codegen/copy_and_clone.rs#COPY: [missing] -> pass (J0)

Additionally, 26 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 41198cb9659f3cc7c4a1a3ee97bc4af78bee403e --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. aarch64-apple: 5h 28m -> 2h 34m (-52.9%)
  2. dist-x86_64-apple: 2h 5m -> 2h 38m (+27.0%)
  3. tidy: 2m 23s -> 2m 49s (+18.3%)
  4. dist-aarch64-apple: 2h 38m -> 2h 12m (-16.3%)
  5. dist-aarch64-llvm-mingw: 1h 32m -> 1h 46m (+15.1%)
  6. i686-gnu-nopt-1: 1h 59m -> 2h 9m (+8.7%)
  7. x86_64-gnu-miri: 1h 11m -> 1h 16m (+8.2%)
  8. x86_64-gnu-llvm-20: 1h 11m -> 1h 15m (+6.8%)
  9. dist-powerpc-linux: 1h 33m -> 1h 27m (-6.6%)
  10. dist-loongarch64-musl: 1h 45m -> 1h 51m (+5.8%)
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
Collaborator

Finished benchmarking commit (41198cb): 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.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
-0.6% [-2.1%, -0.2%] 9
Improvements ✅
(secondary)
-0.5% [-0.8%, -0.2%] 14
All ❌✅ (primary) -0.5% [-2.1%, 0.7%] 10

Max RSS (memory usage)

Results (primary -0.7%)

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.5%, 3.3%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.3% [-4.5%, -4.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-4.5%, 3.3%] 4

Cycles

Results (primary -2.2%, secondary 9.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)
9.6% [9.6%, 9.6%] 1
Improvements ✅
(primary)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.2% [-2.2%, -2.2%] 1

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.2% [-0.8%, -0.0%] 9
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 2
All ❌✅ (primary) -0.1% [-0.8%, 0.2%] 14

Bootstrap: 481.318s -> 479.676s (-0.34%)
Artifact size: 397.87 MiB -> 397.83 MiB (-0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Feb 19, 2026
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.

Suboptimal codegen for non-copy-derived struct with all Copy derived fields

8 participants

Comments