@@ -7,9 +7,9 @@ use core::fmt;
77use core:: ops:: Deref ;
88use wasmtime_environ:: component:: {
99 ComponentTypes , InterfaceType , ResourceIndex , TypeComponentIndex , TypeComponentInstanceIndex ,
10- TypeDef , TypeEnumIndex , TypeFlagsIndex , TypeFuncIndex , TypeListIndex , TypeModuleIndex ,
11- TypeOptionIndex , TypeRecordIndex , TypeResourceTableIndex , TypeResultIndex , TypeTupleIndex ,
12- TypeVariantIndex ,
10+ TypeDef , TypeEnumIndex , TypeFlagsIndex , TypeFuncIndex , TypeFutureIndex , TypeFutureTableIndex ,
11+ TypeListIndex , TypeModuleIndex , TypeOptionIndex , TypeRecordIndex , TypeResourceTableIndex ,
12+ TypeResultIndex , TypeStreamIndex , TypeStreamTableIndex , TypeTupleIndex , TypeVariantIndex ,
1313} ;
1414use wasmtime_environ:: PrimaryMap ;
1515
@@ -145,9 +145,16 @@ impl TypeChecker<'_> {
145145 ( InterfaceType :: String , _) => false ,
146146 ( InterfaceType :: Char , InterfaceType :: Char ) => true ,
147147 ( InterfaceType :: Char , _) => false ,
148- ( InterfaceType :: Future ( _) , _)
149- | ( InterfaceType :: Stream ( _) , _)
150- | ( InterfaceType :: ErrorContext ( _) , _) => todo ! ( ) ,
148+ ( InterfaceType :: Future ( t1) , InterfaceType :: Future ( t2) ) => {
149+ self . future_table_types_equal ( t1, t2)
150+ }
151+ ( InterfaceType :: Future ( _) , _) => false ,
152+ ( InterfaceType :: Stream ( t1) , InterfaceType :: Stream ( t2) ) => {
153+ self . stream_table_types_equal ( t1, t2)
154+ }
155+ ( InterfaceType :: Stream ( _) , _) => false ,
156+ ( InterfaceType :: ErrorContext ( _) , InterfaceType :: ErrorContext ( _) ) => true ,
157+ ( InterfaceType :: ErrorContext ( _) , _) => false ,
151158 }
152159 }
153160
@@ -247,6 +254,34 @@ impl TypeChecker<'_> {
247254 let b = & self . b_types [ f2] ;
248255 a. names == b. names
249256 }
257+
258+ fn future_table_types_equal ( & self , t1 : TypeFutureTableIndex , t2 : TypeFutureTableIndex ) -> bool {
259+ self . futures_equal ( self . a_types [ t1] . ty , self . b_types [ t2] . ty )
260+ }
261+
262+ fn futures_equal ( & self , t1 : TypeFutureIndex , t2 : TypeFutureIndex ) -> bool {
263+ let a = & self . a_types [ t1] ;
264+ let b = & self . b_types [ t2] ;
265+ match ( a. payload , b. payload ) {
266+ ( Some ( t1) , Some ( t2) ) => self . interface_types_equal ( t1, t2) ,
267+ ( None , None ) => true ,
268+ _ => false ,
269+ }
270+ }
271+
272+ fn stream_table_types_equal ( & self , t1 : TypeStreamTableIndex , t2 : TypeStreamTableIndex ) -> bool {
273+ self . streams_equal ( self . a_types [ t1] . ty , self . b_types [ t2] . ty )
274+ }
275+
276+ fn streams_equal ( & self , t1 : TypeStreamIndex , t2 : TypeStreamIndex ) -> bool {
277+ let a = & self . a_types [ t1] ;
278+ let b = & self . b_types [ t2] ;
279+ match ( a. payload , b. payload ) {
280+ ( Some ( t1) , Some ( t2) ) => self . interface_types_equal ( t1, t2) ,
281+ ( None , None ) => true ,
282+ _ => false ,
283+ }
284+ }
250285}
251286
252287/// A `list` interface type
@@ -419,7 +454,7 @@ impl PartialEq for OptionType {
419454
420455impl Eq for OptionType { }
421456
422- /// An `expected ` interface type
457+ /// A `result ` interface type
423458#[ derive( Clone , Debug ) ]
424459pub struct ResultType ( Handle < TypeResultIndex > ) ;
425460
@@ -479,6 +514,58 @@ impl PartialEq for Flags {
479514
480515impl Eq for Flags { }
481516
517+ /// An `future` interface type
518+ #[ derive( Clone , Debug ) ]
519+ pub struct FutureType ( Handle < TypeFutureIndex > ) ;
520+
521+ impl FutureType {
522+ pub ( crate ) fn from ( index : TypeFutureIndex , ty : & InstanceType < ' _ > ) -> Self {
523+ FutureType ( Handle :: new ( index, ty) )
524+ }
525+
526+ /// Retrieve the type parameter for this `future`.
527+ pub fn ty ( & self ) -> Option < Type > {
528+ Some ( Type :: from (
529+ self . 0 . types [ self . 0 . index ] . payload . as_ref ( ) ?,
530+ & self . 0 . instance ( ) ,
531+ ) )
532+ }
533+ }
534+
535+ impl PartialEq for FutureType {
536+ fn eq ( & self , other : & Self ) -> bool {
537+ self . 0 . equivalent ( & other. 0 , TypeChecker :: futures_equal)
538+ }
539+ }
540+
541+ impl Eq for FutureType { }
542+
543+ /// An `stream` interface type
544+ #[ derive( Clone , Debug ) ]
545+ pub struct StreamType ( Handle < TypeStreamIndex > ) ;
546+
547+ impl StreamType {
548+ pub ( crate ) fn from ( index : TypeStreamIndex , ty : & InstanceType < ' _ > ) -> Self {
549+ StreamType ( Handle :: new ( index, ty) )
550+ }
551+
552+ /// Retrieve the type parameter for this `stream`.
553+ pub fn ty ( & self ) -> Option < Type > {
554+ Some ( Type :: from (
555+ self . 0 . types [ self . 0 . index ] . payload . as_ref ( ) ?,
556+ & self . 0 . instance ( ) ,
557+ ) )
558+ }
559+ }
560+
561+ impl PartialEq for StreamType {
562+ fn eq ( & self , other : & Self ) -> bool {
563+ self . 0 . equivalent ( & other. 0 , TypeChecker :: streams_equal)
564+ }
565+ }
566+
567+ impl Eq for StreamType { }
568+
482569/// Represents a component model interface type
483570#[ derive( Clone , PartialEq , Eq , Debug ) ]
484571#[ allow( missing_docs) ]
@@ -506,6 +593,9 @@ pub enum Type {
506593 Flags ( Flags ) ,
507594 Own ( ResourceType ) ,
508595 Borrow ( ResourceType ) ,
596+ Future ( FutureType ) ,
597+ Stream ( StreamType ) ,
598+ ErrorContext ,
509599}
510600
511601impl Type {
@@ -663,9 +753,9 @@ impl Type {
663753 InterfaceType :: Flags ( index) => Type :: Flags ( Flags :: from ( * index, instance) ) ,
664754 InterfaceType :: Own ( index) => Type :: Own ( instance. resource_type ( * index) ) ,
665755 InterfaceType :: Borrow ( index) => Type :: Borrow ( instance. resource_type ( * index) ) ,
666- InterfaceType :: Future ( _ )
667- | InterfaceType :: Stream ( _ )
668- | InterfaceType :: ErrorContext ( _) => todo ! ( ) ,
756+ InterfaceType :: Future ( index ) => Type :: Future ( instance . future_type ( * index ) ) ,
757+ InterfaceType :: Stream ( index ) => Type :: Stream ( instance . stream_type ( * index ) ) ,
758+ InterfaceType :: ErrorContext ( _) => Type :: ErrorContext ,
669759 }
670760 }
671761
@@ -694,6 +784,9 @@ impl Type {
694784 Type :: Flags ( _) => "flags" ,
695785 Type :: Own ( _) => "own" ,
696786 Type :: Borrow ( _) => "borrow" ,
787+ Type :: Future ( _) => "future" ,
788+ Type :: Stream ( _) => "stream" ,
789+ Type :: ErrorContext => "error-context" ,
697790 }
698791 }
699792}
0 commit comments