| 546f6dbc | 12-Mar-2026 |
Vasily Chekalkin <[email protected]> |
c-api: implement wasm_tagtype_t for exception tag types (#10252) (#12763)
* c-api: implement wasm_tagtype_t for exception tag types (#10252)
Implement the C embedder API for WebAssembly exception t
c-api: implement wasm_tagtype_t for exception tag types (#10252) (#12763)
* c-api: implement wasm_tagtype_t for exception tag types (#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 #10252), and wasm_externtype_kind / cast function correctness
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* c-api: move tag type declarations to wasmtime/tag.h
- 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]>
* Apply rustfmt and clang-format to tag type implementation
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* Fix Clippy warnings: remove unused imports and dead code
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]>
* Redesign tag type API with wasmtime_* prefix per reviewer feedback
- 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]>
---------
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
show more ...
|
| 1b59b579 | 09-Mar-2026 |
Yordis Prieto <[email protected]> |
Add support for map type (#12216)
* Add support for map type
Signed-off-by: Yordis Prieto <[email protected]>
* Add Map and MapEntry classes to support key/value pairs in component model
Th
Add support for map type (#12216)
* Add support for map type
Signed-off-by: Yordis Prieto <[email protected]>
* Add Map and MapEntry classes to support key/value pairs in component model
This commit introduces the Map and MapEntry classes, enabling the representation of map values in the component model. The Map class allows for the creation and iteration of key/value pairs, enhancing the functionality of the wasmtime component API. Additionally, the .gitignore file is updated to exclude build artifacts from the crates/c-api directory.
* Add wasm_component_model_map configuration support
* Format code
* Format C code
* Enhance component model to support HashMap<K, V> type
This commit introduces support for HashMap<K, V> in the component model, allowing maps to be represented as list<tuple<K, V>> in the canonical ABI. It includes implementations for the ComponentType, Lower, and Lift traits for HashMap, enabling type checking, lowering to flat representations, and lifting from memory. Additionally, the maximum depth for type generation in the fuzzing utility is updated to accommodate the new map type.
* Refactor component configuration to introduce map support
This commit removes the previous wasm features configuration and adds new functions for creating a map-configured engine. The `map_config` and `map_engine` functions are introduced to facilitate the use of the component model with maps in tests, ensuring that the engine is properly configured for map types in the component model.
* Add new WAST test for map types and remove map type definitions from existing tests
This commit introduces a new WAST test file specifically for testing various map types in the component model. Additionally, it removes the redundant map type definitions from the existing types.wast file to streamline the test suite.
* Update component fuzzing and dynamic tests to replace call_and_post_return with call
* Format code
* Refactor HashMap usage in typed.rs to use wasmtime_environ collections
* Fix HashMap initialization and insertion to handle potential errors in typed.rs
* Refactor HashMap handling in typed.rs to use lower_map_iter for improved iteration and memory management. Introduce new implementations for ComponentType, Lower, and Lift traits for std::collections::HashMap, enhancing support for map types in the component model.
* Fix map adapter trampoline compilation and alignment bugs
The translate_map function had two categories of bugs preventing map adapter trampolines from working:
1. Wasm stack discipline: local_set_new_tmp emits LocalSet which pops from the stack, but was called when the stack was empty (to "pre-allocate" locals). Fixed by computing values first, then calling local_set_new_tmp to consume them—matching translate_list's pattern. Also removed an erroneous LocalTee that left an orphan value on the stack. Affected: src_byte_len, dst_byte_len, cur_src_ptr, cur_dst_ptr.
2. Pointer advancement: after value translation, the pointer still points at the value start. The code only advanced by trailing padding instead of value_size + trailing_padding, causing every loop iteration to re-read the same memory.
Also fixes entry layout to use proper record alignment rules (entry align = max(key_align, value_align), value at aligned offset).
* Refactor map entry layout calculations to use canonical ABI
* Remove unnecessary clone of map pairs during lowering
Val::Map already holds Vec<(Val, Val)> which derefs to &[(Val, Val)], matching lower_map's signature directly. The intermediate Vec allocation and deep clone of every key/value pair was redundant.
* Deduplicate map lift logic between HashMap implementations
* Deduplicate list and map sequence translation scaffolding
* Fix cargo fmt formatting issues
* Deduplicate map typecheck logic
* Deduplicate map lowering with linear_lower_map_to_flat and linear_lower_map_to_memory helpers
* Clean up lift_try_map: use drop, move TryHashMap import to module scope
* Fix CI: arbtest overflow and no-std HashMap lift_map
- component_fuzz: use saturating_sub in generate_hashable_key to prevent underflow when fuel is 0 and Enum variant is chosen - typed: remove incorrect ? operators in lift_map for hashbrown::HashMap (with_capacity and insert don't return Result)
* Store map tuple layout in TypeMap
Compute map entry ABI and value offsets once during type building, and reuse that metadata in runtime map lift/lower paths instead of recalculating tuple layout at each call site.
* Refactor map ABI argument passing
Bundle map lift/lower layout and type metadata into a small MapAbi32 helper so map helper calls stay concise without changing behavior.
* Fix CI: enable component_model_map in fuzzing and handle map in arbitrary_val
The fuzzer's component_api oracle was generating map types but the engine didn't have the map feature enabled, and arbitrary_val had no arm for Type::Map. Enable component_model_map in the store helper (matching how component_model_async is forced on) and implement arbitrary value generation for map types.
---------
Signed-off-by: Yordis Prieto <[email protected]>
show more ...
|