Skip to content

winch: implement ref.null, ref.is_null, ref.func, and typed select#12940

Merged
cfallin merged 3 commits intobytecodealliance:mainfrom
r-near:winch-reference-types
Apr 2, 2026
Merged

winch: implement ref.null, ref.is_null, ref.func, and typed select#12940
cfallin merged 3 commits intobytecodealliance:mainfrom
r-near:winch-reference-types

Conversation

@r-near
Copy link
Copy Markdown
Contributor

@r-near r-near commented Apr 2, 2026

Implements the core reference type instructions for Winch (funcref only):

  • ref.null: pushes a null funcref (pointer-sized zero)
  • ref.is_null: compares a ref to zero, produces i32 0/1
  • ref.func: calls the existing ref_func builtin to get a funcref for a function index
  • typed select: delegates to the existing untyped select implementation

Non-func heap types (externref, etc.) bail with an unsupported error, consistent with how table_get, table_set, and other table ops already handle them.

Relates to #8088, #9924.

@r-near r-near requested a review from a team as a code owner April 2, 2026 05:36
@r-near r-near requested review from cfallin and Copilot and removed request for a team April 2, 2026 05:36
@r-near r-near force-pushed the winch-reference-types branch from e2ab600 to db12a1b Compare April 2, 2026 05:46
@r-near r-near requested a review from a team as a code owner April 2, 2026 05:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial support for core WebAssembly reference-type operators (funcref-only) in Winch, enabling compilation of modules that use ref.null, ref.is_null, ref.func, and typed select, while rejecting unsupported heap types in line with existing table-op behavior.

Changes:

  • Implement ref.null, ref.is_null, and ref.func visitor lowering (funcref-only; other heap types error out).
  • Add support for typed select by delegating to the existing select lowering.
  • Extend the “supported ops” list so these operators are no longer treated as unimplemented.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@r-near r-near marked this pull request as draft April 2, 2026 05:47
@r-near r-near force-pushed the winch-reference-types branch from db12a1b to b9dd9f3 Compare April 2, 2026 05:50
@r-near r-near marked this pull request as ready for review April 2, 2026 05:57
@r-near r-near marked this pull request as draft April 2, 2026 05:59
@r-near r-near force-pushed the winch-reference-types branch from b9dd9f3 to 3ceeab8 Compare April 2, 2026 06:02
@r-near r-near force-pushed the winch-reference-types branch from 3ceeab8 to 9fe5fa4 Compare April 2, 2026 06:11
@r-near r-near marked this pull request as ready for review April 2, 2026 06:24
@github-actions github-actions bot added the winch Winch issues or pull requests label Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Subscribe to Label Action

cc @saulecabrera

Details This issue or pull request has been labeled: "winch"

Thus the following users have been cc'd because of the following labels:

  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

This looks reasonable overall to me -- thanks!

A few testing requests:

  • It doesn't look like ref.func's return value is actually tested with a call; could you add a test case that does a table.set then a call_indirect to make use of it?
  • It would be great to have disas tests (tests/disas/winch/) for all of these operators as well.

@r-near
Copy link
Copy Markdown
Contributor Author

r-near commented Apr 2, 2026

Thanks for the quick review @cfallin! Added the tests here: 43d2950 (this PR)

Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me -- thanks!

@cfallin cfallin added this pull request to the merge queue Apr 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 2, 2026
@cfallin
Copy link
Copy Markdown
Member

cfallin commented Apr 2, 2026

@r-near there's a CI test failure (see status from the merge queue attempt) -- perhaps a test is running that shouldn't yet with the current implementation status. Could you take a look?

@r-near r-near requested a review from a team as a code owner April 2, 2026 18:06
@r-near r-near requested review from alexcrichton and removed request for a team April 2, 2026 18:06
Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Actually I believe @fitzgen added this wasmtime::gc test hostcall recently -- Nick, could you verify this is added at the correct place in this case? Thanks!

@cfallin cfallin added this pull request to the merge queue Apr 2, 2026
Merged via the queue into bytecodealliance:main with commit 071c406 Apr 2, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

winch Winch issues or pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants