fix dev-wasm ListGetUnsafe refcounting

This commit is contained in:
Brendan Hansknecht 2024-07-12 16:50:02 -07:00
parent 5d613cd5f5
commit 0d083bc192
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
2 changed files with 20 additions and 7 deletions

View file

@ -416,13 +416,6 @@ impl<'a> LowLevelCall<'a> {
AddressValue::NotLoaded(elem_local),
0,
);
// Increment refcount
if self.ret_layout_raw.is_refcounted(backend.layout_interner) {
let inc_fn = backend.get_refcount_fn_index(self.ret_layout, HelperOp::Inc);
backend.code_builder.get_local(elem_local);
backend.code_builder.call(inc_fn);
}
}
ListReplaceUnsafe => {
// List.replace_unsafe : List elem, U64, elem -> { list: List elem, value: elem }

View file

@ -179,6 +179,26 @@ fn list_str_slice() {
);
}
#[test]
#[cfg(feature = "gen-wasm")]
fn list_get() {
assert_refcounts!(
indoc!(
r#"
s = Str.concat "A long enough string " "to be heap-allocated"
i1 = [s, s, s]
List.get i1 1
|> Result.withDefault ""
"#
),
RocStr,
&[
(StandardRC, Live(1)), // s
(AfterSize, Deallocated), // i1
]
);
}
#[test]
#[cfg(feature = "gen-wasm")]
fn list_map() {