Skip to content

wast: parse core rec groups in component and instance types - #2798

Open
jrandolf wants to merge 2 commits into
bytecodealliance:mainfrom
jrandolf:wast-core-rec-in-types
Open

jrandolf wants to merge 2 commits into
bytecodealliance:mainfrom
jrandolf:wast-core-rec-in-types

Conversation

@jrandolf

Copy link
Copy Markdown
Contributor

Component and instance types can declare core recursion groups, which wasmprinter prints as (core rec ...), like at the top level of a component. The text parser only accepted them at the top level, so this valid component printed as text that didn't parse:

(component
  (type (instance
    (core rec (type (func)))
  ))
)

This parses, resolves and encodes them in component and instance types as at the top level.

Found by fuzzing with components generated from the component model's binary grammar (#2796, which skips these until this lands).

Component and instance types can declare core recursion groups, which
`wasmprinter` prints as `(core rec ...)` like at the top level of a
component, but the text parser only accepted them at the top level, so
the printed text of these valid components didn't parse.
@jrandolf
jrandolf requested a review from a team as a code owner October 23, 2026 23:34
@jrandolf
jrandolf requested review from dicej and removed request for a team October 23, 2026 23:34
@alexcrichton
alexcrichton requested review from alexcrichton and removed request for dicej October 24, 2026 03:06
fn expand_component_ty(&mut self, ty: &mut ComponentType<'a>) {
Expander::default().expand_decls(&mut ty.decls, |e, decl| match decl {
ComponentTypeDecl::CoreType(t) => e.expand_core_type(t),
ComponentTypeDecl::CoreRec(_) => {}

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.

I think this, and the one below, need to call expand_core_type on the rec group members, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think these need it. Rec group members are core::Types rather than CoreTypes, so they can't be module types. For non-module types, expand_core_type only fills in a generated id that nothing uses. The top-level ComponentField::CoreRec(_) => None skips them the same way. I've added a test where a module type uses alias outer to refer to a rec group member next to an inline func type, and it roundtrips. I can add the call anyway if you'd prefer.

Covers a module type in an instance type that refers to a type in a rec
group through an outer alias, next to an inline function type.
@jrandolf
jrandolf requested a review from alexcrichton October 26, 2026 16:42

This branch has not been deployed

No deployments
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