Skip to content

Commit

Permalink
convert MIR to iterate over the bodies vector
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 28, 2017
1 parent a780fa3 commit 384f044
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Expand Up @@ -89,6 +89,7 @@ pub enum DepNode<D: Clone + Debug> {

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

BorrowCheckKrate,
Expand Down Expand Up @@ -212,6 +213,7 @@ impl<D: Clone + Debug> DepNode<D> {
match *self {
Krate => Some(Krate),
BorrowCheckKrate => Some(BorrowCheckKrate),
MirKrate => Some(MirKrate),
TypeckBodiesKrate => Some(TypeckBodiesKrate),
CollectLanguageItems => Some(CollectLanguageItems),
CheckStaticRecursion => Some(CheckStaticRecursion),
Expand Down
26 changes: 5 additions & 21 deletions src/librustc_mir/mir_map.rs
Expand Up @@ -30,7 +30,6 @@ use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::ty::subst::Substs;
use rustc::hir;
use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
use syntax::abi::Abi;
use syntax::ast;
use syntax_pos::Span;
Expand All @@ -39,9 +38,11 @@ use std::cell::RefCell;
use std::mem;

pub fn build_mir_for_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
tcx.visit_all_item_likes_in_krate(DepNode::Mir, &mut BuildMir {
tcx: tcx
}.as_deep_visitor());
tcx.dep_graph.with_task(DepNode::MirKrate, || {
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
tcx.item_mir(body_owner_def_id);
});
});
}

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

struct BuildMir<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>
}

impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::None
}

fn visit_nested_body(&mut self, body_id: hir::BodyId) {
self.tcx.item_mir(self.tcx.hir.body_owner_def_id(body_id));

let body = self.tcx.hir.body(body_id);
self.visit_body(body);
}
}

fn closure_self_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
closure_expr_id: ast::NodeId,
body_id: hir::BodyId)
Expand Down

0 comments on commit 384f044

Please sign in to comment.