Make TerminatorEdge plural.

This commit is contained in:
Camille GILLOT 2023-05-27 16:27:04 +00:00
parent 6cf15d4cb5
commit 388f6a6413
12 changed files with 59 additions and 59 deletions

View File

@ -3,7 +3,7 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{
self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdge,
self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdges,
};
use rustc_middle::ty::RegionVid;
use rustc_middle::ty::TyCtxt;
@ -411,7 +411,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
if let mir::TerminatorKind::InlineAsm { operands, .. } = &terminator.kind {
for op in operands {
if let mir::InlineAsmOperand::Out { place: Some(place), .. }

View File

@ -5,7 +5,7 @@
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{
self, BasicBlock, CallReturnPlaces, Local, Location, Statement, StatementKind, TerminatorEdge,
self, BasicBlock, CallReturnPlaces, Local, Location, Statement, StatementKind, TerminatorEdges,
};
use rustc_mir_dataflow::fmt::DebugWithContext;
use rustc_mir_dataflow::JoinSemiLattice;
@ -352,7 +352,7 @@ where
state: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
self.transfer_function(state).visit_terminator(terminator, location);
terminator.edges()
}

View File

@ -433,7 +433,7 @@ impl<'tcx> TerminatorKind<'tcx> {
}
#[derive(Copy, Clone, Debug)]
pub enum TerminatorEdge<'mir, 'tcx> {
pub enum TerminatorEdges<'mir, 'tcx> {
/// For terminators that have no successor, like `return`.
None,
/// For terminators that a single successor, like `goto`, and `assert` without cleanup block.
@ -451,7 +451,7 @@ pub enum TerminatorEdge<'mir, 'tcx> {
}
/// List of places that are written to after a successful (non-unwind) return
/// from a `Call` or `InlineAsm`.
/// from a `Call`, `Yield` or `InlineAsm`.
#[derive(Copy, Clone, Debug)]
pub enum CallReturnPlaces<'a, 'tcx> {
Call(Place<'tcx>),
@ -477,34 +477,34 @@ impl<'tcx> CallReturnPlaces<'_, 'tcx> {
}
impl<'tcx> Terminator<'tcx> {
pub fn edges(&self) -> TerminatorEdge<'_, 'tcx> {
pub fn edges(&self) -> TerminatorEdges<'_, 'tcx> {
self.kind.edges()
}
}
impl<'tcx> TerminatorKind<'tcx> {
pub fn edges(&self) -> TerminatorEdge<'_, 'tcx> {
pub fn edges(&self) -> TerminatorEdges<'_, 'tcx> {
use TerminatorKind::*;
match *self {
Return | Resume | Terminate | GeneratorDrop | Unreachable => TerminatorEdge::None,
Return | Resume | Terminate | GeneratorDrop | Unreachable => TerminatorEdges::None,
Goto { target } => TerminatorEdge::Single(target),
Goto { target } => TerminatorEdges::Single(target),
Assert { target, unwind, expected: _, msg: _, cond: _ }
| Drop { target, unwind, place: _, replace: _ }
| FalseUnwind { real_target: target, unwind } => match unwind {
UnwindAction::Cleanup(unwind) => TerminatorEdge::Double(target, unwind),
UnwindAction::Cleanup(unwind) => TerminatorEdges::Double(target, unwind),
UnwindAction::Continue | UnwindAction::Terminate | UnwindAction::Unreachable => {
TerminatorEdge::Single(target)
TerminatorEdges::Single(target)
}
},
FalseEdge { real_target, imaginary_target } => {
TerminatorEdge::Double(real_target, imaginary_target)
TerminatorEdges::Double(real_target, imaginary_target)
}
Yield { resume: target, drop, resume_arg, value: _ } => {
TerminatorEdge::AssignOnReturn {
TerminatorEdges::AssignOnReturn {
return_: Some(target),
unwind: drop.map_or(UnwindAction::Terminate, UnwindAction::Cleanup),
place: CallReturnPlaces::Yield(resume_arg),
@ -512,7 +512,7 @@ impl<'tcx> TerminatorKind<'tcx> {
}
Call { unwind, destination, target, func: _, args: _, fn_span: _, call_source: _ } => {
TerminatorEdge::AssignOnReturn {
TerminatorEdges::AssignOnReturn {
return_: target,
unwind,
place: CallReturnPlaces::Call(destination),
@ -526,13 +526,13 @@ impl<'tcx> TerminatorKind<'tcx> {
line_spans: _,
destination,
unwind,
} => TerminatorEdge::AssignOnReturn {
} => TerminatorEdges::AssignOnReturn {
return_: destination,
unwind,
place: CallReturnPlaces::InlineAsm(operands),
},
SwitchInt { ref targets, ref discr } => TerminatorEdge::SwitchInt { targets, discr },
SwitchInt { ref targets, ref discr } => TerminatorEdges::SwitchInt { targets, discr },
}
}
}

View File

@ -1,5 +1,5 @@
use rustc_middle::mir::{
self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdge, UnwindAction,
self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdges, UnwindAction,
};
use std::ops::RangeInclusive;
@ -29,7 +29,7 @@ pub trait Direction {
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
statement_effect: Option<&dyn Fn(BasicBlock, &mut A::Domain)>,
) -> TerminatorEdge<'mir, 'tcx>
) -> TerminatorEdges<'mir, 'tcx>
where
A: Analysis<'tcx>;
@ -55,7 +55,7 @@ pub trait Direction {
body: &mir::Body<'tcx>,
exit_state: &mut A::Domain,
block: BasicBlock,
edges: TerminatorEdge<'_, 'tcx>,
edges: TerminatorEdges<'_, 'tcx>,
propagate: impl FnMut(BasicBlock, &A::Domain),
) where
A: Analysis<'tcx>;
@ -73,7 +73,7 @@ impl Direction for Backward {
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
statement_effect: Option<&dyn Fn(BasicBlock, &mut A::Domain)>,
) -> TerminatorEdge<'mir, 'tcx>
) -> TerminatorEdges<'mir, 'tcx>
where
A: Analysis<'tcx>,
{
@ -222,7 +222,7 @@ impl Direction for Backward {
body: &mir::Body<'tcx>,
exit_state: &mut A::Domain,
bb: BasicBlock,
_edges: TerminatorEdge<'_, 'tcx>,
_edges: TerminatorEdges<'_, 'tcx>,
mut propagate: impl FnMut(BasicBlock, &A::Domain),
) where
A: Analysis<'tcx>,
@ -330,7 +330,7 @@ impl Direction for Forward {
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
statement_effect: Option<&dyn Fn(BasicBlock, &mut A::Domain)>,
) -> TerminatorEdge<'mir, 'tcx>
) -> TerminatorEdges<'mir, 'tcx>
where
A: Analysis<'tcx>,
{
@ -474,19 +474,19 @@ impl Direction for Forward {
_body: &mir::Body<'tcx>,
exit_state: &mut A::Domain,
bb: BasicBlock,
edges: TerminatorEdge<'_, 'tcx>,
edges: TerminatorEdges<'_, 'tcx>,
mut propagate: impl FnMut(BasicBlock, &A::Domain),
) where
A: Analysis<'tcx>,
{
match edges {
TerminatorEdge::None => {}
TerminatorEdge::Single(target) => propagate(target, exit_state),
TerminatorEdge::Double(target, unwind) => {
TerminatorEdges::None => {}
TerminatorEdges::Single(target) => propagate(target, exit_state),
TerminatorEdges::Double(target, unwind) => {
propagate(target, exit_state);
propagate(unwind, exit_state);
}
TerminatorEdge::AssignOnReturn { return_, unwind, place } => {
TerminatorEdges::AssignOnReturn { return_, unwind, place } => {
// This must be done *first*, otherwise the unwind path will see the assignments.
if let UnwindAction::Cleanup(unwind) = unwind {
propagate(unwind, exit_state);
@ -496,7 +496,7 @@ impl Direction for Forward {
propagate(return_, exit_state);
}
}
TerminatorEdge::SwitchInt { targets, discr } => {
TerminatorEdges::SwitchInt { targets, discr } => {
let mut applier = ForwardSwitchIntEdgeEffectsApplier {
exit_state,
targets,

View File

@ -34,7 +34,7 @@ use std::cmp::Ordering;
use rustc_index::bit_set::{BitSet, ChunkedBitSet, HybridBitSet};
use rustc_index::Idx;
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdge};
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges};
use rustc_middle::ty::TyCtxt;
mod cursor;
@ -168,7 +168,7 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
state: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx>;
) -> TerminatorEdges<'mir, 'tcx>;
/// Updates the current dataflow state with an effect that occurs immediately *before* the
/// given terminator.
@ -297,7 +297,7 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx>;
) -> TerminatorEdges<'mir, 'tcx>;
/// See `Analysis::apply_before_terminator_effect`.
fn before_terminator_effect(
@ -356,7 +356,7 @@ where
state: &mut A::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
self.terminator_effect(state, terminator, location)
}

View File

@ -203,7 +203,7 @@ impl<'tcx, D: Direction> Analysis<'tcx> for MockAnalysis<'tcx, D> {
state: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
let idx = self.effect(Effect::Primary.at_index(location.statement_index));
assert!(state.insert(idx));
terminator.edges()

View File

@ -54,7 +54,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeBorrowedLocals {
trans: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
self.transfer_function(trans).visit_terminator(terminator, location);
terminator.edges()
}

View File

@ -1,6 +1,6 @@
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
use rustc_index::Idx;
use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdge};
use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
use rustc_middle::ty::{self, TyCtxt};
use crate::drop_flag_effects_for_function_entry;
@ -362,14 +362,14 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
state: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
let mut edges = terminator.edges();
if self.skip_unreachable_unwind
&& let mir::TerminatorKind::Drop { target, unwind, place, replace: _ } = terminator.kind
&& matches!(unwind, mir::UnwindAction::Cleanup(_))
&& self.is_unwind_dead(place, state)
{
edges = TerminatorEdge::Single(target);
edges = TerminatorEdges::Single(target);
}
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
Self::update_bits(state, path, s)
@ -491,14 +491,14 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
Self::update_bits(trans, path, s)
});
if self.skip_unreachable_unwind.contains(location.block) {
let mir::TerminatorKind::Drop { target, unwind, .. } = terminator.kind else { bug!() };
assert!(matches!(unwind, mir::UnwindAction::Cleanup(_)));
TerminatorEdge::Single(target)
TerminatorEdges::Single(target)
} else {
terminator.edges()
}
@ -619,7 +619,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
Self::update_bits(trans, path, s)
});
@ -702,7 +702,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
let (body, move_data) = (self.body, self.move_data());
let term = body[location.block].terminator();
let init_loc_map = &move_data.init_loc_map;

View File

@ -1,7 +1,7 @@
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{
self, CallReturnPlaces, Local, Location, Place, StatementKind, TerminatorEdge,
self, CallReturnPlaces, Local, Location, Place, StatementKind, TerminatorEdges,
};
use crate::{Analysis, AnalysisDomain, Backward, GenKill, GenKillAnalysis};
@ -63,7 +63,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
TransferFunction(trans).visit_terminator(terminator, location);
terminator.edges()
}
@ -280,9 +280,9 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
trans: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
TransferFunction(trans).visit_terminator(terminator, location);
TerminatorEdge::None
TerminatorEdges::None
}
fn apply_call_return_effect(

View File

@ -71,7 +71,7 @@ impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
_trans: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>,
_: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
// Terminators have no effect
terminator.edges()
}
@ -143,7 +143,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageDead {
_: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>,
_: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
// Terminators have no effect
terminator.edges()
}
@ -310,7 +310,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
trans: &mut Self::Domain,
terminator: &'t Terminator<'tcx>,
loc: Location,
) -> TerminatorEdge<'t, 'tcx> {
) -> TerminatorEdges<'t, 'tcx> {
match terminator.kind {
// For call terminators the destination requires storage for the call
// and after the call returns successfully, but not after a panic.

View File

@ -245,7 +245,7 @@ pub trait ValueAnalysis<'tcx> {
&self,
terminator: &'mir Terminator<'tcx>,
state: &mut State<Self::Value>,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
self.super_terminator(terminator, state)
}
@ -253,7 +253,7 @@ pub trait ValueAnalysis<'tcx> {
&self,
terminator: &'mir Terminator<'tcx>,
state: &mut State<Self::Value>,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
match &terminator.kind {
TerminatorKind::Call { .. } | TerminatorKind::InlineAsm { .. } => {
// Effect is applied by `handle_call_return`.
@ -306,7 +306,7 @@ pub trait ValueAnalysis<'tcx> {
discr: &'mir Operand<'tcx>,
targets: &'mir SwitchTargets,
state: &mut State<Self::Value>,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
self.super_switch_int(discr, targets, state)
}
@ -315,8 +315,8 @@ pub trait ValueAnalysis<'tcx> {
discr: &'mir Operand<'tcx>,
targets: &'mir SwitchTargets,
_state: &mut State<Self::Value>,
) -> TerminatorEdge<'mir, 'tcx> {
TerminatorEdge::SwitchInt { discr, targets }
) -> TerminatorEdges<'mir, 'tcx> {
TerminatorEdges::SwitchInt { discr, targets }
}
fn wrap(self) -> ValueAnalysisWrapper<Self>
@ -371,11 +371,11 @@ where
state: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>,
_location: Location,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
if state.is_reachable() {
self.0.handle_terminator(terminator, state)
} else {
TerminatorEdge::None
TerminatorEdges::None
}
}

View File

@ -252,19 +252,19 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
discr: &'mir Operand<'tcx>,
targets: &'mir SwitchTargets,
state: &mut State<Self::Value>,
) -> TerminatorEdge<'mir, 'tcx> {
) -> TerminatorEdges<'mir, 'tcx> {
let value = match self.handle_operand(discr, state) {
ValueOrPlace::Value(value) => value,
ValueOrPlace::Place(place) => state.get_idx(place, self.map()),
};
let FlatSet::Elem(ScalarTy(scalar, _)) = value else {
// Do nothing if we don't know which branch will be taken.
return TerminatorEdge::SwitchInt { discr, targets };
return TerminatorEdges::SwitchInt { discr, targets };
};
let int = scalar.assert_int();
let choice = int.assert_bits(int.size());
TerminatorEdge::Single(targets.target_for_value(choice))
TerminatorEdges::Single(targets.target_for_value(choice))
}
}