Skip to content

Commit 8b11dbd

Browse files
authored
Don't generate exports named memory in wit-smith (#1472)
* Don't generate exports named `memory` in wit-smith This fixes a fuzz bug discovered last night and this applies a similar fix for interfaces which avoids using `memory` that clashes with the canonical name for linear memory itself. * Review comments
1 parent 7906a20 commit 8b11dbd

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

crates/wit-smith/src/generate.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,14 @@ impl Generator {
318318

319319
impl<'a> InterfaceGenerator<'a> {
320320
fn new(gen: &'a Generator, file: &'a mut File) -> InterfaceGenerator<'a> {
321-
// Claim the name `memory` to avoid conflicting with the canonical ABI
322-
// always using a linear memory named `memory`.
323-
let mut unique_names = HashSet::new();
324-
unique_names.insert("memory".to_string());
325321
InterfaceGenerator {
326322
gen,
327323
file,
328324
config: &gen.config,
329325
types_in_interface: Vec::new(),
330-
unique_names,
326+
// Claim the name `memory` to avoid conflicting with the canonical
327+
// ABI always using a linear memory named `memory`.
328+
unique_names: HashSet::from_iter(["memory".to_string()]),
331329
}
332330
}
333331

@@ -413,7 +411,10 @@ impl<'a> InterfaceGenerator<'a> {
413411
let mut parts = Vec::new();
414412
let mut imported_interfaces = HashSet::new();
415413
let mut exported_interfaces = HashSet::new();
416-
let mut export_names = HashSet::new();
414+
415+
// Claim the name `memory` to avoid conflicting with the canonical
416+
// ABI always using a linear memory named `memory`.
417+
let mut export_names = HashSet::from_iter(["memory".to_string()]);
417418

418419
while parts.len() < self.config.max_world_items && !u.is_empty() && u.arbitrary()? {
419420
let kind = u.arbitrary::<ItemKind>()?;

0 commit comments

Comments
 (0)