Rm allocation in uninhabited_enum_branching
Also convert `uninhabited_enum_branching` `Cow<[u128]>::to_mut`
This commit is contained in:
parent
70ad31847d
commit
fd63bf7262
3 changed files with 32 additions and 52 deletions
|
@ -246,12 +246,14 @@ fn get_arm_identity_info<'a, 'tcx>(
|
|||
tmp_assigned_vars.insert(*r);
|
||||
}
|
||||
|
||||
let mut dbg_info_to_adjust = Vec::new();
|
||||
for (i, var_info) in debug_info.iter().enumerate() {
|
||||
if tmp_assigned_vars.contains(var_info.place.local) {
|
||||
dbg_info_to_adjust.push(i);
|
||||
}
|
||||
}
|
||||
let dbg_info_to_adjust: Vec<_> =
|
||||
debug_info
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, var_info)| {
|
||||
if tmp_assigned_vars.contains(var_info.place.local) { Some(i) } else { None }
|
||||
})
|
||||
.collect();
|
||||
|
||||
Some(ArmIdentityInfo {
|
||||
local_temp_0: local_tmp_s0,
|
||||
|
@ -461,14 +463,14 @@ fn match_get_variant_field<'tcx>(
|
|||
stmt: &Statement<'tcx>,
|
||||
) -> Option<(Local, Local, VarField<'tcx>, &'tcx List<PlaceElem<'tcx>>)> {
|
||||
match &stmt.kind {
|
||||
StatementKind::Assign(box (place_into, rvalue_from)) => match rvalue_from {
|
||||
Rvalue::Use(Operand::Copy(pf) | Operand::Move(pf)) => {
|
||||
let local_into = place_into.as_local()?;
|
||||
let (local_from, vf) = match_variant_field_place(*pf)?;
|
||||
Some((local_into, local_from, vf, pf.projection))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
StatementKind::Assign(box (
|
||||
place_into,
|
||||
Rvalue::Use(Operand::Copy(pf) | Operand::Move(pf)),
|
||||
)) => {
|
||||
let local_into = place_into.as_local()?;
|
||||
let (local_from, vf) = match_variant_field_place(*pf)?;
|
||||
Some((local_into, local_from, vf, pf.projection))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -479,14 +481,11 @@ fn match_get_variant_field<'tcx>(
|
|||
/// ```
|
||||
fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> {
|
||||
match &stmt.kind {
|
||||
StatementKind::Assign(box (place_from, rvalue_into)) => match rvalue_into {
|
||||
Rvalue::Use(Operand::Move(place_into)) => {
|
||||
let local_into = place_into.as_local()?;
|
||||
let (local_from, vf) = match_variant_field_place(*place_from)?;
|
||||
Some((local_into, local_from, vf))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
StatementKind::Assign(box (place_from, Rvalue::Use(Operand::Move(place_into)))) => {
|
||||
let local_into = place_into.as_local()?;
|
||||
let (local_from, vf) = match_variant_field_place(*place_from)?;
|
||||
Some((local_into, local_from, vf))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,26 +99,18 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
|
|||
if let TerminatorKind::SwitchInt { values, targets, .. } =
|
||||
&mut body.basic_blocks_mut()[bb].terminator_mut().kind
|
||||
{
|
||||
let vals = &*values;
|
||||
let zipped = vals.iter().zip(targets.iter());
|
||||
// take otherwise out early
|
||||
let otherwise = targets.pop().unwrap();
|
||||
assert_eq!(targets.len(), values.len());
|
||||
let mut i = 0;
|
||||
targets.retain(|_| {
|
||||
let keep = allowed_variants.contains(&values[i]);
|
||||
i += 1;
|
||||
keep
|
||||
});
|
||||
targets.push(otherwise);
|
||||
|
||||
let mut matched_values = Vec::with_capacity(allowed_variants.len());
|
||||
let mut matched_targets = Vec::with_capacity(allowed_variants.len() + 1);
|
||||
|
||||
for (val, target) in zipped {
|
||||
if allowed_variants.contains(val) {
|
||||
matched_values.push(*val);
|
||||
matched_targets.push(*target);
|
||||
} else {
|
||||
trace!("eliminating {:?} -> {:?}", val, target);
|
||||
}
|
||||
}
|
||||
|
||||
// handle the "otherwise" branch
|
||||
matched_targets.push(targets.pop().unwrap());
|
||||
|
||||
*values = matched_values.into();
|
||||
*targets = matched_targets;
|
||||
values.to_mut().retain(|var| allowed_variants.contains(var));
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
|
|
@ -68,17 +68,6 @@ where
|
|||
F: Fn(BasicBlock) -> bool,
|
||||
{
|
||||
let terminator = match *terminator_kind {
|
||||
TerminatorKind::FalseEdge { real_target, imaginary_target }
|
||||
if predicate(real_target) && predicate(imaginary_target) =>
|
||||
{
|
||||
TerminatorKind::Unreachable
|
||||
}
|
||||
TerminatorKind::FalseUnwind { real_target, unwind }
|
||||
if predicate(real_target) && unwind.map_or(true, &predicate) =>
|
||||
{
|
||||
TerminatorKind::Unreachable
|
||||
}
|
||||
|
||||
TerminatorKind::Goto { target } if predicate(target) => TerminatorKind::Unreachable,
|
||||
TerminatorKind::SwitchInt { ref discr, switch_ty, ref values, ref targets } => {
|
||||
let original_targets_len = targets.len();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue