Add support for non-nullable tables and init expressions#8405
Add support for non-nullable tables and init expressions#8405pufferfish101007 wants to merge 12 commits intoWebAssembly:mainfrom
Conversation
I don't see these changes in shared.py, can we add them? |
There was a problem hiding this comment.
Add a CHANGELOG.md entry under Current Trunk describing the breakage and how to fix it for C/JS library users.
| }; | ||
| self['addTable'] = function(table, initial, maximum, type = Module['_BinaryenTypeFuncref']()) { | ||
| return preserveStack(() => Module['_BinaryenAddTable'](module, strToStack(table), initial, maximum, type)); | ||
| self['addTable'] = function(table, initial, maximum, type = Module['_BinaryenTypeFuncref'](), init = null) { |
There was a problem hiding this comment.
setMemory has a default param for null but most other cases seem to rely on unset params being implicitly undefined in JS, maybe we should do the same here?
i.e.
function(..., init) {
return preserveStack(() => Module['_BinaryenAddTable'](..., init)
}(or check for undefined if needed)
cc @kripken if you have any opinion
There was a problem hiding this comment.
I think optional parameters need to come after all non-optional parameters, so init would need to come before type. To me, that seems less nice, both because adding it at the end isn't breaking for the JS api, and because the init expression would naturally come at the end when writing WAT.
Resolves #5628
Adds support for non-nullable tables with init expressions. I'm not totally sure how I should go about adding new tests, but manual test cases are below. I have also unignored previously ignored spec tests
instance.wast,ref_is_null.wast,table.wast,i31.wast, which now all pass. I have also changed the reason for ignoringarray.wastas it does not (and has not in the past, AFAICT) rely on non-nullable table types.This introduces a breaking change in the C api, as it adds an extra argument to
addTable. Is this ok? Should a new method be added instead? (e.g.addTableWithInit?)Manual tests
The validation ones might overlap with the spec tests. Unchecked boxes indicate tests that currently fail.
Correctly fails with
[wasm-validator error in module] unexpected false: tables with non-nullable types require an initializer expression, on tableCorrectly fails with
[wasm-validator error in module] init expression must be a subtype of the table type, on (i32.const 0)Correctly fails with
[wasm-validator error in module] init expression must be a subtype of the table type, on (i32.const 0)wasm-optdoesn't remove init expr as dead codeglobal.wastfails at the following (validation succeeds), although I don't understand why the module should be invalid: