Skip to content

Commit 8c0f097

Browse files
committed
Parallelize type collecting and item-types checking
1 parent 59a8294 commit 8c0f097

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,9 +1445,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
14451445

14461446
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
14471447
let module = tcx.hir_module_items(module_def_id);
1448-
for id in module.items() {
1449-
check_item_type(tcx, id);
1450-
}
1448+
module.par_items(|id| check_item_type(tcx, id));
14511449
if module_def_id == LocalModDefId::CRATE_DEF_ID {
14521450
super::entry::check_for_entry_fn(tcx);
14531451
}

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod type_of;
4949
// Main entry point
5050

5151
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
52-
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CollectItemTypesVisitor { tcx });
52+
tcx.hir().par_visit_item_likes_in_module(module_def_id, || CollectItemTypesVisitor { tcx });
5353
}
5454

5555
pub fn provide(providers: &mut Providers) {

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
192192
// FIXME(matthewjasper) We shouldn't need to use `track_errors`.
193193
tcx.sess.track_errors(|| {
194194
tcx.sess.time("type_collecting", || {
195-
tcx.hir().for_each_module(|module| tcx.ensure().collect_mod_item_types(module))
195+
// Run dependencies of type collecting before entering the loop
196+
tcx.ensure_with_value().inferred_outlives_crate(());
197+
198+
let _prof_timer = tcx.sess.timer("type_collecting_loop");
199+
tcx.hir().par_for_each_module(|module| tcx.ensure().collect_mod_item_types(module));
196200
});
197201
})?;
198202

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,34 @@ impl<'hir> Map<'hir> {
618618
}
619619
}
620620

621+
/// A parallel version of `visit_item_likes_in_module`.
622+
pub fn par_visit_item_likes_in_module<V>(
623+
&self,
624+
module: LocalModDefId,
625+
make_visitor: impl Fn() -> V + DynSync,
626+
) where
627+
V: Visitor<'hir>,
628+
{
629+
let module = self.tcx.hir_module_items(module);
630+
631+
parallel!(
632+
{
633+
module.par_items(|id| make_visitor().visit_item(self.item(id)));
634+
},
635+
{
636+
module.par_trait_items(|id| make_visitor().visit_trait_item(self.trait_item(id)));
637+
},
638+
{
639+
module.par_impl_items(|id| make_visitor().visit_impl_item(self.impl_item(id)));
640+
},
641+
{
642+
module.par_foreign_items(|id| {
643+
make_visitor().visit_foreign_item(self.foreign_item(id))
644+
});
645+
}
646+
);
647+
}
648+
621649
pub fn for_each_module(self, mut f: impl FnMut(LocalModDefId)) {
622650
let crate_items = self.tcx.hir_crate_items(());
623651
for module in crate_items.submodules.iter() {

0 commit comments

Comments
 (0)