Skip to content
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

Renames mir::Mir to mir::Body #60242

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SuppressRegionErrors {

// If we're on MIR or Compare mode, don't report AST region errors as they should
// be reported by NLL
BorrowckMode::Compare | BorrowckMode::Mir => SuppressRegionErrors { suppressed: true },
BorrowckMode::Compare | BorrowckMode::Body => SuppressRegionErrors { suppressed: true },
}
}
}
Expand Down
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>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli We might need a separate issue for replacing mir used in the names of mir::Bodys (I don't think we can do too, in this PR, it would bitrot much faster then).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, we can just keep the issue open and make it track multiple points

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
Original file line number Diff line number Diff line change
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 `Body`.
marimeireles marked this conversation as resolved.
Show resolved Hide resolved
pub promoted: Option<mir::Promoted>,
}

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 @@ -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.
marimeireles marked this conversation as resolved.
Show resolved Hide resolved
#[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 @@ -2853,23 +2853,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 @@ -2878,7 +2878,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 @@ -2887,12 +2887,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 @@ -2931,7 +2931,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 @@ -3165,7 +3165,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
8 changes: 4 additions & 4 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ 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>) {
fn visit_mir(&mut self, mir: & $($mutability)? Body<'tcx>) {
self.super_mir(mir);
}

Expand Down Expand Up @@ -269,7 +269,7 @@ macro_rules! make_mir_visitor {
// not meant to be overridden.

fn super_mir(&mut self,
mir: & $($mutability)? Mir<'tcx>) {
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 @@ -278,7 +278,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 Body::invalidate for
// each basic block.
macro_rules! basic_blocks {
(mut) => (mir.basic_blocks_mut().iter_enumerated_mut());
Expand Down Expand Up @@ -886,7 +886,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
Original file line number Diff line number Diff line change
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 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, Lrc<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 @@ -458,7 +458,7 @@ rustc_queries! {
/// in the case of closures, this will be redirected to the enclosing function.
query region_scope_tree(_: DefId) -> Lrc<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
Loading