Skip to content

wasmparser: share the function subtyping check - #2765

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
Lstarsky0:dedup-func-subtype
Oct 9, 2026
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
Lstarsky0:dedup-func-subtype

Conversation

@Lstarsky0

Copy link
Copy Markdown
Contributor

Closes #2480.

OperatorValidator::is_func_subtype and Matches for WithRecGroup<&FuncType> both spelled out the params-contravariant / results-covariant rule. This moves it into one func_signature_matches in matches.rs, which takes each side's params and results as iterators plus an x <: y predicate for single value types. That covers the difference between the two callers:

  • the type-section check still pairs each value type with its rec group and calls Matches::matches;
  • the operator validator (the stack-switching on / switch handler checks) still compares canonical types through WasmModuleResources::is_subtype, and keeps passing ad hoc (params, results) slices, so it doesn't need a FuncType.

The variance comment moved with the logic, unchanged. No behaviour change intended.

To make sure both callers are actually exercised, I flipped each one's predicate in turn: the type-section side breaks 7 tests in the cli suite (gc subtypes, type-subtyping, stack-switching/validation_gc.wast, ...) and the operator side breaks 2 (stack-switching/validation_gc.wast, folding/fold-stack-switching-gc.wast). With the change as is, cargo test --all, the cli suite (916), clippy, rustfmt and the wasmparser --no-default-features / x86_64-unknown-none checks from CI all pass.

The operator validator's `is_func_subtype` (used for stack-switching
handlers) and `Matches for WithRecGroup<&FuncType>` each spelled out the
contravariant-params / covariant-results rule. Pull it into one
`func_signature_matches` that takes the value types as iterators plus an
`x <: y` predicate, so the type-section path keeps pairing each value
with its rec group and the operator validator keeps going through
`WasmModuleResources::is_subtype`.

Closes bytecodealliance#2480
@Lstarsky0
Lstarsky0 requested a review from a team as a code owner October 9, 2026 16:30

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@alexcrichton
alexcrichton added this pull request to the merge queue Oct 9, 2026
Merged via the queue into bytecodealliance:main with commit 1c27a83 Oct 9, 2026
37 checks passed
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.

Deduplicate "is function type A a subtype of function type B"

2 participants