1
Fork 0

Fix remaining Body -> (ReadOnly)BodyCache type errors in librustc_mir outside of librustc_mir/transform

This commit is contained in:
Paul Daniel Faria 2019-10-25 10:01:08 -04:00
parent 3642a71da2
commit 38c0887c76
2 changed files with 16 additions and 14 deletions

View file

@ -202,12 +202,14 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
sig.inputs().len(),
span);
let mut body_cache = BodyCache::new(&mut body);
if let Some(..) = ty {
// The first argument (index 0), but add 1 for the return value.
let dropee_ptr = Place::from(Local::new(1+0));
if tcx.sess.opts.debugging_opts.mir_emit_retag {
// Function arguments should be retagged, and we make this one raw.
body.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
body_cache.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
source_info,
kind: StatementKind::Retag(RetagKind::Raw, box(dropee_ptr.clone())),
});
@ -215,8 +217,8 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
let patch = {
let param_env = tcx.param_env(def_id).with_reveal_all();
let mut elaborator = DropShimElaborator {
body: &body,
patch: MirPatch::new(&body),
body: body_cache.body(),
patch: MirPatch::new(body_cache.body()),
tcx,
param_env
};
@ -233,9 +235,10 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
);
elaborator.patch
};
patch.apply(&mut body);
patch.apply(&mut body_cache);
}
// TODO(pfaia) return owning body cache...
body
}

View file

@ -1,6 +1,6 @@
//! Def-use analysis.
use rustc::mir::{Body, Local, Location, PlaceElem, VarDebugInfo};
use rustc::mir::{Body, BodyCache, Local, Location, PlaceElem, ReadOnlyBodyCache, VarDebugInfo};
use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor};
use rustc::ty::TyCtxt;
use rustc_index::vec::IndexVec;
@ -30,7 +30,7 @@ impl DefUseAnalysis {
}
}
pub fn analyze(&mut self, body: &Body<'_>) {
pub fn analyze(&mut self, body_cache: &ReadOnlyBodyCache<'_, '_>) {
self.clear();
let mut finder = DefUseFinder {
@ -38,7 +38,7 @@ impl DefUseAnalysis {
var_debug_info_index: 0,
in_var_debug_info: false,
};
finder.visit_body(body);
finder.visit_body(body_cache);
self.info = finder.info
}
@ -55,28 +55,28 @@ impl DefUseAnalysis {
fn mutate_defs_and_uses(
&self,
local: Local,
body: &mut Body<'tcx>,
body_cache: &mut BodyCache<&mut Body<'tcx>>,
new_local: Local,
tcx: TyCtxt<'tcx>,
) {
let mut visitor = MutateUseVisitor::new(local, new_local, body, tcx);
let mut visitor = MutateUseVisitor::new(local, new_local, tcx);
let info = &self.info[local];
for place_use in &info.defs_and_uses {
visitor.visit_location(body, place_use.location)
visitor.visit_location(body_cache, place_use.location)
}
// Update debuginfo as well, alongside defs/uses.
for &i in &info.var_debug_info_indices {
visitor.visit_var_debug_info(&mut body.var_debug_info[i]);
visitor.visit_var_debug_info(&mut body_cache.var_debug_info[i]);
}
}
// FIXME(pcwalton): this should update the def-use chains.
pub fn replace_all_defs_and_uses_with(&self,
local: Local,
body: &mut Body<'tcx>,
body_cache: &mut BodyCache<&mut Body<'tcx>>,
new_local: Local,
tcx: TyCtxt<'tcx>) {
self.mutate_defs_and_uses(local, body, new_local, tcx)
self.mutate_defs_and_uses(local, body_cache, new_local, tcx)
}
}
@ -156,7 +156,6 @@ impl MutateUseVisitor<'tcx> {
fn new(
query: Local,
new_local: Local,
_: &Body<'tcx>,
tcx: TyCtxt<'tcx>,
) -> MutateUseVisitor<'tcx> {
MutateUseVisitor { query, new_local, tcx }