Fix wasm module

This commit is contained in:
Ayaz Hafiz 2022-12-29 08:18:06 -06:00
parent 650d3e6321
commit f2a42affd1
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 18 additions and 10 deletions

View file

@ -111,7 +111,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
procedures,
mut interns,
exposed_to_host,
layout_interner,
mut layout_interner,
..
} = loaded;
@ -125,7 +125,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
let env = roc_gen_wasm::Env {
arena,
layout_interner: &layout_interner,
module_id,
exposed_to_host,
stack_bytes: roc_gen_wasm::Env::DEFAULT_STACK_BYTES,
@ -140,8 +139,13 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
)
});
let (mut module, mut called_fns, main_fn_index) =
roc_gen_wasm::build_app_module(&env, &mut interns, host_module, procedures);
let (mut module, mut called_fns, main_fn_index) = roc_gen_wasm::build_app_module(
&env,
&mut layout_interner,
&mut interns,
host_module,
procedures,
);
T::insert_wrapper(arena, &mut module, TEST_WRAPPER_NAME, main_fn_index);
called_fns.push(true);

View file

@ -141,7 +141,7 @@ struct BackendInputs<'a> {
}
impl<'a> BackendInputs<'a> {
fn new(arena: &'a Bump, layout_interner: &'a STLayoutInterner<'a>) -> Self {
fn new(arena: &'a Bump) -> Self {
// Compile the host from an external source file
let host_bytes = fs::read(LINKING_TEST_HOST_WASM).unwrap();
let host_module: WasmModule = roc_gen_wasm::parse_host(arena, &host_bytes).unwrap();
@ -159,7 +159,6 @@ impl<'a> BackendInputs<'a> {
exposed_to_host.insert(roc_main_sym);
let env = Env {
arena,
layout_interner,
module_id,
exposed_to_host,
stack_bytes: Env::DEFAULT_STACK_BYTES,
@ -263,22 +262,27 @@ fn test_help(
dump_filename: &str,
) {
let arena = Bump::new();
let layout_interner = STLayoutInterner::with_capacity(4);
let mut layout_interner = STLayoutInterner::with_capacity(4);
let BackendInputs {
env,
mut interns,
host_module,
procedures,
} = BackendInputs::new(&arena, &layout_interner);
} = BackendInputs::new(&arena);
let host_import_names = Vec::from_iter(host_module.import.imports.iter().map(|imp| imp.name));
assert_eq!(&host_import_names, expected_host_import_names);
assert!(&host_module.names.function_names.is_empty());
let (mut final_module, called_fns, _roc_main_index) =
roc_gen_wasm::build_app_module(&env, &mut interns, host_module, procedures);
let (mut final_module, called_fns, _roc_main_index) = roc_gen_wasm::build_app_module(
&env,
&mut layout_interner,
&mut interns,
host_module,
procedures,
);
if eliminate_dead_code {
final_module.eliminate_dead_code(env.arena, called_fns);