From dd040d5f7313d2447175a17b1692cef5997e5d58 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Mon, 8 Aug 2022 21:41:25 +0100 Subject: [PATCH] wasm: add stack_bytes field to Env --- crates/compiler/build/src/program.rs | 1 + crates/compiler/gen_wasm/src/backend.rs | 4 +--- crates/compiler/gen_wasm/src/lib.rs | 5 +++++ crates/compiler/test_gen/src/helpers/wasm.rs | 1 + crates/compiler/test_gen/src/wasm_linking.rs | 1 + crates/repl_wasm/src/repl.rs | 1 + 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/compiler/build/src/program.rs b/crates/compiler/build/src/program.rs index f16a25029d..1899921b04 100644 --- a/crates/compiler/build/src/program.rs +++ b/crates/compiler/build/src/program.rs @@ -474,6 +474,7 @@ fn gen_from_mono_module_dev_wasm32( arena, module_id, exposed_to_host, + stack_bytes: roc_gen_wasm::Env::DEFAULT_STACK_BYTES, }; let host_bytes = std::fs::read(preprocessed_host_path).unwrap_or_else(|_| { diff --git a/crates/compiler/gen_wasm/src/backend.rs b/crates/compiler/gen_wasm/src/backend.rs index 738ad9875d..b87bffe0c8 100644 --- a/crates/compiler/gen_wasm/src/backend.rs +++ b/crates/compiler/gen_wasm/src/backend.rs @@ -272,9 +272,7 @@ impl<'a> WasmBackend<'a> { } pub fn finalize(mut self) -> (WasmModule<'a>, BitVec) { - // TODO: get this from a CLI parameter with some default - const STACK_SIZE: u32 = 1024 * 1024; - self.set_memory_layout(STACK_SIZE); + self.set_memory_layout(self.env.stack_bytes); self.export_globals(); self.maybe_call_host_main(); diff --git a/crates/compiler/gen_wasm/src/lib.rs b/crates/compiler/gen_wasm/src/lib.rs index 4fa721a08a..4e37bb63f7 100644 --- a/crates/compiler/gen_wasm/src/lib.rs +++ b/crates/compiler/gen_wasm/src/lib.rs @@ -45,6 +45,11 @@ pub struct Env<'a> { pub arena: &'a Bump, pub module_id: ModuleId, pub exposed_to_host: MutSet, + pub stack_bytes: u32, +} + +impl Env<'_> { + pub const DEFAULT_STACK_BYTES: u32 = 1024 * 1024; } /// Parse the preprocessed host binary diff --git a/crates/compiler/test_gen/src/helpers/wasm.rs b/crates/compiler/test_gen/src/helpers/wasm.rs index 75985fe4b2..a791c33ef9 100644 --- a/crates/compiler/test_gen/src/helpers/wasm.rs +++ b/crates/compiler/test_gen/src/helpers/wasm.rs @@ -122,6 +122,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>( arena, module_id, exposed_to_host, + stack_bytes: roc_gen_wasm::Env::DEFAULT_STACK_BYTES, }; let host_module = roc_gen_wasm::parse_host(env.arena, host_bytes).unwrap_or_else(|e| { diff --git a/crates/compiler/test_gen/src/wasm_linking.rs b/crates/compiler/test_gen/src/wasm_linking.rs index 64cb1503e3..8979f0d0bf 100644 --- a/crates/compiler/test_gen/src/wasm_linking.rs +++ b/crates/compiler/test_gen/src/wasm_linking.rs @@ -161,6 +161,7 @@ impl<'a> BackendInputs<'a> { arena, module_id, exposed_to_host, + stack_bytes: Env::DEFAULT_STACK_BYTES, }; // Identifier stuff for the backend diff --git a/crates/repl_wasm/src/repl.rs b/crates/repl_wasm/src/repl.rs index 4d45342267..2493f04dc4 100644 --- a/crates/repl_wasm/src/repl.rs +++ b/crates/repl_wasm/src/repl.rs @@ -213,6 +213,7 @@ pub async fn entrypoint_from_js(src: String) -> Result { let env = roc_gen_wasm::Env { arena, module_id, + stack_bytes: roc_gen_wasm::Env::DEFAULT_STACK_BYTES, exposed_to_host: exposed_to_host .values .keys()