mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-22 03:22:30 +00:00
fix and optimize tail-recursive decrement
This commit is contained in:
parent
755c294d90
commit
a7c7ad2d17
2 changed files with 53 additions and 44 deletions
|
@ -538,42 +538,37 @@ impl<'a> CodeGenHelp<'a> {
|
|||
|
||||
fn union_tail_recursion_fields(
|
||||
&self,
|
||||
layout_interner: &STLayoutInterner<'a>,
|
||||
union_in_layout: InLayout<'a>,
|
||||
union: UnionLayout<'a>,
|
||||
) -> Option<Vec<'a, Option<usize>>> {
|
||||
use UnionLayout::*;
|
||||
match union {
|
||||
NonRecursive(_) => None,
|
||||
|
||||
Recursive(tags) => self.union_tail_recursion_fields_help(layout_interner, tags),
|
||||
Recursive(tags) => self.union_tail_recursion_fields_help(union_in_layout, tags),
|
||||
|
||||
NonNullableUnwrapped(field_layouts) => {
|
||||
self.union_tail_recursion_fields_help(layout_interner, &[field_layouts])
|
||||
self.union_tail_recursion_fields_help(union_in_layout, &[field_layouts])
|
||||
}
|
||||
|
||||
NullableWrapped {
|
||||
other_tags: tags, ..
|
||||
} => self.union_tail_recursion_fields_help(layout_interner, tags),
|
||||
} => self.union_tail_recursion_fields_help(union_in_layout, tags),
|
||||
|
||||
NullableUnwrapped { other_fields, .. } => {
|
||||
self.union_tail_recursion_fields_help(layout_interner, &[other_fields])
|
||||
self.union_tail_recursion_fields_help(union_in_layout, &[other_fields])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn union_tail_recursion_fields_help(
|
||||
&self,
|
||||
layout_interner: &STLayoutInterner<'a>,
|
||||
in_layout: InLayout<'a>,
|
||||
tags: &[&'a [InLayout<'a>]],
|
||||
) -> Option<Vec<'a, Option<usize>>> {
|
||||
let tailrec_indices = tags
|
||||
.iter()
|
||||
.map(|fields| {
|
||||
let found_index = fields
|
||||
.iter()
|
||||
.position(|f| matches!(layout_interner.get(*f), Layout::RecursivePointer(_)));
|
||||
found_index
|
||||
})
|
||||
.map(|fields| fields.iter().position(|f| *f == in_layout))
|
||||
.collect_in::<Vec<_>>(self.arena);
|
||||
|
||||
if tailrec_indices.iter().any(|i| i.is_some()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue