Skip to content

Commit

Permalink
Remove SwitchIntTarget.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed Feb 16, 2025
1 parent db1ca60 commit 3b81d9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
12 changes: 5 additions & 7 deletions compiler/rustc_mir_dataflow/src/framework/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_middle::mir::{
};

use super::visitor::ResultsVisitor;
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
use super::{Analysis, Effect, EffectIndex, Results};

pub trait Direction {
const IS_FORWARD: bool;
Expand Down Expand Up @@ -117,8 +117,7 @@ impl Direction for Backward {
let mut tmp = analysis.bottom_value(body);
for &value in &body.basic_blocks.switch_sources()[&(block, pred)] {
tmp.clone_from(exit_state);
let si_target = SwitchIntTarget { value, target: block };
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, value);
propagate(pred, &tmp);
}
} else {
Expand Down Expand Up @@ -292,9 +291,8 @@ impl Direction for Forward {
let mut tmp = analysis.bottom_value(body);
for (value, target) in targets.iter() {
tmp.clone_from(exit_state);
let si_target =
SwitchIntTarget { value: SwitchTargetValue::Normal(value), target };
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
let value = SwitchTargetValue::Normal(value);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, value);
propagate(target, &tmp);
}

Expand All @@ -305,7 +303,7 @@ impl Direction for Forward {
analysis.apply_switch_int_edge_effect(
&mut data,
exit_state,
SwitchIntTarget { value: SwitchTargetValue::Otherwise, target: otherwise },
SwitchTargetValue::Otherwise,
);
propagate(otherwise, exit_state);
} else {
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_mir_dataflow/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub trait Analysis<'tcx> {
&mut self,
_data: &mut Self::SwitchIntData,
_state: &mut Self::Domain,
_edge: SwitchIntTarget,
_value: SwitchTargetValue,
) {
unreachable!();
}
Expand Down Expand Up @@ -432,10 +432,5 @@ impl EffectIndex {
}
}

pub struct SwitchIntTarget {
pub value: SwitchTargetValue,
pub target: BasicBlock,
}

#[cfg(test)]
mod tests;
9 changes: 4 additions & 5 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use rustc_middle::ty::{self, TyCtxt};
use tracing::{debug, instrument};

use crate::drop_flag_effects::DropFlagState;
use crate::framework::SwitchIntTarget;
use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
use crate::{
Analysis, GenKill, MaybeReachable, drop_flag_effects, drop_flag_effects_for_function_entry,
Expand Down Expand Up @@ -424,9 +423,9 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
&mut self,
data: &mut Self::SwitchIntData,
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
// particular outgoing edge of a `SwitchInt`.
drop_flag_effects::on_all_inactive_variants(
Expand Down Expand Up @@ -537,9 +536,9 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
&mut self,
data: &mut Self::SwitchIntData,
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
// uninitialized (in reality, they are *definitely* uninitialized).
drop_flag_effects::on_all_inactive_variants(
Expand Down

0 comments on commit 3b81d9d

Please sign in to comment.