Skip to content

Commit c560421

Browse files
authored
[wasm64] Remove temporary toIndexType workaround (#22773)
Now the firefox and chrome both use BigInt for indexing 64-bit memories and tables this workaround is no longer needed.
1 parent dab8702 commit c560421

File tree

7 files changed

+11
-25
lines changed

7 files changed

+11
-25
lines changed

src/library.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,12 @@ addToLibrary({
19031903
$setWasmTableEntry__internal: true,
19041904
$setWasmTableEntry__deps: ['$wasmTableMirror', '$wasmTable'],
19051905
$setWasmTableEntry: (idx, func) => {
1906+
/** @suppress {checkTypes} */
19061907
wasmTable.set({{{ toIndexType('idx') }}}, func);
19071908
// With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overridden to return wrapped
19081909
// functions so we need to call it here to retrieve the potential wrapper correctly
19091910
// instead of just storing 'func' directly into wasmTableMirror
1911+
/** @suppress {checkTypes} */
19101912
wasmTableMirror[idx] = wasmTable.get({{{ toIndexType('idx') }}});
19111913
},
19121914

@@ -1922,6 +1924,7 @@ addToLibrary({
19221924
var func = wasmTableMirror[funcPtr];
19231925
if (!func) {
19241926
if (funcPtr >= wasmTableMirror.length) wasmTableMirror.length = funcPtr + 1;
1927+
/** @suppress {checkTypes} */
19251928
wasmTableMirror[funcPtr] = func = wasmTable.get({{{ toIndexType('funcPtr') }}});
19261929
#if ASYNCIFY == 2
19271930
if (Asyncify.isAsyncExport(func)) {
@@ -1930,23 +1933,21 @@ addToLibrary({
19301933
#endif
19311934
}
19321935
#if ASSERTIONS && ASYNCIFY != 2 // With JSPI the function stored in the table will be a wrapper.
1936+
/** @suppress {checkTypes} */
19331937
assert(wasmTable.get({{{ toIndexType('funcPtr') }}}) == func, 'JavaScript-side Wasm function table mirror is out of date!');
19341938
#endif
19351939
return func;
19361940
},
19371941

19381942
#else
19391943

1944+
$setWasmTableEntry__docs: '/** @suppress{checkTypes} */',
19401945
$setWasmTableEntry__deps: ['$wasmTable'],
19411946
$setWasmTableEntry: (idx, func) => wasmTable.set({{{ toIndexType('idx') }}}, func),
19421947

1948+
$getWasmTableEntry__docs: '/** @suppress{checkTypes} */',
19431949
$getWasmTableEntry__deps: ['$wasmTable'],
19441950
$getWasmTableEntry: (funcPtr) => {
1945-
#if MEMORY64
1946-
// Function pointers are 64-bit, but wasmTable.get() requires a Number.
1947-
// https://github.com/emscripten-core/emscripten/issues/18200
1948-
funcPtr = Number(funcPtr);
1949-
#endif
19501951
// In -Os and -Oz builds, do not implement a JS side wasm table mirror for small
19511952
// code size, but directly access wasmTable, which is a bit slower as uncached.
19521953
return wasmTable.get({{{ toIndexType('funcPtr') }}});

src/library_addfunction.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ addToLibrary({
151151
}
152152
// Grow the table
153153
try {
154+
/** @suppress {checkTypes} */
154155
wasmTable.grow({{{ toIndexType('1') }}});
155156
} catch (err) {
156157
if (!(err instanceof RangeError)) {

src/parseTools.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,7 @@ function from64Expr(x, assign = true) {
964964
}
965965

966966
function toIndexType(x) {
967-
if (MEMORY64 != 1) return x;
968-
return `toIndexType(${x})`;
967+
return to64(x);
969968
}
970969

971970
function to64(x) {

src/runtime_init_memory.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if (!ENVIRONMENT_IS_PTHREAD) {
2626
#if ASSERTIONS
2727
assert(INITIAL_MEMORY >= {{{STACK_SIZE}}}, 'INITIAL_MEMORY should be larger than STACK_SIZE, was ' + INITIAL_MEMORY + '! (STACK_SIZE=' + {{{STACK_SIZE}}} + ')');
2828
#endif
29+
/** @suppress {checkTypes} */
2930
#if MINIMAL_RUNTIME && WASM_WORKERS
3031
wasmMemory = Module['mem'] || new WebAssembly.Memory({
3132
#else

src/runtime_shared.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ function updateMemoryViews() {
4747
#endif
4848
}
4949

50-
#if MEMORY64 == 1
51-
var toIndexType = (function() {
52-
// Probe for support of bigint bounds with memory64.
53-
// TODO(sbc): Remove this once all browsers start requiring bigint here.
54-
// See https://github.com/WebAssembly/memory64/issues/68
55-
var bigintMemoryBounds = 1;
56-
try {
57-
/** @suppress {checkTypes} */
58-
new WebAssembly.Memory({'initial': 1n, 'index': 'i64', 'address': 'i64'});
59-
} catch (e) {
60-
bigintMemoryBounds = 0;
61-
}
62-
return (i) => bigintMemoryBounds ? BigInt(i) : i;
63-
})();
64-
#endif
65-
6650
#if ENVIRONMENT_MAY_BE_NODE && MIN_NODE_VERSION < 160000
6751
// The performance global was added to node in v16.0.0:
6852
// https://nodejs.org/api/globals.html#performance
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1589
1+
1522
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3311
1+
3179

0 commit comments

Comments
 (0)