mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-18 09:39:47 +00:00
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:
parent
3c842196fa
commit
93fab26c01
9 changed files with 237 additions and 310 deletions
|
@ -8,7 +8,7 @@ use bumpalo::{collections::Vec, Bump};
|
|||
|
||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_mono::layout::{Builtin, InLayout, LayoutInterner, LayoutRepr, UnionLayout};
|
||||
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::{
|
||||
linking::SymInfo, linking::WasmObjectSymbol, Align, Export, ExportType, LocalId, Signature,
|
||||
ValueType, WasmModule,
|
||||
|
@ -197,7 +197,10 @@ impl Wasm32Result for RocStr {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Wasm32Result> Wasm32Result for RocList<T> {
|
||||
impl<T: Wasm32Result> Wasm32Result for RocList<T>
|
||||
where
|
||||
T: RocRefcounted,
|
||||
{
|
||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||
build_wrapper_body_stack_memory(code_builder, main_function_index, 12)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
|
||||
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocRefcounted, RocResult, RocStr, I128, U128};
|
||||
|
||||
pub trait Wasm32Sized: Sized {
|
||||
const SIZE_OF_WASM: usize;
|
||||
|
@ -53,7 +53,10 @@ impl Wasm32Sized for RocStr {
|
|||
const ALIGN_OF_WASM: usize = 4;
|
||||
}
|
||||
|
||||
impl<T: Wasm32Sized> Wasm32Sized for RocList<T> {
|
||||
impl<T: Wasm32Sized> Wasm32Sized for RocList<T>
|
||||
where
|
||||
T: RocRefcounted,
|
||||
{
|
||||
const SIZE_OF_WASM: usize = 12;
|
||||
const ALIGN_OF_WASM: usize = 4;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue