mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
refactor
This commit is contained in:
parent
84855dae5e
commit
e80f8a5114
2 changed files with 15 additions and 42 deletions
|
@ -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;
|
||||||
|
|
|
@ -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,7 +142,9 @@ 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 {
|
if let Layout::RecursivePointer = result {
|
||||||
Layout::Union(self)
|
Layout::Union(self)
|
||||||
|
@ -170,18 +153,6 @@ impl<'a> UnionLayout<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct LambdaSet<'a> {
|
pub struct LambdaSet<'a> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue