Skip to content

rustc_mir: hardcode pass list internally and remove premature pluggability. #45916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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