Skip to content

Commit c730ac2

Browse files
committed
!! (WIP) switch to Box<[Word]>
1 parent 0967d97 commit c730ac2

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

compiler/rustc_index/src/bit_set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ macro_rules! bit_relations_inherent_impls {
121121
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext))]
122122
#[derive(Eq, PartialEq, Hash)]
123123
pub struct DenseBitSet<T> {
124-
raw: RawBitSet<Vec<Word>>,
124+
raw: RawBitSet<Box<[Word]>>,
125125
marker: PhantomData<T>,
126126
}
127127

@@ -251,7 +251,7 @@ impl<T: Idx> BitRelations<DenseBitSet<T>> for DenseBitSet<T> {
251251
impl<T: Idx> From<GrowableBitSet<T>> for DenseBitSet<T> {
252252
fn from(bit_set: GrowableBitSet<T>) -> Self {
253253
let GrowableBitSet { raw, marker } = bit_set;
254-
DenseBitSet { raw, marker }
254+
DenseBitSet { raw: raw.adjust_words_storage(Vec::into_boxed_slice), marker }
255255
}
256256
}
257257

@@ -1156,7 +1156,7 @@ impl<T: Idx> GrowableBitSet<T> {
11561156
impl<T: Idx> From<DenseBitSet<T>> for GrowableBitSet<T> {
11571157
fn from(bit_set: DenseBitSet<T>) -> Self {
11581158
let DenseBitSet { raw, marker } = bit_set;
1159-
GrowableBitSet { raw, marker }
1159+
GrowableBitSet { raw: raw.adjust_words_storage(<[_]>::into_vec), marker }
11601160
}
11611161
}
11621162

compiler/rustc_index/src/bit_set/raw.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ impl<W> RawBitSet<W> {
3333
pub(crate) fn domain_size(&self) -> usize {
3434
self.domain_size
3535
}
36-
}
3736

38-
impl<W> RawBitSet<W> {
3937
pub(crate) fn new_empty_in(
4038
domain_size: usize,
4139
alloc_words: impl FnOnce(usize, Word) -> W,
@@ -45,13 +43,14 @@ impl<W> RawBitSet<W> {
4543

4644
RawBitSet { domain_size, words }
4745
}
48-
}
4946

50-
impl<W: AsMut<[Word]>> RawBitSet<W> {
5147
pub(crate) fn new_filled_in(
5248
domain_size: usize,
5349
alloc_words: impl FnOnce(usize, Word) -> W,
54-
) -> Self {
50+
) -> Self
51+
where
52+
W: AsMut<[Word]>,
53+
{
5554
let num_words = num_words(domain_size);
5655
let words = alloc_words(num_words, !0);
5756

@@ -60,19 +59,30 @@ impl<W: AsMut<[Word]>> RawBitSet<W> {
6059

6160
this
6261
}
62+
63+
pub(crate) fn adjust_words_storage<W2>(
64+
self,
65+
adjust_words: impl FnOnce(W) -> W2,
66+
) -> RawBitSet<W2> {
67+
let Self { domain_size, words } = self;
68+
RawBitSet { domain_size, words: adjust_words(words) }
69+
}
6370
}
6471

65-
impl RawBitSet<Vec<Word>> {
72+
impl<W: From<Vec<Word>>> RawBitSet<W> {
6673
/// Creates a new, empty bitset with a given `domain_size`.
6774
#[inline]
6875
pub(crate) fn new_empty(domain_size: usize) -> Self {
69-
Self::new_empty_in(domain_size, |num_words, w| vec![w; num_words])
76+
Self::new_empty_in(domain_size, |num_words, w| W::from(vec![w; num_words]))
7077
}
7178

7279
/// Creates a new, filled bitset with a given `domain_size`.
7380
#[inline]
74-
pub(crate) fn new_filled(domain_size: usize) -> Self {
75-
Self::new_filled_in(domain_size, |num_words, w| vec![w; num_words])
81+
pub(crate) fn new_filled(domain_size: usize) -> Self
82+
where
83+
W: AsMut<[Word]>,
84+
{
85+
Self::new_filled_in(domain_size, |num_words, w| W::from(vec![w; num_words]))
7686
}
7787
}
7888

0 commit comments

Comments
 (0)