@@ -1118,6 +1118,25 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1118
1118
}
1119
1119
Ok ( matrix)
1120
1120
}
1121
+
1122
+ /// Recover row usefulness and intersection information from a processed specialized matrix.
1123
+ /// `specialized` must come from `self.specialize_constructor`.
1124
+ fn unspecialize ( & mut self , specialized : Self ) {
1125
+ for child_row in specialized. rows ( ) {
1126
+ let parent_row_id = child_row. parent_row ;
1127
+ let parent_row = & mut self . rows [ parent_row_id] ;
1128
+ // A parent row is useful if any of its children is.
1129
+ parent_row. useful |= child_row. useful ;
1130
+ for child_intersection in child_row. intersects . iter ( ) {
1131
+ // Convert the intersecting ids into ids for the parent matrix.
1132
+ let parent_intersection = specialized. rows [ child_intersection] . parent_row ;
1133
+ // Note: self-intersection can happen with or-patterns.
1134
+ if parent_intersection != parent_row_id {
1135
+ parent_row. intersects . insert ( parent_intersection) ;
1136
+ }
1137
+ }
1138
+ }
1139
+ }
1121
1140
}
1122
1141
1123
1142
/// Pretty-printer for matrices of patterns, example:
@@ -1542,21 +1561,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1542
1561
// Accumulate the found witnesses.
1543
1562
ret. extend ( witnesses) ;
1544
1563
1545
- for child_row in spec_matrix. rows ( ) {
1546
- let parent_row_id = child_row. parent_row ;
1547
- let parent_row = & mut matrix. rows [ parent_row_id] ;
1548
- // A parent row is useful if any of its children is.
1549
- parent_row. useful |= child_row. useful ;
1550
- for child_intersection in child_row. intersects . iter ( ) {
1551
- // Convert the intersecting ids into ids for the parent matrix.
1552
- let parent_intersection = spec_matrix. rows [ child_intersection] . parent_row ;
1553
- // Note: self-intersection can happen with or-patterns.
1554
- if parent_intersection != parent_row_id {
1555
- parent_row. intersects . insert ( parent_intersection) ;
1556
- }
1557
- }
1558
- }
1559
-
1560
1564
// Detect ranges that overlap on their endpoints.
1561
1565
if let Constructor :: IntRange ( overlap_range) = ctor {
1562
1566
if overlap_range. is_singleton ( )
@@ -1566,6 +1570,8 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1566
1570
collect_overlapping_range_endpoints ( mcx, overlap_range, matrix, & spec_matrix) ;
1567
1571
}
1568
1572
}
1573
+
1574
+ matrix. unspecialize ( spec_matrix) ;
1569
1575
}
1570
1576
1571
1577
// Record usefulness in the patterns.
0 commit comments