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 25, 2019
2 parents 02f5786 + d5f7181 commit 4761a82
Show file tree
Hide file tree
Showing 90 changed files with 439 additions and 436 deletions.
6 changes: 3 additions & 3 deletions src/librustc/mir/cache.rs
Original file line number Diff line number Diff line change
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
42 changes: 21 additions & 21 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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 @@ -88,7 +88,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 @@ -109,15 +109,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 @@ -169,12 +169,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 @@ -191,7 +191,7 @@ impl<'tcx> Mir<'tcx> {
local_decls.len()
);

Mir {
Body {
phase: MirPhase::Build,
basic_blocks,
source_scopes,
Expand Down Expand Up @@ -425,7 +425,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 @@ -444,7 +444,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 @@ -453,7 +453,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 @@ -601,7 +601,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 @@ -2890,23 +2890,23 @@ fn def_path_str(def_id: DefId) -> String {
ty::tls::with(|tcx| tcx.def_path_str(def_id))
}

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 @@ -2915,7 +2915,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 @@ -2924,12 +2924,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 @@ -2968,7 +2968,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 @@ -3221,7 +3221,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
Original file line number Diff line number Diff line change
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
10 changes: 5 additions & 5 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
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 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
12 changes: 6 additions & 6 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::middle::cstore::EncodedMetadata;
use crate::middle::lang_items;
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
use crate::middle::stability;
use crate::mir::{self, Mir, interpret, ProjectionKind};
use crate::mir::{self, Body, interpret, ProjectionKind};
use crate::mir::interpret::{ConstValue, Allocation};
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, Subst};
use crate::ty::ReprOptions;
Expand Down Expand Up @@ -103,8 +103,8 @@ pub struct GlobalArenas<'tcx> {
generics: TypedArena<ty::Generics>,
trait_def: TypedArena<ty::TraitDef>,
adt_def: TypedArena<ty::AdtDef>,
steal_mir: TypedArena<Steal<Mir<'tcx>>>,
mir: TypedArena<Mir<'tcx>>,
steal_mir: TypedArena<Steal<Body<'tcx>>>,
mir: TypedArena<Body<'tcx>>,
tables: TypedArena<ty::TypeckTables<'tcx>>,
/// miri allocations
const_allocs: TypedArena<interpret::Allocation>,
Expand Down Expand Up @@ -1151,11 +1151,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.global_arenas.generics.alloc(generics)
}

pub fn alloc_steal_mir(self, mir: Mir<'gcx>) -> &'gcx Steal<Mir<'gcx>> {
pub fn alloc_steal_mir(self, mir: Body<'gcx>) -> &'gcx Steal<Body<'gcx>> {
self.global_arenas.steal_mir.alloc(Steal::new(mir))
}

pub fn alloc_mir(self, mir: Mir<'gcx>) -> &'gcx Mir<'gcx> {
pub fn alloc_mir(self, mir: Body<'gcx>) -> &'gcx Body<'gcx> {
self.global_arenas.mir.alloc(mir)
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::ich::StableHashingContext;
use crate::infer::canonical::Canonical;
use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
use crate::mir::Mir;
use crate::mir::Body;
use crate::mir::interpret::{GlobalId, ErrorHandled};
use crate::mir::GeneratorLayout;
use crate::session::CrateDisambiguator;
Expand Down Expand Up @@ -3002,7 +3002,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
pub fn instance_mir(self, instance: ty::InstanceDef<'gcx>)
-> &'gcx Mir<'gcx>
-> &'gcx Body<'gcx>
{
match instance {
ty::InstanceDef::Item(did) => {
Expand Down
Loading

0 comments on commit 4761a82

Please sign in to comment.