Repository navigation
wasmparser: share the function subtyping check - #2765
Merged
Merged
Conversation
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
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.
Closes #2480.
OperatorValidator::is_func_subtypeandMatches for WithRecGroup<&FuncType>both spelled out the params-contravariant / results-covariant rule. This moves it into onefunc_signature_matchesinmatches.rs, which takes each side's params and results as iterators plus anx <: ypredicate for single value types. That covers the difference between the two callers:Matches::matches;on/switchhandler checks) still compares canonical types throughWasmModuleResources::is_subtype, and keeps passing ad hoc(params, results)slices, so it doesn't need aFuncType.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-nonechecks from CI all pass.