Skip to content
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

rework async function semantics #3033

Merged
merged 83 commits into from
Aug 15, 2019
Merged

rework async function semantics #3033

merged 83 commits into from
Aug 15, 2019

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Aug 8, 2019

This is #2377 as well as #1778.

checklist:

  • zig fmt support for the syntax
  • compile error (instead of crashing) for trying to get @Frame of generic function
  • compile error (instead of crashing) for trying to async call and passing @Frame of wrong function
  • implicit cast of normal function to async function should be allowed when it is inferred to be async
  • compile error for error: expected anyframe->T, found 'anyframe'
  • compile error for error: expected anyframe->T, found 'i32'
  • peer type resolution of *@Frame(func) and anyframe
  • peer type resolution of *@Frame(func) and anyframe->T when the return type matches
  • for loops need to spill the index. other payload captures probably also need to spill
  • const result = (await a) + (await b); this causes "Instruction does not dominate all uses" - need spill
  • @typeInfo for @Frame(func)
  • returning a value from within a suspend block
  • make resuming inside a suspend block, with nothing after it, a must-tail call.
  • make sure there are safety tests for all the new safety features (search the new PanicFnId enum values)
  • compile error for casting a function to a non-async function pointer, but then later it gets inferred to be an async function
  • compile error for copying a frame
  • compile error for resuming a const frame pointer
  • runtime safety enabling/disabling scope has to be coordinated across resume/await/calls/return
  • calling a generic function which is async
  • make sure await @asyncCall and await async are handled correctly.
  • allow @asyncCall with a real @Frame(func) (the point of this is result pointer)
  • when there are multiple calls to async functions in a function, reuse the same frame buffer, so that the
    needed bytes is equal to the largest callee's frame
  • if an async function is never called with async then a few optimizations can be made:
    • the return does not need to be atomic
    • it can be assumed that these are always available: the awaiter ptr, return ptr if applicable,
      error return trace ptr if applicable.
    • it can be assumed that it is never cancelled
  • fix the debug info for variables of async functions
  • re-order the frame fields for less memory usage for async calls of blocking functions
  • await should not be a suspend point when used on a @Frame(func) and func is blocking.

this prevents a segfault in stack trace printing to activate the
segfault handler.
 * add implicit cast from `*@frame(func)` to `anyframe->T` or `anyframe`.
 * add implicit cast from `anyframe->T` to `anyframe`.
 * `resume` works on `anyframe->T` and `anyframe` types.
fixes async function tests in optimized builds
@andrewrk andrewrk merged commit 8b97a1a into master Aug 15, 2019
@andrewrk andrewrk deleted the rewrite-coroutines branch August 15, 2019 21:01
@andrewrk
Copy link
Member Author

Follow-up items are in issue #3063.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant