Fix some minor C API mistakes#13149
Merged
cfallin merged 1 commit intobytecodealliance:mainfrom Apr 20, 2026
Merged
Conversation
* Remove stray `struct wasmtime_eqref` * Remove header definition for `wasmtime_anyref_to_eqref` as it doesn't exist. The function is actually `wasmtime_anyref_as_eqref` which has tests and such. * Define `wasm_tagtype_vec_*` functions.
cfallin
approved these changes
Apr 20, 2026
alexcrichton
added a commit
to alexcrichton/wasmtime
that referenced
this pull request
Apr 21, 2026
In updating `wasmtime-py` to Wasmtime 44 I noticed a few discrepancies in the C API, and then C++ API, in addition to what was found in bytecodealliance#13149. Notably we had both `wasmtime_exn_t`/`Exn` and `wasmtime_exnref_t`/`ExnRef`. In sorting this out with some deeper fixes in bytecodealliance#13149 I got stuck again in the rat's nest of circular definitions of classes in C++. In the end I gave up trying to incrementally improve things and decided to go with a larger refactoring. The goal here is to more cleanly separate out responsibilities and improve how circular definitions in C++ are handled: * All reference types now live in their own file. Reference types aren't in a mix of `val.h` or `gc.h` or `exn.h`, but instead each type lives in its own file. This means that `gc.h` is now gone and is replaced by `anyref.h`, `externref.h`, `exnref.h`, `eqref.h`, ... * C++ class definitions are split into separate headers from their main files. For example there's now `wasmtime/_anyref_class.hh` instead of just `wasmtime/anyref.hh`. This new method of resolving circular dependencies has some nice properties where headers that depend on the `AnyRef` type, for example, include `_anyref_class.h`. The `anyref.h` header then is able to include all other headers necessary for defining methods. Notably this means that methods now always live in the header of the type as opposed to sprinkled about in various locations. Note that this is applied to preexisting headers like `func.hh` and `store.hh` out of necessity, too. * Reference types in the C++ now share core methods via a macro to avoid duplicating code and to ensure they have a uniform API. * Some `#define`s for `WASMTIME_FEATURE_GC` guards were adjusted in a few locations. For example `wasmtime_valraw_t` no longer has GC fields when the GC proposal is disabled. * Reorganization was reflected on the Rust side as well. This means the previous `ref.rs` is now broken up into files such as `anyref.rs`. Some logic of core functions was also deduplicated within the `ref_wrapper!` macro. The old definitions of `wasmtime_exn_t` and `wasmtime_exnref_t` were also both merged. Overall this PR contains quite a lot of code movement and things were shuffled around, as well as adjustments to the `exnref` C API (removing duplication). Overall though the API is largely as it was before, although for the C++ API if individual headers are being included some new ones may need to be included to ensure all methods are defined. My hope is that the end result here is a bit more maintainable, types are easier to modify/extend, there's no longer any soups to deal with in C++, and everything should have a uniform API.
pull bot
pushed a commit
to Haofei/wasmtime
that referenced
this pull request
Apr 21, 2026
* Refactor reference types in the C/C++ API In updating `wasmtime-py` to Wasmtime 44 I noticed a few discrepancies in the C API, and then C++ API, in addition to what was found in bytecodealliance#13149. Notably we had both `wasmtime_exn_t`/`Exn` and `wasmtime_exnref_t`/`ExnRef`. In sorting this out with some deeper fixes in bytecodealliance#13149 I got stuck again in the rat's nest of circular definitions of classes in C++. In the end I gave up trying to incrementally improve things and decided to go with a larger refactoring. The goal here is to more cleanly separate out responsibilities and improve how circular definitions in C++ are handled: * All reference types now live in their own file. Reference types aren't in a mix of `val.h` or `gc.h` or `exn.h`, but instead each type lives in its own file. This means that `gc.h` is now gone and is replaced by `anyref.h`, `externref.h`, `exnref.h`, `eqref.h`, ... * C++ class definitions are split into separate headers from their main files. For example there's now `wasmtime/_anyref_class.hh` instead of just `wasmtime/anyref.hh`. This new method of resolving circular dependencies has some nice properties where headers that depend on the `AnyRef` type, for example, include `_anyref_class.h`. The `anyref.h` header then is able to include all other headers necessary for defining methods. Notably this means that methods now always live in the header of the type as opposed to sprinkled about in various locations. Note that this is applied to preexisting headers like `func.hh` and `store.hh` out of necessity, too. * Reference types in the C++ now share core methods via a macro to avoid duplicating code and to ensure they have a uniform API. * Some `#define`s for `WASMTIME_FEATURE_GC` guards were adjusted in a few locations. For example `wasmtime_valraw_t` no longer has GC fields when the GC proposal is disabled. * Reorganization was reflected on the Rust side as well. This means the previous `ref.rs` is now broken up into files such as `anyref.rs`. Some logic of core functions was also deduplicated within the `ref_wrapper!` macro. The old definitions of `wasmtime_exn_t` and `wasmtime_exnref_t` were also both merged. Overall this PR contains quite a lot of code movement and things were shuffled around, as well as adjustments to the `exnref` C API (removing duplication). Overall though the API is largely as it was before, although for the C++ API if individual headers are being included some new ones may need to be included to ensure all methods are defined. My hope is that the end result here is a bit more maintainable, types are easier to modify/extend, there's no longer any soups to deal with in C++, and everything should have a uniform API. * Add anyerf.h to list of all headers * Fix clippy prtest:full * Fix docs * Fix leak in test * More doc fixes * Review comments * Fix rebase conflict
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.
struct wasmtime_eqrefwasmtime_anyref_to_eqrefas it doesn't exist. The function is actuallywasmtime_anyref_as_eqrefwhich has tests and such.wasm_tagtype_vec_*functions.