From e80de439e79ed1dab1c1adcbd5b9cca7a79be023 Mon Sep 17 00:00:00 2001 From: Oscar Spencer Date: Thu, 23 Sep 2021 17:54:59 -0400 Subject: [PATCH] fix(compiler): Remove existing exports when writing universal exports (#919) * fix(compiler): Remove existing exports when writing universal exports * Actual test repro --- compiler/src/codegen/comp_utils.re | 2 ++ compiler/test/input/wasiPolyfill.gr | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/compiler/src/codegen/comp_utils.re b/compiler/src/codegen/comp_utils.re index d7922189bd..02a4200583 100644 --- a/compiler/src/codegen/comp_utils.re +++ b/compiler/src/codegen/comp_utils.re @@ -191,6 +191,8 @@ let write_universal_exports = [||], function_body, ); + // Remove existing Grain export (if any) + Export.remove_export(wasm_mod, name); ignore @@ Export.add_function_export(wasm_mod, name, name); | TSigValue(_) | TSigType(_) diff --git a/compiler/test/input/wasiPolyfill.gr b/compiler/test/input/wasiPolyfill.gr index 6df049ac61..0a4c02ebdb 100644 --- a/compiler/test/input/wasiPolyfill.gr +++ b/compiler/test/input/wasiPolyfill.gr @@ -1,7 +1,22 @@ -import foreign wasm fd_write : (WasmI32, WasmI32, WasmI32, WasmI32) -> WasmI32 from "wasi_snapshot_preview1" +import foreign wasm fd_write: ( + WasmI32, + WasmI32, + WasmI32, + WasmI32 +) -> WasmI32 from "wasi_snapshot_preview1" -export let fd_write: (WasmI32, WasmI32, WasmI32, WasmI32) -> WasmI32 = (fd, iovs, iovs_len, nwritten) => { - fd_write(fd, iovs, iovs_len, nwritten) - fd_write(fd, iovs, iovs_len, nwritten) - fd_write(fd, iovs, iovs_len, nwritten) +export let fd_write: (WasmI32, WasmI32, WasmI32, WasmI32) -> WasmI32 = + ( + fd, + iovs, + iovs_len, + nwritten, + ) => { + fd_write(fd, iovs, iovs_len, nwritten) + fd_write(fd, iovs, iovs_len, nwritten) + fd_write(fd, iovs, iovs_len, nwritten) +} + +export let args_get = (a, b) => { + 76n }