mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Merge branch 'main' into Frame-Limited
This commit is contained in:
commit
9b410694fe
591 changed files with 42667 additions and 28227 deletions
|
@ -125,16 +125,6 @@ impl<'a> CodeGenHelp<'a> {
|
|||
modify: &ModifyRc,
|
||||
following: &'a Stmt<'a>,
|
||||
) -> (&'a Stmt<'a>, Vec<'a, (Symbol, ProcLayout<'a>)>) {
|
||||
if !refcount::is_rc_implemented_yet(layout_interner, layout) {
|
||||
// Just a warning, so we can decouple backend development from refcounting development.
|
||||
// When we are closer to completion, we can change it to a panic.
|
||||
println!(
|
||||
"WARNING! MEMORY LEAK! Refcounting not yet implemented for Layout {:?}",
|
||||
layout
|
||||
);
|
||||
return (following, Vec::new_in(self.arena));
|
||||
}
|
||||
|
||||
let op = match modify {
|
||||
ModifyRc::Inc(..) => HelperOp::Inc,
|
||||
ModifyRc::Dec(_) => HelperOp::Dec,
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn refcount_stmt<'a>(
|
|||
|
||||
ModifyRc::DecRef(structure) => {
|
||||
match layout_interner.get(layout) {
|
||||
// Str has no children, so we might as well do what we normally do and call the helper.
|
||||
// Str has no children, so Dec is the same as DecRef.
|
||||
Layout::Builtin(Builtin::Str) => {
|
||||
ctx.op = HelperOp::Dec;
|
||||
refcount_stmt(
|
||||
|
@ -127,8 +127,6 @@ pub fn refcount_generic<'a>(
|
|||
layout: InLayout<'a>,
|
||||
structure: Symbol,
|
||||
) -> Stmt<'a> {
|
||||
debug_assert!(is_rc_implemented_yet(layout_interner, layout));
|
||||
|
||||
match layout_interner.get(layout) {
|
||||
Layout::Builtin(Builtin::Int(_) | Builtin::Float(_) | Builtin::Bool | Builtin::Decimal) => {
|
||||
// Generate a dummy function that immediately returns Unit
|
||||
|
@ -141,7 +139,6 @@ pub fn refcount_generic<'a>(
|
|||
ident_ids,
|
||||
ctx,
|
||||
layout_interner,
|
||||
layout,
|
||||
elem_layout,
|
||||
structure,
|
||||
),
|
||||
|
@ -416,44 +413,6 @@ pub fn refcount_reset_proc_body<'a>(
|
|||
rc_ptr_stmt
|
||||
}
|
||||
|
||||
// Check if refcounting is implemented yet. In the long term, this will be deleted.
|
||||
// In the short term, it helps us to skip refcounting and let it leak, so we can make
|
||||
// progress incrementally. Kept in sync with generate_procs using assertions.
|
||||
pub fn is_rc_implemented_yet<'a, I>(interner: &I, layout: InLayout<'a>) -> bool
|
||||
where
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use UnionLayout::*;
|
||||
|
||||
match interner.get(layout) {
|
||||
Layout::Builtin(Builtin::List(elem_layout)) => is_rc_implemented_yet(interner, elem_layout),
|
||||
Layout::Builtin(_) => true,
|
||||
Layout::Struct { field_layouts, .. } => field_layouts
|
||||
.iter()
|
||||
.all(|l| is_rc_implemented_yet(interner, *l)),
|
||||
Layout::Union(union_layout) => match union_layout {
|
||||
NonRecursive(tags) => tags
|
||||
.iter()
|
||||
.all(|fields| fields.iter().all(|l| is_rc_implemented_yet(interner, *l))),
|
||||
Recursive(tags) => tags
|
||||
.iter()
|
||||
.all(|fields| fields.iter().all(|l| is_rc_implemented_yet(interner, *l))),
|
||||
NonNullableUnwrapped(fields) => {
|
||||
fields.iter().all(|l| is_rc_implemented_yet(interner, *l))
|
||||
}
|
||||
NullableWrapped { other_tags, .. } => other_tags
|
||||
.iter()
|
||||
.all(|fields| fields.iter().all(|l| is_rc_implemented_yet(interner, *l))),
|
||||
NullableUnwrapped { other_fields, .. } => other_fields
|
||||
.iter()
|
||||
.all(|l| is_rc_implemented_yet(interner, *l)),
|
||||
},
|
||||
Layout::LambdaSet(lambda_set) => is_rc_implemented_yet(interner, lambda_set.representation),
|
||||
Layout::RecursivePointer(_) => true,
|
||||
Layout::Boxed(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn rc_return_stmt<'a>(
|
||||
root: &CodeGenHelp<'a>,
|
||||
ident_ids: &mut IdentIds,
|
||||
|
@ -765,7 +724,6 @@ fn refcount_list<'a>(
|
|||
ident_ids: &mut IdentIds,
|
||||
ctx: &mut Context<'a>,
|
||||
layout_interner: &mut STLayoutInterner<'a>,
|
||||
layout: InLayout,
|
||||
elem_layout: InLayout<'a>,
|
||||
structure: Symbol,
|
||||
) -> Stmt<'a> {
|
||||
|
@ -773,8 +731,7 @@ fn refcount_list<'a>(
|
|||
let arena = root.arena;
|
||||
|
||||
// A "Box" layout (heap pointer to a single list element)
|
||||
let box_union_layout = UnionLayout::NonNullableUnwrapped(arena.alloc([elem_layout]));
|
||||
let box_layout = layout_interner.insert(Layout::Union(box_union_layout));
|
||||
let box_layout = layout_interner.insert(Layout::Boxed(elem_layout));
|
||||
|
||||
//
|
||||
// Check if the list is empty
|
||||
|
@ -814,7 +771,7 @@ fn refcount_list<'a>(
|
|||
//
|
||||
|
||||
let rc_ptr = root.create_symbol(ident_ids, "rc_ptr");
|
||||
let alignment = layout_interner.alignment_bytes(layout);
|
||||
let elem_alignment = layout_interner.alignment_bytes(elem_layout);
|
||||
|
||||
let ret_stmt = rc_return_stmt(root, ident_ids, ctx);
|
||||
let modify_list = modify_refcount(
|
||||
|
@ -822,7 +779,7 @@ fn refcount_list<'a>(
|
|||
ident_ids,
|
||||
ctx,
|
||||
rc_ptr,
|
||||
alignment,
|
||||
elem_alignment,
|
||||
arena.alloc(ret_stmt),
|
||||
);
|
||||
|
||||
|
@ -845,7 +802,7 @@ fn refcount_list<'a>(
|
|||
layout_interner,
|
||||
elem_layout,
|
||||
LAYOUT_UNIT,
|
||||
box_union_layout,
|
||||
box_layout,
|
||||
len,
|
||||
elements,
|
||||
get_rc_and_modify_list,
|
||||
|
@ -895,7 +852,7 @@ fn refcount_list_elems<'a>(
|
|||
layout_interner: &mut STLayoutInterner<'a>,
|
||||
elem_layout: InLayout<'a>,
|
||||
ret_layout: InLayout<'a>,
|
||||
box_union_layout: UnionLayout<'a>,
|
||||
box_layout: InLayout<'a>,
|
||||
length: Symbol,
|
||||
elements: Symbol,
|
||||
following: Stmt<'a>,
|
||||
|
@ -955,17 +912,11 @@ fn refcount_list_elems<'a>(
|
|||
|
||||
// Cast integer to box pointer
|
||||
let box_ptr = root.create_symbol(ident_ids, "box");
|
||||
let box_layout = layout_interner.insert(Layout::Union(box_union_layout));
|
||||
let box_stmt = |next| let_lowlevel(arena, box_layout, box_ptr, PtrCast, &[addr], next);
|
||||
|
||||
// Dereference the box pointer to get the current element
|
||||
let elem = root.create_symbol(ident_ids, "elem");
|
||||
let elem_expr = Expr::UnionAtIndex {
|
||||
structure: box_ptr,
|
||||
union_layout: box_union_layout,
|
||||
tag_id: 0,
|
||||
index: 0,
|
||||
};
|
||||
let elem_expr = Expr::ExprUnbox { symbol: box_ptr };
|
||||
let elem_stmt = |next| Stmt::Let(elem, elem_expr, elem_layout, next);
|
||||
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue