Skip to content

Commit 932ff69

Browse files
committed
Make 'async' part of the function type, not a hint
1 parent 1ba749e commit 932ff69

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

design/mvp/Binary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ valtype ::= i:<typeidx> => i
216216
resourcetype ::= 0x3f 0x7f f?:<funcidx>? => (resource (rep i32) (dtor f)?)
217217
| 0x3e 0x7f f:<funcidx> cb?:<funcidx>? => (resource (rep i32) (dtor async f (callback cb)?)) 🚝
218218
functype ::= 0x40 ps:<paramlist> rs:<resultlist> => (func ps rs)
219+
| 0x43 ps:<paramlist> rs:<resultlist> => (func async ps rs)
219220
paramlist ::= lt*:vec(<labelvaltype>) => (param lt)*
220221
resultlist ::= 0x00 t:<valtype> => (result t)
221222
| 0x01 0x00 =>

design/mvp/Explainer.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ valtype ::= <typeidx>
568568
| <defvaltype>
569569
resourcetype ::= (resource (rep i32) (dtor <funcidx>)?)
570570
| (resource (rep i32) (dtor async <funcidx> (callback <funcidx>)?)?) 🚝
571-
functype ::= (func (param "<label>" <valtype>)* (result <valtype>)?)
571+
functype ::= (func async? (param "<label>" <valtype>)* (result <valtype>)?)
572572
componenttype ::= (component <componentdecl>*)
573573
instancetype ::= (instance <instancedecl>*)
574574
componentdecl ::= <importdecl>
@@ -737,11 +737,8 @@ are useful for:
737737

738738
A `future<T>` asynchronously delivers exactly one `T` value from a source to a
739739
destination, unless the destination signals that it doesn't want the `T` value
740-
any more. Because [all imports can be called asynchronously][summary], futures
741-
are not necessary to express a traditional `async` function -- all functions
742-
are effectively `async`. Instead futures are useful in more advanced scenarios
743-
where a parameter or result value may not be ready at the same time as the
744-
other synchronous parameters or results.
740+
any more. When function types are marked [`async`][summary] directly,
741+
...TODO... `future<T>` is only needed to express *additional* concurrency.
745742

746743
The `T` element type of `stream` and `future` is an optional `valtype`. As with
747744
variant-case payloads and function results, when `T` is absent, the "value(s)"
@@ -793,7 +790,9 @@ shared-nothing functions, resources, components, and component instances:
793790

794791
The `func` type constructor describes a component-level function definition
795792
that takes a list of `valtype` parameters with [strongly-unique] names and
796-
optionally returns a `valtype`.
793+
optionally returns a `valtype`. The optional `async` effect type indicates that
794+
the function may block (calling a blocking built-in like `waitable-set.wait` or
795+
synchronously calling an imported `async` function).
797796

798797
The `resource` type constructor creates a fresh type for each instance of the
799798
containing component (with "freshness" and its interaction with general
@@ -2521,12 +2520,9 @@ importname ::= <exportname>
25212520
| <urlname>
25222521
| <hashname>
25232522
plainname ::= <label>
2524-
| '[async]' <label> 🔀
25252523
| '[constructor]' <label>
25262524
| '[method]' <label> '.' <label>
2527-
| '[async method]' <label> '.' <label> 🔀
25282525
| '[static]' <label> '.' <label>
2529-
| '[async static]' <label> '.' <label> 🔀
25302526
label ::= <fragment>
25312527
| <label> '-' <fragment>
25322528
fragment ::= <word>
@@ -2671,10 +2667,10 @@ annotations trigger additional type-validation rules (listed in
26712667
* Similarly, an import or export named `[method]R.foo` must be a function whose
26722668
first parameter must be `(param "self" (borrow $R))`.
26732669

2674-
When a function is annotated with `async`, bindings generators are expected to
2670+
When a function's type is `async`, bindings generators are expected to
26752671
emit whatever asynchronous language construct is appropriate (such as an
2676-
`async` function in JS, Python or Rust). Note the absence of
2677-
`[async constructor]`. See the [concurrency explainer] for more details.
2672+
`async` function in JS, Python or Rust). See the [concurrency explainer] for
2673+
more details.
26782674

26792675
The `label` production used inside `plainname` as well as the labels of
26802676
`record` and `variant` types are required to have [kebab case]. The reason for
@@ -2806,7 +2802,8 @@ Thus, the following names are strongly-unique:
28062802
* `foo`, `foo-bar`, `[constructor]foo`, `[method]foo.bar`, `[method]foo.baz`
28072803

28082804
but attempting to add *any* of the following names would be a validation error:
2809-
* `foo`, `foo-BAR`, `[constructor]foo-BAR`, `[method]foo.foo`, `[async]foo`, `[method]foo.BAR`
2805+
* `foo`, `foo-BAR`, `[constructor]foo-BAR`, `[method]foo.foo`,
2806+
`[static]foo.foo`, `[method]foo.BAR`
28102807

28112808
Note that additional validation rules involving types apply to names with
28122809
annotations. For example, the validation rules for `[constructor]foo` require

design/mvp/WIT.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,16 +1450,11 @@ named-type-list ::= ϵ
14501450
named-type ::= id ':' ty
14511451
```
14521452

1453-
The optional `async` hint in a WIT function type indicates that the callee
1454-
is expected to block and thus the caller should emit whatever asynchronous
1455-
language bindings are appropriate (e.g., in JS, Python, C# or Rust, an `async`
1456-
WIT function would emit an `async` JS/Python/C#/Rust function). Because `async`
1457-
is just a hint and not enforced by the runtime, it is technically possible for
1458-
a non-`async` callee to block. In that case, though, it is the *callee's* fault
1459-
for any resultant loss of concurrency, not the caller's. Thus, `async` is
1460-
primarily intended to document expectations in a way that can be taken
1461-
advantage of by bindings generators. (For more details, see the [concurrency
1462-
explainer](Concurrency.md).)
1453+
The optional `async` prefix in a WIT function type indicates that the callee is
1454+
allowed to block and thus the caller should emit the appropriate asynchronous
1455+
source-language bindings (e.g., in JS, Python, C# or Rust, an `async` WIT
1456+
function would emit an `async` JS/Python/C#/Rust function). (For more details,
1457+
see the [concurrency explainer](Concurrency.md).)
14631458

14641459

14651460
## Item: `use`
@@ -1689,8 +1684,8 @@ resource-method ::= func-item
16891684
| 'constructor' param-list ';'
16901685
```
16911686

1692-
The optional `async` hint on `static` functions has the same meaning as
1693-
in a non-`static` `func-item`.
1687+
The optional `async` on `static` functions has the same meaning as in a
1688+
non-`static` `func-item`.
16941689

16951690
The syntax for handle types is presented [below](#handles).
16961691

0 commit comments

Comments
 (0)