This commit is contained in:
Folkert 2021-09-10 15:43:41 +02:00
parent 770c8352e3
commit 05ef6fdeb7

View file

@ -1201,17 +1201,10 @@ enum DecOrReuse {
Reuse, Reuse,
} }
fn must_refcount(tags: &[&[Layout<'_>]]) -> bool { fn fields_need_no_refcounting(field_layouts: &[Layout]) -> bool {
for field_layouts in tags.iter() { !field_layouts
// if none of the fields are or contain anything refcounted, just move on .iter()
if !field_layouts .any(|x| x.is_refcounted() || x.contains_refcounted())
.iter()
.any(|x| x.is_refcounted() || x.contains_refcounted())
{
return false;
}
}
true
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -1241,10 +1234,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx, 'env>(
for (tag_id, field_layouts) in tags.iter().enumerate() { for (tag_id, field_layouts) in tags.iter().enumerate() {
// if none of the fields are or contain anything refcounted, just move on // if none of the fields are or contain anything refcounted, just move on
if !field_layouts if fields_need_no_refcounting(field_layouts) {
.iter()
.any(|x| x.is_refcounted() || x.contains_refcounted())
{
continue; continue;
} }
@ -1344,11 +1334,13 @@ fn build_rec_union_recursive_decrement<'a, 'ctx, 'env>(
cases.reverse(); cases.reverse();
if cases.len() == 1 && must_refcount(tags) { if matches!(
// there is only one tag in total; we don't need a switch union_layout,
// this is essential for nullable unwrapped layouts, UnionLayout::NullableUnwrapped { .. } | UnionLayout::NonNullableUnwrapped { .. }
// because the `else` branch below would try to read its ) {
// (nonexistant) tag id debug_assert_eq!(cases.len(), 1);
// in this case, don't switch, because the `else` branch below would try to read the (nonexistant) tag id
let (_, only_branch) = cases.pop().unwrap(); let (_, only_branch) = cases.pop().unwrap();
env.builder.build_unconditional_branch(only_branch); env.builder.build_unconditional_branch(only_branch);
} else { } else {