Skip to content

mir_build: Split MatchPairTree into testable and or-pattern variants - #158551

Closed
Zalathar wants to merge 2 commits into
rust-lang:mainfrom
Zalathar:or-pat
Closed

mir_build: Split MatchPairTree into testable and or-pattern variants#158551
Zalathar wants to merge 2 commits into
rust-lang:mainfrom
Zalathar:or-pat

Conversation

@Zalathar

Copy link
Copy Markdown
Member

This creates a clearer distinction between non-or-pattern nodes that can be directly tested, and or-pattern nodes that require or-expansion before they can participate in tests.

Storing testable nodes and or-pattern nodes in separate lists means that there is no need to uphold a sorting invariant, and avoids the need for assertions and unwraps in various helper functions that expect to only deal with one or the other.

There should be no change to the resulting MIR.

r? Nadrieril

Zalathar added 2 commits June 29, 2026 18:14
This creates a clearer distinction between non-or-pattern nodes that can be
directly tested, and or-pattern nodes that require or-expansion before they can
participate in tests.

Storing testable nodes and or-pattern nodes in separate lists means that there
is no need to uphold a sorting invariant, and avoids the need for assertions
and unwraps in various helper functions that expect to only deal with one or
the other.

There should be no change to the resulting MIR.
Now that or-patterns have their own separate variant, testable match-pairs are
always guaranteed to have a place.
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Nadrieril is currently at their maximum review capacity.
They may take a while to respond.

Comment on lines +1136 to +1144
#[derive(Debug)]
struct MatchPairsQueue<'tcx> {
/// Match pairs that can be "tested" directly, because they are not or-patterns.
testable_match_pairs: Vec<TestableMatchPairTree<'tcx>>,
/// Or-patterns, which must be expanded before their subpatterns can participate in tests.
/// These should only be processed after `testable_match_pairs` is empty
/// (see [`Self::starts_with_or_pattern`]).
or_match_pairs: Vec<OrMatchPairTree<'tcx>>,
}

@Nadrieril Nadrieril Jun 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately I don't think that's the right approach: we will need to support having or-patterns not sorted to the end in order to fix #158387. Also, it's not a "must": sorting or-patterns at the end is purely an optimization (well, except the union case), so forgetting the invariant isn't a huge issue.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm yeah, I can appreciate not wanting to further entrench the or-pattern reordering behaviour.

@Zalathar

Zalathar commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

The future of this PR is a bit murky and it’s currently not a high priority for me, so:

@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 Jul 5, 2026
@Zalathar

Zalathar commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

Closing this, as I now have some different ideas about separating or-patterns and testable patterns.

@Zalathar Zalathar closed this Aug 3, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 3, 2026
@Zalathar
Zalathar deleted the or-pat branch August 3, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants