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 final_continuation = loop {
match stmt {
Stmt::Let(binding, expr, layout, continuation) => {
while let Stmt::Let(binding, expr, layout, continuation) = stmt {
environment.add_symbol_layout(*binding, *layout);
// update the environment based on the expr
@ -162,7 +160,7 @@ fn specialize_drops_stmt<'a, 'i>(
Call(_) => {
// Expr::Call is tricky and we are lazy and handle it elsewhere. it
// ends a chain of eligible Let statements.
break stmt;
break;
}
Literal(crate::ir::Literal::Int(i)) => {
environment
@ -178,12 +176,7 @@ fn specialize_drops_stmt<'a, 'i>(
environment.symbol_tag.insert(*binding, *tag_id);
for (index, child) in children.iter().enumerate() {
environment.add_union_child(
*binding,
*child,
*tag_id,
index as u64,
);
environment.add_union_child(*binding, *child, *tag_id, index as u64);
}
}
Struct(children) => {
@ -195,7 +188,6 @@ fn specialize_drops_stmt<'a, 'i>(
index, structure, ..
} => {
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?
// 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, ..
} => {
let it =
children.iter().enumerate().filter_map(|(index, child)| {
match child {
children
.iter()
.enumerate()
.filter_map(|(index, child)| match child {
ListLiteralElement::Literal(_) => None,
ListLiteralElement::Symbol(s) => Some((index, s)),
}
});
for (index, child) in it {
@ -236,10 +229,8 @@ fn specialize_drops_stmt<'a, 'i>(
}
}
Reset { .. } | Expr::ResetRef { .. } => { /* do nothing */ }
RuntimeErrorFunction(_)
| GetTagId { .. }
| EmptyArray
| NullPointer => { /* do nothing */ }
RuntimeErrorFunction(_) | GetTagId { .. } | EmptyArray | NullPointer => { /* do nothing */
}
}
// now store the let binding for later
@ -248,31 +239,11 @@ fn specialize_drops_stmt<'a, 'i>(
// and "recurse" down the statement chain
stmt = continuation;
}
_ => {
// the chain of eligeble `Let`s stops at any non-let statement
break stmt;
}
};
};
let mut final_continuation = specialize_drops_stmt(
arena,
layout_interner,
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
stack.into_iter().rev().fold(
specialize_drops_stmt(arena, layout_interner, ident_ids, environment, stmt),
|acc, (binding, expr, layout)| arena.alloc(Stmt::Let(binding, expr, layout, acc)),
)
}
Stmt::Switch {
cond_symbol,