Skip to content

Commit

Permalink
Change MirPass to also take NodeId
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Mar 7, 2016
1 parent 27d91d7 commit e30ff06
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/librustc/mir/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/erase_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/no_landing_pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/transform/remove_dead_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/transform/simplify_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
39 changes: 18 additions & 21 deletions src/librustc_mir/transform/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*) => ({
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/auxiliary/dummy_mir_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit e30ff06

Please sign in to comment.