Skip to content

Commit

Permalink
Add 'stream' and 'future' types
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Oct 10, 2024
1 parent 2323ed5 commit 6fc9489
Show file tree
Hide file tree
Showing 6 changed files with 1,918 additions and 164 deletions.
27 changes: 15 additions & 12 deletions design/mvp/Async.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,24 @@ 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:
* add `error` type that can be included when closing a stream/future
* `nonblocking` function type attribute: allow a function to declare in its
type that it will not transitively do anything blocking
* 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
16 changes: 15 additions & 1 deletion design/mvp/Binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ defvaltype ::= pvt:<primvaltype> => pvt
| 0x6a t?:<valtype>? u?:<valtype>? => (result t? (error u)?)
| 0x69 i:<typeidx> => (own i)
| 0x68 i:<typeidx> => (borrow i)
| 0x66 i:<typeidx> => (stream i)
| 0x65 i:<typeidx> => (future i)
labelvaltype ::= l:<label'> t:<valtype> => l t
case ::= l:<label'> t?:<valtype>? 0x00 => (case l t?)
label' ::= len:<u32> l:<label> => l (if len = |l|)
Expand Down Expand Up @@ -290,7 +292,17 @@ canon ::= 0x00 0x00 f:<core:funcidx> opts:<opts> ft:<typeidx> => (canon lift
| 0x0a => (canon task.wait (core func)) 🔀
| 0x0b => (canon task.poll (core func)) 🔀
| 0x0c => (canon task.yield (core func)) 🔀
| 0x0d => (canon subtask.drop (core func)) 🔀
| 0x0d => (canon waitable.drop (core func)) 🔀
| 0x0e t:<typeidx> => (canon stream.new t (core func)) 🔀
| 0x0f => (canon stream.read (core func)) 🔀
| 0x10 => (canon stream.write (core func)) 🔀
| 0x11 async?:<async?> => (canon stream.cancel-read async? (core func)) 🔀
| 0x12 async?:<async?> => (canon stream.cancel-write async? (core func)) 🔀
| 0x13 t:<typeidx> => (canon future.new t (core func)) 🔀
| 0x14 => (canon future.read (core func)) 🔀
| 0x15 => (canon future.write (core func)) 🔀
| 0x16 async?:<async?> => (canon future.cancel-read async? (core func)) 🔀
| 0x17 async?:<async?> => (canon future.cancel-write async? (core func)) 🔀
opts ::= opt*:vec(<canonopt>) => opt*
canonopt ::= 0x00 => string-encoding=utf8
| 0x01 => string-encoding=utf16
Expand All @@ -300,6 +312,8 @@ canonopt ::= 0x00 => string-encod
| 0x05 f:<core:funcidx> => (post-return f)
| 0x06 => async 🔀
| 0x07 f:<core:funcidx> => (callback f) 🔀
async? ::= 0x00 =>
| 0x01 => async
```
Notes:
* The second `0x00` byte in `canon` stands for the `func` sort and thus the
Expand Down
Loading

0 comments on commit 6fc9489

Please sign in to comment.