1
Fork 0

Remove BodyCache.body and rely on Deref as much as possible for ReadOnlyBodyCache

This commit is contained in:
Paul Daniel Faria 2019-11-06 00:04:53 -05:00
parent c42bdb8c74
commit 595d161d36
30 changed files with 89 additions and 87 deletions

View file

@ -2,7 +2,7 @@ use rustc_index::vec::IndexVec;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
use crate::ich::StableHashingContext; use crate::ich::StableHashingContext;
use crate::mir::{BasicBlock, BasicBlockData, Body, LocalDecls, Location, Successors}; use crate::mir::{BasicBlock, BasicBlockData, Body, HasLocalDecls, LocalDecls, Location, Successors};
use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors}; use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
use rustc_data_structures::graph::dominators::{dominators, Dominators}; use rustc_data_structures::graph::dominators::{dominators, Dominators};
use std::iter; use std::iter;
@ -181,14 +181,6 @@ impl BodyCache<'tcx> {
ReadOnlyBodyCache::new(&self.cache, &self.body) ReadOnlyBodyCache::new(&self.cache, &self.body)
} }
pub fn body(&self) -> &Body<'tcx> {
&self.body
}
pub fn body_mut(&mut self) -> &mut Body<'tcx> {
&mut self.body
}
pub fn cache(&self) -> &Cache { &self.cache } pub fn cache(&self) -> &Cache { &self.cache }
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> { pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
@ -231,6 +223,12 @@ impl<'tcx> DerefMut for BodyCache<'tcx> {
} }
} }
impl<'tcx> HasLocalDecls<'tcx> for BodyCache<'tcx> {
fn local_decls(&self) -> &LocalDecls<'tcx> {
&self.body.local_decls
}
}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct ReadOnlyBodyCache<'a, 'tcx> { pub struct ReadOnlyBodyCache<'a, 'tcx> {
cache: &'a Cache, cache: &'a Cache,
@ -349,6 +347,12 @@ impl Index<BasicBlock> for ReadOnlyBodyCache<'a, 'tcx> {
} }
} }
impl<'a, 'tcx> HasLocalDecls<'tcx> for ReadOnlyBodyCache<'a, 'tcx> {
fn local_decls(&self) -> &LocalDecls<'tcx> {
&self.body.local_decls
}
}
CloneTypeFoldableAndLiftImpls! { CloneTypeFoldableAndLiftImpls! {
Cache, Cache,
} }

View file

@ -254,14 +254,10 @@ macro_rules! make_mir_visitor {
fn super_body( fn super_body(
&mut self, &mut self,
body_cache: body_cache_type!($($mutability)? '_, 'tcx) $($mutability)? body_cache: body_cache_type!($($mutability)? '_, 'tcx)
) { ) {
macro_rules! body { let span = body_cache.span;
(mut) => (body_cache.body_mut()); if let Some(yield_ty) = &$($mutability)? body_cache.yield_ty {
() => (body_cache.body());
}
let span = body_cache.body().span;
if let Some(yield_ty) = &$($mutability)? body!($($mutability)?).yield_ty {
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo { self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
span, span,
scope: OUTERMOST_SOURCE_SCOPE, scope: OUTERMOST_SOURCE_SCOPE,
@ -279,7 +275,7 @@ macro_rules! make_mir_visitor {
self.visit_basic_block_data(bb, data); self.visit_basic_block_data(bb, data);
} }
let body = body!($($mutability)?); let body: & $($mutability)? Body<'_> = & $($mutability)? body_cache;
for scope in &$($mutability)? body.source_scopes { for scope in &$($mutability)? body.source_scopes {
self.visit_source_scope_data(scope); self.visit_source_scope_data(scope);
} }

View file

@ -3023,7 +3023,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn generator_layout(self, def_id: DefId) -> &'tcx GeneratorLayout<'tcx> { pub fn generator_layout(self, def_id: DefId) -> &'tcx GeneratorLayout<'tcx> {
self.optimized_mir(def_id).body().generator_layout.as_ref().unwrap() self.optimized_mir(def_id).generator_layout.as_ref().unwrap()
} }
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements. /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.

View file

@ -131,7 +131,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
}; };
if is_consume { if is_consume {
let base_ty = let base_ty =
mir::Place::ty_from(place_ref.base, proj_base, self.fx.mir.body(), cx.tcx()); mir::Place::ty_from(place_ref.base, proj_base, &self.fx.mir, cx.tcx());
let base_ty = self.fx.monomorphize(&base_ty); let base_ty = self.fx.monomorphize(&base_ty);
// ZSTs don't require any actual memory access. // ZSTs don't require any actual memory access.

View file

@ -324,7 +324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
target: mir::BasicBlock, target: mir::BasicBlock,
unwind: Option<mir::BasicBlock>, unwind: Option<mir::BasicBlock>,
) { ) {
let ty = location.ty(self.mir.body(), bx.tcx()).ty; let ty = location.ty(&self.mir, bx.tcx()).ty;
let ty = self.monomorphize(&ty); let ty = self.monomorphize(&ty);
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty); let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
@ -510,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let extra_args = &args[sig.inputs().len()..]; let extra_args = &args[sig.inputs().len()..];
let extra_args = extra_args.iter().map(|op_arg| { let extra_args = extra_args.iter().map(|op_arg| {
let op_ty = op_arg.ty(self.mir.body(), bx.tcx()); let op_ty = op_arg.ty(&self.mir, bx.tcx());
self.monomorphize(&op_ty) self.monomorphize(&op_ty)
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
@ -569,7 +569,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// a NOP // a NOP
let target = destination.as_ref().unwrap().1; let target = destination.as_ref().unwrap().1;
helper.maybe_sideeffect(self.mir, &mut bx, &[target]); helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
helper.funclet_br(self, &mut bx, destination.as_ref().unwrap().1) helper.funclet_br(self, &mut bx, target)
} }
return; return;
} }
@ -791,7 +791,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bb: mir::BasicBlock, bb: mir::BasicBlock,
) { ) {
let mut bx = self.build_block(bb); let mut bx = self.build_block(bb);
let data = &self.mir.body()[bb]; let mir = self.mir;
let data = &mir[bb];
debug!("codegen_block({:?}={:?})", bb, data); debug!("codegen_block({:?}={:?})", bb, data);

View file

@ -156,7 +156,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
}).collect(); }).collect();
let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs); let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs);
let mir_body = mir.body(); let mir_body: &Body<'_> = &mir;
let mut fx = FunctionCx { let mut fx = FunctionCx {
instance, instance,
mir, mir,

View file

@ -594,8 +594,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let place_ty = mir::Place::ty_from( let place_ty = mir::Place::ty_from(
place_ref.base, place_ref.base,
place_ref.projection, place_ref.projection,
self.mir.body(), &self.mir,
tcx); tcx,
);
self.monomorphize(&place_ty.ty) self.monomorphize(&place_ty.ty)
} }
} }

View file

@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} }
mir::Rvalue::Discriminant(ref place) => { mir::Rvalue::Discriminant(ref place) => {
let discr_ty = rvalue.ty(self.mir.body(), bx.tcx()); let discr_ty = rvalue.ty(&self.mir, bx.tcx());
let discr = self.codegen_place(&mut bx, &place.as_ref()) let discr = self.codegen_place(&mut bx, &place.as_ref())
.codegen_get_discr(&mut bx, discr_ty); .codegen_get_discr(&mut bx, discr_ty);
(bx, OperandRef { (bx, OperandRef {
@ -513,7 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Aggregate(..) => { mir::Rvalue::Aggregate(..) => {
// According to `rvalue_creates_operand`, only ZST // According to `rvalue_creates_operand`, only ZST
// aggregate rvalues are allowed to be operands. // aggregate rvalues are allowed to be operands.
let ty = rvalue.ty(self.mir.body(), self.cx.tcx()); let ty = rvalue.ty(&self.mir, self.cx.tcx());
let operand = OperandRef::new_zst( let operand = OperandRef::new_zst(
&mut bx, &mut bx,
self.cx.layout_of(self.monomorphize(&ty)), self.cx.layout_of(self.monomorphize(&ty)),
@ -710,7 +710,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
true, true,
mir::Rvalue::Repeat(..) | mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => { mir::Rvalue::Aggregate(..) => {
let ty = rvalue.ty(self.mir.body(), self.cx.tcx()); let ty = rvalue.ty(&self.mir, self.cx.tcx());
let ty = self.monomorphize(&ty); let ty = self.monomorphize(&ty);
self.cx.spanned_layout_of(ty, span).is_zst() self.cx.spanned_layout_of(ty, span).is_zst()
} }

View file

@ -130,7 +130,7 @@ impl<'tcx> BorrowSet<'tcx> {
) -> Self { ) -> Self {
let mut visitor = GatherBorrows { let mut visitor = GatherBorrows {
tcx, tcx,
body: body_cache.body(), body: &body_cache,
idx_vec: IndexVec::new(), idx_vec: IndexVec::new(),
location_map: Default::default(), location_map: Default::default(),
activation_map: Default::default(), activation_map: Default::default(),

View file

@ -208,7 +208,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let ty = Place::ty_from( let ty = Place::ty_from(
used_place.base, used_place.base,
used_place.projection, used_place.projection,
self.body_cache.body(), &self.body_cache,
self.infcx.tcx self.infcx.tcx
).ty; ).ty;
let needs_note = match ty.kind { let needs_note = match ty.kind {
@ -225,7 +225,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mpi = self.move_data.moves[move_out_indices[0]].path; let mpi = self.move_data.moves[move_out_indices[0]].path;
let place = &self.move_data.move_paths[mpi].place; let place = &self.move_data.move_paths[mpi].place;
let ty = place.ty(self.body_cache.body(), self.infcx.tcx).ty; let ty = place.ty(&self.body_cache, self.infcx.tcx).ty;
let opt_name = let opt_name =
self.describe_place_with_options(place.as_ref(), IncludingDowncast(true)); self.describe_place_with_options(place.as_ref(), IncludingDowncast(true));
let note_msg = match opt_name { let note_msg = match opt_name {
@ -625,7 +625,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let ty = Place::ty_from( let ty = Place::ty_from(
place_base, place_base,
place_projection, place_projection,
self.body_cache.body(), &self.body_cache,
self.infcx.tcx self.infcx.tcx
).ty; ).ty;
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty) ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
@ -1635,7 +1635,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Place::ty_from( Place::ty_from(
&place.base, &place.base,
proj_base, proj_base,
self.body_cache.body(), &self.body_cache,
tcx tcx
).ty.is_box(), ).ty.is_box(),
"Drop of value behind a reference or raw pointer" "Drop of value behind a reference or raw pointer"
@ -1648,7 +1648,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let base_ty = Place::ty_from( let base_ty = Place::ty_from(
&place.base, &place.base,
proj_base, proj_base,
self.body_cache.body(), &self.body_cache,
tcx tcx
).ty; ).ty;
match base_ty.kind { match base_ty.kind {

View file

@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let base_ty = Place::ty_from( let base_ty = Place::ty_from(
place.base, place.base,
place.projection, place.projection,
self.body_cache.body(), &self.body_cache,
self.infcx.tcx).ty; self.infcx.tcx).ty;
self.describe_field_from_ty(&base_ty, field, Some(*variant_index)) self.describe_field_from_ty(&base_ty, field, Some(*variant_index))
} }
@ -502,7 +502,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.. ..
}) = bbd.terminator { }) = bbd.terminator {
if let Some(source) = BorrowedContentSource::from_call( if let Some(source) = BorrowedContentSource::from_call(
func.ty(self.body_cache.body(), tcx), func.ty(&self.body_cache, tcx),
tcx tcx
) { ) {
return source; return source;
@ -519,7 +519,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let base_ty = Place::ty_from( let base_ty = Place::ty_from(
deref_base.base, deref_base.base,
deref_base.projection, deref_base.projection,
self.body_cache.body(), &self.body_cache,
tcx tcx
).ty; ).ty;
if base_ty.is_unsafe_ptr() { if base_ty.is_unsafe_ptr() {

View file

@ -646,7 +646,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
// Compute the type with accurate region information. // Compute the type with accurate region information.
let drop_place_ty = drop_place.ty(self.body_cache.body(), self.infcx.tcx); let drop_place_ty = drop_place.ty(&self.body_cache, self.infcx.tcx);
// Erase the regions. // Erase the regions.
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty; let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
@ -990,7 +990,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mut error_reported = false; let mut error_reported = false;
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let body = self.body_cache.body(); let body_cache = self.body_cache;
let body: &Body<'_> = &body_cache;
let param_env = self.param_env; let param_env = self.param_env;
let location_table = self.location_table.start_index(location); let location_table = self.location_table.start_index(location);
let borrow_set = self.borrow_set.clone(); let borrow_set = self.borrow_set.clone();
@ -1341,7 +1342,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
_ => bug!("temporary initialized in arguments"), _ => bug!("temporary initialized in arguments"),
}; };
let bbd = &self.body_cache.body()[loc.block]; let body_cache = self.body_cache;
let bbd = &body_cache[loc.block];
let stmt = &bbd.statements[loc.statement_index]; let stmt = &bbd.statements[loc.statement_index];
debug!("temporary assigned in: stmt={:?}", stmt); debug!("temporary assigned in: stmt={:?}", stmt);

View file

@ -300,7 +300,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// Inspect the type of the content behind the // Inspect the type of the content behind the
// borrow to provide feedback about why this // borrow to provide feedback about why this
// was a move rather than a copy. // was a move rather than a copy.
let ty = deref_target_place.ty(self.body_cache.body(), self.infcx.tcx).ty; let ty = deref_target_place.ty(&self.body_cache, self.infcx.tcx).ty;
let upvar_field = self.prefixes(move_place.as_ref(), PrefixSet::All) let upvar_field = self.prefixes(move_place.as_ref(), PrefixSet::All)
.find_map(|p| self.is_upvar_field_projection(p)); .find_map(|p| self.is_upvar_field_projection(p));
@ -411,7 +411,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}; };
let move_ty = format!( let move_ty = format!(
"{:?}", "{:?}",
move_place.ty(self.body_cache.body(), self.infcx.tcx).ty, move_place.ty(&self.body_cache, self.infcx.tcx).ty,
); );
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) { if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
let is_option = move_ty.starts_with("std::option::Option"); let is_option = move_ty.starts_with("std::option::Option");
@ -454,7 +454,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} }
if binds_to.is_empty() { if binds_to.is_empty() {
let place_ty = move_from.ty(self.body_cache.body(), self.infcx.tcx).ty; let place_ty = move_from.ty(&self.body_cache, self.infcx.tcx).ty;
let place_desc = match self.describe_place(move_from.as_ref()) { let place_desc = match self.describe_place(move_from.as_ref()) {
Some(desc) => format!("`{}`", desc), Some(desc) => format!("`{}`", desc),
None => format!("value"), None => format!("value"),
@ -482,7 +482,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// No binding. Nothing to suggest. // No binding. Nothing to suggest.
GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => { GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
let span = use_spans.var_or_use(); let span = use_spans.var_or_use();
let place_ty = original_path.ty(self.body_cache.body(), self.infcx.tcx).ty; let place_ty = original_path.ty(&self.body_cache, self.infcx.tcx).ty;
let place_desc = match self.describe_place(original_path.as_ref()) { let place_desc = match self.describe_place(original_path.as_ref()) {
Some(desc) => format!("`{}`", desc), Some(desc) => format!("`{}`", desc),
None => format!("value"), None => format!("value"),

View file

@ -64,7 +64,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from( Place::ty_from(
&the_place_err.base, &the_place_err.base,
proj_base, proj_base,
self.body_cache.body(), &self.body_cache,
self.infcx.tcx self.infcx.tcx
).ty)); ).ty));
@ -115,7 +115,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from( Place::ty_from(
the_place_err.base, the_place_err.base,
the_place_err.projection, the_place_err.projection,
self.body_cache.body(), &self.body_cache,
self.infcx.tcx self.infcx.tcx
) )
.ty .ty
@ -229,7 +229,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let Some((span, message)) = annotate_struct_field( if let Some((span, message)) = annotate_struct_field(
self.infcx.tcx, self.infcx.tcx,
Place::ty_from(base, proj_base, self.body_cache.body(), self.infcx.tcx).ty, Place::ty_from(base, proj_base, &self.body_cache, self.infcx.tcx).ty,
field, field,
) { ) {
err.span_suggestion( err.span_suggestion(
@ -304,7 +304,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)], projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
} => { } => {
debug_assert!(is_closure_or_generator( debug_assert!(is_closure_or_generator(
Place::ty_from(base, proj_base, self.body_cache.body(), self.infcx.tcx).ty Place::ty_from(base, proj_base, &self.body_cache, self.infcx.tcx).ty
)); ));
err.span_label(span, format!("cannot {ACT}", ACT = act)); err.span_label(span, format!("cannot {ACT}", ACT = act));

View file

@ -237,7 +237,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
); );
let regioncx = &self.nonlexical_regioncx; let regioncx = &self.nonlexical_regioncx;
let body = self.body_cache.body(); let body: &Body<'_> = &self.body_cache;
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let borrow_region_vid = borrow.region; let borrow_region_vid = borrow.region;

View file

@ -38,7 +38,7 @@ pub(super) fn generate_invalidates<'tcx>(
param_env, param_env,
tcx, tcx,
location_table, location_table,
body: body_cache.body(), body: &body_cache,
dominators, dominators,
}; };
ig.visit_body(body_cache); ig.visit_body(body_cache);

View file

@ -181,7 +181,8 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
let universal_regions = Rc::new(universal_regions); let universal_regions = Rc::new(universal_regions);
let elements = &Rc::new(RegionValueElements::new(body_cache.body())); let elements
= &Rc::new(RegionValueElements::new(&body_cache));
// Run the MIR type-checker. // Run the MIR type-checker.
let MirTypeckResults { let MirTypeckResults {
@ -206,7 +207,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
all_facts all_facts
.universal_region .universal_region
.extend(universal_regions.universal_regions()); .extend(universal_regions.universal_regions());
populate_polonius_move_facts(all_facts, move_data, location_table, body_cache.body()); populate_polonius_move_facts(all_facts, move_data, location_table, &body_cache);
} }
// Create the region inference context, taking ownership of the // Create the region inference context, taking ownership of the
@ -230,7 +231,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
&mut liveness_constraints, &mut liveness_constraints,
&mut all_facts, &mut all_facts,
location_table, location_table,
body_cache.body(), &body_cache,
borrow_set, borrow_set,
); );
@ -239,7 +240,6 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
universal_regions, universal_regions,
placeholder_indices, placeholder_indices,
universal_region_relations, universal_region_relations,
body_cache.body(),
outlives_constraints, outlives_constraints,
member_constraints, member_constraints,
closure_bounds_mapping, closure_bounds_mapping,
@ -284,14 +284,14 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
// Solve the region constraints. // Solve the region constraints.
let closure_region_requirements = let closure_region_requirements =
regioncx.solve(infcx, body_cache.body(), local_names, upvars, def_id, errors_buffer); regioncx.solve(infcx, &body_cache, local_names, upvars, def_id, errors_buffer);
// Dump MIR results into a file, if that is enabled. This let us // Dump MIR results into a file, if that is enabled. This let us
// write unit-tests, as well as helping with debugging. // write unit-tests, as well as helping with debugging.
dump_mir_results( dump_mir_results(
infcx, infcx,
MirSource::item(def_id), MirSource::item(def_id),
body_cache.body(), &body_cache,
&regioncx, &regioncx,
&closure_region_requirements, &closure_region_requirements,
); );
@ -300,7 +300,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
// information // information
dump_annotation( dump_annotation(
infcx, infcx,
body_cache.body(), &body_cache,
def_id, def_id,
&regioncx, &regioncx,
&closure_region_requirements, &closure_region_requirements,

View file

@ -239,7 +239,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
universal_regions: Rc<UniversalRegions<'tcx>>, universal_regions: Rc<UniversalRegions<'tcx>>,
placeholder_indices: Rc<PlaceholderIndices>, placeholder_indices: Rc<PlaceholderIndices>,
universal_region_relations: Rc<UniversalRegionRelations<'tcx>>, universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
_body: &Body<'tcx>,
outlives_constraints: OutlivesConstraintSet, outlives_constraints: OutlivesConstraintSet,
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>, member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
closure_bounds_mapping: FxHashMap< closure_bounds_mapping: FxHashMap<

View file

@ -169,7 +169,7 @@ pub(crate) fn type_check<'tcx>(
&universal_region_relations, &universal_region_relations,
|mut cx| { |mut cx| {
cx.equate_inputs_and_outputs( cx.equate_inputs_and_outputs(
body_cache.body(), &body_cache,
universal_regions, universal_regions,
&normalized_inputs_and_output); &normalized_inputs_and_output);
liveness::generate( liveness::generate(
@ -201,7 +201,7 @@ fn type_check_internal<'a, 'tcx, R>(
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
universal_region_relations: &'a UniversalRegionRelations<'tcx>, universal_region_relations: &'a UniversalRegionRelations<'tcx>,
mut extra: impl FnMut(&mut TypeChecker<'a, 'tcx>) -> R, mut extra: impl FnMut(&mut TypeChecker<'a, 'tcx>) -> R,
) -> R where { ) -> R {
let mut checker = TypeChecker::new( let mut checker = TypeChecker::new(
infcx, infcx,
body_cache.body(), body_cache.body(),
@ -220,7 +220,7 @@ fn type_check_internal<'a, 'tcx, R>(
if !errors_reported { if !errors_reported {
// if verifier failed, don't do further checks to avoid ICEs // if verifier failed, don't do further checks to avoid ICEs
checker.typeck_mir(body_cache.body()); checker.typeck_mir(&body_cache);
} }
extra(&mut checker) extra(&mut checker)

View file

@ -11,7 +11,7 @@ use super::MirBorrowckCtxt;
use rustc::hir; use rustc::hir;
use rustc::ty::{self, TyCtxt}; use rustc::ty::{self, TyCtxt};
use rustc::mir::{Body, Place, PlaceBase, PlaceRef, ProjectionElem}; use rustc::mir::{Place, PlaceBase, PlaceRef, ProjectionElem, ReadOnlyBodyCache};
pub trait IsPrefixOf<'cx, 'tcx> { pub trait IsPrefixOf<'cx, 'tcx> {
fn is_prefix_of(&self, other: PlaceRef<'cx, 'tcx>) -> bool; fn is_prefix_of(&self, other: PlaceRef<'cx, 'tcx>) -> bool;
@ -26,7 +26,7 @@ impl<'cx, 'tcx> IsPrefixOf<'cx, 'tcx> for PlaceRef<'cx, 'tcx> {
} }
pub(super) struct Prefixes<'cx, 'tcx> { pub(super) struct Prefixes<'cx, 'tcx> {
body: &'cx Body<'tcx>, body_cache: ReadOnlyBodyCache<'cx, 'tcx>,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
kind: PrefixSet, kind: PrefixSet,
next: Option<PlaceRef<'cx, 'tcx>>, next: Option<PlaceRef<'cx, 'tcx>>,
@ -56,7 +56,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Prefixes { Prefixes {
next: Some(place_ref), next: Some(place_ref),
kind, kind,
body: self.body_cache.body(), body_cache: self.body_cache,
tcx: self.infcx.tcx, tcx: self.infcx.tcx,
} }
} }
@ -143,7 +143,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
// derefs, except we stop at the deref of a shared // derefs, except we stop at the deref of a shared
// reference. // reference.
let ty = Place::ty_from(cursor.base, proj_base, self.body, self.tcx).ty; let ty = Place::ty_from(cursor.base, proj_base, &self.body_cache, self.tcx).ty;
match ty.kind { match ty.kind {
ty::RawPtr(_) | ty::RawPtr(_) |
ty::Ref( ty::Ref(

View file

@ -1249,11 +1249,10 @@ fn collect_neighbours<'tcx>(
) { ) {
debug!("collect_neighbours: {:?}", instance.def_id()); debug!("collect_neighbours: {:?}", instance.def_id());
let body_cache = tcx.instance_mir(instance.def); let body_cache = tcx.instance_mir(instance.def);
let body = body_cache.body();
MirNeighborCollector { MirNeighborCollector {
tcx, tcx,
body: &body, body: &body_cache,
output, output,
param_substs: instance.substs, param_substs: instance.substs,
}.visit_body(body_cache); }.visit_body(body_cache);

View file

@ -113,7 +113,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
bug!("creating shims from intrinsics ({:?}) is unsupported", instance) bug!("creating shims from intrinsics ({:?}) is unsupported", instance)
} }
}; };
debug!("make_shim({:?}) = untransformed {:?}", instance, result.body()); debug!("make_shim({:?}) = untransformed {:?}", instance, result);
run_passes(tcx, &mut result, instance, None, MirPhase::Const, &[ run_passes(tcx, &mut result, instance, None, MirPhase::Const, &[
&add_moves_for_packed_drops::AddMovesForPackedDrops, &add_moves_for_packed_drops::AddMovesForPackedDrops,
@ -123,7 +123,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
&add_call_guards::CriticalCallEdges, &add_call_guards::CriticalCallEdges,
]); ]);
debug!("make_shim({:?}) = {:?}", instance, result.body()); debug!("make_shim({:?}) = {:?}", instance, result);
result.ensure_predecessors(); result.ensure_predecessors();
tcx.arena.alloc(result) tcx.arena.alloc(result)
@ -220,8 +220,8 @@ fn build_drop_shim<'tcx>(
let patch = { let patch = {
let param_env = tcx.param_env(def_id).with_reveal_all(); let param_env = tcx.param_env(def_id).with_reveal_all();
let mut elaborator = DropShimElaborator { let mut elaborator = DropShimElaborator {
body: body_cache.body(), body: &body_cache,
patch: MirPatch::new(body_cache.body()), patch: MirPatch::new(&body_cache),
tcx, tcx,
param_env param_env
}; };

View file

@ -529,7 +529,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
}; };
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body_cache, tcx, param_env); let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body_cache, tcx, param_env);
let mut cache = body_cache.cache().clone(); let mut cache = body_cache.cache().clone();
let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body_cache.body()); let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body_cache);
checker.visit_body(read_only_cache); checker.visit_body(read_only_cache);
check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);

View file

@ -487,7 +487,7 @@ fn locals_live_across_suspend_points(
) -> LivenessInfo { ) -> LivenessInfo {
let dead_unwinds = BitSet::new_empty(body_cache.basic_blocks().len()); let dead_unwinds = BitSet::new_empty(body_cache.basic_blocks().len());
let def_id = source.def_id(); let def_id = source.def_id();
let body = body_cache.body(); let body: &Body<'_> = &body_cache;
// Calculate when MIR locals have live storage. This gives us an upper bound of their // Calculate when MIR locals have live storage. This gives us an upper bound of their
// lifetimes. // lifetimes.
@ -932,7 +932,7 @@ fn create_generator_drop_shim<'tcx>(
) -> BodyCache<'tcx> { ) -> BodyCache<'tcx> {
let mut body_cache = body_cache.clone(); let mut body_cache = body_cache.clone();
let source_info = source_info(body_cache.body()); let source_info = source_info(&body_cache);
let mut cases = create_cases(&mut body_cache, transform, |point| point.drop); let mut cases = create_cases(&mut body_cache, transform, |point| point.drop);

View file

@ -448,7 +448,7 @@ impl Inliner<'tcx> {
BorrowKind::Mut { allow_two_phase_borrow: false }, BorrowKind::Mut { allow_two_phase_borrow: false },
destination.0); destination.0);
let ty = dest.ty(caller_body.body(), self.tcx); let ty = dest.ty(caller_body, self.tcx);
let temp = LocalDecl::new_temp(ty, callsite.location.span); let temp = LocalDecl::new_temp(ty, callsite.location.span);
@ -553,7 +553,7 @@ impl Inliner<'tcx> {
assert!(args.next().is_none()); assert!(args.next().is_none());
let tuple = Place::from(tuple); let tuple = Place::from(tuple);
let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body_cache.body(), tcx).ty.kind { let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body_cache, tcx).ty.kind {
s s
} else { } else {
bug!("Closure arguments are not passed as a tuple"); bug!("Closure arguments are not passed as a tuple");
@ -608,7 +608,7 @@ impl Inliner<'tcx> {
// Otherwise, create a temporary for the arg // Otherwise, create a temporary for the arg
let arg = Rvalue::Use(arg); let arg = Rvalue::Use(arg);
let ty = arg.ty(caller_body_cache.body(), self.tcx); let ty = arg.ty(caller_body_cache, self.tcx);
let arg_tmp = LocalDecl::new_temp(ty, callsite.location.span); let arg_tmp = LocalDecl::new_temp(ty, callsite.location.span);
let arg_tmp = caller_body_cache.local_decls.push(arg_tmp); let arg_tmp = caller_body_cache.local_decls.push(arg_tmp);

View file

@ -13,7 +13,7 @@ pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body_cache: &mut BodyCa
if tcx.sess.no_landing_pads() { if tcx.sess.no_landing_pads() {
return return
} }
debug!("remove_noop_landing_pads({:?})", body_cache.body()); debug!("remove_noop_landing_pads({:?})", body_cache);
RemoveNoopLandingPads.remove_nop_landing_pads(body_cache) RemoveNoopLandingPads.remove_nop_landing_pads(body_cache)
} }

View file

@ -58,15 +58,15 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
|_, i| DebugFormatted::new(&i)); |_, i| DebugFormatted::new(&i));
if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_init).is_some() { if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_init).is_some() {
sanity_check_via_rustc_peek(tcx, body_cache.body(), def_id, &attributes, &flow_inits); sanity_check_via_rustc_peek(tcx, body_cache, def_id, &attributes, &flow_inits);
} }
if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_uninit).is_some() { if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_uninit).is_some() {
sanity_check_via_rustc_peek(tcx, body_cache.body(), def_id, &attributes, &flow_uninits); sanity_check_via_rustc_peek(tcx, body_cache, def_id, &attributes, &flow_uninits);
} }
if has_rustc_mir_with(&attributes, sym::rustc_peek_definite_init).is_some() { if has_rustc_mir_with(&attributes, sym::rustc_peek_definite_init).is_some() {
sanity_check_via_rustc_peek( sanity_check_via_rustc_peek(
tcx, tcx,
body_cache.body(), body_cache,
def_id, def_id,
&attributes, &attributes,
&flow_def_inits); &flow_def_inits);
@ -74,7 +74,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
if has_rustc_mir_with(&attributes, sym::rustc_peek_indirectly_mutable).is_some() { if has_rustc_mir_with(&attributes, sym::rustc_peek_indirectly_mutable).is_some() {
sanity_check_via_rustc_peek( sanity_check_via_rustc_peek(
tcx, tcx,
body_cache.body(), body_cache,
def_id, def_id,
&attributes, &attributes,
&flow_indirectly_mut); &flow_indirectly_mut);

View file

@ -59,7 +59,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
fn run_pass( fn run_pass(
&self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body_cache: &mut BodyCache<'tcx> &self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body_cache: &mut BodyCache<'tcx>
) { ) {
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body_cache.body()); debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body_cache);
simplify_cfg(body_cache); simplify_cfg(body_cache);
} }
} }
@ -264,7 +264,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
pub fn remove_dead_blocks(body_cache: &mut BodyCache<'_>) { pub fn remove_dead_blocks(body_cache: &mut BodyCache<'_>) {
let mut seen = BitSet::new_empty(body_cache.basic_blocks().len()); let mut seen = BitSet::new_empty(body_cache.basic_blocks().len());
for (bb, _) in traversal::preorder(body_cache.body()) { for (bb, _) in traversal::preorder(body_cache) {
seen.insert(bb.index()); seen.insert(bb.index());
} }

View file

@ -223,7 +223,7 @@ impl<'tcx> MirPass<'tcx> for RestoreSubsliceArrayMoveOut<'tcx> {
let src_ty = Place::ty_from( let src_ty = Place::ty_from(
src_place.base, src_place.base,
src_place.projection, src_place.projection,
body_cache.body(), body_cache,
tcx tcx
).ty; ).ty;
if let ty::Array(_, ref size_o) = src_ty.kind { if let ty::Array(_, ref size_o) = src_ty.kind {

View file

@ -85,7 +85,7 @@ pub fn liveness_of_locals(
// any benefits. Benchmark this and find out. // any benefits. Benchmark this and find out.
let mut dirty_queue: WorkQueue<BasicBlock> let mut dirty_queue: WorkQueue<BasicBlock>
= WorkQueue::with_none(body_cache.basic_blocks().len()); = WorkQueue::with_none(body_cache.basic_blocks().len());
for (bb, _) in traversal::postorder(body_cache.body()) { for (bb, _) in traversal::postorder(&body_cache) {
dirty_queue.insert(bb); dirty_queue.insert(bb);
} }