Commit Graph

513 Commits

Author SHA1 Message Date
Nate Chandler
c73e3c1e62 [NFC] Destructure AsyncFunctionPointer in getAsyncFunctionAndSize.
In irgen::getAsyncFunctionAndSize, an AsyncFunctionPointer is
destructured into one or both of (1) the underlying function pointer and
(2) the async context size.

Previously, the underlying function pointer was obtained via calling
FunctionPointer::getPointer, which function did the work of casting the
function pointer to an AsyncFunctionPointer, loading the relative
function address from it, and using that relative address to obtain the
function pointer.  The size, then, if it was also obtained, was obtained
by again casting the function pointer to an AsyncFunctionPointer and
loading a field from it.

To avoid this repetition, here, the relevant portion of the body of
FunctionPointer::getPointer is inlined.  Now only a single cast to
AsyncFunctionPointerPtrTy is required and one or both fields can be
loaded from it.

The real benefit of this change is as follows: when these function
pointers are authenticated as is required to dereference it on arm64e,
the authentication will only need to be performed once rather than once
for the function pointer and once for the size.
2020-12-04 16:36:37 -08:00
Nate Chandler
d4be3e88e4 [PtrAuth] Adopt AsyncContextResume schema. 2020-12-04 16:36:36 -08:00
Arnold Schwaighofer
1f16f7ad8a Adjust to LLVM change that requires sret parameter attributes to be
annotated with the pointee type.

rdar://71808491
2020-12-03 09:39:41 -08:00
swift_jenkins
a2680b8296 Merge remote-tracking branch 'origin/main' into next 2020-12-01 11:06:33 -08:00
Erik Eckstein
bf2be9eb5d [concurrency] IRGen: update task/executor/context on every suspend point
For this, store those 3 values on the stack at function entry and update them with the return values of coro_suspend_async intrinsic calls.

This fixes a correctness issue, because the executor may be different after a resume.
It also is more efficient, because this means that the 3 values don't have to preserved in the context over a suspension point.
2020-12-01 15:19:39 +01:00
swift_jenkins
8b28c896dd Merge remote-tracking branch 'origin/main' into next 2020-11-30 18:06:27 -08:00
Richard Wei
de2dbe57ed [AutoDiff] Bump-pointer allocate pullback structs in loops. (#34886)
In derivatives of loops, no longer allocate boxes for indirect case payloads. Instead, use a custom pullback context in the runtime which contains a bump-pointer allocator.

When a function contains a differentiated loop, the closure context is a `Builtin.NativeObject`, which contains a `swift::AutoDiffLinearMapContext` and a tail-allocated top-level linear map struct (which represents the linear map struct that was previously directly partial-applied into the pullback). In branching trace enums, the payloads of previously indirect cases will be allocated by `swift::AutoDiffLinearMapContext::allocate` and stored as a `Builtin.RawPointer`.
2020-11-30 15:49:38 -08:00
swift_jenkins
27508c0119 Merge remote-tracking branch 'origin/main' into next 2020-11-30 15:48:51 -08:00
nate-chandler
9dc2a71181 Merge pull request #34892 from apple/concurrency-main
[Concurrency] Merge concurrency-main to main.
2020-11-30 15:37:54 -08:00
swift_jenkins
3bfd2a4bc7 Merge remote-tracking branch 'origin/main' into next 2020-11-30 11:31:01 -08:00
Nate Chandler
017bedef56 [Async CC] Never map returns to native explosions.
Previously, when lowering the entry point of an async function, the
returned values were lowered to explosions that matched those of sync
functions, namely native explosions. That is incorrect for async
functions where the structured values are within the async context.

Here, that error is fixed, by loading the values returned from the call
out of the async context passed in.

rdar://problem/71641793
2020-11-20 15:35:22 -08:00
Arnold Schwaighofer
beb3951c3f Get rid of getOrCreateAwaitAsyncSupendFn 2020-11-19 13:05:06 -08:00
swift_jenkins
43b2fe020b Merge remote-tracking branch 'origin/main' into next 2020-11-18 11:49:18 -08:00
Arnold Schwaighofer
fbfcaabb83 IRGen: Allow calling a pre-defined async silgen_name function using the async convention
The function can then be implemented in the runtime.

Note: This is a temporary hack.
2020-11-17 15:02:13 -08:00
swift_jenkins
9b5fad5447 Merge remote-tracking branch 'origin/main' into next 2020-11-16 17:43:41 -08:00
Arnold Schwaighofer
dafeb892bd Merge pull request #34764 from aschwaighofer/fix_irge_builtins_create_async_tasks
Fix lowering of Builtin.createAsyncTask and Builtin.createAsyncTaskFuture
2020-11-16 16:47:54 -08:00
swift_jenkins
db4e02556a Merge remote-tracking branch 'origin/main' into next 2020-11-16 14:23:23 -08:00
nate-chandler
f8556287c7 Merge pull request #34765 from nate-chandler/concurrency/irgen/thick-context-in-async-context
[Async CC] Move thick context into async context.
2020-11-16 14:21:46 -08:00
swift_jenkins
4b89f765a7 Merge remote-tracking branch 'origin/main' into next 2020-11-16 13:52:10 -08:00
Arnold Schwaighofer
fa54ff8568 IRGen: Fix lowering of Builtin.createAsyncTask and Builtin.createAsyncTaskFuture
Thick async functions store their async context size in the closure
context. Only if the closure context is nil can we assume the
partial_apply_forwarder function to be the address of an async function
pointer struct value.
2020-11-16 13:33:55 -08:00
Nate Chandler
eba057fe88 [Async CC] Move thick context into async context.
Previously, the thick context was passed as a fourth parameter to
partial apply forwarders.  Here, the thick context is instead moved into
the async context at the local context position.  To support this, the
local context is made always available.
2020-11-16 12:02:32 -08:00
Doug Gregor
069dfad638 [Concurrency] Add Builtin.createAsyncTaskFuture.
This new builtin allows the creation of a "future" task, which calls
down to swift_task_create_future to actually form the task.
2020-11-15 22:37:13 -08:00
swift_jenkins
eaa1084fee Merge remote-tracking branch 'origin/main' into next 2020-11-14 10:16:24 -08:00
swift_jenkins
f7ea3ffe95 Merge remote-tracking branch 'origin/main' into next 2020-11-13 14:18:07 -08:00
Arnold Schwaighofer
2271d4df55 Use taskAlloc for dynamic allocas
Async coroutines don't support dynamic allocas.
2020-11-13 10:41:42 -08:00
Arnold Schwaighofer
74419d0885 Lower asynchronous functions to LLVM async coroutine intrinsics
rdar://70097093
2020-11-13 10:41:42 -08:00
Arnold Schwaighofer
ed5a759fcf Change swift_task_create_f to swift_task_create now that explosions are async function pointers 2020-11-13 10:41:42 -08:00
swift_jenkins
c3c8e6dd18 Merge remote-tracking branch 'origin/main' into next 2020-11-13 09:58:56 -08:00
Arnold Schwaighofer
32ecd350e9 Change swift_task_create_f to swift_task_create now that explosions are async function pointers 2020-11-13 07:32:33 -08:00
Nate Chandler
2d21932672 [Async CC] Add constant "pointer" for async func.
An AsyncFunctionPointer, defined in Task.h, is a struct consisting of
two i32s: (1) the relative address of the async function and (2) the
size of the async context to be allocated when calling that function.

Here, such structs are emitted for every async SILFunction that is
emitted.
2020-11-12 18:20:10 -08:00
swift_jenkins
7e9cbf4c0d Merge remote-tracking branch 'origin/main' into next 2020-11-09 20:52:43 -08:00
David Zarzycki
55db26faf9 Partially unbreak the build
CfgTraits was reverted almost two weeks ago upstream but will presumably
come back. See: e025d09b216dc2239e1b502f4f277abb6fb4648a

The PPC MMA clang types were added nine days ago.

The stdlib is still crashing deep in LLVM:

```
swifterror value can only be loaded and stored from, or as a swifterror argument!
%swift.error** %2
  %7 = bitcast %swift.error** %2 to %swift.opaque*
in function $ss7DecoderP16unkeyedContainers015UnkeyedDecodingC0_pyKFTj
```

From a lldb session, the function in question:

```
define protected swiftcc void @"$ss7DecoderP16unkeyedContainers015UnkeyedDecodingC0_pyKFTj"(%Ts24UnkeyedDecodingContainerP* noalias nocapture sret %0, %swift.opaque* noalias nocapture swiftself %1, %swift.error** noalias nocapture swifterror dereferenceable(8) %2, %swift.type* %3, i8** %4) #0 {
  %6 = bitcast %Ts24UnkeyedDecodingContainerP* %0 to %swift.opaque*
  %7 = bitcast %swift.error** %2 to %swift.opaque*
  tail call swiftcc void @"$sSK5index6before5IndexQzAD_tFTj"(%swift.opaque* noalias nocapture sret %6, %swift.opaque* noalias nocapture %1, %swift.opaque* noalias nocapture swiftself %7, %swift.type* %3, i8** %4) #0
  ret void
}
```
2020-11-08 11:05:09 -05:00
Doug Gregor
4c2c2f32e9 [Concurrency] Implement a builtin createAsyncTask() to create a new task.
`Builtin.createAsyncTask` takes flags, an optional parent task, and an
async/throwing function to execute, and passes it along to the
`swift_task_create_f` entry point to create a new (potentially child)
task, returning the new task and its initial context.
2020-11-07 23:05:04 -08:00
swift_jenkins
6c8d31207e Merge remote-tracking branch 'origin/main' into next 2020-11-05 21:34:59 -08:00
Doug Gregor
a2d7c701a4 Merge pull request #34600 from DougGregor/async-task-builtins
[Concurrency] Add cancelAsyncTask() builtin.
2020-11-05 20:53:25 -08:00
swift_jenkins
ecd5ded632 Merge remote-tracking branch 'origin/main' into next 2020-11-05 17:03:22 -08:00
Doug Gregor
c291eb596b [Concurrency] Add cancelAsyncTask() builtin.
Implement a new builtin, `cancelAsyncTask()`, to cancel the given
asynchronous task. This lowers down to a call into the runtime
operation `swift_task_cancel()`.

Use this builtin to implement Task.Handle.cancel().
2020-11-05 13:50:17 -08:00
Nate Chandler
8e2b1277cc [NFC] Clang-formatted 8e9dec23fc.
The commit with the following message wasn't previously formatted.  That
oversight is fixed here.

    [NFC] Construct AsyncContextLayout from module.

    Previously, an IRGenFunction was being passed to the functions that
    construct an AsyncContextLayout.  That was not actually necessary and
    prevented construction of the layout in contexts where no IRGenFunction
    was present.  Here that requirement is eased to requiring an IRGenModule
    which is indeed required to construct an AsyncContextLayout.
2020-11-05 13:37:23 -08:00
swift_jenkins
36503e0c58 Merge remote-tracking branch 'origin/main' into next 2020-11-05 06:59:09 -08:00
Nate Chandler
8e9dec23fc [NFC] Construct AsyncContextLayout from module.
Previously, an IRGenFunction was being passed to the functions that
construct an AsyncContextLayout.  That was not actually necessary and
prevented construction of the layout in contexts where no IRGenFunction
was present.  Here that requirement is eased to requiring an IRGenModule
which is indeed required to construct an AsyncContextLayout.
2020-11-04 18:42:06 -08:00
swift_jenkins
3e5db601d7 Merge remote-tracking branch 'origin/main' into next 2020-11-02 10:06:47 -08:00
Nate Chandler
c502e97a25 [Async CC] Auth'd parent context pointer. 2020-10-28 12:48:54 -07:00
swift_jenkins
3d854c3013 Merge remote-tracking branch 'origin/main' into next 2020-10-28 10:00:57 -07:00
swift_jenkins
01491db27e Merge remote-tracking branch 'origin/main' into next 2020-10-27 18:14:28 -07:00
Nate Chandler
80d1f83b6d [Async CC] Add coroutine fields to context.
The following fields are now available when the function is a coroutine:
- TaskContinuationFunction * __ptrauth(...) yieldToCaller?
- TaskContinuationFunction * __ptrauth(...) resumeFromYield?
- TaskContinuationFunction * __ptrauth(...) abortFromYield?
- ExecutorRef calleeActorDuringYield?
- YieldTypes yieldValues...

These fields have yet to be filled in.

The following field are now available when the function is NOT a
coroutine (whereas previously they were always available):
- ResultTypes directResults...
2020-10-27 18:11:58 -07:00
Nate Chandler
c22c0c523a [Async CC] Add Flags to context. 2020-10-27 18:07:50 -07:00
Nate Chandler
e3f92e4d15 [NFC] Added lambda to add executor.
Filtered code for adding ResumeParentExecutor to the async layout
through the new lambda.
2020-10-27 18:07:39 -07:00
Nate Chandler
5a6290f887 [NFC] Added lambda to add task continuation func.
Filtered code for adding ResumeParent to the async layout through the
new lambda.
2020-10-27 18:06:53 -07:00
Nate Chandler
2ff6ea3693 [Async CC] Pass executor along to callee. 2020-10-27 13:52:59 -07:00
Nate Chandler
ddb739e301 [Async CC] Pass task along from caller to callee. 2020-10-27 13:52:59 -07:00