mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
consider tags that are represented as NULL
This commit is contained in:
parent
5250e930aa
commit
6f48c9762b
2 changed files with 17 additions and 17 deletions
|
@ -196,6 +196,16 @@ impl<'a> UnionLayout<'a> {
|
|||
UnionLayout::NonNullableUnwrapped(_) | UnionLayout::NullableUnwrapped { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tag_is_null(&self, tag_id: u8) -> bool {
|
||||
match self {
|
||||
UnionLayout::NonRecursive(_)
|
||||
| UnionLayout::NonNullableUnwrapped(_)
|
||||
| UnionLayout::Recursive(_) => false,
|
||||
UnionLayout::NullableWrapped { nullable_id, .. } => *nullable_id == tag_id as i64,
|
||||
UnionLayout::NullableUnwrapped { nullable_id, .. } => *nullable_id == (tag_id != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
|
|
|
@ -36,21 +36,11 @@ fn may_reuse(tag_layout: UnionLayout, tag_id: u8, other: &CtorInfo) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
match tag_layout {
|
||||
UnionLayout::NonRecursive(_)
|
||||
| UnionLayout::Recursive(_)
|
||||
| UnionLayout::NonNullableUnwrapped(_) => true,
|
||||
UnionLayout::NullableWrapped { nullable_id, .. } => {
|
||||
// if the source tag id is represented as NULL, there is no memory to re-use
|
||||
// if the current tag id is represented as NULL, then we don't need to re-use the
|
||||
// memory here and can use it somewhere else
|
||||
other.id as i64 != nullable_id && tag_id as i64 != nullable_id
|
||||
}
|
||||
UnionLayout::NullableUnwrapped { nullable_id, .. } => {
|
||||
// idem
|
||||
(other.id != 0) != nullable_id && (tag_id != 0) != nullable_id
|
||||
}
|
||||
}
|
||||
// we should not get here if the tag we matched on is represented as NULL
|
||||
debug_assert!(!tag_layout.tag_is_null(other.id));
|
||||
|
||||
// furthermore, we can only use the memory if the tag we're creating is non-NULL
|
||||
!tag_layout.tag_is_null(tag_id)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -421,7 +411,7 @@ fn function_r<'a, 'i>(env: &mut Env<'a, 'i>, stmt: &'a Stmt<'a>) -> &'a Stmt<'a>
|
|||
layout,
|
||||
tag_id,
|
||||
} => match layout {
|
||||
Layout::Union(union_layout) => {
|
||||
Layout::Union(union_layout) if !union_layout.tag_is_null(*tag_id) => {
|
||||
let ctor_info = CtorInfo {
|
||||
layout: *union_layout,
|
||||
id: *tag_id,
|
||||
|
@ -446,7 +436,7 @@ fn function_r<'a, 'i>(env: &mut Env<'a, 'i>, stmt: &'a Stmt<'a>) -> &'a Stmt<'a>
|
|||
layout,
|
||||
tag_id,
|
||||
} => match layout {
|
||||
Layout::Union(union_layout) => {
|
||||
Layout::Union(union_layout) if !union_layout.tag_is_null(*tag_id) => {
|
||||
let ctor_info = CtorInfo {
|
||||
layout: *union_layout,
|
||||
id: *tag_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue