fix: sanitize Wasm function names - #1342
Closed
mooori wants to merge 1 commit into
Closed
Conversation
mooori
force-pushed
the
mooori/duplicate-wasm-fn-name
branch
from
August 21, 2026 16:59
1d0dcc9 to
bf48ef8
Compare
Contributor
Miden examples benchmarkCandidate
SVG flamegraphs and compiled packages are attached to the workflow run. |
mooori
marked this pull request as ready for review
August 21, 2026 17:38
Contributor
Author
|
cc @djolertrk regarding debuginfo |
mooori
marked this pull request as draft
August 24, 2026 15:39
Contributor
Author
|
Reverted to draft mode as it needs to be reworked as discussed in the sync. |
Contributor
Author
|
Closing in favor of #1357 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1341
Approach is deduplicating function names in the
NameSectionby prepending the function index.Potential other approach: Keep two maps, one for function names as listed in the Wasm
namesection and for unique names. I suspect that would be a bigger change as the new map with unique names would need to be switched in toNameSection.Related issues/changes
Working on this I found some (unlikely/contrived) edge cases that are currently not handled. When sanitizing function names, these edge cases break in a different way.
Are these things we want to fix?
Library exports with duplicate names
Undefined item instead of compilation error
Consider this WAT:
After sanitation, the library roughly looks like
So the package exports
add_func0instead ofadd. Callers might not be aware of this and when they calladdit cannot be resolved.Previously this would fail compilation due to the duplicate function name, see #1341.
Debug info
Some subtle changes
Pasting LLM output here as I haven't really looked into this yet:
Also debug info incorrectly assumes that functions in the name section are unique:
compiler/frontend/wasm/src/module/debug_info.rs
Lines 444 to 447 in 62c4318
For a wasm section like below, the second insertion silently replaces the first.
Opened #1343 for that.