Skip to content

Commit

Permalink
Rollup merge of rust-lang#60928 - TheSirC:fix/60229, r=eddyb
Browse files Browse the repository at this point in the history
Changes the type `mir::Mir` into `mir::Body`

Fixes part 1 of rust-lang#60229 (previously attempted in rust-lang#60242).

I stumbled upon the issue and it seems that the previous attempt at solving it was not merged. This is a second try more up-to-date.

The commit should have changed comments as well.
At the time of writting, it passes the tidy and check tool.
  • Loading branch information
Centril committed May 28, 2019
2 parents e19a229 + 95013e6 commit ee08261
Show file tree
Hide file tree
Showing 93 changed files with 458 additions and 447 deletions.
6 changes: 3 additions & 3 deletions src/librustc/mir/cache.rs
Expand Up @@ -3,7 +3,7 @@ use rustc_data_structures::sync::{RwLock, MappedReadGuard, ReadGuard};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
StableHasherResult};
use crate::ich::StableHashingContext;
use crate::mir::{Mir, BasicBlock};
use crate::mir::{Body, BasicBlock};

use crate::rustc_serialize as serialize;

Expand Down Expand Up @@ -47,7 +47,7 @@ impl Cache {

pub fn predecessors(
&self,
mir: &Mir<'_>
mir: &Body<'_>
) -> MappedReadGuard<'_, IndexVec<BasicBlock, Vec<BasicBlock>>> {
if self.predecessors.borrow().is_none() {
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
Expand All @@ -57,7 +57,7 @@ impl Cache {
}
}

fn calculate_predecessors(mir: &Mir<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
fn calculate_predecessors(mir: &Body<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
for (bb, data) in mir.basic_blocks().iter_enumerated() {
if let Some(ref term) = data.terminator {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/mod.rs
Expand Up @@ -47,7 +47,7 @@ pub struct GlobalId<'tcx> {
/// For a promoted global, the `Instance` of the function they belong to.
pub instance: ty::Instance<'tcx>,

/// The index for promoted globals within their function's `Mir`.
/// The index for promoted globals within their function's `mir::Body`.
pub promoted: Option<mir::Promoted>,
}

Expand Down
42 changes: 21 additions & 21 deletions src/librustc/mir/mod.rs
Expand Up @@ -60,7 +60,7 @@ impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> {
}
}

impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> {
impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
fn local_decls(&self) -> &LocalDecls<'tcx> {
&self.local_decls
}
Expand All @@ -86,7 +86,7 @@ impl MirPhase {

/// Lowered representation of a single function.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mir<'tcx> {
pub struct Body<'tcx> {
/// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
/// that indexes into this vector.
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
Expand All @@ -107,15 +107,15 @@ pub struct Mir<'tcx> {
pub source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,

/// Rvalues promoted from this function, such as borrows of constants.
/// Each of them is the Mir of a constant with the fn's type parameters
/// Each of them is the Body of a constant with the fn's type parameters
/// in scope, but a separate set of locals.
pub promoted: IndexVec<Promoted, Mir<'tcx>>,
pub promoted: IndexVec<Promoted, Body<'tcx>>,

/// Yields type of the function, if it is a generator.
pub yield_ty: Option<Ty<'tcx>>,

/// Generator drop glue
pub generator_drop: Option<Box<Mir<'tcx>>>,
pub generator_drop: Option<Box<Body<'tcx>>>,

/// The layout of a generator. Produced by the state transformation.
pub generator_layout: Option<GeneratorLayout<'tcx>>,
Expand Down Expand Up @@ -167,12 +167,12 @@ pub struct Mir<'tcx> {
cache: cache::Cache,
}

impl<'tcx> Mir<'tcx> {
impl<'tcx> Body<'tcx> {
pub fn new(
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
source_scopes: IndexVec<SourceScope, SourceScopeData>,
source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
promoted: IndexVec<Promoted, Mir<'tcx>>,
promoted: IndexVec<Promoted, Body<'tcx>>,
yield_ty: Option<Ty<'tcx>>,
local_decls: LocalDecls<'tcx>,
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
Expand All @@ -189,7 +189,7 @@ impl<'tcx> Mir<'tcx> {
local_decls.len()
);

Mir {
Body {
phase: MirPhase::Build,
basic_blocks,
source_scopes,
Expand Down Expand Up @@ -423,7 +423,7 @@ pub enum Safety {
ExplicitUnsafe(hir::HirId),
}

impl_stable_hash_for!(struct Mir<'tcx> {
impl_stable_hash_for!(struct Body<'tcx> {
phase,
basic_blocks,
source_scopes,
Expand All @@ -442,7 +442,7 @@ impl_stable_hash_for!(struct Mir<'tcx> {
cache
});

impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
impl<'tcx> Index<BasicBlock> for Body<'tcx> {
type Output = BasicBlockData<'tcx>;

#[inline]
Expand All @@ -451,7 +451,7 @@ impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
}
}

impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
impl<'tcx> IndexMut<BasicBlock> for Body<'tcx> {
#[inline]
fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {
&mut self.basic_blocks_mut()[index]
Expand Down Expand Up @@ -599,7 +599,7 @@ newtype_index! {
}
}

/// Classifies locals into categories. See `Mir::local_kind`.
/// Classifies locals into categories. See `Body::local_kind`.
#[derive(PartialEq, Eq, Debug, HashStable)]
pub enum LocalKind {
/// User-declared variable binding
Expand Down Expand Up @@ -2828,23 +2828,23 @@ impl<'tcx> Display for Constant<'tcx> {
}
}

impl<'tcx> graph::DirectedGraph for Mir<'tcx> {
impl<'tcx> graph::DirectedGraph for Body<'tcx> {
type Node = BasicBlock;
}

impl<'tcx> graph::WithNumNodes for Mir<'tcx> {
impl<'tcx> graph::WithNumNodes for Body<'tcx> {
fn num_nodes(&self) -> usize {
self.basic_blocks.len()
}
}

impl<'tcx> graph::WithStartNode for Mir<'tcx> {
impl<'tcx> graph::WithStartNode for Body<'tcx> {
fn start_node(&self) -> Self::Node {
START_BLOCK
}
}

impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
impl<'tcx> graph::WithPredecessors for Body<'tcx> {
fn predecessors<'graph>(
&'graph self,
node: Self::Node,
Expand All @@ -2853,7 +2853,7 @@ impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
}
}

impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
impl<'tcx> graph::WithSuccessors for Body<'tcx> {
fn successors<'graph>(
&'graph self,
node: Self::Node,
Expand All @@ -2862,12 +2862,12 @@ impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
}
}

impl<'a, 'b> graph::GraphPredecessors<'b> for Mir<'a> {
impl<'a, 'b> graph::GraphPredecessors<'b> for Body<'a> {
type Item = BasicBlock;
type Iter = IntoIter<BasicBlock>;
}

impl<'a, 'b> graph::GraphSuccessors<'b> for Mir<'a> {
impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
type Item = BasicBlock;
type Iter = iter::Cloned<Successors<'b>>;
}
Expand Down Expand Up @@ -2906,7 +2906,7 @@ impl Location {
}

/// Returns `true` if `other` is earlier in the control flow graph than `self`.
pub fn is_predecessor_of<'tcx>(&self, other: Location, mir: &Mir<'tcx>) -> bool {
pub fn is_predecessor_of<'tcx>(&self, other: Location, mir: &Body<'tcx>) -> bool {
// If we are in the same block as the other location and are an earlier statement
// then we are a predecessor of `other`.
if self.block == other.block && self.statement_index < other.statement_index {
Expand Down Expand Up @@ -3159,7 +3159,7 @@ CloneTypeFoldableAndLiftImpls! {
}

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
impl<'tcx> TypeFoldable<'tcx> for Body<'tcx> {
phase,
basic_blocks,
source_scopes,
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/mir/traversal.rs
Expand Up @@ -21,14 +21,14 @@ use super::*;
/// A preorder traversal of this graph is either `A B D C` or `A C D B`
#[derive(Clone)]
pub struct Preorder<'a, 'tcx: 'a> {
mir: &'a Mir<'tcx>,
mir: &'a Body<'tcx>,
visited: BitSet<BasicBlock>,
worklist: Vec<BasicBlock>,
root_is_start_block: bool,
}

impl<'a, 'tcx> Preorder<'a, 'tcx> {
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
let worklist = vec![root];

Preorder {
Expand All @@ -40,7 +40,7 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> {
}
}

pub fn preorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> Preorder<'a, 'tcx> {
pub fn preorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> Preorder<'a, 'tcx> {
Preorder::new(mir, START_BLOCK)
}

Expand Down Expand Up @@ -99,14 +99,14 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
///
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
pub struct Postorder<'a, 'tcx: 'a> {
mir: &'a Mir<'tcx>,
mir: &'a Body<'tcx>,
visited: BitSet<BasicBlock>,
visit_stack: Vec<(BasicBlock, Successors<'a>)>,
root_is_start_block: bool,
}

impl<'a, 'tcx> Postorder<'a, 'tcx> {
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
let mut po = Postorder {
mir,
visited: BitSet::new_empty(mir.basic_blocks().len()),
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
}
}

pub fn postorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> Postorder<'a, 'tcx> {
pub fn postorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> Postorder<'a, 'tcx> {
Postorder::new(mir, START_BLOCK)
}

Expand Down Expand Up @@ -252,13 +252,13 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
/// to re-use the traversal
#[derive(Clone)]
pub struct ReversePostorder<'a, 'tcx: 'a> {
mir: &'a Mir<'tcx>,
mir: &'a Body<'tcx>,
blocks: Vec<BasicBlock>,
idx: usize
}

impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> {
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> {
let blocks : Vec<_> = Postorder::new(mir, root).map(|(bb, _)| bb).collect();

let len = blocks.len();
Expand All @@ -276,7 +276,7 @@ impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
}


pub fn reverse_postorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> ReversePostorder<'a, 'tcx> {
pub fn reverse_postorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> ReversePostorder<'a, 'tcx> {
ReversePostorder::new(mir, START_BLOCK)
}

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/mir/visit.rs
Expand Up @@ -71,8 +71,8 @@ macro_rules! make_mir_visitor {
// Override these, and call `self.super_xxx` to revert back to the
// default behavior.

fn visit_mir(&mut self, mir: & $($mutability)? Mir<'tcx>) {
self.super_mir(mir);
fn visit_body(&mut self, mir: & $($mutability)? Body<'tcx>) {
self.super_body(mir);
}

fn visit_basic_block_data(&mut self,
Expand Down Expand Up @@ -251,8 +251,8 @@ macro_rules! make_mir_visitor {
// The `super_xxx` methods comprise the default behavior and are
// not meant to be overridden.

fn super_mir(&mut self,
mir: & $($mutability)? Mir<'tcx>) {
fn super_body(&mut self,
mir: & $($mutability)? Body<'tcx>) {
if let Some(yield_ty) = &$($mutability)? mir.yield_ty {
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
span: mir.span,
Expand All @@ -261,7 +261,7 @@ macro_rules! make_mir_visitor {
}

// for best performance, we want to use an iterator rather
// than a for-loop, to avoid calling Mir::invalidate for
// than a for-loop, to avoid calling `mir::Body::invalidate` for
// each basic block.
macro_rules! basic_blocks {
(mut) => (mir.basic_blocks_mut().iter_enumerated_mut());
Expand Down Expand Up @@ -825,7 +825,7 @@ macro_rules! make_mir_visitor {

// Convenience methods

fn visit_location(&mut self, mir: & $($mutability)? Mir<'tcx>, location: Location) {
fn visit_location(&mut self, mir: & $($mutability)? Body<'tcx>, location: Location) {
let basic_block = & $($mutability)? mir[location.block];
if basic_block.statements.len() == location.statement_index {
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/query/mod.rs
Expand Up @@ -88,7 +88,7 @@ rustc_queries! {
desc { "getting a list of all mir_keys" }
}

/// Maps DefId's that have an associated Mir to the result
/// Maps DefId's that have an associated `mir::Body` to the result
/// of the MIR qualify_consts pass. The actual meaning of
/// the value isn't known except to the pass itself.
query mir_const_qualif(key: DefId) -> (u8, &'tcx BitSet<mir::Local>) {
Expand All @@ -97,26 +97,26 @@ rustc_queries! {

/// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code.
query mir_built(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {}
query mir_built(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {}

/// Fetch the MIR for a given `DefId` up till the point where it is
/// ready for const evaluation.
///
/// See the README for the `mir` module for details.
query mir_const(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
query mir_const(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
no_hash
}

query mir_validated(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
query mir_validated(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
no_hash
}

/// MIR after our optimization passes have run. This is MIR that is ready
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
query optimized_mir(key: DefId) -> &'tcx mir::Mir<'tcx> {
query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
cache { key.is_local() }
load_cached(tcx, id) {
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
let mir: Option<crate::mir::Body<'tcx>> = tcx.queries.on_disk_cache
.try_load_query_result(tcx, id);
mir.map(|x| tcx.alloc_mir(x))
}
Expand Down Expand Up @@ -456,7 +456,7 @@ rustc_queries! {
/// in the case of closures, this will be redirected to the enclosing function.
query region_scope_tree(_: DefId) -> &'tcx region::ScopeTree {}

query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx> {
query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Body<'tcx> {
no_force
desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
}
Expand Down

0 comments on commit ee08261

Please sign in to comment.