Skip to content

Commit 2a57e5e

Browse files
committed
Use a bitset instead of a hash map in HIR ID validator
1 parent 8c52a83 commit 2a57e5e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler/rustc_index/src/bit_set.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,16 @@ impl<T: Idx> GrowableBitSet<T> {
15461546
let (word_index, mask) = word_index_and_mask(elem);
15471547
self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0)
15481548
}
1549+
1550+
#[inline]
1551+
pub fn iter(&self) -> BitIter<'_, T> {
1552+
self.bit_set.iter()
1553+
}
1554+
1555+
#[inline]
1556+
pub fn len(&self) -> usize {
1557+
self.bit_set.count()
1558+
}
15491559
}
15501560

15511561
impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {

compiler/rustc_passes/src/hir_id_validator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use rustc_data_structures::fx::FxHashSet;
21
use rustc_data_structures::sync::Lock;
32
use rustc_hir as hir;
43
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
54
use rustc_hir::intravisit;
65
use rustc_hir::{HirId, ItemLocalId};
6+
use rustc_index::bit_set::GrowableBitSet;
77
use rustc_middle::hir::map::Map;
88
use rustc_middle::hir::nested_filter;
99
use rustc_middle::ty::TyCtxt;
@@ -40,7 +40,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
4040
struct HirIdValidator<'a, 'hir> {
4141
hir_map: Map<'hir>,
4242
owner: Option<LocalDefId>,
43-
hir_ids_seen: FxHashSet<ItemLocalId>,
43+
hir_ids_seen: GrowableBitSet<ItemLocalId>,
4444
errors: &'a Lock<Vec<String>>,
4545
}
4646

@@ -80,7 +80,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
8080
if max != self.hir_ids_seen.len() - 1 {
8181
// Collect the missing ItemLocalIds
8282
let missing: Vec<_> = (0..=max as u32)
83-
.filter(|&i| !self.hir_ids_seen.contains(&ItemLocalId::from_u32(i)))
83+
.filter(|&i| !self.hir_ids_seen.contains(ItemLocalId::from_u32(i)))
8484
.collect();
8585

8686
// Try to map those to something more useful
@@ -106,7 +106,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
106106
missing_items,
107107
self.hir_ids_seen
108108
.iter()
109-
.map(|&local_id| HirId { owner, local_id })
109+
.map(|local_id| HirId { owner, local_id })
110110
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
111111
.collect::<Vec<_>>()
112112
)

0 commit comments

Comments
 (0)