Prevent generating duplicate exports for closure conversions #4380
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.
We have a report in #4371 where
wasm-bindgen
would generate multiple exported functions with the same name, which is invalid. Specifically these functions wereClosure
converters.I was debugging this just with the generated Wasm module, because I couldn't build the project locally and there was no minimal re-production, the following is just speculation:
The culprit seems to be:
wasm-bindgen/src/closure.rs
Lines 340 to 344 in 88452fa
For some reason, while we are interpreting this descriptor, we find multiple ones with exactly the same name, e.g.:
<dyn core[bd1a764364e91139]::ops::function::FnMut<(), Output = _> as wasm_bindgen[79ff92f6c8c42bdb]::closure::WasmClosure>::describe::invoke::<()>
. While finding multiple ones should not be surprising, as we are dealing with a generic, the name shouldn't be the same because as you can see Rust adds some naming scheme to prevent that. So either this is a bug in Rust, which I very much doubt, or the problem is#[inline(never)]
, which would not be bug in Rust because the reference clearly states that it is just a suggestion and not a guarantee.To fix this we simply apply a number at the end to mangle the name further.
Fixes #4371.
Cc @dpc.