Commit Graph

538 Commits

Author SHA1 Message Date
Arnold Schwaighofer
84eac93568 [IRGen] Use the result polymorphic coro.suspend.async intrinsic
This needs llvm-project PR 2481.
2021-02-12 10:17:11 -08:00
Nate Chandler
e2a8abc9e5 [Async CC] Make error indirect.
Previously, the error stored in the async context was of type SwiftError
*.  In order to enable the context to be callee released, make it
indirect and change its type to SwiftError **.

rdar://71378532
2021-02-11 11:34:47 -08:00
Arnold Schwaighofer
5a6de1ba77 IRGen: Use opaque storage types for non-fixed indirect result types
LLVM does type based analysis on sret storage types. This is a problem
with non-fixed types whose storage type does not contain the non-fixed
part.

rdar://73778591
2021-02-10 16:19:12 -08:00
swift-ci
89c8005a80 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 15:52:25 -08:00
Slava Pestov
c79de40225 IRGen: Emit async function pointers for resilient class and protocol dispatch thunks
This adds new kinds of link entities corresponding to the three
dispatch thunk link entity kinds:

- DispatchThunkAsyncFunctionPointer
- DispatchThunkInitializerAsyncFunctionPointer
- DispatchThunkAllocatorAsyncFunctionPointer
2021-01-27 15:21:22 -05:00
swift-ci
9d0d1fff60 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-26 06:12:31 -08:00
Arnold Schwaighofer
daa72d3cc5 Add llvm::Attribute::SwiftAsync to the context parameter
* Adds support for generating code that uses swiftasync parameter lowering.

* Currently only arm64's llvm lowering supports the swift_async_context_addr intrinsic.

* Add arm64e pointer signing of updated swift_async_context_addr.

This commit needs the PR llvm-project#2291.

* [runtime] unittests should use just-built compiler if the runtime did

This will start to matter with the introduction of usage of swiftasync parameters which only very recent compilers support.

rdar://71499498
2021-01-22 10:01:55 -08:00
swift-ci
d2bafec8a4 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-20 11:12:03 -08:00
Varun Gandhi
a6d0cca201 [IRGen] Add hack to handle _Atomic(_Bool) correctly. 2021-01-20 08:52:07 -08:00
Arnold Schwaighofer
25ff64686d Adjust to llvm's byVal parameter attributes needing the storage type
rdar://73172496
2021-01-14 15:33:42 -08:00
swift_jenkins
6fe8b0edbd Merge remote-tracking branch 'origin/main' into next 2020-12-22 18:03:22 -08:00
Arnold Schwaighofer
59b1deea06 Adjust to addition of llvm::Attribute::SwiftAsync
This the Swift change to go with the llvm PR
https://github.com/apple/llvm-project/pull/2274.
2020-12-21 13:22:22 -08:00
swift_jenkins
f8c59be74a Merge remote-tracking branch 'origin/main' into next 2020-12-17 10:14:35 -08:00
Erik Eckstein
6b13814923 [Concurrency] IRGen: correct substitution for the createAsyncTaskFuture builtin.
Instead of substituting the AST type, substitute the SIL type. This preserves the calling convention.
E.g. if a function has an indirect @out T result, the substituted function must also have an indirect result.
The substituted AST type would just have a direct empty-tuple result.

Fixes a miscompile
rdar://72386504
2020-12-17 14:55:46 +01:00
swift_jenkins
35b1e26cc6 Merge remote-tracking branch 'origin/main' into next 2020-12-16 21:26:12 -08:00
Nate Chandler
98e732de19 [Async CC] Pass witness metadata to callees.
Previously, the WitnessMetadata values that were collected were just
ignored when making a function call, although space was reserved for
them in the async context.  Here, that error is corrected by actually
storing them into the async context if they are present.
2020-12-16 17:20:32 -08:00
Jonas Devlieghere
f7d8659f75 Adjust for upstream PowerPC builtin/instrinsic patch.
See 57d83c3a90c427ad0975803feb5b348d1ad34e29 for the changes to clang.
2020-12-16 09:51:52 -08:00
swift_jenkins
eade12ccaa Merge remote-tracking branch 'origin/main' into next 2020-12-07 08:50:18 -08:00
Nate Chandler
0f2b659a8d [PtrAuth] Pass discriminator to swift_suspend_dispatch.
Previously, swift_suspend_dispatch was passed a pointer to a function
and createAsyncDispatchFn was passed a FunctionPointer.  The latter
constructed a new FunctionPointer using the passed-in function pointer
as the value, because the value inside the FunctionPointer was a value
in a different function.

That worked fine on platforms without pointer authentication.  On
arm64e, however, calling a function can use two values from a
FunctionPointer: the pointer to the function and the discriminator.  The
result was that on arm64e, swift_suspend_dispatch failed verification
because the discriminator value that was used in the call made by
swift_suspend_dispatch did not originate in that function.

Here, that problem is resolved by passing the discriminator to
swift_suspend_dispatch.  Now, createAsyncDispatchFn creates a
FunctionPointer using not just the passed-in function pointer but also
the passed-in discriminator.  The result is that swift_suspend_dispatch
no longer fails verification.
2020-12-04 18:11:05 -08:00
Nate Chandler
b8ec80aac3 [Async CC] Resigned ptr passed to swift_task_create[_f].
When emitting Builtin.createAsyncTask[Future], the function passed to
the builtin is passed along to swift_task_create[_f].  The latter is
expecting a AsyncFunctionType<void()>, which is an alias for

  void (AsyncTask *, ExecutorRef, AsyncContext *)

Previously, no ptrauth logic was emitted when emitting the builtins, so
the function pointer was not signed in the way expected by
swift_task_create[_f].  The result was a ptrauth failure on arm64e.
Here, that problem is fixed by resigning the function pointer in the way
the runtime expects.
2020-12-04 18:11:05 -08:00
Nate Chandler
eac9cfc2cb [Async CC] Auth'd AFP ptr of statically thin fn.
In irgen::getAsyncFunctionAndSize, in the case where the passed-in
function has a thin representation, the pointer that is passed in is not
actually a pointer to a function but instead a pointer to an
AsyncFunctionPointer struct.  To obtain the function pointer and size,
fields must be loaded from this struct.  However, in order to load these
fields, that pointer to the AsyncFunctionPointer struct must itself
first be authenticated.  Here, that authentication is performed.
Subsequently, the function pointer is again signed.
2020-12-04 18:11:05 -08:00
Nate Chandler
0d93b8d7d4 [Async CC] Auth'd AFP ptr to load ptr from FunctionPointer.
In FunctionPointer::getPointer, in the case that the FunctionPointer is
actually a pointer to an AsyncFunctionPointer struct, the relative
address of the function must be loaded from the AsyncFunctionPointer
struct.  Doing so requires authentication that pointer to the
AsyncFunctionPointer struct.  Here, that authentication is done.
2020-12-04 18:11:05 -08:00
Nate Chandler
d17c06905e [Async CC] Auth'd AFP ptr of dynamically thin fn.
In irgen::getAsyncFunctionAndSize, in the case where the passed-in
function has a thick representation but is dynamically thin, the pointer
that is passed in is not actually a pointer to a function but instead a
pointer to an AsyncFunctionPointer struct.  To obtain the function
pointer and size, fields must be loaded from this struct.  However, in
order to load these fields, that pointer to the AsyncFunctionPointer
struct must itself first be authenticated.  Here, that authentication is
performed.
2020-12-04 18:11:05 -08:00
Nate Chandler
bbf57959ef [Async CC] Fixed AuthInfo of AsyncCallEmission.
Previously, an empty PtrAuthInfo was used to construct a FunctionPointer
in AsyncCallEmission::getCalleeFunctionPointer.  Here that is corrected
to use the auth info that was attached to the callee function pointer
(which is actually a pointer to an AsyncFunctionPointer struct).
2020-12-04 18:11:04 -08:00
Nate Chandler
e7ec8c245d [Async CC] Handle contextless fn ptrs in getAsyncFunctionAndSize.
Now that AsyncFunctionPointers are destructured in
getAsyncFunctionAndSize--rather than just calling through to
FunctionPointer::getPointer--in order to avoid authing the same
pointer-to-AsyncFunctionPointer twice in a row, that function must now
also handle the case--previously handled within
FunctionPointer::getPointer--where a FunctionPointer whose Kind is
AsyncFunctionPointer but which has isFunctionPointerWithoutContext set
to true.  Here, that consideration is done.
2020-12-04 18:11:04 -08:00
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