Skip to content

mir_build: Add an extra intermediate step in MIR building for patterns #155144

Draft
Zalathar wants to merge 4 commits intorust-lang:mainfrom
Zalathar:inter-pat
Draft

mir_build: Add an extra intermediate step in MIR building for patterns #155144
Zalathar wants to merge 4 commits intorust-lang:mainfrom
Zalathar:inter-pat

Conversation

@Zalathar
Copy link
Copy Markdown
Member

This is an attempt to partly decouple the data structures created by match_pair.rs from the data structures that are ultimately consumed by the main part of match lowering.

In some ways this is a reversal from #137875. That PR succeeded in removing the TestCase::Irrefutable variant, by taking a pre-existing “simplification” step and fusing it directly into MatchPairTree::for_pattern. Unfortunately, in doing so it also reinforced a very high degree of coupling between the transformations performed in match_pair, and the data structures used by later steps.

My hope is that these changes will make it easier for follow-up work to further separate decision-making from MIR building when lowering patterns.

Currently marked as draft because I want to double-check perf, and because I want to spend some more time thinking about whether this is a good direction.

r? Nadrieril

This makes it easier to perform coordinated modifications to `FlatPat::new` and
`MatchPairTree::from_pattern`, because the two functions are heavily coupled.
@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 11, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 11, 2026

Nadrieril is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

This splits out a separate `InterPat` data structure from
`MatchPairTree`/`FlatPat`/`Candidate`, which should hopefully make it easier to
modify these earlier parts of match lowering without having to simultaneously
adjust many use-sites in later steps.
@Zalathar
Copy link
Copy Markdown
Member Author

@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 11, 2026
mir_build: Add an extra intermediate step in MIR building for patterns
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 11, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 11, 2026

☀️ Try build successful (CI)
Build commit: 76367e4 (76367e4db9c5ebe2cd39a24f067d772b200f4158, parent: c29effdf79bdea928ea366a2a820ed15c1de5f43)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (76367e4): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

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.

@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
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 2.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)
4.8% [0.9%, 6.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.9% [-3.9%, -3.9%] 1
All ❌✅ (primary) - - 0

Cycles

Results (primary -9.8%, secondary -4.3%)

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)
-9.8% [-20.6%, -3.1%] 13
Improvements ✅
(secondary)
-4.3% [-8.0%, -2.5%] 4
All ❌✅ (primary) -9.8% [-20.6%, -3.1%] 13

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 491.148s -> 509.241s (3.68%)
Artifact size: 394.19 MiB -> 394.20 MiB (0.00%)

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

Labels

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.

5 participants