Skip to content

Commit a780fa3

Browse files
committed
rewrite typeck bodies to iterate over the bodies vector
1 parent fab202c commit a780fa3

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

src/librustc/dep_graph/dep_node.rs

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub enum DepNode<D: Clone + Debug> {
115115
SizedConstraint(D),
116116
AssociatedItemDefIds(D),
117117
InherentImpls(D),
118+
TypeckBodiesKrate,
118119
TypeckTables(D),
119120
UsedTraitImports(D),
120121
MonomorphicConstEval(D),
@@ -211,6 +212,7 @@ impl<D: Clone + Debug> DepNode<D> {
211212
match *self {
212213
Krate => Some(Krate),
213214
BorrowCheckKrate => Some(BorrowCheckKrate),
215+
TypeckBodiesKrate => Some(TypeckBodiesKrate),
214216
CollectLanguageItems => Some(CollectLanguageItems),
215217
CheckStaticRecursion => Some(CheckStaticRecursion),
216218
ResolveLifetimes => Some(ResolveLifetimes),

src/librustc_typeck/check/mod.rs

+5-41
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ use syntax::util::lev_distance::find_best_match_for_name;
118118
use syntax_pos::{self, BytePos, Span, DUMMY_SP};
119119

120120
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
121-
use rustc::hir::itemlikevisit::ItemLikeVisitor;
122121
use rustc::hir::{self, PatKind};
123122
use rustc::middle::lang_items;
124123
use rustc_back::slice;
@@ -515,7 +514,6 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
515514
}
516515

517516
struct CheckItemTypesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
518-
struct CheckItemBodiesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
519517

520518
impl<'a, 'tcx> Visitor<'tcx> for CheckItemTypesVisitor<'a, 'tcx> {
521519
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
@@ -550,43 +548,6 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckItemTypesVisitor<'a, 'tcx> {
550548
}
551549
}
552550

553-
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CheckItemBodiesVisitor<'a, 'tcx> {
554-
fn visit_item(&mut self, item: &'tcx hir::Item) {
555-
match item.node {
556-
hir::ItemFn(..) => {
557-
self.tcx.item_tables(self.tcx.hir.local_def_id(item.id));
558-
}
559-
_ => { }
560-
}
561-
}
562-
563-
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
564-
match trait_item.node {
565-
hir::TraitItemKind::Const(_, Some(_)) |
566-
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => {
567-
self.tcx.item_tables(self.tcx.hir.local_def_id(trait_item.id));
568-
}
569-
hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) |
570-
hir::TraitItemKind::Const(_, None) |
571-
hir::TraitItemKind::Type(..) => {
572-
// Nothing to do.
573-
}
574-
}
575-
}
576-
577-
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
578-
match impl_item.node {
579-
hir::ImplItemKind::Const(..) |
580-
hir::ImplItemKind::Method(..) => {
581-
self.tcx.item_tables(self.tcx.hir.local_def_id(impl_item.id));
582-
}
583-
hir::ImplItemKind::Type(_) => {
584-
// Nothing to do here.
585-
}
586-
}
587-
}
588-
}
589-
590551
pub fn check_wf_new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult {
591552
tcx.sess.track_errors(|| {
592553
let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
@@ -604,8 +565,11 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult
604565

605566
pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult {
606567
tcx.sess.track_errors(|| {
607-
let mut visit = CheckItemBodiesVisitor { tcx: tcx };
608-
tcx.visit_all_item_likes_in_krate(DepNode::TypeckTables, &mut visit);
568+
tcx.dep_graph.with_task(DepNode::TypeckBodiesKrate, || {
569+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
570+
tcx.item_tables(body_owner_def_id);
571+
});
572+
});
609573
})
610574
}
611575

0 commit comments

Comments
 (0)