From: Niko Matsakis Date: Mon, 1 May 2017 16:47:00 +0000 (-0400) Subject: remove `Pass` and (temporarily) drop `Inline` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=c253df5249b5f3c7d6f85e1ed28afbf0adc1390b;p=rust.git remove `Pass` and (temporarily) drop `Inline` --- diff --git a/src/librustc/mir/transform.rs b/src/librustc/mir/transform.rs index 69dc83f6dcc..28b34459b30 100644 --- a/src/librustc/mir/transform.rs +++ b/src/librustc/mir/transform.rs @@ -15,8 +15,6 @@ use hir::map::DefPathData; use mir::{Mir, Promoted}; use ty::TyCtxt; -use ty::maps::Multi; -use ty::steal::Steal; use std::cell::Ref; use std::rc::Rc; use syntax::ast::NodeId; @@ -135,19 +133,6 @@ fn on_mir_pass<'a, 'tcx: 'a>(&self, /// application of a pass to a def-id. pub type PassId = (MirSuite, MirPassIndex, DefId); -/// The most generic sort of MIR pass. You only want to implement this -/// rather general trait if you are doing an interprocedural pass that -/// may inspect and affect the MIR of many def-ids. Otherwise, prefer -/// the more steamlined `DefIdPass` or `MirPass`. -pub trait Pass { - fn name<'a>(&'a self) -> Cow<'a, str> { - default_name::() - } - - fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) - -> Multi>>; -} - /// A streamlined trait that you can implement to create an /// intraprocedural pass; the pass will be invoked to process the MIR /// with the given `def_id`. This lets you do things before we fetch @@ -160,17 +145,6 @@ fn name<'a>(&'a self) -> Cow<'a, str> { fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) -> Mir<'tcx>; } -impl Pass for T { - fn name<'a>(&'a self) -> Cow<'a, str> { - DefIdPass::name(self) - } - - fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) - -> Multi>> { - Multi::from(mir_cx.tcx().alloc_steal_mir(DefIdPass::run_pass(self, mir_cx))) - } -} - /// A streamlined trait that you can implement to create a pass; the /// pass will be named after the type, and it will consist of a main /// loop that goes over each available MIR and applies `run_pass`. @@ -210,7 +184,7 @@ fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) -> Mir<'tcx> { #[derive(Clone)] pub struct Passes { pass_hooks: Vec>, - suites: Vec>>, + suites: Vec>>, } /// The number of "pass suites" that we have: @@ -238,7 +212,7 @@ pub fn new() -> Passes { } /// Pushes a built-in pass. - pub fn push_pass(&mut self, suite: MirSuite, pass: T) { + pub fn push_pass(&mut self, suite: MirSuite, pass: T) { self.suites[suite.0].push(Rc::new(pass)); } @@ -251,7 +225,7 @@ pub fn len_passes(&self, suite: MirSuite) -> usize { self.suites[suite.0].len() } - pub fn pass(&self, suite: MirSuite, pass: MirPassIndex) -> &Pass { + pub fn pass(&self, suite: MirSuite, pass: MirPassIndex) -> &DefIdPass { &*self.suites[suite.0][pass.0] } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index f80d6473dcc..a08fd1f9bf6 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -928,7 +928,7 @@ macro_rules! try_with_f { passes.push_pass(MIR_OPTIMIZED, mir::transform::simplify::SimplifyCfg::new("elaborate-drops")); // No lifetime analysis based on borrowing can be done from here on out. - passes.push_pass(MIR_OPTIMIZED, mir::transform::inline::Inline); + // TODO passes.push_pass(MIR_OPTIMIZED, mir::transform::inline::Inline); passes.push_pass(MIR_OPTIMIZED, mir::transform::instcombine::InstCombine); passes.push_pass(MIR_OPTIMIZED, mir::transform::deaggregator::Deaggregator); passes.push_pass(MIR_OPTIMIZED, mir::transform::copy_prop::CopyPropagation); diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index e10a91c6ec2..2323b55951d 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -18,7 +18,7 @@ use rustc::dep_graph::DepNode; use rustc::mir::*; -use rustc::mir::transform::{MirCtxt, MirSource, Pass, PassId}; +use rustc::mir::transform::{MirCtxt, MirSource, PassId}; use rustc::mir::visit::*; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt}; @@ -45,6 +45,11 @@ pub struct Inline; +pub trait Pass { + fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) + -> Multi>>; +} + impl Pass for Inline { fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) -> Multi>> { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 81af7c23960..feef7a197c5 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -70,15 +70,11 @@ fn mir_pass<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mir = pass.run_pass(&mir_ctxt); - let key = &(suite, pass_num, def_id); for hook in passes.hooks() { - for (&(_, _, k), v) in mir.iter(key) { - let v = &v.borrow(); - hook.on_mir_pass(&mir_ctxt, Some((k, v))); - } + hook.on_mir_pass(&mir_ctxt, Some((def_id, &mir))); } - mir + Multi::from(tcx.alloc_steal_mir(mir)) } struct MirCtxtImpl<'a, 'tcx: 'a> {