Merge branch 'trunk' of github.com:rtfeldman/roc into wasm-runtime-error

This commit is contained in:
Brian Carroll 2022-02-27 22:57:23 +00:00
commit 7ccc5ec768
337 changed files with 17368 additions and 5923 deletions

View file

@ -1,7 +1,6 @@
use libloading::Library;
use roc_build::link::{link, LinkType};
use roc_builtins::bitcode;
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::MutMap;
use roc_region::all::LineInfo;
use tempfile::tempdir;
@ -58,7 +57,6 @@ pub fn helper(
src_dir,
exposed_types,
roc_target::TargetInfo::default_x86_64(),
builtin_defs_map,
);
let mut loaded = loaded.expect("failed to load module");

View file

@ -1,5 +1,5 @@
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
use roc_std::{RocDec, RocList, RocOrder, RocStr};
use roc_std::{ReferenceCount, RocDec, RocList, RocOrder, RocStr};
pub trait FromWasmerMemory: Wasm32Sized {
fn decode(memory: &wasmer::Memory, offset: u32) -> Self;
@ -61,19 +61,19 @@ impl FromWasmerMemory for RocStr {
let actual_length = (last_byte ^ 0b1000_0000) as usize;
let slice = &bytes.to_ne_bytes()[..actual_length as usize];
RocStr::from_slice(slice)
unsafe { RocStr::from_slice(slice) }
} else {
// this is a big string
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(elements);
let foobar = (ptr.deref(memory, 0, length)).unwrap();
let wasm_slice = unsafe { std::mem::transmute(foobar) };
RocStr::from_slice(wasm_slice)
unsafe { RocStr::from_slice(wasm_slice) }
}
}
}
impl<T: FromWasmerMemory + Clone> FromWasmerMemory for RocList<T> {
impl<T: FromWasmerMemory + Clone + ReferenceCount> FromWasmerMemory for RocList<T> {
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let bytes = <u64 as FromWasmerMemory>::decode(memory, offset);

View file

@ -3,14 +3,10 @@ use inkwell::module::Module;
use libloading::Library;
use roc_build::link::module_to_dylib;
use roc_build::program::FunctionIterator;
use roc_can::builtins::builtin_defs_map;
use roc_can::def::Def;
use roc_collections::all::{MutMap, MutSet};
use roc_gen_llvm::llvm::externs::add_default_roc_externs;
use roc_module::symbol::Symbol;
use roc_mono::ir::OptLevel;
use roc_region::all::LineInfo;
use roc_types::subs::VarStore;
use target_lexicon::Triple;
fn promote_expr_to_module(src: &str) -> String {
@ -25,9 +21,6 @@ fn promote_expr_to_module(src: &str) -> String {
buffer
}
pub fn test_builtin_defs(symbol: Symbol, var_store: &mut VarStore) -> Option<Def> {
builtin_defs_map(symbol, var_store)
}
#[allow(clippy::too_many_arguments)]
fn create_llvm_module<'a>(
@ -67,7 +60,6 @@ fn create_llvm_module<'a>(
src_dir,
exposed_types,
target_info,
test_builtin_defs,
);
let mut loaded = match loaded {
@ -497,10 +489,7 @@ where
match test_wrapper.call(&[]) {
Err(e) => Err(format!("call to `test_wrapper`: {:?}", e)),
Ok(result) => {
let address = match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
};
let address = result[0].unwrap_i32();
let output = <T as crate::helpers::llvm::FromWasmerMemory>::decode(
memory,

View file

@ -7,7 +7,6 @@ use std::path::{Path, PathBuf};
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_result::Wasm32Result;
use roc_gen_wasm::{DEBUG_LOG_SETTINGS, MEMORY_NAME};
@ -95,7 +94,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
src_dir,
exposed_types,
roc_target::TargetInfo::default_wasm32(),
builtin_defs_map,
);
let loaded = loaded.expect("failed to load module");
@ -209,10 +207,7 @@ where
Err(_) => Err(format!("{}", e)),
},
Ok(result) => {
let address = match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
};
let address = result[0].unwrap_i32();
if false {
println!("test_wrapper returned 0x{:x}", address);
@ -283,10 +278,7 @@ where
let init_result = init_refcount_test.call(&[wasmer::Value::I32(expected_len)]);
let refcount_vector_addr = match init_result {
Err(e) => return Err(format!("{:?}", e)),
Ok(result) => match result[0] {
wasmer::Value::I32(a) => a,
_ => panic!(),
},
Ok(result) => result[0].unwrap_i32(),
};
// Run the test