Skip to content

Commit 621525d

Browse files
committed
Remove the separate simplify step for match-pair trees
What remained of this simplification process has been integrated into construction of the match-pair trees.
1 parent 54cc229 commit 621525d

File tree

3 files changed

+15
-67
lines changed

3 files changed

+15
-67
lines changed

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

+7
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ impl<'tcx> MatchPairTree<'tcx> {
319319

320320
if let Some(test_case) = test_case {
321321
// This pattern is refutable, so push a new match-pair node.
322+
sort_match_pairs(&mut subpairs);
322323
match_pairs.push(MatchPairTree {
323324
place,
324325
test_case,
@@ -333,3 +334,9 @@ impl<'tcx> MatchPairTree<'tcx> {
333334
}
334335
}
335336
}
337+
338+
/// Sorts or-patterns to the end of the list, as required by [`FlatPat`] and
339+
/// its enclosed [`MatchPairTree`] nodes.
340+
pub(super) fn sort_match_pairs(match_pairs: &mut [MatchPairTree<'_>]) {
341+
match_pairs.sort_by_key(|pair| matches!(pair.test_case, TestCase::Or { .. }));
342+
}

compiler/rustc_mir_build/src/builder/matches/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::builder::{
2626

2727
// helper functions, broken out by category:
2828
mod match_pair;
29-
mod simplify;
3029
mod test;
3130
mod util;
3231

@@ -989,16 +988,16 @@ impl<'tcx> PatternExtraData<'tcx> {
989988
/// A pattern in a form suitable for lowering the match tree, with all irrefutable
990989
/// patterns simplified away, and or-patterns sorted to the end.
991990
///
992-
/// Here, "flat" indicates that the pattern's match pairs have been recursively
993-
/// simplified by [`Builder::simplify_match_pairs`]. They are not necessarily
994-
/// flat in an absolute sense.
991+
/// Here, "flat" indicates that irrefutable nodes in the pattern tree have been
992+
/// recursively replaced with their refutable subpatterns. They are not
993+
/// necessarily flat in an absolute sense.
995994
///
996995
/// Will typically be incorporated into a [`Candidate`].
997996
#[derive(Debug, Clone)]
998997
struct FlatPat<'tcx> {
999998
/// To match the pattern, all of these must be satisfied...
1000-
// Invariant: all the match pairs are recursively simplified.
1001-
// Invariant: or-patterns must be sorted to the end.
999+
/// ---
1000+
/// Invariant: Or-patterns must be sorted to the end.
10021001
match_pairs: Vec<MatchPairTree<'tcx>>,
10031002

10041003
extra_data: PatternExtraData<'tcx>,
@@ -1017,7 +1016,7 @@ impl<'tcx> FlatPat<'tcx> {
10171016
is_never: pattern.is_never_pattern(),
10181017
};
10191018
MatchPairTree::for_pattern(place, pattern, cx, &mut match_pairs, &mut extra_data);
1020-
cx.simplify_match_pairs(&mut match_pairs, &mut extra_data);
1019+
match_pair::sort_match_pairs(&mut match_pairs);
10211020

10221021
Self { match_pairs, extra_data }
10231022
}
@@ -1271,6 +1270,8 @@ pub(crate) struct MatchPairTree<'tcx> {
12711270
/// parent has succeeded. For example, the pattern `Some(3)` might have an
12721271
/// outer match pair that tests for the variant `Some`, and then a subpair
12731272
/// that tests its field for the value `3`.
1273+
///
1274+
/// Invariant: Or-patterns must be sorted to the end.
12741275
subpairs: Vec<Self>,
12751276

12761277
/// Type field of the pattern this node was created from.

compiler/rustc_mir_build/src/builder/matches/simplify.rs

-60
This file was deleted.

0 commit comments

Comments
 (0)