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> { ) -> StorePattern<'a> {
use Pattern::*; 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 arg_layouts = Vec::with_capacity_in(arguments.len(), env.arena);
let mut is_productive = false; 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> { pub fn layout_at(self, tag_id: u8, index: usize) -> Layout<'a> {
match self { let result = match self {
UnionLayout::NonRecursive(tag_layouts) => { UnionLayout::NonRecursive(tag_layouts) => {
let field_layouts = tag_layouts[tag_id as usize]; 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) => { UnionLayout::Recursive(tag_layouts) => {
let field_layouts = tag_layouts[tag_id as usize]; let field_layouts = tag_layouts[tag_id as usize];
let result = field_layouts[index]; 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
}
} }
UnionLayout::NonNullableUnwrapped(field_layouts) => field_layouts[index],
UnionLayout::NullableWrapped { UnionLayout::NullableWrapped {
nullable_id, nullable_id,
other_tags, other_tags,
@ -146,13 +133,7 @@ impl<'a> UnionLayout<'a> {
}; };
let field_layouts = other_tags[tag_index as usize]; let field_layouts = other_tags[tag_index as usize];
let result = field_layouts[index]; field_layouts[index]
if let Layout::RecursivePointer = result {
Layout::Union(self)
} else {
result
}
} }
UnionLayout::NullableUnwrapped { UnionLayout::NullableUnwrapped {
@ -161,24 +142,14 @@ impl<'a> UnionLayout<'a> {
} => { } => {
debug_assert_ne!(nullable_id, tag_id != 0); 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)
} else {
result
}
} }
} };
}
pub fn stores_tag(&self) -> bool { if let Layout::RecursivePointer = result {
match self { Layout::Union(self)
UnionLayout::NonRecursive(_) => true, } else {
UnionLayout::Recursive(_) => true, result
UnionLayout::NonNullableUnwrapped(_) => false,
UnionLayout::NullableWrapped { .. } => true,
UnionLayout::NullableUnwrapped { .. } => true,
} }
} }
} }