diff --git a/compiler/gen_wasm/src/lib.rs b/compiler/gen_wasm/src/lib.rs index c5dd2e83ce..b1d72458c0 100644 --- a/compiler/gen_wasm/src/lib.rs +++ b/compiler/gen_wasm/src/lib.rs @@ -5,8 +5,8 @@ mod storage; pub mod wasm_module; // Helpers for interfacing to a Wasm module from outside +pub mod wasm32_result; pub mod wasm32_sized; -pub mod wasm32_test_result; use bumpalo::{self, collections::Vec, Bump}; diff --git a/compiler/gen_wasm/src/wasm32_test_result.rs b/compiler/gen_wasm/src/wasm32_result.rs similarity index 74% rename from compiler/gen_wasm/src/wasm32_test_result.rs rename to compiler/gen_wasm/src/wasm32_result.rs index 2f525149d8..f4548c8f75 100644 --- a/compiler/gen_wasm/src/wasm32_test_result.rs +++ b/compiler/gen_wasm/src/wasm32_result.rs @@ -7,8 +7,8 @@ use crate::wasm_module::{ }; use roc_std::{RocDec, RocList, RocOrder, RocStr}; -pub trait Wasm32TestResult { - fn insert_test_wrapper<'a>( +pub trait Wasm32Result { + fn insert_wrapper<'a>( arena: &'a bumpalo::Bump, module: &mut WasmModule<'a>, wrapper_name: &str, @@ -64,9 +64,9 @@ macro_rules! build_wrapper_body_primitive { }; } -macro_rules! wasm_test_result_primitive { +macro_rules! wasm_result_primitive { ($type_name: ident, $store_instruction: ident, $align: expr) => { - impl Wasm32TestResult for $type_name { + impl Wasm32Result for $type_name { build_wrapper_body_primitive!($store_instruction, $align); } }; @@ -89,9 +89,9 @@ fn build_wrapper_body_stack_memory( code_builder.build_fn_header_and_footer(local_types, size as i32, frame_pointer); } -macro_rules! wasm_test_result_stack_memory { +macro_rules! wasm_result_stack_memory { ($type_name: ident) => { - impl Wasm32TestResult for $type_name { + impl Wasm32Result for $type_name { fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) { build_wrapper_body_stack_memory( code_builder, @@ -103,47 +103,47 @@ macro_rules! wasm_test_result_stack_memory { }; } -wasm_test_result_primitive!(bool, i32_store8, Align::Bytes1); -wasm_test_result_primitive!(RocOrder, i32_store8, Align::Bytes1); +wasm_result_primitive!(bool, i32_store8, Align::Bytes1); +wasm_result_primitive!(RocOrder, i32_store8, Align::Bytes1); -wasm_test_result_primitive!(u8, i32_store8, Align::Bytes1); -wasm_test_result_primitive!(i8, i32_store8, Align::Bytes1); -wasm_test_result_primitive!(u16, i32_store16, Align::Bytes2); -wasm_test_result_primitive!(i16, i32_store16, Align::Bytes2); -wasm_test_result_primitive!(u32, i32_store, Align::Bytes4); -wasm_test_result_primitive!(i32, i32_store, Align::Bytes4); -wasm_test_result_primitive!(u64, i64_store, Align::Bytes8); -wasm_test_result_primitive!(i64, i64_store, Align::Bytes8); -wasm_test_result_primitive!(usize, i32_store, Align::Bytes4); +wasm_result_primitive!(u8, i32_store8, Align::Bytes1); +wasm_result_primitive!(i8, i32_store8, Align::Bytes1); +wasm_result_primitive!(u16, i32_store16, Align::Bytes2); +wasm_result_primitive!(i16, i32_store16, Align::Bytes2); +wasm_result_primitive!(u32, i32_store, Align::Bytes4); +wasm_result_primitive!(i32, i32_store, Align::Bytes4); +wasm_result_primitive!(u64, i64_store, Align::Bytes8); +wasm_result_primitive!(i64, i64_store, Align::Bytes8); +wasm_result_primitive!(usize, i32_store, Align::Bytes4); -wasm_test_result_primitive!(f32, f32_store, Align::Bytes4); -wasm_test_result_primitive!(f64, f64_store, Align::Bytes8); +wasm_result_primitive!(f32, f32_store, Align::Bytes4); +wasm_result_primitive!(f64, f64_store, Align::Bytes8); -wasm_test_result_stack_memory!(u128); -wasm_test_result_stack_memory!(i128); -wasm_test_result_stack_memory!(RocDec); -wasm_test_result_stack_memory!(RocStr); +wasm_result_stack_memory!(u128); +wasm_result_stack_memory!(i128); +wasm_result_stack_memory!(RocDec); +wasm_result_stack_memory!(RocStr); -impl Wasm32TestResult for RocList { +impl Wasm32Result for RocList { fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) { build_wrapper_body_stack_memory(code_builder, main_function_index, 12) } } -impl Wasm32TestResult for &'_ T { +impl Wasm32Result for &'_ T { build_wrapper_body_primitive!(i32_store, Align::Bytes4); } -impl Wasm32TestResult for [T; N] +impl Wasm32Result for [T; N] where - T: Wasm32TestResult + Wasm32Sized, + T: Wasm32Result + Wasm32Sized, { fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) { build_wrapper_body_stack_memory(code_builder, main_function_index, N * T::ACTUAL_WIDTH) } } -impl Wasm32TestResult for () { +impl Wasm32Result for () { fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) { // Main's symbol index is the same as its function index, since the first symbols we created were for procs let main_symbol_index = main_function_index; @@ -153,10 +153,10 @@ impl Wasm32TestResult for () { } } -impl Wasm32TestResult for (T, U) +impl Wasm32Result for (T, U) where - T: Wasm32TestResult + Wasm32Sized, - U: Wasm32TestResult + Wasm32Sized, + T: Wasm32Result + Wasm32Sized, + U: Wasm32Result + Wasm32Sized, { fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) { build_wrapper_body_stack_memory( @@ -167,11 +167,11 @@ where } } -impl Wasm32TestResult for (T, U, V) +impl Wasm32Result for (T, U, V) where - T: Wasm32TestResult + Wasm32Sized, - U: Wasm32TestResult + Wasm32Sized, - V: Wasm32TestResult + Wasm32Sized, + T: Wasm32Result + Wasm32Sized, + U: Wasm32Result + Wasm32Sized, + V: Wasm32Result + Wasm32Sized, { fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) { build_wrapper_body_stack_memory( diff --git a/compiler/test_gen/src/helpers/wasm.rs b/compiler/test_gen/src/helpers/wasm.rs index f16bd5f819..d2bd39ef81 100644 --- a/compiler/test_gen/src/helpers/wasm.rs +++ b/compiler/test_gen/src/helpers/wasm.rs @@ -9,7 +9,7 @@ use wasmer::{Memory, WasmPtr}; use crate::helpers::from_wasmer_memory::FromWasmerMemory; use roc_can::builtins::builtin_defs_map; use roc_collections::all::{MutMap, MutSet}; -use roc_gen_wasm::wasm32_test_result::Wasm32TestResult; +use roc_gen_wasm::wasm32_result::Wasm32Result; use roc_gen_wasm::{DEBUG_LOG_SETTINGS, MEMORY_NAME}; // Should manually match build.rs @@ -40,7 +40,7 @@ pub enum TestType { } #[allow(dead_code)] -pub fn compile_and_load<'a, T: Wasm32TestResult>( +pub fn compile_and_load<'a, T: Wasm32Result>( arena: &'a bumpalo::Bump, src: &str, stdlib: &'a roc_builtins::std::StdLib, @@ -72,7 +72,7 @@ fn src_hash(src: &str) -> u64 { hash_state.finish() } -fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>( +fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>( arena: &'a bumpalo::Bump, stdlib: &'a roc_builtins::std::StdLib, preload_bytes: &[u8], @@ -138,7 +138,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>( procedures, ); - T::insert_test_wrapper(arena, &mut module, TEST_WRAPPER_NAME, main_fn_index); + T::insert_wrapper(arena, &mut module, TEST_WRAPPER_NAME, main_fn_index); // Export the initialiser function for refcount tests let init_refcount_bytes = INIT_REFCOUNT_NAME.as_bytes(); @@ -193,7 +193,7 @@ fn load_bytes_into_runtime(bytes: Vec) -> wasmer::Instance { #[allow(dead_code)] pub fn assert_wasm_evals_to_help(src: &str, phantom: PhantomData) -> Result where - T: FromWasmerMemory + Wasm32TestResult, + T: FromWasmerMemory + Wasm32Result, { let arena = bumpalo::Bump::new(); @@ -239,7 +239,7 @@ pub fn assert_wasm_refcounts_help( num_refcounts: usize, ) -> Result, String> where - T: FromWasmerMemory + Wasm32TestResult, + T: FromWasmerMemory + Wasm32Result, { let arena = bumpalo::Bump::new();