Skip to content

Commit b2fe254

Browse files
committed
Remove HasLocalDecls impl from BodyCache's, properly reborrow to Body, rename all body_cache back to body
1 parent 595d161 commit b2fe254

Some content is hidden

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

59 files changed

+618
-630
lines changed

src/librustc/mir/cache.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_index::vec::IndexVec;
22
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
33
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
44
use crate::ich::StableHashingContext;
5-
use crate::mir::{BasicBlock, BasicBlockData, Body, HasLocalDecls, LocalDecls, Location, Successors};
5+
use crate::mir::{BasicBlock, BasicBlockData, Body, LocalDecls, Location, Successors};
66
use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
77
use rustc_data_structures::graph::dominators::{dominators, Dominators};
88
use std::iter;
@@ -160,10 +160,10 @@ impl BodyCache<'tcx> {
160160

161161
#[macro_export]
162162
macro_rules! read_only {
163-
($body_cache:expr) => {
163+
($body:expr) => {
164164
{
165-
$body_cache.ensure_predecessors();
166-
$body_cache.unwrap_read_only()
165+
$body.ensure_predecessors();
166+
$body.unwrap_read_only()
167167
}
168168
};
169169
}
@@ -223,12 +223,6 @@ impl<'tcx> DerefMut for BodyCache<'tcx> {
223223
}
224224
}
225225

226-
impl<'tcx> HasLocalDecls<'tcx> for BodyCache<'tcx> {
227-
fn local_decls(&self) -> &LocalDecls<'tcx> {
228-
&self.body.local_decls
229-
}
230-
}
231-
232226
#[derive(Copy, Clone, Debug)]
233227
pub struct ReadOnlyBodyCache<'a, 'tcx> {
234228
cache: &'a Cache,
@@ -347,12 +341,6 @@ impl Index<BasicBlock> for ReadOnlyBodyCache<'a, 'tcx> {
347341
}
348342
}
349343

350-
impl<'a, 'tcx> HasLocalDecls<'tcx> for ReadOnlyBodyCache<'a, 'tcx> {
351-
fn local_decls(&self) -> &LocalDecls<'tcx> {
352-
&self.body.local_decls
353-
}
354-
}
355-
356344
CloneTypeFoldableAndLiftImpls! {
357345
Cache,
358346
}

src/librustc/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ impl Location {
26022602
pub fn is_predecessor_of<'tcx>(
26032603
&self,
26042604
other: Location,
2605-
body_cache: ReadOnlyBodyCache<'_, 'tcx>
2605+
body: ReadOnlyBodyCache<'_, 'tcx>
26062606
) -> bool {
26072607
// If we are in the same block as the other location and are an earlier statement
26082608
// then we are a predecessor of `other`.
@@ -2611,13 +2611,13 @@ impl Location {
26112611
}
26122612

26132613
// If we're in another block, then we want to check that block is a predecessor of `other`.
2614-
let mut queue: Vec<BasicBlock> = body_cache.predecessors_for(other.block).to_vec();
2614+
let mut queue: Vec<BasicBlock> = body.predecessors_for(other.block).to_vec();
26152615
let mut visited = FxHashSet::default();
26162616

26172617
while let Some(block) = queue.pop() {
26182618
// If we haven't visited this block before, then make sure we visit it's predecessors.
26192619
if visited.insert(block) {
2620-
queue.extend(body_cache.predecessors_for(block).iter().cloned());
2620+
queue.extend(body.predecessors_for(block).iter().cloned());
26212621
} else {
26222622
continue;
26232623
}

src/librustc/mir/visit.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ macro_rules! make_mir_visitor {
8282

8383
fn visit_body(
8484
&mut self,
85-
body_cache: body_cache_type!($($mutability)? '_, 'tcx)
85+
body: body_cache_type!($($mutability)? '_, 'tcx)
8686
) {
87-
self.super_body(body_cache);
87+
self.super_body(body);
8888
}
8989

9090
fn visit_basic_block_data(&mut self,
@@ -254,10 +254,10 @@ macro_rules! make_mir_visitor {
254254

255255
fn super_body(
256256
&mut self,
257-
$($mutability)? body_cache: body_cache_type!($($mutability)? '_, 'tcx)
257+
$($mutability)? body: body_cache_type!($($mutability)? '_, 'tcx)
258258
) {
259-
let span = body_cache.span;
260-
if let Some(yield_ty) = &$($mutability)? body_cache.yield_ty {
259+
let span = body.span;
260+
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
261261
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
262262
span,
263263
scope: OUTERMOST_SOURCE_SCOPE,
@@ -268,14 +268,14 @@ macro_rules! make_mir_visitor {
268268
// than a for-loop, to avoid calling `body::Body::invalidate` for
269269
// each basic block.
270270
macro_rules! basic_blocks {
271-
(mut) => (body_cache.basic_blocks_mut().iter_enumerated_mut());
272-
() => (body_cache.basic_blocks().iter_enumerated());
271+
(mut) => (body.basic_blocks_mut().iter_enumerated_mut());
272+
() => (body.basic_blocks().iter_enumerated());
273273
};
274274
for (bb, data) in basic_blocks!($($mutability)?) {
275275
self.visit_basic_block_data(bb, data);
276276
}
277277

278-
let body: & $($mutability)? Body<'_> = & $($mutability)? body_cache;
278+
let body: & $($mutability)? Body<'_> = & $($mutability)? body;
279279
for scope in &$($mutability)? body.source_scopes {
280280
self.visit_source_scope_data(scope);
281281
}
@@ -808,10 +808,10 @@ macro_rules! make_mir_visitor {
808808

809809
fn visit_location(
810810
&mut self,
811-
body_cache: body_cache_type!($($mutability)? '_, 'tcx),
811+
body: body_cache_type!($($mutability)? '_, 'tcx),
812812
location: Location
813813
) {
814-
let basic_block = & $($mutability)? body_cache[location.block];
814+
let basic_block = & $($mutability)? body[location.block];
815815
if basic_block.statements.len() == location.statement_index {
816816
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
817817
self.visit_terminator(terminator, location)

src/librustc/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ rustc_queries! {
149149
>> = tcx.queries.on_disk_cache.try_load_query_result(tcx, id);
150150
promoted.map(|p| {
151151
let cache = tcx.arena.alloc(p);
152-
for body_cache in cache.iter_mut() {
153-
body_cache.ensure_predecessors();
152+
for body in cache.iter_mut() {
153+
body.ensure_predecessors();
154154
}
155155
&*cache
156156
})

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,8 @@ impl<'tcx> TyCtxt<'tcx> {
10831083
&self.hir_map
10841084
}
10851085

1086-
pub fn alloc_steal_mir(self, mir_cache: BodyCache<'tcx>) -> &'tcx Steal<BodyCache<'tcx>> {
1087-
self.arena.alloc(Steal::new(mir_cache))
1086+
pub fn alloc_steal_mir(self, mir: BodyCache<'tcx>) -> &'tcx Steal<BodyCache<'tcx>> {
1087+
self.arena.alloc(Steal::new(mir))
10881088
}
10891089

10901090
pub fn alloc_steal_promoted(self, promoted: IndexVec<Promoted, BodyCache<'tcx>>) ->

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
131131
};
132132
if is_consume {
133133
let base_ty =
134-
mir::Place::ty_from(place_ref.base, proj_base, &self.fx.mir, cx.tcx());
134+
mir::Place::ty_from(place_ref.base, proj_base, &*self.fx.mir, cx.tcx());
135135
let base_ty = self.fx.monomorphize(&base_ty);
136136

137137
// ZSTs don't require any actual memory access.

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
324324
target: mir::BasicBlock,
325325
unwind: Option<mir::BasicBlock>,
326326
) {
327-
let ty = location.ty(&self.mir, bx.tcx()).ty;
327+
let ty = location.ty(&*self.mir, bx.tcx()).ty;
328328
let ty = self.monomorphize(&ty);
329329
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
330330

@@ -510,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
510510

511511
let extra_args = &args[sig.inputs().len()..];
512512
let extra_args = extra_args.iter().map(|op_arg| {
513-
let op_ty = op_arg.ty(&self.mir, bx.tcx());
513+
let op_ty = op_arg.ty(&*self.mir, bx.tcx());
514514
self.monomorphize(&op_ty)
515515
}).collect::<Vec<_>>();
516516

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
594594
let place_ty = mir::Place::ty_from(
595595
place_ref.base,
596596
place_ref.projection,
597-
&self.mir,
597+
&*self.mir,
598598
tcx,
599599
);
600600
self.monomorphize(&place_ty.ty)

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
460460
}
461461

462462
mir::Rvalue::Discriminant(ref place) => {
463-
let discr_ty = rvalue.ty(&self.mir, bx.tcx());
463+
let discr_ty = rvalue.ty(&*self.mir, bx.tcx());
464464
let discr = self.codegen_place(&mut bx, &place.as_ref())
465465
.codegen_get_discr(&mut bx, discr_ty);
466466
(bx, OperandRef {
@@ -513,7 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
513513
mir::Rvalue::Aggregate(..) => {
514514
// According to `rvalue_creates_operand`, only ZST
515515
// aggregate rvalues are allowed to be operands.
516-
let ty = rvalue.ty(&self.mir, self.cx.tcx());
516+
let ty = rvalue.ty(&*self.mir, self.cx.tcx());
517517
let operand = OperandRef::new_zst(
518518
&mut bx,
519519
self.cx.layout_of(self.monomorphize(&ty)),
@@ -710,7 +710,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
710710
true,
711711
mir::Rvalue::Repeat(..) |
712712
mir::Rvalue::Aggregate(..) => {
713-
let ty = rvalue.ty(&self.mir, self.cx.tcx());
713+
let ty = rvalue.ty(&*self.mir, self.cx.tcx());
714714
let ty = self.monomorphize(&ty);
715715
self.cx.spanned_layout_of(ty, span).is_zst()
716716
}

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,8 @@ impl<'a, 'tcx> CrateMetadata {
11011101
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
11021102
})
11031103
.decode((self, tcx));
1104-
for body_cache in cache.iter_mut() {
1105-
body_cache.ensure_predecessors();
1104+
for body in cache.iter_mut() {
1105+
body.ensure_predecessors();
11061106
}
11071107
cache
11081108
}

0 commit comments

Comments
 (0)