Component model & GC
A few days ago WASM 3.0 was standardized, supporting GC. However, I am trying to use the component model and I cannot find any information how/if it supports/will support WASM 3.0 GC. I found some issues describing mapping to the GC model but it would be really nice to have an official roadmap. I need to make some key decisions how I will generate the WASM code.
I am relatively new here but there seems to be a bit of an impedance mismatch between the GC types and WIT types? It feels like the new types make it a lot easier to do components?
So I am thoroughly confused and would love a pointer to where this information can be found.
If there is another medium I should post these questions on then sorry for the disruption.
Hi, great question! There is currently a proposal for how we'd add a second gc Canonical ABI option in #525 and I think there has been some prototypical work since then too, but I'm not sure of the exact status (I'd ask @fitzgen). I do think this would be a natural addition to include in a 1.0 MVP, depending on time and available resources. In the meantime, although it's decidedly suboptimal, I'd suggest copying to and from a linear memory scratch buffer at ABI boundaries.
I'm not an expert so I might be off. But I understand that with the gc option and reference types you let the container do the memory allocation. The host just gets normal reference pointers. This is a gigantic simplification wrt having to do your own memory management. Or am I missing something?
If I'm understanding your question correctly, yes, those are some of the benefits of wasm-gc. I will note that if a reference to a mutable memory location is passed between the host and wasm code, the host still needs to be careful to root the reference appropriately (and use appropriate indirection if the GC is moving) and ensure value semantics by making a copy, if need be, before allowing wasm to run again and potentially mutate the location's contents.
@lukewagner I am having a HARD time finding any documentation about how to work with GC types. I can see classes in Rust for Wasmtime but their documentation is very local, I am missing an overview and examples. I saw RootScope and Rooted but so far had not made the link to the GC :-( (The comments in the Root* files helped a bit!) I am screaming for a description of how to work with GC and Wasmtime. And Copilot and chatgpt still very much have their head in the pre-GC wasmtime.
Do you have any links to documentation? My current mind model is that GC will provide so much advantages that I will try my own marshaling/lifting partly because I've actually only one data type that needs to be marshaled so that should be doable ... in some way.
At the component-model level, since #525 is just a pre-proposal and not yet implemented, there isn't any documentation for how this would work yet. But for a sense of what rooting looks like, though, you can see the existing Core WebAssembly host APIs for interacting GC references, e.g., see the use of Rooted in Wasmtime's [Val] type for the reference-typed cases; if you want to roll your own wasm-gc ABI, working directly with Core WebAssembly modules may be a good way to start.