Remove SwitchIntTarget.

It's only passed to `Analysis::apply_switch_int_edge_effect`, and the
existing impls of that method only use the `value` field. So pass that
instead.
This commit is contained in:
Nicholas Nethercote 2025-02-14 13:23:00 +11:00
parent db1ca60470
commit 3b81d9d42d
3 changed files with 10 additions and 18 deletions

View file

@ -5,7 +5,7 @@ use rustc_middle::mir::{
}; };
use super::visitor::ResultsVisitor; use super::visitor::ResultsVisitor;
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget}; use super::{Analysis, Effect, EffectIndex, Results};
pub trait Direction { pub trait Direction {
const IS_FORWARD: bool; const IS_FORWARD: bool;
@ -117,8 +117,7 @@ impl Direction for Backward {
let mut tmp = analysis.bottom_value(body); let mut tmp = analysis.bottom_value(body);
for &value in &body.basic_blocks.switch_sources()[&(block, pred)] { for &value in &body.basic_blocks.switch_sources()[&(block, pred)] {
tmp.clone_from(exit_state); tmp.clone_from(exit_state);
let si_target = SwitchIntTarget { value, target: block }; analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, value);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
propagate(pred, &tmp); propagate(pred, &tmp);
} }
} else { } else {
@ -292,9 +291,8 @@ impl Direction for Forward {
let mut tmp = analysis.bottom_value(body); let mut tmp = analysis.bottom_value(body);
for (value, target) in targets.iter() { for (value, target) in targets.iter() {
tmp.clone_from(exit_state); tmp.clone_from(exit_state);
let si_target = let value = SwitchTargetValue::Normal(value);
SwitchIntTarget { value: SwitchTargetValue::Normal(value), target }; analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, value);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
propagate(target, &tmp); propagate(target, &tmp);
} }
@ -305,7 +303,7 @@ impl Direction for Forward {
analysis.apply_switch_int_edge_effect( analysis.apply_switch_int_edge_effect(
&mut data, &mut data,
exit_state, exit_state,
SwitchIntTarget { value: SwitchTargetValue::Otherwise, target: otherwise }, SwitchTargetValue::Otherwise,
); );
propagate(otherwise, exit_state); propagate(otherwise, exit_state);
} else { } else {

View file

@ -222,7 +222,7 @@ pub trait Analysis<'tcx> {
&mut self, &mut self,
_data: &mut Self::SwitchIntData, _data: &mut Self::SwitchIntData,
_state: &mut Self::Domain, _state: &mut Self::Domain,
_edge: SwitchIntTarget, _value: SwitchTargetValue,
) { ) {
unreachable!(); unreachable!();
} }
@ -432,10 +432,5 @@ impl EffectIndex {
} }
} }
pub struct SwitchIntTarget {
pub value: SwitchTargetValue,
pub target: BasicBlock,
}
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View file

@ -12,7 +12,6 @@ use rustc_middle::ty::{self, TyCtxt};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use crate::drop_flag_effects::DropFlagState; use crate::drop_flag_effects::DropFlagState;
use crate::framework::SwitchIntTarget;
use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex}; use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
use crate::{ use crate::{
Analysis, GenKill, MaybeReachable, drop_flag_effects, drop_flag_effects_for_function_entry, Analysis, GenKill, MaybeReachable, drop_flag_effects, drop_flag_effects_for_function_entry,
@ -424,9 +423,9 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
&mut self, &mut self,
data: &mut Self::SwitchIntData, data: &mut Self::SwitchIntData,
state: &mut Self::Domain, state: &mut Self::Domain,
edge: SwitchIntTarget, value: SwitchTargetValue,
) { ) {
if let SwitchTargetValue::Normal(value) = edge.value { if let SwitchTargetValue::Normal(value) = value {
// Kill all move paths that correspond to variants we know to be inactive along this // Kill all move paths that correspond to variants we know to be inactive along this
// particular outgoing edge of a `SwitchInt`. // particular outgoing edge of a `SwitchInt`.
drop_flag_effects::on_all_inactive_variants( drop_flag_effects::on_all_inactive_variants(
@ -537,9 +536,9 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
&mut self, &mut self,
data: &mut Self::SwitchIntData, data: &mut Self::SwitchIntData,
state: &mut Self::Domain, state: &mut Self::Domain,
edge: SwitchIntTarget, value: SwitchTargetValue,
) { ) {
if let SwitchTargetValue::Normal(value) = edge.value { if let SwitchTargetValue::Normal(value) = value {
// Mark all move paths that correspond to variants other than this one as maybe // Mark all move paths that correspond to variants other than this one as maybe
// uninitialized (in reality, they are *definitely* uninitialized). // uninitialized (in reality, they are *definitely* uninitialized).
drop_flag_effects::on_all_inactive_variants( drop_flag_effects::on_all_inactive_variants(