Skip to content

Commit 9f210e4

Browse files
authored
Rollup merge of rust-lang#60928 - TheSirC:fix/60229, r=eddyb
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.
2 parents 02f5786 + d5f7181 commit 9f210e4

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

+439
-436
lines changed

src/librustc/mir/cache.rs

+3-3
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

+21-21
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> {
6262
}
6363
}
6464

65-
impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> {
65+
impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
6666
fn local_decls(&self) -> &LocalDecls<'tcx> {
6767
&self.local_decls
6868
}
@@ -88,7 +88,7 @@ impl MirPhase {
8888

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

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

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

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

122122
/// The layout of a generator. Produced by the state transformation.
123123
pub generator_layout: Option<GeneratorLayout<'tcx>>,
@@ -169,12 +169,12 @@ pub struct Mir<'tcx> {
169169
cache: cache::Cache,
170170
}
171171

172-
impl<'tcx> Mir<'tcx> {
172+
impl<'tcx> Body<'tcx> {
173173
pub fn new(
174174
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
175175
source_scopes: IndexVec<SourceScope, SourceScopeData>,
176176
source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
177-
promoted: IndexVec<Promoted, Mir<'tcx>>,
177+
promoted: IndexVec<Promoted, Body<'tcx>>,
178178
yield_ty: Option<Ty<'tcx>>,
179179
local_decls: LocalDecls<'tcx>,
180180
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
@@ -191,7 +191,7 @@ impl<'tcx> Mir<'tcx> {
191191
local_decls.len()
192192
);
193193

194-
Mir {
194+
Body {
195195
phase: MirPhase::Build,
196196
basic_blocks,
197197
source_scopes,
@@ -425,7 +425,7 @@ pub enum Safety {
425425
ExplicitUnsafe(hir::HirId),
426426
}
427427

428-
impl_stable_hash_for!(struct Mir<'tcx> {
428+
impl_stable_hash_for!(struct Body<'tcx> {
429429
phase,
430430
basic_blocks,
431431
source_scopes,
@@ -444,7 +444,7 @@ impl_stable_hash_for!(struct Mir<'tcx> {
444444
cache
445445
});
446446

447-
impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
447+
impl<'tcx> Index<BasicBlock> for Body<'tcx> {
448448
type Output = BasicBlockData<'tcx>;
449449

450450
#[inline]
@@ -453,7 +453,7 @@ impl<'tcx> Index<BasicBlock> for Mir<'tcx> {
453453
}
454454
}
455455

456-
impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
456+
impl<'tcx> IndexMut<BasicBlock> for Body<'tcx> {
457457
#[inline]
458458
fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {
459459
&mut self.basic_blocks_mut()[index]
@@ -601,7 +601,7 @@ newtype_index! {
601601
}
602602
}
603603

604-
/// Classifies locals into categories. See `Mir::local_kind`.
604+
/// Classifies locals into categories. See `Body::local_kind`.
605605
#[derive(PartialEq, Eq, Debug, HashStable)]
606606
pub enum LocalKind {
607607
/// User-declared variable binding
@@ -2890,23 +2890,23 @@ fn def_path_str(def_id: DefId) -> String {
28902890
ty::tls::with(|tcx| tcx.def_path_str(def_id))
28912891
}
28922892

2893-
impl<'tcx> graph::DirectedGraph for Mir<'tcx> {
2893+
impl<'tcx> graph::DirectedGraph for Body<'tcx> {
28942894
type Node = BasicBlock;
28952895
}
28962896

2897-
impl<'tcx> graph::WithNumNodes for Mir<'tcx> {
2897+
impl<'tcx> graph::WithNumNodes for Body<'tcx> {
28982898
fn num_nodes(&self) -> usize {
28992899
self.basic_blocks.len()
29002900
}
29012901
}
29022902

2903-
impl<'tcx> graph::WithStartNode for Mir<'tcx> {
2903+
impl<'tcx> graph::WithStartNode for Body<'tcx> {
29042904
fn start_node(&self) -> Self::Node {
29052905
START_BLOCK
29062906
}
29072907
}
29082908

2909-
impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
2909+
impl<'tcx> graph::WithPredecessors for Body<'tcx> {
29102910
fn predecessors<'graph>(
29112911
&'graph self,
29122912
node: Self::Node,
@@ -2915,7 +2915,7 @@ impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
29152915
}
29162916
}
29172917

2918-
impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
2918+
impl<'tcx> graph::WithSuccessors for Body<'tcx> {
29192919
fn successors<'graph>(
29202920
&'graph self,
29212921
node: Self::Node,
@@ -2924,12 +2924,12 @@ impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
29242924
}
29252925
}
29262926

2927-
impl<'a, 'b> graph::GraphPredecessors<'b> for Mir<'a> {
2927+
impl<'a, 'b> graph::GraphPredecessors<'b> for Body<'a> {
29282928
type Item = BasicBlock;
29292929
type Iter = IntoIter<BasicBlock>;
29302930
}
29312931

2932-
impl<'a, 'b> graph::GraphSuccessors<'b> for Mir<'a> {
2932+
impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
29332933
type Item = BasicBlock;
29342934
type Iter = iter::Cloned<Successors<'b>>;
29352935
}
@@ -2968,7 +2968,7 @@ impl Location {
29682968
}
29692969

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

32233223
BraceStructTypeFoldableImpl! {
3224-
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
3224+
impl<'tcx> TypeFoldable<'tcx> for Body<'tcx> {
32253225
phase,
32263226
basic_blocks,
32273227
source_scopes,

src/librustc/mir/traversal.rs

+9-9
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

+5-5
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

+6-6
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

+5-5
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};
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>,
@@ -1151,11 +1151,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11511151
self.global_arenas.generics.alloc(generics)
11521152
}
11531153

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

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

src/librustc/ty/mod.rs

+2-2
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)