@@ -692,6 +692,10 @@ declarators to be used by subsequent declarators in the type:
692
692
)
693
693
```
694
694
695
+ The ` type ` declarator is restricted by validation to disallow ` resource ` type
696
+ definitions. Thus, the only resource types possible in an ` instancetype ` or
697
+ ` componenttype ` are introduced by ` importdecl ` or ` exportdecl ` .
698
+
695
699
With what's defined so far, we can define component types using a mix of type
696
700
definitions:
697
701
``` wasm
@@ -991,28 +995,6 @@ replaced by `$R` when validating the instantiations of `$c1` and `$c2`. These
991
995
type-checking rules for instantiating type imports mirror the * elimination*
992
996
rule of [ universal types] (∀T).
993
997
994
- As a final constraint on both the ` export ` declarators of a ` componenttype ` and
995
- the ` export ` definitions of a ` component ` , all transitive uses of abstract
996
- types in the types of exported functions or values must refer to * exported*
997
- abstract types (concretely, via the type index introduced by the ` export ` ).
998
- This ensures that the client of a component is * always* able to define, in the
999
- client's own type index space, a type compatible with the component's exports.
1000
- For example, in the following component:
1001
- ``` wasm
1002
- (component
1003
- (type $R (resource (rep i32)))
1004
- (export $R' "R" (type (sub $R)))
1005
- (func $f1 (result (own $R)) (canon lift ...))
1006
- (func $f2 (result (own $R') (canon lift ...))
1007
- ;; (export "f" (func $f1)) -- invalid
1008
- (export "f" (func $f2))
1009
- )
1010
- ```
1011
- the commented-out ` export ` is invalid because its type transitively refers to
1012
- ` $R ` , which is not a type-export. This requirement is meant to address the
1013
- standard [ avoidance problem] that appears in module systems with abstract
1014
- types.
1015
-
1016
998
In summary: all type constructors are * structural* with the exception of
1017
999
` resource ` , which is * abstract* and * generative* . Type imports and exports that
1018
1000
have a subtype bound also introduce abstract types and follow the standard
@@ -1320,6 +1302,29 @@ In the case of exports, the `<id>?` right after the `export` is bound (the
1320
1302
` <id> ` inside the ` <sortidx> ` is a reference to the preceding definition being
1321
1303
exported).
1322
1304
1305
+ Validation of ` export ` requires that all transitive uses of resource types in
1306
+ the types of exported functions or values refer to resources that were either
1307
+ imported or exported (concretely, via the type index introduced by an ` import `
1308
+ or ` export ` ). For example, in the following component:
1309
+ ``` wasm
1310
+ (component
1311
+ (import "R1" (type $R1 (sub resource)))
1312
+ (type $R2 (resource (rep i32)))
1313
+ (export $R2' "R2" (type $R2))
1314
+ (func $f1 (result (own $R1)) (canon lift ...))
1315
+ (func $f2 (result (own $R2)) (canon lift ...))
1316
+ (func $f2' (result (own $R2')) (canon lift ...))
1317
+ (export "f1" (func $f1))
1318
+ ;; (export "f2" (func $f2)) -- invalid
1319
+ (export "f2" (func $f2'))
1320
+ )
1321
+ ```
1322
+ the commented-out ` export ` is invalid because its type transitively refers to
1323
+ ` $R2 ` , which is a private type definition. This requirement is meant to address
1324
+ the standard [ avoidance problem] that appears in module systems with abstract
1325
+ types. In particular, it ensures that a client of a component is able to
1326
+ externally define a type compatible with the exports of the component.
1327
+
1323
1328
Components split the single externally-visible name of imports and exports into
1324
1329
two sub-fields: a kebab-case ` name ` (as defined [ above] ( #instance-definitions ) )
1325
1330
and a ` URL ` (defined by the [ URL Standard] , noting that, in this URL Standard,
0 commit comments