Skip to content

Commit 6e5e0da

Browse files
author
Claude-Alban RANÉLY-VERGÉ-DÉPRÉ
committed
Changes the type mir::Mir into mir::Body
The commit should have changed comments as well. At the time of writting, it passes the tidy and check tool. Revisions asked by eddyb : - Renamed of all the occurences of {visit/super}_mir - Renamed test structures `CachedMir` to `Cached` Fixing the missing import on `AggregateKind`
1 parent 7da1185 commit 6e5e0da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+441
-435
lines changed

src/librustc/mir/cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_data_structures::sync::{RwLock, MappedReadGuard, ReadGuard};
33
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
44
StableHasherResult};
55
use crate::ich::StableHashingContext;
6-
use crate::mir::{Mir, BasicBlock};
6+
use crate::mir::{Body, BasicBlock};
77

88
use crate::rustc_serialize as serialize;
99

@@ -47,7 +47,7 @@ impl Cache {
4747

4848
pub fn predecessors(
4949
&self,
50-
mir: &Mir<'_>
50+
mir: &Body<'_>
5151
) -> MappedReadGuard<'_, IndexVec<BasicBlock, Vec<BasicBlock>>> {
5252
if self.predecessors.borrow().is_none() {
5353
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
@@ -57,7 +57,7 @@ impl Cache {
5757
}
5858
}
5959

60-
fn calculate_predecessors(mir: &Mir<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
60+
fn calculate_predecessors(mir: &Body<'_>) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
6161
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
6262
for (bb, data) in mir.basic_blocks().iter_enumerated() {
6363
if let Some(ref term) = data.terminator {

src/librustc/mir/mod.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> {
6060
}
6161
}
6262

63-
impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> {
63+
impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
6464
fn local_decls(&self) -> &LocalDecls<'tcx> {
6565
&self.local_decls
6666
}
@@ -86,7 +86,7 @@ impl MirPhase {
8686

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

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

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

117117
/// Generator drop glue
118-
pub generator_drop: Option<Box<Mir<'tcx>>>,
118+
pub generator_drop: Option<Box<Body<'tcx>>>,
119119

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

170-
impl<'tcx> Mir<'tcx> {
170+
impl<'tcx> Body<'tcx> {
171171
pub fn new(
172172
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
173173
source_scopes: IndexVec<SourceScope, SourceScopeData>,
174174
source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
175-
promoted: IndexVec<Promoted, Mir<'tcx>>,
175+
promoted: IndexVec<Promoted, Body<'tcx>>,
176176
yield_ty: Option<Ty<'tcx>>,
177177
local_decls: LocalDecls<'tcx>,
178178
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
@@ -189,7 +189,7 @@ impl<'tcx> Mir<'tcx> {
189189
local_decls.len()
190190
);
191191

192-
Mir {
192+
Body {
193193
phase: MirPhase::Build,
194194
basic_blocks,
195195
source_scopes,
@@ -423,7 +423,7 @@ pub enum Safety {
423423
ExplicitUnsafe(hir::HirId),
424424
}
425425

426-
impl_stable_hash_for!(struct Mir<'tcx> {
426+
impl_stable_hash_for!(struct Body<'tcx> {
427427
phase,
428428
basic_blocks,
429429
source_scopes,
@@ -442,7 +442,7 @@ impl_stable_hash_for!(struct Mir<'tcx> {
442442
cache
443443
});
444444

445-
impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
445+
impl<'tcx> Index<BasicBlock> for Body<'tcx> {
446446
type Output = BasicBlockData<'tcx>;
447447

448448
#[inline]
@@ -451,7 +451,7 @@ impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
451451
}
452452
}
453453

454-
impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
454+
impl<'tcx> IndexMut<BasicBlock> for Body<'tcx> {
455455
#[inline]
456456
fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {
457457
&mut self.basic_blocks_mut()[index]
@@ -599,7 +599,7 @@ newtype_index! {
599599
}
600600
}
601601

602-
/// Classifies locals into categories. See `Mir::local_kind`.
602+
/// Classifies locals into categories. See `Body::local_kind`.
603603
#[derive(PartialEq, Eq, Debug, HashStable)]
604604
pub enum LocalKind {
605605
/// User-declared variable binding
@@ -2831,23 +2831,23 @@ impl<'tcx> Display for Constant<'tcx> {
28312831
}
28322832
}
28332833

2834-
impl<'tcx> graph::DirectedGraph for Mir<'tcx> {
2834+
impl<'tcx> graph::DirectedGraph for Body<'tcx> {
28352835
type Node = BasicBlock;
28362836
}
28372837

2838-
impl<'tcx> graph::WithNumNodes for Mir<'tcx> {
2838+
impl<'tcx> graph::WithNumNodes for Body<'tcx> {
28392839
fn num_nodes(&self) -> usize {
28402840
self.basic_blocks.len()
28412841
}
28422842
}
28432843

2844-
impl<'tcx> graph::WithStartNode for Mir<'tcx> {
2844+
impl<'tcx> graph::WithStartNode for Body<'tcx> {
28452845
fn start_node(&self) -> Self::Node {
28462846
START_BLOCK
28472847
}
28482848
}
28492849

2850-
impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
2850+
impl<'tcx> graph::WithPredecessors for Body<'tcx> {
28512851
fn predecessors<'graph>(
28522852
&'graph self,
28532853
node: Self::Node,
@@ -2856,7 +2856,7 @@ impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
28562856
}
28572857
}
28582858

2859-
impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
2859+
impl<'tcx> graph::WithSuccessors for Body<'tcx> {
28602860
fn successors<'graph>(
28612861
&'graph self,
28622862
node: Self::Node,
@@ -2865,12 +2865,12 @@ impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
28652865
}
28662866
}
28672867

2868-
impl<'a, 'b> graph::GraphPredecessors<'b> for Mir<'a> {
2868+
impl<'a, 'b> graph::GraphPredecessors<'b> for Body<'a> {
28692869
type Item = BasicBlock;
28702870
type Iter = IntoIter<BasicBlock>;
28712871
}
28722872

2873-
impl<'a, 'b> graph::GraphSuccessors<'b> for Mir<'a> {
2873+
impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
28742874
type Item = BasicBlock;
28752875
type Iter = iter::Cloned<Successors<'b>>;
28762876
}
@@ -2909,7 +2909,7 @@ impl Location {
29092909
}
29102910

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

31643164
BraceStructTypeFoldableImpl! {
3165-
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
3165+
impl<'tcx> TypeFoldable<'tcx> for Body<'tcx> {
31663166
phase,
31673167
basic_blocks,
31683168
source_scopes,

src/librustc/mir/traversal.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ use super::*;
2121
/// A preorder traversal of this graph is either `A B D C` or `A C D B`
2222
#[derive(Clone)]
2323
pub struct Preorder<'a, 'tcx: 'a> {
24-
mir: &'a Mir<'tcx>,
24+
mir: &'a Body<'tcx>,
2525
visited: BitSet<BasicBlock>,
2626
worklist: Vec<BasicBlock>,
2727
root_is_start_block: bool,
2828
}
2929

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

3434
Preorder {
@@ -40,7 +40,7 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> {
4040
}
4141
}
4242

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

@@ -99,14 +99,14 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
9999
///
100100
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
101101
pub struct Postorder<'a, 'tcx: 'a> {
102-
mir: &'a Mir<'tcx>,
102+
mir: &'a Body<'tcx>,
103103
visited: BitSet<BasicBlock>,
104104
visit_stack: Vec<(BasicBlock, Successors<'a>)>,
105105
root_is_start_block: bool,
106106
}
107107

108108
impl<'a, 'tcx> Postorder<'a, 'tcx> {
109-
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
109+
pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
110110
let mut po = Postorder {
111111
mir,
112112
visited: BitSet::new_empty(mir.basic_blocks().len()),
@@ -194,7 +194,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
194194
}
195195
}
196196

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

@@ -252,13 +252,13 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
252252
/// to re-use the traversal
253253
#[derive(Clone)]
254254
pub struct ReversePostorder<'a, 'tcx: 'a> {
255-
mir: &'a Mir<'tcx>,
255+
mir: &'a Body<'tcx>,
256256
blocks: Vec<BasicBlock>,
257257
idx: usize
258258
}
259259

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

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

278278

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

src/librustc/mir/visit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ macro_rules! make_mir_visitor {
7171
// Override these, and call `self.super_xxx` to revert back to the
7272
// default behavior.
7373

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

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

254-
fn super_mir(&mut self,
255-
mir: & $($mutability)? Mir<'tcx>) {
254+
fn super_body(&mut self,
255+
mir: & $($mutability)? Body<'tcx>) {
256256
if let Some(yield_ty) = &$($mutability)? mir.yield_ty {
257257
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
258258
span: mir.span,
@@ -825,7 +825,7 @@ macro_rules! make_mir_visitor {
825825

826826
// Convenience methods
827827

828-
fn visit_location(&mut self, mir: & $($mutability)? Mir<'tcx>, location: Location) {
828+
fn visit_location(&mut self, mir: & $($mutability)? Body<'tcx>, location: Location) {
829829
let basic_block = & $($mutability)? mir[location.block];
830830
if basic_block.statements.len() == location.statement_index {
831831
if let Some(ref $($mutability)? terminator) = basic_block.terminator {

src/librustc/query/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,26 @@ rustc_queries! {
9797

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

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

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

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

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

src/librustc/ty/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::middle::cstore::EncodedMetadata;
2323
use crate::middle::lang_items;
2424
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
2525
use crate::middle::stability;
26-
use crate::mir::{self, Mir, interpret, ProjectionKind};
26+
use crate::mir::{self, Body, interpret, ProjectionKind};
2727
use crate::mir::interpret::{ConstValue, Allocation, Scalar};
2828
use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, Subst};
2929
use crate::ty::ReprOptions;
@@ -103,8 +103,8 @@ pub struct GlobalArenas<'tcx> {
103103
generics: TypedArena<ty::Generics>,
104104
trait_def: TypedArena<ty::TraitDef>,
105105
adt_def: TypedArena<ty::AdtDef>,
106-
steal_mir: TypedArena<Steal<Mir<'tcx>>>,
107-
mir: TypedArena<Mir<'tcx>>,
106+
steal_mir: TypedArena<Steal<Body<'tcx>>>,
107+
mir: TypedArena<Body<'tcx>>,
108108
tables: TypedArena<ty::TypeckTables<'tcx>>,
109109
/// miri allocations
110110
const_allocs: TypedArena<interpret::Allocation>,
@@ -1154,11 +1154,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11541154
self.global_arenas.generics.alloc(generics)
11551155
}
11561156

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

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

src/librustc/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::ich::StableHashingContext;
1919
use crate::infer::canonical::Canonical;
2020
use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
2121
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
22-
use crate::mir::Mir;
22+
use crate::mir::Body;
2323
use crate::mir::interpret::{GlobalId, ErrorHandled};
2424
use crate::mir::GeneratorLayout;
2525
use crate::session::CrateDisambiguator;
@@ -3002,7 +3002,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
30023002

30033003
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
30043004
pub fn instance_mir(self, instance: ty::InstanceDef<'gcx>)
3005-
-> &'gcx Mir<'gcx>
3005+
-> &'gcx Body<'gcx>
30063006
{
30073007
match instance {
30083008
ty::InstanceDef::Item(did) => {

0 commit comments

Comments
 (0)