Add a RocRefcounted trait in roc_std

This is required to properly handle refcounting of RocList.
Without it, we can't tell if we need to get the length from the heap.
That said, it isn't a pretty solution.

I think dealing with generating bespoke type in glue would feel nicer than this but be much more work.
It also would deal with the issue of implementations in the bitcode not matching external libraries.
That said, it would require exposing way more symbols from roc for each monomophorphized list variant.
This commit is contained in:
Brendan Hansknecht 2024-04-05 17:48:30 -07:00
parent 3c842196fa
commit 93fab26c01
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
9 changed files with 237 additions and 310 deletions

View file

@ -1,7 +1,7 @@
use roc_error_macros::internal_error;
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
use roc_mono::layout::Builtin;
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocRefcounted, RocResult, RocStr, I128, U128};
use roc_wasm_module::round_up_to_alignment;
use std::convert::TryInto;
@ -84,7 +84,10 @@ impl FromWasm32Memory for RocStr {
}
}
impl<T: FromWasm32Memory + Clone> FromWasm32Memory for RocList<T> {
impl<T: FromWasm32Memory + Clone> FromWasm32Memory for RocList<T>
where
T: RocRefcounted,
{
fn decode(memory: &[u8], offset: u32) -> Self {
let elements = <u32 as FromWasm32Memory>::decode(memory, offset + 4 * Builtin::WRAPPER_PTR);
let length = <u32 as FromWasm32Memory>::decode(memory, offset + 4 * Builtin::WRAPPER_LEN);