@@ -7,9 +7,9 @@ use core::fmt;
7
7
use core:: ops:: Deref ;
8
8
use wasmtime_environ:: component:: {
9
9
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 ,
13
13
} ;
14
14
use wasmtime_environ:: PrimaryMap ;
15
15
@@ -145,9 +145,16 @@ impl TypeChecker<'_> {
145
145
( InterfaceType :: String , _) => false ,
146
146
( InterfaceType :: Char , InterfaceType :: Char ) => true ,
147
147
( 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 ,
151
158
}
152
159
}
153
160
@@ -247,6 +254,34 @@ impl TypeChecker<'_> {
247
254
let b = & self . b_types [ f2] ;
248
255
a. names == b. names
249
256
}
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
+ }
250
285
}
251
286
252
287
/// A `list` interface type
@@ -419,7 +454,7 @@ impl PartialEq for OptionType {
419
454
420
455
impl Eq for OptionType { }
421
456
422
- /// An `expected ` interface type
457
+ /// A `result ` interface type
423
458
#[ derive( Clone , Debug ) ]
424
459
pub struct ResultType ( Handle < TypeResultIndex > ) ;
425
460
@@ -479,6 +514,58 @@ impl PartialEq for Flags {
479
514
480
515
impl Eq for Flags { }
481
516
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
+
482
569
/// Represents a component model interface type
483
570
#[ derive( Clone , PartialEq , Eq , Debug ) ]
484
571
#[ allow( missing_docs) ]
@@ -506,6 +593,9 @@ pub enum Type {
506
593
Flags ( Flags ) ,
507
594
Own ( ResourceType ) ,
508
595
Borrow ( ResourceType ) ,
596
+ Future ( FutureType ) ,
597
+ Stream ( StreamType ) ,
598
+ ErrorContext ,
509
599
}
510
600
511
601
impl Type {
@@ -663,9 +753,9 @@ impl Type {
663
753
InterfaceType :: Flags ( index) => Type :: Flags ( Flags :: from ( * index, instance) ) ,
664
754
InterfaceType :: Own ( index) => Type :: Own ( instance. resource_type ( * index) ) ,
665
755
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 ,
669
759
}
670
760
}
671
761
@@ -694,6 +784,9 @@ impl Type {
694
784
Type :: Flags ( _) => "flags" ,
695
785
Type :: Own ( _) => "own" ,
696
786
Type :: Borrow ( _) => "borrow" ,
787
+ Type :: Future ( _) => "future" ,
788
+ Type :: Stream ( _) => "stream" ,
789
+ Type :: ErrorContext => "error-context" ,
697
790
}
698
791
}
699
792
}
0 commit comments