Skip to content

chore: update Binaryen #2927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025
Merged

Conversation

CountBleck
Copy link
Member

Changes proposed in this pull request:
⯈ Updating Binaryen to v123

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@CountBleck
Copy link
Member Author

CountBleck commented May 30, 2025

This is a draft because I need to update binaryen.js's types so that the code typechecks correctly. (Edit: I am stupid and only had to update the glue types.)
Also, some of the changes to *.release.wat should be looked over...

)
(func $start:function-call~anonymous|2 (param $0 i32) (param $1 i32) (result i32)
local.get $0
local.get $1
i32.add
)
(func $start:function-call~fn2|4 (param $0 i32) (result i32)
i32.const 1
local.get $0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this definitely got worse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these two cases are caused by the same issue (the dae/DeadArgumentElimination pass not doing its job? I'm not fully sure).

I did a bisection to find the Binaryen commit that's responsible. (I tested on the call-optional WAT file in S-expr format, but the issue applies here as well.) It looks like WebAssembly/binaryen#7135 is the cause, as that PR treats any funcref as being possibly leaked to the outside world...

How should we proceed? I don't think marking the module as closed-world is accurate...

Copy link
Member Author

@CountBleck CountBleck Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxGraey Should we just eat the cost and merge this PR? We could also mark the module as closed world if exported functions don't return funcrefs and tables aren't imported/exported...what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also mark the module as closed world if exported functions don't return funcrefs and tables aren't imported/exported...what do you think?

That would be ideal because it's a quite common scenario.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxGraey I made that change now!

(Now that I think about it, AS currently never exports arrow functions/etc. as funcrefs, but as boxed objects instead...regardless, the change accounts for table imports/exports as well as users specifying ref_func exports, or exported functions returning ref_func.)

@CountBleck CountBleck marked this pull request as ready for review June 1, 2025 07:50
Some new features are being added, although only relaxed SIMD is in a
usable state. stringref has been almost obliterated, and only
functionality compatible with JS string builtins is being kept.

Binaryen also seems to be generating more nops and blocks than usual.
Also, due to WebAssembly/binaryen#7135, dead arguments aren't being
eliminated when a function reference is made (ref.func), which affects
the optimized output of call-optional, function-call, and other tests.
@@ -152,6 +152,7 @@
global.get $comma/a
i32.lt_s
if
nop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Do you have any assumption why the nops started showing up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxGraey The function that wrote WAT (StackIR) was passed a true argument to optimize the StackIR, but this was changed to a global option. Setting this global option removes these nops.

Due to WebAssembly/binaryen#7135, any function reference is treated as
potentially leaked to the outside world, unless the module is marked as
closed-world. This prevents DAE from taking place. To fix this, mark
the module as closed-world when tables are neither imported nor exported
and when exports do not return/contain funcrefs.
In WebAssembly/binaryen#6568, StackIR was changed from a set of passes
to a global option. This meant that the `true` argument passed into
_BinaryenModuleAllocateAndWriteStackIR (to optimize the StackIR) no
longer had an effect. This commit restores that and also runs the
optimizations under the same {optimize,shrink}Levels as wasm-opt.
@CountBleck CountBleck requested a review from MaxGraey June 3, 2025 03:23
Copy link
Member

@MaxGraey MaxGraey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CountBleck CountBleck merged commit e5539ef into AssemblyScript:main Jun 3, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants