Skip to content

Support table initializers #2593

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

zherczeg
Copy link
Contributor

Another large patch on the top of the other two. Now there are 3-4000 lines of new code is waiting for review, and it looks like the end is still far.

The painful part so far:
https://webassembly.github.io/function-references/core/binary/modules.html#element-section

Since type 0-3 is reserved for (ref func), all (elem ... funcref ...) must be encoded with 4-7, which increase binary size. This affect several tests, and probably real word programs :(

There are spec tests to check this behavior.

@zherczeg
Copy link
Contributor Author

zherczeg commented May 1, 2025

Function references is a Phase 5 (The Feature is Standardized) proposal for WebAssembly. It is a requirement for the Garbage Collection proposal. It is part of the WebAssembly 3.0 draft as well:

https://webassembly.github.io/spec/versions/core/WebAssembly-3.0-draft.pdf

The overview of the proposal isn't that long, but it turned out that it affects all parts of the project, since types are everywhere and type comparisons / validations are frequently used. Nullable / non-nullable references (e.g. tables with initializers and/or active elem initializers, etc.) requires many extra checks as well. Imports are on another level, since you need to validate them across modules. I have no idea how a native function can define references though, there is no module assigned for them.

This amount of work this feature needs was unexpected for me. Unfortunately, this is unavoidable. I made many patches, and these cover most specification tests, although some of them are still just partly supported. However, I don't get any reviews for them. I would like to understand why.

  • Is this a feature which does not align with the aims of wabt?
  • Are these changes too big / too risky?
  • Any other reasons?

It is very hard to make progress when I don't get any feedback, and I need to maintain several patches. Is there a chance these patches will land?

@sbc100
Copy link
Member

sbc100 commented May 6, 2025

This amount of work this feature needs was unexpected for me. Unfortunately, this is unavoidable. I made many patches, and these cover most specification tests, although some of them are still just partly supported. However, I don't get any reviews for them. I would like to understand why.

  • Is this a feature which does not align with the aims of wabt?
  • Are these changes too big / too risky?
  • Any other reasons?

It is very hard to make progress when I don't get any feedback, and I need to maintain several patches. Is there a chance these patches will land?

Sorry for the lack of feedback on some of your patches. Unfortunately there are very few folks to who have any time to work on wabt these days (or review patches).

Please expect fairly long feedback cycles. If you are waiting for a review from me, feel free to ping me a every couple of days, but please understand that I have very few cycles to spend on wabt myself.

For some background on where some folks see wabt heading see this issue: #2348. If you would like to help maintain wabt going forward, and potentially work on major additions such as GC please join that discussion.

@zherczeg
Copy link
Contributor Author

zherczeg commented May 6, 2025

Thank you for the suggestion!

@zherczeg zherczeg force-pushed the table_init branch 2 times, most recently from 6492586 to e92be0b Compare May 8, 2025 12:14
@zherczeg zherczeg marked this pull request as ready for review May 8, 2025 12:19
@zherczeg
Copy link
Contributor Author

zherczeg commented May 8, 2025

The patch set (#2562, #2567, and this patch) covers 25 tests from the 26 spec tests in testsuite/proposals/function-references. That is 96% pass rate. The missing one is ref.wast, which needs removing the invalid reference test during parsing.

@sbc100
Copy link
Member

sbc100 commented May 8, 2025

The patch set (#2562, #2567, and this patch) covers 25 tests from the 26 spec tests in testsuite/proposals/function-references. That is 96% pass rate. The missing one is ref.wast, which needs removing the invalid reference test during parsing.

Nice! Thanks for all the hard work on this.

I assume #2562 is the first in the series and the one we should look at first?

BTW can you have this PR a better title? Support table initializers sounds odd because that is obviously something that wabt already supports. Perhaps you mean a certain type of new table intializer?

@zherczeg
Copy link
Contributor Author

zherczeg commented May 8, 2025

I assume #2562 is the first in the series and the one we should look at first?

Yes. It focuses on extending the existing features, e.g. tables / globals now supports refs. Recursive refs, and not initalized non nullable refs are detected as well.
The next patch focuses on adding new byte codes.
The last focuses on a new initializer value for tables. It breaks the current API.

BTW can you have this PR a better title? Support table initializers sounds odd because that is obviously something that wabt already supports. Perhaps you mean a certain type of new table intializer?

I am open to any ideas.

https://github.com/WebAssembly/function-references/blob/main/proposals/function-references/Overview.md#tables
Tables can have an optional initializer value, and all elements of the table is set to that value when the table is constructed (before active elems are processed). If ref.null is not possible for a table (e.g. it has (ref func) type), the initializer is mandatory.

Btw I found a case, which has no spec test, and the specification is unclear:

(table (ref func) (elem 1)) -> since all elements of the table is initialized, it seems the initializer is unnecessary.

However, if I do the inlining here, I should get a missing initializer error:
https://webassembly.github.io/function-references/core/text/modules.html#tables
And I have no idea how the binary should be constructed. Maybe the first function could be the initializer.

@keithw
Copy link
Member

keithw commented May 8, 2025

FWIW, when I hit a case where the prose spec is unclear, I usually just go try it in the reference interpreter and in wasm-tools. If those two disagree, it's an even better opportunity to submit a new test case. :-) Andreas is usually very quick about accepting new test cases into the spec repo.

@zherczeg zherczeg force-pushed the table_init branch 2 times, most recently from ec270d6 to e6dff8a Compare May 9, 2025 09:46
@zherczeg
Copy link
Contributor Author

zherczeg commented May 9, 2025

The last test is done, now all spec test are pass.

Zoltan Herczeg added 3 commits May 14, 2025 07:11
Support named references for globals, locals, tables, elems
Support named references for call_ref, ref_null
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