Add SwitchTargetValue
.
This is much clearer than `Option<u128>`.
This commit is contained in:
parent
23dbff88f6
commit
8403d39dce
5 changed files with 33 additions and 12 deletions
|
@ -1,6 +1,8 @@
|
|||
use std::ops::RangeInclusive;
|
||||
|
||||
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges};
|
||||
use rustc_middle::mir::{
|
||||
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
|
||||
};
|
||||
|
||||
use super::visitor::ResultsVisitor;
|
||||
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
|
||||
|
@ -290,7 +292,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: Some(value), target };
|
||||
let si_target =
|
||||
SwitchIntTarget { value: SwitchTargetValue::Normal(value), target };
|
||||
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
|
||||
propagate(target, &tmp);
|
||||
}
|
||||
|
@ -302,7 +305,7 @@ impl Direction for Forward {
|
|||
analysis.apply_switch_int_edge_effect(
|
||||
&mut data,
|
||||
exit_state,
|
||||
SwitchIntTarget { value: None, target: otherwise },
|
||||
SwitchIntTarget { value: SwitchTargetValue::Otherwise, target: otherwise },
|
||||
);
|
||||
propagate(otherwise, exit_state);
|
||||
} else {
|
||||
|
|
|
@ -38,7 +38,9 @@ use rustc_data_structures::work_queue::WorkQueue;
|
|||
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges, traversal};
|
||||
use rustc_middle::mir::{
|
||||
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges, traversal,
|
||||
};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use tracing::error;
|
||||
|
||||
|
@ -431,7 +433,7 @@ impl EffectIndex {
|
|||
}
|
||||
|
||||
pub struct SwitchIntTarget {
|
||||
pub value: Option<u128>,
|
||||
pub value: SwitchTargetValue,
|
||||
pub target: BasicBlock,
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ use rustc_abi::VariantIdx;
|
|||
use rustc_index::Idx;
|
||||
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
|
||||
use rustc_middle::mir::{
|
||||
self, Body, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
|
||||
};
|
||||
use rustc_middle::ty::util::Discr;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use tracing::{debug, instrument};
|
||||
|
@ -424,7 +426,7 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
|
|||
state: &mut Self::Domain,
|
||||
edge: SwitchIntTarget,
|
||||
) {
|
||||
if let Some(value) = edge.value {
|
||||
if let SwitchTargetValue::Normal(value) = edge.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(
|
||||
|
@ -537,7 +539,7 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
|
|||
state: &mut Self::Domain,
|
||||
edge: SwitchIntTarget,
|
||||
) {
|
||||
if let Some(value) = edge.value {
|
||||
if let SwitchTargetValue::Normal(value) = edge.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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue