mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
free or reuse unconditionally when value is unique
This commit is contained in:
parent
e3ab023f62
commit
fc3004da58
21 changed files with 381 additions and 69 deletions
|
@ -2919,6 +2919,39 @@ pub(crate) fn build_exp_stmt<'a, 'ctx>(
|
|||
cont,
|
||||
)
|
||||
}
|
||||
|
||||
Free(symbol) => {
|
||||
// unconditionally deallocate the symbol
|
||||
let (value, layout) = scope.load_symbol_and_layout(symbol);
|
||||
let alignment = layout_interner.alignment_bytes(layout);
|
||||
|
||||
debug_assert!(value.is_pointer_value());
|
||||
let value = value.into_pointer_value();
|
||||
|
||||
let clear_tag_id = match layout_interner.chase_recursive(layout) {
|
||||
LayoutRepr::Union(union) => union.stores_tag_id_in_pointer(env.target_info),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let ptr = if clear_tag_id {
|
||||
tag_pointer_clear_tag_id(env, value)
|
||||
} else {
|
||||
value
|
||||
};
|
||||
|
||||
let rc_ptr = PointerToRefcount::from_ptr_to_data(env, ptr);
|
||||
rc_ptr.deallocate(env, alignment);
|
||||
|
||||
build_exp_stmt(
|
||||
env,
|
||||
layout_interner,
|
||||
layout_ids,
|
||||
func_spec_solutions,
|
||||
scope,
|
||||
parent,
|
||||
cont,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue