Skip to content

Commit e9f4ab3

Browse files
authored
Merge pull request #155 from WebAssembly/extend-exports
add optional export type ascription
2 parents 72d061c + be0c9fc commit e9f4ab3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

design/mvp/Binary.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ flags are set.
324324
(See [Import and Export Definitions](Explainer.md#import-and-export-definitions)
325325
in the explainer.)
326326
```
327-
import ::= en:<externname> ed:<externdesc> => (import en ed)
328-
export ::= en:<externname> si:<sortidx> => (export en si)
329-
externname ::= n:<name> u?:<URL>? => n u?
330-
URL ::= b*:vec(byte) => char(b)*, if char(b)* parses as a URL
327+
import ::= en:<externname> ed:<externdesc> => (import en ed)
328+
export ::= en:<externname> si:<sortidx> ed?:<externdesc>? => (export en si ed?)
329+
externname ::= n:<name> u?:<URL>? => n u?
330+
URL ::= b*:vec(byte) => char(b)*, if char(b)* parses as a URL
331331
```
332332
Notes:
333333
* All exports (of all `sort`s) introduce a new index that aliases the exported
@@ -338,7 +338,10 @@ Notes:
338338
parser] with `char(b)*` as *input*, no optional parameters and non-fatal
339339
validation errors (which coincides with definition of `URL` in JS and `rust-url`).
340340
* Validation requires any exported `sortidx` to have a valid `externdesc`
341-
(which disallows core sorts other than `core module`).
341+
(which disallows core sorts other than `core module`). When the optional
342+
`externdesc` immediate is present, validation requires it to be equal to
343+
the inferred `externdesc` of the `sortidx` (where equality judges a type and
344+
the `typeidx` of an export of that type (via `eq` or `sub`) equivalent).
342345
* The `name` fields of `externname` must be unique among imports and exports,
343346
respectively. The `URL` fields of `externname` (that are present) must
344347
independently unique among imports and exports, respectively.

design/mvp/Explainer.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ of core linear memory.
12991299
Lastly, imports and exports are defined as:
13001300
```
13011301
import ::= (import <externname> bind-id(<externdesc>))
1302-
export ::= (export <id>? <externname> <sortidx>)
1302+
export ::= (export <id>? <externname> <sortidx> <externdesc>?)
13031303
externname ::= <name> <URL>?
13041304
```
13051305
Both import and export definitions append a new element to the index space of
@@ -1313,7 +1313,11 @@ exported).
13131313
Validation of `export` requires that all transitive uses of resource types in
13141314
the types of exported functions or values refer to resources that were either
13151315
imported or exported (concretely, via the type index introduced by an `import`
1316-
or `export`). For example, in the following component:
1316+
or `export`). The optional `<externdesc>?` in `export` can be used to ascribe
1317+
an equivalent-but-different type to an exported definition, allowing a private
1318+
type definition to be replaced with a public (exported) type definition.
1319+
1320+
For example, in the following component:
13171321
```wasm
13181322
(component
13191323
(import "R1" (type $R1 (sub resource)))
@@ -1324,6 +1328,7 @@ or `export`). For example, in the following component:
13241328
(func $f2' (result (own $R2')) (canon lift ...))
13251329
(export "f1" (func $f1))
13261330
;; (export "f2" (func $f2)) -- invalid
1331+
(export "f2" (func $f2) (func (result (own $R2'))))
13271332
(export "f2" (func $f2'))
13281333
)
13291334
```

0 commit comments

Comments
 (0)