@@ -436,6 +436,11 @@ pub enum WasmHeapType {
436436 ConcreteFunc ( EngineOrModuleTypeIndex ) ,
437437 NoFunc ,
438438
439+ // Continuation types.
440+ Cont ,
441+ ConcreteCont ( EngineOrModuleTypeIndex ) ,
442+ NoCont ,
443+
439444 // Internal types.
440445 Any ,
441446 Eq ,
@@ -454,6 +459,7 @@ impl From<WasmHeapTopType> for WasmHeapType {
454459 WasmHeapTopType :: Extern => Self :: Extern ,
455460 WasmHeapTopType :: Any => Self :: Any ,
456461 WasmHeapTopType :: Func => Self :: Func ,
462+ WasmHeapTopType :: Cont => Self :: Cont ,
457463 }
458464 }
459465}
@@ -465,6 +471,7 @@ impl From<WasmHeapBottomType> for WasmHeapType {
465471 WasmHeapBottomType :: NoExtern => Self :: NoExtern ,
466472 WasmHeapBottomType :: None => Self :: None ,
467473 WasmHeapBottomType :: NoFunc => Self :: NoFunc ,
474+ WasmHeapBottomType :: NoCont => Self :: NoCont ,
468475 }
469476 }
470477}
@@ -477,6 +484,9 @@ impl fmt::Display for WasmHeapType {
477484 Self :: Func => write ! ( f, "func" ) ,
478485 Self :: ConcreteFunc ( i) => write ! ( f, "func {i}" ) ,
479486 Self :: NoFunc => write ! ( f, "nofunc" ) ,
487+ Self :: Cont => write ! ( f, "cont" ) ,
488+ Self :: ConcreteCont ( i) => write ! ( f, "cont {i}" ) ,
489+ Self :: NoCont => write ! ( f, "nocont" ) ,
480490 Self :: Any => write ! ( f, "any" ) ,
481491 Self :: Eq => write ! ( f, "eq" ) ,
482492 Self :: I31 => write ! ( f, "i31" ) ,
@@ -498,6 +508,7 @@ impl TypeTrace for WasmHeapType {
498508 Self :: ConcreteArray ( i) => func ( i) ,
499509 Self :: ConcreteFunc ( i) => func ( i) ,
500510 Self :: ConcreteStruct ( i) => func ( i) ,
511+ Self :: ConcreteCont ( i) => func ( i) ,
501512 _ => Ok ( ( ) ) ,
502513 }
503514 }
@@ -510,6 +521,7 @@ impl TypeTrace for WasmHeapType {
510521 Self :: ConcreteArray ( i) => func ( i) ,
511522 Self :: ConcreteFunc ( i) => func ( i) ,
512523 Self :: ConcreteStruct ( i) => func ( i) ,
524+ Self :: ConcreteCont ( i) => func ( i) ,
513525 _ => Ok ( ( ) ) ,
514526 }
515527 }
@@ -526,6 +538,7 @@ impl WasmHeapType {
526538
527539 // All `t <: (ref null func)` are not.
528540 WasmHeapTopType :: Func => false ,
541+ WasmHeapTopType :: Cont => false ,
529542 }
530543 }
531544
@@ -555,6 +568,10 @@ impl WasmHeapType {
555568 WasmHeapTopType :: Func
556569 }
557570
571+ WasmHeapType :: Cont | WasmHeapType :: ConcreteCont ( _) | WasmHeapType :: NoCont => {
572+ WasmHeapTopType :: Cont
573+ }
574+
558575 WasmHeapType :: Any
559576 | WasmHeapType :: Eq
560577 | WasmHeapType :: I31
@@ -582,6 +599,10 @@ impl WasmHeapType {
582599 WasmHeapBottomType :: NoFunc
583600 }
584601
602+ WasmHeapType :: Cont | WasmHeapType :: ConcreteCont ( _) | WasmHeapType :: NoCont => {
603+ WasmHeapBottomType :: NoCont
604+ }
605+
585606 WasmHeapType :: Any
586607 | WasmHeapType :: Eq
587608 | WasmHeapType :: I31
@@ -603,6 +624,8 @@ pub enum WasmHeapTopType {
603624 Any ,
604625 /// The common supertype of all function references.
605626 Func ,
627+ /// The common supertype of all continuation references.
628+ Cont ,
606629}
607630
608631/// A bottom heap type.
@@ -614,6 +637,8 @@ pub enum WasmHeapBottomType {
614637 None ,
615638 /// The common subtype of all function references.
616639 NoFunc ,
640+ /// The common subtype of all continuation references.
641+ NoCont ,
617642}
618643
619644/// WebAssembly function type -- equivalent of `wasmparser`'s FuncType.
@@ -761,6 +786,39 @@ impl WasmFuncType {
761786 }
762787}
763788
789+ /// WebAssembly continuation type -- equivalent of `wasmparser`'s ContType.
790+ #[ derive( Debug , Clone , Eq , PartialEq , Hash , Serialize , Deserialize ) ]
791+ pub struct WasmContType ( EngineOrModuleTypeIndex ) ;
792+
793+ impl fmt:: Display for WasmContType {
794+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
795+ write ! ( f, "(cont {})" , self . 0 )
796+ }
797+ }
798+
799+ impl WasmContType {
800+ /// Constructs a new continuation type.
801+ pub fn new ( idx : EngineOrModuleTypeIndex ) -> Self {
802+ WasmContType ( idx)
803+ }
804+ }
805+
806+ impl TypeTrace for WasmContType {
807+ fn trace < F , E > ( & self , func : & mut F ) -> Result < ( ) , E >
808+ where
809+ F : FnMut ( EngineOrModuleTypeIndex ) -> Result < ( ) , E > ,
810+ {
811+ func ( self . 0 )
812+ }
813+
814+ fn trace_mut < F , E > ( & mut self , func : & mut F ) -> Result < ( ) , E >
815+ where
816+ F : FnMut ( & mut EngineOrModuleTypeIndex ) -> Result < ( ) , E > ,
817+ {
818+ func ( & mut self . 0 )
819+ }
820+ }
821+
764822/// Represents storage types introduced in the GC spec for array and struct fields.
765823#[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash , Serialize , Deserialize ) ]
766824pub enum WasmStorageType {
@@ -935,6 +993,7 @@ pub enum WasmCompositeInnerType {
935993 Array ( WasmArrayType ) ,
936994 Func ( WasmFuncType ) ,
937995 Struct ( WasmStructType ) ,
996+ Cont ( WasmContType ) ,
938997}
939998
940999impl fmt:: Display for WasmCompositeInnerType {
@@ -943,6 +1002,7 @@ impl fmt::Display for WasmCompositeInnerType {
9431002 Self :: Array ( ty) => fmt:: Display :: fmt ( ty, f) ,
9441003 Self :: Func ( ty) => fmt:: Display :: fmt ( ty, f) ,
9451004 Self :: Struct ( ty) => fmt:: Display :: fmt ( ty, f) ,
1005+ Self :: Cont ( ty) => fmt:: Display :: fmt ( ty, f) ,
9461006 }
9471007 }
9481008}
@@ -1002,6 +1062,24 @@ impl WasmCompositeInnerType {
10021062 pub fn unwrap_struct ( & self ) -> & WasmStructType {
10031063 self . as_struct ( ) . unwrap ( )
10041064 }
1065+
1066+ #[ inline]
1067+ pub fn is_cont ( & self ) -> bool {
1068+ matches ! ( self , Self :: Cont ( _) )
1069+ }
1070+
1071+ #[ inline]
1072+ pub fn as_cont ( & self ) -> Option < & WasmContType > {
1073+ match self {
1074+ Self :: Cont ( f) => Some ( f) ,
1075+ _ => None ,
1076+ }
1077+ }
1078+
1079+ #[ inline]
1080+ pub fn unwrap_cont ( & self ) -> & WasmContType {
1081+ self . as_cont ( ) . unwrap ( )
1082+ }
10051083}
10061084
10071085impl TypeTrace for WasmCompositeType {
@@ -1013,6 +1091,7 @@ impl TypeTrace for WasmCompositeType {
10131091 WasmCompositeInnerType :: Array ( a) => a. trace ( func) ,
10141092 WasmCompositeInnerType :: Func ( f) => f. trace ( func) ,
10151093 WasmCompositeInnerType :: Struct ( a) => a. trace ( func) ,
1094+ WasmCompositeInnerType :: Cont ( c) => c. trace ( func) ,
10161095 }
10171096 }
10181097
@@ -1024,6 +1103,7 @@ impl TypeTrace for WasmCompositeType {
10241103 WasmCompositeInnerType :: Array ( a) => a. trace_mut ( func) ,
10251104 WasmCompositeInnerType :: Func ( f) => f. trace_mut ( func) ,
10261105 WasmCompositeInnerType :: Struct ( a) => a. trace_mut ( func) ,
1106+ WasmCompositeInnerType :: Cont ( c) => c. trace_mut ( func) ,
10271107 }
10281108 }
10291109}
@@ -1123,6 +1203,26 @@ impl WasmSubType {
11231203 assert ! ( !self . composite_type. shared) ;
11241204 self . composite_type . inner . unwrap_struct ( )
11251205 }
1206+
1207+ #[ inline]
1208+ pub fn is_cont ( & self ) -> bool {
1209+ self . composite_type . inner . is_cont ( ) && !self . composite_type . shared
1210+ }
1211+
1212+ #[ inline]
1213+ pub fn as_cont ( & self ) -> Option < & WasmContType > {
1214+ if self . composite_type . shared {
1215+ None
1216+ } else {
1217+ self . composite_type . inner . as_cont ( )
1218+ }
1219+ }
1220+
1221+ #[ inline]
1222+ pub fn unwrap_cont ( & self ) -> & WasmContType {
1223+ assert ! ( !self . composite_type. shared) ;
1224+ self . composite_type . inner . unwrap_cont ( )
1225+ }
11261226}
11271227
11281228impl TypeTrace for WasmSubType {
@@ -2018,8 +2118,8 @@ pub trait TypeConvert {
20182118 wasmparser:: CompositeInnerType :: Struct ( s) => {
20192119 WasmCompositeInnerType :: Struct ( self . convert_struct_type ( s) )
20202120 }
2021- wasmparser:: CompositeInnerType :: Cont ( _ ) => {
2022- unimplemented ! ( "continuation types" )
2121+ wasmparser:: CompositeInnerType :: Cont ( c ) => {
2122+ WasmCompositeInnerType :: Cont ( self . convert_cont_type ( c ) )
20232123 }
20242124 } ;
20252125 WasmCompositeType {
@@ -2028,6 +2128,15 @@ pub trait TypeConvert {
20282128 }
20292129 }
20302130
2131+ /// Converts a wasmparser continuation type to a wasmtime type
2132+ fn convert_cont_type ( & self , ty : & wasmparser:: ContType ) -> WasmContType {
2133+ if let WasmHeapType :: ConcreteFunc ( sigidx) = self . lookup_heap_type ( ty. 0 . unpack ( ) ) {
2134+ WasmContType :: new ( sigidx)
2135+ } else {
2136+ panic ! ( "Failed to extract signature index for continuation type." )
2137+ }
2138+ }
2139+
20312140 fn convert_struct_type ( & self , ty : & wasmparser:: StructType ) -> WasmStructType {
20322141 WasmStructType {
20332142 fields : ty
0 commit comments