Skip to content

Commit f65f4ac

Browse files
authored
Merge pull request #145 from WebAssembly/loosen-export-rules
Loosen type-export validation rules
2 parents aab97d1 + 88513d1 commit f65f4ac

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

design/mvp/Binary.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ Notes:
260260
* Validation rejects `resourcetype` type definitions inside `componenttype` and
261261
`instancettype`. Thus, handle types inside a `componenttype` can only refer
262262
to resource types that are imported or exported.
263-
* Validation requires that all resource types transitively used in the type of an
264-
export are introduced by a preceding `exportdecl`.
265263
* The uniqueness validation rules for `externname` described below are also
266264
applied at the instance- and component-type level.
267265
* Validation of `externdesc` requires the various `typeidx` type constructors
@@ -335,7 +333,7 @@ Notes:
335333
* All exports (of all `sort`s) introduce a new index that aliases the exported
336334
definition and can be used by all subsequent definitions just like an alias.
337335
* Validation requires that all resource types transitively used in the type of an
338-
export are introduced by a preceding `exportdecl`.
336+
export are introduced by a preceding `importdecl` or `exportdecl`.
339337
* The "parses as a URL" condition is defined by executing the [basic URL
340338
parser] with `char(b)*` as *input*, no optional parameters and non-fatal
341339
validation errors (which coincides with definition of `URL` in JS and `rust-url`).

design/mvp/Explainer.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ declarators to be used by subsequent declarators in the type:
692692
)
693693
```
694694

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+
695699
With what's defined so far, we can define component types using a mix of type
696700
definitions:
697701
```wasm
@@ -991,28 +995,6 @@ replaced by `$R` when validating the instantiations of `$c1` and `$c2`. These
991995
type-checking rules for instantiating type imports mirror the *elimination*
992996
rule of [universal types] (∀T).
993997

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-
1016998
In summary: all type constructors are *structural* with the exception of
1017999
`resource`, which is *abstract* and *generative*. Type imports and exports that
10181000
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
13201302
`<id>` inside the `<sortidx>` is a reference to the preceding definition being
13211303
exported).
13221304

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+
13231328
Components split the single externally-visible name of imports and exports into
13241329
two sub-fields: a kebab-case `name` (as defined [above](#instance-definitions))
13251330
and a `URL` (defined by the [URL Standard], noting that, in this URL Standard,

0 commit comments

Comments
 (0)