Fix wasm-gc externref trait-object cast path#6
Open
bikallem wants to merge 1 commit intomoonbitlang:mainfrom
Open
Fix wasm-gc externref trait-object cast path#6bikallem wants to merge 1 commit intomoonbitlang:mainfrom
bikallem wants to merge 1 commit intomoonbitlang:mainfrom
Conversation
Fixes moonbitlang/moonbit-docs#1123. The wasm-gc backend was emitting invalid cast sequences when trait-object conversion involved #external values across supertrait chains. This change adds a Pidentity lowering path in clam_of_core and tightens Pcast lowering to avoid redundant casts and preserve source/target type intent. In wasm_of_clam_gc, Lcast now handles Ref_extern<->Ref_any with the dedicated conversion ops (Extern_convert_any / Any_convert_extern) instead of generic ref_cast where needed.
f2811ac to
9dbea76
Compare
There was a problem hiding this comment.
Pull request overview
Fixes wasm-gc reference casting for trait-object paths when #external (externref) values cross supertrait chains, avoiding invalid Wasm validation due to mismatched ref kinds.
Changes:
- Emit
extern.convert_any/any.convert_externforLcastbetweenRef_externandRef_anyinstead of using genericref.cast. - Lower
%identityand tighten%castlowering soLcastis only emitted when source/target ltypes differ (and ensure casts operate on vars viabind). - Adjust stub type validation to allow function-typed stub parameters under the
Wasm_gctarget.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/wasm_of_clam_gc.ml |
Special-cases Lcast between externref/anyref using dedicated Wasm GC conversion ops. |
src/clam_of_core.ml |
Adds explicit %identity lowering and avoids emitting redundant Lcast when ltypes are equal. |
src/typeutil.ml |
Changes stub type checking behavior for function types when targeting Wasm_gc. |
💡 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
Fixes the wasm-gc cast path for trait objects when
#external(externref) values flow across supertrait chains.What changed
clam_of_core: add explicitPidentitylowering and tightenPcastlowering so casts are emitted only when source/target ltypes differ.wasm_of_clam_gc: handleLcastbetweenRef_externandRef_anywith dedicated ops (Extern_convert_any/Any_convert_extern) instead of genericref_castin those cases.Why
Issue report shows invalid wasm validation/instantiation due to mismatch in casted ref kinds for
#external-> trait object conversion.Fixes moonbitlang/moonbit-docs#1123.