Skip to content

Commit 384f044

Browse files
committed
convert MIR to iterate over the bodies vector
1 parent a780fa3 commit 384f044

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/librustc/dep_graph/dep_node.rs

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub enum DepNode<D: Clone + Debug> {
8989

9090
// Represents the MIR for a fn; also used as the task node for
9191
// things read/modify that MIR.
92+
MirKrate,
9293
Mir(D),
9394

9495
BorrowCheckKrate,
@@ -212,6 +213,7 @@ impl<D: Clone + Debug> DepNode<D> {
212213
match *self {
213214
Krate => Some(Krate),
214215
BorrowCheckKrate => Some(BorrowCheckKrate),
216+
MirKrate => Some(MirKrate),
215217
TypeckBodiesKrate => Some(TypeckBodiesKrate),
216218
CollectLanguageItems => Some(CollectLanguageItems),
217219
CheckStaticRecursion => Some(CheckStaticRecursion),

src/librustc_mir/mir_map.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc::ty::{self, Ty, TyCtxt};
3030
use rustc::ty::maps::Providers;
3131
use rustc::ty::subst::Substs;
3232
use rustc::hir;
33-
use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
3433
use syntax::abi::Abi;
3534
use syntax::ast;
3635
use syntax_pos::Span;
@@ -39,9 +38,11 @@ use std::cell::RefCell;
3938
use std::mem;
4039

4140
pub fn build_mir_for_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
42-
tcx.visit_all_item_likes_in_krate(DepNode::Mir, &mut BuildMir {
43-
tcx: tcx
44-
}.as_deep_visitor());
41+
tcx.dep_graph.with_task(DepNode::MirKrate, || {
42+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
43+
tcx.item_mir(body_owner_def_id);
44+
});
45+
});
4546
}
4647

4748
pub fn provide(providers: &mut Providers) {
@@ -180,23 +181,6 @@ impl<'a, 'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'a, 'gcx> {
180181
///////////////////////////////////////////////////////////////////////////
181182
// BuildMir -- walks a crate, looking for fn items and methods to build MIR from
182183

183-
struct BuildMir<'a, 'tcx: 'a> {
184-
tcx: TyCtxt<'a, 'tcx, 'tcx>
185-
}
186-
187-
impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
188-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
189-
NestedVisitorMap::None
190-
}
191-
192-
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
193-
self.tcx.item_mir(self.tcx.hir.body_owner_def_id(body_id));
194-
195-
let body = self.tcx.hir.body(body_id);
196-
self.visit_body(body);
197-
}
198-
}
199-
200184
fn closure_self_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
201185
closure_expr_id: ast::NodeId,
202186
body_id: hir::BodyId)

0 commit comments

Comments
 (0)