diff options
| author | bors <bors@rust-lang.org> | 2025-06-15 16:52:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-15 16:52:31 +0000 |
| commit | 586ad391f5ee4519acc7cae340e34673bae762b1 (patch) | |
| tree | acbcca417897edd86c04d3cee41fd97a50cf40b4 /compiler/rustc_hir_analysis | |
| parent | 7827d55852783e8d85932a938d70fff64e9b9f07 (diff) | |
| parent | 6f5a717a6cfe9e0bea8a67f30a1db90ccd91aee9 (diff) | |
| download | rust-586ad391f5ee4519acc7cae340e34673bae762b1.tar.gz rust-586ad391f5ee4519acc7cae340e34673bae762b1.zip | |
Auto merge of #142455 - jdonszelmann:attempt-to-mitigate-delayed-lint-perf-problems, r=oli-obk
collect delayed lints in hir_crate_items r? `@oli-obk` Attempt to mitigate perf problems in rust-lang/rust#138164
Diffstat (limited to 'compiler/rustc_hir_analysis')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 4f699462ac3..7c8c9425a03 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -193,13 +193,41 @@ pub fn check_crate(tcx: TyCtxt<'_>) { let _: R = tcx.ensure_ok().crate_inherent_impls_overlap_check(()); }); - for owner_id in tcx.hir_crate_items(()).owners() { - if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) { - for lint in &delayed_lints.lints { - emit_delayed_lint(lint, tcx); + tcx.sess.time("emit_ast_lowering_delayed_lints", || { + // sanity check in debug mode that all lints are really noticed + // and we really will emit them all in the loop right below. + // + // during ast lowering, when creating items, foreign items, trait items and impl items + // we store in them whether they have any lints in their owner node that should be + // picked up by `hir_crate_items`. However, theoretically code can run between that + // boolean being inserted into the item and the owner node being created. + // We don't want any new lints to be emitted there + // (though honestly, you have to really try to manage to do that but still), + // but this check is there to catch that. + #[cfg(debug_assertions)] + { + // iterate over all owners + for owner_id in tcx.hir_crate_items(()).owners() { + // if it has delayed lints + if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) { + if !delayed_lints.lints.is_empty() { + // assert that delayed_lint_items also picked up this item to have lints + assert!( + tcx.hir_crate_items(()).delayed_lint_items().any(|i| i == owner_id) + ); + } + } } } - } + + for owner_id in tcx.hir_crate_items(()).delayed_lint_items() { + if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) { + for lint in &delayed_lints.lints { + emit_delayed_lint(lint, tcx); + } + } + } + }); tcx.par_hir_body_owners(|item_def_id| { let def_kind = tcx.def_kind(item_def_id); |
