Skip to content

Commit 20fd50d

Browse files
committed
Make impl WF inference more parallel
1 parent 1a37f05 commit 20fd50d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/librustc_typeck/impl_wf_check.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use crate::constrained_generic_params as cgp;
1212
use rustc::ty::query::Providers;
1313
use rustc::ty::{self, TyCtxt, TypeFoldable};
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
15+
use rustc_data_structures::sync::par_for_each;
1516
use rustc_errors::struct_span_err;
1617
use rustc_hir as hir;
1718
use rustc_hir::def_id::DefId;
18-
use rustc_hir::itemlikevisit::ItemLikeVisitor;
19+
use rustc_hir::itemlikevisit::ParItemLikeVisitor;
1920
use std::collections::hash_map::Entry::{Occupied, Vacant};
2021

2122
use rustc_span::Span;
@@ -56,13 +57,13 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
5657
// We will tag this as part of the WF check -- logically, it is,
5758
// but it's one that we must perform earlier than the rest of
5859
// WfCheck.
59-
for &module in tcx.hir().krate().modules.keys() {
60+
par_for_each(&tcx.hir().krate().modules, |(&module, _)| {
6061
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
61-
}
62+
});
6263
}
6364

6465
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: DefId) {
65-
tcx.hir().visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx });
66+
tcx.hir().par_visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx });
6667
}
6768

6869
pub fn provide(providers: &mut Providers<'_>) {
@@ -73,18 +74,18 @@ struct ImplWfCheck<'tcx> {
7374
tcx: TyCtxt<'tcx>,
7475
}
7576

76-
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
77-
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
77+
impl ParItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
78+
fn visit_item(&self, item: &'tcx hir::Item<'tcx>) {
7879
if let hir::ItemKind::Impl(.., ref impl_item_refs) = item.kind {
7980
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
8081
enforce_impl_params_are_constrained(self.tcx, impl_def_id, impl_item_refs);
8182
enforce_impl_items_are_distinct(self.tcx, impl_item_refs);
8283
}
8384
}
8485

85-
fn visit_trait_item(&mut self, _trait_item: &'tcx hir::TraitItem<'tcx>) {}
86+
fn visit_trait_item(&self, _trait_item: &'tcx hir::TraitItem<'tcx>) {}
8687

87-
fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem<'tcx>) {}
88+
fn visit_impl_item(&self, _impl_item: &'tcx hir::ImplItem<'tcx>) {}
8889
}
8990

9091
fn enforce_impl_params_are_constrained(

0 commit comments

Comments
 (0)