Stream: git-wasmtime

Topic: wasmtime / PR #12940 winch: implement ref.null, ref.is_nu...


view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:36):

r-near opened PR #12940 from r-near:winch-reference-types to bytecodealliance:main:

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

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.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:36):

r-near requested cfallin for a review on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:36):

r-near requested Copilot for a review on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:36):

r-near requested wasmtime-compiler-reviewers for a review on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:46):

r-near updated PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:46):

r-near requested wasmtime-core-reviewers for a review on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:47):

Copilot created PR review comment:

visit_ref_is_null hardcodes RegImm::i64(0) and OperandSize::S64. Since ref.is_null is defined over pointer-sized references and this module already threads env.ptr_type() elsewhere (e.g. visit_ref_null, memory_grow adjustments), it would be more robust to derive the operand size/immediate from the target pointer type (or from the popped value’s WasmValType) rather than assuming 64-bit.

This avoids future miscompiles if/when Winch gains 32-bit pointer support or if pointer width becomes configurable in more places.

            let (zero, size) = match self.env.ptr_type() {
                WasmValType::I64 => (RegImm::i64(0), OperandSize::S64),
                WasmValType::I32 => (RegImm::i32(0), OperandSize::S32),
                _ => bail!(CodeGenError::unsupported_wasm_type()),
            };
            masm.cmp_with_set(writable!(reg), zero, IntCmpKind::Eq, size)?;

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:47):

Copilot submitted PR review:

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:


:light_bulb: <a href="/bytecodealliance/wasmtime/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:47):

Copilot created PR review comment:

visit_typed_select ignores the immediate result type and delegates to visit_select, which pushes val2 with its original WasmValType. For typed select, operands may have different (e.g. different ref nullability/subtypes) types while the immediate type defines the result; keeping val2's type can leave the value stack with an incorrect type for subsequent lowering decisions.

Consider converting the ValType immediate to the corresponding WasmValType (e.g. via the existing TypeConverter) and updating the selected value's tracked type to that result type (and/or asserting it matches the operand widths) before pushing it back onto the stack.

    fn visit_typed_select(&mut self, ty: ValType) -> Self::Output {
        let cond = self.context.pop_to_reg(self.masm, None)?;
        let val2 = self.context.pop_to_reg(self.masm, None)?;
        let val1 = self.context.pop_to_reg(self.masm, None)?;

        // Determine the result machine type from the immediate. Numeric types
        // map directly; all ref-like types are represented using the pointer
        // type in this backend.
        let result_ty = match ty {
            ValType::I32 => WasmValType::I32,
            ValType::I64 => WasmValType::I64,
            ValType::F32 => WasmValType::F32,
            ValType::F64 => WasmValType::F64,
            ValType::V128 => WasmValType::V128,
            _ => self.env.ptr_type(),
        };

        // In well-typed Wasm, the operands to a select have the same
        // representation type as the result. Assert this in debug builds.
        debug_assert_eq!(val1.ty, val2.ty);
        debug_assert_eq!(val1.ty, result_ty);

        self.masm
            .cmp(cond.reg, RegImm::i32(0), OperandSize::S32)?;
        // Conditionally move val1 to val2 if the comparison is not zero.
        self.masm.cmov(
            writable!(val2.into()),
            val1.into(),
            IntCmpKind::Ne,
            val1.ty.try_into()?,
        )?;

        // Push the selected value back on the stack using the result type
        // derived from the immediate, not the original type of `val2`.
        self.context.stack.push(Val::reg(val2.reg, result_ty));

        self.context.free_reg(val1.reg);
        self.context.free_reg(cond);

        Ok(())

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:47):

r-near converted PR #12940 winch: implement ref.null, ref.is_null, ref.func, and typed select to a draft.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:50):

r-near updated PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:51):

r-near submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:51):

r-near created PR review comment:

Good catch, fixed to derive the size from ptr_type()

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:51):

r-near submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:51):

r-near created PR review comment:

In well-typed wasm the operands already have the same representation type as the result, the type annotation is purely for validation. The existing visit_select handles this correctly since it derives the operand size from the stack values. Duplicating the logic to thread a ValType we don't need seems like unnecessary complexity.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:57):

r-near has marked PR #12940 as ready for review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 05:59):

r-near converted PR #12940 winch: implement ref.null, ref.is_null, ref.func, and typed select to a draft.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 06:02):

r-near updated PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 06:11):

r-near updated PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 06:25):

r-near has marked PR #12940 as ready for review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 10:03):

github-actions[bot] added the label winch on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 10:03):

github-actions[bot] commented on PR #12940:

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:

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

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 14:52):

cfallin submitted PR review:

This looks reasonable overall to me -- thanks!

A few testing requests:

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 16:40):

r-near updated PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 17:00):

r-near commented on PR #12940:

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

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 17:03):

cfallin submitted PR review:

Looks reasonable to me -- thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 17:03):

cfallin added PR #12940 winch: implement ref.null, ref.is_null, ref.func, and typed select to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 17:37):

github-merge-queue[bot] removed PR #12940 winch: implement ref.null, ref.is_null, ref.func, and typed select from the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 17:40):

cfallin commented on PR #12940:

@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?

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 18:06):

r-near requested alexcrichton for a review on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 18:06):

r-near requested wasmtime-fuzz-reviewers for a review on PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 18:06):

r-near updated PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 18:17):

cfallin submitted PR review:

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!

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 19:37):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 19:48):

cfallin added PR #12940 winch: implement ref.null, ref.is_null, ref.func, and typed select to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 20:11):

cfallin merged PR #12940.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 02 2026 at 20:11):

cfallin removed PR #12940 winch: implement ref.null, ref.is_null, ref.func, and typed select from the merge queue.


Last updated: Apr 12 2026 at 23:10 UTC