Skip to content

Support multiple supertypes in everything but validation - #2652

Open
alexcrichton wants to merge 2 commits into
bytecodealliance:mainfrom
alexcrichton:handle-multiple-supertypes
Open

alexcrichton wants to merge 2 commits into
bytecodealliance:mainfrom
alexcrichton:handle-multiple-supertypes

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

Upstream a new spec test has been added that a type with multiple supetypes is considered invalid. This is distinct from malformed meaning that the binary doesn't even parse, but by being invalid that means that the binary parses but is dynamically considered invalid. This test requires handling multiple supertypes in all locations throughout the tooling here, for example wast, wasm-encoder, and wasmparser. Notably wasmparser now has a Vec<u32> for supertype indices, and lengths > 1 are rejected during validation.

While here this is changing all of the dump test outputs anyway so this switches to printing types in a more human-readable format.

Upstream a new spec test has been added that a type with multiple
supetypes is considered invalid. This is distinct from malformed meaning
that the binary doesn't even parse, but by being invalid that means that
the binary parses but is dynamically considered invalid. This test
requires handling multiple supertypes in all locations throughout the
tooling here, for example `wast`, `wasm-encoder`, and `wasmparser`.
Notably `wasmparser` now has a `Vec<u32>` for supertype indices, and
lengths > 1 are rejected during validation.

While here this is changing all of the `dump` test outputs anyway so
this switches to printing types in a more human-readable format.
@alexcrichton
alexcrichton requested a review from a team as a code owner September 11, 2026 15:01

@fitzgen fitzgen 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.

LGTM with below addressed

/// The list of supertype indexes. As of GC MVP, there can be at most one
/// supertype.
pub supertype_idx: Option<u32>,
pub supertype_idxs: Vec<u32>,

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.

SmallVec to avoid the heap allocation in practice for valid modules?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How strongly do you feel about that? This has come up a few times in the past about using smallvec in wasmparser and other crates here, so this isn't new, but so far we haven't added the dependency. This would add a new dep to all of these crates, and the only real perf-critical one is wasmparser which is already, before this PR, collecting the results into the heap and then taking it back out.

If smallvec or similar were in libstd I'd use it without hesitation, but as an extra dep it's something extra for all users to pull in and depend on, and wasmparser in particular shows up in a good number of dependency trees. Keeping our deps slim for minimal feature builds (e.g. without the component-model) feels relatively important at least.

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.

It feels like a very light dep to me, but if we're concerned about that, then I think we can do some small shenanigans to make it optional while making the uses inside the crates not too bad. Luckily that is pretty simple and concise, so not too annoying to duplicate across each crate.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That unfortunately wouldn't work though b/c toggling a Cargo feature would be able to cause compile-time breakages -- basically it's public knowledge that SmallVec<...> == Vec<T> so when the crate dep is pulled in it'd break builds that relied on such equivalence. We've historically solved this in wasmparser with collection wrappers but that requires duplicating the API surface area of collections which I think crosses the threshold of "probably shouldn't copy across crates".

I suppose another way to say what I'm thinking is that I don't think that the crate dependency is worth it unless we've got benchmarks showing such. At this time I don't think we do have such benchmarks, and at least for Wasmtime's use cases I don't think validation/parsing really factors into any of them, so I don't think we actually have a benchmark-driven use case for taking a new dependency at this time

pub is_final: bool,
/// The list of supertype indexes. As of GC MVP, there can be at most one supertype.
pub supertype_idx: Option<PackedIndex>,
pub supertype_idxs: Vec<PackedIndex>,

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.

Ditto

Comment thread crates/wasmparser/src/limits.rs
pub shared: bool,
/// The declared parent type of this definition.
pub parent: Option<Index<'a>>,
pub parents: Vec<Index<'a>>,

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.

Ditto re SmallVec

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.

2 participants