cleanup after review

This commit is contained in:
Folkert 2023-07-12 17:55:21 +02:00
parent da9482b7fa
commit a50f013fce
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -152,9 +152,7 @@ fn specialize_drops_stmt<'a, 'i>(
let mut stmt = stmt; let mut stmt = stmt;
let final_continuation = loop { while let Stmt::Let(binding, expr, layout, continuation) = stmt {
match stmt {
Stmt::Let(binding, expr, layout, continuation) => {
environment.add_symbol_layout(*binding, *layout); environment.add_symbol_layout(*binding, *layout);
// update the environment based on the expr // update the environment based on the expr
@ -162,7 +160,7 @@ fn specialize_drops_stmt<'a, 'i>(
Call(_) => { Call(_) => {
// Expr::Call is tricky and we are lazy and handle it elsewhere. it // Expr::Call is tricky and we are lazy and handle it elsewhere. it
// ends a chain of eligible Let statements. // ends a chain of eligible Let statements.
break stmt; break;
} }
Literal(crate::ir::Literal::Int(i)) => { Literal(crate::ir::Literal::Int(i)) => {
environment environment
@ -178,12 +176,7 @@ fn specialize_drops_stmt<'a, 'i>(
environment.symbol_tag.insert(*binding, *tag_id); environment.symbol_tag.insert(*binding, *tag_id);
for (index, child) in children.iter().enumerate() { for (index, child) in children.iter().enumerate() {
environment.add_union_child( environment.add_union_child(*binding, *child, *tag_id, index as u64);
*binding,
*child,
*tag_id,
index as u64,
);
} }
} }
Struct(children) => { Struct(children) => {
@ -195,7 +188,6 @@ fn specialize_drops_stmt<'a, 'i>(
index, structure, .. index, structure, ..
} => { } => {
environment.add_struct_child(*structure, *binding, *index); environment.add_struct_child(*structure, *binding, *index);
// alloc_let_with_continuation!(environment)
// TODO do we need to remove the indexed value to prevent it from being dropped sooner? // TODO do we need to remove the indexed value to prevent it from being dropped sooner?
// It will only be dropped sooner if the reference count is 1. Which can only happen if there is no increment before. // It will only be dropped sooner if the reference count is 1. Which can only happen if there is no increment before.
@ -224,11 +216,12 @@ fn specialize_drops_stmt<'a, 'i>(
elems: children, .. elems: children, ..
} => { } => {
let it = let it =
children.iter().enumerate().filter_map(|(index, child)| { children
match child { .iter()
.enumerate()
.filter_map(|(index, child)| match child {
ListLiteralElement::Literal(_) => None, ListLiteralElement::Literal(_) => None,
ListLiteralElement::Symbol(s) => Some((index, s)), ListLiteralElement::Symbol(s) => Some((index, s)),
}
}); });
for (index, child) in it { for (index, child) in it {
@ -236,10 +229,8 @@ fn specialize_drops_stmt<'a, 'i>(
} }
} }
Reset { .. } | Expr::ResetRef { .. } => { /* do nothing */ } Reset { .. } | Expr::ResetRef { .. } => { /* do nothing */ }
RuntimeErrorFunction(_) RuntimeErrorFunction(_) | GetTagId { .. } | EmptyArray | NullPointer => { /* do nothing */
| GetTagId { .. } }
| EmptyArray
| NullPointer => { /* do nothing */ }
} }
// now store the let binding for later // now store the let binding for later
@ -248,31 +239,11 @@ fn specialize_drops_stmt<'a, 'i>(
// and "recurse" down the statement chain // and "recurse" down the statement chain
stmt = continuation; stmt = continuation;
} }
_ => {
// the chain of eligeble `Let`s stops at any non-let statement
break stmt;
}
};
};
let mut final_continuation = specialize_drops_stmt( stack.into_iter().rev().fold(
arena, specialize_drops_stmt(arena, layout_interner, ident_ids, environment, stmt),
layout_interner, |acc, (binding, expr, layout)| arena.alloc(Stmt::Let(binding, expr, layout, acc)),
ident_ids, )
environment,
final_continuation,
);
for (binding, expr, layout) in stack.into_iter().rev() {
final_continuation = arena.alloc(Stmt::Let(
binding,
expr,
layout,
arena.alloc(final_continuation),
));
}
final_continuation
} }
Stmt::Switch { Stmt::Switch {
cond_symbol, cond_symbol,