@@ -930,10 +930,9 @@ bind a fresh abstract type. For example, in the following component:
930
930
all four types aliases in the outer component are unequal, reflecting the fact
931
931
that each instance of ` $C ` generates two fresh resource types.
932
932
933
- If a single resource type definition is exported twice, clients must * still*
934
- treat each export as abstract and thus unequal; the fact that the underlying
935
- concrete type is the same is kept an encapsulated implementation detail. For
936
- example, the following component:
933
+ If a single resource type definition is exported greater than once, the exports
934
+ after the first are equality-bound to the first export. For example, the
935
+ following component:
937
936
``` wasm
938
937
(component
939
938
(type $r (resource (rep i32)))
@@ -944,32 +943,34 @@ example, the following component:
944
943
is assigned the following ` componenttype ` :
945
944
``` wasm
946
945
(component
947
- (export "r1" (type (sub resource)))
948
- (export "r2" (type (sub resource )))
946
+ (export $r1 "r1" (type (sub resource)))
947
+ (export "r2" (type (eq $r1 )))
949
948
)
950
949
```
951
- Thus, from an external perspective, ` r1 ` and ` r2 ` are completely distinct. The
952
- assignment of this type to the above component mirrors the * introduction* rule
953
- of [ existential types] (∃T).
950
+ Thus, from an external perspective, ` r1 ` and ` r2 ` are two labels for the same
951
+ type.
954
952
955
- If a component * wants* to publicly export a single private resource type twice
956
- with the second export equal to the first, it can do so by having the second
957
- export refer to the type index introduced by the first export. For example, the
958
- following component:
953
+ If a component wants to hide this fact and force clients to assume ` r1 ` and
954
+ ` r2 ` are distinct types (thereby allowing the implementation to actually use
955
+ separate types in the future without breaking clients), an explicit type can be
956
+ ascribed to the export that replaces the ` eq ` bound with a less-precise ` sub `
957
+ bound.
959
958
``` wasm
960
959
(component
961
960
(type $r (resource (rep i32)))
962
- (export $r1 "r1" (type $r) )
963
- (export "r2" (type $r1 ))
961
+ (export "r1" (type $r)
962
+ (export "r2" (type $r) (type (sub resource) ))
964
963
)
965
964
```
966
- is assigned the following ` componenttype ` :
965
+ This component is assigned the following ` componenttype ` :
967
966
``` wasm
968
967
(component
969
- (export $r1 "r1" (type (sub resource)))
970
- (export "r2" (type (eq $r1 )))
968
+ (export "r1" (type (sub resource)))
969
+ (export "r2" (type (sub resource )))
971
970
)
972
971
```
972
+ The assignment of this type to the above component mirrors the * introduction*
973
+ rule of [ existential types] (∃T).
973
974
974
975
When supplying a resource type (imported * or* defined) to a type import via
975
976
` instantiate ` , type checking performs a substitution, replacing all uses of the
0 commit comments