Skip to content

Commit 24840da

Browse files
committed
Auto merge of #45916 - eddyb:even-mirer-0, r=nikomatsakis
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
2 parents b5a3ab2 + d6aa56f commit 24840da

40 files changed

+343
-516
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,28 @@ impl<'hir> Map<'hir> {
448448
})
449449
}
450450

451+
pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind {
452+
// Handle constants in enum discriminants, types, and repeat expressions.
453+
let def_id = self.local_def_id(id);
454+
let def_key = self.def_key(def_id);
455+
if def_key.disambiguated_data.data == DefPathData::Initializer {
456+
return BodyOwnerKind::Const;
457+
}
458+
459+
match self.get(id) {
460+
NodeItem(&Item { node: ItemConst(..), .. }) |
461+
NodeTraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
462+
NodeImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) => {
463+
BodyOwnerKind::Const
464+
}
465+
NodeItem(&Item { node: ItemStatic(_, m, _), .. }) => {
466+
BodyOwnerKind::Static(m)
467+
}
468+
// Default to function if it's not a constant or static.
469+
_ => BodyOwnerKind::Fn
470+
}
471+
}
472+
451473
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
452474
match self.get(id) {
453475
NodeItem(&Item { node: ItemTrait(..), .. }) => id,

src/librustc/hir/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,18 @@ impl Body {
10281028
}
10291029
}
10301030

1031+
#[derive(Copy, Clone, Debug)]
1032+
pub enum BodyOwnerKind {
1033+
/// Functions and methods.
1034+
Fn,
1035+
1036+
/// Constants and associated constants.
1037+
Const,
1038+
1039+
/// Initializer of a `static` item.
1040+
Static(Mutability),
1041+
}
1042+
10311043
/// An expression
10321044
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
10331045
pub struct Expr {

src/librustc/middle/region.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use hir;
3131
use hir::def_id::DefId;
3232
use hir::intravisit::{self, Visitor, NestedVisitorMap};
3333
use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
34-
use mir::transform::MirSource;
3534
use rustc_data_structures::indexed_vec::Idx;
3635
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
3736
StableHasherResult};
@@ -1298,7 +1297,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
12981297

12991298
// The body of the every fn is a root scope.
13001299
self.cx.parent = self.cx.var_parent;
1301-
if let MirSource::Fn(_) = MirSource::from_node(self.tcx, owner_id) {
1300+
if let hir::BodyOwnerKind::Fn = self.tcx.hir.body_owner_kind(owner_id) {
13021301
self.visit_expr(&body.value);
13031302
} else {
13041303
// Only functions have an outer terminating (drop) scope, while

src/librustc/mir/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use syntax_pos::Span;
4141
mod cache;
4242
pub mod tcx;
4343
pub mod visit;
44-
pub mod transform;
4544
pub mod traversal;
4645

4746
/// Types for locals

src/librustc/mir/transform.rs

Lines changed: 0 additions & 190 deletions
This file was deleted.

src/librustc/ty/context.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use middle::lang_items;
3131
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
3232
use middle::stability;
3333
use mir::Mir;
34-
use mir::transform::Passes;
3534
use ty::subst::{Kind, Substs};
3635
use ty::ReprOptions;
3736
use traits;
@@ -882,8 +881,6 @@ pub struct GlobalCtxt<'tcx> {
882881

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

885-
pub mir_passes: Rc<Passes>,
886-
887884
// Records the free variables refrenced by every closure
888885
// expression. Do not track deps for this, just recompute it from
889886
// scratch every time.
@@ -1055,7 +1052,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10551052
cstore: &'tcx CrateStore,
10561053
local_providers: ty::maps::Providers<'tcx>,
10571054
extern_providers: ty::maps::Providers<'tcx>,
1058-
mir_passes: Rc<Passes>,
10591055
arenas: &'tcx GlobalArenas<'tcx>,
10601056
arena: &'tcx DroplessArena,
10611057
resolutions: ty::Resolutions,
@@ -1172,7 +1168,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11721168
hir,
11731169
def_path_hash_to_def_id,
11741170
maps: maps::Maps::new(providers),
1175-
mir_passes,
11761171
rcache: RefCell::new(FxHashMap()),
11771172
selection_cache: traits::SelectionCache::new(),
11781173
evaluation_cache: traits::EvaluationCache::new(),

src/librustc/ty/maps/keys.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! Defines the set of legal keys that can be used in queries.
1212
1313
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
14-
use mir::transform::{MirSuite, MirPassIndex};
1514
use ty::{self, Ty, TyCtxt};
1615
use ty::subst::Substs;
1716
use ty::fast_reject::SimplifiedType;
@@ -116,24 +115,6 @@ impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) {
116115
}
117116
}
118117

119-
impl Key for (MirSuite, DefId) {
120-
fn map_crate(&self) -> CrateNum {
121-
self.1.map_crate()
122-
}
123-
fn default_span(&self, tcx: TyCtxt) -> Span {
124-
self.1.default_span(tcx)
125-
}
126-
}
127-
128-
impl Key for (MirSuite, MirPassIndex, DefId) {
129-
fn map_crate(&self) -> CrateNum {
130-
self.2.map_crate()
131-
}
132-
fn default_span(&self, tcx: TyCtxt) -> Span {
133-
self.2.default_span(tcx)
134-
}
135-
}
136-
137118
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
138119
fn map_crate(&self) -> CrateNum {
139120
self.1.def_id().krate

0 commit comments

Comments
 (0)