Skip to content

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

Open
Zalathar wants to merge 2 commits into
rust-lang:mainfrom
Zalathar:inter-pat
Open

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

Conversation

@Zalathar
Copy link
Copy Markdown
Member

@Zalathar Zalathar commented Apr 11, 2026

View all comments

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.

r? Nadrieril

@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.

@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
@Zalathar

This comment was marked as resolved.

@Zalathar Zalathar force-pushed the inter-pat branch 2 times, most recently from 0623749 to c9949ba Compare April 18, 2026 05:34
@rust-bors

This comment has been minimized.

@Zalathar Zalathar force-pushed the inter-pat branch 2 times, most recently from 9631275 to 7abdb0f Compare April 18, 2026 12:02
@Zalathar
Copy link
Copy Markdown
Member Author

Marking this as ready for consideration.

I'm not entirely confident about the name “InterPat”, and I'm aware that this change doesn't yet demonstrate any clear benefit on its own, but I think it's a worthwhile step towards hopefully being able to disentangle match-lowering a bit more.

@Zalathar Zalathar marked this pull request as ready for review April 18, 2026 12:06
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 18, 2026

Some changes occurred in match lowering

cc @Nadrieril

@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 Apr 18, 2026
Copy link
Copy Markdown
Member

@Nadrieril Nadrieril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, the separation of concerns is very clean. I'm on board, I only have a couple nits. Agreed that InterPat isn't an amazing name but it's used in a single file so who cares really.

View changes since this review

Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs Outdated
Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs Outdated
Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs
Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs Outdated
Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs Outdated
Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs Outdated
@rustbot

This comment has been minimized.

@Zalathar
Copy link
Copy Markdown
Member Author

(Rebased onto main to make things easier; no actual changes yet.)

Comment thread compiler/rustc_mir_build/src/builder/matches/match_pair.rs Outdated
@Zalathar
Copy link
Copy Markdown
Member Author

Updated some comments (diff); still considering what to do about the style feedback.

@Zalathar Zalathar force-pushed the inter-pat branch 3 times, most recently from 2165ec3 to 6a94268 Compare April 27, 2026 11:30
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@Nadrieril
Copy link
Copy Markdown
Member

Still waiting on you, right?

@rustbot author

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

Oh I thought I was waiting for you, but I'll do another self-review pass before kicking this back to ready. 😅

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 13, 2026

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.

@Zalathar
Copy link
Copy Markdown
Member Author

Rebased and added a few more comments (diff).

@rustbot ready

@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 May 13, 2026
@rust-log-analyzer

This comment has been minimized.

Zalathar added 2 commits May 13, 2026 22:37
This makes it easier to perform coordinated modifications to `FlatPat::new` and
`MatchPairTree::from_pattern`, because the two functions are heavily coupled.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants