Skip to content

Commit

Permalink
Rollup merge of rust-lang#72814 - RalfJung:mir-visir-terminator, r=ol…
Browse files Browse the repository at this point in the history
…i-obk

remove visit_terminator_kind from MIR visitor

For some reason, we had both `visit_terminator` and `visit_terminator_kind`. In contrast, for `Statement` we just have `visit_statement`. So this cleans things up by removing `visit_terminator_kind` and porting its users to `visit_terminator`.
  • Loading branch information
Dylan-DPC authored Jun 16, 2020
2 parents c8a9c34 + 827ccf7 commit 5d7a1ca
Show file tree
Hide file tree
Showing 27 changed files with 156 additions and 179 deletions.
6 changes: 3 additions & 3 deletions src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
self.visit_rvalue(rvalue, location);
}

fn visit_terminator_kind(&mut self, kind: &mir::TerminatorKind<'tcx>, location: Location) {
let check = match *kind {
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
let check = match terminator.kind {
mir::TerminatorKind::Call { func: mir::Operand::Constant(ref c), ref args, .. } => {
match c.literal.ty.kind {
ty::FnDef(did, _) => Some((did, args)),
Expand All @@ -259,7 +259,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
}
}

self.super_terminator_kind(kind, location);
self.super_terminator(terminator, location);
}

fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.unreachable();
}

mir::TerminatorKind::Drop { location, target, unwind } => {
self.codegen_drop_terminator(helper, bx, location, target, unwind);
mir::TerminatorKind::Drop { place, target, unwind } => {
self.codegen_drop_terminator(helper, bx, place, target, unwind);
}

mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ pub enum TerminatorKind<'tcx> {
Unreachable,

/// Drop the `Place`.
Drop { location: Place<'tcx>, target: BasicBlock, unwind: Option<BasicBlock> },
Drop { place: Place<'tcx>, target: BasicBlock, unwind: Option<BasicBlock> },

/// Drop the `Place` and assign the new value over it. This ensures
/// that the assignment to `P` occurs *even if* the destructor for
Expand Down Expand Up @@ -1141,7 +1141,7 @@ pub enum TerminatorKind<'tcx> {
/// }
/// ```
DropAndReplace {
location: Place<'tcx>,
place: Place<'tcx>,
value: Operand<'tcx>,
target: BasicBlock,
unwind: Option<BasicBlock>,
Expand Down Expand Up @@ -1607,9 +1607,9 @@ impl<'tcx> TerminatorKind<'tcx> {
Abort => write!(fmt, "abort"),
Yield { value, resume_arg, .. } => write!(fmt, "{:?} = yield({:?})", resume_arg, value),
Unreachable => write!(fmt, "unreachable"),
Drop { location, .. } => write!(fmt, "drop({:?})", location),
DropAndReplace { location, value, .. } => {
write!(fmt, "replace({:?} <- {:?})", location, value)
Drop { place, .. } => write!(fmt, "drop({:?})", place),
DropAndReplace { place, value, .. } => {
write!(fmt, "replace({:?} <- {:?})", place, value)
}
Call { func, args, destination, .. } => {
if let Some((destination, _)) = destination {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_middle/mir/type_foldable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
values: values.clone(),
targets: targets.clone(),
},
Drop { ref location, target, unwind } => {
Drop { location: location.fold_with(folder), target, unwind }
Drop { ref place, target, unwind } => {
Drop { place: place.fold_with(folder), target, unwind }
}
DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
location: location.fold_with(folder),
DropAndReplace { ref place, ref value, target, unwind } => DropAndReplace {
place: place.fold_with(folder),
value: value.fold_with(folder),
target,
unwind,
Expand Down Expand Up @@ -97,9 +97,9 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
SwitchInt { ref discr, switch_ty, .. } => {
discr.visit_with(visitor) || switch_ty.visit_with(visitor)
}
Drop { ref location, .. } => location.visit_with(visitor),
DropAndReplace { ref location, ref value, .. } => {
location.visit_with(visitor) || value.visit_with(visitor)
Drop { ref place, .. } => place.visit_with(visitor),
DropAndReplace { ref place, ref value, .. } => {
place.visit_with(visitor) || value.visit_with(visitor)
}
Yield { ref value, .. } => value.visit_with(visitor),
Call { ref func, ref args, ref destination, .. } => {
Expand Down
56 changes: 22 additions & 34 deletions src/librustc_middle/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ macro_rules! make_mir_visitor {
self.super_terminator(terminator, location);
}

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

fn visit_assert_message(&mut self,
msg: & $($mutability)? AssertMessage<'tcx>,
location: Location) {
Expand Down Expand Up @@ -417,12 +411,6 @@ macro_rules! make_mir_visitor {
let Terminator { source_info, kind } = terminator;

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

fn super_terminator_kind(&mut self,
kind: & $($mutability)? TerminatorKind<'tcx>,
source_location: Location) {
match kind {
TerminatorKind::Goto { .. } |
TerminatorKind::Resume |
Expand All @@ -440,7 +428,7 @@ macro_rules! make_mir_visitor {
self.visit_local(
& $($mutability)? local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
source_location,
location,
);

assert_eq!(
Expand All @@ -456,34 +444,34 @@ macro_rules! make_mir_visitor {
values: _,
targets: _
} => {
self.visit_operand(discr, source_location);
self.visit_ty(switch_ty, TyContext::Location(source_location));
self.visit_operand(discr, location);
self.visit_ty(switch_ty, TyContext::Location(location));
}

TerminatorKind::Drop {
location,
place,
target: _,
unwind: _,
} => {
self.visit_place(
location,
place,
PlaceContext::MutatingUse(MutatingUseContext::Drop),
source_location
location
);
}

TerminatorKind::DropAndReplace {
location,
place,
value,
target: _,
unwind: _,
} => {
self.visit_place(
location,
place,
PlaceContext::MutatingUse(MutatingUseContext::Drop),
source_location
location
);
self.visit_operand(value, source_location);
self.visit_operand(value, location);
}

TerminatorKind::Call {
Expand All @@ -494,15 +482,15 @@ macro_rules! make_mir_visitor {
from_hir_call: _,
fn_span: _
} => {
self.visit_operand(func, source_location);
self.visit_operand(func, location);
for arg in args {
self.visit_operand(arg, source_location);
self.visit_operand(arg, location);
}
if let Some((destination, _)) = destination {
self.visit_place(
destination,
PlaceContext::MutatingUse(MutatingUseContext::Call),
source_location
location
);
}
}
Expand All @@ -514,8 +502,8 @@ macro_rules! make_mir_visitor {
target: _,
cleanup: _,
} => {
self.visit_operand(cond, source_location);
self.visit_assert_message(msg, source_location);
self.visit_operand(cond, location);
self.visit_assert_message(msg, location);
}

TerminatorKind::Yield {
Expand All @@ -524,11 +512,11 @@ macro_rules! make_mir_visitor {
resume_arg,
drop: _,
} => {
self.visit_operand(value, source_location);
self.visit_operand(value, location);
self.visit_place(
resume_arg,
PlaceContext::MutatingUse(MutatingUseContext::Yield),
source_location,
location,
);
}

Expand All @@ -543,29 +531,29 @@ macro_rules! make_mir_visitor {
match op {
InlineAsmOperand::In { value, .. }
| InlineAsmOperand::Const { value } => {
self.visit_operand(value, source_location);
self.visit_operand(value, location);
}
InlineAsmOperand::Out { place, .. } => {
if let Some(place) = place {
self.visit_place(
place,
PlaceContext::MutatingUse(MutatingUseContext::Store),
source_location,
location,
);
}
}
InlineAsmOperand::InOut { in_value, out_place, .. } => {
self.visit_operand(in_value, source_location);
self.visit_operand(in_value, location);
if let Some(out_place) = out_place {
self.visit_place(
out_place,
PlaceContext::MutatingUse(MutatingUseContext::Store),
source_location,
location,
);
}
}
InlineAsmOperand::SymFn { value } => {
self.visit_constant(value, source_location);
self.visit_constant(value, location);
}
InlineAsmOperand::SymStatic { def_id: _ } => {}
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/borrow_check/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_data_structures::graph::dominators::Dominators;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{BasicBlock, Body, Location, Place, Rvalue};
use rustc_middle::mir::{BorrowKind, Mutability, Operand};
use rustc_middle::mir::{InlineAsmOperand, TerminatorKind};
use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
use rustc_middle::mir::{Statement, StatementKind};
use rustc_middle::ty::TyCtxt;

Expand Down Expand Up @@ -112,14 +112,14 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
self.super_statement(statement, location);
}

fn visit_terminator_kind(&mut self, kind: &TerminatorKind<'tcx>, location: Location) {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
self.check_activations(location);

match kind {
match &terminator.kind {
TerminatorKind::SwitchInt { ref discr, switch_ty: _, values: _, targets: _ } => {
self.consume_operand(location, discr);
}
TerminatorKind::Drop { location: drop_place, target: _, unwind: _ } => {
TerminatorKind::Drop { place: drop_place, target: _, unwind: _ } => {
self.access_place(
location,
*drop_place,
Expand All @@ -128,7 +128,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
);
}
TerminatorKind::DropAndReplace {
location: drop_place,
place: drop_place,
value: ref new_value,
target: _,
unwind: _,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
}
}

self.super_terminator_kind(kind, location);
self.super_terminator(terminator, location);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
TerminatorKind::SwitchInt { ref discr, switch_ty: _, values: _, targets: _ } => {
self.consume_operand(loc, (discr, span), flow_state);
}
TerminatorKind::Drop { location: ref drop_place, target: _, unwind: _ } => {
TerminatorKind::Drop { place: ref drop_place, target: _, unwind: _ } => {
let tcx = self.infcx.tcx;

// Compute the type with accurate region information.
Expand Down Expand Up @@ -692,7 +692,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
);
}
TerminatorKind::DropAndReplace {
location: drop_place,
place: drop_place,
value: ref new_value,
target: _,
unwind: _,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,8 +1558,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// no checks needed for these
}

TerminatorKind::DropAndReplace { ref location, ref value, target: _, unwind: _ } => {
let place_ty = location.ty(body, tcx).ty;
TerminatorKind::DropAndReplace { ref place, ref value, target: _, unwind: _ } => {
let place_ty = place.ty(body, tcx).ty;
let rv_ty = value.ty(body, tcx);

let locations = term_location.to_locations();
Expand Down
20 changes: 13 additions & 7 deletions src/librustc_mir/borrow_check/used_muts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{Local, Location, Place, Statement, StatementKind, TerminatorKind};
use rustc_middle::mir::{
Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind,
};

use rustc_data_structures::fx::FxHashSet;

Expand Down Expand Up @@ -62,20 +64,22 @@ impl GatherUsedMutsVisitor<'_, '_, '_> {
}

impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tcx> {
fn visit_terminator_kind(&mut self, kind: &TerminatorKind<'tcx>, _location: Location) {
debug!("visit_terminator_kind: kind={:?}", kind);
match &kind {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
debug!("visit_terminator: terminator={:?}", terminator);
match &terminator.kind {
TerminatorKind::Call { destination: Some((into, _)), .. } => {
self.remove_never_initialized_mut_locals(*into);
}
TerminatorKind::DropAndReplace { location, .. } => {
self.remove_never_initialized_mut_locals(*location);
TerminatorKind::DropAndReplace { place, .. } => {
self.remove_never_initialized_mut_locals(*place);
}
_ => {}
}

self.super_terminator(terminator, location);
}

fn visit_statement(&mut self, statement: &Statement<'tcx>, _location: Location) {
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
if let StatementKind::Assign(box (into, _)) = &statement.kind {
debug!(
"visit_statement: statement={:?} local={:?} \
Expand All @@ -84,6 +88,8 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc
);
self.remove_never_initialized_mut_locals(*into);
}

self.super_statement(statement, location);
}

fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/framework/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ impl Direction for Forward {
Goto { target } => propagate(target, exit_state),

Assert { target, cleanup: unwind, expected: _, msg: _, cond: _ }
| Drop { target, unwind, location: _ }
| DropAndReplace { target, unwind, value: _, location: _ }
| Drop { target, unwind, place: _ }
| DropAndReplace { target, unwind, value: _, place: _ }
| FalseUnwind { real_target: target, unwind } => {
if let Some(unwind) = unwind {
if dead_unwinds.map_or(true, |dead| !dead.contains(bb)) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ where
self.super_terminator(terminator, location);

match terminator.kind {
mir::TerminatorKind::Drop { location: dropped_place, .. }
| mir::TerminatorKind::DropAndReplace { location: dropped_place, .. } => {
mir::TerminatorKind::Drop { place: dropped_place, .. }
| mir::TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
// See documentation for `unsound_ignore_borrow_on_drop` for an explanation.
if !self.ignore_borrow_on_drop {
self.trans.gen(dropped_place.local);
Expand Down
Loading

0 comments on commit 5d7a1ca

Please sign in to comment.