fix: module imports should not use type index as their function identifier#411
fix: module imports should not use type index as their function identifier#411ColinEberhardt merged 2 commits intomasterfrom
Conversation
| @@ -0,0 +1,5 @@ | |||
| (module | |||
There was a problem hiding this comment.
this simple test, which adds a couple of type definitions, was enough to repro the issues from #406
| const fnParams = []; | ||
| const fnResult = []; | ||
|
|
||
| let fnName = t.identifier(getUniqueName("func")); |
There was a problem hiding this comment.
this change was not necessarily needed to make tests pass, but this does mean we have the same generated names when parsing wat
There was a problem hiding this comment.
Following https://github.com/xtuc/webassemblyjs/pull/411/files#r202406723 we could add our own func increment, or maybe we already have this information?
|
The "AST synchronization" test suite in |
| } | ||
|
|
||
| const id = t.numberLiteralFromRaw(typeindex); | ||
| const id = getUniqueName("func"); |
There was a problem hiding this comment.
Maybe we should try to eliminate the unique name generator (because statefull), and rather use the typeindex here.
There was a problem hiding this comment.
Maybe we should try to eliminate the unique name generator (because statefull)
I agree, that maybe the type name generator should be removed. I'm not sure what it's used for!
and rather use the typeindex here
No ... that's the bug that this PR is fixing. Module imports are functions which are referenced by index, i.e. if you have the following:
(type (func (result i32)))
(type (func (param i32) (result i32)))
(import "a" "c" (func $foo (type 1)))
(func $bar)
The function foo has index 0, and bar has index 1. The index does not relate to the type reference.
OK - I'll explore further and see what I've broken! |
@xtuc ok, I've had a look at the test and understand what it is doing now. I've fixed the test by making the following changes:
|
|
The tests are currently failing, but looks like a CI issue rather than a unit test failure! |
|
kicked Travis and the build works now :-) |
fixes #406
@xtuc there is a wasm-edit test failing as a result of this change, wondering if you have any pointers?