mirror of
https://codeberg.org/ziglang/zig
synced 2026-11-18 07:05:05 +00:00
improve async function semantics
* add safety panic for resuming a function which is returning, pending an await * remove IrInstructionResultPtr * add IrInstructionReturnBegin. This does the early return in async functions; does nothing in normal functions. * `await` gets a result location * `analyze_fn_async` will call `analyze_fn_body` if necessary. * async function frames have a result pointer field for themselves to access and one for the awaiter to supply before the atomic rmw. when returning, async functions copy the result to the awaiter result pointer, if it is non-null. * async function frames have a stack trace pointer which is supplied by the awaiter before the atomicrmw. Later in the frame is a stack trace struct and addresses, which is used for its own calls and awaits. * when awaiting an async function, if an early return occurred, the awaiter tail resumes the frame. * when an async function returns, early return does a suspend (in IrInstructionReturnBegin) before copying the error return trace data, result, and running the defers. After the last defer runs, the frame will no longer be accessed. * proper acquire/release atomic ordering attributes in async functions.
This commit is contained in:
parent
20f63e588e
commit
400500a3af
7 changed files with 491 additions and 323 deletions
441
src/codegen.cpp
441
src/codegen.cpp
251
src/ir.cpp
251
src/ir.cpp
Loading…
Add table
Add a link
Reference in a new issue