Simplify visit_statement.

This commit is contained in:
Camille GILLOT 2023-03-07 14:41:13 +00:00
parent 9a56933e8c
commit 2247cd6643
2 changed files with 61 additions and 65 deletions

View File

@ -961,13 +961,14 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
}
}
}
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
StatementKind::StorageLive(local) => {
let frame = self.ecx.frame_mut();
frame.locals[local].value = if let StatementKind::StorageLive(_) = statement.kind {
LocalValue::Live(interpret::Operand::Immediate(interpret::Immediate::Uninit))
} else {
LocalValue::Dead
};
frame.locals[local].value =
LocalValue::Live(interpret::Operand::Immediate(interpret::Immediate::Uninit));
}
StatementKind::StorageDead(local) => {
let frame = self.ecx.frame_mut();
frame.locals[local].value = LocalValue::Dead;
}
_ => {}
}

View File

@ -522,7 +522,8 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
trace!("visit_statement: {:?}", statement);
let source_info = statement.source_info;
self.source_info = Some(source_info);
if let StatementKind::Assign(box (place, ref rval)) = statement.kind {
match statement.kind {
StatementKind::Assign(box (place, ref rval)) => {
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
if let Some(()) = self.const_prop(rval, source_info, place) {
match can_const_prop {
@ -559,14 +560,11 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
);
Self::remove_const(&mut self.ecx, place.local);
}
} else {
match statement.kind {
}
StatementKind::SetDiscriminant { ref place, .. } => {
match self.ecx.machine.can_const_prop[place.local] {
ConstPropMode::FullConstProp | ConstPropMode::OnlyInsideOwnBlock => {
if self
.use_ecx(source_info, |this| this.ecx.statement(statement))
.is_some()
if self.use_ecx(source_info, |this| this.ecx.statement(statement)).is_some()
{
trace!("propped discriminant into {:?}", place);
} else {
@ -578,20 +576,17 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
}
}
}
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
StatementKind::StorageLive(local) => {
let frame = self.ecx.frame_mut();
frame.locals[local].value =
if let StatementKind::StorageLive(_) = statement.kind {
LocalValue::Live(interpret::Operand::Immediate(
interpret::Immediate::Uninit,
))
} else {
LocalValue::Dead
};
LocalValue::Live(interpret::Operand::Immediate(interpret::Immediate::Uninit));
}
StatementKind::StorageDead(local) => {
let frame = self.ecx.frame_mut();
frame.locals[local].value = LocalValue::Dead;
}
_ => {}
}
}
self.super_statement(statement, location);
}