Skip to content

Expose GC API to Binaryen.JS #7466

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 29 commits into from
Apr 15, 2025
Merged

Expose GC API to Binaryen.JS #7466

merged 29 commits into from
Apr 15, 2025

Conversation

GulgDev
Copy link
Contributor

@GulgDev GulgDev commented Apr 8, 2025

Adds TypeBuilder interface and the following WasmGC instructions to JS: ref.test, ref.cast, any.convert_extern, extern.convert_any, br_on_null, br_on_non_null, br_on_cast, br_on_cast_fail, struct.new, struct.new_default, struct.get, struct.set, array.new, array.new_default, array.new_fixed, array.new_data, array.new_elem*, array.get, array.set, array.len, array.fill*, array.copy, array.init_data*, array.init_elem*.
Instructions that were added both to JS and to C are marked with an asterisk (*).
The corresponding test case was also added (gc.js).
Fixes #5921
This PR also fixes memory leaks caused by stack allocations that are not wrapped in preserveStack.

@GulgDev
Copy link
Contributor Author

GulgDev commented Apr 8, 2025

There are some functions I'm unsure how to implement. For example, I can't seem to find a C implementation of array.init_elem

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Yes, it looks like ArrayInitElem needs to be added to the C API, first.

@kripken
Copy link
Member

kripken commented Apr 9, 2025

Looks like there are errors on CI, might make sense to fix those before I do an in-depth review here, but let me know if you are stuck.

@GulgDev
Copy link
Contributor Author

GulgDev commented Apr 10, 2025

Looks like there are errors on CI, might make sense to fix those before I do an in-depth review here, but let me know if you are stuck.

I'm not stuck, just doing some experiments. I will re-request review when I'm done, thanks! The missing C API is already there, just need to add JS wrapper & tests.

I had some issues with testing locally, so I had to use CI for that purpose, but I finally managed to resolve this problem. I think that tests are just not optimized for Windows.

@GulgDev GulgDev marked this pull request as draft April 11, 2025 11:20
@GulgDev GulgDev marked this pull request as ready for review April 13, 2025 07:44
@GulgDev GulgDev requested a review from kripken April 13, 2025 07:44
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Great work, thanks @GulgDev !

@kripken kripken merged commit 5dab961 into WebAssembly:main Apr 15, 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.

Exposing GC in binaryen.js APIs
2 participants