Skip to content

Commit 787bb11

Browse files
committed
No explicit column counting on pattern matrix
1 parent 62a57cc commit 787bb11

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

crates/hir-analysis/src/ty/pattern_analysis.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,11 @@ use hir::hir_def::{scope_graph::ScopeId, Body as HirBody, LitKind, Pat as HirPat
1313
#[derive(Clone, Debug, PartialEq, Eq)]
1414
pub struct PatternMatrix<'db> {
1515
pub rows: Vec<PatternRowVec<'db>>,
16-
/// Column count for empty matrices (when rows.is_empty())
17-
column_count: Option<usize>,
1816
}
1917

2018
impl<'db> PatternMatrix<'db> {
2119
pub fn new(rows: Vec<PatternRowVec<'db>>) -> Self {
22-
Self {
23-
rows,
24-
column_count: None,
25-
}
26-
}
27-
28-
pub fn new_with_column_count(rows: Vec<PatternRowVec<'db>>, column_count: usize) -> Self {
29-
Self {
30-
rows,
31-
column_count: Some(column_count),
32-
}
20+
Self { rows }
3321
}
3422

3523
pub fn from_hir_patterns(
@@ -48,10 +36,7 @@ impl<'db> PatternMatrix<'db> {
4836
)])
4937
})
5038
.collect();
51-
Self {
52-
rows,
53-
column_count: None,
54-
}
39+
Self { rows }
5540
}
5641

5742
/// Find missing patterns that would make the matrix exhaustive
@@ -163,7 +148,6 @@ impl<'db> PatternMatrix<'db> {
163148

164149
let previous = PatternMatrix {
165150
rows: self.rows[0..row].to_vec(),
166-
column_count: None,
167151
};
168152
previous.is_pattern_useful(db, &self.rows[row])
169153
}
@@ -216,15 +200,7 @@ impl<'db> PatternMatrix<'db> {
216200
.flat_map(|row| row.phi_specialize(db, ctor))
217201
.collect();
218202

219-
// Calculate column count for specialized matrix
220-
let new_column_count = if rows.is_empty() && self.ncols() > 0 {
221-
// Original columns - 1 (removed) + ctor.arity (added)
222-
Some(self.ncols() - 1 + ctor.arity(db))
223-
} else {
224-
None
225-
};
226-
227-
PatternMatrix::new_with_column_count(rows, new_column_count.unwrap_or(0))
203+
PatternMatrix::new(rows)
228204
}
229205

230206
pub fn d_specialize(&self) -> Self {
@@ -234,14 +210,7 @@ impl<'db> PatternMatrix<'db> {
234210
.flat_map(|row| row.d_specialize())
235211
.collect();
236212

237-
// Default specialization removes one column
238-
let new_column_count = if rows.is_empty() && self.ncols() > 0 {
239-
Some(self.ncols() - 1)
240-
} else {
241-
None
242-
};
243-
244-
PatternMatrix::new_with_column_count(rows, new_column_count.unwrap_or(0))
213+
PatternMatrix::new(rows)
245214
}
246215

247216
pub fn sigma_set(&self) -> SigmaSet<'db> {
@@ -258,7 +227,7 @@ impl<'db> PatternMatrix<'db> {
258227

259228
pub fn ncols(&self) -> usize {
260229
if self.nrows() == 0 {
261-
self.column_count.unwrap_or(0)
230+
0
262231
} else {
263232
let ncols = self.rows[0].len();
264233
debug_assert!(self.rows.iter().all(|row| row.len() == ncols));

0 commit comments

Comments
 (0)