diff --git a/src/librustc/mir/transform.rs b/src/librustc/mir/transform.rs index d15ef724d59f..afcb5b956319 100644 --- a/src/librustc/mir/transform.rs +++ b/src/librustc/mir/transform.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use dep_graph::DepNode; use mir::mir_map::MirMap; use mir::repr::Mir; use middle::ty::TyCtxt; +use syntax::ast::NodeId; /// Various information about pass. pub trait Pass { @@ -26,13 +26,13 @@ pub trait MirMapPass<'tcx>: Pass { /// A pass which inspects Mir of functions in isolation. pub trait MirPass<'tcx>: Pass { - fn run_pass(&mut self, cx: &TyCtxt<'tcx>, mir: &mut Mir<'tcx>); + fn run_pass(&mut self, cx: &TyCtxt<'tcx>, id: NodeId, mir: &mut Mir<'tcx>); } impl<'tcx, T: MirPass<'tcx>> MirMapPass<'tcx> for T { fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, map: &mut MirMap<'tcx>) { - for (_, mir) in &mut map.map { - MirPass::run_pass(self, tcx, mir); + for (&id, mir) in &mut map.map { + MirPass::run_pass(self, tcx, id, mir); } } } diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 2bab0168c523..1920bd552ec3 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -16,6 +16,7 @@ use rustc::middle::ty::{self, TyCtxt}; use rustc::mir::repr::*; use rustc::mir::visit::MutVisitor; use rustc::mir::transform::{MirPass, Pass}; +use syntax::ast::NodeId; struct EraseRegionsVisitor<'a, 'tcx: 'a> { tcx: &'a TyCtxt<'tcx>, @@ -123,7 +124,7 @@ pub struct EraseRegions; impl Pass for EraseRegions {} impl<'tcx> MirPass<'tcx> for EraseRegions { - fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, mir: &mut Mir<'tcx>) { + fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) { EraseRegionsVisitor::new(tcx).visit_mir(mir); } } diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index c08f45a8ec4e..9caee36e44a7 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -15,6 +15,7 @@ use rustc::middle::ty::TyCtxt; use rustc::mir::repr::*; use rustc::mir::visit::MutVisitor; use rustc::mir::transform::{Pass, MirPass}; +use syntax::ast::NodeId; pub struct NoLandingPads; @@ -41,7 +42,7 @@ impl<'tcx> MutVisitor<'tcx> for NoLandingPads { } impl<'tcx> MirPass<'tcx> for NoLandingPads { - fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, mir: &mut Mir<'tcx>) { + fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) { if tcx.sess.no_landing_pads() { self.visit_mir(mir); } diff --git a/src/librustc_mir/transform/remove_dead_blocks.rs b/src/librustc_mir/transform/remove_dead_blocks.rs index 308e257c20d0..4513aeef86d9 100644 --- a/src/librustc_mir/transform/remove_dead_blocks.rs +++ b/src/librustc_mir/transform/remove_dead_blocks.rs @@ -36,11 +36,12 @@ use rustc_data_structures::bitvec::BitVector; use rustc::middle::ty::TyCtxt; use rustc::mir::repr::*; use rustc::mir::transform::{Pass, MirPass}; +use syntax::ast::NodeId; pub struct RemoveDeadBlocks; impl<'tcx> MirPass<'tcx> for RemoveDeadBlocks { - fn run_pass(&mut self, _: &TyCtxt<'tcx>, mir: &mut Mir<'tcx>) { + fn run_pass(&mut self, _: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) { let mut seen = BitVector::new(mir.basic_blocks.len()); // These blocks are always required. seen.insert(START_BLOCK.index()); diff --git a/src/librustc_mir/transform/simplify_cfg.rs b/src/librustc_mir/transform/simplify_cfg.rs index 85f36df7ced8..84410bdc57c0 100644 --- a/src/librustc_mir/transform/simplify_cfg.rs +++ b/src/librustc_mir/transform/simplify_cfg.rs @@ -12,6 +12,7 @@ use rustc::middle::const_eval::ConstVal; use rustc::middle::ty::TyCtxt; use rustc::mir::repr::*; use rustc::mir::transform::{MirPass, Pass}; +use syntax::ast::NodeId; use super::remove_dead_blocks::RemoveDeadBlocks; @@ -101,12 +102,12 @@ impl SimplifyCfg { } impl<'tcx> MirPass<'tcx> for SimplifyCfg { - fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, mir: &mut Mir<'tcx>) { + fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, id: NodeId, mir: &mut Mir<'tcx>) { let mut changed = true; while changed { changed = self.simplify_branches(mir); changed |= self.remove_goto_chains(mir); - RemoveDeadBlocks.run_pass(tcx, mir); + RemoveDeadBlocks.run_pass(tcx, id, mir); } // FIXME: Should probably be moved into some kind of pass manager mir.basic_blocks.shrink_to_fit(); diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 0d942f35654a..9924a4f1ad93 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -14,16 +14,15 @@ use rustc::dep_graph::DepNode; use rustc::middle::infer::{self, InferCtxt}; use rustc::middle::traits; -use rustc::middle::ty::{self, Ty, TyCtxt}; use rustc::middle::ty::fold::TypeFoldable; +use rustc::middle::ty::{self, Ty, TyCtxt}; use rustc::mir::repr::*; -use rustc::mir::mir_map::MirMap; use rustc::mir::tcx::LvalueTy; -use rustc::mir::transform::{MirMapPass, Pass}; +use rustc::mir::transform::{MirPass, Pass}; use rustc::mir::visit::{self, Visitor}; - -use syntax::codemap::{Span, DUMMY_SP}; use std::fmt; +use syntax::ast::NodeId; +use syntax::codemap::{Span, DUMMY_SP}; macro_rules! span_mirbug { ($context:expr, $elem:expr, $($message:tt)*) => ({ @@ -574,29 +573,27 @@ impl TypeckMir { } } -impl<'tcx> MirMapPass<'tcx> for TypeckMir { - fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, map: &mut MirMap<'tcx>) { +impl<'tcx> MirPass<'tcx> for TypeckMir { + fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, id: NodeId, mir: &mut Mir<'tcx>) { if tcx.sess.err_count() > 0 { // compiling a broken program can obviously result in a // broken MIR, so try not to report duplicate errors. return; } - for (&id, mir) in &mut map.map { - let _task = tcx.dep_graph.in_task(DepNode::MirTypeck(id)); - let param_env = ty::ParameterEnvironment::for_item(tcx, id); - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env)); - let mut checker = TypeChecker::new(&infcx); - { - let mut verifier = TypeVerifier::new(&mut checker, mir); - verifier.visit_mir(mir); - if verifier.errors_reported { - // don't do further checks to avoid ICEs - continue; - } + let _task = tcx.dep_graph.in_task(DepNode::MirTypeck(id)); + let param_env = ty::ParameterEnvironment::for_item(tcx, id); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env)); + let mut checker = TypeChecker::new(&infcx); + { + let mut verifier = TypeVerifier::new(&mut checker, mir); + verifier.visit_mir(mir); + if verifier.errors_reported { + // don't do further checks to avoid ICEs + return; } - checker.typeck_mir(mir); - checker.verify_obligations(mir); } + checker.typeck_mir(mir); + checker.verify_obligations(mir); } } diff --git a/src/test/auxiliary/dummy_mir_pass.rs b/src/test/auxiliary/dummy_mir_pass.rs index aec5165f6cfd..89101fe709d9 100644 --- a/src/test/auxiliary/dummy_mir_pass.rs +++ b/src/test/auxiliary/dummy_mir_pass.rs @@ -25,11 +25,13 @@ use rustc::middle::ty; use rustc::middle::const_eval::ConstVal; use rustc_plugin::Registry; +use syntax::ast::NodeId; + struct Pass; impl transform::Pass for Pass {} impl<'tcx> MirPass<'tcx> for Pass { - fn run_pass(&mut self, _: &ty::ctxt<'tcx>, mir: &mut Mir<'tcx>) { + fn run_pass(&mut self, _: &ty::TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) { Visitor.visit_mir(mir) } }