Skip to content

Commit 8287842

Browse files
Use Body everywhere
1 parent 64db428 commit 8287842

Some content is hidden

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

53 files changed

+224
-317
lines changed

src/librustc_codegen_ssa/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
152152
// a loop.
153153
fn maybe_sideeffect<Bx: BuilderMethods<'a, 'tcx>>(
154154
&self,
155-
mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>,
155+
mir: &'tcx mir::Body<'tcx>,
156156
bx: &mut Bx,
157157
targets: &[mir::BasicBlock],
158158
) {

src/librustc_codegen_ssa/mir/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use self::operand::{OperandRef, OperandValue};
2121
pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
2222
instance: Instance<'tcx>,
2323

24-
mir: mir::ReadOnlyBodyAndCache<'tcx, 'tcx>,
24+
mir: &'tcx mir::Body<'tcx>,
2525

2626
debug_context: Option<FunctionDebugContext<Bx::DIScope>>,
2727

@@ -169,7 +169,6 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
169169
.collect();
170170

171171
let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs);
172-
let mir_body: &mir::Body<'_> = *mir;
173172
let mut fx = FunctionCx {
174173
instance,
175174
mir,
@@ -197,7 +196,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
197196
let args = arg_local_refs(&mut bx, &mut fx, &memory_locals);
198197

199198
let mut allocate_local = |local| {
200-
let decl = &mir_body.local_decls[local];
199+
let decl = &mir.local_decls[local];
201200
let layout = bx.layout_of(fx.monomorphize(&decl.ty));
202201
assert!(!layout.ty.has_erasable_regions());
203202

@@ -223,7 +222,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
223222
let retptr = allocate_local(mir::RETURN_PLACE);
224223
iter::once(retptr)
225224
.chain(args.into_iter())
226-
.chain(mir_body.vars_and_temps_iter().map(allocate_local))
225+
.chain(mir.vars_and_temps_iter().map(allocate_local))
227226
.collect()
228227
};
229228

@@ -235,8 +234,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
235234
bx.br(fx.blocks[mir::START_BLOCK]);
236235
}
237236

238-
let rpo = traversal::reverse_postorder(&mir_body);
239-
let mut visited = BitSet::new_empty(mir_body.basic_blocks().len());
237+
let rpo = traversal::reverse_postorder(&mir);
238+
let mut visited = BitSet::new_empty(mir.basic_blocks().len());
240239

241240
// Codegen the body of each block using reverse postorder
242241
for (bb, _) in rpo {
@@ -246,7 +245,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
246245

247246
// Remove blocks that haven't been visited, or have no
248247
// predecessors.
249-
for bb in mir_body.basic_blocks().indices() {
248+
for bb in mir.basic_blocks().indices() {
250249
// Unreachable block
251250
if !visited.contains(bb.index()) {
252251
debug!("codegen_mir: block {:?} was not visited", bb);

src/librustc_metadata/rmeta/decoder.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::middle::cstore::{CrateSource, ExternCrate};
2626
use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLibrary};
2727
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
2828
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
29-
use rustc_middle::mir::{self, interpret, BodyAndCache, Promoted};
29+
use rustc_middle::mir::{self, interpret, Body, Promoted};
3030
use rustc_middle::ty::codec::TyDecoder;
3131
use rustc_middle::ty::{self, Ty, TyCtxt};
3232
use rustc_middle::util::common::record_time;
@@ -1099,40 +1099,28 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10991099
!self.is_proc_macro(id) && self.root.tables.mir.get(self, id).is_some()
11001100
}
11011101

1102-
fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tcx> {
1103-
let mut cache = self
1104-
.root
1102+
fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
1103+
self.root
11051104
.tables
11061105
.mir
11071106
.get(self, id)
11081107
.filter(|_| !self.is_proc_macro(id))
11091108
.unwrap_or_else(|| {
11101109
bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id))
11111110
})
1112-
.decode((self, tcx));
1113-
cache.ensure_predecessors();
1114-
cache
1111+
.decode((self, tcx))
11151112
}
11161113

1117-
fn get_promoted_mir(
1118-
&self,
1119-
tcx: TyCtxt<'tcx>,
1120-
id: DefIndex,
1121-
) -> IndexVec<Promoted, BodyAndCache<'tcx>> {
1122-
let mut cache = self
1123-
.root
1114+
fn get_promoted_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec<Promoted, Body<'tcx>> {
1115+
self.root
11241116
.tables
11251117
.promoted_mir
11261118
.get(self, id)
11271119
.filter(|_| !self.is_proc_macro(id))
11281120
.unwrap_or_else(|| {
11291121
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
11301122
})
1131-
.decode((self, tcx));
1132-
for body in cache.iter_mut() {
1133-
body.ensure_predecessors();
1134-
}
1135-
cache
1123+
.decode((self, tcx))
11361124
}
11371125

11381126
fn mir_const_qualif(&self, id: DefIndex) -> mir::ConstQualifs {

src/librustc_metadata/rmeta/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ define_tables! {
275275
// Also, as an optimization, a missing entry indicates an empty `&[]`.
276276
inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>,
277277
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
278-
mir: Table<DefIndex, Lazy!(mir::BodyAndCache<'tcx>)>,
279-
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>>)>,
278+
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
279+
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
280280
}
281281

282282
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]

src/librustc_middle/arena.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ macro_rules! arena_types {
1515
[] generics: rustc_middle::ty::Generics,
1616
[] trait_def: rustc_middle::ty::TraitDef,
1717
[] adt_def: rustc_middle::ty::AdtDef,
18-
[] steal_mir: rustc_middle::ty::steal::Steal<rustc_middle::mir::BodyAndCache<$tcx>>,
19-
[] mir: rustc_middle::mir::BodyAndCache<$tcx>,
18+
[] steal_mir: rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>,
19+
[] mir: rustc_middle::mir::Body<$tcx>,
2020
[] steal_promoted: rustc_middle::ty::steal::Steal<
2121
rustc_index::vec::IndexVec<
2222
rustc_middle::mir::Promoted,
23-
rustc_middle::mir::BodyAndCache<$tcx>
23+
rustc_middle::mir::Body<$tcx>
2424
>
2525
>,
2626
[] promoted: rustc_index::vec::IndexVec<
2727
rustc_middle::mir::Promoted,
28-
rustc_middle::mir::BodyAndCache<$tcx>
28+
rustc_middle::mir::Body<$tcx>
2929
>,
3030
[decode] tables: rustc_middle::ty::TypeckTables<$tcx>,
3131
[decode] borrowck_result: rustc_middle::mir::BorrowCheckResult<$tcx>,

src/librustc_middle/mir/visit.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,6 @@ use rustc_span::Span;
6565
// variant argument) that does not require visiting, as in
6666
// `is_cleanup` above.
6767

68-
macro_rules! body_type {
69-
(mut $tcx:lifetime) => {
70-
&mut BodyAndCache<$tcx>
71-
};
72-
($tcx:lifetime) => {
73-
&Body<$tcx>
74-
};
75-
}
76-
7768
macro_rules! make_mir_visitor {
7869
($visitor_trait_name:ident, $($mutability:ident)?) => {
7970
pub trait $visitor_trait_name<'tcx> {
@@ -82,7 +73,7 @@ macro_rules! make_mir_visitor {
8273

8374
fn visit_body(
8475
&mut self,
85-
body: body_type!($($mutability)? 'tcx)
76+
body: &$($mutability)? Body<'tcx>,
8677
) {
8778
self.super_body(body);
8879
}
@@ -254,7 +245,7 @@ macro_rules! make_mir_visitor {
254245

255246
fn super_body(
256247
&mut self,
257-
$($mutability)? body: body_type!($($mutability)? 'tcx)
248+
body: &$($mutability)? Body<'tcx>,
258249
) {
259250
let span = body.span;
260251
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
@@ -275,7 +266,6 @@ macro_rules! make_mir_visitor {
275266
self.visit_basic_block_data(bb, data);
276267
}
277268

278-
let body: & $($mutability)? Body<'_> = & $($mutability)? body;
279269
for scope in &$($mutability)? body.source_scopes {
280270
self.visit_source_scope_data(scope);
281271
}
@@ -819,10 +809,14 @@ macro_rules! make_mir_visitor {
819809

820810
fn visit_location(
821811
&mut self,
822-
body: body_type!($($mutability)? 'tcx),
812+
body: &$($mutability)? Body<'tcx>,
823813
location: Location
824814
) {
825-
let basic_block = & $($mutability)? body[location.block];
815+
macro_rules! basic_blocks {
816+
(mut) => (body.basic_blocks_mut());
817+
() => (body.basic_blocks());
818+
};
819+
let basic_block = & $($mutability)? basic_blocks!($($mutability)?)[location.block];
826820
if basic_block.statements.len() == location.statement_index {
827821
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
828822
self.visit_terminator(terminator, location)

src/librustc_middle/query/mod.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -170,56 +170,46 @@ rustc_queries! {
170170

171171
/// Fetch the MIR for a given `DefId` right after it's built - this includes
172172
/// unreachable code.
173-
query mir_built(_: DefId) -> &'tcx Steal<mir::BodyAndCache<'tcx>> {
173+
query mir_built(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
174174
desc { "building MIR for" }
175175
}
176176

177177
/// Fetch the MIR for a given `DefId` up till the point where it is
178178
/// ready for const evaluation.
179179
///
180180
/// See the README for the `mir` module for details.
181-
query mir_const(_: DefId) -> &'tcx Steal<mir::BodyAndCache<'tcx>> {
181+
query mir_const(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
182182
no_hash
183183
}
184184

185185
query mir_validated(_: DefId) ->
186186
(
187-
&'tcx Steal<mir::BodyAndCache<'tcx>>,
188-
&'tcx Steal<IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>>>
187+
&'tcx Steal<mir::Body<'tcx>>,
188+
&'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
189189
) {
190190
no_hash
191191
}
192192

193193
/// MIR after our optimization passes have run. This is MIR that is ready
194194
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
195-
query optimized_mir(key: DefId) -> &'tcx mir::BodyAndCache<'tcx> {
195+
query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
196196
cache_on_disk_if { key.is_local() }
197197
load_cached(tcx, id) {
198-
let mir: Option<crate::mir::BodyAndCache<'tcx>>
198+
let mir: Option<crate::mir::Body<'tcx>>
199199
= tcx.queries.on_disk_cache.try_load_query_result(tcx, id);
200-
mir.map(|x| {
201-
let cache = tcx.arena.alloc(x);
202-
cache.ensure_predecessors();
203-
&*cache
204-
})
200+
mir.map(|x| &*tcx.arena.alloc(x))
205201
}
206202
}
207203

208-
query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>> {
204+
query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
209205
cache_on_disk_if { key.is_local() }
210206
load_cached(tcx, id) {
211207
let promoted: Option<
212208
rustc_index::vec::IndexVec<
213209
crate::mir::Promoted,
214-
crate::mir::BodyAndCache<'tcx>
210+
crate::mir::Body<'tcx>
215211
>> = tcx.queries.on_disk_cache.try_load_query_result(tcx, id);
216-
promoted.map(|p| {
217-
let cache = tcx.arena.alloc(p);
218-
for body in cache.iter_mut() {
219-
body.ensure_predecessors();
220-
}
221-
&*cache
222-
})
212+
promoted.map(|p| &*tcx.arena.alloc(p))
223213
}
224214
}
225215
}
@@ -618,7 +608,7 @@ rustc_queries! {
618608
/// in the case of closures, this will be redirected to the enclosing function.
619609
query region_scope_tree(_: DefId) -> &'tcx region::ScopeTree {}
620610

621-
query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::BodyAndCache<'tcx> {
611+
query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Body<'tcx> {
622612
desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
623613
}
624614

src/librustc_middle/ty/context.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use crate::middle::cstore::EncodedMetadata;
1414
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
1515
use crate::middle::stability;
1616
use crate::mir::interpret::{Allocation, ConstValue, Scalar};
17-
use crate::mir::{
18-
interpret, BodyAndCache, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
19-
};
17+
use crate::mir::{interpret, Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
2018
use crate::traits;
2119
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
2220
use crate::ty::query;
@@ -993,21 +991,21 @@ pub struct GlobalCtxt<'tcx> {
993991
}
994992

995993
impl<'tcx> TyCtxt<'tcx> {
996-
pub fn alloc_steal_mir(self, mir: BodyAndCache<'tcx>) -> &'tcx Steal<BodyAndCache<'tcx>> {
994+
pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal<Body<'tcx>> {
997995
self.arena.alloc(Steal::new(mir))
998996
}
999997

1000998
pub fn alloc_steal_promoted(
1001999
self,
1002-
promoted: IndexVec<Promoted, BodyAndCache<'tcx>>,
1003-
) -> &'tcx Steal<IndexVec<Promoted, BodyAndCache<'tcx>>> {
1000+
promoted: IndexVec<Promoted, Body<'tcx>>,
1001+
) -> &'tcx Steal<IndexVec<Promoted, Body<'tcx>>> {
10041002
self.arena.alloc(Steal::new(promoted))
10051003
}
10061004

10071005
pub fn intern_promoted(
10081006
self,
1009-
promoted: IndexVec<Promoted, BodyAndCache<'tcx>>,
1010-
) -> &'tcx IndexVec<Promoted, BodyAndCache<'tcx>> {
1007+
promoted: IndexVec<Promoted, Body<'tcx>>,
1008+
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
10111009
self.arena.alloc(promoted)
10121010
}
10131011

src/librustc_middle/ty/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::infer::canonical::Canonical;
1111
use crate::middle::cstore::CrateStoreDyn;
1212
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
1313
use crate::mir::interpret::ErrorHandled;
14+
use crate::mir::Body;
1415
use crate::mir::GeneratorLayout;
15-
use crate::mir::ReadOnlyBodyAndCache;
1616
use crate::traits::{self, Reveal};
1717
use crate::ty;
1818
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
@@ -2808,17 +2808,17 @@ impl<'tcx> TyCtxt<'tcx> {
28082808
}
28092809

28102810
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
2811-
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> ReadOnlyBodyAndCache<'tcx, 'tcx> {
2811+
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
28122812
match instance {
2813-
ty::InstanceDef::Item(did) => self.optimized_mir(did).unwrap_read_only(),
2813+
ty::InstanceDef::Item(did) => self.optimized_mir(did),
28142814
ty::InstanceDef::VtableShim(..)
28152815
| ty::InstanceDef::ReifyShim(..)
28162816
| ty::InstanceDef::Intrinsic(..)
28172817
| ty::InstanceDef::FnPtrShim(..)
28182818
| ty::InstanceDef::Virtual(..)
28192819
| ty::InstanceDef::ClosureOnceShim { .. }
28202820
| ty::InstanceDef::DropGlue(..)
2821-
| ty::InstanceDef::CloneShim(..) => self.mir_shims(instance).unwrap_read_only(),
2821+
| ty::InstanceDef::CloneShim(..) => self.mir_shims(instance),
28222822
}
28232823
}
28242824

src/librustc_mir/borrow_check/borrow_set.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_index::bit_set::BitSet;
88
use rustc_index::vec::IndexVec;
99
use rustc_middle::mir::traversal;
1010
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
11-
use rustc_middle::mir::{self, Body, Local, Location, ReadOnlyBodyAndCache};
11+
use rustc_middle::mir::{self, Body, Local, Location};
1212
use rustc_middle::ty::{RegionVid, TyCtxt};
1313
use std::fmt;
1414
use std::ops::Index;
@@ -90,7 +90,7 @@ crate enum LocalsStateAtExit {
9090
impl LocalsStateAtExit {
9191
fn build(
9292
locals_are_invalidated_at_exit: bool,
93-
body: ReadOnlyBodyAndCache<'_, 'tcx>,
93+
body: &Body<'tcx>,
9494
move_data: &MoveData<'tcx>,
9595
) -> Self {
9696
struct HasStorageDead(BitSet<Local>);
@@ -122,7 +122,7 @@ impl LocalsStateAtExit {
122122
impl<'tcx> BorrowSet<'tcx> {
123123
pub fn build(
124124
tcx: TyCtxt<'tcx>,
125-
body: ReadOnlyBodyAndCache<'_, 'tcx>,
125+
body: &Body<'tcx>,
126126
locals_are_invalidated_at_exit: bool,
127127
move_data: &MoveData<'tcx>,
128128
) -> Self {

0 commit comments

Comments
 (0)