Skip to content

Commit 18b17a7

Browse files
authored
feat: update binaryen to v130 (#3026)
1 parent ffed83a commit 18b17a7

9 files changed

Lines changed: 89 additions & 42 deletions

File tree

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"engineStrict": true,
2727
"dependencies": {
28-
"binaryen": "129.0.0-nightly.20260428",
28+
"binaryen": "130.0.0-nightly.20260609",
2929
"long": "^5.2.4"
3030
},
3131
"devDependencies": {

src/compiler.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ export class Compiler extends DiagnosticEmitter {
881881
let options = this.options;
882882
let module = this.module;
883883

884-
// import and/or export table if requested (default table is named '0' by Binaryen)
884+
// import and/or export table if requested (default table is named '0' by Binaryen).
885+
// non-imported tables are declared lazily on first indirect call, see ensureFunctionTable
885886
if (options.importTable) {
886887
module.addTableImport(
887888
CommonNames.DefaultTable,
@@ -2152,7 +2153,11 @@ export class Compiler extends DiagnosticEmitter {
21522153
let memorySegment = instance.memorySegment;
21532154
if (!memorySegment) {
21542155

2155-
// Add to the function table
2156+
// Add to the function table, declaring it on first use so effect analysis works
2157+
if (!this.options.importTable) {
2158+
this.module.ensureFunctionTable(CommonNames.DefaultTable);
2159+
}
2160+
21562161
let functionTable = this.functionTable;
21572162
let tableBase = this.options.tableBase;
21582163
if (!tableBase) tableBase = 1; // leave first elem blank
@@ -7128,13 +7133,11 @@ export class Compiler extends DiagnosticEmitter {
71287133
// provided, so we must set `argumentsLength` in any case. Inject setting it
71297134
// into the index argument, which becomes executed last after any operands.
71307135
let argumentsLength = this.ensureArgumentsLength();
7131-
7132-
71337136
let functionArgWithVararg = module.block(null, [
71347137
module.global_set(argumentsLength, module.i32(numArguments)),
71357138
functionArg
71367139
], sizeTypeRef);
7137-
7140+
71387141
if (operands) this.operandsTostack(signature, operands);
71397142
let expr = module.call_indirect(
71407143
null, // TODO: handle multiple tables

src/glue/binaryen.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ export declare function _BinaryenUnarySetOp(expr: ExpressionRef, op: Op): void;
267267
export declare function _BinaryenUnaryGetValue(expr: ExpressionRef): ExpressionRef;
268268
export declare function _BinaryenUnarySetValue(expr: ExpressionRef, valueExpr: ExpressionRef): void;
269269

270+
export declare function _BinaryenWideIntAddSub(module: ModuleRef, op: Op, leftLowExpr: ExpressionRef, leftHighExpr: ExpressionRef, rightLowExpr: ExpressionRef, rightHighExpr: ExpressionRef): ExpressionRef;
271+
export declare function _BinaryenWideIntMul(module: ModuleRef, op: Op, leftExpr: ExpressionRef, rightExpr: ExpressionRef): ExpressionRef;
272+
270273
export declare function _BinaryenBinary(module: ModuleRef, op: Op, leftExpr: ExpressionRef, rightExpr: ExpressionRef): ExpressionRef;
271274
export declare function _BinaryenBinaryGetOp(expr: ExpressionRef): Op;
272275
export declare function _BinaryenBinarySetOp(expr: ExpressionRef, op: Op): void;

src/glue/binaryen.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export const {
223223
_BinaryenUnaryGetValue,
224224
_BinaryenUnarySetValue,
225225

226+
_BinaryenWideIntAddSub,
227+
_BinaryenWideIntMul,
228+
226229
_BinaryenBinary,
227230
_BinaryenBinaryGetOp,
228231
_BinaryenBinarySetOp,

src/module.ts

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ export const enum ExpressionId {
331331
ResumeThrow = 102 /* _BinaryenResumeThrowId */,
332332
StackSwitch = 103 /* _BinaryenStackSwitchId */,
333333
StructWait = 104 /* _BinaryenStructWaitId */,
334-
StructNotify = 105 /* _BinaryenStructNotifyId */
334+
StructNotify = 105 /* _BinaryenStructNotifyId */,
335+
WideIntAddSub = 106 /* _BinaryenWideIntAddSubId */,
336+
WideIntMul = 107 /* _BinaryenWideIntMulId */
335337
}
336338

337339
/** Binaryen external kind constants. */
@@ -1057,7 +1059,7 @@ export const enum BinaryOp {
10571059
/** i16x8.relaxed_q15mulr_s */
10581060
RelaxedQ15MulrI16x8 = 215 /* _BinaryenRelaxedQ15MulrSVecI16x8 */,
10591061
/** i16x8.relaxed_dot_i8x16_i7x16_s */
1060-
RelaxedDotI8x16I7x16ToI16x8 = 216 /* _BinaryenDotI8x16I7x16SToVecI16x8 */,
1062+
RelaxedDotI8x16I7x16ToI16x8 = 216 /* _BinaryenRelaxedDotI8x16I7x16SToVecI16x8 */,
10611063

10621064
_last = RelaxedDotI8x16I7x16ToI16x8,
10631065

@@ -1258,15 +1260,15 @@ export const enum SIMDTernaryOp {
12581260
/** f64x2.relaxed_nmadd */
12591261
RelaxedNmaddF64x2 = 4 /* _BinaryenRelaxedNmaddVecF64x2 */,
12601262
/** i8x16.relaxed_laneselect */
1261-
RelaxedLaneselectI8x16 = 5 /* _BinaryenLaneselectI8x16 */,
1263+
RelaxedLaneselectI8x16 = 5 /* _BinaryenRelaxedLaneselectI8x16 */,
12621264
/** i16x8.relaxed_laneselect */
1263-
RelaxedLaneselectI16x8 = 6 /* _BinaryenLaneselectI16x8 */,
1265+
RelaxedLaneselectI16x8 = 6 /* _BinaryenRelaxedLaneselectI16x8 */,
12641266
/** i32x4.relaxed_laneselect */
1265-
RelaxedLaneselectI32x4 = 7 /* _BinaryenLaneselectI32x4 */,
1267+
RelaxedLaneselectI32x4 = 7 /* _BinaryenRelaxedLaneselectI32x4 */,
12661268
/** i64x2.relaxed_laneselect */
1267-
RelaxedLaneselectI64x2 = 8 /* _BinaryenLaneselectI64x2 */,
1269+
RelaxedLaneselectI64x2 = 8 /* _BinaryenRelaxedLaneselectI64x2 */,
12681270
/** i32x4.relaxed_dot_i8x16_i7x16_add_s */
1269-
RelaxedDotI8x16I7x16AddToI32x4 = 9 /* _BinaryenDotI8x16I7x16AddSToVecI32x4 */,
1271+
RelaxedDotI8x16I7x16AddToI32x4 = 9 /* _BinaryenRelaxedDotI8x16I7x16AddSToVecI32x4 */,
12701272
// FIXME: f16x8 madd/nmadd (= 10, 11) are in wasm.h but not yet exported via C API
12711273
}
12721274

@@ -1275,9 +1277,25 @@ export const enum RefAsOp {
12751277
/** ref.as_non_null */
12761278
NonNull = 0 /* _BinaryenRefAsNonNull */,
12771279
/** any.convert_extern */
1278-
ExternInternalize = 1 /* _BinaryenRefAsAnyConvertExtern */,
1280+
AnyConvertExtern = 1 /* _BinaryenRefAsAnyConvertExtern */,
12791281
/** extern.convert_any */
1280-
ExternExternalize = 2 /* _BinaryenRefAsExternConvertAny */
1282+
ExternConvertAny = 2 /* _BinaryenRefAsExternConvertAny */
1283+
}
1284+
1285+
/** Binaryen wide integer add/sub operation constants. */
1286+
export const enum WideIntAddSubOp {
1287+
/** i64.add128 */
1288+
Add = 0 /* _BinaryenAddInt128 */,
1289+
/** i64.sub128 */
1290+
Sub = 1 /* _BinaryenSubInt128 */
1291+
}
1292+
1293+
/** Binaryen wide integer multiply operation constants. */
1294+
export const enum WideIntMulOp {
1295+
/** i64.mul_wide_s */
1296+
SignedI64 = 0 /* _BinaryenMulWideSInt64 */,
1297+
/** i64.mul_wide_u */
1298+
UnsignedI64 = 1 /* _BinaryenMulWideUInt64 */
12811299
}
12821300

12831301
/** Binaryen BrOn operation constants. */
@@ -1511,6 +1529,24 @@ export class Module {
15111529
return binaryen._BinaryenBinary(this.ref, op, left, right);
15121530
}
15131531

1532+
wide_int_add_sub(
1533+
op: WideIntAddSubOp,
1534+
leftLow: ExpressionRef,
1535+
leftHigh: ExpressionRef,
1536+
rightLow: ExpressionRef,
1537+
rightHigh: ExpressionRef
1538+
): ExpressionRef {
1539+
return binaryen._BinaryenWideIntAddSub(this.ref, op, leftLow, leftHigh, rightLow, rightHigh);
1540+
}
1541+
1542+
wide_int_mul(
1543+
op: WideIntMulOp,
1544+
left: ExpressionRef,
1545+
right: ExpressionRef
1546+
): ExpressionRef {
1547+
return binaryen._BinaryenWideIntMul(this.ref, op, left, right);
1548+
}
1549+
15141550
memory_size(name: string = CommonNames.DefaultMemory, is64: bool = false): ExpressionRef {
15151551
let cStr = this.allocStringCached(name);
15161552
return binaryen._BinaryenMemorySize(this.ref, cStr, is64);
@@ -2450,6 +2486,14 @@ export class Module {
24502486
binaryen._free(cArr);
24512487
}
24522488

2489+
/** Ensures that an empty function table of the given name exists, to be sized and filled later. */
2490+
ensureFunctionTable(name: string): void {
2491+
let cStr = this.allocStringCached(name);
2492+
if (!binaryen._BinaryenGetTable(this.ref, cStr)) {
2493+
binaryen._BinaryenAddTable(this.ref, cStr, 0, Module.UNLIMITED_TABLE, TypeRef.Funcref);
2494+
}
2495+
}
2496+
24532497
/* setFunctionTable(
24542498
initial: Index,
24552499
maximum: Index,

tests/compiler/assert-nonnull.release.wat

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(module
22
(type $0 (func (param i32) (result i32)))
3-
(type $1 (func (result i32)))
4-
(type $2 (func (param i32 i32 i32 i32)))
3+
(type $1 (func (param i32 i32 i32 i32)))
54
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
65
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 34236))
76
(memory $0 1)
@@ -15,7 +14,6 @@
1514
(data $3.1 (i32.const 1304) "\02\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
1615
(data $4 (i32.const 1340) "|")
1716
(data $4.1 (i32.const 1352) "\02\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y")
18-
(table $0 1 1 funcref)
1917
(export "memory" (memory $0))
2018
(export "testVar" (func $export:assert-nonnull/testVar))
2119
(export "testObj" (func $export:assert-nonnull/testObj))
@@ -165,7 +163,6 @@
165163
br_if $folding-inner1
166164
local.get $0
167165
i32.load
168-
call_indirect (type $1)
169166
unreachable
170167
end
171168
i32.const 34256
@@ -283,7 +280,6 @@
283280
br_if $folding-inner1
284281
local.get $0
285282
i32.load
286-
call_indirect (type $1)
287283
unreachable
288284
end
289285
i32.const 34256
@@ -344,7 +340,6 @@
344340
end
345341
local.get $0
346342
i32.load
347-
call_indirect (type $1)
348343
unreachable
349344
end
350345
i32.const 34256
@@ -456,7 +451,6 @@
456451
i32.store offset=4
457452
local.get $0
458453
i32.load
459-
call_indirect (type $1)
460454
unreachable
461455
end
462456
i32.const 34256
@@ -505,7 +499,6 @@
505499
end
506500
local.get $0
507501
i32.load
508-
call_indirect (type $1)
509502
unreachable
510503
end
511504
i32.const 34256

tests/compiler/features/relaxed-simd.debug.wat

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,42 @@
8383
global.get $features/relaxed-simd/v
8484
global.get $features/relaxed-simd/v
8585
global.get $features/relaxed-simd/v
86-
i8x16.laneselect
86+
i8x16.relaxed_laneselect
8787
global.set $features/relaxed-simd/r
8888
global.get $features/relaxed-simd/v
8989
global.get $features/relaxed-simd/v
9090
global.get $features/relaxed-simd/v
91-
i8x16.laneselect
91+
i8x16.relaxed_laneselect
9292
global.set $features/relaxed-simd/r
9393
global.get $features/relaxed-simd/v
9494
global.get $features/relaxed-simd/v
9595
global.get $features/relaxed-simd/v
96-
i16x8.laneselect
96+
i16x8.relaxed_laneselect
9797
global.set $features/relaxed-simd/r
9898
global.get $features/relaxed-simd/v
9999
global.get $features/relaxed-simd/v
100100
global.get $features/relaxed-simd/v
101-
i16x8.laneselect
101+
i16x8.relaxed_laneselect
102102
global.set $features/relaxed-simd/r
103103
global.get $features/relaxed-simd/v
104104
global.get $features/relaxed-simd/v
105105
global.get $features/relaxed-simd/v
106-
i32x4.laneselect
106+
i32x4.relaxed_laneselect
107107
global.set $features/relaxed-simd/r
108108
global.get $features/relaxed-simd/v
109109
global.get $features/relaxed-simd/v
110110
global.get $features/relaxed-simd/v
111-
i32x4.laneselect
111+
i32x4.relaxed_laneselect
112112
global.set $features/relaxed-simd/r
113113
global.get $features/relaxed-simd/v
114114
global.get $features/relaxed-simd/v
115115
global.get $features/relaxed-simd/v
116-
i64x2.laneselect
116+
i64x2.relaxed_laneselect
117117
global.set $features/relaxed-simd/r
118118
global.get $features/relaxed-simd/v
119119
global.get $features/relaxed-simd/v
120120
global.get $features/relaxed-simd/v
121-
i64x2.laneselect
121+
i64x2.relaxed_laneselect
122122
global.set $features/relaxed-simd/r
123123
global.get $features/relaxed-simd/v
124124
global.get $features/relaxed-simd/v
@@ -162,11 +162,11 @@
162162
global.set $features/relaxed-simd/r
163163
global.get $features/relaxed-simd/v
164164
global.get $features/relaxed-simd/v
165-
i16x8.dot_i8x16_i7x16_s
165+
i16x8.relaxed_dot_i8x16_i7x16_s
166166
global.set $features/relaxed-simd/r
167167
global.get $features/relaxed-simd/v
168168
global.get $features/relaxed-simd/v
169-
i16x8.dot_i8x16_i7x16_s
169+
i16x8.relaxed_dot_i8x16_i7x16_s
170170
global.set $features/relaxed-simd/r
171171
)
172172
(func $~start

tests/compiler/ternary.release.wat

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
select
4949
)
5050
(func $export:ternary/testVoidInclTypeMismatch (param $0 i32) (param $1 i32)
51+
(local $2 i32)
5152
global.get $~lib/memory/__stack_pointer
5253
i32.const 4
5354
i32.sub
@@ -68,11 +69,11 @@
6869
i32.store
6970
local.get $1
7071
i32.load
72+
local.tee $2
7173
call_indirect (type $0)
7274
local.get $0
7375
if
74-
local.get $1
75-
i32.load
76+
local.get $2
7677
call_indirect (type $0)
7778
end
7879
local.get $0

0 commit comments

Comments
 (0)