Skip to content

Conversation

@yordis
Copy link

@yordis yordis commented Oct 17, 2025

@alexcrichton
Copy link
Member

Thanks for this! Are you looking to get this merged ASAP? Or is this more of a proof-of-concept to support the development of the PR on the spec itself? If you're looking to get this merged sooner-rather-than-later, do you have plans to work on other parts of the stack such as wit-bindgen or Wasmtime?

@yordis
Copy link
Author

yordis commented Oct 20, 2025

@alexcrichton no rush at all in my end. I want to learn how to do the whole thing if possible if that is ok with you

@yordis yordis force-pushed the yordis/add-map-support branch 3 times, most recently from 8a0b8c4 to cd02439 Compare October 21, 2025 01:13
Signed-off-by: Yordis Prieto <[email protected]>
@yordis yordis force-pushed the yordis/add-map-support branch from cd02439 to 2487714 Compare October 21, 2025 02:11
@yordis
Copy link
Author

yordis commented Oct 21, 2025

Note for self: 0x63 why is that typed in so many places instead of having a enum somewhere?

TypeDefKind::Enum(_) => Self::empty(),
TypeDefKind::List(t) => Self::for_type(resolve, t) | Self::LIST,
TypeDefKind::Map(k, v) => {
Self::for_type(resolve, k) | Self::for_type(resolve, v) | Self::LIST
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Self::for_type(resolve, k) | Self::for_type(resolve, v) | Self::LIST
Self::for_type(resolve, k) | Self::for_type(resolve, v)

Should this be Self::MAP or just removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're up for it renaming LIST to something like NEEDS_MEMORY or something like that would be appropriate. Otherwise though this looks correct where LIST is mostly a proxy for "needs a memory canon option" which is always true for map

| TypeDefKind::FixedSizeList(ty, _)
| TypeDefKind::Option(ty) => find_in_type(types, *ty),
TypeDefKind::Map(k, v) => {
find_in_type(types, *k).or_else(|| find_in_type(types, *v))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused on this one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine yeah, and close enough to an approximation.

@yordis yordis marked this pull request as ready for review October 21, 2025 19:39
@yordis yordis requested a review from a team as a code owner October 21, 2025 19:39
@yordis yordis requested review from pchickey and removed request for a team October 21, 2025 19:39
@alexcrichton alexcrichton requested review from alexcrichton and removed request for pchickey October 21, 2025 21:51
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok looked over things, and thanks for this!

In terms of implementing this, adding a new type is a relatively major endeavor that takes awhile as there are a lot of integration points. Given that we'll want to make sure that this work is properly "gated" from external users to avoid, in theory, accidentally hitting unimplemented parts of the type system. The primary way this is done is via WasmFeatures in the wasmparser crate. What I'd recommend is adding a new cm_map feature similar to cm_fixed_size_lists. Effectively you'll want to add a bunch of tests/checks/etc in the same manner as fixed-size-lists, also an unstable feature at this time.

Additionally you'll want to add tests in tests/cli/component-model/*.wast for this new type as well. You should be able to find tests for fixed-size-lists around there and you can structure tests in a similar way.

Other than that though I think this would be reasonable to land. After landing here would come integration work into wasmtime/wit-bindgen/etc.


ComponentDefinedType::List(ty) | ComponentDefinedType::FixedSizeList(ty, _) => {
ComponentDefinedType::List(ty)
| ComponentDefinedType::Map(ty, _)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I think it would be best for Map to be routed to some sort of "not implemented" error and you can defer the work to someone fleshing out GC support in the future

TypeDefKind::Enum(_) => Self::empty(),
TypeDefKind::List(t) => Self::for_type(resolve, t) | Self::LIST,
TypeDefKind::Map(k, v) => {
Self::for_type(resolve, k) | Self::for_type(resolve, v) | Self::LIST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're up for it renaming LIST to something like NEEDS_MEMORY or something like that would be appropriate. Otherwise though this looks correct where LIST is mostly a proxy for "needs a memory canon option" which is always true for map

Comment on lines +163 to +171
pub struct wit_map {
pub interface: *const ::std::os::raw::c_char,
pub name: *const ::std::os::raw::c_char,
pub key_ty: wit_type_t,
pub value_ty: wit_type_t,
}
pub type wit_map_t = wit_map;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I'd recommend skipping wit-dylib entirely. I ended up skipping fixed-size-lists mostly for example and figure it's fine to come back later and add support as needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, if you're specifically interested in getting this working mind splitting it out to a separate follow-up PR?

| TypeDefKind::FixedSizeList(ty, _)
| TypeDefKind::Option(ty) => find_in_type(types, *ty),
TypeDefKind::Map(k, v) => {
find_in_type(types, *k).or_else(|| find_in_type(types, *v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine yeah, and close enough to an approximation.

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