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);
|
tmp_assigned_vars.insert(*r);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dbg_info_to_adjust = Vec::new();
|
let dbg_info_to_adjust: Vec<_> =
|
||||||
for (i, var_info) in debug_info.iter().enumerate() {
|
debug_info
|
||||||
if tmp_assigned_vars.contains(var_info.place.local) {
|
.iter()
|
||||||
dbg_info_to_adjust.push(i);
|
.enumerate()
|
||||||
}
|
.filter_map(|(i, var_info)| {
|
||||||
}
|
if tmp_assigned_vars.contains(var_info.place.local) { Some(i) } else { None }
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Some(ArmIdentityInfo {
|
Some(ArmIdentityInfo {
|
||||||
local_temp_0: local_tmp_s0,
|
local_temp_0: local_tmp_s0,
|
||||||
|
@ -461,15 +463,15 @@ fn match_get_variant_field<'tcx>(
|
||||||
stmt: &Statement<'tcx>,
|
stmt: &Statement<'tcx>,
|
||||||
) -> Option<(Local, Local, VarField<'tcx>, &'tcx List<PlaceElem<'tcx>>)> {
|
) -> Option<(Local, Local, VarField<'tcx>, &'tcx List<PlaceElem<'tcx>>)> {
|
||||||
match &stmt.kind {
|
match &stmt.kind {
|
||||||
StatementKind::Assign(box (place_into, rvalue_from)) => match rvalue_from {
|
StatementKind::Assign(box (
|
||||||
Rvalue::Use(Operand::Copy(pf) | Operand::Move(pf)) => {
|
place_into,
|
||||||
|
Rvalue::Use(Operand::Copy(pf) | Operand::Move(pf)),
|
||||||
|
)) => {
|
||||||
let local_into = place_into.as_local()?;
|
let local_into = place_into.as_local()?;
|
||||||
let (local_from, vf) = match_variant_field_place(*pf)?;
|
let (local_from, vf) = match_variant_field_place(*pf)?;
|
||||||
Some((local_into, local_from, vf, pf.projection))
|
Some((local_into, local_from, vf, pf.projection))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
|
||||||
_ => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,15 +481,12 @@ fn match_get_variant_field<'tcx>(
|
||||||
/// ```
|
/// ```
|
||||||
fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> {
|
fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> {
|
||||||
match &stmt.kind {
|
match &stmt.kind {
|
||||||
StatementKind::Assign(box (place_from, rvalue_into)) => match rvalue_into {
|
StatementKind::Assign(box (place_from, Rvalue::Use(Operand::Move(place_into)))) => {
|
||||||
Rvalue::Use(Operand::Move(place_into)) => {
|
|
||||||
let local_into = place_into.as_local()?;
|
let local_into = place_into.as_local()?;
|
||||||
let (local_from, vf) = match_variant_field_place(*place_from)?;
|
let (local_from, vf) = match_variant_field_place(*place_from)?;
|
||||||
Some((local_into, local_from, vf))
|
Some((local_into, local_from, vf))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
|
||||||
_ => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,26 +99,18 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
|
||||||
if let TerminatorKind::SwitchInt { values, targets, .. } =
|
if let TerminatorKind::SwitchInt { values, targets, .. } =
|
||||||
&mut body.basic_blocks_mut()[bb].terminator_mut().kind
|
&mut body.basic_blocks_mut()[bb].terminator_mut().kind
|
||||||
{
|
{
|
||||||
let vals = &*values;
|
// take otherwise out early
|
||||||
let zipped = vals.iter().zip(targets.iter());
|
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());
|
values.to_mut().retain(|var| allowed_variants.contains(var));
|
||||||
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;
|
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,17 +68,6 @@ where
|
||||||
F: Fn(BasicBlock) -> bool,
|
F: Fn(BasicBlock) -> bool,
|
||||||
{
|
{
|
||||||
let terminator = match *terminator_kind {
|
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::Goto { target } if predicate(target) => TerminatorKind::Unreachable,
|
||||||
TerminatorKind::SwitchInt { ref discr, switch_ty, ref values, ref targets } => {
|
TerminatorKind::SwitchInt { ref discr, switch_ty, ref values, ref targets } => {
|
||||||
let original_targets_len = targets.len();
|
let original_targets_len = targets.len();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue