Skip to content

Commit ee08261

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 e19a229 + 95013e6 commit ee08261

Some content is hidden

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

93 files changed

+458
-447
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/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct GlobalId<'tcx> {
4747
/// For a promoted global, the `Instance` of the function they belong to.
4848
pub instance: ty::Instance<'tcx>,
4949

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

src/librustc/mir/mod.rs

+21-21
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
@@ -2828,23 +2828,23 @@ impl<'tcx> Display for Constant<'tcx> {
28282828
}
28292829
}
28302830

2831-
impl<'tcx> graph::DirectedGraph for Mir<'tcx> {
2831+
impl<'tcx> graph::DirectedGraph for Body<'tcx> {
28322832
type Node = BasicBlock;
28332833
}
28342834

2835-
impl<'tcx> graph::WithNumNodes for Mir<'tcx> {
2835+
impl<'tcx> graph::WithNumNodes for Body<'tcx> {
28362836
fn num_nodes(&self) -> usize {
28372837
self.basic_blocks.len()
28382838
}
28392839
}
28402840

2841-
impl<'tcx> graph::WithStartNode for Mir<'tcx> {
2841+
impl<'tcx> graph::WithStartNode for Body<'tcx> {
28422842
fn start_node(&self) -> Self::Node {
28432843
START_BLOCK
28442844
}
28452845
}
28462846

2847-
impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
2847+
impl<'tcx> graph::WithPredecessors for Body<'tcx> {
28482848
fn predecessors<'graph>(
28492849
&'graph self,
28502850
node: Self::Node,
@@ -2853,7 +2853,7 @@ impl<'tcx> graph::WithPredecessors for Mir<'tcx> {
28532853
}
28542854
}
28552855

2856-
impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
2856+
impl<'tcx> graph::WithSuccessors for Body<'tcx> {
28572857
fn successors<'graph>(
28582858
&'graph self,
28592859
node: Self::Node,
@@ -2862,12 +2862,12 @@ impl<'tcx> graph::WithSuccessors for Mir<'tcx> {
28622862
}
28632863
}
28642864

2865-
impl<'a, 'b> graph::GraphPredecessors<'b> for Mir<'a> {
2865+
impl<'a, 'b> graph::GraphPredecessors<'b> for Body<'a> {
28662866
type Item = BasicBlock;
28672867
type Iter = IntoIter<BasicBlock>;
28682868
}
28692869

2870-
impl<'a, 'b> graph::GraphSuccessors<'b> for Mir<'a> {
2870+
impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
28712871
type Item = BasicBlock;
28722872
type Iter = iter::Cloned<Successors<'b>>;
28732873
}
@@ -2906,7 +2906,7 @@ impl Location {
29062906
}
29072907

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

31613161
BraceStructTypeFoldableImpl! {
3162-
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
3162+
impl<'tcx> TypeFoldable<'tcx> for Body<'tcx> {
31633163
phase,
31643164
basic_blocks,
31653165
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

+6-6
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,
@@ -261,7 +261,7 @@ macro_rules! make_mir_visitor {
261261
}
262262

263263
// for best performance, we want to use an iterator rather
264-
// than a for-loop, to avoid calling Mir::invalidate for
264+
// than a for-loop, to avoid calling `mir::Body::invalidate` for
265265
// each basic block.
266266
macro_rules! basic_blocks {
267267
(mut) => (mir.basic_blocks_mut().iter_enumerated_mut());
@@ -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

+7-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ rustc_queries! {
8888
desc { "getting a list of all mir_keys" }
8989
}
9090

91-
/// Maps DefId's that have an associated Mir to the result
91+
/// Maps DefId's that have an associated `mir::Body` to the result
9292
/// of the MIR qualify_consts pass. The actual meaning of
9393
/// the value isn't known except to the pass itself.
9494
query mir_const_qualif(key: DefId) -> (u8, &'tcx BitSet<mir::Local>) {
@@ -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
}

0 commit comments

Comments
 (0)