-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add first batch of async support #363
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might provide useful context to mention how this proposal relates to the stack-switching proposal; that is, that it doesn't depend on stack-switching, but stack-switching could be used in conjunction with it.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want to commit to cancellation for Preview 3? I'm concerned it adds a lot of scope, delaying the release. As usual, I'm always looking for opportunities to reduce scope so we can deliver the valuable pieces we've already got a firm handle on ASAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think cancellation ends up being an integral part of the async "protocol" (which, if you ignore, ends up being a breaking change to add later) which makes me think we need it in the initial shippable unit. Also, my impression is that, while it takes some careful state-transition thought, it won't actually be that bad or that much impl work (in the runtime, at least -- language bindings will have more fun).
Co-authored-by: Dan Gohman <dev@sunfishcode.online>
Co-authored-by: Joel Dice <joel.dice@fermyon.com>
Thanks for all the feedback! I'll merge for now, but of course what's proposed here is expected to change as the implementation progresses and also the remaining async functionality (listed in Async.md#TODO) is filled out. I'll start working on the next PR with the next batch of functionality (I'm thinking |
This PR adds a first batch of async support, viz., the
async
andcallback
options tocanon lift
/lower
and the supporting canonical built-ins. The PR does not addfuture
orstream
, those will be in the next PR (as well as a number of other key parts of the async story; see Async.md#TODO).There are two commits in the PR, a tiny one that removes something and a big one that adds all the async stuff.
The first commit removes a special case where reentrance was allowed in a very hand-wavy manner for parent-->child-->parent cases. Working through async and thinking about what reentrance even means in an async context, I realized that the hand-wavy approach was wrong and the better way to enable this use case is by adding a new
reentrant
(name TBD) attribute to function types that basically opts into reentrance at the type-level, allowing parent-->child-->parent reentrance as a special case. I'm pretty sure this won't break any code because it requires doing "donut wrapping" which isn't supported by the producer toolchains yet. Addingreentrant
is in the Async.md#TODO list.The second commit is somewhat big and I'd recommend reading it by:
Big thanks to @dicej who has been collaborating on this design and has built a working prototype that we'll now iterate on to precisely match this PR. (Apologies in advance for slow replies over the next week due to in-person wasm CG meeting.)