Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"engineStrict": true,
"dependencies": {
"binaryen": "116.0.0-nightly.20240114",
"binaryen": "123.0.0-nightly.20250530",
"long": "^5.2.4"
},
"devDependencies": {
Expand Down
8 changes: 3 additions & 5 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,8 +1654,7 @@ function builtin_max(ctx: BuiltinFunctionContext): ExpressionRef {
module.binary(op,
module.local_get(temp1.index, typeRef),
module.local_get(temp2.index, typeRef)
),
typeRef
)
);
return ret;
}
Expand Down Expand Up @@ -1723,8 +1722,7 @@ function builtin_min(ctx: BuiltinFunctionContext): ExpressionRef {
module.binary(op,
module.local_get(temp1.index, typeRef),
module.local_get(temp2.index, typeRef)
),
typeRef
)
);
return ret;
}
Expand Down Expand Up @@ -3133,7 +3131,7 @@ function builtin_select(ctx: BuiltinFunctionContext): ExpressionRef {
operands[2]
);
compiler.currentType = type;
return module.select(arg0, arg1, arg2, type.toRef());
return module.select(arg0, arg1, arg2);
}
builtinFunctions.set(BuiltinNames.select, builtin_select);

Expand Down
13 changes: 11 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ export class Compiler extends DiagnosticEmitter {
// initialize lookup maps, built-ins, imports, exports, etc.
this.program.initialize();


// Binaryen treats all function references as being leaked to the outside world when
// the module isn't marked as closed-world (see WebAssembly/binaryen#7135). Therefore,
// we should mark the module as closed-world when we're definitely sure it is.
module.setClosedWorld(true);

// obtain the main start function
let startFunctionInstance = this.currentFlow.targetFunction;
assert(startFunctionInstance.internalName == BuiltinNames.start);
Expand Down Expand Up @@ -857,6 +863,7 @@ export class Compiler extends DiagnosticEmitter {
ImportNames.DefaultNamespace,
ImportNames.Table
);
module.setClosedWorld(false);
if (options.pedantic && options.willOptimize) {
this.pedantic(
DiagnosticCode.Importing_the_table_disables_some_indirect_call_optimizations,
Expand All @@ -866,6 +873,7 @@ export class Compiler extends DiagnosticEmitter {
}
if (options.exportTable) {
module.addTableExport(CommonNames.DefaultTable, ExportNames.Table);
module.setClosedWorld(false);
if (options.pedantic && options.willOptimize) {
this.pedantic(
DiagnosticCode.Exporting_the_table_disables_some_indirect_call_optimizations,
Expand Down Expand Up @@ -977,6 +985,7 @@ export class Compiler extends DiagnosticEmitter {
}
}
}
if (functionInstance.signature.returnType.kind == TypeKind.Func) this.module.setClosedWorld(false);
}
return;
}
Expand Down Expand Up @@ -1007,6 +1016,7 @@ export class Compiler extends DiagnosticEmitter {
this.desiresExportRuntime = true;
}
}
if (global.type.kind == TypeKind.Func) this.module.setClosedWorld(false);
}
if (global.type == Type.v128) {
this.warning(
Expand Down Expand Up @@ -4975,8 +4985,7 @@ export class Compiler extends DiagnosticEmitter {
return module.select(
module.i32(1),
module.binary(BinaryOp.EqI32, rightExpr, module.i32(0)),
leftExpr,
TypeRef.I32
leftExpr
);
}
case TypeKind.I8:
Expand Down
Loading