Skip to content

Commit be137a2

Browse files
committed
Change type of SwitchIntTarget::value.
`SwitchIntTarget` only exists to serve as an input to `Analysis::apply_switch_int_edge_effect`. `SwitchIntTarget::value` is and `Option<u128>` but all non-empty impls of `apply_switch_int_edge_effect` ignore any `SwitchIntTarget` that contains a `None` value. Therefore, we can remove the `apply_switch_int_edge_effect` calls that pass in `None`, and simplify the `Option<u128>` to `u128`.
1 parent 4cc0b59 commit be137a2

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

compiler/rustc_mir_dataflow/src/framework/direction.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ impl Direction for Backward {
115115
let mut tmp = analysis.bottom_value(body);
116116
for &value in &body.basic_blocks.switch_sources()[&(block, pred)] {
117117
tmp.clone_from(exit_state);
118-
let si_target = SwitchIntTarget { value, target: block };
119-
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
118+
if let Some(value) = value {
119+
let si_target = SwitchIntTarget { value, target: block };
120+
analysis
121+
.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
122+
}
120123
propagate(pred, &tmp);
121124
}
122125
} else {
@@ -290,21 +293,11 @@ impl Direction for Forward {
290293
let mut tmp = analysis.bottom_value(body);
291294
for (value, target) in targets.iter() {
292295
tmp.clone_from(exit_state);
293-
let si_target = SwitchIntTarget { value: Some(value), target };
296+
let si_target = SwitchIntTarget { value, target };
294297
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, si_target);
295298
propagate(target, &tmp);
296299
}
297-
298-
// Once we get to the final, "otherwise" branch, there is no need to preserve
299-
// `exit_state`, so pass it directly to `apply_switch_int_edge_effect` to save
300-
// a clone of the dataflow state.
301-
let otherwise = targets.otherwise();
302-
analysis.apply_switch_int_edge_effect(
303-
&mut data,
304-
exit_state,
305-
SwitchIntTarget { value: None, target: otherwise },
306-
);
307-
propagate(otherwise, exit_state);
300+
propagate(targets.otherwise(), exit_state);
308301
} else {
309302
for target in targets.all_targets() {
310303
propagate(*target, exit_state);

compiler/rustc_mir_dataflow/src/framework/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ pub trait Analysis<'tcx> {
199199
/// Unlike the other edge-specific effects, which are allowed to mutate `Self::Domain`
200200
/// directly, overriders of this method must return a `Self::SwitchIntData` value (wrapped in
201201
/// `Some`). The `apply_switch_int_edge_effect` method will then be called once for each
202-
/// outgoing edge and will have access to the dataflow state that will be propagated along that
203-
/// edge, and also the `Self::SwitchIntData` value.
202+
/// outgoing edge (excluding the "otherwise" target) and will have access to the dataflow
203+
/// state that will be propagated along that edge, and also the `Self::SwitchIntData` value.
204204
///
205205
/// This interface is somewhat more complex than the other visitor-like "effect" methods.
206206
/// However, it is both more ergonomic—callers don't need to recompute or cache information
@@ -431,7 +431,7 @@ impl EffectIndex {
431431
}
432432

433433
pub struct SwitchIntTarget {
434-
pub value: Option<u128>,
434+
pub value: u128,
435435
pub target: BasicBlock,
436436
}
437437

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,14 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
424424
state: &mut Self::Domain,
425425
edge: SwitchIntTarget,
426426
) {
427-
if let Some(value) = edge.value {
428-
// Kill all move paths that correspond to variants we know to be inactive along this
429-
// particular outgoing edge of a `SwitchInt`.
430-
drop_flag_effects::on_all_inactive_variants(
431-
self.move_data,
432-
data.enum_place,
433-
data.next_discr(value),
434-
|mpi| state.kill(mpi),
435-
);
436-
}
427+
// Kill all move paths that correspond to variants we know to be inactive along this
428+
// particular outgoing edge of a `SwitchInt`.
429+
drop_flag_effects::on_all_inactive_variants(
430+
self.move_data,
431+
data.enum_place,
432+
data.next_discr(edge.value),
433+
|mpi| state.kill(mpi),
434+
);
437435
}
438436
}
439437

@@ -537,16 +535,14 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
537535
state: &mut Self::Domain,
538536
edge: SwitchIntTarget,
539537
) {
540-
if let Some(value) = edge.value {
541-
// Mark all move paths that correspond to variants other than this one as maybe
542-
// uninitialized (in reality, they are *definitely* uninitialized).
543-
drop_flag_effects::on_all_inactive_variants(
544-
self.move_data,
545-
data.enum_place,
546-
data.next_discr(value),
547-
|mpi| state.gen_(mpi),
548-
);
549-
}
538+
// Mark all move paths that correspond to variants other than this one as maybe
539+
// uninitialized (in reality, they are *definitely* uninitialized).
540+
drop_flag_effects::on_all_inactive_variants(
541+
self.move_data,
542+
data.enum_place,
543+
data.next_discr(edge.value),
544+
|mpi| state.gen_(mpi),
545+
);
550546
}
551547
}
552548

0 commit comments

Comments
 (0)