Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 9 additions & 37 deletions compiler/rustc_mir_dataflow/src/framework/direction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_middle::bug;
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges};
use rustc_middle::mir::{self, BasicBlock, Location, TerminatorEdges};

use super::visitor::ResultsVisitor;
use super::{Analysis, Effect, EffectIndex, SwitchTargetIndex};
Expand Down Expand Up @@ -79,45 +79,17 @@ impl Direction for Backward {

let exit_state = state;
for pred in body.basic_blocks.predecessors()[block].iter().copied() {
match body[pred].terminator().kind {
match body[pred].terminator().edges() {
// Apply terminator-specific edge effects.
mir::TerminatorKind::Call { destination, target: Some(dest), .. }
if dest == block =>
TerminatorEdges::AssignOnReturn { return_, place, .. }
if return_.contains(&block) =>
{
let mut tmp = exit_state.clone();
analysis.apply_call_return_effect(
&mut tmp,
pred,
CallReturnPlaces::Call(destination),
);
propagate(pred, &tmp);
}

mir::TerminatorKind::InlineAsm { ref targets, ref operands, .. }
if targets.contains(&block) =>
{
let mut tmp = exit_state.clone();
analysis.apply_call_return_effect(
&mut tmp,
pred,
CallReturnPlaces::InlineAsm(operands),
);
propagate(pred, &tmp);
}

mir::TerminatorKind::Yield { resume, drop, resume_arg, .. }
if resume == block || drop == Some(block) =>
{
let mut tmp = exit_state.clone();
analysis.apply_call_return_effect(
&mut tmp,
block,
CallReturnPlaces::Yield(resume_arg),
);
analysis.apply_call_return_effect(&mut tmp, pred, place);
propagate(pred, &tmp);
}

mir::TerminatorKind::SwitchInt { ref targets, ref discr } => {
TerminatorEdges::SwitchInt { targets, discr } => {
if let Some(_data) = analysis.get_switch_int_data(pred, targets, discr) {
bug!(
"SwitchInt edge effects are unsupported in backward dataflow analyses"
Expand Down Expand Up @@ -220,12 +192,12 @@ impl Direction for Forward {
}
}
TerminatorEdges::SwitchInt { targets, discr } => {
if let Some(mut data) = analysis.get_switch_int_data(block, targets, discr) {
if let Some(data) = analysis.get_switch_int_data(block, targets, discr) {
let mut tmp = analysis.bottom_value(body);
for (i, (_value, target)) in targets.iter().enumerate() {
tmp.clone_from(exit_state);
let target_idx = SwitchTargetIndex::Normal(i);
analysis.apply_switch_int_edge_effect(&mut tmp, &mut data, target_idx);
analysis.apply_switch_int_edge_effect(&mut tmp, &data, target_idx);
propagate(target, &tmp);
}

Expand All @@ -234,7 +206,7 @@ impl Direction for Forward {
// a clone of the dataflow state.
analysis.apply_switch_int_edge_effect(
exit_state,
&mut data,
&data,
SwitchTargetIndex::Otherwise,
);
propagate(targets.otherwise(), exit_state);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/framework/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,13 @@ where
})?;
}

mir::TerminatorKind::Yield { resume, resume_arg, .. } => {
mir::TerminatorKind::Yield { resume_arg, .. } => {
self.write_row(w, "", "(on yield resume)", |this, w, fmt| {
let state_on_coroutine_drop = this.cursor.get().clone();
this.cursor.apply_custom_effect(|analysis, state| {
analysis.apply_call_return_effect(
state,
resume,
block,
CallReturnPlaces::Yield(resume_arg),
);
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub trait Analysis<'tcx> {
fn apply_switch_int_edge_effect(
&self,
_state: &mut Self::Domain,
_data: &mut Self::SwitchIntData,
_data: &Self::SwitchIntData,
_target_idx: SwitchTargetIndex,
) {
unreachable!();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
fn apply_switch_int_edge_effect(
&self,
state: &mut Self::Domain,
data: &mut Self::SwitchIntData,
data: &Self::SwitchIntData,
target_idx: SwitchTargetIndex,
) {
let inactive_variants = match target_idx {
Expand Down Expand Up @@ -588,7 +588,7 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
fn apply_switch_int_edge_effect(
&self,
state: &mut Self::Domain,
data: &mut Self::SwitchIntData,
data: &Self::SwitchIntData,
target_idx: SwitchTargetIndex,
) {
let inactive_variants = match target_idx {
Expand Down
Loading