Skip to content

Commit ce85826

Browse files
authored
Unrolled build for rust-lang#121324
Rollup merge of rust-lang#121324 - Nadrieril:unspecialize, r=cjgillot pattern_analysis: factor out unspecialization Just moving a dense bit of logic into its own method.
2 parents 34aab62 + 47b2173 commit ce85826

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

compiler/rustc_pattern_analysis/src/usefulness.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,25 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
11891189
}
11901190
Ok(matrix)
11911191
}
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+
}
11921211
}
11931212

11941213
/// Pretty-printer for matrices of patterns, example:
@@ -1558,21 +1577,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15581577
// Accumulate the found witnesses.
15591578
ret.extend(witnesses);
15601579

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-
15761580
// Detect ranges that overlap on their endpoints.
15771581
if let Constructor::IntRange(overlap_range) = ctor {
15781582
if overlap_range.is_singleton()
@@ -1582,6 +1586,8 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15821586
collect_overlapping_range_endpoints(mcx, overlap_range, matrix, &spec_matrix);
15831587
}
15841588
}
1589+
1590+
matrix.unspecialize(spec_matrix);
15851591
}
15861592

15871593
// Record usefulness in the patterns.

0 commit comments

Comments
 (0)