Commit Graph

1209 Commits

Author SHA1 Message Date
Andrew Kelley 1afbb53661 fix awaiting when result type is a struct 2019-08-06 19:07:25 -04:00
Andrew Kelley 966c9ea63c error return trace across suspend points 2019-08-06 18:47:09 -04:00
Andrew Kelley 17199b0879 passing the error return trace async function test 2019-08-06 18:29:56 -04:00
Andrew Kelley 400500a3af 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.
2019-08-06 16:53:22 -04:00
Andrew Kelley 20f63e588e async functions have error return traces where appropriate
however the traces are not merged on `await` or async function calls
yet.

When an async function has an error set or error union as its return
type, it has a `StackTrace` before the args in the frame, so that it is
accessible from `anyframe->T` awaiters. However when it does not have an
errorable return type, but it does call or await an errorable, it has a
stack trace just before the locals. This way when doing an `@asyncCall`
on an async function pointer, it can populate the args (which are after
the `StackTrace`) because it knows the offset of the args based only on
the return type.

This sort of matches normal functions, where a stack trace pointer could
be supplied by a parameter, or it could be supplied by the stack of the
function, depending on whether the function itself is errorable.
2019-08-05 03:10:14 -04:00
Andrew Kelley a7763c06f9 delete IrInstructionMarkErrRetTracePtr
this IR instruction is no longer needed
2019-08-05 00:44:39 -04:00
Andrew Kelley 0d8c9fcb18 support async functions with inferred error sets 2019-08-05 00:41:49 -04:00
Andrew Kelley f27e5d439c refactor logic for determining if there is a frame pointer 2019-08-04 20:44:52 -04:00
Andrew Kelley fbf21efd24 simpler, less memory intensive suspend/resume implementation 2019-08-04 18:58:14 -04:00
Andrew Kelley 042914de75 move state from ZigFn to CodeGen to save memory 2019-08-04 18:26:37 -04:00
Andrew Kelley fa30ebfbe5 suspension points inside branching control flow 2019-08-04 18:24:10 -04:00
Andrew Kelley 87710a1cc2 implement @asyncCall which supports async function pointers 2019-08-03 16:17:42 -04:00
Andrew Kelley e444e737b7 add runtime safety for resuming an awaiting function 2019-08-03 02:11:52 -04:00
Andrew Kelley 0920bb0872 implement async functions returning structs 2019-08-02 19:27:27 -04:00
Andrew Kelley b3b6a98451 Merge remote-tracking branch 'origin/master' into rewrite-coroutines 2019-08-02 16:31:43 -04:00
Andrew Kelley f07f09a373 Merge branch 'master' into rewrite-coroutines 2019-08-02 16:13:36 -04:00
Andrew Kelley 90e64bc620 fix cmpxchg with discarded result 2019-08-02 14:47:26 -04:00
Andrew Kelley 056c4e2c98 implement async await and return 2019-08-02 01:06:00 -04:00
Andrew Kelley 1dd0c3d49f fix calling an inferred async function 2019-08-01 16:41:30 -04:00
Andrew Kelley e7ae4e4645 reimplement async with function splitting instead of switch 2019-08-01 16:08:52 -04:00
Andrew Kelley dbdc4d62d0 improve support for anyframe and anyframe->T
* 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.
2019-07-29 19:32:49 -04:00
Andrew Kelley ee64a22045 add the anyframe and anyframe->T types 2019-07-26 19:52:35 -04:00
Andrew Kelley 018a89c7a1 async functions return void, no more GetSize resume block 2019-07-26 17:07:19 -04:00
Andrew Kelley 7b3686861f @frameSize works via PrefixData 2019-07-25 22:24:01 -04:00
Andrew Kelley 538c0cd225 implement @frameSize 2019-07-25 15:05:55 -04:00
Andrew Kelley 70bced5dcf implement @frame and @Frame 2019-07-25 01:47:56 -04:00
Andrew Kelley ead2d32be8 calling an inferred async function 2019-07-25 00:03:06 -04:00
Michael Dusan 8e4f3a6f15 align src for IrInstructionArrayToVector
closes #2942
2019-07-24 15:04:32 -04:00
Andrew Kelley e220812f2f implement local variables in async functions 2019-07-24 02:59:51 -04:00
Andrew Kelley 7e9760de10 inferring async from async calls 2019-07-23 18:54:45 -04:00
Andrew Kelley fcadeb50c0 fix multiple coroutines existing clobbering each other 2019-07-22 14:36:14 -04:00
Andrew Kelley bc31c1280e disable segfault handler when panicking
this prevents a segfault in stack trace printing to activate the
segfault handler.
2019-07-22 12:41:59 -04:00
Andrew Kelley 5b69a9cd83 disable segfault handler when panicking
this prevents a segfault in stack trace printing to activate the
segfault handler.
2019-07-22 12:15:16 -04:00
Andrew Kelley 32d0ac1355 fix wrong calling convention on async resume 2019-07-22 00:07:48 -04:00
Andrew Kelley 59bf9ca58c implement async function parameters 2019-07-21 23:27:47 -04:00
Andrew Kelley 11bd50f2b2 implement coroutine resume 2019-07-21 20:54:08 -04:00
Andrew Kelley 78e03c466c simple async function passing test 2019-07-21 19:56:37 -04:00
Andrew Kelley 56c08eb302 returning from async fn adds bad resume safety 2019-07-21 17:17:44 -04:00
Andrew Kelley 6053ca4f69 fix not jumping to entry 2019-07-21 17:10:16 -04:00
Andrew Kelley 72e983670e simple async function call working 2019-07-21 16:21:16 -04:00
Andrew Kelley 54e716afdc remove coroutines implementation and promise type 2019-07-19 18:18:44 -04:00
Andrew Kelley c0b4121ff2 libc headers before C language headers, and disable libunwind on arm32 2019-07-16 21:38:18 -04:00
Andrew Kelley d994379173 update bundled musl source to 1.1.23 2019-07-16 19:54:14 -04:00
Andrew Kelley f70ce707e2 update musl headers to musl v1.1.23 2019-07-16 19:02:51 -04:00
Andrew Kelley 776423bbf7 fix result location alignment in ir_render_call 2019-07-15 23:44:44 -04:00
Andrew Kelley 7b8ba871a9 mingw libc: solve the segfault having to do with destructors
* fixed --verbose-cc printing an extra "zig" before the rest of
   the command line
 * windows-gnu targets use libfoo.a, foo.o extensions to match mingw
   conventions.
2019-07-12 14:44:34 -04:00
Andrew Kelley d9c4c96bf2 add -Wno-pragma-pack when targeting windows-gnu
windows.h has files such as pshpack1.h which do #pragma packing,
triggering a clang warning. So for this target, this warning is
disabled.

this commit also improves the error message printed when no libc can be
used, printing the "zig triple" rather than the "llvm triple".
2019-07-11 23:48:13 -04:00
Andrew Kelley ea90a3a9a1 mingw: building and linking mingw32.lib 2019-07-10 14:13:00 -04:00
Andrew Kelley 56d8185650 expose glibc version in builtin 2019-07-07 17:56:43 -04:00
Andrew Kelley 7ccf7807b3 ability to target any glibc version 2019-07-07 17:56:08 -04:00