Repository navigation
c-api: implement wasm_tagtype_t for exception tag types (#10252) - #12763
Conversation
…ance#10252) Implement the C embedder API for WebAssembly exception tags, resolving the long-standing todo!() in CExternType::new() that caused a Rust panic whenever a module with tag exports had its exports enumerated via the C API (e.g. wasm_module_exports / wasmtime_module_exports). Changes: - Add wasm_tagtype_t type with wasm_tagtype_new/params/delete/copy and the standard as_externtype / externtype_as_tagtype cast functions - Add WASM_EXTERN_TAG = 4 constant to wasm_externkind_enum in wasm.h - Add CExternType::Tag(CTagType) variant; wire into CExternType::new() and wasm_externtype_kind() - Add wasmtime/types/tag.hh C++ wrapper (TagType / TagType::Ref) - Extend ExternType::Ref variant and ref_from_c() switch in extern.hh - Add TagType tests: construction, module export enumeration (regression for bytecodealliance#10252), and wasm_externtype_kind / cast function correctness Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Thanks! There's a number of things that CI is turning up here, but one of the more substantive things is that while To handle that, though, it's fine to add functions to a wasmtime-specific header (e.g. a new |
- Revert wasm.h to its vendored upstream state (it must not be modified locally; tag support is not yet in the upstream wasm-c-api spec header) - Add crates/c-api/include/wasmtime/tag.h with wasm_tagtype_t forward declaration, WASM_EXTERN_TAG constant, and all wasm_tagtype_* / wasm_externtype_as_tagtype* function declarations - Include wasmtime/tag.h from wasmtime.h Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Where is
Updated. |
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
The script we use for vendoring is here. For Wasmtime-specific functions, can you use the |
Drop unused `wasm_tagtype_t` import from extern.rs, and remove the `force`/`ty`/`wasm_tagtype_t::new` dead-code paths from tag.rs that were written for future engine-resolution support but are not yet called. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
| WASM_API_EXTERN wasmtime_tagtype_t * | ||
| wasmtime_tagtype_new(wasm_engine_t *engine, const wasm_valkind_t *params, | ||
| size_t nparams); |
There was a problem hiding this comment.
For the signature of this function I'd recommend following the same rough signature of Wasmtime itself. Namely in Wasmtime a tag is constructed from a full FuncType, whereas here all the pieces are provided.
In the original exception-handling proposal tags could only have parameters, but in the stack switching proposal this was relaxed to additionally allow result types too. Given that, and looking forward, I think we'll want to support constructing tags both with and without params/results, so at the very least this constructor needs to grow parameters to communicate the tag's result types. At that point I think it's probably easiest to just take a function type in the constructor.
| /** | ||
| * \brief Returns the kind of the nth exception payload type. | ||
| * | ||
| * Returns 0 if `nth` is out of bounds. | ||
| */ | ||
| WASM_API_EXTERN wasm_valkind_t | ||
| wasmtime_tagtype_param(const wasmtime_tagtype_t *, size_t nth); |
There was a problem hiding this comment.
Here tag parameters are going to want to be communicated with their full value, not just their kind. Similar to above though I'd recommend following the Rust API here which is to just return a function type. This could return either a const wasm_functype_t* which is owned by the tag, or it's probably easier to return an owned wasm_functype_t* which the caller must deallocate.
| /// \brief Value of #wasmtime_extern_kind_t meaning that #wasm_externtype_t is a | ||
| /// tag (WebAssembly exception-handling proposal) | ||
| #define WASMTIME_EXTERN_TAG 5 |
There was a problem hiding this comment.
This is a bit subtle and will need to change. The definitions in this file of WASMTIME_EXTERN_* are discriminants for the wasmtime_extern_t structure below. Eventually that'll want a tag variant as well, in which case this WASMTIME_EXTERN_TAG subtly would serve a double-meaning.
To resolve this I'd recommend moving this #define into tag.h and renaming it perhaps to WASMTIME_EXTERNTYPE_TAG to make it clear that it's for the wasm_externtype_t discriminant rather than wasmtime_extern_t.
| /// Value returned by `wasm_externtype_kind` for exception tags. | ||
| /// Lives alongside `WASMTIME_EXTERN_SHAREDMEMORY` (4) in the `wasmtime_extern_kind_t` space. | ||
| pub const WASMTIME_EXTERN_TAG: wasm_externkind_t = 5; |
There was a problem hiding this comment.
As a further note on this, there's no need to leave room for the SHAREDMEMORY type here. This is ok to have value 4 since it's the next-in-sequence for the wasm_externkind_t union.
- Rename wasm_tagtype_t → wasmtime_tagtype_t and all wasm_tagtype_* functions → wasmtime_tagtype_* to avoid clashing with future wasm.h additions (as requested by alexcrichton) - Constructor now takes wasm_engine_t* + wasm_valkind_t array + count instead of wasm_valtype_vec_t, eliminating the lazy-init complexity - Replace wasm_tagtype_params() (returning a vec) with wasmtime_tagtype_param_count() + wasmtime_tagtype_param(nth), matching the component type accessor iterator pattern - Rename WASM_EXTERN_TAG → WASMTIME_EXTERN_TAG - Simplify CTagType: stores TagType directly, no Arc<Mutex<LazyTagType>> - Update C++ TagType wrapper: constructor takes Engine&, Ref exposes param_count() / param(nth) instead of params() returning ListRef - Add ValType::c_to_kind() static helper used by TagType::Ref::param() - Fix null-pointer panic for zero-length param arrays in Rust Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Erm. How I can re-run test which looks like some transient DNS error?
|
546f6db
Fix for wasm_tagtype_t / C API panic on tag exports was merged upstream as bytecodealliance/wasmtime#12763. Includes all changes from wasmtime 41.0.1 → upstream main, including wasmtime 42.0.x releases. commit-id:7ceabee1
Part of #10252.
I was hitting
todo!()when was playing with ClickHouse WASM UDF, which caused whole ClickHouse to crash. It was only happening with Debug WASM builds andassertfiring all over the place.Implement the C embedder API for WebAssembly exception tags, resolving the long-standing todo!() in CExternType::new() that caused a Rust panic whenever a module with tag exports had its exports enumerated via the C API (e.g. wasm_module_exports / wasmtime_module_exports).
Changes: