From b2dbbb6076ae6c7bdfc31bf6e30be0c8a3b21295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 28 Aug 2025 12:32:13 +0000 Subject: [PATCH 1/2] densebitset-unsafe wip --- compiler/rustc_index/src/bit_set.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 684bd34f909c0..3892086b168f7 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -194,7 +194,11 @@ impl DenseBitSet { self.domain_size, ); let (word_index, mask) = word_index_and_mask(elem); - let word_ref = &mut self.words[word_index]; + // SAFETY: + // The number of words we have is the domain size divided by word size (rounded up). We have + // asserted above that the element is contained within the domain size. Therefore, + // word_index is in bounds. + let word_ref = unsafe { self.words.get_unchecked_mut(word_index) }; let word = *word_ref; let new_word = word | mask; *word_ref = new_word; From 2cd24b5fa3dca39ceef9a91e1f823b248bc69b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Thu, 28 Aug 2025 12:39:29 +0000 Subject: [PATCH 2/2] densebitset-unsafe wip --- compiler/rustc_index/src/bit_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 3892086b168f7..914821bbc7858 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -187,7 +187,7 @@ impl DenseBitSet { /// Insert `elem`. Returns whether the set has changed. #[inline] pub fn insert(&mut self, elem: T) -> bool { - assert!( + debug_assert!( elem.index() < self.domain_size, "inserting element at index {} but domain size is {}", elem.index(),