alexcrichton opened PR #13154 from alexcrichton:refactor-gc-c-api to bytecodealliance:main:
In updating
wasmtime-pyto Wasmtime 44 I noticed a few discrepancies in the C API, and then C++ API, in addition to what was found in #13149. Notably we had bothwasmtime_exn_t/Exnand
wasmtime_exnref_t/ExnRef. In sorting this out with some deeper fixes in #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.horgc.horexn.h, but instead each type lives in its own file. This means thatgc.his now gone and is replaced byanyref.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.hhinstead of justwasmtime/anyref.hh. This new method of resolving circular dependencies has some nice properties where headers that depend on theAnyReftype, for example, include_anyref_class.h. Theanyref.hheader 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 likefunc.hhandstore.hhout 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
#defines forWASMTIME_FEATURE_GCguards were adjusted in a few locations. For examplewasmtime_valraw_tno longer has GC fields when the GC proposal is disabled.Reorganization was reflected on the Rust side as well. This means the previous
ref.rsis now broken up into files such asanyref.rs. Some logic of core functions was also deduplicated within theref_wrapper!macro. The old definitions ofwasmtime_exn_tandwasmtime_exnref_twere also both merged.Overall this PR contains quite a lot of code movement and things were shuffled around, as well as adjustments to the
exnrefC 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.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested dicej for a review on PR #13154.
alexcrichton requested wasmtime-core-reviewers for a review on PR #13154.
alexcrichton updated PR #13154.
alexcrichton updated PR #13154.
alexcrichton updated PR #13154.
github-actions[bot] added the label wasmtime:c-api on PR #13154.
fitzgen submitted PR review:
LGTM
I think in the few other C++ codebases I've touched, the
_foo.hhwould befoo.hhand the existingfoo.hhwould befoo-inlines.hhbut I don't really care what color we paint the bikeshed.
fitzgen created PR review comment:
// ============================================================================ // wasmtime_array_type_t?
fitzgen created PR review comment:
Awkward indent, I think it should be something like
)? }) => {to match the opening
fitzgen created PR review comment:
* APIs for interacting with WebAssembly GC `structref` type in Wasmtime.
alexcrichton updated PR #13154.
alexcrichton commented on PR #13154:
Oh nice! I'll be honest in that I don't really have much experience in C++ codebases. I'm going to flag this for merge mostly out of inertia, but I'm also happy to adjust to that pattern next time I'm in these parts.
alexcrichton has enabled auto merge for PR #13154.
alexcrichton added PR #13154 Refactor reference types in the C/C++ API to the merge queue.
alexcrichton merged PR #13154.
alexcrichton removed PR #13154 Refactor reference types in the C/C++ API from the merge queue.
Last updated: May 03 2026 at 22:13 UTC