Merge pull request #5432 from JTeeuwissen/5430-string-memory-issue

updated drop_specialization for boxes
This commit is contained in:
Folkert de Vries 2023-05-23 18:13:29 +02:00 committed by GitHub
commit 9b58c0fb9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -807,25 +807,56 @@ 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>(