Skip to content

Commit 6523c67

Browse files
committed
Parallelize type collecting and item-types checking
1 parent 959b2c7 commit 6523c67

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
@@ -1447,9 +1447,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
14471447

14481448
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
14491449
let module = tcx.hir_module_items(module_def_id);
1450-
for id in module.items() {
1451-
check_item_type(tcx, id);
1452-
}
1450+
module.par_items(|id| check_item_type(tcx, id));
14531451
if module_def_id == LocalModDefId::CRATE_DEF_ID {
14541452
super::entry::check_for_entry_fn(tcx);
14551453
}

compiler/rustc_hir_analysis/src/collect.rs

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

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

5656
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
@@ -168,7 +168,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
168168
// FIXME(matthewjasper) We shouldn't need to use `track_errors`.
169169
tcx.sess.track_errors(|| {
170170
tcx.sess.time("type_collecting", || {
171-
tcx.hir().for_each_module(|module| tcx.ensure().collect_mod_item_types(module))
171+
// Run dependencies of type collecting before entering the loop
172+
tcx.ensure_with_value().inferred_outlives_crate(());
173+
174+
let _prof_timer = tcx.sess.timer("type_collecting_loop");
175+
tcx.hir().par_for_each_module(|module| tcx.ensure().collect_mod_item_types(module));
172176
});
173177
})?;
174178

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

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

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

0 commit comments

Comments
 (0)