Skip to content

Commit e05df1c

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 854feae commit e05df1c

File tree

3 files changed

+14
-71
lines changed

3 files changed

+14
-71
lines changed

Diff for: compiler/rustc_mir_build/src/builder/matches/mod.rs

+13-10
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

@@ -987,18 +986,16 @@ impl<'tcx> PatternExtraData<'tcx> {
987986
}
988987

989988
/// A pattern in a form suitable for lowering the match tree, with all irrefutable
990-
/// patterns simplified away, and or-patterns sorted to the end.
989+
/// patterns simplified away.
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.
1002999
match_pairs: Vec<MatchPairTree<'tcx>>,
10031000

10041001
extra_data: PatternExtraData<'tcx>,
@@ -1017,7 +1014,6 @@ impl<'tcx> FlatPat<'tcx> {
10171014
is_never: pattern.is_never_pattern(),
10181015
};
10191016
MatchPairTree::for_pattern(place, pattern, cx, &mut match_pairs, &mut extra_data);
1020-
cx.simplify_match_pairs(&mut match_pairs, &mut extra_data);
10211017

10221018
Self { match_pairs, extra_data }
10231019
}
@@ -1124,7 +1120,7 @@ impl<'tcx> Candidate<'tcx> {
11241120

11251121
/// Incorporates an already-simplified [`FlatPat`] into a new candidate.
11261122
fn from_flat_pat(flat_pat: FlatPat<'tcx>, has_guard: bool) -> Self {
1127-
Candidate {
1123+
let mut this = Candidate {
11281124
match_pairs: flat_pat.match_pairs,
11291125
extra_data: flat_pat.extra_data,
11301126
has_guard,
@@ -1133,7 +1129,14 @@ impl<'tcx> Candidate<'tcx> {
11331129
otherwise_block: None,
11341130
pre_binding_block: None,
11351131
false_edge_start_block: None,
1136-
}
1132+
};
1133+
this.sort_match_pairs();
1134+
this
1135+
}
1136+
1137+
/// Restores the invariant that or-patterns must be sorted to the end.
1138+
fn sort_match_pairs(&mut self) {
1139+
self.match_pairs.sort_by_key(|pair| matches!(pair.test_case, TestCase::Or { .. }));
11371140
}
11381141

11391142
/// Returns whether the first match pair of this candidate is an or-pattern.

Diff for: compiler/rustc_mir_build/src/builder/matches/simplify.rs

-60
This file was deleted.

Diff for: compiler/rustc_mir_build/src/builder/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
763763
let match_pair = candidate.match_pairs.remove(match_pair_index);
764764
candidate.match_pairs.extend(match_pair.subpairs);
765765
// Move or-patterns to the end.
766-
candidate.match_pairs.sort_by_key(|pair| matches!(pair.test_case, TestCase::Or { .. }));
766+
candidate.sort_match_pairs();
767767
}
768768

769769
ret

0 commit comments

Comments
 (0)