@@ -1118,6 +1118,25 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
11181118 }
11191119 Ok ( matrix)
11201120 }
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+ }
11211140}
11221141
11231142/// Pretty-printer for matrices of patterns, example:
@@ -1542,21 +1561,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15421561 // Accumulate the found witnesses.
15431562 ret. extend ( witnesses) ;
15441563
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-
15601564 // Detect ranges that overlap on their endpoints.
15611565 if let Constructor :: IntRange ( overlap_range) = ctor {
15621566 if overlap_range. is_singleton ( )
@@ -1566,6 +1570,8 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15661570 collect_overlapping_range_endpoints ( mcx, overlap_range, matrix, & spec_matrix) ;
15671571 }
15681572 }
1573+
1574+ matrix. unspecialize ( spec_matrix) ;
15691575 }
15701576
15711577 // Record usefulness in the patterns.
0 commit comments