Skip to content

Fix some minor C API mistakes#13149

Merged
cfallin merged 1 commit intobytecodealliance:mainfrom
alexcrichton:fix-some-c-api-mistakes
Apr 20, 2026
Merged

Fix some minor C API mistakes#13149
cfallin merged 1 commit intobytecodealliance:mainfrom
alexcrichton:fix-some-c-api-mistakes

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

  • 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.

* 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.
@alexcrichton alexcrichton requested a review from a team as a code owner April 20, 2026 16:00
@alexcrichton alexcrichton requested review from cfallin and removed request for a team April 20, 2026 16:00
@cfallin cfallin added this pull request to the merge queue Apr 20, 2026
Merged via the queue into bytecodealliance:main with commit e3c18ed Apr 20, 2026
52 checks passed
@alexcrichton alexcrichton deleted the fix-some-c-api-mistakes branch April 20, 2026 18:34
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
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