Skip to content

Fill out GC type reflection in the C API#13235

Merged
alexcrichton merged 8 commits intobytecodealliance:mainfrom
alexcrichton:c-api-reftypes
May 1, 2026
Merged

Fill out GC type reflection in the C API#13235
alexcrichton merged 8 commits intobytecodealliance:mainfrom
alexcrichton:c-api-reftypes

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit fills out APIs necessary to reflect on value types to get the full type hierarchy of WebAssembly. Currently types in the C API are primarily inherited from wasm.h which notably doesn't handle proposals such as simd or GC or typed function references. This puts us in a bit of an awkward position where much of our API relies on wasm.h, but there's obvious holes in wasm.h that would otherwise require modifications.

This commit takes the route of adding a parallel wasmtime_valtype_t definition fully tailored for Wasmtime's use case. Conversions are then provided between wasmtime_valtype_t and wasm_valtype_t. The Wasmtime version notably has a different representation which enables, for example, constructing primitive types without function calls.

This then fills out the corresponding C++ APIs and fills gaps in the preexisting types. For example FieldType is much different from before and now follows C++ idioms and semantics. Additionally it now has the ability to express the full breadth of all wasm types in fields and they can both be constructed and read.

This is all necessary for some implementation work to fill out the GC proposal in the wasmtime-py bindings where the lack of type information was otherwise leading to a pretty awkward API relative to the rest of the package.

This commit fills out APIs necessary to reflect on value types to get
the full type hierarchy of WebAssembly. Currently types in the C API are
primarily inherited from `wasm.h` which notably doesn't handle
proposals such as simd or GC or typed function references. This puts us
in a bit of an awkward position where much of our API relies on
`wasm.h`, but there's obvious holes in `wasm.h` that would otherwise
require modifications.

This commit takes the route of adding a parallel `wasmtime_valtype_t`
definition fully tailored for Wasmtime's use case. Conversions are then
provided between `wasmtime_valtype_t` and `wasm_valtype_t`. The
Wasmtime version notably has a different representation which enables,
for example, constructing primitive types without function calls.

This then fills out the corresponding C++ APIs and fills gaps in the
preexisting types. For example `FieldType` is much different from before
and now follows C++ idioms and semantics. Additionally it now has the
ability to express the full breadth of all wasm types in fields and they
can both be constructed and read.

This is all necessary for some implementation work to fill out the GC
proposal in the `wasmtime-py` bindings where the lack of type
information was otherwise leading to a pretty awkward API relative to
the rest of the package.
@alexcrichton alexcrichton requested a review from a team as a code owner April 30, 2026 00:39
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team April 30, 2026 00:39
@github-actions github-actions Bot added the wasmtime:c-api Issues pertaining to the C API. label Apr 30, 2026
Copy link
Copy Markdown
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

LGTM!

@fitzgen fitzgen added this pull request to the merge queue May 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 1, 2026
@alexcrichton alexcrichton enabled auto-merge May 1, 2026 19:35
@alexcrichton alexcrichton added this pull request to the merge queue May 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 1, 2026
@alexcrichton alexcrichton added this pull request to the merge queue May 1, 2026
Merged via the queue into bytecodealliance:main with commit e956168 May 1, 2026
52 checks passed
@alexcrichton alexcrichton deleted the c-api-reftypes branch May 1, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants