mir_build: Split MatchPairTree into testable and or-pattern variants - #158551
mir_build: Split MatchPairTree into testable and or-pattern variants#158551Zalathar wants to merge 2 commits into
MatchPairTree into testable and or-pattern variants#158551Conversation
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.
|
Some changes occurred in match lowering cc @Nadrieril |
|
|
| #[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>>, | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Hmm yeah, I can appreciate not wanting to further entrench the or-pattern reordering behaviour.
|
The future of this PR is a bit murky and it’s currently not a high priority for me, so: @rustbot author |
|
Closing this, as I now have some different ideas about separating or-patterns and testable patterns. |
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