Improved BodyCache body impl so it only returns a sharable ref, add new body_mut method, fix visit macros, simplify usage in codegen_ssa analyzer
This commit is contained in:
parent
30b1d9e798
commit
3d68f5f3e7
@ -132,7 +132,7 @@ impl<'a, 'tcx> BodyCache<&'a Body<'tcx>> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(&self) -> &Body<'tcx> {
|
||||
pub fn body(&self) -> &'a Body<'tcx> {
|
||||
self.body
|
||||
}
|
||||
|
||||
@ -149,7 +149,8 @@ impl<'a, 'tcx> BodyCache<&'a Body<'tcx>> {
|
||||
|
||||
impl<'a, 'tcx> Deref for BodyCache<&'a Body<'tcx>> {
|
||||
type Target = Body<'tcx>;
|
||||
fn deref(&self) -> &Body<'tcx> {
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.body
|
||||
}
|
||||
}
|
||||
@ -209,7 +210,12 @@ impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for BodyCache<&'a Body<'tcx>> {
|
||||
|
||||
impl<'a, 'tcx> BodyCache<&'a mut Body<'tcx>> {
|
||||
#[inline]
|
||||
pub fn body(&mut self) -> &mut Body<'tcx> {
|
||||
pub fn body(&self) -> &Body<'tcx> {
|
||||
self.body
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body_mut(&mut self) -> &mut Body<'tcx> {
|
||||
self.body
|
||||
}
|
||||
|
||||
@ -227,7 +233,7 @@ impl<'a, 'tcx> BodyCache<&'a mut Body<'tcx>> {
|
||||
impl<'a, 'tcx> Deref for BodyCache<&'a mut Body<'tcx>> {
|
||||
type Target = Body<'tcx>;
|
||||
|
||||
fn deref(&self) -> &Body<'tcx> {
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.body
|
||||
}
|
||||
}
|
||||
|
@ -247,8 +247,12 @@ macro_rules! make_mir_visitor {
|
||||
&mut self,
|
||||
body_cache: & $($mutability)? BodyCache<&'_ $($mutability)? Body<'tcx>>
|
||||
) {
|
||||
macro_rules! body {
|
||||
(mut) => (body_cache.body_mut());
|
||||
() => (body_cache.body());
|
||||
}
|
||||
let span = body_cache.body().span;
|
||||
if let Some(yield_ty) = &$($mutability)? body_cache.body().yield_ty {
|
||||
if let Some(yield_ty) = &$($mutability)? body!($($mutability)?).yield_ty {
|
||||
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
|
||||
span,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
@ -266,7 +270,7 @@ macro_rules! make_mir_visitor {
|
||||
self.visit_basic_block_data(bb, data);
|
||||
}
|
||||
|
||||
let body = body_cache.body();
|
||||
let body = body!($($mutability)?);
|
||||
for scope in &$($mutability)? body.source_scopes {
|
||||
self.visit_source_scope_data(scope);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc::mir::{self, BasicBlock, Body, BodyCache, Location, TerminatorKind};
|
||||
use rustc::mir::{self, Body, BodyCache, Location, TerminatorKind};
|
||||
use rustc::mir::visit::{
|
||||
Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext, NonUseContext,
|
||||
};
|
||||
@ -20,8 +20,7 @@ pub fn non_ssa_locals<'b, 'a: 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
fx: &mut FunctionCx<'a, 'tcx, Bx>,
|
||||
mir: &'b mut BodyCache<&'a Body<'tcx>>,
|
||||
) -> BitSet<mir::Local> {
|
||||
let dominators = mir.dominators();
|
||||
let mut analyzer = LocalAnalyzer::new(fx, mir, dominators);
|
||||
let mut analyzer = LocalAnalyzer::new(fx, mir);
|
||||
|
||||
analyzer.visit_body(mir);
|
||||
|
||||
@ -68,13 +67,15 @@ struct LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
|
||||
first_assignment: IndexVec<mir::Local, Location>,
|
||||
}
|
||||
|
||||
impl<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx> {
|
||||
fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>, mir: &'b Body<'tcx>, dominators: Dominators<BasicBlock>) -> Self {
|
||||
impl<'mir, 'a, 'b, 'c, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx> {
|
||||
fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>, mir: &'c mut BodyCache<&'b Body<'tcx>>) -> Self {
|
||||
let invalid_location =
|
||||
mir::BasicBlock::new(mir.basic_blocks().len()).start_location();
|
||||
let dominators = mir.dominators();
|
||||
let body = mir.body();
|
||||
let mut analyzer = LocalAnalyzer {
|
||||
fx,
|
||||
mir,
|
||||
mir: body,
|
||||
dominators,
|
||||
non_ssa_locals: BitSet::new_empty(mir.local_decls.len()),
|
||||
first_assignment: IndexVec::from_elem(invalid_location, &mir.local_decls)
|
||||
|
Loading…
x
Reference in New Issue
Block a user