Skip to content

Commit be8fe77

Browse files
authored
Rollup merge of rust-lang#72814 - RalfJung:mir-visir-terminator, r=oli-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`.
2 parents 32b4084 + 827ccf7 commit be8fe77

27 files changed

+156
-179
lines changed

src/librustc_codegen_ssa/mir/analyze.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
234234
self.visit_rvalue(rvalue, location);
235235
}
236236

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

262-
self.super_terminator_kind(kind, location);
262+
self.super_terminator(terminator, location);
263263
}
264264

265265
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {

src/librustc_codegen_ssa/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
998998
bx.unreachable();
999999
}
10001000

1001-
mir::TerminatorKind::Drop { location, target, unwind } => {
1002-
self.codegen_drop_terminator(helper, bx, location, target, unwind);
1001+
mir::TerminatorKind::Drop { place, target, unwind } => {
1002+
self.codegen_drop_terminator(helper, bx, place, target, unwind);
10031003
}
10041004

10051005
mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => {

src/librustc_middle/mir/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ pub enum TerminatorKind<'tcx> {
11121112
Unreachable,
11131113

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

11171117
/// Drop the `Place` and assign the new value over it. This ensures
11181118
/// that the assignment to `P` occurs *even if* the destructor for
@@ -1141,7 +1141,7 @@ pub enum TerminatorKind<'tcx> {
11411141
/// }
11421142
/// ```
11431143
DropAndReplace {
1144-
location: Place<'tcx>,
1144+
place: Place<'tcx>,
11451145
value: Operand<'tcx>,
11461146
target: BasicBlock,
11471147
unwind: Option<BasicBlock>,
@@ -1607,9 +1607,9 @@ impl<'tcx> TerminatorKind<'tcx> {
16071607
Abort => write!(fmt, "abort"),
16081608
Yield { value, resume_arg, .. } => write!(fmt, "{:?} = yield({:?})", resume_arg, value),
16091609
Unreachable => write!(fmt, "unreachable"),
1610-
Drop { location, .. } => write!(fmt, "drop({:?})", location),
1611-
DropAndReplace { location, value, .. } => {
1612-
write!(fmt, "replace({:?} <- {:?})", location, value)
1610+
Drop { place, .. } => write!(fmt, "drop({:?})", place),
1611+
DropAndReplace { place, value, .. } => {
1612+
write!(fmt, "replace({:?} <- {:?})", place, value)
16131613
}
16141614
Call { func, args, destination, .. } => {
16151615
if let Some((destination, _)) = destination {

src/librustc_middle/mir/type_foldable.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
2727
values: values.clone(),
2828
targets: targets.clone(),
2929
},
30-
Drop { ref location, target, unwind } => {
31-
Drop { location: location.fold_with(folder), target, unwind }
30+
Drop { ref place, target, unwind } => {
31+
Drop { place: place.fold_with(folder), target, unwind }
3232
}
33-
DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
34-
location: location.fold_with(folder),
33+
DropAndReplace { ref place, ref value, target, unwind } => DropAndReplace {
34+
place: place.fold_with(folder),
3535
value: value.fold_with(folder),
3636
target,
3737
unwind,
@@ -97,9 +97,9 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
9797
SwitchInt { ref discr, switch_ty, .. } => {
9898
discr.visit_with(visitor) || switch_ty.visit_with(visitor)
9999
}
100-
Drop { ref location, .. } => location.visit_with(visitor),
101-
DropAndReplace { ref location, ref value, .. } => {
102-
location.visit_with(visitor) || value.visit_with(visitor)
100+
Drop { ref place, .. } => place.visit_with(visitor),
101+
DropAndReplace { ref place, ref value, .. } => {
102+
place.visit_with(visitor) || value.visit_with(visitor)
103103
}
104104
Yield { ref value, .. } => value.visit_with(visitor),
105105
Call { ref func, ref args, ref destination, .. } => {

src/librustc_middle/mir/visit.rs

+22-34
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ macro_rules! make_mir_visitor {
108108
self.super_terminator(terminator, location);
109109
}
110110

111-
fn visit_terminator_kind(&mut self,
112-
kind: & $($mutability)? TerminatorKind<'tcx>,
113-
location: Location) {
114-
self.super_terminator_kind(kind, location);
115-
}
116-
117111
fn visit_assert_message(&mut self,
118112
msg: & $($mutability)? AssertMessage<'tcx>,
119113
location: Location) {
@@ -417,12 +411,6 @@ macro_rules! make_mir_visitor {
417411
let Terminator { source_info, kind } = terminator;
418412

419413
self.visit_source_info(source_info);
420-
self.visit_terminator_kind(kind, location);
421-
}
422-
423-
fn super_terminator_kind(&mut self,
424-
kind: & $($mutability)? TerminatorKind<'tcx>,
425-
source_location: Location) {
426414
match kind {
427415
TerminatorKind::Goto { .. } |
428416
TerminatorKind::Resume |
@@ -440,7 +428,7 @@ macro_rules! make_mir_visitor {
440428
self.visit_local(
441429
& $($mutability)? local,
442430
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
443-
source_location,
431+
location,
444432
);
445433

446434
assert_eq!(
@@ -456,34 +444,34 @@ macro_rules! make_mir_visitor {
456444
values: _,
457445
targets: _
458446
} => {
459-
self.visit_operand(discr, source_location);
460-
self.visit_ty(switch_ty, TyContext::Location(source_location));
447+
self.visit_operand(discr, location);
448+
self.visit_ty(switch_ty, TyContext::Location(location));
461449
}
462450

463451
TerminatorKind::Drop {
464-
location,
452+
place,
465453
target: _,
466454
unwind: _,
467455
} => {
468456
self.visit_place(
469-
location,
457+
place,
470458
PlaceContext::MutatingUse(MutatingUseContext::Drop),
471-
source_location
459+
location
472460
);
473461
}
474462

475463
TerminatorKind::DropAndReplace {
476-
location,
464+
place,
477465
value,
478466
target: _,
479467
unwind: _,
480468
} => {
481469
self.visit_place(
482-
location,
470+
place,
483471
PlaceContext::MutatingUse(MutatingUseContext::Drop),
484-
source_location
472+
location
485473
);
486-
self.visit_operand(value, source_location);
474+
self.visit_operand(value, location);
487475
}
488476

489477
TerminatorKind::Call {
@@ -494,15 +482,15 @@ macro_rules! make_mir_visitor {
494482
from_hir_call: _,
495483
fn_span: _
496484
} => {
497-
self.visit_operand(func, source_location);
485+
self.visit_operand(func, location);
498486
for arg in args {
499-
self.visit_operand(arg, source_location);
487+
self.visit_operand(arg, location);
500488
}
501489
if let Some((destination, _)) = destination {
502490
self.visit_place(
503491
destination,
504492
PlaceContext::MutatingUse(MutatingUseContext::Call),
505-
source_location
493+
location
506494
);
507495
}
508496
}
@@ -514,8 +502,8 @@ macro_rules! make_mir_visitor {
514502
target: _,
515503
cleanup: _,
516504
} => {
517-
self.visit_operand(cond, source_location);
518-
self.visit_assert_message(msg, source_location);
505+
self.visit_operand(cond, location);
506+
self.visit_assert_message(msg, location);
519507
}
520508

521509
TerminatorKind::Yield {
@@ -524,11 +512,11 @@ macro_rules! make_mir_visitor {
524512
resume_arg,
525513
drop: _,
526514
} => {
527-
self.visit_operand(value, source_location);
515+
self.visit_operand(value, location);
528516
self.visit_place(
529517
resume_arg,
530518
PlaceContext::MutatingUse(MutatingUseContext::Yield),
531-
source_location,
519+
location,
532520
);
533521
}
534522

@@ -543,29 +531,29 @@ macro_rules! make_mir_visitor {
543531
match op {
544532
InlineAsmOperand::In { value, .. }
545533
| InlineAsmOperand::Const { value } => {
546-
self.visit_operand(value, source_location);
534+
self.visit_operand(value, location);
547535
}
548536
InlineAsmOperand::Out { place, .. } => {
549537
if let Some(place) = place {
550538
self.visit_place(
551539
place,
552540
PlaceContext::MutatingUse(MutatingUseContext::Store),
553-
source_location,
541+
location,
554542
);
555543
}
556544
}
557545
InlineAsmOperand::InOut { in_value, out_place, .. } => {
558-
self.visit_operand(in_value, source_location);
546+
self.visit_operand(in_value, location);
559547
if let Some(out_place) = out_place {
560548
self.visit_place(
561549
out_place,
562550
PlaceContext::MutatingUse(MutatingUseContext::Store),
563-
source_location,
551+
location,
564552
);
565553
}
566554
}
567555
InlineAsmOperand::SymFn { value } => {
568-
self.visit_constant(value, source_location);
556+
self.visit_constant(value, location);
569557
}
570558
InlineAsmOperand::SymStatic { def_id: _ } => {}
571559
}

src/librustc_mir/borrow_check/invalidation.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_data_structures::graph::dominators::Dominators;
22
use rustc_middle::mir::visit::Visitor;
33
use rustc_middle::mir::{BasicBlock, Body, Location, Place, Rvalue};
44
use rustc_middle::mir::{BorrowKind, Mutability, Operand};
5-
use rustc_middle::mir::{InlineAsmOperand, TerminatorKind};
5+
use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
66
use rustc_middle::mir::{Statement, StatementKind};
77
use rustc_middle::ty::TyCtxt;
88

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

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

118-
match kind {
118+
match &terminator.kind {
119119
TerminatorKind::SwitchInt { ref discr, switch_ty: _, values: _, targets: _ } => {
120120
self.consume_operand(location, discr);
121121
}
122-
TerminatorKind::Drop { location: drop_place, target: _, unwind: _ } => {
122+
TerminatorKind::Drop { place: drop_place, target: _, unwind: _ } => {
123123
self.access_place(
124124
location,
125125
*drop_place,
@@ -128,7 +128,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
128128
);
129129
}
130130
TerminatorKind::DropAndReplace {
131-
location: drop_place,
131+
place: drop_place,
132132
value: ref new_value,
133133
target: _,
134134
unwind: _,
@@ -222,7 +222,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
222222
}
223223
}
224224

225-
self.super_terminator_kind(kind, location);
225+
self.super_terminator(terminator, location);
226226
}
227227
}
228228

src/librustc_mir/borrow_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
663663
TerminatorKind::SwitchInt { ref discr, switch_ty: _, values: _, targets: _ } => {
664664
self.consume_operand(loc, (discr, span), flow_state);
665665
}
666-
TerminatorKind::Drop { location: ref drop_place, target: _, unwind: _ } => {
666+
TerminatorKind::Drop { place: ref drop_place, target: _, unwind: _ } => {
667667
let tcx = self.infcx.tcx;
668668

669669
// Compute the type with accurate region information.
@@ -692,7 +692,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
692692
);
693693
}
694694
TerminatorKind::DropAndReplace {
695-
location: drop_place,
695+
place: drop_place,
696696
value: ref new_value,
697697
target: _,
698698
unwind: _,

src/librustc_mir/borrow_check/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1558,8 +1558,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15581558
// no checks needed for these
15591559
}
15601560

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

15651565
let locations = term_location.to_locations();

src/librustc_mir/borrow_check/used_muts.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc_middle::mir::visit::{PlaceContext, Visitor};
2-
use rustc_middle::mir::{Local, Location, Place, Statement, StatementKind, TerminatorKind};
2+
use rustc_middle::mir::{
3+
Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind,
4+
};
35

46
use rustc_data_structures::fx::FxHashSet;
57

@@ -62,20 +64,22 @@ impl GatherUsedMutsVisitor<'_, '_, '_> {
6264
}
6365

6466
impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tcx> {
65-
fn visit_terminator_kind(&mut self, kind: &TerminatorKind<'tcx>, _location: Location) {
66-
debug!("visit_terminator_kind: kind={:?}", kind);
67-
match &kind {
67+
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
68+
debug!("visit_terminator: terminator={:?}", terminator);
69+
match &terminator.kind {
6870
TerminatorKind::Call { destination: Some((into, _)), .. } => {
6971
self.remove_never_initialized_mut_locals(*into);
7072
}
71-
TerminatorKind::DropAndReplace { location, .. } => {
72-
self.remove_never_initialized_mut_locals(*location);
73+
TerminatorKind::DropAndReplace { place, .. } => {
74+
self.remove_never_initialized_mut_locals(*place);
7375
}
7476
_ => {}
7577
}
78+
79+
self.super_terminator(terminator, location);
7680
}
7781

78-
fn visit_statement(&mut self, statement: &Statement<'tcx>, _location: Location) {
82+
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
7983
if let StatementKind::Assign(box (into, _)) = &statement.kind {
8084
debug!(
8185
"visit_statement: statement={:?} local={:?} \
@@ -84,6 +88,8 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc
8488
);
8589
self.remove_never_initialized_mut_locals(*into);
8690
}
91+
92+
self.super_statement(statement, location);
8793
}
8894

8995
fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) {

src/librustc_mir/dataflow/framework/direction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ impl Direction for Forward {
441441
Goto { target } => propagate(target, exit_state),
442442

443443
Assert { target, cleanup: unwind, expected: _, msg: _, cond: _ }
444-
| Drop { target, unwind, location: _ }
445-
| DropAndReplace { target, unwind, value: _, location: _ }
444+
| Drop { target, unwind, place: _ }
445+
| DropAndReplace { target, unwind, value: _, place: _ }
446446
| FalseUnwind { real_target: target, unwind } => {
447447
if let Some(unwind) = unwind {
448448
if dead_unwinds.map_or(true, |dead| !dead.contains(bb)) {

src/librustc_mir/dataflow/impls/borrowed_locals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ where
189189
self.super_terminator(terminator, location);
190190

191191
match terminator.kind {
192-
mir::TerminatorKind::Drop { location: dropped_place, .. }
193-
| mir::TerminatorKind::DropAndReplace { location: dropped_place, .. } => {
192+
mir::TerminatorKind::Drop { place: dropped_place, .. }
193+
| mir::TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
194194
// See documentation for `unsound_ignore_borrow_on_drop` for an explanation.
195195
if !self.ignore_borrow_on_drop {
196196
self.trans.gen(dropped_place.local);

0 commit comments

Comments
 (0)