@@ -1189,6 +1189,25 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1189
1189
}
1190
1190
Ok ( matrix)
1191
1191
}
1192
+
1193
+ /// Recover row usefulness and intersection information from a processed specialized matrix.
1194
+ /// `specialized` must come from `self.specialize_constructor`.
1195
+ fn unspecialize ( & mut self , specialized : Self ) {
1196
+ for child_row in specialized. rows ( ) {
1197
+ let parent_row_id = child_row. parent_row ;
1198
+ let parent_row = & mut self . rows [ parent_row_id] ;
1199
+ // A parent row is useful if any of its children is.
1200
+ parent_row. useful |= child_row. useful ;
1201
+ for child_intersection in child_row. intersects . iter ( ) {
1202
+ // Convert the intersecting ids into ids for the parent matrix.
1203
+ let parent_intersection = specialized. rows [ child_intersection] . parent_row ;
1204
+ // Note: self-intersection can happen with or-patterns.
1205
+ if parent_intersection != parent_row_id {
1206
+ parent_row. intersects . insert ( parent_intersection) ;
1207
+ }
1208
+ }
1209
+ }
1210
+ }
1192
1211
}
1193
1212
1194
1213
/// Pretty-printer for matrices of patterns, example:
@@ -1558,21 +1577,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1558
1577
// Accumulate the found witnesses.
1559
1578
ret. extend ( witnesses) ;
1560
1579
1561
- for child_row in spec_matrix. rows ( ) {
1562
- let parent_row_id = child_row. parent_row ;
1563
- let parent_row = & mut matrix. rows [ parent_row_id] ;
1564
- // A parent row is useful if any of its children is.
1565
- parent_row. useful |= child_row. useful ;
1566
- for child_intersection in child_row. intersects . iter ( ) {
1567
- // Convert the intersecting ids into ids for the parent matrix.
1568
- let parent_intersection = spec_matrix. rows [ child_intersection] . parent_row ;
1569
- // Note: self-intersection can happen with or-patterns.
1570
- if parent_intersection != parent_row_id {
1571
- parent_row. intersects . insert ( parent_intersection) ;
1572
- }
1573
- }
1574
- }
1575
-
1576
1580
// Detect ranges that overlap on their endpoints.
1577
1581
if let Constructor :: IntRange ( overlap_range) = ctor {
1578
1582
if overlap_range. is_singleton ( )
@@ -1582,6 +1586,8 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1582
1586
collect_overlapping_range_endpoints ( mcx, overlap_range, matrix, & spec_matrix) ;
1583
1587
}
1584
1588
}
1589
+
1590
+ matrix. unspecialize ( spec_matrix) ;
1585
1591
}
1586
1592
1587
1593
// Record usefulness in the patterns.
0 commit comments