Skip to content

wasm-mutate: add export mutator - #2639

Merged
alexcrichton merged 3 commits into
bytecodealliance:mainfrom
GtechGovind:fix/add-export-mutation
Sep 14, 2026
Merged

alexcrichton merged 3 commits into
bytecodealliance:mainfrom
GtechGovind:fix/add-export-mutation

Conversation

@GtechGovind

Copy link
Copy Markdown
Contributor

Summary

  • add a wasm-mutate mutator that exports a randomly selected existing function, table, memory, global, or tag
  • preserve existing exports and create the export section at the correct position when absent
  • account for local tag sections so tags are available to the mutator
  • disable the mutation when preserving semantics or reducing size

Part of #415.

Testing

  • cargo test -p wasm-mutate
  • cargo clippy -p wasm-mutate --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

@GtechGovind
GtechGovind marked this pull request as ready for review September 7, 2026 05:43
@GtechGovind
GtechGovind requested a review from a team as a code owner September 7, 2026 05:43
@GtechGovind
GtechGovind requested review from pchickey and removed request for a team September 7, 2026 05:43
@GtechGovind
GtechGovind marked this pull request as draft September 7, 2026 06:14
@alexcrichton

Copy link
Copy Markdown
Member

Thanks @GtechGovind! FWIW while these PRs are in draft reviewers aren't assigned and typically don't look too closely. When you're ready feel free to take them out of draft and a reviewer will be assigned.

@GtechGovind
GtechGovind marked this pull request as ready for review September 11, 2026 19:32

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just one minor comment but otherwise looks good to me

Comment on lines +68 to +76
let kind = match export.kind {
wasmparser::ExternalKind::Func => ExportKind::Func,
wasmparser::ExternalKind::Table => ExportKind::Table,
wasmparser::ExternalKind::Memory => ExportKind::Memory,
wasmparser::ExternalKind::Global => ExportKind::Global,
wasmparser::ExternalKind::Tag => ExportKind::Tag,
wasmparser::ExternalKind::FuncExact => unreachable!(),
};
exports.export(export.name, kind, export.index);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use the wasm_encoder::reencode module perhaps?

@alexcrichton
alexcrichton requested review from alexcrichton and removed request for pchickey September 14, 2026 14:17
@alexcrichton
alexcrichton added this pull request to the merge queue Sep 14, 2026
Merged via the queue into bytecodealliance:main with commit 663ba14 Sep 14, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants