@@ -1451,6 +1451,8 @@ pub enum ComponentDefinedType {
14511451 Variant ( VariantType ) ,
14521452 /// The type is a list.
14531453 List ( ComponentValType ) ,
1454+ /// The type is a map.
1455+ Map ( ComponentValType , ComponentValType ) ,
14541456 /// The type is a fixed size list.
14551457 FixedSizeList ( ComponentValType , u32 ) ,
14561458 /// The type is a tuple.
@@ -1494,6 +1496,11 @@ impl TypeData for ComponentDefinedType {
14941496 Self :: Variant ( v) => v. info ,
14951497 Self :: Tuple ( t) => t. info ,
14961498 Self :: List ( ty) | Self :: FixedSizeList ( ty, _) | Self :: Option ( ty) => ty. info ( types) ,
1499+ Self :: Map ( k, v) => {
1500+ let mut info = k. info ( types) ;
1501+ info. combine ( v. info ( types) , 0 ) . unwrap ( ) ;
1502+ info
1503+ }
14971504 Self :: Result { ok, err } => {
14981505 let default = TypeInfo :: new ( ) ;
14991506 let mut info = ok. map ( |ty| ty. type_info ( types) ) . unwrap_or ( default) ;
@@ -1514,7 +1521,7 @@ impl ComponentDefinedType {
15141521 . cases
15151522 . values ( )
15161523 . any ( |case| case. ty . map ( |ty| ty. contains_ptr ( types) ) . unwrap_or ( false ) ) ,
1517- Self :: List ( _) => true ,
1524+ Self :: List ( _) | Self :: Map ( _ , _ ) => true ,
15181525 Self :: Tuple ( t) => t. types . iter ( ) . any ( |ty| ty. contains_ptr ( types) ) ,
15191526 Self :: Flags ( _)
15201527 | Self :: Enum ( _)
@@ -1542,7 +1549,7 @@ impl ComponentDefinedType {
15421549 types,
15431550 lowered_types,
15441551 ) ,
1545- Self :: List ( _) => {
1552+ Self :: List ( _) | Self :: Map ( _ , _ ) => {
15461553 lowered_types. try_push ( ValType :: I32 ) && lowered_types. try_push ( ValType :: I32 )
15471554 }
15481555 Self :: FixedSizeList ( ty, length) => {
@@ -1622,6 +1629,7 @@ impl ComponentDefinedType {
16221629 ComponentDefinedType :: Flags ( _) => "flags" ,
16231630 ComponentDefinedType :: Option ( _) => "option" ,
16241631 ComponentDefinedType :: List ( _) => "list" ,
1632+ ComponentDefinedType :: Map ( _, _) => "map" ,
16251633 ComponentDefinedType :: FixedSizeList ( _, _) => "fixed size list" ,
16261634 ComponentDefinedType :: Result { .. } => "result" ,
16271635 ComponentDefinedType :: Own ( _) => "own" ,
@@ -1646,7 +1654,9 @@ impl ComponentDefinedType {
16461654
16471655 ComponentDefinedType :: Variant ( ty) => ty. lower_gc ( types, abi, options, offset, core) ,
16481656
1649- ComponentDefinedType :: List ( ty) | ComponentDefinedType :: FixedSizeList ( ty, _) => {
1657+ ComponentDefinedType :: List ( ty)
1658+ | ComponentDefinedType :: Map ( ty, _)
1659+ | ComponentDefinedType :: FixedSizeList ( ty, _) => {
16501660 let id = match core. as_concrete_ref ( ) {
16511661 Some ( id) => id,
16521662 None => bail ! (
@@ -2498,6 +2508,10 @@ impl TypeAlloc {
24982508 | ComponentDefinedType :: Option ( ty) => {
24992509 self . free_variables_valtype ( ty, set) ;
25002510 }
2511+ ComponentDefinedType :: Map ( k, v) => {
2512+ self . free_variables_valtype ( k, set) ;
2513+ self . free_variables_valtype ( v, set) ;
2514+ }
25012515 ComponentDefinedType :: Result { ok, err } => {
25022516 if let Some ( ok) = ok {
25032517 self . free_variables_valtype ( ok, set) ;
@@ -2640,6 +2654,9 @@ impl TypeAlloc {
26402654 ComponentDefinedType :: List ( ty)
26412655 | ComponentDefinedType :: FixedSizeList ( ty, _)
26422656 | ComponentDefinedType :: Option ( ty) => self . type_named_valtype ( ty, set) ,
2657+ ComponentDefinedType :: Map ( k, v) => {
2658+ self . type_named_valtype ( k, set) && self . type_named_valtype ( v, set)
2659+ }
26432660
26442661 // own/borrow themselves don't have to be named, but the resource
26452662 // they refer to must be named.
@@ -2832,6 +2849,10 @@ where
28322849 | ComponentDefinedType :: Option ( ty) => {
28332850 any_changed |= self . remap_valtype ( ty, map) ;
28342851 }
2852+ ComponentDefinedType :: Map ( k, v) => {
2853+ any_changed |= self . remap_valtype ( k, map) ;
2854+ any_changed |= self . remap_valtype ( v, map) ;
2855+ }
28352856 ComponentDefinedType :: Result { ok, err } => {
28362857 if let Some ( ok) = ok {
28372858 any_changed |= self . remap_valtype ( ok, map) ;
@@ -3724,6 +3745,13 @@ impl<'a> SubtypeCx<'a> {
37243745 ( Variant ( _) , b) => bail ! ( offset, "expected {}, found variant" , b. desc( ) ) ,
37253746 ( List ( a) , List ( b) ) | ( Option ( a) , Option ( b) ) => self . component_val_type ( a, b, offset) ,
37263747 ( List ( _) , b) => bail ! ( offset, "expected {}, found list" , b. desc( ) ) ,
3748+ ( Map ( ak, av) , Map ( bk, bv) ) => {
3749+ self . component_val_type ( ak, bk, offset)
3750+ . with_context ( || "type mismatch in map key" ) ?;
3751+ self . component_val_type ( av, bv, offset)
3752+ . with_context ( || "type mismatch in map value" )
3753+ }
3754+ ( Map ( _, _) , b) => bail ! ( offset, "expected {}, found map" , b. desc( ) ) ,
37273755 ( FixedSizeList ( a, asize) , FixedSizeList ( b, bsize) ) => {
37283756 if asize != bsize {
37293757 bail ! ( offset, "expected fixed size {bsize}, found size {asize}" )
0 commit comments