This commit is contained in:
Folkert 2021-06-21 23:24:55 +02:00
parent 84855dae5e
commit e80f8a5114
2 changed files with 15 additions and 42 deletions

View file

@ -5674,7 +5674,9 @@ fn store_tag_pattern<'a>(
) -> StorePattern<'a> {
use Pattern::*;
let write_tag = union_layout.stores_tag();
// rosetree-like structures don't store the tag ID, the others do from the perspective of the IR
// The backend can make different choices there (and will, for UnionLayout::NullableUnwrapped)
let write_tag = !matches!(union_layout, UnionLayout::NonNullableUnwrapped(_));
let mut arg_layouts = Vec::with_capacity_in(arguments.len(), env.arena);
let mut is_productive = false;

View file

@ -107,32 +107,19 @@ impl<'a> UnionLayout<'a> {
}
pub fn layout_at(self, tag_id: u8, index: usize) -> Layout<'a> {
match self {
let result = match self {
UnionLayout::NonRecursive(tag_layouts) => {
let field_layouts = tag_layouts[tag_id as usize];
field_layouts[index]
// this cannot be recursive; return immediately
return field_layouts[index];
}
UnionLayout::Recursive(tag_layouts) => {
let field_layouts = tag_layouts[tag_id as usize];
let result = field_layouts[index];
if let Layout::RecursivePointer = result {
Layout::Union(self)
} else {
result
}
}
UnionLayout::NonNullableUnwrapped(field_layouts) => {
let result = field_layouts[index];
if let Layout::RecursivePointer = result {
Layout::Union(self)
} else {
result
}
field_layouts[index]
}
UnionLayout::NonNullableUnwrapped(field_layouts) => field_layouts[index],
UnionLayout::NullableWrapped {
nullable_id,
other_tags,
@ -146,13 +133,7 @@ impl<'a> UnionLayout<'a> {
};
let field_layouts = other_tags[tag_index as usize];
let result = field_layouts[index];
if let Layout::RecursivePointer = result {
Layout::Union(self)
} else {
result
}
field_layouts[index]
}
UnionLayout::NullableUnwrapped {
@ -161,7 +142,9 @@ impl<'a> UnionLayout<'a> {
} => {
debug_assert_ne!(nullable_id, tag_id != 0);
let result = other_fields[index as usize];
other_fields[index as usize]
}
};
if let Layout::RecursivePointer = result {
Layout::Union(self)
@ -169,18 +152,6 @@ impl<'a> UnionLayout<'a> {
result
}
}
}
}
pub fn stores_tag(&self) -> bool {
match self {
UnionLayout::NonRecursive(_) => true,
UnionLayout::Recursive(_) => true,
UnionLayout::NonNullableUnwrapped(_) => false,
UnionLayout::NullableWrapped { .. } => true,
UnionLayout::NullableUnwrapped { .. } => true,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]