Auto merge of #98841 - Kobzol:hir-validator-bitset, r=cjgillot
Use a bitset instead of a hash map in HIR ID validator The hashset insertion was slightly hot in incr patched runs, but it seems unnecessary to use a hashset here, as it just checks that a dense set of N integers was seen. I'm not sure if it's possible to know the amount of items beforehand to preallocate the bitset? I suppose not.
This commit is contained in:
commit
c461f7a16e
2 changed files with 32 additions and 19 deletions
|
@ -1546,6 +1546,16 @@ impl<T: Idx> GrowableBitSet<T> {
|
||||||
let (word_index, mask) = word_index_and_mask(elem);
|
let (word_index, mask) = word_index_and_mask(elem);
|
||||||
self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0)
|
self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn iter(&self) -> BitIter<'_, T> {
|
||||||
|
self.bit_set.iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.bit_set.count()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
|
impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
|
||||||
use rustc_data_structures::sync::Lock;
|
use rustc_data_structures::sync::Lock;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::intravisit;
|
use rustc_hir::intravisit;
|
||||||
use rustc_hir::{HirId, ItemLocalId};
|
use rustc_hir::{HirId, ItemLocalId};
|
||||||
|
use rustc_index::bit_set::GrowableBitSet;
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
@ -15,6 +15,8 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||||
crate::hir_stats::print_hir_stats(tcx);
|
crate::hir_stats::print_hir_stats(tcx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
let errors = Lock::new(Vec::new());
|
let errors = Lock::new(Vec::new());
|
||||||
let hir_map = tcx.hir();
|
let hir_map = tcx.hir();
|
||||||
|
|
||||||
|
@ -35,12 +37,13 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||||
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
|
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
|
||||||
tcx.sess.delay_span_bug(rustc_span::DUMMY_SP, &message);
|
tcx.sess.delay_span_bug(rustc_span::DUMMY_SP, &message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HirIdValidator<'a, 'hir> {
|
struct HirIdValidator<'a, 'hir> {
|
||||||
hir_map: Map<'hir>,
|
hir_map: Map<'hir>,
|
||||||
owner: Option<LocalDefId>,
|
owner: Option<LocalDefId>,
|
||||||
hir_ids_seen: FxHashSet<ItemLocalId>,
|
hir_ids_seen: GrowableBitSet<ItemLocalId>,
|
||||||
errors: &'a Lock<Vec<String>>,
|
errors: &'a Lock<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +83,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
|
||||||
if max != self.hir_ids_seen.len() - 1 {
|
if max != self.hir_ids_seen.len() - 1 {
|
||||||
// Collect the missing ItemLocalIds
|
// Collect the missing ItemLocalIds
|
||||||
let missing: Vec<_> = (0..=max as u32)
|
let missing: Vec<_> = (0..=max as u32)
|
||||||
.filter(|&i| !self.hir_ids_seen.contains(&ItemLocalId::from_u32(i)))
|
.filter(|&i| !self.hir_ids_seen.contains(ItemLocalId::from_u32(i)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Try to map those to something more useful
|
// Try to map those to something more useful
|
||||||
|
@ -106,7 +109,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
|
||||||
missing_items,
|
missing_items,
|
||||||
self.hir_ids_seen
|
self.hir_ids_seen
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&local_id| HirId { owner, local_id })
|
.map(|local_id| HirId { owner, local_id })
|
||||||
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
|
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue