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,26 +807,57 @@ fn specialize_boxed<'a, 'i>(
|
||||||
incremented_children: &mut MutSet<Child>,
|
incremented_children: &mut MutSet<Child>,
|
||||||
symbol: &Symbol,
|
symbol: &Symbol,
|
||||||
continuation: &'a Stmt<'a>,
|
continuation: &'a Stmt<'a>,
|
||||||
) -> &'a mut Stmt<'a> {
|
) -> &'a Stmt<'a> {
|
||||||
let removed = match incremented_children.iter().next() {
|
let removed = match incremented_children.iter().next() {
|
||||||
Some(s) => incremented_children.remove(&s.clone()),
|
Some(s) => {
|
||||||
None => false,
|
let s = *s;
|
||||||
|
incremented_children.remove(&s);
|
||||||
|
Some(s)
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_continuation =
|
let new_continuation =
|
||||||
specialize_drops_stmt(arena, layout_interner, ident_ids, environment, continuation);
|
specialize_drops_stmt(arena, layout_interner, ident_ids, environment, continuation);
|
||||||
|
|
||||||
if removed {
|
match removed {
|
||||||
// No need to decrement the containing value since we already decremented the child.
|
Some(s) => {
|
||||||
|
branch_uniqueness(
|
||||||
|
arena,
|
||||||
|
ident_ids,
|
||||||
|
layout_interner,
|
||||||
|
environment,
|
||||||
|
*symbol,
|
||||||
|
// If the symbol is unique:
|
||||||
|
// - free the box
|
||||||
|
|_, _, _| {
|
||||||
arena.alloc(Stmt::Refcounting(
|
arena.alloc(Stmt::Refcounting(
|
||||||
|
// TODO can be replaced by free if ever added to the IR.
|
||||||
ModifyRc::DecRef(*symbol),
|
ModifyRc::DecRef(*symbol),
|
||||||
new_continuation,
|
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.
|
// No known children, keep decrementing the symbol.
|
||||||
arena.alloc(Stmt::Refcounting(ModifyRc::Dec(*symbol), new_continuation))
|
arena.alloc(Stmt::Refcounting(ModifyRc::Dec(*symbol), new_continuation))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn specialize_list<'a, 'i>(
|
fn specialize_list<'a, 'i>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue