wasm: fix refcount bug in higher order low-levels

This commit is contained in:
Brian Carroll 2022-08-05 09:51:51 +01:00
parent 7f44ace383
commit e71a6da62d
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
4 changed files with 31 additions and 3 deletions

View file

@ -2319,7 +2319,13 @@ fn list_map_n<'a>(
// If we have lists of different lengths, we may need to decrement
let num_wasm_args = if arg_elem_layouts.len() > 1 {
for el in arg_elem_layouts.iter() {
let idx = backend.get_refcount_fn_index(*el, HelperOp::Dec);
// The dec function will be passed a pointer to the element within the list, not the element itself!
// Here we wrap the layout in a Struct to ensure we get the right code gen
let el_ptr = Layout::Struct {
field_order_hash: FieldOrderHash::from_ordered_fields(&[]),
field_layouts: backend.env.arena.alloc([*el]),
};
let idx = backend.get_refcount_fn_index(el_ptr, HelperOp::Dec);
let ptr = backend.get_fn_ptr(idx);
backend.code_builder.i32_const(ptr);
}