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

Support multiple supertypes in everything but validation#2652
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.

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

// See https://webassembly.github.io/spec/js-api/#limits for details.
pub const MAX_WASM_TYPES: usize = 1_000_000;
pub const MAX_WASM_SUPERTYPES: usize = 1;
pub const MAX_WASM_SUPERTYPES: usize = 5;

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.

This seems wrong.

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.

This is required insofar as without this the test case doesn't get past the parsing stage -- an error is generated because 2 supertypes exceeds the maximum of 1. I needed to change this to something, and so I just sort of arbitrarily bumped this up a little bit to get tests passing but not enough that we'd have to worry about it.

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