Skip to content

Commit e5539ef

Browse files
authored
chore: update Binaryen (#2927)
1 parent 44b658d commit e5539ef

File tree

106 files changed

+4388
-6660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+4388
-6660
lines changed

cli/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,10 @@ export async function main(argv, options) {
945945
try {
946946
// use superset text format when extension is `.wast`.
947947
// Otherwise use official stack IR format (wat).
948+
binaryen.setOptimizeStackIR(true);
948949
out = opts.textFile?.endsWith(".wast")
949950
? binaryenModule.emitText()
950-
: binaryenModule.emitStackIR(true);
951+
: binaryenModule.emitStackIR();
951952
} catch (e) {
952953
crash("emitText", e);
953954
}

package-lock.json

Lines changed: 15 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": "116.0.0-nightly.20240114",
28+
"binaryen": "123.0.0-nightly.20250530",
2929
"long": "^5.2.4"
3030
},
3131
"devDependencies": {

src/builtins.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,8 +1654,7 @@ function builtin_max(ctx: BuiltinFunctionContext): ExpressionRef {
16541654
module.binary(op,
16551655
module.local_get(temp1.index, typeRef),
16561656
module.local_get(temp2.index, typeRef)
1657-
),
1658-
typeRef
1657+
)
16591658
);
16601659
return ret;
16611660
}
@@ -1723,8 +1722,7 @@ function builtin_min(ctx: BuiltinFunctionContext): ExpressionRef {
17231722
module.binary(op,
17241723
module.local_get(temp1.index, typeRef),
17251724
module.local_get(temp2.index, typeRef)
1726-
),
1727-
typeRef
1725+
)
17281726
);
17291727
return ret;
17301728
}
@@ -3133,7 +3131,7 @@ function builtin_select(ctx: BuiltinFunctionContext): ExpressionRef {
31333131
operands[2]
31343132
);
31353133
compiler.currentType = type;
3136-
return module.select(arg0, arg1, arg2, type.toRef());
3134+
return module.select(arg0, arg1, arg2);
31373135
}
31383136
builtinFunctions.set(BuiltinNames.select, builtin_select);
31393137

src/compiler.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ export class Compiler extends DiagnosticEmitter {
536536
// initialize lookup maps, built-ins, imports, exports, etc.
537537
this.program.initialize();
538538

539+
540+
// Binaryen treats all function references as being leaked to the outside world when
541+
// the module isn't marked as closed-world (see WebAssembly/binaryen#7135). Therefore,
542+
// we should mark the module as closed-world when we're definitely sure it is.
543+
module.setClosedWorld(true);
544+
539545
// obtain the main start function
540546
let startFunctionInstance = this.currentFlow.targetFunction;
541547
assert(startFunctionInstance.internalName == BuiltinNames.start);
@@ -857,6 +863,7 @@ export class Compiler extends DiagnosticEmitter {
857863
ImportNames.DefaultNamespace,
858864
ImportNames.Table
859865
);
866+
module.setClosedWorld(false);
860867
if (options.pedantic && options.willOptimize) {
861868
this.pedantic(
862869
DiagnosticCode.Importing_the_table_disables_some_indirect_call_optimizations,
@@ -866,6 +873,7 @@ export class Compiler extends DiagnosticEmitter {
866873
}
867874
if (options.exportTable) {
868875
module.addTableExport(CommonNames.DefaultTable, ExportNames.Table);
876+
module.setClosedWorld(false);
869877
if (options.pedantic && options.willOptimize) {
870878
this.pedantic(
871879
DiagnosticCode.Exporting_the_table_disables_some_indirect_call_optimizations,
@@ -977,6 +985,7 @@ export class Compiler extends DiagnosticEmitter {
977985
}
978986
}
979987
}
988+
if (functionInstance.signature.returnType.kind == TypeKind.Func) this.module.setClosedWorld(false);
980989
}
981990
return;
982991
}
@@ -1007,6 +1016,7 @@ export class Compiler extends DiagnosticEmitter {
10071016
this.desiresExportRuntime = true;
10081017
}
10091018
}
1019+
if (global.type.kind == TypeKind.Func) this.module.setClosedWorld(false);
10101020
}
10111021
if (global.type == Type.v128) {
10121022
this.warning(
@@ -4975,8 +4985,7 @@ export class Compiler extends DiagnosticEmitter {
49754985
return module.select(
49764986
module.i32(1),
49774987
module.binary(BinaryOp.EqI32, rightExpr, module.i32(0)),
4978-
leftExpr,
4979-
TypeRef.I32
4988+
leftExpr
49804989
);
49814990
}
49824991
case TypeKind.I8:

0 commit comments

Comments
 (0)