From 4b83547c8ba991f2d0a9e745e0c3256f0b5bda38 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 24 Aug 2026 11:54:18 +1000 Subject: [PATCH] [EXPERIMENT] Check if isolating `Matrix::unspecializes` dodges regressions --- compiler/rustc_index/src/bit_set.rs | 12 ++++++++++++ compiler/rustc_pattern_analysis/src/usefulness.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index aa3c759a6adbd..daaa6139d63d6 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -147,6 +147,18 @@ impl DenseBitSet { /// Insert `elem`. Returns whether the set has changed. #[inline] pub fn insert(&mut self, elem: T) -> bool { + assert!(elem.index() < self.domain_size); + let (word_index, mask) = word_index_and_mask(elem); + let word_ref = &mut self.words[word_index]; + let word = *word_ref; + let new_word = word | mask; + *word_ref = new_word; + new_word != word + } + + /// Insert `elem`. Returns whether the set has changed. + #[inline] + pub fn insert2(&mut self, elem: T) -> bool { assert!( elem.index() < self.domain_size, "inserting element at index {} but domain size is {}", diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 1f19bfd732892..b5249af65a4ba 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -1327,7 +1327,7 @@ impl<'p, Cx: PatCx> Matrix<'p, Cx> { let parent_intersection = specialized.rows[child_intersection].parent_row; // Note: self-intersection can happen with or-patterns. if parent_intersection != parent_row_id { - parent_row.intersects_at_least.insert(parent_intersection); + parent_row.intersects_at_least.insert2(parent_intersection); } } }