mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Merge pull request #2301 from rtfeldman/wasm-refcount-list
Wasm refcounting for lists
This commit is contained in:
commit
f767014f30
8 changed files with 514 additions and 117 deletions
|
@ -680,17 +680,13 @@ impl<'a> WasmBackend<'a> {
|
|||
}
|
||||
|
||||
Expr::Array { elems, elem_layout } => {
|
||||
if let StoredValue::StackMemory {
|
||||
location,
|
||||
alignment_bytes,
|
||||
..
|
||||
} = storage
|
||||
{
|
||||
if let StoredValue::StackMemory { location, .. } = storage {
|
||||
let size = elem_layout.stack_size(PTR_SIZE) * (elems.len() as u32);
|
||||
|
||||
// Allocate heap space and store its address in a local variable
|
||||
let heap_local_id = self.storage.create_anonymous_local(PTR_TYPE);
|
||||
self.allocate_with_refcount(Some(size), *alignment_bytes, 1);
|
||||
let heap_alignment = elem_layout.alignment_bytes(PTR_SIZE);
|
||||
self.allocate_with_refcount(Some(size), heap_alignment, 1);
|
||||
self.code_builder.set_local(heap_local_id);
|
||||
|
||||
let (stack_local_id, stack_offset) =
|
||||
|
@ -1050,12 +1046,11 @@ impl<'a> WasmBackend<'a> {
|
|||
|
||||
// Save the allocation address to a temporary local variable
|
||||
let local_id = self.storage.create_anonymous_local(ValueType::I32);
|
||||
self.code_builder.set_local(local_id);
|
||||
self.code_builder.tee_local(local_id);
|
||||
|
||||
// Write the initial refcount
|
||||
let refcount_offset = extra_bytes - PTR_SIZE;
|
||||
let encoded_refcount = (initial_refcount as i32) - 1 + i32::MIN;
|
||||
self.code_builder.get_local(local_id);
|
||||
self.code_builder.i32_const(encoded_refcount);
|
||||
self.code_builder.i32_store(Align::Bytes4, refcount_offset);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue