@@ -35,27 +35,28 @@ pub use crate::component::resources::ResourceType;
3535/// component with different resources produces different instance types but
3636/// the same underlying component type, so this field serves the purpose to
3737/// distinguish instance types from one another. This is runtime state created
38- /// during instantiation and threaded through here.
38+ /// during instantiation and threaded through here. Note that if this field
39+ /// is `None` then this represents an abstract uninstantiated component type.
3940#[ derive( Clone ) ]
4041struct Handle < T > {
4142 index : T ,
4243 types : Arc < ComponentTypes > ,
43- resources : Arc < TryPrimaryMap < ResourceIndex , ResourceType > > ,
44+ resources : Option < Arc < TryPrimaryMap < ResourceIndex , ResourceType > > > ,
4445}
4546
4647impl < T > Handle < T > {
4748 fn new ( index : T , ty : & InstanceType < ' _ > ) -> Handle < T > {
4849 Handle {
4950 index,
5051 types : ty. types . clone ( ) ,
51- resources : ty. resources . clone ( ) ,
52+ resources : ty. resources . cloned ( ) ,
5253 }
5354 }
5455
5556 fn instance ( & self ) -> InstanceType < ' _ > {
5657 InstanceType {
5758 types : & self . types ,
58- resources : & self . resources ,
59+ resources : self . resources . as_ref ( ) ,
5960 }
6061 }
6162
@@ -69,13 +70,17 @@ impl<T> Handle<T> {
6970 {
7071 ( self . index == other. index
7172 && Arc :: ptr_eq ( & self . types , & other. types )
72- && Arc :: ptr_eq ( & self . resources , & other. resources ) )
73+ && match ( & self . resources , & other. resources ) {
74+ ( Some ( a) , Some ( b) ) => Arc :: ptr_eq ( a, b) ,
75+ ( None , None ) => true ,
76+ _ => false ,
77+ } )
7378 || type_check (
7479 & TypeChecker {
7580 a_types : & self . types ,
7681 b_types : & other. types ,
77- a_resource : & self . resources ,
78- b_resource : & other. resources ,
82+ a_resource : self . resources . as_deref ( ) ,
83+ b_resource : other. resources . as_deref ( ) ,
7984 } ,
8085 self . index ,
8186 other. index ,
@@ -94,9 +99,9 @@ impl<T: fmt::Debug> fmt::Debug for Handle<T> {
9499/// Type checker between two `Handle`s
95100struct TypeChecker < ' a > {
96101 a_types : & ' a ComponentTypes ,
97- a_resource : & ' a TryPrimaryMap < ResourceIndex , ResourceType > ,
102+ a_resource : Option < & ' a TryPrimaryMap < ResourceIndex , ResourceType > > ,
98103 b_types : & ' a ComponentTypes ,
99- b_resource : & ' a TryPrimaryMap < ResourceIndex , ResourceType > ,
104+ b_resource : Option < & ' a TryPrimaryMap < ResourceIndex , ResourceType > > ,
100105}
101106
102107impl TypeChecker < ' _ > {
@@ -184,7 +189,7 @@ impl TypeChecker<'_> {
184189 (
185190 TypeResourceTable :: Concrete { ty : a, .. } ,
186191 TypeResourceTable :: Concrete { ty : b, .. } ,
187- ) => self . a_resource [ * a] == self . b_resource [ * b] ,
192+ ) => self . a_resource . unwrap ( ) [ * a] == self . b_resource . unwrap ( ) [ * b] ,
188193 ( TypeResourceTable :: Concrete { .. } , _) => false ,
189194
190195 // Abstract resource types are only the same if they have the same
@@ -615,9 +620,9 @@ impl FutureType {
615620 match ( my_payload, payload) {
616621 ( Some ( a) , Some ( b) ) => TypeChecker {
617622 a_types : & self . 0 . types ,
618- a_resource : & self . 0 . resources ,
623+ a_resource : self . 0 . resources . as_deref ( ) ,
619624 b_types : ty. types ,
620- b_resource : ty. resources ,
625+ b_resource : ty. resources . map ( |p| & * * p ) ,
621626 }
622627 . interface_types_equal ( * a, * b) ,
623628 ( None , None ) => true ,
@@ -672,9 +677,9 @@ impl StreamType {
672677 match ( my_payload, payload) {
673678 ( Some ( a) , Some ( b) ) => TypeChecker {
674679 a_types : & self . 0 . types ,
675- a_resource : & self . 0 . resources ,
680+ a_resource : self . 0 . resources . as_deref ( ) ,
676681 b_types : ty. types ,
677- b_resource : ty. resources ,
682+ b_resource : ty. resources . map ( |p| & * * p ) ,
678683 }
679684 . interface_types_equal ( * a, * b) ,
680685 ( None , None ) => true ,
@@ -1071,7 +1076,7 @@ impl Component {
10711076 pub fn instance_type ( & self ) -> InstanceType < ' _ > {
10721077 InstanceType {
10731078 types : & self . 0 . types ,
1074- resources : & self . 0 . resources ,
1079+ resources : self . 0 . resources . as_ref ( ) ,
10751080 }
10761081 }
10771082}
@@ -1152,7 +1157,7 @@ impl ComponentItem {
11521157 TypeResourceTable :: Concrete {
11531158 ty : resource_index, ..
11541159 } => {
1155- let ty = match ty. resources . get ( resource_index) {
1160+ let ty = match ty. resources . and_then ( |t| t . get ( resource_index) ) {
11561161 // This resource type was substituted by a linker for
11571162 // example so it's replaced here.
11581163 Some ( ty) => * ty,
0 commit comments