@@ -926,27 +926,45 @@ bind a fresh abstract type. For example, in the following component:
926
926
all four types aliases in the outer component are unequal, reflecting the fact
927
927
that each instance of ` $C ` generates two fresh resource types.
928
928
929
- However, even if a single resource type definition is exported twice with ` sub `
930
- bounds, clients must * still * treat the two types as abstract and thus unequal;
931
- the fact that the underlying concrete type is the same is kept an encapsulated
932
- implementation detail. For example, in the following component:
929
+ If a single resource type definition is exported twice, clients must * still *
930
+ treat each export as abstract and thus unequal; the fact that the underlying
931
+ concrete type is the same is kept an encapsulated implementation detail. For
932
+ example, the following component:
933
933
``` wasm
934
934
(component
935
935
(type $r (resource (rep i32)))
936
- (export "r1" (type (sub $r) ))
937
- (export "r2" (type (sub $r) ))
936
+ (export "r1" (type $r ))
937
+ (export "r2" (type $r ))
938
938
)
939
939
```
940
- Any client of this component will treat ` r1 ` and ` r2 ` as totally distinct
941
- types since this component definition has the ` componenttype ` :
940
+ is assigned the following ` componenttype ` :
942
941
``` wasm
943
942
(component
944
943
(export "r1" (type (sub resource)))
945
944
(export "r2" (type (sub resource)))
946
945
)
947
946
```
948
- The assignment of this type to the above component mirrors the * introduction*
949
- rule of [ existential types] (∃T).
947
+ Thus, from an external perspective, ` r1 ` and ` r2 ` are completely distinct. The
948
+ assignment of this type to the above component mirrors the * introduction* rule
949
+ of [ existential types] (∃T).
950
+
951
+ If a component * wants* to publicly export a single private resource type twice
952
+ with the second export equal to the first, it can do so by having the second
953
+ export refer to the type index introduced by the first export. For example, the
954
+ following component:
955
+ ``` wasm
956
+ (component
957
+ (type $r (resource (rep i32)))
958
+ (export $r1 "r1" (type $r))
959
+ (export "r2" (type $r1))
960
+ ```
961
+ is assigned the following ` componenttype ` :
962
+ ``` wasm
963
+ (component
964
+ (export $r1 "r1" (type (sub resource)))
965
+ (export "r2" (type (eq $r1)))
966
+ )
967
+ ```
950
968
951
969
When supplying a resource type (imported * or* defined) to a type import via
952
970
` instantiate ` , type checking performs a substitution, replacing all uses of the
0 commit comments