Skip to content

Commit

Permalink
Add proper cfgs for struct HirIdValidator used only with debug assert…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
mu001999 committed Mar 6, 2024
1 parent 2064c19 commit f415379
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ pub fn create_global_ctxt<'tcx>(
/// Runs the type-checking, region checking and other miscellaneous analysis
/// passes on the crate.
fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
if tcx.sess.opts.unstable_opts.hir_stats {
rustc_passes::hir_stats::print_hir_stats(tcx);
}

#[cfg(debug_assertions)]
rustc_passes::hir_id_validator::check_crate(tcx);

let sess = tcx.sess;
Expand Down
36 changes: 12 additions & 24 deletions compiler/rustc_passes/src/hir_id_validator.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
use rustc_data_structures::sync::Lock;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit;
use rustc_hir::{HirId, ItemLocalId};
use rustc_hir::{intravisit, HirId, ItemLocalId};
use rustc_index::bit_set::GrowableBitSet;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;

pub fn check_crate(tcx: TyCtxt<'_>) {
if tcx.sess.opts.unstable_opts.hir_stats {
crate::hir_stats::print_hir_stats(tcx);
}

#[cfg(debug_assertions)]
{
let errors = Lock::new(Vec::new());
let errors = Lock::new(Vec::new());

tcx.hir().par_for_each_module(|module_id| {
let mut v = HirIdValidator {
tcx,
owner: None,
hir_ids_seen: Default::default(),
errors: &errors,
};
tcx.hir().par_for_each_module(|module_id| {
let mut v =
HirIdValidator { tcx, owner: None, hir_ids_seen: Default::default(), errors: &errors };

tcx.hir().visit_item_likes_in_module(module_id, &mut v);
});
tcx.hir().visit_item_likes_in_module(module_id, &mut v);
});

let errors = errors.into_inner();
let errors = errors.into_inner();

if !errors.is_empty() {
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
tcx.dcx().delayed_bug(message);
}
if !errors.is_empty() {
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
tcx.dcx().delayed_bug(message);
}
}

Expand Down Expand Up @@ -90,7 +78,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
self.error(|| {
format!(
"ItemLocalIds not assigned densely in {pretty_owner}. \
Max ItemLocalId = {max}, missing IDs = {missing_items:#?}; seen IDs = {seen_items:#?}"
Max ItemLocalId = {max}, missing IDs = {missing_items:#?}; seen IDs = {seen_items:#?}"
)
});
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod debugger_visualizer;
mod diagnostic_items;
pub mod entry;
mod errors;
#[cfg(debug_assertions)]
pub mod hir_id_validator;
pub mod hir_stats;
mod lang_items;
Expand Down

0 comments on commit f415379

Please sign in to comment.