spec
spec copied to clipboard
Inconsistencies with memory and table max limits in core spec, js-api spec and tests
Current status:
After the memory64 update, the spec says that (link):
- table limits must be within range
2^addrtype - 1, i.e. for table32 up to2^32 - 1, for table64 up to2^64 - 1; - memory limits must be within range
2^(addrtype - 16), i.e. for memory32 up to2^16pages, for memory64 up to2^48pages. This means that we should throw CompileErrors if the limits are exceeded.
After the memory64 update, the js-api says that (link): Regarding tables:
- throw a CompileError if "The maximum size of a table is 10,000,000." is exceeded;
- throw a CompileError if "The maximum number of table entries in any table initialization is 10,000,000." is exceeded;
- throw a RuntimeError if "The maximum size of a table is 10,000,000." is exceeded;
Regarding memories:
- throw a RuntimeError if for memory32
2^16pages is exceeded; - throw a RuntimeError if for memory64
2^18pages is exceeded;
After the memory64 update, the spec tests say that (link): Regarding tables:
- table32 with max size
2^32 - 1is still valid, if exceeded throw CompileError; - throw CompileError for table32 with initial size
2^32; - table64 with max size
2^64 - 1is still valid;
Regarding memories:
- memory32 with max size
2^16pages is still valid, if exceeded throw CompileError; - memory64 with max size
2^16pages is still valid; - throw CompileError for memory64 with initial or max size
2^48 + 1.
After the memory64 update, the js-api test limits.any.js tests:
Regarding tables:
- instantiation fails if the initial table size is
10,000,000 + 1; - instantiation succeeds if the max size is
10,000,000 + 1; - growing table fails, INCORRECT (Wasm function in line 228 returns
wasmI32Const(-1)by default);
Regarding memories:
- no memory tests!
Proposed changes:
-
js-api spec: PR a) remove sentence to throw CompileError if "The maximum size of a table is 10,000,000.", as these tables are valid b) remove sentence to throw CompileError if "The maximum number of table entries in any table initialization is 10,000,000.", as these tables are valid c) adjust sentence to throw RuntimeError if "The maximum size of a table is 10,000,000.". It's unclear if it's both initial and max size of the table.
-
spec tests: a) add tests for table32 with
2^32 - 1and table64 with2^64 - 1initial page size is still valid PR; b) add test that memory32 with initial size2^16pages is still valid PR; c) add test that memory64 with initial OR max size2^48pages is still valid PR and PR; -
js-api limits.any.js: a) fix table grow function in
testDynamicLimit()b) add tests for memory instantiation (initial and max size are OOB or just in bounds) c) add tests for memory64 or table64
growing table fails, INCORRECT (growing returns -1 by default);
The table.grow wasm instruction returns -1 on failure, but the Table.grow() JS method throws RangeError on failure. So I think the existing test is correct.
Sorry, I wasn't clear with the comment. In limits.any.js:228 we have a Wasm function grow that just returns wasmI32Const(-1) by default.
Transferring this issue to the main spec repo since memory64 is being archived.