WebAssembly / WebAssembly/binaryen

[wasm-opt] `--minify-imports-and-exports-and-modules` does not report module renames.

Open
#7,657 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

When using wasm-opt with the --minify-imports-and-exports-and-modules flag, the tool correctly minifies both the import module names and the import function names. It often merges multiple import modules into a single new minified name.

However, the mapping printed to stdout is incomplete. It includes the remapping for the function names but completely omits the remapping for the module names. This makes it impossible for tools that rely on this map to correctly patch the host JavaScript environment, breaking the application.

Environment
  • wasm-opt Version: wasm-opt version 123
Minimal Reproducible Example (MRE)

1. Input .wat file (test.wat):

This file defines a module that imports two functions from two different, uniquely named modules.

(module
  (type (;0;) (func))
  (import "long_module_name_a" "long_function_name_foo" (func (;0;) (type 0)))
  (import "long_module_name_b" "long_function_name_bar" (func (;1;) (type 0)))
)

2. Assemble to .wasm:

wat2wasm test.wat -o test.wasm

3. Run wasm-opt:

wasm-opt test.wasm -o output.wasm --minify-imports-and-exports-and-modules
Results
Actual stdout Output:

The tool only prints the mapping for the function names:

long_function_name_foo => a
long_function_name_bar => b
Actual Contents of output.wasm (decompiled with wasm2wat):

The output Wasm shows that the module names were also minified and merged into "a":

(module
  (type (;0;) (func))
  (import "a" "a" (func (;0;) (type 0)))
  (import "a" "b" (func (;1;) (type 0)))
)
Expected Behavior

The stdout mapping should be complete and reflect all minification operations performed on the import/export interface. A correct and unambiguous output would look something like this:

long_module_name_a => a
long_module_name_b => a
long_function_name_foo => a
long_function_name_bar => b

This would provide all the necessary information for a host environment to correctly wire up the minified module.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with wasm-opt version 123 using the provided test.wat, wat2wasm command, and --minify-imports-and-exports-and-modules flag. Inspect the flag's mapping output and compare it with wasm2wat output; done means stdout reports both module and function renames, including merged module names.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
cli, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.