Commit Graph

542 Commits

Author SHA1 Message Date
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
Nate Chandler
f73eff7e8e [Async CC] Save parent executor into context.
When an async function is called from an async function, the caller
stores its own executor into the the callee's context in the
ResumeParentExecutor field.
2020-10-27 13:52:58 -07:00
David Smith
0180aca9fc Merge branch 'main' into david/fix-merge-conflict 2020-10-27 13:05:20 -07:00
Nate Chandler
c9e567b530 [Async CC] Save parent context into child context.
When an async function is called from an async function, it stores its
own context pointer into the callee's callerContext.
2020-10-27 12:40:54 -07:00
Nate Chandler
904876e6bd [Async CC] Pass the function's task to task_[de]alloc.
Previously, a null task was always passed to
swift_task_alloc/swift_task_dealloc.  Now that the current task is
available as one of the arguments to every async function, pass that
value along to the runtime de/allocation functions.
2020-10-27 12:40:49 -07:00
Nate Chandler
1e0d6f39d7 [Async CC] Add ResumeParentExecutor to context. 2020-10-27 12:40:42 -07:00
Nate Chandler
f29f43907f [Async CC] Add ResumeParent to async context. 2020-10-27 12:40:40 -07:00
Nate Chandler
5d67c4a74b [Async CC] Add parent to async context. 2020-10-27 12:39:56 -07:00
Nate Chandler
b65d71b24a [Async CC] Added conveniences to retrieve argumments.
Because all async functions have the same signature, namely

  void(%swift.task*, %swift.executor*, %swift.context*)

it is always possible to provide access to the three argument values
(the current task, current executor, and current context) within an
IRGenFunction which is async.  Here, that is provided in the form of
IRGenFunction::getAsyncExecutor,IRGenFunction::getAsyncContext, and
IRGenFunction::getAsyncTask.
2020-10-26 20:07:56 -07:00
Nate Chandler
b74052cdd2 [Async CC] Added task and executor args.
The previous stage of bringup only had async functions taking a single
argument: the async context.  The next stage will involve the task and
executor.  Here, arguments are added for those values.  To begin with,
null is always passed for these values.
2020-10-26 14:27:16 -07:00
nate-chandler
d1bfe027c0 Merge pull request #34402 from nate-chandler/concurrency/irgen/tests-all-async
[Async CC] Test: Mark functions that call async functions async.
2020-10-26 09:59:48 -07:00
Nate Chandler
a963d0a66b [Async CC] Added TODO for codesize improvement. 2020-10-23 11:09:46 -07:00
Nate Chandler
b8a5b62f72 [NFC] Cached the layout in AsyncCallEmission. 2020-10-23 11:08:38 -07:00
swift-ci
64ec60bbd4 Merge pull request #34370 from nate-chandler/concurrency/irgen/partial-apply 2020-10-22 13:54:37 -07:00
Nate Chandler
506473dfba [Async CC] Supported partial application.
The majority of support comes in the form of emitting partial
application forwarders for partial applications of async functions.
Such a partial application forwarder must take an async context which
has been partially populated at the apply site.  It is responsible for
populating it "the rest of the way".  To do so, like sync partial
application forwarders, it takes a second argument, its context, from
which it pulls the additional arguments which were capture at
partial_apply time.

The size of the async context that is passed to the forwarder, however,
can't be known at the apply site by simply looking at the signature of
the function to be applied (not even by looking at the size associated
with the function in the special async function pointer constant which
will soon be emitted).  The reason is that there are an unknown (at the
apply site) number of additional arguments which will be filled by the
partial apply forwarder (and in the case of repeated partial
applications, further filled in incrementally at each level).  To enable
this, there will always be a heap object for thick async functions.
These heap objects will always store the size of the async context to be
allocated as their first element.  (Note that it may be possible to
apply the same optimization that was applied for thick sync functions
where a single refcounted object could be used as the context; doing so,
however, must be made to interact properly with the async context size
stored in the heap object.)

To continue to allow promoting thin async functions to thick async
functions without incurring a thunk, at the apply site, a null-check
will be performed on the context pointer.  If it is null, then the async
context size will be determined based on the signature.  (When async
function pointers become pointers to a constant with a size i32 and a
relative address to the underlying function, the size will be read from
that constant.)  When it is not-null, the size will be pulled from the
first field of the context (which will in that case be cast to
<{%swift.refcounted, i32}>).

To facilitate sharing code and preserving the original structure of
emitPartialApplicationForwarder (which weighed in at roughly 700 lines
prior to this change), a new small class hierarchy, descending from
PartialApplicationForwarderEmission has been added, with subclasses for
the sync and async case.  The shuffling of arguments into and out of the
final explosion that was being performed in the synchronous case has
been preserved there, though the arguments are added and removed through
a number of methods on the superclass with more descriptive names.  That
was necessary to enable the async class to handle these different
flavors of parameters correctly.

To get some initial test coverage, the preexisting
IRGen/partial_apply.sil and IRGen/partial_apply_forwarder.sil tests have
been duplicated into the async folder.  Those tests cases within these
files which happened to have been crashing have each been extracted into
its own runnable test that both verifies that the compiler does not
crash and also that the partial application forwarder behaves correctly.
The FileChecks in these tests are extremely minimal, providing only
enough information to be sure that arguments are in fact squeezed into
an async context.
2020-10-22 12:21:56 -07:00
Nate Chandler
03f4e40f20 [Async CC] Move self after formal arguments.
Partial applies of methods supply only self.  When applies of the
resulting thick function are performed, that self was one of the
arguments is not known.  As a result, self must appear after the fields
that might be supplied at the apply site, which  is to say all the
arguments.
2020-10-21 16:20:51 -07:00
Nate Chandler
63b5ba457e [NFC] Used consistent style for casting. 2020-10-21 16:19:29 -07:00
Nate Chandler
0356c9f4c0 [NFC] Simplify saving of self to async context. 2020-10-21 16:19:20 -07:00
Nate Chandler
a9aee1b9dd [Async CC] Put bindings after formal arguments.
Bindings will always be supplied by the first partial apply, so they
will only be added to the async context when its full layout is known.
If they are earlier in the layout, subsequent partial applies will put
their arguments into the wrong position because they will not be privy
to the space requirements of the bindings.
2020-10-21 16:18:29 -07:00
Nate Chandler
97202faee5 [Async CC] Put direct returns after indirect returns.
For callers who do not know the actual type of the called function, e.g.
when the called function is the result of a partial apply, the offset to
the direct returns would otherwise not be known.
2020-10-21 16:18:25 -07:00
swift-ci
7e16e3b4d2 Merge pull request #30630 from martinboehme/cxx-constructors 2020-10-20 14:37:29 -07:00
zoecarver
1d3b051151 [cxx-interop] Remove logic around applying attributes.
Removes the logic around applying attributes to C++ constructor's
indirect results.

Also fixes some commenting.
2020-10-15 13:10:55 -07:00