Skip to content

Commit

Permalink
Remove BasicBlock parameter from mir visitor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Apr 26, 2019
1 parent 597f432 commit 0eeab6b
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 99 deletions.
35 changes: 14 additions & 21 deletions src/librustc/mir/visit.rs
Expand Up @@ -88,32 +88,28 @@ macro_rules! make_mir_visitor {
}

fn visit_statement(&mut self,
block: BasicBlock,
statement: & $($mutability)? Statement<'tcx>,
location: Location) {
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}

fn visit_assign(&mut self,
block: BasicBlock,
place: & $($mutability)? Place<'tcx>,
rvalue: & $($mutability)? Rvalue<'tcx>,
location: Location) {
self.super_assign(block, place, rvalue, location);
self.super_assign(place, rvalue, location);
}

fn visit_terminator(&mut self,
block: BasicBlock,
terminator: & $($mutability)? Terminator<'tcx>,
location: Location) {
self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}

fn visit_terminator_kind(&mut self,
block: BasicBlock,
kind: & $($mutability)? TerminatorKind<'tcx>,
location: Location) {
self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
}

fn visit_assert_message(&mut self,
Expand Down Expand Up @@ -327,13 +323,13 @@ macro_rules! make_mir_visitor {
let mut index = 0;
for statement in statements {
let location = Location { block: block, statement_index: index };
self.visit_statement(block, statement, location);
self.visit_statement(statement, location);
index += 1;
}

if let Some(terminator) = terminator {
let location = Location { block: block, statement_index: index };
self.visit_terminator(block, terminator, location);
self.visit_terminator(terminator, location);
}
}

Expand All @@ -350,7 +346,6 @@ macro_rules! make_mir_visitor {
}

fn super_statement(&mut self,
block: BasicBlock,
statement: & $($mutability)? Statement<'tcx>,
location: Location) {
let Statement {
Expand All @@ -361,7 +356,7 @@ macro_rules! make_mir_visitor {
self.visit_source_info(source_info);
match kind {
StatementKind::Assign(place, rvalue) => {
self.visit_assign(block, place, rvalue, location);
self.visit_assign(place, rvalue, location);
}
StatementKind::FakeRead(_, place) => {
self.visit_place(
Expand Down Expand Up @@ -415,7 +410,6 @@ macro_rules! make_mir_visitor {
}

fn super_assign(&mut self,
_block: BasicBlock,
place: &$($mutability)? Place<'tcx>,
rvalue: &$($mutability)? Rvalue<'tcx>,
location: Location) {
Expand All @@ -428,19 +422,18 @@ macro_rules! make_mir_visitor {
}

fn super_terminator(&mut self,
block: BasicBlock,
terminator: &$($mutability)? Terminator<'tcx>,
location: Location) {
let Terminator { source_info, kind } = terminator;

self.visit_source_info(source_info);
self.visit_terminator_kind(block, kind, location);
self.visit_terminator_kind(kind, location);
}

fn super_terminator_kind(&mut self,
block: BasicBlock,
kind: & $($mutability)? TerminatorKind<'tcx>,
source_location: Location) {
let block = source_location.block;
match kind {
TerminatorKind::Goto { target } => {
self.visit_branch(block, *target);
Expand Down Expand Up @@ -890,12 +883,12 @@ macro_rules! make_mir_visitor {
let basic_block = & $($mutability)? mir[location.block];
if basic_block.statements.len() == location.statement_index {
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
self.visit_terminator(location.block, terminator, location)
self.visit_terminator(terminator, location)
}
} else {
let statement = & $($mutability)?
basic_block.statements[location.statement_index];
self.visit_statement(location.block, statement, location)
self.visit_statement(statement, location)
}
}
}
Expand All @@ -912,21 +905,21 @@ pub trait MirVisitable<'tcx> {
impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_statement(location.block, self, location)
visitor.visit_statement(self, location)
}
}

impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_terminator(location.block, self, location)
visitor.visit_terminator(self, location)
}
}

impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_terminator(location.block, self.as_ref().unwrap(), location)
visitor.visit_terminator(self.as_ref().unwrap(), location)
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/librustc_codegen_ssa/mir/analyze.rs
Expand Up @@ -97,11 +97,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
for LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
fn visit_assign(&mut self,
block: mir::BasicBlock,
place: &mir::Place<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
location: Location) {
debug!("visit_assign(block={:?}, place={:?}, rvalue={:?})", block, place, rvalue);
debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);

if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
self.assign(index, location);
Expand All @@ -120,7 +119,6 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
}

fn visit_terminator_kind(&mut self,
block: mir::BasicBlock,
kind: &mir::TerminatorKind<'tcx>,
location: Location) {
let check = match *kind {
Expand Down Expand Up @@ -148,7 +146,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
}
}

self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
}

fn visit_place(&mut self,
Expand Down
12 changes: 1 addition & 11 deletions src/librustc_mir/borrow_check/borrow_set.rs
Expand Up @@ -184,7 +184,6 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
fn visit_assign(
&mut self,
block: mir::BasicBlock,
assigned_place: &mir::Place<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
location: mir::Location,
Expand Down Expand Up @@ -215,7 +214,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
}
}

self.super_assign(block, assigned_place, rvalue, location)
self.super_assign(assigned_place, rvalue, location)
}

fn visit_local(
Expand Down Expand Up @@ -287,15 +286,6 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {

return self.super_rvalue(rvalue, location);
}

fn visit_statement(
&mut self,
block: mir::BasicBlock,
statement: &mir::Statement<'tcx>,
location: Location,
) {
return self.super_statement(block, statement, location);
}
}

impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_mir/borrow_check/nll/constraint_generation.rs
Expand Up @@ -100,7 +100,6 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx

fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
Expand All @@ -117,12 +116,11 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
));
}

self.super_statement(block, statement, location);
self.super_statement(statement, location);
}

fn visit_assign(
&mut self,
block: BasicBlock,
place: &Place<'tcx>,
rvalue: &Rvalue<'tcx>,
location: Location,
Expand All @@ -141,12 +139,11 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
}
}

self.super_assign(block, place, rvalue, location);
self.super_assign(place, rvalue, location);
}

fn visit_terminator(
&mut self,
block: BasicBlock,
terminator: &Terminator<'tcx>,
location: Location,
) {
Expand All @@ -167,7 +164,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
}
}

self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}

fn visit_ascribe_user_ty(
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_mir/borrow_check/nll/invalidation.rs
Expand Up @@ -58,7 +58,6 @@ struct InvalidationGenerator<'cx, 'tcx: 'cx, 'gcx: 'tcx> {
impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
Expand Down Expand Up @@ -134,13 +133,12 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
}
}

self.super_statement(block, statement, location);
self.super_statement(statement, location);
}

fn visit_terminator(
&mut self,
block: BasicBlock,
terminator: &Terminator<'tcx>,
kind: &Terminator<'tcx>,
location: Location
) {
self.check_activations(location);
Expand Down Expand Up @@ -258,7 +256,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
}
}

self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/borrow_check/used_muts.rs
@@ -1,6 +1,6 @@
use rustc::mir::visit::{PlaceContext, Visitor};
use rustc::mir::{
BasicBlock, Local, Location, Place, PlaceBase, Statement, StatementKind, TerminatorKind
Local, Location, Place, PlaceBase, Statement, StatementKind, TerminatorKind
};

use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -55,7 +55,6 @@ struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'gcx: 'tcx, 'tcx: 'cx> {
impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'gcx, 'tcx> {
fn visit_terminator_kind(
&mut self,
_block: BasicBlock,
kind: &TerminatorKind<'tcx>,
_location: Location,
) {
Expand All @@ -77,7 +76,6 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c

fn visit_statement(
&mut self,
_block: BasicBlock,
statement: &Statement<'tcx>,
_location: Location,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/impls/borrowed_locals.rs
Expand Up @@ -44,7 +44,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {

BorrowedLocalsVisitor {
sets,
}.visit_statement(loc.block, stmt, loc);
}.visit_statement(stmt, loc);

// StorageDead invalidates all borrows and raw pointers to a local
match stmt.kind {
Expand All @@ -58,7 +58,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {
loc: Location) {
BorrowedLocalsVisitor {
sets,
}.visit_terminator(loc.block, self.mir[loc.block].terminator(), loc);
}.visit_terminator(self.mir[loc.block].terminator(), loc);
}

fn propagate_call_return(
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/monomorphize/collector.rs
Expand Up @@ -615,7 +615,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
}

fn visit_terminator_kind(&mut self,
block: mir::BasicBlock,
kind: &mir::TerminatorKind<'tcx>,
location: Location) {
debug!("visiting terminator {:?} @ {:?}", kind, location);
Expand Down Expand Up @@ -654,7 +653,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
mir::TerminatorKind::FalseUnwind { .. } => bug!(),
}

self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
}

fn visit_place(&mut self,
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/transform/check_unsafety.rs
Expand Up @@ -65,7 +65,6 @@ impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> {

impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
fn visit_terminator(&mut self,
block: BasicBlock,
terminator: &Terminator<'tcx>,
location: Location)
{
Expand Down Expand Up @@ -97,11 +96,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}
}
}
self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}

fn visit_statement(&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location)
{
Expand All @@ -124,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
UnsafetyViolationKind::General)
},
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}

fn visit_rvalue(&mut self,
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_mir/transform/cleanup_post_borrowck.rs
Expand Up @@ -16,7 +16,7 @@
//! [`FakeRead`]: rustc::mir::StatementKind::FakeRead
//! [`Nop`]: rustc::mir::StatementKind::Nop

use rustc::mir::{BasicBlock, BorrowKind, Rvalue, Location, Mir};
use rustc::mir::{BorrowKind, Rvalue, Location, Mir};
use rustc::mir::{Statement, StatementKind};
use rustc::mir::visit::MutVisitor;
use rustc::ty::TyCtxt;
Expand All @@ -38,7 +38,6 @@ impl MirPass for CleanupNonCodegenStatements {

impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements {
fn visit_statement(&mut self,
block: BasicBlock,
statement: &mut Statement<'tcx>,
location: Location) {
match statement.kind {
Expand All @@ -47,6 +46,6 @@ impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements {
| StatementKind::FakeRead(..) => statement.make_nop(),
_ => (),
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
}

0 comments on commit 0eeab6b

Please sign in to comment.