Skip to content

Commit

Permalink
Add 'stream' type
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Oct 7, 2024
1 parent 43aa23f commit 2d6a20f
Show file tree
Hide file tree
Showing 5 changed files with 1,265 additions and 112 deletions.
28 changes: 16 additions & 12 deletions design/mvp/Async.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,25 @@ For now, this remains a [TODO](#todo) and validation will reject `async`-lifted

## TODO

Native async support is being proposed in progressive chunks. The following
features will be added in future chunks to complete "async" in Preview 3:
* `future`/`stream`/`error`: add for use in function types for finer-grained
concurrency
* `subtask.cancel`: allow a supertask to signal to a subtask that its result is
no longer wanted and to please wrap it up promptly
* allow "tail-calling" a subtask so that the current wasm instance can be torn
down eagerly
* `task.index`+`task.wake`: allow tasks in the same instance to wait on and
wake each other (async condvar-style)
Native async support is being proposed incrementally. The following features
will be added in future chunks roughly in the order list to complete the full
"async" story:
* `nonblocking` function type attribute: allow a function to declare in its
type that it will not transitively do anything blocking
* add `future` type
* add `error` type that can be included when closing a stream/future
* define what `async` means for `start` functions (top-level await + background
tasks), along with cross-task coordination built-ins
* `subtask.cancel`: allow a supertask to signal to a subtask that its result is
no longer wanted and to please wrap it up promptly
* zero-copy forwarding/splicing and built-in way to "tail-call" a subtask so
that the current wasm instance can be torn down eagerly while preserving
structured concurrency
* some way to say "no more elements are coming for a while"
* `recursive` function type attribute: allow a function to be reentered
recursively (instead of trapping)
* enable `async` `start` functions
recursively (instead of trapping) and link inner and outer activations
* allow pipelining multiple `stream.read`/`write` calls
* allow chaining multiple async calls together ("promise pipelining")
* integrate with `shared`: define how to lift and lower functions `async` *and*
`shared`

Expand Down
1 change: 1 addition & 0 deletions design/mvp/CanonicalABI.md
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ where `$callee` has type `$ft`, validation specifies:
* a `memory` is present if required by lifting and is a subtype of `(memory 1)`
* a `realloc` is present if required by lifting and has type `(func (param i32 i32 i32 i32) (result i32))`
* there is no `post-return` in `$opts`
* if `contains_async($ft)`, then `$opts.async` must be set

When instantiating component instance `$inst`:
* Define `$f` to be the partially-bound closure: `canon_lower($opts, $ft, $callee)`
Expand Down
10 changes: 6 additions & 4 deletions design/mvp/Explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,12 @@ validated to have parameters matching the callee's return type and empty
results.

🔀 The `async` option specifies that the component wants to make (for imports)
or support (for exports) multiple concurrent (asynchronous) calls. This option
can be applied to any component-level function type and changes the derived
Canonical ABI significantly. See the [async explainer](Async.md) for more
details.
or support (for exports) multiple concurrent (asynchronous) calls. This
option can be applied to any component-level function type and changes the
derived Canonical ABI significantly. See the [async explainer](Async.md) for
more details. When a function signature contains a `future` or `stream`,
validation requires the `async` option to be set (since a synchronous call to
a function using these types is likely to deadlock).

🔀 The `(callback ...)` option may only be present in `canon lift` when the
`async` option has also been set and specifies a core function that is
Expand Down
Loading

0 comments on commit 2d6a20f

Please sign in to comment.