mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Merge pull request #5432 from JTeeuwissen/5430-string-memory-issue
updated drop_specialization for boxes
This commit is contained in:
commit
9b58c0fb9c
1 changed files with 43 additions and 12 deletions
|
@ -807,25 +807,56 @@ fn specialize_boxed<'a, 'i>(
|
|||
incremented_children: &mut MutSet<Child>,
|
||||
symbol: &Symbol,
|
||||
continuation: &'a Stmt<'a>,
|
||||
) -> &'a mut Stmt<'a> {
|
||||
) -> &'a Stmt<'a> {
|
||||
let removed = match incremented_children.iter().next() {
|
||||
Some(s) => incremented_children.remove(&s.clone()),
|
||||
None => false,
|
||||
Some(s) => {
|
||||
let s = *s;
|
||||
incremented_children.remove(&s);
|
||||
Some(s)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
let new_continuation =
|
||||
specialize_drops_stmt(arena, layout_interner, ident_ids, environment, continuation);
|
||||
|
||||
if removed {
|
||||
// No need to decrement the containing value since we already decremented the child.
|
||||
match removed {
|
||||
Some(s) => {
|
||||
branch_uniqueness(
|
||||
arena,
|
||||
ident_ids,
|
||||
layout_interner,
|
||||
environment,
|
||||
*symbol,
|
||||
// If the symbol is unique:
|
||||
// - free the box
|
||||
|_, _, _| {
|
||||
arena.alloc(Stmt::Refcounting(
|
||||
// TODO can be replaced by free if ever added to the IR.
|
||||
ModifyRc::DecRef(*symbol),
|
||||
new_continuation,
|
||||
))
|
||||
} else {
|
||||
},
|
||||
// If the symbol is not unique:
|
||||
// - increment the child
|
||||
// - decref the box
|
||||
|_, _, _| {
|
||||
arena.alloc(Stmt::Refcounting(
|
||||
ModifyRc::Inc(s, 1),
|
||||
arena.alloc(Stmt::Refcounting(
|
||||
ModifyRc::DecRef(*symbol),
|
||||
new_continuation,
|
||||
)),
|
||||
))
|
||||
},
|
||||
new_continuation,
|
||||
)
|
||||
}
|
||||
None => {
|
||||
// No known children, keep decrementing the symbol.
|
||||
arena.alloc(Stmt::Refcounting(ModifyRc::Dec(*symbol), new_continuation))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn specialize_list<'a, 'i>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue