Skip to content

Commit d1f3b92

Browse files
committed
Add 'optional' imports/exports
1 parent b11fa46 commit d1f3b92

4 files changed

Lines changed: 52 additions & 5 deletions

File tree

design/mvp/Binary.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ instancedecl ::= 0x00 t:<core:type> => t
232232
| 0x04 ed:<exportdecl> => ed
233233
importdecl ::= na:<nameattributes> et:<externtype> => (import na et)
234234
exportdecl ::= na:<nameattributes> et:<externtype> => (export na et)
235-
externtype ::= 0x00 0x11 i:<core:typeidx> => (core module (type i))
235+
externtype ::= 0x10 t:<someexterntype> => (optional t)
236+
| t:<someexterntype> => t
237+
someexterntype ::= 0x00 0x11 i:<core:typeidx> => (core module (type i))
236238
| 0x01 i:<typeidx> => (func (type i))
237239
| 0x02 b:<valuebound> => (value b) 🪙
238240
| 0x03 b:<typebound> => (type b)
@@ -541,6 +543,7 @@ named once.
541543
subset of `canonopt`s.
542544
* Add optional `shared` immediate to all canonical definitions (explicitly or
543545
via `<canonopt>`) when shared-everything-threads (🧵②) is added.
546+
* Improve `externtype` opcodes for `optional`
544547

545548

546549
[`core:byte`]: https://webassembly.github.io/spec/core/binary/values.html#binary-byte

design/mvp/CanonicalABI.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ specified here.
6868
* [`canon thread.yield-then-resume`](#-canon-threadyield-then-resume) 🧵
6969
* [`canon thread.suspend-then-promote`](#-canon-threadsuspend-then-promote) 🧵
7070
* [`canon thread.yield-then-promote`](#-canon-threadyield-then-promote) 🧵
71+
* [`canon optional.test`](#-canon-optionaltest)
7172
* [`canon error-context.new`](#-canon-error-contextnew) 📝
7273
* [`canon error-context.debug-message`](#-canon-error-contextdebug-message) 📝
7374
* [`canon error-context.drop`](#-canon-error-contextdrop) 📝
@@ -5097,6 +5098,20 @@ prepared to propagate cancellation, they can omit `cancellable` so that
50975098
cancellation is instead delivered at a later `cancellable` call.
50985099

50995100

5101+
### `canon optional.test`
5102+
5103+
For a canonical definition:
5104+
```wat
5105+
(canon optional.test (instance $instanceidx) (core global $present))
5106+
```
5107+
validation specifies:
5108+
* `$instanceidx` must refer to an instance in the instance index space with
5109+
type `optional`
5110+
* `$optional.test` is given type `(global i32)`
5111+
5112+
TODO: describe
5113+
5114+
51005115
### 📝 `canon error-context.new`
51015116

51025117
For a canonical definition:

design/mvp/Explainer.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ more user-focused explanation, take a look at the
2121
* [Specialized value types](#specialized-value-types)
2222
* [Definition types](#definition-types)
2323
* [Declarators](#declarators)
24+
* [Optional types](#optional-types)
2425
* [Type checking](#type-checking)
2526
* [Canonical definitions](#canonical-definitions)
2627
* [Canonical ABI](#canonical-abi)
2728
* [Canonical built-ins](#canonical-built-ins)
2829
* [Resource built-ins](#resource-built-ins)
2930
* [Concurrency built-ins](#-concurrency-built-ins)
31+
* [Feature-test built-in](#-feature-test-built-in)
3032
* [Error Context built-ins](#-error-context-built-ins)
3133
* [Value definitions](#-value-definitions)
3234
* [Start definitions](#-start-definitions)
@@ -69,6 +71,7 @@ subsequent WASI Developer Preview minor releases:
6971
* 🐘: [memory64]
7072
* 🗺️: the `map` type
7173
* 🏷️: `implements` annotations for plain-named interface imports/exports
74+
* ❓: `optional` imports and exports
7275

7376

7477
## Grammar
@@ -618,7 +621,9 @@ instancedecl ::= core-prefix(<core:type>)
618621
| <exportdecl>
619622
importdecl ::= (import <externnamelit> <attribute>* bind-id(<externtype>))
620623
exportdecl ::= (export <externnamelit> <attribute>* bind-id(<externtype>))
621-
externtype ::= (<sort> (type <u32>) )
624+
externtype ::= (optional <someexterntype>)
625+
| <someexterntype>
626+
someexterntype ::= (<sort> (type <u32>) )
622627
| core-prefix(<core:moduletype>)
623628
| <functype>
624629
| <componenttype>
@@ -1009,6 +1014,10 @@ definitions:
10091014
Note that the inline use of `$G` and `$U` are syntactic sugar for `outer`
10101015
aliases.
10111016

1017+
#### Optional types
1018+
1019+
TODO
1020+
10121021
#### Type Checking
10131022

10141023
Like core modules, components have an up-front validation phase in which the
@@ -1091,6 +1100,8 @@ and `$C1` is a subtype of `$C2`:
10911100
checking and so any `external-id`, `implements` or `versionsuffix` attribute can
10921101
be added to any of the `func`s above without changing the result.
10931102

1103+
TODO: also mention `optional`
1104+
10941105
When we next consider type imports and exports, there are two distinct
10951106
subcases of `typebound` to consider: `eq` and `sub`.
10961107

@@ -1545,6 +1556,7 @@ canon ::= ...
15451556
| (canon thread.yield-then-resume cancellable? (core func <id>?)) 🧵
15461557
| (canon thread.suspend-then-promote cancellable? (core func <id>?)) 🧵
15471558
| (canon thread.yield-then-promote cancellable? (core func <id>?)) 🧵
1559+
| (canon optional.test (instance <instanceidx>) (core global <id>?)) ❓
15481560
| (canon error-context.new <canonopt>* (core func <id>?)) 📝
15491561
| (canon error-context.debug-message <canonopt>* (core func <id>?)) 📝
15501562
| (canon error-context.drop (core func <id>?)) 📝
@@ -2331,6 +2343,11 @@ For details, see [`canon_thread_available_parallelism`] in the Canonical ABI
23312343
explainer.
23322344

23332345

2346+
##### ❓ Feature-test built-in
2347+
2348+
TODO: describe `canon optional.test`
2349+
2350+
23342351
##### 📝 Error Context built-ins
23352352

23362353
###### 📝 `error-context.new`

design/mvp/WIT.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ world union-my-world {
308308
}
309309
```
310310

311+
TODO: add `optional` to examples
312+
311313
### De-duplication of interfaces
312314

313315
If two worlds share an imported or exported [interface name], then the union of
@@ -339,6 +341,8 @@ world union-my-world-b {
339341
}
340342
```
341343

344+
TODO: mention merging of `optional` and non-`optional`
345+
342346
### Name Conflicts and `with`
343347

344348
When two or more included Worlds have the same name for an import or export
@@ -438,6 +442,7 @@ world invalid-union-world {
438442

439443
### A Note on Subtyping
440444

445+
TODO: update this
441446
In the future, when `optional` export is supported, the world author may explicitly mark exports as optional to make a component targeting an included World a subtype of the union World.
442447

443448
For now, we are not following the subtyping rules for the `include` statement. That is, the `include` statement does not imply any subtyping relationship between the included worlds and the union world.
@@ -563,6 +568,9 @@ interface my-interface {
563568
}
564569
```
565570

571+
TODO: mention `use` from `optional` import/export on world
572+
TODO: we'll need `optional` dependencies... (and if we have that, maybe can have optional on interface items...)
573+
566574
#### Top-level `use`
567575

568576
If a package being referred to has a version number, then using the above syntax
@@ -1448,9 +1456,11 @@ import-item ::= external-id? 'import' id ':' extern-type
14481456
14491457
external-id ::= '@external-id' '(' string-literal ')' 🏷️
14501458
1451-
extern-type ::= func-type ';'
1452-
| 'interface' '{' interface-items* '}'
1453-
| use-path ';' 🏷️
1459+
extern-type ::= 'optional' some-extern-type
1460+
| some-extern-type
1461+
some-extern-type ::= func-type ';'
1462+
| 'interface' '{' interface-items* '}'
1463+
| use-path ';' 🏷️
14541464
```
14551465

14561466
🏷️ While `id`s are restricted to kebab-case (to enable idiomatic bindings for
@@ -1508,6 +1518,8 @@ world my-world {
15081518
}
15091519
```
15101520

1521+
TODO: note `optional` and what it means
1522+
15111523
[`componenttype`]: Explainer.md#type-definitions
15121524

15131525
## Item: `include`

0 commit comments

Comments
 (0)