diff options
| author | Paul Daniel Faria <Nashenas88@users.noreply.github.com> | 2019-10-14 00:46:56 -0400 |
|---|---|---|
| committer | Paul Daniel Faria <Nashenas88@users.noreply.github.com> | 2019-12-02 08:30:30 -0500 |
| commit | 3d68f5f3e775b5854c40e1ad1433a8a7c8c53e1f (patch) | |
| tree | bc22028f3861c5879fbb76169ca40b96c96f789f | |
| parent | 30b1d9e79861dcc40cfcfcf7faf5a890369f9693 (diff) | |
| download | rust-3d68f5f3e775b5854c40e1ad1433a8a7c8c53e1f.tar.gz rust-3d68f5f3e775b5854c40e1ad1433a8a7c8c53e1f.zip | |
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
| -rw-r--r-- | src/librustc/mir/cache.rs | 14 | ||||
| -rw-r--r-- | src/librustc/mir/visit.rs | 8 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/analyze.rs | 13 |
3 files changed, 23 insertions, 12 deletions
diff --git a/src/librustc/mir/cache.rs b/src/librustc/mir/cache.rs index e218931b749..103b24ecf61 100644 --- a/src/librustc/mir/cache.rs +++ b/src/librustc/mir/cache.rs @@ -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 } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 5803663bbec..aa3aeb36e06 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -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); } diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 68d5eec9b25..2f45bf0ae74 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -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) |
