fix: skip is_simple_stub for closures on wasm-gc#5
Open
bikallem wants to merge 1 commit intomoonbitlang:mainfrom
Open
fix: skip is_simple_stub for closures on wasm-gc#5bikallem wants to merge 1 commit intomoonbitlang:mainfrom
bikallem wants to merge 1 commit intomoonbitlang:mainfrom
Conversation
On wasm-gc, closures passed to FFI stubs are externref regardless of their internal type signatures. Skip is_simple_stub validation for arrow types when target is Wasm_gc. Fixes: moonbitlang/moonbit-docs#1131 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adjusts FFI stub type validation for the wasm-gc backend so that closure (arrow) types don’t undergo the stricter is_simple_stub validation of their internal parameter/return types, aligning with the fact that closures are passed as externref in wasm import/export signatures on wasm-gc.
Changes:
- Skip
is_simple_stubvalidation forTarrowtypes when!Basic_config.target = Wasm_gc. - Preserve existing rejection of async functions / disallowed function positions via the prior
Tarrow { is_async; _ } when ...guard.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
externrefregardless of their internal type signatures. Skipis_simple_stubvalidation for arrow types when target isWasm_gc.Fixes: moonbitlang/moonbit-docs#1131
Root Cause
check_stub_typeintypeutil.mlvalidates types inside closure signatures viais_simple_stub(lines 1004–1031), which is more restrictive than the top-level validation — but shouldn't need to be, since closures are justexternrefon wasm-gc.String
Enums (e.g.
NotificationPermission)Why it doesn't matter
On wasm-gc, a closure in an FFI stub becomes
externref. The wasm import signature is(func (param externref) (result externref))regardless of the MoonBit-level closure type. The types inside the closure are a MoonBit-level concern — they only matter when JS calls the closure back. They're irrelevant to the wasm import signature.Fix
When
!Basic_config.target = Wasm_gc, returnNoneimmediately for arrow types, skippingis_simple_stubentirely. This matches the existing wasm-gc special-casing pattern forT_stringat line 970.Test plan
String,Array[T], and enum params/returns compile in wasm-gc stubsis_simple_stub🤖 Generated with Claude Code