From d783f26ad9b583d0068bcf9162d6fe3f7efc0b1a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 27 Jul 2023 20:40:00 -0700 Subject: [PATCH] Don't generate same-named imports in fact modules Ensure that all imports have unique module/name combos to ensure that the module can be instantiable in JS where separate functions need to be provided for each import. --- crates/environ/src/fact.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/environ/src/fact.rs b/crates/environ/src/fact.rs index 4d35ee5ea602..70437996c996 100644 --- a/crates/environ/src/fact.rs +++ b/crates/environ/src/fact.rs @@ -262,7 +262,7 @@ impl<'a> Module<'a> { let memory = memory.as_ref().map(|memory| { self.import_memory( "memory", - "", + &format!("m{}", self.imported_memories.len()), MemoryType { minimum: 0, maximum: None, @@ -279,7 +279,12 @@ impl<'a> Module<'a> { ValType::I32 }; let ty = self.core_types.function(&[ptr, ptr, ptr, ptr], &[ptr]); - self.import_func("realloc", "", ty, func.clone()) + self.import_func( + "realloc", + &format!("f{}", self.imported_funcs.len()), + ty, + func.clone(), + ) }); AdapterOptions {