Skip to content

Commit

Permalink
Auto merge of #45916 - eddyb:even-mirer-0, r=nikomatsakis
Browse files Browse the repository at this point in the history
rustc_mir: hardcode pass list internally and remove premature pluggability.

Fixes #41712 by moving the MIR pass lists from `rustc_driver` to `rustc_mir`.
The application of the passes is done with the `rustc_mir::transform::run_passes` macro, which is public, as are all the passes AFAIK, and can be used to apply MIR passes outside of `rustc_mir`.

With the ability to override query providers through the `rustc_driver` (orthogonal to, and not included in this PR), custom drivers will be able to substitute the entire pass list if they want to.
**EDIT**: the aforementioned ability is added by #45944.

r? @nikomatsakis
  • Loading branch information
bors committed Nov 14, 2017
2 parents b5a3ab2 + d6aa56f commit 24840da
Show file tree
Hide file tree
Showing 40 changed files with 343 additions and 516 deletions.
22 changes: 22 additions & 0 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,28 @@ impl<'hir> Map<'hir> {
})
}

pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind {
// Handle constants in enum discriminants, types, and repeat expressions.
let def_id = self.local_def_id(id);
let def_key = self.def_key(def_id);
if def_key.disambiguated_data.data == DefPathData::Initializer {
return BodyOwnerKind::Const;
}

match self.get(id) {
NodeItem(&Item { node: ItemConst(..), .. }) |
NodeTraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
NodeImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) => {
BodyOwnerKind::Const
}
NodeItem(&Item { node: ItemStatic(_, m, _), .. }) => {
BodyOwnerKind::Static(m)
}
// Default to function if it's not a constant or static.
_ => BodyOwnerKind::Fn
}
}

pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
match self.get(id) {
NodeItem(&Item { node: ItemTrait(..), .. }) => id,
Expand Down
12 changes: 12 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ impl Body {
}
}

#[derive(Copy, Clone, Debug)]
pub enum BodyOwnerKind {
/// Functions and methods.
Fn,

/// Constants and associated constants.
Const,

/// Initializer of a `static` item.
Static(Mutability),
}

/// An expression
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Expr {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use hir;
use hir::def_id::DefId;
use hir::intravisit::{self, Visitor, NestedVisitorMap};
use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
use mir::transform::MirSource;
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
StableHasherResult};
Expand Down Expand Up @@ -1298,7 +1297,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {

// The body of the every fn is a root scope.
self.cx.parent = self.cx.var_parent;
if let MirSource::Fn(_) = MirSource::from_node(self.tcx, owner_id) {
if let hir::BodyOwnerKind::Fn = self.tcx.hir.body_owner_kind(owner_id) {
self.visit_expr(&body.value);
} else {
// Only functions have an outer terminating (drop) scope, while
Expand Down
1 change: 0 additions & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use syntax_pos::Span;
mod cache;
pub mod tcx;
pub mod visit;
pub mod transform;
pub mod traversal;

/// Types for locals
Expand Down
190 changes: 0 additions & 190 deletions src/librustc/mir/transform.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use middle::lang_items;
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
use middle::stability;
use mir::Mir;
use mir::transform::Passes;
use ty::subst::{Kind, Substs};
use ty::ReprOptions;
use traits;
Expand Down Expand Up @@ -882,8 +881,6 @@ pub struct GlobalCtxt<'tcx> {

pub maps: maps::Maps<'tcx>,

pub mir_passes: Rc<Passes>,

// Records the free variables refrenced by every closure
// expression. Do not track deps for this, just recompute it from
// scratch every time.
Expand Down Expand Up @@ -1055,7 +1052,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
cstore: &'tcx CrateStore,
local_providers: ty::maps::Providers<'tcx>,
extern_providers: ty::maps::Providers<'tcx>,
mir_passes: Rc<Passes>,
arenas: &'tcx GlobalArenas<'tcx>,
arena: &'tcx DroplessArena,
resolutions: ty::Resolutions,
Expand Down Expand Up @@ -1172,7 +1168,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
hir,
def_path_hash_to_def_id,
maps: maps::Maps::new(providers),
mir_passes,
rcache: RefCell::new(FxHashMap()),
selection_cache: traits::SelectionCache::new(),
evaluation_cache: traits::EvaluationCache::new(),
Expand Down
19 changes: 0 additions & 19 deletions src/librustc/ty/maps/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! Defines the set of legal keys that can be used in queries.
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
use mir::transform::{MirSuite, MirPassIndex};
use ty::{self, Ty, TyCtxt};
use ty::subst::Substs;
use ty::fast_reject::SimplifiedType;
Expand Down Expand Up @@ -116,24 +115,6 @@ impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) {
}
}

impl Key for (MirSuite, DefId) {
fn map_crate(&self) -> CrateNum {
self.1.map_crate()
}
fn default_span(&self, tcx: TyCtxt) -> Span {
self.1.default_span(tcx)
}
}

impl Key for (MirSuite, MirPassIndex, DefId) {
fn map_crate(&self) -> CrateNum {
self.2.map_crate()
}
fn default_span(&self, tcx: TyCtxt) -> Span {
self.2.default_span(tcx)
}
}

impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
fn map_crate(&self) -> CrateNum {
self.1.def_id().krate
Expand Down
Loading

0 comments on commit 24840da

Please sign in to comment.